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
#include <array>
#include <bits/stdint-uintn.h>
#include <cstdint>
#include <iostream>

std::uint32_t string_to_index(const std::string &x) {
  const std::uint32_t round = [&]() {
    switch (x[0]) {
    case '1':
      return 0;
    case '2':
      return 1;
    case '3':
      return 2;
    case '4':
      return 3;
    case '5':
      return 4;
    default:
      return 0;
    }
  }();
  const std::uint32_t section = [&]() {
    switch (x[1]) {
    case 'A':
      return 0;
    case 'B':
      return 1;
    case 'C':
      return 2;
    default:
      return 0;
    }
  }();
  return round * 3 + section;
}

int main() {
  std::uint32_t n = 0;
  std::cin >> n;

  std::array<std::uint32_t, 15> count{0};

  for (std::uint32_t i = 0; i < n; ++i) {
    std::string s;
    std::cin >> s;
    ++count[string_to_index(s)];
  }

  constexpr std::array<std::uint32_t, 15> required_count{1, 1, 1, 1, 1, 1, 1, 1,
                                                         1, 1, 1, 1, 2, 2, 2};

  bool correct = true;
  for (std::uint32_t i = 0; i < count.size(); ++i) {
    correct = correct && count[i] >= required_count[i];
  }

  if (correct) {
    std::cout << "TAK\n";
  } else {
    std::cout << "NIE\n";
  }

  return 0;
}