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
#include <iostream>

int main() {
  bool fine = true;
  char d;
  int n, m;
  int a[5] = {0};
  int b[5] = {0};
  int c[5] = {0};
  std::ios::sync_with_stdio(false);

  std::cin >> n;
  
  for(int i = 0; i < n; i++) {
    std::cin >> m >> d;

    if (d == 'A') a[m-1]++;
    if (d == 'B') b[m-1]++;
    if (d == 'C') c[m-1]++;
  }

  fine = a[4] > 1 && b[4] > 1 && c[4] > 1;

  for(int i = 3; i > -1 && fine; i--) {
    fine = a[i] > 0 && b[i] > 0 && c[i] > 0;
  }

  std::printf("%s\n", fine ? "TAK" : "NIE");

  return 0;
}