#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
map<string, int> mm;
const int maxn = 10010;
string who[maxn];
int getid(string s) {
  if (mm.count(s)) return mm[s];
  int cc = int((mm).size());
  mm[s] = cc;
  who[cc] = s;
  return cc;
}
set<pair<int, int> > edges;
vector<int> a[maxn];
int bestnum[maxn];
int ans[maxn];
int main() {
  memset(bestnum, -1, sizeof(bestnum));
  memset(ans, 0, sizeof(ans));
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    string p1, p2;
    cin >> p1 >> p2;
    int i1 = getid(p1), i2 = getid(p2);
    edges.insert(make_pair(i1, i2));
    edges.insert(make_pair(i2, i1));
    a[i1].push_back(i2);
    a[i2].push_back(i1);
  }
  int n = int((mm).size());
  vector<pair<int, int> > v;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < int((a[i]).size()); ++j) {
      for (int k = 0; k < int((a[i]).size()); ++k) {
        if (j == k) continue;
        int to1 = a[i][j];
        int to2 = a[i][k];
        if (!edges.count(make_pair(to1, to2))) {
          v.push_back(make_pair(to1, to2));
        }
      }
    }
  }
  sort(v.begin(), v.end());
  vector<pair<pair<int, int>, int> > res;
  for (int i = 0; i < int((v).size()); ++i) {
    if (res.empty() || res.back().first != v[i])
      res.push_back(make_pair(v[i], 1));
    else
      res.back().second++;
  }
  for (int i = 0; i < int((res).size()); ++i) {
    bestnum[res[i].first.first] =
        max(bestnum[res[i].first.first], res[i].second);
  }
  for (int i = 0; i < int((res).size()); ++i) {
    if (bestnum[res[i].first.first] == res[i].second) ans[res[i].first.first]++;
  }
  for (int i = 0; i < n; ++i) {
    if (ans[i] == 0) ans[i] = n - 1 - int((a[i]).size());
  }
  printf("%d\n", n);
  for (int i = 0; i < n; ++i) cout << who[i] << " " << ans[i] << "\n";
  return 0;
}
