#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 10;
int m;
int cnt;
map<string, int> ps;
set<int> st[maxn];
set<int>::iterator it;
string pr[maxn];
string s, ss;
int a[maxn];
int main() {
  cnt = 0;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    cin >> s >> ss;
    if (ps[s] == 0) {
      ps[s] = ++cnt;
      pr[cnt] = s;
    }
    if (ps[ss] == 0) {
      ps[ss] = ++cnt;
      pr[cnt] = ss;
    }
    int a = ps[s], b = ps[ss];
    st[a].insert(b);
    st[b].insert(a);
  }
  for (int i = 1; i <= cnt; i++) {
    int ans = -1;
    int sum = 0;
    for (int j = 1; j <= cnt; j++) {
      if (i == j) continue;
      if (st[i].find(j) != st[i].end()) continue;
      int cnt = 0;
      for (it = st[j].begin(); it != st[j].end(); it++) {
        if (st[i].find(*it) != st[i].end()) cnt++;
      }
      if (cnt > ans)
        ans = cnt, sum = 1;
      else if (cnt == ans)
        sum++;
    }
    a[i] = sum;
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) {
    cout << pr[i];
    printf(" %d\n", a[i]);
  }
  return 0;
}
