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 n, m;
bool a[1610][1610], b[1610][1610];
int v[1610][1610], tg = 0, d[1610][1610], qx[1610 * 1610], qy[1610 * 1610],
                   A[1610 * 1610], L, w[1610][1610];
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int ff(int sx, int sy, int sd) {
  int le = 0, ri = 1;
  qx[0] = sx, qy[0] = sy, d[sx][sy] = 0, v[sx][sy] = tg;
  while (le < ri) {
    int x = qx[le], y = qy[le];
    le++;
    if (d[x][y] == sd) break;
    for (int i = 0; i < 4; i++) {
      int x1 = x + dx[i], y1 = y + dy[i];
      if (x1 < 0 || x1 >= n || y1 < 0 || y1 >= m) continue;
      if (!a[x1][y1]) continue;
      if (v[x1][y1] != tg)
        v[x1][y1] = tg, qx[ri] = x1, qy[ri] = y1, ri++, d[x1][y1] = d[x][y] + 1;
    }
  }
  return ri;
}
int gg(int sx, int sy) {
  int le = 0, ri = 1;
  qx[0] = sx, qy[0] = sy, w[sx][sy] = tg;
  while (le < ri) {
    int x = qx[le], y = qy[le];
    le++;
    for (int i = 0; i < 4; i++) {
      int x1 = x + dx[i], y1 = y + dy[i];
      if (x1 < 0 || x1 >= n || y1 < 0 || y1 >= m) continue;
      if (!b[x1][y1]) continue;
      if (w[x1][y1] != tg)
        w[x1][y1] = tg, qx[ri] = x1, qy[ri] = y1, ri++, d[x1][y1] = d[x][y] + 1;
    }
  }
  return ri;
}
set<int> W;
int hh(int sx, int sy) {
  int le = 0, ri = 1;
  qx[0] = sx, qy[0] = sy, d[sx][sy] = 0, v[sx][sy] = tg;
  int s = 0;
  while (le < ri) {
    int x = qx[le], y = qy[le];
    le++;
    if (w[x][y] && W.find(w[x][y]) == W.end()) W.insert(w[x][y]), s++;
    for (int i = 0; i < 4; i++) {
      int x1 = x + dx[i], y1 = y + dy[i];
      if (x1 < 0 || x1 >= n || y1 < 0 || y1 >= m) continue;
      if (!a[x1][y1]) continue;
      if (v[x1][y1] != tg)
        v[x1][y1] = tg, qx[ri] = x1, qy[ri] = y1, ri++, d[x1][y1] = d[x][y] + 1;
    }
  }
  return s;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int x;
      scanf("%d", &x);
      a[i][j] = x;
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j]) {
        tg++;
        if (ff(i, j, 5) <= 20) b[i][j] = 1;
      }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (b[i][j]) tg++, gg(i, j);
  tg++;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] && v[i][j] != tg) A[L++] = hh(i, j);
  sort(A, A + L);
  printf("%d\n", L);
  for (int i = 0; i < L; i++) printf("%d%c", A[i], i == L - 1 ? '\n' : ' ');
  return 0;
}