#include <bits/stdc++.h>
using namespace std;
const int pos[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int n;
char s[510][510];
int v[510][510];
vector<pair<int, int> > vec, ans;
int operator*(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first * b.second - a.second * b.first;
}
pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
pair<int, int> stk[250010];
int main() {
  while (1) {
    ans.clear();
    scanf("%d", &n);
    if (n == 0) break;
    for (int i = n; i >= 1; i--) scanf("%s", s[i] + 1);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) v[i][j] = s[i][j] - '0';
    vec.clear();
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        int cnt = 0;
        for (int k = -1; k <= 0; k++) {
          for (int l = -1; l <= 0; l++) {
            cnt += v[i + k][j + l];
          }
        }
        if (cnt == 1) {
          if (v[i][j] == 1)
            vec.push_back(make_pair(i, j));
          else if (v[i - 1][j] == 1)
            vec.push_back(make_pair(i - 2, j));
          else if (v[i][j - 1] == 1)
            vec.push_back(make_pair(i, j - 2));
          else
            vec.push_back(make_pair(i - 2, j - 2));
        }
      }
    }
    for (auto &x : vec) swap(x.first, x.second);
    sort(vec.begin(), vec.end());
    int top = 0;
    for (auto &x : vec) {
      while (top > 1 && (stk[top] - stk[top - 1]) * (x - stk[top]) >= 0) top--;
      stk[++top] = x;
    }
    for (int i = 1; i <= top; i++) ans.push_back(stk[i]);
    reverse(vec.begin(), vec.end());
    top = 0;
    for (auto &x : vec) {
      while (top > 1 && (stk[top] - stk[top - 1]) * (x - stk[top]) >= 0) top--;
      stk[++top] = x;
    }
    for (int i = 2; i < top; i++) ans.push_back(stk[i]);
    printf("%d\n", ans.size());
    for (auto &x : ans) printf("%d %d\n", x.first, x.second);
  }
  return 0;
}
