#include <bits/stdc++.h>
using namespace std;
vector<string> users;
int getUserId(string s) {
  for (int i = (0); i < (users.size()); i++) {
    if (users[i] == s) return i;
  }
  users.push_back(s);
  return users.size() - 1;
}
vector<int> g[10007];
bool isFriend[10007];
int common[10007];
int main() {
  int M;
  scanf("%d ", &M);
  ;
  for (int i = (0); i < (M); i++) {
    string a, b;
    cin >> a >> b;
    int ai = getUserId(a);
    int bi = getUserId(b);
    g[ai].push_back(bi);
    g[bi].push_back(ai);
  }
  int N = users.size();
  cout << N << endl;
  for (int i = (0); i < (N); i++) {
    memset((isFriend), (false), sizeof((isFriend)));
    for (int j = (0); j < (g[i].size()); j++) {
      int u = g[i][j];
      isFriend[u] = true;
    }
    int mx = 0;
    int cnt = 0;
    for (int v = (0); v < (N); v++) {
      if (v == i) continue;
      if (isFriend[v]) continue;
      int comm = 0;
      for (int j = (0); j < (g[v].size()); j++) {
        int u = g[v][j];
        if (isFriend[u]) comm++;
      }
      if (comm > mx) {
        mx = comm;
        cnt = 1;
      } else if (comm == mx)
        cnt++;
    }
    cout << users[i] << " " << cnt << endl;
  }
  return 0;
}
