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
#include <bits/stdc++.h>

using namespace std;

struct TestCase
{
  int task_count;
  vector<string> tasks;
};

TestCase read_test_case();
void solve_test_case(const TestCase&);

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve_test_case(read_test_case());
}

TestCase read_test_case()
{
  TestCase test_case;
  cin >> test_case.task_count;
  test_case.tasks.resize(test_case.task_count);
  for (auto& task : test_case.tasks) cin >> task;
  return test_case;
}

int requirement(string division)
{
  if (division[0] < '5') return 1;
  return 2;
}

list<string> divisions()
{
  list<string> result;
  for (char i = '1'; i <= '5'; i++)
    for (char d = 'A'; d <= 'C'; d++) result.push_back({i, d});
  return result;
}

void solve_test_case(const TestCase& test_case)
{
  map<string, int> division_task_count;
  for (auto task : test_case.tasks) division_task_count[task]++;
  const auto div = divisions();
  bool ok = all_of(div.begin(), div.end(), [&division_task_count](string d) {
    return division_task_count[d] >= requirement(d);
  });
  cout << (ok ? "TAK" : "NIE") << "\n";
}