#include <bits/stdc++.h>
using namespace std;
int m, n;
map<string, int> name_to_num;
string num_to_name[11000];
vector<int> E[11000];
struct T {
  int ver;
  bool con;
  int times;
} a[11000];
int ans, num;
int getnum() {
  string s;
  cin >> s;
  int &x = name_to_num[s];
  if (x == 0) x = ++n, num_to_name[x] = s;
  return x;
}
int main() {
  cin >> m;
  while (m--) {
    int x = getnum(), y = getnum();
    E[x].push_back(y);
    E[y].push_back(x);
  }
  cout << n << endl;
  for (int x = (1); x <= (n); x++) {
    cout << num_to_name[x] << " ";
    a[x].ver = x, a[x].con = 1;
    for (typeof((E[x]).begin()) y = (E[x]).begin(); y != (E[x]).end(); y++)
      a[*y].ver = x, a[*y].con = 1;
    ans = 0;
    num = n - ((int)(E[x]).size()) - 1;
    for (typeof((E[x]).begin()) y = (E[x]).begin(); y != (E[x]).end(); y++)
      for (typeof((E[*y]).begin()) z = (E[*y]).begin(); z != (E[*y]).end(); z++)
        if (a[*z].ver != x || a[*z].ver == x && !a[*z].con) {
          if (a[*z].ver != x) {
            a[*z].ver = x;
            a[*z].con = 0;
            a[*z].times = 0;
          }
          a[*z].times++;
          if (a[*z].times > ans) ans = a[*z].times, num = 0;
          if (a[*z].times == ans) num++;
        }
    cout << num << endl;
  }
  return 0;
}
