#include <bits/stdc++.h>
using namespace std;
map<string, int> mapa;
string ime[10001];
bool mat[10001][10001];
vector<vector<int> > v(100001);
int main() {
  int m;
  cin >> m;
  int n = 0;
  for (int i = 0; i < m; i++) {
    string a, b;
    cin >> a >> b;
    if (mapa.find(a) == mapa.end()) mapa[a] = n++;
    if (mapa.find(b) == mapa.end()) mapa[b] = n++;
    int teme1 = mapa[a];
    int teme2 = mapa[b];
    ime[teme1] = a;
    ime[teme2] = b;
    mat[teme1][teme2] = true;
    mat[teme2][teme1] = true;
    v[teme1].push_back(teme2);
    v[teme2].push_back(teme1);
  }
  cout << n << endl;
  for (int i = 0; i < n; i++) {
    cout << ime[i] << " ";
    int res = 0;
    int naj = 0;
    for (int j = 0; j < n; j++) {
      if (mat[i][j] == false && i != j) {
        int kolku_ima = 0;
        for (int k = 0; k < v[j].size(); k++)
          if (mat[i][v[j][k]] == true) kolku_ima++;
        if (kolku_ima > naj) {
          naj = kolku_ima;
          res = 1;
        } else if (kolku_ima == naj)
          res++;
      }
    }
    cout << res << endl;
  }
  return 0;
}
