#include <bits/stdc++.h>
using namespace std;
const int MaxM = 1 << 14;
int M;
bool Mark[MaxM];
string A, B;
map<string, int> Hash;
map<int, string> ReverseHash;
vector<int> E[MaxM];
int main(void) {
  cin.sync_with_stdio(0);
  cin >> M;
  int HashValue = 0;
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    if (!Hash[A]) {
      Hash[A] = ++HashValue;
      ReverseHash[HashValue] = A;
    }
    if (!Hash[B]) {
      Hash[B] = ++HashValue;
      ReverseHash[HashValue] = B;
    }
    int idx = Hash[A], idy = Hash[B];
    E[idx].push_back(idy);
    E[idy].push_back(idx);
  }
  for (int i = 1; i <= HashValue; i++) sort(E[i].begin(), E[i].end());
  cout << HashValue << endl;
  for (int i = 1; i <= HashValue; i++) {
    memset(Mark, false, sizeof(Mark));
    Mark[i] = true;
    for (vector<int>::iterator it = E[i].begin(); it != E[i].end(); it++)
      Mark[*it] = true;
    int Max = -(1 << 30), Cnt = 0;
    for (int j = 1; j <= HashValue; j++) {
      if (Mark[j]) continue;
      vector<int>::iterator idx = E[i].begin(), idy = E[j].begin();
      int Curr = 0;
      while ((idx != E[i].end()) && (idy != E[j].end())) {
        if (*idx == *idy) {
          Curr++;
          idx++;
          idy++;
        } else if (*idx < *idy)
          idx++;
        else
          idy++;
      }
      if (Curr == Max)
        Cnt++;
      else if (Curr > Max) {
        Max = Curr;
        Cnt = 1;
      }
    }
    cout << ReverseHash[i] << " " << Cnt << endl;
  }
  return 0;
}
