#include <bits/stdc++.h>
using namespace std;
int n, i, j, ans[10005], cnt[10005], nxt;
map<string, int> id;
vector<int> edge[10005];
vector<string> name;
bool used[10005];
void solve(int s) {
  memset(used, 0, sizeof(used));
  for (int k = 0; k < edge[s].size(); k++) used[edge[s][k]] = 1;
  int count = 0;
  for (int k = 1; k <= nxt; k++) {
    if (s == k || used[k]) continue;
    int temp = 0;
    for (int ii = 0; ii < edge[k].size(); ii++) temp += used[edge[k][ii]];
    if (temp > ans[s]) {
      ans[s] = temp;
      count = 1;
    } else if (temp == ans[s])
      count++;
  }
  ans[s] = count;
}
int main() {
  scanf("%d", &n);
  nxt = 0;
  for (i = 0; i < n; i++) {
    string x, y;
    cin >> x >> y;
    if (id[x] == 0) {
      id[x] = ++nxt;
      name.push_back(x);
    }
    if (id[y] == 0) {
      id[y] = ++nxt;
      name.push_back(y);
    }
    edge[id[x]].push_back(id[y]);
    edge[id[y]].push_back(id[x]);
  }
  printf("%d\n", nxt);
  for (i = 1; i <= nxt; i++) {
    cout << name[i - 1] << " ";
    solve(i);
    printf("%d\n", ans[i]);
  }
}
