#include <iostream>
using namespace std;
int freq[26], mod[26];
int main() {
int n, k;
string s;
cin >> n >> k >> s;
for(int i = 0; i < n; ++i){
freq[s[i] - 'a']++;
}
bool u = 0;
for(int i = 0; i < 26; ++i){
if(freq[i] % k){
u = 1;
}
mod[i] = freq[i] % k;
}
for(int i = 0; i < 26; ++i){
if(freq[i] < k && freq[i] || freq[i] && mod[i] > freq[i] / k){
cout << 3 << endl;
return 0;
}
}
if(!u){
cout << 1 << endl;
for(int i = 0; i < n; ){
for(int j = 0; j < 26; ++j){
for(int l = 0; l < freq[j] / k; ++l){
cout << (char)('a' + j);
++i;
}
}
}
}
else{
cout << 2 << endl;
int l = 0, c = 0;
while(c < k){
for(int i = 0; i < 26; ++i){
for(int j = 0; j < mod[i]; ++j){
cout << (char)('a' + i);
}
}
for(int i = 0; i < 26; ++i){
for(int j = 0; j < freq[i] / k - mod[i] && freq[i]; ++j){
cout << (char)('a' + i);
}
}
++c;
}
for(int i = 0; i < 26; ++i){
for(int j = 0; j < mod[i]; ++j){
cout << (char)('a' + i);
}
}
}
return 0;
}
Copy