#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
int N;
int K = 0;
map<string, int> n2i;
bool grid[(10 * 1024)][(10 * 1024)];
vector<string> i2n;
set<int> adj[(10 * 1024)];
int geti(const string &str) {
  auto it = n2i.find(str);
  if (it == n2i.end()) {
    i2n.push_back(str);
    return n2i[str] = K++;
  }
  return it->second;
}
int main() {
  i2n.reserve((10 * 1024));
  cin >> N;
  for (int i = (0); i < (N); i++) {
    string sa, sb;
    cin >> sa >> sb;
    int a = geti(sa);
    int b = geti(sb);
    adj[a].insert(b);
    adj[b].insert(a);
    grid[a][b] = grid[b][a] = true;
  }
  printf("%d\n", K);
  vector<int> tmp;
  tmp.reserve((10 * 1024));
  for (int a = (0); a < (K); a++) {
    int cnt = 0;
    int best = -1;
    for (int b = (0); b < (K); b++)
      if (a != b) {
        if (grid[a][b]) continue;
        if (int((adj[b]).size()) < best) continue;
        tmp.resize(0);
        set_intersection((adj[a]).begin(), (adj[a]).end(), (adj[b]).begin(),
                         (adj[b]).end(), back_inserter(tmp));
        int s = int((tmp).size());
        if (s == best)
          cnt++;
        else if (s > best)
          best = s, cnt = 1;
      }
    printf("%s %d\n", i2n[a].c_str(), cnt);
  }
}
