#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int k = 0;
string s[10005];
vector<int> fr[10005];
int fm[10005], opt[10005];
bool f[10005];
int cal(int a) {
  int i, j, res = 0, ans = 0, cnt = 0;
  memset(f, 0, sizeof(f));
  for (i = 0; i < fr[a].size(); ++i) f[fr[a][i]] = 1;
  f[a] = 1;
  for (i = 1; i <= k; ++i) {
    if (f[i]) continue;
    ans = 0;
    for (j = 0; j < fr[i].size(); ++j)
      if (f[fr[i][j]]) ++ans;
    if (ans > res) {
      res = ans;
      cnt = 1;
    } else if (ans == res)
      ++cnt;
  }
  return cnt;
}
int main() {
  int m, i;
  string a, b;
  char sa[30], sb[30];
  scanf("%d", &m);
  while (m--) {
    scanf("%s%s", sa, sb);
    a = sa;
    b = sb;
    if (mp[a] == 0) mp[a] = ++k, s[k] = a;
    if (mp[b] == 0) mp[b] = ++k, s[k] = b;
    int u = mp[a], v = mp[b];
    fr[u].push_back(v);
    fr[v].push_back(u);
  }
  printf("%d\n", k);
  for (i = 1; i <= k; ++i) printf("%s %d\n", s[i].c_str(), cal(i));
  return 0;
}
