Problem: Offering the ABBYY Cup participants a problem written by the Smart Beaver is becoming a tradition. He proposed the following problem.

You are given a monochrome image, that is, an image that is composed of two colors (black and white). The image is given in raster form, that is, as a matrix of pixels' colors, and the matrix's size coincides with the size of the image.

The white color on the given image corresponds to the background. Also, the image contains several black geometric shapes. It is known that the image can contain only two types of shapes: squares and circles. Your task is to count the number of circles and the number of squares which the given image contains.

The squares on the image can be rotated arbitrarily. In addition, the image can possibly contain some noise arranged as follows: each pixel of the original image can change its color to the opposite with the probability of 20%.

<image> An example of an image that has no noise and the sides of the squares are parallel to the coordinate axes (two circles and three squares).  <image> An example of an image that has no noise and the squares are rotated arbitrarily (two circles and three squares).  <image> An example of an image that has noise and the squares are rotated arbitrarily (one circle and three squares). 

Input

The first input line contains a single integer n (1000 ≤ n ≤ 2000), which is the length and the width of the original image. 

Next n lines describe the matrix of colors of the image pixels. The i-th line contains exactly n integers aij (0 ≤ aij ≤ 1), separated by spaces. Value of aij = 0 corresponds to a white pixel and aij = 1 corresponds to a black one. 

It is guaranteed that the lengths of the sides of the squares and the diameters of the circles in the image are at least 15 pixels, and the distance between any two figures is at least 10 pixels. It is also guaranteed that a human can easily calculate the number of circles and squares in the original image. The total number of figures in the image doesn't exceed 50.

The input limitations for getting 20 points are: 

  * These test cases have no noise and the sides of the squares are parallel to the coordinate axes. 



The input limitations for getting 50 points are: 

  * These test cases have no noise, but the squares are rotated arbitrarily. 



The input limitations for getting 100 points are: 

  * These test cases have noise and the squares are rotated arbitrarily. 

Output

Print exactly two integers, separated by a single space — the number of circles and the number of squares in the given image, correspondingly.

Examples

Note

You are given a sample of original data for each difficulty level. The samples are available at http://codeforces.ru/static/materials/contests/178/e-samples.zip .

Solution (in JAVA):

Solution:
//package abbyy2.hard;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;


public class EH2 {
	BufferedReader br;
	PrintWriter out;
	String INPUT = "";
	
	void solve() throws Exception
	{
		int n = Integer.parseInt(br.readLine());
		DJSet ds = new DJSet(n*n);
//		long S = System.currentTimeMillis();
		int[][] pp = new int[n][n];
		int[][] p = new int[n][n];
		for(int i = 0;i < n;i++){
			String line = br.readLine();
			for(int j = 0;j < n;j++){
				pp[i][j] = line.charAt(j*2)-'0';
			}
		}
		
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				int ct = 0;
				int all = 0;
				for(int k = -1;k <= 1;k++){
					for(int l = -1;l <= 1;l++){
						if(k == 0 && l == 0)continue;
						int nx = i+k, ny = j+l;
						if(nx >= 0 && nx < n && ny >= 0 && ny < n){
							all++;
							ct += pp[nx][ny];
						}
					}
				}
				if(ct > all/2+1){
					p[i][j] = 1;
				}else if(ct < all/2-1){
					p[i][j] = 0;
				}else{
					p[i][j] = pp[i][j];
				}
			}
		}
		
//		tr(System.currentTimeMillis() - S);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n-1;j++){
				if(p[i][j] == 1 && p[i][j+1] == 1){
					ds.union(i*n+j, i*n+(j+1));
				}
			}
		}
		for(int i = 0;i < n-1;i++){
			for(int j = 0;j < n;j++){
				if(p[i][j] == 1 && p[i+1][j] == 1){
					ds.union(i*n+j, (i+1)*n+j);
				}
			}
		}
		double[][] cent = new double[n*n][2];
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				int clus = ds.root(i*n+j);
				cent[clus][0] += i;
				cent[clus][1] += j;
			}
		}
//		tr(System.currentTimeMillis() - S);
		
		Map<Integer, Integer> ics = new HashMap<Integer, Integer>();
		int[] nums = new int[100];
		int q = 0;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(ds.upper[i*n+j] < -100){
					int num = -ds.upper[i*n+j];
					int clus = i*n+j;
					cent[clus][0] /= num;
					cent[clus][1] /= num;
					nums[q] = num;
					ics.put(clus, q++);
				}
			}
		}
		
		int N = 9;
		double[][] max = new double[q][N];
		double[] v = new double[q];
		
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(ds.upper[ds.root(i*n+j)] < -100){
					int clus = ds.root(i*n+j);
					int id = ics.get(clus);
					double D = (i-cent[clus][0])*(i-cent[clus][0])+(j-cent[clus][1])*(j-cent[clus][1]);
					for(int k = 0;k <= N-1;k++){
						if(D > max[id][k]){
							for(int l = N-2;l >= k;l--){
								max[id][l+1] = max[id][l];
							}
							max[id][k] = D;
						}
					}
					v[id] += D;
				}
			}
		}
		
		int cir = 0, sq = 0;
		for(int i = 0;i < q;i++){
			v[i] /= nums[i];
			if(v[i] > 13*max[i][0]/36){
				cir++;
			}else{
				sq++;
			}
		}
		out.println(cir + " " + sq);
	}
	
	public static class DJSet { public int[] upper; public DJSet(int n){ upper = new int[n]; Arrays.fill(upper, -1);} public int root(int x){	return upper[x] < 0 ? x : (upper[x] = root(upper[x]));}	public boolean equiv(int x, int y){ return root(x) == root(y);} public void union(int x, int y){ x = root(x);y = root(y);if(x != y) { if(upper[y] < upper[x]) { int d = x; x = y; y = d;	} upper[x] += upper[y]; upper[y] = x;}} public int count(){	int ct = 0;	for(int i = 0;i < upper.length;i++){ if(upper[i] < 0)ct++; } return ct; }}
	
	void run() throws Exception
	{
		long S = System.currentTimeMillis();
		br = new BufferedReader(INPUT.isEmpty() ? new InputStreamReader(System.in) : new StringReader(INPUT));
//		br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("x:\\hard_2.in"))));
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
		long G = System.currentTimeMillis();
		tr(G-S+"ms");
	}
	
	public static void main(String[] args) throws Exception
	{
		new EH2().run();
	}
	
	void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}