#include #include #include #include #include #include using namespace std; int n, K, m; int a[100]; int cnt[100]; string curr; int ju(int k) { int res = 0; for (int i = 0; i < 10; i++) { res += cnt[k * 10 + i]; } return res; } void dfs(int d) { if (curr.size() == m) { cout << curr << endl; K--; if (K == 0) exit(0); return; } if (d == -1) { for (int i = 9; i >= 1; i--) { dfs(i); } } else { for (int i = 9; i >= 0; i--) { int x = d * 10 + i; if (cnt[x] > 0) { cnt[x]--; curr += to_string(x); dfs(-1); curr.pop_back(); curr.pop_back(); cnt[x]++; } else if (i > 0 && cnt[d] > 0 && (cnt[i] > 0 || ju(i) > 0)) { cnt[d]--; curr += to_string(d); dfs(i); curr.pop_back(); cnt[d]++; } } } } int main() { cin >> n >> K; for (int i = 0; i < n; i++) { cin >> a[i]; cnt[a[i]]++; m += to_string(a[i]).size(); } dfs(-1); }