#include <bits/stdc++.h>
using namespace std;
set<int> e[10005];
map<string, int> mp;
string x, y, s[10005];
int n, m;
int main() {
  int i, j, k;
  scanf("%d", &m);
  while (m--) {
    cin >> x >> y;
    if (mp.find(x) == mp.end()) mp[x] = ++n, s[n] = x;
    if (mp.find(y) == mp.end()) mp[y] = ++n, s[n] = y;
    e[mp[x]].insert(mp[y]);
    e[mp[y]].insert(mp[x]);
  }
  cout << n << endl;
  for (i = 1; i <= n; i++) {
    int p = 0, t = 0;
    for (j = 1; j <= n; j++) {
      if (i != j && e[i].find(j) == e[i].end()) {
        int x = 0;
        for (set<int>::iterator it = e[i].begin(); it != e[i].end(); it++)
          if (e[j].find(*it) != e[j].end()) x++;
        if (x > p)
          p = x, t = 1;
        else if (x == p)
          t++;
      }
    }
    cout << s[i] << " " << t << endl;
  }
  return 0;
}
