OI XXXIV - pcb

// https://sio2.mimuw.edu.pl/c/oi34-1/p/pcb/

#include <bits/stdc++.h>

// #define GARY_DBG

constexpr int sizik = 1000 * 1001;

bool was[sizik];

int z[sizik];

void solve() {
    int n;
    std::cin >> n;

    bool isGood = true;
    int x = 0;

    for (int i = 1; i <= n; i++) {
        int a;
        std::cin >> a;

        z[i] = a;

        if (a > 0) {
            x++;
            if (was[a]) isGood = false;
            was[a] = true;
        }
    }

    if (!isGood) {
        std::cout << "NIE\n";
        return;
    }

    if (x <= 2) {
        std::cout << "TAK\n";
        return;
    }

    std::vector<int> nasze;
    nasze.reserve(n);
    for (int i = 1; i <= n; i++) {
        if (z[i] > 0) {
            nasze.push_back(z[i]);
        }
    }

    int m = nasze.size();

    int first = nasze[0];
    int second = nasze[1];

    std::vector<bool> zabl(n + 1, 0);

    auto blok = [&zabl, &n](int x, int y) -> void {
        while (x != y) {
            zabl[x] = 1;
            x--;
            if (x == 0) x = n;
        }
        zabl[y] = 1;
    };

    blok(first, second);

    for (int i = 2; i < m; i++) {
        if (zabl[nasze[i]]) {
            isGood = false;
            break;
        } else {
            blok(nasze[i - 1], nasze[i]);
        }
    }

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

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    solve();

    return 0;
}