#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 = 1 * 1000; const int TL2 = 2 * 1000; const int inf = 1e9; 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(); int scr = 0; const int brd = 0; vii used(len, vi(len)); rep(i, n) { int j = i / len; int k = i % len; if (j == k) d[i].vec[j] = 6; else { //d[i].vec[j] = 3; //d[i].vec[k] = 3; rep(_, 6) d[i].vec[_] = 1; } } rep(i, len) rep(j, len) board[i][j] = i * len + j; rep(i, brd) { rep(j, len) d[i].vec[j] = 0; vi vec(len); rep(j, len) { cin >> vec[j]; vec[j]--; d[i].vec[vec[j]]++; } bool ok = false; rep(j, len) if (d[i].vec[j] >= 3 && !used[j][j]) { cout << j + 1 << " " << j + 1 << endl; used[j][j] = true; board[j][j] = i; ok = true; break; } if (ok) continue; map mp; rep(j, len) rep(k, j) mp[{min(vec[j], vec[k]), max(vec[j], vec[k])}]++; vi> d2; for (auto elem : mp) d2.push_back({ elem.second, elem.first }); sort(d2.begin(), d2.end(), greater>{}); for (auto elem : d2) { int x = elem.second.first, y = elem.second.second; if (!used[x][y]) { cout << x + 1 << " " << y + 1 << endl; used[x][y] = true; board[x][y] = i; ok = true; break; } else if (!used[y][x]) { cout << y + 1 << " " << x + 1 << endl; used[y][x] = true; board[y][x] = i; ok = true; break; } } if (ok) continue; rep(j, len) { rep(k, len) { if (!used[j][k]) { cout << j + 1 << " " << k + 1 << endl; used[j][k] = true; board[j][k] = i; ok = true; break; } } if (ok) break; } } for(int i = brd; i < n - 1; i++) { dice D; rep(j, len) { int t; cin >> t; t--; D.vec[t]++; } int pj = -1, pk = -1; scr = -inf; rep(j, len) rep(k, len) { if (used[j][k]) continue; swap(d[j * len + k], D); int ts = score(); if (ts >= scr) { scr = ts; pj = j; pk = k; } swap(d[j * len + k], D); } used[pj][pk] = true; swap(d[pj * len + pk], D); cout << pj + 1 << " " << pk + 1 << endl; } //cout << score() << endl; return 0; }