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;
char a[1600][1600];
char b[1600][1600];
int n, m;
int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
inline bool ok(int first, int second) {
  return first >= 0 && first < n && second >= 0 && second < m;
}
bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.first < b.first || a.first == b.first && a.second < b.second;
}
bool cw(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
  return a.first * (b.second - c.second) + b.first * (c.second - a.second) +
             c.first * (a.second - b.second) <
         0;
}
bool ccw(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
  return a.first * (b.second - c.second) + b.first * (c.second - a.second) +
             c.first * (a.second - b.second) >
         0;
}
int sh = 4;
inline int ngb(int first, int second) {
  int tot = 0;
  for (int i = first - sh; i <= first + sh; ++i)
    for (int j = second - sh; j <= second + sh; ++j)
      if (a[i][j] == 1) ++tot;
  return tot;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
      b[i][j] = 0;
    }
  }
  for (int i = sh; i < n - sh; ++i)
    for (int j = sh; j < m - sh; ++j)
      if (a[i][j] == 1 && ngb(i, j) == (2 * sh + 1) * (2 * sh + 1)) b[i][j] = 1;
  vector<int> ans(0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (b[i][j] == 1) {
        queue<pair<int, int> > q;
        vector<pair<int, int> > allp;
        q.push(make_pair(i, j));
        allp.push_back(make_pair(i, j));
        a[i][j] = 2;
        while (!q.empty()) {
          pair<int, int> cur = q.front();
          q.pop();
          for (int w = 0; w < 8; ++w) {
            pair<int, int> nxt =
                make_pair(cur.first + dx[w], cur.second + dy[w]);
            if (!ok(nxt.first, nxt.second)) continue;
            if (a[nxt.first][nxt.second] != 1) continue;
            a[nxt.first][nxt.second] = 2;
            allp.push_back(nxt);
            q.push(nxt);
          }
        }
        vector<pair<int, int> > pts(0);
        q.push(make_pair(i, j));
        pts.push_back(make_pair(i, j));
        b[i][j] = 0;
        a[i][j] = 0;
        while (!q.empty()) {
          pair<int, int> cur = q.front();
          q.pop();
          for (int w = 0; w < 8; ++w) {
            pair<int, int> nxt =
                make_pair(cur.first + dx[w], cur.second + dy[w]);
            if (!ok(nxt.first, nxt.second)) continue;
            if (b[nxt.first][nxt.second] != 1) continue;
            b[nxt.first][nxt.second] = 0;
            a[nxt.first][nxt.second] = 0;
            pts.push_back(nxt);
            q.push(nxt);
          }
        }
        int si = 0, sj = 0;
        for (int k = 0; k < ((int)(pts).size()); ++k) {
          si += pts[k].first;
          sj += pts[k].second;
        }
        double cx = si / ((int)(pts).size());
        double cy = sj / ((int)(pts).size());
        double ddx = 0, ddy = 0;
        for (int k = 0; k < ((int)(pts).size()); ++k) {
          ddx = max(ddx, 1. * pts[k].first);
          ddy = max(ddy, 1. * pts[k].second);
        }
        ddx -= cx;
        ddy -= cy;
        double c = sqrt(abs(ddx * ddx - ddy * ddy));
        for (int k = 0; k < ((int)(pts).size()); ++k) {
          double vx = pts[k].first - cx;
          double vy = pts[k].second - cy;
          double vl = sqrt(vx * vx + vy * vy);
          vx /= vl;
          vy /= vl;
          for (int act = 1; act <= 7; ++act) {
            double px = pts[k].first + vx * act;
            double py = pts[k].second + vy * act;
            int sadd = 2;
            for (int sx = -sadd; sx <= sadd; ++sx)
              for (int sy = -sadd; sy <= sadd; ++sy)
                if (ok((int)px + sx, (int)py + sy) &&
                    a[(int)px + sx][(int)py + sy] == 2)
                  a[(int)px + sx][(int)py + sy] = 0;
          }
        }
        int rays = 0;
        for (int k = 0; k < ((int)(allp).size()); ++k) {
          if (a[allp[k].first][allp[k].second] == 2) {
            q.push(make_pair(allp[k].first, allp[k].second));
            a[allp[k].first][allp[k].second] = 0;
            ++rays;
            while (!q.empty()) {
              pair<int, int> cur = q.front();
              q.pop();
              for (int w = 0; w < 8; ++w) {
                pair<int, int> nxt =
                    make_pair(cur.first + dx[w], cur.second + dy[w]);
                if (!ok(nxt.first, nxt.second)) continue;
                if (a[nxt.first][nxt.second] != 2) continue;
                a[nxt.first][nxt.second] = 0;
                pts.push_back(nxt);
                q.push(nxt);
              }
            }
          }
        }
        ans.push_back(rays);
      }
    }
  }
  cout << ((int)(ans).size()) << endl;
  sort((ans).begin(), (ans).end());
  for (int i = 0; i < ((int)(ans).size()); ++i) {
    if (i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
}