#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
const int MAXP = 501 * 501;
int N, M;
char grid[MAXN][MAXN];
complex<long long> P[MAXP];
complex<long long> H[MAXP];
int sz;
long long cross(complex<long long> a, complex<long long> b) {
  return imag(conj(a) * b);
}
bool compare_pt(complex<long long> a, complex<long long> b) {
  return a.real() < b.real() || (a.real() == b.real() && a.imag() < b.imag());
}
void find_hull() {
  sort(P, P + M, compare_pt);
  for (int i = 0; i < M; i++) {
    while (sz >= 2 && cross(H[sz - 2] - H[sz - 1], P[i] - H[sz - 1]) <= 0) sz--;
    H[sz] = P[i];
    sz++;
  }
  for (int i = M - 2, j = sz + 1; i >= 0; i--) {
    while (sz >= j && cross(H[sz - 2] - H[sz - 1], P[i] - H[sz - 1]) <= 0) sz--;
    H[sz] = P[i];
    sz++;
  }
  sz--;
}
int main() {
  ios::sync_with_stdio(0);
  while ((cin >> N) && N != 0) {
    for (int y = N; y >= 1; y--) {
      string s;
      cin >> s;
      for (int x = 1; x <= N; x++) grid[x][y] = s[x - 1];
    }
    for (int i = 0; i <= N + 1; i++) grid[0][i] = grid[N + 1][i] = '0';
    for (int i = 0; i <= N + 1; i++) grid[i][0] = grid[i][N + 1] = '0';
    M = 0, sz = 0;
    set<pair<int, int> > st;
    for (int x = 0; x < N + 1; x++)
      for (int y = 0; y < N + 1; y++) {
        if (grid[x][y] == '0' && grid[x][y + 1] == '0' &&
            grid[x + 1][y] == '0' && grid[x + 1][y + 1] == '1')
          st.insert(make_pair(x + 1, y + 1));
        if (grid[x][y] == '0' && grid[x][y + 1] == '0' &&
            grid[x + 1][y] == '1' && grid[x + 1][y + 1] == '0')
          st.insert(make_pair(x + 1, y - 1));
        if (grid[x][y] == '0' && grid[x][y + 1] == '1' &&
            grid[x + 1][y] == '0' && grid[x + 1][y + 1] == '0')
          st.insert(make_pair(x - 1, y + 1));
        if (grid[x][y] == '1' && grid[x][y + 1] == '0' &&
            grid[x + 1][y] == '0' && grid[x + 1][y + 1] == '0')
          st.insert(make_pair(x - 1, y - 1));
      }
    for (set<pair<int, int> >::iterator it = st.begin(); it != st.end(); it++)
      P[M++] = complex<long long>(it->first, it->second);
    find_hull();
    cout << sz << "\n";
    for (int i = 0; i < sz; i++)
      cout << H[i].real() << " " << H[i].imag() << "\n";
  }
  return 0;
}
