#include <bits/stdc++.h>
using namespace std;
int n;
int a[503][503];
bool lq(double x, double y) { return y > x; }
bool leq(double x, double y) { return y >= x; }
struct P {
  int x, y;
  P() {}
  P(int x, int y) : x(int(x)), y(int(y)) {}
  P operator+(const P &a) const { return P(x + a.x, y + a.y); }
  P operator-(const P &a) const { return P(x - a.x, y - a.y); }
  bool operator==(const P &a) const { return a.x == x && a.y == y; }
  int operator*(const P &a) const { return x * a.x + y * a.y; }
  int operator^(const P &a) const { return x * a.y - y * a.x; }
  void in() { scanf("%d%d", &x, &y); }
};
P X[2001];
bool cmp(P U, P V) {
  if (U.x == V.x) return U.y < V.y;
  return U.x < V.x;
}
void Convex_Hull(P C[], P T[], int n, int &f) {
  for (int i = 0; i < n; i++) X[i] = C[i];
  sort(X, X + n, cmp);
  int cnt = 0, num = 0;
  for (int i = 0; i < n; i++) {
    while (num >= 2 &&
           leq((T[cnt - 1] - T[cnt - 2]) ^ (X[i] - T[cnt - 1]), 0)) {
      num--;
      cnt--;
    }
    T[cnt++] = X[i];
    num++;
  }
  num = 0;
  cnt--;
  for (int i = n - 1; i >= 0; i--) {
    while (num >= 2 &&
           leq((T[cnt - 1] - T[cnt - 2]) ^ (X[i] - T[cnt - 1]), 0)) {
      num--;
      cnt--;
    }
    T[cnt++] = X[i];
    num++;
  }
  f = cnt - 1;
}
P Z[6001], W[6001];
int top, tail;
void solve() {
  for (int i = n; i >= 1; i--) {
    string x;
    cin >> x;
    for (int j = 1; j <= n; j++) a[i][j] = (int)(x[j - 1] - '0');
  }
  for (int i = 0; i <= n + 1; i++)
    a[0][i] = a[n + 1][i] = a[i][0] = a[i][n + 1] = 0;
  top = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[i][j]) {
        if (!a[i - 1][j] && !a[i - 1][j - 1] && !a[i][j - 1])
          W[top++] = P(j, i);
        if (!a[i - 1][j] && !a[i - 1][j + 1] && !a[i][j + 1])
          W[top++] = P(j - 1, i);
        if (!a[i + 1][j] && !a[i + 1][j - 1] && !a[i][j - 1])
          W[top++] = P(j, i - 1);
        if (!a[i + 1][j] && !a[i + 1][j + 1] && !a[i][j + 1])
          W[top++] = P(j - 1, i - 1);
      }
  Convex_Hull(W, Z, top, tail);
  printf("%d\n%d %d\n", tail, Z[0].x, Z[0].y);
  for (int i = tail - 1; i >= 1; i--) printf("%d %d\n", Z[i].x, Z[i].y);
}
int main() {
  while (scanf("%d", &n), n != 0) solve();
  return 0;
}
