Problem: Now that Heidi has made sure her Zombie Contamination level checker works, it's time to strike! This time, the zombie lair is a strictly convex polygon on the lattice. Each vertex of the polygon occupies a point on the lattice. For each cell of the lattice, Heidi knows the level of Zombie Contamination – the number of corners of the cell that are inside or on the border of the lair.

Given this information, Heidi wants to know the exact shape of the lair to rain destruction on the zombies. Help her!

<image>

Input

The input contains multiple test cases.

The first line of each test case contains one integer N, the size of the lattice grid (5 ≤ N ≤ 500). The next N lines each contain N characters, describing the level of Zombie Contamination of each cell in the lattice. Every character of every line is a digit between 0 and 4. 

Cells are given in the same order as they are shown in the picture above: rows go in the decreasing value of y coordinate, and in one row cells go in the order of increasing x coordinate. This means that the first row corresponds to cells with coordinates (1, N), ..., (N, N) and the last row corresponds to cells with coordinates (1, 1), ..., (N, 1).

The last line of the file contains a zero. This line should not be treated as a test case. The sum of the N values for all tests in one file will not exceed 5000.

Output

For each test case, give the following output:

The first line of the output should contain one integer V, the number of vertices of the polygon that is the secret lair. The next V lines each should contain two integers, denoting the vertices of the polygon in the clockwise order, starting from the lexicographically smallest vertex.

Examples

Input

8
00000000
00000110
00012210
01234200
02444200
01223200
00001100
00000000
5
00000
01210
02420
01210
00000
7
0000000
0122100
0134200
0013200
0002200
0001100
0000000
0


Output

4
2 3
2 4
6 6
5 2
4
2 2
2 3
3 3
3 2
3
2 5
4 5
4 2

Note

It is guaranteed that the solution always exists and is unique. It is guaranteed that in the correct solution the coordinates of the polygon vertices are between 2 and N - 2. A vertex (x1, y1) is lexicographically smaller than vertex (x2, y2) if x1 < x2 or <image>.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct cell {
  int set_zero, set_one, non_set;
  int black;
  void reset() {
    set_zero = set_one = 0;
    non_set = 4;
    black = 0;
  }
  void add_zero() {
    set_zero++;
    non_set--;
  }
  void add_one() {
    set_one++;
    non_set--;
  }
  bool can_deduce() {
    return (black == set_one + non_set) || (4 - black == set_zero + non_set);
  }
};
int n, i, j;
char s[555];
cell C[555][555];
int tp[555][555];
bool in_queue[555][555];
queue<pair<int, int> > Q;
int limit;
vector<pair<int, int> > P, Hull;
void set_tp(int x, int y, int v) {
  if (x == 0 || y == 0) return;
  tp[x][y] = v;
  if (v == 0) {
    C[x - 1][y - 1].add_zero();
    C[x][y - 1].add_zero();
    C[x - 1][y].add_zero();
    C[x][y].add_zero();
  } else {
    C[x - 1][y - 1].add_one();
    C[x][y - 1].add_one();
    C[x - 1][y].add_one();
    C[x][y].add_one();
  }
  for (int px = -1; px <= 0; px++)
    for (int py = -1; py <= 0; py++)
      if (!in_queue[x + px][y + py])
        if (C[x + px][y + py].can_deduce()) Q.push(make_pair(x + px, y + py));
}
void add_zero(int x, int y) { set_tp(x, y, 0); }
void add_one(int x, int y) {
  set_tp(x, y, 1);
  P.push_back(make_pair(x, y));
}
int cross(pair<int, int> A, pair<int, int> B, pair<int, int> C) {
  B.first -= A.first;
  B.second -= A.second;
  C.first -= A.first;
  C.second -= A.second;
  return B.first * C.second - B.second * C.first;
}
void solve() {
  int i, j;
  int dim = n + 1;
  P.clear();
  for (i = 1; i <= dim; i++) {
    for (j = 1; j <= dim; j++) {
      if (!C[i][j].can_deduce()) continue;
      Q.push(make_pair(i, j));
      in_queue[i][j] = true;
    }
  }
  while (!Q.empty()) {
    int x = Q.front().first;
    int y = Q.front().second;
    Q.pop();
    if (C[x][y].black == C[x][y].set_one + C[x][y].non_set) {
      if (tp[x][y] == -1) tp[x][y] = 1, add_one(x, y);
      if (tp[x + 1][y] == -1) tp[x + 1][y] = 1, add_one(x + 1, y);
      if (tp[x][y + 1] == -1) tp[x][y + 1] = 1, add_one(x, y + 1);
      if (tp[x + 1][y + 1] == -1) tp[x + 1][y + 1] = 1, add_one(x + 1, y + 1);
    } else {
      if (tp[x][y] == -1) tp[x][y] = 0, add_zero(x, y);
      if (tp[x + 1][y] == -1) tp[x + 1][y] = 0, add_zero(x + 1, y);
      if (tp[x][y + 1] == -1) tp[x][y + 1] = 0, add_zero(x, y + 1);
      if (tp[x + 1][y + 1] == -1) tp[x + 1][y + 1] = 0, add_zero(x + 1, y + 1);
    }
  }
  Hull.clear();
  sort(P.begin(), P.end());
  P.resize(unique(P.begin(), P.end()) - P.begin());
  dim = 2;
  for (auto p : P) {
    while (Hull.size() >= dim) {
      if (cross(Hull[Hull.size() - 2], Hull.back(), p) < 0) break;
      Hull.pop_back();
    }
    Hull.push_back(p);
  }
  P.pop_back();
  reverse(P.begin(), P.end());
  dim = Hull.size() + 1;
  for (auto p : P) {
    while (Hull.size() >= dim) {
      if (cross(Hull[Hull.size() - 2], Hull.back(), p) < 0) break;
      Hull.pop_back();
    }
    Hull.push_back(p);
  }
  Hull.pop_back();
  printf("%d\n", Hull.size());
  for (auto e : Hull) printf("%d %d\n", e.first - 1, e.second - 1);
}
int main() {
  while (scanf("%d\n", &n)) {
    if (n == 0) return 0;
    for (i = 0; i <= n + 3; i++)
      for (j = 0; j <= n + 3; j++)
        C[i][j].reset(), tp[i][j] = -1, in_queue[i][j] = false;
    for (i = 1; i <= n; i++) {
      scanf("%s\n", s + 1);
      for (j = 1; j <= n; j++) C[j][n - i + 1].black = s[j] - '0';
    }
    solve();
  }
  return 0;
}