#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 10000 + 10;
vector<int> v[MAX_N];
int n = 0, m = 0;
map<string, int> M;
int get_int(string s) {
  if (M.find(s) == M.end()) {
    M[s] = n;
    n++;
  }
  return M[s];
}
short int a[MAX_N][MAX_N];
int ans[MAX_N];
int main() {
  cin >> m;
  for (int i = 0; i < m; i++) {
    string s, t;
    cin >> s >> t;
    int X = get_int(s), Y = get_int(t);
    v[X].push_back(Y);
    v[Y].push_back(X);
    a[X][Y] = a[Y][X] = -1;
  }
  for (int i = 0; i < n; i++) {
    for (int r1 = 0; r1 < (int)v[i].size(); r1++) {
      int j = v[i][r1];
      for (int r2 = 0; r2 < (int)v[j].size(); r2++) {
        int l = v[j][r2];
        if (j != i && j != l && l != i && a[l][i] != -1) a[i][l]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int best = -1;
    ans[i] = 0;
    for (int j = 0; j < n; j++)
      if (i != j && a[i][j] != -1)
        if (a[i][j] > best) best = a[i][j];
    for (int j = 0; j < n; j++)
      if (i != j && a[i][j] != -1)
        if (a[i][j] == best) ans[i]++;
  }
  cout << n << endl;
  for (map<string, int>::iterator it = M.begin(); it != M.end(); it++)
    cout << (it->first) << " " << ans[it->second] << endl;
  return 0;
}
