#include #include int main() { int i, j, k, l = 0, lsize, N, A[6][4], B[100], cnt = 0, ANS[10] = {0,1,2,3,4,5,6,7,8,9}; char s[6][10]; scanf("%d", &N); for (i = 0; i < N; i++) { scanf("%d %d %d %d", &A[i][0], &A[i][1], &A[i][2], &A[i][3]); scanf("%s", s[i]); } for (i = 0; i < N ; i++) { for (j = 0; j < 4; j++) { if (strcmp(s[i], "NO") == 0) { ANS[A[i][j]] = -1; } else { B[l++] = A[i][j]; } } } for( k = 0; k <10; k++){ if (ANS[k] != -1) { cnt++; } } if (cnt == 1) { printf("%d\n", ANS[k-1]); return 0; } lsize = l ; l = 0; for (i = 0; i < N; i++) { if (strcmp(s[i], "YES") == 0) { for (k = 0; k < lsize; k++) { for (l = k + 1; l < lsize; l++) { if (B[k] == B[l] && ANS[B[l]] != -1) { printf("%d\n", B[l]); return 0; } } } } } }