#include using namespace std; char mat[14][14]; bool viz[14][14]; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int apar[6]; char ch[] = {'0','1','2','3', '4', '5'}; void resetApar() { for(int i = 0; i < 6; i++) apar[i] = 0; } void resetViz() { for(int i = 0; i < 14; i++) { for(int j = 0; j < 14; j++) { viz[i][j] = false; } } } bool inBounds(int x, int y) { if (x < 0 || x > 13) return false; if (y < 0 || y > 13) return false; return true; } void flood(int x, int y, char target, char repl) { if(mat[x][y] == target || (mat[x][y] == repl && !viz[x][y])) { mat[x][y] = repl; viz[x][y] = true; int newX, newY; for(int i = 0; i < 4; i++) { newX = x + dx[i]; newY = y + dy[i]; if(inBounds(newX, newY)) flood(newX, newY, target, repl); } } else { apar[mat[x][y] - '0']++; return; } } int getMaj() { int maxx = 0; int col = 0; for(int i = 0; i < 6; i++) { if(apar[i] > maxx) { maxx = apar[i]; col = i; } } return col; } bool ok() { char c = mat[0][0]; for(int i = 0; i < 14; i++) { for(int j = 0; j < 14; j++) { if(mat[i][j] != c) { return false; } } } return true; } int main() { char c; for(int i = 0; i < 14; i++) { for(int j = 0; j < 14; j++) { cin >> mat[i][j]; } } flood(0, 0, mat[0][0], mat[0][0]); int afis; while(!ok()) { afis = getMaj(); resetApar(); cout << afis << " "; flood(0, 0, mat[0][0], ch[afis]); resetViz(); } return 0; }