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 di[4] = {0, 1, 0, -1};
const int dj[4] = {1, 0, -1, 0};
const int P = 1;
int N;
int A[2010][2010];
int K;
int B[2010][2010];
bool vis[2010][2010];
vector<pair<int, int> > ps;
void search(int i, int j) {
  queue<pair<int, int> > que;
  que.push(make_pair(i, j));
  vis[i][j] = true;
  while (!que.empty()) {
    i = que.front().first;
    j = que.front().second;
    que.pop();
    ps.push_back(make_pair(i, j));
    for (int d = 0; d < (int)(4); d++) {
      int ti = i + di[d];
      int tj = j + dj[d];
      if (ti < 0 || K <= ti || tj < 0 || K <= tj) continue;
      if (!B[ti][tj]) continue;
      if (vis[ti][tj]) continue;
      vis[ti][tj] = true;
      que.push(make_pair(ti, tj));
    }
  }
}
double relerror(double x, double y) {
  return fabs(y - x) / max(fabs(y), fabs(x));
}
int square, circle;
double avg(vector<int> a) {
  return accumulate((a).begin(), (a).end(), 0.0) / a.size();
}
inline int getA(int y, int x) {
  if (y < 0 || N <= y || x < 0 || N <= x)
    return 0;
  else
    return A[y][x];
}
void doit(int i, int j) {
  ps.clear();
  search(i, j);
  if (ps.size() <= 3) return;
  int imax = INT_MIN, imin = INT_MAX, jmax = INT_MIN, jmin = INT_MAX;
  for (int k = 0; k < (int)(ps.size()); k++) {
    imax = max(imax, ps[k].first);
    imin = min(imin, ps[k].first);
    jmax = max(jmax, ps[k].second);
    jmin = min(jmin, ps[k].second);
  }
  vector<int> imax_js, imin_js, jmax_is, jmin_is;
  for (int k = 0; k < (int)(ps.size()); k++) {
    if (ps[k].first == imax) imax_js.push_back(ps[k].second);
    if (ps[k].first == imin) imin_js.push_back(ps[k].second);
    if (ps[k].second == jmax) jmax_is.push_back(ps[k].first);
    if (ps[k].second == jmin) jmin_is.push_back(ps[k].first);
  }
  double imax_javg = avg(imax_js);
  double imin_javg = avg(imin_js);
  double jmax_iavg = avg(jmax_is);
  double jmin_iavg = avg(jmin_is);
  int area = 0;
  for (int y = imin * P; y < min(N, imax * P); ++y) {
    for (int x = jmin * P; x < min(N, jmax * P); ++x) {
      area += A[y][x];
    }
  }
  double h = (imax - imin) * P + P;
  double w = (jmax - jmin) * P + P;
  double r = (h + w) / 2.0 / 2.0;
  int y = round(((imin + P / 2.0) + (imax - imin) / 2.0) * P);
  int x = round(((jmin + P / 2.0) + (jmax - jmin) / 2.0) * P);
  const int D = 20;
  for (int dy = -D; dy <= D; dy += 3) {
    int ty = y + dy;
    for (int dx = -D; dx <= D; dx += 3) {
      int tx = x + dx;
      for (int dr = -D; dr <= D; dr += 3) {
        int tr = r + dr;
        if (tr < 5) continue;
        const int S = 100;
        int in = 0, ou = 0;
        for (int i = 0; i < (int)(S); i++) {
          double a = M_PI * 2 * i / S;
          double sa = sin(a);
          double ca = cos(a);
          in += getA(round(ty + tr * 0.88 * sa), round(tx + tr * 0.88 * ca));
          ou += getA(round(ty + tr * 1.12 * sa), round(tx + tr * 1.12 * ca));
        }
        if (in / double(S) > 0.9 && ou / double(S) < 0.1) {
          ++circle;
          return;
        } else {
        }
      }
    }
  }
  ++square;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < (int)(N); i++)
    for (int j = 0; j < (int)(N); j++) scanf("%d", &A[i][j]);
  K = N / P;
  for (int i = 0; i < (int)(N); i++)
    for (int j = 0; j < (int)(N); j++) B[i / P][j / P] += A[i][j];
  for (int i = 0; i < (int)(K); i++)
    for (int j = 0; j < (int)(K); j++) {
      if (B[i][j] > 0.6 * P * P)
        B[i][j] = 1;
      else
        B[i][j] = 0;
    }
  for (int i = 0; i < (int)(K); i++)
    for (int j = 0; j < (int)(K); j++) {
      if (B[i][j] && !vis[i][j]) {
        doit(i, j);
      }
    }
  printf("%d %d\n", circle, square);
  return 0;
}