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;
template <class _T>
inline _T sqr(const _T &x) {
  return x * x;
}
template <class _T>
inline string tostr(const _T &a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-11;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
int n, m;
int a[2024][2024];
bool u[2024][2024];
int u2[2024][2024];
bool u3[2024][2024];
int d[2024][2024];
int q[2024 * 2024][2];
int e[1024000];
void bfs(int x, int y, signed long long &sx, signed long long &sy, int &s) {
  int qb = 0, qe = 0;
  s = 1;
  sx = x;
  sy = y;
  u[x][y] = true;
  q[qe][0] = x;
  q[qe][1] = y;
  qe++;
  while (qb != qe) {
    x = q[qb][0];
    y = q[qb][1];
    qb++;
    for (int l = 0; l < (int)(4); l++) {
      int xn = x + dx[l];
      int yn = y + dy[l];
      if (xn < 0 || xn >= n || yn < 0 || yn >= m || !a[xn][yn] || u[xn][yn])
        continue;
      u[xn][yn] = true;
      q[qe][0] = xn;
      q[qe][1] = yn;
      sx += xn;
      sy += yn;
      s++;
      qe++;
    }
  }
}
int bfs2(int x, int y, int col) {
  int qb = 0, qe = 0;
  u2[x][y] = col;
  d[x][y] = 0;
  q[qe][0] = x;
  q[qe][1] = y;
  qe++;
  while (qb != qe) {
    x = q[qb][0];
    y = q[qb][1];
    qb++;
    for (int l = 0; l < (int)(4); l++) {
      int xn = x + dx[l];
      int yn = y + dy[l];
      if (xn < 0 || xn >= n || yn < 0 || yn >= m || !a[xn][yn] || u2[xn][yn])
        continue;
      d[xn][yn] = d[x][y] + 1;
      u2[xn][yn] = col;
      q[qe][0] = xn;
      q[qe][1] = yn;
      qe++;
    }
  }
  return qe;
}
int main() {
  cout << setiosflags(ios::fixed) << setprecision(10);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(m); j++) {
      scanf("%d", &a[i][j]);
    }
  }
  int cnt = 0;
  memset((u), 0, sizeof(u));
  memset((u2), 0, sizeof(u2));
  memset((u3), 0, sizeof(u3));
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(m); j++) {
      if (a[i][j] && !u[i][j]) {
        signed long long xs, ys;
        int s;
        bfs(i, j, xs, ys, s);
        int t = bfs2(xs / s, ys / s, cnt + 1);
        int z = 0;
        for (int k = 0; k < (int)(t); k++) {
          int x = q[k][0];
          int y = q[k][1];
          bool bb = false;
          for (int l = 0; l < (int)(4); l++) {
            int xn = x + dx[l];
            int yn = y + dy[l];
            if (xn < 0 || xn >= n || yn < 0 || yn >= m || !a[xn][yn]) continue;
            if (d[xn][yn] > d[x][y]) bb = true;
          }
          if (!u3[x][y] && bb) {
            int w = 0;
            for (int di = (-4); di <= (int)(4); di++) {
              for (int dj = (-4); dj <= (int)(4); dj++) {
                int xn = x + di;
                int yn = y + dj;
                if (xn < 0 || xn >= n || yn < 0 || yn >= m || !a[xn][yn] ||
                    u2[xn][yn] != cnt + 1)
                  continue;
                w++;
              }
            }
            if (w < 25) {
              z++;
              for (int di = (-4); di <= (int)(4); di++) {
                for (int dj = (-4); dj <= (int)(4); dj++) {
                  int xn = x + di;
                  int yn = y + dj;
                  if (xn < 0 || xn >= n || yn < 0 || yn >= m || !a[xn][yn] ||
                      u3[xn][yn])
                    continue;
                  u3[xn][yn] = true;
                }
              }
            }
          }
        }
        e[cnt] = z;
        cnt++;
      }
    }
  }
  printf("%d\n", cnt);
  sort(e, e + cnt);
  for (int i = 0; i < (int)(cnt); i++) {
    if (i) putchar(' ');
    printf("%d", e[i]);
  }
  puts("");
  return 0;
}