#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int inf = 1000000009;
int i, j, k, m, n, l;
int ans;
string s[505];
pair<int, int> head;
int cc(pair<int, int> A, pair<int, int> B) {
  A.first -= head.first;
  A.second -= head.second;
  B.first -= head.first;
  B.second -= head.second;
  if (A.first * B.second != A.second * B.first)
    return A.first * B.second < A.second * B.first;
  return A.first * A.first + A.second * A.second <
         B.first * B.first + B.second * B.second;
}
int cmp(pair<int, int> head, pair<int, int> A, pair<int, int> B) {
  A.first -= head.first;
  A.second -= head.second;
  B.first -= head.first;
  B.second -= head.second;
  return A.first * B.second - A.second * B.first;
}
int main() {
  while (1) {
    cin >> n;
    if (n == 0) break;
    for (int i = 0; i < n; i++) cin >> s[n - i - 1];
    vector<pair<int, int> > p;
    for (int i = 1; i <= n - 2; i++)
      for (int j = 1; j <= n - 2; j++) {
        int has1 = 0, has0 = 0;
        for (int dx = 0; dx < 2; dx++)
          for (int dy = 0; dy < 2; dy++) {
            if (s[i + dx][j + dy] == '0') has0 = 1;
            if (s[i + dx][j + dy] == '1') has1 = 1;
          }
        if (has1 && !has0) p.push_back(make_pair(j + 1, i + 1));
      }
    int k = 0;
    for (int i = 0; i < ((int)p.size()); i++)
      if (p[i] < p[k]) k = i;
    swap(p[k], p[0]);
    head = p[0];
    sort(p.begin() + 1, p.end(), cc);
    vector<pair<int, int> > w;
    w.push_back(p[0]);
    for (int i = 1; i < ((int)p.size()); i++) {
      while (w.size() >= 2 &&
             cmp(w[((int)w.size()) - 2], w[((int)w.size()) - 1], p[i]) >= 0)
        w.pop_back();
      w.push_back(p[i]);
    }
    cout << ((int)w.size()) << endl;
    for (int i = 0; i < ((int)w.size()); i++)
      cout << w[i].first << " " << w[i].second << endl;
  }
  return 0;
}
