#include <bits/stdc++.h>
using namespace std;
bool matAdj[10002][10002];
bool isFriend[10002];
int main() {
  string x, y;
  vector<string> toString;
  map<string, int> toInt;
  memset(matAdj, 0, sizeof(matAdj));
  vector<vector<int> > adjL;
  int n, u, v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (toInt.insert(make_pair(x, toString.size())).second) {
      toString.push_back(x);
      adjL.push_back(*new vector<int>());
    }
    if (toInt.insert(make_pair(y, toString.size())).second) {
      toString.push_back(y);
      adjL.push_back(*new vector<int>());
    }
    u = toInt[x];
    v = toInt[y];
    matAdj[u][v] = 1;
    matAdj[v][u] = 1;
    adjL[u].push_back(v);
    adjL[v].push_back(u);
  }
  int N = adjL.size();
  cout << N << endl;
  for (int i = 0; i < N; i++) {
    int v = 0, q = 0;
    memset(isFriend, 0, sizeof(isFriend));
    for (int j = 0; j < adjL[i].size(); j++) isFriend[adjL[i][j]] = true;
    for (int k = 0; k < adjL.size(); k++) {
      if (i != k && !matAdj[i][k]) {
        int a = 0;
        for (int j = 0; j < adjL[k].size(); j++) {
          if (isFriend[adjL[k][j]]) a++;
        }
        if (a > v) {
          v = a;
          q = 1;
        } else if (a == v) {
          q++;
        }
      }
    }
    cout << toString[i] << " " << q << endl;
  }
  return 0;
}
