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;
const int NMax = 1700;
const long long INF = 1000000007LL;
int N, M, ID[NMax][NMax], ID1[NMax][NMax];
int A[NMax][NMax];
int F[NMax][NMax];
pair<int, int> Max[100], Min[100], Max1[100], Min1[100];
bool check(int first, int second) {
  return first > 0 && first <= N && second > 0 && second <= M &&
         A[first][second] && !ID[first][second];
}
void DFS(int a, int b, int c) {
  ID[a][b] = c;
  Max[c].first = max(Max[c].first, a);
  Max[c].second = max(Max[c].second, b);
  Min[c].first = min(Min[c].first, a);
  Min[c].second = min(Min[c].second, b);
  if (check(a - 1, b)) DFS(a - 1, b, c);
  if (check(a + 1, b)) DFS(a + 1, b, c);
  if (check(a, b - 1)) DFS(a, b - 1, c);
  if (check(a, b + 1)) DFS(a, b + 1, c);
}
bool check1(int first, int second, int z) {
  return first > 0 && first <= N && second > 0 && second <= M &&
         ID1[first][second] == z && !F[first][second];
}
int size[100];
void DFS(int a, int b, int c, int d) {
  F[a][b] = c;
  size[c]++;
  if (check1(a - 1, b, d)) DFS(a - 1, b, c, d);
  if (check1(a + 1, b, d)) DFS(a + 1, b, c, d);
  if (check1(a, b - 1, d)) DFS(a, b - 1, c, d);
  if (check1(a, b + 1, d)) DFS(a, b + 1, c, d);
}
bool check(int a, int b, int c) {
  return a > 0 && a <= N && b > 0 && b <= M && ID[a][b] == c;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) scanf("%d", &A[i][j]);
  int nn = 0;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      if (A[i][j] && !ID[i][j]) {
        Max[++nn] = make_pair(-1, -1);
        Min[nn] = make_pair(2000, 2000);
        DFS(i, j, nn);
      }
  for (int i = 1; i <= nn; i++) {
    Max1[i] = make_pair(-1, -1);
    Min1[i] = make_pair(2000, 2000);
    for (int j = Min[i].first; j <= Max[i].first; j++) {
      for (int k = Min[i].second; k <= Max[i].second; k++)
        if (ID[j][k] == i) {
          int t1 = j, t2 = k;
          while (check(t1 - 1, k, i)) t1--;
          int start = t1;
          t1 = j;
          while (check(t1 + 1, k, i)) t1++;
          int last = t1;
          int X = last - start + 1;
          while (check(j, t2 - 1, i)) t2--;
          start = t2;
          t2 = k;
          while (check(j, t2 + 1, i)) t2++;
          last = t2;
          int Y = last - start + 1;
          if ((X < 7 || Y < 7)) {
            ID1[j][k] = i;
            Max1[i].first = max(Max1[i].first, j);
            Min1[i].first = min(Min1[i].first, j);
            Max1[i].second = max(Max1[i].second, k);
            Min1[i].second = min(Min1[i].second, k);
          }
        }
    }
  }
  printf("%d\n", nn);
  int Q[100], long long = 0;
  for (int i = 1; i <= nn; i++) {
    int cc = 0;
    for (int j = Min1[i].first; j <= Max1[i].first; j++)
      for (int k = Min1[i].second; k <= Max1[i].second; k++)
        if (!F[j][k] && ID1[j][k] == i) {
          size[++cc] = 0;
          DFS(j, k, cc, i);
        }
    int ret = cc;
    for (int c = 1; c <= cc; c++) {
      if (size[c] < 13) {
        ret--;
        continue;
      }
    }
    Q[long long ++] = ret;
  }
  sort(Q, Q + long long);
  for (int i = 0; i < long long; i++) printf("%d ", Q[i]);
  puts("");
  return 0;
}