#include <stdbool.h> #include <stdio.h> #include <stdlib.h> int main() { bool after[100][100] = {false}; unsigned char x, y; while (scanf("%hhu|%hhu\n", &x, &y) == 2) after[y][x] = true; unsigned char line[90]; unsigned sum = y = 0; do { bool right = true; do { line[y] = x; for (unsigned char i = 0; right && i < y; ++i) if (after[line[i]][line[y]]) right = false; } while (scanf(",%hhu", &x) == 1 && ++y); if (right) sum += line[y + 1 >> 1]; } while (y = 0, scanf("%hhu", &x) == 1); printf("%u\n", sum); return 0; }