#include #define REP(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using namespace std; struct Input { array, 36> in; Input() { REP(i, 36) { REP(j, 6) { cin >> in[i][j]; in[i][j]--; } in[i][6] = i; } } array CheckCount() { // 残っているダイスの数を数える array ret; REP(i, 36) { if(in[i][0] == -1)continue; REP(j, 6) { ret[in[i][j]]++; } } return ret; } int SearchTarget() { //並べる数を探す array ss = CheckCount(); int ret = 0; REP(i, 6) { if(ss[ret] < ss[i]) { ret = i; } } return ret; } void Solve() { array, 36> ans; REP(i, 6) { const int TARGET = SearchTarget(); sort(in.begin(), in.end(), [&](auto l, auto r) { if(l[0] == -1)return false; if(r[0] == -1)return true; auto f = [&](array arr) { int ret = 0; REP(i, 6) { if(arr[i] == TARGET)ret++; } return ret; }; int lcount = f(l), rcount = f(r); return lcount > rcount; }); REP(j, 6) { ans[in[j][6]] = pair(i + 1, j + 1); in[j][0] = -1; } } REP(i, 36) { cout << ans[i].first << " " << ans[i].second << endl; } } }; int main() { Input in; in.Solve(); }