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
69
70
71
72
73
74
75
#include <iostream>

const int MAX = 303;
int S[MAX];
int V[MAX];
int K[MAX];
int n;
int INF = MAX * 1000000;

bool check(int s) {
    int sum = 0;
    for (int i=0;i<=s;++i) sum += V[i];
    for (int i=s;i<n;++i) {
        if (sum > S[s]) return false;
        sum += V[i];
        sum -= V[i];
    }
    return sum <= S[s];
}

bool check2(int s) {
    int sum = 0;
    for (int i=0;i<=s;++i) sum += V[i];
    for (int i=s;i<n;++i) {
        if (sum == S[s]) return true;
        sum += V[i];
        sum -= V[i];
    }
    return sum == S[s];
}

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin >> n;
    for (int i=0;i<n;++i) std::cin >> S[i];
    for (int i=0;i<n;++i) {
        for (int j=0;j<i;++j) {
            K[j] -= V[i-j-1];
        }
        V[i] = INF;
        for (int j=0;j<=i;++j) {
            V[i] = std::min(V[i], S[j]-K[j]);
        }
        // for (int j=0;j<=i;++j) 
        // {
        //     std::clog << ":: $$ :: " << K[j] << std::endl;
        // }
        for (int j=0;j<=n;++j) {
            K[j] += V[i];
        }
        // std::clog << ":: " << V[i]  << " / " << S[i] << std::endl;
        // for (int j=0;j<=i;++j) 
        // {
        //     std::clog << ":: :: " << K[j] << std::endl;
        // }
        // std::clog << std::endl;
    }
    // for (int i=0;i<n;++i)
    //     std::clog << V[i] << " ";
    // std::clog << std::endl;
    

    bool result = true;
    for (int i=0;i<n;++i) result &= check(i) & check2(i);

    if (result) {
        std::cout << "TAK\n" << n << std::endl;
        for (int i=0;i<n;++i)
            std::cout << V[i] << " ";
        std::cout << std::endl;
    } else {
        std::cout << "NIE" << std::endl;
    }
    return 0;
}