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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <unordered_map>
#include <vector>
#include <sstream>
#include <iterator>
#include<cmath>
using namespace std;

template <typename T>
void println(T t)
{
    cout << t << endl;
}


int main() {


    string min_len;
    getline(cin, min_len);

    string inputs;

    getline(cin, inputs);

    istringstream is_str(inputs);

    vector<string> new_range{
            istream_iterator<string>{is_str},
            istream_iterator<string>{}
    };
    vector<int64_t> input_ints(new_range.size());

    for (int i = 0; i < new_range.size(); ++i) {
        input_ints[i] = stoi(new_range[i]);
    }

//    safety check

    bool can_exist = true;
    auto max_inc = input_ints[0];
    for (int i = 1; i < input_ints.size() - 1; ++i) {
        auto inp = input_ints[i];
        auto next_inp = input_ints[i+1];
        if (next_inp > inp) {

            if (next_inp > (inp + max_inc)) {
                can_exist = false;
                break;
            }

        }
        else {
            continue;
        }
    }

    vector<int64_t> new_out;
    int64_t min_val = pow(10, 13) * -1;
    new_out.push_back(max_inc);
    for (int i = 1; i < input_ints.size(); ++i) {
        auto inp = input_ints[i];
        auto prev_inp = input_ints[i-1];
        if (inp >= prev_inp) {
            new_out.push_back(inp - prev_inp);
            continue;
        }
        else {
            vector<int64_t> tmp_vec;
            tmp_vec.push_back(min_val);

            tmp_vec.push_back(inp - prev_inp);
            auto new_out_size = new_out.size() - 1;


            for (int j = 0; j < i; ++j) {
                tmp_vec.push_back(new_out[new_out_size-j]);
            }
            for (const auto& value: tmp_vec) {
                new_out.push_back(value);
            }
        }
    }


    if (can_exist){
        println("TAK");
        println(new_out.size());
        for (const auto& value: new_out) {
            cout << value << " ";
        }

    }
    else{
        println("NIE");
    }

}