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

using namespace std;

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        scanf("%d", &n);
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            scanf("%d", &a[i]);
        }
        if (n == 1) {
            puts(a[0] == 1 ? "TAK" : "NIE");
            continue;
        }
        if (n == 2) {
            puts(abs(a[0] - a[1]) <= 1 ? "TAK" : "NIE");
            continue;
        }
        int max_val = *max_element(a.begin(), a.end());
        int k = 0;
        while (k < n && a[k] != max_val) k++;
        bool increasing = true;
        for (int i = 1; i <= k; ++i) {
            if (a[i] < a[i - 1]) {
                increasing = false;
                break;
            }
        }
        if (!increasing) {
            puts("NIE");
            continue;
        }
        bool decreasing = true;
        for (int i = k + 1; i < n; ++i) {
            if (a[i] > a[i - 1]) {
                decreasing = false;
                break;
            }
        }
        puts(decreasing ? "TAK" : "NIE");
    }
}