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
#include <stdio.h>
using namespace std;

int index(char taskDivision, int taskNum) {
  if (taskDivision == 'C') return 9 + taskNum;
  if (taskDivision == 'B') return 4 + taskNum;
  return taskNum - 1;
}

int main(int argc, char const *argv[]) {
  int ideasNum, result = 0, taskNum, maxIdeas = 15;
  int ideas[maxIdeas];
  char taskDivision;

  for (int i = 0; i < maxIdeas; ++i) {
    if (i == 4 || i == 9 || i == 14) {
      ideas[i] = 2;
    } else {
      ideas[i] = 1;
    }
  }


  if (!scanf("%d", &ideasNum)) return 1;

  for (int i = 0; i < ideasNum; ++i) {
    if (!scanf("%d%c", &taskNum, &taskDivision)) return 1;

    if (ideas[index(taskDivision, taskNum)] > 0 && --ideas[index(taskDivision, taskNum)] == 0) {
      ++result;
    }
  }

  if (result == maxIdeas) {
    printf("TAK");
  } else {
    printf("NIE");
  }
  return 0;
}