#include <bits/stdc++.h>
using namespace std;
int n, m, cnt[10005];
vector<int> adj[10005];
string name[10005];
map<string, int> idx;
char s1[50], s2[50];
int getIndex(string s) {
  if (idx.count(s)) return idx[s];
  idx[s] = ++n;
  name[n] = s;
  return n;
}
int main() {
  int u, v;
  n = 0;
  scanf(" %d ", &m);
  while (m--) {
    scanf(" %s %s ", s1, s2);
    u = getIndex(s1);
    v = getIndex(s2);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  printf("%d\n", n);
  for (int i = (1), _b = (n); i <= _b; i++) {
    for (int j = (1), _b = (n); j <= _b; j++) cnt[j] = 0;
    cnt[i] = -1;
    for (int j = 0, _n = (adj[i].size()); j < _n; j++) cnt[adj[i][j]] = -1;
    for (int j = 0, _n = (adj[i].size()); j < _n; j++) {
      v = adj[i][j];
      for (int k = 0, _n = (adj[v].size()); k < _n; k++) {
        u = adj[v][k];
        if (u != i && cnt[u] != -1) {
          cnt[u]++;
        }
      }
    }
    int most = 0, num = 0;
    for (int j = (1), _b = (n); j <= _b; j++) {
      if (cnt[j] > most) {
        most = cnt[j];
        num = 1;
      } else if (cnt[j] == most)
        num++;
    }
    cout << name[i] << " " << num << endl;
  }
  return 0;
}
