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 int MAX_N = 500;
const int MAX_M = MAX_N * MAX_N;
const int dxs[] = {1, 0, -1, 0}, dys[] = {0, 1, 0, -1};
template <typename T>
struct Pt {
  T x, y;
  Pt() {}
  Pt(T _x, T _y) : x(_x), y(_y) {}
  Pt(const Pt<T> &p) : x(p.x), y(p.y) {}
  Pt<T> operator+(const Pt<T> p) const { return Pt<T>(x + p.x, y + p.y); }
  Pt<T> operator-() const { return Pt<T>(-x, -y); }
  Pt<T> operator-(const Pt<T> p) const { return Pt<T>(x - p.x, y - p.y); }
  Pt<T> operator*(T t) const { return Pt<T>(x * t, y * t); }
  Pt<T> operator/(T t) const { return Pt<T>(x / t, y / t); }
  T dot(Pt<T> v) const { return x * v.x + y * v.y; }
  T cross(Pt<T> v) const { return x * v.y - y * v.x; }
  Pt<T> mid(const Pt<T> p) { return Pt<T>((x + p.x) / 2, (y + p.y) / 2); }
  T d2() { return x * x + y * y; }
  double d() { return sqrt(d2()); }
  Pt<T> rot(double th) {
    double c = cos(th), s = sin(th);
    return Pt<T>(c * x - s * y, s * x + c * y);
  }
  bool operator==(const Pt<T> pt) const { return x == pt.x && y == pt.y; }
  bool operator<(const Pt<T> &pt) const {
    return x < pt.x || (x == pt.x && y < pt.y);
  }
  void print() { printf("(%d,%d)", x, y); }
};
char s[MAX_N + 4];
int as[MAX_N][MAX_N];
Pt<int> ps[MAX_M];
void convex_hull(int n, Pt<int> ps[], vector<Pt<int> > &chs) {
  vector<Pt<int> > lhs, uhs;
  lhs.push_back(ps[0]);
  lhs.push_back(ps[1]);
  for (int i = 2; i < n; i++) {
    while (lhs.size() >= 2) {
      int ln = lhs.size();
      Pt<int> &lh0 = lhs[ln - 2], &lh1 = lhs[ln - 1];
      if ((lh1 - lh0).cross(ps[i] - lh1) > 0) break;
      lhs.pop_back();
    }
    lhs.push_back(ps[i]);
  }
  uhs.push_back(ps[n - 1]);
  uhs.push_back(ps[n - 2]);
  for (int i = n - 3; i >= 0; i--) {
    while (uhs.size() >= 2) {
      int un = uhs.size();
      Pt<int> &uh0 = uhs[un - 2], &uh1 = uhs[un - 1];
      if ((uh1 - uh0).cross(ps[i] - uh1) > 0) break;
      uhs.pop_back();
    }
    uhs.push_back(ps[i]);
  }
  lhs.pop_back();
  uhs.pop_back();
  chs.clear();
  chs.reserve(lhs.size() + uhs.size());
  chs.assign(lhs.begin(), lhs.end());
  chs.insert(chs.end(), uhs.begin(), uhs.end());
}
int main() {
  for (int n; scanf("%d", &n) > 0 && n > 0;) {
    for (int y = n - 1; y >= 0; y--) {
      scanf("%s", s);
      for (int x = 0; x < n; x++) as[y][x] = s[x] - '0';
    }
    int m = 0;
    for (int y = 0; y < n; y++)
      for (int x = 0; x < n; x++)
        if (as[y][x] == 1) {
          int c = 0, b = 0;
          for (int di = 0; di < 4; di++) {
            int vx = x + dxs[di], vy = y + dys[di];
            if (vx >= 0 && vx < n && vy >= 0 && vy < n && as[vy][vx] > 0)
              c++, b |= (1 << di);
          }
          if (c == 2) {
            switch (b) {
              case 3:
                ps[m] = Pt<int>(x + 1, y + 1);
                break;
              case 6:
                ps[m] = Pt<int>(x, y + 1);
                break;
              case 12:
                ps[m] = Pt<int>(x, y);
                break;
              case 9:
                ps[m] = Pt<int>(x + 1, y);
                break;
            }
            m++;
          }
        }
    sort(ps, ps + m);
    m = unique(ps, ps + m) - ps;
    vector<Pt<int> > cps;
    convex_hull(m, ps, cps);
    int k = cps.size();
    printf("%d\n", k);
    for (int i = 0, j = 0; i < k; i++, j = (j + k - 1) % k)
      printf("%d %d\n", cps[j].x, cps[j].y);
  }
  return 0;
}