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
#include <cstdio>
#include <vector>

using namespace std;

typedef long long LL;
LL inf = 1e13;

int main() {
  int n; scanf("%d", &n);
  vector<int> a;
  a.resize(n);
  for (int i=0; i<n; ++i) {
    scanf("%d", &a[i]);
  }

  // Maximum limit because of lower limits.
  vector<LL> t;
  t.resize(n+1, inf);
  t[0] = 0;
  for (int i=1; i<n+1; ++i) {
    int x = a[i-1];
    if (i > 1) {
      if (t[i] < x) {
        printf("NIE\n");
        return 0;
      }
    }
    for (int j = 0; j+i <= n; ++j) {
      t[j+i] = std::min(t[j+i], t[j] + x);
    }
  }

  printf("TAK\n");
  printf("%d\n", (n+1) * (n+2) / 2);
  printf("%lld ", -10000000000000LL);
  for (int i=1; i<=n; ++i) {
    for (int j=1; j<i; ++j) {
      printf("%lld ", t[j] - t[j-1]);
    }
    printf("%lld ", a[i-1] - t[i-1]);
    printf("%lld ", -10000000000000LL);
  }
  printf("\n");

  return 0;
}