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>
void Get(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
int N;
int G[2005][2005];
void Init() {
  Get(N);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) Get(G[i][j]);
}
double Dis(int X, int Y, int X2, int Y2) {
  double DX = X - X2;
  double DY = Y - Y2;
  return sqrt(DX * DX + DY * DY);
}
int QX[4000005];
int QY[4000005];
int L, R;
bool Visited[2005][2005];
int DX[] = {0, 0, 1, -1};
int DY[] = {1, -1, 0, 0};
int BFS(int X, int Y) {
  int Cnt = 1;
  QX[L = R = 1] = X;
  QY[1] = Y;
  Visited[X][Y] = 1;
  for (; L <= R; L++) {
    for (int i = 0; i <= 3; i++) {
      int NewX = QX[L] + DX[i];
      int NewY = QY[L] + DY[i];
      if (Visited[NewX][NewY] == 0 && NewX > 0 && NewX <= N && NewY > 0 &&
          NewY <= N && G[NewX][NewY] == G[X][Y]) {
        Visited[NewX][NewY] = 1;
        QX[++R] = NewX;
        QY[R] = NewY;
        Cnt++;
      }
    }
  }
  return Cnt;
}
int Top;
int ID[2005][2005];
int Fa[4000005];
double SumX[4000005];
double SumY[4000005];
double Sum[4000005];
double Max[4000005];
int Cnt[4000005];
int GetFa(int X) {
  if (Fa[X] == X) return Fa[X];
  return Fa[X] = GetFa(Fa[X]);
}
int Ans1, Ans2;
void Work() {
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      if (!Visited[i][j] && G[i][j] == 1) {
        int Ans = BFS(i, j);
        if (Ans <= 99) {
          for (int i = 1; i <= Ans; i++) {
            G[QX[i]][QY[i]] = !G[QX[i]][QY[i]];
          }
        }
      }
  memset(Visited, 0, sizeof Visited);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      if (!Visited[i][j] && G[i][j] == 0) {
        int Ans = BFS(i, j);
        if (Ans <= 99) {
          for (int i = 1; i <= Ans; i++) {
            G[QX[i]][QY[i]] = !G[QX[i]][QY[i]];
          }
        }
      }
  memset(Visited, 0, sizeof Visited);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      if (!Visited[i][j] && G[i][j] == 1) {
        int Ans = BFS(i, j);
        Top++;
        Fa[Top] = Top;
        for (int i = 1; i <= Ans; i++) {
          ID[QX[i]][QY[i]] = Top;
        }
      }
  for (int i = 1; i <= 2000; i++)
    for (int j = 1; j <= 2000; j++) {
      if (G[i][j] == 1) {
        for (int i2 = -5; i2 <= 5; i2++)
          for (int j2 = -(5 - std::abs(i2)); j2 + std::abs(i2) <= 5; j2++) {
            int X = i + i2;
            int Y = j + j2;
            if (X > 0 && X <= 2000 && Y > 0 && Y <= 2000 && G[X][Y] == 1 &&
                GetFa(ID[X][Y]) != GetFa(ID[i][j])) {
              int Ans1 = GetFa(ID[X][Y]), Ans2 = GetFa(ID[i][j]);
              Fa[Ans1] = Ans2;
            }
          }
      }
    }
  for (int i = 1; i <= 2000; i++)
    for (int j = 1; j <= 2000; j++) {
      Cnt[GetFa(ID[i][j])]++;
      SumX[GetFa(ID[i][j])] += i;
      SumY[GetFa(ID[i][j])] += j;
    }
  for (int i = 1; i <= Top; i++)
    if (Cnt[i] > 0) {
      SumX[i] /= Cnt[i];
      SumY[i] /= Cnt[i];
    }
  for (int i = 1; i <= 2000; i++)
    for (int j = 1; j <= 2000; j++) {
      double Dist = Dis(i, j, SumX[GetFa(ID[i][j])], SumY[GetFa(ID[i][j])]);
      Sum[GetFa(ID[i][j])] += Dist;
      if (Max[GetFa(ID[i][j])] < Dist) Max[GetFa(ID[i][j])] = Dist;
    }
  for (int i = 1; i <= Top; i++)
    if (Cnt[i] > 0) {
      Sum[i] /= Cnt[i];
      double Except2 = (Max[i] * 0.765195) - Sum[i] * sqrtl(2);
      double Except1 = (Max[i] * 2 / 3.) - Sum[i];
      if (Except1 < 0) Except1 = -Except1;
      if (Except2 < 0) Except2 = -Except2;
      Except1 *= 0.85;
      if (Except1 < Except2)
        Ans1++;
      else
        Ans2++;
    }
}
void Output() { printf("%d %d\n", Ans1, Ans2); }
int main() {
  Init();
  Work();
  Output();
  return 0;
}