#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
const double pi = 3.14159265358979323;
const double eps = 1e-8;
const int N = 11111;
vector<int> vec[N];
map<string, int> id;
int n, m;
int cnt[N];
int ans[N];
bool aFriend[N];
void work(int a) {
  memset(cnt, 0, sizeof(cnt));
  memset(aFriend, false, sizeof(aFriend));
  aFriend[a] = true;
  for (int i = 0; i < vec[a].size(); i++) {
    int b = vec[a][i];
    aFriend[b] = true;
  }
  int maxNumber = 0;
  for (int i = 1; i <= n; i++) {
    if (aFriend[i]) continue;
    for (int j = 0; j < vec[i].size(); j++) {
      if (aFriend[vec[i][j]]) cnt[i]++;
    }
    maxNumber = max(maxNumber, cnt[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (!aFriend[i] && cnt[i] == maxNumber) ans[a]++;
  }
}
int main() {
  while (cin >> m) {
    n = 0;
    id.clear();
    for (int i = 0; i < N; i++) vec[i].clear();
    for (int i = 0; i < m; i++) {
      string a, b;
      int u, v;
      cin >> a >> b;
      if (id[a] == 0) {
        id[a] = ++n;
      }
      u = id[a];
      if (id[b] == 0) {
        id[b] = ++n;
      }
      v = id[b];
      vec[u].push_back(v);
      vec[v].push_back(u);
    }
    cout << n << endl;
    memset(ans, 0, sizeof(ans));
    for (int i = 1; i <= n; i++) {
      work(i);
    }
    for (map<string, int>::iterator it = id.begin(); it != id.end(); it++) {
      cout << it->first << " " << ans[it->second] << endl;
    }
  }
  return 0;
}
