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 Point {
  int x;
  int y;
  Point() { x = y = 0; }
  Point(double _x, double _y) {
    x = _x;
    y = _y;
  }
  friend Point operator+(const Point &a, const Point &b) {
    return Point(b.x + a.x, b.y + a.y);
  }
  friend Point operator-(const Point &a, const Point &b) {
    return Point(a.x - b.x, a.y - b.y);
  }
  friend Point operator*(const Point &a, double p) {
    return Point(a.x * p, a.y * p);
  }
  friend Point operator/(const Point &a, double p) {
    return Point(a.x / p, a.y / p);
  }
  friend double operator*(const Point &p, const Point &a) {
    return (p.x * a.x + p.y * a.y);
  }
  friend double operator/(const Point &p, const Point &a) {
    return (p.x * a.y - p.y * a.x);
  }
  friend bool operator<(const Point &a, const Point &b) {
    if (a.x < b.x) return true;
    if (a.x > b.x) return false;
    if (a.y < b.y) return true;
    return false;
  }
  friend bool operator>(const Point &a, const Point &b) {
    if (a.x > b.x) return true;
    if (a.x < b.x) return false;
    if (a.y > b.y) return true;
    return false;
  }
  friend bool operator==(const Point &a, const Point &b) {
    return (a.x == b.x && a.y == b.y);
  }
  friend bool operator!=(const Point &a, const Point &b) {
    return (a.x != b.x || a.y != b.y);
  }
  double slope() { return y / x; }
  double measure() { return sqrt(x * x + y * y); }
  double angle() {
    double an = atan2(y, x);
    if (an < 0) an += 2 * 3.1415926535897932385;
    return an;
  }
  Point shrink() { return Point(1, y / x); }
};
struct Hashdata {
  Point p;
  int t;
  Hashdata() {
    p = Point();
    t = 0;
  }
  Hashdata(Point _p, int _t) {
    p = _p;
    t = _t;
  }
};
int n, m, hc, cc;
int leftone[100010], rightone[100010];
Point peter[200010], charles[4 * 200010], harry[200010];
int hull[200010], q[200010], nowtest;
Hashdata corner[3000007];
int point_hash(Point a) {
  int x = a.x, y = a.y;
  return (x * 10007 + y) % 3000007;
}
bool reader() {
  scanf("%d%d", &n, &m);
  if (n == 0) return false;
  for (int i = 1; i <= n; i++) leftone[i] = n, rightone[i] = 0;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    peter[i] = Point(x, y);
    if (x < leftone[y]) leftone[y] = x;
    if (x > rightone[y]) rightone[y] = x;
  }
  return true;
}
void qsort(int l, int r) {
  int i = l, j = r;
  Point mid = charles[(l + r) / 2];
  do {
    while (charles[i] < mid) i++;
    while (charles[j] > mid) j--;
    if (i <= j) {
      Point t = charles[i];
      charles[i] = charles[j];
      charles[j] = t;
      i++;
      j--;
    }
  } while (i <= j);
  if (i < r) qsort(i, r);
  if (l < j) qsort(l, j);
}
void convex_hull(int vc) {
  int qh = 2;
  q[1] = vc;
  q[2] = vc - 1;
  for (int i = vc - 2; i >= 1; i--) {
    while ((qh >= 2) && ((charles[i] - charles[q[qh - 1]]) /
                             (charles[q[qh]] - charles[q[qh - 1]]) <=
                         0))
      qh--;
    qh++;
    q[qh] = i;
  }
  int qh1 = qh;
  for (int i = 1; i <= qh; i++) hull[i] = q[i];
  qh = 2;
  q[1] = 1;
  q[2] = 2;
  for (int i = 3; i <= vc; i++) {
    while ((qh >= 2) && ((charles[i] - charles[q[qh - 1]]) /
                             (charles[q[qh]] - charles[q[qh - 1]]) <=
                         0))
      qh--;
    qh++;
    q[qh] = i;
  }
  for (int i = 2; i < qh; i++) hull[qh1 + i - 1] = q[i];
  hc = qh1 + qh - 2;
  for (int i = 0; i < hc; i++) harry[i] = charles[hull[i + 1]];
}
bool in_hull(int x, int y) {
  if (x < leftone[y]) return false;
  if (x > rightone[y]) return false;
  return true;
}
bool check_zeroes(int x, int y) {
  if (!in_hull(x, y)) return false;
  if (!in_hull(x + 1, y)) return false;
  if (!in_hull(x, y + 1)) return false;
  if (!in_hull(x + 1, y + 1)) return false;
  return true;
}
void add_corner(Point a) {
  int h = point_hash(a);
  while (corner[h].t == nowtest) {
    if (corner[h].p == a) return;
    h = (h + 1) % 3000007;
  }
  corner[h] = Hashdata(a, nowtest);
  charles[++cc] = a;
}
void generate() {
  cc = 0;
  for (int i = 1; i <= m; i++) {
    int x = peter[i].x, y = peter[i].y;
    if (check_zeroes(x, y)) add_corner(Point(x, y));
    if (check_zeroes(x - 1, y)) add_corner(Point(x - 1, y));
    if (check_zeroes(x, y - 1)) add_corner(Point(x, y - 1));
    if (check_zeroes(x - 1, y - 1)) add_corner(Point(x - 1, y - 1));
  }
  qsort(1, cc);
}
void printer() {
  printf("%d\n", hc);
  Point starter = harry[0];
  int si = 0;
  for (int i = 1; i < hc; i++)
    if (harry[i] < starter) starter = harry[i], si = i;
  for (int i = si; i < hc; i++) {
    int x = harry[i].x, y = harry[i].y;
    printf("%d %d\n", x, y);
  }
  for (int i = 0; i < si; i++) {
    int x = harry[i].x, y = harry[i].y;
    printf("%d %d\n", x, y);
  }
}
int main() {
  nowtest = 1;
  while (reader()) {
    generate();
    convex_hull(cc);
    printer();
    nowtest += 2;
  }
}