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
#include<iostream>
using namespace std;

long long t[100000];
long long pref[100000];
long long mx[300];
const long long neg_inf = -1e13;
int n;

void fill_pref(int i) {
  if (i > 0) {
    pref[i] = pref[i - 1];
  }
  pref[i] += t[i];
}

int main() {
  ios_base::sync_with_stdio(0);

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

  int curr = 0;
  for (int i = 0; i < n; i++) {
    long long sum = 0;
    for (int j = 0; j < i; j++) {
      t[curr] = mx[j] - sum;
      fill_pref(curr);
      for (int k = 0; k < n && i - k - 1 >= 0; k++) {
        long long tmp_sum = pref[curr] - pref[curr - k - 1];
        if (tmp_sum > mx[k]) {
          t[curr] -= tmp_sum - mx[k];
        }
      }
      fill_pref(curr);
      sum += t[curr];
      curr++;
    }
    t[curr] = mx[i] - sum;
    pref[curr] = pref[curr - 1] + t[curr];
    for (int j = 0; j < n && i - j - 1 >= 0; j++) {
      if (pref[curr] - pref[curr - j - 1] > mx[j]) {
        cout << "NIE" << endl;
        return 0;
      }
    }
    curr++;
    t[curr] = neg_inf;
    pref[curr] = pref[curr - 1] + t[curr];
    curr++;
  }

  cout << "TAK" << endl << curr - 1 << endl;
  for (int i = 0; i < curr - 1; i++) {
    cout << t[i] << " ";
  }
  cout << endl;

  return 0;
}