#include <bits/stdc++.h>
using namespace std;
const int N = int(1e4 + 5);
vector<int> g[N];
map<string, int> num;
string name[N];
int dp[N], cnt;
bool vis[N];
int main() {
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    int n1, n2;
    if (!num.count(s1)) {
      name[cnt] = s1;
      num[s1] = cnt++;
    }
    if (!num.count(s2)) {
      name[cnt] = s2;
      num[s2] = cnt++;
    }
    n1 = num[s1], n2 = num[s2];
    g[n1].push_back(n2);
    g[n2].push_back(n1);
  }
  cout << cnt << endl;
  for (int i = 0; i < cnt; i++) {
    memset(dp, 0, sizeof(dp));
    memset(vis, 0, sizeof(vis));
    for (int j = 0; j < (int)(g[i]).size(); j++) {
      int to = g[i][j];
      vis[to]++;
    }
    int mx = 0;
    for (int j = 0; j < cnt; j++)
      if (vis[j]) {
        for (int k = 0; k < (int)(g[j]).size(); k++) {
          int to = g[j][k];
          if (to != i && !vis[to]) {
            dp[to]++;
          }
        }
      }
    for (int j = 0; j < cnt; j++) mx = max(mx, dp[j]);
    int ans = 0;
    for (int j = 0; j < cnt; j++)
      if (dp[j] == mx) ans++;
    if (mx == 0) ans = cnt - 1 - (int)(g[i]).size();
    cout << name[i] << " " << ans << endl;
  }
  return 0;
}
