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
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
#include <iostream>

using namespace std;

int main()
{
    int A[5] = { 0,0,0,0,0 };
    int B[5] = { 0,0,0,0,0 };
    int C[5] = { 0,0,0,0,0 };

    int n;

    int cyfra = 0;
    char litera = 0;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> cyfra >> litera;
        switch (litera)
        {
        case 'A':
            if (cyfra == 5)
            {
                A[4]++;
            }
            else if (cyfra == 4)
            {
                A[3]++;
            }
            else if (cyfra == 3)
            {
                A[2]++;
            }
            else if (cyfra == 2)
            {
                A[1]++;
            }
            else if (cyfra == 1)
            {
                A[0]++;
            }
            break;
        case 'B':
            if (cyfra == 5)
            {
                B[4]++;
            }
            else if (cyfra == 4)
            {
                B[3]++;
            }
            else if (cyfra == 3)
            {
                B[2]++;
            }
            else if (cyfra == 2)
            {
                B[1]++;
            }
            else if (cyfra == 1)
            {
                B[0]++;
            }
            break;
        case 'C':
            if (cyfra == 5)
            {
                C[4]++;
            }
            else if (cyfra == 4)
            {
                C[3]++;
            }
            else if (cyfra == 3)
            {
                C[2]++;
            }
            else if (cyfra == 2)
            {
                C[1]++;
            }
            else if (cyfra == 1)
            {
                C[0]++;
            }
            break;
        }
    }
    for (int i = 0; i < 4; i++)
    {
        if (A[i] == 0) { cout << "NIE"; return 0; }
    }
    if (A[4] < 2) { cout << "NIE"; return 0; }
    for (int i = 0; i < 4; i++)
    {
        if (B[i] == 0) { cout << "NIE"; return 0; }
    }
    if (B[4] < 2) { cout << "NIE"; return 0; }
    for (int i = 0; i < 4; i++)
    {
        if (C[i] == 0) { cout << "NIE"; return 0; }
    }
    if (C[4] < 2) { cout << "NIE"; return 0; }
    cout << "TAK";
    return 0;
}