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 MAXH = 1700;
const int MAXW = 1700;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int f[MAXH][MAXW];
int h, w;
bool check_circ(int x0, int y0, int maxr) {
  int rs = sqrt(maxr) + 5;
  while (rs * rs > maxr) rs--;
  for (int dy = -rs; dy <= rs; dy++)
    for (int dx = -rs; dx <= rs; dx++)
      if (dx * dx + dy * dy <= maxr) {
        int x = x0 + dx, y = y0 + dy;
        if (x < 0 || y < 0 || x >= w || y >= h) return false;
        if (!f[y][x]) return false;
      }
  return true;
}
int was[MAXH][MAXW];
const int C = 5;
int sumx, sumy, sumc;
vector<pair<int, int> > pts;
void dfs(int x, int y) {
  if (x < 0 || y < 0 || x >= w || y >= h) return;
  if (was[y][x]) return;
  if (!f[y][x]) return;
  bool g = true;
  for (int y1 = -C; y1 <= C; y1++)
    for (int x1 = -C; x1 <= C; x1++) {
      int nx = x + x1, ny = y + y1;
      if (nx < 0 || ny < 0 || nx >= w || ny >= h)
        g = false;
      else
        g = g && f[ny][nx];
    }
  if (g) {
    sumx += x;
    sumy += y;
    sumc++;
  } else {
    pts.push_back(make_pair(x, y));
  }
  was[y][x] = true;
  for (int i = 0; i < 4; i++) dfs(x + dx[i], y + dy[i]);
}
double radius;
void dfs2(int x, int y) {
  if (x < 0 || y < 0 || x >= w || y >= h) return;
  if (was[y][x] >= 2) return;
  if (!f[y][x]) return;
  int curd = (x - sumx) * (x - sumx) + (y - sumy) * (y - sumy);
  if (sqrt(curd) <= radius + 5) return;
  was[y][x] = 2;
  for (int i = 0; i < 4; i++) dfs2(x + dx[i], y + dy[i]);
}
int main() {
  while (scanf("%d%d", &h, &w) >= 1) {
    for (int y = 0; y < h; y++)
      for (int x = 0; x < w; x++) scanf("%d", &f[y][x]);
    vector<int> anses;
    memset(was, 0, sizeof was);
    for (int y = 0; y < h; y++)
      for (int x = 0; x < w; x++)
        if (f[y][x] && !was[y][x]) {
          sumx = 0;
          sumy = 0;
          sumc = 0;
          pts.clear();
          dfs(x, y);
          assert(sumc);
          sumx /= sumc;
          sumy /= sumc;
          f[sumy][sumx] = 2;
          int L = 0, R = min(w, h) * min(w, h) + 100;
          while (L + 1 < R) {
            int M = (L + R) / 2;
            if (check_circ(sumx, sumy, M))
              L = M;
            else
              R = M;
          }
          radius = sqrt(L);
          int cans = 0;
          for (int i = 0; i < ((int)(pts).size()); i++) {
            int x = pts[i].first, y = pts[i].second;
            int cd = (x - sumx) * (x - sumx) + (y - sumy) * (y - sumy);
            if (sqrt(cd) <= radius + 6) continue;
            f[y][x] = 3;
            if (was[y][x] >= 2) continue;
            cans++;
            dfs2(x, y);
          }
          anses.push_back(cans);
        }
    sort(anses.begin(), anses.end());
    printf("%d\n", ((int)(anses).size()));
    for (int i = 0; i < ((int)(anses).size()); i++)
      printf("%d%c", anses[i], "\n "[i + 1 < ((int)(anses).size())]);
  }
  return 0;
}