#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> ship[N];
map<string, int> name;
int m;
string x, y;
int ans[N];
int flag[N];
int main() {
  std::ios::sync_with_stdio(false);
  cin >> m;
  int ix, iy, tot = 0;
  map<string, int>::iterator iter;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    iter = name.find(x);
    if (iter != name.end())
      ix = iter->second;
    else
      name.insert(pair<string, int>(x, ix = ++tot));
    iter = name.find(y);
    if (iter != name.end())
      iy = iter->second;
    else
      name.insert(pair<string, int>(y, iy = ++tot));
    ship[ix].push_back(iy);
    ship[iy].push_back(ix);
  }
  cout << tot << endl;
  for (int i = 1; i <= tot; i++) {
    int suggest_friends = 0;
    memset(flag, 0, sizeof(flag));
    for (int j = 0; j < ship[i].size(); j++) flag[ship[i][j]] = 1;
    for (int j = 1; j <= tot; j++) {
      if (i == j) continue;
      if (!flag[j]) {
        int both_friend = 0;
        for (int k = 0; k < ship[j].size(); k++) {
          if (flag[ship[j][k]]) both_friend++;
        }
        if (both_friend > ans[i]) {
          suggest_friends = 1;
          ans[i] = both_friend;
        } else if (both_friend == ans[i])
          suggest_friends++;
      }
    }
    ans[i] = suggest_friends;
  }
  for (iter = name.begin(); iter != name.end(); ++iter)
    cout << iter->first << " " << ans[iter->second] << endl;
  return 0;
}
