fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define ne "\n"
  4. #define ll long long
  5. #define re return
  6. #define all(v) (v.begin(),v.end())
  7. #define sz(v) ((int)(v.size()))
  8. #define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  9.  
  10. typedef std::vector<int> vec;
  11.  
  12. using namespace std;
  13.  
  14. int main() {
  15. int k;cin>>k;
  16. string s;cin>>s;
  17. map<char,int>freq;
  18. for(int i=0;i<s.size();i++) {
  19. freq[s[i]]++;
  20. }
  21. for(int i=0;i<s.size();i++)
  22. {
  23. if(freq[s[i]]%k!=0)
  24. {
  25. cout<<"-1"<<ne;
  26. re 0;
  27. }
  28. }
  29. sort all(s);
  30. string ans;
  31. int l;
  32. for(int i=0;i<s.size();i++)
  33. {
  34. l=freq[s[i]]/k;
  35. while(l--)
  36. ans+=s[i];
  37. freq[s[i]]=0;
  38. }
  39.  
  40. while(k--)
  41. cout<<ans;
  42. cout<<ne;
  43. }
Success #stdin #stdout 0.01s 5296KB
stdin
2
aazz
stdout
azaz