#include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) template using vi = vector; template using vii = vector>; template using viii = vector>; using pii = pair; int n = 36; const int len = 6; const int TL = 1000 * 1000; const int TL2 = 1920 * 1000; struct dice { vi vec; int idx = 0; dice() : vec(len), idx(0){} }; vi d(n); vii board(len, vi(len)); int score() { const int inf = 1e9; int res = 0; rep(i, len){ vi cnt(len, 0); rep(j, len) { rep(k, len) { //どの値 int pos = board[i][j]; int num = d[pos].vec[k]; if (num) cnt[k] += num; else cnt[k] = -inf; } } rep(k, len) { if (cnt[k] > 0) res += 3 + cnt[k] - 6; } } rep(j, len){ vi cnt(len, 0); rep(i, len) { rep(k, len) { //どの値 int pos = board[i][j]; int num = d[pos].vec[k]; if (num) cnt[k] += num; else cnt[k] = -inf; } } rep(k, len) { if (cnt[k] > 0) res += 3 + cnt[k] - 6; } } return res * 1000; } void inv() { rep(i, len) rep(j, i) { swap(board[i][j], board[j][i]); } return; } int main() { random_device rnd; clock_t start = clock(); rep(i, n) { rep(j, len) { int t; cin >> t; t--; d[i].vec[t]++; } d[i].idx = i; } int scr = 0; { vi used(n); rep(i, len) { scr = 0; rep(j, len) { vi cnt; rep(k, n) { if (used[k]) continue; cnt.push_back({ d[k].vec[j], k }); } sort(cnt.begin(), cnt.end(), greater{}); int ts = 0; rep(k2, len) ts += cnt[k2].first; if (ts > scr) { rep(k2, len) board[i][k2] = cnt[k2].second; scr = ts; } } rep(j, len) used[board[i][j]] = true; } } scr = score(); double t0 = 1000, t1 = 900, tmp = t0; int cn = 0; while (clock() - start < TL2) { cn++; if (cn % 100 == 0) { double lt = (double)(clock() - start) / TL2; tmp = pow(t0, 1 - lt) * pow(t1, lt); } if (clock() - start > TL && (rnd() & 1)) inv(); { int idx0 = rnd() % len; int idx1 = (idx0 + rnd() % (len - 1) + 1) % len; int row0 = rnd() % len; int row1 = (row0 + rnd() % (len - 1) + 1) % len; swap(board[row0][idx0], board[row1][idx1]); int ts = score(); bernoulli_distribution bd(min(1, exp((ts - scr) / tmp))); if (ts >= scr || bd(rnd)) scr = ts; //if (ts >= scr) scr = ts; else swap(board[row0][idx0], board[row1][idx1]); } } vi ans(n); rep(i, len) rep(j, len) { ans[board[i][j]] = { i + 1, j + 1 }; } for (pii elem : ans) cout << elem.first << " " << elem.second << endl; return 0; }