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 MAXN = 1700;
const int OFFSET = 50;
const int PADDING = 6;
const int MARGIN = 8;
const int MIN_SUN = 500;
const int MIN_RAY = 9;
bool ok1[OFFSET][OFFSET], ok2[OFFSET][OFFSET];
template <int DIS>
pair<int, pair<int, int> > floodfill(int x, int y, const int z,
                                     const char s[MAXN][MAXN],
                                     int tag[MAXN][MAXN]) {
  pair<int, pair<int, int> > ret;
  queue<pair<int, int> > q;
  tag[x][y] = z;
  q.push({x, y});
  while (!q.empty()) {
    tie(x, y) = q.front();
    q.pop();
    ++ret.first;
    ret.second.first += x;
    ret.second.second += y;
    for (int xx = x - DIS; xx <= x + DIS; ++xx) {
      for (int yy = y - DIS; yy <= y + DIS; ++yy) {
        if (s[xx][yy] == '1' && tag[xx][yy] == -1) {
          tag[xx][yy] = z;
          q.push({xx, yy});
        }
      }
    }
  }
  ret.second.first /= ret.first;
  ret.second.second /= ret.first;
  return ret;
}
char s1[MAXN][MAXN], s2[MAXN][MAXN];
int tag1[MAXN][MAXN], tag2[MAXN][MAXN];
int main() {
  int h, w;
  map<int, int> sun, ray;
  vector<pair<int, int> > center;
  for (int i = 0; i < (int)(OFFSET); ++i)
    for (int j = 0; j < (int)(OFFSET); ++j) {
      ok1[i][j] = i * i + j * j <= PADDING * PADDING;
      ok2[i][j] = i * i + j * j <= MARGIN * MARGIN;
    }
  memset(tag1, 0xff, sizeof(tag1));
  memset(tag2, 0xff, sizeof(tag2));
  scanf("%d%d", &h, &w);
  for (int i = 0; i < (int)(h); ++i) {
    for (int j = 0; j < (int)(w); ++j) {
      scanf(" %c", &s1[OFFSET + i][OFFSET + j]);
    }
  }
  for (int i = 0; i < (int)(h); ++i) {
    for (int j = 0; j < (int)(w); ++j) {
      if (s1[OFFSET + i][OFFSET + j] == '1' &&
          tag1[OFFSET + i][OFFSET + j] == -1) {
        int id = center.size();
        auto tmp = floodfill<1>(OFFSET + i, OFFSET + j, id, s1, tag1);
        sun[id] = tmp.first;
        center.push_back(tmp.second);
        if (sun[id] >= MIN_SUN) {
          ray[id];
        } else if (sun[id] > 1) {
          fprintf(stderr, "ignore (%d, %d) size = %d\n", i, j, tmp.first);
        }
      }
    }
  }
  for (int i = 0; i < (int)(h); ++i) {
    for (int j = 0; j < (int)(w); ++j) {
      s2[OFFSET + i][OFFSET + j] = '1';
      for (int xx = i - PADDING; xx <= i + PADDING; ++xx) {
        for (int yy = j - PADDING; yy <= j + PADDING; ++yy) {
          if (!ok1[abs(i - xx)][abs(j - yy)]) {
            continue;
          }
          if (s1[OFFSET + xx][OFFSET + yy] != '1') {
            s2[OFFSET + i][OFFSET + j] = '0';
            goto NEXT;
          }
        }
      }
    NEXT:
      continue;
    }
  }
  for (int i = 0; i < (int)center.size(); ++i) {
    if (sun[i] < MIN_SUN) {
      continue;
    }
    auto tmp = floodfill<1>(center[i].first, center[i].second, i, s2, tag2);
    fprintf(stderr, "sun[%d] (%d, %d) %d => %d\n", i, center[i].first,
            center[i].second, sun[i], tmp.first);
  }
  for (int i = 0; i < (int)(h); ++i) {
    for (int j = 0; j < (int)(w); ++j) {
      if (tag2[OFFSET + i][OFFSET + j] != -1) {
        for (int xx = i - MARGIN; xx <= i + MARGIN; ++xx) {
          for (int yy = j - MARGIN; yy <= j + MARGIN; ++yy) {
            if (!ok2[abs(i - xx)][abs(j - yy)]) {
              continue;
            }
            s1[OFFSET + xx][OFFSET + yy] = '0';
          }
        }
      }
    }
  }
  memset(tag2, 0xff, sizeof(tag2));
  for (int i = 0; i < (int)(h); ++i) {
    for (int j = 0; j < (int)(w); ++j) {
      if (s1[OFFSET + i][OFFSET + j] == '1' &&
          tag1[OFFSET + i][OFFSET + j] != -1 &&
          tag2[OFFSET + i][OFFSET + j] == -1) {
        auto tmp = floodfill<1>(OFFSET + i, OFFSET + j, 0, s1, tag2);
        if (tmp.first >= MIN_RAY) {
          fprintf(stderr, "ray[%d] (%d, %d) => %d\n",
                  tag1[OFFSET + i][OFFSET + j], i, j, tmp.first);
          ++ray[tag1[OFFSET + i][OFFSET + j]];
        } else if (tmp.first > 1) {
          fprintf(stderr, "IGNORE_RAY[%d] (%d, %d) => %d\n",
                  tag1[OFFSET + i][OFFSET + j], i, j, tmp.first);
        }
      }
    }
  }
  vector<int> ans;
  for (auto i : ray) {
    ans.push_back(i.second);
  }
  sort(ans.begin(), ans.end());
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)ans.size(); ++i) {
    if (i > 0) {
      putchar(' ');
    }
    printf("%d", ans[i]);
  }
  puts("");
  return 0;
}