#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = 1000 * 1000 * 1000;
const double EPS = 1e-9;
const int MAXN = 2 * 5000 + 1;
vector<vector<int> > g;
bitset<MAXN> fr[MAXN];
short cnt[MAXN][MAXN];
int main() {
  int M;
  cin >> M;
  g.resize(2 * M);
  map<string, int> q;
  for (int i = 0; i < M; ++i) {
    string name1, name2;
    cin >> name1 >> name2;
    q.insert(make_pair(name1, (int)q.size()));
    q.insert(make_pair(name2, (int)q.size()));
    fr[q[name1]][q[name2]] = fr[q[name2]][q[name1]] = true;
    g[q[name1]].push_back(q[name2]);
    g[q[name2]].push_back(q[name1]);
  }
  map<int, string> inv;
  for (map<string, int>::iterator it = q.begin(); it != q.end(); ++it) {
    inv.insert(make_pair(it->second, it->first));
  }
  int N = (int)q.size();
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < (int)g[i].size(); ++j)
      for (int k = 0; k < (int)g[i].size(); ++k)
        if (j != k) {
          ++cnt[g[i][j]][g[i][k]];
          ++cnt[g[i][k]][g[i][j]];
        }
  cout << N << endl;
  for (int i = 0; i < N; ++i) {
    cout << inv[i] << " ";
    int q = 0;
    int val = 0;
    for (int j = 0; j < N; ++j)
      if (!fr[i][j] && i != j)
        if (cnt[i][j] > val) {
          val = cnt[i][j];
          q = 1;
        } else if (cnt[i][j] == val) {
          val = cnt[i][j];
          ++q;
        }
    cout << q << endl;
  }
  return 0;
}
