#include <bits/stdc++.h>
using namespace std;
const int maxv = 10001;
map<string, int> tidx;
map<int, int> fp[maxv];
struct Edge {
  int to, next;
} edge[maxv * 2];
int m, idx, head[maxv], ednum, deg[maxv];
char tmp[22];
bool mp[maxv][maxv];
void addedge(int u, int v) {
  edge[ednum] = Edge{v, head[u]};
  head[u] = ednum++;
  edge[ednum] = Edge{u, head[v]};
  head[v] = ednum++;
}
void cal(int u) {
  int i, j, vi, vj;
  deg[u] = 1;
  for (i = head[u]; i != -1; i = edge[i].next) {
    deg[u]++;
    for (j = edge[i].next; j != -1; j = edge[j].next) {
      vi = edge[i].to;
      vj = edge[j].to;
      if (!mp[vi][vj] && !mp[vj][vi]) fp[vi][vj] += 1, fp[vj][vi] += 1;
    }
  }
}
int main() {
  int a, b, i, maxv, num;
  string u, v;
  memset(head, -1, sizeof(head));
  map<string, int>::iterator it;
  map<int, int>::iterator jt;
  idx = ednum = 0;
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%s", tmp);
    u = tmp;
    scanf("%s", tmp);
    v = tmp;
    if (tidx.find(u) == tidx.end())
      tidx[u] = a = idx++;
    else
      a = tidx[u];
    if (tidx.find(v) == tidx.end())
      tidx[v] = b = idx++;
    else
      b = tidx[v];
    mp[a][b] = mp[b][a] = true;
    addedge(a, b);
  }
  printf("%d\n", idx);
  for (i = 0; i < idx; i++) cal(i);
  for (it = tidx.begin(); it != tidx.end(); it++) {
    i = it->second;
    maxv = 0, num = idx - fp[i].size() - deg[i];
    for (jt = fp[i].begin(); jt != fp[i].end(); jt++) {
      if (jt->second > maxv) {
        maxv = jt->second;
        num = 1;
      } else if (jt->second == maxv)
        num++;
    }
    printf("%s %d\n", it->first.c_str(), num);
  }
  return 0;
}
