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 <typename T>
inline T Abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
template <typename T>
inline void relaxMin(T &a, T b) {
  if (b < a) a = b;
}
template <typename T>
inline void relaxMax(T &a, T b) {
  if (b > a) a = b;
}
const int INF = (int)1E9;
const long double EPS = 1E-6;
const long double PI = 3.1415926535897932384626433832795;
void pre() {}
int w, h;
int f[2000][2000];
int id[2000][2000];
int id2[2000][2000];
int nvalid[2000][2000];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
vector<vector<pair<int, int> > > sall;
vector<int> ans;
bool valid(int x, int y) { return x >= 0 && x < h && y >= 0 && y < w; }
void erase(int x, int y, int len) {
  for (int dx = -len; dx <= len; dx++)
    for (int dy = -len; dy <= len; dy++)
      if (dx * dx + dy * dy <= len) {
        int px = x + dx, py = y + dy;
        if (valid(px, py)) nvalid[px][py] = 1;
      }
}
bool good(int x, int y, int len) {
  for (int dx = -len; dx <= len; dx++)
    for (int dy = -len; dy <= len; dy++)
      if (dx * dx + dy * dy <= len) {
        int px = x + dx, py = y + dy;
        if (valid(px, py) && !f[px][py]) return false;
      }
  return true;
}
int used[2000][2000];
vector<pair<int, int> > bfs(int sx, int sy, int cmp1[2000][2000], int op1,
                            int cmp2[2000][2000], int op2) {
  vector<pair<int, int> > ans;
  queue<pair<int, int> > q;
  q.push(make_pair(sx, sy));
  while (!q.empty()) {
    pair<int, int> v = q.front();
    q.pop();
    ans.push_back(v);
    int x = v.first, y = v.second;
    for (int d(0), _bb(4); d < _bb; ++d) {
      int nx = x + dx[d], ny = y + dy[d];
      if (valid(nx, ny) && !used[nx][ny] && (cmp1[nx][ny] == op1) &&
          (cmp2[nx][ny] == op2)) {
        used[nx][ny] = 1;
        q.push(make_pair(nx, ny));
      }
    }
  }
  return ans;
}
void solve() {
  scanf("%d%d", &h, &w);
  for (int i(0), _bb(h); i < _bb; ++i)
    for (int j(0), _bb(w); j < _bb; ++j) scanf("%d", &f[i][j]);
  memset(id, -1, sizeof id);
  ;
  memset(used, 0, sizeof used);
  ;
  for (int i(0), _bb(h); i < _bb; ++i) {
    for (int j(0), _bb(w); j < _bb; ++j)
      if (f[i][j] && id[i][j] == -1) {
        int sid = sall.size();
        vector<pair<int, int> > v = bfs(i, j, f, 1, f, 1);
        sall.push_back(v);
        for (int k(0), _bb(v.size()); k < _bb; ++k)
          id[v[k].first][v[k].second] = sid;
      }
  }
  memset(nvalid, 0, sizeof nvalid);
  ;
  memset(id2, -1, sizeof id2);
  ;
  memset(used, 0, sizeof used);
  ;
  for (int sid(0), _bb(sall.size()); sid < _bb; ++sid) {
    vector<pair<int, int> > g;
    for (int i(0), _bb(sall[sid].size()); i < _bb; ++i)
      if (good(sall[sid][i].first, sall[sid][i].second, 7))
        g.push_back(sall[sid][i]);
    for (int i(0), _bb(g.size()); i < _bb; ++i)
      erase(g[i].first, g[i].second, 15);
    int cnt = 0;
    for (int i(0), _bb(sall[sid].size()); i < _bb; ++i) {
      int x = sall[sid][i].first, y = sall[sid][i].second;
      if (nvalid[x][y] || id2[x][y] != -1) continue;
      vector<pair<int, int> > v = bfs(x, y, nvalid, 0, id, id[x][y]);
      cnt++;
      for (int k(0), _bb(v.size()); k < _bb; ++k)
        id2[v[k].first][v[k].second] = 1;
    }
    ans.push_back(cnt);
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i(0), _bb(ans.size()); i < _bb; ++i) cout << ans[i] << " ";
}
int main() {
  srand(0xA1B2C3D4);
  pre();
  solve();
  return 0;
}