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 {
  long long x, y;
  int id;
  point(){};
  point(long long _x, long long _y, int _id) : x(_x), y(_y), id(_id){};
};
struct vect {
  long long x, y;
  vect(){};
  vect(long long _x, long long _y) : x(_x), y(_y){};
  vect(point a, point b) : x(b.x - a.x), y(b.y - a.y){};
};
long long crossProductNorm(vect a, vect b) { return a.x * b.y - b.x * a.y; }
bool isCCW(vect a, vect b) { return crossProductNorm(a, b) < 0; }
long long dst(point a, point b) {
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
point refPoint;
bool compCW(point a, point b) {
  vect aVect(refPoint, a);
  vect bVect(refPoint, b);
  return isCCW(aVect, bVect) || (crossProductNorm(aVect, bVect) == 0 &&
                                 dst(refPoint, a) < dst(refPoint, b));
}
vector<point> constructConvexHull(vector<point> &pts) {
  if (pts.empty()) {
    vector<point> v;
    return v;
  }
  int minY = pts[0].y, minX = pts[0].x;
  int minYP = 0;
  for (int i = (1); i < (pts.size()); i++)
    if (pts[i].y < minY || (pts[i].y == minY && pts[i].x < minX))
      minY = pts[i].y, minX = pts[i].x, minYP = i;
  refPoint = pts[minYP];
  pts.erase(pts.begin() + minYP);
  sort(pts.begin(), pts.end(), compCW);
  pts.insert(pts.begin(), refPoint);
  vector<point> myCH;
  myCH.push_back(pts[0]);
  for (int i = (1); i < (pts.size()); i++) {
    while (myCH.size() >= 2) {
      vect v1(myCH[myCH.size() - 1], pts[i]);
      vect v2(myCH[myCH.size() - 2], myCH[myCH.size() - 1]);
      if (!isCCW(v2, v1))
        myCH.pop_back();
      else
        break;
    }
    myCH.push_back(pts[i]);
  }
  while (myCH.size() > 2) {
    vect v1(myCH[myCH.size() - 1], pts[0]);
    vect v2(myCH[myCH.size() - 2], myCH[myCH.size() - 1]);
    if (!isCCW(v2, v1))
      myCH.pop_back();
    else
      break;
  }
  return myCH;
}
pair<int, int> mny[100005], mnx[100005], mxy[100005], mxx[100005];
int T;
int main() {
  while (1) {
    int n, M;
    scanf("%d %d", &n, &M);
    if (n == 0) return 0;
    set<pair<int, int> > tp;
    set<pair<int, int> > cnd;
    T++;
    for (int t = (0); t < (M); t++) {
      int x, y;
      scanf("%d %d", &x, &y);
      x--;
      y--;
      tp.emplace(x, y);
      if (mny[x].second != T) mny[x] = make_pair(y, T);
      if (mxy[x].second != T) mxy[x] = make_pair(y, T);
      if (mnx[y].second != T) mnx[y] = make_pair(x, T);
      if (mxx[y].second != T) mxx[y] = make_pair(x, T);
      mny[x].first = min(mny[x].first, y);
      mxy[x].first = max(mxy[x].first, y);
      mnx[y].first = min(mnx[y].first, x);
      mxx[y].first = max(mxx[y].first, x);
      for (int dy = (-1); dy < (2); dy++)
        for (int dx = (-1); dx < (2); dx++) {
          cnd.emplace(x + dx, y + dy);
        }
    }
    vector<point> vp;
    for (auto p : cnd) {
      int x = p.first, y = p.second;
      int cnt = 0;
      for (int dy = (-1); dy < (1); dy++)
        for (int dx = (-1); dx < (1); dx++) {
          cnt += tp.count(make_pair(x + dx, y + dy));
        }
      if (cnt == 4) {
        vp.emplace_back(x, y, 0);
      } else if (cnt == 3) {
        for (int dy = (-1); dy < (1); dy++)
          for (int dx = (-1); dx < (1); dx++) {
            if (!tp.count(make_pair(x + dx, y + dy))) {
              int nx = x + dx, ny = y + dy;
              if (mny[nx].first > ny || mxy[nx].first < ny ||
                  mnx[ny].first > nx || mxx[ny].first < nx) {
              } else {
                vp.emplace_back(x, y, 0);
              }
            }
          }
      }
    }
    vector<point> ch = constructConvexHull(vp);
    int m = int(ch.size());
    int make_pair = 0;
    for (int i = (1); i < (m); i++)
      if (ch[i].x < ch[make_pair].x ||
          (ch[i].x == ch[make_pair].x && ch[i].y < ch[make_pair].y))
        make_pair = i;
    printf("%d\n", m);
    for (int i = (0); i < (m); i++)
      printf("%lld %lld\n", ch[(make_pair + i) % m].x,
             ch[(make_pair + i) % m].y);
  }
}