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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "stddef.h"
#include "stdio.h"

#ifdef __unix
#define getchar getchar_unlocked
#endif
#ifndef __LOCAL
#define debug(...) // debug
#else
#define debug(...) fprintf(stderr, __VA_ARGS__)
#endif

typedef int cint;
inline cint getInt(){
    char get_tmp;
    unsigned int tmp;
    tmp = 0;
    while((get_tmp=getchar()) >= '0'){
        tmp = ((tmp<<3) + (tmp<<1)) + get_tmp - '0';
    }
    return tmp;
}

inline cint getSlowo(){
    static char get_tmp;
    static int tmp;
    while((get_tmp=getchar()) < '0'){}
    // debug("get_tmp: %hhd\n", get_tmp);
    tmp = (get_tmp-'1')*3;
    // debug("D: %hhd\n", tmp);
    tmp += getchar()-'A';
    // debug("A: %hhd\n", tmp);
    getchar();
    return tmp;
}


int main(){
    cint n = getInt();
    int flag = 0;
    int counter[] = {0, 0, 0};
    if(n < 18){
        printf("NIE");
        return 0;
    }
    for(int i=0;i<n;i++){
        cint slowo = getSlowo();
        // debug("%d ", slowo);
        if(slowo < 12){
            flag |= 1<<slowo;
        }else{
            counter[slowo-12]++;
            if(counter[slowo-12]>1){
                // debug("5 dywizja: %d\n", slowo-12);
                flag |= 1<<slowo;
            }
        }
    }
    // debug("%X\n", flag);
    if(flag == (1<<15)-1){
        printf("TAK");
    }else{
        printf("NIE");
    }

}