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

Solution:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 100;
const int K = 8;
const int dif = 13;
const double zero = 1e-7;
int n, x, st, ed, u, d, l, r, cx, cy, rr, unround, ress, resr, rounddisp, pcl;
int dat[maxn][maxn], gar[maxn][maxn], tar[maxn][maxn];
char ch;
struct points {
  int x, y, d;
  points() {}
  points(int xx, int yy, int dd) {
    x = xx, y = yy;
    d = dd;
  }
} b[maxn * maxn];
vector<points> q;
inline double csqr(double x) { return x * x; }
inline int cabs(int x) { return x > 0 ? x : -x; }
inline int cmax(int x, int y) { return x < y ? y : x; }
inline double cfabs(int x) {
  if (x > zero) return x;
  if (x < -zero) return -x;
  return 0;
}
struct fastio11 {
  int getint() {
    for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
      ;
    x = ch - 48;
    while ((ch = getchar()) >= '0' && ch <= '9') x = x * 10 + ch - 48;
    return x;
  }
} tool1;
struct binarygraph {
  int dat[maxn][maxn];
  int n, cnt, l, r;
  double c, t;
  void preset(int size) {
    n = size;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) dat[i][j] = 0;
  }
  void delblanks() {
    for (int i = 1; i <= n; i++) {
      for (l = 1; l < n && dat[i][l] == 0; l++)
        ;
      for (r = n; r > 1 && dat[i][r] == 0; r--)
        ;
      for (int j = l; j <= r; j++) dat[i][j] = 1;
    }
  }
  void printout() {
    printf("%d\n", n);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) printf(dat[i][j] ? "W" : " ");
      printf("\n");
    }
  }
  int check() {
    c = n / 2.0;
    cnt = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        if (cfabs(t = sqrt(csqr(i - c) + csqr(j - c)) - c) - 1 > zero) {
          if (t > zero && dat[i][j] == 1) cnt++;
          if (t < -zero && dat[i][j] == 0) cnt++;
        }
    return cnt < n / 3;
  }
} tool2;
int main() {
  n = tool1.getint();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) dat[i][j] = tool1.getint();
  for (int i = 3; i <= n - 2; i++)
    for (int j = 3; j <= n - 2; j++) {
      int cnt = 0;
      for (int k = i - 2; k <= i + 2; k++)
        for (int l = j - 2; l <= j + 2; l++)
          if (dat[k][l]) cnt++;
      gar[i][j] = cnt;
    }
  memcpy(tar, gar, sizeof(tar));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (tar[i][j] >= dif) {
        q.clear();
        q.push_back(b[ed = 1] = points(i, j, tar[i][j]));
        tar[i][j] = 0;
        st = 0;
        while (st < ed) {
          points t = b[++st];
          if (t.x > 1 && tar[t.x - 1][t.y] >= dif) {
            q.push_back(b[++ed] = points(t.x - 1, t.y, tar[t.x - 1][t.y]));
            tar[t.x - 1][t.y] = 0;
          }
          if (t.x < n && tar[t.x + 1][t.y] >= dif) {
            q.push_back(b[++ed] = points(t.x + 1, t.y, tar[t.x + 1][t.y]));
            tar[t.x + 1][t.y] = 0;
          }
          if (t.y > 1 && tar[t.x][t.y - 1] >= dif) {
            q.push_back(b[++ed] = points(t.x, t.y - 1, tar[t.x][t.y - 1]));
            tar[t.x][t.y - 1] = 0;
          }
          if (t.y < n && tar[t.x][t.y + 1] >= dif) {
            q.push_back(b[++ed] = points(t.x, t.y + 1, tar[t.x][t.y + 1]));
            tar[t.x][t.y + 1] = 0;
          }
        }
        if (ed < 50) continue;
        u = r = 0;
        l = d = 0x7fffffff;
        for (int p = 0; p < q.size(); p++) {
          if (q[p].x > u) u = q[p].x;
          if (q[p].x < d) d = q[p].x;
          if (q[p].y > r) r = q[p].y;
          if (q[p].y < l) l = q[p].y;
        }
        tool2.preset(cmax(r - l + 1, u - d + 1));
        for (int p = 0; p < q.size(); p++)
          tool2.dat[q[p].x - d + 1][q[p].y - l + 1] = 1;
        tool2.delblanks();
        if (tool2.check())
          resr++;
        else
          ress++;
      }
  printf("%d %d\n", resr, ress);
  return 0;
}