#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int maxlog = 22;
const int mod = 1e9 + 7;
const int sq = 350;
map<string, int> m;
string str[maxn];
vector<int> edge[maxn];
int cnt[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(20);
  int n = 1;
  int k;
  cin >> k;
  while (k--) {
    string s, t;
    cin >> s >> t;
    if (!m[s]) {
      m[s] = n;
      str[n] = s;
      n++;
    }
    if (!m[t]) {
      m[t] = n;
      str[n] = t;
      n++;
    }
    edge[m[s]].push_back(m[t]);
    edge[m[t]].push_back(m[s]);
  }
  cout << n - 1 << endl;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) cnt[j] = 0;
    cnt[i] = -1;
    for (int j = 0; j < edge[i].size(); j++) {
      int k = edge[i][j];
      cnt[k] = -1;
    }
    for (int j = 0; j < edge[i].size(); j++) {
      int u = edge[i][j];
      for (int k = 0; k < edge[u].size(); k++) {
        int v = edge[u][k];
        if (cnt[v] != -1) cnt[v]++;
      }
    }
    int res = 0, maxi = -1;
    for (int j = 1; j < n; j++) {
      if (cnt[j] > maxi) res = 0;
      maxi = max(maxi, cnt[j]);
      if (cnt[j] == maxi) res++;
    }
    if (maxi != -1)
      cout << str[i] << " " << res << endl;
    else
      cout << str[i] << " " << 0 << endl;
  }
  return 0;
}
