if (T == 1) { cout << ans1; ENTER } else { int ans2 = 0; pair pr = {0, 0}; char col = farm[0][0]; int best[26]; for (i = 0; i < N; ++i) { for (j = 0; j < M; ++j) { memset(best, 0, sizeof(best)); for (k = 0; k < 4; ++k) { x = i + dx[k]; y = j + dy[k]; if (0 <= x && x < N && 0 <= y && y < M) { if (visited[parent[x][y]] == 0) { visited[parent[x][y]] = 1; best[farm[x][y] - 'a'] += values[x][y]; } } } visited.reset(); for (k = 0; k < 26; ++k) { if (ans2 < best[k] + 1) { ans2 = best[k] + 1; pr = {i, j}; col = (char) k + 'a'; } } } } cout << pr.first + 1 << ' ' << pr.second + 1; ENTER cout << col; ENTER } return 0; }