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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#define OPTIONS_NO 3
#define DAYS_NO 5

uint8_t** malloc_table() {
    uint8_t** table = (uint8_t**) malloc(sizeof(uint8_t*) * OPTIONS_NO);
    for(uint8_t i = 0; i < OPTIONS_NO; ++i) {
        table[i] = (uint8_t*) malloc(sizeof(uint8_t) * DAYS_NO);
        for(uint8_t j = 0; j < DAYS_NO; ++j) {
            table[i][j] = 0;
        }
    }
    return table;
}

void free_table(uint8_t** table) {
    for(uint8_t i = 0; i < OPTIONS_NO; ++i) {
        free(table[i]);
    }
    free(table);
}

int main(void) {
    uint8_t n;
    scanf("%u", &n);
    char* buffer = (char*) malloc(sizeof(char) * 2);
    uint8_t** table = malloc_table();
    uint8_t i, j;
    char answer = 1;
    while(n--) {
        scanf("%s", buffer);
        i = buffer[1] - 'A';
        j = buffer[0] - '1';
        table[i][j]++;
    }
    for(uint8_t i = 0; i < OPTIONS_NO; ++i) {
        for(uint8_t j = 0; j < DAYS_NO; ++j) {
            if (table[i][j] == 0) {
                answer = 0;
                break;
            } else if (j == 4 && table[i][j] == 1) {
                answer = 0;
                break;
            }
        }
        if (!answer) {
            break;
        }
    }
    if (answer) {
        printf("TAK");
    } else {
        printf("NIE");
    }
    free(buffer);
    free_table(table);
}