#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;
map<string, int> mp;
map<int, string> mpr;
map<int, int> mpi[10002];
int vis[10002];
vector<int> g[10003];
int f[10002];
vector<string> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n;
  cin >> n;
  int k = 1;
  string s, s1;
  for (int i = 0; i < n; ++i) {
    cin >> s >> s1;
    if (mp[s] == 0) {
      mp[s] = k;
      k++;
      v.push_back(s);
    }
    if (mp[s1] == 0) {
      mp[s1] = k;
      ;
      k++;
      v.push_back(s1);
    }
    g[mp[s]].push_back(mp[s1]);
    g[mp[s1]].push_back(mp[s]);
  }
  int ans = 0;
  cout << k - 1 << endl;
  for (int i = 1; i < k; ++i) {
    memset(vis, 0, sizeof(vis));
    for (int j = 0; j < g[i].size(); ++j) vis[g[i][j]] = 1;
    int ct = 0;
    int ma = 0;
    for (int j = 1; j < k; ++j) {
      if (j == i || vis[j] == 1) continue;
      ans = 0;
      for (int k = 0; k < g[j].size(); ++k) ans += vis[g[j][k]];
      if (ans > ma) {
        ma = ans;
        ct = 1;
      } else if (ans == ma)
        ct++;
    }
    f[i] = ct;
  }
  for (int i = 1; i < k; ++i) {
    cout << v[i - 1] << " " << f[i] << endl;
  }
}
