#include #include #include #define map unordered_map #define set unordered_set using namespace std; int main(int argc, char **argv) { int rowC; while (cin >> rowC) { string row; map found; map x; map y; char t[rowC][rowC]; for (int i=0; i> row; for (string::size_type j = 0; j < row.length(); ++j) { t[i][j] = row[j]; if (found.find(row[j]) == found.end()) { y[row[j]] = i+1; x[row[j]] = j+1; found[row[j]] = 1; } else { ++ found[row[j]]; } } } char best = -1; char more = -1; int rx = -1,ry=-1; for (auto bf = found.begin(); bf != found.end(); ++bf) { //printf("%c %d\n", bf->first, bf->second); if (bf->second == rowC-1) { best = bf->first; }else if (bf->second == rowC+1) { more = bf->first; } else if (bf->second == 1) { rx = x[bf->first]; ry = y[bf->first]; } } if (more < 0) { printf("%d %d %c\n", ry, rx, best); continue; } for (int i = 0; i < rowC; ++i) { for (int j=0 ; j< rowC; ++j) { if (t[i][j] != more) continue; int cnt = 0; for (int k = 0; k < rowC ; ++k) { if (t[i][k] == more) ++cnt; } for (int k = 0; k < rowC ; ++k) { if (t[k][j] == more) ++cnt; } if (cnt == 4) { rx = j+1; ry = i+1; } } } printf("%d %d %c\n", ry, rx, best); } return 0; }