#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
template <class T>
inline T bigMod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T modInv(T a, T M) {
  return bigMod(a, M - 2, M);
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T>
inline T egcd(T a, T b, T &x, T &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  T d = egcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
template <class T>
inline T eModInv(T a, T m) {
  T x, y;
  exgcd(a, m, &x, &y);
  x %= m;
  if (x < 0) x += m;
  return x;
}
template <class T>
inline string int2String(T a) {
  ostringstream str;
  str << a;
  return str.str();
}
template <class T>
inline T string2int(string a) {
  stringstream str(a);
  T b;
  str >> b;
  return b;
}
template <class T>
inline void read(T &r) {
  r = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' or ch > '9') {
    f = (ch == '-' ? -1 : 1), ch = getchar();
  }
  while (ch >= '0' and ch <= '9') {
    r = r * 10 + ch - '0', ch = getchar();
  }
  r *= f;
}
const int dr[] = {0, 1, 0, -1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2};
int sSz;
vector<int> G[10004];
unordered_map<string, int> mp;
int res[10004];
bool ar[10004][10004];
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    char second[25], tt[25];
    int id1, id2;
    scanf("%s %s", second, tt);
    if (!mp[second])
      id1 = mp[second] = ++sSz;
    else
      id1 = mp[second];
    if (!mp[tt])
      id2 = mp[tt] = ++sSz;
    else
      id2 = mp[tt];
    ar[id1][id2] = ar[id2][id1] = 1;
    G[id1].push_back(id2);
    G[id2].push_back(id1);
  }
  for (int i = 1; i <= sSz; i++) {
    int tmp[10004] = {0};
    int ans = 0;
    int mx = 0;
    for (auto &u : G[i]) {
      for (auto &v : G[u]) {
        if (v != i and ar[v][i] == 0) tmp[v]++, mx = max(tmp[v], mx);
      }
    }
    for (int j = 1; j <= sSz; j++) {
      if (i != j and ar[i][j] == 0 and mx == tmp[j]) ans++;
    }
    res[i] = ans;
  }
  printf("%d\n", sSz);
  for (auto &par : mp) {
    printf("%s %d\n", par.first.c_str(), res[par.second]);
  }
  return 0;
}
