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 PI = acos(-1.0);
const long long LINF = (long long)1e18 + 5;
const int INF = (int)1e9 + 5;
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T abs(T x) {
  return x < 0 ? -x : x;
}
template <class T>
long long round(T x) {
  return x < 0 ? x - 0.5 : x + 0.5;
}
template <class T>
bool chmin(T& x, const T& y) {
  if (y < x) {
    x = y;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& x, const T& y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}
template <class P, class Q>
ostream& operator<<(ostream& os, const pair<P, Q>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  bool was = false;
  for (const T& x : v) {
    if (was) {
      os << ", ";
    }
    was = true;
    os << x;
  }
  os << "}";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << "{";
  bool was = false;
  for (const T& x : v) {
    if (was) {
      os << ", ";
    }
    was = true;
    os << x;
  }
  os << "}";
  return os;
}
template <class P, class Q>
ostream& operator<<(ostream& os, const map<P, Q>& m) {
  os << "{";
  bool was = false;
  for (const auto& x : m) {
    if (was) {
      os << ", ";
    }
    was = true;
    os << x;
  }
  os << "}";
  return os;
}
struct pt {
  int x, y;
  pt() {}
  pt(int x, int y) : x(x), y(y) {}
  bool operator<(const pt& o) const { return x < o.x || (x == o.x && y < o.y); }
  bool operator==(const pt& o) const { return x == o.x && y == o.y; }
  pt operator-(const pt& o) const { return pt(x - o.x, y - o.y); }
};
long long trapeze(const pt& a, const pt& b) {
  return 1LL * (a.x - b.x) * (a.y + b.y);
}
long long triArea(const pt& a, const pt& b, const pt& c) {
  return trapeze(a, b) + trapeze(b, c) + trapeze(c, a);
}
vector<pt> normalizeToOutput(vector<pt> v) {
  reverse(v.begin(), v.end());
  int pos = min_element((v).begin(), (v).end()) - v.begin();
  auto leftPart = vector<pt>(v.begin() + pos, v.end());
  auto rightPart = vector<pt>(v.begin(), v.begin() + pos);
  for (auto p : rightPart) {
    leftPart.push_back(p);
  }
  return leftPart;
}
ostream& operator<<(ostream& os, const pt& p) {
  return os << "(" << p.x << ", " << p.y << ")";
}
vector<pt> convexHull(vector<pt> res) {
  sort((res).begin(), (res).end());
  res.erase(unique((res).begin(), (res).end()), res.end());
  {};
  int pos = min_element((res).begin(), (res).end()) - res.begin();
  pt lwr = res[pos];
  res.erase(res.begin() + pos);
  sort((res).begin(), (res).end(), [&lwr](const pt& a, const pt& b) {
    long long z = triArea(lwr, a, b);
    if (z != 0) return z > 0;
    return (a - lwr) < (b - lwr);
  });
  vector<pt> r = {lwr};
  for (auto p : res) {
    while (r.size() >= 2 && triArea(r[(int)r.size() - 2], r.back(), p) <= 0)
      r.pop_back();
    r.push_back(p);
  }
  return r;
}
vector<pt> getConvex(const vector<string>& s, int n) {
  auto valAt = [&s, &n](int x, int y) {
    if (x < 0 || x >= n || y < 0 || y >= n) return 0;
    return s[x][y] - '0';
  };
  vector<vector<char>> isCovered(n + 1, vector<char>(n + 1, false));
  auto addPt = [&isCovered](int x, int y) { isCovered[x][y] = true; };
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < n; y++) {
      if (valAt(x, y) == 4) {
        addPt(x, y);
        addPt(x + 1, y);
        addPt(x, y + 1);
        addPt(x + 1, y + 1);
      } else if (valAt(x, y) == 3) {
        if (valAt(x - 1, y - 1) == 0) {
          addPt(x + 1, y);
          addPt(x, y + 1);
          addPt(x + 1, y + 1);
        } else if (valAt(x - 1, y + 1) == 0) {
          addPt(x, y);
          addPt(x + 1, y + 1);
          addPt(x + 1, y);
        } else if (valAt(x + 1, y + 1) == 0) {
          addPt(x, y);
          addPt(x + 1, y);
          addPt(x, y + 1);
        } else {
          addPt(x, y);
          addPt(x, y + 1);
          addPt(x + 1, y + 1);
        }
      } else if (valAt(x, y) == 2) {
        if (valAt(x - 1, y) == 0) {
          addPt(x + 1, y);
          addPt(x + 1, y + 1);
        } else if (valAt(x + 1, y) == 0) {
          addPt(x, y);
          addPt(x, y + 1);
        } else if (valAt(x, y - 1) == 0) {
          addPt(x, y + 1);
          addPt(x + 1, y + 1);
        } else if (valAt(x, y + 1) == 0) {
          addPt(x, y);
          addPt(x + 1, y);
        } else if (valAt(x + 1, y - 1) != 0 && valAt(x - 1, y + 1) != 0) {
          addPt(x + 1, y);
          addPt(x, y + 1);
        } else {
          addPt(x, y);
          addPt(x + 1, y + 1);
        }
      } else if (valAt(x, y) == 1) {
        if (valAt(x - 1, y - 1) && valAt(x - 1, y) && valAt(x, y - 1)) {
          addPt(x, y);
        } else if (valAt(x - 1, y + 1) && valAt(x - 1, y) && valAt(x, y + 1)) {
          addPt(x, y + 1);
        } else if (valAt(x + 1, y - 1) && valAt(x + 1, y) && valAt(x, y - 1)) {
          addPt(x + 1, y);
        } else if (valAt(x + 1, y + 1) && valAt(x + 1, y) && valAt(x, y + 1)) {
          addPt(x + 1, y + 1);
        }
      }
    }
  }
  vector<pt> result;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (isCovered[i][j]) {
        result.push_back(pt(i, j));
      }
    }
  }
  return normalizeToOutput(convexHull(result));
}
bool solve() {
  int n;
  scanf("%d", &n);
  if (n == 0) return false;
  vector<string> s(n), tmp(n);
  for (int i = 0; i < n; i++) {
    static char buf[555];
    scanf("%s", buf);
    s[i] = buf;
    tmp[i] = buf;
  }
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < n; y++) {
      s[x][y] = tmp[n - y - 1][x];
    }
  }
  {};
  vector<pt> res = getConvex(s, n);
  printf("%d\n", (int)res.size());
  for (auto p : res) {
    printf("%d %d\n", p.x, p.y);
  }
  return true;
}
int main() {
  while (solve())
    ;
}