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

const long long marker = -10000000000000LL;

int n;
int limit[500];
std::vector<long long> ans;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", limit + i);

    for (int i = 0; i < n; ++i) {
        if (i != 0) ans.push_back(marker);
        for (int j = 0; j <= i; ++j) {
            long long best = limit[0];
            long long sum = 0;
            for (int k = 0; k < j; ++k) {
                sum += ans[ans.size() - 1 - k];
                best = std::min(best, limit[k + 1] - sum);
            }
            if (j == i) {
                long long exp = limit[i] - sum;
                if (best < exp) {
                    printf ("NIE\n");
                    return 0;
                }
                best = exp;
            }
            ans.push_back(best);
        }
    }

    printf("TAK\n%d\n", ans.size());
    for (int i = 0; i < ans.size(); ++i) printf("%lld ", ans[i]);

    return 0;
}