#include #include #define N 1000 #define M 1000000 char c[N][N]; int p[N][N]; int w,h; int color; int smer[][2] = { {0,1},{1,0},{-1,0},{0,-1}}; int ret[N*N]; int stack[M]; int stn; int push(int k) {stack[stn]=k; stn++; return 0;} int pop() {stn--; return stack[stn];} int farbi(int a, int b) { int i,px,py,x,y; stn=0; push(a);push(b);push(0); while (stn) { i=pop();y=pop();x=pop(); if (i>=4) continue; p[x][y]=color; px=x+smer[i][0]; py=y+smer[i][1]; i++; push(x);push(y);push(i); if (px>=0 && px=0 && py=4) continue; p[x][y]=-abs(p[x][y]); px=x+smer[i][0]; py=y+smer[i][1]; i++; push(x);push(y);push(i); if (px>=0 && px=0 && py0 && c[px][py]=='X') { push(px);push(py);push(0); } } return 0; } int int_cmp(const void *va, const void *vb) { int *a = (int *)va; int *b = (int *)vb; if (*a > *b) return 1; if (*a == *b) return 0; return -1; } int main() { int i,j; while (1) { scanf("%d %d", &h, &w); if (w==0 && h==0) break; fgets(c[0], N, stdin); for ( i=0; i0) { ret[p[i][j]-1]++; xfarbi(i,j); } qsort(&ret, color-1, sizeof(int), int_cmp); printf("Throw:"); for ( i=0; i