#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
map<string, int> ma;
vector<int> ve[10001];
bool fl[10001][10001];
string s[10001];
int num[10001];
int main() {
  int n;
  while (cin >> n) {
    ma.clear();
    memset(fl, 0, sizeof(fl));
    string s1, s2;
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
      cin >> s1 >> s2;
      if (ma[s1] == 0) ma[s1] = ++cnt;
      if (ma[s2] == 0) ma[s2] = ++cnt;
      int u, v;
      u = ma[s1], v = ma[s2];
      s[u] = s1, s[v] = s2;
      ve[u].push_back(v);
      ve[v].push_back(u);
      fl[u][v] = fl[v][u] = 1;
    }
    cout << cnt << endl;
    for (int i = 1; i <= cnt; ++i) {
      memset(num, 0, sizeof(num));
      int size = ve[i].size();
      for (int j = 0; j < size; ++j) {
        int v2 = ve[i][j];
        int size2 = ve[v2].size();
        for (int k = 0; k < size2; ++k) {
          num[ve[v2][k]]++;
        }
      }
      int ma = 0, ans = 0;
      for (int j = 1; j <= cnt; ++j) {
        if (!fl[i][j] && j != i) {
          if (num[j] > ma) {
            ma = num[j];
            ans = 1;
          } else if (num[j] == ma) {
            ans++;
          }
        }
      }
      cout << s[i] << ' ' << ans << endl;
    }
  }
  return 0;
}
