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;
const long double EPS = 1e-10;
char a[500][501];
int s1[250000], s2[250000], d1[250000], d2[250000];
long double s[250000];
long double sqr(long double w) { return w * w; }
int cmp(long double c1, int c2, int c3, long double v1, int v2, int v3) {
  if (c1 + EPS < v1) {
    return -1;
  }
  if (c1 - EPS > v1) {
    return 1;
  }
  if (c2 > v2) {
    return -1;
  }
  if (c2 < v2) {
    return 1;
  }
  if (c3 < v3) {
    return -1;
  }
  if (c3 > v3) {
    return 1;
  }
  return 0;
}
void qs(int q, int w) {
  int e = q, r = w, y = q + (rand() % (w - q + 1));
  long double t1 = s[y];
  int t2 = s1[y], t3 = s2[y];
  do {
    while (cmp(s[e], s1[e], s2[e], t1, t2, t3) < 0) e++;
    while (cmp(s[r], s1[r], s2[r], t1, t2, t3) > 0) r--;
    if (e <= r) {
      swap(s[e], s[r]);
      swap(s1[e], s1[r]);
      swap(s2[e], s2[r]);
      e++;
      r--;
    }
  } while (e <= r);
  if (q < r) qs(q, r);
  if (e < w) qs(e, w);
}
long double rot(long double q, long double w, long double e, long double r,
                long double t, long double y) {
  return (e - q) * (y - w) - (t - q) * (r - w);
}
int q, lAns1, lAns2;
int sch(int e, int r) {
  swap(e, r);
  e = q - e - 1;
  if (((e < 0) || (e >= q)) || ((r < 0) || (r >= q))) {
    return 0;
  }
  return (a[e][r] != '0');
}
void check(int e, int r, int de, int dr) {
  if (sch(e + de, r) + sch(e, r + dr) == 2) {
    lAns1 = (1 + de) / 2;
    lAns2 = (1 + dr) / 2;
  }
}
int main() {
  int w, e, r, t, numV;
  for (scanf("%d", &q); q; scanf("%d", &q)) {
    numV = 0;
    for (w = 0; w < q; w++) {
      scanf("%s", a[w]);
      for (e = 0; e < q; e++) {
        if (a[w][e] == '1') {
          s1[numV] = q - w - 1;
          s2[numV] = e;
          swap(s1[numV], s2[numV]);
          numV++;
        }
      }
    }
    for (w = 1; w < numV; w++) {
      if ((s2[w] < s2[0]) || ((s2[w] == s2[0]) && (s1[w] < s1[0]))) {
        swap(s1[w], s1[0]);
        swap(s2[w], s2[0]);
      }
    }
    for (w = 1; w < numV; w++) {
      long double AB = sqrt(sqr(s1[w] - s1[0]) + sqr(s2[w] - s2[0]));
      s[w] = (sqr(AB) + 1 - (sqr(s1[w] - s1[0] - 1) + sqr(s2[w] - s2[0]))) / AB;
    }
    qs(1, numV - 1);
    t = 0;
    for (w = 1; w < numV; w++) {
      while (!((t == 0) || (rot(s1[t - 1], s2[t - 1], s1[t], s2[t], s1[w],
                                s2[w]) < -0.1))) {
        t--;
      }
      t++;
      s1[t] = s1[w];
      s2[t] = s2[w];
    }
    t++;
    for (w = 0; w < t; w++) {
      check(s1[w], s2[w], 1, 1);
      check(s1[w], s2[w], 1, -1);
      check(s1[w], s2[w], -1, 1);
      check(s1[w], s2[w], -1, -1);
      d1[w] = s1[w] + lAns1;
      d2[w] = s2[w] + lAns2;
    }
    r = 0;
    for (w = 1; w < t; w++) {
      if ((d1[w] != d1[r]) || (d2[w] != d2[r])) {
        r++;
        d1[r] = d1[w];
        d2[r] = d2[w];
      }
    }
    while ((d1[r] == d1[0]) && (d2[r] == d2[0])) {
      r--;
    }
    t = r + 1;
    r = 0;
    for (e = 1; e < t; e++) {
      if ((d1[e] < d1[r]) || ((d1[e] == d1[r]) && (d2[e] < d2[r]))) {
        r = e;
      }
    }
    cout << t << "\n";
    e = r;
    do {
      printf("%d %d\n", d1[e], d2[e]);
      e++;
      if (e == t) {
        e = 0;
      }
    } while (e != r);
  }
  return 0;
}