#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
bool cnc[10001][10001];
int main() {
  int i, j, n, k, p, a, b, mx, mf, tx, tf;
  string x, y;
  map<string, int>::iterator it;
  p = 1;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x >> y;
    if (m.count(x) > 0)
      a = m[x];
    else {
      m[x] = p++;
      a = p - 1;
    }
    if (m.count(y) > 0)
      b = m[y];
    else {
      m[y] = p++;
      b = p - 1;
    }
    cnc[a][b] = 1;
    cnc[b][a] = 1;
  }
  int ans[p + 1];
  vector<int> v[p + 1];
  for (i = 1; i < p; i++) {
    ans[i] = 0;
    for (j = 1; j < p; j++)
      if (i != j && cnc[i][j]) v[i].push_back(j);
  }
  for (i = 1; i < p; i++) {
    mx = 0;
    mf = 0;
    for (j = 1; j < p; j++) {
      tx = tf = 0;
      if (j != i && !cnc[i][j]) {
        for (k = 0; k < v[j].size(); k++)
          if (cnc[v[j][k]][i]) tx++;
        if (tx > mx) {
          mf = 1;
          mx = tx;
        } else if (tx == mx)
          mf++;
      }
    }
    ans[i] = mf;
  }
  cout << (p - 1) << endl;
  for (it = m.begin(); it != m.end(); it++)
    cout << (*it).first << " " << ans[(*it).second] << endl;
}
