import java.util.Scanner; public class prog { public static void main(String[] args) throws java.lang.Exception { Scanner scanner = new Scanner(System.in); Integer type = Integer.parseInt(scanner.nextLine()); String[] data = scanner.nextLine().split(" "); Integer m = Integer.parseInt(data[0]); Integer n = Integer.parseInt(data[1]); char[][] matrix = new char[m][n]; UF uf = new UF(n * m); for (int i = 0; i < m; i++) { String cells = scanner.nextLine(); for (int j = 0; j < cells.length(); j++) { matrix[i][j] = cells.charAt(j); } } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (i > 0) { if (matrix[i][j] == matrix[i - 1][j]) { if (!uf.connected(i * m + j, (i - 1) * m + j)) { uf.union(i * m + j, (i - 1) * m + j); } } } if (j > 0) { if (matrix[i][j] == matrix[i][j - 1]) { if (!uf.connected(i * m + j, i * m + j - 1)) { uf.union(i * m + j, i * m + j - 1); } } } if (i < m - 1) { if (matrix[i][j] == matrix[i + 1][j]) { if (!uf.connected(i * m + j, (i + 1) * m + j)) { uf.union(i * m + j, (i + 1) * m + j); } } } if (j < n - 1) { if (matrix[i][j] == matrix[i][j + 1]) { if (!uf.connected(i * m + j, i * m + j + 1)) { uf.union(i * m + j, i * m + j + 1); } } } } } if (type == 1) { System.out.println(uf.getMaxSize()); } else { int x = 0; int y = 0; char ch = 'a'; int maxSize = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { int[] sizes = new int[26]; if (i > 0) { if (!uf.connected(i * m + j, (i - 1) * m + j)) { char c = matrix[i - 1][j]; sizes[c - 'a'] += uf.getSize(uf.find((i - 1) * m + j)); } } if (j > 0) { if (!uf.connected(i * m + j, i * m + j - 1)) { char c = matrix[i][j - 1]; sizes[c - 'a'] += uf.getSize(uf.find(i * m + j - 1)); } } if (i < m - 1) { if (!uf.connected(i * m + j, (i + 1) * m + j)) { char c = matrix[i + 1][j]; sizes[c - 'a'] += uf.getSize(uf.find((i + 1) * m + j)); } } if (j < n - 1) { if (!uf.connected(i * m + j, i * m + j + 1)) { char c = matrix[i][j + 1]; sizes[c - 'a'] += uf.getSize(uf.find(i * m + j + 1)); } } for (int k = 0; k < sizes.length; k++) { int newSize = uf.getSize(uf.find(i * m + j)) + sizes[k]; if (maxSize < newSize) { maxSize = newSize; x = i + 1; y = j + 1; ch = (char) (k + 'a'); } } } } System.out.println(x + " " + y); System.out.println(ch); } scanner.close(); } static class UF { private int[] id; private byte[] rank; private int[] size; private int maxSize; private int count; public UF(int N) { if (N < 0) throw new IllegalArgumentException(); count = N; id = new int[N]; size = new int[N]; rank = new byte[N]; maxSize = 1; for (int i = 0; i < N; i++) { id[i] = i; size[i] = 1; rank[i] = 0; } } public int find(int p) { if (p < 0 || p >= id.length) throw new IndexOutOfBoundsException(); while (p != id[p]) { id[p] = id[id[p]]; p = id[p]; } return p; } public int count() { return count; } public boolean connected(int p, int q) { return find(p) == find(q); } public int getMaxSize() { return maxSize; } public int getSize(int p) { return size[p]; } public void union(int p, int q) { int i = find(p); int j = find(q); if (i == j){ return; } if (rank[i] < rank[j]) { id[i] = j; size[j] += size[i]; } else if (rank[i] > rank[j]) { id[j] = i; size[i] += size[j]; } else { id[j] = i; size[j] += size[i]; rank[i]++; } maxSize = Math.max(maxSize, size[i]); count--; } } }