#include <bits/stdc++.h>
using namespace std;
map<string, int> s;
string s1, s2, name[10010];
vector<int> e[10010];
int n, m;
int t, c, cnt;
int Exist(int x, int y) {
  int n = e[y].size();
  for (int i = 0; i < n; i++)
    if (e[y][i] == x) return 1;
  return 0;
}
int Get(int x, int y) {
  int n = e[x].size(), m = e[y].size();
  int cnt = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (e[x][i] == e[y][j]) cnt++;
  return cnt;
}
int main() {
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    cin >> s1 >> s2;
    if (s[s1] == 0) s[s1] = ++n, name[n] = s1;
    if (s[s2] == 0) s[s2] = ++n, name[n] = s2;
    e[s[s1]].push_back(s[s2]);
    e[s[s2]].push_back(s[s1]);
  }
  printf("%d\n", n);
  for (int i = 1; i <= n; i++) {
    t = c = 0;
    for (int j = 1; j <= n; j++)
      if (j != i && Exist(j, i) == 0) {
        cnt = Get(i, j);
        if (cnt > t)
          t = cnt, c = 1;
        else if (cnt == t)
          c++;
      }
    cout << name[i] << " " << c << endl;
  }
}
