#include <bits/stdc++.h>
using namespace std;
vector<int> G[10005];
int v[10005], d[10005];
int main() {
  int n, i, j = 0;
  map<string, int> m;
  map<int, string> m1;
  scanf("%d", &n);
  ;
  for (i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;
    if (m.find(a) == m.end()) {
      m[a] = j;
      m1[j] = a;
      j++;
    }
    if (m.find(b) == m.end()) {
      m[b] = j;
      m1[j] = b;
      j++;
    }
    G[m[a]].push_back(m[b]);
    G[m[b]].push_back(m[a]);
  }
  int users = j;
  cout << users << endl;
  for (i = 0; i < users; i++) {
    queue<int> q;
    int mx = 0, mxc = 0;
    for (j = 0; j < users; j++) {
      d[j] = 0;
      v[j] = 0;
    }
    q.push(i);
    v[i] = 1;
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      int l = G[cur].size();
      if (d[cur] == 2) {
        int c = 0;
        for (j = 0; j < l; j++) {
          int x = G[cur][j];
          if (d[x] == 1) c++;
        }
        if (c > mx) {
          mx = c;
          mxc = 1;
        } else if (c == mx)
          mxc++;
      } else {
        for (j = 0; j < l; j++) {
          int x = G[cur][j];
          if (!v[x]) {
            d[x] = d[cur] + 1;
            q.push(x);
            v[x] = 1;
          }
        }
      }
    }
    int l = G[i].size();
    if (mxc == 0 && l != users - 2) mxc = users - l - 1;
    cout << m1[i] << " " << mxc << endl;
  }
  return 0;
}
