/* -*- coding: utf-8 -*- * * 2590.cc: No.2590 100000 Days of Christmas - yukicoder */ #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ typedef long long ll; /* global variables */ string ss[MAX_N], uss[MAX_N]; int ds[MAX_N]; ll cs[MAX_N], es[MAX_N]; /* subroutines */ /* main */ int main() { int n; cin >> n; string tmp; getline(cin, tmp); for (int i = 0; i < n; i++) getline(cin, ss[i]); //for (int i = 0; i < n; i++) puts(ss[i].c_str()); copy(ss, ss + n, uss); sort(uss, uss + n); int m = unique(uss, uss + n) - uss; int k = 0; for (int i = 0; i < n; i++) { int id = lower_bound(uss, uss + m, ss[i]) - uss; es[id] += cs[id] * (i - ds[id]); cs[id] += i + 1; ds[id] = i; } for (int i = 0; i < m; i++) { es[i] += cs[i] * (n - ds[i]); printf("%lld %s\n", es[i], uss[i].c_str()); } return 0; }