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 a[1700][1700];
int b[100][100];
int k;
vector<pair<int, int> > w;
vector<int> t;
vector<int> ans;
void dfs(int x, int y, int k) {
  if (a[x][y] != 1) {
    return;
  }
  a[x][y] = k;
  dfs(x + 1, y, k);
  dfs(x - 1, y, k);
  dfs(x, y + 1, k);
  dfs(x, y - 1, k);
}
void dfs2(int x, int y, int k, int r) {
  if (a[x][y] != k || r < 0) {
    return;
  }
  a[x][y] = -k;
  dfs2(x + 1, y, k, r - 1);
  dfs2(x - 1, y, k, r - 1);
  dfs2(x, y + 1, k, r - 1);
  dfs2(x, y - 1, k, r - 1);
}
void g(int i, int j) {
  if (a[i][j] < 0) {
    t[-a[i][j]] += -100000;
    return;
  }
  if (a[i][j] != 0) {
    t[a[i][j]]++;
  }
}
void u(int i, int j) {
  if (a[i][j] < 0) {
    t[-a[i][j]] -= -100000;
    return;
  }
  if (a[i][j] != 0) {
    t[a[i][j]]--;
  }
}
int test(int x, int y, int h) {
  int mx = 1;
  for (int i = 0; i < (int)t.size(); i++) {
    if (t[i] > t[mx]) {
      mx = i;
    }
  }
  int s = t[mx];
  if (s < h * h * 0.35) {
    return -1;
  }
  int l1 = 0, l2 = 0, l3 = 0, l4 = 0;
  for (int i = 0; i < h - 1; i++) {
    if (a[x + i][y] == mx) l1++;
    if (a[x][y + i] == mx) l4++;
    if (a[x + i][y + h - 1] == mx) l3++;
    if (a[x + h - 1][y + i] == mx) l2++;
  }
  int l = l1 + l2 + l3 + l4;
  vector<int> v;
  v.push_back(l1);
  v.push_back(l2);
  v.push_back(l3);
  v.push_back(l4);
  sort(v.begin(), v.end());
  int z = 0;
  l = 0;
  for (int i = 0; i < (int)w.size(); i++) {
    l += (a[x + w[i].first][y + w[i].second] == mx) ? 1 : 0;
    if (a[x + w[i].first][y + w[i].second] != mx) {
      if (i > 0) {
        if (a[x + w[i - 1].first][y + w[i - 1].second] == mx) {
          z++;
        }
      } else {
        if (a[x + w[w.size() - 1].first][y + w[w.size() - 1].second] == mx) {
          z++;
        }
      }
    }
  }
  if (z == 1 && l <= 8) {
    for (int i = x; i < x + h; i++) {
      for (int j = y; j < y + h; j++) {
        if (a[i][j] == mx) {
          dfs2(i, j, mx, 5);
        }
      }
    }
    return mx;
  }
  return -1;
}
void solve(int x1, int y1, int x2, int y2, int h) {
  for (int i = x1; i < x2; i++) {
    for (int j = y1; j < y2; j++) {
      if (j > y1) {
        for (int x = i; x < i + h; x++) {
          g(x, j + h - 1);
          u(x, j - 1);
        }
      } else {
        for (int q = 0; q < (int)t.size(); q++) {
          t[q] = 0;
        }
        for (int x = i; x < i + h; x++) {
          for (int y = j; y < j + h; y++) {
            g(x, y);
          }
        }
      }
      int x = test(i, j, h);
      if (x > 0) {
        ans[x - 2]++;
        for (int q = 0; q < (int)t.size(); q++) {
          t[q] = 0;
        }
        for (int x = i; x < i + h; x++) {
          for (int y = j; y < j + h; y++) {
            g(x, y);
          }
        }
      }
    }
  }
}
int main() {
  int n, m;
  memset(a, 0, sizeof(a));
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[5 + i][5 + j]);
    }
  }
  n += 15;
  m += 15;
  k = 0;
  vector<double> d1, d2, dn;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 1) {
        dfs(i, j, k + 2);
        k++;
        d1.push_back(i);
        d2.push_back(j);
        dn.push_back(1);
      } else {
        if (a[i][j] > 1) {
          d1[a[i][j] - 2] += i;
          d2[a[i][j] - 2] += j;
          dn[a[i][j] - 2]++;
        }
      }
    }
  }
  cout << k << endl;
  t.resize(k + 5);
  int h = 7;
  for (int i = 0; i < 0 + h - 1; i++) {
    w.push_back(make_pair(i, 0));
  }
  for (int i = 0; i < 0 + h - 1; i++) {
    w.push_back(make_pair(h - 1, i));
  }
  for (int i = 0 + h - 1; i > 0; i--) {
    w.push_back(make_pair(i, 0 + h - 1));
  }
  for (int i = 0 + h - 1; i > 0; i--) {
    w.push_back(make_pair(0, i));
  }
  ans.resize(k);
  for (int i = 0; i < k; i++) {
    int dx = (int)d1[i] / dn[i];
    int dy = (int)d2[i] / dn[i];
    int w = 150;
    int x1 = max(0, dx - w), x2 = min(n - h, dx + w - h);
    int y1 = max(0, dy - w), y2 = min(m - h, dy + w - h);
    solve(x1, y1, x2, y2, h);
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < k; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}