fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n , ans=0 , freq[27];
  6. cin>>n ;
  7. string s;
  8. cin>>s ;
  9. if ( n >26 )
  10. cout<<"-1"<<endl;
  11. else {
  12. for (int i=0 ;i<n ;i++ )
  13. freq[s[i]-'a' ]++;
  14.  
  15. for ( int j=0 ;j<26 ;j++){
  16. if (freq[j] >1 ){
  17. ans+=freq[s[j]]-1 ;
  18. }
  19. }
  20. }
  21. cout<<ans <<endl;
  22. return 0;
  23. }
Success #stdin #stdout 0s 15240KB
stdin
4
koko
stdout
923522051