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
// Ran.cpp : This file contains the 'main' function. Program execution begins and ends there.
#include <iostream>


#define MAXN 300 

int check(int res[], int elems, int size)
{
    if (elems > size) return 0;

    int sum = 0;
    int max = 0;

    for (int i = 0; i < elems; i++) sum += res[i];
    max = sum;

    for (int i = elems; i < size; i++)
    {
        sum += -res[i - elems] + res[i];
        if (sum > max) max = sum;
    }
    return max;
}

int main()
{
    std::ios::sync_with_stdio(false);

    int n;
    int changes[MAXN];
    int res[MAXN];

    std::fill_n(changes, MAXN, 0);
    std::fill_n(res, MAXN, 0);

    std::cin >> n;
    for (int i = 0; i < n; i++)
    {
        std::cin >> changes[i];
    }

    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        res[i] = changes[i] - sum;
        sum = changes[i];
    }

    //check if works
    for (int i = 0; i < n; i++)
    {
        if (check(res, i+1, n) > changes[i])
        {
            std::cout << "NIE" << std::endl;
            return 0;
        };
    }

    std::cout << "TAK" << std::endl;
    std::cout << n << std::endl;

    for (int i = 0; i < n; i++)
    {
        std::cout << res[i] << " ";
    }

    return 0;
}