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
#include <cstdio>
#include <map>
#include <utility>

bool result = false;
int n;
int counts[5][3];

bool solve() {
  for(int j=0; j<3; j++) {
    for (int i=0; i<4; i++) {
      if (counts[i][j] < 1){
        return false;
      }
    }
    if (counts[4][j] < 2) {
      return false;
    }
  }
  return true;
}

int main() {
  scanf("%d\n", &n);

  for (int i=0; i<n; i++) {
    char c1, c2;
    scanf("%c%c", &c1, &c2);
    if (i < n-1) {
      scanf(" ");
    }
    int x = (int)(c1 - '1');
    int y = (int)(c2 - 'A');
    counts[x][y]++;
  }

  if (solve())  {
    printf("TAK\n");
  } else {
    printf("NIE\n");
  }
  return 0;
}