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

using namespace std;

int sum(int* output, int start, int end) {
    int out = 0;
    for (int i = start; i <= end; i++) {
        out += output[i];
    }
    return out;
}

bool check(int* array, int * output, int n) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - i; j++) {
            if (sum(output, j, j + i) > array[i]) {
                return false;
            }
        }
    }
    return true;
}

void isPossible() {
    int n;
    cin >> n;
    int* array = new int[n];
    int* output = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> array[i];
    }
    output[0] = array[0];
    for (int i = 1; i < n; i++) {
        if (array[i] - array[i - 1] > output[0]) {
            cout << "NIE" << endl;
            return;
        }
        else {
            output[i] = array[i] - array[i - 1];
        }
    }
    if (!check(array,output,n)) {
        cout << "NIE" << endl;
        return;
    }
    cout << "TAK" << endl << n << endl;
    for (int i = 0; i < n; i++) {
        cout << output[i] << " ";
    }cout << endl;
}

int main()
{
    isPossible();
    return 0;
}