Lucy likes letters. She studied the definition of the lexicographical order at school and plays with it.
At first, she tried to construct the lexicographically smallest word out of given letters. It was so easy! Then she tried to build multiple words and minimize one of them. This was much harder!
Formally, Lucy wants to make nn words of length ll each out of the given n⋅ln⋅l letters, so that the kk-th of them in the lexicographic order is lexicographically as small as possible.
Input
The first line contains three integers nn, ll, and kk (1≤k≤n≤10001≤k≤n≤1000; 1≤l≤10001≤l≤1000) — the total number of words, the length of each word, and the index of the word Lucy wants to minimize.
The next line contains a string of n⋅ln⋅l lowercase letters of the English alphabet.
Output
Output nn words of ll letters each, one per line, using the letters from the input. Words must be sorted in the lexicographic order, and the kk-th of them must be lexicographically as small as possible. If there are multiple answers with the smallest kk-th word, output any of them.
Examples
Input
Copy
3 2 2
abcdef
Output
Copy
af
bc
ed
Input
Copy
2 3 1
abcabc
Output
Copy
aab
bcc
//借鉴
#include<bits/stdc++.h>
using namespace std;
string sp[1005];
bool flag[1005];
int main()
{
memset(flag,false,sizeof(flag));
multiset<string>st;
int n,m,k;
cin>>n>>m>>k;
string s;
cin>>s;
sort(s.begin(),s.end());
int pos=0;
while(sp[k].size()<m)
{
for(int i=1;i<=k;i++)
{
if(flag[i])
{
sp[i].push_back(s.back());
s.pop_back();
pos--;
}
else
sp[i].push_back(s[pos]);
pos++;
}
for(int j=1;j<k;j++)
{
if(!flag[j]&&sp[j].back()!=sp[k].back()) flag[j]=true;
}
}
for(int i=1;i<=n-k;i++)
{
st.insert(s.substr(pos,m));
pos+=m;
}
for(int i=1;i<=k;i++)
st.insert(sp[i]);
for(auto R : st)
cout<<R<<endl;
return 0;
}