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 N = 500 + 7;
const int M = 59;
const int mid = M / 2;
const int mod = 1e9 + 9;
const int inf = 1e6 + 3;
const long long linf = 1ll * inf * inf;
const double pi = acos(-1);
const double eps = 1e-7;
const double ep = 1e-5;
const int maxn = 1e5 + 7;
const double PI = acos(-1);
struct PT {
  double x, y;
  PT() {}
  PT(double x, double y) : x(x), y(y) {}
  PT(const PT& p) : x(p.x), y(p.y) {}
  bool operator<(const PT& rhs) const {
    return make_pair(y, x) < make_pair(rhs.y, rhs.x);
  }
  bool operator==(const PT& rhs) const {
    return make_pair(y, x) == make_pair(rhs.y, rhs.x);
  }
  PT operator+(const PT& p) const { return PT(x + p.x, y + p.y); }
  PT operator-(const PT& p) const { return PT(x - p.x, y - p.y); }
  PT operator*(double c) const { return PT(x * c, y * c); }
  PT operator/(double c) const { return PT(x / c, y / c); }
};
double cross(PT p, PT q) { return p.x * q.y - p.y * q.x; }
double area(PT a, PT b, PT c) {
  return fabs(cross(a, b) + cross(b, c) + cross(c, a)) / 2;
}
double area2(PT a, PT b, PT c) {
  return cross(a, b) + cross(b, c) + cross(c, a);
}
double dot(PT p, PT q) { return p.x * q.x + p.y * q.y; }
double dist(PT p, PT q) { return sqrt(dot(p - q, p - q)); }
double dist2(PT p, PT q) { return dot(p - q, p - q); }
PT RotateCCW90(PT p) { return PT(-p.y, p.x); }
PT RotateCW90(PT p) { return PT(p.y, -p.x); }
PT RotateCCW(PT p, double t) {
  return PT(p.x * cos(t) - p.y * sin(t), p.x * sin(t) + p.y * cos(t));
}
int rlcmp(double x) { return x < -1e-12 ? -1 : x > 1e-12; }
int rlcmp(double x, double y) { return rlcmp(x - y); }
bool between(const PT& a, const PT& b, const PT& c) {
  return (fabs(area2(a, b, c)) < 1e-12 && (a.x - b.x) * (c.x - b.x) <= 0 &&
          (a.y - b.y) * (c.y - b.y) <= 0);
}
void ConvexHull(vector<PT>& pts) {
  sort(pts.begin(), pts.end());
  pts.erase(unique(pts.begin(), pts.end()), pts.end());
  vector<PT> up, dn;
  for (int i = 0; i < pts.size(); i++) {
    while (up.size() > 1 && area2(up[up.size() - 2], up.back(), pts[i]) >= 0)
      up.pop_back();
    while (dn.size() > 1 && area2(dn[dn.size() - 2], dn.back(), pts[i]) <= 0)
      dn.pop_back();
    up.push_back(pts[i]);
    dn.push_back(pts[i]);
  }
  pts = dn;
  for (int i = up.size() - 2; i >= 1; i--) pts.push_back(up[i]);
  if (pts.size() <= 2) return;
  dn.clear();
  dn.push_back(pts[0]);
  dn.push_back(pts[1]);
  for (int i = 2; i < pts.size(); i++) {
    if (between(dn[dn.size() - 2], dn[dn.size() - 1], pts[i])) dn.pop_back();
    dn.push_back(pts[i]);
  }
  if (dn.size() >= 3 && between(dn.back(), dn[0], dn[1])) {
    dn[0] = dn.back();
    dn.pop_back();
  }
  pts = dn;
}
char s[N][N];
int n;
int x[4] = {0, 0, 1, 1};
int y[4] = {0, 1, 0, 1};
pair<int, int> st[N * N];
int top = 0, bot = 0;
bool check[N][N];
bool valid(int u, int v) {
  return u >= 0 && v >= 0 && u < n && v < n && s[u][v] > '0';
}
void setBit(int u, int v) {
  check[u][v] = true;
  for (int t = (0); t < (4); t++) {
    int x1 = u - x[t];
    int y1 = v - y[t];
    if (valid(x1, y1)) {
      s[x1][y1]--;
      if (s[x1][y1] == '1') {
        st[bot++] = make_pair(x1, y1);
      }
    }
  }
}
void solve() {
  while (cin >> n) {
    if (!n) return;
    for (int i = (0); i < (n + 1); i++)
      for (int j = (0); j < (n + 1); j++) check[i][j] = false;
    for (int i = n - 1; i >= 0; --i) scanf("%s", s[i]);
    top = bot = 0;
    for (int i = (0); i < (n); i++)
      for (int j = (0); j < (n); j++)
        if (s[i][j] == '1') {
          st[bot++] = make_pair(i, j);
        }
    while (top < bot) {
      pair<int, int> now = st[top++];
      int u = now.first;
      int v = now.second;
      if (s[now.first][now.second] == '0') continue;
      if (valid(u, v - 1) && valid(u - 1, v)) {
        setBit(u, v);
      }
      if (valid(u, v - 1) && valid(u + 1, v)) {
        setBit(u + 1, v);
      }
      if (valid(u - 1, v) && valid(u, v + 1)) {
        setBit(u, v + 1);
      }
      if (valid(u + 1, v) && valid(u, v + 1)) {
        setBit(u + 1, v + 1);
      }
    }
    vector<PT> pts;
    for (int i = (0); i < (n); i++)
      for (int j = (0); j < (n); j++) {
        if (check[i][j]) pts.push_back(PT(i, j));
      }
    ConvexHull(pts);
    cout << pts.size() << "\n";
    for (int i = (0); i < (pts.size()); i++) {
      printf("%.0lf %.0lf\n", pts[i].y, pts[i].x);
    }
  }
}
int main() {
  int T = 1;
  for (int i = (1); i < (T + 1); i++) {
    solve();
  }
}