#include <bits/stdc++.h>
using namespace std;
int _;
const int MAXN = 10055;
const int INF = 20 * 1000;
int m;
map<string, int> mp;
map<int, string> mp2;
string s[MAXN][2];
short int d[MAXN][MAXN];
vector<int> v[MAXN];
int main() {
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> s[i][0] >> s[i][1];
    mp[s[i][0]] = mp[s[i][1]] = 0;
  }
  int n = 0;
  for (__typeof((mp).begin()) it = (mp).begin(); it != (mp).end(); ++it) {
    mp2[n] = it->first;
    it->second = n++;
  }
  for (int i = 0; i < m; ++i) {
    int a = mp[s[i][0]], b = mp[s[i][1]];
    v[a].push_back(b);
    v[b].push_back(a);
    d[a][b] = d[b][a] = -INF;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < ((int)(v[i]).size()); ++j)
      for (int k = j + 1; k < ((int)(v[i]).size()); ++k)
        d[v[i][j]][v[i][k]]++, d[v[i][k]][v[i][j]]++;
  }
  cout << n << endl;
  for (int i = 0; i < n; ++i) {
    int mx = 0, cnt = 0;
    d[i][i] = -INF;
    for (int j = 0; j < n; ++j)
      if (d[i][j] > mx)
        mx = d[i][j], cnt = 1;
      else if (d[i][j] == mx)
        ++cnt;
    cout << mp2[i] << " " << cnt << endl;
  }
  return 0;
}
