// @BEGIN_OF_SOURCE_CODE /* @JUDGE_ID: 17243NT 119 C++ */ // Send to judge@uva.es #include #include char names[10][14]; int getnameid(char[], int); void docase(int); int main() { int n; int first = 0; while(scanf("%d", &n) == 1) { if(first) printf("\n"); first = 1; docase(n); } return 0; } void docase(int n) { int h, i, j, k, m, x, o; long money[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; char temp[14]; for (i = 0; i < n; i++) { scanf("%s", &names[i]); } for (i = 0; i < n; i++) { scanf("%s", &temp); scanf("%d", &m); scanf("%d", &x); if(x == 0) continue; j = getnameid(temp, n); o = m / x; money[j] -= o * x; for(h = 0; h < x; h++) { scanf("%s", &temp); k = getnameid(temp, n); money[k] += o; } } for (i = 0; i < n; i++) { printf("%s %d\n", names[i], money[i]); } } int getnameid(char temp[], int n) { int i; for(i = 0; i < n; i++) if(0 == strcmp(temp, names[i])) return i; return 0; } // @END_OF_SOURCE_CODE