#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
map<string, int> id;
string name[10005];
vector<int> g[10005];
int getid(string& s) {
  if (id.count(s)) return id[s];
  name[id.size()] = s;
  int i = id.size();
  return id[s] = i;
}
pair<int, int> res[10005];
int main() {
  string a, b;
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    int A = getid(a), B = getid(b);
    g[A].push_back(B);
    g[B].push_back(A);
  }
  m = id.size();
  for (int i = 0; i < m; ++i) sort((g[i]).begin(), (g[i]).end());
  for (int i = 0; i < m; ++i)
    for (int j = 0; j < i; ++j)
      if (!binary_search((g[i]).begin(), (g[i]).end(), j)) {
        int k = 0, l = 0;
        int same = 0;
        while (k < g[i].size() && l < g[j].size()) {
          if (g[i][k] == g[j][l]) {
            ++same;
            ++k;
            ++l;
          } else if (g[i][k] > g[j][l]) {
            ++l;
          } else {
            ++k;
          }
        }
        if (res[i].first < same)
          res[i] = make_pair(same, 1);
        else if (res[i].first == same)
          ++res[i].second;
        if (res[j].first < same)
          res[j] = make_pair(same, 1);
        else if (res[j].first == same)
          ++res[j].second;
      }
  printf("%d\n", m);
  for (int i = 0; i < m; ++i) cout << name[i] << ' ' << res[i].second << '\n';
  return 0;
}
