#P9093. [PA 2020] Punkty rankingowe
[PA 2020] Punkty rankingowe
Problem Description
This problem is translated from PA 2020 Round 1 Punkty rankingowe.
Bytie decided to seriously prepare for this year's PA. For training, he created a BitForces account. BitForces is a platform that regularly hosts programming contests.
Bytie knows that the platform uses a points system (also called rating). This system lets him see his progress and compare his results with other contestants. A contestant's rating is an integer (it may be negative). After creating the account, Bytie's rating is . After each contest, his rating increases or decreases by some integer. Also, after each contest, the history of rating changes can be viewed on the platform. Excited, Bytie started analyzing this data. He wrote down consecutive numbers on paper:
- the maximum rating increase after one contest;
- the maximum value of the sum of rating increases over two consecutive contests;
- the maximum value of the sum of rating increases over three consecutive contests;
- and so on, until he wrote down the maximum value of the sum of rating increases over consecutive contests.
A few days later, Bytie wanted to recall the sequence of rating changes. However, BitForces is currently having technical problems. Help Bytie reconstruct a valid rating change sequence, with length at least , that matches the data written on the paper.
Input Format
The first line contains an integer , the number of values written on the paper.
The second line contains integers . For each , the maximum total rating increase over consecutive contests is exactly .
Output Format
If there exists a rating change sequence that satisfies all conditions in the statement, output one line TAK. Then output a line with one integer . In the third line output the found rating change sequence . If there are multiple answers, output any one of them.
If no such change sequence exists, output one line NIE.
It can be proven that if a rating change sequence exists for the given input, then there must exist one that satisfies the limits above.
4
3 4 5 -1
TAK
9
2 2 -7 0 3 -7 3 -1 3
10
3 1 4 1 5 9 2 6 5 3
NIE
Hint
Explanation of Sample 1
Below are the intervals where the rank increase is the largest for , , , and consecutive contests.

Constraints
This problem uses bundled testdata.
For of the testdata, it is guaranteed that , , , .
Translated by ChatGPT 5