#include <iostream>
#include <vector>
using namespace std;
int n, a[10], arr[10], k, used[10], d = 1, s = 0;
bool timThayyy = false;
// a[] là hoán vị của các số tự nhiên từ 1 đến n
// arr[] là hoán vị của n phần tử
void check() {
if (timThayyy)
return;
int sum = 0;
vector<int> res;
res.clear();
for (int i = 0; i < n; i++) {
if (sum + arr[a[i] - 1] > s/k)
return;
sum += arr[a[i] - 1];
if (sum == s/k) {
res.push_back(a[i] - 1); // lưu vị trí phần tử cuối của nhóm
sum = 0;
}
}
timThayyy = true;
cout<< "Có thể chia "<< n<< " phần tử thành "<< k<< " nhóm có tổng là "<< s/k<< endl;
int j = 0;
cout<< j + 1<< ": ";
for (int i = 0; i < n; i++) {
cout<< arr[a[i] - 1]<< " ";
if (res[j] == a[i] - 1) {
cout<< endl;
j++;
if (i < n - 1)
cout<< j + 1<< ": ";
}
}
}
void permutation(int i) {
if (timThayyy)
return;
for (int j = 1; j <= n; j++) {
if (!used[j]) {
a[i] = j;
used[j] = 1;
if (i == n - 1)
check();
else
permutation(i + 1);
used[j] = 0;
}
}
}
int main() {
cin >> n>> k;
for (int i = 0; i < n; i++) {
cin>> arr[i];
s += arr[i];
}
if (s % k != 0) {
cout<< "oh noooo!!!!";
return 0;
}
permutation(0);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG4sIGFbMTBdLCBhcnJbMTBdLCBrLCB1c2VkWzEwXSwgZCA9IDEsIHMgPSAwOwpib29sIHRpbVRoYXl5eSA9IGZhbHNlOwoKLy8gYVtdIGzDoCBob8OhbiB24buLIGPhu6dhIGPDoWMgc+G7kSB04buxIG5oacOqbiB04burIDEgxJHhur9uIG4KLy8gYXJyW10gbMOgIGhvw6FuIHbhu4sgY+G7p2EgbiBwaOG6p24gdOG7rSAKCgp2b2lkIGNoZWNrKCkgewoJaWYgKHRpbVRoYXl5eSkKCQlyZXR1cm47CglpbnQgc3VtID0g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ICAgICAgICAgICB1c2VkW2pdID0gMDsgCiAgICAgICAgfQogICAgfQp9CgppbnQgbWFpbigpIHsKICAgIGNpbiA+PiBuPj4gazsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAJY2luPj4gYXJyW2ldOwogICAgCXMgKz0gYXJyW2ldOwogICAgfQogICAgaWYgKHMgJSBrICE9IDApIHsKICAgIAljb3V0PDwgIm9oIG5vb29vISEhISI7CiAgICAJcmV0dXJuIDA7CiAgICB9CiAgICBwZXJtdXRhdGlvbigwKTsKfQo=