#include <bits/stdc++.h>
using namespace std;
struct user {
  string name;
  int *friends, fc;
  bool isFriendsWith[10010];
  set<int> friendSet;
  user() {
    memset(isFriendsWith, 0, sizeof(isFriendsWith));
    fc = 0;
  }
  ~user() { delete[] friends; }
  void setToArray() {
    friends = new int[friendSet.size()];
    for (set<int>::iterator it = friendSet.begin(); it != friendSet.end();
         it++) {
      friends[fc++] = *it;
    }
  }
};
map<string, int> mapping;
int distinct;
void solve() {
  int m, a, b;
  distinct = 0;
  scanf("%d", &m);
  user users[2 * m];
  for (int i = 0; i < m; i++) {
    char buf1[30], buf2[30];
    scanf("%s %s", buf1, buf2);
    string u1(buf1), u2(buf2);
    if (((mapping).find(u1) != (mapping).end())) {
      a = mapping[u1];
    } else {
      a = distinct++;
      mapping[u1] = a;
      users[a].name = u1;
    }
    if (((mapping).find(u2) != (mapping).end())) {
      b = mapping[u2];
    } else {
      b = distinct++;
      mapping[u2] = b;
      users[b].name = u2;
    }
    users[a].friendSet.insert(b);
    users[b].friendSet.insert(a);
    users[a].isFriendsWith[b] = true;
    users[b].isFriendsWith[a] = true;
    if (0) {
      cout << u1 << " -> " << a << endl;
      cout << u2 << " -> " << b << endl;
    }
  }
  for (int i = 0; i < distinct; i++) {
    users[i].setToArray();
  }
  if (0) {
    cout << "distinct = " << distinct << endl;
  }
  printf("%d\n", distinct);
  int *f, fSize, *f2, fSize2, goTo[distinct], max, maxCnt;
  for (int i = 0; i < distinct; i++) {
    fSize = users[i].fc;
    f = users[i].friends;
    memset(goTo, 0, sizeof(goTo));
    max = -1;
    maxCnt = 0;
    for (int j = 0; j < fSize; j++) {
      f2 = users[f[j]].friends;
      fSize2 = users[f[j]].fc;
      for (int k = 0; k < fSize2; k++) {
        if (f2[k] == i || users[i].isFriendsWith[f2[k]]) {
          continue;
        }
        goTo[f2[k]]++;
        if (goTo[f2[k]] > max) {
          max = goTo[f2[k]];
          maxCnt = 1;
        } else if (goTo[f2[k]] == max) {
          maxCnt++;
        }
      }
    }
    if (max == -1) {
      maxCnt = distinct - 1 - users[i].friendSet.size();
    }
    printf("%s %d\n", users[i].name.c_str(), maxCnt);
  }
}
int main() {
  solve();
  return 0;
}
