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;
#pragma comment(linker, "/STACK:64000000")
int w, h, g[8][2] = {{1, 0}, {-1, 0}, {0, 1},  {0, -1},
                     {1, 1}, {1, -1}, {-1, 1}, {-1, -1}},
          ans_sun, num;
queue<pair<int, int> > q;
vector<vector<int> > pic, mod_pic, temp_pic, used_pic, used_mod, used_ray;
vector<int> ray;
void modification(vector<vector<int> > &a, vector<vector<int> > &b,
                  int background) {
  for (int i = 0; i < w; i++)
    for (int j = 0; j < h; j++) b[i][j] = a[i][j];
  for (int i = 1; i <= w; i++)
    for (int j = 1; j <= h; j++)
      if (a[i][j] != background &&
          (a[i + 1][j] == background || a[i - 1][j] == background ||
           a[i][j + 1] == background || a[i][j - 1] == background))
        b[i][j] = background;
}
void way(int x, int y, int col, vector<vector<int> > &a,
         vector<vector<int> > &used, vector<vector<int> > &used_mod) {
  if (a[x][y] && !used[x][y] && !used_mod[x][y])
    q.push(make_pair(x, y)), used[x][y] = col;
}
void bfs(int x, int y, int col, vector<vector<int> > &a,
         vector<vector<int> > &used, vector<vector<int> > &used_mod) {
  used[x][y] = col;
  q.push(make_pair(x, y));
  while (!q.empty()) {
    pair<int, int> temp;
    int x, y;
    temp = q.front(), q.pop();
    x = temp.first, y = temp.second;
    for (int i = 0; i < 8; i++)
      way(x + g[i][0], y + g[i][1], col, a, used, used_mod);
  }
}
void mod() {
  modification(pic, mod_pic, 0);
  modification(mod_pic, temp_pic, 0);
  modification(temp_pic, mod_pic, 0);
  modification(mod_pic, temp_pic, 1);
  modification(temp_pic, mod_pic, 1);
  modification(temp_pic, mod_pic, 1);
  modification(mod_pic, temp_pic, 1);
  modification(temp_pic, mod_pic, 1);
  modification(mod_pic, temp_pic, 1);
}
int main() {
  scanf("%d %d\n", &w, &h);
  pic.resize(w + 10), mod_pic.resize(w + 10), temp_pic.resize(w + 10);
  used_pic.resize(w + 10), used_mod.resize(w + 10), used_ray.resize(w + 10);
  w += 2, h += 2;
  int col = 2;
  for (int i = 0; i < w + 3; i++) {
    pic[i].resize(h + 10), mod_pic[i].resize(h + 10),
        temp_pic[i].resize(h + 10);
    used_pic[i].resize(h + 10), used_mod[i].resize(h + 10),
        used_ray[i].resize(h + 10);
    if (i < 2 || i > w) continue;
    for (int j = 0; j < h; j++) {
      if (j < 2) continue;
      scanf("%d ", &pic[i][j]);
    }
  }
  for (int i = 0; i < w; i++)
    for (int j = 0; j < h; j++)
      if (pic[i][j] && !used_pic[i][j])
        bfs(i, j, ans_sun + 1, pic, used_pic, used_ray), ans_sun++;
  ray.resize(ans_sun);
  col = ans_sun + 1;
  mod();
  for (int i = 0; i < w; i++)
    for (int j = 0; j < h; j++)
      if (temp_pic[i][j] && !used_mod[i][j])
        bfs(i, j, col, temp_pic, used_mod, used_ray), col++;
  for (int i = 0; i < w; i++)
    for (int j = 0; j < h; j++)
      if (pic[i][j] && !used_mod[i][j] && !used_ray[i][j])
        bfs(i, j, col, pic, used_ray, used_mod), ray[used_pic[i][j] - 1]++;
  cout << ans_sun << '\n';
  sort(ray.begin(), ray.end());
  for (int i = 0; i < ray.size(); i++) cout << ray[i] << ' ';
  return 0;
}