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>
T inline Abs(const T& x) {
  return x < 0 ? -x : x;
}
template <class T>
T inline Sqr(const T& x) {
  return x * x;
}
const int dx[4] = {0, 0, -1, +1};
const int dy[4] = {-1, +1, 0, 0};
const int maxn = 1610;
int a[maxn][maxn];
int s[maxn][maxn];
int c[maxn][maxn];
int b[maxn][maxn];
int color = 0;
vector<vector<pair<int, int> > > comps;
vector<int> ans;
int h, w;
void Dfs(int y, int x) {
  c[y][x] = color;
  comps[color].push_back(make_pair(y, x));
  for (int i = 0; i < 4; ++i) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (ny >= 1 && ny <= h && nx >= 1 && nx <= w && c[ny][nx] == 0 &&
        a[ny][nx] == 1) {
      Dfs(ny, nx);
    }
  }
}
int cc;
void Dfs2(int y, int x) {
  ++cc;
  b[y][x] = 1;
  for (int i = 0; i < 4; ++i) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (ny >= 1 && ny <= h && nx >= 1 && nx <= w && c[ny][nx] == color &&
        !b[ny][nx]) {
      Dfs2(ny, nx);
    }
  }
}
int GetSum(int Yy1, int Xx1, int y2, int x2) {
  --Yy1;
  --Xx1;
  return s[y2][x2] - s[Yy1][x2] - s[y2][Xx1] + s[Yy1][Xx1];
}
int main(int argc, char* argv[]) {
  cin >> h >> w;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      scanf("%d", &a[i][j]);
      s[i][j] = a[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (c[i][j] == 0 && a[i][j] > 0) {
        ++color;
        comps.resize(color + 1);
        Dfs(i, j);
      }
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      bool in = false;
      in = in || i >= 4 && j >= 4 && GetSum(i - 3, j - 3, i, j) == 16;
      in = in || i >= 4 && j + 3 <= w && GetSum(i - 3, j, i, j + 3) == 16;
      in = in || i + 3 <= h && j >= 4 && GetSum(i, j - 3, i + 3, j) == 16;
      in = in || i + 3 <= h && j + 3 <= w && GetSum(i, j, i + 3, j + 3) == 16;
      if (in) {
        c[i][j] = -1;
      }
    }
  }
  ans.resize(comps.size());
  memset(b, 0, sizeof(b));
  for (int i = 1; i < comps.size(); ++i) {
    color = i;
    for (int j = 0; j < comps[i].size(); ++j) {
      int y = comps[i][j].first;
      int x = comps[i][j].second;
      if (c[y][x] == i && !b[y][x]) {
        cc = 0;
        Dfs2(y, x);
        if (cc >= 20) {
          ++ans[i];
        }
      }
    }
  }
  ans.erase(ans.begin(), ans.begin() + 1);
  sort(ans.begin(), ans.end());
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); ++i) {
    printf("%d ", ans[i]);
  }
  cout << endl;
  return 0;
}