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
#include <bits/stdc++.h>

using namespace std;
vector<long long> w;
long long a, b[301];
bool solve(int x)
{
    long long int dp_max[301], dp_min[301];
    long long int sum = -9999999999999LL;
    for (int i = 0; i < x; i++)
    {
        dp_max[i] = b[0];
        sum = 0;
        for (int z = i - 1; z >= 0; z--)
        {
            sum += dp_min[z];
            dp_max[i] = min(dp_max[i], b[i - z] - sum);
        }
        dp_min[i] = -9999999999999LL;
        if (i != 0 && i!= x-1)
        {
            dp_min[i] = b[x-1] - b[i-1] - b[x - 2 - i];
        }
        else 
        {
            dp_min[i] = b[x-1] - b[x - 2];
        }
 //cout << dp_max[i] << " [" << i << "] " << dp_min[i] << endl;
        if (dp_max[i] < dp_min[i])
        {
            return 0;
        }
       
    }
    for (int i = x - 1; i >= 0; i--)
    {

        sum = 0;
        for (int z = i + 1; z < x; z++)
        {
            sum += dp_min[z];
            dp_max[i] = min(dp_max[i], b[z - i] - sum);
        }
       // cout << dp_max[i] << " [" << i << "] " << dp_min[i] << endl;
        if (dp_max[i] < dp_min[i])
        {
            return 0;
        }
    }
    sum = 0;
    for (int i = 0; i < x; i++)
    {

        if (i != 0)
        {
            dp_max[i] = min(dp_max[i], b[i] - sum);
            if (dp_max[i] < dp_min[i])
            {
                return 0;
            }
        }
        sum += dp_max[i];
    }
    for (int i = 0; i < x; i++)
    {

        w.push_back(dp_max[i]);
        //cout << w[w.size() - 1] << endl;
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> a;

    for (int i = 0; i < a; i++)
    {
        cin >> b[i];
        if (!solve(i + 1))
        {
            cout << "NIE\n";
            return 0;
        }
        w.push_back(-9999999999999LL);
    }
    cout << "TAK\n";
    cout << w.size() << "\n";
    for (int i = 0; i < w.size(); i++)
    {
        cout << w[i] << " ";
    }
    return 0;
}