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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * author: pavveu
 * task: PA Runda 1 - Punkty Rankingowe [A]
*/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

#define FOR(iter, val) for(int iter = 0; iter < (val); iter++)
#define all(x) begin(x), end(x)

/// ------------- TESTING SOLUTION ----------------------------

vi generate_good_array(int n, int bound) {
	vector<int> ratings;

	int score = 0;
	for (int i = 0; i < n; i++) {
		int l = rand() % (bound + 1) - bound/2;
		ratings.push_back(l - score);
		score += l - score;
	}

	vi a(n);
	for (int l = 1; l <= n; l++) {
		int seg_score = 0;

		FOR(i, l) seg_score += ratings[i];
		int max_seg_score = seg_score;

		for(int i = l; i < n; i++) {
			seg_score -= ratings[i - l];
			seg_score += ratings[i];
			max_seg_score = std::max(max_seg_score, seg_score);
		}

		a[l - 1] = max_seg_score;
	}

	return a;
}

bool check(vi& a, vi& b) {
	int n = a.size();

	for (int l = 1; l <= n; l++) {
		int seg_score = 0;

		FOR(i, l) seg_score += b[i];
		int max_seg_score = seg_score;

		for(int i = l; i < (int) b.size(); i++) {
			seg_score -= b[i - l];
			seg_score += b[i];
			max_seg_score = std::max(max_seg_score, seg_score);
		}

		if ( a[l - 1] != max_seg_score ) return false;
	}

	return true;
}

vi get_solution(const vi& a, bool& valid_testcase);

void test() {
	srand(time(NULL));

	const int ntests = 100000;
	const int n = 300;
	const int bound = 1e6;

	int t = 0;
	FOR(q, ntests) {
		auto a { generate_good_array(n, bound) };
		bool correct_input = true;
		auto b = get_solution(a, correct_input);

		if ( !correct_input ) {
			cerr << "ERROR OCCURED, optimal returned false: " << endl;
			return;
		}
		else if ( !check(a, b) ) {
			cerr << "WRONG ANSWER" << endl;
			return;
		}
		else {
			cerr << "OK.  ";
		}
		t++;
	}
	cout << t << " testcases passed.\n"; 
}
///// ----------------------------------------------------------------------------

vi get_solution(const vi& a, bool& valid_testcase) {
	int n = a.size();

	vi b { a[0] };
	for (int i = 1; i < n; i++) 
		b.push_back(a[i] - a[i - 1]);

	valid_testcase = true;

	FOR(i, n) {
		for (int j = 0; i - j > 0; j++ ) {
			if ( a[i] - a[j] > a[i - j - 1] ) 
				valid_testcase = false;
		}
	}

	return b;
}


void go() {
	int n; cin >> n;
	vi a(n);
	for (auto& i : a) cin >> i;


	bool valid_input { true };
	auto b { get_solution(a, valid_input) };

	if ( valid_input ) {
		cout << "TAK\n";
		cout << b.size() << endl;
		for (int x : b) cout << x << " ";
		cout << "\n";
	} 
	else {
		cout << "NIE\n";
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	go();
	// test();
	return 0;
}