#include <bits/stdc++.h>
using namespace std;
const int MAX = 505;
char ma[MAX][MAX];
int pnt[MAX][MAX];
int dx[] = {-1, -1, 0, 0};
int dy[] = {-1, 0, 0, -1};
int n;
bool ok(int x, int y) { return x >= 0 && x < n && y >= 0 && y < n; }
int main() {
  while (scanf("%d", &n) && n) {
    for (int i = 0; i < n; i++) scanf("%s", ma[i]);
    memset(pnt, 0, sizeof pnt);
    for (char zombie = '0'; zombie <= '4'; zombie++) {
      for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
          for (int k = 0; k < 4; k++) {
            int curx = i + dx[k], cury = j + dy[k];
            if (ok(i + dx[k], j + dy[k])) {
              if (pnt[i][j] == -1) continue;
              if (ma[curx][cury] == zombie) {
                if (zombie == '0') {
                  pnt[i][j] = -1;
                } else {
                  pnt[i][j] = 1;
                }
              }
            }
          }
        }
      }
    }
    vector<complex<long double> > v;
    vector<pair<pair<long double, long double>, int> > vv;
    long double mx, my;
    int mi;
    mx = my = n + 1;
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        if (pnt[i][j] == 1) {
          v.push_back(complex<long double>(j, n - i));
          if (mx > j || (mx == j && my > n - i)) {
            mi = v.size() - 1;
            mx = j;
            my = n - i;
          }
        }
      }
    }
    for (int i = 0; i < v.size(); i++) {
      if (mi == i)
        vv.push_back(make_pair(make_pair(-20, 0), i));
      else
        vv.push_back(
            make_pair(make_pair(-arg(v[i] - v[mi]), norm(v[i] - v[mi])), i));
    }
    sort(vv.begin(), vv.end());
    vector<complex<long double> > ch;
    ch.push_back(v[vv[0].second]);
    ch.push_back(v[vv[1].second]);
    int pos = 2;
    while (pos < vv.size()) {
      complex<long double> v1, v2;
      do {
        v1 = v[vv[pos].second] - ch[ch.size() - 1];
        v2 = ch[ch.size() - 2] - ch[ch.size() - 1];
        if (imag(conj(v1) * v2) >= 0) {
          ch.pop_back();
        }
      } while (imag(conj(v1) * v2) >= 0);
      ch.push_back(v[vv[pos].second]);
      pos++;
    }
    cout << ch.size() << endl;
    for (int i = 0; i < ch.size(); i++) {
      cout << real(ch[i]) << " " << imag(ch[i]) << endl;
    }
  }
  return 0;
}
