#include <bits/stdc++.h>
using namespace std;
const int maxn = 505 * 505;
inline pair<int, int> operator-(const pair<int, int> &p,
                                const pair<int, int> &q) {
  return pair<int, int>(p.first - q.first, p.second - q.second);
}
pair<int, int> p[maxn];
int sz;
vector<pair<int, int> > lo, up;
inline long long cross(const pair<int, int> &p, const pair<int, int> &q) {
  return 1LL * p.first * q.second - 1LL * p.second * q.first;
}
inline int hull(vector<pair<int, int> > &h) {
  if (sz <= 1) return sz;
  h.clear();
  h.push_back(p[0]);
  for (int i = 1; i < sz; i++) {
    while (h.size() > 1 &&
           cross(h.back() - h[(int)h.size() - 2], p[i] - h.back()) <= 0)
      h.pop_back();
    h.push_back(p[i]);
  }
  return h.size();
}
inline bool fnd(const pair<int, int> &p, const vector<pair<int, int> > &v) {
  int i = lower_bound((v).begin(), (v).end(), p) - v.begin();
  return i < v.size() && v[i] == p;
}
inline int convex_hull() {
  lo.clear();
  up.clear();
  if (sz <= 1) return sz;
  sort(p, p + sz);
  sz = unique(p, p + sz) - p;
  int L = hull(lo);
  reverse(p, p + sz);
  int H = hull(up);
  sz = 0;
  for (int i = 0; i < lo.size(); i++) p[sz++] = lo[i];
  for (int i = 1; i < up.size() - 1; i++) p[sz++] = up[i];
  return L + H - 2;
}
bool mark[505][505];
int a[505][505];
int main() {
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n && n) {
    for (int i = n - 1; i >= 0; i--)
      for (int j = 0; j < n; j++) {
        char c;
        cin >> c;
        a[i][j] = (c - '0');
        mark[i][j] = false;
      }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (a[i][j] == 0)
          mark[i][j] = mark[i][j + 1] = mark[i + 1][j] = mark[i + 1][j + 1] =
              true;
      }
    }
    sz = 0;
    for (int i = 2; i < n - 1; i++)
      for (int j = 2; j < n - 1; j++)
        if (!mark[i][j]) p[sz++] = make_pair(j, i);
    convex_hull();
    cout << sz << endl;
    int st = 0;
    for (int i = 0; i < sz; i++)
      if (p[i] < p[st]) st = i;
    int j = st;
    do {
      cout << p[j].first << ' ' << p[j].second << '\n';
      j--;
      if (j < 0) j = sz - 1;
    } while (j != st);
  }
  return 0;
}
