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

using namespace std;

const int maxk=404;

int tab[maxk], sum;
vector<int> gs;

int k = 400;
int n,r,g;

int main(){
  scanf("%d", &n);
  scanf("%d", &g);
  gs.push_back(g);
  k = min (n+4, k);
  
  for(int i = 1; i <= k; i++){
    tab[i] = g;
  }
  for(int i = 1 ; i < n; i++){
    scanf("%d", &g);
    gs.push_back(g);
    sum = 0;
    for(int p = 1; p <= i; p++){
      sum += tab[p];
    }
    for(int q = 1; q <= k - i; q++){
      sum -= tab[q-1];
      sum += tab[q+i];
      if(sum > g){
        tab[q] -= (sum - g);
        sum = g;
      }
    }
  }
  bool ans = true;
  bool found;
  for(int i = 0 ; i < n; i++){
    sum = 0;
    found = false;
    for(int p = 1; p <= i; p++){
      sum += tab[p];
    }
    for(int q = 1; q <= k - i; q++){
      sum -= tab[q-1];
      sum += tab[q+i];
      if(sum == gs[i]){
        found = true;
        break;
      }
    }
    if(found){
      continue;
    }
    else{
      ans = false;
      break;
    }
  }
  if(ans){
    cout<<"TAK"<<endl;
    printf("%d\n", k);
    for(int i = 1; i<=k; i++){
      printf("%d", tab[i]);
      if(i<k) printf(" ");
    }
    printf("\n");
  }
  else{
    cout<<"NIE"<<endl;
  }
}