#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int tot;
string name1, name2, name[100010];
vector<int> G[100010];
int vis[100010], ans[100010], res[100010];
void bfs(int x) {
  memset(vis, 0, sizeof(vis));
  memset(ans, 0, sizeof(ans));
  vis[x] = 1;
  for (int i = 0; i < G[x].size(); i++) vis[G[x][i]] = 1;
  int mx = 0;
  for (int i = 0; i < G[x].size(); i++) {
    int v = G[x][i];
    for (int j = 0; j < G[v].size(); j++)
      if (!vis[G[v][j]]) {
        ans[G[v][j]]++;
        mx = max(mx, ans[G[v][j]]);
      }
  }
  int ct = 0;
  for (int i = 1; i <= tot; i++)
    if (ans[i] == mx && !vis[i]) ++ct;
  res[x] = ct;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> name1 >> name2;
    if (!mp[name1]) mp[name1] = ++tot, name[tot] = name1;
    if (!mp[name2]) mp[name2] = ++tot, name[tot] = name2;
    int x = mp[name1], y = mp[name2];
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for (int i = 1; i <= tot; i++) bfs(i);
  cout << tot << endl;
  for (int i = 1; i <= tot; i++) cout << name[i] << " " << res[i] << endl;
  return 0;
}
