#include <iostream>
#include <vector>
static const int N = 6;
static const int M = 6;
typedef std::vector<int> vec;
static const int U[M][N] = {{1, 12, 10, 8, 9, 3},
{14, 16, 17, 6, 2, 15},
{12, 1, 13, 2, 4, 18},
{13, 9, 9, 10, 13, 12},
{0, 2, 17, 14, 7, 11},
{19, 3, 2, 19, 0, 1}};
vec assign(int n,int m, vec ne, vec po, vec ot, int j) {
for (int i{}; i < m; i++) {
if(po[i] == 0) {
po[i] = 1;
ne[j] = i;
ne[n] += U[ne[j]][j];
if (j < n-1) ot = assign(n, m, ne, po, ot, j+1);
if(ne[n] > ot[n]) ot = ne;
else {
po[i] = 0;
ne[n] -= U[ne[j]][j];
}
}
}
return ot;
}
vec assign() {
return assign( N, M, vec(N+1, 0), vec(N+1, 0), vec(N+1, 0), 0);
}
int main() {
// your code goes here
vec ot = assign();
for (int i : ot) std::cout << i << ' ';
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKc3RhdGljIGNvbnN0IGludCBOID0gNjsKc3RhdGljIGNvbnN0IGludCBNID0gNjsKCnR5cGVkZWYgc3RkOjp2ZWN0b3I8aW50PiB2ZWM7CgpzdGF0aWMgY29uc3QgaW50IFVbTV1bTl0gPSB7ezEsIDEyLCAxMCwgOCwgOSwgM30sCgkJCQkJCQl7MTQsIDE2LCAxNywgNiwgMiwgMTV9LAoJCQkJCQkJezEyLCAxLCAxMywgMiwgNCwgMTh9LAoJCQkJCQkJezEzLCA5LCA5LCAxMCwgMTMsIDEyfSwKCQkJCQkJCXswLCAyLCAxNywgMTQsIDcsIDExfSwKCQkJCQkJCXsxOSwgMywgMiwgMTksIDAsIDF9fTsKCnZlYyBhc3NpZ24oaW50IG4saW50IG0sIHZlYyBuZSwgdmVjIHBvLCB2ZWMgb3QsIGludCBqKSB7Cglmb3IgKGludCBpe307IGkgPCBtOyBpKyspIHsKCQlpZihwb1tpXSA9PSAwKSB7CgkJCXBvW2ldID0gMTsKCQkJbmV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