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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define FORE(i, t) for(__typeof(t.begin())i=t.begin();i!=t.end();++i)
#define SZ(x) int((x).size())
#define REP(i, n) for(int i=0,_=(n);i<_;++i)
#define FOR(i, a, b) for(int i=(a),_=(b);i<=_;++i)
#define FORD(i, a, b) for(int i=(a),_=(b);i>=_;--i)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1e9 + 9;

#include "cielib.h"

int d, k, r;

const int MX = 503;

int mini[MX], maxi[MX];

struct Point: vi {
    bool is_axis;
    Point(int n, int value=0, bool is_axis=false): vi(n, value), is_axis(is_axis) {}

    int dist_from_left(const Point &v, bool abs) const {
        int result = INF;
//        int max_diff = 0;
//        if (!is_axis) {
//            REP (i, d) {
//                max_diff = max(max_diff, maxi[i] - mini[i] + 1);
//            }
//        }
        REP (i, d) {
//            cout << "!!! i=" << i << " v[i]=" << v[i] << " at(i)=" << at(i) << " mini=" << mini[i] << " maxi=" << maxi[i] << "\n";
            if (v[i] == 1) {
                if (abs) {
                    result = min(result, at(i));
                } else {
                    result = min(result, at(i) - mini[i]);
                }
            } else if (v[i] == -1) {
                if (abs) {
                    result = min(result, r - at(i));
                } else {
                    result = min(result, maxi[i] - at(i));
                }
            }
        }
//        cout << "!!!!!! dist_from_left: result=" << result << " abs=" << abs << "\n";
        return result;
    }

    int dist_from_right(const Point &v, bool abs) const {
        int result = INF;
//        int max_diff = 0;
//        if (!is_axis) {
//            REP (i, d) {
//                max_diff = max(max_diff, maxi[i] - mini[i] + 1);
//            }
//        }
        REP (i, d) {
            if (v[i] == 1) {
                if (abs) {
                    result = min(result, r - at(i));
                } else {
                    result = min(result, maxi[i] - at(i));
                }
            } else if (v[i] == -1) {
                if (abs) {
                    result = min(result, at(i));
                } else {
                    result = min(result, at(i) - mini[i]);
                }
            }
        }
        return result;
    }

    void add_times(const Point &v, int times) {
        REP (i, d) {
            at(i) += v[i] * times;
        }
    }

//    void print() const {
//        REP (i, d) {
//            cout << " " << at(i);
//        }
//        cout << "\n";
//    }
};

int my_czy_cieplo(const vi &v) {
    int t[d];
    REP (i, d) {
        t[i] = v[i];
    }
    --k;
    return czyCieplo(t);
}

void my_znalazlem(const vi &v) {
    int t[d];
    REP (i, d) {
        t[i] = v[i];
    }
    znalazlem(t);
    exit(0);
}

Point fit_to_vector(const Point &pos_start, const Point &v, int axis=-1) {
    Point pos = pos_start;
//    cout << "  pos start: "; pos.print();

    int left = pos.dist_from_left(v, false);
    int right = pos.dist_from_right(v, false);

//    int left = pos.dist_from_left(v, axis == -1);
//    int right = pos.dist_from_right(v, axis == -1);
//
//    int max_diff = 0;
//    if (axis == -1) {
//        REP (i, d) {
//            max_diff = max(max_diff, maxi[i] - mini[i] + 1);
//        }
//        left = min(left, max_diff / 2);
//        right = min(right, max_diff / 2);
//    }

//    cout << "  left, right: " << left << ", " << right << "\n";
    if (left > 0) {
        pos.add_times(v, -left);
    }
    my_czy_cieplo(pos);
    int a = 0, b = left + right;
//    cout << "  pos lefted: "; pos.print();
    int lefted_x = -1;
    if (axis != -1) {
        lefted_x = pos[axis];
    }
//    cout << "  v: "; v.print();
//    cout << "  a: " << a << " b: " << b << "\n";
    while (a < b) {
        int mid = (a + b) / 2;
//        cout << "    a: " << a << " b: " << b << " mid: " << mid << "\n";
        pos.add_times(v, b - a);
//        cout << "    new_pos: "; pos.print();
        int new_a = a;
        int new_b = b;
        int cieplo = my_czy_cieplo(pos);
//        cout << "   cieplo: " << cieplo << "\n";
        if (cieplo == 1) {
            new_a = mid + 1;
//                new_a = mid;
        } else {
            new_b = mid;
        }
        pos.add_times(v, -(b - new_a));
        int cieplo_wracajac = my_czy_cieplo(pos);
//        cout << "   wracajac czy cieplo: " << cieplo_wracajac << "\n";
        if (cieplo == 0 && cieplo_wracajac == 0) {
//            cout << "NIEROZROZNIALNY ZAKRES: " << a << ".." << b << "\n";
            int mid_delta = mid - a;
            if (mid_delta > 0) {
                pos.add_times(v, mid_delta);
                my_czy_cieplo(pos);
            }
            break;
        }
        a = new_a;
        b = new_b;
    }
    if (axis != -1) {
//        cout << "ZAWEZAM ZAKRES " << axis << " do " << lefted_x + a << ".." << lefted_x + b << "\n";
        mini[axis] = max(mini[axis], lefted_x + a);
        maxi[axis] = min(maxi[axis], lefted_x + b);
    }
    return pos;
}



void inline one() {
    d = podajD();
    k = podajK();
    r = podajR();

    REP (i, d) {
        mini[i] = 0;
        maxi[i] = r;
    }

    Point pos(d);
    Point last_pos = pos;
    REP (retry, MX) {
        Point v(d, 1);

        if (d > 1) {
            REP (turn, d) {
                break;
//                if (retry > 0 && turn > 0) {
                if (turn != (retry)) {
                    v[turn] = -v[turn];
                    continue;
                }
//                cout << "turn: " << turn << "\n";
                pos = fit_to_vector(pos, v);
//                cout << retry << ": pos po turze: " << turn << ": "; pos.print();
                v[turn] = -v[turn];
                cout << "\n\n";
            }
        }
//        if (pos == last_pos) {
//            break;
//        }

        vi perm(d);
        REP (i, d) {
            perm[i] = i;
        }
        random_shuffle(perm.begin(), perm.end());

        REP (i, d) {
            int axis = perm[i];
//            cout << "turn axis: " << axis << "\n";
            v = Point(d, 0, true);
            v[axis] = 1;
            if (maxi[axis] == mini[axis]) {
//                cout << "Ta os juz jest ustalona!\n";
            } else {
                pos = fit_to_vector(pos, v, axis);
            }

//            cout << retry << " pos po axis turze: " << axis << ": "; pos.print();
//            cout << "\n\n";
        }
//        REP (i, d) {
//            cout << "axis=" << i << " mini=" << mini[i] << " maxi=" << maxi[i] << " size=" << maxi[i] - mini[i] + 1 << "\n";
//        }
//        cout << "BREAK EARLY???\n";
        if (pos == last_pos) {
//            cout << "YES!\n";
            break;
        }
        last_pos = pos;
    }

    bool all_ok = true;
    REP (axis, d) {
        if (maxi[axis] != mini[axis]) {
            all_ok = false;
            break;
        }
    }

    if (!all_ok) {
//        cout << "oddalanie sie od krawedzi: ";
        REP (axis, d) {
            if (maxi[axis] == mini[axis]) {
                continue;
            }
            if (pos[axis] == 0) {
                ++pos[axis];
            } else if (pos[axis] == r) {
                --pos[axis];
            }
        }
//        pos.print();

        my_czy_cieplo(pos);

        REP (axis, d) {
            if (maxi[axis] == mini[axis]) {
                continue;
            }
            if (k < 5) {
                break;
            }
            int x = pos[axis];
//            cout << "axis: " << axis << " x: " << x << "\n";
            int fwd = x + 1;
            int fwd_delta = 0;
            if (fwd >= 0 && fwd <= r) {
                Point fwd_pos = pos;
                fwd_pos[axis] = fwd;
                if (my_czy_cieplo(fwd_pos) == 1) {
                    fwd_delta = 1;
                }
                if (my_czy_cieplo(pos) == 1) {
                    fwd_delta = -1;
                }
            }
            int back = x - 1;
            int back_delta = 0;
            if (back >= 0 && back <= r) {
                Point back_pos = pos;
                back_pos[axis] = back;
                if (my_czy_cieplo(back_pos) == 1) {
                    back_delta = 1;
                }
                if (my_czy_cieplo(pos) == 1) {
                    back_delta = -1;
                }
            }
            int delta = fwd_delta - back_delta;
//            cout << "fwd_delta: " << fwd_delta << " back_delta: " << back_delta << " delta: " << delta << "\n";
            if (delta > 1) {
                delta = 1;
            }
            if (delta < -1) {
                delta = -1;
            }
            if (delta != 0) {
                int nx = pos[axis] + delta;
                if (nx >= 0 && nx <= r) {
                    pos[axis] = nx;
                    my_czy_cieplo(pos);
//                    cout << "delting pos: "; pos.print();
                }
            }

        }
    }
//    cout << "result: "; pos.print();
//    Point result(d);
//    int *result_array = result.data();
    my_znalazlem(pos);
}

int main() {
    ios::sync_with_stdio(false);
    //int z; cin >> z; while(z--)
    one();
}