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

using namespace std;

typedef long long ll;

const ll P = 1000000001;

ll Hasz(vector<char>& s)
{
    ll h = 0;
    for (int i = 0; i < s.size(); ++i)
        h = h * P + s[i];
    return h;
}

bool Pali(vector<char>& s)
{
    for (int i = 0, j = s.size() - 1; i < j; ++i, --j)
        if (s[i] != s[j])
            return false;
    return true;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    int part = 100000;
    bool odp = true;
    if (n != 0)
    {
        int ilepar = n / (2 * part);
        int r = n - 2 * ilepar * part;
        vector<ll> hL;
        for (int i = 0; i < ilepar; ++i)
        {
            vector<char> s(part);
            for (int j = 0; j < part; ++j)
                cin >> s[j];
            hL.push_back(Hasz(s));
        }
        vector<char> sr(r);
        for (int i = 0; i < r; ++i)
            cin >> sr[i];
        vector<ll> hP;
        for (int i = 0; i < ilepar; ++i)
        {
            vector<char> s(part);
            for (int j = 0; j < part; ++j)
                cin >> s[j];
            reverse(s.begin(), s.end());
            hP.push_back(Hasz(s));
        }
        for (int i = 0, j = ilepar - 1; i < ilepar; ++i, --j)
            if (hL[i] != hP[j])
                odp = false;
        if (!Pali(sr))
            odp = false;
    }
    else
    {
        string t;
        cin >> t;
        vector<char> c;
        for (int i = 0; i < t.size(); ++i)
            c.push_back(t[i]);
        if (!Pali(c))
            odp = false;
    }
    if (odp)
        cout << "TAK";
    else
        cout << "NIE";
    return 0;
}