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>
void splitstr(const string &s, vector<T> &out) {
  istringstream in(s);
  out.clear();
  copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
static void redirect(int argc, const char **argv) {
  if (argc > 1) {
    static filebuf f;
    f.open(argv[1], ios::in);
    cin.rdbuf(&f);
    if (!cin) {
      cerr << "Failed to open '" << argv[1] << "'" << endl;
      exit(1);
    }
  }
  if (argc > 2) {
    static filebuf f;
    f.open(argv[2], ios::out | ios::trunc);
    cout.rdbuf(&f);
    if (!cout) {
      cerr << "Failed to open '" << argv[2] << "'" << endl;
    }
  }
}
static const int dr[4] = {-1, 0, 1, 0};
static const int dc[4] = {0, -1, 0, 1};
static void dfs(vector<vector<bool> > &img, int r, int c,
                vector<pair<int, int> > &coords) {
  coords.push_back(pair<int, int>(r, c));
  img[r][c] = false;
  for (int d = 0; d < 4; d++) {
    int r2 = r + dr[d];
    int c2 = c + dc[d];
    if (r2 >= 0 && r2 < ((int)(img).size()) && c2 >= 0 &&
        c2 < ((int)(img[0]).size()) && img[r2][c2])
      dfs(img, r2, c2, coords);
  }
}
static void dilate(vector<vector<bool> > &img, bool fg) {
  int R = ((int)(img).size());
  int C = ((int)(img[0]).size());
  vector<vector<bool> > out = img;
  for (int i = 0; i < R; i++)
    for (int j = 0; j < C; j++)
      if (img[i][j] == fg)
        for (int d = 0; d < 4; d++) {
          int r2 = i + dr[d];
          int c2 = j + dc[d];
          if (r2 >= 0 && r2 < R && c2 >= 0 && c2 < C) out[r2][c2] = fg;
        }
  img.swap(out);
}
int main(int argc, const char **argv) {
  redirect(argc, argv);
  int R, C;
  cin >> R >> C;
  vector<vector<bool> > img(R, vector<bool>(C));
  for (int i = 0; i < R; i++)
    for (int j = 0; j < C; j++) {
      int v;
      cin >> v;
      img[i][j] = v == 1;
    }
  vector<int> rays;
  for (int i = 0; i < R; i++)
    for (int j = 0; j < C; j++) {
      if (img[i][j]) {
        vector<pair<int, int> > coords;
        dfs(img, i, j, coords);
        int rmin = INT_MAX, rmax = INT_MIN, cmin = INT_MAX, cmax = INT_MIN;
        for (int k = 0; k < ((int)(coords).size()); k++) {
          rmin = min(rmin, coords[k].first);
          rmax = max(rmax, coords[k].first);
          cmin = min(cmin, coords[k].second);
          cmax = max(cmax, coords[k].second);
        }
        rmin -= 5;
        rmax += 5;
        cmin -= 5;
        cmax += 5;
        int sR = rmax - rmin + 1;
        int sC = cmax - cmin + 1;
        vector<vector<bool> > sun(sR, vector<bool>(sC));
        for (int k = 0; k < ((int)(coords).size()); k++)
          sun[coords[k].first - rmin][coords[k].second - cmin] = true;
        vector<vector<bool> > middle = sun;
        for (int k = 0; k < 3; k++) dilate(middle, false);
        for (int k = 0; k < 6; k++) dilate(middle, true);
        for (int r = 0; r < sR; r++)
          for (int c = 0; c < sC; c++) sun[r][c] = sun[r][c] && !middle[r][c];
        dilate(sun, false);
        dilate(sun, true);
        int nrays = 0;
        for (int r = 0; r < sR; r++)
          for (int c = 0; c < sC; c++)
            if (sun[r][c]) {
              vector<pair<int, int> > dummy;
              dfs(sun, r, c, dummy);
              nrays++;
            }
        rays.push_back(nrays);
      }
    }
  sort((rays).begin(), (rays).end());
  cout << rays.size() << '\n';
  for (int i = 0; i < ((int)(rays).size()); i++) {
    if (i) cout << ' ';
    cout << rays[i];
  }
  cout << '\n';
  return 0;
}