Problem: Smart Beaver became interested in drawing. He draws suns. However, at some point, Smart Beaver realized that simply drawing suns is boring. So he decided to design a program that will process his drawings. You are given a picture drawn by the beaver. It will have two colors: one for the background and one for the suns in the image. Your task will be to count the number of suns in the image and for each of them to count the number of rays.

Sun is arbitrarily rotated ellipse with rays. Ray is a segment which connects point on boundary of the ellipse with some point outside ellipse.

<image> An image where all suns are circles.  <image> An image where all suns are ellipses, their axes are parallel to the coordinate axes.  <image> An image where all suns are rotated ellipses. 

It is guaranteed that: 

  * No two suns have common points. 
  * The rays’ width is 3 pixels. 
  * The lengths of the ellipsis suns’ axes will lie between 40 and 200 pixels. 
  * No two rays intersect. 
  * The lengths of all rays will lie between 10 and 30 pixels. 

Input

The first line contains two integers h and w — the height and width of the image (1 ≤ h, w ≤ 1600). Next h lines will contain w space-separated integers each. They describe Smart Beaver’s picture. Each number equals either a 0 (the image background), or a 1 (the sun color).

The input limits for scoring 30 points are (subproblem F1): 

  * All suns on the image are circles. 



The input limits for scoring 70 points are (subproblems F1+F2): 

  * All suns on the image are ellipses with axes parallel to the coordinate axes. 



The input limits for scoring 100 points are (subproblems F1+F2+F3):

  * All suns on the image are ellipses, they can be arbitrarily rotated. 

Output

The first line must contain a single number k — the number of suns on the beaver’s image. The second line must contain exactly k space-separated integers, corresponding to the number of rays on each sun. The numbers of the second line must be sorted in the increasing order.

Examples

Note

For each complexity level you are suggested a sample in the initial data. You can download the samples at http://www.abbyy.ru/sun.zip.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int D[1605][1605], N, M;
int A[1605][1605], RayPart[1605][1605], LoopPart[1605][1605];
int Zraka[1000];
void ucitaj() {
  int i, j;
  scanf("%d%d", &N, &M);
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= M; j++) scanf("%d", A[i] + j);
  }
}
int Qx[2560005], Qy[2560005], qs, qe, suns;
void obidji0(int x, int y) {
  if (x < 1 || x > N || y < 1 || y > M) return;
  if (D[x][y] != 0) return;
  if (A[x][y] == 0) return;
  qe++;
  Qx[qe] = x;
  Qy[qe] = y;
  D[x][y] = suns;
}
void bfs0(int x, int y) {
  suns++;
  qs = 1;
  qe = 1;
  Qx[1] = x;
  Qy[1] = y;
  D[x][y] = suns;
  while (qs <= qe) {
    x = Qx[qs];
    y = Qy[qs];
    qs++;
    obidji0(x + 1, y);
    obidji0(x - 1, y);
    obidji0(x, y + 1);
    obidji0(x, y - 1);
  }
}
void find_suns() {
  int x, y;
  for (x = 1; x <= N; x++) {
    for (y = 1; y <= M; y++) {
      if (D[x][y] == 0 && A[x][y] == 1) bfs0(x, y);
    }
  }
}
inline int sun_index(int x, int y) {
  if (x < 1 || x > N || y < 1 || y > M) return 0;
  return D[x][y];
}
void find_rays() {
  int x, y, dx, dy;
  bool found;
  for (x = 1; x <= N; x++) {
    for (y = 1; y <= M; y++) {
      if (D[x][y] != 0) {
        found = false;
        for (dy = -3; dy <= 3; dy++) {
          for (dx = abs(dy) - 3; dx <= 3 - abs(dy); dx++) {
            if (sun_index(x + dx, y + dy) == 0) {
              found = true;
              goto fuck;
            }
          }
        }
      fuck:
        if (found) RayPart[x][y] = D[x][y];
      }
    }
  }
}
int pknz(int x, int y) {
  if (x < 1 || x > N || y < 1 || y > M) return 0;
  if (RayPart[x][y] != 0) return 0;
  return D[x][y];
}
void find_loops() {
  int x, y, dx, dy;
  int found5;
  bool found4;
  for (x = 1; x <= N; x++) {
    for (y = 1; y <= M; y++) {
      found4 = false;
      for (dx = -5; dx <= 5; dx++) {
        if (pknz(x + dx, y + 5 - abs(dx)) != 0 ||
            pknz(x + dx, y - (5 - abs(dx))) != 0) {
          found4 = true;
          break;
        }
      }
      if (found4) continue;
      found5 = 0;
      for (dx = -6; dx <= 6; dx++) {
        found5 = pknz(x + dx, y + 6 - abs(dx));
        if (found5 != 0) break;
        found5 = pknz(x + dx, y - (6 - abs(dx)));
        if (found5 != 0) break;
      }
      if (found5 != 0) {
        LoopPart[x][y] = found5;
      }
    }
  }
}
void traverse_loops() {
  int x, y, xc, yc, pres, i, j, sunac, len;
  for (x = 1; x <= N; x++) {
    for (y = 1; y <= M; y++) {
      if (LoopPart[x][y] != 0 && RayPart[x][y] == 0) {
        xc = x;
        yc = y;
        sunac = LoopPart[x][y];
        pres = 0;
        len = 0;
        while (true) {
          len++;
          LoopPart[xc][yc] = 0;
          j = RayPart[xc][yc];
          if (LoopPart[xc + 1][yc] == sunac) {
            xc = xc + 1;
            yc = yc;
            goto zajedno;
          };
          if (LoopPart[xc - 1][yc] == sunac) {
            xc = xc - 1;
            yc = yc;
            goto zajedno;
          };
          if (LoopPart[xc][yc + 1] == sunac) {
            xc = xc;
            yc = yc + 1;
            goto zajedno;
          };
          if (LoopPart[xc][yc - 1] == sunac) {
            xc = xc;
            yc = yc - 1;
            goto zajedno;
          };
          if (LoopPart[xc + 1][yc + 1] == sunac) {
            xc = xc + 1;
            yc = yc + 1;
            goto zajedno;
          };
          if (LoopPart[xc - 1][yc + 1] == sunac) {
            xc = xc - 1;
            yc = yc + 1;
            goto zajedno;
          };
          if (LoopPart[xc + 1][yc - 1] == sunac) {
            xc = xc + 1;
            yc = yc - 1;
            goto zajedno;
          };
          if (LoopPart[xc - 1][yc - 1] == sunac) {
            xc = xc - 1;
            yc = yc - 1;
            goto zajedno;
          };
          if (LoopPart[xc + 2][yc] == sunac) {
            xc = xc + 2;
            yc = yc;
            goto zajedno;
          };
          if (LoopPart[xc - 2][yc] == sunac) {
            xc = xc - 2;
            yc = yc;
            goto zajedno;
          };
          if (LoopPart[xc][yc + 2] == sunac) {
            xc = xc;
            yc = yc + 2;
            goto zajedno;
          };
          if (LoopPart[xc][yc - 2] == sunac) {
            xc = xc;
            yc = yc - 2;
            goto zajedno;
          };
          if (LoopPart[xc + 2][yc + 1] == sunac) {
            xc = xc + 2;
            yc = yc + 1;
            goto zajedno;
          };
          if (LoopPart[xc - 2][yc + 1] == sunac) {
            xc = xc - 2;
            yc = yc + 1;
            goto zajedno;
          };
          if (LoopPart[xc + 2][yc - 1] == sunac) {
            xc = xc + 2;
            yc = yc - 1;
            goto zajedno;
          };
          if (LoopPart[xc - 2][yc - 1] == sunac) {
            xc = xc - 2;
            yc = yc - 1;
            goto zajedno;
          };
          if (LoopPart[xc + 1][yc + 2] == sunac) {
            xc = xc + 1;
            yc = yc + 2;
            goto zajedno;
          };
          if (LoopPart[xc - 1][yc + 2] == sunac) {
            xc = xc - 1;
            yc = yc + 2;
            goto zajedno;
          };
          if (LoopPart[xc + 1][yc - 2] == sunac) {
            xc = xc + 1;
            yc = yc - 2;
            goto zajedno;
          };
          if (LoopPart[xc - 1][yc - 2] == sunac) {
            xc = xc - 1;
            yc = yc - 2;
            goto zajedno;
          };
          if (LoopPart[xc + 2][yc + 2] == sunac) {
            xc = xc + 2;
            yc = yc + 2;
            goto zajedno;
          };
          if (LoopPart[xc - 2][yc + 2] == sunac) {
            xc = xc - 2;
            yc = yc + 2;
            goto zajedno;
          };
          if (LoopPart[xc + 2][yc - 2] == sunac) {
            xc = xc + 2;
            yc = yc - 2;
            goto zajedno;
          };
          if (LoopPart[xc - 2][yc - 2] == sunac) {
            xc = xc - 2;
            yc = yc - 2;
            goto zajedno;
          };
          break;
        zajedno:
          if (RayPart[xc][yc] == sunac && j == 0) pres++;
        }
        if (len > 20) Zraka[sunac] = pres;
      }
    }
  }
}
void printem() {
  sort(Zraka + 1, Zraka + suns + 1);
  printf("%d\n", suns);
  for (int i = 1; i <= suns; i++)
    printf("%d%c", Zraka[i], i == suns ? '\n' : ' ');
}
int main() {
  ucitaj();
  find_suns();
  find_rays();
  find_loops();
  traverse_loops();
  printem();
  return 0;
}