1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <cstdio>

int main() {
    int n, stage;
    char letter;
    int a[5] = {0,0,0,0,0};
    int b[5] = {0,0,0,0,0};
    int c[5] = {0,0,0,0,0};
    
    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        scanf("%d%c", &stage, &letter);
        if(letter == 'A') {
            a[stage-1]++;
        } else if(letter == 'B') {
            b[stage-1]++;
        } else if(letter == 'C') {
            c[stage-1]++;
        }
    }

    for(int i=0; i<4; i++) {
        if(a[i] == 0 || b[i] == 0 || c[i] == 0) {
            printf("NIE\n");
            return 0;
        }
    }

    if(a[4] < 2 || b[4] < 2 || c[4] < 2) {
        printf("NIE\n");
        return 0;
    }

    printf("TAK\n");
    return 0;
}