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 JAVA):

Solution:
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskF1 solver = new TaskF1();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskF1 {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int h = in.nextInt();
        int w = in.nextInt();
        boolean[][] board = new boolean[h][w];
        for (int r = 0; r < h; ++r)
            for (int c = 0; c < w; ++c)
                board[r][c] = in.nextInt() == 1;
        int[][] comp = new int[h][w];
        int ncomp = 0;
        for (int r = 0; r < h; ++r)
            for (int c = 0; c < w; ++c)
                if (board[r][c] && comp[r][c] == 0)
                    markComp(r, c, h, w, ++ncomp, board, comp);
        int[] rays = new int[ncomp];
        out.println(ncomp);
        int[][] psum = new int[h + 1][w + 1];
        for (int r = 0; r < h; ++r)
            for (int c = 0; c < w; ++c) {
                psum[r + 1][c + 1] = psum[r][c + 1] + psum[r + 1][c] - psum[r][c] + (board[r][c] ? 1 : 0);
            }
        boolean[][] sun = new boolean[h][w];
        for (int r = 0; r < h; ++r)
            for (int c = 0; c < w; ++c) if (board[r][c]) {
                int cnt = psum[Math.min(h, r + 3)][Math.min(w, c + 3)] - psum[Math.max(0, r - 3)][Math.min(w, c + 3)] - psum[Math.min(h, r + 3)][Math.max(0, c - 3)] + psum[Math.max(0, r - 3)][Math.max(0, c - 3)];
                if (cnt == 36) {
                    for (int dr = -4; dr <= 4; ++dr)
                        for (int dc = -4; dc <= 4; ++dc)
                        {
                            int nr = r + dr;
                            int nc = c + dc;
                            if (nr >= 0 && nr < h && nc >= 0 && nc < w && board[nr][nc])
                                sun[nr][nc] = true;
                        }
                }
            }
        for (int r = 0; r < h; ++r)
            for (int c = 0; c < w; ++c)
                if (sun[r][c]) board[r][c] = false;
        int[][] c2 = new int[h][w];
        for (int r = 0; r < h; ++r)
            for (int c = 0; c < w; ++c)
                if (board[r][c] && c2[r][c] == 0) {
                    markComp(r, c, h, w, 1, board, c2);
                    ++rays[comp[r][c] - 1];
                }
        Arrays.sort(rays);
        for (int i = 0; i < ncomp; ++i) {
            if (i > 0) out.print(" ");
            out.print(rays[i]);
        }
        out.println();
    }

    private void markComp(int r, int c, int h, int w, int cid, boolean[][] board, int[][] comp) {
        if (comp[r][c] != 0) {
            if (comp[r][c] != cid) throw new RuntimeException();
            return;
        }
        comp[r][c] = cid;
        for (int dr = -1; dr <= 1; ++dr)
            for (int dc = -1; dc <= 1; ++dc)
                if (Math.abs(dr) + Math.abs(dc) == 1) {
                    int nr = r + dr;
                    int nc = c + dc;
                    if (nr >= 0 && nr < h && nc >= 0 && nc < w && board[nr][nc])
                        markComp(nr, nc, h, w, cid, board, comp);
                }

    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    }