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
#include <cstdio>
#include <string>
#include <utility>
#include <map>

int MIN_VAL = 400 * -1000000;
int res[400 * 400];
int t[400];
int left[400];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &t[i]);
  }
  bool ok = true;
  int pos = 0;
  for (int i = 1; ok && i <= n; ++i) {
    res[pos] = MIN_VAL;
    int sum = t[i];
    int avg = sum / i;
    if (avg * i > sum) {
      --avg;
    }
    int rem = sum - avg * i;

    for (int j = 1; j < i; ++j) {
      left[j] = t[j] - avg * j;
      if (left[j] < 0) {
        ok = false;
      }
    }
    for (int k = 1; ok && k <= i; ++k) {
      res[pos + k] = avg;
      if (rem > 0) {
        bool anything_left = true;
        for (int j = 1; j < i; ++j) {
          if (left[j] < 1) {
            anything_left = false;
            break;
          }
        }
        if (anything_left) {
          for (int j = 1; j < i; ++j) {
            --left[j];
          }
          ++res[pos + k];
          --rem;
        }
        for (int j = 1; j <= k; ++j) {
          left[j] += (res[pos + k - j + 1] - avg);
        }
      }
    }
    if (rem > 0) {
      ok = false;
    }
    pos += (i + 1);
  }
  printf("%s\n", ok ? "TAK" : "NIE");
  if (ok) {
    printf("%d\n", pos);
    for (int i = 0; i < pos; ++i) {
      printf("%d ", res[i]);
    }
  }

  return 0;
}