#include <bits/stdc++.h>
using namespace std;
int n, cnt = 1;
vector<int> graph[11111];
map<string, int> idx;
map<int, string> idx2;
int ans[11111][2];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s1, s2;
    cin >> s1 >> s2;
    int i1, i2;
    if (idx[s1] == 0) {
      i1 = cnt;
      idx[s1] = cnt;
      idx2[cnt] = s1;
      cnt++;
    }
    if (idx[s2] == 0) {
      i2 = cnt;
      idx[s2] = cnt;
      idx2[cnt] = s2;
      cnt++;
    }
    i1 = idx[s1], i2 = idx[s2];
    graph[i1].push_back(i2);
    graph[i2].push_back(i1);
  }
  for (int i = 1; i < cnt; ++i) sort(graph[i].begin(), graph[i].end());
  for (int i = 1; i < cnt; ++i) {
    for (int j = 1; j < cnt; ++j) {
      if (i == j) continue;
      if (binary_search(graph[i].begin(), graph[i].end(), j)) continue;
      int a = 0, b = 0, ret = 0;
      while (a < graph[i].size() && b < graph[j].size()) {
        if (graph[i][a] == graph[j][b]) {
          ret++;
          a++;
          b++;
        } else if (graph[i][a] > graph[j][b])
          b++;
        else
          a++;
      }
      if (ret == ans[i][0]) ans[i][1]++;
      if (ret > ans[i][0]) {
        ans[i][0] = ret;
        ans[i][1] = 1;
      }
    }
  }
  cout << cnt - 1 << endl;
  for (int i = 1; i < cnt; ++i) {
    string nm = idx2[i];
    cout << nm << " " << ans[i][1] << endl;
  }
  return 0;
}
