Unfortunately we were unable to fully decode your file, as it is not encoded in UTF-8. You can try to decode it yourself by downloading it here.
 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
#include <iostream>
#include <vector>
using namespace std;

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

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        vector<long long> a(n + 1); // Indeksowanie od 1
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }

        // Znajd� pierwszy i ostatni niezerowy element
        int l = 1;
        while (l <= n && a[l] == 0) l++;
        int r = n;
        while (r >= 1 && a[r] == 0) r--;

        // Je�li wszystkie elementy s� zerowe, to nie ma wyliczanki
        if (l > n) {
            cout << "NIE\n";
            continue;
        }

        // Sprawd�, czy wszystkie elementy mi�dzy l a r s� niezerowe
        bool valid = true;
        for (int i = l; i <= r; i++) {
            if (a[i] == 0) {
                valid = false;
                break;
            }
        }

        if (!valid) {
            cout << "NIE\n";
            continue;
        }

        // Oblicz sum� element�w mi�dzy l a r
        long long sum = 0;
        for (int i = l; i <= r; i++) {
            sum += a[i];
        }

        // Sprawd� warunki
        if (l == r) {
            // Tylko jedna niezerowa zabawka: a[l] musi by� nieparzyste
            if (a[l] % 2 == 0) valid = false;
        } else {
            // Wi�cej ni� jedna niezerowa zabawka: suma musi by� >= 2*(r-l) + 1
            // oraz r�nica mi�dzy sum� a 2*(r-l)+1 musi by� parzysta
            long long min_sum = 2 * (r - l) + 1;
            if (sum < min_sum || (sum - min_sum) % 2 != 0) valid = false;
        }

        cout << (valid ? "TAK" : "NIE") << "\n";
    }

    return 0;
}