#include <bits/stdc++.h>
using namespace std;
string s[10005];
map<string, int> Hash;
vector<int> vt[10005];
int vis[10005];
void dfs(int s, int fa) {
  for (int i = 0; i < vt[s].size(); ++i) {
    int j = vt[s][i];
    if (j == fa) continue;
    if (fa != s) ++vis[j];
    if (fa == s) dfs(j, fa);
  }
}
int main() {
  int m, n = 0;
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    cin >> s[10001] >> s[10002];
    if (!Hash[s[10001]]) s[++n] = s[10001], Hash[s[n]] = n;
    if (!Hash[s[10002]]) s[++n] = s[10002], Hash[s[n]] = n;
    int u = Hash[s[10001]], v = Hash[s[10002]];
    vt[u].push_back(v);
    vt[v].push_back(u);
  }
  cout << n << endl;
  for (int i = 1; i <= n; ++i) {
    memset(vis, 0, sizeof(vis));
    dfs(i, i);
    for (int j = 0; j < vt[i].size(); ++j) vis[vt[i][j]] = 0;
    int ans = 0, num = 0;
    for (int j = 1; j <= n; ++j)
      if (vis[j]) {
        if (vis[j] > ans)
          ans = vis[j], num = 1;
        else if (vis[j] == ans)
          ++num;
      }
    if (num == 0) num = n - 1 - vt[i].size();
    cout << s[i] << ' ' << num << endl;
  }
}
