#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
vector<int> add[10005];
int vis[10005], inter[10005];
int cnt[10005] = {0};
int main() {
  int index = 1, j, m, fa, fb, max1, ans, temp;
  scanf("%d", &m);
  while (m--) {
    string a, b;
    cin >> a >> b;
    if (mp[a] == 0) mp[a] = index++;
    if (mp[b] == 0) mp[b] = index++;
    add[mp[a]].push_back(mp[b]);
    add[mp[b]].push_back(mp[a]);
  }
  for (int i = 1; i < index; i++) {
    sort(add[i].begin(), add[i].end());
  }
  for (int i = 1; i < index; i++) {
    ans = 0;
    max1 = 0;
    memset(vis, 0, sizeof(vis));
    for (j = 0; j < add[i].size(); j++) vis[add[i][j]] = 1;
    for (j = 1; j < index; j++) {
      if (vis[j] || i == j) continue;
      temp = set_intersection(add[i].begin(), add[i].end(), add[j].begin(),
                              add[j].end(), inter) -
             inter;
      if (temp > max1) {
        ans = 1;
        max1 = temp;
      } else if (temp == max1) {
        ans++;
      }
    }
    cnt[i] = ans;
  }
  printf("%d\n", index - 1);
  for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    cout << it->first << " " << cnt[it->second] << "\n";
  }
  return 0;
}
