#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N,K; string A[101]; vector> V; int B[101]; vector S; unordered_set memo[101]; ll mo[2]={1000000007,1000000021}; void dfs(int id,string& cur,ll H1,ll H2,ll ma) { if(S.size()>K+600) { return; } ll H3=((H1<<32)|H2)^ma; if(memo[id].count(H3)) return; memo[id].insert(H3); if(id==N) { S.push_back(cur); return; } int i; FOR(i,V.size()) if(V[i].second) { if(S.size()>K+600) return; V[i].second--; cur+=V[i].first; ll G1,G2; if(B[i]<10) { G1=H1*10+B[i]; G2=H2*10+B[i]; } else { G1=H1*100+B[i]; G2=H2*100+B[i]; } dfs(id+1,cur,G1%mo[0],G2%mo[1],ma^(1LL<<(i%50))); V[i].second++; cur.resize(cur.size()-V[i].first.size()); } } void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>K; FOR(i,N) cin>>A[i]; FOR(i,N) { FOR(j,N-1) { if(A[j]+A[j+1]