#include using namespace std; typedef unsigned color; constexpr color BYTE = 0xff; constexpr int RS = 0; constexpr int GS = 11; constexpr int BS = 22; constexpr color COLOR = 0x3fc7f8ff; double dist(const color a, const color b) { return /*sqrt(*/((a >> RS & BYTE) - (b >> RS & BYTE)) * ((a >> RS & BYTE) - (b >> RS & BYTE)) + ((a >> GS & BYTE) - (b >> GS & BYTE)) * ((a >> GS & BYTE) - (b >> GS & BYTE)) + ((a >> BS & BYTE) - (b >> BS & BYTE)) * ((a >> BS & BYTE) - (b >> BS & BYTE)); } color mix(const color a, const color b) { return ((a + b) / 2) & COLOR; } const int MAXN = 300; const int MAXK = 12; color palette[MAXK]; color mat[MAXN][MAXN]; color mine[MAXN][MAXN]; void stall() { cout<<"3 1 1 0 0\n"; } void print(int i, int j, int x, int k) { if (x < k - 2) cout<<"1 "<>n>>k; for (i = 0; i < k; ++i) { cin>>r>>g>>b; palette[i] = r<>r; mat[i][j] |= r << RS; } for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) { cin>>g; mat[i][j] |= g << GS; } for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) { cin>>b; mat[i][j] |= b << BS; } cout<= 1) for (y = 0; y < k; ++y) { col2 = mix(col1, palette[y]); cur = dist(col2, mat[i][j]) + dist(col2, mat[i + 1][j]);// + dist(col2, mat[i + 2][j]);// + dist(col2, mat[i + 3][j]); if (cur < bestd) { bestd = cur; where = x + k * (y + k * (k + k * k)); } if (excess >= 2) for (z = 0; z < k; ++z) { col3 = mix(col2, palette[z]); cur = dist(col3, mat[i][j]) + dist(col3, mat[i + 1][j]);// + dist(col3, mat[i + 2][j]);// + dist(col3, mat[i + 3][j]); if (cur < bestd) { bestd = cur; where = x + k * (y + k * (z + k * k)); } if (excess >= 3) for (w = k - 2; w < k; ++w) { col4 = mix(col3, palette[w]); cur = dist(col4, mat[i][j]) + dist(col4, mat[i + 1][j]); if (cur < bestd) { bestd = cur; where = x + k * (y + k * (z + k * w)); } } } } } for (x = 0; x <= i; x += 2) for (y = 0; y < n && (x < i || y < j); y += (rand() % 64 + 1)) { cur = dist(mix(current, mine[x][y]), mat[i][j]) + dist(mix(current, mine[x][y]), mat[i + 1][j]); if (cur < bestd) { bestd = cur; where = -1 - (x * n + y); } } if (where >= 0) { if (where < k + k * (k + k * (k + k * k))) { current = mix(current, palette[where % k]); print(i, j, where % k, k); where /= k; if (where < k + k * (k + k * k)) { current = mix(current, palette[where % k]); print(i, j, where % k, k); where /= k; if (where < k + k * k) { current = mix(current, palette[where % k]); print(i, j, where % k, k); where /= k; if (where < k) { current = mix(current, palette[where]); print(i, j, where, k); excess += -3; } else excess += -2; } else excess += -1; } else excess += 0; } else excess += 1; } else { where = -where - 1; current = mix(current, mine[where / n][where % n]); cout<<"2 "<