#include <bits/stdc++.h>
using namespace std;
map<string, int> K;
string sss[10001];
vector<int> a[10001];
int main() {
  int i, j, T, n, m, ans = 0;
  K.clear();
  scanf("%d", &T);
  string s, second;
  m = 1;
  for (i = 1; i <= T; i++) {
    cin >> s >> second;
    if (!K.count(s)) a[m].clear(), K[s] = m, sss[m] = s, m++;
    if (!K.count(second)) a[m].clear(), K[second] = m, sss[m] = second, m++;
    a[K[s]].push_back(K[second]);
    a[K[second]].push_back(K[s]);
  }
  int p[10001], qq;
  bool f[10001];
  for (i = 1; i < m; i++) sort(a[i].begin(), a[i].end());
  cout << m - 1 << endl;
  for (i = 1; i < m; i++) {
    n = 0;
    ans = 0;
    memset(f, 0, sizeof(f));
    for (vector<int>::iterator it = a[i].begin(); it != a[i].end(); it++)
      f[*it] = 1;
    for (j = 1; j < m; j++)
      if (i != j && !f[j]) {
        qq = set_intersection(a[i].begin(), a[i].end(), a[j].begin(),
                              a[j].end(), p) -
             p;
        if (qq > n)
          n = qq, ans = 1;
        else if (qq == n)
          ans++;
      }
    cout << sss[i] << ' ' << ans << endl;
  }
}
