#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
template <typename T>
void DEBUG(string label, T value) {
  cerr << "[" << label << " = " << value << "]\n";
}
map<string, int> encode;
map<int, string> decode;
int m, n;
vector<vector<int>> adj;
void solve() {
  cin >> m;
  n = 0;
  for (int i = 0; i < m; ++i) {
    string a, b;
    cin >> a >> b;
    if (encode.count(a) == 0) {
      encode[a] = n;
      decode[n] = a;
      n++;
    }
    if (encode.count(b) == 0) {
      encode[b] = n;
      decode[n] = b;
      n++;
    }
    while (adj.size() < n) {
      adj.push_back(vector<int>());
    }
    adj[encode[a]].push_back(encode[b]);
    adj[encode[b]].push_back(encode[a]);
  }
  cout << n << '\n';
  for (int i = 0; i < n; ++i) {
    vector<bool> vis(n);
    vis[i] = true;
    for (int nxt : adj[i]) {
      vis[nxt] = true;
    }
    vector<int> cnt(n);
    for (int nxt : adj[i]) {
      for (int k : adj[nxt]) {
        if (!vis[k]) {
          cnt[k]++;
        }
      }
    }
    int mx = *max_element(cnt.begin(), cnt.end());
    int ans = 0;
    for (int j = 0; j < n; ++j) {
      ans += (!vis[j] && cnt[j] == mx);
    }
    cout << decode[i] << " " << ans << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  t = 1;
  while (t--) solve();
}
