#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000007);
const int INF((1 << 30) - 1);
const int MAXN(10005);
map<string, int> name;
vector<int> a[MAXN];
bool mark[MAXN];
int ans[MAXN];
int main() {
  int n = 0, m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    if (!name[s1]) name[s1] = (++n);
    if (!name[s2]) name[s2] = (++n);
    int u = name[s1], v = name[s2];
    a[u].push_back(v);
    a[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= n; j++) mark[j] = 0;
    for (int j = 0; j < a[i].size(); j++) mark[a[i][j]] = 1;
    for (int j = 1; j <= n; j++) {
      if (j == i || mark[j]) continue;
      int tmp = 0;
      for (int k = 0; k < a[j].size(); k++) tmp += mark[a[j][k]];
      if (tmp > ans[i]) {
        ans[i] = tmp;
        cnt = 1;
      } else if (tmp == ans[i])
        cnt++;
    }
    ans[i] = cnt;
  }
  printf("%d\n", n);
  for (typeof(name.begin()) it = name.begin(); it != name.end(); it++)
    cout << it->first << " " << ans[it->second] << endl;
}
