#include <bits/stdc++.h>
using namespace std;
static const int MAX = 10001;
static map<int, string> iToN;
static map<string, int> nToI;
static set<int> g[MAX];
static map<int, unsigned short> common[MAX];
static int m, n = 0;
int toId(const string &str) {
  int id = nToI[str];
  if (id > 0) return id;
  id = ++n;
  nToI[str] = id;
  iToN[id] = str;
  return id;
}
int main() {
  cin >> m;
  for (int i = 0; i < m; ++i) {
    string a, b;
    cin >> a >> b;
    int idA = toId(a);
    int idB = toId(b);
    g[idA].insert(idB);
    g[idB].insert(idA);
  }
  for (int i = 1; i <= n; ++i) {
    for (set<int>::iterator a = g[i].begin(); a != g[i].end(); ++a) {
      set<int>::iterator b = a;
      while (++b != g[i].end()) {
        if (g[*a].count(*b) == 0) {
          common[*a][*b]++;
          common[*b][*a]++;
        }
      }
    }
  }
  cout << n << endl;
  for (int i = 1; i <= n; ++i) {
    unsigned short num = 0, ans = 0;
    if (common[i].empty()) {
      ans = n - g[i].size() - 1;
    } else {
      for (map<int, unsigned short>::iterator it = common[i].begin();
           it != common[i].end(); ++it) {
        num = max(num, it->second);
      }
      for (map<int, unsigned short>::iterator it = common[i].begin();
           it != common[i].end(); ++it) {
        if (it->second == num) {
          ++ans;
        }
      }
    }
    cout << iToN[i] << " " << ans << endl;
  }
  return 0;
}
