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

auto go(std::vector<int32_t> a) {
    std::vector<int32_t> diffs;
    std::vector<int32_t> output;

    for (int32_t i = 0; i < (int32_t)a.size(); ++i) {
        diffs.push_back(a[i]);
        output.push_back(a[i] - (i == 0 ? 0 : a[i - 1]));
        for (int32_t j = 0; j < i; ++j) {
            diffs[j] += output[i];
            diffs[j] -= output[i - (j + 1)];
            if (diffs[j] > a[j]) {
                return std::optional<decltype(output)>();
            }
        }
    }

    return std::make_optional(output);
}

int main() {
    int32_t n;
    std::cin >> n;

    std::vector<int32_t> a(n);
    for (int32_t i = 0; i < n; ++i) {
        std::cin >> a[i];
    }

    if (auto output = go(std::move(a))) {
        std::cout << "TAK\n" << output->size() << "\n";
        for (auto &val: *output) {
            std::cout << val << " ";
        }
        std::cout << "\n";
    } else {
        std::cout << "NIE\n";
    }
}