#include <bits/stdc++.h>
using namespace std;
int head[200005], size;
bool vis[200005];
struct Edge {
  int v, next;
  Edge() {}
  Edge(int V, int NEXT) : v(V), next(NEXT) {}
} edge[200005];
map<string, int> mp;
vector<string> name;
void Init() {
  size = 0;
  memset(head, -1, sizeof(head));
}
void InsertEdge(int u, int v) {
  edge[size] = Edge(v, head[u]);
  head[u] = size++;
}
int main() {
  int n, cnt = 0;
  string s1, s2;
  cin >> n;
  Init();
  while (n--) {
    cin >> s1 >> s2;
    if (mp.find(s1) == mp.end()) mp[s1] = cnt++, name.push_back(s1);
    if (mp.find(s2) == mp.end()) mp[s2] = cnt++, name.push_back(s2);
    InsertEdge(mp[s1], mp[s2]);
    InsertEdge(mp[s2], mp[s1]);
  }
  cout << cnt << endl;
  for (int i = 0; i < cnt; i++) {
    memset(vis, false, sizeof(vis));
    for (int j = head[i]; j != -1; j = edge[j].next) vis[edge[j].v] = true;
    vis[i] = true;
    int ans = 0, mmax = -1;
    for (int j = 0; j < cnt; j++) {
      if (vis[j]) continue;
      int tmp = 0;
      for (int k = head[j]; k != -1; k = edge[k].next) {
        if (vis[edge[k].v]) tmp++;
      }
      if (tmp > mmax)
        mmax = tmp, ans = 1;
      else if (tmp == mmax)
        ans++;
    }
    cout << name[i] << " " << ans << endl;
  }
  return 0;
}
