Solutions to this problem: http://codeforces.com/contest/1028/problem/A Solution in C #include #include int main() { int n,m; scanf("%d%d",&n,&m); char **table = (char **)malloc(sizeof(char*)*(n)); for(int i=0;i using namespace std; int X,Y,n,m,cnt;char s[1005]; int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) { scanf("%s",s+1); for (int j=1;j<=m;j++) if (s[j]=='B') cnt++,X+=i,Y+=j; } X/=cnt;Y/=cnt; printf("%d %d\n",X,Y); return 0; } ------------------------------------------------------------ Solution in Java 8 import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Scanner; import java.util.TreeMap; import java.util.TreeSet; public class JavaClass { public static void main(String[] args){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int m=s.nextInt(); String[] arr=new String[n]; for(int j=0;j x) let read_string _ = bscanf Scanning.stdib " %s " (fun x -> x) let () = let n = read_int () in let m = read_int () in let board = Array.init n read_string in let next (i,j) = if j