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
#include <iostream>
#include <stdio.h>

int min_find_withLimit(long double *array, int index){
    long double min = *array;
    int outIndex = 0;
    for(int i=1; i<=index; i++){
        if(array[i]<min){
            min = array[i];
            outIndex = i;
        }
    }
    return outIndex;
}

bool partial_max_possible(long long int* val, long double* max_per_single, 
                        int i, int origin, long long int mx){
    int c = min_find_withLimit(max_per_single, i);
    int full = (i+1)/(c+1);
    int rest = (i+1)%(c+1);
    mx += full * val[c];
    //printf("%d %lld   %d %lld   %d %d   %lld\n", i, val[i], c, val[c], full, rest, mx);
    if (rest==0) {
        if (val[origin]<=mx){
            return true;
        } else {
            return false;
        }
    } else {
        return partial_max_possible(val, max_per_single, rest-1, origin, mx);
    }
}

int main() {

    int n;
    scanf("%d", &n);
    long long int val[300];
    long double max_per_single[300];

    for(int i=0; i<n; i++){
        scanf("%lld", &val[i]);
        max_per_single[i] = val[i]/(float)(i+1);
        bool x = partial_max_possible(val, max_per_single, i, i, 0);
        if(!x){
            printf("NIE");
            return 0;
        }
    }
    printf("TAK\n");
    printf("%d\n", n);
    printf("%lld", val[0]);
    for(int i=1; i<n; i++){
        printf(" %lld", val[i]-val[i-1]);
    }
    return 0;
}