#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T checkmin(T &a, T b) {
  return (a < b) ? a : a = b;
}
template <class T>
inline T checkmax(T &a, T b) {
  return (a > b) ? a : a = b;
}
template <class T>
T GCD(T a, T b) {
  if (a < 0) return GCD(-a, b);
  if (b < 0) return GCD(a, -b);
  return (a == 0) ? b : GCD(b % a, a);
}
template <class T>
T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b;
}
template <class T>
T sqr(T X) {
  return X * X;
}
namespace Poor {
const int MaxiN = 2005;
int N, Circle, Square;
int A[MaxiN][MaxiN], B[MaxiN][MaxiN], S[MaxiN][MaxiN];
bool Vis[MaxiN][MaxiN];
inline int Ask(int X1, int Y1, int X2, int Y2) {
  return S[X2][Y2] - S[X1 - 1][Y2] - S[X2][Y1 - 1] + S[X1 - 1][Y1 - 1];
}
void Run() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j) scanf("%d", &A[i + 1][j + 1]);
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j)
      S[i][j] = S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1] + A[i][j];
  Circle = Square = 0;
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j) {
      int X1 = max(i - 3, 1), Y1 = max(j - 3, 1);
      int X2 = min(i + 3, N), Y2 = min(j + 3, N);
      int Sum = Ask(X1, Y1, X2, Y2);
      int Tot = (X2 - X1 + 1) * (Y2 - Y1 + 1);
      double Rate = (double)Sum / (double)Tot;
      B[i][j] = (Rate > 0.37);
    }
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j)
      if (B[i][j] && !Vis[i][j]) {
        deque<pair<int, int> > Q;
        Q.push_back(make_pair(i, j));
        vector<pair<int, int> > Visitor;
        Vis[i][j] = 1;
        while (!Q.empty()) {
          int CX = Q.front().first, CY = Q.front().second;
          Q.pop_front();
          Visitor.push_back(make_pair(CX, CY));
          for (int a = -1; a <= 1; ++a)
            for (int b = -1; b <= 1; ++b) {
              int TX = CX + a, TY = CY + b;
              if (TX >= 1 && TX <= N && TY >= 1 && TY <= N && !Vis[TX][TY] &&
                  B[TX][TY]) {
                Vis[TX][TY] = 1;
                Q.push_back(make_pair(TX, TY));
              }
            }
        }
        int MinX = INT_MAX, MaxX = INT_MIN;
        int MinY = INT_MAX, MaxY = INT_MIN;
        for (typeof(Visitor.begin()) it = Visitor.begin(); it != Visitor.end();
             ++it) {
          checkmin(MinX, it->first);
          checkmax(MaxX, it->first);
          checkmin(MinY, it->second);
          checkmax(MaxY, it->second);
        }
        if (MaxY - MinY <= 9 || MaxX - MinX <= 9) continue;
        double X = 0, Y = 0;
        for (typeof(Visitor.begin()) it = Visitor.begin(); it != Visitor.end();
             ++it)
          X += it->first, Y += it->second;
        X /= Visitor.size(), Y /= Visitor.size();
        double R = min(min(fabs(X - MinX), fabs(MaxX - X)),
                       min(fabs(Y - MinY), fabs(MaxY - Y)));
        int Count = 0;
        for (typeof(Visitor.begin()) it = Visitor.begin(); it != Visitor.end();
             ++it)
          if (sqr(X - it->first) + sqr(Y - it->second) <= sqr(R)) ++Count;
        double Rate =
            (double)Count / (double)((MaxX - MinX + 1) * (MaxY - MinY + 1));
        double Rate2 = (double)Visitor.size() /
                       (double)((MaxX - MinX + 1) * (MaxY - MinY + 1));
        if ((Count + 10 >= (int)Visitor.size() ||
             (double)Count / (double)Visitor.size() > 0.92) &&
            fabs(Rate - 3.1415926 / 4.0) < 0.1 &&
            fabs(Rate2 - 3.1415926 / 4.0) < 0.1)
          ++Circle;
        else
          ++Square;
      }
  cout << Circle << " " << Square << endl;
}
}  // namespace Poor
int main() {
  Poor::Run();
  return 0;
}

### Prompt

Generate a cpp solution to the following 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 .

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T checkmin(T &a, T b) {
  return (a < b) ? a : a = b;
}
template <class T>
inline T checkmax(T &a, T b) {
  return (a > b) ? a : a = b;
}
template <class T>
T GCD(T a, T b) {
  if (a < 0) return GCD(-a, b);
  if (b < 0) return GCD(a, -b);
  return (a == 0) ? b : GCD(b % a, a);
}
template <class T>
T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b;
}
template <class T>
T sqr(T X) {
  return X * X;
}
namespace Poor {
const int MaxiN = 2005;
int N, Circle, Square;
int A[MaxiN][MaxiN], B[MaxiN][MaxiN], S[MaxiN][MaxiN];
bool Vis[MaxiN][MaxiN];
inline int Ask(int X1, int Y1, int X2, int Y2) {
  return S[X2][Y2] - S[X1 - 1][Y2] - S[X2][Y1 - 1] + S[X1 - 1][Y1 - 1];
}
void Run() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j) scanf("%d", &A[i + 1][j + 1]);
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j)
      S[i][j] = S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1] + A[i][j];
  Circle = Square = 0;
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j) {
      int X1 = max(i - 3, 1), Y1 = max(j - 3, 1);
      int X2 = min(i + 3, N), Y2 = min(j + 3, N);
      int Sum = Ask(X1, Y1, X2, Y2);
      int Tot = (X2 - X1 + 1) * (Y2 - Y1 + 1);
      double Rate = (double)Sum / (double)Tot;
      B[i][j] = (Rate > 0.37);
    }
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j)
      if (B[i][j] && !Vis[i][j]) {
        deque<pair<int, int> > Q;
        Q.push_back(make_pair(i, j));
        vector<pair<int, int> > Visitor;
        Vis[i][j] = 1;
        while (!Q.empty()) {
          int CX = Q.front().first, CY = Q.front().second;
          Q.pop_front();
          Visitor.push_back(make_pair(CX, CY));
          for (int a = -1; a <= 1; ++a)
            for (int b = -1; b <= 1; ++b) {
              int TX = CX + a, TY = CY + b;
              if (TX >= 1 && TX <= N && TY >= 1 && TY <= N && !Vis[TX][TY] &&
                  B[TX][TY]) {
                Vis[TX][TY] = 1;
                Q.push_back(make_pair(TX, TY));
              }
            }
        }
        int MinX = INT_MAX, MaxX = INT_MIN;
        int MinY = INT_MAX, MaxY = INT_MIN;
        for (typeof(Visitor.begin()) it = Visitor.begin(); it != Visitor.end();
             ++it) {
          checkmin(MinX, it->first);
          checkmax(MaxX, it->first);
          checkmin(MinY, it->second);
          checkmax(MaxY, it->second);
        }
        if (MaxY - MinY <= 9 || MaxX - MinX <= 9) continue;
        double X = 0, Y = 0;
        for (typeof(Visitor.begin()) it = Visitor.begin(); it != Visitor.end();
             ++it)
          X += it->first, Y += it->second;
        X /= Visitor.size(), Y /= Visitor.size();
        double R = min(min(fabs(X - MinX), fabs(MaxX - X)),
                       min(fabs(Y - MinY), fabs(MaxY - Y)));
        int Count = 0;
        for (typeof(Visitor.begin()) it = Visitor.begin(); it != Visitor.end();
             ++it)
          if (sqr(X - it->first) + sqr(Y - it->second) <= sqr(R)) ++Count;
        double Rate =
            (double)Count / (double)((MaxX - MinX + 1) * (MaxY - MinY + 1));
        double Rate2 = (double)Visitor.size() /
                       (double)((MaxX - MinX + 1) * (MaxY - MinY + 1));
        if ((Count + 10 >= (int)Visitor.size() ||
             (double)Count / (double)Visitor.size() > 0.92) &&
            fabs(Rate - 3.1415926 / 4.0) < 0.1 &&
            fabs(Rate2 - 3.1415926 / 4.0) < 0.1)
          ++Circle;
        else
          ++Square;
      }
  cout << Circle << " " << Square << endl;
}
}  // namespace Poor
int main() {
  Poor::Run();
  return 0;
}

```