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 DIR_NUM = 4;
const int SIZEH = 1610, SIZEC = 100010;
int H, W;
int C;
int board[SIZEH][SIZEH];
int core[SIZEH][SIZEH];
int sun[SIZEH][SIZEH];
int raynum[SIZEC] = {0};
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
void print(int s[SIZEH][SIZEH]) {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (s[i][j] == -1)
        printf("-");
      else
        printf("%d", s[i][j]);
    }
    printf("\n");
  }
}
int nowtot = 0;
int DFS_ray(int x, int y) {
  sun[x][y] = -1;
  nowtot++;
  int ans = 0;
  for (int d = 0; d < DIR_NUM; d++) {
    int x1 = x + dx[d], y1 = y + dy[d];
    if (0 <= x1 && x1 < H && 0 <= y1 && y1 < W) {
      if (sun[x1][y1] > 0)
        ans = sun[x1][y1];
      else if (sun[x1][y1] == 0) {
        int tp = DFS_ray(x1, y1);
        if (tp) ans = tp;
      }
    }
  }
  return ans;
}
void Find_Ray(void) {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (sun[i][j] == 0) {
        nowtot = 0;
        int t = DFS_ray(i, j);
        if (nowtot >= 5) raynum[t]++;
      }
    }
  }
}
void DFS_core(int x, int y, int col) {
  core[x][y] = col;
  for (int d = 0; d < DIR_NUM; d++) {
    int x1 = x + dx[d], y1 = y + dy[d];
    if (0 <= x1 && x1 < H && 0 <= y1 && y1 < W) {
      if (core[x1][y1] == 0) DFS_core(x1, y1, col);
    }
  }
}
void Find_Core(void) {
  int timer = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (core[i][j] == 0) {
        DFS_core(i, j, ++timer);
      }
    }
  }
  C = timer;
}
void Background_Spread(int f[SIZEH][SIZEH], int g[SIZEH][SIZEH]) {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      g[i][j] = f[i][j];
      for (int d = 0; d < DIR_NUM; d++) {
        int i1 = i + dx[d], j1 = j + dy[d];
        if (0 <= i1 && i1 < H && 0 <= j1 && j1 < W) {
          if (f[i1][j1] == -1) g[i][j] = -1;
        }
      }
    }
  }
}
void Multiple_Background_Spread(int f[SIZEH][SIZEH], int tim) {
  static int g[SIZEH][SIZEH];
  for (int i = 1; i <= tim; i++) {
    Background_Spread(f, g);
    memcpy(f, g, sizeof(g));
  }
}
void Sun_Recover(int f[SIZEH][SIZEH], int g[SIZEH][SIZEH]) {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      g[i][j] = max(f[i][j], board[i][j]);
      for (int d = 0; d < DIR_NUM; d++) {
        int i1 = i + dx[d], j1 = j + dy[d];
        if (0 <= i1 && i1 < H && 0 <= j1 && j1 < W) {
          if (board[i][j] >= 0 && f[i1][j1] > 0) g[i][j] = f[i1][j1];
        }
      }
    }
  }
}
void Multiple_Sun_Recover(int f[SIZEH][SIZEH], int tim) {
  static int g[SIZEH][SIZEH];
  for (int i = 1; i <= tim; i++) {
    Sun_Recover(f, g);
    memcpy(f, g, sizeof(g));
  }
}
void Work(void) {
  int width = 3;
  memcpy(core, board, sizeof(core));
  Multiple_Background_Spread(core, width);
  Find_Core();
  memcpy(sun, core, sizeof(sun));
  Multiple_Sun_Recover(sun, width);
  Find_Ray();
  sort(raynum + 1, raynum + 1 + C);
  printf("%d\n", C);
  for (int i = 1; i <= C; i++) printf("%d ", raynum[i]);
  printf("\n");
}
void Read(void) {
  scanf("%d%d", &H, &W);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      scanf("%d", &board[i][j]);
      board[i][j]--;
    }
  }
}
int main() {
  Read();
  Work();
  return 0;
}