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


int main() {

    int n;
    std::cin >> n;
    std::vector<int> b(n);
    for(int i = 0; i < n; i++)
        std::cin >> b[i];


    bool possible = true;
    std::vector<int> ranking(n, 0);
    std::vector<int> sequence_sum(n, 0);

    ranking[0] = b[0];
    sequence_sum[0] = 0;
    for(int i = 1; i < n && possible; i++) {
        sequence_sum[i] = sequence_sum[i-1] + ranking[i-1];
        int required = b[i] - sequence_sum[i];
        for(int j = 0; j <= i && possible; j++) {
            if(sequence_sum[i] - sequence_sum[j] + required > b[i-j])
                possible = false;
        }
        ranking[i] = required;
    }

    if(possible) {
        std::cout << "TAK" << std::endl;
        std::cout << n << std::endl;
        std::string s = "";
        for(int i = 0; i < n; i++) {
            std::cout << s << ranking[i];
            s = " ";
        }
        std::cout << std::endl;
    } else {
        std::cout << "NIE" << std::endl;
    }
    
}