#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n = 0, u, v;
  map<string, int> frend;
  vector<vector<int> > g(10010, vector<int>(0, 0));
  scanf("%d", &m);
  char s1[25], s2[25];
  for (int i = 0; i < m; i++) {
    scanf("%s %s", s1, s2);
    string s_1(s1), s_2(s2);
    if (!frend.count(s_1)) frend[s_1] = (++n);
    if (!frend.count(s_2)) frend[s_2] = (++n);
    u = frend[s_1];
    v = frend[s_2];
    g[u].push_back(v);
    g[v].push_back(u);
  }
  printf("%d\n", n);
  int num, maxx;
  for (map<string, int>::iterator it = frend.begin(); it != frend.end(); it++) {
    vector<int> ans(10010, 0);
    num = (it->second);
    for (int i = 0; i < g[num].size(); i++) {
      int u = g[num][i];
      for (int j = 0; j < g[u].size(); j++) ans[g[u][j]]++;
    }
    for (int i = 0; i < g[num].size(); i++) ans[g[num][i]] = -1;
    ans[num] = -1;
    maxx = *max_element(ans.begin(), ans.begin() + n + 1);
    int ans_k = 0;
    for (int i = 1; i <= n; i++)
      if (ans[i] == maxx) ans_k++;
    printf("%s %d\n", (it->first).c_str(), ans_k);
  }
  return 0;
}
