#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
  Point operator-(Point b) {
    Point ret;
    ret.x = x - b.x;
    ret.y = y - b.y;
    return ret;
  }
  int operator^(Point a) { return x * a.y - y * a.x; }
};
bool cmp(Point a, Point b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }
bool HASH[555][555];
char cmap[555][555];
int n;
vector<Point> p, q, tmp;
void convex_hull() {
  sort(p.begin(), p.end(), cmp);
  tmp.clear();
  n = (int)p.size();
  for (int i = 0; i < n; i++) {
    while ((int)q.size() > 1 &&
           ((p[i] - q[(int)q.size() - 1]) ^
            (q[(int)q.size() - 1] - q[(int)q.size() - 2])) <= 0)
      q.pop_back();
    while ((int)tmp.size() > 1 &&
           ((p[i] - tmp[(int)tmp.size() - 1]) ^
            (tmp[(int)tmp.size() - 1] - tmp[(int)tmp.size() - 2])) >= 0)
      tmp.pop_back();
    q.push_back(p[i]);
    tmp.push_back(p[i]);
  }
  for (int i = (int)tmp.size() - 2; i; i--) q.push_back(tmp[i]);
  return;
}
int main() {
  while (scanf("%d", &n) == 1 && n) {
    for (int i = 0; i < n; i++) scanf("%s", cmap[n - i] + 1);
    memset(HASH, 0, sizeof(HASH));
    p.clear();
    q.clear();
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        if (cmap[i][j] == '1') {
          Point tmp;
          if (cmap[i][j + 1] != '0' && cmap[i + 1][j] != '0' &&
              cmap[i + 1][j + 1] != '0') {
            tmp.x = j;
            tmp.y = i;
          } else if (cmap[i][j - 1] != '0' && cmap[i + 1][j] != '0' &&
                     cmap[i + 1][j - 1] != '0') {
            tmp.x = j - 1;
            tmp.y = i;
          } else if (cmap[i - 1][j - 1] != '0' && cmap[i][j - 1] != '0' &&
                     cmap[i - 1][j] != '0') {
            tmp.x = j - 1;
            tmp.y = i - 1;
          } else {
            tmp.x = j;
            tmp.y = i - 1;
          }
          if (!HASH[tmp.x + 1][tmp.y + 1]) {
            HASH[tmp.x + 1][tmp.y + 1] = 1;
            p.push_back(tmp);
          }
        }
    convex_hull();
    printf("%d\n", (int)q.size());
    for (int i = 0; i < (int)q.size(); i++) printf("%d %d\n", q[i].x, q[i].y);
  }
  return 0;
}
