#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 10;
map<string, int> m;
map<int, string> m2;
int s[MAXN];
vector<pair<int, int> > v;
bitset<10010> g;
int main() {
  ios::sync_with_stdio(false);
  int n, cnt = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;
    if (m[a] == 0) m[a] = cnt++, m2[cnt - 1] = a;
    if (m[b] == 0) m[b] = cnt++, m2[cnt - 1] = b;
    int x = m[a], y = m[b];
    v.push_back({m[a], m[b]});
  }
  cnt--;
  cout << cnt << endl;
  for (int i = 1; i <= cnt; i++) {
    g = 0;
    for (pair<int, int> p : v)
      if (p.first == i)
        g[p.second] = 1;
      else if (p.second == i)
        g[p.first] = 1;
    memset(s, 0, sizeof s);
    for (pair<int, int> p : v) {
      if (g[p.first]) s[p.second]++;
      if (g[p.second]) s[p.first]++;
    }
    int ind = 0, ans = 0;
    for (int j = 1; j <= cnt; j++)
      if (g[j] == 0 and j != i and s[j] > s[ind]) ind = j;
    for (int j = 1; j <= cnt; j++)
      if (g[j] == 0 and j != i and s[j] == s[ind]) ans++;
    cout << m2[i] << " " << ans << "\n";
  }
  return 0;
}
