#include <bits/stdc++.h>
using namespace std;
const int INF32 = int(1e9);
void deb() {}
int m;
unordered_map<string, int> um;
vector<string> inv;
vector<vector<int>> gr;
void add(string s) {
  if (!um.count(s)) {
    um[s] = um.size();
    inv[um[s]] = s;
  }
}
int main() {
  cin >> m;
  gr.resize(2 * m);
  inv.resize(2 * m);
  for (int i = 0; i < m; ++i) {
    string a, b;
    cin >> a >> b;
    add(a);
    add(b);
    int aid = um[a], bid = um[b];
    gr[aid].push_back(bid);
    gr[bid].push_back(aid);
  }
  int n = int((um).size());
  cout << n << endl;
  for (int i = 0; i < n; ++i) {
    vector<int> cnt(n, 0);
    vector<bool> IsFriends(n, false);
    IsFriends[i] = true;
    cnt[i] = -1;
    for (int j = 0; j < int((gr[i]).size()); ++j)
      IsFriends[gr[i][j]] = true, cnt[gr[i][j]] = -1;
    for (int j = 0; j < int((gr[i]).size()); ++j) {
      int m = gr[i][j];
      for (int k = 0; k < int((gr[m]).size()); ++k) {
        int to = gr[m][k];
        if (to == i || IsFriends[to]) continue;
        ++cnt[to];
      }
    }
    int most = 0, num = 0;
    for (int j = 0; j < n; ++j) {
      if (cnt[j] > most) {
        most = cnt[j];
        num = 1;
      } else if (cnt[j] == most)
        num++;
    }
    cout << inv[i] << " " << num << endl;
  }
  return 0;
}
