He-Ren commited on
Commit
1fe85dc
·
verified ·
1 Parent(s): 7050489

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. ICPC/nwerc2022_A/data.zip +3 -0
  2. ICPC/nwerc2022_A/init.yml +485 -0
  3. ICPC/nwerc2022_B/data.zip +3 -0
  4. ICPC/nwerc2022_B/init.yml +84 -0
  5. ICPC/nwerc2022_C/data.zip +3 -0
  6. ICPC/nwerc2022_C/init.yml +102 -0
  7. ICPC/nwerc2022_D/data.zip +3 -0
  8. ICPC/nwerc2022_D/init.yml +222 -0
  9. ICPC/nwerc2022_E/data.zip +3 -0
  10. ICPC/nwerc2022_E/init.yml +319 -0
  11. ICPC/nwerc2022_E/output_validators/output_validator/output_validator.cpp +86 -0
  12. ICPC/nwerc2022_E/output_validators/output_validator/validation.h +1520 -0
  13. ICPC/nwerc2022_F/data.zip +3 -0
  14. ICPC/nwerc2022_F/init.yml +665 -0
  15. ICPC/nwerc2022_G/data.zip +3 -0
  16. ICPC/nwerc2022_G/init.yml +624 -0
  17. ICPC/nwerc2022_G/output_validators/validate/validate.cpp +120 -0
  18. ICPC/nwerc2022_G/output_validators/validate/validate.h +154 -0
  19. ICPC/nwerc2022_H/data.zip +3 -0
  20. ICPC/nwerc2022_H/init.yml +251 -0
  21. ICPC/nwerc2022_I/data.zip +3 -0
  22. ICPC/nwerc2022_I/init.yml +223 -0
  23. ICPC/nwerc2022_I/output_validators/output_validator/output_validator.cpp +54 -0
  24. ICPC/nwerc2022_I/output_validators/output_validator/validation.h +1520 -0
  25. ICPC/nwerc2022_J/data.zip +3 -0
  26. ICPC/nwerc2022_J/init.yml +377 -0
  27. ICPC/nwerc2022_K/data.zip +3 -0
  28. ICPC/nwerc2022_K/init.yml +491 -0
  29. ICPC/nwerc2022_L/data.zip +3 -0
  30. ICPC/nwerc2022_L/init.yml +496 -0
  31. ICPC/nwerc2022_L/output_validators/validate/output-validator.cc +86 -0
  32. ICPC/nwerc2022_L/output_validators/validate/validation.h +1520 -0
  33. ICPC/nwerc2023_A/data.zip +3 -0
  34. ICPC/nwerc2023_A/init.yml +350 -0
  35. ICPC/nwerc2023_B/data.zip +3 -0
  36. ICPC/nwerc2023_B/init.yml +406 -0
  37. ICPC/nwerc2023_B/output_validators/output_validator/outputValidator.cpp +104 -0
  38. ICPC/nwerc2023_B/output_validators/output_validator/validate.h +2662 -0
  39. ICPC/nwerc2023_C/data.zip +3 -0
  40. ICPC/nwerc2023_C/init.yml +137 -0
  41. ICPC/nwerc2023_D/data.zip +3 -0
  42. ICPC/nwerc2023_D/init.yml +255 -0
  43. ICPC/nwerc2023_E/data.zip +3 -0
  44. ICPC/nwerc2023_E/init.yml +404 -0
  45. ICPC/nwerc2023_F/data.zip +3 -0
  46. ICPC/nwerc2023_F/init.yml +223 -0
  47. ICPC/nwerc2023_F/output_validators/output_validator/outputValidator.cpp +84 -0
  48. ICPC/nwerc2023_F/output_validators/output_validator/validate.h +2662 -0
  49. ICPC/nwerc2023_G/data.zip +3 -0
  50. ICPC/nwerc2023_G/init.yml +174 -0
ICPC/nwerc2022_A/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e1b74bb39283545bc56ef173c41b542756db2623c949b79bfa7618c1aedb4b3
3
+ size 34128131
ICPC/nwerc2022_A/init.yml ADDED
@@ -0,0 +1,485 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ test_cases:
3
+ - in: 001-all_small_perms.in
4
+ out: 001-all_small_perms.ans
5
+ points: 1
6
+ - in: 002-all_small_perms.in
7
+ out: 002-all_small_perms.ans
8
+ points: 1
9
+ - in: 003-all_small_perms.in
10
+ out: 003-all_small_perms.ans
11
+ points: 1
12
+ - in: 004-all_small_perms.in
13
+ out: 004-all_small_perms.ans
14
+ points: 1
15
+ - in: 005-all_small_perms.in
16
+ out: 005-all_small_perms.ans
17
+ points: 1
18
+ - in: 006-all_small_perms.in
19
+ out: 006-all_small_perms.ans
20
+ points: 1
21
+ - in: 007-all_small_perms.in
22
+ out: 007-all_small_perms.ans
23
+ points: 1
24
+ - in: 008-all_small_perms.in
25
+ out: 008-all_small_perms.ans
26
+ points: 1
27
+ - in: 009-all_small_perms.in
28
+ out: 009-all_small_perms.ans
29
+ points: 1
30
+ - in: 010-all_small_perms.in
31
+ out: 010-all_small_perms.ans
32
+ points: 1
33
+ - in: 011-all_small_perms.in
34
+ out: 011-all_small_perms.ans
35
+ points: 1
36
+ - in: 012-all_small_perms.in
37
+ out: 012-all_small_perms.ans
38
+ points: 1
39
+ - in: 013-all_small_perms.in
40
+ out: 013-all_small_perms.ans
41
+ points: 1
42
+ - in: 014-all_small_perms.in
43
+ out: 014-all_small_perms.ans
44
+ points: 1
45
+ - in: 015-all_small_perms.in
46
+ out: 015-all_small_perms.ans
47
+ points: 1
48
+ - in: 016-all_small_perms.in
49
+ out: 016-all_small_perms.ans
50
+ points: 1
51
+ - in: 017-all_small_perms.in
52
+ out: 017-all_small_perms.ans
53
+ points: 1
54
+ - in: 018-all_small_perms.in
55
+ out: 018-all_small_perms.ans
56
+ points: 1
57
+ - in: 019-all_small_perms.in
58
+ out: 019-all_small_perms.ans
59
+ points: 1
60
+ - in: 020-all_small_perms.in
61
+ out: 020-all_small_perms.ans
62
+ points: 1
63
+ - in: 021-all_small_perms.in
64
+ out: 021-all_small_perms.ans
65
+ points: 1
66
+ - in: 022-all_small_perms.in
67
+ out: 022-all_small_perms.ans
68
+ points: 1
69
+ - in: 023-all_small_perms.in
70
+ out: 023-all_small_perms.ans
71
+ points: 1
72
+ - in: 024-all_small_perms.in
73
+ out: 024-all_small_perms.ans
74
+ points: 1
75
+ - in: 025-all_small_perms.in
76
+ out: 025-all_small_perms.ans
77
+ points: 1
78
+ - in: 026-all_small_perms.in
79
+ out: 026-all_small_perms.ans
80
+ points: 1
81
+ - in: 027-all_small_perms.in
82
+ out: 027-all_small_perms.ans
83
+ points: 1
84
+ - in: 028-all_small_perms.in
85
+ out: 028-all_small_perms.ans
86
+ points: 1
87
+ - in: 029-all_small_perms.in
88
+ out: 029-all_small_perms.ans
89
+ points: 1
90
+ - in: 030-all_small_perms.in
91
+ out: 030-all_small_perms.ans
92
+ points: 1
93
+ - in: 031-all_small_perms.in
94
+ out: 031-all_small_perms.ans
95
+ points: 1
96
+ - in: 032-all_small_perms.in
97
+ out: 032-all_small_perms.ans
98
+ points: 1
99
+ - in: 033-minimal.in
100
+ out: 033-minimal.ans
101
+ points: 1
102
+ - in: 034-minimal.in
103
+ out: 034-minimal.ans
104
+ points: 1
105
+ - in: 035-minimal.in
106
+ out: 035-minimal.ans
107
+ points: 1
108
+ - in: 036-minimal.in
109
+ out: 036-minimal.ans
110
+ points: 1
111
+ - in: 037-random_small.in
112
+ out: 037-random_small.ans
113
+ points: 1
114
+ - in: 038-random_small.in
115
+ out: 038-random_small.ans
116
+ points: 1
117
+ - in: 039-random_small.in
118
+ out: 039-random_small.ans
119
+ points: 1
120
+ - in: 040-random_small.in
121
+ out: 040-random_small.ans
122
+ points: 1
123
+ - in: 041-random_small.in
124
+ out: 041-random_small.ans
125
+ points: 1
126
+ - in: 042-random_small.in
127
+ out: 042-random_small.ans
128
+ points: 1
129
+ - in: 043-random_small.in
130
+ out: 043-random_small.ans
131
+ points: 1
132
+ - in: 044-random_small.in
133
+ out: 044-random_small.ans
134
+ points: 1
135
+ - in: 045-random_small.in
136
+ out: 045-random_small.ans
137
+ points: 1
138
+ - in: 046-random_large.in
139
+ out: 046-random_large.ans
140
+ points: 1
141
+ - in: 047-random_large.in
142
+ out: 047-random_large.ans
143
+ points: 1
144
+ - in: 048-random_large.in
145
+ out: 048-random_large.ans
146
+ points: 1
147
+ - in: 049-random_large.in
148
+ out: 049-random_large.ans
149
+ points: 1
150
+ - in: 050-random_large.in
151
+ out: 050-random_large.ans
152
+ points: 1
153
+ - in: 051-random_large.in
154
+ out: 051-random_large.ans
155
+ points: 1
156
+ - in: 052-random_large.in
157
+ out: 052-random_large.ans
158
+ points: 1
159
+ - in: 053-random_large.in
160
+ out: 053-random_large.ans
161
+ points: 1
162
+ - in: 054-random_large.in
163
+ out: 054-random_large.ans
164
+ points: 1
165
+ - in: 055-random_large.in
166
+ out: 055-random_large.ans
167
+ points: 1
168
+ - in: 056-random_large.in
169
+ out: 056-random_large.ans
170
+ points: 1
171
+ - in: 057-random_large.in
172
+ out: 057-random_large.ans
173
+ points: 1
174
+ - in: 058-random_large.in
175
+ out: 058-random_large.ans
176
+ points: 1
177
+ - in: 059-random_large.in
178
+ out: 059-random_large.ans
179
+ points: 1
180
+ - in: 060-random_large.in
181
+ out: 060-random_large.ans
182
+ points: 1
183
+ - in: 061-binary.in
184
+ out: 061-binary.ans
185
+ points: 1
186
+ - in: 062-binary.in
187
+ out: 062-binary.ans
188
+ points: 1
189
+ - in: 063-same.in
190
+ out: 063-same.ans
191
+ points: 1
192
+ - in: 064-same.in
193
+ out: 064-same.ans
194
+ points: 1
195
+ - in: 065-increasing.in
196
+ out: 065-increasing.ans
197
+ points: 1
198
+ - in: 066-increasing.in
199
+ out: 066-increasing.ans
200
+ points: 1
201
+ - in: 067-decreasing.in
202
+ out: 067-decreasing.ans
203
+ points: 1
204
+ - in: 068-decreasing.in
205
+ out: 068-decreasing.ans
206
+ points: 1
207
+ - in: 069-small.in
208
+ out: 069-small.ans
209
+ points: 1
210
+ - in: 070-small.in
211
+ out: 070-small.ans
212
+ points: 1
213
+ - in: 071-small.in
214
+ out: 071-small.ans
215
+ points: 1
216
+ - in: 072-small.in
217
+ out: 072-small.ans
218
+ points: 1
219
+ - in: 073-small.in
220
+ out: 073-small.ans
221
+ points: 1
222
+ - in: 074-small.in
223
+ out: 074-small.ans
224
+ points: 1
225
+ - in: 075-small.in
226
+ out: 075-small.ans
227
+ points: 1
228
+ - in: 076-small.in
229
+ out: 076-small.ans
230
+ points: 1
231
+ - in: 077-small.in
232
+ out: 077-small.ans
233
+ points: 1
234
+ - in: 078-small.in
235
+ out: 078-small.ans
236
+ points: 1
237
+ - in: 079-small.in
238
+ out: 079-small.ans
239
+ points: 1
240
+ - in: 080-small.in
241
+ out: 080-small.ans
242
+ points: 1
243
+ - in: 081-small.in
244
+ out: 081-small.ans
245
+ points: 1
246
+ - in: 082-small.in
247
+ out: 082-small.ans
248
+ points: 1
249
+ - in: 083-small.in
250
+ out: 083-small.ans
251
+ points: 1
252
+ - in: 084-small.in
253
+ out: 084-small.ans
254
+ points: 1
255
+ - in: 085-small.in
256
+ out: 085-small.ans
257
+ points: 1
258
+ - in: 086-small.in
259
+ out: 086-small.ans
260
+ points: 1
261
+ - in: 087-small.in
262
+ out: 087-small.ans
263
+ points: 1
264
+ - in: 088-binary.in
265
+ out: 088-binary.ans
266
+ points: 1
267
+ - in: 089-binary.in
268
+ out: 089-binary.ans
269
+ points: 1
270
+ - in: 090-binary.in
271
+ out: 090-binary.ans
272
+ points: 1
273
+ - in: 091-binary.in
274
+ out: 091-binary.ans
275
+ points: 1
276
+ - in: 092-binary.in
277
+ out: 092-binary.ans
278
+ points: 1
279
+ - in: 093-binary.in
280
+ out: 093-binary.ans
281
+ points: 1
282
+ - in: 094-one-off.in
283
+ out: 094-one-off.ans
284
+ points: 1
285
+ - in: 095-max-dist.in
286
+ out: 095-max-dist.ans
287
+ points: 1
288
+ - in: 096-even-cross.in
289
+ out: 096-even-cross.ans
290
+ points: 1
291
+ - in: 097-odd-cross.in
292
+ out: 097-odd-cross.ans
293
+ points: 1
294
+ - in: 098-max-ans-front-even.in
295
+ out: 098-max-ans-front-even.ans
296
+ points: 1
297
+ - in: 099-max-ans-front-odd.in
298
+ out: 099-max-ans-front-odd.ans
299
+ points: 1
300
+ - in: 100-max-ans-back-odd.in
301
+ out: 100-max-ans-back-odd.ans
302
+ points: 1
303
+ - in: 101-max-ans-back-even.in
304
+ out: 101-max-ans-back-even.ans
305
+ points: 1
306
+ - in: 102-slow_descent_small.in
307
+ out: 102-slow_descent_small.ans
308
+ points: 1
309
+ - in: 103-slow_descent.in
310
+ out: 103-slow_descent.ans
311
+ points: 1
312
+ - in: 104-slow_descent.in
313
+ out: 104-slow_descent.ans
314
+ points: 1
315
+ - in: 105-slow_descent.in
316
+ out: 105-slow_descent.ans
317
+ points: 1
318
+ - in: 106-slow_descent.in
319
+ out: 106-slow_descent.ans
320
+ points: 1
321
+ - in: 107-slow_descent.in
322
+ out: 107-slow_descent.ans
323
+ points: 1
324
+ - in: 108-slow_descent.in
325
+ out: 108-slow_descent.ans
326
+ points: 1
327
+ - in: 109-slow_descent.in
328
+ out: 109-slow_descent.ans
329
+ points: 1
330
+ - in: 110-repeated_slow_descent_small.in
331
+ out: 110-repeated_slow_descent_small.ans
332
+ points: 1
333
+ - in: 111-repeated_slow_descent.in
334
+ out: 111-repeated_slow_descent.ans
335
+ points: 1
336
+ - in: 112-repeated_slow_descent.in
337
+ out: 112-repeated_slow_descent.ans
338
+ points: 1
339
+ - in: 113-repeated_slow_descent.in
340
+ out: 113-repeated_slow_descent.ans
341
+ points: 1
342
+ - in: 114-repeated_slow_descent.in
343
+ out: 114-repeated_slow_descent.ans
344
+ points: 1
345
+ - in: 115-repeated_slow_descent.in
346
+ out: 115-repeated_slow_descent.ans
347
+ points: 1
348
+ - in: 116-repeated_slow_descent.in
349
+ out: 116-repeated_slow_descent.ans
350
+ points: 1
351
+ - in: 117-doubling.in
352
+ out: 117-doubling.ans
353
+ points: 1
354
+ - in: 118-doubling.in
355
+ out: 118-doubling.ans
356
+ points: 1
357
+ - in: 119-doubling.in
358
+ out: 119-doubling.ans
359
+ points: 1
360
+ - in: 120-doubling.in
361
+ out: 120-doubling.ans
362
+ points: 1
363
+ - in: 121-doubling.in
364
+ out: 121-doubling.ans
365
+ points: 1
366
+ - in: 122-doubling.in
367
+ out: 122-doubling.ans
368
+ points: 1
369
+ - in: 123-doubling.in
370
+ out: 123-doubling.ans
371
+ points: 1
372
+ - in: 124-doubling.in
373
+ out: 124-doubling.ans
374
+ points: 1
375
+ - in: 125-doubling.in
376
+ out: 125-doubling.ans
377
+ points: 1
378
+ - in: 126-doubling.in
379
+ out: 126-doubling.ans
380
+ points: 1
381
+ - in: 127-doubling.in
382
+ out: 127-doubling.ans
383
+ points: 1
384
+ - in: 128-doubling.in
385
+ out: 128-doubling.ans
386
+ points: 1
387
+ - in: 129-doubling.in
388
+ out: 129-doubling.ans
389
+ points: 1
390
+ - in: 130-doubling.in
391
+ out: 130-doubling.ans
392
+ points: 1
393
+ - in: 131-doubling.in
394
+ out: 131-doubling.ans
395
+ points: 1
396
+ - in: 132-doubling.in
397
+ out: 132-doubling.ans
398
+ points: 1
399
+ - in: 133-doubling.in
400
+ out: 133-doubling.ans
401
+ points: 1
402
+ - in: 134-doubling.in
403
+ out: 134-doubling.ans
404
+ points: 1
405
+ - in: 135-doubling.in
406
+ out: 135-doubling.ans
407
+ points: 1
408
+ - in: 136-doubling.in
409
+ out: 136-doubling.ans
410
+ points: 1
411
+ - in: 137-doubling.in
412
+ out: 137-doubling.ans
413
+ points: 1
414
+ - in: 138-doubling.in
415
+ out: 138-doubling.ans
416
+ points: 1
417
+ - in: 139-doubling.in
418
+ out: 139-doubling.ans
419
+ points: 1
420
+ - in: 140-doubling.in
421
+ out: 140-doubling.ans
422
+ points: 1
423
+ - in: 141-doubling.in
424
+ out: 141-doubling.ans
425
+ points: 1
426
+ - in: 142-doubling.in
427
+ out: 142-doubling.ans
428
+ points: 1
429
+ - in: 143-doubling.in
430
+ out: 143-doubling.ans
431
+ points: 1
432
+ - in: 144-doubling.in
433
+ out: 144-doubling.ans
434
+ points: 1
435
+ - in: 145-doubling.in
436
+ out: 145-doubling.ans
437
+ points: 1
438
+ - in: 146-doubling.in
439
+ out: 146-doubling.ans
440
+ points: 1
441
+ - in: 147-doubling.in
442
+ out: 147-doubling.ans
443
+ points: 1
444
+ - in: 148-doubling.in
445
+ out: 148-doubling.ans
446
+ points: 1
447
+ - in: 149-doubling-backoff.in
448
+ out: 149-doubling-backoff.ans
449
+ points: 1
450
+ - in: 150-doubling-backoff.in
451
+ out: 150-doubling-backoff.ans
452
+ points: 1
453
+ - in: 151-doubling-backoff.in
454
+ out: 151-doubling-backoff.ans
455
+ points: 1
456
+ - in: 152-doubling-backoff.in
457
+ out: 152-doubling-backoff.ans
458
+ points: 1
459
+ - in: 153-doubling-backoff.in
460
+ out: 153-doubling-backoff.ans
461
+ points: 1
462
+ - in: 154-doubling-backoff.in
463
+ out: 154-doubling-backoff.ans
464
+ points: 1
465
+ - in: 155-doubling-backoff.in
466
+ out: 155-doubling-backoff.ans
467
+ points: 1
468
+ - in: 156-doubling-backoff.in
469
+ out: 156-doubling-backoff.ans
470
+ points: 1
471
+ - in: 157-doubling-backoff.in
472
+ out: 157-doubling-backoff.ans
473
+ points: 1
474
+ - in: 158-doubling-backoff.in
475
+ out: 158-doubling-backoff.ans
476
+ points: 1
477
+ - in: 159-doubling-backoff.in
478
+ out: 159-doubling-backoff.ans
479
+ points: 1
480
+ - in: 160-doubling-backoff.in
481
+ out: 160-doubling-backoff.ans
482
+ points: 1
483
+ - in: 161-doubling-backoff.in
484
+ out: 161-doubling-backoff.ans
485
+ points: 1
ICPC/nwerc2022_B/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0de8718ad75e9b155afd5c28e97b0008d643a918fa2fd1ab338fb538b9924db6
3
+ size 6051
ICPC/nwerc2022_B/init.yml ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ checker:
3
+ args:
4
+ precision: 6
5
+ name: floats
6
+ test_cases:
7
+ - in: 01-min.in
8
+ out: 01-min.ans
9
+ points: 1
10
+ - in: 02-max.in
11
+ out: 02-max.ans
12
+ points: 1
13
+ - in: 03-max_diff.in
14
+ out: 03-max_diff.ans
15
+ points: 1
16
+ - in: 04-max_diff.in
17
+ out: 04-max_diff.ans
18
+ points: 1
19
+ - in: 05-close.in
20
+ out: 05-close.ans
21
+ points: 1
22
+ - in: 06-close.in
23
+ out: 06-close.ans
24
+ points: 1
25
+ - in: 07-close.in
26
+ out: 07-close.ans
27
+ points: 1
28
+ - in: 08-close.in
29
+ out: 08-close.ans
30
+ points: 1
31
+ - in: 09-close.in
32
+ out: 09-close.ans
33
+ points: 1
34
+ - in: 10-close.in
35
+ out: 10-close.ans
36
+ points: 1
37
+ - in: 11-manual.in
38
+ out: 11-manual.ans
39
+ points: 1
40
+ - in: 12-manual.in
41
+ out: 12-manual.ans
42
+ points: 1
43
+ - in: 13-manual.in
44
+ out: 13-manual.ans
45
+ points: 1
46
+ - in: 14-manual.in
47
+ out: 14-manual.ans
48
+ points: 1
49
+ - in: 15-manual.in
50
+ out: 15-manual.ans
51
+ points: 1
52
+ - in: 16-manual.in
53
+ out: 16-manual.ans
54
+ points: 1
55
+ - in: 17-manual.in
56
+ out: 17-manual.ans
57
+ points: 1
58
+ - in: 18-random.in
59
+ out: 18-random.ans
60
+ points: 1
61
+ - in: 19-random.in
62
+ out: 19-random.ans
63
+ points: 1
64
+ - in: 20-random.in
65
+ out: 20-random.ans
66
+ points: 1
67
+ - in: 21-random.in
68
+ out: 21-random.ans
69
+ points: 1
70
+ - in: 22-random.in
71
+ out: 22-random.ans
72
+ points: 1
73
+ - in: 23-random.in
74
+ out: 23-random.ans
75
+ points: 1
76
+ - in: 24-random.in
77
+ out: 24-random.ans
78
+ points: 1
79
+ - in: 25-random.in
80
+ out: 25-random.ans
81
+ points: 1
82
+ - in: 26-random.in
83
+ out: 26-random.ans
84
+ points: 1
ICPC/nwerc2022_C/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9fcc1c2ccef8d81e0db764f9628bf1e0dafa1d3edeb69ef2261170ac1d7201ab
3
+ size 7287
ICPC/nwerc2022_C/init.yml ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ checker:
3
+ args:
4
+ precision: 6
5
+ name: floats
6
+ test_cases:
7
+ - in: 01-min-1.in
8
+ out: 01-min-1.ans
9
+ points: 1
10
+ - in: 02-min-2.in
11
+ out: 02-min-2.ans
12
+ points: 1
13
+ - in: 03-min-3.in
14
+ out: 03-min-3.ans
15
+ points: 1
16
+ - in: 04-min-4.in
17
+ out: 04-min-4.ans
18
+ points: 1
19
+ - in: 05-max.in
20
+ out: 05-max.ans
21
+ points: 1
22
+ - in: 06-small.in
23
+ out: 06-small.ans
24
+ points: 1
25
+ - in: 07-exact.in
26
+ out: 07-exact.ans
27
+ points: 1
28
+ - in: 08-exact.in
29
+ out: 08-exact.ans
30
+ points: 1
31
+ - in: 09-exact.in
32
+ out: 09-exact.ans
33
+ points: 1
34
+ - in: 10-exact.in
35
+ out: 10-exact.ans
36
+ points: 1
37
+ - in: 11-random.in
38
+ out: 11-random.ans
39
+ points: 1
40
+ - in: 12-random.in
41
+ out: 12-random.ans
42
+ points: 1
43
+ - in: 13-random.in
44
+ out: 13-random.ans
45
+ points: 1
46
+ - in: 14-random.in
47
+ out: 14-random.ans
48
+ points: 1
49
+ - in: 15-random.in
50
+ out: 15-random.ans
51
+ points: 1
52
+ - in: 16-random.in
53
+ out: 16-random.ans
54
+ points: 1
55
+ - in: 17-random.in
56
+ out: 17-random.ans
57
+ points: 1
58
+ - in: 18-random.in
59
+ out: 18-random.ans
60
+ points: 1
61
+ - in: 19-random.in
62
+ out: 19-random.ans
63
+ points: 1
64
+ - in: 20-random.in
65
+ out: 20-random.ans
66
+ points: 1
67
+ - in: 21-random.in
68
+ out: 21-random.ans
69
+ points: 1
70
+ - in: 22-random.in
71
+ out: 22-random.ans
72
+ points: 1
73
+ - in: 23-random.in
74
+ out: 23-random.ans
75
+ points: 1
76
+ - in: 24-random.in
77
+ out: 24-random.ans
78
+ points: 1
79
+ - in: 25-random.in
80
+ out: 25-random.ans
81
+ points: 1
82
+ - in: 26-random.in
83
+ out: 26-random.ans
84
+ points: 1
85
+ - in: 27-random.in
86
+ out: 27-random.ans
87
+ points: 1
88
+ - in: 28-random.in
89
+ out: 28-random.ans
90
+ points: 1
91
+ - in: 29-random.in
92
+ out: 29-random.ans
93
+ points: 1
94
+ - in: 30-random.in
95
+ out: 30-random.ans
96
+ points: 1
97
+ - in: 31-random.in
98
+ out: 31-random.ans
99
+ points: 1
100
+ - in: 32-random.in
101
+ out: 32-random.ans
102
+ points: 1
ICPC/nwerc2022_D/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:067de4df9a960214b3dccb34facbd8b4a88d0d2a08b2635fdc3eff1dae29feea
3
+ size 347341
ICPC/nwerc2022_D/init.yml ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ checker:
3
+ args:
4
+ precision: 6
5
+ name: floats
6
+ test_cases:
7
+ - in: 01-small-X.in
8
+ out: 01-small-X.ans
9
+ points: 1
10
+ - in: 02-small-O.in
11
+ out: 02-small-O.ans
12
+ points: 1
13
+ - in: 03-small.in
14
+ out: 03-small.ans
15
+ points: 1
16
+ - in: 04-small.in
17
+ out: 04-small.ans
18
+ points: 1
19
+ - in: 05-small.in
20
+ out: 05-small.ans
21
+ points: 1
22
+ - in: 06-row.in
23
+ out: 06-row.ans
24
+ points: 1
25
+ - in: 07-col.in
26
+ out: 07-col.ans
27
+ points: 1
28
+ - in: 08-medium.in
29
+ out: 08-medium.ans
30
+ points: 1
31
+ - in: 09-medium.in
32
+ out: 09-medium.ans
33
+ points: 1
34
+ - in: 10-medium.in
35
+ out: 10-medium.ans
36
+ points: 1
37
+ - in: 11-large-x.in
38
+ out: 11-large-x.ans
39
+ points: 1
40
+ - in: 12-large-few-o.in
41
+ out: 12-large-few-o.ans
42
+ points: 1
43
+ - in: 13-large-few-o.in
44
+ out: 13-large-few-o.ans
45
+ points: 1
46
+ - in: 14-large-few-o.in
47
+ out: 14-large-few-o.ans
48
+ points: 1
49
+ - in: 15-large-equal.in
50
+ out: 15-large-equal.ans
51
+ points: 1
52
+ - in: 16-large-many-o.in
53
+ out: 16-large-many-o.ans
54
+ points: 1
55
+ - in: 17-large-many-o.in
56
+ out: 17-large-many-o.ans
57
+ points: 1
58
+ - in: 18-large-many-o.in
59
+ out: 18-large-many-o.ans
60
+ points: 1
61
+ - in: 19-large-o.in
62
+ out: 19-large-o.ans
63
+ points: 1
64
+ - in: 20-tall.in
65
+ out: 20-tall.ans
66
+ points: 1
67
+ - in: 21-tall.in
68
+ out: 21-tall.ans
69
+ points: 1
70
+ - in: 22-tall.in
71
+ out: 22-tall.ans
72
+ points: 1
73
+ - in: 23-tall.in
74
+ out: 23-tall.ans
75
+ points: 1
76
+ - in: 24-wide.in
77
+ out: 24-wide.ans
78
+ points: 1
79
+ - in: 25-wide.in
80
+ out: 25-wide.ans
81
+ points: 1
82
+ - in: 26-wide.in
83
+ out: 26-wide.ans
84
+ points: 1
85
+ - in: 27-wide.in
86
+ out: 27-wide.ans
87
+ points: 1
88
+ - in: 28-large.in
89
+ out: 28-large.ans
90
+ points: 1
91
+ - in: 29-large-o.in
92
+ out: 29-large-o.ans
93
+ points: 1
94
+ - in: 30-large-x.in
95
+ out: 30-large-x.ans
96
+ points: 1
97
+ - in: 31-large-few-o.in
98
+ out: 31-large-few-o.ans
99
+ points: 1
100
+ - in: 32-large-many-o.in
101
+ out: 32-large-many-o.ans
102
+ points: 1
103
+ - in: 33-max.in
104
+ out: 33-max.ans
105
+ points: 1
106
+ - in: 34-max-o.in
107
+ out: 34-max-o.ans
108
+ points: 1
109
+ - in: 35-max-x.in
110
+ out: 35-max-x.ans
111
+ points: 1
112
+ - in: 36-max-few-o.in
113
+ out: 36-max-few-o.ans
114
+ points: 1
115
+ - in: 37-max-many-o.in
116
+ out: 37-max-many-o.ans
117
+ points: 1
118
+ - in: 38-diag.in
119
+ out: 38-diag.ans
120
+ points: 1
121
+ - in: 39-diag.in
122
+ out: 39-diag.ans
123
+ points: 1
124
+ - in: 40-diag.in
125
+ out: 40-diag.ans
126
+ points: 1
127
+ - in: 41-diag.in
128
+ out: 41-diag.ans
129
+ points: 1
130
+ - in: 42-diag-small.in
131
+ out: 42-diag-small.ans
132
+ points: 1
133
+ - in: 43-diag-small.in
134
+ out: 43-diag-small.ans
135
+ points: 1
136
+ - in: 44-diag-small.in
137
+ out: 44-diag-small.ans
138
+ points: 1
139
+ - in: 45-diag-small.in
140
+ out: 45-diag-small.ans
141
+ points: 1
142
+ - in: 46-diag-400.in
143
+ out: 46-diag-400.ans
144
+ points: 1
145
+ - in: 47-diag-400.in
146
+ out: 47-diag-400.ans
147
+ points: 1
148
+ - in: 48-diag-400.in
149
+ out: 48-diag-400.ans
150
+ points: 1
151
+ - in: 49-diag-400.in
152
+ out: 49-diag-400.ans
153
+ points: 1
154
+ - in: 50-diag-700.in
155
+ out: 50-diag-700.ans
156
+ points: 1
157
+ - in: 51-diag-700.in
158
+ out: 51-diag-700.ans
159
+ points: 1
160
+ - in: 52-diag-700.in
161
+ out: 52-diag-700.ans
162
+ points: 1
163
+ - in: 53-diag-700.in
164
+ out: 53-diag-700.ans
165
+ points: 1
166
+ - in: 54-manual.in
167
+ out: 54-manual.ans
168
+ points: 1
169
+ - in: 55-manual.in
170
+ out: 55-manual.ans
171
+ points: 1
172
+ - in: 56-manual.in
173
+ out: 56-manual.ans
174
+ points: 1
175
+ - in: 57-manual.in
176
+ out: 57-manual.ans
177
+ points: 1
178
+ - in: 58-manual.in
179
+ out: 58-manual.ans
180
+ points: 1
181
+ - in: 59-manual.in
182
+ out: 59-manual.ans
183
+ points: 1
184
+ - in: 60-diag.in
185
+ out: 60-diag.ans
186
+ points: 1
187
+ - in: 61-diag.in
188
+ out: 61-diag.ans
189
+ points: 1
190
+ - in: 62-diag.in
191
+ out: 62-diag.ans
192
+ points: 1
193
+ - in: 63-diag.in
194
+ out: 63-diag.ans
195
+ points: 1
196
+ - in: 64-diag.in
197
+ out: 64-diag.ans
198
+ points: 1
199
+ - in: 65-corner1.in
200
+ out: 65-corner1.ans
201
+ points: 1
202
+ - in: 66-corner2.in
203
+ out: 66-corner2.ans
204
+ points: 1
205
+ - in: 67-sidel.in
206
+ out: 67-sidel.ans
207
+ points: 1
208
+ - in: 68-sider.in
209
+ out: 68-sider.ans
210
+ points: 1
211
+ - in: 69-sideu.in
212
+ out: 69-sideu.ans
213
+ points: 1
214
+ - in: 70-sided.in
215
+ out: 70-sided.ans
216
+ points: 1
217
+ - in: 71-moon1.in
218
+ out: 71-moon1.ans
219
+ points: 1
220
+ - in: 72-moon2.in
221
+ out: 72-moon2.ans
222
+ points: 1
ICPC/nwerc2022_E/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:931f1f2c289de53af9c2c4f82799bb43e88e4985ec051891224c306ffe111a88
3
+ size 115467
ICPC/nwerc2022_E/init.yml ADDED
@@ -0,0 +1,319 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ checker:
3
+ args:
4
+ files:
5
+ - output_validators/output_validator/output_validator.cpp
6
+ - output_validators/output_validator/validation.h
7
+ lang: CPP17
8
+ type: default
9
+ name: bridged
10
+ test_cases:
11
+ - in: 001-kill-denominator.in
12
+ out: 001-kill-denominator.ans
13
+ points: 1
14
+ - in: 002-kill-denominator.in
15
+ out: 002-kill-denominator.ans
16
+ points: 1
17
+ - in: 003-kill-denominator.in
18
+ out: 003-kill-denominator.ans
19
+ points: 1
20
+ - in: 004-minimal-input.in
21
+ out: 004-minimal-input.ans
22
+ points: 1
23
+ - in: 005-minimal-ab.in
24
+ out: 005-minimal-ab.ans
25
+ points: 1
26
+ - in: 006-maximal-input.in
27
+ out: 006-maximal-input.ans
28
+ points: 1
29
+ - in: 007-maximal-input.in
30
+ out: 007-maximal-input.ans
31
+ points: 1
32
+ - in: 008-maximal-ab.in
33
+ out: 008-maximal-ab.ans
34
+ points: 1
35
+ - in: 009-maximal-not-int.in
36
+ out: 009-maximal-not-int.ans
37
+ points: 1
38
+ - in: 010-maximal-not-int.in
39
+ out: 010-maximal-not-int.ans
40
+ points: 1
41
+ - in: 011-manual-tricky.in
42
+ out: 011-manual-tricky.ans
43
+ points: 1
44
+ - in: 012-manual-tricky.in
45
+ out: 012-manual-tricky.ans
46
+ points: 1
47
+ - in: 013-manual-tricky.in
48
+ out: 013-manual-tricky.ans
49
+ points: 1
50
+ - in: 014-just-impossible.in
51
+ out: 014-just-impossible.ans
52
+ points: 1
53
+ - in: 015-just-impossible.in
54
+ out: 015-just-impossible.ans
55
+ points: 1
56
+ - in: 016-just-impossible.in
57
+ out: 016-just-impossible.ans
58
+ points: 1
59
+ - in: 017-manual-half.in
60
+ out: 017-manual-half.ans
61
+ points: 1
62
+ - in: 018-manual-half.in
63
+ out: 018-manual-half.ans
64
+ points: 1
65
+ - in: 019-manual-half.in
66
+ out: 019-manual-half.ans
67
+ points: 1
68
+ - in: 020-manual-two.in
69
+ out: 020-manual-two.ans
70
+ points: 1
71
+ - in: 021-manual-two.in
72
+ out: 021-manual-two.ans
73
+ points: 1
74
+ - in: 022-manual-two.in
75
+ out: 022-manual-two.ans
76
+ points: 1
77
+ - in: 023-manual-two.in
78
+ out: 023-manual-two.ans
79
+ points: 1
80
+ - in: 024-manual-two.in
81
+ out: 024-manual-two.ans
82
+ points: 1
83
+ - in: 025-manual-two.in
84
+ out: 025-manual-two.ans
85
+ points: 1
86
+ - in: 026-manual-two.in
87
+ out: 026-manual-two.ans
88
+ points: 1
89
+ - in: 027-manual-three.in
90
+ out: 027-manual-three.ans
91
+ points: 1
92
+ - in: 028-manual-three.in
93
+ out: 028-manual-three.ans
94
+ points: 1
95
+ - in: 029-manual-three.in
96
+ out: 029-manual-three.ans
97
+ points: 1
98
+ - in: 030-manual-three.in
99
+ out: 030-manual-three.ans
100
+ points: 1
101
+ - in: 031-manual-three.in
102
+ out: 031-manual-three.ans
103
+ points: 1
104
+ - in: 032-manual-triangular.in
105
+ out: 032-manual-triangular.ans
106
+ points: 1
107
+ - in: 033-manual-triangular.in
108
+ out: 033-manual-triangular.ans
109
+ points: 1
110
+ - in: 034-manual-triangular.in
111
+ out: 034-manual-triangular.ans
112
+ points: 1
113
+ - in: 035-manual-triangular.in
114
+ out: 035-manual-triangular.ans
115
+ points: 1
116
+ - in: 036-manual-triangular.in
117
+ out: 036-manual-triangular.ans
118
+ points: 1
119
+ - in: 037-manual-triangular.in
120
+ out: 037-manual-triangular.ans
121
+ points: 1
122
+ - in: 038-manual-triangular.in
123
+ out: 038-manual-triangular.ans
124
+ points: 1
125
+ - in: 039-manual-triangular.in
126
+ out: 039-manual-triangular.ans
127
+ points: 1
128
+ - in: 040-manual-triangular.in
129
+ out: 040-manual-triangular.ans
130
+ points: 1
131
+ - in: 041-manual-triangular.in
132
+ out: 041-manual-triangular.ans
133
+ points: 1
134
+ - in: 042-manual-triangular.in
135
+ out: 042-manual-triangular.ans
136
+ points: 1
137
+ - in: 043-manual-triangular.in
138
+ out: 043-manual-triangular.ans
139
+ points: 1
140
+ - in: 044-manual-triangular.in
141
+ out: 044-manual-triangular.ans
142
+ points: 1
143
+ - in: 045-manual-triangular.in
144
+ out: 045-manual-triangular.ans
145
+ points: 1
146
+ - in: 046-manual-triangular.in
147
+ out: 046-manual-triangular.ans
148
+ points: 1
149
+ - in: 047-manual-triangular.in
150
+ out: 047-manual-triangular.ans
151
+ points: 1
152
+ - in: 048-manual-triangular.in
153
+ out: 048-manual-triangular.ans
154
+ points: 1
155
+ - in: 049-manual-triangular.in
156
+ out: 049-manual-triangular.ans
157
+ points: 1
158
+ - in: 050-manual-triangular.in
159
+ out: 050-manual-triangular.ans
160
+ points: 1
161
+ - in: 051-manual-triangular.in
162
+ out: 051-manual-triangular.ans
163
+ points: 1
164
+ - in: 052-manual-power.in
165
+ out: 052-manual-power.ans
166
+ points: 1
167
+ - in: 053-manual-power.in
168
+ out: 053-manual-power.ans
169
+ points: 1
170
+ - in: 054-manual-power.in
171
+ out: 054-manual-power.ans
172
+ points: 1
173
+ - in: 055-impossible.in
174
+ out: 055-impossible.ans
175
+ points: 1
176
+ - in: 056-impossible.in
177
+ out: 056-impossible.ans
178
+ points: 1
179
+ - in: 057-impossible.in
180
+ out: 057-impossible.ans
181
+ points: 1
182
+ - in: 058-impossible.in
183
+ out: 058-impossible.ans
184
+ points: 1
185
+ - in: 059-impossible.in
186
+ out: 059-impossible.ans
187
+ points: 1
188
+ - in: 060-impossible.in
189
+ out: 060-impossible.ans
190
+ points: 1
191
+ - in: 061-impossible.in
192
+ out: 061-impossible.ans
193
+ points: 1
194
+ - in: 062-impossible.in
195
+ out: 062-impossible.ans
196
+ points: 1
197
+ - in: 063-impossible.in
198
+ out: 063-impossible.ans
199
+ points: 1
200
+ - in: 064-impossible.in
201
+ out: 064-impossible.ans
202
+ points: 1
203
+ - in: 065-just-possible.in
204
+ out: 065-just-possible.ans
205
+ points: 1
206
+ - in: 066-just-possible.in
207
+ out: 066-just-possible.ans
208
+ points: 1
209
+ - in: 067-just-possible.in
210
+ out: 067-just-possible.ans
211
+ points: 1
212
+ - in: 068-just-possible.in
213
+ out: 068-just-possible.ans
214
+ points: 1
215
+ - in: 069-just-possible.in
216
+ out: 069-just-possible.ans
217
+ points: 1
218
+ - in: 070-just-possible.in
219
+ out: 070-just-possible.ans
220
+ points: 1
221
+ - in: 071-just-possible.in
222
+ out: 071-just-possible.ans
223
+ points: 1
224
+ - in: 072-just-possible.in
225
+ out: 072-just-possible.ans
226
+ points: 1
227
+ - in: 073-just-possible.in
228
+ out: 073-just-possible.ans
229
+ points: 1
230
+ - in: 074-just-possible.in
231
+ out: 074-just-possible.ans
232
+ points: 1
233
+ - in: 075-random.in
234
+ out: 075-random.ans
235
+ points: 1
236
+ - in: 076-random.in
237
+ out: 076-random.ans
238
+ points: 1
239
+ - in: 077-random.in
240
+ out: 077-random.ans
241
+ points: 1
242
+ - in: 078-random.in
243
+ out: 078-random.ans
244
+ points: 1
245
+ - in: 079-random.in
246
+ out: 079-random.ans
247
+ points: 1
248
+ - in: 080-random.in
249
+ out: 080-random.ans
250
+ points: 1
251
+ - in: 081-random.in
252
+ out: 081-random.ans
253
+ points: 1
254
+ - in: 082-random.in
255
+ out: 082-random.ans
256
+ points: 1
257
+ - in: 083-random.in
258
+ out: 083-random.ans
259
+ points: 1
260
+ - in: 084-random.in
261
+ out: 084-random.ans
262
+ points: 1
263
+ - in: 085-random.in
264
+ out: 085-random.ans
265
+ points: 1
266
+ - in: 086-random.in
267
+ out: 086-random.ans
268
+ points: 1
269
+ - in: 087-random.in
270
+ out: 087-random.ans
271
+ points: 1
272
+ - in: 088-random.in
273
+ out: 088-random.ans
274
+ points: 1
275
+ - in: 089-random.in
276
+ out: 089-random.ans
277
+ points: 1
278
+ - in: 090-random.in
279
+ out: 090-random.ans
280
+ points: 1
281
+ - in: 091-random.in
282
+ out: 091-random.ans
283
+ points: 1
284
+ - in: 092-random.in
285
+ out: 092-random.ans
286
+ points: 1
287
+ - in: 093-random.in
288
+ out: 093-random.ans
289
+ points: 1
290
+ - in: 094-large.in
291
+ out: 094-large.ans
292
+ points: 1
293
+ - in: 095-large.in
294
+ out: 095-large.ans
295
+ points: 1
296
+ - in: 096-large.in
297
+ out: 096-large.ans
298
+ points: 1
299
+ - in: 097-large.in
300
+ out: 097-large.ans
301
+ points: 1
302
+ - in: 098-large.in
303
+ out: 098-large.ans
304
+ points: 1
305
+ - in: 099-large.in
306
+ out: 099-large.ans
307
+ points: 1
308
+ - in: 100-large.in
309
+ out: 100-large.ans
310
+ points: 1
311
+ - in: 101-large.in
312
+ out: 101-large.ans
313
+ points: 1
314
+ - in: 102-large.in
315
+ out: 102-large.ans
316
+ points: 1
317
+ - in: 103-large.in
318
+ out: 103-large.ans
319
+ points: 1
ICPC/nwerc2022_E/output_validators/output_validator/output_validator.cpp ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #include<cstdlib>
3
+ int qwerty_getcode(int code) {
4
+ return code == 42? 0: 1;
5
+ }
6
+ namespace std {
7
+ void qwerty_exit(int code){
8
+ exit(qwerty_getcode(code));
9
+ }
10
+ } using std::qwerty_exit;
11
+ #define exit qwerty_exit
12
+ #define main qwerty_main
13
+ #include "validation.h"
14
+ using std::vector;
15
+ using std::string;
16
+
17
+ // Output: a list of `n` page flips from `i` to `j`.
18
+
19
+ int main(int argc, char **argv) {
20
+ // Set up the input and answer streams.
21
+ std::ifstream in(argv[1]);
22
+ std::ifstream ans(argv[2]); // Only for custom checker.
23
+ OutputValidator v(argc, argv);
24
+
25
+ long long a,b;
26
+ char c;
27
+ in >> a >> c >> b;
28
+ string s;
29
+ ans >> s;
30
+ if (s == "impossible"){
31
+ v.test_string("impossible");
32
+ v.newline();
33
+ }
34
+ else {
35
+ long long n = v.read_integer("n",1,1e6);
36
+ v.space();
37
+ long long m = v.read_integer("m",1,1e6);
38
+ v.newline();
39
+ vector<vector<long long>> graph(n+1,vector<long long>{});
40
+ for (long long i=0;i<m;i++){
41
+ long long x = v.read_integer("x", 1, n);
42
+ v.space();
43
+ long long y = v.read_integer("x", 1, n);
44
+ v.newline();
45
+ graph[x].push_back(y);
46
+ graph[y].push_back(x);
47
+ }
48
+ long long total = 0;
49
+ vector<bool> visited(n+1);
50
+ vector<long long> queue_out, queue_in;
51
+ long long distance = 0;
52
+ queue_out.push_back(1);
53
+ while (queue_out.size() > 0){
54
+ for (long long i : queue_out){
55
+ if (visited[i])
56
+ continue;
57
+ total += distance;
58
+ visited[i] = true;
59
+ for (long long j : graph[i])
60
+ queue_in.push_back(j);
61
+ }
62
+ queue_out = queue_in;
63
+ queue_in = {};
64
+ distance += 1;
65
+ }
66
+ for (long long i=1;i<=n;i++) v.check(visited[i], "Graph not connected, vertex ", i, " unreachable");
67
+ std::cerr << total << '/' << n << std::endl;
68
+ v.check(a*n == total*b, "Wrong average distance, got ", total, "/", n, ", wanted ", a, "/", b);
69
+ }
70
+ }
71
+
72
+ #undef main
73
+ #include<cstdio>
74
+ #include<vector>
75
+ #include<string>
76
+ #include<filesystem>
77
+ int main(int argc, char **argv) {
78
+ namespace fs = std::filesystem;
79
+ freopen(argv[2], "r", stdin);
80
+ char judge_out[] = "/dev";
81
+ std::vector<char*> new_argv = {
82
+ argv[0], argv[1], argv[3],
83
+ judge_out,
84
+ };
85
+ return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data()));
86
+ }
ICPC/nwerc2022_E/output_validators/output_validator/validation.h ADDED
@@ -0,0 +1,1520 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ // A header library to safely parse team input.
3
+ // It does not support floating points or big integers.
4
+ // Author: Ragnar Groot Koerkamp
5
+
6
+ // The easiest way to use this is to symlink it from a validator directory,
7
+ // so that it will be picked up when creating a contest zip.
8
+
9
+ // The default checking behaviour is lenient for both white space and case.
10
+ // When validating .in and .ans files, the case_sensitive and
11
+ // space_change_sensitive flags should be passed. When validating team output,
12
+ // the flags in problem.yaml should be used.
13
+
14
+ // Compile with -Duse_source_location to enable
15
+ // std::experimental::source_location. This is needed for constraints checking.
16
+
17
+ #include <algorithm>
18
+ #include <array>
19
+ #include <bitset>
20
+ #include <cassert>
21
+ #include <charconv>
22
+ #include <cstring>
23
+ #include <fstream>
24
+ #include <functional>
25
+ #include <iomanip>
26
+ #include <iostream>
27
+ #include <limits>
28
+ #include <map>
29
+ #include <optional>
30
+ #include <random>
31
+ #include <set>
32
+ #include <stdexcept>
33
+ #include <string>
34
+ #include <string_view>
35
+ #include <type_traits>
36
+ #include <unordered_map>
37
+ #include <utility>
38
+ #include <variant>
39
+ #include <vector>
40
+
41
+ #ifdef use_source_location
42
+ #include <experimental/source_location>
43
+ constexpr bool has_source_location = true;
44
+ using std::experimental::source_location;
45
+ namespace std {
46
+ bool operator<(const source_location& l, const source_location& r) {
47
+ return l.line() < r.line();
48
+ }
49
+ } // namespace std
50
+ namespace std::experimental::fundamentals_v2 {
51
+ bool operator<(const source_location& l, const source_location& r) {
52
+ return l.line() < r.line();
53
+ }
54
+ } // namespace std::experimental::fundamentals_v2
55
+ #else
56
+ constexpr bool has_source_location = false;
57
+ struct source_location {
58
+ static source_location current() { return {}; }
59
+ [[nodiscard]] int line() const { return 0; } // NOLINT
60
+ [[nodiscard]] std::string file_name() const { return ""; } // NOLINT
61
+ };
62
+ inline bool operator<(const source_location& l, const source_location& r) {
63
+ return l.line() < r.line();
64
+ }
65
+ #endif
66
+
67
+ inline std::string location_to_string(source_location loc) {
68
+ return std::string(loc.file_name()) + ":" + std::to_string(loc.line());
69
+ }
70
+
71
+ const std::string_view case_sensitive_flag = "case_sensitive";
72
+ const std::string_view ws_sensitive_flag = "space_change_sensitive";
73
+ const std::string_view constraints_file_flag = "--constraints_file";
74
+ const std::string_view generate_flag = "--generate";
75
+ const std::string_view generate_binary_substring = "generat";
76
+
77
+ inline struct ArbitraryTag {
78
+ static constexpr bool unique = false;
79
+ static constexpr bool strict = false;
80
+ static constexpr bool increasing = false;
81
+ static constexpr bool decreasing = false;
82
+ } Arbitrary;
83
+ inline struct UniqueTag : ArbitraryTag {
84
+ static constexpr bool unique = true;
85
+ static constexpr bool strict = false;
86
+ static constexpr bool increasing = false;
87
+ static constexpr bool decreasing = false;
88
+ } Unique;
89
+ inline struct IncreasingTag : ArbitraryTag { static constexpr bool increasing = true; } Increasing;
90
+ inline struct DecreasingTag : ArbitraryTag { static constexpr bool decreasing = true; } Decreasing;
91
+ inline struct StrictlyIncreasingTag : ArbitraryTag {
92
+ static constexpr bool strict = true;
93
+ static constexpr bool increasing = true;
94
+ } StrictlyIncreasing;
95
+ inline struct StrictlyDecreasingTag : ArbitraryTag {
96
+ static constexpr bool strict = true;
97
+ static constexpr bool decreasing = true;
98
+ } StrictlyDecreasing;
99
+
100
+ template <typename... T>
101
+ struct Merge : T... {
102
+ static constexpr bool unique = (T::unique || ...);
103
+ static constexpr bool strict = (T::strict || ...);
104
+ static constexpr bool increasing = (T::increasing || ...);
105
+ static constexpr bool decreasing = (T::decreasing || ...);
106
+ };
107
+
108
+ template <typename T1, typename T2,
109
+ std::enable_if_t<
110
+ std::is_base_of_v<ArbitraryTag, T1> and std::is_base_of_v<ArbitraryTag, T2>, int> = 0>
111
+ auto operator|(T1 /*unused*/, T2 /*unused*/) {
112
+ return Merge<T1, T2>();
113
+ }
114
+
115
+ enum Separator { Space, Newline };
116
+
117
+ // this contains some specific code which emulates c++20 features
118
+ namespace cpp20 {
119
+
120
+ constexpr int countl_zero(unsigned long long x) {
121
+ int res = 64;
122
+ for(int i = 32; i > 0; i >>= 1) {
123
+ if((x >> i) > 0) {
124
+ res -= i;
125
+ x >>= i;
126
+ }
127
+ }
128
+ if(x > 0) res--;
129
+ return res;
130
+ }
131
+
132
+ int popcount(unsigned long long x) {
133
+ return static_cast<int>(std::bitset<64>(x).count());
134
+ }
135
+
136
+ constexpr long double PI = 3.141592653589793238462643383279502884l;
137
+
138
+ } // namespace cpp20
139
+
140
+ namespace Random {
141
+
142
+ constexpr unsigned int default_seed = 3141592653; // some digits of PI
143
+
144
+ unsigned long long bits64(std::mt19937_64& rng) {
145
+ static_assert(std::mt19937_64::max() == 0xFFFF'FFFF'FFFF'FFFFull);
146
+ static_assert(std::mt19937_64::min() == 0ull);
147
+ return rng();
148
+ }
149
+
150
+ // generates a uniform real in [0, 1)
151
+ long double real64(std::mt19937_64& rng) {
152
+ // a long double can represent more than 2^64 values in the range [0, 1)...
153
+ // another problem is that real64() < 1.0/3.0 is technically biased.
154
+ long double res = bits64(rng) / 0x1.0p64l;
155
+ res += bits64(rng) / 0x1.0p128l;
156
+ assert(res < 1.0l);
157
+ return res;
158
+ }
159
+
160
+ bool bit(std::mt19937_64& rng) {
161
+ return cpp20::popcount(bits64(rng)) & 1;
162
+ }
163
+
164
+ } // namespace Random
165
+
166
+ template <typename T>
167
+ constexpr bool is_number_v = std::is_same_v<T, long long> or std::is_same_v<T, long double>;
168
+
169
+ namespace Generators {
170
+
171
+ template <typename T>
172
+ struct ConstGenerator {
173
+ static_assert(is_number_v<T> or std::is_same_v<T, char> or std::is_same_v<T, std::string>);
174
+ static constexpr std::string_view name = "const";
175
+ using Args = std::tuple<T>;
176
+
177
+ const T const_;
178
+
179
+ explicit ConstGenerator(T val) : const_(std::move(val)) {}
180
+
181
+ // For char and string, the constant store has a different type than the min and max length
182
+ // passed in.
183
+ template <typename U>
184
+ T operator()(U low, U high, std::mt19937_64& rng) const {
185
+ return std::clamp(const_, low, high);
186
+ }
187
+ };
188
+
189
+ struct MinGenerator {
190
+ static constexpr std::string_view name = "min";
191
+ using Args = std::tuple<>;
192
+
193
+ explicit MinGenerator() = default;
194
+
195
+ template <typename T>
196
+ T operator()(T low, T high, std::mt19937_64& rng) const {
197
+ static_assert(is_number_v<T>);
198
+ return low;
199
+ }
200
+ };
201
+
202
+ struct MaxGenerator {
203
+ static constexpr std::string_view name = "max";
204
+ using Args = std::tuple<>;
205
+
206
+ explicit MaxGenerator() = default;
207
+
208
+ template <typename T>
209
+ T operator()(T low, T high, std::mt19937_64& rng) const {
210
+ static_assert(is_number_v<T>);
211
+ return high;
212
+ }
213
+ };
214
+
215
+ struct UniformGenerator {
216
+ static constexpr std::string_view name = "uniform";
217
+ using Args = std::tuple<>;
218
+
219
+ explicit UniformGenerator() = default;
220
+
221
+ template <typename T>
222
+ T operator()(T low, T high, std::mt19937_64& rng) const {
223
+ static_assert(is_number_v<T>);
224
+ if(low == high) return low;
225
+
226
+ if constexpr(std::is_same_v<T, long long>) {
227
+ assert(low < high);
228
+ // Since C++20 we can assume Two's Complement but any sane system used it before anyway.
229
+ // Rejection sampling is not as fast as possible but definitely unbiased.
230
+ auto ul = static_cast<unsigned long long>(low);
231
+ auto uh = static_cast<unsigned long long>(high);
232
+ int shifts = cpp20::countl_zero(uh - ul);
233
+ unsigned long long res;
234
+ do {
235
+ res = Random::bits64(rng) >> shifts;
236
+ } while(res > uh - ul);
237
+ return static_cast<long long>(res + ul);
238
+ } else {
239
+ assert(low < high);
240
+ return low + Random::real64(rng) * (high - low);
241
+ }
242
+ }
243
+ };
244
+
245
+ template <typename T>
246
+ struct RangeGenerator {
247
+ static_assert(is_number_v<T>);
248
+ static constexpr std::string_view name = "range";
249
+ using Args = std::tuple<T, T>;
250
+
251
+ const T low_, high_;
252
+
253
+ explicit RangeGenerator(T low, T high) : low_(low), high_(high) {}
254
+
255
+ T operator()(T low, T high, std::mt19937_64& rng) const {
256
+ return UniformGenerator()(std::max(low, low_), std::min(high, high_), rng);
257
+ }
258
+ };
259
+
260
+ template <typename T>
261
+ struct StepRangeGenerator {
262
+ static_assert(is_number_v<T>);
263
+ static constexpr std::string_view name = "steprange";
264
+ using Args = std::tuple<T, T, T>;
265
+
266
+ const T low_, high_, step_;
267
+
268
+ explicit StepRangeGenerator(T low, T high, T step) : low_(low), high_(high), step_(step) {}
269
+
270
+ T operator()(T low, T high, std::mt19937_64& rng) const {
271
+ // round up low to the first multiple of step_.
272
+ T start;
273
+ if(low <= low_) {
274
+ start = low_;
275
+ } else {
276
+ // first multiple of low_+k*step_ >= low
277
+ start = low_ + (long long)((low - low_) / step_) * step_;
278
+ if(start < low) start += step_;
279
+ assert(low <= start && start < low + step_);
280
+ }
281
+ long long maxsteps = (std::min(high, high_) - start) / step_;
282
+ long long steps = UniformGenerator()(0ll, maxsteps, rng);
283
+ return start + steps * step_;
284
+ }
285
+ };
286
+
287
+ struct NormalDistributionGenerator {
288
+ static constexpr std::string_view name = "normal";
289
+ using T = long double;
290
+ using Args = std::tuple<T, T>;
291
+
292
+ const T mean_, stddev_;
293
+
294
+ explicit NormalDistributionGenerator(T mean, T stddev) : mean_(mean), stddev_(stddev) {
295
+ assert(stddev_ >= 0);
296
+ }
297
+
298
+ // NOTE: Currently this retries instead of clamping to the interval.
299
+ T operator()(T low, T high, std::mt19937_64& rng) const {
300
+ assert(low < high);
301
+ T v;
302
+ while(true) {
303
+ T u1 = Random::real64(rng);
304
+ T u2 = Random::real64(rng);
305
+ // Box-Muller-Methode
306
+ // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
307
+ v = std::sqrt(-2.0l * std::log(u1)) * std::cos(2.0l * cpp20::PI * u2);
308
+ v = std::sqrt(stddev_) * v + mean_;
309
+ if(v >= low && v < high) return v;
310
+ v = std::sqrt(-2.0l * std::log(u1)) * std::sin(2.0l * cpp20::PI * u2);
311
+ v = std::sqrt(stddev_) * v + mean_;
312
+ if(v >= low && v < high) return v;
313
+ }
314
+ return v;
315
+ }
316
+ };
317
+
318
+ struct ExponentialDistributionGenerator {
319
+ static constexpr std::string_view name = "exponential";
320
+ using T = long double;
321
+ using Args = std::tuple<T>;
322
+
323
+ T lambda_;
324
+
325
+ explicit ExponentialDistributionGenerator(T lambda) : lambda_(lambda) { assert(lambda_ > 0); }
326
+
327
+ // NOTE: Currently this retries instead of clamping to the interval.
328
+ T operator()(T low, T high, std::mt19937_64& rng) const {
329
+ assert(low < high);
330
+ T v;
331
+ while(true) {
332
+ v = low - std::log(Random::real64(rng)) / lambda_;
333
+ if(v < high) return v;
334
+ }
335
+ }
336
+ };
337
+
338
+ struct GeometricDistributionGenerator {
339
+ static constexpr std::string_view name = "geometric";
340
+ using T = long long;
341
+ using Args = std::tuple<long double>;
342
+
343
+ double p_;
344
+
345
+ explicit GeometricDistributionGenerator(double p) : p_(p) {
346
+ assert(p_ > 0);
347
+ assert(p_ < 1);
348
+ }
349
+
350
+ // NOTE: Currently this retries instead of clamping to the interval.
351
+ T operator()(T low, T high, std::mt19937_64& rng) const {
352
+ assert(low <= high);
353
+ T v;
354
+ while(true) {
355
+ // https://en.wikipedia.org/wiki/Geometric_distribution
356
+ // "The exponential distribution is the continuous analogue of the geometric
357
+ // distribution[...]"
358
+ v = low + std::floor(std::log(Random::real64(rng)) / std::log1p(-p_));
359
+ if(v <= high) return v;
360
+ }
361
+ }
362
+ };
363
+
364
+ struct BinomialDistributionGenerator {
365
+ static constexpr std::string_view name = "binomial";
366
+ using T = long long;
367
+ using Args = std::tuple<long long, long double>;
368
+
369
+ long long n_;
370
+ double p_;
371
+
372
+ explicit BinomialDistributionGenerator(long long n, double p) : n_(n), p_(p) {
373
+ assert(p_ >= 0);
374
+ assert(p_ <= 1);
375
+ std::cerr << "Warning: Large n (" << n_ << ") is slow for BinomialDistributionGenerator!"
376
+ << std::endl;
377
+ }
378
+
379
+ // NOTE: Currently this retries instead of clamping to the interval.
380
+ T operator()(T low, T high, std::mt19937_64& rng) const {
381
+ assert(low <= high);
382
+ // this will be slow for large n
383
+ // (a faster implementation requires efficient poisson sampling)
384
+ while(true) {
385
+ T v = 0;
386
+ for(long long i = 0; i < n_; i++) {
387
+ v += Random::real64(rng) < p_ ? 1 : 0;
388
+ }
389
+ if(v >= low && v <= high) return v;
390
+ }
391
+ }
392
+ };
393
+
394
+ template <typename T>
395
+ struct ChoiceGenerator {
396
+ using GeneratorType = std::conditional_t<
397
+ std::is_same_v<T, long long>,
398
+ std::variant<ConstGenerator<T>, MinGenerator, MaxGenerator, UniformGenerator,
399
+ RangeGenerator<T>, StepRangeGenerator<T>, GeometricDistributionGenerator,
400
+ BinomialDistributionGenerator>,
401
+ std::variant<ConstGenerator<T>, MinGenerator, MaxGenerator, UniformGenerator,
402
+ RangeGenerator<T>, StepRangeGenerator<T>, NormalDistributionGenerator,
403
+ ExponentialDistributionGenerator>>;
404
+
405
+ std::vector<std::pair<GeneratorType, double>> generators_;
406
+ double total_weight_;
407
+
408
+ template <typename>
409
+ struct Pack {};
410
+
411
+ template <typename A>
412
+ static A parse_number(std::string_view s) {
413
+ static_assert(is_number_v<A>);
414
+ if constexpr(std::is_same_v<A, long long>)
415
+ return stoll(std::string(s));
416
+ else
417
+ return stold(std::string(s));
418
+ }
419
+
420
+ template <typename A>
421
+ static A parse_argument(std::string_view& s) {
422
+ auto end = s.find_first_of(",)");
423
+ assert(end != std::string_view::npos);
424
+ auto v = parse_number<A>(s.substr(0, end));
425
+ s.remove_prefix(end);
426
+ // Pop the trailing , or )
427
+ s.remove_prefix(1);
428
+ return v;
429
+ }
430
+
431
+ template <typename... As>
432
+ static std::tuple<As...> parse_arguments(std::string_view& s,
433
+ Pack<std::tuple<As...>> /*unused*/) {
434
+ std::tuple<As...> args{parse_argument<As>(s)...};
435
+ return args;
436
+ }
437
+
438
+ // Try parsing one generator type from the start of s.
439
+ template <typename G>
440
+ static void parse_generator(std::string_view& s, std::optional<GeneratorType>& out) {
441
+ if(out) return;
442
+ if(s.substr(0, G::name.size()) != G::name) return;
443
+
444
+ // Drop the name.
445
+ s.remove_prefix(G::name.size());
446
+ if constexpr(std::tuple_size_v<typename G::Args> == 0) {
447
+ out.emplace(std::in_place_type_t<G>{});
448
+ return;
449
+ }
450
+
451
+ // Drop the (
452
+ assert(not s.empty() and s.front() == '(');
453
+ s.remove_prefix(1);
454
+
455
+ auto args = parse_arguments(s, Pack<typename G::Args>{});
456
+ // Construct the resulting generator in-place in the variant..
457
+ std::apply([&](const auto&... _args) { out.emplace(std::in_place_type_t<G>{}, _args...); },
458
+ args);
459
+ }
460
+
461
+ template <typename... Gs>
462
+ static std::optional<GeneratorType> parse_generators(std::string_view& s,
463
+ Pack<std::variant<Gs...>> /*unused*/) {
464
+ std::optional<GeneratorType> out;
465
+ (parse_generator<Gs>(s, out), ...);
466
+ return out;
467
+ }
468
+
469
+ explicit ChoiceGenerator(std::string_view s) : total_weight_(0) {
470
+ // PARSE
471
+ while(not s.empty()) {
472
+ auto generator = parse_generators(s, Pack<GeneratorType>{});
473
+ if(!generator) {
474
+ // Check for range syntax:
475
+ auto comma = s.find_first_of(",:");
476
+ if(comma == std::string::npos) comma = s.size();
477
+ auto dots = s.find("..");
478
+ if(dots != std::string_view::npos and dots < comma) {
479
+ auto start = s.substr(0, dots);
480
+ auto end = s.substr(dots + 2, comma - dots - 2);
481
+
482
+ generator.emplace(std::in_place_type_t<RangeGenerator<T>>{},
483
+ parse_number<T>(start), parse_number<T>(end));
484
+ s.remove_prefix(comma);
485
+ }
486
+
487
+ // Fall back to constant.
488
+ if(!generator) {
489
+ generator.emplace(std::in_place_type_t<ConstGenerator<T>>{},
490
+ parse_number<T>(s.substr(0, comma)));
491
+ s.remove_prefix(comma);
492
+ }
493
+ }
494
+
495
+ // Parse weight if given.
496
+ double weight = 1;
497
+ if(not s.empty() and s.front() == ':') {
498
+ s.remove_prefix(1);
499
+ auto comma = s.find(',');
500
+ if(comma == std::string_view::npos) comma = s.size();
501
+ weight = parse_number<long double>(s.substr(0, comma));
502
+ s.remove_prefix(comma);
503
+ }
504
+
505
+ // should now be at , or end
506
+ assert(s.empty() or s.front() == ',');
507
+ if(not s.empty()) s.remove_prefix(1);
508
+ generators_.emplace_back(std::move(*generator), weight);
509
+ total_weight_ += weight;
510
+ }
511
+ }
512
+
513
+ T operator()(T low, T high, std::mt19937_64& rng) const {
514
+ Generators::UniformGenerator uniform;
515
+ double x = uniform.operator()<long double>(0, total_weight_, rng);
516
+ for(size_t i = 0; i < generators_.size(); ++i) {
517
+ x -= generators_[i].second;
518
+ if(x <= 0)
519
+ return std::visit([&](auto& g) { return g(low, high, rng); }, generators_[i].first);
520
+ }
521
+ assert(false);
522
+ }
523
+ };
524
+
525
+ struct ParamGenerator {
526
+ std::variant<std::string_view, ChoiceGenerator<long long>, ChoiceGenerator<long double>>
527
+ generator;
528
+ explicit ParamGenerator(std::string_view s) : generator(s) {}
529
+
530
+ template <typename T>
531
+ T operator()(T low, T high, std::mt19937_64& rng) {
532
+ static_assert(is_number_v<T>);
533
+ if(std::holds_alternative<std::string_view>(generator)) {
534
+ generator = ChoiceGenerator<T>(std::get<std::string_view>(generator));
535
+ }
536
+ return std::get<ChoiceGenerator<T>>(generator)(low, high, rng);
537
+ }
538
+ };
539
+
540
+ } // namespace Generators
541
+
542
+ using Generators::ParamGenerator;
543
+
544
+ namespace Random {
545
+ template <class RandomIt>
546
+ void shuffle(RandomIt first, RandomIt last, std::mt19937_64& rng) {
547
+ Generators::UniformGenerator uniform;
548
+ long long n = last - first;
549
+ for(long long i = n - 1; i > 0; i--) {
550
+ std::swap(first[i], first[uniform(0ll, i, rng)]);
551
+ }
552
+ }
553
+
554
+ template <class T>
555
+ void shuffle(std::pair<T, T>& in, std::mt19937_64& rng) {
556
+ if(bit(rng)) std::swap(in.first, in.second);
557
+ }
558
+
559
+ template <class RandomIt>
560
+ auto& select(RandomIt first, RandomIt last, std::mt19937_64& rng) {
561
+ assert(first != last);
562
+ Generators::UniformGenerator uniform;
563
+ long long n = last - first;
564
+ return first[uniform(0ll, n - 1, rng)];
565
+ }
566
+
567
+ template <class T>
568
+ const T& select(const std::pair<T, T>& in, std::mt19937_64& rng) {
569
+ return bit(rng) ? in.first : in.second;
570
+ }
571
+
572
+ template <class T>
573
+ T& select(std::pair<T, T>& in, std::mt19937_64& rng) {
574
+ return bit(rng) ? in.first : in.second;
575
+ }
576
+
577
+ } // namespace Random
578
+
579
+ class Validator {
580
+ protected:
581
+ Validator(bool ws_, bool case_, std::istream& in_, std::string constraints_file_path_ = "",
582
+ std::optional<unsigned int> seed = std::nullopt,
583
+ std::unordered_map<std::string, ParamGenerator> params_ = {})
584
+ : in(in_), ws(ws_), case_sensitive(case_),
585
+ constraints_file_path(std::move(constraints_file_path_)), gen(seed.has_value()),
586
+ rng(seed.value_or(Random::default_seed)), params(std::move(params_)) {
587
+
588
+ std::ios_base::sync_with_stdio(false);
589
+ in.tie(nullptr);
590
+
591
+ if(gen) return;
592
+ if(ws)
593
+ in >> std::noskipws;
594
+ else
595
+ in >> std::skipws;
596
+
597
+ if(!constraints_file_path.empty()) {
598
+ assert(has_source_location); // NOLINT
599
+ }
600
+ }
601
+
602
+ public:
603
+ // No copying, no moving.
604
+ Validator(const Validator&) = delete;
605
+ Validator(Validator&&) = delete;
606
+ void operator=(const Validator&) = delete;
607
+ void operator=(Validator&&) = delete;
608
+
609
+ // At the end of the scope, check whether the EOF has been reached.
610
+ // If so, return AC. Otherwise, return WA.
611
+ ~Validator() {
612
+ eof();
613
+ write_constraints();
614
+ AC();
615
+ }
616
+
617
+ void space() {
618
+ if(gen) {
619
+ out << ' ';
620
+ return;
621
+ }
622
+
623
+ if(ws) {
624
+ char c;
625
+ in >> c;
626
+ check(!in.eof(), "Expected space, found EOF.");
627
+ if(c != ' ')
628
+ expected("space", std::string("\"") +
629
+ ((c == '\n' or c == '\r') ? std::string("newline")
630
+ : std::string(1, c)) +
631
+ "\"");
632
+ }
633
+ }
634
+
635
+ void newline() {
636
+ if(gen) {
637
+ out << '\n';
638
+ return;
639
+ }
640
+
641
+ if(ws) {
642
+ char c;
643
+ in >> c;
644
+ check(!in.eof(), "Expected newline, found EOF.");
645
+ if(c != '\n') {
646
+ if(c == '\r')
647
+ expected("newline", "DOS line ending (\\r)");
648
+ else
649
+ expected("newline", std::string("\"") + c + "\"");
650
+ }
651
+ }
652
+ }
653
+
654
+ private:
655
+ void separator(Separator s) {
656
+ switch(s) {
657
+ case Separator::Space: space(); break;
658
+ case Separator::Newline: newline(); break;
659
+ }
660
+ }
661
+
662
+ template <typename T>
663
+ auto& seen() {
664
+ static std::map<source_location, std::set<T>> seen;
665
+ return seen;
666
+ }
667
+ template <typename T>
668
+ auto& last_seen() {
669
+ static std::map<source_location, T> last_seen;
670
+ return last_seen;
671
+ }
672
+ template <typename T>
673
+ auto& integers_seen() {
674
+ static std::map<source_location, std::tuple<std::set<T>, std::vector<T>, bool>>
675
+ integers_seen;
676
+ return integers_seen;
677
+ }
678
+ template <typename T>
679
+ void reset(source_location loc) {
680
+ seen<T>().erase(loc);
681
+ last_seen<T>().erase(loc);
682
+ integers_seen<T>().erase(loc);
683
+ }
684
+
685
+ template <typename T, typename Tag>
686
+ void check_number(const std::string& name, T low, T high, T v, Tag /*unused*/,
687
+ source_location loc) {
688
+ static_assert(is_number_v<T>);
689
+ if(v < low or v > high) {
690
+ std::string type_name;
691
+ if constexpr(std::is_integral_v<T>) {
692
+ type_name = "integer";
693
+ }
694
+ if constexpr(std::is_floating_point_v<T>) {
695
+ type_name = "float";
696
+ }
697
+ expected(name + ": " + type_name + " between " + std::to_string(low) + " and " +
698
+ std::to_string(high),
699
+ std::to_string(v));
700
+ }
701
+ log_constraint(name, low, high, v, loc);
702
+ if constexpr(Tag::unique) {
703
+ auto [it, inserted] = seen<T>()[loc].emplace(v);
704
+ check(inserted, name, ": Value ", v, " seen twice, but must be unique!");
705
+ } else {
706
+ auto [it, inserted] = last_seen<T>().emplace(loc, v);
707
+ if(inserted) return;
708
+
709
+ auto last = it->second;
710
+ it->second = v;
711
+
712
+ if constexpr(Tag::increasing)
713
+ check(v >= last, name, " is not increasing: value ", v, " follows ", last);
714
+ if constexpr(Tag::decreasing)
715
+ check(v <= last, name, " is not decreasing: value ", v, " follows ", last);
716
+ if constexpr(Tag::strict)
717
+ check(v != last, name, " is not strict: value ", v, " equals ", last);
718
+ }
719
+ }
720
+
721
+ template <typename Tag>
722
+ void check_string(const std::string& name, int low, int high, const std::string& v,
723
+ Tag /*unused*/, source_location loc) {
724
+ using T = std::string;
725
+ if((int) v.size() < low or (int) v.size() > high) {
726
+ expected(name + ": " + "string with" + " length between " + std::to_string(low) +
727
+ " and " + std::to_string(high),
728
+ v);
729
+ }
730
+ log_constraint(name, low, high, static_cast<int>(v.size()), loc);
731
+ if constexpr(Tag::unique) {
732
+ // static map<source_location, set<T>> seen;
733
+ auto [it, inserted] = seen<T>()[loc].emplace(v);
734
+ check(inserted, name, ": Value ", v, " seen twice, but must be unique!");
735
+ } else if(Tag::increasing or Tag::decreasing) {
736
+ // static map<source_location, T> last_seen;
737
+ auto [it, inserted] = last_seen<T>().emplace(loc, v);
738
+ if(inserted) return;
739
+
740
+ auto last = it->second;
741
+ it->second = v;
742
+
743
+ if constexpr(Tag::increasing)
744
+ check(v >= last, name, " is not increasing: value ", v, " follows ", last);
745
+ if constexpr(Tag::decreasing)
746
+ check(v <= last, name, " is not decreasing: value ", v, " follows ", last);
747
+ if constexpr(Tag::strict)
748
+ check(v != last, name, " is not strict: value ", v, " equals ", last);
749
+ }
750
+ }
751
+
752
+ // Generate a random integer in [low, high] or float in [low, high).
753
+ template <typename T>
754
+ T uniform_number(T low, T high) {
755
+ assert(low <= high);
756
+ Generators::UniformGenerator uniform;
757
+ if constexpr(std::is_integral<T>::value)
758
+ return uniform.operator()<long long>(low, high, rng);
759
+ else
760
+ return uniform.operator()<long double>(low, high, rng);
761
+ }
762
+
763
+ template <typename T, typename Tag>
764
+ T gen_number(const std::string& name, T low, T high, Tag /*unused*/, source_location loc) {
765
+ static_assert(is_number_v<T>);
766
+ T v;
767
+
768
+ if constexpr(Tag::unique) {
769
+ assert(params.find(name) == params.end() &&
770
+ "Parameters are not supported for unique values.");
771
+ if constexpr(std::is_integral<T>::value) {
772
+ auto& [seen_here, remaining_here, use_remaining] = integers_seen<T>()[loc];
773
+
774
+ if(use_remaining) {
775
+ check(!remaining_here.empty(), name, ": no unique values left");
776
+ v = remaining_here.back();
777
+ remaining_here.pop_back();
778
+ } else {
779
+ do {
780
+ v = uniform_number(low, high);
781
+ } while(!seen_here.insert(v).second);
782
+
783
+ struct CountIterator {
784
+ T v;
785
+ T& operator*() { return v; }
786
+ T& operator++() { return ++v; }
787
+ T operator++(int) { return v++; }
788
+ bool operator!=(CountIterator r) { return v != r.v; }
789
+ };
790
+
791
+ if(seen_here.size() > (high - low) / 2) {
792
+ use_remaining = true;
793
+ set_difference(CountIterator{low}, CountIterator{high + 1},
794
+ seen_here.begin(), seen_here.end(),
795
+ std::back_inserter(remaining_here));
796
+ }
797
+ }
798
+ } else {
799
+ // For floats, just regenerate numbers until success.
800
+ auto& seen_here = seen<T>()[loc];
801
+ do {
802
+ v = uniform_number(low, high);
803
+ } while(!seen_here.insert(v).second);
804
+ }
805
+
806
+ } else {
807
+ assert(not Tag::increasing && "Generating increasing sequences is not yet supported!");
808
+ assert(not Tag::decreasing && "Generating decreasing sequences is not yet supported!");
809
+ assert((std::is_same<Tag, ArbitraryTag>::value) &&
810
+ "Only Unique and Arbitrary are supported!");
811
+
812
+ if(params.find(name) != params.end()) {
813
+ v = params.at(name).operator()<T>(low, high, rng);
814
+ // This will be checked during input validation of the generated case.
815
+ // assert(low <= v and v <= high);
816
+ } else {
817
+ v = uniform_number<T>(low, high);
818
+ }
819
+ }
820
+
821
+ return v;
822
+ }
823
+
824
+ std::string gen_string(const std::string& name, long long low, long long high,
825
+ std::string_view chars) {
826
+ assert(!chars.empty());
827
+
828
+ int len;
829
+ if(params.find(name + ".length") != params.end())
830
+ len = params.at(name + ".length").operator()<long long>(low, high, rng);
831
+ else
832
+ len = uniform_number(low, high);
833
+ std::string s(len, ' ');
834
+ for(auto& x : s) x = chars[uniform_number<int>(0, chars.size() - 1)];
835
+
836
+ out << s;
837
+ return s;
838
+ }
839
+
840
+ public:
841
+ template <typename Tag = ArbitraryTag>
842
+ long long gen_integer(const std::string& name, long long low, long long high, Tag tag = Tag{},
843
+ source_location loc = source_location::current()) {
844
+ return gen_number(name, low, high, tag, loc);
845
+ }
846
+
847
+ template <typename Tag = ArbitraryTag>
848
+ long double gen_float(const std::string& name, long double low, long double high,
849
+ Tag tag = Tag{}, source_location loc = source_location::current()) {
850
+ return gen_number(name, low, high, tag, loc);
851
+ }
852
+
853
+ private:
854
+ template <typename T, typename Tag>
855
+ std::vector<T> gen_numbers(const std::string& name, int count, T low, T high, Tag /*unused*/,
856
+ source_location loc) {
857
+ static_assert(is_number_v<T>);
858
+ std::vector<T> v;
859
+ v.reserve(count);
860
+ if constexpr(std::is_same_v<Tag, ArbitraryTag>) {
861
+ if(params.find(name) != params.end()) {
862
+ auto& generator = params.at(name);
863
+ for(int i = 0; i < count; ++i) {
864
+ auto val = generator.operator()<T>(low, high, rng);
865
+ assert(low <= val and val <= high);
866
+ v.push_back(val);
867
+ }
868
+ } else {
869
+ for(int i = 0; i < count; ++i) {
870
+ v.push_back(uniform_number<T>(low, high));
871
+ }
872
+ }
873
+ } else if constexpr(Tag::unique) {
874
+ assert(params.find(name) == params.end() &&
875
+ "Parameters are not supported for unique values.");
876
+ std::set<T> seen_here;
877
+ if constexpr(std::is_integral_v<T>) {
878
+ if(2 * count < high - low) {
879
+ for(int i = 0; i < count; ++i) {
880
+ // If density < 1/2: retry.
881
+ T w;
882
+ do {
883
+ w = uniform_number(low, high);
884
+ } while(!seen_here.insert(w).second);
885
+ v.push_back(w);
886
+ }
887
+ } else {
888
+ // If density >= 1/2, crop a random permutation.
889
+ v.resize(high - low + 1);
890
+ iota(begin(v), end(v), low);
891
+ Random::shuffle(begin(v), end(v), rng);
892
+ v.resize(count);
893
+ }
894
+ } else {
895
+ for(int i = 0; i < count; ++i) {
896
+ // For floats, just regenerate numbers until success.
897
+ T w;
898
+ do {
899
+ w = uniform_number(low, high);
900
+ } while(!seen_here.insert(w).second);
901
+ v.push_back(w);
902
+ }
903
+ }
904
+ } else {
905
+ static_assert(Tag::increasing or Tag::decreasing);
906
+
907
+ constexpr bool integral_strict = Tag::strict and std::is_integral<T>::value;
908
+ if(integral_strict) {
909
+ assert(params.find(name) == params.end() &&
910
+ "Parameters are not supported for strict integer values.");
911
+ high = high - count + 1;
912
+ }
913
+
914
+ if(params.find(name) != params.end()) {
915
+ auto& generator = params.at(name);
916
+ for(int i = 0; i < count; ++i) {
917
+ auto val = generator.operator()<T>(low, high, rng);
918
+ assert(low <= val and val <= high);
919
+ v.push_back(val);
920
+ }
921
+ } else {
922
+ for(int i = 0; i < count; ++i) {
923
+ v.push_back(uniform_number<T>(low, high));
924
+ }
925
+ }
926
+
927
+ sort(begin(v), end(v));
928
+
929
+ if(integral_strict) {
930
+ for(int i = 0; i < count; ++i) v[i] += i;
931
+ }
932
+
933
+ if(Tag::decreasing) reverse(begin(v), end(v));
934
+ }
935
+
936
+ return v;
937
+ }
938
+
939
+ public:
940
+ template <typename Tag = ArbitraryTag>
941
+ std::vector<long long> gen_integers(const std::string& name, int count, long long low,
942
+ long long high, Tag tag = Tag{},
943
+ source_location loc = source_location::current()) {
944
+ return gen_numbers(name, count, low, high, tag, loc);
945
+ }
946
+
947
+ template <typename Tag = ArbitraryTag>
948
+ std::vector<long double> gen_floats(const std::string& name, int count, long double low,
949
+ long double high, Tag tag = Tag{},
950
+ source_location loc = source_location::current()) {
951
+ return gen_numbers(name, count, low, high, tag, loc);
952
+ }
953
+
954
+ private:
955
+ template <typename T, typename Tag>
956
+ T read_number(const std::string& name, T low, T high, Tag tag, source_location loc) {
957
+ if(gen) {
958
+ auto v = gen_number(name, low, high, tag, loc);
959
+ out << std::setprecision(10) << std::fixed << v;
960
+ return v;
961
+ }
962
+
963
+ const auto v = [&] {
964
+ if constexpr(std::is_integral<T>::value)
965
+ return read_integer(name);
966
+ else
967
+ return read_float(name);
968
+ }();
969
+
970
+ check_number(name, low, high, v, tag, loc);
971
+ return v;
972
+ }
973
+
974
+ // Read a vector of numbers, separated by spaces and ended by a newline.
975
+ template <typename T, typename Tag>
976
+ std::vector<T> read_numbers(const std::string& name, int count, T low, T high, Tag tag,
977
+ Separator sep, source_location loc) {
978
+ if(gen) {
979
+ auto v = gen_numbers(name, count, low, high, tag, loc);
980
+
981
+ out << std::setprecision(10) << std::fixed;
982
+ for(int i = 0; i < count; ++i) {
983
+ out << v[i];
984
+ if(i < count - 1) separator(sep);
985
+ }
986
+ newline();
987
+
988
+ return v;
989
+ }
990
+ reset<T>(loc);
991
+ std::vector<T> v(count);
992
+ for(int i = 0; i < count; ++i) {
993
+ if constexpr(std::is_integral<T>::value)
994
+ v[i] = read_integer(name);
995
+ else
996
+ v[i] = read_float(name);
997
+ check_number(name, low, high, v[i], tag, loc);
998
+ if(i < count - 1) separator(sep);
999
+ }
1000
+ newline();
1001
+ return v;
1002
+ }
1003
+
1004
+ public:
1005
+ template <typename Tag = ArbitraryTag>
1006
+ long long read_integer(const std::string& name, long long low, long long high, Tag tag = Tag{},
1007
+ source_location loc = source_location::current()) {
1008
+ return read_number(name, low, high, tag, loc);
1009
+ }
1010
+ template <typename Tag = ArbitraryTag>
1011
+ std::vector<long long> read_integers(const std::string& name, int count, long long low,
1012
+ long long high, Tag tag = Tag{}, Separator sep = Space,
1013
+ source_location loc = source_location::current()) {
1014
+ return read_numbers(name, count, low, high, tag, sep, loc);
1015
+ }
1016
+
1017
+ template <typename Tag = ArbitraryTag>
1018
+ long double read_float(const std::string& name, long double low, long double high,
1019
+ Tag tag = Tag{}, source_location loc = source_location::current()) {
1020
+ return read_number(name, low, high, tag, loc);
1021
+ }
1022
+ template <typename Tag = ArbitraryTag>
1023
+ std::vector<long double> read_floats(const std::string& name, int count, long double low,
1024
+ long double high, Tag tag = Tag{}, Separator sep = Space,
1025
+ source_location loc = source_location::current()) {
1026
+ return read_numbers(name, count, low, high, tag, sep, loc);
1027
+ }
1028
+
1029
+ // Read a vector of strings, separated by spaces and ended by a newline.
1030
+ template <typename Tag = ArbitraryTag>
1031
+ std::vector<std::string> read_strings(const std::string& name, int count, int min, int max,
1032
+ const std::string_view chars = "", Tag tag = Tag(),
1033
+ Separator sep = Space,
1034
+ source_location loc = source_location::current()) {
1035
+ reset<std::string>(loc);
1036
+ if(gen) return gen_strings(name, count, min, max, chars, tag, sep, loc);
1037
+ assert(!gen);
1038
+ std::vector<std::string> v(count);
1039
+ for(int i = 0; i < count; ++i) {
1040
+ v[i] = read_string(name, min, max, chars, tag, loc);
1041
+ if(i < count - 1) separator(sep);
1042
+ }
1043
+ newline();
1044
+ return v;
1045
+ }
1046
+
1047
+ template <typename Tag>
1048
+ std::vector<std::string> gen_strings(const std::string& name, int count, int min, int max,
1049
+ const std::string_view chars, Tag /*unused*/,
1050
+ Separator sep, source_location loc) {
1051
+ assert(!chars.empty());
1052
+
1053
+ std::vector<std::string> v(count);
1054
+ if constexpr(std::is_same<Tag, ArbitraryTag>::value) {
1055
+ for(int i = 0; i < count; ++i) {
1056
+ std::string s(uniform_number(min, max), ' ');
1057
+ for(auto& x : s) x = chars[uniform_number<int>(0, chars.size() - 1)];
1058
+ v.push_back(s);
1059
+ out << s;
1060
+ if(i < count - 1) separator(sep);
1061
+ }
1062
+ } else if constexpr(Tag::unique) {
1063
+ std::set<std::string> seen_here;
1064
+ for(int i = 0; i < count; ++i) {
1065
+ // Just regenerate strings until success.
1066
+ std::string s;
1067
+ do {
1068
+ s = std::string(uniform_number(min, max), ' ');
1069
+ for(auto& x : s) x = chars[uniform_number<int>(0, chars.size() - 1)];
1070
+ } while(!seen_here.insert(s).second);
1071
+ v.push_back(s);
1072
+ out << s;
1073
+ if(i < count - 1) separator(sep);
1074
+ }
1075
+ } else {
1076
+ static_assert(Tag::increasing or Tag::decreasing);
1077
+
1078
+ assert(false && "Generating increasing/decreasing lists of strings is not "
1079
+ "supported!");
1080
+ }
1081
+
1082
+ newline();
1083
+
1084
+ return v;
1085
+ }
1086
+
1087
+ // Check the next character.
1088
+ bool peek(char c, const std::string& name = "") {
1089
+ if(gen) {
1090
+ // TODO
1091
+ // if(not name.empty() and params.contains(name)) {
1092
+ // return c == params.at(name).operator()<char>(0, 0, rng);
1093
+ //}
1094
+ return Random::bit(rng);
1095
+ }
1096
+ if(!ws) in >> std::ws;
1097
+ if(case_sensitive) return in.peek() == std::char_traits<char>::to_int_type(c);
1098
+ return tolower(in.peek()) == tolower(std::char_traits<char>::to_int_type(c));
1099
+ }
1100
+
1101
+ // Read a string and make sure it equals `expected`.
1102
+ // Takes by value because it needs to lowercase its arguments.
1103
+ std::string test_strings(std::vector<std::string> expected, const std::string& name = "") {
1104
+ if(gen) {
1105
+ int index = 0;
1106
+ // TODO
1107
+ // if(not name.empty() and params.contains(name)) {
1108
+ // auto s = params.at(name).operator()<std::string>(0, 0, rng);
1109
+ // index = std::find(expected.begin(), expected.end(), s) - expected.begin();
1110
+ // assert(0 <= index and index < expected.size());
1111
+ //} else {
1112
+ index = expected.size() == 1 ? 0 : uniform_number<int>(0, expected.size() - 1);
1113
+ //}
1114
+ out << expected[index];
1115
+ return expected[index];
1116
+ }
1117
+ std::string s = get_string();
1118
+ lowercase(s);
1119
+
1120
+ for(std::string e : expected)
1121
+ if(s == lowercase(e)) return s;
1122
+
1123
+ std::string error;
1124
+ for(const auto& e : expected) {
1125
+ if(not error.empty()) error += "|";
1126
+ error += e;
1127
+ }
1128
+ WA("Expected string \"", error, "\", but found ", s);
1129
+ }
1130
+
1131
+ // Read a string and make sure it equals `expected`.
1132
+ std::string test_string(std::string expected, const std::string& name = "") {
1133
+ return test_strings({std::move(expected)}, name);
1134
+ }
1135
+
1136
+ // Read an arbitrary string of a given length.
1137
+ template <typename Tag = ArbitraryTag>
1138
+ std::string read_string(const std::string& name, long long min, long long max,
1139
+ const std::string_view chars = "", Tag tag = Tag(),
1140
+ source_location loc = source_location::current()) {
1141
+ if(gen) {
1142
+ return gen_string(name, min, max, chars);
1143
+ }
1144
+ std::string s = get_string();
1145
+ std::array<bool, 256> ok_char{};
1146
+ if(!chars.empty()) {
1147
+ for(auto c : chars) ok_char[c] = true;
1148
+ for(auto c : s)
1149
+ check(ok_char[c], name, ": expected characters in ", chars, " but found character ",
1150
+ c, " in ", s);
1151
+ }
1152
+ check_string(name, min, max, s, tag, loc);
1153
+ return s;
1154
+ }
1155
+
1156
+ // Read an arbitrary line of a given length.
1157
+ std::string read_line(const std::string& name, long long min, long long max,
1158
+ const std::string_view chars = "",
1159
+ source_location loc = source_location::current()) {
1160
+ if(gen) {
1161
+ // TODO: Params for lines.
1162
+ assert(!chars.empty());
1163
+
1164
+ std::string s(uniform_number(min, max), ' ');
1165
+ for(auto& x : s) x = chars[uniform_number<int>(0, chars.size() - 1)];
1166
+
1167
+ out << s << '\n';
1168
+ return s;
1169
+ }
1170
+
1171
+ if(ws) {
1172
+ char next = in.peek();
1173
+ if(min > 0 and isspace(next))
1174
+ expected("non empty line", next == '\n' ? "newline" : "whitespace");
1175
+ if(in.eof()) expected("line", "EOF");
1176
+ }
1177
+ std::string s;
1178
+ if(!getline(in, s)) expected("line", "nothing");
1179
+ long long size = s.size();
1180
+ if(size < min || size > max)
1181
+ expected(name + ": line of length between " + std::to_string(min) + " and " +
1182
+ std::to_string(max),
1183
+ s);
1184
+ std::array<bool, 256> ok_char{};
1185
+ if(!chars.empty()) {
1186
+ for(auto c : chars) ok_char[c] = true;
1187
+ for(auto c : s)
1188
+ check(ok_char[c], name, ": expected characters in ", chars, " but found character ",
1189
+ c, " in ", s);
1190
+ }
1191
+ log_constraint(name, min, max, size, loc);
1192
+ return s;
1193
+ }
1194
+
1195
+ // Return ACCEPTED verdict.
1196
+ void eof_and_AC() {
1197
+ eof();
1198
+ AC();
1199
+ }
1200
+
1201
+ private:
1202
+ std::function<void()> WA_handler = [] {};
1203
+
1204
+ public:
1205
+ void set_WA_handler(std::function<void()> f) { WA_handler = std::move(f); }
1206
+
1207
+ // Return WA with the given reason.
1208
+ template <typename... Ts>
1209
+ [[noreturn]] void WA(const Ts&... ts) {
1210
+ static_assert(sizeof...(Ts) > 0);
1211
+
1212
+ WA_handler();
1213
+
1214
+ auto pos = get_file_pos();
1215
+ std::cerr << pos.first << ":" << pos.second << ": ";
1216
+
1217
+ WA_impl(ts...);
1218
+ }
1219
+
1220
+ // Check that the condition is true.
1221
+ template <typename... Ts>
1222
+ void check(bool b, const Ts&... ts) {
1223
+ static_assert(sizeof...(Ts) > 0, "Provide a non-empty error message.");
1224
+
1225
+ if(!b) WA(ts...);
1226
+ }
1227
+
1228
+ // Log some value in a range.
1229
+ template <typename T>
1230
+ void log_constraint(const std::string& name, T low, T high, T v,
1231
+ source_location loc = source_location::current()) {
1232
+ // Do not log when line number is unknown/default/unsupported.
1233
+ if(loc.line() == 0 or constraints_file_path.empty()) return;
1234
+
1235
+ // All integer types get bounds as long long, all floating point types as long_double.
1236
+ using U = Bounds<std::conditional_t<std::is_integral_v<T>, long long, long double>>;
1237
+
1238
+ auto [it, inserted] = bounds.emplace(loc, U(name, v, v, low, high));
1239
+ assert(std::holds_alternative<U>(it->second));
1240
+ auto& done = std::get<U>(it->second);
1241
+ if(inserted) {
1242
+ assert(!name.empty() && "Variable names must not be empty.");
1243
+ assert(name.find(' ') == std::string::npos && "Variable name must not contain spaces.");
1244
+ } else {
1245
+ assert(name == done.name && "Variable name must be constant.");
1246
+ }
1247
+ if(v < done.min) {
1248
+ done.min = v;
1249
+ done.low = low;
1250
+ }
1251
+ if(v > done.max) {
1252
+ done.max = v;
1253
+ done.high = high;
1254
+ }
1255
+ done.has_min |= v == low;
1256
+ done.has_max |= v == high;
1257
+ }
1258
+
1259
+ private:
1260
+ long long read_integer(const std::string& name) {
1261
+ assert(!gen);
1262
+ std::string s = get_string("integer");
1263
+ if(s.empty()) {
1264
+ WA(name, ": Want integer, found nothing");
1265
+ }
1266
+ long long v;
1267
+ auto begin = s.c_str(), end = begin + s.size();
1268
+ auto [ptr, ec] = std::from_chars(begin, end, v);
1269
+ if(ec == std::errc::result_out_of_range){
1270
+ WA(name, ": Number " + s + " does not fit in a long long!");
1271
+ } else if(ptr != end) {
1272
+ WA(name, ": Parsing " + s + " as long long failed! Did not process all characters");
1273
+ } else if (ec != std::errc{}) {
1274
+ WA(name, ": Parsing " + s + " as long long failed!");
1275
+ }
1276
+ // Check for leading zero.
1277
+ if(v == 0) {
1278
+ if(s.size() != 1) WA(name, ": Parsed 0, but has leading 0 or minus sign: ", s);
1279
+ }
1280
+ if(v > 0) {
1281
+ if(s[0] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s);
1282
+ }
1283
+ if(v < 0) {
1284
+ if(s.size() <= 1) WA(name, ": Parsed ", v, ", but string is: ", s);
1285
+ if(s[1] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s);
1286
+ }
1287
+ return v;
1288
+ }
1289
+
1290
+ long double read_float(const std::string& name) {
1291
+ assert(!gen);
1292
+ std::string s = get_string("long double");
1293
+ long double v;
1294
+ try {
1295
+ size_t chars_processed;
1296
+ v = stold(s, &chars_processed);
1297
+ if(chars_processed != s.size())
1298
+ WA(name, ": Parsing ", s,
1299
+ " as long double failed! Did not process all characters.");
1300
+ } catch(const std::out_of_range& e) {
1301
+ WA(name, ": Number " + s + " does not fit in a long double!");
1302
+ } catch(const std::invalid_argument& e) {
1303
+ WA("Parsing " + s + " as long double failed!");
1304
+ }
1305
+ return v;
1306
+ }
1307
+
1308
+ [[noreturn]] void expected(const std::string& exp = "", const std::string& s = "") {
1309
+ assert(!gen && "Expected is not supported for generators.");
1310
+ if(!s.empty())
1311
+ WA("Expected ", exp, ", found ", s);
1312
+ else
1313
+ WA(exp);
1314
+ }
1315
+
1316
+ template <typename T>
1317
+ [[noreturn]] void WA_impl(T t) {
1318
+ std::cerr << t << std::endl;
1319
+ exit(ret_WA);
1320
+ }
1321
+
1322
+ std::pair<int, int> get_file_pos() {
1323
+ int line = 1, col = 0;
1324
+ in.clear();
1325
+ auto originalPos = in.tellg();
1326
+ if(originalPos < 0) return {-1, -1};
1327
+ in.seekg(0);
1328
+ char c;
1329
+ while((in.tellg() < originalPos) && in.get(c)) {
1330
+ if(c == '\n')
1331
+ ++line, col = 0;
1332
+ else
1333
+ ++col;
1334
+ }
1335
+ return {line, col};
1336
+ }
1337
+
1338
+ template <typename T, typename... Ts>
1339
+ [[noreturn]] void WA_impl(T t, Ts... ts) {
1340
+ std::cerr << t;
1341
+ WA_impl(ts...);
1342
+ }
1343
+
1344
+ std::string get_string(const std::string& wanted = "string") {
1345
+ assert(!gen && "get_string is not supported for generators.");
1346
+ if(ws) {
1347
+ char next = in.peek();
1348
+ if(isspace(next)) expected(wanted, next == '\n' ? "newline" : "whitespace");
1349
+ if(in.eof()) expected(wanted, "EOF");
1350
+ }
1351
+
1352
+ std::string s;
1353
+ if(in >> s) {
1354
+ return s;
1355
+ }
1356
+ expected(wanted, "nothing");
1357
+ }
1358
+
1359
+ // Return ACCEPTED verdict.
1360
+ void AC() const {
1361
+ if(gen) {
1362
+ // nothing
1363
+ return;
1364
+ }
1365
+
1366
+ exit(ret_AC);
1367
+ }
1368
+
1369
+ void eof() {
1370
+ if(gen) {
1371
+ out.flush();
1372
+ fclose(stdout);
1373
+ return;
1374
+ }
1375
+ if(in.eof()) return;
1376
+ // Sometimes EOF hasn't been triggered yet.
1377
+ if(!ws) in >> std::ws;
1378
+ char c = in.get();
1379
+ if(c == std::char_traits<char>::eof()) return;
1380
+ std::string got = std::string("\"") + char(c) + '"';
1381
+ if(c == '\n') got = "newline";
1382
+ expected("EOF", got);
1383
+ }
1384
+
1385
+ // Convert a string to lowercase is matching is not case sensitive.
1386
+ std::string& lowercase(std::string& s) const {
1387
+ if(case_sensitive) return s;
1388
+ transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
1389
+ return s;
1390
+ }
1391
+
1392
+ // Keep track of the min/max value read at every call site.
1393
+ template <typename T>
1394
+ struct Bounds {
1395
+ Bounds(std::string name_, T min_, T max_, T low_, T high_)
1396
+ : name(std::move(name_)), min(min_), max(max_), low(low_), high(high_) {} // NOLINT
1397
+ std::string name;
1398
+ T min, max; // Smallest / largest value observed
1399
+ T low, high; // Bounds
1400
+ bool has_min = false, has_max = false;
1401
+ };
1402
+
1403
+ std::map<source_location, std::variant<Bounds<long long>, Bounds<long double>>> bounds;
1404
+
1405
+ void write_constraints() {
1406
+ if(constraints_file_path.empty()) return;
1407
+
1408
+ std::ofstream os(constraints_file_path);
1409
+
1410
+ for(const auto& [location, bound] : bounds) {
1411
+ os << location_to_string(location) << " ";
1412
+ std::visit(
1413
+ [&](const auto& b) {
1414
+ os << b.name << " " << b.has_min << " " << b.has_max << " " << b.min << " "
1415
+ << b.max << " " << b.low << " " << b.high << std::endl;
1416
+ },
1417
+ bound);
1418
+ }
1419
+ }
1420
+
1421
+ static const int ret_AC = 42, ret_WA = 43;
1422
+ std::istream& in = std::cin;
1423
+ std::ostream& out = std::cout;
1424
+
1425
+ public:
1426
+ const bool ws = true;
1427
+ const bool case_sensitive = true;
1428
+ const std::string constraints_file_path;
1429
+ const bool gen = false;
1430
+
1431
+ std::mt19937_64 rng;
1432
+
1433
+ private:
1434
+ std::unordered_map<std::string, ParamGenerator> params;
1435
+
1436
+ public:
1437
+ std::string_view get_param(std::string_view name, std::string_view default_) {
1438
+ auto it = params.find(std::string(name));
1439
+ if(it == params.end()) return default_;
1440
+ return std::get<std::string_view>(it->second.generator);
1441
+ }
1442
+
1443
+ protected:
1444
+ static std::string get_constraints_file(int argc, char** argv) {
1445
+ for(int i = 1; i < argc; ++i) {
1446
+ if(argv[i] == constraints_file_flag) {
1447
+ if(i + 1 < argc) return argv[i + 1];
1448
+ std::cerr << constraints_file_flag << " should be followed by a file path!";
1449
+ exit(1);
1450
+ }
1451
+ }
1452
+ return {};
1453
+ }
1454
+ };
1455
+
1456
+ class Generator : public Validator {
1457
+ public:
1458
+ explicit Generator(unsigned int seed)
1459
+ : Validator(true, true, std::cin, /*constraints_file_path_=*/"", seed) {}
1460
+ };
1461
+
1462
+ class InputValidator : public Validator {
1463
+ public:
1464
+ // An InputValidator is always both whitespace and case sensitive.
1465
+ explicit InputValidator(int argc = 0, char** argv = nullptr)
1466
+ : Validator(true, true, std::cin, get_constraints_file(argc, argv), get_seed(argc, argv),
1467
+ get_params(argc, argv)) {}
1468
+
1469
+ private:
1470
+ static std::optional<unsigned int> get_seed(int argc, char** argv) {
1471
+ for(int i = 1; i < argc - 1; ++i) {
1472
+ if(argv[i] == generate_flag) {
1473
+ return std::stol(argv[i + 1]);
1474
+ }
1475
+ }
1476
+ // If no --generate is given, but `generat` is a substring of the binary path,
1477
+ // use the first argument as seed.
1478
+ if(std::string(argv[0]).find(generate_binary_substring) != std::string::npos) {
1479
+ return std::stol(argv[1]);
1480
+ }
1481
+ return std::nullopt;
1482
+ }
1483
+
1484
+ static std::unordered_map<std::string, ParamGenerator> get_params(int argc, char** argv) {
1485
+ std::unordered_map<std::string, ParamGenerator> params;
1486
+ for(int i = 1; i < argc - 1; ++i) {
1487
+ if(std::strlen(argv[i]) == 0 or argv[i][0] != '-') continue;
1488
+ if(argv[i] == generate_flag) {
1489
+ continue;
1490
+ }
1491
+ std::string_view name(argv[i] + 1);
1492
+ std::string_view value(argv[i + 1]);
1493
+ params.insert({std::string(name), ParamGenerator(value)});
1494
+ }
1495
+ return params;
1496
+ }
1497
+ };
1498
+
1499
+ class OutputValidator : public Validator {
1500
+ public:
1501
+ // An OutputValidator can be run in different modes.
1502
+ explicit OutputValidator(int argc, char** argv, std::istream& in_ = std::cin)
1503
+ : Validator(is_ws_sensitive(argc, argv), is_case_sensitive(argc, argv), in_,
1504
+ get_constraints_file(argc, argv)) {}
1505
+
1506
+ private:
1507
+ static bool is_ws_sensitive(int argc, char** argv) {
1508
+ for(int i = 1; i < argc; ++i) {
1509
+ if(argv[i] == ws_sensitive_flag) return true;
1510
+ }
1511
+ return false;
1512
+ }
1513
+
1514
+ static bool is_case_sensitive(int argc, char** argv) {
1515
+ for(int i = 1; i < argc; ++i) {
1516
+ if(argv[i] == case_sensitive_flag) return true;
1517
+ }
1518
+ return false;
1519
+ }
1520
+ };
ICPC/nwerc2022_F/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ecf0c3b63e72a3e39274bb80c7b227c503eccad52366caf3dd56a9e414081285
3
+ size 295421524
ICPC/nwerc2022_F/init.yml ADDED
@@ -0,0 +1,665 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ test_cases:
3
+ - in: 001-precision.in
4
+ out: 001-precision.ans
5
+ points: 1
6
+ - in: 002-precision.in
7
+ out: 002-precision.ans
8
+ points: 1
9
+ - in: 003-precision.in
10
+ out: 003-precision.ans
11
+ points: 1
12
+ - in: 004-precision.in
13
+ out: 004-precision.ans
14
+ points: 1
15
+ - in: 005-gen_jorke1.in
16
+ out: 005-gen_jorke1.ans
17
+ points: 1
18
+ - in: 006-gen_jorke1.in
19
+ out: 006-gen_jorke1.ans
20
+ points: 1
21
+ - in: 007-gen_jorke1.in
22
+ out: 007-gen_jorke1.ans
23
+ points: 1
24
+ - in: 008-gen_jorke1.in
25
+ out: 008-gen_jorke1.ans
26
+ points: 1
27
+ - in: 009-gen_jorke1.in
28
+ out: 009-gen_jorke1.ans
29
+ points: 1
30
+ - in: 010-gen_jorke1.in
31
+ out: 010-gen_jorke1.ans
32
+ points: 1
33
+ - in: 011-gen_jorke2.in
34
+ out: 011-gen_jorke2.ans
35
+ points: 1
36
+ - in: 012-gen_jorke2.in
37
+ out: 012-gen_jorke2.ans
38
+ points: 1
39
+ - in: 013-gen_jorke2.in
40
+ out: 013-gen_jorke2.ans
41
+ points: 1
42
+ - in: 014-gen_jorke2.in
43
+ out: 014-gen_jorke2.ans
44
+ points: 1
45
+ - in: 015-gen_jorke2.in
46
+ out: 015-gen_jorke2.ans
47
+ points: 1
48
+ - in: 016-gen_jorke2.in
49
+ out: 016-gen_jorke2.ans
50
+ points: 1
51
+ - in: 017-side_boxes_hor.in
52
+ out: 017-side_boxes_hor.ans
53
+ points: 1
54
+ - in: 018-side_boxes_hor.in
55
+ out: 018-side_boxes_hor.ans
56
+ points: 1
57
+ - in: 019-side_boxes_hor.in
58
+ out: 019-side_boxes_hor.ans
59
+ points: 1
60
+ - in: 020-side_boxes_hor.in
61
+ out: 020-side_boxes_hor.ans
62
+ points: 1
63
+ - in: 021-side_boxes_hor.in
64
+ out: 021-side_boxes_hor.ans
65
+ points: 1
66
+ - in: 022-side_boxes_hor.in
67
+ out: 022-side_boxes_hor.ans
68
+ points: 1
69
+ - in: 023-side_boxes_ver.in
70
+ out: 023-side_boxes_ver.ans
71
+ points: 1
72
+ - in: 024-side_boxes_ver.in
73
+ out: 024-side_boxes_ver.ans
74
+ points: 1
75
+ - in: 025-side_boxes_ver.in
76
+ out: 025-side_boxes_ver.ans
77
+ points: 1
78
+ - in: 026-side_boxes_ver.in
79
+ out: 026-side_boxes_ver.ans
80
+ points: 1
81
+ - in: 027-side_boxes_ver.in
82
+ out: 027-side_boxes_ver.ans
83
+ points: 1
84
+ - in: 028-side_boxes_ver.in
85
+ out: 028-side_boxes_ver.ans
86
+ points: 1
87
+ - in: 029-worstcase_200000_00.in
88
+ out: 029-worstcase_200000_00.ans
89
+ points: 1
90
+ - in: 030-worstcase_200000_00.in
91
+ out: 030-worstcase_200000_00.ans
92
+ points: 1
93
+ - in: 031-worstcase_200000_10.in
94
+ out: 031-worstcase_200000_10.ans
95
+ points: 1
96
+ - in: 032-worstcase_200000_10.in
97
+ out: 032-worstcase_200000_10.ans
98
+ points: 1
99
+ - in: 033-worstcase_200000_01.in
100
+ out: 033-worstcase_200000_01.ans
101
+ points: 1
102
+ - in: 034-worstcase_200000_01.in
103
+ out: 034-worstcase_200000_01.ans
104
+ points: 1
105
+ - in: 035-worstcase_200000_11.in
106
+ out: 035-worstcase_200000_11.ans
107
+ points: 1
108
+ - in: 036-worstcase_200000_11.in
109
+ out: 036-worstcase_200000_11.ans
110
+ points: 1
111
+ - in: 037-doomsday_manual.in
112
+ out: 037-doomsday_manual.ans
113
+ points: 1
114
+ - in: 038-doomsday_manual.in
115
+ out: 038-doomsday_manual.ans
116
+ points: 1
117
+ - in: 039-doomsday_manual.in
118
+ out: 039-doomsday_manual.ans
119
+ points: 1
120
+ - in: 040-doomsday_precision.in
121
+ out: 040-doomsday_precision.ans
122
+ points: 1
123
+ - in: 041-doomsday_precision.in
124
+ out: 041-doomsday_precision.ans
125
+ points: 1
126
+ - in: 042-manual.in
127
+ out: 042-manual.ans
128
+ points: 1
129
+ - in: 043-manual.in
130
+ out: 043-manual.ans
131
+ points: 1
132
+ - in: 044-manual.in
133
+ out: 044-manual.ans
134
+ points: 1
135
+ - in: 045-manual.in
136
+ out: 045-manual.ans
137
+ points: 1
138
+ - in: 046-manual.in
139
+ out: 046-manual.ans
140
+ points: 1
141
+ - in: 047-manual.in
142
+ out: 047-manual.ans
143
+ points: 1
144
+ - in: 048-manual.in
145
+ out: 048-manual.ans
146
+ points: 1
147
+ - in: 049-manual.in
148
+ out: 049-manual.ans
149
+ points: 1
150
+ - in: 050-manual.in
151
+ out: 050-manual.ans
152
+ points: 1
153
+ - in: 051-manual.in
154
+ out: 051-manual.ans
155
+ points: 1
156
+ - in: 052-manual.in
157
+ out: 052-manual.ans
158
+ points: 1
159
+ - in: 053-manual.in
160
+ out: 053-manual.ans
161
+ points: 1
162
+ - in: 054-manual.in
163
+ out: 054-manual.ans
164
+ points: 1
165
+ - in: 055-manual.in
166
+ out: 055-manual.ans
167
+ points: 1
168
+ - in: 056-manual.in
169
+ out: 056-manual.ans
170
+ points: 1
171
+ - in: 057-manual.in
172
+ out: 057-manual.ans
173
+ points: 1
174
+ - in: 058-manual.in
175
+ out: 058-manual.ans
176
+ points: 1
177
+ - in: 059-manual.in
178
+ out: 059-manual.ans
179
+ points: 1
180
+ - in: 060-manual.in
181
+ out: 060-manual.ans
182
+ points: 1
183
+ - in: 061-manual.in
184
+ out: 061-manual.ans
185
+ points: 1
186
+ - in: 062-manual.in
187
+ out: 062-manual.ans
188
+ points: 1
189
+ - in: 063-manual.in
190
+ out: 063-manual.ans
191
+ points: 1
192
+ - in: 064-manual.in
193
+ out: 064-manual.ans
194
+ points: 1
195
+ - in: 065-minimal-low.in
196
+ out: 065-minimal-low.ans
197
+ points: 1
198
+ - in: 066-minimal-high.in
199
+ out: 066-minimal-high.ans
200
+ points: 1
201
+ - in: 067-minimal-low-high.in
202
+ out: 067-minimal-low-high.ans
203
+ points: 1
204
+ - in: 068-gen1.in
205
+ out: 068-gen1.ans
206
+ points: 1
207
+ - in: 069-gen1.in
208
+ out: 069-gen1.ans
209
+ points: 1
210
+ - in: 070-gen1.in
211
+ out: 070-gen1.ans
212
+ points: 1
213
+ - in: 071-gen1.in
214
+ out: 071-gen1.ans
215
+ points: 1
216
+ - in: 072-gen2.in
217
+ out: 072-gen2.ans
218
+ points: 1
219
+ - in: 073-gen2.in
220
+ out: 073-gen2.ans
221
+ points: 1
222
+ - in: 074-gen2.in
223
+ out: 074-gen2.ans
224
+ points: 1
225
+ - in: 075-gen2.in
226
+ out: 075-gen2.ans
227
+ points: 1
228
+ - in: 076-gen3.in
229
+ out: 076-gen3.ans
230
+ points: 1
231
+ - in: 077-gen4.in
232
+ out: 077-gen4.ans
233
+ points: 1
234
+ - in: 078-gen5.in
235
+ out: 078-gen5.ans
236
+ points: 1
237
+ - in: 079-gen6.in
238
+ out: 079-gen6.ans
239
+ points: 1
240
+ - in: 080-gen6.in
241
+ out: 080-gen6.ans
242
+ points: 1
243
+ - in: 081-gen7.in
244
+ out: 081-gen7.ans
245
+ points: 1
246
+ - in: 082-gen7.in
247
+ out: 082-gen7.ans
248
+ points: 1
249
+ - in: 083-gen7.in
250
+ out: 083-gen7.ans
251
+ points: 1
252
+ - in: 084-parabola_gen_5.in
253
+ out: 084-parabola_gen_5.ans
254
+ points: 1
255
+ - in: 085-parabola_gen_20.in
256
+ out: 085-parabola_gen_20.ans
257
+ points: 1
258
+ - in: 086-parabola_gen_1000.in
259
+ out: 086-parabola_gen_1000.ans
260
+ points: 1
261
+ - in: 087-parabola_gen_200000.in
262
+ out: 087-parabola_gen_200000.ans
263
+ points: 1
264
+ - in: 088-parabola_gen_200000.in
265
+ out: 088-parabola_gen_200000.ans
266
+ points: 1
267
+ - in: 089-parabola_gen_200000.in
268
+ out: 089-parabola_gen_200000.ans
269
+ points: 1
270
+ - in: 090-parpar_gen_5.in
271
+ out: 090-parpar_gen_5.ans
272
+ points: 1
273
+ - in: 091-parpar_gen_20.in
274
+ out: 091-parpar_gen_20.ans
275
+ points: 1
276
+ - in: 092-parpar_gen_1000.in
277
+ out: 092-parpar_gen_1000.ans
278
+ points: 1
279
+ - in: 093-parpar_gen_5000.in
280
+ out: 093-parpar_gen_5000.ans
281
+ points: 1
282
+ - in: 094-parpar_gen_10000.in
283
+ out: 094-parpar_gen_10000.ans
284
+ points: 1
285
+ - in: 095-parpar_gen_200000.in
286
+ out: 095-parpar_gen_200000.ans
287
+ points: 1
288
+ - in: 096-parpar_gen_200000.in
289
+ out: 096-parpar_gen_200000.ans
290
+ points: 1
291
+ - in: 097-parpar_gen_200000.in
292
+ out: 097-parpar_gen_200000.ans
293
+ points: 1
294
+ - in: 098-pardis_5.in
295
+ out: 098-pardis_5.ans
296
+ points: 1
297
+ - in: 099-pardis_20.in
298
+ out: 099-pardis_20.ans
299
+ points: 1
300
+ - in: 100-pardis_1000.in
301
+ out: 100-pardis_1000.ans
302
+ points: 1
303
+ - in: 101-pardis_5000.in
304
+ out: 101-pardis_5000.ans
305
+ points: 1
306
+ - in: 102-pardis_10000.in
307
+ out: 102-pardis_10000.ans
308
+ points: 1
309
+ - in: 103-pardis_200000.in
310
+ out: 103-pardis_200000.ans
311
+ points: 1
312
+ - in: 104-pardis_200000.in
313
+ out: 104-pardis_200000.ans
314
+ points: 1
315
+ - in: 105-partan_5.in
316
+ out: 105-partan_5.ans
317
+ points: 1
318
+ - in: 106-partan_20.in
319
+ out: 106-partan_20.ans
320
+ points: 1
321
+ - in: 107-partan_5000.in
322
+ out: 107-partan_5000.ans
323
+ points: 1
324
+ - in: 108-partan_10000.in
325
+ out: 108-partan_10000.ans
326
+ points: 1
327
+ - in: 109-partan_10000.in
328
+ out: 109-partan_10000.ans
329
+ points: 1
330
+ - in: 110-partan_200000.in
331
+ out: 110-partan_200000.ans
332
+ points: 1
333
+ - in: 111-partan_200000.in
334
+ out: 111-partan_200000.ans
335
+ points: 1
336
+ - in: 112-partan_200000.in
337
+ out: 112-partan_200000.ans
338
+ points: 1
339
+ - in: 113-partan_200000.in
340
+ out: 113-partan_200000.ans
341
+ points: 1
342
+ - in: 114-worstcase_5_00.in
343
+ out: 114-worstcase_5_00.ans
344
+ points: 1
345
+ - in: 115-worstcase_20_00.in
346
+ out: 115-worstcase_20_00.ans
347
+ points: 1
348
+ - in: 116-worstcase_1000_00.in
349
+ out: 116-worstcase_1000_00.ans
350
+ points: 1
351
+ - in: 117-worstcase_5000_00.in
352
+ out: 117-worstcase_5000_00.ans
353
+ points: 1
354
+ - in: 118-worstcase_10000_00.in
355
+ out: 118-worstcase_10000_00.ans
356
+ points: 1
357
+ - in: 119-worstcase_200000_00.in
358
+ out: 119-worstcase_200000_00.ans
359
+ points: 1
360
+ - in: 120-worstcase_200000_00.in
361
+ out: 120-worstcase_200000_00.ans
362
+ points: 1
363
+ - in: 121-worstcase_200000_00.in
364
+ out: 121-worstcase_200000_00.ans
365
+ points: 1
366
+ - in: 122-worstcase_5_10.in
367
+ out: 122-worstcase_5_10.ans
368
+ points: 1
369
+ - in: 123-worstcase_20_10.in
370
+ out: 123-worstcase_20_10.ans
371
+ points: 1
372
+ - in: 124-worstcase_1000_10.in
373
+ out: 124-worstcase_1000_10.ans
374
+ points: 1
375
+ - in: 125-worstcase_5000_10.in
376
+ out: 125-worstcase_5000_10.ans
377
+ points: 1
378
+ - in: 126-worstcase_10000_10.in
379
+ out: 126-worstcase_10000_10.ans
380
+ points: 1
381
+ - in: 127-worstcase_200000_10.in
382
+ out: 127-worstcase_200000_10.ans
383
+ points: 1
384
+ - in: 128-worstcase_200000_10.in
385
+ out: 128-worstcase_200000_10.ans
386
+ points: 1
387
+ - in: 129-worstcase_200000_10.in
388
+ out: 129-worstcase_200000_10.ans
389
+ points: 1
390
+ - in: 130-worstcase_200000_10.in
391
+ out: 130-worstcase_200000_10.ans
392
+ points: 1
393
+ - in: 131-worstcase_200000_10.in
394
+ out: 131-worstcase_200000_10.ans
395
+ points: 1
396
+ - in: 132-worstcase_200000_10.in
397
+ out: 132-worstcase_200000_10.ans
398
+ points: 1
399
+ - in: 133-worstcase_20_01.in
400
+ out: 133-worstcase_20_01.ans
401
+ points: 1
402
+ - in: 134-worstcase_20_11.in
403
+ out: 134-worstcase_20_11.ans
404
+ points: 1
405
+ - in: 135-box_5_0.in
406
+ out: 135-box_5_0.ans
407
+ points: 1
408
+ - in: 136-box_7_0.in
409
+ out: 136-box_7_0.ans
410
+ points: 1
411
+ - in: 137-box_10_0.in
412
+ out: 137-box_10_0.ans
413
+ points: 1
414
+ - in: 138-box_10_0.in
415
+ out: 138-box_10_0.ans
416
+ points: 1
417
+ - in: 139-box_7_0.in
418
+ out: 139-box_7_0.ans
419
+ points: 1
420
+ - in: 140-box_7_0.in
421
+ out: 140-box_7_0.ans
422
+ points: 1
423
+ - in: 141-box_7_0.in
424
+ out: 141-box_7_0.ans
425
+ points: 1
426
+ - in: 142-box_5_5.in
427
+ out: 142-box_5_5.ans
428
+ points: 1
429
+ - in: 143-box_5_5.in
430
+ out: 143-box_5_5.ans
431
+ points: 1
432
+ - in: 144-box_5_5.in
433
+ out: 144-box_5_5.ans
434
+ points: 1
435
+ - in: 145-box_5_5.in
436
+ out: 145-box_5_5.ans
437
+ points: 1
438
+ - in: 146-box_7_5.in
439
+ out: 146-box_7_5.ans
440
+ points: 1
441
+ - in: 147-box_5_7.in
442
+ out: 147-box_5_7.ans
443
+ points: 1
444
+ - in: 148-box_7_7.in
445
+ out: 148-box_7_7.ans
446
+ points: 1
447
+ - in: 149-box_7_7.in
448
+ out: 149-box_7_7.ans
449
+ points: 1
450
+ - in: 150-box_3_10.in
451
+ out: 150-box_3_10.ans
452
+ points: 1
453
+ - in: 151-box_3_10.in
454
+ out: 151-box_3_10.ans
455
+ points: 1
456
+ - in: 152-box_3_10.in
457
+ out: 152-box_3_10.ans
458
+ points: 1
459
+ - in: 153-prime_line.in
460
+ out: 153-prime_line.ans
461
+ points: 1
462
+ - in: 154-prime_line.in
463
+ out: 154-prime_line.ans
464
+ points: 1
465
+ - in: 155-prime_line.in
466
+ out: 155-prime_line.ans
467
+ points: 1
468
+ - in: 156-manual_break_nils.in
469
+ out: 156-manual_break_nils.ans
470
+ points: 1
471
+ - in: 157-side_boxes_hor.in
472
+ out: 157-side_boxes_hor.ans
473
+ points: 1
474
+ - in: 158-side_boxes_hor.in
475
+ out: 158-side_boxes_hor.ans
476
+ points: 1
477
+ - in: 159-side_boxes_ver.in
478
+ out: 159-side_boxes_ver.ans
479
+ points: 1
480
+ - in: 160-gen_jorke3.in
481
+ out: 160-gen_jorke3.ans
482
+ points: 1
483
+ - in: 161-gen_jorke3.in
484
+ out: 161-gen_jorke3.ans
485
+ points: 1
486
+ - in: 162-gen_jorke3.in
487
+ out: 162-gen_jorke3.ans
488
+ points: 1
489
+ - in: 163-gen_jorke3.in
490
+ out: 163-gen_jorke3.ans
491
+ points: 1
492
+ - in: 164-gen_jorke3.in
493
+ out: 164-gen_jorke3.ans
494
+ points: 1
495
+ - in: 165-gen_jorke3.in
496
+ out: 165-gen_jorke3.ans
497
+ points: 1
498
+ - in: 166-gen_jorke3.in
499
+ out: 166-gen_jorke3.ans
500
+ points: 1
501
+ - in: 167-gen_jorke3.in
502
+ out: 167-gen_jorke3.ans
503
+ points: 1
504
+ - in: 168-gen_jorke3.in
505
+ out: 168-gen_jorke3.ans
506
+ points: 1
507
+ - in: 169-gen_jorke3.in
508
+ out: 169-gen_jorke3.ans
509
+ points: 1
510
+ - in: 170-gen_jorke3.in
511
+ out: 170-gen_jorke3.ans
512
+ points: 1
513
+ - in: 171-gen_jorke3.in
514
+ out: 171-gen_jorke3.ans
515
+ points: 1
516
+ - in: 172-gen_jorke3.in
517
+ out: 172-gen_jorke3.ans
518
+ points: 1
519
+ - in: 173-gen_jorke3.in
520
+ out: 173-gen_jorke3.ans
521
+ points: 1
522
+ - in: 174-gen_jorke3.in
523
+ out: 174-gen_jorke3.ans
524
+ points: 1
525
+ - in: 175-gen_jorke3.in
526
+ out: 175-gen_jorke3.ans
527
+ points: 1
528
+ - in: 176-gen_jorke3.in
529
+ out: 176-gen_jorke3.ans
530
+ points: 1
531
+ - in: 177-gen_jorke3.in
532
+ out: 177-gen_jorke3.ans
533
+ points: 1
534
+ - in: 178-long_box.in
535
+ out: 178-long_box.ans
536
+ points: 1
537
+ - in: 179-long_box.in
538
+ out: 179-long_box.ans
539
+ points: 1
540
+ - in: 180-long_box.in
541
+ out: 180-long_box.ans
542
+ points: 1
543
+ - in: 181-long_box.in
544
+ out: 181-long_box.ans
545
+ points: 1
546
+ - in: 182-long_box.in
547
+ out: 182-long_box.ans
548
+ points: 1
549
+ - in: 183-long_box.in
550
+ out: 183-long_box.ans
551
+ points: 1
552
+ - in: 184-long_box.in
553
+ out: 184-long_box.ans
554
+ points: 1
555
+ - in: 185-long_box.in
556
+ out: 185-long_box.ans
557
+ points: 1
558
+ - in: 186-long_box.in
559
+ out: 186-long_box.ans
560
+ points: 1
561
+ - in: 187-long_box.in
562
+ out: 187-long_box.ans
563
+ points: 1
564
+ - in: 188-long_box.in
565
+ out: 188-long_box.ans
566
+ points: 1
567
+ - in: 189-long_box.in
568
+ out: 189-long_box.ans
569
+ points: 1
570
+ - in: 190-gen_ragnar_markus.in
571
+ out: 190-gen_ragnar_markus.ans
572
+ points: 1
573
+ - in: 191-gen_ragnar_markus.in
574
+ out: 191-gen_ragnar_markus.ans
575
+ points: 1
576
+ - in: 192-gen_ragnar_markus.in
577
+ out: 192-gen_ragnar_markus.ans
578
+ points: 1
579
+ - in: 193-gen_ragnar_markus.in
580
+ out: 193-gen_ragnar_markus.ans
581
+ points: 1
582
+ - in: 194-gen_ragnar_markus.in
583
+ out: 194-gen_ragnar_markus.ans
584
+ points: 1
585
+ - in: 195-gen_ragnar_markus.in
586
+ out: 195-gen_ragnar_markus.ans
587
+ points: 1
588
+ - in: 196-gen_ragnar_markus.in
589
+ out: 196-gen_ragnar_markus.ans
590
+ points: 1
591
+ - in: 197-gen_ragnar_markus.in
592
+ out: 197-gen_ragnar_markus.ans
593
+ points: 1
594
+ - in: 198-gen_ragnar_markus.in
595
+ out: 198-gen_ragnar_markus.ans
596
+ points: 1
597
+ - in: 199-gen_ragnar_markus.in
598
+ out: 199-gen_ragnar_markus.ans
599
+ points: 1
600
+ - in: 200-gen_ragnar_markus.in
601
+ out: 200-gen_ragnar_markus.ans
602
+ points: 1
603
+ - in: 201-gen_ragnar_markus.in
604
+ out: 201-gen_ragnar_markus.ans
605
+ points: 1
606
+ - in: 202-gen_ragnar_markus.in
607
+ out: 202-gen_ragnar_markus.ans
608
+ points: 1
609
+ - in: 203-gen_ragnar_markus.in
610
+ out: 203-gen_ragnar_markus.ans
611
+ points: 1
612
+ - in: 204-gen_ragnar_markus.in
613
+ out: 204-gen_ragnar_markus.ans
614
+ points: 1
615
+ - in: 205-gen_ragnar_markus.in
616
+ out: 205-gen_ragnar_markus.ans
617
+ points: 1
618
+ - in: 206-gen_ragnar_markus.in
619
+ out: 206-gen_ragnar_markus.ans
620
+ points: 1
621
+ - in: 207-gen_ragnar_markus.in
622
+ out: 207-gen_ragnar_markus.ans
623
+ points: 1
624
+ - in: 208-gen_ragnar_markus.in
625
+ out: 208-gen_ragnar_markus.ans
626
+ points: 1
627
+ - in: 209-gen_jorke3_fuzzed.in
628
+ out: 209-gen_jorke3_fuzzed.ans
629
+ points: 1
630
+ - in: 210-gen_jorke3_fuzzed.in
631
+ out: 210-gen_jorke3_fuzzed.ans
632
+ points: 1
633
+ - in: 211-gen_jorke3_fuzzed.in
634
+ out: 211-gen_jorke3_fuzzed.ans
635
+ points: 1
636
+ - in: 212-gen_jorke3_fuzzed.in
637
+ out: 212-gen_jorke3_fuzzed.ans
638
+ points: 1
639
+ - in: 213-gen_jorke3_fuzzed.in
640
+ out: 213-gen_jorke3_fuzzed.ans
641
+ points: 1
642
+ - in: 214-gen_jorke3_fuzzed.in
643
+ out: 214-gen_jorke3_fuzzed.ans
644
+ points: 1
645
+ - in: 215-gen_jorke3_fuzzed.in
646
+ out: 215-gen_jorke3_fuzzed.ans
647
+ points: 1
648
+ - in: 216-gen_jorke3_fuzzed.in
649
+ out: 216-gen_jorke3_fuzzed.ans
650
+ points: 1
651
+ - in: 217-gen_jorke3_fuzzed.in
652
+ out: 217-gen_jorke3_fuzzed.ans
653
+ points: 1
654
+ - in: 218-gen8.in
655
+ out: 218-gen8.ans
656
+ points: 1
657
+ - in: 219-gen8.in
658
+ out: 219-gen8.ans
659
+ points: 1
660
+ - in: 220-gen8.in
661
+ out: 220-gen8.ans
662
+ points: 1
663
+ - in: 221-gen8.in
664
+ out: 221-gen8.ans
665
+ points: 1
ICPC/nwerc2022_G/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f2f5f0bbf09389c282827ce78c294db9ceaa8b89348714372d3cb13a0610d74
3
+ size 101977
ICPC/nwerc2022_G/init.yml ADDED
@@ -0,0 +1,624 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ interactive:
3
+ files:
4
+ - output_validators/validate/validate.cpp
5
+ - output_validators/validate/validate.h
6
+ lang: CPP17
7
+ type: default
8
+ test_cases:
9
+ - in: 001-period.in
10
+ out: 001-period.ans
11
+ points: 1
12
+ - in: 002-period.in
13
+ out: 002-period.ans
14
+ points: 1
15
+ - in: 003-period.in
16
+ out: 003-period.ans
17
+ points: 1
18
+ - in: 004-period.in
19
+ out: 004-period.ans
20
+ points: 1
21
+ - in: 005-period.in
22
+ out: 005-period.ans
23
+ points: 1
24
+ - in: 006-period.in
25
+ out: 006-period.ans
26
+ points: 1
27
+ - in: 007-period.in
28
+ out: 007-period.ans
29
+ points: 1
30
+ - in: 008-period.in
31
+ out: 008-period.ans
32
+ points: 1
33
+ - in: 009-period.in
34
+ out: 009-period.ans
35
+ points: 1
36
+ - in: 010-period.in
37
+ out: 010-period.ans
38
+ points: 1
39
+ - in: 011-period.in
40
+ out: 011-period.ans
41
+ points: 1
42
+ - in: 012-period.in
43
+ out: 012-period.ans
44
+ points: 1
45
+ - in: 013-debruijn.in
46
+ out: 013-debruijn.ans
47
+ points: 1
48
+ - in: 014-debruijn.in
49
+ out: 014-debruijn.ans
50
+ points: 1
51
+ - in: 015-debruijn.in
52
+ out: 015-debruijn.ans
53
+ points: 1
54
+ - in: 016-debruijn.in
55
+ out: 016-debruijn.ans
56
+ points: 1
57
+ - in: 017-debruijn.in
58
+ out: 017-debruijn.ans
59
+ points: 1
60
+ - in: 018-debruijn.in
61
+ out: 018-debruijn.ans
62
+ points: 1
63
+ - in: 019-debruijn.in
64
+ out: 019-debruijn.ans
65
+ points: 1
66
+ - in: 020-debruijn.in
67
+ out: 020-debruijn.ans
68
+ points: 1
69
+ - in: 021-debruijn.in
70
+ out: 021-debruijn.ans
71
+ points: 1
72
+ - in: 022-debruijn.in
73
+ out: 022-debruijn.ans
74
+ points: 1
75
+ - in: 023-debruijn.in
76
+ out: 023-debruijn.ans
77
+ points: 1
78
+ - in: 024-debruijn.in
79
+ out: 024-debruijn.ans
80
+ points: 1
81
+ - in: 025-constants.in
82
+ out: 025-constants.ans
83
+ points: 1
84
+ - in: 026-constants.in
85
+ out: 026-constants.ans
86
+ points: 1
87
+ - in: 027-constants.in
88
+ out: 027-constants.ans
89
+ points: 1
90
+ - in: 028-constants.in
91
+ out: 028-constants.ans
92
+ points: 1
93
+ - in: 029-ones.in
94
+ out: 029-ones.ans
95
+ points: 1
96
+ - in: 030-ones.in
97
+ out: 030-ones.ans
98
+ points: 1
99
+ - in: 031-ones.in
100
+ out: 031-ones.ans
101
+ points: 1
102
+ - in: 032-ones.in
103
+ out: 032-ones.ans
104
+ points: 1
105
+ - in: 033-ones.in
106
+ out: 033-ones.ans
107
+ points: 1
108
+ - in: 034-ones.in
109
+ out: 034-ones.ans
110
+ points: 1
111
+ - in: 035-ones.in
112
+ out: 035-ones.ans
113
+ points: 1
114
+ - in: 036-ones.in
115
+ out: 036-ones.ans
116
+ points: 1
117
+ - in: 037-ones.in
118
+ out: 037-ones.ans
119
+ points: 1
120
+ - in: 038-ones.in
121
+ out: 038-ones.ans
122
+ points: 1
123
+ - in: 039-ones.in
124
+ out: 039-ones.ans
125
+ points: 1
126
+ - in: 040-ones.in
127
+ out: 040-ones.ans
128
+ points: 1
129
+ - in: 041-ones.in
130
+ out: 041-ones.ans
131
+ points: 1
132
+ - in: 042-ones.in
133
+ out: 042-ones.ans
134
+ points: 1
135
+ - in: 043-ones.in
136
+ out: 043-ones.ans
137
+ points: 1
138
+ - in: 044-zeroes.in
139
+ out: 044-zeroes.ans
140
+ points: 1
141
+ - in: 045-zeroes.in
142
+ out: 045-zeroes.ans
143
+ points: 1
144
+ - in: 046-zeroes.in
145
+ out: 046-zeroes.ans
146
+ points: 1
147
+ - in: 047-zeroes.in
148
+ out: 047-zeroes.ans
149
+ points: 1
150
+ - in: 048-zeroes.in
151
+ out: 048-zeroes.ans
152
+ points: 1
153
+ - in: 049-zeroes.in
154
+ out: 049-zeroes.ans
155
+ points: 1
156
+ - in: 050-zeroes.in
157
+ out: 050-zeroes.ans
158
+ points: 1
159
+ - in: 051-zeroes.in
160
+ out: 051-zeroes.ans
161
+ points: 1
162
+ - in: 052-zeroes.in
163
+ out: 052-zeroes.ans
164
+ points: 1
165
+ - in: 053-zeroes.in
166
+ out: 053-zeroes.ans
167
+ points: 1
168
+ - in: 054-zeroes.in
169
+ out: 054-zeroes.ans
170
+ points: 1
171
+ - in: 055-zeroes.in
172
+ out: 055-zeroes.ans
173
+ points: 1
174
+ - in: 056-zeroes.in
175
+ out: 056-zeroes.ans
176
+ points: 1
177
+ - in: 057-zeroes.in
178
+ out: 057-zeroes.ans
179
+ points: 1
180
+ - in: 058-zeroes.in
181
+ out: 058-zeroes.ans
182
+ points: 1
183
+ - in: 059-uniform_random.in
184
+ out: 059-uniform_random.ans
185
+ points: 1
186
+ - in: 060-uniform_random.in
187
+ out: 060-uniform_random.ans
188
+ points: 1
189
+ - in: 061-uniform_random.in
190
+ out: 061-uniform_random.ans
191
+ points: 1
192
+ - in: 062-uniform_random.in
193
+ out: 062-uniform_random.ans
194
+ points: 1
195
+ - in: 063-uniform_random.in
196
+ out: 063-uniform_random.ans
197
+ points: 1
198
+ - in: 064-uniform_random.in
199
+ out: 064-uniform_random.ans
200
+ points: 1
201
+ - in: 065-uniform_random.in
202
+ out: 065-uniform_random.ans
203
+ points: 1
204
+ - in: 066-uniform_random.in
205
+ out: 066-uniform_random.ans
206
+ points: 1
207
+ - in: 067-uniform_random.in
208
+ out: 067-uniform_random.ans
209
+ points: 1
210
+ - in: 068-uniform_random.in
211
+ out: 068-uniform_random.ans
212
+ points: 1
213
+ - in: 069-uniform_random.in
214
+ out: 069-uniform_random.ans
215
+ points: 1
216
+ - in: 070-uniform_random.in
217
+ out: 070-uniform_random.ans
218
+ points: 1
219
+ - in: 071-uniform_random.in
220
+ out: 071-uniform_random.ans
221
+ points: 1
222
+ - in: 072-uniform_random.in
223
+ out: 072-uniform_random.ans
224
+ points: 1
225
+ - in: 073-uniform_random.in
226
+ out: 073-uniform_random.ans
227
+ points: 1
228
+ - in: 074-uniform_random.in
229
+ out: 074-uniform_random.ans
230
+ points: 1
231
+ - in: 075-uniform_random.in
232
+ out: 075-uniform_random.ans
233
+ points: 1
234
+ - in: 076-uniform_random.in
235
+ out: 076-uniform_random.ans
236
+ points: 1
237
+ - in: 077-uniform_random.in
238
+ out: 077-uniform_random.ans
239
+ points: 1
240
+ - in: 078-uniform_random.in
241
+ out: 078-uniform_random.ans
242
+ points: 1
243
+ - in: 079-uniform_random.in
244
+ out: 079-uniform_random.ans
245
+ points: 1
246
+ - in: 080-uniform_random.in
247
+ out: 080-uniform_random.ans
248
+ points: 1
249
+ - in: 081-uniform_random.in
250
+ out: 081-uniform_random.ans
251
+ points: 1
252
+ - in: 082-uniform_random.in
253
+ out: 082-uniform_random.ans
254
+ points: 1
255
+ - in: 083-uniform_random.in
256
+ out: 083-uniform_random.ans
257
+ points: 1
258
+ - in: 084-uniform_random.in
259
+ out: 084-uniform_random.ans
260
+ points: 1
261
+ - in: 085-uniform_random.in
262
+ out: 085-uniform_random.ans
263
+ points: 1
264
+ - in: 086-uniform_random.in
265
+ out: 086-uniform_random.ans
266
+ points: 1
267
+ - in: 087-uniform_random.in
268
+ out: 087-uniform_random.ans
269
+ points: 1
270
+ - in: 088-biased_one.in
271
+ out: 088-biased_one.ans
272
+ points: 1
273
+ - in: 089-biased_one.in
274
+ out: 089-biased_one.ans
275
+ points: 1
276
+ - in: 090-biased_one.in
277
+ out: 090-biased_one.ans
278
+ points: 1
279
+ - in: 091-biased_one.in
280
+ out: 091-biased_one.ans
281
+ points: 1
282
+ - in: 092-biased_one.in
283
+ out: 092-biased_one.ans
284
+ points: 1
285
+ - in: 093-biased_one.in
286
+ out: 093-biased_one.ans
287
+ points: 1
288
+ - in: 094-biased_one.in
289
+ out: 094-biased_one.ans
290
+ points: 1
291
+ - in: 095-biased_one.in
292
+ out: 095-biased_one.ans
293
+ points: 1
294
+ - in: 096-biased_one.in
295
+ out: 096-biased_one.ans
296
+ points: 1
297
+ - in: 097-biased_one.in
298
+ out: 097-biased_one.ans
299
+ points: 1
300
+ - in: 098-biased_one.in
301
+ out: 098-biased_one.ans
302
+ points: 1
303
+ - in: 099-biased_one.in
304
+ out: 099-biased_one.ans
305
+ points: 1
306
+ - in: 100-biased_one.in
307
+ out: 100-biased_one.ans
308
+ points: 1
309
+ - in: 101-biased_one.in
310
+ out: 101-biased_one.ans
311
+ points: 1
312
+ - in: 102-biased_one.in
313
+ out: 102-biased_one.ans
314
+ points: 1
315
+ - in: 103-biased_one.in
316
+ out: 103-biased_one.ans
317
+ points: 1
318
+ - in: 104-biased_one.in
319
+ out: 104-biased_one.ans
320
+ points: 1
321
+ - in: 105-biased_one.in
322
+ out: 105-biased_one.ans
323
+ points: 1
324
+ - in: 106-biased_one.in
325
+ out: 106-biased_one.ans
326
+ points: 1
327
+ - in: 107-biased_one.in
328
+ out: 107-biased_one.ans
329
+ points: 1
330
+ - in: 108-biased_one.in
331
+ out: 108-biased_one.ans
332
+ points: 1
333
+ - in: 109-biased_one.in
334
+ out: 109-biased_one.ans
335
+ points: 1
336
+ - in: 110-biased_one.in
337
+ out: 110-biased_one.ans
338
+ points: 1
339
+ - in: 111-biased_one.in
340
+ out: 111-biased_one.ans
341
+ points: 1
342
+ - in: 112-biased_one.in
343
+ out: 112-biased_one.ans
344
+ points: 1
345
+ - in: 113-biased_one.in
346
+ out: 113-biased_one.ans
347
+ points: 1
348
+ - in: 114-biased_one.in
349
+ out: 114-biased_one.ans
350
+ points: 1
351
+ - in: 115-biased_one.in
352
+ out: 115-biased_one.ans
353
+ points: 1
354
+ - in: 116-biased_one.in
355
+ out: 116-biased_one.ans
356
+ points: 1
357
+ - in: 117-biased_one.in
358
+ out: 117-biased_one.ans
359
+ points: 1
360
+ - in: 118-biased_one.in
361
+ out: 118-biased_one.ans
362
+ points: 1
363
+ - in: 119-biased_one.in
364
+ out: 119-biased_one.ans
365
+ points: 1
366
+ - in: 120-biased_one.in
367
+ out: 120-biased_one.ans
368
+ points: 1
369
+ - in: 121-biased_one.in
370
+ out: 121-biased_one.ans
371
+ points: 1
372
+ - in: 122-biased_one.in
373
+ out: 122-biased_one.ans
374
+ points: 1
375
+ - in: 123-biased_one.in
376
+ out: 123-biased_one.ans
377
+ points: 1
378
+ - in: 124-biased_one.in
379
+ out: 124-biased_one.ans
380
+ points: 1
381
+ - in: 125-biased_one.in
382
+ out: 125-biased_one.ans
383
+ points: 1
384
+ - in: 126-biased_one.in
385
+ out: 126-biased_one.ans
386
+ points: 1
387
+ - in: 127-biased_one.in
388
+ out: 127-biased_one.ans
389
+ points: 1
390
+ - in: 128-biased_one.in
391
+ out: 128-biased_one.ans
392
+ points: 1
393
+ - in: 129-biased_one.in
394
+ out: 129-biased_one.ans
395
+ points: 1
396
+ - in: 130-biased_one.in
397
+ out: 130-biased_one.ans
398
+ points: 1
399
+ - in: 131-biased_one.in
400
+ out: 131-biased_one.ans
401
+ points: 1
402
+ - in: 132-biased_one.in
403
+ out: 132-biased_one.ans
404
+ points: 1
405
+ - in: 133-biased_one.in
406
+ out: 133-biased_one.ans
407
+ points: 1
408
+ - in: 134-biased_one.in
409
+ out: 134-biased_one.ans
410
+ points: 1
411
+ - in: 135-biased_one.in
412
+ out: 135-biased_one.ans
413
+ points: 1
414
+ - in: 136-biased_one.in
415
+ out: 136-biased_one.ans
416
+ points: 1
417
+ - in: 137-biased_one.in
418
+ out: 137-biased_one.ans
419
+ points: 1
420
+ - in: 138-biased_one.in
421
+ out: 138-biased_one.ans
422
+ points: 1
423
+ - in: 139-biased_one.in
424
+ out: 139-biased_one.ans
425
+ points: 1
426
+ - in: 140-biased_one.in
427
+ out: 140-biased_one.ans
428
+ points: 1
429
+ - in: 141-biased_one.in
430
+ out: 141-biased_one.ans
431
+ points: 1
432
+ - in: 142-biased_one.in
433
+ out: 142-biased_one.ans
434
+ points: 1
435
+ - in: 143-biased_one.in
436
+ out: 143-biased_one.ans
437
+ points: 1
438
+ - in: 144-biased_one.in
439
+ out: 144-biased_one.ans
440
+ points: 1
441
+ - in: 145-biased_one.in
442
+ out: 145-biased_one.ans
443
+ points: 1
444
+ - in: 146-biased_zero.in
445
+ out: 146-biased_zero.ans
446
+ points: 1
447
+ - in: 147-biased_zero.in
448
+ out: 147-biased_zero.ans
449
+ points: 1
450
+ - in: 148-biased_zero.in
451
+ out: 148-biased_zero.ans
452
+ points: 1
453
+ - in: 149-biased_zero.in
454
+ out: 149-biased_zero.ans
455
+ points: 1
456
+ - in: 150-biased_zero.in
457
+ out: 150-biased_zero.ans
458
+ points: 1
459
+ - in: 151-biased_zero.in
460
+ out: 151-biased_zero.ans
461
+ points: 1
462
+ - in: 152-biased_zero.in
463
+ out: 152-biased_zero.ans
464
+ points: 1
465
+ - in: 153-biased_zero.in
466
+ out: 153-biased_zero.ans
467
+ points: 1
468
+ - in: 154-biased_zero.in
469
+ out: 154-biased_zero.ans
470
+ points: 1
471
+ - in: 155-biased_zero.in
472
+ out: 155-biased_zero.ans
473
+ points: 1
474
+ - in: 156-biased_zero.in
475
+ out: 156-biased_zero.ans
476
+ points: 1
477
+ - in: 157-biased_zero.in
478
+ out: 157-biased_zero.ans
479
+ points: 1
480
+ - in: 158-biased_zero.in
481
+ out: 158-biased_zero.ans
482
+ points: 1
483
+ - in: 159-biased_zero.in
484
+ out: 159-biased_zero.ans
485
+ points: 1
486
+ - in: 160-biased_zero.in
487
+ out: 160-biased_zero.ans
488
+ points: 1
489
+ - in: 161-biased_zero.in
490
+ out: 161-biased_zero.ans
491
+ points: 1
492
+ - in: 162-biased_zero.in
493
+ out: 162-biased_zero.ans
494
+ points: 1
495
+ - in: 163-biased_zero.in
496
+ out: 163-biased_zero.ans
497
+ points: 1
498
+ - in: 164-biased_zero.in
499
+ out: 164-biased_zero.ans
500
+ points: 1
501
+ - in: 165-biased_zero.in
502
+ out: 165-biased_zero.ans
503
+ points: 1
504
+ - in: 166-biased_zero.in
505
+ out: 166-biased_zero.ans
506
+ points: 1
507
+ - in: 167-biased_zero.in
508
+ out: 167-biased_zero.ans
509
+ points: 1
510
+ - in: 168-biased_zero.in
511
+ out: 168-biased_zero.ans
512
+ points: 1
513
+ - in: 169-biased_zero.in
514
+ out: 169-biased_zero.ans
515
+ points: 1
516
+ - in: 170-biased_zero.in
517
+ out: 170-biased_zero.ans
518
+ points: 1
519
+ - in: 171-biased_zero.in
520
+ out: 171-biased_zero.ans
521
+ points: 1
522
+ - in: 172-biased_zero.in
523
+ out: 172-biased_zero.ans
524
+ points: 1
525
+ - in: 173-biased_zero.in
526
+ out: 173-biased_zero.ans
527
+ points: 1
528
+ - in: 174-biased_zero.in
529
+ out: 174-biased_zero.ans
530
+ points: 1
531
+ - in: 175-biased_zero.in
532
+ out: 175-biased_zero.ans
533
+ points: 1
534
+ - in: 176-biased_zero.in
535
+ out: 176-biased_zero.ans
536
+ points: 1
537
+ - in: 177-biased_zero.in
538
+ out: 177-biased_zero.ans
539
+ points: 1
540
+ - in: 178-biased_zero.in
541
+ out: 178-biased_zero.ans
542
+ points: 1
543
+ - in: 179-biased_zero.in
544
+ out: 179-biased_zero.ans
545
+ points: 1
546
+ - in: 180-biased_zero.in
547
+ out: 180-biased_zero.ans
548
+ points: 1
549
+ - in: 181-biased_zero.in
550
+ out: 181-biased_zero.ans
551
+ points: 1
552
+ - in: 182-biased_zero.in
553
+ out: 182-biased_zero.ans
554
+ points: 1
555
+ - in: 183-biased_zero.in
556
+ out: 183-biased_zero.ans
557
+ points: 1
558
+ - in: 184-biased_zero.in
559
+ out: 184-biased_zero.ans
560
+ points: 1
561
+ - in: 185-biased_zero.in
562
+ out: 185-biased_zero.ans
563
+ points: 1
564
+ - in: 186-biased_zero.in
565
+ out: 186-biased_zero.ans
566
+ points: 1
567
+ - in: 187-biased_zero.in
568
+ out: 187-biased_zero.ans
569
+ points: 1
570
+ - in: 188-biased_zero.in
571
+ out: 188-biased_zero.ans
572
+ points: 1
573
+ - in: 189-biased_zero.in
574
+ out: 189-biased_zero.ans
575
+ points: 1
576
+ - in: 190-biased_zero.in
577
+ out: 190-biased_zero.ans
578
+ points: 1
579
+ - in: 191-biased_zero.in
580
+ out: 191-biased_zero.ans
581
+ points: 1
582
+ - in: 192-biased_zero.in
583
+ out: 192-biased_zero.ans
584
+ points: 1
585
+ - in: 193-biased_zero.in
586
+ out: 193-biased_zero.ans
587
+ points: 1
588
+ - in: 194-biased_zero.in
589
+ out: 194-biased_zero.ans
590
+ points: 1
591
+ - in: 195-biased_zero.in
592
+ out: 195-biased_zero.ans
593
+ points: 1
594
+ - in: 196-biased_zero.in
595
+ out: 196-biased_zero.ans
596
+ points: 1
597
+ - in: 197-biased_zero.in
598
+ out: 197-biased_zero.ans
599
+ points: 1
600
+ - in: 198-biased_zero.in
601
+ out: 198-biased_zero.ans
602
+ points: 1
603
+ - in: 199-biased_zero.in
604
+ out: 199-biased_zero.ans
605
+ points: 1
606
+ - in: 200-biased_zero.in
607
+ out: 200-biased_zero.ans
608
+ points: 1
609
+ - in: 201-biased_zero.in
610
+ out: 201-biased_zero.ans
611
+ points: 1
612
+ - in: 202-biased_zero.in
613
+ out: 202-biased_zero.ans
614
+ points: 1
615
+ - in: 203-biased_zero.in
616
+ out: 203-biased_zero.ans
617
+ points: 1
618
+ - in: 204-biased_zero.in
619
+ out: 204-biased_zero.ans
620
+ points: 1
621
+ - in: 205-biased_zero.in
622
+ out: 205-biased_zero.ans
623
+ points: 1
624
+ unbuffered: false
ICPC/nwerc2022_G/output_validators/validate/validate.cpp ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #include<cstdlib>
3
+ int qwerty_getcode(int code) {
4
+ return code == 42? 0: 1;
5
+ }
6
+ namespace std {
7
+ void qwerty_exit(int code){
8
+ exit(qwerty_getcode(code));
9
+ }
10
+ } using std::qwerty_exit;
11
+ #define exit qwerty_exit
12
+ #define main qwerty_main
13
+ #include <climits>
14
+ #include <set>
15
+ #include <vector>
16
+
17
+ #include "validate.h"
18
+ using namespace std;
19
+
20
+ void to_lower(std::string& s) {
21
+ for (char& c : s) c |= 0x20;
22
+ }
23
+
24
+ int main(int argc, char **argv) {
25
+ init_io(argc,argv);
26
+
27
+ int n;
28
+ judge_in >> n;
29
+
30
+ int position = 0;
31
+ vector<int> state(n);
32
+ for (int i = 0; i < n; i++) {
33
+ char c;
34
+ judge_in >> c;
35
+ state[i] = c - '0';
36
+ }
37
+
38
+ cout << state[position] << endl;
39
+
40
+ int max_queries = 3*n + 500;
41
+ int lim_queries = 5*n + 1000;
42
+ int queries_used = 0;
43
+ while (true) {
44
+ string response;
45
+ if (!(author_out >> response)) {
46
+ wrong_answer("Wrong answer: failed to read response. Queries used: %d\n", queries_used);
47
+ }
48
+
49
+ if (response == "?") {
50
+ queries_used++;
51
+
52
+ string query;
53
+ if (!(author_out >> query)) {
54
+ wrong_answer("Wrong answer: failed to read query. Queries used: %d\n", queries_used);
55
+ }
56
+ to_lower(query);
57
+
58
+ if (query == "left") {
59
+ position = (position + n - 1) % n;
60
+ } else if (query == "right") {
61
+ position = (position + 1) % n;
62
+ } else if (query == "flip") {
63
+ state[position] = 1 - state[position];
64
+ } else {
65
+ wrong_answer("Wrong answer: invalid query type. Queries used: %d\n", queries_used);
66
+ }
67
+
68
+ cout << state[position] << endl;
69
+ } else if (response == "!") {
70
+ int guess;
71
+ if (!(author_out >> guess)) {
72
+ wrong_answer("Wrong answer: failed to read guess. Queries used: %d\n", queries_used);
73
+ }
74
+
75
+ string junk;
76
+ if (author_out >> junk) {
77
+ wrong_answer("Wrong answer: trailing output after guess.\n");
78
+ }
79
+
80
+ if (guess == n) {
81
+ if (queries_used > max_queries) {
82
+ wrong_answer("Wrong answer: correct guess, but used too many queries. Queries used: %d (%d too many)\n", queries_used, queries_used-max_queries);
83
+ }
84
+ break;
85
+ } else {
86
+ wrong_answer("Wrong answer: incorrect guess %d (ans: %d). Queries used: %d\n", guess, n, queries_used);
87
+ }
88
+ } else {
89
+ wrong_answer("Wrong answer: invalid response type. Queries used: %d\n", queries_used);
90
+ }
91
+ if (queries_used > lim_queries) {
92
+ wrong_answer("Wrong answer: used too many queries. Queries used: %d (%d too many, terminated)\n", queries_used, queries_used-max_queries);
93
+ }
94
+ }
95
+
96
+ string junk;
97
+ if (author_out >> junk) {
98
+ wrong_answer("Wrong answer: trailing output.\n");
99
+ }
100
+
101
+ judge_message("Queries used: %d.\n", queries_used);
102
+
103
+ accept();
104
+ }
105
+
106
+
107
+ #undef main
108
+ #include<cstdio>
109
+ #include<vector>
110
+ #include<string>
111
+ #include<filesystem>
112
+ int main(int argc, char **argv) {
113
+ namespace fs = std::filesystem;
114
+ char judge_out[] = "/dev";
115
+ std::vector<char*> new_argv = {
116
+ argv[0], argv[1], argv[2],
117
+ judge_out,
118
+ };
119
+ return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data()));
120
+ }
ICPC/nwerc2022_G/output_validators/validate/validate.h ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Utility functions for writing output validators for the Kattis
2
+ * problem format.
3
+ *
4
+ * The primary functions and variables available are the following.
5
+ * In many cases, the only functions needed are "init_io",
6
+ * "wrong_answer", and "accept".
7
+ *
8
+ * - init_io(argc, argv):
9
+ * initialization
10
+ *
11
+ * - judge_in, judge_ans, author_out:
12
+ * std::istream objects for judge input file, judge answer
13
+ * file, and submission output file.
14
+ *
15
+ * - accept():
16
+ * exit and give Accepted!
17
+ *
18
+ * - accept_with_score(double score):
19
+ * exit with Accepted and give a score (for scoring problems)
20
+ *
21
+ * - judge_message(std::string msg, ...):
22
+ * printf-style function for emitting a judge message (a
23
+ * message that gets displayed to a privileged user with access
24
+ * to secret data etc).
25
+ *
26
+ * - wrong_answer(std::string msg, ...):
27
+ * printf-style function for exitting and giving Wrong Answer,
28
+ * and emitting a judge message (which would typically explain
29
+ * the cause of the Wrong Answer)
30
+ *
31
+ * - judge_error(std::string msg, ...):
32
+ * printf-style function for exitting and giving Judge Error,
33
+ * and emitting a judge message (which would typically explain
34
+ * the cause of the Judge Error)
35
+ *
36
+ * - author_message(std::string msg, ...):
37
+ * printf-style function for emitting an author message (a
38
+ * message that gets displayed to the author of the
39
+ * submission). (Use with caution, and be careful not to let
40
+ * it leak information!)
41
+ *
42
+ */
43
+ #pragma once
44
+
45
+ #include <sys/stat.h>
46
+ #include <cassert>
47
+ #include <cstdarg>
48
+ #include <cstdlib>
49
+ #include <iostream>
50
+ #include <fstream>
51
+ #include <sstream>
52
+
53
+ typedef void (*feedback_function)(const std::string &, ...);
54
+
55
+ const int EXITCODE_AC = 42;
56
+ const int EXITCODE_WA = 43;
57
+ const std::string FILENAME_AUTHOR_MESSAGE = "teammessage.txt";
58
+ const std::string FILENAME_JUDGE_MESSAGE = "null";
59
+ const std::string FILENAME_JUDGE_ERROR = "judgeerror.txt";
60
+ const std::string FILENAME_SCORE = "score.txt";
61
+
62
+ #define USAGE "%s: judge_in judge_ans feedback_dir < author_out\n"
63
+
64
+ std::ifstream judge_in, judge_ans;
65
+ std::istream author_out(std::cin.rdbuf());
66
+
67
+ char *feedbackdir = NULL;
68
+
69
+ void vreport_feedback(const std::string &category,
70
+ const std::string &msg,
71
+ va_list pvar) {
72
+ std::ostringstream fname;
73
+ if (feedbackdir)
74
+ fname << feedbackdir << '/';
75
+ fname << category;
76
+ FILE *f = fopen(fname.str().c_str(), "a");
77
+ assert(f);
78
+ vfprintf(f, msg.c_str(), pvar);
79
+ fclose(f);
80
+ }
81
+
82
+ void report_feedback(const std::string &category, const std::string &msg, ...) {
83
+ va_list pvar;
84
+ va_start(pvar, msg);
85
+ vreport_feedback(category, msg, pvar);
86
+ }
87
+
88
+ void author_message(const std::string &msg, ...) {
89
+ va_list pvar;
90
+ va_start(pvar, msg);
91
+ vreport_feedback(FILENAME_AUTHOR_MESSAGE, msg, pvar);
92
+ }
93
+
94
+ void judge_message(const std::string &msg, ...) {
95
+ va_list pvar;
96
+ va_start(pvar, msg);
97
+ vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar);
98
+ }
99
+
100
+ void wrong_answer(const std::string &msg, ...) {
101
+ va_list pvar;
102
+ va_start(pvar, msg);
103
+ vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar);
104
+ exit(EXITCODE_WA);
105
+ }
106
+
107
+ void judge_error(const std::string &msg, ...) {
108
+ va_list pvar;
109
+ va_start(pvar, msg);
110
+ vreport_feedback(FILENAME_JUDGE_ERROR, msg, pvar);
111
+ assert(0);
112
+ }
113
+
114
+ void accept() {
115
+ exit(EXITCODE_AC);
116
+ }
117
+
118
+ void accept_with_score(double scorevalue) {
119
+ report_feedback(FILENAME_SCORE, "%.9le", scorevalue);
120
+ exit(EXITCODE_AC);
121
+ }
122
+
123
+
124
+ bool is_directory(const char *path) {
125
+ if(std::string(path) == std::string("/dev")) return 1;
126
+ struct stat entry;
127
+ return stat(path, &entry) == 0 && S_ISDIR(entry.st_mode);
128
+ }
129
+
130
+ void init_io(int argc, char **argv) {
131
+ if(argc < 4) {
132
+ fprintf(stderr, USAGE, argv[0]);
133
+ judge_error("Usage: %s judgein judgeans feedbackdir [opts] < userout", argv[0]);
134
+ }
135
+
136
+ // Set up feedbackdir first, as that allows us to produce feedback
137
+ // files for errors in the other parameters.
138
+ if (!is_directory(argv[3])) {
139
+ judge_error("%s: %s is not a directory\n", argv[0], argv[3]);
140
+ }
141
+ feedbackdir = argv[3];
142
+
143
+ judge_in.open(argv[1], std::ios_base::in);
144
+ if (judge_in.fail()) {
145
+ judge_error("%s: failed to open %s\n", argv[0], argv[1]);
146
+ }
147
+
148
+ judge_ans.open(argv[2], std::ios_base::in);
149
+ if (judge_ans.fail()) {
150
+ judge_error("%s: failed to open %s\n", argv[0], argv[2]);
151
+ }
152
+
153
+ author_out.rdbuf(std::cin.rdbuf());
154
+ }
ICPC/nwerc2022_H/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:67e095af096b197afd21937619a0a8bff678c8b5c9bf747d261b0de61c8d6229
3
+ size 32405712
ICPC/nwerc2022_H/init.yml ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ test_cases:
3
+ - in: 01-path-tree.in
4
+ out: 01-path-tree.ans
5
+ points: 1
6
+ - in: 02-path-tree.in
7
+ out: 02-path-tree.ans
8
+ points: 1
9
+ - in: 03-path-tree.in
10
+ out: 03-path-tree.ans
11
+ points: 1
12
+ - in: 04-complete.in
13
+ out: 04-complete.ans
14
+ points: 1
15
+ - in: 05-complete.in
16
+ out: 05-complete.ans
17
+ points: 1
18
+ - in: 06-fibonacci_path_on_leaf.in
19
+ out: 06-fibonacci_path_on_leaf.ans
20
+ points: 1
21
+ - in: 07-fibonacci_path_on_leaf.in
22
+ out: 07-fibonacci_path_on_leaf.ans
23
+ points: 1
24
+ - in: 08-fibonacci_random.in
25
+ out: 08-fibonacci_random.ans
26
+ points: 1
27
+ - in: 09-fibonacci_random.in
28
+ out: 09-fibonacci_random.ans
29
+ points: 1
30
+ - in: 10-copath.in
31
+ out: 10-copath.ans
32
+ points: 1
33
+ - in: 11-copath.in
34
+ out: 11-copath.ans
35
+ points: 1
36
+ - in: 12-copath.in
37
+ out: 12-copath.ans
38
+ points: 1
39
+ - in: 13-binary.in
40
+ out: 13-binary.ans
41
+ points: 1
42
+ - in: 14-binary.in
43
+ out: 14-binary.ans
44
+ points: 1
45
+ - in: 15-random2.in
46
+ out: 15-random2.ans
47
+ points: 1
48
+ - in: 16-random2.in
49
+ out: 16-random2.ans
50
+ points: 1
51
+ - in: 17-random2.in
52
+ out: 17-random2.ans
53
+ points: 1
54
+ - in: 18-random2.in
55
+ out: 18-random2.ans
56
+ points: 1
57
+ - in: 19-random2.in
58
+ out: 19-random2.ans
59
+ points: 1
60
+ - in: 20-fibonacci_path_on_leaf.in
61
+ out: 20-fibonacci_path_on_leaf.ans
62
+ points: 1
63
+ - in: 21-fibonacci_path_on_leaf.in
64
+ out: 21-fibonacci_path_on_leaf.ans
65
+ points: 1
66
+ - in: 22-fibonacci_path_on_leaf.in
67
+ out: 22-fibonacci_path_on_leaf.ans
68
+ points: 1
69
+ - in: 23-fibonacci_path_on_leaf.in
70
+ out: 23-fibonacci_path_on_leaf.ans
71
+ points: 1
72
+ - in: 24-fibonacci_path_on_leaf.in
73
+ out: 24-fibonacci_path_on_leaf.ans
74
+ points: 1
75
+ - in: 25-fibonacci_path_on_leaf.in
76
+ out: 25-fibonacci_path_on_leaf.ans
77
+ points: 1
78
+ - in: 26-fibonacci_path_on_leaf.in
79
+ out: 26-fibonacci_path_on_leaf.ans
80
+ points: 1
81
+ - in: 27-fibonacci_path_on_leaf.in
82
+ out: 27-fibonacci_path_on_leaf.ans
83
+ points: 1
84
+ - in: 28-fibonacci_path_on_leaf.in
85
+ out: 28-fibonacci_path_on_leaf.ans
86
+ points: 1
87
+ - in: 29-fibonacci_path_on_leaf.in
88
+ out: 29-fibonacci_path_on_leaf.ans
89
+ points: 1
90
+ - in: 30-fibonacci_path_on_leaf.in
91
+ out: 30-fibonacci_path_on_leaf.ans
92
+ points: 1
93
+ - in: 31-fibonacci_path_on_leaf.in
94
+ out: 31-fibonacci_path_on_leaf.ans
95
+ points: 1
96
+ - in: 32-fibonacci_random.in
97
+ out: 32-fibonacci_random.ans
98
+ points: 1
99
+ - in: 33-fibonacci_random.in
100
+ out: 33-fibonacci_random.ans
101
+ points: 1
102
+ - in: 34-fibonacci_random.in
103
+ out: 34-fibonacci_random.ans
104
+ points: 1
105
+ - in: 35-fibonacci_random.in
106
+ out: 35-fibonacci_random.ans
107
+ points: 1
108
+ - in: 36-fibonacci_random.in
109
+ out: 36-fibonacci_random.ans
110
+ points: 1
111
+ - in: 37-fibonacci_random.in
112
+ out: 37-fibonacci_random.ans
113
+ points: 1
114
+ - in: 38-fibonacci_random.in
115
+ out: 38-fibonacci_random.ans
116
+ points: 1
117
+ - in: 39-fibonacci_random.in
118
+ out: 39-fibonacci_random.ans
119
+ points: 1
120
+ - in: 40-fibonacci_random.in
121
+ out: 40-fibonacci_random.ans
122
+ points: 1
123
+ - in: 41-fibonacci_random.in
124
+ out: 41-fibonacci_random.ans
125
+ points: 1
126
+ - in: 42-fibonacci_random.in
127
+ out: 42-fibonacci_random.ans
128
+ points: 1
129
+ - in: 43-fibonacci.in
130
+ out: 43-fibonacci.ans
131
+ points: 1
132
+ - in: 44-path.in
133
+ out: 44-path.ans
134
+ points: 1
135
+ - in: 45-path.in
136
+ out: 45-path.ans
137
+ points: 1
138
+ - in: 46-copath-small.in
139
+ out: 46-copath-small.ans
140
+ points: 1
141
+ - in: 47-copath-small.in
142
+ out: 47-copath-small.ans
143
+ points: 1
144
+ - in: 48-random.in
145
+ out: 48-random.ans
146
+ points: 1
147
+ - in: 49-random.in
148
+ out: 49-random.ans
149
+ points: 1
150
+ - in: 50-random.in
151
+ out: 50-random.ans
152
+ points: 1
153
+ - in: 51-random.in
154
+ out: 51-random.ans
155
+ points: 1
156
+ - in: 52-random.in
157
+ out: 52-random.ans
158
+ points: 1
159
+ - in: 53-random.in
160
+ out: 53-random.ans
161
+ points: 1
162
+ - in: 54-random.in
163
+ out: 54-random.ans
164
+ points: 1
165
+ - in: 55-random.in
166
+ out: 55-random.ans
167
+ points: 1
168
+ - in: 56-random.in
169
+ out: 56-random.ans
170
+ points: 1
171
+ - in: 57-random.in
172
+ out: 57-random.ans
173
+ points: 1
174
+ - in: 58-random.in
175
+ out: 58-random.ans
176
+ points: 1
177
+ - in: 59-random.in
178
+ out: 59-random.ans
179
+ points: 1
180
+ - in: 60-random.in
181
+ out: 60-random.ans
182
+ points: 1
183
+ - in: 61-random.in
184
+ out: 61-random.ans
185
+ points: 1
186
+ - in: 62-random.in
187
+ out: 62-random.ans
188
+ points: 1
189
+ - in: 63-random.in
190
+ out: 63-random.ans
191
+ points: 1
192
+ - in: 64-random.in
193
+ out: 64-random.ans
194
+ points: 1
195
+ - in: 65-random.in
196
+ out: 65-random.ans
197
+ points: 1
198
+ - in: 66-random.in
199
+ out: 66-random.ans
200
+ points: 1
201
+ - in: 67-random.in
202
+ out: 67-random.ans
203
+ points: 1
204
+ - in: 68-random.in
205
+ out: 68-random.ans
206
+ points: 1
207
+ - in: 69-random2-small.in
208
+ out: 69-random2-small.ans
209
+ points: 1
210
+ - in: 70-random2-small.in
211
+ out: 70-random2-small.ans
212
+ points: 1
213
+ - in: 71-random2-small.in
214
+ out: 71-random2-small.ans
215
+ points: 1
216
+ - in: 72-random2-small.in
217
+ out: 72-random2-small.ans
218
+ points: 1
219
+ - in: 73-random2-small.in
220
+ out: 73-random2-small.ans
221
+ points: 1
222
+ - in: 74-random2-small.in
223
+ out: 74-random2-small.ans
224
+ points: 1
225
+ - in: 75-random2-small.in
226
+ out: 75-random2-small.ans
227
+ points: 1
228
+ - in: 76-random2-small.in
229
+ out: 76-random2-small.ans
230
+ points: 1
231
+ - in: 77-binary.in
232
+ out: 77-binary.ans
233
+ points: 1
234
+ - in: 78-binary.in
235
+ out: 78-binary.ans
236
+ points: 1
237
+ - in: 79-binary.in
238
+ out: 79-binary.ans
239
+ points: 1
240
+ - in: 80-binary.in
241
+ out: 80-binary.ans
242
+ points: 1
243
+ - in: 81-binary.in
244
+ out: 81-binary.ans
245
+ points: 1
246
+ - in: 82-binary.in
247
+ out: 82-binary.ans
248
+ points: 1
249
+ - in: 83-binary.in
250
+ out: 83-binary.ans
251
+ points: 1
ICPC/nwerc2022_I/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72281fe73c0859d81835dd0bdc762a728a8b3dcf6197dd1ae3f461d2304eef18
3
+ size 5549755
ICPC/nwerc2022_I/init.yml ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ checker:
3
+ args:
4
+ files:
5
+ - output_validators/output_validator/output_validator.cpp
6
+ - output_validators/output_validator/validation.h
7
+ lang: CPP17
8
+ type: default
9
+ name: bridged
10
+ test_cases:
11
+ - in: 01-length-one-num.in
12
+ out: 01-length-one-num.ans
13
+ points: 1
14
+ - in: 02-length-one-fizz.in
15
+ out: 02-length-one-fizz.ans
16
+ points: 1
17
+ - in: 03-length-one-buzz.in
18
+ out: 03-length-one-buzz.ans
19
+ points: 1
20
+ - in: 04-length-one-fizzbuzz.in
21
+ out: 04-length-one-fizzbuzz.ans
22
+ points: 1
23
+ - in: 05-random-small.in
24
+ out: 05-random-small.ans
25
+ points: 1
26
+ - in: 06-random-small.in
27
+ out: 06-random-small.ans
28
+ points: 1
29
+ - in: 07-random-small.in
30
+ out: 07-random-small.ans
31
+ points: 1
32
+ - in: 08-random-small.in
33
+ out: 08-random-small.ans
34
+ points: 1
35
+ - in: 09-random-small.in
36
+ out: 09-random-small.ans
37
+ points: 1
38
+ - in: 10-random-small.in
39
+ out: 10-random-small.ans
40
+ points: 1
41
+ - in: 11-random-small.in
42
+ out: 11-random-small.ans
43
+ points: 1
44
+ - in: 12-random-small.in
45
+ out: 12-random-small.ans
46
+ points: 1
47
+ - in: 13-random-small.in
48
+ out: 13-random-small.ans
49
+ points: 1
50
+ - in: 14-random-small.in
51
+ out: 14-random-small.ans
52
+ points: 1
53
+ - in: 15-random-small.in
54
+ out: 15-random-small.ans
55
+ points: 1
56
+ - in: 16-random-small.in
57
+ out: 16-random-small.ans
58
+ points: 1
59
+ - in: 17-random-small.in
60
+ out: 17-random-small.ans
61
+ points: 1
62
+ - in: 18-random-small.in
63
+ out: 18-random-small.ans
64
+ points: 1
65
+ - in: 19-random-small.in
66
+ out: 19-random-small.ans
67
+ points: 1
68
+ - in: 20-random-small.in
69
+ out: 20-random-small.ans
70
+ points: 1
71
+ - in: 21-random-small.in
72
+ out: 21-random-small.ans
73
+ points: 1
74
+ - in: 22-random-small.in
75
+ out: 22-random-small.ans
76
+ points: 1
77
+ - in: 23-random-small.in
78
+ out: 23-random-small.ans
79
+ points: 1
80
+ - in: 24-random-small.in
81
+ out: 24-random-small.ans
82
+ points: 1
83
+ - in: 25-random-small-fuzz.in
84
+ out: 25-random-small-fuzz.ans
85
+ points: 1
86
+ - in: 26-random-small-fuzz.in
87
+ out: 26-random-small-fuzz.ans
88
+ points: 1
89
+ - in: 27-random-max.in
90
+ out: 27-random-max.ans
91
+ points: 1
92
+ - in: 28-random-max.in
93
+ out: 28-random-max.ans
94
+ points: 1
95
+ - in: 29-random-max.in
96
+ out: 29-random-max.ans
97
+ points: 1
98
+ - in: 30-random-max.in
99
+ out: 30-random-max.ans
100
+ points: 1
101
+ - in: 31-random-max.in
102
+ out: 31-random-max.ans
103
+ points: 1
104
+ - in: 32-random.in
105
+ out: 32-random.ans
106
+ points: 1
107
+ - in: 33-random.in
108
+ out: 33-random.ans
109
+ points: 1
110
+ - in: 34-random.in
111
+ out: 34-random.ans
112
+ points: 1
113
+ - in: 35-random.in
114
+ out: 35-random.ans
115
+ points: 1
116
+ - in: 36-random.in
117
+ out: 36-random.ans
118
+ points: 1
119
+ - in: 37-random.in
120
+ out: 37-random.ans
121
+ points: 1
122
+ - in: 38-random.in
123
+ out: 38-random.ans
124
+ points: 1
125
+ - in: 39-random.in
126
+ out: 39-random.ans
127
+ points: 1
128
+ - in: 40-random.in
129
+ out: 40-random.ans
130
+ points: 1
131
+ - in: 41-random.in
132
+ out: 41-random.ans
133
+ points: 1
134
+ - in: 42-just-max.in
135
+ out: 42-just-max.ans
136
+ points: 1
137
+ - in: 43-max-no-fizz-no-buzz.in
138
+ out: 43-max-no-fizz-no-buzz.ans
139
+ points: 1
140
+ - in: 44-one-fizzbuzz.in
141
+ out: 44-one-fizzbuzz.ans
142
+ points: 1
143
+ - in: 45-two-fizzbuzz.in
144
+ out: 45-two-fizzbuzz.ans
145
+ points: 1
146
+ - in: 46-many-fizzbuzz.in
147
+ out: 46-many-fizzbuzz.ans
148
+ points: 1
149
+ - in: 47-no-fizz-no-buzz.in
150
+ out: 47-no-fizz-no-buzz.ans
151
+ points: 1
152
+ - in: 48-no-fizz-one-buzz.in
153
+ out: 48-no-fizz-one-buzz.ans
154
+ points: 1
155
+ - in: 49-no-fizz-two-buzz.in
156
+ out: 49-no-fizz-two-buzz.ans
157
+ points: 1
158
+ - in: 50-no-fizz-many-buzz.in
159
+ out: 50-no-fizz-many-buzz.ans
160
+ points: 1
161
+ - in: 51-no-fizz-all-buzz.in
162
+ out: 51-no-fizz-all-buzz.ans
163
+ points: 1
164
+ - in: 52-one-fizz-no-buzz.in
165
+ out: 52-one-fizz-no-buzz.ans
166
+ points: 1
167
+ - in: 53-one-fizz-one-buzz.in
168
+ out: 53-one-fizz-one-buzz.ans
169
+ points: 1
170
+ - in: 54-one-fizz-two-buzz.in
171
+ out: 54-one-fizz-two-buzz.ans
172
+ points: 1
173
+ - in: 55-one-fizz-many-buzz.in
174
+ out: 55-one-fizz-many-buzz.ans
175
+ points: 1
176
+ - in: 56-one-fizz-all-buzz.in
177
+ out: 56-one-fizz-all-buzz.ans
178
+ points: 1
179
+ - in: 57-two-fizz-no-buzz.in
180
+ out: 57-two-fizz-no-buzz.ans
181
+ points: 1
182
+ - in: 58-two-fizz-one-buzz.in
183
+ out: 58-two-fizz-one-buzz.ans
184
+ points: 1
185
+ - in: 59-two-fizz-two-buzz.in
186
+ out: 59-two-fizz-two-buzz.ans
187
+ points: 1
188
+ - in: 60-two-fizz-many-buzz.in
189
+ out: 60-two-fizz-many-buzz.ans
190
+ points: 1
191
+ - in: 61-two-fizz-all-buzz.in
192
+ out: 61-two-fizz-all-buzz.ans
193
+ points: 1
194
+ - in: 62-many-fizz-no-buzz.in
195
+ out: 62-many-fizz-no-buzz.ans
196
+ points: 1
197
+ - in: 63-many-fizz-one-buzz.in
198
+ out: 63-many-fizz-one-buzz.ans
199
+ points: 1
200
+ - in: 64-many-fizz-two-buzz.in
201
+ out: 64-many-fizz-two-buzz.ans
202
+ points: 1
203
+ - in: 65-many-fizz-many-buzz.in
204
+ out: 65-many-fizz-many-buzz.ans
205
+ points: 1
206
+ - in: 66-many-fizz-all-buzz.in
207
+ out: 66-many-fizz-all-buzz.ans
208
+ points: 1
209
+ - in: 67-all-fizz-no-buzz.in
210
+ out: 67-all-fizz-no-buzz.ans
211
+ points: 1
212
+ - in: 68-all-fizz-one-buzz.in
213
+ out: 68-all-fizz-one-buzz.ans
214
+ points: 1
215
+ - in: 69-all-fizz-two-buzz.in
216
+ out: 69-all-fizz-two-buzz.ans
217
+ points: 1
218
+ - in: 70-all-fizz-many-buzz.in
219
+ out: 70-all-fizz-many-buzz.ans
220
+ points: 1
221
+ - in: 71-all-fizz-all-buzz.in
222
+ out: 71-all-fizz-all-buzz.ans
223
+ points: 1
ICPC/nwerc2022_I/output_validators/output_validator/output_validator.cpp ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #include<cstdlib>
3
+ int qwerty_getcode(int code) {
4
+ return code == 42? 0: 1;
5
+ }
6
+ namespace std {
7
+ void qwerty_exit(int code){
8
+ exit(qwerty_getcode(code));
9
+ }
10
+ } using std::qwerty_exit;
11
+ #define exit qwerty_exit
12
+ #define main qwerty_main
13
+ #include "validation.h"
14
+
15
+ int main(int argc, char **argv) {
16
+ std::ifstream in(argv[1]);
17
+ OutputValidator v(argc, argv);
18
+
19
+ int c, d;
20
+ in >> c >> d;
21
+
22
+ std::vector<std::string> items(d-c+1);
23
+ for (auto &s: items) in >> s;
24
+
25
+ int a = v.read_integer("a", 1, 1'000'000);
26
+ v.space();
27
+ int b = v.read_integer("b", 1, 1'000'000);
28
+ v.newline();
29
+
30
+ for (int i = c; i <= d; i++) {
31
+ std::string str;
32
+ if (i%a == 0) str += "Fizz";
33
+ if (i%b == 0) str += "Buzz";
34
+ if (str.empty()) str += std::to_string(i);
35
+
36
+ v.check(str == items[i-c], "Mismatch at position ", i, ": expected ", items[i-c], ", got ", str);
37
+ }
38
+ }
39
+
40
+ #undef main
41
+ #include<cstdio>
42
+ #include<vector>
43
+ #include<string>
44
+ #include<filesystem>
45
+ int main(int argc, char **argv) {
46
+ namespace fs = std::filesystem;
47
+ freopen(argv[2], "r", stdin);
48
+ char judge_out[] = "/dev";
49
+ std::vector<char*> new_argv = {
50
+ argv[0], argv[1], argv[3],
51
+ judge_out,
52
+ };
53
+ return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data()));
54
+ }
ICPC/nwerc2022_I/output_validators/output_validator/validation.h ADDED
@@ -0,0 +1,1520 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ // A header library to safely parse team input.
3
+ // It does not support floating points or big integers.
4
+ // Author: Ragnar Groot Koerkamp
5
+
6
+ // The easiest way to use this is to symlink it from a validator directory,
7
+ // so that it will be picked up when creating a contest zip.
8
+
9
+ // The default checking behaviour is lenient for both white space and case.
10
+ // When validating .in and .ans files, the case_sensitive and
11
+ // space_change_sensitive flags should be passed. When validating team output,
12
+ // the flags in problem.yaml should be used.
13
+
14
+ // Compile with -Duse_source_location to enable
15
+ // std::experimental::source_location. This is needed for constraints checking.
16
+
17
+ #include <algorithm>
18
+ #include <array>
19
+ #include <bitset>
20
+ #include <cassert>
21
+ #include <charconv>
22
+ #include <cstring>
23
+ #include <fstream>
24
+ #include <functional>
25
+ #include <iomanip>
26
+ #include <iostream>
27
+ #include <limits>
28
+ #include <map>
29
+ #include <optional>
30
+ #include <random>
31
+ #include <set>
32
+ #include <stdexcept>
33
+ #include <string>
34
+ #include <string_view>
35
+ #include <type_traits>
36
+ #include <unordered_map>
37
+ #include <utility>
38
+ #include <variant>
39
+ #include <vector>
40
+
41
+ #ifdef use_source_location
42
+ #include <experimental/source_location>
43
+ constexpr bool has_source_location = true;
44
+ using std::experimental::source_location;
45
+ namespace std {
46
+ bool operator<(const source_location& l, const source_location& r) {
47
+ return l.line() < r.line();
48
+ }
49
+ } // namespace std
50
+ namespace std::experimental::fundamentals_v2 {
51
+ bool operator<(const source_location& l, const source_location& r) {
52
+ return l.line() < r.line();
53
+ }
54
+ } // namespace std::experimental::fundamentals_v2
55
+ #else
56
+ constexpr bool has_source_location = false;
57
+ struct source_location {
58
+ static source_location current() { return {}; }
59
+ [[nodiscard]] int line() const { return 0; } // NOLINT
60
+ [[nodiscard]] std::string file_name() const { return ""; } // NOLINT
61
+ };
62
+ inline bool operator<(const source_location& l, const source_location& r) {
63
+ return l.line() < r.line();
64
+ }
65
+ #endif
66
+
67
+ inline std::string location_to_string(source_location loc) {
68
+ return std::string(loc.file_name()) + ":" + std::to_string(loc.line());
69
+ }
70
+
71
+ const std::string_view case_sensitive_flag = "case_sensitive";
72
+ const std::string_view ws_sensitive_flag = "space_change_sensitive";
73
+ const std::string_view constraints_file_flag = "--constraints_file";
74
+ const std::string_view generate_flag = "--generate";
75
+ const std::string_view generate_binary_substring = "generat";
76
+
77
+ inline struct ArbitraryTag {
78
+ static constexpr bool unique = false;
79
+ static constexpr bool strict = false;
80
+ static constexpr bool increasing = false;
81
+ static constexpr bool decreasing = false;
82
+ } Arbitrary;
83
+ inline struct UniqueTag : ArbitraryTag {
84
+ static constexpr bool unique = true;
85
+ static constexpr bool strict = false;
86
+ static constexpr bool increasing = false;
87
+ static constexpr bool decreasing = false;
88
+ } Unique;
89
+ inline struct IncreasingTag : ArbitraryTag { static constexpr bool increasing = true; } Increasing;
90
+ inline struct DecreasingTag : ArbitraryTag { static constexpr bool decreasing = true; } Decreasing;
91
+ inline struct StrictlyIncreasingTag : ArbitraryTag {
92
+ static constexpr bool strict = true;
93
+ static constexpr bool increasing = true;
94
+ } StrictlyIncreasing;
95
+ inline struct StrictlyDecreasingTag : ArbitraryTag {
96
+ static constexpr bool strict = true;
97
+ static constexpr bool decreasing = true;
98
+ } StrictlyDecreasing;
99
+
100
+ template <typename... T>
101
+ struct Merge : T... {
102
+ static constexpr bool unique = (T::unique || ...);
103
+ static constexpr bool strict = (T::strict || ...);
104
+ static constexpr bool increasing = (T::increasing || ...);
105
+ static constexpr bool decreasing = (T::decreasing || ...);
106
+ };
107
+
108
+ template <typename T1, typename T2,
109
+ std::enable_if_t<
110
+ std::is_base_of_v<ArbitraryTag, T1> and std::is_base_of_v<ArbitraryTag, T2>, int> = 0>
111
+ auto operator|(T1 /*unused*/, T2 /*unused*/) {
112
+ return Merge<T1, T2>();
113
+ }
114
+
115
+ enum Separator { Space, Newline };
116
+
117
+ // this contains some specific code which emulates c++20 features
118
+ namespace cpp20 {
119
+
120
+ constexpr int countl_zero(unsigned long long x) {
121
+ int res = 64;
122
+ for(int i = 32; i > 0; i >>= 1) {
123
+ if((x >> i) > 0) {
124
+ res -= i;
125
+ x >>= i;
126
+ }
127
+ }
128
+ if(x > 0) res--;
129
+ return res;
130
+ }
131
+
132
+ int popcount(unsigned long long x) {
133
+ return static_cast<int>(std::bitset<64>(x).count());
134
+ }
135
+
136
+ constexpr long double PI = 3.141592653589793238462643383279502884l;
137
+
138
+ } // namespace cpp20
139
+
140
+ namespace Random {
141
+
142
+ constexpr unsigned int default_seed = 3141592653; // some digits of PI
143
+
144
+ unsigned long long bits64(std::mt19937_64& rng) {
145
+ static_assert(std::mt19937_64::max() == 0xFFFF'FFFF'FFFF'FFFFull);
146
+ static_assert(std::mt19937_64::min() == 0ull);
147
+ return rng();
148
+ }
149
+
150
+ // generates a uniform real in [0, 1)
151
+ long double real64(std::mt19937_64& rng) {
152
+ // a long double can represent more than 2^64 values in the range [0, 1)...
153
+ // another problem is that real64() < 1.0/3.0 is technically biased.
154
+ long double res = bits64(rng) / 0x1.0p64l;
155
+ res += bits64(rng) / 0x1.0p128l;
156
+ assert(res < 1.0l);
157
+ return res;
158
+ }
159
+
160
+ bool bit(std::mt19937_64& rng) {
161
+ return cpp20::popcount(bits64(rng)) & 1;
162
+ }
163
+
164
+ } // namespace Random
165
+
166
+ template <typename T>
167
+ constexpr bool is_number_v = std::is_same_v<T, long long> or std::is_same_v<T, long double>;
168
+
169
+ namespace Generators {
170
+
171
+ template <typename T>
172
+ struct ConstGenerator {
173
+ static_assert(is_number_v<T> or std::is_same_v<T, char> or std::is_same_v<T, std::string>);
174
+ static constexpr std::string_view name = "const";
175
+ using Args = std::tuple<T>;
176
+
177
+ const T const_;
178
+
179
+ explicit ConstGenerator(T val) : const_(std::move(val)) {}
180
+
181
+ // For char and string, the constant store has a different type than the min and max length
182
+ // passed in.
183
+ template <typename U>
184
+ T operator()(U low, U high, std::mt19937_64& rng) const {
185
+ return std::clamp(const_, low, high);
186
+ }
187
+ };
188
+
189
+ struct MinGenerator {
190
+ static constexpr std::string_view name = "min";
191
+ using Args = std::tuple<>;
192
+
193
+ explicit MinGenerator() = default;
194
+
195
+ template <typename T>
196
+ T operator()(T low, T high, std::mt19937_64& rng) const {
197
+ static_assert(is_number_v<T>);
198
+ return low;
199
+ }
200
+ };
201
+
202
+ struct MaxGenerator {
203
+ static constexpr std::string_view name = "max";
204
+ using Args = std::tuple<>;
205
+
206
+ explicit MaxGenerator() = default;
207
+
208
+ template <typename T>
209
+ T operator()(T low, T high, std::mt19937_64& rng) const {
210
+ static_assert(is_number_v<T>);
211
+ return high;
212
+ }
213
+ };
214
+
215
+ struct UniformGenerator {
216
+ static constexpr std::string_view name = "uniform";
217
+ using Args = std::tuple<>;
218
+
219
+ explicit UniformGenerator() = default;
220
+
221
+ template <typename T>
222
+ T operator()(T low, T high, std::mt19937_64& rng) const {
223
+ static_assert(is_number_v<T>);
224
+ if(low == high) return low;
225
+
226
+ if constexpr(std::is_same_v<T, long long>) {
227
+ assert(low < high);
228
+ // Since C++20 we can assume Two's Complement but any sane system used it before anyway.
229
+ // Rejection sampling is not as fast as possible but definitely unbiased.
230
+ auto ul = static_cast<unsigned long long>(low);
231
+ auto uh = static_cast<unsigned long long>(high);
232
+ int shifts = cpp20::countl_zero(uh - ul);
233
+ unsigned long long res;
234
+ do {
235
+ res = Random::bits64(rng) >> shifts;
236
+ } while(res > uh - ul);
237
+ return static_cast<long long>(res + ul);
238
+ } else {
239
+ assert(low < high);
240
+ return low + Random::real64(rng) * (high - low);
241
+ }
242
+ }
243
+ };
244
+
245
+ template <typename T>
246
+ struct RangeGenerator {
247
+ static_assert(is_number_v<T>);
248
+ static constexpr std::string_view name = "range";
249
+ using Args = std::tuple<T, T>;
250
+
251
+ const T low_, high_;
252
+
253
+ explicit RangeGenerator(T low, T high) : low_(low), high_(high) {}
254
+
255
+ T operator()(T low, T high, std::mt19937_64& rng) const {
256
+ return UniformGenerator()(std::max(low, low_), std::min(high, high_), rng);
257
+ }
258
+ };
259
+
260
+ template <typename T>
261
+ struct StepRangeGenerator {
262
+ static_assert(is_number_v<T>);
263
+ static constexpr std::string_view name = "steprange";
264
+ using Args = std::tuple<T, T, T>;
265
+
266
+ const T low_, high_, step_;
267
+
268
+ explicit StepRangeGenerator(T low, T high, T step) : low_(low), high_(high), step_(step) {}
269
+
270
+ T operator()(T low, T high, std::mt19937_64& rng) const {
271
+ // round up low to the first multiple of step_.
272
+ T start;
273
+ if(low <= low_) {
274
+ start = low_;
275
+ } else {
276
+ // first multiple of low_+k*step_ >= low
277
+ start = low_ + (long long)((low - low_) / step_) * step_;
278
+ if(start < low) start += step_;
279
+ assert(low <= start && start < low + step_);
280
+ }
281
+ long long maxsteps = (std::min(high, high_) - start) / step_;
282
+ long long steps = UniformGenerator()(0ll, maxsteps, rng);
283
+ return start + steps * step_;
284
+ }
285
+ };
286
+
287
+ struct NormalDistributionGenerator {
288
+ static constexpr std::string_view name = "normal";
289
+ using T = long double;
290
+ using Args = std::tuple<T, T>;
291
+
292
+ const T mean_, stddev_;
293
+
294
+ explicit NormalDistributionGenerator(T mean, T stddev) : mean_(mean), stddev_(stddev) {
295
+ assert(stddev_ >= 0);
296
+ }
297
+
298
+ // NOTE: Currently this retries instead of clamping to the interval.
299
+ T operator()(T low, T high, std::mt19937_64& rng) const {
300
+ assert(low < high);
301
+ T v;
302
+ while(true) {
303
+ T u1 = Random::real64(rng);
304
+ T u2 = Random::real64(rng);
305
+ // Box-Muller-Methode
306
+ // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
307
+ v = std::sqrt(-2.0l * std::log(u1)) * std::cos(2.0l * cpp20::PI * u2);
308
+ v = std::sqrt(stddev_) * v + mean_;
309
+ if(v >= low && v < high) return v;
310
+ v = std::sqrt(-2.0l * std::log(u1)) * std::sin(2.0l * cpp20::PI * u2);
311
+ v = std::sqrt(stddev_) * v + mean_;
312
+ if(v >= low && v < high) return v;
313
+ }
314
+ return v;
315
+ }
316
+ };
317
+
318
+ struct ExponentialDistributionGenerator {
319
+ static constexpr std::string_view name = "exponential";
320
+ using T = long double;
321
+ using Args = std::tuple<T>;
322
+
323
+ T lambda_;
324
+
325
+ explicit ExponentialDistributionGenerator(T lambda) : lambda_(lambda) { assert(lambda_ > 0); }
326
+
327
+ // NOTE: Currently this retries instead of clamping to the interval.
328
+ T operator()(T low, T high, std::mt19937_64& rng) const {
329
+ assert(low < high);
330
+ T v;
331
+ while(true) {
332
+ v = low - std::log(Random::real64(rng)) / lambda_;
333
+ if(v < high) return v;
334
+ }
335
+ }
336
+ };
337
+
338
+ struct GeometricDistributionGenerator {
339
+ static constexpr std::string_view name = "geometric";
340
+ using T = long long;
341
+ using Args = std::tuple<long double>;
342
+
343
+ double p_;
344
+
345
+ explicit GeometricDistributionGenerator(double p) : p_(p) {
346
+ assert(p_ > 0);
347
+ assert(p_ < 1);
348
+ }
349
+
350
+ // NOTE: Currently this retries instead of clamping to the interval.
351
+ T operator()(T low, T high, std::mt19937_64& rng) const {
352
+ assert(low <= high);
353
+ T v;
354
+ while(true) {
355
+ // https://en.wikipedia.org/wiki/Geometric_distribution
356
+ // "The exponential distribution is the continuous analogue of the geometric
357
+ // distribution[...]"
358
+ v = low + std::floor(std::log(Random::real64(rng)) / std::log1p(-p_));
359
+ if(v <= high) return v;
360
+ }
361
+ }
362
+ };
363
+
364
+ struct BinomialDistributionGenerator {
365
+ static constexpr std::string_view name = "binomial";
366
+ using T = long long;
367
+ using Args = std::tuple<long long, long double>;
368
+
369
+ long long n_;
370
+ double p_;
371
+
372
+ explicit BinomialDistributionGenerator(long long n, double p) : n_(n), p_(p) {
373
+ assert(p_ >= 0);
374
+ assert(p_ <= 1);
375
+ std::cerr << "Warning: Large n (" << n_ << ") is slow for BinomialDistributionGenerator!"
376
+ << std::endl;
377
+ }
378
+
379
+ // NOTE: Currently this retries instead of clamping to the interval.
380
+ T operator()(T low, T high, std::mt19937_64& rng) const {
381
+ assert(low <= high);
382
+ // this will be slow for large n
383
+ // (a faster implementation requires efficient poisson sampling)
384
+ while(true) {
385
+ T v = 0;
386
+ for(long long i = 0; i < n_; i++) {
387
+ v += Random::real64(rng) < p_ ? 1 : 0;
388
+ }
389
+ if(v >= low && v <= high) return v;
390
+ }
391
+ }
392
+ };
393
+
394
+ template <typename T>
395
+ struct ChoiceGenerator {
396
+ using GeneratorType = std::conditional_t<
397
+ std::is_same_v<T, long long>,
398
+ std::variant<ConstGenerator<T>, MinGenerator, MaxGenerator, UniformGenerator,
399
+ RangeGenerator<T>, StepRangeGenerator<T>, GeometricDistributionGenerator,
400
+ BinomialDistributionGenerator>,
401
+ std::variant<ConstGenerator<T>, MinGenerator, MaxGenerator, UniformGenerator,
402
+ RangeGenerator<T>, StepRangeGenerator<T>, NormalDistributionGenerator,
403
+ ExponentialDistributionGenerator>>;
404
+
405
+ std::vector<std::pair<GeneratorType, double>> generators_;
406
+ double total_weight_;
407
+
408
+ template <typename>
409
+ struct Pack {};
410
+
411
+ template <typename A>
412
+ static A parse_number(std::string_view s) {
413
+ static_assert(is_number_v<A>);
414
+ if constexpr(std::is_same_v<A, long long>)
415
+ return stoll(std::string(s));
416
+ else
417
+ return stold(std::string(s));
418
+ }
419
+
420
+ template <typename A>
421
+ static A parse_argument(std::string_view& s) {
422
+ auto end = s.find_first_of(",)");
423
+ assert(end != std::string_view::npos);
424
+ auto v = parse_number<A>(s.substr(0, end));
425
+ s.remove_prefix(end);
426
+ // Pop the trailing , or )
427
+ s.remove_prefix(1);
428
+ return v;
429
+ }
430
+
431
+ template <typename... As>
432
+ static std::tuple<As...> parse_arguments(std::string_view& s,
433
+ Pack<std::tuple<As...>> /*unused*/) {
434
+ std::tuple<As...> args{parse_argument<As>(s)...};
435
+ return args;
436
+ }
437
+
438
+ // Try parsing one generator type from the start of s.
439
+ template <typename G>
440
+ static void parse_generator(std::string_view& s, std::optional<GeneratorType>& out) {
441
+ if(out) return;
442
+ if(s.substr(0, G::name.size()) != G::name) return;
443
+
444
+ // Drop the name.
445
+ s.remove_prefix(G::name.size());
446
+ if constexpr(std::tuple_size_v<typename G::Args> == 0) {
447
+ out.emplace(std::in_place_type_t<G>{});
448
+ return;
449
+ }
450
+
451
+ // Drop the (
452
+ assert(not s.empty() and s.front() == '(');
453
+ s.remove_prefix(1);
454
+
455
+ auto args = parse_arguments(s, Pack<typename G::Args>{});
456
+ // Construct the resulting generator in-place in the variant..
457
+ std::apply([&](const auto&... _args) { out.emplace(std::in_place_type_t<G>{}, _args...); },
458
+ args);
459
+ }
460
+
461
+ template <typename... Gs>
462
+ static std::optional<GeneratorType> parse_generators(std::string_view& s,
463
+ Pack<std::variant<Gs...>> /*unused*/) {
464
+ std::optional<GeneratorType> out;
465
+ (parse_generator<Gs>(s, out), ...);
466
+ return out;
467
+ }
468
+
469
+ explicit ChoiceGenerator(std::string_view s) : total_weight_(0) {
470
+ // PARSE
471
+ while(not s.empty()) {
472
+ auto generator = parse_generators(s, Pack<GeneratorType>{});
473
+ if(!generator) {
474
+ // Check for range syntax:
475
+ auto comma = s.find_first_of(",:");
476
+ if(comma == std::string::npos) comma = s.size();
477
+ auto dots = s.find("..");
478
+ if(dots != std::string_view::npos and dots < comma) {
479
+ auto start = s.substr(0, dots);
480
+ auto end = s.substr(dots + 2, comma - dots - 2);
481
+
482
+ generator.emplace(std::in_place_type_t<RangeGenerator<T>>{},
483
+ parse_number<T>(start), parse_number<T>(end));
484
+ s.remove_prefix(comma);
485
+ }
486
+
487
+ // Fall back to constant.
488
+ if(!generator) {
489
+ generator.emplace(std::in_place_type_t<ConstGenerator<T>>{},
490
+ parse_number<T>(s.substr(0, comma)));
491
+ s.remove_prefix(comma);
492
+ }
493
+ }
494
+
495
+ // Parse weight if given.
496
+ double weight = 1;
497
+ if(not s.empty() and s.front() == ':') {
498
+ s.remove_prefix(1);
499
+ auto comma = s.find(',');
500
+ if(comma == std::string_view::npos) comma = s.size();
501
+ weight = parse_number<long double>(s.substr(0, comma));
502
+ s.remove_prefix(comma);
503
+ }
504
+
505
+ // should now be at , or end
506
+ assert(s.empty() or s.front() == ',');
507
+ if(not s.empty()) s.remove_prefix(1);
508
+ generators_.emplace_back(std::move(*generator), weight);
509
+ total_weight_ += weight;
510
+ }
511
+ }
512
+
513
+ T operator()(T low, T high, std::mt19937_64& rng) const {
514
+ Generators::UniformGenerator uniform;
515
+ double x = uniform.operator()<long double>(0, total_weight_, rng);
516
+ for(size_t i = 0; i < generators_.size(); ++i) {
517
+ x -= generators_[i].second;
518
+ if(x <= 0)
519
+ return std::visit([&](auto& g) { return g(low, high, rng); }, generators_[i].first);
520
+ }
521
+ assert(false);
522
+ }
523
+ };
524
+
525
+ struct ParamGenerator {
526
+ std::variant<std::string_view, ChoiceGenerator<long long>, ChoiceGenerator<long double>>
527
+ generator;
528
+ explicit ParamGenerator(std::string_view s) : generator(s) {}
529
+
530
+ template <typename T>
531
+ T operator()(T low, T high, std::mt19937_64& rng) {
532
+ static_assert(is_number_v<T>);
533
+ if(std::holds_alternative<std::string_view>(generator)) {
534
+ generator = ChoiceGenerator<T>(std::get<std::string_view>(generator));
535
+ }
536
+ return std::get<ChoiceGenerator<T>>(generator)(low, high, rng);
537
+ }
538
+ };
539
+
540
+ } // namespace Generators
541
+
542
+ using Generators::ParamGenerator;
543
+
544
+ namespace Random {
545
+ template <class RandomIt>
546
+ void shuffle(RandomIt first, RandomIt last, std::mt19937_64& rng) {
547
+ Generators::UniformGenerator uniform;
548
+ long long n = last - first;
549
+ for(long long i = n - 1; i > 0; i--) {
550
+ std::swap(first[i], first[uniform(0ll, i, rng)]);
551
+ }
552
+ }
553
+
554
+ template <class T>
555
+ void shuffle(std::pair<T, T>& in, std::mt19937_64& rng) {
556
+ if(bit(rng)) std::swap(in.first, in.second);
557
+ }
558
+
559
+ template <class RandomIt>
560
+ auto& select(RandomIt first, RandomIt last, std::mt19937_64& rng) {
561
+ assert(first != last);
562
+ Generators::UniformGenerator uniform;
563
+ long long n = last - first;
564
+ return first[uniform(0ll, n - 1, rng)];
565
+ }
566
+
567
+ template <class T>
568
+ const T& select(const std::pair<T, T>& in, std::mt19937_64& rng) {
569
+ return bit(rng) ? in.first : in.second;
570
+ }
571
+
572
+ template <class T>
573
+ T& select(std::pair<T, T>& in, std::mt19937_64& rng) {
574
+ return bit(rng) ? in.first : in.second;
575
+ }
576
+
577
+ } // namespace Random
578
+
579
+ class Validator {
580
+ protected:
581
+ Validator(bool ws_, bool case_, std::istream& in_, std::string constraints_file_path_ = "",
582
+ std::optional<unsigned int> seed = std::nullopt,
583
+ std::unordered_map<std::string, ParamGenerator> params_ = {})
584
+ : in(in_), ws(ws_), case_sensitive(case_),
585
+ constraints_file_path(std::move(constraints_file_path_)), gen(seed.has_value()),
586
+ rng(seed.value_or(Random::default_seed)), params(std::move(params_)) {
587
+
588
+ std::ios_base::sync_with_stdio(false);
589
+ in.tie(nullptr);
590
+
591
+ if(gen) return;
592
+ if(ws)
593
+ in >> std::noskipws;
594
+ else
595
+ in >> std::skipws;
596
+
597
+ if(!constraints_file_path.empty()) {
598
+ assert(has_source_location); // NOLINT
599
+ }
600
+ }
601
+
602
+ public:
603
+ // No copying, no moving.
604
+ Validator(const Validator&) = delete;
605
+ Validator(Validator&&) = delete;
606
+ void operator=(const Validator&) = delete;
607
+ void operator=(Validator&&) = delete;
608
+
609
+ // At the end of the scope, check whether the EOF has been reached.
610
+ // If so, return AC. Otherwise, return WA.
611
+ ~Validator() {
612
+ eof();
613
+ write_constraints();
614
+ AC();
615
+ }
616
+
617
+ void space() {
618
+ if(gen) {
619
+ out << ' ';
620
+ return;
621
+ }
622
+
623
+ if(ws) {
624
+ char c;
625
+ in >> c;
626
+ check(!in.eof(), "Expected space, found EOF.");
627
+ if(c != ' ')
628
+ expected("space", std::string("\"") +
629
+ ((c == '\n' or c == '\r') ? std::string("newline")
630
+ : std::string(1, c)) +
631
+ "\"");
632
+ }
633
+ }
634
+
635
+ void newline() {
636
+ if(gen) {
637
+ out << '\n';
638
+ return;
639
+ }
640
+
641
+ if(ws) {
642
+ char c;
643
+ in >> c;
644
+ check(!in.eof(), "Expected newline, found EOF.");
645
+ if(c != '\n') {
646
+ if(c == '\r')
647
+ expected("newline", "DOS line ending (\\r)");
648
+ else
649
+ expected("newline", std::string("\"") + c + "\"");
650
+ }
651
+ }
652
+ }
653
+
654
+ private:
655
+ void separator(Separator s) {
656
+ switch(s) {
657
+ case Separator::Space: space(); break;
658
+ case Separator::Newline: newline(); break;
659
+ }
660
+ }
661
+
662
+ template <typename T>
663
+ auto& seen() {
664
+ static std::map<source_location, std::set<T>> seen;
665
+ return seen;
666
+ }
667
+ template <typename T>
668
+ auto& last_seen() {
669
+ static std::map<source_location, T> last_seen;
670
+ return last_seen;
671
+ }
672
+ template <typename T>
673
+ auto& integers_seen() {
674
+ static std::map<source_location, std::tuple<std::set<T>, std::vector<T>, bool>>
675
+ integers_seen;
676
+ return integers_seen;
677
+ }
678
+ template <typename T>
679
+ void reset(source_location loc) {
680
+ seen<T>().erase(loc);
681
+ last_seen<T>().erase(loc);
682
+ integers_seen<T>().erase(loc);
683
+ }
684
+
685
+ template <typename T, typename Tag>
686
+ void check_number(const std::string& name, T low, T high, T v, Tag /*unused*/,
687
+ source_location loc) {
688
+ static_assert(is_number_v<T>);
689
+ if(v < low or v > high) {
690
+ std::string type_name;
691
+ if constexpr(std::is_integral_v<T>) {
692
+ type_name = "integer";
693
+ }
694
+ if constexpr(std::is_floating_point_v<T>) {
695
+ type_name = "float";
696
+ }
697
+ expected(name + ": " + type_name + " between " + std::to_string(low) + " and " +
698
+ std::to_string(high),
699
+ std::to_string(v));
700
+ }
701
+ log_constraint(name, low, high, v, loc);
702
+ if constexpr(Tag::unique) {
703
+ auto [it, inserted] = seen<T>()[loc].emplace(v);
704
+ check(inserted, name, ": Value ", v, " seen twice, but must be unique!");
705
+ } else {
706
+ auto [it, inserted] = last_seen<T>().emplace(loc, v);
707
+ if(inserted) return;
708
+
709
+ auto last = it->second;
710
+ it->second = v;
711
+
712
+ if constexpr(Tag::increasing)
713
+ check(v >= last, name, " is not increasing: value ", v, " follows ", last);
714
+ if constexpr(Tag::decreasing)
715
+ check(v <= last, name, " is not decreasing: value ", v, " follows ", last);
716
+ if constexpr(Tag::strict)
717
+ check(v != last, name, " is not strict: value ", v, " equals ", last);
718
+ }
719
+ }
720
+
721
+ template <typename Tag>
722
+ void check_string(const std::string& name, int low, int high, const std::string& v,
723
+ Tag /*unused*/, source_location loc) {
724
+ using T = std::string;
725
+ if((int) v.size() < low or (int) v.size() > high) {
726
+ expected(name + ": " + "string with" + " length between " + std::to_string(low) +
727
+ " and " + std::to_string(high),
728
+ v);
729
+ }
730
+ log_constraint(name, low, high, static_cast<int>(v.size()), loc);
731
+ if constexpr(Tag::unique) {
732
+ // static map<source_location, set<T>> seen;
733
+ auto [it, inserted] = seen<T>()[loc].emplace(v);
734
+ check(inserted, name, ": Value ", v, " seen twice, but must be unique!");
735
+ } else if(Tag::increasing or Tag::decreasing) {
736
+ // static map<source_location, T> last_seen;
737
+ auto [it, inserted] = last_seen<T>().emplace(loc, v);
738
+ if(inserted) return;
739
+
740
+ auto last = it->second;
741
+ it->second = v;
742
+
743
+ if constexpr(Tag::increasing)
744
+ check(v >= last, name, " is not increasing: value ", v, " follows ", last);
745
+ if constexpr(Tag::decreasing)
746
+ check(v <= last, name, " is not decreasing: value ", v, " follows ", last);
747
+ if constexpr(Tag::strict)
748
+ check(v != last, name, " is not strict: value ", v, " equals ", last);
749
+ }
750
+ }
751
+
752
+ // Generate a random integer in [low, high] or float in [low, high).
753
+ template <typename T>
754
+ T uniform_number(T low, T high) {
755
+ assert(low <= high);
756
+ Generators::UniformGenerator uniform;
757
+ if constexpr(std::is_integral<T>::value)
758
+ return uniform.operator()<long long>(low, high, rng);
759
+ else
760
+ return uniform.operator()<long double>(low, high, rng);
761
+ }
762
+
763
+ template <typename T, typename Tag>
764
+ T gen_number(const std::string& name, T low, T high, Tag /*unused*/, source_location loc) {
765
+ static_assert(is_number_v<T>);
766
+ T v;
767
+
768
+ if constexpr(Tag::unique) {
769
+ assert(params.find(name) == params.end() &&
770
+ "Parameters are not supported for unique values.");
771
+ if constexpr(std::is_integral<T>::value) {
772
+ auto& [seen_here, remaining_here, use_remaining] = integers_seen<T>()[loc];
773
+
774
+ if(use_remaining) {
775
+ check(!remaining_here.empty(), name, ": no unique values left");
776
+ v = remaining_here.back();
777
+ remaining_here.pop_back();
778
+ } else {
779
+ do {
780
+ v = uniform_number(low, high);
781
+ } while(!seen_here.insert(v).second);
782
+
783
+ struct CountIterator {
784
+ T v;
785
+ T& operator*() { return v; }
786
+ T& operator++() { return ++v; }
787
+ T operator++(int) { return v++; }
788
+ bool operator!=(CountIterator r) { return v != r.v; }
789
+ };
790
+
791
+ if(seen_here.size() > (high - low) / 2) {
792
+ use_remaining = true;
793
+ set_difference(CountIterator{low}, CountIterator{high + 1},
794
+ seen_here.begin(), seen_here.end(),
795
+ std::back_inserter(remaining_here));
796
+ }
797
+ }
798
+ } else {
799
+ // For floats, just regenerate numbers until success.
800
+ auto& seen_here = seen<T>()[loc];
801
+ do {
802
+ v = uniform_number(low, high);
803
+ } while(!seen_here.insert(v).second);
804
+ }
805
+
806
+ } else {
807
+ assert(not Tag::increasing && "Generating increasing sequences is not yet supported!");
808
+ assert(not Tag::decreasing && "Generating decreasing sequences is not yet supported!");
809
+ assert((std::is_same<Tag, ArbitraryTag>::value) &&
810
+ "Only Unique and Arbitrary are supported!");
811
+
812
+ if(params.find(name) != params.end()) {
813
+ v = params.at(name).operator()<T>(low, high, rng);
814
+ // This will be checked during input validation of the generated case.
815
+ // assert(low <= v and v <= high);
816
+ } else {
817
+ v = uniform_number<T>(low, high);
818
+ }
819
+ }
820
+
821
+ return v;
822
+ }
823
+
824
+ std::string gen_string(const std::string& name, long long low, long long high,
825
+ std::string_view chars) {
826
+ assert(!chars.empty());
827
+
828
+ int len;
829
+ if(params.find(name + ".length") != params.end())
830
+ len = params.at(name + ".length").operator()<long long>(low, high, rng);
831
+ else
832
+ len = uniform_number(low, high);
833
+ std::string s(len, ' ');
834
+ for(auto& x : s) x = chars[uniform_number<int>(0, chars.size() - 1)];
835
+
836
+ out << s;
837
+ return s;
838
+ }
839
+
840
+ public:
841
+ template <typename Tag = ArbitraryTag>
842
+ long long gen_integer(const std::string& name, long long low, long long high, Tag tag = Tag{},
843
+ source_location loc = source_location::current()) {
844
+ return gen_number(name, low, high, tag, loc);
845
+ }
846
+
847
+ template <typename Tag = ArbitraryTag>
848
+ long double gen_float(const std::string& name, long double low, long double high,
849
+ Tag tag = Tag{}, source_location loc = source_location::current()) {
850
+ return gen_number(name, low, high, tag, loc);
851
+ }
852
+
853
+ private:
854
+ template <typename T, typename Tag>
855
+ std::vector<T> gen_numbers(const std::string& name, int count, T low, T high, Tag /*unused*/,
856
+ source_location loc) {
857
+ static_assert(is_number_v<T>);
858
+ std::vector<T> v;
859
+ v.reserve(count);
860
+ if constexpr(std::is_same_v<Tag, ArbitraryTag>) {
861
+ if(params.find(name) != params.end()) {
862
+ auto& generator = params.at(name);
863
+ for(int i = 0; i < count; ++i) {
864
+ auto val = generator.operator()<T>(low, high, rng);
865
+ assert(low <= val and val <= high);
866
+ v.push_back(val);
867
+ }
868
+ } else {
869
+ for(int i = 0; i < count; ++i) {
870
+ v.push_back(uniform_number<T>(low, high));
871
+ }
872
+ }
873
+ } else if constexpr(Tag::unique) {
874
+ assert(params.find(name) == params.end() &&
875
+ "Parameters are not supported for unique values.");
876
+ std::set<T> seen_here;
877
+ if constexpr(std::is_integral_v<T>) {
878
+ if(2 * count < high - low) {
879
+ for(int i = 0; i < count; ++i) {
880
+ // If density < 1/2: retry.
881
+ T w;
882
+ do {
883
+ w = uniform_number(low, high);
884
+ } while(!seen_here.insert(w).second);
885
+ v.push_back(w);
886
+ }
887
+ } else {
888
+ // If density >= 1/2, crop a random permutation.
889
+ v.resize(high - low + 1);
890
+ iota(begin(v), end(v), low);
891
+ Random::shuffle(begin(v), end(v), rng);
892
+ v.resize(count);
893
+ }
894
+ } else {
895
+ for(int i = 0; i < count; ++i) {
896
+ // For floats, just regenerate numbers until success.
897
+ T w;
898
+ do {
899
+ w = uniform_number(low, high);
900
+ } while(!seen_here.insert(w).second);
901
+ v.push_back(w);
902
+ }
903
+ }
904
+ } else {
905
+ static_assert(Tag::increasing or Tag::decreasing);
906
+
907
+ constexpr bool integral_strict = Tag::strict and std::is_integral<T>::value;
908
+ if(integral_strict) {
909
+ assert(params.find(name) == params.end() &&
910
+ "Parameters are not supported for strict integer values.");
911
+ high = high - count + 1;
912
+ }
913
+
914
+ if(params.find(name) != params.end()) {
915
+ auto& generator = params.at(name);
916
+ for(int i = 0; i < count; ++i) {
917
+ auto val = generator.operator()<T>(low, high, rng);
918
+ assert(low <= val and val <= high);
919
+ v.push_back(val);
920
+ }
921
+ } else {
922
+ for(int i = 0; i < count; ++i) {
923
+ v.push_back(uniform_number<T>(low, high));
924
+ }
925
+ }
926
+
927
+ sort(begin(v), end(v));
928
+
929
+ if(integral_strict) {
930
+ for(int i = 0; i < count; ++i) v[i] += i;
931
+ }
932
+
933
+ if(Tag::decreasing) reverse(begin(v), end(v));
934
+ }
935
+
936
+ return v;
937
+ }
938
+
939
+ public:
940
+ template <typename Tag = ArbitraryTag>
941
+ std::vector<long long> gen_integers(const std::string& name, int count, long long low,
942
+ long long high, Tag tag = Tag{},
943
+ source_location loc = source_location::current()) {
944
+ return gen_numbers(name, count, low, high, tag, loc);
945
+ }
946
+
947
+ template <typename Tag = ArbitraryTag>
948
+ std::vector<long double> gen_floats(const std::string& name, int count, long double low,
949
+ long double high, Tag tag = Tag{},
950
+ source_location loc = source_location::current()) {
951
+ return gen_numbers(name, count, low, high, tag, loc);
952
+ }
953
+
954
+ private:
955
+ template <typename T, typename Tag>
956
+ T read_number(const std::string& name, T low, T high, Tag tag, source_location loc) {
957
+ if(gen) {
958
+ auto v = gen_number(name, low, high, tag, loc);
959
+ out << std::setprecision(10) << std::fixed << v;
960
+ return v;
961
+ }
962
+
963
+ const auto v = [&] {
964
+ if constexpr(std::is_integral<T>::value)
965
+ return read_integer(name);
966
+ else
967
+ return read_float(name);
968
+ }();
969
+
970
+ check_number(name, low, high, v, tag, loc);
971
+ return v;
972
+ }
973
+
974
+ // Read a vector of numbers, separated by spaces and ended by a newline.
975
+ template <typename T, typename Tag>
976
+ std::vector<T> read_numbers(const std::string& name, int count, T low, T high, Tag tag,
977
+ Separator sep, source_location loc) {
978
+ if(gen) {
979
+ auto v = gen_numbers(name, count, low, high, tag, loc);
980
+
981
+ out << std::setprecision(10) << std::fixed;
982
+ for(int i = 0; i < count; ++i) {
983
+ out << v[i];
984
+ if(i < count - 1) separator(sep);
985
+ }
986
+ newline();
987
+
988
+ return v;
989
+ }
990
+ reset<T>(loc);
991
+ std::vector<T> v(count);
992
+ for(int i = 0; i < count; ++i) {
993
+ if constexpr(std::is_integral<T>::value)
994
+ v[i] = read_integer(name);
995
+ else
996
+ v[i] = read_float(name);
997
+ check_number(name, low, high, v[i], tag, loc);
998
+ if(i < count - 1) separator(sep);
999
+ }
1000
+ newline();
1001
+ return v;
1002
+ }
1003
+
1004
+ public:
1005
+ template <typename Tag = ArbitraryTag>
1006
+ long long read_integer(const std::string& name, long long low, long long high, Tag tag = Tag{},
1007
+ source_location loc = source_location::current()) {
1008
+ return read_number(name, low, high, tag, loc);
1009
+ }
1010
+ template <typename Tag = ArbitraryTag>
1011
+ std::vector<long long> read_integers(const std::string& name, int count, long long low,
1012
+ long long high, Tag tag = Tag{}, Separator sep = Space,
1013
+ source_location loc = source_location::current()) {
1014
+ return read_numbers(name, count, low, high, tag, sep, loc);
1015
+ }
1016
+
1017
+ template <typename Tag = ArbitraryTag>
1018
+ long double read_float(const std::string& name, long double low, long double high,
1019
+ Tag tag = Tag{}, source_location loc = source_location::current()) {
1020
+ return read_number(name, low, high, tag, loc);
1021
+ }
1022
+ template <typename Tag = ArbitraryTag>
1023
+ std::vector<long double> read_floats(const std::string& name, int count, long double low,
1024
+ long double high, Tag tag = Tag{}, Separator sep = Space,
1025
+ source_location loc = source_location::current()) {
1026
+ return read_numbers(name, count, low, high, tag, sep, loc);
1027
+ }
1028
+
1029
+ // Read a vector of strings, separated by spaces and ended by a newline.
1030
+ template <typename Tag = ArbitraryTag>
1031
+ std::vector<std::string> read_strings(const std::string& name, int count, int min, int max,
1032
+ const std::string_view chars = "", Tag tag = Tag(),
1033
+ Separator sep = Space,
1034
+ source_location loc = source_location::current()) {
1035
+ reset<std::string>(loc);
1036
+ if(gen) return gen_strings(name, count, min, max, chars, tag, sep, loc);
1037
+ assert(!gen);
1038
+ std::vector<std::string> v(count);
1039
+ for(int i = 0; i < count; ++i) {
1040
+ v[i] = read_string(name, min, max, chars, tag, loc);
1041
+ if(i < count - 1) separator(sep);
1042
+ }
1043
+ newline();
1044
+ return v;
1045
+ }
1046
+
1047
+ template <typename Tag>
1048
+ std::vector<std::string> gen_strings(const std::string& name, int count, int min, int max,
1049
+ const std::string_view chars, Tag /*unused*/,
1050
+ Separator sep, source_location loc) {
1051
+ assert(!chars.empty());
1052
+
1053
+ std::vector<std::string> v(count);
1054
+ if constexpr(std::is_same<Tag, ArbitraryTag>::value) {
1055
+ for(int i = 0; i < count; ++i) {
1056
+ std::string s(uniform_number(min, max), ' ');
1057
+ for(auto& x : s) x = chars[uniform_number<int>(0, chars.size() - 1)];
1058
+ v.push_back(s);
1059
+ out << s;
1060
+ if(i < count - 1) separator(sep);
1061
+ }
1062
+ } else if constexpr(Tag::unique) {
1063
+ std::set<std::string> seen_here;
1064
+ for(int i = 0; i < count; ++i) {
1065
+ // Just regenerate strings until success.
1066
+ std::string s;
1067
+ do {
1068
+ s = std::string(uniform_number(min, max), ' ');
1069
+ for(auto& x : s) x = chars[uniform_number<int>(0, chars.size() - 1)];
1070
+ } while(!seen_here.insert(s).second);
1071
+ v.push_back(s);
1072
+ out << s;
1073
+ if(i < count - 1) separator(sep);
1074
+ }
1075
+ } else {
1076
+ static_assert(Tag::increasing or Tag::decreasing);
1077
+
1078
+ assert(false && "Generating increasing/decreasing lists of strings is not "
1079
+ "supported!");
1080
+ }
1081
+
1082
+ newline();
1083
+
1084
+ return v;
1085
+ }
1086
+
1087
+ // Check the next character.
1088
+ bool peek(char c, const std::string& name = "") {
1089
+ if(gen) {
1090
+ // TODO
1091
+ // if(not name.empty() and params.contains(name)) {
1092
+ // return c == params.at(name).operator()<char>(0, 0, rng);
1093
+ //}
1094
+ return Random::bit(rng);
1095
+ }
1096
+ if(!ws) in >> std::ws;
1097
+ if(case_sensitive) return in.peek() == std::char_traits<char>::to_int_type(c);
1098
+ return tolower(in.peek()) == tolower(std::char_traits<char>::to_int_type(c));
1099
+ }
1100
+
1101
+ // Read a string and make sure it equals `expected`.
1102
+ // Takes by value because it needs to lowercase its arguments.
1103
+ std::string test_strings(std::vector<std::string> expected, const std::string& name = "") {
1104
+ if(gen) {
1105
+ int index = 0;
1106
+ // TODO
1107
+ // if(not name.empty() and params.contains(name)) {
1108
+ // auto s = params.at(name).operator()<std::string>(0, 0, rng);
1109
+ // index = std::find(expected.begin(), expected.end(), s) - expected.begin();
1110
+ // assert(0 <= index and index < expected.size());
1111
+ //} else {
1112
+ index = expected.size() == 1 ? 0 : uniform_number<int>(0, expected.size() - 1);
1113
+ //}
1114
+ out << expected[index];
1115
+ return expected[index];
1116
+ }
1117
+ std::string s = get_string();
1118
+ lowercase(s);
1119
+
1120
+ for(std::string e : expected)
1121
+ if(s == lowercase(e)) return s;
1122
+
1123
+ std::string error;
1124
+ for(const auto& e : expected) {
1125
+ if(not error.empty()) error += "|";
1126
+ error += e;
1127
+ }
1128
+ WA("Expected string \"", error, "\", but found ", s);
1129
+ }
1130
+
1131
+ // Read a string and make sure it equals `expected`.
1132
+ std::string test_string(std::string expected, const std::string& name = "") {
1133
+ return test_strings({std::move(expected)}, name);
1134
+ }
1135
+
1136
+ // Read an arbitrary string of a given length.
1137
+ template <typename Tag = ArbitraryTag>
1138
+ std::string read_string(const std::string& name, long long min, long long max,
1139
+ const std::string_view chars = "", Tag tag = Tag(),
1140
+ source_location loc = source_location::current()) {
1141
+ if(gen) {
1142
+ return gen_string(name, min, max, chars);
1143
+ }
1144
+ std::string s = get_string();
1145
+ std::array<bool, 256> ok_char{};
1146
+ if(!chars.empty()) {
1147
+ for(auto c : chars) ok_char[c] = true;
1148
+ for(auto c : s)
1149
+ check(ok_char[c], name, ": expected characters in ", chars, " but found character ",
1150
+ c, " in ", s);
1151
+ }
1152
+ check_string(name, min, max, s, tag, loc);
1153
+ return s;
1154
+ }
1155
+
1156
+ // Read an arbitrary line of a given length.
1157
+ std::string read_line(const std::string& name, long long min, long long max,
1158
+ const std::string_view chars = "",
1159
+ source_location loc = source_location::current()) {
1160
+ if(gen) {
1161
+ // TODO: Params for lines.
1162
+ assert(!chars.empty());
1163
+
1164
+ std::string s(uniform_number(min, max), ' ');
1165
+ for(auto& x : s) x = chars[uniform_number<int>(0, chars.size() - 1)];
1166
+
1167
+ out << s << '\n';
1168
+ return s;
1169
+ }
1170
+
1171
+ if(ws) {
1172
+ char next = in.peek();
1173
+ if(min > 0 and isspace(next))
1174
+ expected("non empty line", next == '\n' ? "newline" : "whitespace");
1175
+ if(in.eof()) expected("line", "EOF");
1176
+ }
1177
+ std::string s;
1178
+ if(!getline(in, s)) expected("line", "nothing");
1179
+ long long size = s.size();
1180
+ if(size < min || size > max)
1181
+ expected(name + ": line of length between " + std::to_string(min) + " and " +
1182
+ std::to_string(max),
1183
+ s);
1184
+ std::array<bool, 256> ok_char{};
1185
+ if(!chars.empty()) {
1186
+ for(auto c : chars) ok_char[c] = true;
1187
+ for(auto c : s)
1188
+ check(ok_char[c], name, ": expected characters in ", chars, " but found character ",
1189
+ c, " in ", s);
1190
+ }
1191
+ log_constraint(name, min, max, size, loc);
1192
+ return s;
1193
+ }
1194
+
1195
+ // Return ACCEPTED verdict.
1196
+ void eof_and_AC() {
1197
+ eof();
1198
+ AC();
1199
+ }
1200
+
1201
+ private:
1202
+ std::function<void()> WA_handler = [] {};
1203
+
1204
+ public:
1205
+ void set_WA_handler(std::function<void()> f) { WA_handler = std::move(f); }
1206
+
1207
+ // Return WA with the given reason.
1208
+ template <typename... Ts>
1209
+ [[noreturn]] void WA(const Ts&... ts) {
1210
+ static_assert(sizeof...(Ts) > 0);
1211
+
1212
+ WA_handler();
1213
+
1214
+ auto pos = get_file_pos();
1215
+ std::cerr << pos.first << ":" << pos.second << ": ";
1216
+
1217
+ WA_impl(ts...);
1218
+ }
1219
+
1220
+ // Check that the condition is true.
1221
+ template <typename... Ts>
1222
+ void check(bool b, const Ts&... ts) {
1223
+ static_assert(sizeof...(Ts) > 0, "Provide a non-empty error message.");
1224
+
1225
+ if(!b) WA(ts...);
1226
+ }
1227
+
1228
+ // Log some value in a range.
1229
+ template <typename T>
1230
+ void log_constraint(const std::string& name, T low, T high, T v,
1231
+ source_location loc = source_location::current()) {
1232
+ // Do not log when line number is unknown/default/unsupported.
1233
+ if(loc.line() == 0 or constraints_file_path.empty()) return;
1234
+
1235
+ // All integer types get bounds as long long, all floating point types as long_double.
1236
+ using U = Bounds<std::conditional_t<std::is_integral_v<T>, long long, long double>>;
1237
+
1238
+ auto [it, inserted] = bounds.emplace(loc, U(name, v, v, low, high));
1239
+ assert(std::holds_alternative<U>(it->second));
1240
+ auto& done = std::get<U>(it->second);
1241
+ if(inserted) {
1242
+ assert(!name.empty() && "Variable names must not be empty.");
1243
+ assert(name.find(' ') == std::string::npos && "Variable name must not contain spaces.");
1244
+ } else {
1245
+ assert(name == done.name && "Variable name must be constant.");
1246
+ }
1247
+ if(v < done.min) {
1248
+ done.min = v;
1249
+ done.low = low;
1250
+ }
1251
+ if(v > done.max) {
1252
+ done.max = v;
1253
+ done.high = high;
1254
+ }
1255
+ done.has_min |= v == low;
1256
+ done.has_max |= v == high;
1257
+ }
1258
+
1259
+ private:
1260
+ long long read_integer(const std::string& name) {
1261
+ assert(!gen);
1262
+ std::string s = get_string("integer");
1263
+ if(s.empty()) {
1264
+ WA(name, ": Want integer, found nothing");
1265
+ }
1266
+ long long v;
1267
+ auto begin = s.c_str(), end = begin + s.size();
1268
+ auto [ptr, ec] = std::from_chars(begin, end, v);
1269
+ if(ec == std::errc::result_out_of_range){
1270
+ WA(name, ": Number " + s + " does not fit in a long long!");
1271
+ } else if(ptr != end) {
1272
+ WA(name, ": Parsing " + s + " as long long failed! Did not process all characters");
1273
+ } else if (ec != std::errc{}) {
1274
+ WA(name, ": Parsing " + s + " as long long failed!");
1275
+ }
1276
+ // Check for leading zero.
1277
+ if(v == 0) {
1278
+ if(s.size() != 1) WA(name, ": Parsed 0, but has leading 0 or minus sign: ", s);
1279
+ }
1280
+ if(v > 0) {
1281
+ if(s[0] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s);
1282
+ }
1283
+ if(v < 0) {
1284
+ if(s.size() <= 1) WA(name, ": Parsed ", v, ", but string is: ", s);
1285
+ if(s[1] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s);
1286
+ }
1287
+ return v;
1288
+ }
1289
+
1290
+ long double read_float(const std::string& name) {
1291
+ assert(!gen);
1292
+ std::string s = get_string("long double");
1293
+ long double v;
1294
+ try {
1295
+ size_t chars_processed;
1296
+ v = stold(s, &chars_processed);
1297
+ if(chars_processed != s.size())
1298
+ WA(name, ": Parsing ", s,
1299
+ " as long double failed! Did not process all characters.");
1300
+ } catch(const std::out_of_range& e) {
1301
+ WA(name, ": Number " + s + " does not fit in a long double!");
1302
+ } catch(const std::invalid_argument& e) {
1303
+ WA("Parsing " + s + " as long double failed!");
1304
+ }
1305
+ return v;
1306
+ }
1307
+
1308
+ [[noreturn]] void expected(const std::string& exp = "", const std::string& s = "") {
1309
+ assert(!gen && "Expected is not supported for generators.");
1310
+ if(!s.empty())
1311
+ WA("Expected ", exp, ", found ", s);
1312
+ else
1313
+ WA(exp);
1314
+ }
1315
+
1316
+ template <typename T>
1317
+ [[noreturn]] void WA_impl(T t) {
1318
+ std::cerr << t << std::endl;
1319
+ exit(ret_WA);
1320
+ }
1321
+
1322
+ std::pair<int, int> get_file_pos() {
1323
+ int line = 1, col = 0;
1324
+ in.clear();
1325
+ auto originalPos = in.tellg();
1326
+ if(originalPos < 0) return {-1, -1};
1327
+ in.seekg(0);
1328
+ char c;
1329
+ while((in.tellg() < originalPos) && in.get(c)) {
1330
+ if(c == '\n')
1331
+ ++line, col = 0;
1332
+ else
1333
+ ++col;
1334
+ }
1335
+ return {line, col};
1336
+ }
1337
+
1338
+ template <typename T, typename... Ts>
1339
+ [[noreturn]] void WA_impl(T t, Ts... ts) {
1340
+ std::cerr << t;
1341
+ WA_impl(ts...);
1342
+ }
1343
+
1344
+ std::string get_string(const std::string& wanted = "string") {
1345
+ assert(!gen && "get_string is not supported for generators.");
1346
+ if(ws) {
1347
+ char next = in.peek();
1348
+ if(isspace(next)) expected(wanted, next == '\n' ? "newline" : "whitespace");
1349
+ if(in.eof()) expected(wanted, "EOF");
1350
+ }
1351
+
1352
+ std::string s;
1353
+ if(in >> s) {
1354
+ return s;
1355
+ }
1356
+ expected(wanted, "nothing");
1357
+ }
1358
+
1359
+ // Return ACCEPTED verdict.
1360
+ void AC() const {
1361
+ if(gen) {
1362
+ // nothing
1363
+ return;
1364
+ }
1365
+
1366
+ exit(ret_AC);
1367
+ }
1368
+
1369
+ void eof() {
1370
+ if(gen) {
1371
+ out.flush();
1372
+ fclose(stdout);
1373
+ return;
1374
+ }
1375
+ if(in.eof()) return;
1376
+ // Sometimes EOF hasn't been triggered yet.
1377
+ if(!ws) in >> std::ws;
1378
+ char c = in.get();
1379
+ if(c == std::char_traits<char>::eof()) return;
1380
+ std::string got = std::string("\"") + char(c) + '"';
1381
+ if(c == '\n') got = "newline";
1382
+ expected("EOF", got);
1383
+ }
1384
+
1385
+ // Convert a string to lowercase is matching is not case sensitive.
1386
+ std::string& lowercase(std::string& s) const {
1387
+ if(case_sensitive) return s;
1388
+ transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
1389
+ return s;
1390
+ }
1391
+
1392
+ // Keep track of the min/max value read at every call site.
1393
+ template <typename T>
1394
+ struct Bounds {
1395
+ Bounds(std::string name_, T min_, T max_, T low_, T high_)
1396
+ : name(std::move(name_)), min(min_), max(max_), low(low_), high(high_) {} // NOLINT
1397
+ std::string name;
1398
+ T min, max; // Smallest / largest value observed
1399
+ T low, high; // Bounds
1400
+ bool has_min = false, has_max = false;
1401
+ };
1402
+
1403
+ std::map<source_location, std::variant<Bounds<long long>, Bounds<long double>>> bounds;
1404
+
1405
+ void write_constraints() {
1406
+ if(constraints_file_path.empty()) return;
1407
+
1408
+ std::ofstream os(constraints_file_path);
1409
+
1410
+ for(const auto& [location, bound] : bounds) {
1411
+ os << location_to_string(location) << " ";
1412
+ std::visit(
1413
+ [&](const auto& b) {
1414
+ os << b.name << " " << b.has_min << " " << b.has_max << " " << b.min << " "
1415
+ << b.max << " " << b.low << " " << b.high << std::endl;
1416
+ },
1417
+ bound);
1418
+ }
1419
+ }
1420
+
1421
+ static const int ret_AC = 42, ret_WA = 43;
1422
+ std::istream& in = std::cin;
1423
+ std::ostream& out = std::cout;
1424
+
1425
+ public:
1426
+ const bool ws = true;
1427
+ const bool case_sensitive = true;
1428
+ const std::string constraints_file_path;
1429
+ const bool gen = false;
1430
+
1431
+ std::mt19937_64 rng;
1432
+
1433
+ private:
1434
+ std::unordered_map<std::string, ParamGenerator> params;
1435
+
1436
+ public:
1437
+ std::string_view get_param(std::string_view name, std::string_view default_) {
1438
+ auto it = params.find(std::string(name));
1439
+ if(it == params.end()) return default_;
1440
+ return std::get<std::string_view>(it->second.generator);
1441
+ }
1442
+
1443
+ protected:
1444
+ static std::string get_constraints_file(int argc, char** argv) {
1445
+ for(int i = 1; i < argc; ++i) {
1446
+ if(argv[i] == constraints_file_flag) {
1447
+ if(i + 1 < argc) return argv[i + 1];
1448
+ std::cerr << constraints_file_flag << " should be followed by a file path!";
1449
+ exit(1);
1450
+ }
1451
+ }
1452
+ return {};
1453
+ }
1454
+ };
1455
+
1456
+ class Generator : public Validator {
1457
+ public:
1458
+ explicit Generator(unsigned int seed)
1459
+ : Validator(true, true, std::cin, /*constraints_file_path_=*/"", seed) {}
1460
+ };
1461
+
1462
+ class InputValidator : public Validator {
1463
+ public:
1464
+ // An InputValidator is always both whitespace and case sensitive.
1465
+ explicit InputValidator(int argc = 0, char** argv = nullptr)
1466
+ : Validator(true, true, std::cin, get_constraints_file(argc, argv), get_seed(argc, argv),
1467
+ get_params(argc, argv)) {}
1468
+
1469
+ private:
1470
+ static std::optional<unsigned int> get_seed(int argc, char** argv) {
1471
+ for(int i = 1; i < argc - 1; ++i) {
1472
+ if(argv[i] == generate_flag) {
1473
+ return std::stol(argv[i + 1]);
1474
+ }
1475
+ }
1476
+ // If no --generate is given, but `generat` is a substring of the binary path,
1477
+ // use the first argument as seed.
1478
+ if(std::string(argv[0]).find(generate_binary_substring) != std::string::npos) {
1479
+ return std::stol(argv[1]);
1480
+ }
1481
+ return std::nullopt;
1482
+ }
1483
+
1484
+ static std::unordered_map<std::string, ParamGenerator> get_params(int argc, char** argv) {
1485
+ std::unordered_map<std::string, ParamGenerator> params;
1486
+ for(int i = 1; i < argc - 1; ++i) {
1487
+ if(std::strlen(argv[i]) == 0 or argv[i][0] != '-') continue;
1488
+ if(argv[i] == generate_flag) {
1489
+ continue;
1490
+ }
1491
+ std::string_view name(argv[i] + 1);
1492
+ std::string_view value(argv[i + 1]);
1493
+ params.insert({std::string(name), ParamGenerator(value)});
1494
+ }
1495
+ return params;
1496
+ }
1497
+ };
1498
+
1499
+ class OutputValidator : public Validator {
1500
+ public:
1501
+ // An OutputValidator can be run in different modes.
1502
+ explicit OutputValidator(int argc, char** argv, std::istream& in_ = std::cin)
1503
+ : Validator(is_ws_sensitive(argc, argv), is_case_sensitive(argc, argv), in_,
1504
+ get_constraints_file(argc, argv)) {}
1505
+
1506
+ private:
1507
+ static bool is_ws_sensitive(int argc, char** argv) {
1508
+ for(int i = 1; i < argc; ++i) {
1509
+ if(argv[i] == ws_sensitive_flag) return true;
1510
+ }
1511
+ return false;
1512
+ }
1513
+
1514
+ static bool is_case_sensitive(int argc, char** argv) {
1515
+ for(int i = 1; i < argc; ++i) {
1516
+ if(argv[i] == case_sensitive_flag) return true;
1517
+ }
1518
+ return false;
1519
+ }
1520
+ };
ICPC/nwerc2022_J/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3e980aaccf3b6013c6279a2daa2da2569b5deecf8006b706234b2af05ccb1401
3
+ size 77274230
ICPC/nwerc2022_J/init.yml ADDED
@@ -0,0 +1,377 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ test_cases:
3
+ - in: 001-tower_overlapping.in
4
+ out: 001-tower_overlapping.ans
5
+ points: 1
6
+ - in: 002-tower_overlapping.in
7
+ out: 002-tower_overlapping.ans
8
+ points: 1
9
+ - in: 003-tower_overlapping.in
10
+ out: 003-tower_overlapping.ans
11
+ points: 1
12
+ - in: 004-tower_overlapping.in
13
+ out: 004-tower_overlapping.ans
14
+ points: 1
15
+ - in: 005-tower_overlapping.in
16
+ out: 005-tower_overlapping.ans
17
+ points: 1
18
+ - in: 006-manual.in
19
+ out: 006-manual.ans
20
+ points: 1
21
+ - in: 007-manual.in
22
+ out: 007-manual.ans
23
+ points: 1
24
+ - in: 008-manual.in
25
+ out: 008-manual.ans
26
+ points: 1
27
+ - in: 009-manual.in
28
+ out: 009-manual.ans
29
+ points: 1
30
+ - in: 010-manual.in
31
+ out: 010-manual.ans
32
+ points: 1
33
+ - in: 011-fuzz-small.in
34
+ out: 011-fuzz-small.ans
35
+ points: 1
36
+ - in: 012-fuzz-small.in
37
+ out: 012-fuzz-small.ans
38
+ points: 1
39
+ - in: 013-fuzz-small.in
40
+ out: 013-fuzz-small.ans
41
+ points: 1
42
+ - in: 014-fuzz-small.in
43
+ out: 014-fuzz-small.ans
44
+ points: 1
45
+ - in: 015-fuzz.in
46
+ out: 015-fuzz.ans
47
+ points: 1
48
+ - in: 016-fuzz.in
49
+ out: 016-fuzz.ans
50
+ points: 1
51
+ - in: 017-fuzz.in
52
+ out: 017-fuzz.ans
53
+ points: 1
54
+ - in: 018-fuzz.in
55
+ out: 018-fuzz.ans
56
+ points: 1
57
+ - in: 019-fuzz.in
58
+ out: 019-fuzz.ans
59
+ points: 1
60
+ - in: 020-fuzz.in
61
+ out: 020-fuzz.ans
62
+ points: 1
63
+ - in: 021-fuzz.in
64
+ out: 021-fuzz.ans
65
+ points: 1
66
+ - in: 022-max-left.in
67
+ out: 022-max-left.ans
68
+ points: 1
69
+ - in: 023-max-right.in
70
+ out: 023-max-right.ans
71
+ points: 1
72
+ - in: 024-max-left-shufle.in
73
+ out: 024-max-left-shufle.ans
74
+ points: 1
75
+ - in: 025-bipartite.in
76
+ out: 025-bipartite.ans
77
+ points: 1
78
+ - in: 026-bipartite.in
79
+ out: 026-bipartite.ans
80
+ points: 1
81
+ - in: 027-bipartite.in
82
+ out: 027-bipartite.ans
83
+ points: 1
84
+ - in: 028-bipartite.in
85
+ out: 028-bipartite.ans
86
+ points: 1
87
+ - in: 029-bipartite.in
88
+ out: 029-bipartite.ans
89
+ points: 1
90
+ - in: 030-tower.in
91
+ out: 030-tower.ans
92
+ points: 1
93
+ - in: 031-random.in
94
+ out: 031-random.ans
95
+ points: 1
96
+ - in: 032-random.in
97
+ out: 032-random.ans
98
+ points: 1
99
+ - in: 033-random.in
100
+ out: 033-random.ans
101
+ points: 1
102
+ - in: 034-random.in
103
+ out: 034-random.ans
104
+ points: 1
105
+ - in: 035-random-few-ends.in
106
+ out: 035-random-few-ends.ans
107
+ points: 1
108
+ - in: 036-random-few-ends.in
109
+ out: 036-random-few-ends.ans
110
+ points: 1
111
+ - in: 037-random-few-ends.in
112
+ out: 037-random-few-ends.ans
113
+ points: 1
114
+ - in: 038-random-few-ends.in
115
+ out: 038-random-few-ends.ans
116
+ points: 1
117
+ - in: 039-random-many-ends.in
118
+ out: 039-random-many-ends.ans
119
+ points: 1
120
+ - in: 040-random-many-ends.in
121
+ out: 040-random-many-ends.ans
122
+ points: 1
123
+ - in: 041-random-many-ends.in
124
+ out: 041-random-many-ends.ans
125
+ points: 1
126
+ - in: 042-random-many-ends.in
127
+ out: 042-random-many-ends.ans
128
+ points: 1
129
+ - in: 043-random-many-ends.in
130
+ out: 043-random-many-ends.ans
131
+ points: 1
132
+ - in: 044-random-many-ends.in
133
+ out: 044-random-many-ends.ans
134
+ points: 1
135
+ - in: 045-random-small.in
136
+ out: 045-random-small.ans
137
+ points: 1
138
+ - in: 046-random-small.in
139
+ out: 046-random-small.ans
140
+ points: 1
141
+ - in: 047-random-small.in
142
+ out: 047-random-small.ans
143
+ points: 1
144
+ - in: 048-random-small.in
145
+ out: 048-random-small.ans
146
+ points: 1
147
+ - in: 049-small.in
148
+ out: 049-small.ans
149
+ points: 1
150
+ - in: 050-small.in
151
+ out: 050-small.ans
152
+ points: 1
153
+ - in: 051-small.in
154
+ out: 051-small.ans
155
+ points: 1
156
+ - in: 052-small.in
157
+ out: 052-small.ans
158
+ points: 1
159
+ - in: 053-small.in
160
+ out: 053-small.ans
161
+ points: 1
162
+ - in: 054-tower.in
163
+ out: 054-tower.ans
164
+ points: 1
165
+ - in: 055-tower.in
166
+ out: 055-tower.ans
167
+ points: 1
168
+ - in: 056-overlapping.in
169
+ out: 056-overlapping.ans
170
+ points: 1
171
+ - in: 057-overlapping.in
172
+ out: 057-overlapping.ans
173
+ points: 1
174
+ - in: 058-complete.in
175
+ out: 058-complete.ans
176
+ points: 1
177
+ - in: 059-complete.in
178
+ out: 059-complete.ans
179
+ points: 1
180
+ - in: 060-complete.in
181
+ out: 060-complete.ans
182
+ points: 1
183
+ - in: 061-complete.in
184
+ out: 061-complete.ans
185
+ points: 1
186
+ - in: 062-complete.in
187
+ out: 062-complete.ans
188
+ points: 1
189
+ - in: 063-dense.in
190
+ out: 063-dense.ans
191
+ points: 1
192
+ - in: 064-dense.in
193
+ out: 064-dense.ans
194
+ points: 1
195
+ - in: 065-dense.in
196
+ out: 065-dense.ans
197
+ points: 1
198
+ - in: 066-dense.in
199
+ out: 066-dense.ans
200
+ points: 1
201
+ - in: 067-dense.in
202
+ out: 067-dense.ans
203
+ points: 1
204
+ - in: 068-dense.in
205
+ out: 068-dense.ans
206
+ points: 1
207
+ - in: 069-dense.in
208
+ out: 069-dense.ans
209
+ points: 1
210
+ - in: 070-dense.in
211
+ out: 070-dense.ans
212
+ points: 1
213
+ - in: 071-dense.in
214
+ out: 071-dense.ans
215
+ points: 1
216
+ - in: 072-dense-maxn.in
217
+ out: 072-dense-maxn.ans
218
+ points: 1
219
+ - in: 073-dense-maxn.in
220
+ out: 073-dense-maxn.ans
221
+ points: 1
222
+ - in: 074-dense-maxn.in
223
+ out: 074-dense-maxn.ans
224
+ points: 1
225
+ - in: 075-dense-maxn.in
226
+ out: 075-dense-maxn.ans
227
+ points: 1
228
+ - in: 076-dense-maxn.in
229
+ out: 076-dense-maxn.ans
230
+ points: 1
231
+ - in: 077-dense-maxn.in
232
+ out: 077-dense-maxn.ans
233
+ points: 1
234
+ - in: 078-dense-maxn.in
235
+ out: 078-dense-maxn.ans
236
+ points: 1
237
+ - in: 079-dense-maxn.in
238
+ out: 079-dense-maxn.ans
239
+ points: 1
240
+ - in: 080-dense-maxn.in
241
+ out: 080-dense-maxn.ans
242
+ points: 1
243
+ - in: 081-dense-maxn.in
244
+ out: 081-dense-maxn.ans
245
+ points: 1
246
+ - in: 082-tree.in
247
+ out: 082-tree.ans
248
+ points: 1
249
+ - in: 083-tree.in
250
+ out: 083-tree.ans
251
+ points: 1
252
+ - in: 084-tree.in
253
+ out: 084-tree.ans
254
+ points: 1
255
+ - in: 085-tree.in
256
+ out: 085-tree.ans
257
+ points: 1
258
+ - in: 086-tree.in
259
+ out: 086-tree.ans
260
+ points: 1
261
+ - in: 087-tree.in
262
+ out: 087-tree.ans
263
+ points: 1
264
+ - in: 088-tree-binary.in
265
+ out: 088-tree-binary.ans
266
+ points: 1
267
+ - in: 089-tree-binary.in
268
+ out: 089-tree-binary.ans
269
+ points: 1
270
+ - in: 090-tree-binary.in
271
+ out: 090-tree-binary.ans
272
+ points: 1
273
+ - in: 091-tree-binary.in
274
+ out: 091-tree-binary.ans
275
+ points: 1
276
+ - in: 092-tree-binary.in
277
+ out: 092-tree-binary.ans
278
+ points: 1
279
+ - in: 093-tree-binary.in
280
+ out: 093-tree-binary.ans
281
+ points: 1
282
+ - in: 094-tree-binary.in
283
+ out: 094-tree-binary.ans
284
+ points: 1
285
+ - in: 095-tree-binary-deep.in
286
+ out: 095-tree-binary-deep.ans
287
+ points: 1
288
+ - in: 096-tree-binary-deep.in
289
+ out: 096-tree-binary-deep.ans
290
+ points: 1
291
+ - in: 097-tree-binary-deep.in
292
+ out: 097-tree-binary-deep.ans
293
+ points: 1
294
+ - in: 098-tree-binary-deep.in
295
+ out: 098-tree-binary-deep.ans
296
+ points: 1
297
+ - in: 099-tree-binary-deep.in
298
+ out: 099-tree-binary-deep.ans
299
+ points: 1
300
+ - in: 100-tree-binary-deep.in
301
+ out: 100-tree-binary-deep.ans
302
+ points: 1
303
+ - in: 101-tree-random.in
304
+ out: 101-tree-random.ans
305
+ points: 1
306
+ - in: 102-tree-random.in
307
+ out: 102-tree-random.ans
308
+ points: 1
309
+ - in: 103-tree-random.in
310
+ out: 103-tree-random.ans
311
+ points: 1
312
+ - in: 104-tree-random.in
313
+ out: 104-tree-random.ans
314
+ points: 1
315
+ - in: 105-tree-random.in
316
+ out: 105-tree-random.ans
317
+ points: 1
318
+ - in: 106-tree-random.in
319
+ out: 106-tree-random.ans
320
+ points: 1
321
+ - in: 107-tree-large.in
322
+ out: 107-tree-large.ans
323
+ points: 1
324
+ - in: 108-tree-large.in
325
+ out: 108-tree-large.ans
326
+ points: 1
327
+ - in: 109-tree-large.in
328
+ out: 109-tree-large.ans
329
+ points: 1
330
+ - in: 110-tree-pathy.in
331
+ out: 110-tree-pathy.ans
332
+ points: 1
333
+ - in: 111-tree-pathy.in
334
+ out: 111-tree-pathy.ans
335
+ points: 1
336
+ - in: 112-tree-pathy.in
337
+ out: 112-tree-pathy.ans
338
+ points: 1
339
+ - in: 113-tree-pathy.in
340
+ out: 113-tree-pathy.ans
341
+ points: 1
342
+ - in: 114-tree-pathy.in
343
+ out: 114-tree-pathy.ans
344
+ points: 1
345
+ - in: 115-tree-pathy.in
346
+ out: 115-tree-pathy.ans
347
+ points: 1
348
+ - in: 116-tree-pathy.in
349
+ out: 116-tree-pathy.ans
350
+ points: 1
351
+ - in: 117-tree-pathy-deep.in
352
+ out: 117-tree-pathy-deep.ans
353
+ points: 1
354
+ - in: 118-tree-pathy-deep.in
355
+ out: 118-tree-pathy-deep.ans
356
+ points: 1
357
+ - in: 119-tree-pathy-deep.in
358
+ out: 119-tree-pathy-deep.ans
359
+ points: 1
360
+ - in: 120-tree-pathy-deep.in
361
+ out: 120-tree-pathy-deep.ans
362
+ points: 1
363
+ - in: 121-tree-pathy-deep.in
364
+ out: 121-tree-pathy-deep.ans
365
+ points: 1
366
+ - in: 122-tree-pathy-deep.in
367
+ out: 122-tree-pathy-deep.ans
368
+ points: 1
369
+ - in: 123-tree-pathy-deep.in
370
+ out: 123-tree-pathy-deep.ans
371
+ points: 1
372
+ - in: 124-tree-pathy-deep.in
373
+ out: 124-tree-pathy-deep.ans
374
+ points: 1
375
+ - in: 125-tree-pathy-deep.in
376
+ out: 125-tree-pathy-deep.ans
377
+ points: 1
ICPC/nwerc2022_K/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:598d142a779315a78464d1ea3b333ae881c6f035fa8b7ae0169df2ca7e46e22d
3
+ size 19948886
ICPC/nwerc2022_K/init.yml ADDED
@@ -0,0 +1,491 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ test_cases:
3
+ - in: 001-2multiedges_selfloops.in
4
+ out: 001-2multiedges_selfloops.ans
5
+ points: 1
6
+ - in: 002-2multiedges.in
7
+ out: 002-2multiedges.ans
8
+ points: 1
9
+ - in: 003-2selfloops_degree3.in
10
+ out: 003-2selfloops_degree3.ans
11
+ points: 1
12
+ - in: 004-3selfloops_degree3.in
13
+ out: 004-3selfloops_degree3.ans
14
+ points: 1
15
+ - in: 005-cycle_and_edge.in
16
+ out: 005-cycle_and_edge.ans
17
+ points: 1
18
+ - in: 006-cycle_and_selfloop.in
19
+ out: 006-cycle_and_selfloop.ans
20
+ points: 1
21
+ - in: 007-cycle_and_vertex.in
22
+ out: 007-cycle_and_vertex.ans
23
+ points: 1
24
+ - in: 008-multiedge_on_cycle.in
25
+ out: 008-multiedge_on_cycle.ans
26
+ points: 1
27
+ - in: 009-selfloop_edge_cycle.in
28
+ out: 009-selfloop_edge_cycle.ans
29
+ points: 1
30
+ - in: 010-selfloops_on_cycle.in
31
+ out: 010-selfloops_on_cycle.ans
32
+ points: 1
33
+ - in: 011-two_cycles.in
34
+ out: 011-two_cycles.ans
35
+ points: 1
36
+ - in: 012-two_paths.in
37
+ out: 012-two_paths.ans
38
+ points: 1
39
+ - in: 013-matching.in
40
+ out: 013-matching.ans
41
+ points: 1
42
+ - in: 014-random.in
43
+ out: 014-random.ans
44
+ points: 1
45
+ - in: 015-random.in
46
+ out: 015-random.ans
47
+ points: 1
48
+ - in: 016-random.in
49
+ out: 016-random.ans
50
+ points: 1
51
+ - in: 017-random.in
52
+ out: 017-random.ans
53
+ points: 1
54
+ - in: 018-random.in
55
+ out: 018-random.ans
56
+ points: 1
57
+ - in: 019-random.in
58
+ out: 019-random.ans
59
+ points: 1
60
+ - in: 020-random.in
61
+ out: 020-random.ans
62
+ points: 1
63
+ - in: 021-random.in
64
+ out: 021-random.ans
65
+ points: 1
66
+ - in: 022-random.in
67
+ out: 022-random.ans
68
+ points: 1
69
+ - in: 023-random.in
70
+ out: 023-random.ans
71
+ points: 1
72
+ - in: 024-random-possible.in
73
+ out: 024-random-possible.ans
74
+ points: 1
75
+ - in: 025-random-possible.in
76
+ out: 025-random-possible.ans
77
+ points: 1
78
+ - in: 026-random-possible.in
79
+ out: 026-random-possible.ans
80
+ points: 1
81
+ - in: 027-random-possible.in
82
+ out: 027-random-possible.ans
83
+ points: 1
84
+ - in: 028-random-possible.in
85
+ out: 028-random-possible.ans
86
+ points: 1
87
+ - in: 029-random-possible.in
88
+ out: 029-random-possible.ans
89
+ points: 1
90
+ - in: 030-random-possible.in
91
+ out: 030-random-possible.ans
92
+ points: 1
93
+ - in: 031-random-possible.in
94
+ out: 031-random-possible.ans
95
+ points: 1
96
+ - in: 032-random-possible.in
97
+ out: 032-random-possible.ans
98
+ points: 1
99
+ - in: 033-random-possible.in
100
+ out: 033-random-possible.ans
101
+ points: 1
102
+ - in: 034-long-cycle.in
103
+ out: 034-long-cycle.ans
104
+ points: 1
105
+ - in: 035-two-long-cycles.in
106
+ out: 035-two-long-cycles.ans
107
+ points: 1
108
+ - in: 036-long-chain.in
109
+ out: 036-long-chain.ans
110
+ points: 1
111
+ - in: 037-two-long-chains.in
112
+ out: 037-two-long-chains.ans
113
+ points: 1
114
+ - in: 038-long-cycle-and-chain.in
115
+ out: 038-long-cycle-and-chain.ans
116
+ points: 1
117
+ - in: 039-long-cycle-and-two-chains.in
118
+ out: 039-long-cycle-and-two-chains.ans
119
+ points: 1
120
+ - in: 040-long-cycle-and-edge.in
121
+ out: 040-long-cycle-and-edge.ans
122
+ points: 1
123
+ - in: 041-long-chain-and-edge.in
124
+ out: 041-long-chain-and-edge.ans
125
+ points: 1
126
+ - in: 042-long-cycle-decorated.in
127
+ out: 042-long-cycle-decorated.ans
128
+ points: 1
129
+ - in: 043-two-long-cycles-decorated.in
130
+ out: 043-two-long-cycles-decorated.ans
131
+ points: 1
132
+ - in: 044-long-chain-decorated.in
133
+ out: 044-long-chain-decorated.ans
134
+ points: 1
135
+ - in: 045-two-long-chains-decorated.in
136
+ out: 045-two-long-chains-decorated.ans
137
+ points: 1
138
+ - in: 046-long-cycle-and-node.in
139
+ out: 046-long-cycle-and-node.ans
140
+ points: 1
141
+ - in: 047-long-cycle-and-selfloop.in
142
+ out: 047-long-cycle-and-selfloop.ans
143
+ points: 1
144
+ - in: 048-many-2-chains.in
145
+ out: 048-many-2-chains.ans
146
+ points: 1
147
+ - in: 049-many-selfloops.in
148
+ out: 049-many-selfloops.ans
149
+ points: 1
150
+ - in: 050-many-5-chains.in
151
+ out: 050-many-5-chains.ans
152
+ points: 1
153
+ - in: 051-long-cycle-and-clique.in
154
+ out: 051-long-cycle-and-clique.ans
155
+ points: 1
156
+ - in: 052-two-long-cycles-and-clique.in
157
+ out: 052-two-long-cycles-and-clique.ans
158
+ points: 1
159
+ - in: 053-long-chain-and-clique.in
160
+ out: 053-long-chain-and-clique.ans
161
+ points: 1
162
+ - in: 054-two-long-chains-and-clique.in
163
+ out: 054-two-long-chains-and-clique.ans
164
+ points: 1
165
+ - in: 055-many-2-chains-and-clique.in
166
+ out: 055-many-2-chains-and-clique.ans
167
+ points: 1
168
+ - in: 056-many-selfloops-and-clique.in
169
+ out: 056-many-selfloops-and-clique.ans
170
+ points: 1
171
+ - in: 057-many-5-chains-and-clique.in
172
+ out: 057-many-5-chains-and-clique.ans
173
+ points: 1
174
+ - in: 058-large-clique.in
175
+ out: 058-large-clique.ans
176
+ points: 1
177
+ - in: 059-large-clique.in
178
+ out: 059-large-clique.ans
179
+ points: 1
180
+ - in: 060-large-clique-decorated.in
181
+ out: 060-large-clique-decorated.ans
182
+ points: 1
183
+ - in: 061-large-clique-decorated.in
184
+ out: 061-large-clique-decorated.ans
185
+ points: 1
186
+ - in: 062-peter.in
187
+ out: 062-peter.ans
188
+ points: 1
189
+ - in: 063-peter.in
190
+ out: 063-peter.ans
191
+ points: 1
192
+ - in: 064-random-mutated.in
193
+ out: 064-random-mutated.ans
194
+ points: 1
195
+ - in: 065-random-mutated.in
196
+ out: 065-random-mutated.ans
197
+ points: 1
198
+ - in: 066-random-mutated.in
199
+ out: 066-random-mutated.ans
200
+ points: 1
201
+ - in: 067-random-mutated.in
202
+ out: 067-random-mutated.ans
203
+ points: 1
204
+ - in: 068-random-mutated.in
205
+ out: 068-random-mutated.ans
206
+ points: 1
207
+ - in: 069-random-mutated.in
208
+ out: 069-random-mutated.ans
209
+ points: 1
210
+ - in: 070-random-mutated.in
211
+ out: 070-random-mutated.ans
212
+ points: 1
213
+ - in: 071-random-mutated.in
214
+ out: 071-random-mutated.ans
215
+ points: 1
216
+ - in: 072-random-mutated.in
217
+ out: 072-random-mutated.ans
218
+ points: 1
219
+ - in: 073-random-mutated.in
220
+ out: 073-random-mutated.ans
221
+ points: 1
222
+ - in: 074-random-mutated.in
223
+ out: 074-random-mutated.ans
224
+ points: 1
225
+ - in: 075-random-mutated.in
226
+ out: 075-random-mutated.ans
227
+ points: 1
228
+ - in: 076-random-mutated.in
229
+ out: 076-random-mutated.ans
230
+ points: 1
231
+ - in: 077-random-mutated.in
232
+ out: 077-random-mutated.ans
233
+ points: 1
234
+ - in: 078-random-mutated.in
235
+ out: 078-random-mutated.ans
236
+ points: 1
237
+ - in: 079-random-mutated.in
238
+ out: 079-random-mutated.ans
239
+ points: 1
240
+ - in: 080-random-mutated.in
241
+ out: 080-random-mutated.ans
242
+ points: 1
243
+ - in: 081-random-mutated.in
244
+ out: 081-random-mutated.ans
245
+ points: 1
246
+ - in: 082-random-mutated.in
247
+ out: 082-random-mutated.ans
248
+ points: 1
249
+ - in: 083-random-mutated.in
250
+ out: 083-random-mutated.ans
251
+ points: 1
252
+ - in: 084-random-mutated.in
253
+ out: 084-random-mutated.ans
254
+ points: 1
255
+ - in: 085-random-mutated.in
256
+ out: 085-random-mutated.ans
257
+ points: 1
258
+ - in: 086-random-mutated.in
259
+ out: 086-random-mutated.ans
260
+ points: 1
261
+ - in: 087-random-mutated.in
262
+ out: 087-random-mutated.ans
263
+ points: 1
264
+ - in: 088-random-mutated.in
265
+ out: 088-random-mutated.ans
266
+ points: 1
267
+ - in: 089-random-mutated.in
268
+ out: 089-random-mutated.ans
269
+ points: 1
270
+ - in: 090-random-mutated.in
271
+ out: 090-random-mutated.ans
272
+ points: 1
273
+ - in: 091-random-mutated.in
274
+ out: 091-random-mutated.ans
275
+ points: 1
276
+ - in: 092-random-mutated.in
277
+ out: 092-random-mutated.ans
278
+ points: 1
279
+ - in: 093-random-mutated.in
280
+ out: 093-random-mutated.ans
281
+ points: 1
282
+ - in: 094-random-mutated.in
283
+ out: 094-random-mutated.ans
284
+ points: 1
285
+ - in: 095-random-mutated.in
286
+ out: 095-random-mutated.ans
287
+ points: 1
288
+ - in: 096-random-mutated.in
289
+ out: 096-random-mutated.ans
290
+ points: 1
291
+ - in: 097-random-mutated.in
292
+ out: 097-random-mutated.ans
293
+ points: 1
294
+ - in: 098-random-mutated.in
295
+ out: 098-random-mutated.ans
296
+ points: 1
297
+ - in: 099-random-mutated.in
298
+ out: 099-random-mutated.ans
299
+ points: 1
300
+ - in: 100-random-mutated.in
301
+ out: 100-random-mutated.ans
302
+ points: 1
303
+ - in: 101-random-mutated.in
304
+ out: 101-random-mutated.ans
305
+ points: 1
306
+ - in: 102-random-mutated.in
307
+ out: 102-random-mutated.ans
308
+ points: 1
309
+ - in: 103-random-mutated.in
310
+ out: 103-random-mutated.ans
311
+ points: 1
312
+ - in: 104-random-mutated.in
313
+ out: 104-random-mutated.ans
314
+ points: 1
315
+ - in: 105-random-mutated.in
316
+ out: 105-random-mutated.ans
317
+ points: 1
318
+ - in: 106-random-mutated.in
319
+ out: 106-random-mutated.ans
320
+ points: 1
321
+ - in: 107-random-mutated.in
322
+ out: 107-random-mutated.ans
323
+ points: 1
324
+ - in: 108-random-mutated.in
325
+ out: 108-random-mutated.ans
326
+ points: 1
327
+ - in: 109-random-mutated.in
328
+ out: 109-random-mutated.ans
329
+ points: 1
330
+ - in: 110-random-mutated.in
331
+ out: 110-random-mutated.ans
332
+ points: 1
333
+ - in: 111-random-mutated.in
334
+ out: 111-random-mutated.ans
335
+ points: 1
336
+ - in: 112-random-mutated.in
337
+ out: 112-random-mutated.ans
338
+ points: 1
339
+ - in: 113-random-mutated.in
340
+ out: 113-random-mutated.ans
341
+ points: 1
342
+ - in: 114-random-mutated.in
343
+ out: 114-random-mutated.ans
344
+ points: 1
345
+ - in: 115-random-mutated.in
346
+ out: 115-random-mutated.ans
347
+ points: 1
348
+ - in: 116-random-mutated.in
349
+ out: 116-random-mutated.ans
350
+ points: 1
351
+ - in: 117-random-mutated.in
352
+ out: 117-random-mutated.ans
353
+ points: 1
354
+ - in: 118-random-mutated.in
355
+ out: 118-random-mutated.ans
356
+ points: 1
357
+ - in: 119-random-mutated.in
358
+ out: 119-random-mutated.ans
359
+ points: 1
360
+ - in: 120-random-mutated.in
361
+ out: 120-random-mutated.ans
362
+ points: 1
363
+ - in: 121-random-mutated.in
364
+ out: 121-random-mutated.ans
365
+ points: 1
366
+ - in: 122-random-mutated.in
367
+ out: 122-random-mutated.ans
368
+ points: 1
369
+ - in: 123-random-mutated.in
370
+ out: 123-random-mutated.ans
371
+ points: 1
372
+ - in: 124-random-mutated.in
373
+ out: 124-random-mutated.ans
374
+ points: 1
375
+ - in: 125-random-mutated.in
376
+ out: 125-random-mutated.ans
377
+ points: 1
378
+ - in: 126-random-mutated.in
379
+ out: 126-random-mutated.ans
380
+ points: 1
381
+ - in: 127-random-mutated.in
382
+ out: 127-random-mutated.ans
383
+ points: 1
384
+ - in: 128-random-mutated.in
385
+ out: 128-random-mutated.ans
386
+ points: 1
387
+ - in: 129-random-mutated.in
388
+ out: 129-random-mutated.ans
389
+ points: 1
390
+ - in: 130-random-mutated.in
391
+ out: 130-random-mutated.ans
392
+ points: 1
393
+ - in: 131-random-mutated.in
394
+ out: 131-random-mutated.ans
395
+ points: 1
396
+ - in: 132-random-mutated.in
397
+ out: 132-random-mutated.ans
398
+ points: 1
399
+ - in: 133-random-mutated.in
400
+ out: 133-random-mutated.ans
401
+ points: 1
402
+ - in: 134-random-mutated.in
403
+ out: 134-random-mutated.ans
404
+ points: 1
405
+ - in: 135-random-mutated.in
406
+ out: 135-random-mutated.ans
407
+ points: 1
408
+ - in: 136-random-mutated.in
409
+ out: 136-random-mutated.ans
410
+ points: 1
411
+ - in: 137-random-mutated.in
412
+ out: 137-random-mutated.ans
413
+ points: 1
414
+ - in: 138-random-mutated.in
415
+ out: 138-random-mutated.ans
416
+ points: 1
417
+ - in: 139-random-mutated.in
418
+ out: 139-random-mutated.ans
419
+ points: 1
420
+ - in: 140-random-mutated.in
421
+ out: 140-random-mutated.ans
422
+ points: 1
423
+ - in: 141-random-mutated.in
424
+ out: 141-random-mutated.ans
425
+ points: 1
426
+ - in: 142-random-mutated.in
427
+ out: 142-random-mutated.ans
428
+ points: 1
429
+ - in: 143-random-mutated.in
430
+ out: 143-random-mutated.ans
431
+ points: 1
432
+ - in: 144-random-mutated.in
433
+ out: 144-random-mutated.ans
434
+ points: 1
435
+ - in: 145-random-mutated.in
436
+ out: 145-random-mutated.ans
437
+ points: 1
438
+ - in: 146-random-mutated.in
439
+ out: 146-random-mutated.ans
440
+ points: 1
441
+ - in: 147-random-mutated.in
442
+ out: 147-random-mutated.ans
443
+ points: 1
444
+ - in: 148-random-mutated.in
445
+ out: 148-random-mutated.ans
446
+ points: 1
447
+ - in: 149-random-mutated.in
448
+ out: 149-random-mutated.ans
449
+ points: 1
450
+ - in: 150-random-mutated.in
451
+ out: 150-random-mutated.ans
452
+ points: 1
453
+ - in: 151-random-mutated.in
454
+ out: 151-random-mutated.ans
455
+ points: 1
456
+ - in: 152-random-mutated.in
457
+ out: 152-random-mutated.ans
458
+ points: 1
459
+ - in: 153-random-mutated.in
460
+ out: 153-random-mutated.ans
461
+ points: 1
462
+ - in: 154-random-mutated.in
463
+ out: 154-random-mutated.ans
464
+ points: 1
465
+ - in: 155-random-mutated.in
466
+ out: 155-random-mutated.ans
467
+ points: 1
468
+ - in: 156-random-mutated.in
469
+ out: 156-random-mutated.ans
470
+ points: 1
471
+ - in: 157-random-mutated.in
472
+ out: 157-random-mutated.ans
473
+ points: 1
474
+ - in: 158-random-mutated.in
475
+ out: 158-random-mutated.ans
476
+ points: 1
477
+ - in: 159-random-mutated.in
478
+ out: 159-random-mutated.ans
479
+ points: 1
480
+ - in: 160-random-mutated.in
481
+ out: 160-random-mutated.ans
482
+ points: 1
483
+ - in: 161-random-mutated.in
484
+ out: 161-random-mutated.ans
485
+ points: 1
486
+ - in: 162-random-mutated.in
487
+ out: 162-random-mutated.ans
488
+ points: 1
489
+ - in: 163-random-mutated.in
490
+ out: 163-random-mutated.ans
491
+ points: 1
ICPC/nwerc2022_L/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99155e33e1631315454d4789cc8de5c8534227e940264de6ce0dbbcfef1fa4e4
3
+ size 1388307
ICPC/nwerc2022_L/init.yml ADDED
@@ -0,0 +1,496 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ checker:
3
+ args:
4
+ files:
5
+ - output_validators/validate/output-validator.cc
6
+ - output_validators/validate/validation.h
7
+ lang: CPP17
8
+ type: default
9
+ name: bridged
10
+ test_cases:
11
+ - in: 001-anti-two-step.in
12
+ out: 001-anti-two-step.ans
13
+ points: 1
14
+ - in: 002-anti-two-step.in
15
+ out: 002-anti-two-step.ans
16
+ points: 1
17
+ - in: 003-anti-two-step.in
18
+ out: 003-anti-two-step.ans
19
+ points: 1
20
+ - in: 004-anti-two-step.in
21
+ out: 004-anti-two-step.ans
22
+ points: 1
23
+ - in: 005-slack.in
24
+ out: 005-slack.ans
25
+ points: 1
26
+ - in: 006-slack.in
27
+ out: 006-slack.ans
28
+ points: 1
29
+ - in: 007-slack.in
30
+ out: 007-slack.ans
31
+ points: 1
32
+ - in: 008-multi-triangle.in
33
+ out: 008-multi-triangle.ans
34
+ points: 1
35
+ - in: 009-multi-triangle.in
36
+ out: 009-multi-triangle.ans
37
+ points: 1
38
+ - in: 010-multi-triangle.in
39
+ out: 010-multi-triangle.ans
40
+ points: 1
41
+ - in: 011-spanning-tree.in
42
+ out: 011-spanning-tree.ans
43
+ points: 1
44
+ - in: 012-spanning-tree.in
45
+ out: 012-spanning-tree.ans
46
+ points: 1
47
+ - in: 013-spanning-tree.in
48
+ out: 013-spanning-tree.ans
49
+ points: 1
50
+ - in: 014-random.in
51
+ out: 014-random.ans
52
+ points: 1
53
+ - in: 015-random.in
54
+ out: 015-random.ans
55
+ points: 1
56
+ - in: 016-random.in
57
+ out: 016-random.ans
58
+ points: 1
59
+ - in: 017-random.in
60
+ out: 017-random.ans
61
+ points: 1
62
+ - in: 018-random.in
63
+ out: 018-random.ans
64
+ points: 1
65
+ - in: 019-random.in
66
+ out: 019-random.ans
67
+ points: 1
68
+ - in: 020-random.in
69
+ out: 020-random.ans
70
+ points: 1
71
+ - in: 021-random.in
72
+ out: 021-random.ans
73
+ points: 1
74
+ - in: 022-random.in
75
+ out: 022-random.ans
76
+ points: 1
77
+ - in: 023-random.in
78
+ out: 023-random.ans
79
+ points: 1
80
+ - in: 024-random.in
81
+ out: 024-random.ans
82
+ points: 1
83
+ - in: 025-random.in
84
+ out: 025-random.ans
85
+ points: 1
86
+ - in: 026-random.in
87
+ out: 026-random.ans
88
+ points: 1
89
+ - in: 027-random.in
90
+ out: 027-random.ans
91
+ points: 1
92
+ - in: 028-random.in
93
+ out: 028-random.ans
94
+ points: 1
95
+ - in: 029-random.in
96
+ out: 029-random.ans
97
+ points: 1
98
+ - in: 030-random-no-green.in
99
+ out: 030-random-no-green.ans
100
+ points: 1
101
+ - in: 031-random-no-green.in
102
+ out: 031-random-no-green.ans
103
+ points: 1
104
+ - in: 032-random-no-green.in
105
+ out: 032-random-no-green.ans
106
+ points: 1
107
+ - in: 033-random-no-green.in
108
+ out: 033-random-no-green.ans
109
+ points: 1
110
+ - in: 034-random-no-green.in
111
+ out: 034-random-no-green.ans
112
+ points: 1
113
+ - in: 035-random-no-green.in
114
+ out: 035-random-no-green.ans
115
+ points: 1
116
+ - in: 036-random-no-green.in
117
+ out: 036-random-no-green.ans
118
+ points: 1
119
+ - in: 037-random-no-green.in
120
+ out: 037-random-no-green.ans
121
+ points: 1
122
+ - in: 038-random-no-green.in
123
+ out: 038-random-no-green.ans
124
+ points: 1
125
+ - in: 039-random-no-green.in
126
+ out: 039-random-no-green.ans
127
+ points: 1
128
+ - in: 040-random-no-green.in
129
+ out: 040-random-no-green.ans
130
+ points: 1
131
+ - in: 041-random-no-green.in
132
+ out: 041-random-no-green.ans
133
+ points: 1
134
+ - in: 042-random-no-green.in
135
+ out: 042-random-no-green.ans
136
+ points: 1
137
+ - in: 043-random-no-green.in
138
+ out: 043-random-no-green.ans
139
+ points: 1
140
+ - in: 044-separate-greens.in
141
+ out: 044-separate-greens.ans
142
+ points: 1
143
+ - in: 045-all-black.in
144
+ out: 045-all-black.ans
145
+ points: 1
146
+ - in: 046-all-black.in
147
+ out: 046-all-black.ans
148
+ points: 1
149
+ - in: 047-all-black.in
150
+ out: 047-all-black.ans
151
+ points: 1
152
+ - in: 048-all-black.in
153
+ out: 048-all-black.ans
154
+ points: 1
155
+ - in: 049-all-black.in
156
+ out: 049-all-black.ans
157
+ points: 1
158
+ - in: 050-all-black.in
159
+ out: 050-all-black.ans
160
+ points: 1
161
+ - in: 051-manual.in
162
+ out: 051-manual.ans
163
+ points: 1
164
+ - in: 052-manual.in
165
+ out: 052-manual.ans
166
+ points: 1
167
+ - in: 053-manual.in
168
+ out: 053-manual.ans
169
+ points: 1
170
+ - in: 054-manual.in
171
+ out: 054-manual.ans
172
+ points: 1
173
+ - in: 055-manual.in
174
+ out: 055-manual.ans
175
+ points: 1
176
+ - in: 056-manual.in
177
+ out: 056-manual.ans
178
+ points: 1
179
+ - in: 057-english.in
180
+ out: 057-english.ans
181
+ points: 1
182
+ - in: 058-english.in
183
+ out: 058-english.ans
184
+ points: 1
185
+ - in: 059-all-yellow.in
186
+ out: 059-all-yellow.ans
187
+ points: 1
188
+ - in: 060-all-yellow.in
189
+ out: 060-all-yellow.ans
190
+ points: 1
191
+ - in: 061-all-yellow.in
192
+ out: 061-all-yellow.ans
193
+ points: 1
194
+ - in: 062-all-yellow.in
195
+ out: 062-all-yellow.ans
196
+ points: 1
197
+ - in: 063-all-yellow.in
198
+ out: 063-all-yellow.ans
199
+ points: 1
200
+ - in: 064-all-yellow.in
201
+ out: 064-all-yellow.ans
202
+ points: 1
203
+ - in: 065-all-yellow.in
204
+ out: 065-all-yellow.ans
205
+ points: 1
206
+ - in: 066-all-yellow.in
207
+ out: 066-all-yellow.ans
208
+ points: 1
209
+ - in: 067-all-yellow.in
210
+ out: 067-all-yellow.ans
211
+ points: 1
212
+ - in: 068-all-yellow.in
213
+ out: 068-all-yellow.ans
214
+ points: 1
215
+ - in: 069-all-yellow.in
216
+ out: 069-all-yellow.ans
217
+ points: 1
218
+ - in: 070-all-yellow.in
219
+ out: 070-all-yellow.ans
220
+ points: 1
221
+ - in: 071-all-yellow.in
222
+ out: 071-all-yellow.ans
223
+ points: 1
224
+ - in: 072-all-yellow.in
225
+ out: 072-all-yellow.ans
226
+ points: 1
227
+ - in: 073-all-yellow.in
228
+ out: 073-all-yellow.ans
229
+ points: 1
230
+ - in: 074-black-and-green.in
231
+ out: 074-black-and-green.ans
232
+ points: 1
233
+ - in: 075-black-and-green.in
234
+ out: 075-black-and-green.ans
235
+ points: 1
236
+ - in: 076-black-and-green.in
237
+ out: 076-black-and-green.ans
238
+ points: 1
239
+ - in: 077-black-and-green.in
240
+ out: 077-black-and-green.ans
241
+ points: 1
242
+ - in: 078-black-and-green.in
243
+ out: 078-black-and-green.ans
244
+ points: 1
245
+ - in: 079-black-and-green.in
246
+ out: 079-black-and-green.ans
247
+ points: 1
248
+ - in: 080-black-and-green.in
249
+ out: 080-black-and-green.ans
250
+ points: 1
251
+ - in: 081-black-and-green.in
252
+ out: 081-black-and-green.ans
253
+ points: 1
254
+ - in: 082-black-and-green.in
255
+ out: 082-black-and-green.ans
256
+ points: 1
257
+ - in: 083-black-and-green.in
258
+ out: 083-black-and-green.ans
259
+ points: 1
260
+ - in: 084-rotate.in
261
+ out: 084-rotate.ans
262
+ points: 1
263
+ - in: 085-split.in
264
+ out: 085-split.ans
265
+ points: 1
266
+ - in: 086-split.in
267
+ out: 086-split.ans
268
+ points: 1
269
+ - in: 087-split.in
270
+ out: 087-split.ans
271
+ points: 1
272
+ - in: 088-incremental.in
273
+ out: 088-incremental.ans
274
+ points: 1
275
+ - in: 089-incremental.in
276
+ out: 089-incremental.ans
277
+ points: 1
278
+ - in: 090-incremental.in
279
+ out: 090-incremental.ans
280
+ points: 1
281
+ - in: 091-incremental.in
282
+ out: 091-incremental.ans
283
+ points: 1
284
+ - in: 092-incremental.in
285
+ out: 092-incremental.ans
286
+ points: 1
287
+ - in: 093-incremental.in
288
+ out: 093-incremental.ans
289
+ points: 1
290
+ - in: 094-incremental.in
291
+ out: 094-incremental.ans
292
+ points: 1
293
+ - in: 095-fuzz.in
294
+ out: 095-fuzz.ans
295
+ points: 1
296
+ - in: 096-slack.in
297
+ out: 096-slack.ans
298
+ points: 1
299
+ - in: 097-slack.in
300
+ out: 097-slack.ans
301
+ points: 1
302
+ - in: 098-slack.in
303
+ out: 098-slack.ans
304
+ points: 1
305
+ - in: 099-slack.in
306
+ out: 099-slack.ans
307
+ points: 1
308
+ - in: 100-triangle.in
309
+ out: 100-triangle.ans
310
+ points: 1
311
+ - in: 101-fuzz.in
312
+ out: 101-fuzz.ans
313
+ points: 1
314
+ - in: 102-fuzz.in
315
+ out: 102-fuzz.ans
316
+ points: 1
317
+ - in: 103-fuzz.in
318
+ out: 103-fuzz.ans
319
+ points: 1
320
+ - in: 104-fuzz.in
321
+ out: 104-fuzz.ans
322
+ points: 1
323
+ - in: 105-fuzz.in
324
+ out: 105-fuzz.ans
325
+ points: 1
326
+ - in: 106-fuzz.in
327
+ out: 106-fuzz.ans
328
+ points: 1
329
+ - in: 107-fuzz.in
330
+ out: 107-fuzz.ans
331
+ points: 1
332
+ - in: 108-fuzz.in
333
+ out: 108-fuzz.ans
334
+ points: 1
335
+ - in: 109-fuzz.in
336
+ out: 109-fuzz.ans
337
+ points: 1
338
+ - in: 110-fuzz.in
339
+ out: 110-fuzz.ans
340
+ points: 1
341
+ - in: 111-fuzz.in
342
+ out: 111-fuzz.ans
343
+ points: 1
344
+ - in: 112-fuzz.in
345
+ out: 112-fuzz.ans
346
+ points: 1
347
+ - in: 113-fuzz.in
348
+ out: 113-fuzz.ans
349
+ points: 1
350
+ - in: 114-fuzz.in
351
+ out: 114-fuzz.ans
352
+ points: 1
353
+ - in: 115-fuzz.in
354
+ out: 115-fuzz.ans
355
+ points: 1
356
+ - in: 116-fuzz.in
357
+ out: 116-fuzz.ans
358
+ points: 1
359
+ - in: 117-fuzz.in
360
+ out: 117-fuzz.ans
361
+ points: 1
362
+ - in: 118-fuzz.in
363
+ out: 118-fuzz.ans
364
+ points: 1
365
+ - in: 119-fuzz.in
366
+ out: 119-fuzz.ans
367
+ points: 1
368
+ - in: 120-fuzz.in
369
+ out: 120-fuzz.ans
370
+ points: 1
371
+ - in: 121-fuzz.in
372
+ out: 121-fuzz.ans
373
+ points: 1
374
+ - in: 122-fuzz.in
375
+ out: 122-fuzz.ans
376
+ points: 1
377
+ - in: 123-fuzz.in
378
+ out: 123-fuzz.ans
379
+ points: 1
380
+ - in: 124-fuzz.in
381
+ out: 124-fuzz.ans
382
+ points: 1
383
+ - in: 125-fuzz.in
384
+ out: 125-fuzz.ans
385
+ points: 1
386
+ - in: 126-fuzz.in
387
+ out: 126-fuzz.ans
388
+ points: 1
389
+ - in: 127-fuzz.in
390
+ out: 127-fuzz.ans
391
+ points: 1
392
+ - in: 128-fuzz.in
393
+ out: 128-fuzz.ans
394
+ points: 1
395
+ - in: 129-fuzz.in
396
+ out: 129-fuzz.ans
397
+ points: 1
398
+ - in: 130-fuzz.in
399
+ out: 130-fuzz.ans
400
+ points: 1
401
+ - in: 131-fuzz.in
402
+ out: 131-fuzz.ans
403
+ points: 1
404
+ - in: 132-fuzz.in
405
+ out: 132-fuzz.ans
406
+ points: 1
407
+ - in: 133-fuzz.in
408
+ out: 133-fuzz.ans
409
+ points: 1
410
+ - in: 134-fuzz.in
411
+ out: 134-fuzz.ans
412
+ points: 1
413
+ - in: 135-fuzz.in
414
+ out: 135-fuzz.ans
415
+ points: 1
416
+ - in: 136-fuzz.in
417
+ out: 136-fuzz.ans
418
+ points: 1
419
+ - in: 137-fuzz.in
420
+ out: 137-fuzz.ans
421
+ points: 1
422
+ - in: 138-fuzz.in
423
+ out: 138-fuzz.ans
424
+ points: 1
425
+ - in: 139-fuzz.in
426
+ out: 139-fuzz.ans
427
+ points: 1
428
+ - in: 140-fuzz.in
429
+ out: 140-fuzz.ans
430
+ points: 1
431
+ - in: 141-fuzz.in
432
+ out: 141-fuzz.ans
433
+ points: 1
434
+ - in: 142-fuzz.in
435
+ out: 142-fuzz.ans
436
+ points: 1
437
+ - in: 143-fuzz.in
438
+ out: 143-fuzz.ans
439
+ points: 1
440
+ - in: 144-fuzz.in
441
+ out: 144-fuzz.ans
442
+ points: 1
443
+ - in: 145-fuzz.in
444
+ out: 145-fuzz.ans
445
+ points: 1
446
+ - in: 146-fuzz.in
447
+ out: 146-fuzz.ans
448
+ points: 1
449
+ - in: 147-fuzz.in
450
+ out: 147-fuzz.ans
451
+ points: 1
452
+ - in: 148-fuzz.in
453
+ out: 148-fuzz.ans
454
+ points: 1
455
+ - in: 149-fuzz.in
456
+ out: 149-fuzz.ans
457
+ points: 1
458
+ - in: 150-fuzz.in
459
+ out: 150-fuzz.ans
460
+ points: 1
461
+ - in: 151-fuzz.in
462
+ out: 151-fuzz.ans
463
+ points: 1
464
+ - in: 152-fuzz.in
465
+ out: 152-fuzz.ans
466
+ points: 1
467
+ - in: 153-fuzz.in
468
+ out: 153-fuzz.ans
469
+ points: 1
470
+ - in: 154-fuzz.in
471
+ out: 154-fuzz.ans
472
+ points: 1
473
+ - in: 155-fuzz.in
474
+ out: 155-fuzz.ans
475
+ points: 1
476
+ - in: 156-fuzz.in
477
+ out: 156-fuzz.ans
478
+ points: 1
479
+ - in: 157-fuzz.in
480
+ out: 157-fuzz.ans
481
+ points: 1
482
+ - in: 158-anti-two-step.in
483
+ out: 158-anti-two-step.ans
484
+ points: 1
485
+ - in: 159-anti-two-step.in
486
+ out: 159-anti-two-step.ans
487
+ points: 1
488
+ - in: 160-anti-two-step.in
489
+ out: 160-anti-two-step.ans
490
+ points: 1
491
+ - in: 161-anti-two-step.in
492
+ out: 161-anti-two-step.ans
493
+ points: 1
494
+ - in: 162-anti-two-step.in
495
+ out: 162-anti-two-step.ans
496
+ points: 1
ICPC/nwerc2022_L/output_validators/validate/output-validator.cc ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #include<cstdlib>
3
+ int qwerty_getcode(int code) {
4
+ return code == 42? 0: 1;
5
+ }
6
+ namespace std {
7
+ void qwerty_exit(int code){
8
+ exit(qwerty_getcode(code));
9
+ }
10
+ } using std::qwerty_exit;
11
+ #define exit qwerty_exit
12
+ #define main qwerty_main
13
+ #include <iostream>
14
+ #include <cassert>
15
+ #include "validation.h"
16
+
17
+ std::string wordle_query(std::string query, std::string answer) {
18
+ int n = std::size(query);
19
+ std::string res(n, 'B');
20
+
21
+ std::array<int,26> count = {};
22
+ for (char c: answer) count[c-'a']++;
23
+
24
+ // place green tiles
25
+ for (int i = 0; i < n; i++) {
26
+ if (query[i] == answer[i]) {
27
+ res[i] = 'G';
28
+ count[query[i]-'a']--;
29
+ }
30
+ }
31
+
32
+ // place yellow tiles
33
+ for (int i = 0; i < n; i++) {
34
+ if (res[i] != 'G' && count[query[i]-'a'] > 0) {
35
+ count[query[i]-'a']--;
36
+ res[i] = 'Y';
37
+ }
38
+ }
39
+
40
+ return res;
41
+ }
42
+
43
+ int main(int argc, char **argv) {
44
+ std::ifstream in(argv[1]);
45
+ OutputValidator v(argc, argv);
46
+
47
+ int m, n;
48
+ in >> m >> n;
49
+
50
+ std::vector<std::string> words(m-1), colors(m-1);
51
+ for (int i = 0; i < m-1; i++) {
52
+ in >> words[i] >> colors[i];
53
+ }
54
+
55
+ std::string all_letters = std::string(26, 'a') + std::string(26, 'A');
56
+ for (int i = 0; i < 26; i++) {
57
+ all_letters[i] += i;
58
+ all_letters[26+i] += i;
59
+ }
60
+
61
+ // TODO: extend validation.h with case insensitivity?
62
+ std::string answer = v.read_string("word", n, n, all_letters);
63
+ for (char& c : answer) c |= 0x20;
64
+ v.newline();
65
+
66
+ for (int i = 0; i < m-1; i++) {
67
+ v.check(wordle_query(words[i], answer) == colors[i],
68
+ "Wrong answer: does not fit word ", i);
69
+ }
70
+ }
71
+
72
+ #undef main
73
+ #include<cstdio>
74
+ #include<vector>
75
+ #include<string>
76
+ #include<filesystem>
77
+ int main(int argc, char **argv) {
78
+ namespace fs = std::filesystem;
79
+ freopen(argv[2], "r", stdin);
80
+ char judge_out[] = "/dev";
81
+ std::vector<char*> new_argv = {
82
+ argv[0], argv[1], argv[3],
83
+ judge_out,
84
+ };
85
+ return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data()));
86
+ }
ICPC/nwerc2022_L/output_validators/validate/validation.h ADDED
@@ -0,0 +1,1520 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ // A header library to safely parse team input.
3
+ // It does not support floating points or big integers.
4
+ // Author: Ragnar Groot Koerkamp
5
+
6
+ // The easiest way to use this is to symlink it from a validator directory,
7
+ // so that it will be picked up when creating a contest zip.
8
+
9
+ // The default checking behaviour is lenient for both white space and case.
10
+ // When validating .in and .ans files, the case_sensitive and
11
+ // space_change_sensitive flags should be passed. When validating team output,
12
+ // the flags in problem.yaml should be used.
13
+
14
+ // Compile with -Duse_source_location to enable
15
+ // std::experimental::source_location. This is needed for constraints checking.
16
+
17
+ #include <algorithm>
18
+ #include <array>
19
+ #include <bitset>
20
+ #include <cassert>
21
+ #include <charconv>
22
+ #include <cstring>
23
+ #include <fstream>
24
+ #include <functional>
25
+ #include <iomanip>
26
+ #include <iostream>
27
+ #include <limits>
28
+ #include <map>
29
+ #include <optional>
30
+ #include <random>
31
+ #include <set>
32
+ #include <stdexcept>
33
+ #include <string>
34
+ #include <string_view>
35
+ #include <type_traits>
36
+ #include <unordered_map>
37
+ #include <utility>
38
+ #include <variant>
39
+ #include <vector>
40
+
41
+ #ifdef use_source_location
42
+ #include <experimental/source_location>
43
+ constexpr bool has_source_location = true;
44
+ using std::experimental::source_location;
45
+ namespace std {
46
+ bool operator<(const source_location& l, const source_location& r) {
47
+ return l.line() < r.line();
48
+ }
49
+ } // namespace std
50
+ namespace std::experimental::fundamentals_v2 {
51
+ bool operator<(const source_location& l, const source_location& r) {
52
+ return l.line() < r.line();
53
+ }
54
+ } // namespace std::experimental::fundamentals_v2
55
+ #else
56
+ constexpr bool has_source_location = false;
57
+ struct source_location {
58
+ static source_location current() { return {}; }
59
+ [[nodiscard]] int line() const { return 0; } // NOLINT
60
+ [[nodiscard]] std::string file_name() const { return ""; } // NOLINT
61
+ };
62
+ inline bool operator<(const source_location& l, const source_location& r) {
63
+ return l.line() < r.line();
64
+ }
65
+ #endif
66
+
67
+ inline std::string location_to_string(source_location loc) {
68
+ return std::string(loc.file_name()) + ":" + std::to_string(loc.line());
69
+ }
70
+
71
+ const std::string_view case_sensitive_flag = "case_sensitive";
72
+ const std::string_view ws_sensitive_flag = "space_change_sensitive";
73
+ const std::string_view constraints_file_flag = "--constraints_file";
74
+ const std::string_view generate_flag = "--generate";
75
+ const std::string_view generate_binary_substring = "generat";
76
+
77
+ inline struct ArbitraryTag {
78
+ static constexpr bool unique = false;
79
+ static constexpr bool strict = false;
80
+ static constexpr bool increasing = false;
81
+ static constexpr bool decreasing = false;
82
+ } Arbitrary;
83
+ inline struct UniqueTag : ArbitraryTag {
84
+ static constexpr bool unique = true;
85
+ static constexpr bool strict = false;
86
+ static constexpr bool increasing = false;
87
+ static constexpr bool decreasing = false;
88
+ } Unique;
89
+ inline struct IncreasingTag : ArbitraryTag { static constexpr bool increasing = true; } Increasing;
90
+ inline struct DecreasingTag : ArbitraryTag { static constexpr bool decreasing = true; } Decreasing;
91
+ inline struct StrictlyIncreasingTag : ArbitraryTag {
92
+ static constexpr bool strict = true;
93
+ static constexpr bool increasing = true;
94
+ } StrictlyIncreasing;
95
+ inline struct StrictlyDecreasingTag : ArbitraryTag {
96
+ static constexpr bool strict = true;
97
+ static constexpr bool decreasing = true;
98
+ } StrictlyDecreasing;
99
+
100
+ template <typename... T>
101
+ struct Merge : T... {
102
+ static constexpr bool unique = (T::unique || ...);
103
+ static constexpr bool strict = (T::strict || ...);
104
+ static constexpr bool increasing = (T::increasing || ...);
105
+ static constexpr bool decreasing = (T::decreasing || ...);
106
+ };
107
+
108
+ template <typename T1, typename T2,
109
+ std::enable_if_t<
110
+ std::is_base_of_v<ArbitraryTag, T1> and std::is_base_of_v<ArbitraryTag, T2>, int> = 0>
111
+ auto operator|(T1 /*unused*/, T2 /*unused*/) {
112
+ return Merge<T1, T2>();
113
+ }
114
+
115
+ enum Separator { Space, Newline };
116
+
117
+ // this contains some specific code which emulates c++20 features
118
+ namespace cpp20 {
119
+
120
+ constexpr int countl_zero(unsigned long long x) {
121
+ int res = 64;
122
+ for(int i = 32; i > 0; i >>= 1) {
123
+ if((x >> i) > 0) {
124
+ res -= i;
125
+ x >>= i;
126
+ }
127
+ }
128
+ if(x > 0) res--;
129
+ return res;
130
+ }
131
+
132
+ int popcount(unsigned long long x) {
133
+ return static_cast<int>(std::bitset<64>(x).count());
134
+ }
135
+
136
+ constexpr long double PI = 3.141592653589793238462643383279502884l;
137
+
138
+ } // namespace cpp20
139
+
140
+ namespace Random {
141
+
142
+ constexpr unsigned int default_seed = 3141592653; // some digits of PI
143
+
144
+ unsigned long long bits64(std::mt19937_64& rng) {
145
+ static_assert(std::mt19937_64::max() == 0xFFFF'FFFF'FFFF'FFFFull);
146
+ static_assert(std::mt19937_64::min() == 0ull);
147
+ return rng();
148
+ }
149
+
150
+ // generates a uniform real in [0, 1)
151
+ long double real64(std::mt19937_64& rng) {
152
+ // a long double can represent more than 2^64 values in the range [0, 1)...
153
+ // another problem is that real64() < 1.0/3.0 is technically biased.
154
+ long double res = bits64(rng) / 0x1.0p64l;
155
+ res += bits64(rng) / 0x1.0p128l;
156
+ assert(res < 1.0l);
157
+ return res;
158
+ }
159
+
160
+ bool bit(std::mt19937_64& rng) {
161
+ return cpp20::popcount(bits64(rng)) & 1;
162
+ }
163
+
164
+ } // namespace Random
165
+
166
+ template <typename T>
167
+ constexpr bool is_number_v = std::is_same_v<T, long long> or std::is_same_v<T, long double>;
168
+
169
+ namespace Generators {
170
+
171
+ template <typename T>
172
+ struct ConstGenerator {
173
+ static_assert(is_number_v<T> or std::is_same_v<T, char> or std::is_same_v<T, std::string>);
174
+ static constexpr std::string_view name = "const";
175
+ using Args = std::tuple<T>;
176
+
177
+ const T const_;
178
+
179
+ explicit ConstGenerator(T val) : const_(std::move(val)) {}
180
+
181
+ // For char and string, the constant store has a different type than the min and max length
182
+ // passed in.
183
+ template <typename U>
184
+ T operator()(U low, U high, std::mt19937_64& rng) const {
185
+ return std::clamp(const_, low, high);
186
+ }
187
+ };
188
+
189
+ struct MinGenerator {
190
+ static constexpr std::string_view name = "min";
191
+ using Args = std::tuple<>;
192
+
193
+ explicit MinGenerator() = default;
194
+
195
+ template <typename T>
196
+ T operator()(T low, T high, std::mt19937_64& rng) const {
197
+ static_assert(is_number_v<T>);
198
+ return low;
199
+ }
200
+ };
201
+
202
+ struct MaxGenerator {
203
+ static constexpr std::string_view name = "max";
204
+ using Args = std::tuple<>;
205
+
206
+ explicit MaxGenerator() = default;
207
+
208
+ template <typename T>
209
+ T operator()(T low, T high, std::mt19937_64& rng) const {
210
+ static_assert(is_number_v<T>);
211
+ return high;
212
+ }
213
+ };
214
+
215
+ struct UniformGenerator {
216
+ static constexpr std::string_view name = "uniform";
217
+ using Args = std::tuple<>;
218
+
219
+ explicit UniformGenerator() = default;
220
+
221
+ template <typename T>
222
+ T operator()(T low, T high, std::mt19937_64& rng) const {
223
+ static_assert(is_number_v<T>);
224
+ if(low == high) return low;
225
+
226
+ if constexpr(std::is_same_v<T, long long>) {
227
+ assert(low < high);
228
+ // Since C++20 we can assume Two's Complement but any sane system used it before anyway.
229
+ // Rejection sampling is not as fast as possible but definitely unbiased.
230
+ auto ul = static_cast<unsigned long long>(low);
231
+ auto uh = static_cast<unsigned long long>(high);
232
+ int shifts = cpp20::countl_zero(uh - ul);
233
+ unsigned long long res;
234
+ do {
235
+ res = Random::bits64(rng) >> shifts;
236
+ } while(res > uh - ul);
237
+ return static_cast<long long>(res + ul);
238
+ } else {
239
+ assert(low < high);
240
+ return low + Random::real64(rng) * (high - low);
241
+ }
242
+ }
243
+ };
244
+
245
+ template <typename T>
246
+ struct RangeGenerator {
247
+ static_assert(is_number_v<T>);
248
+ static constexpr std::string_view name = "range";
249
+ using Args = std::tuple<T, T>;
250
+
251
+ const T low_, high_;
252
+
253
+ explicit RangeGenerator(T low, T high) : low_(low), high_(high) {}
254
+
255
+ T operator()(T low, T high, std::mt19937_64& rng) const {
256
+ return UniformGenerator()(std::max(low, low_), std::min(high, high_), rng);
257
+ }
258
+ };
259
+
260
+ template <typename T>
261
+ struct StepRangeGenerator {
262
+ static_assert(is_number_v<T>);
263
+ static constexpr std::string_view name = "steprange";
264
+ using Args = std::tuple<T, T, T>;
265
+
266
+ const T low_, high_, step_;
267
+
268
+ explicit StepRangeGenerator(T low, T high, T step) : low_(low), high_(high), step_(step) {}
269
+
270
+ T operator()(T low, T high, std::mt19937_64& rng) const {
271
+ // round up low to the first multiple of step_.
272
+ T start;
273
+ if(low <= low_) {
274
+ start = low_;
275
+ } else {
276
+ // first multiple of low_+k*step_ >= low
277
+ start = low_ + (long long)((low - low_) / step_) * step_;
278
+ if(start < low) start += step_;
279
+ assert(low <= start && start < low + step_);
280
+ }
281
+ long long maxsteps = (std::min(high, high_) - start) / step_;
282
+ long long steps = UniformGenerator()(0ll, maxsteps, rng);
283
+ return start + steps * step_;
284
+ }
285
+ };
286
+
287
+ struct NormalDistributionGenerator {
288
+ static constexpr std::string_view name = "normal";
289
+ using T = long double;
290
+ using Args = std::tuple<T, T>;
291
+
292
+ const T mean_, stddev_;
293
+
294
+ explicit NormalDistributionGenerator(T mean, T stddev) : mean_(mean), stddev_(stddev) {
295
+ assert(stddev_ >= 0);
296
+ }
297
+
298
+ // NOTE: Currently this retries instead of clamping to the interval.
299
+ T operator()(T low, T high, std::mt19937_64& rng) const {
300
+ assert(low < high);
301
+ T v;
302
+ while(true) {
303
+ T u1 = Random::real64(rng);
304
+ T u2 = Random::real64(rng);
305
+ // Box-Muller-Methode
306
+ // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
307
+ v = std::sqrt(-2.0l * std::log(u1)) * std::cos(2.0l * cpp20::PI * u2);
308
+ v = std::sqrt(stddev_) * v + mean_;
309
+ if(v >= low && v < high) return v;
310
+ v = std::sqrt(-2.0l * std::log(u1)) * std::sin(2.0l * cpp20::PI * u2);
311
+ v = std::sqrt(stddev_) * v + mean_;
312
+ if(v >= low && v < high) return v;
313
+ }
314
+ return v;
315
+ }
316
+ };
317
+
318
+ struct ExponentialDistributionGenerator {
319
+ static constexpr std::string_view name = "exponential";
320
+ using T = long double;
321
+ using Args = std::tuple<T>;
322
+
323
+ T lambda_;
324
+
325
+ explicit ExponentialDistributionGenerator(T lambda) : lambda_(lambda) { assert(lambda_ > 0); }
326
+
327
+ // NOTE: Currently this retries instead of clamping to the interval.
328
+ T operator()(T low, T high, std::mt19937_64& rng) const {
329
+ assert(low < high);
330
+ T v;
331
+ while(true) {
332
+ v = low - std::log(Random::real64(rng)) / lambda_;
333
+ if(v < high) return v;
334
+ }
335
+ }
336
+ };
337
+
338
+ struct GeometricDistributionGenerator {
339
+ static constexpr std::string_view name = "geometric";
340
+ using T = long long;
341
+ using Args = std::tuple<long double>;
342
+
343
+ double p_;
344
+
345
+ explicit GeometricDistributionGenerator(double p) : p_(p) {
346
+ assert(p_ > 0);
347
+ assert(p_ < 1);
348
+ }
349
+
350
+ // NOTE: Currently this retries instead of clamping to the interval.
351
+ T operator()(T low, T high, std::mt19937_64& rng) const {
352
+ assert(low <= high);
353
+ T v;
354
+ while(true) {
355
+ // https://en.wikipedia.org/wiki/Geometric_distribution
356
+ // "The exponential distribution is the continuous analogue of the geometric
357
+ // distribution[...]"
358
+ v = low + std::floor(std::log(Random::real64(rng)) / std::log1p(-p_));
359
+ if(v <= high) return v;
360
+ }
361
+ }
362
+ };
363
+
364
+ struct BinomialDistributionGenerator {
365
+ static constexpr std::string_view name = "binomial";
366
+ using T = long long;
367
+ using Args = std::tuple<long long, long double>;
368
+
369
+ long long n_;
370
+ double p_;
371
+
372
+ explicit BinomialDistributionGenerator(long long n, double p) : n_(n), p_(p) {
373
+ assert(p_ >= 0);
374
+ assert(p_ <= 1);
375
+ std::cerr << "Warning: Large n (" << n_ << ") is slow for BinomialDistributionGenerator!"
376
+ << std::endl;
377
+ }
378
+
379
+ // NOTE: Currently this retries instead of clamping to the interval.
380
+ T operator()(T low, T high, std::mt19937_64& rng) const {
381
+ assert(low <= high);
382
+ // this will be slow for large n
383
+ // (a faster implementation requires efficient poisson sampling)
384
+ while(true) {
385
+ T v = 0;
386
+ for(long long i = 0; i < n_; i++) {
387
+ v += Random::real64(rng) < p_ ? 1 : 0;
388
+ }
389
+ if(v >= low && v <= high) return v;
390
+ }
391
+ }
392
+ };
393
+
394
+ template <typename T>
395
+ struct ChoiceGenerator {
396
+ using GeneratorType = std::conditional_t<
397
+ std::is_same_v<T, long long>,
398
+ std::variant<ConstGenerator<T>, MinGenerator, MaxGenerator, UniformGenerator,
399
+ RangeGenerator<T>, StepRangeGenerator<T>, GeometricDistributionGenerator,
400
+ BinomialDistributionGenerator>,
401
+ std::variant<ConstGenerator<T>, MinGenerator, MaxGenerator, UniformGenerator,
402
+ RangeGenerator<T>, StepRangeGenerator<T>, NormalDistributionGenerator,
403
+ ExponentialDistributionGenerator>>;
404
+
405
+ std::vector<std::pair<GeneratorType, double>> generators_;
406
+ double total_weight_;
407
+
408
+ template <typename>
409
+ struct Pack {};
410
+
411
+ template <typename A>
412
+ static A parse_number(std::string_view s) {
413
+ static_assert(is_number_v<A>);
414
+ if constexpr(std::is_same_v<A, long long>)
415
+ return stoll(std::string(s));
416
+ else
417
+ return stold(std::string(s));
418
+ }
419
+
420
+ template <typename A>
421
+ static A parse_argument(std::string_view& s) {
422
+ auto end = s.find_first_of(",)");
423
+ assert(end != std::string_view::npos);
424
+ auto v = parse_number<A>(s.substr(0, end));
425
+ s.remove_prefix(end);
426
+ // Pop the trailing , or )
427
+ s.remove_prefix(1);
428
+ return v;
429
+ }
430
+
431
+ template <typename... As>
432
+ static std::tuple<As...> parse_arguments(std::string_view& s,
433
+ Pack<std::tuple<As...>> /*unused*/) {
434
+ std::tuple<As...> args{parse_argument<As>(s)...};
435
+ return args;
436
+ }
437
+
438
+ // Try parsing one generator type from the start of s.
439
+ template <typename G>
440
+ static void parse_generator(std::string_view& s, std::optional<GeneratorType>& out) {
441
+ if(out) return;
442
+ if(s.substr(0, G::name.size()) != G::name) return;
443
+
444
+ // Drop the name.
445
+ s.remove_prefix(G::name.size());
446
+ if constexpr(std::tuple_size_v<typename G::Args> == 0) {
447
+ out.emplace(std::in_place_type_t<G>{});
448
+ return;
449
+ }
450
+
451
+ // Drop the (
452
+ assert(not s.empty() and s.front() == '(');
453
+ s.remove_prefix(1);
454
+
455
+ auto args = parse_arguments(s, Pack<typename G::Args>{});
456
+ // Construct the resulting generator in-place in the variant..
457
+ std::apply([&](const auto&... _args) { out.emplace(std::in_place_type_t<G>{}, _args...); },
458
+ args);
459
+ }
460
+
461
+ template <typename... Gs>
462
+ static std::optional<GeneratorType> parse_generators(std::string_view& s,
463
+ Pack<std::variant<Gs...>> /*unused*/) {
464
+ std::optional<GeneratorType> out;
465
+ (parse_generator<Gs>(s, out), ...);
466
+ return out;
467
+ }
468
+
469
+ explicit ChoiceGenerator(std::string_view s) : total_weight_(0) {
470
+ // PARSE
471
+ while(not s.empty()) {
472
+ auto generator = parse_generators(s, Pack<GeneratorType>{});
473
+ if(!generator) {
474
+ // Check for range syntax:
475
+ auto comma = s.find_first_of(",:");
476
+ if(comma == std::string::npos) comma = s.size();
477
+ auto dots = s.find("..");
478
+ if(dots != std::string_view::npos and dots < comma) {
479
+ auto start = s.substr(0, dots);
480
+ auto end = s.substr(dots + 2, comma - dots - 2);
481
+
482
+ generator.emplace(std::in_place_type_t<RangeGenerator<T>>{},
483
+ parse_number<T>(start), parse_number<T>(end));
484
+ s.remove_prefix(comma);
485
+ }
486
+
487
+ // Fall back to constant.
488
+ if(!generator) {
489
+ generator.emplace(std::in_place_type_t<ConstGenerator<T>>{},
490
+ parse_number<T>(s.substr(0, comma)));
491
+ s.remove_prefix(comma);
492
+ }
493
+ }
494
+
495
+ // Parse weight if given.
496
+ double weight = 1;
497
+ if(not s.empty() and s.front() == ':') {
498
+ s.remove_prefix(1);
499
+ auto comma = s.find(',');
500
+ if(comma == std::string_view::npos) comma = s.size();
501
+ weight = parse_number<long double>(s.substr(0, comma));
502
+ s.remove_prefix(comma);
503
+ }
504
+
505
+ // should now be at , or end
506
+ assert(s.empty() or s.front() == ',');
507
+ if(not s.empty()) s.remove_prefix(1);
508
+ generators_.emplace_back(std::move(*generator), weight);
509
+ total_weight_ += weight;
510
+ }
511
+ }
512
+
513
+ T operator()(T low, T high, std::mt19937_64& rng) const {
514
+ Generators::UniformGenerator uniform;
515
+ double x = uniform.operator()<long double>(0, total_weight_, rng);
516
+ for(size_t i = 0; i < generators_.size(); ++i) {
517
+ x -= generators_[i].second;
518
+ if(x <= 0)
519
+ return std::visit([&](auto& g) { return g(low, high, rng); }, generators_[i].first);
520
+ }
521
+ assert(false);
522
+ }
523
+ };
524
+
525
+ struct ParamGenerator {
526
+ std::variant<std::string_view, ChoiceGenerator<long long>, ChoiceGenerator<long double>>
527
+ generator;
528
+ explicit ParamGenerator(std::string_view s) : generator(s) {}
529
+
530
+ template <typename T>
531
+ T operator()(T low, T high, std::mt19937_64& rng) {
532
+ static_assert(is_number_v<T>);
533
+ if(std::holds_alternative<std::string_view>(generator)) {
534
+ generator = ChoiceGenerator<T>(std::get<std::string_view>(generator));
535
+ }
536
+ return std::get<ChoiceGenerator<T>>(generator)(low, high, rng);
537
+ }
538
+ };
539
+
540
+ } // namespace Generators
541
+
542
+ using Generators::ParamGenerator;
543
+
544
+ namespace Random {
545
+ template <class RandomIt>
546
+ void shuffle(RandomIt first, RandomIt last, std::mt19937_64& rng) {
547
+ Generators::UniformGenerator uniform;
548
+ long long n = last - first;
549
+ for(long long i = n - 1; i > 0; i--) {
550
+ std::swap(first[i], first[uniform(0ll, i, rng)]);
551
+ }
552
+ }
553
+
554
+ template <class T>
555
+ void shuffle(std::pair<T, T>& in, std::mt19937_64& rng) {
556
+ if(bit(rng)) std::swap(in.first, in.second);
557
+ }
558
+
559
+ template <class RandomIt>
560
+ auto& select(RandomIt first, RandomIt last, std::mt19937_64& rng) {
561
+ assert(first != last);
562
+ Generators::UniformGenerator uniform;
563
+ long long n = last - first;
564
+ return first[uniform(0ll, n - 1, rng)];
565
+ }
566
+
567
+ template <class T>
568
+ const T& select(const std::pair<T, T>& in, std::mt19937_64& rng) {
569
+ return bit(rng) ? in.first : in.second;
570
+ }
571
+
572
+ template <class T>
573
+ T& select(std::pair<T, T>& in, std::mt19937_64& rng) {
574
+ return bit(rng) ? in.first : in.second;
575
+ }
576
+
577
+ } // namespace Random
578
+
579
+ class Validator {
580
+ protected:
581
+ Validator(bool ws_, bool case_, std::istream& in_, std::string constraints_file_path_ = "",
582
+ std::optional<unsigned int> seed = std::nullopt,
583
+ std::unordered_map<std::string, ParamGenerator> params_ = {})
584
+ : in(in_), ws(ws_), case_sensitive(case_),
585
+ constraints_file_path(std::move(constraints_file_path_)), gen(seed.has_value()),
586
+ rng(seed.value_or(Random::default_seed)), params(std::move(params_)) {
587
+
588
+ std::ios_base::sync_with_stdio(false);
589
+ in.tie(nullptr);
590
+
591
+ if(gen) return;
592
+ if(ws)
593
+ in >> std::noskipws;
594
+ else
595
+ in >> std::skipws;
596
+
597
+ if(!constraints_file_path.empty()) {
598
+ assert(has_source_location); // NOLINT
599
+ }
600
+ }
601
+
602
+ public:
603
+ // No copying, no moving.
604
+ Validator(const Validator&) = delete;
605
+ Validator(Validator&&) = delete;
606
+ void operator=(const Validator&) = delete;
607
+ void operator=(Validator&&) = delete;
608
+
609
+ // At the end of the scope, check whether the EOF has been reached.
610
+ // If so, return AC. Otherwise, return WA.
611
+ ~Validator() {
612
+ eof();
613
+ write_constraints();
614
+ AC();
615
+ }
616
+
617
+ void space() {
618
+ if(gen) {
619
+ out << ' ';
620
+ return;
621
+ }
622
+
623
+ if(ws) {
624
+ char c;
625
+ in >> c;
626
+ check(!in.eof(), "Expected space, found EOF.");
627
+ if(c != ' ')
628
+ expected("space", std::string("\"") +
629
+ ((c == '\n' or c == '\r') ? std::string("newline")
630
+ : std::string(1, c)) +
631
+ "\"");
632
+ }
633
+ }
634
+
635
+ void newline() {
636
+ if(gen) {
637
+ out << '\n';
638
+ return;
639
+ }
640
+
641
+ if(ws) {
642
+ char c;
643
+ in >> c;
644
+ check(!in.eof(), "Expected newline, found EOF.");
645
+ if(c != '\n') {
646
+ if(c == '\r')
647
+ expected("newline", "DOS line ending (\\r)");
648
+ else
649
+ expected("newline", std::string("\"") + c + "\"");
650
+ }
651
+ }
652
+ }
653
+
654
+ private:
655
+ void separator(Separator s) {
656
+ switch(s) {
657
+ case Separator::Space: space(); break;
658
+ case Separator::Newline: newline(); break;
659
+ }
660
+ }
661
+
662
+ template <typename T>
663
+ auto& seen() {
664
+ static std::map<source_location, std::set<T>> seen;
665
+ return seen;
666
+ }
667
+ template <typename T>
668
+ auto& last_seen() {
669
+ static std::map<source_location, T> last_seen;
670
+ return last_seen;
671
+ }
672
+ template <typename T>
673
+ auto& integers_seen() {
674
+ static std::map<source_location, std::tuple<std::set<T>, std::vector<T>, bool>>
675
+ integers_seen;
676
+ return integers_seen;
677
+ }
678
+ template <typename T>
679
+ void reset(source_location loc) {
680
+ seen<T>().erase(loc);
681
+ last_seen<T>().erase(loc);
682
+ integers_seen<T>().erase(loc);
683
+ }
684
+
685
+ template <typename T, typename Tag>
686
+ void check_number(const std::string& name, T low, T high, T v, Tag /*unused*/,
687
+ source_location loc) {
688
+ static_assert(is_number_v<T>);
689
+ if(v < low or v > high) {
690
+ std::string type_name;
691
+ if constexpr(std::is_integral_v<T>) {
692
+ type_name = "integer";
693
+ }
694
+ if constexpr(std::is_floating_point_v<T>) {
695
+ type_name = "float";
696
+ }
697
+ expected(name + ": " + type_name + " between " + std::to_string(low) + " and " +
698
+ std::to_string(high),
699
+ std::to_string(v));
700
+ }
701
+ log_constraint(name, low, high, v, loc);
702
+ if constexpr(Tag::unique) {
703
+ auto [it, inserted] = seen<T>()[loc].emplace(v);
704
+ check(inserted, name, ": Value ", v, " seen twice, but must be unique!");
705
+ } else {
706
+ auto [it, inserted] = last_seen<T>().emplace(loc, v);
707
+ if(inserted) return;
708
+
709
+ auto last = it->second;
710
+ it->second = v;
711
+
712
+ if constexpr(Tag::increasing)
713
+ check(v >= last, name, " is not increasing: value ", v, " follows ", last);
714
+ if constexpr(Tag::decreasing)
715
+ check(v <= last, name, " is not decreasing: value ", v, " follows ", last);
716
+ if constexpr(Tag::strict)
717
+ check(v != last, name, " is not strict: value ", v, " equals ", last);
718
+ }
719
+ }
720
+
721
+ template <typename Tag>
722
+ void check_string(const std::string& name, int low, int high, const std::string& v,
723
+ Tag /*unused*/, source_location loc) {
724
+ using T = std::string;
725
+ if((int) v.size() < low or (int) v.size() > high) {
726
+ expected(name + ": " + "string with" + " length between " + std::to_string(low) +
727
+ " and " + std::to_string(high),
728
+ v);
729
+ }
730
+ log_constraint(name, low, high, static_cast<int>(v.size()), loc);
731
+ if constexpr(Tag::unique) {
732
+ // static map<source_location, set<T>> seen;
733
+ auto [it, inserted] = seen<T>()[loc].emplace(v);
734
+ check(inserted, name, ": Value ", v, " seen twice, but must be unique!");
735
+ } else if(Tag::increasing or Tag::decreasing) {
736
+ // static map<source_location, T> last_seen;
737
+ auto [it, inserted] = last_seen<T>().emplace(loc, v);
738
+ if(inserted) return;
739
+
740
+ auto last = it->second;
741
+ it->second = v;
742
+
743
+ if constexpr(Tag::increasing)
744
+ check(v >= last, name, " is not increasing: value ", v, " follows ", last);
745
+ if constexpr(Tag::decreasing)
746
+ check(v <= last, name, " is not decreasing: value ", v, " follows ", last);
747
+ if constexpr(Tag::strict)
748
+ check(v != last, name, " is not strict: value ", v, " equals ", last);
749
+ }
750
+ }
751
+
752
+ // Generate a random integer in [low, high] or float in [low, high).
753
+ template <typename T>
754
+ T uniform_number(T low, T high) {
755
+ assert(low <= high);
756
+ Generators::UniformGenerator uniform;
757
+ if constexpr(std::is_integral<T>::value)
758
+ return uniform.operator()<long long>(low, high, rng);
759
+ else
760
+ return uniform.operator()<long double>(low, high, rng);
761
+ }
762
+
763
+ template <typename T, typename Tag>
764
+ T gen_number(const std::string& name, T low, T high, Tag /*unused*/, source_location loc) {
765
+ static_assert(is_number_v<T>);
766
+ T v;
767
+
768
+ if constexpr(Tag::unique) {
769
+ assert(params.find(name) == params.end() &&
770
+ "Parameters are not supported for unique values.");
771
+ if constexpr(std::is_integral<T>::value) {
772
+ auto& [seen_here, remaining_here, use_remaining] = integers_seen<T>()[loc];
773
+
774
+ if(use_remaining) {
775
+ check(!remaining_here.empty(), name, ": no unique values left");
776
+ v = remaining_here.back();
777
+ remaining_here.pop_back();
778
+ } else {
779
+ do {
780
+ v = uniform_number(low, high);
781
+ } while(!seen_here.insert(v).second);
782
+
783
+ struct CountIterator {
784
+ T v;
785
+ T& operator*() { return v; }
786
+ T& operator++() { return ++v; }
787
+ T operator++(int) { return v++; }
788
+ bool operator!=(CountIterator r) { return v != r.v; }
789
+ };
790
+
791
+ if(seen_here.size() > (high - low) / 2) {
792
+ use_remaining = true;
793
+ set_difference(CountIterator{low}, CountIterator{high + 1},
794
+ seen_here.begin(), seen_here.end(),
795
+ std::back_inserter(remaining_here));
796
+ }
797
+ }
798
+ } else {
799
+ // For floats, just regenerate numbers until success.
800
+ auto& seen_here = seen<T>()[loc];
801
+ do {
802
+ v = uniform_number(low, high);
803
+ } while(!seen_here.insert(v).second);
804
+ }
805
+
806
+ } else {
807
+ assert(not Tag::increasing && "Generating increasing sequences is not yet supported!");
808
+ assert(not Tag::decreasing && "Generating decreasing sequences is not yet supported!");
809
+ assert((std::is_same<Tag, ArbitraryTag>::value) &&
810
+ "Only Unique and Arbitrary are supported!");
811
+
812
+ if(params.find(name) != params.end()) {
813
+ v = params.at(name).operator()<T>(low, high, rng);
814
+ // This will be checked during input validation of the generated case.
815
+ // assert(low <= v and v <= high);
816
+ } else {
817
+ v = uniform_number<T>(low, high);
818
+ }
819
+ }
820
+
821
+ return v;
822
+ }
823
+
824
+ std::string gen_string(const std::string& name, long long low, long long high,
825
+ std::string_view chars) {
826
+ assert(!chars.empty());
827
+
828
+ int len;
829
+ if(params.find(name + ".length") != params.end())
830
+ len = params.at(name + ".length").operator()<long long>(low, high, rng);
831
+ else
832
+ len = uniform_number(low, high);
833
+ std::string s(len, ' ');
834
+ for(auto& x : s) x = chars[uniform_number<int>(0, chars.size() - 1)];
835
+
836
+ out << s;
837
+ return s;
838
+ }
839
+
840
+ public:
841
+ template <typename Tag = ArbitraryTag>
842
+ long long gen_integer(const std::string& name, long long low, long long high, Tag tag = Tag{},
843
+ source_location loc = source_location::current()) {
844
+ return gen_number(name, low, high, tag, loc);
845
+ }
846
+
847
+ template <typename Tag = ArbitraryTag>
848
+ long double gen_float(const std::string& name, long double low, long double high,
849
+ Tag tag = Tag{}, source_location loc = source_location::current()) {
850
+ return gen_number(name, low, high, tag, loc);
851
+ }
852
+
853
+ private:
854
+ template <typename T, typename Tag>
855
+ std::vector<T> gen_numbers(const std::string& name, int count, T low, T high, Tag /*unused*/,
856
+ source_location loc) {
857
+ static_assert(is_number_v<T>);
858
+ std::vector<T> v;
859
+ v.reserve(count);
860
+ if constexpr(std::is_same_v<Tag, ArbitraryTag>) {
861
+ if(params.find(name) != params.end()) {
862
+ auto& generator = params.at(name);
863
+ for(int i = 0; i < count; ++i) {
864
+ auto val = generator.operator()<T>(low, high, rng);
865
+ assert(low <= val and val <= high);
866
+ v.push_back(val);
867
+ }
868
+ } else {
869
+ for(int i = 0; i < count; ++i) {
870
+ v.push_back(uniform_number<T>(low, high));
871
+ }
872
+ }
873
+ } else if constexpr(Tag::unique) {
874
+ assert(params.find(name) == params.end() &&
875
+ "Parameters are not supported for unique values.");
876
+ std::set<T> seen_here;
877
+ if constexpr(std::is_integral_v<T>) {
878
+ if(2 * count < high - low) {
879
+ for(int i = 0; i < count; ++i) {
880
+ // If density < 1/2: retry.
881
+ T w;
882
+ do {
883
+ w = uniform_number(low, high);
884
+ } while(!seen_here.insert(w).second);
885
+ v.push_back(w);
886
+ }
887
+ } else {
888
+ // If density >= 1/2, crop a random permutation.
889
+ v.resize(high - low + 1);
890
+ iota(begin(v), end(v), low);
891
+ Random::shuffle(begin(v), end(v), rng);
892
+ v.resize(count);
893
+ }
894
+ } else {
895
+ for(int i = 0; i < count; ++i) {
896
+ // For floats, just regenerate numbers until success.
897
+ T w;
898
+ do {
899
+ w = uniform_number(low, high);
900
+ } while(!seen_here.insert(w).second);
901
+ v.push_back(w);
902
+ }
903
+ }
904
+ } else {
905
+ static_assert(Tag::increasing or Tag::decreasing);
906
+
907
+ constexpr bool integral_strict = Tag::strict and std::is_integral<T>::value;
908
+ if(integral_strict) {
909
+ assert(params.find(name) == params.end() &&
910
+ "Parameters are not supported for strict integer values.");
911
+ high = high - count + 1;
912
+ }
913
+
914
+ if(params.find(name) != params.end()) {
915
+ auto& generator = params.at(name);
916
+ for(int i = 0; i < count; ++i) {
917
+ auto val = generator.operator()<T>(low, high, rng);
918
+ assert(low <= val and val <= high);
919
+ v.push_back(val);
920
+ }
921
+ } else {
922
+ for(int i = 0; i < count; ++i) {
923
+ v.push_back(uniform_number<T>(low, high));
924
+ }
925
+ }
926
+
927
+ sort(begin(v), end(v));
928
+
929
+ if(integral_strict) {
930
+ for(int i = 0; i < count; ++i) v[i] += i;
931
+ }
932
+
933
+ if(Tag::decreasing) reverse(begin(v), end(v));
934
+ }
935
+
936
+ return v;
937
+ }
938
+
939
+ public:
940
+ template <typename Tag = ArbitraryTag>
941
+ std::vector<long long> gen_integers(const std::string& name, int count, long long low,
942
+ long long high, Tag tag = Tag{},
943
+ source_location loc = source_location::current()) {
944
+ return gen_numbers(name, count, low, high, tag, loc);
945
+ }
946
+
947
+ template <typename Tag = ArbitraryTag>
948
+ std::vector<long double> gen_floats(const std::string& name, int count, long double low,
949
+ long double high, Tag tag = Tag{},
950
+ source_location loc = source_location::current()) {
951
+ return gen_numbers(name, count, low, high, tag, loc);
952
+ }
953
+
954
+ private:
955
+ template <typename T, typename Tag>
956
+ T read_number(const std::string& name, T low, T high, Tag tag, source_location loc) {
957
+ if(gen) {
958
+ auto v = gen_number(name, low, high, tag, loc);
959
+ out << std::setprecision(10) << std::fixed << v;
960
+ return v;
961
+ }
962
+
963
+ const auto v = [&] {
964
+ if constexpr(std::is_integral<T>::value)
965
+ return read_integer(name);
966
+ else
967
+ return read_float(name);
968
+ }();
969
+
970
+ check_number(name, low, high, v, tag, loc);
971
+ return v;
972
+ }
973
+
974
+ // Read a vector of numbers, separated by spaces and ended by a newline.
975
+ template <typename T, typename Tag>
976
+ std::vector<T> read_numbers(const std::string& name, int count, T low, T high, Tag tag,
977
+ Separator sep, source_location loc) {
978
+ if(gen) {
979
+ auto v = gen_numbers(name, count, low, high, tag, loc);
980
+
981
+ out << std::setprecision(10) << std::fixed;
982
+ for(int i = 0; i < count; ++i) {
983
+ out << v[i];
984
+ if(i < count - 1) separator(sep);
985
+ }
986
+ newline();
987
+
988
+ return v;
989
+ }
990
+ reset<T>(loc);
991
+ std::vector<T> v(count);
992
+ for(int i = 0; i < count; ++i) {
993
+ if constexpr(std::is_integral<T>::value)
994
+ v[i] = read_integer(name);
995
+ else
996
+ v[i] = read_float(name);
997
+ check_number(name, low, high, v[i], tag, loc);
998
+ if(i < count - 1) separator(sep);
999
+ }
1000
+ newline();
1001
+ return v;
1002
+ }
1003
+
1004
+ public:
1005
+ template <typename Tag = ArbitraryTag>
1006
+ long long read_integer(const std::string& name, long long low, long long high, Tag tag = Tag{},
1007
+ source_location loc = source_location::current()) {
1008
+ return read_number(name, low, high, tag, loc);
1009
+ }
1010
+ template <typename Tag = ArbitraryTag>
1011
+ std::vector<long long> read_integers(const std::string& name, int count, long long low,
1012
+ long long high, Tag tag = Tag{}, Separator sep = Space,
1013
+ source_location loc = source_location::current()) {
1014
+ return read_numbers(name, count, low, high, tag, sep, loc);
1015
+ }
1016
+
1017
+ template <typename Tag = ArbitraryTag>
1018
+ long double read_float(const std::string& name, long double low, long double high,
1019
+ Tag tag = Tag{}, source_location loc = source_location::current()) {
1020
+ return read_number(name, low, high, tag, loc);
1021
+ }
1022
+ template <typename Tag = ArbitraryTag>
1023
+ std::vector<long double> read_floats(const std::string& name, int count, long double low,
1024
+ long double high, Tag tag = Tag{}, Separator sep = Space,
1025
+ source_location loc = source_location::current()) {
1026
+ return read_numbers(name, count, low, high, tag, sep, loc);
1027
+ }
1028
+
1029
+ // Read a vector of strings, separated by spaces and ended by a newline.
1030
+ template <typename Tag = ArbitraryTag>
1031
+ std::vector<std::string> read_strings(const std::string& name, int count, int min, int max,
1032
+ const std::string_view chars = "", Tag tag = Tag(),
1033
+ Separator sep = Space,
1034
+ source_location loc = source_location::current()) {
1035
+ reset<std::string>(loc);
1036
+ if(gen) return gen_strings(name, count, min, max, chars, tag, sep, loc);
1037
+ assert(!gen);
1038
+ std::vector<std::string> v(count);
1039
+ for(int i = 0; i < count; ++i) {
1040
+ v[i] = read_string(name, min, max, chars, tag, loc);
1041
+ if(i < count - 1) separator(sep);
1042
+ }
1043
+ newline();
1044
+ return v;
1045
+ }
1046
+
1047
+ template <typename Tag>
1048
+ std::vector<std::string> gen_strings(const std::string& name, int count, int min, int max,
1049
+ const std::string_view chars, Tag /*unused*/,
1050
+ Separator sep, source_location loc) {
1051
+ assert(!chars.empty());
1052
+
1053
+ std::vector<std::string> v(count);
1054
+ if constexpr(std::is_same<Tag, ArbitraryTag>::value) {
1055
+ for(int i = 0; i < count; ++i) {
1056
+ std::string s(uniform_number(min, max), ' ');
1057
+ for(auto& x : s) x = chars[uniform_number<int>(0, chars.size() - 1)];
1058
+ v.push_back(s);
1059
+ out << s;
1060
+ if(i < count - 1) separator(sep);
1061
+ }
1062
+ } else if constexpr(Tag::unique) {
1063
+ std::set<std::string> seen_here;
1064
+ for(int i = 0; i < count; ++i) {
1065
+ // Just regenerate strings until success.
1066
+ std::string s;
1067
+ do {
1068
+ s = std::string(uniform_number(min, max), ' ');
1069
+ for(auto& x : s) x = chars[uniform_number<int>(0, chars.size() - 1)];
1070
+ } while(!seen_here.insert(s).second);
1071
+ v.push_back(s);
1072
+ out << s;
1073
+ if(i < count - 1) separator(sep);
1074
+ }
1075
+ } else {
1076
+ static_assert(Tag::increasing or Tag::decreasing);
1077
+
1078
+ assert(false && "Generating increasing/decreasing lists of strings is not "
1079
+ "supported!");
1080
+ }
1081
+
1082
+ newline();
1083
+
1084
+ return v;
1085
+ }
1086
+
1087
+ // Check the next character.
1088
+ bool peek(char c, const std::string& name = "") {
1089
+ if(gen) {
1090
+ // TODO
1091
+ // if(not name.empty() and params.contains(name)) {
1092
+ // return c == params.at(name).operator()<char>(0, 0, rng);
1093
+ //}
1094
+ return Random::bit(rng);
1095
+ }
1096
+ if(!ws) in >> std::ws;
1097
+ if(case_sensitive) return in.peek() == std::char_traits<char>::to_int_type(c);
1098
+ return tolower(in.peek()) == tolower(std::char_traits<char>::to_int_type(c));
1099
+ }
1100
+
1101
+ // Read a string and make sure it equals `expected`.
1102
+ // Takes by value because it needs to lowercase its arguments.
1103
+ std::string test_strings(std::vector<std::string> expected, const std::string& name = "") {
1104
+ if(gen) {
1105
+ int index = 0;
1106
+ // TODO
1107
+ // if(not name.empty() and params.contains(name)) {
1108
+ // auto s = params.at(name).operator()<std::string>(0, 0, rng);
1109
+ // index = std::find(expected.begin(), expected.end(), s) - expected.begin();
1110
+ // assert(0 <= index and index < expected.size());
1111
+ //} else {
1112
+ index = expected.size() == 1 ? 0 : uniform_number<int>(0, expected.size() - 1);
1113
+ //}
1114
+ out << expected[index];
1115
+ return expected[index];
1116
+ }
1117
+ std::string s = get_string();
1118
+ lowercase(s);
1119
+
1120
+ for(std::string e : expected)
1121
+ if(s == lowercase(e)) return s;
1122
+
1123
+ std::string error;
1124
+ for(const auto& e : expected) {
1125
+ if(not error.empty()) error += "|";
1126
+ error += e;
1127
+ }
1128
+ WA("Expected string \"", error, "\", but found ", s);
1129
+ }
1130
+
1131
+ // Read a string and make sure it equals `expected`.
1132
+ std::string test_string(std::string expected, const std::string& name = "") {
1133
+ return test_strings({std::move(expected)}, name);
1134
+ }
1135
+
1136
+ // Read an arbitrary string of a given length.
1137
+ template <typename Tag = ArbitraryTag>
1138
+ std::string read_string(const std::string& name, long long min, long long max,
1139
+ const std::string_view chars = "", Tag tag = Tag(),
1140
+ source_location loc = source_location::current()) {
1141
+ if(gen) {
1142
+ return gen_string(name, min, max, chars);
1143
+ }
1144
+ std::string s = get_string();
1145
+ std::array<bool, 256> ok_char{};
1146
+ if(!chars.empty()) {
1147
+ for(auto c : chars) ok_char[c] = true;
1148
+ for(auto c : s)
1149
+ check(ok_char[c], name, ": expected characters in ", chars, " but found character ",
1150
+ c, " in ", s);
1151
+ }
1152
+ check_string(name, min, max, s, tag, loc);
1153
+ return s;
1154
+ }
1155
+
1156
+ // Read an arbitrary line of a given length.
1157
+ std::string read_line(const std::string& name, long long min, long long max,
1158
+ const std::string_view chars = "",
1159
+ source_location loc = source_location::current()) {
1160
+ if(gen) {
1161
+ // TODO: Params for lines.
1162
+ assert(!chars.empty());
1163
+
1164
+ std::string s(uniform_number(min, max), ' ');
1165
+ for(auto& x : s) x = chars[uniform_number<int>(0, chars.size() - 1)];
1166
+
1167
+ out << s << '\n';
1168
+ return s;
1169
+ }
1170
+
1171
+ if(ws) {
1172
+ char next = in.peek();
1173
+ if(min > 0 and isspace(next))
1174
+ expected("non empty line", next == '\n' ? "newline" : "whitespace");
1175
+ if(in.eof()) expected("line", "EOF");
1176
+ }
1177
+ std::string s;
1178
+ if(!getline(in, s)) expected("line", "nothing");
1179
+ long long size = s.size();
1180
+ if(size < min || size > max)
1181
+ expected(name + ": line of length between " + std::to_string(min) + " and " +
1182
+ std::to_string(max),
1183
+ s);
1184
+ std::array<bool, 256> ok_char{};
1185
+ if(!chars.empty()) {
1186
+ for(auto c : chars) ok_char[c] = true;
1187
+ for(auto c : s)
1188
+ check(ok_char[c], name, ": expected characters in ", chars, " but found character ",
1189
+ c, " in ", s);
1190
+ }
1191
+ log_constraint(name, min, max, size, loc);
1192
+ return s;
1193
+ }
1194
+
1195
+ // Return ACCEPTED verdict.
1196
+ void eof_and_AC() {
1197
+ eof();
1198
+ AC();
1199
+ }
1200
+
1201
+ private:
1202
+ std::function<void()> WA_handler = [] {};
1203
+
1204
+ public:
1205
+ void set_WA_handler(std::function<void()> f) { WA_handler = std::move(f); }
1206
+
1207
+ // Return WA with the given reason.
1208
+ template <typename... Ts>
1209
+ [[noreturn]] void WA(const Ts&... ts) {
1210
+ static_assert(sizeof...(Ts) > 0);
1211
+
1212
+ WA_handler();
1213
+
1214
+ auto pos = get_file_pos();
1215
+ std::cerr << pos.first << ":" << pos.second << ": ";
1216
+
1217
+ WA_impl(ts...);
1218
+ }
1219
+
1220
+ // Check that the condition is true.
1221
+ template <typename... Ts>
1222
+ void check(bool b, const Ts&... ts) {
1223
+ static_assert(sizeof...(Ts) > 0, "Provide a non-empty error message.");
1224
+
1225
+ if(!b) WA(ts...);
1226
+ }
1227
+
1228
+ // Log some value in a range.
1229
+ template <typename T>
1230
+ void log_constraint(const std::string& name, T low, T high, T v,
1231
+ source_location loc = source_location::current()) {
1232
+ // Do not log when line number is unknown/default/unsupported.
1233
+ if(loc.line() == 0 or constraints_file_path.empty()) return;
1234
+
1235
+ // All integer types get bounds as long long, all floating point types as long_double.
1236
+ using U = Bounds<std::conditional_t<std::is_integral_v<T>, long long, long double>>;
1237
+
1238
+ auto [it, inserted] = bounds.emplace(loc, U(name, v, v, low, high));
1239
+ assert(std::holds_alternative<U>(it->second));
1240
+ auto& done = std::get<U>(it->second);
1241
+ if(inserted) {
1242
+ assert(!name.empty() && "Variable names must not be empty.");
1243
+ assert(name.find(' ') == std::string::npos && "Variable name must not contain spaces.");
1244
+ } else {
1245
+ assert(name == done.name && "Variable name must be constant.");
1246
+ }
1247
+ if(v < done.min) {
1248
+ done.min = v;
1249
+ done.low = low;
1250
+ }
1251
+ if(v > done.max) {
1252
+ done.max = v;
1253
+ done.high = high;
1254
+ }
1255
+ done.has_min |= v == low;
1256
+ done.has_max |= v == high;
1257
+ }
1258
+
1259
+ private:
1260
+ long long read_integer(const std::string& name) {
1261
+ assert(!gen);
1262
+ std::string s = get_string("integer");
1263
+ if(s.empty()) {
1264
+ WA(name, ": Want integer, found nothing");
1265
+ }
1266
+ long long v;
1267
+ auto begin = s.c_str(), end = begin + s.size();
1268
+ auto [ptr, ec] = std::from_chars(begin, end, v);
1269
+ if(ec == std::errc::result_out_of_range){
1270
+ WA(name, ": Number " + s + " does not fit in a long long!");
1271
+ } else if(ptr != end) {
1272
+ WA(name, ": Parsing " + s + " as long long failed! Did not process all characters");
1273
+ } else if (ec != std::errc{}) {
1274
+ WA(name, ": Parsing " + s + " as long long failed!");
1275
+ }
1276
+ // Check for leading zero.
1277
+ if(v == 0) {
1278
+ if(s.size() != 1) WA(name, ": Parsed 0, but has leading 0 or minus sign: ", s);
1279
+ }
1280
+ if(v > 0) {
1281
+ if(s[0] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s);
1282
+ }
1283
+ if(v < 0) {
1284
+ if(s.size() <= 1) WA(name, ": Parsed ", v, ", but string is: ", s);
1285
+ if(s[1] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s);
1286
+ }
1287
+ return v;
1288
+ }
1289
+
1290
+ long double read_float(const std::string& name) {
1291
+ assert(!gen);
1292
+ std::string s = get_string("long double");
1293
+ long double v;
1294
+ try {
1295
+ size_t chars_processed;
1296
+ v = stold(s, &chars_processed);
1297
+ if(chars_processed != s.size())
1298
+ WA(name, ": Parsing ", s,
1299
+ " as long double failed! Did not process all characters.");
1300
+ } catch(const std::out_of_range& e) {
1301
+ WA(name, ": Number " + s + " does not fit in a long double!");
1302
+ } catch(const std::invalid_argument& e) {
1303
+ WA("Parsing " + s + " as long double failed!");
1304
+ }
1305
+ return v;
1306
+ }
1307
+
1308
+ [[noreturn]] void expected(const std::string& exp = "", const std::string& s = "") {
1309
+ assert(!gen && "Expected is not supported for generators.");
1310
+ if(!s.empty())
1311
+ WA("Expected ", exp, ", found ", s);
1312
+ else
1313
+ WA(exp);
1314
+ }
1315
+
1316
+ template <typename T>
1317
+ [[noreturn]] void WA_impl(T t) {
1318
+ std::cerr << t << std::endl;
1319
+ exit(ret_WA);
1320
+ }
1321
+
1322
+ std::pair<int, int> get_file_pos() {
1323
+ int line = 1, col = 0;
1324
+ in.clear();
1325
+ auto originalPos = in.tellg();
1326
+ if(originalPos < 0) return {-1, -1};
1327
+ in.seekg(0);
1328
+ char c;
1329
+ while((in.tellg() < originalPos) && in.get(c)) {
1330
+ if(c == '\n')
1331
+ ++line, col = 0;
1332
+ else
1333
+ ++col;
1334
+ }
1335
+ return {line, col};
1336
+ }
1337
+
1338
+ template <typename T, typename... Ts>
1339
+ [[noreturn]] void WA_impl(T t, Ts... ts) {
1340
+ std::cerr << t;
1341
+ WA_impl(ts...);
1342
+ }
1343
+
1344
+ std::string get_string(const std::string& wanted = "string") {
1345
+ assert(!gen && "get_string is not supported for generators.");
1346
+ if(ws) {
1347
+ char next = in.peek();
1348
+ if(isspace(next)) expected(wanted, next == '\n' ? "newline" : "whitespace");
1349
+ if(in.eof()) expected(wanted, "EOF");
1350
+ }
1351
+
1352
+ std::string s;
1353
+ if(in >> s) {
1354
+ return s;
1355
+ }
1356
+ expected(wanted, "nothing");
1357
+ }
1358
+
1359
+ // Return ACCEPTED verdict.
1360
+ void AC() const {
1361
+ if(gen) {
1362
+ // nothing
1363
+ return;
1364
+ }
1365
+
1366
+ exit(ret_AC);
1367
+ }
1368
+
1369
+ void eof() {
1370
+ if(gen) {
1371
+ out.flush();
1372
+ fclose(stdout);
1373
+ return;
1374
+ }
1375
+ if(in.eof()) return;
1376
+ // Sometimes EOF hasn't been triggered yet.
1377
+ if(!ws) in >> std::ws;
1378
+ char c = in.get();
1379
+ if(c == std::char_traits<char>::eof()) return;
1380
+ std::string got = std::string("\"") + char(c) + '"';
1381
+ if(c == '\n') got = "newline";
1382
+ expected("EOF", got);
1383
+ }
1384
+
1385
+ // Convert a string to lowercase is matching is not case sensitive.
1386
+ std::string& lowercase(std::string& s) const {
1387
+ if(case_sensitive) return s;
1388
+ transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
1389
+ return s;
1390
+ }
1391
+
1392
+ // Keep track of the min/max value read at every call site.
1393
+ template <typename T>
1394
+ struct Bounds {
1395
+ Bounds(std::string name_, T min_, T max_, T low_, T high_)
1396
+ : name(std::move(name_)), min(min_), max(max_), low(low_), high(high_) {} // NOLINT
1397
+ std::string name;
1398
+ T min, max; // Smallest / largest value observed
1399
+ T low, high; // Bounds
1400
+ bool has_min = false, has_max = false;
1401
+ };
1402
+
1403
+ std::map<source_location, std::variant<Bounds<long long>, Bounds<long double>>> bounds;
1404
+
1405
+ void write_constraints() {
1406
+ if(constraints_file_path.empty()) return;
1407
+
1408
+ std::ofstream os(constraints_file_path);
1409
+
1410
+ for(const auto& [location, bound] : bounds) {
1411
+ os << location_to_string(location) << " ";
1412
+ std::visit(
1413
+ [&](const auto& b) {
1414
+ os << b.name << " " << b.has_min << " " << b.has_max << " " << b.min << " "
1415
+ << b.max << " " << b.low << " " << b.high << std::endl;
1416
+ },
1417
+ bound);
1418
+ }
1419
+ }
1420
+
1421
+ static const int ret_AC = 42, ret_WA = 43;
1422
+ std::istream& in = std::cin;
1423
+ std::ostream& out = std::cout;
1424
+
1425
+ public:
1426
+ const bool ws = true;
1427
+ const bool case_sensitive = true;
1428
+ const std::string constraints_file_path;
1429
+ const bool gen = false;
1430
+
1431
+ std::mt19937_64 rng;
1432
+
1433
+ private:
1434
+ std::unordered_map<std::string, ParamGenerator> params;
1435
+
1436
+ public:
1437
+ std::string_view get_param(std::string_view name, std::string_view default_) {
1438
+ auto it = params.find(std::string(name));
1439
+ if(it == params.end()) return default_;
1440
+ return std::get<std::string_view>(it->second.generator);
1441
+ }
1442
+
1443
+ protected:
1444
+ static std::string get_constraints_file(int argc, char** argv) {
1445
+ for(int i = 1; i < argc; ++i) {
1446
+ if(argv[i] == constraints_file_flag) {
1447
+ if(i + 1 < argc) return argv[i + 1];
1448
+ std::cerr << constraints_file_flag << " should be followed by a file path!";
1449
+ exit(1);
1450
+ }
1451
+ }
1452
+ return {};
1453
+ }
1454
+ };
1455
+
1456
+ class Generator : public Validator {
1457
+ public:
1458
+ explicit Generator(unsigned int seed)
1459
+ : Validator(true, true, std::cin, /*constraints_file_path_=*/"", seed) {}
1460
+ };
1461
+
1462
+ class InputValidator : public Validator {
1463
+ public:
1464
+ // An InputValidator is always both whitespace and case sensitive.
1465
+ explicit InputValidator(int argc = 0, char** argv = nullptr)
1466
+ : Validator(true, true, std::cin, get_constraints_file(argc, argv), get_seed(argc, argv),
1467
+ get_params(argc, argv)) {}
1468
+
1469
+ private:
1470
+ static std::optional<unsigned int> get_seed(int argc, char** argv) {
1471
+ for(int i = 1; i < argc - 1; ++i) {
1472
+ if(argv[i] == generate_flag) {
1473
+ return std::stol(argv[i + 1]);
1474
+ }
1475
+ }
1476
+ // If no --generate is given, but `generat` is a substring of the binary path,
1477
+ // use the first argument as seed.
1478
+ if(std::string(argv[0]).find(generate_binary_substring) != std::string::npos) {
1479
+ return std::stol(argv[1]);
1480
+ }
1481
+ return std::nullopt;
1482
+ }
1483
+
1484
+ static std::unordered_map<std::string, ParamGenerator> get_params(int argc, char** argv) {
1485
+ std::unordered_map<std::string, ParamGenerator> params;
1486
+ for(int i = 1; i < argc - 1; ++i) {
1487
+ if(std::strlen(argv[i]) == 0 or argv[i][0] != '-') continue;
1488
+ if(argv[i] == generate_flag) {
1489
+ continue;
1490
+ }
1491
+ std::string_view name(argv[i] + 1);
1492
+ std::string_view value(argv[i + 1]);
1493
+ params.insert({std::string(name), ParamGenerator(value)});
1494
+ }
1495
+ return params;
1496
+ }
1497
+ };
1498
+
1499
+ class OutputValidator : public Validator {
1500
+ public:
1501
+ // An OutputValidator can be run in different modes.
1502
+ explicit OutputValidator(int argc, char** argv, std::istream& in_ = std::cin)
1503
+ : Validator(is_ws_sensitive(argc, argv), is_case_sensitive(argc, argv), in_,
1504
+ get_constraints_file(argc, argv)) {}
1505
+
1506
+ private:
1507
+ static bool is_ws_sensitive(int argc, char** argv) {
1508
+ for(int i = 1; i < argc; ++i) {
1509
+ if(argv[i] == ws_sensitive_flag) return true;
1510
+ }
1511
+ return false;
1512
+ }
1513
+
1514
+ static bool is_case_sensitive(int argc, char** argv) {
1515
+ for(int i = 1; i < argc; ++i) {
1516
+ if(argv[i] == case_sensitive_flag) return true;
1517
+ }
1518
+ return false;
1519
+ }
1520
+ };
ICPC/nwerc2023_A/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fb24aeac8306c68202fc2dde976466ba81c12dfeb111cd2df644468ba06ce0c3
3
+ size 26893358
ICPC/nwerc2023_A/init.yml ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ test_cases:
3
+ - in: 001-one_plug.in
4
+ out: 001-one_plug.ans
5
+ points: 1
6
+ - in: 002-one_socket.in
7
+ out: 002-one_socket.ans
8
+ points: 1
9
+ - in: 003-much_free.in
10
+ out: 003-much_free.ans
11
+ points: 1
12
+ - in: 004-much_free.in
13
+ out: 004-much_free.ans
14
+ points: 1
15
+ - in: 005-two_max_length.in
16
+ out: 005-two_max_length.ans
17
+ points: 1
18
+ - in: 006-greedy_edge_case_small.in
19
+ out: 006-greedy_edge_case_small.ans
20
+ points: 1
21
+ - in: 007-greedy_edge_case_small.in
22
+ out: 007-greedy_edge_case_small.ans
23
+ points: 1
24
+ - in: 008-tight-pack.in
25
+ out: 008-tight-pack.ans
26
+ points: 1
27
+ - in: 009-many_gaps.in
28
+ out: 009-many_gaps.ans
29
+ points: 1
30
+ - in: 010-greedy_edge_case.in
31
+ out: 010-greedy_edge_case.ans
32
+ points: 1
33
+ - in: 011-greedy_edge_case.in
34
+ out: 011-greedy_edge_case.ans
35
+ points: 1
36
+ - in: 012-almost_max_constraints.in
37
+ out: 012-almost_max_constraints.ans
38
+ points: 1
39
+ - in: 013-almost_max_constraints.in
40
+ out: 013-almost_max_constraints.ans
41
+ points: 1
42
+ - in: 014-random.in
43
+ out: 014-random.ans
44
+ points: 1
45
+ - in: 015-random.in
46
+ out: 015-random.ans
47
+ points: 1
48
+ - in: 016-random.in
49
+ out: 016-random.ans
50
+ points: 1
51
+ - in: 017-random.in
52
+ out: 017-random.ans
53
+ points: 1
54
+ - in: 018-random.in
55
+ out: 018-random.ans
56
+ points: 1
57
+ - in: 019-random.in
58
+ out: 019-random.ans
59
+ points: 1
60
+ - in: 020-random.in
61
+ out: 020-random.ans
62
+ points: 1
63
+ - in: 021-random.in
64
+ out: 021-random.ans
65
+ points: 1
66
+ - in: 022-max_constraints.in
67
+ out: 022-max_constraints.ans
68
+ points: 1
69
+ - in: 023-almost_max_constraints.in
70
+ out: 023-almost_max_constraints.ans
71
+ points: 1
72
+ - in: 024-almost_max_constraints.in
73
+ out: 024-almost_max_constraints.ans
74
+ points: 1
75
+ - in: 025-almost_max_constraints.in
76
+ out: 025-almost_max_constraints.ans
77
+ points: 1
78
+ - in: 026-greedy_edge_case.in
79
+ out: 026-greedy_edge_case.ans
80
+ points: 1
81
+ - in: 027-greedy_edge_case.in
82
+ out: 027-greedy_edge_case.ans
83
+ points: 1
84
+ - in: 028-greedy_edge_case.in
85
+ out: 028-greedy_edge_case.ans
86
+ points: 1
87
+ - in: 029-greedy_edge_case_small.in
88
+ out: 029-greedy_edge_case_small.ans
89
+ points: 1
90
+ - in: 030-greedy_edge_case_small.in
91
+ out: 030-greedy_edge_case_small.ans
92
+ points: 1
93
+ - in: 031-greedy_edge_case_small.in
94
+ out: 031-greedy_edge_case_small.ans
95
+ points: 1
96
+ - in: 032-greedy_edge_case_small.in
97
+ out: 032-greedy_edge_case_small.ans
98
+ points: 1
99
+ - in: 033-greedy_edge_case_small.in
100
+ out: 033-greedy_edge_case_small.ans
101
+ points: 1
102
+ - in: 034-three_type_case.in
103
+ out: 034-three_type_case.ans
104
+ points: 1
105
+ - in: 035-three_type_case.in
106
+ out: 035-three_type_case.ans
107
+ points: 1
108
+ - in: 036-three_type_case.in
109
+ out: 036-three_type_case.ans
110
+ points: 1
111
+ - in: 037-three_type_case.in
112
+ out: 037-three_type_case.ans
113
+ points: 1
114
+ - in: 038-three_type_case.in
115
+ out: 038-three_type_case.ans
116
+ points: 1
117
+ - in: 039-two_type_case.in
118
+ out: 039-two_type_case.ans
119
+ points: 1
120
+ - in: 040-two_type_case.in
121
+ out: 040-two_type_case.ans
122
+ points: 1
123
+ - in: 041-two_type_case.in
124
+ out: 041-two_type_case.ans
125
+ points: 1
126
+ - in: 042-two_type_case.in
127
+ out: 042-two_type_case.ans
128
+ points: 1
129
+ - in: 043-two_type_case.in
130
+ out: 043-two_type_case.ans
131
+ points: 1
132
+ - in: 044-some_large_plugs.in
133
+ out: 044-some_large_plugs.ans
134
+ points: 1
135
+ - in: 045-some_large_plugs.in
136
+ out: 045-some_large_plugs.ans
137
+ points: 1
138
+ - in: 046-some_large_plugs.in
139
+ out: 046-some_large_plugs.ans
140
+ points: 1
141
+ - in: 047-some_large_plugs.in
142
+ out: 047-some_large_plugs.ans
143
+ points: 1
144
+ - in: 048-some_large_plugs.in
145
+ out: 048-some_large_plugs.ans
146
+ points: 1
147
+ - in: 049-some_large_plugs.in
148
+ out: 049-some_large_plugs.ans
149
+ points: 1
150
+ - in: 050-some_large_plugs.in
151
+ out: 050-some_large_plugs.ans
152
+ points: 1
153
+ - in: 051-some_large_plugs.in
154
+ out: 051-some_large_plugs.ans
155
+ points: 1
156
+ - in: 052-some_large_plugs.in
157
+ out: 052-some_large_plugs.ans
158
+ points: 1
159
+ - in: 053-some_large_plugs.in
160
+ out: 053-some_large_plugs.ans
161
+ points: 1
162
+ - in: 054-some_large_plugs.in
163
+ out: 054-some_large_plugs.ans
164
+ points: 1
165
+ - in: 055-some_large_plugs.in
166
+ out: 055-some_large_plugs.ans
167
+ points: 1
168
+ - in: 056-some_large_plugs.in
169
+ out: 056-some_large_plugs.ans
170
+ points: 1
171
+ - in: 057-some_modulo_class.in
172
+ out: 057-some_modulo_class.ans
173
+ points: 1
174
+ - in: 058-some_modulo_class.in
175
+ out: 058-some_modulo_class.ans
176
+ points: 1
177
+ - in: 059-some_modulo_class.in
178
+ out: 059-some_modulo_class.ans
179
+ points: 1
180
+ - in: 060-some_modulo_class.in
181
+ out: 060-some_modulo_class.ans
182
+ points: 1
183
+ - in: 061-some_modulo_class.in
184
+ out: 061-some_modulo_class.ans
185
+ points: 1
186
+ - in: 062-some_modulo_class.in
187
+ out: 062-some_modulo_class.ans
188
+ points: 1
189
+ - in: 063-some_modulo_class.in
190
+ out: 063-some_modulo_class.ans
191
+ points: 1
192
+ - in: 064-some_modulo_class.in
193
+ out: 064-some_modulo_class.ans
194
+ points: 1
195
+ - in: 065-some_modulo_class.in
196
+ out: 065-some_modulo_class.ans
197
+ points: 1
198
+ - in: 066-some_modulo_class.in
199
+ out: 066-some_modulo_class.ans
200
+ points: 1
201
+ - in: 067-some_modulo_class.in
202
+ out: 067-some_modulo_class.ans
203
+ points: 1
204
+ - in: 068-some_modulo_class.in
205
+ out: 068-some_modulo_class.ans
206
+ points: 1
207
+ - in: 069-some_modulo_class.in
208
+ out: 069-some_modulo_class.ans
209
+ points: 1
210
+ - in: 070-some_modulo_class.in
211
+ out: 070-some_modulo_class.ans
212
+ points: 1
213
+ - in: 071-some_modulo_class.in
214
+ out: 071-some_modulo_class.ans
215
+ points: 1
216
+ - in: 072-some_modulo_class.in
217
+ out: 072-some_modulo_class.ans
218
+ points: 1
219
+ - in: 073-some_modulo_class.in
220
+ out: 073-some_modulo_class.ans
221
+ points: 1
222
+ - in: 074-some_modulo_class.in
223
+ out: 074-some_modulo_class.ans
224
+ points: 1
225
+ - in: 075-some_modulo_class.in
226
+ out: 075-some_modulo_class.ans
227
+ points: 1
228
+ - in: 076-some_modulo_class.in
229
+ out: 076-some_modulo_class.ans
230
+ points: 1
231
+ - in: 077-some_modulo_class.in
232
+ out: 077-some_modulo_class.ans
233
+ points: 1
234
+ - in: 078-some_modulo_class.in
235
+ out: 078-some_modulo_class.ans
236
+ points: 1
237
+ - in: 079-some_modulo_class.in
238
+ out: 079-some_modulo_class.ans
239
+ points: 1
240
+ - in: 080-some_modulo_class.in
241
+ out: 080-some_modulo_class.ans
242
+ points: 1
243
+ - in: 081-some_modulo_class.in
244
+ out: 081-some_modulo_class.ans
245
+ points: 1
246
+ - in: 082-some_modulo_class.in
247
+ out: 082-some_modulo_class.ans
248
+ points: 1
249
+ - in: 083-some_modulo_class.in
250
+ out: 083-some_modulo_class.ans
251
+ points: 1
252
+ - in: 084-some_modulo_class.in
253
+ out: 084-some_modulo_class.ans
254
+ points: 1
255
+ - in: 085-some_modulo_class.in
256
+ out: 085-some_modulo_class.ans
257
+ points: 1
258
+ - in: 086-some_modulo_class.in
259
+ out: 086-some_modulo_class.ans
260
+ points: 1
261
+ - in: 087-some_modulo_class.in
262
+ out: 087-some_modulo_class.ans
263
+ points: 1
264
+ - in: 088-some_modulo_class.in
265
+ out: 088-some_modulo_class.ans
266
+ points: 1
267
+ - in: 089-some_modulo_class.in
268
+ out: 089-some_modulo_class.ans
269
+ points: 1
270
+ - in: 090-some_modulo_class.in
271
+ out: 090-some_modulo_class.ans
272
+ points: 1
273
+ - in: 091-some_modulo_class.in
274
+ out: 091-some_modulo_class.ans
275
+ points: 1
276
+ - in: 092-some_modulo_class.in
277
+ out: 092-some_modulo_class.ans
278
+ points: 1
279
+ - in: 093-some_modulo_class.in
280
+ out: 093-some_modulo_class.ans
281
+ points: 1
282
+ - in: 094-some_modulo_class.in
283
+ out: 094-some_modulo_class.ans
284
+ points: 1
285
+ - in: 095-some_modulo_class.in
286
+ out: 095-some_modulo_class.ans
287
+ points: 1
288
+ - in: 096-some_modulo_class.in
289
+ out: 096-some_modulo_class.ans
290
+ points: 1
291
+ - in: 097-some_modulo_class.in
292
+ out: 097-some_modulo_class.ans
293
+ points: 1
294
+ - in: 098-some_modulo_class.in
295
+ out: 098-some_modulo_class.ans
296
+ points: 1
297
+ - in: 099-some_modulo_class.in
298
+ out: 099-some_modulo_class.ans
299
+ points: 1
300
+ - in: 100-some_modulo_class.in
301
+ out: 100-some_modulo_class.ans
302
+ points: 1
303
+ - in: 101-some_modulo_class.in
304
+ out: 101-some_modulo_class.ans
305
+ points: 1
306
+ - in: 102-some_modulo_class.in
307
+ out: 102-some_modulo_class.ans
308
+ points: 1
309
+ - in: 103-some_modulo_class.in
310
+ out: 103-some_modulo_class.ans
311
+ points: 1
312
+ - in: 104-some_modulo_class.in
313
+ out: 104-some_modulo_class.ans
314
+ points: 1
315
+ - in: 105-some_modulo_class.in
316
+ out: 105-some_modulo_class.ans
317
+ points: 1
318
+ - in: 106-some_modulo_class.in
319
+ out: 106-some_modulo_class.ans
320
+ points: 1
321
+ - in: 107-some_modulo_class.in
322
+ out: 107-some_modulo_class.ans
323
+ points: 1
324
+ - in: 108-some_modulo_class.in
325
+ out: 108-some_modulo_class.ans
326
+ points: 1
327
+ - in: 109-some_modulo_class.in
328
+ out: 109-some_modulo_class.ans
329
+ points: 1
330
+ - in: 110-some_modulo_class.in
331
+ out: 110-some_modulo_class.ans
332
+ points: 1
333
+ - in: 111-some_modulo_class.in
334
+ out: 111-some_modulo_class.ans
335
+ points: 1
336
+ - in: 112-some_modulo_class.in
337
+ out: 112-some_modulo_class.ans
338
+ points: 1
339
+ - in: 113-some_modulo_class.in
340
+ out: 113-some_modulo_class.ans
341
+ points: 1
342
+ - in: 114-some_modulo_class.in
343
+ out: 114-some_modulo_class.ans
344
+ points: 1
345
+ - in: 115-some_modulo_class.in
346
+ out: 115-some_modulo_class.ans
347
+ points: 1
348
+ - in: 116-some_modulo_class.in
349
+ out: 116-some_modulo_class.ans
350
+ points: 1
ICPC/nwerc2023_B/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ec6dceb011ea9328d261a0dfbff0d804afec39333cb02894d8054f26e978da0d
3
+ size 22766975
ICPC/nwerc2023_B/init.yml ADDED
@@ -0,0 +1,406 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ checker:
3
+ args:
4
+ files:
5
+ - output_validators/output_validator/validate.h
6
+ - output_validators/output_validator/outputValidator.cpp
7
+ lang: CPP17
8
+ type: default
9
+ name: bridged
10
+ test_cases:
11
+ - in: 001-earlyBreak.in
12
+ out: 001-earlyBreak.ans
13
+ points: 1
14
+ - in: 002-manual_impossible.in
15
+ out: 002-manual_impossible.ans
16
+ points: 1
17
+ - in: 003-manual_impossible.in
18
+ out: 003-manual_impossible.ans
19
+ points: 1
20
+ - in: 004-ones_twos.in
21
+ out: 004-ones_twos.ans
22
+ points: 1
23
+ - in: 005-ones_twos.in
24
+ out: 005-ones_twos.ans
25
+ points: 1
26
+ - in: 006-ones_twos.in
27
+ out: 006-ones_twos.ans
28
+ points: 1
29
+ - in: 007-residue.in
30
+ out: 007-residue.ans
31
+ points: 1
32
+ - in: 008-residue.in
33
+ out: 008-residue.ans
34
+ points: 1
35
+ - in: 009-residue.in
36
+ out: 009-residue.ans
37
+ points: 1
38
+ - in: 010-residue.in
39
+ out: 010-residue.ans
40
+ points: 1
41
+ - in: 011-residue.in
42
+ out: 011-residue.ans
43
+ points: 1
44
+ - in: 012-residue.in
45
+ out: 012-residue.ans
46
+ points: 1
47
+ - in: 013-residue.in
48
+ out: 013-residue.ans
49
+ points: 1
50
+ - in: 014-residue.in
51
+ out: 014-residue.ans
52
+ points: 1
53
+ - in: 015-residue.in
54
+ out: 015-residue.ans
55
+ points: 1
56
+ - in: 016-residue.in
57
+ out: 016-residue.ans
58
+ points: 1
59
+ - in: 017-residue.in
60
+ out: 017-residue.ans
61
+ points: 1
62
+ - in: 018-residue.in
63
+ out: 018-residue.ans
64
+ points: 1
65
+ - in: 019-residue.in
66
+ out: 019-residue.ans
67
+ points: 1
68
+ - in: 020-random.in
69
+ out: 020-random.ans
70
+ points: 1
71
+ - in: 021-random.in
72
+ out: 021-random.ans
73
+ points: 1
74
+ - in: 022-random.in
75
+ out: 022-random.ans
76
+ points: 1
77
+ - in: 023-random.in
78
+ out: 023-random.ans
79
+ points: 1
80
+ - in: 024-random.in
81
+ out: 024-random.ans
82
+ points: 1
83
+ - in: 025-useAll.in
84
+ out: 025-useAll.ans
85
+ points: 1
86
+ - in: 026-useAll.in
87
+ out: 026-useAll.ans
88
+ points: 1
89
+ - in: 027-useAll.in
90
+ out: 027-useAll.ans
91
+ points: 1
92
+ - in: 028-unique.in
93
+ out: 028-unique.ans
94
+ points: 1
95
+ - in: 029-unique.in
96
+ out: 029-unique.ans
97
+ points: 1
98
+ - in: 030-unique.in
99
+ out: 030-unique.ans
100
+ points: 1
101
+ - in: 031-unique.in
102
+ out: 031-unique.ans
103
+ points: 1
104
+ - in: 032-unique.in
105
+ out: 032-unique.ans
106
+ points: 1
107
+ - in: 033-unique.in
108
+ out: 033-unique.ans
109
+ points: 1
110
+ - in: 034-many.in
111
+ out: 034-many.ans
112
+ points: 1
113
+ - in: 035-residue.in
114
+ out: 035-residue.ans
115
+ points: 1
116
+ - in: 036-residue.in
117
+ out: 036-residue.ans
118
+ points: 1
119
+ - in: 037-residue.in
120
+ out: 037-residue.ans
121
+ points: 1
122
+ - in: 038-residue.in
123
+ out: 038-residue.ans
124
+ points: 1
125
+ - in: 039-residue.in
126
+ out: 039-residue.ans
127
+ points: 1
128
+ - in: 040-residue.in
129
+ out: 040-residue.ans
130
+ points: 1
131
+ - in: 041-residue.in
132
+ out: 041-residue.ans
133
+ points: 1
134
+ - in: 042-residue.in
135
+ out: 042-residue.ans
136
+ points: 1
137
+ - in: 043-residue.in
138
+ out: 043-residue.ans
139
+ points: 1
140
+ - in: 044-residue.in
141
+ out: 044-residue.ans
142
+ points: 1
143
+ - in: 045-residue.in
144
+ out: 045-residue.ans
145
+ points: 1
146
+ - in: 046-residue.in
147
+ out: 046-residue.ans
148
+ points: 1
149
+ - in: 047-residue.in
150
+ out: 047-residue.ans
151
+ points: 1
152
+ - in: 048-manual_possible.in
153
+ out: 048-manual_possible.ans
154
+ points: 1
155
+ - in: 049-manual_possible.in
156
+ out: 049-manual_possible.ans
157
+ points: 1
158
+ - in: 050-manual_possible.in
159
+ out: 050-manual_possible.ans
160
+ points: 1
161
+ - in: 051-manual_possible.in
162
+ out: 051-manual_possible.ans
163
+ points: 1
164
+ - in: 052-manual_possible.in
165
+ out: 052-manual_possible.ans
166
+ points: 1
167
+ - in: 053-manual_possible.in
168
+ out: 053-manual_possible.ans
169
+ points: 1
170
+ - in: 054-manual_possible.in
171
+ out: 054-manual_possible.ans
172
+ points: 1
173
+ - in: 055-manual_possible.in
174
+ out: 055-manual_possible.ans
175
+ points: 1
176
+ - in: 056-manual_possible.in
177
+ out: 056-manual_possible.ans
178
+ points: 1
179
+ - in: 057-manual_possible.in
180
+ out: 057-manual_possible.ans
181
+ points: 1
182
+ - in: 058-manual_possible.in
183
+ out: 058-manual_possible.ans
184
+ points: 1
185
+ - in: 059-manual_impossible.in
186
+ out: 059-manual_impossible.ans
187
+ points: 1
188
+ - in: 060-manual_impossible.in
189
+ out: 060-manual_impossible.ans
190
+ points: 1
191
+ - in: 061-manual_impossible.in
192
+ out: 061-manual_impossible.ans
193
+ points: 1
194
+ - in: 062-random.in
195
+ out: 062-random.ans
196
+ points: 1
197
+ - in: 063-random.in
198
+ out: 063-random.ans
199
+ points: 1
200
+ - in: 064-random.in
201
+ out: 064-random.ans
202
+ points: 1
203
+ - in: 065-random.in
204
+ out: 065-random.ans
205
+ points: 1
206
+ - in: 066-random.in
207
+ out: 066-random.ans
208
+ points: 1
209
+ - in: 067-random.in
210
+ out: 067-random.ans
211
+ points: 1
212
+ - in: 068-random.in
213
+ out: 068-random.ans
214
+ points: 1
215
+ - in: 069-random.in
216
+ out: 069-random.ans
217
+ points: 1
218
+ - in: 070-random.in
219
+ out: 070-random.ans
220
+ points: 1
221
+ - in: 071-random.in
222
+ out: 071-random.ans
223
+ points: 1
224
+ - in: 072-range.in
225
+ out: 072-range.ans
226
+ points: 1
227
+ - in: 073-range.in
228
+ out: 073-range.ans
229
+ points: 1
230
+ - in: 074-range.in
231
+ out: 074-range.ans
232
+ points: 1
233
+ - in: 075-range.in
234
+ out: 075-range.ans
235
+ points: 1
236
+ - in: 076-range.in
237
+ out: 076-range.ans
238
+ points: 1
239
+ - in: 077-range.in
240
+ out: 077-range.ans
241
+ points: 1
242
+ - in: 078-range.in
243
+ out: 078-range.ans
244
+ points: 1
245
+ - in: 079-range.in
246
+ out: 079-range.ans
247
+ points: 1
248
+ - in: 080-range.in
249
+ out: 080-range.ans
250
+ points: 1
251
+ - in: 081-range.in
252
+ out: 081-range.ans
253
+ points: 1
254
+ - in: 082-range.in
255
+ out: 082-range.ans
256
+ points: 1
257
+ - in: 083-range.in
258
+ out: 083-range.ans
259
+ points: 1
260
+ - in: 084-many_same.in
261
+ out: 084-many_same.ans
262
+ points: 1
263
+ - in: 085-many_same.in
264
+ out: 085-many_same.ans
265
+ points: 1
266
+ - in: 086-many_same.in
267
+ out: 086-many_same.ans
268
+ points: 1
269
+ - in: 087-many_same.in
270
+ out: 087-many_same.ans
271
+ points: 1
272
+ - in: 088-many_same.in
273
+ out: 088-many_same.ans
274
+ points: 1
275
+ - in: 089-many_same.in
276
+ out: 089-many_same.ans
277
+ points: 1
278
+ - in: 090-many_same.in
279
+ out: 090-many_same.ans
280
+ points: 1
281
+ - in: 091-many_same.in
282
+ out: 091-many_same.ans
283
+ points: 1
284
+ - in: 092-many_same.in
285
+ out: 092-many_same.ans
286
+ points: 1
287
+ - in: 093-many_same.in
288
+ out: 093-many_same.ans
289
+ points: 1
290
+ - in: 094-many_same.in
291
+ out: 094-many_same.ans
292
+ points: 1
293
+ - in: 095-many_same.in
294
+ out: 095-many_same.ans
295
+ points: 1
296
+ - in: 096-many_same.in
297
+ out: 096-many_same.ans
298
+ points: 1
299
+ - in: 097-powers_of_two.in
300
+ out: 097-powers_of_two.ans
301
+ points: 1
302
+ - in: 098-powers_of_two.in
303
+ out: 098-powers_of_two.ans
304
+ points: 1
305
+ - in: 099-powers_of_two.in
306
+ out: 099-powers_of_two.ans
307
+ points: 1
308
+ - in: 100-powers_of_two.in
309
+ out: 100-powers_of_two.ans
310
+ points: 1
311
+ - in: 101-powers_of_three.in
312
+ out: 101-powers_of_three.ans
313
+ points: 1
314
+ - in: 102-powers_of_three.in
315
+ out: 102-powers_of_three.ans
316
+ points: 1
317
+ - in: 103-diviors.in
318
+ out: 103-diviors.ans
319
+ points: 1
320
+ - in: 104-max.in
321
+ out: 104-max.ans
322
+ points: 1
323
+ - in: 105-max.in
324
+ out: 105-max.ans
325
+ points: 1
326
+ - in: 106-max.in
327
+ out: 106-max.ans
328
+ points: 1
329
+ - in: 107-max.in
330
+ out: 107-max.ans
331
+ points: 1
332
+ - in: 108-min.in
333
+ out: 108-min.ans
334
+ points: 1
335
+ - in: 109-min.in
336
+ out: 109-min.ans
337
+ points: 1
338
+ - in: 110-min.in
339
+ out: 110-min.ans
340
+ points: 1
341
+ - in: 111-min.in
342
+ out: 111-min.ans
343
+ points: 1
344
+ - in: 112-min.in
345
+ out: 112-min.ans
346
+ points: 1
347
+ - in: 113-min.in
348
+ out: 113-min.ans
349
+ points: 1
350
+ - in: 114-small.in
351
+ out: 114-small.ans
352
+ points: 1
353
+ - in: 115-small.in
354
+ out: 115-small.ans
355
+ points: 1
356
+ - in: 116-small.in
357
+ out: 116-small.ans
358
+ points: 1
359
+ - in: 117-small.in
360
+ out: 117-small.ans
361
+ points: 1
362
+ - in: 118-small.in
363
+ out: 118-small.ans
364
+ points: 1
365
+ - in: 119-small.in
366
+ out: 119-small.ans
367
+ points: 1
368
+ - in: 120-small.in
369
+ out: 120-small.ans
370
+ points: 1
371
+ - in: 121-small.in
372
+ out: 121-small.ans
373
+ points: 1
374
+ - in: 122-small.in
375
+ out: 122-small.ans
376
+ points: 1
377
+ - in: 123-small.in
378
+ out: 123-small.ans
379
+ points: 1
380
+ - in: 124-small.in
381
+ out: 124-small.ans
382
+ points: 1
383
+ - in: 125-small.in
384
+ out: 125-small.ans
385
+ points: 1
386
+ - in: 126-small.in
387
+ out: 126-small.ans
388
+ points: 1
389
+ - in: 127-small.in
390
+ out: 127-small.ans
391
+ points: 1
392
+ - in: 128-small.in
393
+ out: 128-small.ans
394
+ points: 1
395
+ - in: 129-small.in
396
+ out: 129-small.ans
397
+ points: 1
398
+ - in: 130-small.in
399
+ out: 130-small.ans
400
+ points: 1
401
+ - in: 131-small.in
402
+ out: 131-small.ans
403
+ points: 1
404
+ - in: 132-small.in
405
+ out: 132-small.ans
406
+ points: 1
ICPC/nwerc2023_B/output_validators/output_validator/outputValidator.cpp ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #include<cstdlib>
3
+ int qwerty_getcode(int code) {
4
+ return code == 42? 0: 1;
5
+ }
6
+ namespace std {
7
+ void qwerty_exit(int code){
8
+ exit(qwerty_getcode(code));
9
+ }
10
+ } using std::qwerty_exit;
11
+ #define exit qwerty_exit
12
+ #define main qwerty_main
13
+ #include "validate.h"
14
+
15
+ int main(int argc, char **argv) {
16
+ OutputValidator::init(argc, argv); // initialize streams, rng and parse arguments
17
+ using namespace OutputValidator;
18
+
19
+ Integer n = testIn.integer();
20
+ Integer w = testIn.integer();
21
+ auto ws = testIn.integers(n);
22
+ std::sort(ws.begin(), ws.end());
23
+ ws.push_back(LARGE);
24
+
25
+ auto check = [&](std::vector<std::vector<Integer>> wall, std::string_view sol, Verdict v){
26
+ for (auto& row : wall) {
27
+ Integer sum = 0;
28
+ for (Integer& brick : row) {
29
+ if (*std::lower_bound(ws.begin(), ws.end(), brick) != brick) {
30
+ juryOut << sol << " solution contains invalid brick: " << brick << v;
31
+ }
32
+ brick += sum;
33
+ sum = brick;
34
+ }
35
+ if (sum != w) {
36
+ juryOut << sol << " solution has invalid row length: " << sum << v;
37
+ }
38
+ row.pop_back();
39
+ }
40
+ Integer a = 0;
41
+ Integer b = 0;
42
+ while(a < wall[0].size() && b < wall[1].size()) {
43
+ if(wall[0][a] < wall[1][b])
44
+ a++;
45
+ else if(wall[0][a] > wall[1][b])
46
+ b++;
47
+ else
48
+ juryOut << sol << " solution is unstable at x=" << wall[0][a] << v;
49
+ }
50
+ };
51
+
52
+ auto jury = juryAns.string(std::regex("(impossible|possible)", std::regex::icase));
53
+ auto team = teamAns.string(std::regex("(impossible|possible)", std::regex::icase));
54
+ if (caseSensitive) {
55
+ if(jury != "possible" && jury != "impossible") juryOut << "wrong case" << FAIL;
56
+ if(team != "possible" && team != "impossible") juryOut << "wrong case" << WA;
57
+ }
58
+ toLower(jury);
59
+ toLower(team);
60
+ teamAns.newline();
61
+
62
+ if(jury == "possible") {
63
+ Integer rows = 2; //juryAns.integer(1, 11);
64
+ std::vector<std::vector<Integer>> wall(rows);
65
+ for (auto& row : wall) {
66
+ Integer k = juryAns.integer(1, w+1);
67
+ row = juryAns.integers(1, w+1, k);
68
+ }
69
+ check(wall, "jury", FAIL);
70
+ }
71
+ if(team == "possible") {
72
+ Integer rows = 2; //teamAns.integer(1, 11);
73
+ std::vector<std::vector<Integer>> wall(rows);
74
+ for (auto& row : wall) {
75
+ Integer k = teamAns.integer(1, w+1);
76
+ teamAns.newline();
77
+ row = teamAns.integers(1, w+1, k);
78
+ teamAns.newline();
79
+ }
80
+ check(wall, "team", WA);
81
+ }
82
+
83
+ if(jury == "possible" && team == "impossible") juryOut << "team found no solution but jury did" << WA;
84
+ if(team == "possible" && jury == "impossible") juryOut << "jury found no solution but team did" << FAIL;
85
+
86
+ teamAns.eof();
87
+ return AC;
88
+ }
89
+
90
+ #undef main
91
+ #include<cstdio>
92
+ #include<vector>
93
+ #include<string>
94
+ #include<filesystem>
95
+ int main(int argc, char **argv) {
96
+ namespace fs = std::filesystem;
97
+ freopen(argv[2], "r", stdin);
98
+ char judge_out[] = "/dev";
99
+ std::vector<char*> new_argv = {
100
+ argv[0], argv[1], argv[3],
101
+ judge_out,
102
+ };
103
+ return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data()));
104
+ }
ICPC/nwerc2023_B/output_validators/output_validator/validate.h ADDED
@@ -0,0 +1,2662 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //============================================================================//
2
+ // validate.h //
3
+ //============================================================================//
4
+ // This header can be used to safely parse team output tokenwise. We support: //
5
+ // - string tokens (get converted to lowercase) //
6
+ // - integer tokens in [-2^63, 2^63) //
7
+ // - float tokens (relative and absolute error of 10^6 is allowed by default) //
8
+ // Tokens need to be separated by whitespace (any amount). The following //
9
+ // command line flags allow stricter checking: //
10
+ // - caseSensitive: string tokens don't get converted to lowercase //
11
+ // - space_change_sensitive: tokens need to be separated by the corect //
12
+ // amount of whitespaces //
13
+ // - FLOAT_{RELATIVE|ABSOLUTE}_TOLERANCE: allowed relative/absolute error //
14
+ // //
15
+ // This header can also be used to safely verify input files. In this case //
16
+ // tokens are case sensitive and all whitespaces have to be checked. Also //
17
+ // whitespaces are not interchangeable. //
18
+ // //
19
+ // This header can be used to generate random numbers in a deterministic and //
20
+ // reproducable fashion. (The randomness is consistent across compilers and //
21
+ // machines) //
22
+ //============================================================================//
23
+ // version 2.3.2 //
24
+ // https://github.com/mzuenni/icpc-header //
25
+ //============================================================================//
26
+
27
+ #ifndef VALIDATE_H
28
+ #define VALIDATE_H
29
+
30
+ #include <algorithm>
31
+ #include <array>
32
+ #include <bitset>
33
+ #include <cctype>
34
+ #include <cmath>
35
+ #include <charconv>
36
+ #include <complex>
37
+ #include <cstdlib>
38
+ #include <filesystem>
39
+ #include <fstream>
40
+ #include <functional>
41
+ #include <iomanip>
42
+ #include <iostream>
43
+ #include <limits>
44
+ #include <map>
45
+ #include <numeric>
46
+ #include <optional>
47
+ #include <queue>
48
+ #include <random>
49
+ #include <regex>
50
+ #include <set>
51
+ #include <string>
52
+ #include <string_view>
53
+ #include <typeinfo>
54
+ #include <typeindex>
55
+ #include <type_traits>
56
+ #include <utility>
57
+ #include <variant>
58
+ #include <vector>
59
+
60
+
61
+ //============================================================================//
62
+ // Basic definitions and constants //
63
+ //============================================================================//
64
+ // default types
65
+ using Integer = std::int64_t;
66
+ using Real = long double;
67
+
68
+ // derived types
69
+ using UInteger = std::make_unsigned<Integer>::type;
70
+ constexpr Integer operator ""_int(unsigned long long int value) {return static_cast<Integer>(value);}
71
+ constexpr UInteger operator ""_uint(unsigned long long int value) {return static_cast<UInteger>(value);}
72
+ constexpr Real operator ""_real(unsigned long long int value) {return static_cast<Real>(value);}
73
+ constexpr Real operator ""_real(long double value) {return static_cast<Real>(value);}
74
+
75
+ // settings which can be overwritten before the include!
76
+ //#define DOUBLE_FALLBACK
77
+ namespace Settings {
78
+ namespace details {
79
+ using RandomEngine = std::mt19937_64;
80
+ constexpr Integer LARGE = 0x3FFF'FFFF'FFFF'FFFF;
81
+ constexpr bool DEFAULT_CASE_LOWER = true;
82
+ constexpr int DEFAULT_PRECISION = 6;
83
+ constexpr Real DEFAULT_EPS = 1e-6_real;
84
+
85
+ [[noreturn]] void exitVerdict(int exitCode) {
86
+ //throw exitCode;
87
+ //quick_exit(exitCode);
88
+ std::exit(exitCode);
89
+ }
90
+ }
91
+ using namespace details;
92
+ }
93
+ // make settings publically available
94
+ using Settings::RandomEngine;
95
+ using Settings::LARGE;
96
+ using Settings::DEFAULT_CASE_LOWER;
97
+ using Settings::DEFAULT_PRECISION;
98
+ using Settings::DEFAULT_EPS;
99
+ using Settings::exitVerdict;
100
+
101
+ // useful constants
102
+ constexpr std::string_view LETTER = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
103
+ constexpr std::string_view UPPER = LETTER.substr(0, 26);
104
+ constexpr std::string_view LOWER = LETTER.substr(26);
105
+ constexpr std::string_view VOWEL = "AEIOUaeiou";
106
+ constexpr std::string_view UPPER_VOWELS = VOWEL.substr(0, 5);
107
+ constexpr std::string_view LOWER_VOWELS = VOWEL.substr(5);
108
+ constexpr std::string_view CONSONANT = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz";
109
+ constexpr std::string_view UPPER_CONSONANT = CONSONANT.substr(0, 26 - 5);
110
+ constexpr std::string_view LOWER_CONSONANT = CONSONANT.substr(26 - 5);
111
+ constexpr std::string_view ALPHA_NUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
112
+ constexpr std::string_view UPPER_ALPHA_NUMERIC = ALPHA_NUMERIC.substr(0, 10 + 26);
113
+ constexpr std::string_view LOWER_ALPHA_NUMERIC = "0123456789abcdefghijklmnopqrstuvwxyz";
114
+ constexpr std::string_view DIGITS = ALPHA_NUMERIC.substr(0, 10);
115
+ constexpr std::string_view BRACKETS = "()[]{}<>";
116
+ constexpr char NEWLINE = '\n';
117
+ constexpr char SPACE = ' ';
118
+ constexpr char NOSEP = '\0';
119
+ constexpr Real PI = 3.1415926535897932384626433832795028_real;
120
+
121
+
122
+ //============================================================================//
123
+ // internal definitions and constants //
124
+ //============================================================================//
125
+ constexpr UInteger DEFAULT_SEED = 3141592653589793238_uint;
126
+ constexpr std::string_view CASE_SENSITIVE = "case_sensitive";
127
+ constexpr std::string_view SPACE_SENSITIVE = "space_change_sensitive";
128
+ constexpr std::string_view FLOAT_ABSOLUTE_TOLERANCE = "float_absolute_tolerance";
129
+ constexpr std::string_view FLOAT_RELATIVE_TOLERANCE = "float_relative_tolerance";
130
+ constexpr std::string_view FLOAT_TOLERANCE = "float_tolerance";
131
+ constexpr std::string_view JUDGE_MESSAGE = "null";
132
+ constexpr char DEFAULT_SEPARATOR = SPACE;
133
+ constexpr std::string_view EMPTY_COMMAND = "";
134
+ constexpr std::string_view COMMAND_PREFIX = "--";
135
+ constexpr std::string_view CONSTRAINT_COMMAND = "--constraints_file";
136
+ constexpr std::string_view SEED_COMMAND = "--seed";
137
+ constexpr auto REGEX_OPTIONS = std::regex::nosubs | std::regex::optimize;
138
+ inline const std::regex INTEGER_REGEX("0|-?[1-9][0-9]*", REGEX_OPTIONS);
139
+ inline const std::regex REAL_REGEX("-?(0|([1-9][0-9]*))(\\.[0-9]*)?([eE][+-]?(0|([1-9][0-9]*)))?", REGEX_OPTIONS);
140
+ inline const std::regex STRICT_REAL_REGEX("-?(0|([1-9][0-9]*))\\.?[0-9]*", REGEX_OPTIONS);
141
+
142
+ static_assert(2'000'000'000'000'000'000_int < LARGE / 2, "LARGE too small");
143
+ static_assert(LARGE <= std::numeric_limits<Integer>::max() / 2, "LARGE too big");
144
+
145
+ static_assert(-1 == 0xFFFF'FFFF'FFFF'FFFF_int, "Two's complement for signed numbers is required" );
146
+ static_assert(std::is_convertible_v<Integer, UInteger>, "Incompatible Integer and UInteger types?!");
147
+ static_assert(std::is_convertible_v<UInteger, Integer>, "Incompatible Integer and UInteger types?!");
148
+ static_assert(sizeof(Integer) == sizeof(UInteger), "Incompatible Integer and UInteger types?!");
149
+
150
+ template<typename T = std::logic_error>
151
+ constexpr void judgeAssert(bool asserted, std::string_view message) {
152
+ if (!asserted) throw T(message.data());
153
+ }
154
+
155
+
156
+ //============================================================================//
157
+ // SFINAE //
158
+ //============================================================================//
159
+ namespace details {
160
+ template<typename T, typename = void>
161
+ struct IsContainer : std::false_type {};
162
+
163
+ template<typename T>
164
+ struct IsContainer<T, std::void_t<decltype(std::begin(std::declval<std::add_lvalue_reference_t<T>>()))>> : std::true_type {
165
+ using iterator_type = decltype(std::begin(std::declval<std::add_lvalue_reference_t<T>>()));
166
+ using value_type = std::remove_reference_t<decltype(*std::begin(std::declval<std::add_lvalue_reference_t<T>>()))>;
167
+ };
168
+
169
+ template<typename T>
170
+ struct IsStdArray : std::false_type {};
171
+
172
+ template<typename T, std::size_t N>
173
+ struct IsStdArray<std::array<T, N>> : std::true_type {};
174
+
175
+ template<typename T, typename = void>
176
+ struct IsTupleLike : std::false_type {};
177
+
178
+ template<typename T>
179
+ struct IsTupleLike<T, std::void_t<decltype(sizeof(std::tuple_size<T>))>> : std::true_type {};
180
+
181
+ template<typename T, typename = void>
182
+ struct HasOstreamOperator : std::false_type {};
183
+
184
+ template<typename T>
185
+ struct HasOstreamOperator<T, std::void_t<decltype(std::declval<std::ostream>() << std::declval<T>())>> : std::true_type {};
186
+ }
187
+
188
+
189
+ //============================================================================//
190
+ // Verdicts //
191
+ //============================================================================//
192
+ struct Verdict final {
193
+ int exitCode;
194
+
195
+ constexpr explicit Verdict(int exitCode_ = 1) : exitCode(exitCode_) {}
196
+
197
+ constexpr operator int() const {
198
+ return exitCode;
199
+ }
200
+
201
+ [[noreturn]] void exit() const {
202
+ exitVerdict(exitCode);
203
+ }
204
+
205
+ friend void operator<<(std::ostream& os, const Verdict& v) {
206
+ os << std::endl;
207
+ v.exit();
208
+ }
209
+ };
210
+
211
+ // default verdicts (we do not support scoring)
212
+ constexpr Verdict AC(42);
213
+ constexpr Verdict WA(43);
214
+ constexpr Verdict PE = WA;
215
+ constexpr Verdict FAIL(1);
216
+
217
+
218
+ //============================================================================//
219
+ // Output streams //
220
+ //============================================================================//
221
+ class NullStream final : public std::ostream {
222
+ class NullBuffer final : public std::streambuf {
223
+ protected:
224
+ std::streamsize xsputn(const char* /**/, std::streamsize n) override {
225
+ return n;
226
+ }
227
+ int overflow(int c = std::char_traits<char>::eof()) override {
228
+ return std::char_traits<char>::not_eof(c);
229
+ }
230
+ } nullBuffer;
231
+ public:
232
+ NullStream() : std::ostream(&nullBuffer) {}
233
+ };
234
+
235
+ namespace details {
236
+ NullStream nullStream;
237
+ }
238
+
239
+ class OutputStream final {
240
+ std::unique_ptr<std::ofstream> managed;
241
+ std::ostream* os;
242
+
243
+ void init() {
244
+ *os << std::boolalpha;
245
+ *os << std::fixed;
246
+ *os << std::setprecision(DEFAULT_PRECISION);
247
+ }
248
+
249
+ public:
250
+ OutputStream() : os(&details::nullStream) {}
251
+ OutputStream(std::ostream& os_) : os(&os_) {init();}
252
+ explicit OutputStream(const std::filesystem::path& path) : managed(std::make_unique<std::ofstream>(path)), os(managed.get()) {
253
+ judgeAssert<std::runtime_error>(managed->good(), "OutputStream: Could not open File: " + path.string());
254
+ init();
255
+ }
256
+
257
+ OutputStream(OutputStream&& other) = default;
258
+ OutputStream& operator=(OutputStream&& other) = default;
259
+
260
+ OutputStream(const OutputStream&) = delete;
261
+ OutputStream& operator=(const OutputStream&) = delete;
262
+
263
+
264
+ template<typename L, typename R>
265
+ OutputStream& operator<<(const std::pair<L, R>& t) {
266
+ return *this << t.first << DEFAULT_SEPARATOR << t.second;
267
+ }
268
+
269
+ template<typename... Args>
270
+ OutputStream& operator<<(const std::tuple<Args...>& t) {
271
+ return join(t, std::index_sequence_for<Args...>(), DEFAULT_SEPARATOR);
272
+ }
273
+
274
+ template<typename T>
275
+ OutputStream& operator<<(const T& x) {
276
+ if constexpr ((std::is_array_v<T> and !std::is_same_v<std::decay_t<T>, char*>) or
277
+ (details::IsContainer<T>{} and !details::HasOstreamOperator<T>{})) {
278
+ return join(std::begin(x), std::end(x), DEFAULT_SEPARATOR);
279
+ } else {
280
+ *os << x;
281
+ return *this;
282
+ }
283
+ }
284
+
285
+ OutputStream& operator<<(std::ostream& (*manip)(std::ostream&)) {
286
+ *os << manip;
287
+ return *this;
288
+ }
289
+
290
+ template<typename Tuple, std::size_t... Is>
291
+ OutputStream& join(const Tuple& t, std::index_sequence<Is...> /**/, char separator) {
292
+ static_assert(std::tuple_size_v<Tuple> == sizeof...(Is));
293
+ if (separator != NOSEP) ((*os << (Is == 0 ? std::string_view() : std::string_view(&separator, 1)), *this << std::get<Is>(t)), ...);
294
+ else ((*this << std::get<Is>(t)), ...);
295
+ return *this;
296
+ }
297
+
298
+ template<typename T>
299
+ OutputStream& join(T first, T last, char separator) {
300
+ for (auto it = first; it != last; it++) {
301
+ if (it != first and separator != NOSEP) *os << separator;
302
+ *this << *it;
303
+ }
304
+ return *this;
305
+ }
306
+ };
307
+
308
+ namespace ValidateBase {
309
+ // define this early so everyone can use it!
310
+ OutputStream juryErr(std::cerr);
311
+ OutputStream juryOut(std::cout);
312
+ }
313
+
314
+ // allow printing colletions as:
315
+ // join(begin(), end(), [sep])
316
+ namespace details {
317
+ template<typename C>
318
+ class TempWriter final {
319
+ C callable;
320
+ public:
321
+ constexpr explicit TempWriter(const C& callable_) : callable(callable_) {}
322
+
323
+ TempWriter(const TempWriter&) = delete;
324
+ TempWriter(TempWriter&&) = delete;
325
+ TempWriter& operator=(const TempWriter&) = delete;
326
+ TempWriter& operator=(TempWriter&&) = delete;
327
+
328
+ std::string asString() const {
329
+ std::ostringstream os;
330
+ OutputStream tmp(os);
331
+ tmp << *this;
332
+ return os.str();
333
+ }
334
+
335
+ explicit operator std::string() const {
336
+ return asString();
337
+ }
338
+
339
+ friend OutputStream& operator<<(OutputStream& os, const TempWriter<C>& writer) {
340
+ writer.callable(os);
341
+ return os;
342
+ }
343
+
344
+ friend OutputStream& operator<<(std::ostream& os, const TempWriter<C>& writer) = delete; //news OutputStream
345
+ };
346
+
347
+ struct JoinListCapture {
348
+ std::function<void(OutputStream&, char separator)> callable;
349
+
350
+ template<typename... Args>
351
+ JoinListCapture(Args&&... args)
352
+ : callable([t = std::forward_as_tuple(args...)](OutputStream& os, char separator) {
353
+ os.join(t, std::index_sequence_for<Args...>(), separator);
354
+ }) {}
355
+ };
356
+ }
357
+
358
+ template<typename T>
359
+ constexpr auto join(T first, T last, char separator = DEFAULT_SEPARATOR) {
360
+ return details::TempWriter([=](OutputStream& os) {
361
+ os.join(first, last, separator);
362
+ });
363
+ }
364
+
365
+ template<typename CR,
366
+ typename = std::enable_if_t<details::IsContainer<CR>{}>,
367
+ typename = std::enable_if_t<!details::IsStdArray<std::remove_cv_t<std::remove_reference_t<CR>>>{}>>
368
+ constexpr auto join(CR&& c, char separator = DEFAULT_SEPARATOR) {
369
+ if constexpr(std::is_rvalue_reference_v<CR&&>) {
370
+ if constexpr (std::is_array_v<CR>) {
371
+ return details::TempWriter([c, separator](OutputStream& os) {
372
+ os.join(std::begin(c), std::end(c), separator);
373
+ });
374
+ } else {
375
+ return details::TempWriter([c = std::move(c), separator](OutputStream& os) {
376
+ os.join(std::begin(c), std::end(c), separator);
377
+ });
378
+ }
379
+ } else {
380
+ return join(std::begin(c), std::end(c), separator);
381
+ }
382
+ }
383
+
384
+ template<typename CR, std::size_t N = std::tuple_size<std::decay_t<CR>>::value>
385
+ constexpr auto join(CR&& c, char separator = DEFAULT_SEPARATOR) {
386
+ if constexpr(std::is_rvalue_reference_v<CR&&>) {
387
+ return details::TempWriter([c = std::move(c), separator](OutputStream& os) {
388
+ os.join(c, std::make_index_sequence<N>{}, separator);
389
+ });
390
+ } else {
391
+ return details::TempWriter([&c, separator](OutputStream& os) {
392
+ os.join(c, std::make_index_sequence<N>{}, separator);
393
+ });
394
+ }
395
+ }
396
+
397
+ template<typename T, std::size_t N,
398
+ typename = std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, char>>>
399
+ constexpr auto join(T (&c)[N], char separator = DEFAULT_SEPARATOR) {
400
+ static_assert(N > 0, "c-strings should be null terminated!");
401
+ return join(std::begin(c), std::prev(std::end(c)), separator);
402
+ }
403
+
404
+ template<typename T, std::size_t N,
405
+ typename = std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, char>>>
406
+ constexpr auto join(T (&&c)[N], char separator = DEFAULT_SEPARATOR) {
407
+ static_assert(N > 0, "c-strings should be null terminated!");
408
+ return details::TempWriter([c, separator](OutputStream& os) {
409
+ os.join(std::begin(c), std::prev(std::end(c)), separator);
410
+ });
411
+ }
412
+
413
+ template<typename T,
414
+ typename = std::enable_if_t<!std::is_array<T>{}>,
415
+ typename = std::enable_if_t<!details::IsContainer<T>{}>,
416
+ typename = std::enable_if_t<!details::IsTupleLike<T>{}>>
417
+ constexpr auto join(const T& t, char separator = DEFAULT_SEPARATOR) = delete;
418
+
419
+ auto join(details::JoinListCapture c, char separator = DEFAULT_SEPARATOR) {
420
+ return details::TempWriter([c = std::move(c), separator](OutputStream& os) {
421
+ c.callable(os, separator);
422
+ });
423
+ }
424
+
425
+
426
+ //============================================================================//
427
+ // Basic datastructures //
428
+ //============================================================================//
429
+ // make usage of std::priority_queue easier...
430
+ namespace details {
431
+ template<typename T, typename Compare = std::less<T>>
432
+ struct invertCompare {
433
+ constexpr bool operator()(const T &lhs, const T &rhs) const {
434
+ return Compare{}(rhs, lhs);
435
+ }
436
+ };
437
+ }
438
+ template<typename T, typename Compare = std::less<T>>
439
+ using MinPQ = std::priority_queue<T, std::vector<T>, details::invertCompare<T, Compare>>;
440
+ template<typename T, typename Compare = std::less<T>>
441
+ using MaxPQ = std::priority_queue<T, std::vector<T>, Compare>;
442
+
443
+ template<typename C, typename K>
444
+ bool contains(const C& container, const K& key) {
445
+ return container.find(key) != container.end();
446
+ }
447
+
448
+ template<typename C1, typename C2>
449
+ void append(C1& c1, const C2& c2) {
450
+ static_assert(std::is_same_v<typename details::IsContainer<C1>::value_type,
451
+ typename details::IsContainer<C2>::value_type>, "cannot append container of different value type!");
452
+ if (static_cast<const void*>(&c1) != static_cast<const void*>(&c2)) {
453
+ for (auto&& e : c2) c1.emplace(c1.end(), e);
454
+ } else {
455
+ C2 tmp = c2;
456
+ for (auto&& e : tmp) c1.emplace(c1.end(), e);
457
+ }
458
+ }
459
+
460
+ template<typename C1, std::size_t N>
461
+ void append(C1& c1, const typename C1::value_type(&c2)[N]) {
462
+ for (auto&& e : c2) c1.emplace(c1.end(), e);
463
+ }
464
+
465
+ struct shorter {
466
+ template<typename U, typename V>
467
+ bool operator()(const U& a, const V& b) const {
468
+ return std::size(a) < std::size(b);
469
+ }
470
+ };
471
+
472
+ struct longer {
473
+ template<typename U, typename V>
474
+ bool operator()(const U& a, const V& b) const {
475
+ return std::size(b) < std::size(a);
476
+ }
477
+ };
478
+
479
+ namespace details {
480
+ template<typename T, typename = void>
481
+ struct Flatten {using value_type = T;};
482
+
483
+ template<typename T>
484
+ struct Flatten<T, std::enable_if_t<IsContainer<T>{}>> : Flatten<typename IsContainer<T>::value_type> {};
485
+
486
+ template<typename CR, typename V>
487
+ void flatAppend(CR&& c, std::vector<V>& res) {
488
+ using C = std::remove_reference_t<CR>;
489
+ if constexpr(std::is_same_v<C, V>) {
490
+ res.emplace_back(std::forward<CR>(c));
491
+ } else if constexpr (!IsContainer<C>{}) {
492
+ static_assert(IsContainer<C>{}, "invalid base type for flatten()!");
493
+ } else {
494
+ if constexpr (std::is_rvalue_reference_v<CR&&>) {
495
+ for (auto&& v : c) flatAppend(std::move(v), res);
496
+ } else {
497
+ for (auto&& v : c) flatAppend(v, res);
498
+ }
499
+ }
500
+ }
501
+ }
502
+
503
+ template<typename R, typename CR>
504
+ auto flatten(CR&& c) {
505
+ std::vector<R> res;
506
+ details::flatAppend(std::forward<CR>(c), res);
507
+ return res;
508
+ }
509
+
510
+ template<typename CR>
511
+ auto flatten(CR&& c) {
512
+ using C = std::remove_reference_t<CR>;
513
+ return flatten<typename details::Flatten<C>::value_type, CR>(std::forward<CR>(c));
514
+ }
515
+
516
+ template<typename T>
517
+ struct boolean {
518
+ bool value;
519
+ std::optional<T> reason;
520
+
521
+ constexpr boolean(bool value_) : value(value_) {}
522
+ constexpr boolean(bool value_, const T& reason_) : value(value_), reason(reason_) {}
523
+
524
+ constexpr operator bool() const {
525
+ return value;
526
+ }
527
+
528
+ constexpr bool hasReason() const {
529
+ return reason.has_value();
530
+ }
531
+ };
532
+
533
+
534
+ //============================================================================//
535
+ // Utility //
536
+ //============================================================================//
537
+ // for sequences
538
+ template<typename RandomIt,
539
+ typename = std::enable_if_t<std::is_integral_v<typename std::iterator_traits<RandomIt>::value_type>>>
540
+ auto isPerm(RandomIt first, RandomIt last, typename std::iterator_traits<RandomIt>::value_type offset = 0) {
541
+ using T = typename std::iterator_traits<RandomIt>::value_type;
542
+ auto count = std::distance(first, last);
543
+ std::vector<bool> seen(count, false);
544
+ for (; first != last; first++) {
545
+ const T& x = *first;
546
+ if (x < offset or x - offset >= count or seen[x - offset]) {
547
+ return boolean<T>(false, x);
548
+ }
549
+ seen[x - offset] = true;
550
+ }
551
+ return boolean<T>(true);
552
+ }
553
+ template<typename C, typename std::enable_if_t<std::is_integral_v<typename details::IsContainer<C>::value_type>, bool> = true>
554
+ auto isPerm(const C& c, typename details::IsContainer<C>::value_type offset = 0) {
555
+ return isPerm(std::begin(c), std::end(c), offset);
556
+ }
557
+
558
+ template<typename itA, typename itB>
559
+ auto isPerm(itA firstA, itA lastA, itB firstB, itB lastB) {
560
+ using T = typename std::iterator_traits<itA>::value_type;
561
+ std::vector<typename std::iterator_traits<itA>::value_type> a(firstA, lastA);
562
+ std::vector<typename std::iterator_traits<itB>::value_type> b(firstB, lastB);
563
+ if (a.size() != b.size()) return boolean<T>(false);
564
+ std::sort(a.begin(), a.end());
565
+ std::sort(b.begin(), b.end());
566
+ for (std::size_t i = 0; i < a.size(); i++) {
567
+ if (a[i] != b[i]) return boolean<T>(false, a[i]);
568
+ }
569
+ return boolean<T>(true);
570
+ }
571
+ template<typename C1,
572
+ typename C2,
573
+ typename = std::enable_if_t<details::IsContainer<C1>{}>,
574
+ typename = std::enable_if_t<details::IsContainer<C2>{}>>
575
+ auto isPerm(const C1& c1, const C2& c2) {
576
+ return isPerm(std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
577
+ }
578
+
579
+ template<typename RandomIt, typename BinaryPredicate>
580
+ constexpr boolean<Integer> anyAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) {
581
+ if (first != last) {
582
+ for (Integer i = 1; std::next(first) != last; first++, i++) {
583
+ if (p(*first, *std::next(first))) {
584
+ return boolean<Integer>(true, i);
585
+ }
586
+ }
587
+ }
588
+ return boolean<Integer>(false);
589
+ }
590
+ template<typename C, typename BinaryPredicate>
591
+ constexpr boolean<Integer> anyAdjacent(const C& c, BinaryPredicate p) {
592
+ return anyAdjacent(std::begin(c), std::end(c), p);
593
+ }
594
+
595
+ template<typename RandomIt, typename BinaryPredicate>
596
+ constexpr boolean<Integer> noneAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) {
597
+ auto res = anyAdjacent(first, last, p);
598
+ res.value = !res.value;
599
+ return res;
600
+ }
601
+ template<typename C, typename BinaryPredicate>
602
+ constexpr boolean<Integer> noneAdjacent(const C& c, BinaryPredicate p) {
603
+ return noneAdjacent(std::begin(c), std::end(c), p);
604
+ }
605
+
606
+ template<typename RandomIt, typename BinaryPredicate>
607
+ constexpr boolean<Integer> allAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) {
608
+ return noneAdjacent(first, last, std::not_fn(p));
609
+ }
610
+ template<typename C, typename BinaryPredicate>
611
+ constexpr boolean<Integer> allAdjacent(const C& c, BinaryPredicate p) {
612
+ return noneAdjacent(std::begin(c), std::end(c), p);
613
+ }
614
+
615
+ template<typename RandomIt>
616
+ constexpr boolean<Integer> areIncreasing(RandomIt first, RandomIt last) {
617
+ using T = typename std::iterator_traits<RandomIt>::value_type;
618
+ return allAdjacent(first, last, std::less<T>());
619
+ }
620
+ template<typename C>
621
+ constexpr boolean<Integer> areIncreasing(const C& c) {
622
+ return areIncreasing(std::begin(c), std::end(c));
623
+ }
624
+
625
+ template<typename RandomIt>
626
+ constexpr boolean<Integer> areNonDecreasing(RandomIt first, RandomIt last) {
627
+ using T = typename std::iterator_traits<RandomIt>::value_type;
628
+ return allAdjacent(first, last, std::less_equal<T>());
629
+ }
630
+ template<typename C>
631
+ constexpr boolean<Integer> areNonDecreasing(const C& c) {
632
+ return areNonDecreasing(std::begin(c), std::end(c));
633
+ }
634
+
635
+ template<typename RandomIt>
636
+ constexpr boolean<Integer> areDecreasing(RandomIt first, RandomIt last) {
637
+ using T = typename std::iterator_traits<RandomIt>::value_type;
638
+ return allAdjacent(first, last, std::greater<T>());
639
+ }
640
+ template<typename C>
641
+ constexpr boolean<Integer> areDecreasing(const C& c) {
642
+ return areDecreasing(std::begin(c), std::end(c));
643
+ }
644
+
645
+ template<typename RandomIt>
646
+ constexpr boolean<Integer> areNonIncreasing(RandomIt first, RandomIt last) {
647
+ using T = typename std::iterator_traits<RandomIt>::value_type;
648
+ return allAdjacent(first, last, std::greater_equal<T>());
649
+ }
650
+ template<typename C>
651
+ constexpr boolean<Integer> areNonIncreasing(const C& c) {
652
+ return areNonIncreasing(std::begin(c), std::end(c));
653
+ }
654
+
655
+ template<typename RandomIt>
656
+ constexpr auto areDistinct(RandomIt first, RandomIt last) {
657
+ using T = typename std::iterator_traits<RandomIt>::value_type;
658
+ std::vector<T> tmp(first, last);
659
+ std::sort(tmp.begin(), tmp.end());
660
+ auto [b, v] = anyAdjacent(tmp, std::equal_to<T>());
661
+ if (v) return boolean<T>(!b, tmp[*v]);
662
+ return boolean<T>(!b);
663
+ }
664
+ template<typename C>
665
+ constexpr auto areDistinct(const C& c) {
666
+ return areDistinct(std::begin(c), std::end(c));
667
+ }
668
+
669
+
670
+ // for strings (cctype functions are not safe to use with char...)
671
+ constexpr bool isLower(char c) {
672
+ return c >= 'a' and c <= 'z';
673
+ }
674
+
675
+ constexpr bool isUpper(char c) {
676
+ return c >= 'A' and c <= 'Z';
677
+ }
678
+
679
+ constexpr bool isLetter(char c) {
680
+ return isLower(c) or isUpper(c);
681
+ }
682
+
683
+ constexpr bool isDigit(char c) {
684
+ return c >= '0' and c <= '9';
685
+ }
686
+
687
+ constexpr char toLower(char c) {
688
+ if (isUpper(c)) c += 'a' - 'A';
689
+ return c;
690
+ }
691
+
692
+ constexpr bool isVowel(char c) {
693
+ c = toLower(c);
694
+ for (char x : LOWER_VOWELS) {
695
+ if (c == x) return true;
696
+ }
697
+ return false;
698
+ }
699
+
700
+ constexpr bool isConsonant(char c) {
701
+ return isLetter(c) and !isVowel(c);
702
+ }
703
+
704
+ constexpr char toUpper(char c) {
705
+ if (isLower(c)) c -= 'a' - 'A';
706
+ return c;
707
+ }
708
+
709
+ constexpr char toDefaultCase(char c) {
710
+ if constexpr (DEFAULT_CASE_LOWER) return toLower(c);
711
+ return toUpper(c);
712
+ }
713
+
714
+ void toLower(std::string& s) {
715
+ for (char& c : s) c = toLower(c);
716
+ }
717
+
718
+ void toUpper(std::string& s) {
719
+ for (char& c : s) c = toUpper(c);
720
+ }
721
+
722
+ void toDefaultCase(std::string& s) {
723
+ if constexpr (DEFAULT_CASE_LOWER) return toLower(s);
724
+ return toUpper(s);
725
+ }
726
+
727
+ constexpr bool isLower(std::string_view s) {
728
+ for (char c : s) if (!isLower(c)) return false;
729
+ return true;
730
+ }
731
+
732
+ constexpr boolean<char> isUpper(std::string_view s) {
733
+ for (char c : s) if (!isUpper(c)) return boolean<char>(false, c);
734
+ return boolean<char>(true);
735
+ }
736
+
737
+ constexpr boolean<char> isLetter(std::string_view s) {
738
+ for (char c : s) if (!isLetter(c)) return boolean<char>(false, c);
739
+ return boolean<char>(true);
740
+ }
741
+
742
+ constexpr boolean<char> isDigit(std::string_view s) {
743
+ for (char c : s) if (!isDigit(c)) return boolean<char>(false, c);
744
+ return boolean<char>(true);
745
+ }
746
+
747
+ constexpr boolean<char> isVowel(std::string_view s) {
748
+ for (char c : s) if (!isVowel(c)) return boolean<char>(false, c);
749
+ return boolean<char>(true);
750
+ }
751
+
752
+ constexpr boolean<char> isConsonant(std::string_view s) {
753
+ for (char c : s) if (!isConsonant(c)) return boolean<char>(false, c);
754
+ return boolean<char>(true);
755
+ }
756
+
757
+ std::vector<Integer> thueMorse(Integer lower, Integer upper) {
758
+ judgeAssert<std::invalid_argument>(lower < upper, "thueMorse(): Lower must be less than upper!");
759
+ std::vector<Integer> res(upper - lower);
760
+ for (Integer i = lower; i < upper; i++) {
761
+ res[i] = std::bitset<64>(i).count() % 2;
762
+ }
763
+ return res;
764
+ }
765
+
766
+ std::vector<Integer> thueMorse(Integer upper) {
767
+ return thueMorse(0, upper);
768
+ }
769
+
770
+ // allow using std::pair and std::complex similiar
771
+ // (may be useful for geometric problem)
772
+ template<typename T>
773
+ constexpr auto& getX(T& point) {
774
+ return std::get<0>(point);
775
+ }
776
+ template<typename T>
777
+ constexpr auto& getY(T& point) {
778
+ return std::get<1>(point);
779
+ }
780
+ template<typename T>
781
+ constexpr auto& getZ(T& point) {
782
+ return std::get<2>(point);
783
+ }
784
+ template<typename T>
785
+ constexpr auto getX(const T& point) {
786
+ return std::get<0>(point);
787
+ }
788
+ template<typename T>
789
+ constexpr auto getY(const T& point) {
790
+ return std::get<1>(point);
791
+ }
792
+ template<typename T>
793
+ constexpr auto getZ(const T& point) {
794
+ return std::get<2>(point);
795
+ }
796
+
797
+ template<typename T>
798
+ constexpr auto& getX(std::complex<T>& point) {
799
+ return reinterpret_cast<T(&)[2]>(point)[0];
800
+ }
801
+ template<typename T>
802
+ constexpr auto& getY(std::complex<T>& point) {
803
+ return reinterpret_cast<T(&)[2]>(point)[1];
804
+ }
805
+ template<typename T>
806
+ constexpr auto getX(const std::complex<T>& point) {
807
+ return reinterpret_cast<const T(&)[2]>(point)[0];
808
+ }
809
+ template<typename T>
810
+ constexpr auto getY(const std::complex<T>& point) {
811
+ return reinterpret_cast<const T(&)[2]>(point)[1];
812
+ }
813
+
814
+ template<typename T>
815
+ constexpr std::pair<T,T> convert(const std::complex<T>& t) {
816
+ return {getX(t), getY(t)};
817
+ }
818
+
819
+ template<typename L, typename R>
820
+ constexpr std::complex<typename std::common_type<L, R>::type>
821
+ convert(const std::pair<L,R>& t) {
822
+ return {getX(t), getY(t)};
823
+ }
824
+
825
+
826
+ namespace details {
827
+ // Test two numbers for equality, accounting for +/-INF, NaN and precision.
828
+ // Real expected is considered the reference value for relative error.
829
+ bool floatEqual(Real given, Real expected, Real floatAbsTol, Real floatRelTol) {
830
+ judgeAssert<std::domain_error>(floatAbsTol >= 0.0_real, "floatEqual(): floatAbsTol must be positive!");
831
+ judgeAssert<std::domain_error>(floatRelTol >= 0.0_real, "floatEqual(): floatRelTol must be positive!");
832
+ // Finite values are compared with some tolerance
833
+ if (std::isfinite(given) and std::isfinite(expected)) {
834
+ Real absDiff = std::abs(given-expected);
835
+ Real relDiff = std::abs((given-expected)/expected);
836
+ return absDiff <= floatAbsTol or relDiff <= floatRelTol;
837
+ }
838
+ // NaN is equal to NaN (-NaN is also equal NaN)
839
+ if (std::isnan(given) and std::isnan(expected)) {
840
+ return true;
841
+ }
842
+ // Infinite values are equal if their sign matches
843
+ if (std::isinf(given) and std::isinf(expected)) {
844
+ return std::signbit(given) == std::signbit(expected);
845
+ }
846
+ // Values in different classes are always different.
847
+ return false;
848
+ }
849
+
850
+ constexpr boolean<std::size_t> stringEqual(std::string_view a, std::string_view b, bool caseSensitive) {
851
+ std::size_t i = 0;
852
+ for (; i < a.size() and i < b.size(); i++) {
853
+ char aa = a[i];
854
+ char bb = b[i];
855
+ if (!caseSensitive) {
856
+ aa = toDefaultCase(aa);
857
+ bb = toDefaultCase(bb);
858
+ }
859
+ if (aa != bb) {
860
+ return boolean<std::size_t>(false, i);
861
+ }
862
+ }
863
+ if (a.size() != b.size()) {
864
+ return boolean<std::size_t>(false, i);
865
+ } else {
866
+ return boolean<std::size_t>(true);
867
+ }
868
+ }
869
+
870
+ constexpr bool isToken(std::string_view a) {
871
+ for (char c : a) {
872
+ if (c == ' ') return false;
873
+ if (c == '\n') return false;
874
+ if (c == '\r') return false;
875
+ if (c == '\t') return false;
876
+ if (c == '\f') return false;
877
+ if (c == '\v') return false;
878
+ }
879
+ return true;
880
+ }
881
+
882
+ template<typename T>
883
+ bool parse(std::string_view s, T& res) {
884
+ const char* begin = s.data();
885
+ const char* end = s.data() + s.size();
886
+ auto [ptr, ec] = std::from_chars(begin, end, res);
887
+ return ptr == end and ec == std::errc();
888
+ }
889
+ #ifdef DOUBLE_FALLBACK
890
+ template<>
891
+ bool parse(std::string_view s, Real& res) {
892
+ try {
893
+ std::size_t pos = 0;
894
+ res = std::stold(std::string(s), &pos);
895
+ return pos == s.size();
896
+ } catch(...) {
897
+ return false;
898
+ }
899
+ }
900
+ #endif
901
+
902
+ }
903
+
904
+
905
+ //============================================================================//
906
+ // Math //
907
+ //============================================================================//
908
+ namespace details {
909
+ constexpr std::array<Integer, 32> TRIAL_PRIMES = {
910
+ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
911
+ 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131,
912
+ };
913
+ constexpr std::array<UInteger, 7> MILLER_RABIN_WITNESS = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
914
+
915
+ // these operations are safe as long as the value would fit in Integer
916
+ constexpr UInteger mulMod(UInteger lhs, UInteger rhs, UInteger mod) {
917
+ UInteger res = 0;
918
+ while (rhs > 0) {
919
+ if (rhs & 1) res = (lhs + res) % mod;
920
+ lhs = (lhs + lhs) % mod;
921
+ rhs /= 2;
922
+ }
923
+ return res;
924
+ }
925
+
926
+ constexpr UInteger powMod(UInteger base, UInteger exp, UInteger mod) {
927
+ UInteger res = 1;
928
+ if (mod <= 0x1'0000'0000) {
929
+ while (exp > 0) {
930
+ if (exp & 1) res = (base * res) % mod;
931
+ base = (base * base) % mod;
932
+ exp /= 2;
933
+ }
934
+ } else {
935
+ while (exp > 0) {
936
+ if (exp & 1) res = mulMod(base, res, mod);
937
+ base = mulMod(base, base, mod);
938
+ exp /= 2;
939
+ }
940
+ }
941
+ return res;
942
+ }
943
+
944
+ constexpr Integer extendedEuclid(Integer a, Integer b, Integer& x, Integer& y) {
945
+ if (a == 0) {
946
+ x = 0;
947
+ y = 1;
948
+ return b;
949
+ } else {
950
+ Integer x1 = 0;
951
+ Integer y1 = 0;
952
+ Integer d = extendedEuclid(b % a, a, x1, y1);
953
+ x = y1 - (b / a) * x1;
954
+ y = x1;
955
+ return d;
956
+ }
957
+ }
958
+ }
959
+
960
+ constexpr Integer applyMod(Integer x, Integer mod) {
961
+ x %= mod;
962
+ if (x < 0) x += mod;
963
+ return x;
964
+ }
965
+
966
+ constexpr Integer mulMod(Integer lhs, Integer rhs, Integer mod) {
967
+ judgeAssert<std::domain_error>(mod > 0, "mulMod(): mod must be positive!");
968
+ UInteger ul = static_cast<UInteger>(applyMod(lhs, mod));
969
+ UInteger ur = static_cast<UInteger>(applyMod(rhs, mod));
970
+ UInteger um = static_cast<UInteger>(mod);
971
+ return static_cast<Integer>(details::mulMod(ul, ur, um));
972
+ }
973
+
974
+ constexpr Integer powMod(Integer base, Integer exp, Integer mod) {
975
+ judgeAssert<std::domain_error>(mod > 0, "powMod(): mod must be positive!");
976
+ judgeAssert<std::domain_error>(exp >= 0, "powMod(): exp must be non negative!");
977
+ UInteger ub = static_cast<UInteger>(applyMod(base, mod));
978
+ UInteger ue = static_cast<UInteger>(exp);
979
+ UInteger um = static_cast<UInteger>(mod);
980
+ return static_cast<Integer>(details::powMod(ub, ue, um));
981
+ }
982
+
983
+ constexpr Integer multInv(Integer n, Integer mod) {
984
+ judgeAssert<std::domain_error>(mod > 0, "multInv(): mod must be positive!");
985
+ Integer x = 0;
986
+ Integer y = 0;
987
+ Integer g = details::extendedEuclid(n, mod, x, y);
988
+ if (g != 1) return -1;
989
+ else return applyMod(x, mod);
990
+ }
991
+
992
+ constexpr bool isPrime(Integer n) {
993
+ for (Integer p : details::TRIAL_PRIMES) {
994
+ if (n <= p or n % p == 0) {
995
+ return n == p;
996
+ }
997
+ }
998
+ if (details::powMod(details::TRIAL_PRIMES.back() + 1, n - 1, n) != 1) {
999
+ return false;
1000
+ }
1001
+ UInteger un = static_cast<UInteger>(n);
1002
+ UInteger d = un - 1;
1003
+ UInteger j = 0;
1004
+ while (d % 2 == 0) {
1005
+ d /= 2;
1006
+ j++;
1007
+ }
1008
+ for (UInteger a : details::MILLER_RABIN_WITNESS) {
1009
+ if (a % un == 0) continue;
1010
+ UInteger v = details::powMod(a, d, un);
1011
+ if (v == 1 or v == un - 1) continue;
1012
+ for (UInteger i = 1; i < j; i++) {
1013
+ v = details::mulMod(v, v, un);
1014
+ if (v == un - 1 or v <= 1) break;
1015
+ }
1016
+ if (v != un - 1) return false;
1017
+ }
1018
+ return true;
1019
+ }
1020
+
1021
+ std::vector<Integer> primes(Integer lower, Integer upper) {
1022
+ judgeAssert<std::invalid_argument>(lower < upper, "primes(): Lower must be less than upper!");
1023
+ lower = std::max<Integer>(2, lower);
1024
+ upper = std::max<Integer>(2, upper);
1025
+ Integer count = upper - lower;
1026
+ Integer cache = (count + 1) / 2;
1027
+
1028
+ std::vector<bool> notPrime(cache), notPrimeSegment(cache);
1029
+ for (Integer i = 3; i < count; i += 2) {
1030
+ if (!notPrime[i / 2]) {
1031
+ for (Integer j = i * i; j < count; j += 2 * i) {
1032
+ notPrime[j / 2] = true;
1033
+ }
1034
+ Integer lowest = lower - (lower % (2*i)) + i;
1035
+ if (lowest < lower) lowest += 2*i;
1036
+ for (Integer j = std::max(i * i, lowest); j < upper; j += 2 * i) {
1037
+ notPrimeSegment[(j - lower) / 2] = true;
1038
+ }
1039
+ }
1040
+ }
1041
+ std::vector<Integer> res;
1042
+ if (lower <= 2 and 2 < upper) res.emplace_back(2);
1043
+ for (Integer i = lower | 1; i < upper; i += 2) {
1044
+ if (!notPrimeSegment[(i - lower) / 2] and (i < count*count or isPrime(i))) {
1045
+ res.emplace_back(i);
1046
+ }
1047
+ }
1048
+ return res;
1049
+ }
1050
+
1051
+ std::vector<Integer> primes(Integer upper) {
1052
+ return primes(0, upper);
1053
+ }
1054
+
1055
+ template<typename T>
1056
+ constexpr Integer sign(T x) {
1057
+ return (T(0) < x) - (x < T(0));
1058
+ }
1059
+
1060
+
1061
+ //============================================================================//
1062
+ // Geometry (this is just for utility stuff...) //
1063
+ //============================================================================//
1064
+ namespace details {
1065
+ template<typename Point>
1066
+ constexpr Integer cross(Point a, Point b) {
1067
+ return getX(a) * getY(b) - getY(a) * getX(b);
1068
+ }
1069
+ template<typename Point>
1070
+ constexpr Integer cross(Point p, Point a, Point b) {
1071
+ getX(a) -= getX(p);
1072
+ getY(a) -= getY(p);
1073
+ getX(b) -= getX(p);
1074
+ getY(b) -= getY(p);
1075
+ return cross(a, b);
1076
+ }
1077
+
1078
+ template<typename Point>
1079
+ constexpr bool left(Point p) {
1080
+ return getX(p) == 0 ? getY(p) < 0 : getX(p) < 0;
1081
+ }
1082
+
1083
+ template<typename Point>
1084
+ void cyclicSort(std::vector<Point>& in) {
1085
+ std::sort(in.begin(), in.end(), [](const Point& a, const Point& b){
1086
+ return left(a) != left(b) ? left(a) > left(b) : cross(a, b) > 0;
1087
+ });
1088
+ }
1089
+ }
1090
+
1091
+
1092
+ template<typename RandomIt>
1093
+ constexpr bool areConvex(RandomIt first, RandomIt last) {
1094
+ std::size_t n = 0;
1095
+ for (auto it = first; it != last; it++) {
1096
+ n++;
1097
+ judgeAssert(std::abs(getX(*it)) <= 0x3FFF'FFFF, "areConvex(): coordinates too large!");
1098
+ judgeAssert(std::abs(getY(*it)) <= 0x3FFF'FFFF, "areConvex(): coordinates too large!");
1099
+ }
1100
+ if (n < 3) return false;
1101
+ bool hasArea = false;
1102
+ for (std::size_t i = 0; i < n; i++) {
1103
+ if (first[i] == first[(i+1) % n]) return false;
1104
+ if (details::cross(first[0], first[i], first[(i+1) % n]) < 0) return false;
1105
+ if (details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) < 0) return false;
1106
+ hasArea |= details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) != 0;
1107
+ }
1108
+ return hasArea;
1109
+ }
1110
+ template<typename C>
1111
+ constexpr bool areConvex(const C& c) {
1112
+ return areConvex(std::begin(c), std::end(c));
1113
+ }
1114
+
1115
+ template<typename RandomIt>
1116
+ constexpr bool areStrictlyConvex(RandomIt first, RandomIt last) {
1117
+ if (!areConvex(first, last)) return false;
1118
+ std::size_t n = std::distance(first, last);
1119
+ for (std::size_t i = 0; i < n; i++) {
1120
+ if (details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) == 0) return false;
1121
+ }
1122
+ return true;
1123
+ }
1124
+ template<typename C>
1125
+ constexpr bool areStrictlyConvex(const C& c) {
1126
+ return areStrictlyConvex(std::begin(c), std::end(c));
1127
+ }
1128
+
1129
+ //============================================================================//
1130
+ // Random //
1131
+ //============================================================================//
1132
+ namespace Random {
1133
+ // You should not rely on the implementation in details!
1134
+ // Especially you should never use randomNumberGenerator on your own. There is no function in
1135
+ // c++ which uses a random engine and is not implementation defined.
1136
+ namespace details {
1137
+ constexpr Real PI = 3.141592653589793238462643383279502884_real;
1138
+ constexpr Integer PRIME_TRIALS = 4*1600;
1139
+
1140
+ RandomEngine randomNumberGenerator(DEFAULT_SEED);
1141
+ static_assert(RandomEngine::max() == 0xFFFF'FFFF'FFFF'FFFF_uint, "Random Engine should produce 64bit of randomness");
1142
+ static_assert(RandomEngine::min() == 0_uint, "Random Engine should produce 64bit of randomness");
1143
+
1144
+ constexpr UInteger bitMask(UInteger x) {
1145
+ static_assert(sizeof(UInteger) == 8, "bitMask requires 8byte UInteger!");
1146
+ x |= x >> 1;
1147
+ x |= x >> 2;
1148
+ x |= x >> 4;
1149
+ x |= x >> 8;
1150
+ x |= x >> 16;
1151
+ x |= x >> 32;
1152
+ return x;
1153
+ }
1154
+ }
1155
+
1156
+ void seed(UInteger seed) {
1157
+ details::randomNumberGenerator.seed(seed);
1158
+ }
1159
+
1160
+ //========================================================================//
1161
+ // Distributions and generators //
1162
+ //========================================================================//
1163
+ bool bit() {// in {0, 1}
1164
+ return std::bitset<64>(details::randomNumberGenerator()).count() & 1;
1165
+ }
1166
+
1167
+ Integer integer() {// in [-2^63, 2^63)
1168
+ return static_cast<Integer>(details::randomNumberGenerator());
1169
+ }
1170
+ Integer integer(Integer lower, Integer upper) {// in [lower, upper)
1171
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::integer(): Lower must be less than upper!");
1172
+ UInteger ul = static_cast<UInteger>(lower);
1173
+ UInteger uu = static_cast<UInteger>(upper);
1174
+ UInteger mask = details::bitMask(uu - ul - 1_uint);
1175
+ UInteger res;
1176
+ do {
1177
+ res = details::randomNumberGenerator() & mask;
1178
+ } while (res >= uu - ul);
1179
+ return static_cast<Integer>(res + ul);
1180
+ }
1181
+ Integer integer(Integer upper) {// in [0, upper)
1182
+ return integer(0, upper);
1183
+ }
1184
+
1185
+ Real real() {// in [0, 1)
1186
+ while (true) {
1187
+ Real res = details::randomNumberGenerator() / 0x1.0p64_real;
1188
+ res += details::randomNumberGenerator() / 0x1.0p128_real;
1189
+ if (0.0_real <= res and res < 1.0_real) return res;
1190
+ }
1191
+ }
1192
+ Real real(Real upper) {// in [0, upper)
1193
+ judgeAssert<std::domain_error>(std::isfinite(upper), "Random::real(): Upper must be finite!");
1194
+ judgeAssert<std::invalid_argument>(upper > 0.0_real, "Random::real(): Upper must be greater than zero!");
1195
+ while (true) {
1196
+ Real res = real() * upper;
1197
+ if (0.0_real <= res and res < upper) return res;
1198
+ }
1199
+ }
1200
+ Real real(Real lower, Real upper) {// in [lower, upper)
1201
+ judgeAssert<std::domain_error>(std::isfinite(lower), "Random::real(): Lower must be finite!");
1202
+ judgeAssert<std::domain_error>(std::isfinite(upper), "Random::real(): Upper must be finite!");
1203
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::real(): Lower must be less than upper!");
1204
+ while (true) {
1205
+ Real x = real();
1206
+ Real res = lower * (1.0_real - x) + upper * x;
1207
+ if (lower <= res and res < upper) return res;
1208
+ }
1209
+ }
1210
+
1211
+ Real normal(Real mean, Real stddev) {// theoretically in (-inf, inf)
1212
+ judgeAssert<std::domain_error>(stddev >= 0.0_real, "Random::normal(): Standard deviation must be non negative!");
1213
+ Real u1 = real();
1214
+ Real u2 = real();
1215
+ Real res = std::sqrt(-2.0_real * std::log(u1)) * std::cos(2.0_real * details::PI * u2);
1216
+ return std::sqrt(stddev) * res + mean;
1217
+ }
1218
+ Real normal(Real lower, Real upper, Real mean, Real stddev) {// in [lower, upper)
1219
+ judgeAssert<std::domain_error>(!std::isnan(lower), "Random::normal(): Lower must not be NaN!");
1220
+ judgeAssert<std::domain_error>(!std::isnan(upper), "Random::normal(): Upper must not be NaN!");
1221
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::normal(): Lower must be less than upper!");
1222
+ judgeAssert<std::domain_error>(stddev >= 0.0_real, "Random::normal(): Standard deviation must be non negative!");
1223
+ Real res;
1224
+ while (true) {
1225
+ Real u1 = real();
1226
+ Real u2 = real();
1227
+ // Box-Muller-Methode
1228
+ // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
1229
+ res = std::sqrt(-2.0_real * std::log(u1)) * std::cos(2.0_real * details::PI * u2);
1230
+ res = std::sqrt(stddev) * res + mean;
1231
+ if (lower <= res and res < upper) return res;
1232
+ res = std::sqrt(-2.0_real * std::log(u1)) * std::sin(2.0_real * details::PI * u2);
1233
+ res = std::sqrt(stddev) * res + mean;
1234
+ if (lower <= res and res < upper) return res;
1235
+ }
1236
+ }
1237
+
1238
+ Real exponential(Real lambda) {// theoretically in [0, inf)
1239
+ judgeAssert<std::domain_error>(lambda > 0.0_real, "Random::lambda(): lambda must be positive!");
1240
+ return -std::log(real()) / lambda;
1241
+ }
1242
+ Real exponential(Real lower, Real upper, Real lambda) {// in [lower, upper)
1243
+ judgeAssert<std::domain_error>(std::isfinite(lower), "Random::exponential(): Lower must be finite!");
1244
+ judgeAssert<std::domain_error>(!std::isnan(upper), "Random::exponential(): Upper must not be NaN!");
1245
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::exponential(): Lower must be less than upper!");
1246
+ judgeAssert<std::domain_error>(lambda > 0.0_real, "Random::exponential(): Lambda must be positive!");
1247
+ while (true) {
1248
+ Real res = lower - std::log(real()) / lambda;
1249
+ if (res < upper) return res;
1250
+ }
1251
+ }
1252
+
1253
+ Integer geometric(Real p) {// theoretically in [0, inf)
1254
+ judgeAssert<std::domain_error>(0.0_real <= p and p < 1.0_real, "Random::geometric(): p must be in [0,1)!");
1255
+ return std::llround(std::floor(std::log(real()) / std::log1p(-p)));
1256
+ }
1257
+ Integer geometric(Integer lower, Integer upper, Real p) {// in [lower, upper)
1258
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::geometric(): Lower must be less than upper!");
1259
+ judgeAssert<std::domain_error>(0.0_real <= p and p < 1.0_real, "Random::geometric(): p must be in [0,1)!");
1260
+ while (true) {
1261
+ // https://en.wikipedia.org/wiki/Geometric_distribution
1262
+ // "The exponential distribution is the continuous analogue of the geometric distribution[...]"
1263
+ Integer res = lower + std::llround(std::floor(std::log(real()) / std::log1p(-p)));
1264
+ if (res < upper) return res;
1265
+ }
1266
+ }
1267
+
1268
+ Integer binomial(Integer n, Real p) {// in [0, n]
1269
+ judgeAssert<std::domain_error>(n >= 0, "Random::binomial(): n must be non negative!");
1270
+ judgeAssert<std::domain_error>(0.0_real <= p and p <= 1.0_real, "Random::binomial(): p must be in [0,1)!");
1271
+ bool swap = p > 0.5_real;
1272
+ p = std::min(p, 1.0_real - p);
1273
+ if (p*n < 10.0_real) {
1274
+ // BG: Geometric method
1275
+ // https://dl.acm.org/doi/pdf/10.1145/42372.42381
1276
+ Integer res = 0;
1277
+ Integer y = 0;
1278
+ Real lg = std::log1p(-p);
1279
+ if (lg >= 0) return swap ? n : 0;
1280
+ do {
1281
+ y += std::llround(std::floor(std::log(real()) / lg)) + 1;
1282
+ if (y > n) return swap ? n - res : res;
1283
+ res++;
1284
+ } while (true);
1285
+ } else {
1286
+ // BTRS algorithm
1287
+ // https://epub.wu.ac.at/1242/1/document.pdf
1288
+ // note that the original paper has an error
1289
+ // the break condition at the end has to be log(v) < h[...]
1290
+ Real q = 1.0_real - p;
1291
+ Real spq = std::sqrt(n * p * q);
1292
+ Real b = 1.15_real + 2.53_real * spq;
1293
+ Real a = -0.0873_real + 0.0248_real * b + 0.01_real * p;
1294
+ Real c = n * p + 0.5_real;
1295
+ Real vr = 0.92_real - 4.2_real / b;
1296
+
1297
+ bool initialized = false;
1298
+ Real alpha, lpq, m, h;
1299
+ do {
1300
+ Real u = real() - 0.5_real;
1301
+ Real us = 0.5_real - std::abs(u);
1302
+ Integer res = std::llround(std::floor((2.0_real * a / us + b) * u + c));
1303
+ if (res < 0 or res > n) continue;
1304
+
1305
+ Real v = real();
1306
+ if (us >= 0.07_real and v <= vr) {
1307
+ return swap ? n - res : res;
1308
+ }
1309
+
1310
+ if (!initialized) {
1311
+ alpha = (2.83_real + 5.1_real / b) * spq;
1312
+ lpq = std::log(p / q);
1313
+ m = std::llround(std::floor((n + 1) * p));
1314
+ h = std::lgamma(m + 1) + std::lgamma(n - m + 1);
1315
+ initialized = true;
1316
+ }
1317
+ v *= alpha / (a / (us * us) + b);
1318
+ if (std::log(v) <= h - std::lgamma(res + 1) - std::lgamma(n - res + 1) + (res - m) * lpq) {
1319
+ return swap ? n - res : res;
1320
+ }
1321
+ } while (true);
1322
+ }
1323
+ }
1324
+ Integer binomial(Integer lower, Integer upper, Integer n, Real p) {// in [lower, upper)
1325
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::binomial(): n Lower must be less than upper!");
1326
+ while (true) {
1327
+ Integer res = binomial(n, p);
1328
+ if (lower <= res and res < upper) return res;
1329
+ }
1330
+ }
1331
+
1332
+ Integer maximum(Integer lower, Integer upper, Integer n) {// in [lower, upper)
1333
+ judgeAssert<std::invalid_argument>(n > 0, "Random::maximum(): n musst be positive!");
1334
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::maximum(): Lower must be less than upper!");
1335
+ if (n < 5) {
1336
+ Integer res = lower;
1337
+ for (Integer i = 0; i < n; i++) res = std::max(res, integer(lower, upper));
1338
+ return res;
1339
+ } else {// such large n seem unlikely
1340
+ UInteger ul = static_cast<UInteger>(lower);
1341
+ UInteger uu = static_cast<UInteger>(upper);
1342
+ UInteger res = (uu - ul) * std::exp2(std::log2(real()) / n);
1343
+ return std::min(upper - 1, static_cast<Integer>(res + ul));
1344
+ }
1345
+ }
1346
+ Integer maximum(Integer upper, Integer n) {
1347
+ return maximum(0, upper, n);
1348
+ }
1349
+
1350
+ Integer minimum(Integer lower, Integer upper, Integer n) {// in [lower, upper)
1351
+ return upper - 1 - maximum(0, upper - lower, n);
1352
+ }
1353
+ Integer minimum(Integer upper, Integer n) {
1354
+ return minimum(0, upper, n);
1355
+ }
1356
+
1357
+ Integer prime(Integer lower, Integer upper) {// in [lower, upper)
1358
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::prime(): Lower must be less than upper!");
1359
+ Integer sampleL = lower <= 2 ? 0 : (lower / 2);
1360
+ Integer sampleU = upper / 2;
1361
+ if (sampleL < sampleU) {
1362
+ for (Integer i = 0; i < details::PRIME_TRIALS and i < 4 * (upper - lower); i++) {
1363
+ Integer res = std::max<Integer>(2, 2*integer(sampleL, sampleU) | 1);
1364
+ if (isPrime(res)) return res;
1365
+ }
1366
+ }
1367
+ judgeAssert<std::domain_error>(false, "Random::prime(): range contains no primes?");
1368
+ return -1;
1369
+ }
1370
+ Integer prime(Integer upper) {// in [0, upper)
1371
+ return prime(0, upper);
1372
+ }
1373
+
1374
+
1375
+ //========================================================================//
1376
+ // utility //
1377
+ //========================================================================//
1378
+ template<typename RandomIt>
1379
+ typename std::iterator_traits<RandomIt>::reference
1380
+ select(RandomIt first, RandomIt last) {
1381
+ judgeAssert<std::invalid_argument>(first < last, "Random::select(): Lower must be less than upper!");
1382
+ return first[integer(0, last - first)];
1383
+ }
1384
+
1385
+ template<typename C>
1386
+ typename ::details::IsContainer<C>::value_type select(const C& c) {
1387
+ return select(std::begin(c), std::end(c));
1388
+ }
1389
+
1390
+ template<typename C>
1391
+ typename C::reference select(C& c) {
1392
+ return select(std::begin(c), std::end(c));
1393
+ }
1394
+
1395
+ template<typename T, std::size_t N>
1396
+ T select(const T(&c)[N]) {
1397
+ return select(std::begin(c), std::end(c));
1398
+ }
1399
+
1400
+ template<typename T, std::size_t N>
1401
+ T& select(T(&c)[N]) {
1402
+ return select(std::begin(c), std::end(c));
1403
+ }
1404
+
1405
+ template<typename T>
1406
+ T select(const std::pair<T, T>& t) {
1407
+ return bit() ? getX(t) : getY(t);
1408
+ }
1409
+
1410
+ template<typename T>
1411
+ T select(const std::complex<T>& t) {
1412
+ return bit() ? getX(t) : getY(t);
1413
+ }
1414
+
1415
+ template<typename RandomIt>
1416
+ void shuffle(RandomIt first, RandomIt last) {
1417
+ using std::swap;
1418
+ auto n = last - first;
1419
+ for (auto i = n-1; i > 0; i--) {
1420
+ swap(first[i], first[integer(0, i+1)]);
1421
+ }
1422
+ }
1423
+
1424
+ template<typename C>
1425
+ void shuffle(C& c) {
1426
+ return shuffle(std::begin(c), std::end(c));
1427
+ }
1428
+
1429
+ template<typename T>
1430
+ void shuffle(std::pair<T, T>& t) {
1431
+ using std::swap;
1432
+ if (bit()) swap(getX(t), getY(t));
1433
+ }
1434
+
1435
+ template<typename T>
1436
+ void shuffle(std::complex<T>& t) {
1437
+ using std::swap;
1438
+ if (bit()) swap(getX(t), getY(t));
1439
+ }
1440
+
1441
+ template<typename RandomIt>
1442
+ Integer rotate(RandomIt first, RandomIt last) {
1443
+ Integer rotation = integer(0, last - first);
1444
+ std::rotate(first, first + rotation, last);
1445
+ return rotation;
1446
+ }
1447
+
1448
+ template<typename C>
1449
+ Integer rotate(C& c) {
1450
+ return rotate(std::begin(c), std::end(c));
1451
+ }
1452
+
1453
+ //========================================================================//
1454
+ // sequences //
1455
+ //========================================================================//
1456
+ std::vector<Integer> distinct(Integer count, Integer lower, Integer upper) {
1457
+ judgeAssert<std::invalid_argument>(count >= 0, "Random::distinct(): Count must be non negative!");
1458
+ judgeAssert<std::invalid_argument>(lower + count <= upper, "Random::distinct(): Lower must be less than upper + count!");
1459
+ std::map<Integer, Integer> used;
1460
+ std::vector<Integer> res;
1461
+ for (Integer i = 0; i < count; i++) {
1462
+ Integer x = integer(lower, upper - i);
1463
+ auto it = used.find(x);
1464
+ if (it != used.end()) res.emplace_back(it->second);
1465
+ else res.emplace_back(x);
1466
+ it = used.find(upper - i - 1);
1467
+ if (it != used.end()) used[x] = it->second;
1468
+ else used[x] = upper - i - 1;
1469
+ }
1470
+ return res;
1471
+ }
1472
+ std::vector<Integer> distinct(Integer count, Integer upper) {
1473
+ return distinct(count, 0, upper);
1474
+ }
1475
+
1476
+ std::vector<Integer> perm(Integer count, Integer offset = 0) {
1477
+ return distinct(count, offset, offset+count);
1478
+ }
1479
+
1480
+ std::vector<Integer> perm(const std::vector<Integer>& cycles, Integer offset = 0) {
1481
+ auto p = perm(std::accumulate(cycles.begin(), cycles.end(), 0_int));
1482
+ std::vector<Integer> res(p.size());
1483
+ Integer tmp = 0;
1484
+ for (std::size_t i = 0; i < cycles.size(); tmp += cycles[i], i++) {
1485
+ judgeAssert<std::invalid_argument>(cycles[i] > 0, "Random::perm(): Cycle lengths must be positive!");
1486
+ for (Integer j = tmp; j + 1 < tmp + cycles[i]; j++) {
1487
+ res[p[j]] = p[j + 1] + offset;
1488
+ }
1489
+ res[p[tmp + cycles[i] - 1]] = p[tmp] + offset;
1490
+ }
1491
+ return res;
1492
+ }
1493
+
1494
+ std::vector<Integer> perm(std::initializer_list<Integer> cycles, Integer offset = 0) {
1495
+ return perm(std::vector<Integer>(cycles), offset);
1496
+ }
1497
+
1498
+ std::vector<Integer> multiple(Integer count, Integer lower, Integer upper) {
1499
+ std::vector<Integer> res(count);
1500
+ for (Integer& x : res) x = integer(lower, upper);
1501
+ return res;
1502
+ }
1503
+ std::vector<Integer> multiple(Integer count, Integer upper) {
1504
+ return multiple(count, 0, upper);
1505
+ }
1506
+
1507
+ std::vector<Integer> increasing(Integer count, Integer lower, Integer upper) {
1508
+ std::vector<Integer> res = distinct(count, lower, upper);
1509
+ std::sort(res.begin(), res.end(), std::less<Integer>());
1510
+ return res;
1511
+ }
1512
+ std::vector<Integer> increasing(Integer count, Integer upper) {
1513
+ return increasing(count, 0, upper);
1514
+ }
1515
+
1516
+ std::vector<Integer> decreasing(Integer count, Integer lower, Integer upper) {
1517
+ std::vector<Integer> res = distinct(count, lower, upper);
1518
+ std::sort(res.begin(), res.end(), std::greater<Integer>());
1519
+ return res;
1520
+ }
1521
+ std::vector<Integer> decreasing(Integer count, Integer upper) {
1522
+ return decreasing(count, 0, upper);
1523
+ }
1524
+
1525
+ std::vector<Integer> nonDecreasing(Integer count, Integer lower, Integer upper) {
1526
+ std::vector<Integer> res = multiple(count, lower, upper);
1527
+ std::sort(res.begin(), res.end(), std::less<Integer>());
1528
+ return res;
1529
+ }
1530
+ std::vector<Integer> nonDecreasing(Integer count, Integer upper) {
1531
+ return nonDecreasing(count, 0, upper);
1532
+ }
1533
+
1534
+ std::vector<Integer> nonIncreasing(Integer count, Integer lower, Integer upper) {
1535
+ std::vector<Integer> res = multiple(count, lower, upper);
1536
+ std::sort(res.begin(), res.end(), std::greater<Integer>());
1537
+ return res;
1538
+ }
1539
+ std::vector<Integer> nonIncreasing(Integer count, Integer upper) {
1540
+ return nonIncreasing(count, 0, upper);
1541
+ }
1542
+
1543
+ std::vector<Integer> partition(Integer n, Integer k, Integer min = 1) {
1544
+ judgeAssert<std::invalid_argument>(n > 0, "Random::partition(): n must be positive!");
1545
+ judgeAssert<std::invalid_argument>(k > 0, "Random::partition(): k must be positive!");
1546
+ judgeAssert<std::invalid_argument>(min <= 0 or k <= n / min, "Random::partition(): k too large!");
1547
+ n -= (min - 1) * k;
1548
+ std::vector<Integer> res = increasing(k-1, 1, n);
1549
+ res.emplace_back(n);
1550
+ for (Integer i = 0, last = 0; i < k; i++) {
1551
+ res[i] -= last;
1552
+ last += res[i];
1553
+ res[i] += min - 1;
1554
+ }
1555
+ return res;
1556
+ }
1557
+
1558
+ std::string bracketSequence(Integer n, char open = '(', char close = ')') {//proper bracket sequence of length 2*n
1559
+ judgeAssert<std::invalid_argument>(0 <= n and n <= 0x7FFF'FFFF, "Random::bracketSequence(): n out of range!");
1560
+ std::string res(2 * n, open);
1561
+ for (Integer i = 0, diff = 0; i < 2 * n; i++) {
1562
+ Integer opened = (i + diff) / 2;
1563
+ if (integer((2 * n - i) * (diff + 1)) < (n - opened) * (diff + 2)) {
1564
+ diff++;
1565
+ } else {
1566
+ res[i] = close;
1567
+ diff--;
1568
+ }
1569
+ }
1570
+ return res;
1571
+ }
1572
+
1573
+ //========================================================================//
1574
+ // geometry //
1575
+ //========================================================================//
1576
+ template<typename Point = std::pair<Integer, Integer>>
1577
+ std::vector<Point> convex(Integer n, Integer dim) {
1578
+ judgeAssert<std::invalid_argument>(dim <= 0x3FFF'FFFF, "Random::convex(): dim too large!");
1579
+ judgeAssert<std::invalid_argument>(dim > 0, "Random::convex(): dim must be positive!");
1580
+ judgeAssert<std::invalid_argument>(n <= 8*dim - 8, "Random::convex(): dim too small!");
1581
+ judgeAssert<std::invalid_argument>(n >= 3, "Random::convex(): n too small!");
1582
+
1583
+ while (true) {
1584
+ Integer left = 1 + binomial(n - 2, 0.5);
1585
+ Integer down = 1 + binomial(n - 2, 0.5);
1586
+ auto x = partition(2 * dim - 2, left, 0);
1587
+ auto y = partition(2 * dim - 2, down, 0);
1588
+ for (auto& z : x) z = -z;
1589
+ for (auto& z : y) z = -z;
1590
+ append(x, partition(2 * dim - 2, n - left, 0));
1591
+ append(y, partition(2 * dim - 2, n - down, 0));
1592
+ auto itX = std::partition(x.begin(), x.end(), [](Integer z){return z == 0;});
1593
+ auto itY = std::partition(y.begin(), y.end(), [](Integer z){return z != 0;});
1594
+ if (std::distance(x.begin(), itX) + std::distance(itY, y.end()) > n) continue;
1595
+ shuffle(itX, x.end());
1596
+ if (itX != x.begin()) shuffle(y.begin(), itY);
1597
+
1598
+ std::vector<Point> dirs(n);
1599
+ for (Integer i = 0; i < n; i++) {
1600
+ dirs[i] = {x[i], y[i]};
1601
+ }
1602
+ ::details::cyclicSort(dirs);
1603
+
1604
+ std::vector<Point> res = {{0, 0}};
1605
+ Integer maxX = 0;
1606
+ Integer maxY = 0;
1607
+ for (auto dir : dirs) {
1608
+ Point tmp = res.back();
1609
+ getX(tmp) += getX(dir);
1610
+ getY(tmp) += getY(dir);
1611
+ maxX = std::max(maxX, getX(tmp));
1612
+ maxY = std::max(maxY, getY(tmp));
1613
+ res.emplace_back(tmp);
1614
+ }
1615
+ res.pop_back();
1616
+ for (auto& point : res) {
1617
+ getX(point) += dim - 1 - maxX;
1618
+ getY(point) += dim - 1 - maxY;
1619
+ }
1620
+ return res;
1621
+ }
1622
+ }
1623
+
1624
+ template<typename Point = std::pair<Integer, Integer>>
1625
+ std::vector<Point> nonCollinearPoints(Integer n, Integer dim) {
1626
+ judgeAssert<std::invalid_argument>(dim <= 0x1FFF'FFFF, "Random::nonCollinearPoints(): dim too large!");
1627
+ judgeAssert<std::invalid_argument>(n >= 0, "Random::nonCollinearPoints(): dim must be non negative!");
1628
+ judgeAssert<std::invalid_argument>(dim > n, "Random::nonCollinearPoints(): dim too small!");
1629
+ Integer p = prime(dim - 1, 2*dim + 2);
1630
+ Integer rotA = 0;
1631
+ Integer rotB = 0;
1632
+ while (rotA == 0 && rotB == 0) {
1633
+ rotA = integer(0, p);
1634
+ rotB = integer(0, p);
1635
+ }
1636
+ std::array<Integer, 3> abc = {
1637
+ integer(1, p),
1638
+ integer(0, p),
1639
+ integer(0, p),
1640
+ };
1641
+ Integer dx = integer(-dim + 1, dim - p);
1642
+ Integer dy = integer(-dim + 1, dim - p);
1643
+
1644
+ auto xs = distinct(n, p);
1645
+ std::vector<Point> res;
1646
+ for (auto tmpX : xs) {
1647
+ Integer tmpY = 0;
1648
+ for (Integer add : abc[0]) {
1649
+ tmpY *= tmpX;
1650
+ tmpY += add;
1651
+ tmpY %= p;
1652
+ }
1653
+
1654
+ Integer x = applyMod(tmpX * rotA - tmpY * rotB, p);
1655
+ Integer y = applyMod(tmpX * rotB + tmpY * rotA, p);
1656
+
1657
+ res.emplace_back(x + dx, y + dy);
1658
+ }
1659
+ return res;
1660
+ }
1661
+
1662
+ } // namespace Random
1663
+
1664
+
1665
+ //============================================================================//
1666
+ // args parser //
1667
+ //============================================================================//
1668
+ class ParamaterBase {
1669
+ friend class Command;
1670
+ friend struct Paramater;
1671
+
1672
+ std::optional<std::string_view> token;
1673
+
1674
+ template<typename T>
1675
+ T parse(std::string_view s) const {
1676
+ T res = {};
1677
+ judgeAssert<std::invalid_argument>(details::parse<T>(s, res), "Command: Could not parse args");
1678
+ return res;
1679
+ }
1680
+
1681
+ ParamaterBase() = default;
1682
+ explicit ParamaterBase(std::string_view token_) : token(token_) {}
1683
+
1684
+ public:
1685
+ std::string asString() const {
1686
+ return std::string(token.value());
1687
+ }
1688
+
1689
+ std::string asString(std::string_view defaultValue) const {
1690
+ return std::string(token.value_or(defaultValue));
1691
+ }
1692
+
1693
+ Integer asInteger() const {
1694
+ return parse<Integer>(token.value());
1695
+ }
1696
+
1697
+ Integer asInteger(Integer defaultValue) const {
1698
+ return token ? asInteger() : defaultValue;
1699
+ }
1700
+
1701
+ Real asReal() const {
1702
+ return parse<Real>(token.value());
1703
+ }
1704
+
1705
+ Real asReal(Real defaultValue) const {
1706
+ return token ? asReal() : defaultValue;
1707
+ }
1708
+ };
1709
+
1710
+ struct Paramater final : private ParamaterBase {
1711
+ using ParamaterBase::ParamaterBase;
1712
+ using ParamaterBase::asString;
1713
+ using ParamaterBase::asInteger;
1714
+ using ParamaterBase::asReal;
1715
+
1716
+ bool exists() const {
1717
+ return token.has_value();
1718
+ }
1719
+
1720
+ explicit operator bool() const {
1721
+ return exists();
1722
+ }
1723
+ };
1724
+
1725
+ class Command final : private ParamaterBase {
1726
+ const std::vector<std::string>& raw;
1727
+ const Integer first, count;
1728
+ const bool found;
1729
+ public:
1730
+ explicit Command(const std::vector<std::string>& raw_) : raw(raw_), first(0), count(0), found(false) {}
1731
+ explicit Command(const std::vector<std::string>& raw_, Integer first_, Integer count_)
1732
+ : ParamaterBase(count_ == 0 ? ParamaterBase() : ParamaterBase(raw_[first_])),
1733
+ raw(raw_), first(first_), count(count_), found(true) {
1734
+ judgeAssert<std::invalid_argument>(count >= 0, "Command: Invalid command in args!");
1735
+ }
1736
+
1737
+ bool exists() const {
1738
+ return found;
1739
+ }
1740
+
1741
+ explicit operator bool() const {
1742
+ return exists();
1743
+ }
1744
+
1745
+ Integer parameterCount() const {
1746
+ return count;
1747
+ }
1748
+
1749
+ Paramater operator[](Integer i) const {
1750
+ if (i >= 0 and i < count) return Paramater(raw[first + i]);
1751
+ return Paramater();
1752
+ }
1753
+
1754
+ using ParamaterBase::asString;
1755
+ using ParamaterBase::asInteger;
1756
+ using ParamaterBase::asReal;
1757
+
1758
+ std::vector<std::string> asStrings() const {
1759
+ std::vector<std::string> res;
1760
+ std::transform(raw.begin() + first,
1761
+ raw.begin() + first + count,
1762
+ std::back_inserter(res), [](const std::string& value) {
1763
+ return std::string(value);
1764
+ });
1765
+ return res;
1766
+ }
1767
+
1768
+ std::vector<Integer> asIntegers() const {
1769
+ std::vector<Integer> res;
1770
+ std::transform(raw.begin() + first,
1771
+ raw.begin() + first + count,
1772
+ std::back_inserter(res), [this](const std::string& value) {
1773
+ return parse<Integer>(value);
1774
+ });
1775
+ return res;
1776
+ }
1777
+
1778
+ std::vector<Real> asReals() const {
1779
+ std::vector<Real> res;
1780
+ std::transform(raw.begin() + first,
1781
+ raw.begin() + first + count,
1782
+ std::back_inserter(res), [this](const std::string& value) {
1783
+ return parse<Real>(value);
1784
+ });
1785
+ return res;
1786
+ }
1787
+
1788
+ };
1789
+
1790
+ class CommandParser final {
1791
+ std::vector<std::string> raw;
1792
+ std::map<std::string_view, std::pair<Integer, Integer>> commands;
1793
+ std::map<std::string_view, Integer> tokens;
1794
+
1795
+ static bool isCommand(std::string_view s) {
1796
+ return s.size() > 2 and s.substr(0, 2) == COMMAND_PREFIX;
1797
+ }
1798
+ void addCommand(std::string_view command, Integer first, Integer count = 0) {
1799
+ judgeAssert<std::invalid_argument>(commands.count(command) == 0, "Command: Duplcated command in args!");
1800
+ commands.emplace(command, std::pair<Integer, Integer>{first, count});
1801
+ }
1802
+
1803
+ public:
1804
+ CommandParser() = default;
1805
+ explicit CommandParser(int argc, char** argv) {
1806
+ raw.assign(argc, {});
1807
+ std::string_view command = EMPTY_COMMAND;
1808
+ Integer first = 0;
1809
+ Integer count = 0;
1810
+ for (int i = 0; i < argc; i++) {
1811
+ raw[i] = std::string(argv[i]);
1812
+ tokens.emplace(raw[i], i+1);
1813
+ if (isCommand(raw[i])) {
1814
+ addCommand(command, first, count);
1815
+ command = raw[i];
1816
+ first = i+1;
1817
+ count = 0;
1818
+ } else {
1819
+ count++;
1820
+ }
1821
+ }
1822
+ addCommand(command, first, count);
1823
+ }
1824
+ CommandParser(CommandParser&&) = default;
1825
+ CommandParser& operator=(CommandParser&&) = default;
1826
+
1827
+ CommandParser(const CommandParser&) = delete;
1828
+ CommandParser& operator=(const CommandParser&) = delete;
1829
+
1830
+ std::string_view operator[](Integer t) const {
1831
+ judgeAssert<std::out_of_range>(t >= 0 and t < static_cast<Integer>(raw.size()), "Command: Index out of args!");
1832
+ return raw[t];
1833
+ }
1834
+ Command operator[](std::string_view command) const & {
1835
+ judgeAssert<std::invalid_argument>(details::isToken(command), "Command: must not contain a space!");
1836
+ auto it = commands.find(command);
1837
+ if (it == commands.end()) return Command(raw);
1838
+ return Command(raw, it->second.first, it->second.second);
1839
+ }
1840
+ Command getRaw(std::string_view command) const & {
1841
+ judgeAssert<std::invalid_argument>(details::isToken(command), "Command: must not contain a space!");
1842
+ auto it = tokens.find(command);
1843
+ if (it == tokens.end()) return Command(raw);
1844
+ return Command(raw, it->second, raw.size() - it->second);
1845
+ }
1846
+ Command getRaw() const & {
1847
+ return Command(raw, 0, raw.size());
1848
+ }
1849
+ };
1850
+
1851
+
1852
+ //============================================================================//
1853
+ // Constraints //
1854
+ //============================================================================//
1855
+ template<typename T>
1856
+ class Bounds final {
1857
+ bool hadMin, hadMax; // was value==lower/upper at some point
1858
+ T min, max; // range of seen values
1859
+ T lower, upper; // bounds for value
1860
+ public:
1861
+ constexpr explicit Bounds(T lower_, T upper_, T value_) :
1862
+ hadMin(false), hadMax(false),
1863
+ min(value_), max(value_),
1864
+ lower(lower_), upper(upper_) {
1865
+ update(lower_, upper_, value_);
1866
+ }
1867
+
1868
+ void update(T lower_, T upper_, T value_) {
1869
+ if constexpr (std::is_same_v<T, Real>) {
1870
+ hadMin |= details::floatEqual(value_, lower_, DEFAULT_EPS, DEFAULT_EPS);
1871
+ hadMax |= details::floatEqual(value_, upper_, DEFAULT_EPS, DEFAULT_EPS);
1872
+ } else {
1873
+ hadMin |= value_ == lower_;
1874
+ hadMax |= value_ == upper_;
1875
+ }
1876
+ min = std::min(min, value_);
1877
+ max = std::max(max, value_);
1878
+ lower = std::min(lower, lower_);
1879
+ upper = std::max(upper, upper_);
1880
+ }
1881
+
1882
+ friend std::ostream& operator<<(std::ostream& os, const Bounds<T>& bounds) {
1883
+ os << bounds.hadMin << " " << bounds.hadMax << " ";
1884
+ os << bounds.min << " " << bounds.max << " ";
1885
+ return os << bounds.lower << " " << bounds.upper;
1886
+ }
1887
+
1888
+ };
1889
+
1890
+ namespace details {
1891
+ //using typeIndex = std::type_index;
1892
+ using typeIndex = void*;
1893
+
1894
+ template<typename T>
1895
+ typeIndex getTypeIndex() {
1896
+ //return std::type_index(type id(T));
1897
+ static T* uniqueTypeIndex = nullptr;
1898
+ return &uniqueTypeIndex;
1899
+ }
1900
+ }
1901
+
1902
+ class Constraint final {
1903
+ friend class ConstraintsLogger;
1904
+ std::variant<
1905
+ std::monostate, // uninitialized
1906
+ Bounds<Integer>, // Integer or container bound
1907
+ Bounds<Real> // Real bound
1908
+ > bound;
1909
+ std::optional<details::typeIndex> type;
1910
+
1911
+ template<typename T, typename X = T>
1912
+ void update(T lower, T upper, T value) {
1913
+ if constexpr(std::is_integral_v<T>) {
1914
+ upper--; // for BAPCtools the range is closed but we use half open ranges!
1915
+ }
1916
+ if (!type) {
1917
+ type = details::getTypeIndex<X>();
1918
+ bound = Bounds<T>(lower, upper, value);
1919
+ }
1920
+ judgeAssert<std::logic_error>(type == details::getTypeIndex<X>(), "Constraint: type must not change!");
1921
+ std::get<Bounds<T>>(bound).update(lower, upper, value);
1922
+ }
1923
+ public:
1924
+ Constraint() = default;
1925
+ Constraint(Constraint&&) = default;
1926
+ Constraint& operator=(Constraint&&) = default;
1927
+
1928
+ Constraint(const Constraint&) = delete;
1929
+ Constraint& operator=(const Constraint&) = delete;
1930
+
1931
+ template<typename V, typename std::enable_if_t<std::is_integral_v<V>, bool> = true>
1932
+ void log(Integer lower, Integer upper, V value) {
1933
+ update<Integer>(lower, upper, value);
1934
+ }
1935
+
1936
+ template<typename V, typename std::enable_if_t<std::is_floating_point_v<V>, bool> = true>
1937
+ void log(Real lower, Real upper, V value) {
1938
+ update<Real>(lower, upper, value);
1939
+ }
1940
+
1941
+ template<typename C, typename std::enable_if_t<!std::is_arithmetic_v<C>, bool> = true>
1942
+ void log(Integer lower, Integer upper, const C& container) {
1943
+ update<Integer, C>(lower, upper, static_cast<Integer>(std::size(container)));
1944
+ }
1945
+ };
1946
+
1947
+ class ConstraintsLogger final {
1948
+ std::optional<std::string> fileName;
1949
+ std::map<std::string, std::size_t> byName;
1950
+ std::vector<std::unique_ptr<Constraint>> constraints;
1951
+ public:
1952
+ ConstraintsLogger() = default;
1953
+ explicit ConstraintsLogger(std::string_view fileName_) : fileName(fileName_) {}
1954
+
1955
+ ConstraintsLogger(ConstraintsLogger&&) = default;
1956
+ ConstraintsLogger& operator=(ConstraintsLogger&&) = default;
1957
+
1958
+ ConstraintsLogger(const ConstraintsLogger&) = delete;
1959
+ ConstraintsLogger& operator=(const ConstraintsLogger&) = delete;
1960
+
1961
+ Constraint& operator[](const std::string& name) & {
1962
+ judgeAssert<std::invalid_argument>(details::isToken(name), "Constraint: name must not contain a space!");
1963
+ auto res = byName.try_emplace(name, constraints.size());
1964
+ if (res.second) constraints.emplace_back(std::make_unique<Constraint>());
1965
+ return *(constraints[res.first->second]);
1966
+ }
1967
+
1968
+ void write() const {
1969
+ if (!fileName) return;
1970
+ std::ofstream os(*fileName);
1971
+ os << std::noboolalpha;
1972
+ os << std::fixed;
1973
+ os << std::setprecision(DEFAULT_PRECISION);
1974
+ for (const auto& [name, id] : byName) {
1975
+ const Constraint& c = *(constraints[id]);
1976
+ if (c.type) {
1977
+ os << "LocationNotSupported:" << name << " " << name << " ";
1978
+ if (c.bound.index() == 1) os << std::get<1>(c.bound);
1979
+ if (c.bound.index() == 2) os << std::get<2>(c.bound);
1980
+ os << std::endl;
1981
+ }
1982
+ }
1983
+ }
1984
+
1985
+ ~ConstraintsLogger() noexcept {
1986
+ write();
1987
+ }
1988
+ };
1989
+
1990
+ //============================================================================//
1991
+ // custom input stream //
1992
+ //============================================================================//
1993
+ class InputStream final {
1994
+ std::unique_ptr<std::ifstream> managed;
1995
+ std::istream* in;
1996
+ bool spaceSensitive, caseSensitive;
1997
+ Verdict onFail;
1998
+ Real floatAbsTol;
1999
+ Real floatRelTol;
2000
+
2001
+ void init() {
2002
+ if (spaceSensitive) *in >> std::noskipws;
2003
+ else *in >> std::skipws;
2004
+ }
2005
+
2006
+ void checkIn() {
2007
+ judgeAssert<std::runtime_error>(in != nullptr, "InputStream: not initialized!");
2008
+ }
2009
+
2010
+ public:
2011
+ InputStream() = default;
2012
+ explicit InputStream(const std::filesystem::path& path,
2013
+ bool spaceSensitive_,
2014
+ bool caseSensitive_,
2015
+ Verdict onFail_,
2016
+ Real floatAbsTol_ = DEFAULT_EPS,
2017
+ Real floatRelTol_ = DEFAULT_EPS) :
2018
+ managed(std::make_unique<std::ifstream>(path)),
2019
+ in(managed.get()),
2020
+ spaceSensitive(spaceSensitive_),
2021
+ caseSensitive(caseSensitive_),
2022
+ onFail(onFail_),
2023
+ floatAbsTol(floatAbsTol_),
2024
+ floatRelTol(floatRelTol_) {
2025
+ judgeAssert<std::runtime_error>(managed->good(), "InputStream: Could not open File: " + path.string());
2026
+ init();
2027
+ }
2028
+ explicit InputStream(std::istream& in_,
2029
+ bool spaceSensitive_,
2030
+ bool caseSensitive_,
2031
+ Verdict onFail_,
2032
+ Real floatAbsTol_ = DEFAULT_EPS,
2033
+ Real floatRelTol_ = DEFAULT_EPS) :
2034
+ managed(),
2035
+ in(&in_),
2036
+ spaceSensitive(spaceSensitive_),
2037
+ caseSensitive(caseSensitive_),
2038
+ onFail(onFail_),
2039
+ floatAbsTol(floatAbsTol_),
2040
+ floatRelTol(floatRelTol_) {
2041
+ init();
2042
+ }
2043
+
2044
+ InputStream(InputStream&& other) = default;
2045
+ InputStream& operator=(InputStream&& other) = default;
2046
+
2047
+ InputStream(const InputStream&) = delete;
2048
+ InputStream& operator=(const InputStream&) = delete;
2049
+
2050
+ void eof() {
2051
+ checkIn();
2052
+ if (!spaceSensitive) *in >> std::ws;
2053
+ if (in->peek() != std::char_traits<char>::eof()) {
2054
+ in->get();
2055
+ ValidateBase::juryOut << "Missing EOF!";
2056
+ fail();
2057
+ }
2058
+ }
2059
+
2060
+ void noteof() {
2061
+ checkIn();
2062
+ if (!spaceSensitive) *in >> std::ws;
2063
+ if (in->peek() == std::char_traits<char>::eof()) {
2064
+ ValidateBase::juryOut << "Unexpected EOF!" << onFail;
2065
+ }
2066
+ }
2067
+
2068
+ void space() {
2069
+ if (spaceSensitive) {
2070
+ noteof();
2071
+ if (in->get() != std::char_traits<char>::to_int_type(SPACE)) {
2072
+ ValidateBase::juryOut << "Missing space!";
2073
+ fail();
2074
+ }
2075
+ }
2076
+ }
2077
+
2078
+ void newline() {
2079
+ if (spaceSensitive) {
2080
+ noteof();
2081
+ if (in->get() != std::char_traits<char>::to_int_type(NEWLINE)) {
2082
+ ValidateBase::juryOut << "Missing newline!";
2083
+ fail();
2084
+ }
2085
+ }
2086
+ }
2087
+
2088
+ private:
2089
+ void check(const std::string& token, const std::regex& pattern) {
2090
+ if (!std::regex_match(token, pattern)) {
2091
+ ValidateBase::juryOut << "Token \"" << token << "\" does not match pattern!";
2092
+ fail();
2093
+ }
2094
+ }
2095
+
2096
+ std::function<void()> checkSeparator(char separator) {
2097
+ if (separator == SPACE) return [this](){space();};
2098
+ if (separator == NEWLINE) return [this](){newline();};
2099
+ judgeAssert<std::invalid_argument>(false, "InputStream: Separator must be ' ' or '\\n'!");
2100
+ return {};
2101
+ }
2102
+
2103
+ template<typename T>
2104
+ T parse(const std::string& s) {
2105
+ T res = {};
2106
+ if (!details::parse<T>(s, res)) {
2107
+ ValidateBase::juryOut << "Could not parse token \"" << s << "\"!";
2108
+ fail();
2109
+ }
2110
+ return res;
2111
+ }
2112
+
2113
+ public:
2114
+ std::string string() {
2115
+ noteof();
2116
+ if (spaceSensitive and !std::isgraph(in->peek())) {
2117
+ in->get();
2118
+ ValidateBase::juryOut << "Invalid whitespace!";
2119
+ fail();
2120
+ }
2121
+ std::string res;
2122
+ *in >> res;
2123
+ if (res.empty()) {
2124
+ ValidateBase::juryOut << "Unexpected EOF!" << onFail;
2125
+ }
2126
+ if (!caseSensitive) toDefaultCase(res);
2127
+ return res;
2128
+ }
2129
+
2130
+ std::string string(Integer lower, Integer upper) {
2131
+ std::string t = string();
2132
+ Integer length = static_cast<Integer>(t.size());
2133
+ if (length < lower or length >= upper) {
2134
+ ValidateBase::juryOut << "String length " << length << " out of range [" << lower << ", " << upper << ")!";
2135
+ fail();
2136
+ }
2137
+ return t;
2138
+ }
2139
+
2140
+ std::string string(Integer lower, Integer upper, Constraint& constraint) {
2141
+ std::string res = string(lower, upper);
2142
+ constraint.log(lower, upper, res);
2143
+ return res;
2144
+ }
2145
+
2146
+ std::string string(const std::regex& pattern) {
2147
+ std::string t = string();
2148
+ check(t, pattern);
2149
+ return t;
2150
+ }
2151
+
2152
+ std::string string(const std::regex& pattern, Integer lower, Integer upper) {
2153
+ std::string t = string(lower, upper);
2154
+ check(t, pattern);
2155
+ return t;
2156
+ }
2157
+
2158
+ std::string string(const std::regex& pattern, Integer lower, Integer upper, Constraint& constraint) {
2159
+ std::string res = string(pattern, lower, upper);
2160
+ constraint.log(lower, upper, res);
2161
+ return res;
2162
+ }
2163
+
2164
+ template<typename... Args>
2165
+ std::vector<std::string> strings(Args... args, Integer count, char separator) {
2166
+ auto sepCall = checkSeparator(separator);
2167
+ std::vector<std::string> res(count);
2168
+ for (Integer i = 0; i < count; i++) {
2169
+ res[i] = string(args...);
2170
+ if (i + 1 < count) sepCall();
2171
+ }
2172
+ return res;
2173
+ }
2174
+
2175
+ std::vector<std::string> strings(Integer count, char separator = DEFAULT_SEPARATOR) {
2176
+ return strings<>(count, separator);
2177
+ }
2178
+
2179
+ std::vector<std::string> strings(Integer lower, Integer upper,
2180
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2181
+ return strings<Integer, Integer>(lower, upper, count, separator);
2182
+ }
2183
+
2184
+ std::vector<std::string> strings(Integer lower, Integer upper, Constraint& constraint,
2185
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2186
+ return strings<Integer, Integer, Constraint&>(lower, upper, constraint, count, separator);
2187
+ }
2188
+
2189
+ std::vector<std::string> strings(const std::regex& pattern,
2190
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2191
+ return strings<const std::regex&>(pattern, count, separator);
2192
+ }
2193
+
2194
+ std::vector<std::string> strings(const std::regex& pattern, Integer lower, Integer upper,
2195
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2196
+ return strings<const std::regex&, Integer, Integer>(pattern, lower, upper, count, separator);
2197
+ }
2198
+
2199
+ std::vector<std::string> strings(const std::regex& pattern, Integer lower, Integer upper, Constraint& constraint,
2200
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2201
+ return strings<const std::regex&, Integer, Integer, Constraint&>(pattern, lower, upper, constraint, count, separator);
2202
+ }
2203
+
2204
+ Integer integer() {
2205
+ return parse<Integer>(string(INTEGER_REGEX));
2206
+ }
2207
+
2208
+ Integer integer(Integer lower, Integer upper) {
2209
+ Integer res = integer();
2210
+ if (res < lower or res >= upper) {
2211
+ ValidateBase::juryOut << "Integer " << res << " out of range [" << lower << ", " << upper << ")!";
2212
+ fail();
2213
+ }
2214
+ return res;
2215
+ }
2216
+
2217
+ Integer integer(Integer lower, Integer upper, Constraint& constraint) {
2218
+ Integer res = integer(lower, upper);
2219
+ constraint.log(lower, upper, res);
2220
+ return res;
2221
+ }
2222
+
2223
+ template<typename... Args>
2224
+ std::vector<Integer> integers(Args... args, Integer count, char separator) {
2225
+ auto sepCall = checkSeparator(separator);
2226
+ std::vector<Integer> res(count);
2227
+ for (Integer i = 0; i < count; i++) {
2228
+ res[i] = integer(args...);
2229
+ if (i + 1 < count) sepCall();
2230
+ }
2231
+ return res;
2232
+ }
2233
+
2234
+ std::vector<Integer> integers(Integer count, char separator = DEFAULT_SEPARATOR) {
2235
+ return integers<>(count, separator);
2236
+ }
2237
+
2238
+ std::vector<Integer> integers(Integer lower, Integer upper,
2239
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2240
+ return integers<Integer, Integer>(lower, upper, count, separator);
2241
+ }
2242
+
2243
+ std::vector<Integer> integers(Integer lower, Integer upper, Constraint& constraint,
2244
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2245
+ return integers<Integer, Integer, Constraint&>(lower, upper, constraint, count, separator);
2246
+ }
2247
+
2248
+ // this does not allow NaN or Inf!
2249
+ // However, those should never be desired.
2250
+ Real real() {
2251
+ return parse<Real>(string(REAL_REGEX));
2252
+ }
2253
+
2254
+ Real real(Real lower, Real upper) {// uses eps
2255
+ Real res = real();
2256
+ if (details::floatEqual(res, lower, floatAbsTol, floatRelTol)) return res;
2257
+ if (details::floatEqual(res, upper, floatAbsTol, floatRelTol)) return res;
2258
+ if (std::isnan(res) or !(res >= lower) or !(res < upper)) {
2259
+ ValidateBase::juryOut << "Real " << res << " out of range [" << lower << ", " << upper << ")!";
2260
+ fail();
2261
+ }
2262
+ return res;
2263
+ }
2264
+
2265
+ Real real(Real lower, Real upper, Constraint& constraint) {
2266
+ Real res = real(lower, upper);
2267
+ constraint.log(lower, upper, res);
2268
+ return res;
2269
+ }
2270
+
2271
+ template<typename... Args>
2272
+ std::vector<Real> reals(Args... args, Integer count, char separator) {
2273
+ auto sepCall = checkSeparator(separator);
2274
+ std::vector<Real> res(count);
2275
+ for (Integer i = 0; i < count; i++) {
2276
+ res[i] = real(args...);
2277
+ if (i + 1 < count) sepCall();
2278
+ }
2279
+ return res;
2280
+ }
2281
+
2282
+ std::vector<Real> reals(Integer count, char separator = DEFAULT_SEPARATOR) {
2283
+ return reals<>(count, separator);
2284
+ }
2285
+
2286
+ std::vector<Real> reals(Real lower, Real upper,
2287
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2288
+ return reals<Real, Real>(lower, upper, count, separator);
2289
+ }
2290
+
2291
+ std::vector<Real> reals(Real lower, Real upper, Constraint& constraint,
2292
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2293
+ return reals<Real, Real, Constraint&>(lower, upper, constraint, count, separator);
2294
+ }
2295
+
2296
+ Real realStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals) {// does not use eps
2297
+ std::string t = string(STRICT_REAL_REGEX);
2298
+ auto dot = t.find('.');
2299
+ Integer decimals = dot == std::string::npos ? 0 : t.size() - dot - 1;
2300
+ if (decimals < minDecimals or decimals >= maxDecimals) {
2301
+ ValidateBase::juryOut << "Real " << t << " has wrong amount of decimals!";
2302
+ fail();
2303
+ return 0;
2304
+ }
2305
+ try {
2306
+ Real res = parse<Real>(t);
2307
+ if (std::isnan(res) or !(res >= lower) or !(res < upper)) {
2308
+ ValidateBase::juryOut << "Real " << res << " out of range [" << lower << ", " << upper << ")!";
2309
+ fail();
2310
+ }
2311
+ return res;
2312
+ } catch(...) {
2313
+ ValidateBase::juryOut << "Could not parse token \"" << t << "\" as real!";
2314
+ fail();
2315
+ return 0;
2316
+ }
2317
+ }
2318
+
2319
+ Real realStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, Constraint& constraint) {
2320
+ Real res = realStrict(lower, upper, minDecimals, maxDecimals);
2321
+ constraint.log(lower, upper, res);
2322
+ return res;
2323
+ }
2324
+
2325
+ template<typename... Args>
2326
+ std::vector<Real> realsStrict(Args... args, Integer count, char separator) {
2327
+ auto sepCall = checkSeparator(separator);
2328
+ std::vector<Real> res(count);
2329
+ for (Integer i = 0; i < count; i++) {
2330
+ res[i] = realStrict(args...);
2331
+ if (i + 1 < count) sepCall();
2332
+ }
2333
+ return res;
2334
+ }
2335
+
2336
+ std::vector<Real> realsStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals,
2337
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2338
+ return realsStrict<Real, Real, Integer, Integer>(lower, upper, minDecimals, maxDecimals, count, separator);
2339
+ }
2340
+
2341
+ std::vector<Real> realsStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, Constraint& constraint,
2342
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2343
+ return realsStrict<Real, Real, Integer, Integer, Constraint&>(lower, upper, minDecimals, maxDecimals, constraint, count, separator);
2344
+ }
2345
+
2346
+ void expectString(std::string_view expected) {
2347
+ judgeAssert<std::invalid_argument>(details::isToken(expected), "InputStream: expected must not contain a space!");
2348
+ std::string seen = string();
2349
+ auto [eq, pos] = details::stringEqual(seen, expected, caseSensitive);
2350
+ if (!eq) {
2351
+ if (seen.size() > 80) {
2352
+ seen = seen.substr(0, 75) + "[...]";
2353
+ }
2354
+ ValidateBase::juryOut << "Expected \"" << expected << "\" but got \"" << seen << "\"!";
2355
+ if (pos and *pos > 5) {
2356
+ ValidateBase::juryOut << " (different at position: " << *pos+1 << ")";
2357
+ }
2358
+ fail();
2359
+ }
2360
+ }
2361
+
2362
+ void expectInt(Integer expected) {
2363
+ Integer seen = integer();
2364
+ if (seen != expected) {
2365
+ ValidateBase::juryOut << "Expected " << expected << " but got " << seen << "!";
2366
+ fail();
2367
+ }
2368
+ }
2369
+
2370
+ void expectReal(Real expected) {
2371
+ Real seen = real();
2372
+ if (details::floatEqual(seen, expected, floatAbsTol, floatRelTol)) {
2373
+ ValidateBase::juryOut << "Expected " << expected << " but got " << seen << "!";
2374
+ if (std::isfinite(seen) and std::isfinite(expected)) {
2375
+ Real absDiff = std::abs(seen-expected);
2376
+ Real relDiff = std::abs((seen-expected)/expected);
2377
+ ValidateBase::juryOut << " (abs: " << absDiff << ", rel: " << relDiff << ")";
2378
+ }
2379
+ fail();
2380
+ }
2381
+ }
2382
+ private:
2383
+ void fail() {
2384
+ //try to find input position...
2385
+ in->clear();
2386
+ auto originalPos = in->tellg();
2387
+ in->seekg(0);
2388
+ if (originalPos != std::streamoff(-1) and *in) {
2389
+ Integer line = 1;
2390
+ std::size_t l = 0, r = 0;
2391
+ std::string buffer;
2392
+ bool extend = true;
2393
+ while (*in and in->tellg() < originalPos) {
2394
+ l = r = buffer.size();
2395
+ if (std::isgraph(in->peek())) {
2396
+ std::string tmp;
2397
+ *in >> tmp;
2398
+ buffer += tmp;
2399
+ } else if (in->peek() == std::char_traits<char>::to_int_type(NEWLINE)) {
2400
+ line++;
2401
+ in->get();
2402
+ if (in->tellg() < originalPos) {
2403
+ buffer.clear();
2404
+ } else {
2405
+ buffer += ' ';
2406
+ extend = false;
2407
+ }
2408
+ } else {
2409
+ buffer += std::char_traits<char>::to_char_type(in->get());
2410
+ }
2411
+ if (*in and in->tellg() >= originalPos) {
2412
+ r = buffer.size();
2413
+ }
2414
+ }
2415
+ if (l != r) {
2416
+ ValidateBase::juryOut << " Line: " << line << ", Char: " << l << '\n';
2417
+ if (extend) {
2418
+ char tmp;
2419
+ while ((buffer.size() < 80 or buffer.size() < r + 80) and in->get(tmp) and tmp != NEWLINE) {
2420
+ buffer += tmp;
2421
+ }
2422
+ }
2423
+ if (r > 60 and l > 20) {
2424
+ Integer offset = std::min(l - 20, r - 60);
2425
+ l -= offset;
2426
+ r -= offset;
2427
+ buffer = "[...]" + buffer.substr(offset + 5);
2428
+ }
2429
+ if (buffer.size() > 80) {
2430
+ buffer = buffer.substr(0, 75);
2431
+ buffer += "[...]";
2432
+ r = std::min(r, buffer.size());
2433
+ }
2434
+ ValidateBase::juryOut << buffer << '\n';
2435
+ ValidateBase::juryOut << std::string(l, ' ') << '^' << std::string(r - l - 1, '~');
2436
+ }
2437
+ }
2438
+ ValidateBase::juryOut << onFail;
2439
+ }
2440
+ };
2441
+
2442
+
2443
+ //============================================================================//
2444
+ // state guard //
2445
+ //============================================================================//
2446
+ namespace details {
2447
+ bool initialized(bool set = false) {
2448
+ static bool value = false;
2449
+ return std::exchange(value, value |= set);
2450
+ }
2451
+
2452
+ struct InitGuard final {
2453
+ ~InitGuard() {
2454
+ if (std::uncaught_exceptions() == 0) {
2455
+ judgeAssert<std::logic_error>(initialized(), "validate.h: init(argc, argv) was never called!");
2456
+ }
2457
+ }
2458
+ } initGuard;
2459
+ }
2460
+
2461
+
2462
+ //============================================================================//
2463
+ // Settings //
2464
+ //============================================================================//
2465
+ template<typename T>
2466
+ class SettingBase {
2467
+ template<typename U>
2468
+ friend class Setting;
2469
+ friend class SettingCaseSensitive;
2470
+
2471
+ T value;
2472
+
2473
+ SettingBase(T value_) : value(value_) {}
2474
+
2475
+ public:
2476
+ SettingBase(SettingBase<T>&& other) = delete;
2477
+ SettingBase(const SettingBase<T>&) = delete;
2478
+ SettingBase<T>& operator=(SettingBase<T>&& other) = delete;
2479
+ SettingBase<T>& operator=(const SettingBase<T>&) = delete;
2480
+
2481
+ operator T() const {
2482
+ return value;
2483
+ }
2484
+
2485
+ SettingBase<T>& operator=(T value_) {
2486
+ judgeAssert<std::logic_error>(!details::initialized(), "validate.h: Cannot change setting after init(argc, argv) was called!");
2487
+ value = value_;
2488
+ return *this;
2489
+ }
2490
+ };
2491
+
2492
+ template<typename T>
2493
+ class Setting final : public SettingBase<T> {
2494
+ public:
2495
+ Setting(T value) : SettingBase<T>(value) {}
2496
+ using SettingBase<T>::operator T;
2497
+ using SettingBase<T>::operator=;
2498
+ };
2499
+
2500
+ class SettingCaseSensitive final : public SettingBase<bool> {
2501
+ public:
2502
+ SettingCaseSensitive(bool value) : SettingBase<bool>(value) {}
2503
+ using SettingBase<bool>::operator bool;
2504
+ using SettingBase<bool>::operator=;
2505
+
2506
+ std::regex regex(std::string_view s, std::regex_constants::syntax_option_type f = std::regex_constants::ECMAScript) const {
2507
+ if (!value) f |= std::regex_constants::icase;
2508
+ return std::regex(s.data(), s.size(), f);
2509
+ }
2510
+ };
2511
+
2512
+
2513
+ //============================================================================//
2514
+ // Validators and stuff //
2515
+ //============================================================================//
2516
+ namespace ValidateBase {
2517
+ //OutputStream juryOut(std::cout); //already defined earlier
2518
+ //OutputStream juryErr(std::cerr);
2519
+ CommandParser arguments;
2520
+ //you may change these values before calling::init() but not afterwards!
2521
+ Setting<Real> floatAbsTol(DEFAULT_EPS);
2522
+ Setting<Real> floatRelTol(DEFAULT_EPS);
2523
+ Setting<bool> spaceSensitive(false);
2524
+ SettingCaseSensitive caseSensitive(false);
2525
+
2526
+ // Real r2 is considered the reference value for relative error.
2527
+ bool floatEqual(Real given,
2528
+ Real expected,
2529
+ Real floatAbsTol_ = floatAbsTol,
2530
+ Real floatRelTol_ = floatRelTol) {
2531
+ return details::floatEqual(given, expected, floatAbsTol_, floatRelTol_);
2532
+ }
2533
+
2534
+ bool floatLess(Real given,
2535
+ Real expected,
2536
+ Real floatAbsTol_ = floatAbsTol,
2537
+ Real floatRelTol_ = floatRelTol) {
2538
+ return given <= expected or floatEqual(given, expected, floatAbsTol_, floatRelTol_);
2539
+ }
2540
+
2541
+ bool floatGreater(Real given,
2542
+ Real expected,
2543
+ Real floatAbsTol_ = floatAbsTol,
2544
+ Real floatRelTol_ = floatRelTol) {
2545
+ return given >= expected or floatEqual(given, expected, floatAbsTol_, floatRelTol_);
2546
+ }
2547
+
2548
+ constexpr boolean<std::size_t> stringEqual(std::string_view a, std::string_view b, bool caseSensitive_ = caseSensitive) {
2549
+ return details::stringEqual(a, b, caseSensitive_);
2550
+ }
2551
+
2552
+ namespace details {
2553
+ void init(int argc, char** argv) {
2554
+ judgeAssert<std::logic_error>(!::details::initialized(), "validate.h: init(argc, argv) was called twice!");
2555
+
2556
+ //std::ios_base::sync_with_stdio(false);
2557
+ //cin.tie(nullptr);
2558
+
2559
+ arguments = CommandParser(argc, argv);
2560
+ if (auto seed = arguments[SEED_COMMAND]) Random::seed(seed.asInteger());
2561
+ // parse default flags manually, since they dont use '--' prefix
2562
+ auto eps = arguments.getRaw(FLOAT_TOLERANCE);
2563
+ floatAbsTol = eps.asReal(floatAbsTol);
2564
+ floatRelTol = eps.asReal(floatRelTol);
2565
+ floatAbsTol = arguments.getRaw(FLOAT_ABSOLUTE_TOLERANCE).asReal(floatAbsTol);
2566
+ floatRelTol = arguments.getRaw(FLOAT_RELATIVE_TOLERANCE).asReal(floatRelTol);
2567
+
2568
+ if (arguments.getRaw(SPACE_SENSITIVE)) spaceSensitive = true;
2569
+ if (arguments.getRaw(CASE_SENSITIVE)) caseSensitive = true;
2570
+
2571
+ ::details::initialized(true);
2572
+ }
2573
+ }
2574
+
2575
+ } // namespace ValidateBase
2576
+
2577
+ namespace ConstraintsBase {
2578
+ ConstraintsLogger constraint;
2579
+
2580
+ void initConstraints() {
2581
+ if (auto file = ValidateBase::arguments[CONSTRAINT_COMMAND]) {
2582
+ constraint = ConstraintsLogger(file.asString());
2583
+ }
2584
+ }
2585
+
2586
+ } // namespace ConstraintsBase
2587
+
2588
+ //called as ./validator [arguments] < inputfile
2589
+ namespace InputValidator {
2590
+ using namespace ValidateBase;
2591
+ using namespace ConstraintsBase;
2592
+
2593
+ InputStream testIn;
2594
+
2595
+ void init(int argc, char** argv) {
2596
+ spaceSensitive = true;
2597
+ caseSensitive = true;
2598
+
2599
+ ValidateBase::details::init(argc, argv);
2600
+ juryOut = OutputStream(std::cout);
2601
+
2602
+ testIn = InputStream(std::cin, spaceSensitive, caseSensitive, WA, floatAbsTol, floatRelTol);
2603
+ initConstraints();
2604
+ }
2605
+
2606
+ } // namespace InputValidator
2607
+
2608
+ //called as ./validator input judgeanswer feedbackdir < teamoutput
2609
+ namespace OutputValidator {
2610
+ using namespace ValidateBase;
2611
+ using namespace ConstraintsBase;
2612
+
2613
+ InputStream testIn;
2614
+ InputStream juryAns;
2615
+ InputStream teamAns;
2616
+
2617
+ void init(int argc, char** argv) {
2618
+ ValidateBase::details::init(argc, argv);
2619
+ juryOut = OutputStream(std::filesystem::path(arguments[3]) / JUDGE_MESSAGE);
2620
+
2621
+ testIn = InputStream(std::filesystem::path(arguments[1]), false, caseSensitive, FAIL);
2622
+ juryAns = InputStream(std::filesystem::path(arguments[2]), false, caseSensitive, FAIL);
2623
+ teamAns = InputStream(std::cin, spaceSensitive, caseSensitive, WA);
2624
+ initConstraints();
2625
+ }
2626
+
2627
+ } // namespace OutputValidator
2628
+
2629
+ //called as ./interactor input judgeanswer feedbackdir <> teamoutput
2630
+ namespace Interactor {
2631
+ using namespace ValidateBase;
2632
+
2633
+ OutputStream toTeam;
2634
+ InputStream testIn;
2635
+ InputStream fromTeam;
2636
+
2637
+ void init(int argc, char** argv) {
2638
+ ValidateBase::details::init(argc, argv);
2639
+ juryOut = OutputStream(std::filesystem::path(arguments[3]) / JUDGE_MESSAGE);
2640
+ toTeam = OutputStream(std::cout);
2641
+
2642
+ testIn = InputStream(std::filesystem::path(arguments[1]), false, caseSensitive, FAIL);
2643
+ fromTeam = InputStream(std::cin, spaceSensitive, caseSensitive, WA);
2644
+ }
2645
+
2646
+ } // namespace Interactor
2647
+
2648
+ //called as ./generator [arguments]
2649
+ namespace Generator {
2650
+ using namespace ValidateBase;
2651
+
2652
+ OutputStream testOut;
2653
+
2654
+ void init(int argc, char** argv) {
2655
+ ValidateBase::details::init(argc, argv);
2656
+ juryOut = OutputStream(std::cerr);
2657
+ testOut = OutputStream(std::cout);
2658
+ }
2659
+
2660
+ } // namespace Generator
2661
+
2662
+ #endif
ICPC/nwerc2023_C/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:649797f71211929574b32c8992a4bad824163cfa41c8f121fe22b710fff88829
3
+ size 48190763
ICPC/nwerc2023_C/init.yml ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ test_cases:
3
+ - in: 01-query-biggest.in
4
+ out: 01-query-biggest.ans
5
+ points: 1
6
+ - in: 02-random.in
7
+ out: 02-random.ans
8
+ points: 1
9
+ - in: 03-random_even.in
10
+ out: 03-random_even.ans
11
+ points: 1
12
+ - in: 04-random_occupied.in
13
+ out: 04-random_occupied.ans
14
+ points: 1
15
+ - in: 05-distinct_primes.in
16
+ out: 05-distinct_primes.ans
17
+ points: 1
18
+ - in: 06-big_prime.in
19
+ out: 06-big_prime.ans
20
+ points: 1
21
+ - in: 07-small_prime.in
22
+ out: 07-small_prime.ans
23
+ points: 1
24
+ - in: 08-semiprime.in
25
+ out: 08-semiprime.ans
26
+ points: 1
27
+ - in: 09-composite.in
28
+ out: 09-composite.ans
29
+ points: 1
30
+ - in: 10-random.in
31
+ out: 10-random.ans
32
+ points: 1
33
+ - in: 11-random.in
34
+ out: 11-random.ans
35
+ points: 1
36
+ - in: 12-random.in
37
+ out: 12-random.ans
38
+ points: 1
39
+ - in: 13-random.in
40
+ out: 13-random.ans
41
+ points: 1
42
+ - in: 14-random.in
43
+ out: 14-random.ans
44
+ points: 1
45
+ - in: 15-random_even.in
46
+ out: 15-random_even.ans
47
+ points: 1
48
+ - in: 16-random_even.in
49
+ out: 16-random_even.ans
50
+ points: 1
51
+ - in: 17-random_even.in
52
+ out: 17-random_even.ans
53
+ points: 1
54
+ - in: 18-random_even.in
55
+ out: 18-random_even.ans
56
+ points: 1
57
+ - in: 19-random_even.in
58
+ out: 19-random_even.ans
59
+ points: 1
60
+ - in: 20-random_occupied.in
61
+ out: 20-random_occupied.ans
62
+ points: 1
63
+ - in: 21-random_occupied.in
64
+ out: 21-random_occupied.ans
65
+ points: 1
66
+ - in: 22-distinct_primes.in
67
+ out: 22-distinct_primes.ans
68
+ points: 1
69
+ - in: 23-distinct_primes.in
70
+ out: 23-distinct_primes.ans
71
+ points: 1
72
+ - in: 24-power_of_two.in
73
+ out: 24-power_of_two.ans
74
+ points: 1
75
+ - in: 25-follow.in
76
+ out: 25-follow.ans
77
+ points: 1
78
+ - in: 26-follow.in
79
+ out: 26-follow.ans
80
+ points: 1
81
+ - in: 27-random.in
82
+ out: 27-random.ans
83
+ points: 1
84
+ - in: 28-random.in
85
+ out: 28-random.ans
86
+ points: 1
87
+ - in: 29-big_prime.in
88
+ out: 29-big_prime.ans
89
+ points: 1
90
+ - in: 30-big_prime.in
91
+ out: 30-big_prime.ans
92
+ points: 1
93
+ - in: 31-small_prime.in
94
+ out: 31-small_prime.ans
95
+ points: 1
96
+ - in: 32-semiprime.in
97
+ out: 32-semiprime.ans
98
+ points: 1
99
+ - in: 33-semiprime.in
100
+ out: 33-semiprime.ans
101
+ points: 1
102
+ - in: 34-composite.in
103
+ out: 34-composite.ans
104
+ points: 1
105
+ - in: 35-query_all.in
106
+ out: 35-query_all.ans
107
+ points: 1
108
+ - in: 36-query_all.in
109
+ out: 36-query_all.ans
110
+ points: 1
111
+ - in: 37-query_all.in
112
+ out: 37-query_all.ans
113
+ points: 1
114
+ - in: 38-query_all.in
115
+ out: 38-query_all.ans
116
+ points: 1
117
+ - in: 39-query_all.in
118
+ out: 39-query_all.ans
119
+ points: 1
120
+ - in: 40-query_all.in
121
+ out: 40-query_all.ans
122
+ points: 1
123
+ - in: 41-manual.in
124
+ out: 41-manual.ans
125
+ points: 1
126
+ - in: 42-manual.in
127
+ out: 42-manual.ans
128
+ points: 1
129
+ - in: 43-manual.in
130
+ out: 43-manual.ans
131
+ points: 1
132
+ - in: 44-manual.in
133
+ out: 44-manual.ans
134
+ points: 1
135
+ - in: 45-manual.in
136
+ out: 45-manual.ans
137
+ points: 1
ICPC/nwerc2023_D/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aab1e5aeb5b1c01da996d45dca2f863a670ae6b3937726d223786ed3d892f8f7
3
+ size 21922
ICPC/nwerc2023_D/init.yml ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ checker:
3
+ args:
4
+ precision: 6
5
+ name: floats
6
+ test_cases:
7
+ - in: 01-rand_min.in
8
+ out: 01-rand_min.ans
9
+ points: 1
10
+ - in: 02-rand_almost_max.in
11
+ out: 02-rand_almost_max.ans
12
+ points: 1
13
+ - in: 03-rand_almost_max.in
14
+ out: 03-rand_almost_max.ans
15
+ points: 1
16
+ - in: 04-rand_almost_max.in
17
+ out: 04-rand_almost_max.ans
18
+ points: 1
19
+ - in: 05-rand_max.in
20
+ out: 05-rand_max.ans
21
+ points: 1
22
+ - in: 06-rand_worst.in
23
+ out: 06-rand_worst.ans
24
+ points: 1
25
+ - in: 07-rand_worst.in
26
+ out: 07-rand_worst.ans
27
+ points: 1
28
+ - in: 08-rand_worst_rows.in
29
+ out: 08-rand_worst_rows.ans
30
+ points: 1
31
+ - in: 09-rand_worst_rows.in
32
+ out: 09-rand_worst_rows.ans
33
+ points: 1
34
+ - in: 10-rand_worst_cols.in
35
+ out: 10-rand_worst_cols.ans
36
+ points: 1
37
+ - in: 11-rand_worst_cols.in
38
+ out: 11-rand_worst_cols.ans
39
+ points: 1
40
+ - in: 12-all_empty.in
41
+ out: 12-all_empty.ans
42
+ points: 1
43
+ - in: 13-all_empty.in
44
+ out: 13-all_empty.ans
45
+ points: 1
46
+ - in: 14-all_empty.in
47
+ out: 14-all_empty.ans
48
+ points: 1
49
+ - in: 15-all_empty.in
50
+ out: 15-all_empty.ans
51
+ points: 1
52
+ - in: 16-all_empty.in
53
+ out: 16-all_empty.ans
54
+ points: 1
55
+ - in: 17-all_empty.in
56
+ out: 17-all_empty.ans
57
+ points: 1
58
+ - in: 18-all_empty.in
59
+ out: 18-all_empty.ans
60
+ points: 1
61
+ - in: 19-all_empty.in
62
+ out: 19-all_empty.ans
63
+ points: 1
64
+ - in: 20-all_empty.in
65
+ out: 20-all_empty.ans
66
+ points: 1
67
+ - in: 21-all_empty.in
68
+ out: 21-all_empty.ans
69
+ points: 1
70
+ - in: 22-all_empty.in
71
+ out: 22-all_empty.ans
72
+ points: 1
73
+ - in: 23-all_empty.in
74
+ out: 23-all_empty.ans
75
+ points: 1
76
+ - in: 24-all_full.in
77
+ out: 24-all_full.ans
78
+ points: 1
79
+ - in: 25-all_full.in
80
+ out: 25-all_full.ans
81
+ points: 1
82
+ - in: 26-all_full.in
83
+ out: 26-all_full.ans
84
+ points: 1
85
+ - in: 27-all_full.in
86
+ out: 27-all_full.ans
87
+ points: 1
88
+ - in: 28-all_full.in
89
+ out: 28-all_full.ans
90
+ points: 1
91
+ - in: 29-all_full.in
92
+ out: 29-all_full.ans
93
+ points: 1
94
+ - in: 30-all_full.in
95
+ out: 30-all_full.ans
96
+ points: 1
97
+ - in: 31-all_full.in
98
+ out: 31-all_full.ans
99
+ points: 1
100
+ - in: 32-all_full.in
101
+ out: 32-all_full.ans
102
+ points: 1
103
+ - in: 33-all_full.in
104
+ out: 33-all_full.ans
105
+ points: 1
106
+ - in: 34-all_full.in
107
+ out: 34-all_full.ans
108
+ points: 1
109
+ - in: 35-all_full.in
110
+ out: 35-all_full.ans
111
+ points: 1
112
+ - in: 36-exact_fit.in
113
+ out: 36-exact_fit.ans
114
+ points: 1
115
+ - in: 37-exact_fit.in
116
+ out: 37-exact_fit.ans
117
+ points: 1
118
+ - in: 38-exact_fit.in
119
+ out: 38-exact_fit.ans
120
+ points: 1
121
+ - in: 39-exact_fit.in
122
+ out: 39-exact_fit.ans
123
+ points: 1
124
+ - in: 40-exact_fit.in
125
+ out: 40-exact_fit.ans
126
+ points: 1
127
+ - in: 41-exact_fit.in
128
+ out: 41-exact_fit.ans
129
+ points: 1
130
+ - in: 42-exact_fit.in
131
+ out: 42-exact_fit.ans
132
+ points: 1
133
+ - in: 43-exact_fit.in
134
+ out: 43-exact_fit.ans
135
+ points: 1
136
+ - in: 44-exact_fit.in
137
+ out: 44-exact_fit.ans
138
+ points: 1
139
+ - in: 45-exact_fit.in
140
+ out: 45-exact_fit.ans
141
+ points: 1
142
+ - in: 46-exact_fit.in
143
+ out: 46-exact_fit.ans
144
+ points: 1
145
+ - in: 47-exact_fit_shuffled.in
146
+ out: 47-exact_fit_shuffled.ans
147
+ points: 1
148
+ - in: 48-exact_fit_shuffled.in
149
+ out: 48-exact_fit_shuffled.ans
150
+ points: 1
151
+ - in: 49-exact_fit_shuffled.in
152
+ out: 49-exact_fit_shuffled.ans
153
+ points: 1
154
+ - in: 50-exact_fit_shuffled.in
155
+ out: 50-exact_fit_shuffled.ans
156
+ points: 1
157
+ - in: 51-exact_fit_shuffled.in
158
+ out: 51-exact_fit_shuffled.ans
159
+ points: 1
160
+ - in: 52-exact_fit_shuffled.in
161
+ out: 52-exact_fit_shuffled.ans
162
+ points: 1
163
+ - in: 53-exact_fit_shuffled.in
164
+ out: 53-exact_fit_shuffled.ans
165
+ points: 1
166
+ - in: 54-exact_fit_shuffled.in
167
+ out: 54-exact_fit_shuffled.ans
168
+ points: 1
169
+ - in: 55-exact_fit_shuffled.in
170
+ out: 55-exact_fit_shuffled.ans
171
+ points: 1
172
+ - in: 56-exact_fit_shuffled.in
173
+ out: 56-exact_fit_shuffled.ans
174
+ points: 1
175
+ - in: 57-exact_fit_shuffled.in
176
+ out: 57-exact_fit_shuffled.ans
177
+ points: 1
178
+ - in: 58-corners.in
179
+ out: 58-corners.ans
180
+ points: 1
181
+ - in: 59-corners.in
182
+ out: 59-corners.ans
183
+ points: 1
184
+ - in: 60-corners.in
185
+ out: 60-corners.ans
186
+ points: 1
187
+ - in: 61-corners.in
188
+ out: 61-corners.ans
189
+ points: 1
190
+ - in: 62-corners.in
191
+ out: 62-corners.ans
192
+ points: 1
193
+ - in: 63-4corners.in
194
+ out: 63-4corners.ans
195
+ points: 1
196
+ - in: 64-4corners.in
197
+ out: 64-4corners.ans
198
+ points: 1
199
+ - in: 65-4corners.in
200
+ out: 65-4corners.ans
201
+ points: 1
202
+ - in: 66-4corners.in
203
+ out: 66-4corners.ans
204
+ points: 1
205
+ - in: 67-4corners.in
206
+ out: 67-4corners.ans
207
+ points: 1
208
+ - in: 68-4corners.in
209
+ out: 68-4corners.ans
210
+ points: 1
211
+ - in: 69-4corners.in
212
+ out: 69-4corners.ans
213
+ points: 1
214
+ - in: 70-4corners.in
215
+ out: 70-4corners.ans
216
+ points: 1
217
+ - in: 71-4corners.in
218
+ out: 71-4corners.ans
219
+ points: 1
220
+ - in: 72-corner.in
221
+ out: 72-corner.ans
222
+ points: 1
223
+ - in: 73-corner.in
224
+ out: 73-corner.ans
225
+ points: 1
226
+ - in: 74-corner.in
227
+ out: 74-corner.ans
228
+ points: 1
229
+ - in: 75-corner.in
230
+ out: 75-corner.ans
231
+ points: 1
232
+ - in: 76-corner.in
233
+ out: 76-corner.ans
234
+ points: 1
235
+ - in: 77-corner.in
236
+ out: 77-corner.ans
237
+ points: 1
238
+ - in: 78-corner.in
239
+ out: 78-corner.ans
240
+ points: 1
241
+ - in: 79-corner.in
242
+ out: 79-corner.ans
243
+ points: 1
244
+ - in: 80-corner.in
245
+ out: 80-corner.ans
246
+ points: 1
247
+ - in: 81-corner.in
248
+ out: 81-corner.ans
249
+ points: 1
250
+ - in: 82-corner.in
251
+ out: 82-corner.ans
252
+ points: 1
253
+ - in: 83-corner.in
254
+ out: 83-corner.ans
255
+ points: 1
ICPC/nwerc2023_E/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d2d6977cbb540127a2425e6d396e1aa9dcea3c85eb53900366b6d8f16d04079
3
+ size 242919
ICPC/nwerc2023_E/init.yml ADDED
@@ -0,0 +1,404 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ test_cases:
3
+ - in: 001-twos.in
4
+ out: 001-twos.ans
5
+ points: 1
6
+ - in: 002-rivals.in
7
+ out: 002-rivals.ans
8
+ points: 1
9
+ - in: 003-tree2.in
10
+ out: 003-tree2.ans
11
+ points: 1
12
+ - in: 004-tiny.in
13
+ out: 004-tiny.ans
14
+ points: 1
15
+ - in: 005-tiny.in
16
+ out: 005-tiny.ans
17
+ points: 1
18
+ - in: 006-tiny.in
19
+ out: 006-tiny.ans
20
+ points: 1
21
+ - in: 007-tiny.in
22
+ out: 007-tiny.ans
23
+ points: 1
24
+ - in: 008-tiny.in
25
+ out: 008-tiny.ans
26
+ points: 1
27
+ - in: 009-tiny.in
28
+ out: 009-tiny.ans
29
+ points: 1
30
+ - in: 010-tiny.in
31
+ out: 010-tiny.ans
32
+ points: 1
33
+ - in: 011-tiny.in
34
+ out: 011-tiny.ans
35
+ points: 1
36
+ - in: 012-tiny.in
37
+ out: 012-tiny.ans
38
+ points: 1
39
+ - in: 013-wrong_base.in
40
+ out: 013-wrong_base.ans
41
+ points: 1
42
+ - in: 014-wrong_base.in
43
+ out: 014-wrong_base.ans
44
+ points: 1
45
+ - in: 015-random.in
46
+ out: 015-random.ans
47
+ points: 1
48
+ - in: 016-random.in
49
+ out: 016-random.ans
50
+ points: 1
51
+ - in: 017-random.in
52
+ out: 017-random.ans
53
+ points: 1
54
+ - in: 018-random.in
55
+ out: 018-random.ans
56
+ points: 1
57
+ - in: 019-random.in
58
+ out: 019-random.ans
59
+ points: 1
60
+ - in: 020-random.in
61
+ out: 020-random.ans
62
+ points: 1
63
+ - in: 021-random.in
64
+ out: 021-random.ans
65
+ points: 1
66
+ - in: 022-random.in
67
+ out: 022-random.ans
68
+ points: 1
69
+ - in: 023-chain.in
70
+ out: 023-chain.ans
71
+ points: 1
72
+ - in: 024-chain.in
73
+ out: 024-chain.ans
74
+ points: 1
75
+ - in: 025-chain.in
76
+ out: 025-chain.ans
77
+ points: 1
78
+ - in: 026-chain.in
79
+ out: 026-chain.ans
80
+ points: 1
81
+ - in: 027-chain.in
82
+ out: 027-chain.ans
83
+ points: 1
84
+ - in: 028-max_output.in
85
+ out: 028-max_output.ans
86
+ points: 1
87
+ - in: 029-rivals.in
88
+ out: 029-rivals.ans
89
+ points: 1
90
+ - in: 030-rivals.in
91
+ out: 030-rivals.ans
92
+ points: 1
93
+ - in: 031-rivals.in
94
+ out: 031-rivals.ans
95
+ points: 1
96
+ - in: 032-rivals.in
97
+ out: 032-rivals.ans
98
+ points: 1
99
+ - in: 033-rivals.in
100
+ out: 033-rivals.ans
101
+ points: 1
102
+ - in: 034-rivals.in
103
+ out: 034-rivals.ans
104
+ points: 1
105
+ - in: 035-rivals.in
106
+ out: 035-rivals.ans
107
+ points: 1
108
+ - in: 036-rivals.in
109
+ out: 036-rivals.ans
110
+ points: 1
111
+ - in: 037-long_lists.in
112
+ out: 037-long_lists.ans
113
+ points: 1
114
+ - in: 038-long_lists.in
115
+ out: 038-long_lists.ans
116
+ points: 1
117
+ - in: 039-long_lists.in
118
+ out: 039-long_lists.ans
119
+ points: 1
120
+ - in: 040-long_lists.in
121
+ out: 040-long_lists.ans
122
+ points: 1
123
+ - in: 041-long_lists.in
124
+ out: 041-long_lists.ans
125
+ points: 1
126
+ - in: 042-one_long_list.in
127
+ out: 042-one_long_list.ans
128
+ points: 1
129
+ - in: 043-tree.in
130
+ out: 043-tree.ans
131
+ points: 1
132
+ - in: 044-tree.in
133
+ out: 044-tree.ans
134
+ points: 1
135
+ - in: 045-tree.in
136
+ out: 045-tree.ans
137
+ points: 1
138
+ - in: 046-tree.in
139
+ out: 046-tree.ans
140
+ points: 1
141
+ - in: 047-tree.in
142
+ out: 047-tree.ans
143
+ points: 1
144
+ - in: 048-tree.in
145
+ out: 048-tree.ans
146
+ points: 1
147
+ - in: 049-tree.in
148
+ out: 049-tree.ans
149
+ points: 1
150
+ - in: 050-almost_isomorphic.in
151
+ out: 050-almost_isomorphic.ans
152
+ points: 1
153
+ - in: 051-almost_isomorphic.in
154
+ out: 051-almost_isomorphic.ans
155
+ points: 1
156
+ - in: 052-almost_isomorphic.in
157
+ out: 052-almost_isomorphic.ans
158
+ points: 1
159
+ - in: 053-almost_isomorphic.in
160
+ out: 053-almost_isomorphic.ans
161
+ points: 1
162
+ - in: 054-almost_isomorphic.in
163
+ out: 054-almost_isomorphic.ans
164
+ points: 1
165
+ - in: 055-almost_isomorphic.in
166
+ out: 055-almost_isomorphic.ans
167
+ points: 1
168
+ - in: 056-almost_isomorphic.in
169
+ out: 056-almost_isomorphic.ans
170
+ points: 1
171
+ - in: 057-triangles.in
172
+ out: 057-triangles.ans
173
+ points: 1
174
+ - in: 058-triangles.in
175
+ out: 058-triangles.ans
176
+ points: 1
177
+ - in: 059-triangles.in
178
+ out: 059-triangles.ans
179
+ points: 1
180
+ - in: 060-triangles.in
181
+ out: 060-triangles.ans
182
+ points: 1
183
+ - in: 061-triangles.in
184
+ out: 061-triangles.ans
185
+ points: 1
186
+ - in: 062-triangles.in
187
+ out: 062-triangles.ans
188
+ points: 1
189
+ - in: 063-triangles.in
190
+ out: 063-triangles.ans
191
+ points: 1
192
+ - in: 064-triangles.in
193
+ out: 064-triangles.ans
194
+ points: 1
195
+ - in: 065-triangles.in
196
+ out: 065-triangles.ans
197
+ points: 1
198
+ - in: 066-triangles.in
199
+ out: 066-triangles.ans
200
+ points: 1
201
+ - in: 067-tree2.in
202
+ out: 067-tree2.ans
203
+ points: 1
204
+ - in: 068-tree2.in
205
+ out: 068-tree2.ans
206
+ points: 1
207
+ - in: 069-tree2.in
208
+ out: 069-tree2.ans
209
+ points: 1
210
+ - in: 070-tree2.in
211
+ out: 070-tree2.ans
212
+ points: 1
213
+ - in: 071-tree2.in
214
+ out: 071-tree2.ans
215
+ points: 1
216
+ - in: 072-tree2.in
217
+ out: 072-tree2.ans
218
+ points: 1
219
+ - in: 073-tree2.in
220
+ out: 073-tree2.ans
221
+ points: 1
222
+ - in: 074-tree2.in
223
+ out: 074-tree2.ans
224
+ points: 1
225
+ - in: 075-one_query.in
226
+ out: 075-one_query.ans
227
+ points: 1
228
+ - in: 076-anti_ragnar.in
229
+ out: 076-anti_ragnar.ans
230
+ points: 1
231
+ - in: 077-fibonacci.in
232
+ out: 077-fibonacci.ans
233
+ points: 1
234
+ - in: 078-flipflop-1s.in
235
+ out: 078-flipflop-1s.ans
236
+ points: 1
237
+ - in: 079-flipflop-1s.in
238
+ out: 079-flipflop-1s.ans
239
+ points: 1
240
+ - in: 080-flipflop-1s.in
241
+ out: 080-flipflop-1s.ans
242
+ points: 1
243
+ - in: 081-flipflop-2s.in
244
+ out: 081-flipflop-2s.ans
245
+ points: 1
246
+ - in: 082-flipflop-2s.in
247
+ out: 082-flipflop-2s.ans
248
+ points: 1
249
+ - in: 083-flipflop-2s.in
250
+ out: 083-flipflop-2s.ans
251
+ points: 1
252
+ - in: 084-flipflop-2s.in
253
+ out: 084-flipflop-2s.ans
254
+ points: 1
255
+ - in: 085-flipflop-2s.in
256
+ out: 085-flipflop-2s.ans
257
+ points: 1
258
+ - in: 086-flipflop-2s.in
259
+ out: 086-flipflop-2s.ans
260
+ points: 1
261
+ - in: 087-flipflop-3s.in
262
+ out: 087-flipflop-3s.ans
263
+ points: 1
264
+ - in: 088-flipflop-3s.in
265
+ out: 088-flipflop-3s.ans
266
+ points: 1
267
+ - in: 089-flipflop-3s.in
268
+ out: 089-flipflop-3s.ans
269
+ points: 1
270
+ - in: 090-flipflop-3s.in
271
+ out: 090-flipflop-3s.ans
272
+ points: 1
273
+ - in: 091-flipflop-3s.in
274
+ out: 091-flipflop-3s.ans
275
+ points: 1
276
+ - in: 092-flipflop-3s.in
277
+ out: 092-flipflop-3s.ans
278
+ points: 1
279
+ - in: 093-flipflop-4s.in
280
+ out: 093-flipflop-4s.ans
281
+ points: 1
282
+ - in: 094-flipflop-4s.in
283
+ out: 094-flipflop-4s.ans
284
+ points: 1
285
+ - in: 095-flipflop-4s.in
286
+ out: 095-flipflop-4s.ans
287
+ points: 1
288
+ - in: 096-flipflop-4s.in
289
+ out: 096-flipflop-4s.ans
290
+ points: 1
291
+ - in: 097-flipflop-4s.in
292
+ out: 097-flipflop-4s.ans
293
+ points: 1
294
+ - in: 098-flipflop-4s.in
295
+ out: 098-flipflop-4s.ans
296
+ points: 1
297
+ - in: 099-flipflop-9s.in
298
+ out: 099-flipflop-9s.ans
299
+ points: 1
300
+ - in: 100-flipflop-9s.in
301
+ out: 100-flipflop-9s.ans
302
+ points: 1
303
+ - in: 101-flipflop-9s.in
304
+ out: 101-flipflop-9s.ans
305
+ points: 1
306
+ - in: 102-flipflop-9s.in
307
+ out: 102-flipflop-9s.ans
308
+ points: 1
309
+ - in: 103-flipflop-9s.in
310
+ out: 103-flipflop-9s.ans
311
+ points: 1
312
+ - in: 104-flipflop-9s.in
313
+ out: 104-flipflop-9s.ans
314
+ points: 1
315
+ - in: 105-flipflop-id-1s.in
316
+ out: 105-flipflop-id-1s.ans
317
+ points: 1
318
+ - in: 106-flipflop-id-1s.in
319
+ out: 106-flipflop-id-1s.ans
320
+ points: 1
321
+ - in: 107-flipflop-id-1s.in
322
+ out: 107-flipflop-id-1s.ans
323
+ points: 1
324
+ - in: 108-flipflop-id-2s.in
325
+ out: 108-flipflop-id-2s.ans
326
+ points: 1
327
+ - in: 109-flipflop-id-2s.in
328
+ out: 109-flipflop-id-2s.ans
329
+ points: 1
330
+ - in: 110-flipflop-id-2s.in
331
+ out: 110-flipflop-id-2s.ans
332
+ points: 1
333
+ - in: 111-flipflop-id-3s.in
334
+ out: 111-flipflop-id-3s.ans
335
+ points: 1
336
+ - in: 112-flipflop-id-3s.in
337
+ out: 112-flipflop-id-3s.ans
338
+ points: 1
339
+ - in: 113-flipflop-id-3s.in
340
+ out: 113-flipflop-id-3s.ans
341
+ points: 1
342
+ - in: 114-flipflop-id-4s.in
343
+ out: 114-flipflop-id-4s.ans
344
+ points: 1
345
+ - in: 115-flipflop-id-4s.in
346
+ out: 115-flipflop-id-4s.ans
347
+ points: 1
348
+ - in: 116-flipflop-id-4s.in
349
+ out: 116-flipflop-id-4s.ans
350
+ points: 1
351
+ - in: 117-flipflop-id-9s.in
352
+ out: 117-flipflop-id-9s.ans
353
+ points: 1
354
+ - in: 118-flipflop-id-9s.in
355
+ out: 118-flipflop-id-9s.ans
356
+ points: 1
357
+ - in: 119-flipflop-id-9s.in
358
+ out: 119-flipflop-id-9s.ans
359
+ points: 1
360
+ - in: 120-flipflop-id-1s-p.in
361
+ out: 120-flipflop-id-1s-p.ans
362
+ points: 1
363
+ - in: 121-flipflop-id-1s-p.in
364
+ out: 121-flipflop-id-1s-p.ans
365
+ points: 1
366
+ - in: 122-flipflop-id-1s-p.in
367
+ out: 122-flipflop-id-1s-p.ans
368
+ points: 1
369
+ - in: 123-flipflop-id-2s-p.in
370
+ out: 123-flipflop-id-2s-p.ans
371
+ points: 1
372
+ - in: 124-flipflop-id-2s-p.in
373
+ out: 124-flipflop-id-2s-p.ans
374
+ points: 1
375
+ - in: 125-flipflop-id-2s-p.in
376
+ out: 125-flipflop-id-2s-p.ans
377
+ points: 1
378
+ - in: 126-flipflop-id-3s-p.in
379
+ out: 126-flipflop-id-3s-p.ans
380
+ points: 1
381
+ - in: 127-flipflop-id-3s-p.in
382
+ out: 127-flipflop-id-3s-p.ans
383
+ points: 1
384
+ - in: 128-flipflop-id-3s-p.in
385
+ out: 128-flipflop-id-3s-p.ans
386
+ points: 1
387
+ - in: 129-flipflop-id-4s-p.in
388
+ out: 129-flipflop-id-4s-p.ans
389
+ points: 1
390
+ - in: 130-flipflop-id-4s-p.in
391
+ out: 130-flipflop-id-4s-p.ans
392
+ points: 1
393
+ - in: 131-flipflop-id-4s-p.in
394
+ out: 131-flipflop-id-4s-p.ans
395
+ points: 1
396
+ - in: 132-flipflop-id-9s-p.in
397
+ out: 132-flipflop-id-9s-p.ans
398
+ points: 1
399
+ - in: 133-flipflop-id-9s-p.in
400
+ out: 133-flipflop-id-9s-p.ans
401
+ points: 1
402
+ - in: 134-flipflop-id-9s-p.in
403
+ out: 134-flipflop-id-9s-p.ans
404
+ points: 1
ICPC/nwerc2023_F/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:578c303741e521844c78cdfa125ff3dd0e48444b3f99282cddd941cfc59844ad
3
+ size 19220
ICPC/nwerc2023_F/init.yml ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ checker:
3
+ args:
4
+ files:
5
+ - output_validators/output_validator/validate.h
6
+ - output_validators/output_validator/outputValidator.cpp
7
+ lang: CPP17
8
+ type: default
9
+ name: bridged
10
+ test_cases:
11
+ - in: 01-manual-many-subsets.in
12
+ out: 01-manual-many-subsets.ans
13
+ points: 1
14
+ - in: 02-possible.in
15
+ out: 02-possible.ans
16
+ points: 1
17
+ - in: 03-impossible.in
18
+ out: 03-impossible.ans
19
+ points: 1
20
+ - in: 04-manual.in
21
+ out: 04-manual.ans
22
+ points: 1
23
+ - in: 05-manual.in
24
+ out: 05-manual.ans
25
+ points: 1
26
+ - in: 06-manual.in
27
+ out: 06-manual.ans
28
+ points: 1
29
+ - in: 07-manual.in
30
+ out: 07-manual.ans
31
+ points: 1
32
+ - in: 08-manual.in
33
+ out: 08-manual.ans
34
+ points: 1
35
+ - in: 09-manual.in
36
+ out: 09-manual.ans
37
+ points: 1
38
+ - in: 10-manual.in
39
+ out: 10-manual.ans
40
+ points: 1
41
+ - in: 11-manual.in
42
+ out: 11-manual.ans
43
+ points: 1
44
+ - in: 12-manual.in
45
+ out: 12-manual.ans
46
+ points: 1
47
+ - in: 13-manual.in
48
+ out: 13-manual.ans
49
+ points: 1
50
+ - in: 14-manual.in
51
+ out: 14-manual.ans
52
+ points: 1
53
+ - in: 15-manual.in
54
+ out: 15-manual.ans
55
+ points: 1
56
+ - in: 16-manual.in
57
+ out: 16-manual.ans
58
+ points: 1
59
+ - in: 17-overflow.in
60
+ out: 17-overflow.ans
61
+ points: 1
62
+ - in: 18-overflow.in
63
+ out: 18-overflow.ans
64
+ points: 1
65
+ - in: 19-manual.in
66
+ out: 19-manual.ans
67
+ points: 1
68
+ - in: 20-manual.in
69
+ out: 20-manual.ans
70
+ points: 1
71
+ - in: 21-manual.in
72
+ out: 21-manual.ans
73
+ points: 1
74
+ - in: 22-manual.in
75
+ out: 22-manual.ans
76
+ points: 1
77
+ - in: 23-manual.in
78
+ out: 23-manual.ans
79
+ points: 1
80
+ - in: 24-manual.in
81
+ out: 24-manual.ans
82
+ points: 1
83
+ - in: 25-manual.in
84
+ out: 25-manual.ans
85
+ points: 1
86
+ - in: 26-manual.in
87
+ out: 26-manual.ans
88
+ points: 1
89
+ - in: 27-manual.in
90
+ out: 27-manual.ans
91
+ points: 1
92
+ - in: 28-manual.in
93
+ out: 28-manual.ans
94
+ points: 1
95
+ - in: 29-manual.in
96
+ out: 29-manual.ans
97
+ points: 1
98
+ - in: 30-manual.in
99
+ out: 30-manual.ans
100
+ points: 1
101
+ - in: 31-manual.in
102
+ out: 31-manual.ans
103
+ points: 1
104
+ - in: 32-manual.in
105
+ out: 32-manual.ans
106
+ points: 1
107
+ - in: 33-need_gcd.in
108
+ out: 33-need_gcd.ans
109
+ points: 1
110
+ - in: 34-need_gcd.in
111
+ out: 34-need_gcd.ans
112
+ points: 1
113
+ - in: 35-possible.in
114
+ out: 35-possible.ans
115
+ points: 1
116
+ - in: 36-possible.in
117
+ out: 36-possible.ans
118
+ points: 1
119
+ - in: 37-possible.in
120
+ out: 37-possible.ans
121
+ points: 1
122
+ - in: 38-possible.in
123
+ out: 38-possible.ans
124
+ points: 1
125
+ - in: 39-possible.in
126
+ out: 39-possible.ans
127
+ points: 1
128
+ - in: 40-possible.in
129
+ out: 40-possible.ans
130
+ points: 1
131
+ - in: 41-possible.in
132
+ out: 41-possible.ans
133
+ points: 1
134
+ - in: 42-possible.in
135
+ out: 42-possible.ans
136
+ points: 1
137
+ - in: 43-possible.in
138
+ out: 43-possible.ans
139
+ points: 1
140
+ - in: 44-possible.in
141
+ out: 44-possible.ans
142
+ points: 1
143
+ - in: 45-possible.in
144
+ out: 45-possible.ans
145
+ points: 1
146
+ - in: 46-possible.in
147
+ out: 46-possible.ans
148
+ points: 1
149
+ - in: 47-impossible.in
150
+ out: 47-impossible.ans
151
+ points: 1
152
+ - in: 48-impossible.in
153
+ out: 48-impossible.ans
154
+ points: 1
155
+ - in: 49-impossible.in
156
+ out: 49-impossible.ans
157
+ points: 1
158
+ - in: 50-impossible.in
159
+ out: 50-impossible.ans
160
+ points: 1
161
+ - in: 51-impossible.in
162
+ out: 51-impossible.ans
163
+ points: 1
164
+ - in: 52-impossible.in
165
+ out: 52-impossible.ans
166
+ points: 1
167
+ - in: 53-impossible.in
168
+ out: 53-impossible.ans
169
+ points: 1
170
+ - in: 54-impossible.in
171
+ out: 54-impossible.ans
172
+ points: 1
173
+ - in: 55-impossible.in
174
+ out: 55-impossible.ans
175
+ points: 1
176
+ - in: 56-impossible.in
177
+ out: 56-impossible.ans
178
+ points: 1
179
+ - in: 57-impossible.in
180
+ out: 57-impossible.ans
181
+ points: 1
182
+ - in: 58-impossible.in
183
+ out: 58-impossible.ans
184
+ points: 1
185
+ - in: 59-manual-many-subsets.in
186
+ out: 59-manual-many-subsets.ans
187
+ points: 1
188
+ - in: 60-manual-many-subsets.in
189
+ out: 60-manual-many-subsets.ans
190
+ points: 1
191
+ - in: 61-manual-many-subsets.in
192
+ out: 61-manual-many-subsets.ans
193
+ points: 1
194
+ - in: 62-manual-many-subsets.in
195
+ out: 62-manual-many-subsets.ans
196
+ points: 1
197
+ - in: 63-manual-many-subsets.in
198
+ out: 63-manual-many-subsets.ans
199
+ points: 1
200
+ - in: 64-manual-many-subsets.in
201
+ out: 64-manual-many-subsets.ans
202
+ points: 1
203
+ - in: 65-manual-many-subsets.in
204
+ out: 65-manual-many-subsets.ans
205
+ points: 1
206
+ - in: 66-manual-many-subsets.in
207
+ out: 66-manual-many-subsets.ans
208
+ points: 1
209
+ - in: 67-manual-many-subsets.in
210
+ out: 67-manual-many-subsets.ans
211
+ points: 1
212
+ - in: 68-manual-many-subsets.in
213
+ out: 68-manual-many-subsets.ans
214
+ points: 1
215
+ - in: 69-manual-many-subsets.in
216
+ out: 69-manual-many-subsets.ans
217
+ points: 1
218
+ - in: 70-manual-many-subsets.in
219
+ out: 70-manual-many-subsets.ans
220
+ points: 1
221
+ - in: 71-manual-many-subsets.in
222
+ out: 71-manual-many-subsets.ans
223
+ points: 1
ICPC/nwerc2023_F/output_validators/output_validator/outputValidator.cpp ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #include<cstdlib>
3
+ int qwerty_getcode(int code) {
4
+ return code == 42? 0: 1;
5
+ }
6
+ namespace std {
7
+ void qwerty_exit(int code){
8
+ exit(qwerty_getcode(code));
9
+ }
10
+ } using std::qwerty_exit;
11
+ #define exit qwerty_exit
12
+ #define main qwerty_main
13
+ #include "validate.h"
14
+
15
+ std::pair<bool, std::string> isSubsequence(std::string_view x, std::string_view of) {
16
+ std::size_t i = 0;
17
+ std::string remain;
18
+ for (std::size_t j = 0; j < of.size(); j++) {
19
+ if (i < x.size() && x[i] == of[j]) i++;
20
+ else remain.push_back(of[j]);
21
+ }
22
+ std::sort(remain.begin(), remain.end());
23
+ return {i == x.size(), remain};
24
+ }
25
+
26
+ int main(int argc, char **argv) {
27
+ OutputValidator::init(argc, argv);
28
+ using namespace OutputValidator;
29
+
30
+ if (stringEqual(juryAns.string(), "impossible")) {
31
+ teamAns.expectString("impossible");
32
+ teamAns.newline();
33
+ teamAns.eof();
34
+ juryOut << "OK impossible" << AC;
35
+ } else {
36
+ teamAns.expectString("possible");
37
+ teamAns.newline();
38
+ std::string a = testIn.string();
39
+ std::string b = testIn.string();
40
+ Integer c = testIn.integer();
41
+ Integer d = testIn.integer();
42
+
43
+ std::string a2 = teamAns.string(INTEGER_REGEX);
44
+ teamAns.space();
45
+ std::string b2 = teamAns.string(INTEGER_REGEX);
46
+ teamAns.newline();
47
+
48
+ auto [ba, ra] = isSubsequence(a2, a);
49
+ auto [bb, rb] = isSubsequence(b2, b);
50
+
51
+ if (!ba) juryOut << "a' not generated by cancelling digits!" << WA;
52
+ if (!bb) juryOut << "b' not generated by cancelling digits!" << WA;
53
+ if (ra != rb) juryOut << ra << " != " << rb << ": cancelled digits are not the same" << WA;
54
+
55
+ Integer a3 = std::stoll(a2);
56
+ Integer b3 = std::stoll(b2);
57
+ if (a3 == 0 || b3 == 0 ||
58
+ mulMod(c, b3, 1'000'000'007) != mulMod(a3, d, 1'000'000'007) || //product of mods is larger than 10^18*10^18
59
+ mulMod(c, b3, 1'000'000'009) != mulMod(a3, d, 1'000'000'009) ||
60
+ mulMod(c, b3, 1'000'000'021) != mulMod(a3, d, 1'000'000'021) ||
61
+ mulMod(c, b3, 1'000'000'033) != mulMod(a3, d, 1'000'000'033)) {
62
+ juryOut << a << "/" << b << " != " << c << "/" << d << WA;
63
+ }
64
+
65
+ teamAns.eof();
66
+ juryOut << "OK possible" << AC;
67
+ }
68
+ }
69
+
70
+ #undef main
71
+ #include<cstdio>
72
+ #include<vector>
73
+ #include<string>
74
+ #include<filesystem>
75
+ int main(int argc, char **argv) {
76
+ namespace fs = std::filesystem;
77
+ freopen(argv[2], "r", stdin);
78
+ char judge_out[] = "/dev";
79
+ std::vector<char*> new_argv = {
80
+ argv[0], argv[1], argv[3],
81
+ judge_out,
82
+ };
83
+ return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data()));
84
+ }
ICPC/nwerc2023_F/output_validators/output_validator/validate.h ADDED
@@ -0,0 +1,2662 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //============================================================================//
2
+ // validate.h //
3
+ //============================================================================//
4
+ // This header can be used to safely parse team output tokenwise. We support: //
5
+ // - string tokens (get converted to lowercase) //
6
+ // - integer tokens in [-2^63, 2^63) //
7
+ // - float tokens (relative and absolute error of 10^6 is allowed by default) //
8
+ // Tokens need to be separated by whitespace (any amount). The following //
9
+ // command line flags allow stricter checking: //
10
+ // - caseSensitive: string tokens don't get converted to lowercase //
11
+ // - space_change_sensitive: tokens need to be separated by the corect //
12
+ // amount of whitespaces //
13
+ // - FLOAT_{RELATIVE|ABSOLUTE}_TOLERANCE: allowed relative/absolute error //
14
+ // //
15
+ // This header can also be used to safely verify input files. In this case //
16
+ // tokens are case sensitive and all whitespaces have to be checked. Also //
17
+ // whitespaces are not interchangeable. //
18
+ // //
19
+ // This header can be used to generate random numbers in a deterministic and //
20
+ // reproducable fashion. (The randomness is consistent across compilers and //
21
+ // machines) //
22
+ //============================================================================//
23
+ // version 2.3.2 //
24
+ // https://github.com/mzuenni/icpc-header //
25
+ //============================================================================//
26
+
27
+ #ifndef VALIDATE_H
28
+ #define VALIDATE_H
29
+
30
+ #include <algorithm>
31
+ #include <array>
32
+ #include <bitset>
33
+ #include <cctype>
34
+ #include <cmath>
35
+ #include <charconv>
36
+ #include <complex>
37
+ #include <cstdlib>
38
+ #include <filesystem>
39
+ #include <fstream>
40
+ #include <functional>
41
+ #include <iomanip>
42
+ #include <iostream>
43
+ #include <limits>
44
+ #include <map>
45
+ #include <numeric>
46
+ #include <optional>
47
+ #include <queue>
48
+ #include <random>
49
+ #include <regex>
50
+ #include <set>
51
+ #include <string>
52
+ #include <string_view>
53
+ #include <typeinfo>
54
+ #include <typeindex>
55
+ #include <type_traits>
56
+ #include <utility>
57
+ #include <variant>
58
+ #include <vector>
59
+
60
+
61
+ //============================================================================//
62
+ // Basic definitions and constants //
63
+ //============================================================================//
64
+ // default types
65
+ using Integer = std::int64_t;
66
+ using Real = long double;
67
+
68
+ // derived types
69
+ using UInteger = std::make_unsigned<Integer>::type;
70
+ constexpr Integer operator ""_int(unsigned long long int value) {return static_cast<Integer>(value);}
71
+ constexpr UInteger operator ""_uint(unsigned long long int value) {return static_cast<UInteger>(value);}
72
+ constexpr Real operator ""_real(unsigned long long int value) {return static_cast<Real>(value);}
73
+ constexpr Real operator ""_real(long double value) {return static_cast<Real>(value);}
74
+
75
+ // settings which can be overwritten before the include!
76
+ //#define DOUBLE_FALLBACK
77
+ namespace Settings {
78
+ namespace details {
79
+ using RandomEngine = std::mt19937_64;
80
+ constexpr Integer LARGE = 0x3FFF'FFFF'FFFF'FFFF;
81
+ constexpr bool DEFAULT_CASE_LOWER = true;
82
+ constexpr int DEFAULT_PRECISION = 6;
83
+ constexpr Real DEFAULT_EPS = 1e-6_real;
84
+
85
+ [[noreturn]] void exitVerdict(int exitCode) {
86
+ //throw exitCode;
87
+ //quick_exit(exitCode);
88
+ std::exit(exitCode);
89
+ }
90
+ }
91
+ using namespace details;
92
+ }
93
+ // make settings publically available
94
+ using Settings::RandomEngine;
95
+ using Settings::LARGE;
96
+ using Settings::DEFAULT_CASE_LOWER;
97
+ using Settings::DEFAULT_PRECISION;
98
+ using Settings::DEFAULT_EPS;
99
+ using Settings::exitVerdict;
100
+
101
+ // useful constants
102
+ constexpr std::string_view LETTER = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
103
+ constexpr std::string_view UPPER = LETTER.substr(0, 26);
104
+ constexpr std::string_view LOWER = LETTER.substr(26);
105
+ constexpr std::string_view VOWEL = "AEIOUaeiou";
106
+ constexpr std::string_view UPPER_VOWELS = VOWEL.substr(0, 5);
107
+ constexpr std::string_view LOWER_VOWELS = VOWEL.substr(5);
108
+ constexpr std::string_view CONSONANT = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz";
109
+ constexpr std::string_view UPPER_CONSONANT = CONSONANT.substr(0, 26 - 5);
110
+ constexpr std::string_view LOWER_CONSONANT = CONSONANT.substr(26 - 5);
111
+ constexpr std::string_view ALPHA_NUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
112
+ constexpr std::string_view UPPER_ALPHA_NUMERIC = ALPHA_NUMERIC.substr(0, 10 + 26);
113
+ constexpr std::string_view LOWER_ALPHA_NUMERIC = "0123456789abcdefghijklmnopqrstuvwxyz";
114
+ constexpr std::string_view DIGITS = ALPHA_NUMERIC.substr(0, 10);
115
+ constexpr std::string_view BRACKETS = "()[]{}<>";
116
+ constexpr char NEWLINE = '\n';
117
+ constexpr char SPACE = ' ';
118
+ constexpr char NOSEP = '\0';
119
+ constexpr Real PI = 3.1415926535897932384626433832795028_real;
120
+
121
+
122
+ //============================================================================//
123
+ // internal definitions and constants //
124
+ //============================================================================//
125
+ constexpr UInteger DEFAULT_SEED = 3141592653589793238_uint;
126
+ constexpr std::string_view CASE_SENSITIVE = "case_sensitive";
127
+ constexpr std::string_view SPACE_SENSITIVE = "space_change_sensitive";
128
+ constexpr std::string_view FLOAT_ABSOLUTE_TOLERANCE = "float_absolute_tolerance";
129
+ constexpr std::string_view FLOAT_RELATIVE_TOLERANCE = "float_relative_tolerance";
130
+ constexpr std::string_view FLOAT_TOLERANCE = "float_tolerance";
131
+ constexpr std::string_view JUDGE_MESSAGE = "null";
132
+ constexpr char DEFAULT_SEPARATOR = SPACE;
133
+ constexpr std::string_view EMPTY_COMMAND = "";
134
+ constexpr std::string_view COMMAND_PREFIX = "--";
135
+ constexpr std::string_view CONSTRAINT_COMMAND = "--constraints_file";
136
+ constexpr std::string_view SEED_COMMAND = "--seed";
137
+ constexpr auto REGEX_OPTIONS = std::regex::nosubs | std::regex::optimize;
138
+ inline const std::regex INTEGER_REGEX("0|-?[1-9][0-9]*", REGEX_OPTIONS);
139
+ inline const std::regex REAL_REGEX("-?(0|([1-9][0-9]*))(\\.[0-9]*)?([eE][+-]?(0|([1-9][0-9]*)))?", REGEX_OPTIONS);
140
+ inline const std::regex STRICT_REAL_REGEX("-?(0|([1-9][0-9]*))\\.?[0-9]*", REGEX_OPTIONS);
141
+
142
+ static_assert(2'000'000'000'000'000'000_int < LARGE / 2, "LARGE too small");
143
+ static_assert(LARGE <= std::numeric_limits<Integer>::max() / 2, "LARGE too big");
144
+
145
+ static_assert(-1 == 0xFFFF'FFFF'FFFF'FFFF_int, "Two's complement for signed numbers is required" );
146
+ static_assert(std::is_convertible_v<Integer, UInteger>, "Incompatible Integer and UInteger types?!");
147
+ static_assert(std::is_convertible_v<UInteger, Integer>, "Incompatible Integer and UInteger types?!");
148
+ static_assert(sizeof(Integer) == sizeof(UInteger), "Incompatible Integer and UInteger types?!");
149
+
150
+ template<typename T = std::logic_error>
151
+ constexpr void judgeAssert(bool asserted, std::string_view message) {
152
+ if (!asserted) throw T(message.data());
153
+ }
154
+
155
+
156
+ //============================================================================//
157
+ // SFINAE //
158
+ //============================================================================//
159
+ namespace details {
160
+ template<typename T, typename = void>
161
+ struct IsContainer : std::false_type {};
162
+
163
+ template<typename T>
164
+ struct IsContainer<T, std::void_t<decltype(std::begin(std::declval<std::add_lvalue_reference_t<T>>()))>> : std::true_type {
165
+ using iterator_type = decltype(std::begin(std::declval<std::add_lvalue_reference_t<T>>()));
166
+ using value_type = std::remove_reference_t<decltype(*std::begin(std::declval<std::add_lvalue_reference_t<T>>()))>;
167
+ };
168
+
169
+ template<typename T>
170
+ struct IsStdArray : std::false_type {};
171
+
172
+ template<typename T, std::size_t N>
173
+ struct IsStdArray<std::array<T, N>> : std::true_type {};
174
+
175
+ template<typename T, typename = void>
176
+ struct IsTupleLike : std::false_type {};
177
+
178
+ template<typename T>
179
+ struct IsTupleLike<T, std::void_t<decltype(sizeof(std::tuple_size<T>))>> : std::true_type {};
180
+
181
+ template<typename T, typename = void>
182
+ struct HasOstreamOperator : std::false_type {};
183
+
184
+ template<typename T>
185
+ struct HasOstreamOperator<T, std::void_t<decltype(std::declval<std::ostream>() << std::declval<T>())>> : std::true_type {};
186
+ }
187
+
188
+
189
+ //============================================================================//
190
+ // Verdicts //
191
+ //============================================================================//
192
+ struct Verdict final {
193
+ int exitCode;
194
+
195
+ constexpr explicit Verdict(int exitCode_ = 1) : exitCode(exitCode_) {}
196
+
197
+ constexpr operator int() const {
198
+ return exitCode;
199
+ }
200
+
201
+ [[noreturn]] void exit() const {
202
+ exitVerdict(exitCode);
203
+ }
204
+
205
+ friend void operator<<(std::ostream& os, const Verdict& v) {
206
+ os << std::endl;
207
+ v.exit();
208
+ }
209
+ };
210
+
211
+ // default verdicts (we do not support scoring)
212
+ constexpr Verdict AC(42);
213
+ constexpr Verdict WA(43);
214
+ constexpr Verdict PE = WA;
215
+ constexpr Verdict FAIL(1);
216
+
217
+
218
+ //============================================================================//
219
+ // Output streams //
220
+ //============================================================================//
221
+ class NullStream final : public std::ostream {
222
+ class NullBuffer final : public std::streambuf {
223
+ protected:
224
+ std::streamsize xsputn(const char* /**/, std::streamsize n) override {
225
+ return n;
226
+ }
227
+ int overflow(int c = std::char_traits<char>::eof()) override {
228
+ return std::char_traits<char>::not_eof(c);
229
+ }
230
+ } nullBuffer;
231
+ public:
232
+ NullStream() : std::ostream(&nullBuffer) {}
233
+ };
234
+
235
+ namespace details {
236
+ NullStream nullStream;
237
+ }
238
+
239
+ class OutputStream final {
240
+ std::unique_ptr<std::ofstream> managed;
241
+ std::ostream* os;
242
+
243
+ void init() {
244
+ *os << std::boolalpha;
245
+ *os << std::fixed;
246
+ *os << std::setprecision(DEFAULT_PRECISION);
247
+ }
248
+
249
+ public:
250
+ OutputStream() : os(&details::nullStream) {}
251
+ OutputStream(std::ostream& os_) : os(&os_) {init();}
252
+ explicit OutputStream(const std::filesystem::path& path) : managed(std::make_unique<std::ofstream>(path)), os(managed.get()) {
253
+ judgeAssert<std::runtime_error>(managed->good(), "OutputStream: Could not open File: " + path.string());
254
+ init();
255
+ }
256
+
257
+ OutputStream(OutputStream&& other) = default;
258
+ OutputStream& operator=(OutputStream&& other) = default;
259
+
260
+ OutputStream(const OutputStream&) = delete;
261
+ OutputStream& operator=(const OutputStream&) = delete;
262
+
263
+
264
+ template<typename L, typename R>
265
+ OutputStream& operator<<(const std::pair<L, R>& t) {
266
+ return *this << t.first << DEFAULT_SEPARATOR << t.second;
267
+ }
268
+
269
+ template<typename... Args>
270
+ OutputStream& operator<<(const std::tuple<Args...>& t) {
271
+ return join(t, std::index_sequence_for<Args...>(), DEFAULT_SEPARATOR);
272
+ }
273
+
274
+ template<typename T>
275
+ OutputStream& operator<<(const T& x) {
276
+ if constexpr ((std::is_array_v<T> and !std::is_same_v<std::decay_t<T>, char*>) or
277
+ (details::IsContainer<T>{} and !details::HasOstreamOperator<T>{})) {
278
+ return join(std::begin(x), std::end(x), DEFAULT_SEPARATOR);
279
+ } else {
280
+ *os << x;
281
+ return *this;
282
+ }
283
+ }
284
+
285
+ OutputStream& operator<<(std::ostream& (*manip)(std::ostream&)) {
286
+ *os << manip;
287
+ return *this;
288
+ }
289
+
290
+ template<typename Tuple, std::size_t... Is>
291
+ OutputStream& join(const Tuple& t, std::index_sequence<Is...> /**/, char separator) {
292
+ static_assert(std::tuple_size_v<Tuple> == sizeof...(Is));
293
+ if (separator != NOSEP) ((*os << (Is == 0 ? std::string_view() : std::string_view(&separator, 1)), *this << std::get<Is>(t)), ...);
294
+ else ((*this << std::get<Is>(t)), ...);
295
+ return *this;
296
+ }
297
+
298
+ template<typename T>
299
+ OutputStream& join(T first, T last, char separator) {
300
+ for (auto it = first; it != last; it++) {
301
+ if (it != first and separator != NOSEP) *os << separator;
302
+ *this << *it;
303
+ }
304
+ return *this;
305
+ }
306
+ };
307
+
308
+ namespace ValidateBase {
309
+ // define this early so everyone can use it!
310
+ OutputStream juryErr(std::cerr);
311
+ OutputStream juryOut(std::cout);
312
+ }
313
+
314
+ // allow printing colletions as:
315
+ // join(begin(), end(), [sep])
316
+ namespace details {
317
+ template<typename C>
318
+ class TempWriter final {
319
+ C callable;
320
+ public:
321
+ constexpr explicit TempWriter(const C& callable_) : callable(callable_) {}
322
+
323
+ TempWriter(const TempWriter&) = delete;
324
+ TempWriter(TempWriter&&) = delete;
325
+ TempWriter& operator=(const TempWriter&) = delete;
326
+ TempWriter& operator=(TempWriter&&) = delete;
327
+
328
+ std::string asString() const {
329
+ std::ostringstream os;
330
+ OutputStream tmp(os);
331
+ tmp << *this;
332
+ return os.str();
333
+ }
334
+
335
+ explicit operator std::string() const {
336
+ return asString();
337
+ }
338
+
339
+ friend OutputStream& operator<<(OutputStream& os, const TempWriter<C>& writer) {
340
+ writer.callable(os);
341
+ return os;
342
+ }
343
+
344
+ friend OutputStream& operator<<(std::ostream& os, const TempWriter<C>& writer) = delete; //news OutputStream
345
+ };
346
+
347
+ struct JoinListCapture {
348
+ std::function<void(OutputStream&, char separator)> callable;
349
+
350
+ template<typename... Args>
351
+ JoinListCapture(Args&&... args)
352
+ : callable([t = std::forward_as_tuple(args...)](OutputStream& os, char separator) {
353
+ os.join(t, std::index_sequence_for<Args...>(), separator);
354
+ }) {}
355
+ };
356
+ }
357
+
358
+ template<typename T>
359
+ constexpr auto join(T first, T last, char separator = DEFAULT_SEPARATOR) {
360
+ return details::TempWriter([=](OutputStream& os) {
361
+ os.join(first, last, separator);
362
+ });
363
+ }
364
+
365
+ template<typename CR,
366
+ typename = std::enable_if_t<details::IsContainer<CR>{}>,
367
+ typename = std::enable_if_t<!details::IsStdArray<std::remove_cv_t<std::remove_reference_t<CR>>>{}>>
368
+ constexpr auto join(CR&& c, char separator = DEFAULT_SEPARATOR) {
369
+ if constexpr(std::is_rvalue_reference_v<CR&&>) {
370
+ if constexpr (std::is_array_v<CR>) {
371
+ return details::TempWriter([c, separator](OutputStream& os) {
372
+ os.join(std::begin(c), std::end(c), separator);
373
+ });
374
+ } else {
375
+ return details::TempWriter([c = std::move(c), separator](OutputStream& os) {
376
+ os.join(std::begin(c), std::end(c), separator);
377
+ });
378
+ }
379
+ } else {
380
+ return join(std::begin(c), std::end(c), separator);
381
+ }
382
+ }
383
+
384
+ template<typename CR, std::size_t N = std::tuple_size<std::decay_t<CR>>::value>
385
+ constexpr auto join(CR&& c, char separator = DEFAULT_SEPARATOR) {
386
+ if constexpr(std::is_rvalue_reference_v<CR&&>) {
387
+ return details::TempWriter([c = std::move(c), separator](OutputStream& os) {
388
+ os.join(c, std::make_index_sequence<N>{}, separator);
389
+ });
390
+ } else {
391
+ return details::TempWriter([&c, separator](OutputStream& os) {
392
+ os.join(c, std::make_index_sequence<N>{}, separator);
393
+ });
394
+ }
395
+ }
396
+
397
+ template<typename T, std::size_t N,
398
+ typename = std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, char>>>
399
+ constexpr auto join(T (&c)[N], char separator = DEFAULT_SEPARATOR) {
400
+ static_assert(N > 0, "c-strings should be null terminated!");
401
+ return join(std::begin(c), std::prev(std::end(c)), separator);
402
+ }
403
+
404
+ template<typename T, std::size_t N,
405
+ typename = std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, char>>>
406
+ constexpr auto join(T (&&c)[N], char separator = DEFAULT_SEPARATOR) {
407
+ static_assert(N > 0, "c-strings should be null terminated!");
408
+ return details::TempWriter([c, separator](OutputStream& os) {
409
+ os.join(std::begin(c), std::prev(std::end(c)), separator);
410
+ });
411
+ }
412
+
413
+ template<typename T,
414
+ typename = std::enable_if_t<!std::is_array<T>{}>,
415
+ typename = std::enable_if_t<!details::IsContainer<T>{}>,
416
+ typename = std::enable_if_t<!details::IsTupleLike<T>{}>>
417
+ constexpr auto join(const T& t, char separator = DEFAULT_SEPARATOR) = delete;
418
+
419
+ auto join(details::JoinListCapture c, char separator = DEFAULT_SEPARATOR) {
420
+ return details::TempWriter([c = std::move(c), separator](OutputStream& os) {
421
+ c.callable(os, separator);
422
+ });
423
+ }
424
+
425
+
426
+ //============================================================================//
427
+ // Basic datastructures //
428
+ //============================================================================//
429
+ // make usage of std::priority_queue easier...
430
+ namespace details {
431
+ template<typename T, typename Compare = std::less<T>>
432
+ struct invertCompare {
433
+ constexpr bool operator()(const T &lhs, const T &rhs) const {
434
+ return Compare{}(rhs, lhs);
435
+ }
436
+ };
437
+ }
438
+ template<typename T, typename Compare = std::less<T>>
439
+ using MinPQ = std::priority_queue<T, std::vector<T>, details::invertCompare<T, Compare>>;
440
+ template<typename T, typename Compare = std::less<T>>
441
+ using MaxPQ = std::priority_queue<T, std::vector<T>, Compare>;
442
+
443
+ template<typename C, typename K>
444
+ bool contains(const C& container, const K& key) {
445
+ return container.find(key) != container.end();
446
+ }
447
+
448
+ template<typename C1, typename C2>
449
+ void append(C1& c1, const C2& c2) {
450
+ static_assert(std::is_same_v<typename details::IsContainer<C1>::value_type,
451
+ typename details::IsContainer<C2>::value_type>, "cannot append container of different value type!");
452
+ if (static_cast<const void*>(&c1) != static_cast<const void*>(&c2)) {
453
+ for (auto&& e : c2) c1.emplace(c1.end(), e);
454
+ } else {
455
+ C2 tmp = c2;
456
+ for (auto&& e : tmp) c1.emplace(c1.end(), e);
457
+ }
458
+ }
459
+
460
+ template<typename C1, std::size_t N>
461
+ void append(C1& c1, const typename C1::value_type(&c2)[N]) {
462
+ for (auto&& e : c2) c1.emplace(c1.end(), e);
463
+ }
464
+
465
+ struct shorter {
466
+ template<typename U, typename V>
467
+ bool operator()(const U& a, const V& b) const {
468
+ return std::size(a) < std::size(b);
469
+ }
470
+ };
471
+
472
+ struct longer {
473
+ template<typename U, typename V>
474
+ bool operator()(const U& a, const V& b) const {
475
+ return std::size(b) < std::size(a);
476
+ }
477
+ };
478
+
479
+ namespace details {
480
+ template<typename T, typename = void>
481
+ struct Flatten {using value_type = T;};
482
+
483
+ template<typename T>
484
+ struct Flatten<T, std::enable_if_t<IsContainer<T>{}>> : Flatten<typename IsContainer<T>::value_type> {};
485
+
486
+ template<typename CR, typename V>
487
+ void flatAppend(CR&& c, std::vector<V>& res) {
488
+ using C = std::remove_reference_t<CR>;
489
+ if constexpr(std::is_same_v<C, V>) {
490
+ res.emplace_back(std::forward<CR>(c));
491
+ } else if constexpr (!IsContainer<C>{}) {
492
+ static_assert(IsContainer<C>{}, "invalid base type for flatten()!");
493
+ } else {
494
+ if constexpr (std::is_rvalue_reference_v<CR&&>) {
495
+ for (auto&& v : c) flatAppend(std::move(v), res);
496
+ } else {
497
+ for (auto&& v : c) flatAppend(v, res);
498
+ }
499
+ }
500
+ }
501
+ }
502
+
503
+ template<typename R, typename CR>
504
+ auto flatten(CR&& c) {
505
+ std::vector<R> res;
506
+ details::flatAppend(std::forward<CR>(c), res);
507
+ return res;
508
+ }
509
+
510
+ template<typename CR>
511
+ auto flatten(CR&& c) {
512
+ using C = std::remove_reference_t<CR>;
513
+ return flatten<typename details::Flatten<C>::value_type, CR>(std::forward<CR>(c));
514
+ }
515
+
516
+ template<typename T>
517
+ struct boolean {
518
+ bool value;
519
+ std::optional<T> reason;
520
+
521
+ constexpr boolean(bool value_) : value(value_) {}
522
+ constexpr boolean(bool value_, const T& reason_) : value(value_), reason(reason_) {}
523
+
524
+ constexpr operator bool() const {
525
+ return value;
526
+ }
527
+
528
+ constexpr bool hasReason() const {
529
+ return reason.has_value();
530
+ }
531
+ };
532
+
533
+
534
+ //============================================================================//
535
+ // Utility //
536
+ //============================================================================//
537
+ // for sequences
538
+ template<typename RandomIt,
539
+ typename = std::enable_if_t<std::is_integral_v<typename std::iterator_traits<RandomIt>::value_type>>>
540
+ auto isPerm(RandomIt first, RandomIt last, typename std::iterator_traits<RandomIt>::value_type offset = 0) {
541
+ using T = typename std::iterator_traits<RandomIt>::value_type;
542
+ auto count = std::distance(first, last);
543
+ std::vector<bool> seen(count, false);
544
+ for (; first != last; first++) {
545
+ const T& x = *first;
546
+ if (x < offset or x - offset >= count or seen[x - offset]) {
547
+ return boolean<T>(false, x);
548
+ }
549
+ seen[x - offset] = true;
550
+ }
551
+ return boolean<T>(true);
552
+ }
553
+ template<typename C, typename std::enable_if_t<std::is_integral_v<typename details::IsContainer<C>::value_type>, bool> = true>
554
+ auto isPerm(const C& c, typename details::IsContainer<C>::value_type offset = 0) {
555
+ return isPerm(std::begin(c), std::end(c), offset);
556
+ }
557
+
558
+ template<typename itA, typename itB>
559
+ auto isPerm(itA firstA, itA lastA, itB firstB, itB lastB) {
560
+ using T = typename std::iterator_traits<itA>::value_type;
561
+ std::vector<typename std::iterator_traits<itA>::value_type> a(firstA, lastA);
562
+ std::vector<typename std::iterator_traits<itB>::value_type> b(firstB, lastB);
563
+ if (a.size() != b.size()) return boolean<T>(false);
564
+ std::sort(a.begin(), a.end());
565
+ std::sort(b.begin(), b.end());
566
+ for (std::size_t i = 0; i < a.size(); i++) {
567
+ if (a[i] != b[i]) return boolean<T>(false, a[i]);
568
+ }
569
+ return boolean<T>(true);
570
+ }
571
+ template<typename C1,
572
+ typename C2,
573
+ typename = std::enable_if_t<details::IsContainer<C1>{}>,
574
+ typename = std::enable_if_t<details::IsContainer<C2>{}>>
575
+ auto isPerm(const C1& c1, const C2& c2) {
576
+ return isPerm(std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
577
+ }
578
+
579
+ template<typename RandomIt, typename BinaryPredicate>
580
+ constexpr boolean<Integer> anyAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) {
581
+ if (first != last) {
582
+ for (Integer i = 1; std::next(first) != last; first++, i++) {
583
+ if (p(*first, *std::next(first))) {
584
+ return boolean<Integer>(true, i);
585
+ }
586
+ }
587
+ }
588
+ return boolean<Integer>(false);
589
+ }
590
+ template<typename C, typename BinaryPredicate>
591
+ constexpr boolean<Integer> anyAdjacent(const C& c, BinaryPredicate p) {
592
+ return anyAdjacent(std::begin(c), std::end(c), p);
593
+ }
594
+
595
+ template<typename RandomIt, typename BinaryPredicate>
596
+ constexpr boolean<Integer> noneAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) {
597
+ auto res = anyAdjacent(first, last, p);
598
+ res.value = !res.value;
599
+ return res;
600
+ }
601
+ template<typename C, typename BinaryPredicate>
602
+ constexpr boolean<Integer> noneAdjacent(const C& c, BinaryPredicate p) {
603
+ return noneAdjacent(std::begin(c), std::end(c), p);
604
+ }
605
+
606
+ template<typename RandomIt, typename BinaryPredicate>
607
+ constexpr boolean<Integer> allAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) {
608
+ return noneAdjacent(first, last, std::not_fn(p));
609
+ }
610
+ template<typename C, typename BinaryPredicate>
611
+ constexpr boolean<Integer> allAdjacent(const C& c, BinaryPredicate p) {
612
+ return noneAdjacent(std::begin(c), std::end(c), p);
613
+ }
614
+
615
+ template<typename RandomIt>
616
+ constexpr boolean<Integer> areIncreasing(RandomIt first, RandomIt last) {
617
+ using T = typename std::iterator_traits<RandomIt>::value_type;
618
+ return allAdjacent(first, last, std::less<T>());
619
+ }
620
+ template<typename C>
621
+ constexpr boolean<Integer> areIncreasing(const C& c) {
622
+ return areIncreasing(std::begin(c), std::end(c));
623
+ }
624
+
625
+ template<typename RandomIt>
626
+ constexpr boolean<Integer> areNonDecreasing(RandomIt first, RandomIt last) {
627
+ using T = typename std::iterator_traits<RandomIt>::value_type;
628
+ return allAdjacent(first, last, std::less_equal<T>());
629
+ }
630
+ template<typename C>
631
+ constexpr boolean<Integer> areNonDecreasing(const C& c) {
632
+ return areNonDecreasing(std::begin(c), std::end(c));
633
+ }
634
+
635
+ template<typename RandomIt>
636
+ constexpr boolean<Integer> areDecreasing(RandomIt first, RandomIt last) {
637
+ using T = typename std::iterator_traits<RandomIt>::value_type;
638
+ return allAdjacent(first, last, std::greater<T>());
639
+ }
640
+ template<typename C>
641
+ constexpr boolean<Integer> areDecreasing(const C& c) {
642
+ return areDecreasing(std::begin(c), std::end(c));
643
+ }
644
+
645
+ template<typename RandomIt>
646
+ constexpr boolean<Integer> areNonIncreasing(RandomIt first, RandomIt last) {
647
+ using T = typename std::iterator_traits<RandomIt>::value_type;
648
+ return allAdjacent(first, last, std::greater_equal<T>());
649
+ }
650
+ template<typename C>
651
+ constexpr boolean<Integer> areNonIncreasing(const C& c) {
652
+ return areNonIncreasing(std::begin(c), std::end(c));
653
+ }
654
+
655
+ template<typename RandomIt>
656
+ constexpr auto areDistinct(RandomIt first, RandomIt last) {
657
+ using T = typename std::iterator_traits<RandomIt>::value_type;
658
+ std::vector<T> tmp(first, last);
659
+ std::sort(tmp.begin(), tmp.end());
660
+ auto [b, v] = anyAdjacent(tmp, std::equal_to<T>());
661
+ if (v) return boolean<T>(!b, tmp[*v]);
662
+ return boolean<T>(!b);
663
+ }
664
+ template<typename C>
665
+ constexpr auto areDistinct(const C& c) {
666
+ return areDistinct(std::begin(c), std::end(c));
667
+ }
668
+
669
+
670
+ // for strings (cctype functions are not safe to use with char...)
671
+ constexpr bool isLower(char c) {
672
+ return c >= 'a' and c <= 'z';
673
+ }
674
+
675
+ constexpr bool isUpper(char c) {
676
+ return c >= 'A' and c <= 'Z';
677
+ }
678
+
679
+ constexpr bool isLetter(char c) {
680
+ return isLower(c) or isUpper(c);
681
+ }
682
+
683
+ constexpr bool isDigit(char c) {
684
+ return c >= '0' and c <= '9';
685
+ }
686
+
687
+ constexpr char toLower(char c) {
688
+ if (isUpper(c)) c += 'a' - 'A';
689
+ return c;
690
+ }
691
+
692
+ constexpr bool isVowel(char c) {
693
+ c = toLower(c);
694
+ for (char x : LOWER_VOWELS) {
695
+ if (c == x) return true;
696
+ }
697
+ return false;
698
+ }
699
+
700
+ constexpr bool isConsonant(char c) {
701
+ return isLetter(c) and !isVowel(c);
702
+ }
703
+
704
+ constexpr char toUpper(char c) {
705
+ if (isLower(c)) c -= 'a' - 'A';
706
+ return c;
707
+ }
708
+
709
+ constexpr char toDefaultCase(char c) {
710
+ if constexpr (DEFAULT_CASE_LOWER) return toLower(c);
711
+ return toUpper(c);
712
+ }
713
+
714
+ void toLower(std::string& s) {
715
+ for (char& c : s) c = toLower(c);
716
+ }
717
+
718
+ void toUpper(std::string& s) {
719
+ for (char& c : s) c = toUpper(c);
720
+ }
721
+
722
+ void toDefaultCase(std::string& s) {
723
+ if constexpr (DEFAULT_CASE_LOWER) return toLower(s);
724
+ return toUpper(s);
725
+ }
726
+
727
+ constexpr bool isLower(std::string_view s) {
728
+ for (char c : s) if (!isLower(c)) return false;
729
+ return true;
730
+ }
731
+
732
+ constexpr boolean<char> isUpper(std::string_view s) {
733
+ for (char c : s) if (!isUpper(c)) return boolean<char>(false, c);
734
+ return boolean<char>(true);
735
+ }
736
+
737
+ constexpr boolean<char> isLetter(std::string_view s) {
738
+ for (char c : s) if (!isLetter(c)) return boolean<char>(false, c);
739
+ return boolean<char>(true);
740
+ }
741
+
742
+ constexpr boolean<char> isDigit(std::string_view s) {
743
+ for (char c : s) if (!isDigit(c)) return boolean<char>(false, c);
744
+ return boolean<char>(true);
745
+ }
746
+
747
+ constexpr boolean<char> isVowel(std::string_view s) {
748
+ for (char c : s) if (!isVowel(c)) return boolean<char>(false, c);
749
+ return boolean<char>(true);
750
+ }
751
+
752
+ constexpr boolean<char> isConsonant(std::string_view s) {
753
+ for (char c : s) if (!isConsonant(c)) return boolean<char>(false, c);
754
+ return boolean<char>(true);
755
+ }
756
+
757
+ std::vector<Integer> thueMorse(Integer lower, Integer upper) {
758
+ judgeAssert<std::invalid_argument>(lower < upper, "thueMorse(): Lower must be less than upper!");
759
+ std::vector<Integer> res(upper - lower);
760
+ for (Integer i = lower; i < upper; i++) {
761
+ res[i] = std::bitset<64>(i).count() % 2;
762
+ }
763
+ return res;
764
+ }
765
+
766
+ std::vector<Integer> thueMorse(Integer upper) {
767
+ return thueMorse(0, upper);
768
+ }
769
+
770
+ // allow using std::pair and std::complex similiar
771
+ // (may be useful for geometric problem)
772
+ template<typename T>
773
+ constexpr auto& getX(T& point) {
774
+ return std::get<0>(point);
775
+ }
776
+ template<typename T>
777
+ constexpr auto& getY(T& point) {
778
+ return std::get<1>(point);
779
+ }
780
+ template<typename T>
781
+ constexpr auto& getZ(T& point) {
782
+ return std::get<2>(point);
783
+ }
784
+ template<typename T>
785
+ constexpr auto getX(const T& point) {
786
+ return std::get<0>(point);
787
+ }
788
+ template<typename T>
789
+ constexpr auto getY(const T& point) {
790
+ return std::get<1>(point);
791
+ }
792
+ template<typename T>
793
+ constexpr auto getZ(const T& point) {
794
+ return std::get<2>(point);
795
+ }
796
+
797
+ template<typename T>
798
+ constexpr auto& getX(std::complex<T>& point) {
799
+ return reinterpret_cast<T(&)[2]>(point)[0];
800
+ }
801
+ template<typename T>
802
+ constexpr auto& getY(std::complex<T>& point) {
803
+ return reinterpret_cast<T(&)[2]>(point)[1];
804
+ }
805
+ template<typename T>
806
+ constexpr auto getX(const std::complex<T>& point) {
807
+ return reinterpret_cast<const T(&)[2]>(point)[0];
808
+ }
809
+ template<typename T>
810
+ constexpr auto getY(const std::complex<T>& point) {
811
+ return reinterpret_cast<const T(&)[2]>(point)[1];
812
+ }
813
+
814
+ template<typename T>
815
+ constexpr std::pair<T,T> convert(const std::complex<T>& t) {
816
+ return {getX(t), getY(t)};
817
+ }
818
+
819
+ template<typename L, typename R>
820
+ constexpr std::complex<typename std::common_type<L, R>::type>
821
+ convert(const std::pair<L,R>& t) {
822
+ return {getX(t), getY(t)};
823
+ }
824
+
825
+
826
+ namespace details {
827
+ // Test two numbers for equality, accounting for +/-INF, NaN and precision.
828
+ // Real expected is considered the reference value for relative error.
829
+ bool floatEqual(Real given, Real expected, Real floatAbsTol, Real floatRelTol) {
830
+ judgeAssert<std::domain_error>(floatAbsTol >= 0.0_real, "floatEqual(): floatAbsTol must be positive!");
831
+ judgeAssert<std::domain_error>(floatRelTol >= 0.0_real, "floatEqual(): floatRelTol must be positive!");
832
+ // Finite values are compared with some tolerance
833
+ if (std::isfinite(given) and std::isfinite(expected)) {
834
+ Real absDiff = std::abs(given-expected);
835
+ Real relDiff = std::abs((given-expected)/expected);
836
+ return absDiff <= floatAbsTol or relDiff <= floatRelTol;
837
+ }
838
+ // NaN is equal to NaN (-NaN is also equal NaN)
839
+ if (std::isnan(given) and std::isnan(expected)) {
840
+ return true;
841
+ }
842
+ // Infinite values are equal if their sign matches
843
+ if (std::isinf(given) and std::isinf(expected)) {
844
+ return std::signbit(given) == std::signbit(expected);
845
+ }
846
+ // Values in different classes are always different.
847
+ return false;
848
+ }
849
+
850
+ constexpr boolean<std::size_t> stringEqual(std::string_view a, std::string_view b, bool caseSensitive) {
851
+ std::size_t i = 0;
852
+ for (; i < a.size() and i < b.size(); i++) {
853
+ char aa = a[i];
854
+ char bb = b[i];
855
+ if (!caseSensitive) {
856
+ aa = toDefaultCase(aa);
857
+ bb = toDefaultCase(bb);
858
+ }
859
+ if (aa != bb) {
860
+ return boolean<std::size_t>(false, i);
861
+ }
862
+ }
863
+ if (a.size() != b.size()) {
864
+ return boolean<std::size_t>(false, i);
865
+ } else {
866
+ return boolean<std::size_t>(true);
867
+ }
868
+ }
869
+
870
+ constexpr bool isToken(std::string_view a) {
871
+ for (char c : a) {
872
+ if (c == ' ') return false;
873
+ if (c == '\n') return false;
874
+ if (c == '\r') return false;
875
+ if (c == '\t') return false;
876
+ if (c == '\f') return false;
877
+ if (c == '\v') return false;
878
+ }
879
+ return true;
880
+ }
881
+
882
+ template<typename T>
883
+ bool parse(std::string_view s, T& res) {
884
+ const char* begin = s.data();
885
+ const char* end = s.data() + s.size();
886
+ auto [ptr, ec] = std::from_chars(begin, end, res);
887
+ return ptr == end and ec == std::errc();
888
+ }
889
+ #ifdef DOUBLE_FALLBACK
890
+ template<>
891
+ bool parse(std::string_view s, Real& res) {
892
+ try {
893
+ std::size_t pos = 0;
894
+ res = std::stold(std::string(s), &pos);
895
+ return pos == s.size();
896
+ } catch(...) {
897
+ return false;
898
+ }
899
+ }
900
+ #endif
901
+
902
+ }
903
+
904
+
905
+ //============================================================================//
906
+ // Math //
907
+ //============================================================================//
908
+ namespace details {
909
+ constexpr std::array<Integer, 32> TRIAL_PRIMES = {
910
+ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
911
+ 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131,
912
+ };
913
+ constexpr std::array<UInteger, 7> MILLER_RABIN_WITNESS = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
914
+
915
+ // these operations are safe as long as the value would fit in Integer
916
+ constexpr UInteger mulMod(UInteger lhs, UInteger rhs, UInteger mod) {
917
+ UInteger res = 0;
918
+ while (rhs > 0) {
919
+ if (rhs & 1) res = (lhs + res) % mod;
920
+ lhs = (lhs + lhs) % mod;
921
+ rhs /= 2;
922
+ }
923
+ return res;
924
+ }
925
+
926
+ constexpr UInteger powMod(UInteger base, UInteger exp, UInteger mod) {
927
+ UInteger res = 1;
928
+ if (mod <= 0x1'0000'0000) {
929
+ while (exp > 0) {
930
+ if (exp & 1) res = (base * res) % mod;
931
+ base = (base * base) % mod;
932
+ exp /= 2;
933
+ }
934
+ } else {
935
+ while (exp > 0) {
936
+ if (exp & 1) res = mulMod(base, res, mod);
937
+ base = mulMod(base, base, mod);
938
+ exp /= 2;
939
+ }
940
+ }
941
+ return res;
942
+ }
943
+
944
+ constexpr Integer extendedEuclid(Integer a, Integer b, Integer& x, Integer& y) {
945
+ if (a == 0) {
946
+ x = 0;
947
+ y = 1;
948
+ return b;
949
+ } else {
950
+ Integer x1 = 0;
951
+ Integer y1 = 0;
952
+ Integer d = extendedEuclid(b % a, a, x1, y1);
953
+ x = y1 - (b / a) * x1;
954
+ y = x1;
955
+ return d;
956
+ }
957
+ }
958
+ }
959
+
960
+ constexpr Integer applyMod(Integer x, Integer mod) {
961
+ x %= mod;
962
+ if (x < 0) x += mod;
963
+ return x;
964
+ }
965
+
966
+ constexpr Integer mulMod(Integer lhs, Integer rhs, Integer mod) {
967
+ judgeAssert<std::domain_error>(mod > 0, "mulMod(): mod must be positive!");
968
+ UInteger ul = static_cast<UInteger>(applyMod(lhs, mod));
969
+ UInteger ur = static_cast<UInteger>(applyMod(rhs, mod));
970
+ UInteger um = static_cast<UInteger>(mod);
971
+ return static_cast<Integer>(details::mulMod(ul, ur, um));
972
+ }
973
+
974
+ constexpr Integer powMod(Integer base, Integer exp, Integer mod) {
975
+ judgeAssert<std::domain_error>(mod > 0, "powMod(): mod must be positive!");
976
+ judgeAssert<std::domain_error>(exp >= 0, "powMod(): exp must be non negative!");
977
+ UInteger ub = static_cast<UInteger>(applyMod(base, mod));
978
+ UInteger ue = static_cast<UInteger>(exp);
979
+ UInteger um = static_cast<UInteger>(mod);
980
+ return static_cast<Integer>(details::powMod(ub, ue, um));
981
+ }
982
+
983
+ constexpr Integer multInv(Integer n, Integer mod) {
984
+ judgeAssert<std::domain_error>(mod > 0, "multInv(): mod must be positive!");
985
+ Integer x = 0;
986
+ Integer y = 0;
987
+ Integer g = details::extendedEuclid(n, mod, x, y);
988
+ if (g != 1) return -1;
989
+ else return applyMod(x, mod);
990
+ }
991
+
992
+ constexpr bool isPrime(Integer n) {
993
+ for (Integer p : details::TRIAL_PRIMES) {
994
+ if (n <= p or n % p == 0) {
995
+ return n == p;
996
+ }
997
+ }
998
+ if (details::powMod(details::TRIAL_PRIMES.back() + 1, n - 1, n) != 1) {
999
+ return false;
1000
+ }
1001
+ UInteger un = static_cast<UInteger>(n);
1002
+ UInteger d = un - 1;
1003
+ UInteger j = 0;
1004
+ while (d % 2 == 0) {
1005
+ d /= 2;
1006
+ j++;
1007
+ }
1008
+ for (UInteger a : details::MILLER_RABIN_WITNESS) {
1009
+ if (a % un == 0) continue;
1010
+ UInteger v = details::powMod(a, d, un);
1011
+ if (v == 1 or v == un - 1) continue;
1012
+ for (UInteger i = 1; i < j; i++) {
1013
+ v = details::mulMod(v, v, un);
1014
+ if (v == un - 1 or v <= 1) break;
1015
+ }
1016
+ if (v != un - 1) return false;
1017
+ }
1018
+ return true;
1019
+ }
1020
+
1021
+ std::vector<Integer> primes(Integer lower, Integer upper) {
1022
+ judgeAssert<std::invalid_argument>(lower < upper, "primes(): Lower must be less than upper!");
1023
+ lower = std::max<Integer>(2, lower);
1024
+ upper = std::max<Integer>(2, upper);
1025
+ Integer count = upper - lower;
1026
+ Integer cache = (count + 1) / 2;
1027
+
1028
+ std::vector<bool> notPrime(cache), notPrimeSegment(cache);
1029
+ for (Integer i = 3; i < count; i += 2) {
1030
+ if (!notPrime[i / 2]) {
1031
+ for (Integer j = i * i; j < count; j += 2 * i) {
1032
+ notPrime[j / 2] = true;
1033
+ }
1034
+ Integer lowest = lower - (lower % (2*i)) + i;
1035
+ if (lowest < lower) lowest += 2*i;
1036
+ for (Integer j = std::max(i * i, lowest); j < upper; j += 2 * i) {
1037
+ notPrimeSegment[(j - lower) / 2] = true;
1038
+ }
1039
+ }
1040
+ }
1041
+ std::vector<Integer> res;
1042
+ if (lower <= 2 and 2 < upper) res.emplace_back(2);
1043
+ for (Integer i = lower | 1; i < upper; i += 2) {
1044
+ if (!notPrimeSegment[(i - lower) / 2] and (i < count*count or isPrime(i))) {
1045
+ res.emplace_back(i);
1046
+ }
1047
+ }
1048
+ return res;
1049
+ }
1050
+
1051
+ std::vector<Integer> primes(Integer upper) {
1052
+ return primes(0, upper);
1053
+ }
1054
+
1055
+ template<typename T>
1056
+ constexpr Integer sign(T x) {
1057
+ return (T(0) < x) - (x < T(0));
1058
+ }
1059
+
1060
+
1061
+ //============================================================================//
1062
+ // Geometry (this is just for utility stuff...) //
1063
+ //============================================================================//
1064
+ namespace details {
1065
+ template<typename Point>
1066
+ constexpr Integer cross(Point a, Point b) {
1067
+ return getX(a) * getY(b) - getY(a) * getX(b);
1068
+ }
1069
+ template<typename Point>
1070
+ constexpr Integer cross(Point p, Point a, Point b) {
1071
+ getX(a) -= getX(p);
1072
+ getY(a) -= getY(p);
1073
+ getX(b) -= getX(p);
1074
+ getY(b) -= getY(p);
1075
+ return cross(a, b);
1076
+ }
1077
+
1078
+ template<typename Point>
1079
+ constexpr bool left(Point p) {
1080
+ return getX(p) == 0 ? getY(p) < 0 : getX(p) < 0;
1081
+ }
1082
+
1083
+ template<typename Point>
1084
+ void cyclicSort(std::vector<Point>& in) {
1085
+ std::sort(in.begin(), in.end(), [](const Point& a, const Point& b){
1086
+ return left(a) != left(b) ? left(a) > left(b) : cross(a, b) > 0;
1087
+ });
1088
+ }
1089
+ }
1090
+
1091
+
1092
+ template<typename RandomIt>
1093
+ constexpr bool areConvex(RandomIt first, RandomIt last) {
1094
+ std::size_t n = 0;
1095
+ for (auto it = first; it != last; it++) {
1096
+ n++;
1097
+ judgeAssert(std::abs(getX(*it)) <= 0x3FFF'FFFF, "areConvex(): coordinates too large!");
1098
+ judgeAssert(std::abs(getY(*it)) <= 0x3FFF'FFFF, "areConvex(): coordinates too large!");
1099
+ }
1100
+ if (n < 3) return false;
1101
+ bool hasArea = false;
1102
+ for (std::size_t i = 0; i < n; i++) {
1103
+ if (first[i] == first[(i+1) % n]) return false;
1104
+ if (details::cross(first[0], first[i], first[(i+1) % n]) < 0) return false;
1105
+ if (details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) < 0) return false;
1106
+ hasArea |= details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) != 0;
1107
+ }
1108
+ return hasArea;
1109
+ }
1110
+ template<typename C>
1111
+ constexpr bool areConvex(const C& c) {
1112
+ return areConvex(std::begin(c), std::end(c));
1113
+ }
1114
+
1115
+ template<typename RandomIt>
1116
+ constexpr bool areStrictlyConvex(RandomIt first, RandomIt last) {
1117
+ if (!areConvex(first, last)) return false;
1118
+ std::size_t n = std::distance(first, last);
1119
+ for (std::size_t i = 0; i < n; i++) {
1120
+ if (details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) == 0) return false;
1121
+ }
1122
+ return true;
1123
+ }
1124
+ template<typename C>
1125
+ constexpr bool areStrictlyConvex(const C& c) {
1126
+ return areStrictlyConvex(std::begin(c), std::end(c));
1127
+ }
1128
+
1129
+ //============================================================================//
1130
+ // Random //
1131
+ //============================================================================//
1132
+ namespace Random {
1133
+ // You should not rely on the implementation in details!
1134
+ // Especially you should never use randomNumberGenerator on your own. There is no function in
1135
+ // c++ which uses a random engine and is not implementation defined.
1136
+ namespace details {
1137
+ constexpr Real PI = 3.141592653589793238462643383279502884_real;
1138
+ constexpr Integer PRIME_TRIALS = 4*1600;
1139
+
1140
+ RandomEngine randomNumberGenerator(DEFAULT_SEED);
1141
+ static_assert(RandomEngine::max() == 0xFFFF'FFFF'FFFF'FFFF_uint, "Random Engine should produce 64bit of randomness");
1142
+ static_assert(RandomEngine::min() == 0_uint, "Random Engine should produce 64bit of randomness");
1143
+
1144
+ constexpr UInteger bitMask(UInteger x) {
1145
+ static_assert(sizeof(UInteger) == 8, "bitMask requires 8byte UInteger!");
1146
+ x |= x >> 1;
1147
+ x |= x >> 2;
1148
+ x |= x >> 4;
1149
+ x |= x >> 8;
1150
+ x |= x >> 16;
1151
+ x |= x >> 32;
1152
+ return x;
1153
+ }
1154
+ }
1155
+
1156
+ void seed(UInteger seed) {
1157
+ details::randomNumberGenerator.seed(seed);
1158
+ }
1159
+
1160
+ //========================================================================//
1161
+ // Distributions and generators //
1162
+ //========================================================================//
1163
+ bool bit() {// in {0, 1}
1164
+ return std::bitset<64>(details::randomNumberGenerator()).count() & 1;
1165
+ }
1166
+
1167
+ Integer integer() {// in [-2^63, 2^63)
1168
+ return static_cast<Integer>(details::randomNumberGenerator());
1169
+ }
1170
+ Integer integer(Integer lower, Integer upper) {// in [lower, upper)
1171
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::integer(): Lower must be less than upper!");
1172
+ UInteger ul = static_cast<UInteger>(lower);
1173
+ UInteger uu = static_cast<UInteger>(upper);
1174
+ UInteger mask = details::bitMask(uu - ul - 1_uint);
1175
+ UInteger res;
1176
+ do {
1177
+ res = details::randomNumberGenerator() & mask;
1178
+ } while (res >= uu - ul);
1179
+ return static_cast<Integer>(res + ul);
1180
+ }
1181
+ Integer integer(Integer upper) {// in [0, upper)
1182
+ return integer(0, upper);
1183
+ }
1184
+
1185
+ Real real() {// in [0, 1)
1186
+ while (true) {
1187
+ Real res = details::randomNumberGenerator() / 0x1.0p64_real;
1188
+ res += details::randomNumberGenerator() / 0x1.0p128_real;
1189
+ if (0.0_real <= res and res < 1.0_real) return res;
1190
+ }
1191
+ }
1192
+ Real real(Real upper) {// in [0, upper)
1193
+ judgeAssert<std::domain_error>(std::isfinite(upper), "Random::real(): Upper must be finite!");
1194
+ judgeAssert<std::invalid_argument>(upper > 0.0_real, "Random::real(): Upper must be greater than zero!");
1195
+ while (true) {
1196
+ Real res = real() * upper;
1197
+ if (0.0_real <= res and res < upper) return res;
1198
+ }
1199
+ }
1200
+ Real real(Real lower, Real upper) {// in [lower, upper)
1201
+ judgeAssert<std::domain_error>(std::isfinite(lower), "Random::real(): Lower must be finite!");
1202
+ judgeAssert<std::domain_error>(std::isfinite(upper), "Random::real(): Upper must be finite!");
1203
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::real(): Lower must be less than upper!");
1204
+ while (true) {
1205
+ Real x = real();
1206
+ Real res = lower * (1.0_real - x) + upper * x;
1207
+ if (lower <= res and res < upper) return res;
1208
+ }
1209
+ }
1210
+
1211
+ Real normal(Real mean, Real stddev) {// theoretically in (-inf, inf)
1212
+ judgeAssert<std::domain_error>(stddev >= 0.0_real, "Random::normal(): Standard deviation must be non negative!");
1213
+ Real u1 = real();
1214
+ Real u2 = real();
1215
+ Real res = std::sqrt(-2.0_real * std::log(u1)) * std::cos(2.0_real * details::PI * u2);
1216
+ return std::sqrt(stddev) * res + mean;
1217
+ }
1218
+ Real normal(Real lower, Real upper, Real mean, Real stddev) {// in [lower, upper)
1219
+ judgeAssert<std::domain_error>(!std::isnan(lower), "Random::normal(): Lower must not be NaN!");
1220
+ judgeAssert<std::domain_error>(!std::isnan(upper), "Random::normal(): Upper must not be NaN!");
1221
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::normal(): Lower must be less than upper!");
1222
+ judgeAssert<std::domain_error>(stddev >= 0.0_real, "Random::normal(): Standard deviation must be non negative!");
1223
+ Real res;
1224
+ while (true) {
1225
+ Real u1 = real();
1226
+ Real u2 = real();
1227
+ // Box-Muller-Methode
1228
+ // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
1229
+ res = std::sqrt(-2.0_real * std::log(u1)) * std::cos(2.0_real * details::PI * u2);
1230
+ res = std::sqrt(stddev) * res + mean;
1231
+ if (lower <= res and res < upper) return res;
1232
+ res = std::sqrt(-2.0_real * std::log(u1)) * std::sin(2.0_real * details::PI * u2);
1233
+ res = std::sqrt(stddev) * res + mean;
1234
+ if (lower <= res and res < upper) return res;
1235
+ }
1236
+ }
1237
+
1238
+ Real exponential(Real lambda) {// theoretically in [0, inf)
1239
+ judgeAssert<std::domain_error>(lambda > 0.0_real, "Random::lambda(): lambda must be positive!");
1240
+ return -std::log(real()) / lambda;
1241
+ }
1242
+ Real exponential(Real lower, Real upper, Real lambda) {// in [lower, upper)
1243
+ judgeAssert<std::domain_error>(std::isfinite(lower), "Random::exponential(): Lower must be finite!");
1244
+ judgeAssert<std::domain_error>(!std::isnan(upper), "Random::exponential(): Upper must not be NaN!");
1245
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::exponential(): Lower must be less than upper!");
1246
+ judgeAssert<std::domain_error>(lambda > 0.0_real, "Random::exponential(): Lambda must be positive!");
1247
+ while (true) {
1248
+ Real res = lower - std::log(real()) / lambda;
1249
+ if (res < upper) return res;
1250
+ }
1251
+ }
1252
+
1253
+ Integer geometric(Real p) {// theoretically in [0, inf)
1254
+ judgeAssert<std::domain_error>(0.0_real <= p and p < 1.0_real, "Random::geometric(): p must be in [0,1)!");
1255
+ return std::llround(std::floor(std::log(real()) / std::log1p(-p)));
1256
+ }
1257
+ Integer geometric(Integer lower, Integer upper, Real p) {// in [lower, upper)
1258
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::geometric(): Lower must be less than upper!");
1259
+ judgeAssert<std::domain_error>(0.0_real <= p and p < 1.0_real, "Random::geometric(): p must be in [0,1)!");
1260
+ while (true) {
1261
+ // https://en.wikipedia.org/wiki/Geometric_distribution
1262
+ // "The exponential distribution is the continuous analogue of the geometric distribution[...]"
1263
+ Integer res = lower + std::llround(std::floor(std::log(real()) / std::log1p(-p)));
1264
+ if (res < upper) return res;
1265
+ }
1266
+ }
1267
+
1268
+ Integer binomial(Integer n, Real p) {// in [0, n]
1269
+ judgeAssert<std::domain_error>(n >= 0, "Random::binomial(): n must be non negative!");
1270
+ judgeAssert<std::domain_error>(0.0_real <= p and p <= 1.0_real, "Random::binomial(): p must be in [0,1)!");
1271
+ bool swap = p > 0.5_real;
1272
+ p = std::min(p, 1.0_real - p);
1273
+ if (p*n < 10.0_real) {
1274
+ // BG: Geometric method
1275
+ // https://dl.acm.org/doi/pdf/10.1145/42372.42381
1276
+ Integer res = 0;
1277
+ Integer y = 0;
1278
+ Real lg = std::log1p(-p);
1279
+ if (lg >= 0) return swap ? n : 0;
1280
+ do {
1281
+ y += std::llround(std::floor(std::log(real()) / lg)) + 1;
1282
+ if (y > n) return swap ? n - res : res;
1283
+ res++;
1284
+ } while (true);
1285
+ } else {
1286
+ // BTRS algorithm
1287
+ // https://epub.wu.ac.at/1242/1/document.pdf
1288
+ // note that the original paper has an error
1289
+ // the break condition at the end has to be log(v) < h[...]
1290
+ Real q = 1.0_real - p;
1291
+ Real spq = std::sqrt(n * p * q);
1292
+ Real b = 1.15_real + 2.53_real * spq;
1293
+ Real a = -0.0873_real + 0.0248_real * b + 0.01_real * p;
1294
+ Real c = n * p + 0.5_real;
1295
+ Real vr = 0.92_real - 4.2_real / b;
1296
+
1297
+ bool initialized = false;
1298
+ Real alpha, lpq, m, h;
1299
+ do {
1300
+ Real u = real() - 0.5_real;
1301
+ Real us = 0.5_real - std::abs(u);
1302
+ Integer res = std::llround(std::floor((2.0_real * a / us + b) * u + c));
1303
+ if (res < 0 or res > n) continue;
1304
+
1305
+ Real v = real();
1306
+ if (us >= 0.07_real and v <= vr) {
1307
+ return swap ? n - res : res;
1308
+ }
1309
+
1310
+ if (!initialized) {
1311
+ alpha = (2.83_real + 5.1_real / b) * spq;
1312
+ lpq = std::log(p / q);
1313
+ m = std::llround(std::floor((n + 1) * p));
1314
+ h = std::lgamma(m + 1) + std::lgamma(n - m + 1);
1315
+ initialized = true;
1316
+ }
1317
+ v *= alpha / (a / (us * us) + b);
1318
+ if (std::log(v) <= h - std::lgamma(res + 1) - std::lgamma(n - res + 1) + (res - m) * lpq) {
1319
+ return swap ? n - res : res;
1320
+ }
1321
+ } while (true);
1322
+ }
1323
+ }
1324
+ Integer binomial(Integer lower, Integer upper, Integer n, Real p) {// in [lower, upper)
1325
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::binomial(): n Lower must be less than upper!");
1326
+ while (true) {
1327
+ Integer res = binomial(n, p);
1328
+ if (lower <= res and res < upper) return res;
1329
+ }
1330
+ }
1331
+
1332
+ Integer maximum(Integer lower, Integer upper, Integer n) {// in [lower, upper)
1333
+ judgeAssert<std::invalid_argument>(n > 0, "Random::maximum(): n musst be positive!");
1334
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::maximum(): Lower must be less than upper!");
1335
+ if (n < 5) {
1336
+ Integer res = lower;
1337
+ for (Integer i = 0; i < n; i++) res = std::max(res, integer(lower, upper));
1338
+ return res;
1339
+ } else {// such large n seem unlikely
1340
+ UInteger ul = static_cast<UInteger>(lower);
1341
+ UInteger uu = static_cast<UInteger>(upper);
1342
+ UInteger res = (uu - ul) * std::exp2(std::log2(real()) / n);
1343
+ return std::min(upper - 1, static_cast<Integer>(res + ul));
1344
+ }
1345
+ }
1346
+ Integer maximum(Integer upper, Integer n) {
1347
+ return maximum(0, upper, n);
1348
+ }
1349
+
1350
+ Integer minimum(Integer lower, Integer upper, Integer n) {// in [lower, upper)
1351
+ return upper - 1 - maximum(0, upper - lower, n);
1352
+ }
1353
+ Integer minimum(Integer upper, Integer n) {
1354
+ return minimum(0, upper, n);
1355
+ }
1356
+
1357
+ Integer prime(Integer lower, Integer upper) {// in [lower, upper)
1358
+ judgeAssert<std::invalid_argument>(lower < upper, "Random::prime(): Lower must be less than upper!");
1359
+ Integer sampleL = lower <= 2 ? 0 : (lower / 2);
1360
+ Integer sampleU = upper / 2;
1361
+ if (sampleL < sampleU) {
1362
+ for (Integer i = 0; i < details::PRIME_TRIALS and i < 4 * (upper - lower); i++) {
1363
+ Integer res = std::max<Integer>(2, 2*integer(sampleL, sampleU) | 1);
1364
+ if (isPrime(res)) return res;
1365
+ }
1366
+ }
1367
+ judgeAssert<std::domain_error>(false, "Random::prime(): range contains no primes?");
1368
+ return -1;
1369
+ }
1370
+ Integer prime(Integer upper) {// in [0, upper)
1371
+ return prime(0, upper);
1372
+ }
1373
+
1374
+
1375
+ //========================================================================//
1376
+ // utility //
1377
+ //========================================================================//
1378
+ template<typename RandomIt>
1379
+ typename std::iterator_traits<RandomIt>::reference
1380
+ select(RandomIt first, RandomIt last) {
1381
+ judgeAssert<std::invalid_argument>(first < last, "Random::select(): Lower must be less than upper!");
1382
+ return first[integer(0, last - first)];
1383
+ }
1384
+
1385
+ template<typename C>
1386
+ typename ::details::IsContainer<C>::value_type select(const C& c) {
1387
+ return select(std::begin(c), std::end(c));
1388
+ }
1389
+
1390
+ template<typename C>
1391
+ typename C::reference select(C& c) {
1392
+ return select(std::begin(c), std::end(c));
1393
+ }
1394
+
1395
+ template<typename T, std::size_t N>
1396
+ T select(const T(&c)[N]) {
1397
+ return select(std::begin(c), std::end(c));
1398
+ }
1399
+
1400
+ template<typename T, std::size_t N>
1401
+ T& select(T(&c)[N]) {
1402
+ return select(std::begin(c), std::end(c));
1403
+ }
1404
+
1405
+ template<typename T>
1406
+ T select(const std::pair<T, T>& t) {
1407
+ return bit() ? getX(t) : getY(t);
1408
+ }
1409
+
1410
+ template<typename T>
1411
+ T select(const std::complex<T>& t) {
1412
+ return bit() ? getX(t) : getY(t);
1413
+ }
1414
+
1415
+ template<typename RandomIt>
1416
+ void shuffle(RandomIt first, RandomIt last) {
1417
+ using std::swap;
1418
+ auto n = last - first;
1419
+ for (auto i = n-1; i > 0; i--) {
1420
+ swap(first[i], first[integer(0, i+1)]);
1421
+ }
1422
+ }
1423
+
1424
+ template<typename C>
1425
+ void shuffle(C& c) {
1426
+ return shuffle(std::begin(c), std::end(c));
1427
+ }
1428
+
1429
+ template<typename T>
1430
+ void shuffle(std::pair<T, T>& t) {
1431
+ using std::swap;
1432
+ if (bit()) swap(getX(t), getY(t));
1433
+ }
1434
+
1435
+ template<typename T>
1436
+ void shuffle(std::complex<T>& t) {
1437
+ using std::swap;
1438
+ if (bit()) swap(getX(t), getY(t));
1439
+ }
1440
+
1441
+ template<typename RandomIt>
1442
+ Integer rotate(RandomIt first, RandomIt last) {
1443
+ Integer rotation = integer(0, last - first);
1444
+ std::rotate(first, first + rotation, last);
1445
+ return rotation;
1446
+ }
1447
+
1448
+ template<typename C>
1449
+ Integer rotate(C& c) {
1450
+ return rotate(std::begin(c), std::end(c));
1451
+ }
1452
+
1453
+ //========================================================================//
1454
+ // sequences //
1455
+ //========================================================================//
1456
+ std::vector<Integer> distinct(Integer count, Integer lower, Integer upper) {
1457
+ judgeAssert<std::invalid_argument>(count >= 0, "Random::distinct(): Count must be non negative!");
1458
+ judgeAssert<std::invalid_argument>(lower + count <= upper, "Random::distinct(): Lower must be less than upper + count!");
1459
+ std::map<Integer, Integer> used;
1460
+ std::vector<Integer> res;
1461
+ for (Integer i = 0; i < count; i++) {
1462
+ Integer x = integer(lower, upper - i);
1463
+ auto it = used.find(x);
1464
+ if (it != used.end()) res.emplace_back(it->second);
1465
+ else res.emplace_back(x);
1466
+ it = used.find(upper - i - 1);
1467
+ if (it != used.end()) used[x] = it->second;
1468
+ else used[x] = upper - i - 1;
1469
+ }
1470
+ return res;
1471
+ }
1472
+ std::vector<Integer> distinct(Integer count, Integer upper) {
1473
+ return distinct(count, 0, upper);
1474
+ }
1475
+
1476
+ std::vector<Integer> perm(Integer count, Integer offset = 0) {
1477
+ return distinct(count, offset, offset+count);
1478
+ }
1479
+
1480
+ std::vector<Integer> perm(const std::vector<Integer>& cycles, Integer offset = 0) {
1481
+ auto p = perm(std::accumulate(cycles.begin(), cycles.end(), 0_int));
1482
+ std::vector<Integer> res(p.size());
1483
+ Integer tmp = 0;
1484
+ for (std::size_t i = 0; i < cycles.size(); tmp += cycles[i], i++) {
1485
+ judgeAssert<std::invalid_argument>(cycles[i] > 0, "Random::perm(): Cycle lengths must be positive!");
1486
+ for (Integer j = tmp; j + 1 < tmp + cycles[i]; j++) {
1487
+ res[p[j]] = p[j + 1] + offset;
1488
+ }
1489
+ res[p[tmp + cycles[i] - 1]] = p[tmp] + offset;
1490
+ }
1491
+ return res;
1492
+ }
1493
+
1494
+ std::vector<Integer> perm(std::initializer_list<Integer> cycles, Integer offset = 0) {
1495
+ return perm(std::vector<Integer>(cycles), offset);
1496
+ }
1497
+
1498
+ std::vector<Integer> multiple(Integer count, Integer lower, Integer upper) {
1499
+ std::vector<Integer> res(count);
1500
+ for (Integer& x : res) x = integer(lower, upper);
1501
+ return res;
1502
+ }
1503
+ std::vector<Integer> multiple(Integer count, Integer upper) {
1504
+ return multiple(count, 0, upper);
1505
+ }
1506
+
1507
+ std::vector<Integer> increasing(Integer count, Integer lower, Integer upper) {
1508
+ std::vector<Integer> res = distinct(count, lower, upper);
1509
+ std::sort(res.begin(), res.end(), std::less<Integer>());
1510
+ return res;
1511
+ }
1512
+ std::vector<Integer> increasing(Integer count, Integer upper) {
1513
+ return increasing(count, 0, upper);
1514
+ }
1515
+
1516
+ std::vector<Integer> decreasing(Integer count, Integer lower, Integer upper) {
1517
+ std::vector<Integer> res = distinct(count, lower, upper);
1518
+ std::sort(res.begin(), res.end(), std::greater<Integer>());
1519
+ return res;
1520
+ }
1521
+ std::vector<Integer> decreasing(Integer count, Integer upper) {
1522
+ return decreasing(count, 0, upper);
1523
+ }
1524
+
1525
+ std::vector<Integer> nonDecreasing(Integer count, Integer lower, Integer upper) {
1526
+ std::vector<Integer> res = multiple(count, lower, upper);
1527
+ std::sort(res.begin(), res.end(), std::less<Integer>());
1528
+ return res;
1529
+ }
1530
+ std::vector<Integer> nonDecreasing(Integer count, Integer upper) {
1531
+ return nonDecreasing(count, 0, upper);
1532
+ }
1533
+
1534
+ std::vector<Integer> nonIncreasing(Integer count, Integer lower, Integer upper) {
1535
+ std::vector<Integer> res = multiple(count, lower, upper);
1536
+ std::sort(res.begin(), res.end(), std::greater<Integer>());
1537
+ return res;
1538
+ }
1539
+ std::vector<Integer> nonIncreasing(Integer count, Integer upper) {
1540
+ return nonIncreasing(count, 0, upper);
1541
+ }
1542
+
1543
+ std::vector<Integer> partition(Integer n, Integer k, Integer min = 1) {
1544
+ judgeAssert<std::invalid_argument>(n > 0, "Random::partition(): n must be positive!");
1545
+ judgeAssert<std::invalid_argument>(k > 0, "Random::partition(): k must be positive!");
1546
+ judgeAssert<std::invalid_argument>(min <= 0 or k <= n / min, "Random::partition(): k too large!");
1547
+ n -= (min - 1) * k;
1548
+ std::vector<Integer> res = increasing(k-1, 1, n);
1549
+ res.emplace_back(n);
1550
+ for (Integer i = 0, last = 0; i < k; i++) {
1551
+ res[i] -= last;
1552
+ last += res[i];
1553
+ res[i] += min - 1;
1554
+ }
1555
+ return res;
1556
+ }
1557
+
1558
+ std::string bracketSequence(Integer n, char open = '(', char close = ')') {//proper bracket sequence of length 2*n
1559
+ judgeAssert<std::invalid_argument>(0 <= n and n <= 0x7FFF'FFFF, "Random::bracketSequence(): n out of range!");
1560
+ std::string res(2 * n, open);
1561
+ for (Integer i = 0, diff = 0; i < 2 * n; i++) {
1562
+ Integer opened = (i + diff) / 2;
1563
+ if (integer((2 * n - i) * (diff + 1)) < (n - opened) * (diff + 2)) {
1564
+ diff++;
1565
+ } else {
1566
+ res[i] = close;
1567
+ diff--;
1568
+ }
1569
+ }
1570
+ return res;
1571
+ }
1572
+
1573
+ //========================================================================//
1574
+ // geometry //
1575
+ //========================================================================//
1576
+ template<typename Point = std::pair<Integer, Integer>>
1577
+ std::vector<Point> convex(Integer n, Integer dim) {
1578
+ judgeAssert<std::invalid_argument>(dim <= 0x3FFF'FFFF, "Random::convex(): dim too large!");
1579
+ judgeAssert<std::invalid_argument>(dim > 0, "Random::convex(): dim must be positive!");
1580
+ judgeAssert<std::invalid_argument>(n <= 8*dim - 8, "Random::convex(): dim too small!");
1581
+ judgeAssert<std::invalid_argument>(n >= 3, "Random::convex(): n too small!");
1582
+
1583
+ while (true) {
1584
+ Integer left = 1 + binomial(n - 2, 0.5);
1585
+ Integer down = 1 + binomial(n - 2, 0.5);
1586
+ auto x = partition(2 * dim - 2, left, 0);
1587
+ auto y = partition(2 * dim - 2, down, 0);
1588
+ for (auto& z : x) z = -z;
1589
+ for (auto& z : y) z = -z;
1590
+ append(x, partition(2 * dim - 2, n - left, 0));
1591
+ append(y, partition(2 * dim - 2, n - down, 0));
1592
+ auto itX = std::partition(x.begin(), x.end(), [](Integer z){return z == 0;});
1593
+ auto itY = std::partition(y.begin(), y.end(), [](Integer z){return z != 0;});
1594
+ if (std::distance(x.begin(), itX) + std::distance(itY, y.end()) > n) continue;
1595
+ shuffle(itX, x.end());
1596
+ if (itX != x.begin()) shuffle(y.begin(), itY);
1597
+
1598
+ std::vector<Point> dirs(n);
1599
+ for (Integer i = 0; i < n; i++) {
1600
+ dirs[i] = {x[i], y[i]};
1601
+ }
1602
+ ::details::cyclicSort(dirs);
1603
+
1604
+ std::vector<Point> res = {{0, 0}};
1605
+ Integer maxX = 0;
1606
+ Integer maxY = 0;
1607
+ for (auto dir : dirs) {
1608
+ Point tmp = res.back();
1609
+ getX(tmp) += getX(dir);
1610
+ getY(tmp) += getY(dir);
1611
+ maxX = std::max(maxX, getX(tmp));
1612
+ maxY = std::max(maxY, getY(tmp));
1613
+ res.emplace_back(tmp);
1614
+ }
1615
+ res.pop_back();
1616
+ for (auto& point : res) {
1617
+ getX(point) += dim - 1 - maxX;
1618
+ getY(point) += dim - 1 - maxY;
1619
+ }
1620
+ return res;
1621
+ }
1622
+ }
1623
+
1624
+ template<typename Point = std::pair<Integer, Integer>>
1625
+ std::vector<Point> nonCollinearPoints(Integer n, Integer dim) {
1626
+ judgeAssert<std::invalid_argument>(dim <= 0x1FFF'FFFF, "Random::nonCollinearPoints(): dim too large!");
1627
+ judgeAssert<std::invalid_argument>(n >= 0, "Random::nonCollinearPoints(): dim must be non negative!");
1628
+ judgeAssert<std::invalid_argument>(dim > n, "Random::nonCollinearPoints(): dim too small!");
1629
+ Integer p = prime(dim - 1, 2*dim + 2);
1630
+ Integer rotA = 0;
1631
+ Integer rotB = 0;
1632
+ while (rotA == 0 && rotB == 0) {
1633
+ rotA = integer(0, p);
1634
+ rotB = integer(0, p);
1635
+ }
1636
+ std::array<Integer, 3> abc = {
1637
+ integer(1, p),
1638
+ integer(0, p),
1639
+ integer(0, p),
1640
+ };
1641
+ Integer dx = integer(-dim + 1, dim - p);
1642
+ Integer dy = integer(-dim + 1, dim - p);
1643
+
1644
+ auto xs = distinct(n, p);
1645
+ std::vector<Point> res;
1646
+ for (auto tmpX : xs) {
1647
+ Integer tmpY = 0;
1648
+ for (Integer add : abc[0]) {
1649
+ tmpY *= tmpX;
1650
+ tmpY += add;
1651
+ tmpY %= p;
1652
+ }
1653
+
1654
+ Integer x = applyMod(tmpX * rotA - tmpY * rotB, p);
1655
+ Integer y = applyMod(tmpX * rotB + tmpY * rotA, p);
1656
+
1657
+ res.emplace_back(x + dx, y + dy);
1658
+ }
1659
+ return res;
1660
+ }
1661
+
1662
+ } // namespace Random
1663
+
1664
+
1665
+ //============================================================================//
1666
+ // args parser //
1667
+ //============================================================================//
1668
+ class ParamaterBase {
1669
+ friend class Command;
1670
+ friend struct Paramater;
1671
+
1672
+ std::optional<std::string_view> token;
1673
+
1674
+ template<typename T>
1675
+ T parse(std::string_view s) const {
1676
+ T res = {};
1677
+ judgeAssert<std::invalid_argument>(details::parse<T>(s, res), "Command: Could not parse args");
1678
+ return res;
1679
+ }
1680
+
1681
+ ParamaterBase() = default;
1682
+ explicit ParamaterBase(std::string_view token_) : token(token_) {}
1683
+
1684
+ public:
1685
+ std::string asString() const {
1686
+ return std::string(token.value());
1687
+ }
1688
+
1689
+ std::string asString(std::string_view defaultValue) const {
1690
+ return std::string(token.value_or(defaultValue));
1691
+ }
1692
+
1693
+ Integer asInteger() const {
1694
+ return parse<Integer>(token.value());
1695
+ }
1696
+
1697
+ Integer asInteger(Integer defaultValue) const {
1698
+ return token ? asInteger() : defaultValue;
1699
+ }
1700
+
1701
+ Real asReal() const {
1702
+ return parse<Real>(token.value());
1703
+ }
1704
+
1705
+ Real asReal(Real defaultValue) const {
1706
+ return token ? asReal() : defaultValue;
1707
+ }
1708
+ };
1709
+
1710
+ struct Paramater final : private ParamaterBase {
1711
+ using ParamaterBase::ParamaterBase;
1712
+ using ParamaterBase::asString;
1713
+ using ParamaterBase::asInteger;
1714
+ using ParamaterBase::asReal;
1715
+
1716
+ bool exists() const {
1717
+ return token.has_value();
1718
+ }
1719
+
1720
+ explicit operator bool() const {
1721
+ return exists();
1722
+ }
1723
+ };
1724
+
1725
+ class Command final : private ParamaterBase {
1726
+ const std::vector<std::string>& raw;
1727
+ const Integer first, count;
1728
+ const bool found;
1729
+ public:
1730
+ explicit Command(const std::vector<std::string>& raw_) : raw(raw_), first(0), count(0), found(false) {}
1731
+ explicit Command(const std::vector<std::string>& raw_, Integer first_, Integer count_)
1732
+ : ParamaterBase(count_ == 0 ? ParamaterBase() : ParamaterBase(raw_[first_])),
1733
+ raw(raw_), first(first_), count(count_), found(true) {
1734
+ judgeAssert<std::invalid_argument>(count >= 0, "Command: Invalid command in args!");
1735
+ }
1736
+
1737
+ bool exists() const {
1738
+ return found;
1739
+ }
1740
+
1741
+ explicit operator bool() const {
1742
+ return exists();
1743
+ }
1744
+
1745
+ Integer parameterCount() const {
1746
+ return count;
1747
+ }
1748
+
1749
+ Paramater operator[](Integer i) const {
1750
+ if (i >= 0 and i < count) return Paramater(raw[first + i]);
1751
+ return Paramater();
1752
+ }
1753
+
1754
+ using ParamaterBase::asString;
1755
+ using ParamaterBase::asInteger;
1756
+ using ParamaterBase::asReal;
1757
+
1758
+ std::vector<std::string> asStrings() const {
1759
+ std::vector<std::string> res;
1760
+ std::transform(raw.begin() + first,
1761
+ raw.begin() + first + count,
1762
+ std::back_inserter(res), [](const std::string& value) {
1763
+ return std::string(value);
1764
+ });
1765
+ return res;
1766
+ }
1767
+
1768
+ std::vector<Integer> asIntegers() const {
1769
+ std::vector<Integer> res;
1770
+ std::transform(raw.begin() + first,
1771
+ raw.begin() + first + count,
1772
+ std::back_inserter(res), [this](const std::string& value) {
1773
+ return parse<Integer>(value);
1774
+ });
1775
+ return res;
1776
+ }
1777
+
1778
+ std::vector<Real> asReals() const {
1779
+ std::vector<Real> res;
1780
+ std::transform(raw.begin() + first,
1781
+ raw.begin() + first + count,
1782
+ std::back_inserter(res), [this](const std::string& value) {
1783
+ return parse<Real>(value);
1784
+ });
1785
+ return res;
1786
+ }
1787
+
1788
+ };
1789
+
1790
+ class CommandParser final {
1791
+ std::vector<std::string> raw;
1792
+ std::map<std::string_view, std::pair<Integer, Integer>> commands;
1793
+ std::map<std::string_view, Integer> tokens;
1794
+
1795
+ static bool isCommand(std::string_view s) {
1796
+ return s.size() > 2 and s.substr(0, 2) == COMMAND_PREFIX;
1797
+ }
1798
+ void addCommand(std::string_view command, Integer first, Integer count = 0) {
1799
+ judgeAssert<std::invalid_argument>(commands.count(command) == 0, "Command: Duplcated command in args!");
1800
+ commands.emplace(command, std::pair<Integer, Integer>{first, count});
1801
+ }
1802
+
1803
+ public:
1804
+ CommandParser() = default;
1805
+ explicit CommandParser(int argc, char** argv) {
1806
+ raw.assign(argc, {});
1807
+ std::string_view command = EMPTY_COMMAND;
1808
+ Integer first = 0;
1809
+ Integer count = 0;
1810
+ for (int i = 0; i < argc; i++) {
1811
+ raw[i] = std::string(argv[i]);
1812
+ tokens.emplace(raw[i], i+1);
1813
+ if (isCommand(raw[i])) {
1814
+ addCommand(command, first, count);
1815
+ command = raw[i];
1816
+ first = i+1;
1817
+ count = 0;
1818
+ } else {
1819
+ count++;
1820
+ }
1821
+ }
1822
+ addCommand(command, first, count);
1823
+ }
1824
+ CommandParser(CommandParser&&) = default;
1825
+ CommandParser& operator=(CommandParser&&) = default;
1826
+
1827
+ CommandParser(const CommandParser&) = delete;
1828
+ CommandParser& operator=(const CommandParser&) = delete;
1829
+
1830
+ std::string_view operator[](Integer t) const {
1831
+ judgeAssert<std::out_of_range>(t >= 0 and t < static_cast<Integer>(raw.size()), "Command: Index out of args!");
1832
+ return raw[t];
1833
+ }
1834
+ Command operator[](std::string_view command) const & {
1835
+ judgeAssert<std::invalid_argument>(details::isToken(command), "Command: must not contain a space!");
1836
+ auto it = commands.find(command);
1837
+ if (it == commands.end()) return Command(raw);
1838
+ return Command(raw, it->second.first, it->second.second);
1839
+ }
1840
+ Command getRaw(std::string_view command) const & {
1841
+ judgeAssert<std::invalid_argument>(details::isToken(command), "Command: must not contain a space!");
1842
+ auto it = tokens.find(command);
1843
+ if (it == tokens.end()) return Command(raw);
1844
+ return Command(raw, it->second, raw.size() - it->second);
1845
+ }
1846
+ Command getRaw() const & {
1847
+ return Command(raw, 0, raw.size());
1848
+ }
1849
+ };
1850
+
1851
+
1852
+ //============================================================================//
1853
+ // Constraints //
1854
+ //============================================================================//
1855
+ template<typename T>
1856
+ class Bounds final {
1857
+ bool hadMin, hadMax; // was value==lower/upper at some point
1858
+ T min, max; // range of seen values
1859
+ T lower, upper; // bounds for value
1860
+ public:
1861
+ constexpr explicit Bounds(T lower_, T upper_, T value_) :
1862
+ hadMin(false), hadMax(false),
1863
+ min(value_), max(value_),
1864
+ lower(lower_), upper(upper_) {
1865
+ update(lower_, upper_, value_);
1866
+ }
1867
+
1868
+ void update(T lower_, T upper_, T value_) {
1869
+ if constexpr (std::is_same_v<T, Real>) {
1870
+ hadMin |= details::floatEqual(value_, lower_, DEFAULT_EPS, DEFAULT_EPS);
1871
+ hadMax |= details::floatEqual(value_, upper_, DEFAULT_EPS, DEFAULT_EPS);
1872
+ } else {
1873
+ hadMin |= value_ == lower_;
1874
+ hadMax |= value_ == upper_;
1875
+ }
1876
+ min = std::min(min, value_);
1877
+ max = std::max(max, value_);
1878
+ lower = std::min(lower, lower_);
1879
+ upper = std::max(upper, upper_);
1880
+ }
1881
+
1882
+ friend std::ostream& operator<<(std::ostream& os, const Bounds<T>& bounds) {
1883
+ os << bounds.hadMin << " " << bounds.hadMax << " ";
1884
+ os << bounds.min << " " << bounds.max << " ";
1885
+ return os << bounds.lower << " " << bounds.upper;
1886
+ }
1887
+
1888
+ };
1889
+
1890
+ namespace details {
1891
+ //using typeIndex = std::type_index;
1892
+ using typeIndex = void*;
1893
+
1894
+ template<typename T>
1895
+ typeIndex getTypeIndex() {
1896
+ //return std::type_index(type id(T));
1897
+ static T* uniqueTypeIndex = nullptr;
1898
+ return &uniqueTypeIndex;
1899
+ }
1900
+ }
1901
+
1902
+ class Constraint final {
1903
+ friend class ConstraintsLogger;
1904
+ std::variant<
1905
+ std::monostate, // uninitialized
1906
+ Bounds<Integer>, // Integer or container bound
1907
+ Bounds<Real> // Real bound
1908
+ > bound;
1909
+ std::optional<details::typeIndex> type;
1910
+
1911
+ template<typename T, typename X = T>
1912
+ void update(T lower, T upper, T value) {
1913
+ if constexpr(std::is_integral_v<T>) {
1914
+ upper--; // for BAPCtools the range is closed but we use half open ranges!
1915
+ }
1916
+ if (!type) {
1917
+ type = details::getTypeIndex<X>();
1918
+ bound = Bounds<T>(lower, upper, value);
1919
+ }
1920
+ judgeAssert<std::logic_error>(type == details::getTypeIndex<X>(), "Constraint: type must not change!");
1921
+ std::get<Bounds<T>>(bound).update(lower, upper, value);
1922
+ }
1923
+ public:
1924
+ Constraint() = default;
1925
+ Constraint(Constraint&&) = default;
1926
+ Constraint& operator=(Constraint&&) = default;
1927
+
1928
+ Constraint(const Constraint&) = delete;
1929
+ Constraint& operator=(const Constraint&) = delete;
1930
+
1931
+ template<typename V, typename std::enable_if_t<std::is_integral_v<V>, bool> = true>
1932
+ void log(Integer lower, Integer upper, V value) {
1933
+ update<Integer>(lower, upper, value);
1934
+ }
1935
+
1936
+ template<typename V, typename std::enable_if_t<std::is_floating_point_v<V>, bool> = true>
1937
+ void log(Real lower, Real upper, V value) {
1938
+ update<Real>(lower, upper, value);
1939
+ }
1940
+
1941
+ template<typename C, typename std::enable_if_t<!std::is_arithmetic_v<C>, bool> = true>
1942
+ void log(Integer lower, Integer upper, const C& container) {
1943
+ update<Integer, C>(lower, upper, static_cast<Integer>(std::size(container)));
1944
+ }
1945
+ };
1946
+
1947
+ class ConstraintsLogger final {
1948
+ std::optional<std::string> fileName;
1949
+ std::map<std::string, std::size_t> byName;
1950
+ std::vector<std::unique_ptr<Constraint>> constraints;
1951
+ public:
1952
+ ConstraintsLogger() = default;
1953
+ explicit ConstraintsLogger(std::string_view fileName_) : fileName(fileName_) {}
1954
+
1955
+ ConstraintsLogger(ConstraintsLogger&&) = default;
1956
+ ConstraintsLogger& operator=(ConstraintsLogger&&) = default;
1957
+
1958
+ ConstraintsLogger(const ConstraintsLogger&) = delete;
1959
+ ConstraintsLogger& operator=(const ConstraintsLogger&) = delete;
1960
+
1961
+ Constraint& operator[](const std::string& name) & {
1962
+ judgeAssert<std::invalid_argument>(details::isToken(name), "Constraint: name must not contain a space!");
1963
+ auto res = byName.try_emplace(name, constraints.size());
1964
+ if (res.second) constraints.emplace_back(std::make_unique<Constraint>());
1965
+ return *(constraints[res.first->second]);
1966
+ }
1967
+
1968
+ void write() const {
1969
+ if (!fileName) return;
1970
+ std::ofstream os(*fileName);
1971
+ os << std::noboolalpha;
1972
+ os << std::fixed;
1973
+ os << std::setprecision(DEFAULT_PRECISION);
1974
+ for (const auto& [name, id] : byName) {
1975
+ const Constraint& c = *(constraints[id]);
1976
+ if (c.type) {
1977
+ os << "LocationNotSupported:" << name << " " << name << " ";
1978
+ if (c.bound.index() == 1) os << std::get<1>(c.bound);
1979
+ if (c.bound.index() == 2) os << std::get<2>(c.bound);
1980
+ os << std::endl;
1981
+ }
1982
+ }
1983
+ }
1984
+
1985
+ ~ConstraintsLogger() noexcept {
1986
+ write();
1987
+ }
1988
+ };
1989
+
1990
+ //============================================================================//
1991
+ // custom input stream //
1992
+ //============================================================================//
1993
+ class InputStream final {
1994
+ std::unique_ptr<std::ifstream> managed;
1995
+ std::istream* in;
1996
+ bool spaceSensitive, caseSensitive;
1997
+ Verdict onFail;
1998
+ Real floatAbsTol;
1999
+ Real floatRelTol;
2000
+
2001
+ void init() {
2002
+ if (spaceSensitive) *in >> std::noskipws;
2003
+ else *in >> std::skipws;
2004
+ }
2005
+
2006
+ void checkIn() {
2007
+ judgeAssert<std::runtime_error>(in != nullptr, "InputStream: not initialized!");
2008
+ }
2009
+
2010
+ public:
2011
+ InputStream() = default;
2012
+ explicit InputStream(const std::filesystem::path& path,
2013
+ bool spaceSensitive_,
2014
+ bool caseSensitive_,
2015
+ Verdict onFail_,
2016
+ Real floatAbsTol_ = DEFAULT_EPS,
2017
+ Real floatRelTol_ = DEFAULT_EPS) :
2018
+ managed(std::make_unique<std::ifstream>(path)),
2019
+ in(managed.get()),
2020
+ spaceSensitive(spaceSensitive_),
2021
+ caseSensitive(caseSensitive_),
2022
+ onFail(onFail_),
2023
+ floatAbsTol(floatAbsTol_),
2024
+ floatRelTol(floatRelTol_) {
2025
+ judgeAssert<std::runtime_error>(managed->good(), "InputStream: Could not open File: " + path.string());
2026
+ init();
2027
+ }
2028
+ explicit InputStream(std::istream& in_,
2029
+ bool spaceSensitive_,
2030
+ bool caseSensitive_,
2031
+ Verdict onFail_,
2032
+ Real floatAbsTol_ = DEFAULT_EPS,
2033
+ Real floatRelTol_ = DEFAULT_EPS) :
2034
+ managed(),
2035
+ in(&in_),
2036
+ spaceSensitive(spaceSensitive_),
2037
+ caseSensitive(caseSensitive_),
2038
+ onFail(onFail_),
2039
+ floatAbsTol(floatAbsTol_),
2040
+ floatRelTol(floatRelTol_) {
2041
+ init();
2042
+ }
2043
+
2044
+ InputStream(InputStream&& other) = default;
2045
+ InputStream& operator=(InputStream&& other) = default;
2046
+
2047
+ InputStream(const InputStream&) = delete;
2048
+ InputStream& operator=(const InputStream&) = delete;
2049
+
2050
+ void eof() {
2051
+ checkIn();
2052
+ if (!spaceSensitive) *in >> std::ws;
2053
+ if (in->peek() != std::char_traits<char>::eof()) {
2054
+ in->get();
2055
+ ValidateBase::juryOut << "Missing EOF!";
2056
+ fail();
2057
+ }
2058
+ }
2059
+
2060
+ void noteof() {
2061
+ checkIn();
2062
+ if (!spaceSensitive) *in >> std::ws;
2063
+ if (in->peek() == std::char_traits<char>::eof()) {
2064
+ ValidateBase::juryOut << "Unexpected EOF!" << onFail;
2065
+ }
2066
+ }
2067
+
2068
+ void space() {
2069
+ if (spaceSensitive) {
2070
+ noteof();
2071
+ if (in->get() != std::char_traits<char>::to_int_type(SPACE)) {
2072
+ ValidateBase::juryOut << "Missing space!";
2073
+ fail();
2074
+ }
2075
+ }
2076
+ }
2077
+
2078
+ void newline() {
2079
+ if (spaceSensitive) {
2080
+ noteof();
2081
+ if (in->get() != std::char_traits<char>::to_int_type(NEWLINE)) {
2082
+ ValidateBase::juryOut << "Missing newline!";
2083
+ fail();
2084
+ }
2085
+ }
2086
+ }
2087
+
2088
+ private:
2089
+ void check(const std::string& token, const std::regex& pattern) {
2090
+ if (!std::regex_match(token, pattern)) {
2091
+ ValidateBase::juryOut << "Token \"" << token << "\" does not match pattern!";
2092
+ fail();
2093
+ }
2094
+ }
2095
+
2096
+ std::function<void()> checkSeparator(char separator) {
2097
+ if (separator == SPACE) return [this](){space();};
2098
+ if (separator == NEWLINE) return [this](){newline();};
2099
+ judgeAssert<std::invalid_argument>(false, "InputStream: Separator must be ' ' or '\\n'!");
2100
+ return {};
2101
+ }
2102
+
2103
+ template<typename T>
2104
+ T parse(const std::string& s) {
2105
+ T res = {};
2106
+ if (!details::parse<T>(s, res)) {
2107
+ ValidateBase::juryOut << "Could not parse token \"" << s << "\"!";
2108
+ fail();
2109
+ }
2110
+ return res;
2111
+ }
2112
+
2113
+ public:
2114
+ std::string string() {
2115
+ noteof();
2116
+ if (spaceSensitive and !std::isgraph(in->peek())) {
2117
+ in->get();
2118
+ ValidateBase::juryOut << "Invalid whitespace!";
2119
+ fail();
2120
+ }
2121
+ std::string res;
2122
+ *in >> res;
2123
+ if (res.empty()) {
2124
+ ValidateBase::juryOut << "Unexpected EOF!" << onFail;
2125
+ }
2126
+ if (!caseSensitive) toDefaultCase(res);
2127
+ return res;
2128
+ }
2129
+
2130
+ std::string string(Integer lower, Integer upper) {
2131
+ std::string t = string();
2132
+ Integer length = static_cast<Integer>(t.size());
2133
+ if (length < lower or length >= upper) {
2134
+ ValidateBase::juryOut << "String length " << length << " out of range [" << lower << ", " << upper << ")!";
2135
+ fail();
2136
+ }
2137
+ return t;
2138
+ }
2139
+
2140
+ std::string string(Integer lower, Integer upper, Constraint& constraint) {
2141
+ std::string res = string(lower, upper);
2142
+ constraint.log(lower, upper, res);
2143
+ return res;
2144
+ }
2145
+
2146
+ std::string string(const std::regex& pattern) {
2147
+ std::string t = string();
2148
+ check(t, pattern);
2149
+ return t;
2150
+ }
2151
+
2152
+ std::string string(const std::regex& pattern, Integer lower, Integer upper) {
2153
+ std::string t = string(lower, upper);
2154
+ check(t, pattern);
2155
+ return t;
2156
+ }
2157
+
2158
+ std::string string(const std::regex& pattern, Integer lower, Integer upper, Constraint& constraint) {
2159
+ std::string res = string(pattern, lower, upper);
2160
+ constraint.log(lower, upper, res);
2161
+ return res;
2162
+ }
2163
+
2164
+ template<typename... Args>
2165
+ std::vector<std::string> strings(Args... args, Integer count, char separator) {
2166
+ auto sepCall = checkSeparator(separator);
2167
+ std::vector<std::string> res(count);
2168
+ for (Integer i = 0; i < count; i++) {
2169
+ res[i] = string(args...);
2170
+ if (i + 1 < count) sepCall();
2171
+ }
2172
+ return res;
2173
+ }
2174
+
2175
+ std::vector<std::string> strings(Integer count, char separator = DEFAULT_SEPARATOR) {
2176
+ return strings<>(count, separator);
2177
+ }
2178
+
2179
+ std::vector<std::string> strings(Integer lower, Integer upper,
2180
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2181
+ return strings<Integer, Integer>(lower, upper, count, separator);
2182
+ }
2183
+
2184
+ std::vector<std::string> strings(Integer lower, Integer upper, Constraint& constraint,
2185
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2186
+ return strings<Integer, Integer, Constraint&>(lower, upper, constraint, count, separator);
2187
+ }
2188
+
2189
+ std::vector<std::string> strings(const std::regex& pattern,
2190
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2191
+ return strings<const std::regex&>(pattern, count, separator);
2192
+ }
2193
+
2194
+ std::vector<std::string> strings(const std::regex& pattern, Integer lower, Integer upper,
2195
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2196
+ return strings<const std::regex&, Integer, Integer>(pattern, lower, upper, count, separator);
2197
+ }
2198
+
2199
+ std::vector<std::string> strings(const std::regex& pattern, Integer lower, Integer upper, Constraint& constraint,
2200
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2201
+ return strings<const std::regex&, Integer, Integer, Constraint&>(pattern, lower, upper, constraint, count, separator);
2202
+ }
2203
+
2204
+ Integer integer() {
2205
+ return parse<Integer>(string(INTEGER_REGEX));
2206
+ }
2207
+
2208
+ Integer integer(Integer lower, Integer upper) {
2209
+ Integer res = integer();
2210
+ if (res < lower or res >= upper) {
2211
+ ValidateBase::juryOut << "Integer " << res << " out of range [" << lower << ", " << upper << ")!";
2212
+ fail();
2213
+ }
2214
+ return res;
2215
+ }
2216
+
2217
+ Integer integer(Integer lower, Integer upper, Constraint& constraint) {
2218
+ Integer res = integer(lower, upper);
2219
+ constraint.log(lower, upper, res);
2220
+ return res;
2221
+ }
2222
+
2223
+ template<typename... Args>
2224
+ std::vector<Integer> integers(Args... args, Integer count, char separator) {
2225
+ auto sepCall = checkSeparator(separator);
2226
+ std::vector<Integer> res(count);
2227
+ for (Integer i = 0; i < count; i++) {
2228
+ res[i] = integer(args...);
2229
+ if (i + 1 < count) sepCall();
2230
+ }
2231
+ return res;
2232
+ }
2233
+
2234
+ std::vector<Integer> integers(Integer count, char separator = DEFAULT_SEPARATOR) {
2235
+ return integers<>(count, separator);
2236
+ }
2237
+
2238
+ std::vector<Integer> integers(Integer lower, Integer upper,
2239
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2240
+ return integers<Integer, Integer>(lower, upper, count, separator);
2241
+ }
2242
+
2243
+ std::vector<Integer> integers(Integer lower, Integer upper, Constraint& constraint,
2244
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2245
+ return integers<Integer, Integer, Constraint&>(lower, upper, constraint, count, separator);
2246
+ }
2247
+
2248
+ // this does not allow NaN or Inf!
2249
+ // However, those should never be desired.
2250
+ Real real() {
2251
+ return parse<Real>(string(REAL_REGEX));
2252
+ }
2253
+
2254
+ Real real(Real lower, Real upper) {// uses eps
2255
+ Real res = real();
2256
+ if (details::floatEqual(res, lower, floatAbsTol, floatRelTol)) return res;
2257
+ if (details::floatEqual(res, upper, floatAbsTol, floatRelTol)) return res;
2258
+ if (std::isnan(res) or !(res >= lower) or !(res < upper)) {
2259
+ ValidateBase::juryOut << "Real " << res << " out of range [" << lower << ", " << upper << ")!";
2260
+ fail();
2261
+ }
2262
+ return res;
2263
+ }
2264
+
2265
+ Real real(Real lower, Real upper, Constraint& constraint) {
2266
+ Real res = real(lower, upper);
2267
+ constraint.log(lower, upper, res);
2268
+ return res;
2269
+ }
2270
+
2271
+ template<typename... Args>
2272
+ std::vector<Real> reals(Args... args, Integer count, char separator) {
2273
+ auto sepCall = checkSeparator(separator);
2274
+ std::vector<Real> res(count);
2275
+ for (Integer i = 0; i < count; i++) {
2276
+ res[i] = real(args...);
2277
+ if (i + 1 < count) sepCall();
2278
+ }
2279
+ return res;
2280
+ }
2281
+
2282
+ std::vector<Real> reals(Integer count, char separator = DEFAULT_SEPARATOR) {
2283
+ return reals<>(count, separator);
2284
+ }
2285
+
2286
+ std::vector<Real> reals(Real lower, Real upper,
2287
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2288
+ return reals<Real, Real>(lower, upper, count, separator);
2289
+ }
2290
+
2291
+ std::vector<Real> reals(Real lower, Real upper, Constraint& constraint,
2292
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2293
+ return reals<Real, Real, Constraint&>(lower, upper, constraint, count, separator);
2294
+ }
2295
+
2296
+ Real realStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals) {// does not use eps
2297
+ std::string t = string(STRICT_REAL_REGEX);
2298
+ auto dot = t.find('.');
2299
+ Integer decimals = dot == std::string::npos ? 0 : t.size() - dot - 1;
2300
+ if (decimals < minDecimals or decimals >= maxDecimals) {
2301
+ ValidateBase::juryOut << "Real " << t << " has wrong amount of decimals!";
2302
+ fail();
2303
+ return 0;
2304
+ }
2305
+ try {
2306
+ Real res = parse<Real>(t);
2307
+ if (std::isnan(res) or !(res >= lower) or !(res < upper)) {
2308
+ ValidateBase::juryOut << "Real " << res << " out of range [" << lower << ", " << upper << ")!";
2309
+ fail();
2310
+ }
2311
+ return res;
2312
+ } catch(...) {
2313
+ ValidateBase::juryOut << "Could not parse token \"" << t << "\" as real!";
2314
+ fail();
2315
+ return 0;
2316
+ }
2317
+ }
2318
+
2319
+ Real realStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, Constraint& constraint) {
2320
+ Real res = realStrict(lower, upper, minDecimals, maxDecimals);
2321
+ constraint.log(lower, upper, res);
2322
+ return res;
2323
+ }
2324
+
2325
+ template<typename... Args>
2326
+ std::vector<Real> realsStrict(Args... args, Integer count, char separator) {
2327
+ auto sepCall = checkSeparator(separator);
2328
+ std::vector<Real> res(count);
2329
+ for (Integer i = 0; i < count; i++) {
2330
+ res[i] = realStrict(args...);
2331
+ if (i + 1 < count) sepCall();
2332
+ }
2333
+ return res;
2334
+ }
2335
+
2336
+ std::vector<Real> realsStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals,
2337
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2338
+ return realsStrict<Real, Real, Integer, Integer>(lower, upper, minDecimals, maxDecimals, count, separator);
2339
+ }
2340
+
2341
+ std::vector<Real> realsStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, Constraint& constraint,
2342
+ Integer count, char separator = DEFAULT_SEPARATOR) {
2343
+ return realsStrict<Real, Real, Integer, Integer, Constraint&>(lower, upper, minDecimals, maxDecimals, constraint, count, separator);
2344
+ }
2345
+
2346
+ void expectString(std::string_view expected) {
2347
+ judgeAssert<std::invalid_argument>(details::isToken(expected), "InputStream: expected must not contain a space!");
2348
+ std::string seen = string();
2349
+ auto [eq, pos] = details::stringEqual(seen, expected, caseSensitive);
2350
+ if (!eq) {
2351
+ if (seen.size() > 80) {
2352
+ seen = seen.substr(0, 75) + "[...]";
2353
+ }
2354
+ ValidateBase::juryOut << "Expected \"" << expected << "\" but got \"" << seen << "\"!";
2355
+ if (pos and *pos > 5) {
2356
+ ValidateBase::juryOut << " (different at position: " << *pos+1 << ")";
2357
+ }
2358
+ fail();
2359
+ }
2360
+ }
2361
+
2362
+ void expectInt(Integer expected) {
2363
+ Integer seen = integer();
2364
+ if (seen != expected) {
2365
+ ValidateBase::juryOut << "Expected " << expected << " but got " << seen << "!";
2366
+ fail();
2367
+ }
2368
+ }
2369
+
2370
+ void expectReal(Real expected) {
2371
+ Real seen = real();
2372
+ if (details::floatEqual(seen, expected, floatAbsTol, floatRelTol)) {
2373
+ ValidateBase::juryOut << "Expected " << expected << " but got " << seen << "!";
2374
+ if (std::isfinite(seen) and std::isfinite(expected)) {
2375
+ Real absDiff = std::abs(seen-expected);
2376
+ Real relDiff = std::abs((seen-expected)/expected);
2377
+ ValidateBase::juryOut << " (abs: " << absDiff << ", rel: " << relDiff << ")";
2378
+ }
2379
+ fail();
2380
+ }
2381
+ }
2382
+ private:
2383
+ void fail() {
2384
+ //try to find input position...
2385
+ in->clear();
2386
+ auto originalPos = in->tellg();
2387
+ in->seekg(0);
2388
+ if (originalPos != std::streamoff(-1) and *in) {
2389
+ Integer line = 1;
2390
+ std::size_t l = 0, r = 0;
2391
+ std::string buffer;
2392
+ bool extend = true;
2393
+ while (*in and in->tellg() < originalPos) {
2394
+ l = r = buffer.size();
2395
+ if (std::isgraph(in->peek())) {
2396
+ std::string tmp;
2397
+ *in >> tmp;
2398
+ buffer += tmp;
2399
+ } else if (in->peek() == std::char_traits<char>::to_int_type(NEWLINE)) {
2400
+ line++;
2401
+ in->get();
2402
+ if (in->tellg() < originalPos) {
2403
+ buffer.clear();
2404
+ } else {
2405
+ buffer += ' ';
2406
+ extend = false;
2407
+ }
2408
+ } else {
2409
+ buffer += std::char_traits<char>::to_char_type(in->get());
2410
+ }
2411
+ if (*in and in->tellg() >= originalPos) {
2412
+ r = buffer.size();
2413
+ }
2414
+ }
2415
+ if (l != r) {
2416
+ ValidateBase::juryOut << " Line: " << line << ", Char: " << l << '\n';
2417
+ if (extend) {
2418
+ char tmp;
2419
+ while ((buffer.size() < 80 or buffer.size() < r + 80) and in->get(tmp) and tmp != NEWLINE) {
2420
+ buffer += tmp;
2421
+ }
2422
+ }
2423
+ if (r > 60 and l > 20) {
2424
+ Integer offset = std::min(l - 20, r - 60);
2425
+ l -= offset;
2426
+ r -= offset;
2427
+ buffer = "[...]" + buffer.substr(offset + 5);
2428
+ }
2429
+ if (buffer.size() > 80) {
2430
+ buffer = buffer.substr(0, 75);
2431
+ buffer += "[...]";
2432
+ r = std::min(r, buffer.size());
2433
+ }
2434
+ ValidateBase::juryOut << buffer << '\n';
2435
+ ValidateBase::juryOut << std::string(l, ' ') << '^' << std::string(r - l - 1, '~');
2436
+ }
2437
+ }
2438
+ ValidateBase::juryOut << onFail;
2439
+ }
2440
+ };
2441
+
2442
+
2443
+ //============================================================================//
2444
+ // state guard //
2445
+ //============================================================================//
2446
+ namespace details {
2447
+ bool initialized(bool set = false) {
2448
+ static bool value = false;
2449
+ return std::exchange(value, value |= set);
2450
+ }
2451
+
2452
+ struct InitGuard final {
2453
+ ~InitGuard() {
2454
+ if (std::uncaught_exceptions() == 0) {
2455
+ judgeAssert<std::logic_error>(initialized(), "validate.h: init(argc, argv) was never called!");
2456
+ }
2457
+ }
2458
+ } initGuard;
2459
+ }
2460
+
2461
+
2462
+ //============================================================================//
2463
+ // Settings //
2464
+ //============================================================================//
2465
+ template<typename T>
2466
+ class SettingBase {
2467
+ template<typename U>
2468
+ friend class Setting;
2469
+ friend class SettingCaseSensitive;
2470
+
2471
+ T value;
2472
+
2473
+ SettingBase(T value_) : value(value_) {}
2474
+
2475
+ public:
2476
+ SettingBase(SettingBase<T>&& other) = delete;
2477
+ SettingBase(const SettingBase<T>&) = delete;
2478
+ SettingBase<T>& operator=(SettingBase<T>&& other) = delete;
2479
+ SettingBase<T>& operator=(const SettingBase<T>&) = delete;
2480
+
2481
+ operator T() const {
2482
+ return value;
2483
+ }
2484
+
2485
+ SettingBase<T>& operator=(T value_) {
2486
+ judgeAssert<std::logic_error>(!details::initialized(), "validate.h: Cannot change setting after init(argc, argv) was called!");
2487
+ value = value_;
2488
+ return *this;
2489
+ }
2490
+ };
2491
+
2492
+ template<typename T>
2493
+ class Setting final : public SettingBase<T> {
2494
+ public:
2495
+ Setting(T value) : SettingBase<T>(value) {}
2496
+ using SettingBase<T>::operator T;
2497
+ using SettingBase<T>::operator=;
2498
+ };
2499
+
2500
+ class SettingCaseSensitive final : public SettingBase<bool> {
2501
+ public:
2502
+ SettingCaseSensitive(bool value) : SettingBase<bool>(value) {}
2503
+ using SettingBase<bool>::operator bool;
2504
+ using SettingBase<bool>::operator=;
2505
+
2506
+ std::regex regex(std::string_view s, std::regex_constants::syntax_option_type f = std::regex_constants::ECMAScript) const {
2507
+ if (!value) f |= std::regex_constants::icase;
2508
+ return std::regex(s.data(), s.size(), f);
2509
+ }
2510
+ };
2511
+
2512
+
2513
+ //============================================================================//
2514
+ // Validators and stuff //
2515
+ //============================================================================//
2516
+ namespace ValidateBase {
2517
+ //OutputStream juryOut(std::cout); //already defined earlier
2518
+ //OutputStream juryErr(std::cerr);
2519
+ CommandParser arguments;
2520
+ //you may change these values before calling::init() but not afterwards!
2521
+ Setting<Real> floatAbsTol(DEFAULT_EPS);
2522
+ Setting<Real> floatRelTol(DEFAULT_EPS);
2523
+ Setting<bool> spaceSensitive(false);
2524
+ SettingCaseSensitive caseSensitive(false);
2525
+
2526
+ // Real r2 is considered the reference value for relative error.
2527
+ bool floatEqual(Real given,
2528
+ Real expected,
2529
+ Real floatAbsTol_ = floatAbsTol,
2530
+ Real floatRelTol_ = floatRelTol) {
2531
+ return details::floatEqual(given, expected, floatAbsTol_, floatRelTol_);
2532
+ }
2533
+
2534
+ bool floatLess(Real given,
2535
+ Real expected,
2536
+ Real floatAbsTol_ = floatAbsTol,
2537
+ Real floatRelTol_ = floatRelTol) {
2538
+ return given <= expected or floatEqual(given, expected, floatAbsTol_, floatRelTol_);
2539
+ }
2540
+
2541
+ bool floatGreater(Real given,
2542
+ Real expected,
2543
+ Real floatAbsTol_ = floatAbsTol,
2544
+ Real floatRelTol_ = floatRelTol) {
2545
+ return given >= expected or floatEqual(given, expected, floatAbsTol_, floatRelTol_);
2546
+ }
2547
+
2548
+ constexpr boolean<std::size_t> stringEqual(std::string_view a, std::string_view b, bool caseSensitive_ = caseSensitive) {
2549
+ return details::stringEqual(a, b, caseSensitive_);
2550
+ }
2551
+
2552
+ namespace details {
2553
+ void init(int argc, char** argv) {
2554
+ judgeAssert<std::logic_error>(!::details::initialized(), "validate.h: init(argc, argv) was called twice!");
2555
+
2556
+ //std::ios_base::sync_with_stdio(false);
2557
+ //cin.tie(nullptr);
2558
+
2559
+ arguments = CommandParser(argc, argv);
2560
+ if (auto seed = arguments[SEED_COMMAND]) Random::seed(seed.asInteger());
2561
+ // parse default flags manually, since they dont use '--' prefix
2562
+ auto eps = arguments.getRaw(FLOAT_TOLERANCE);
2563
+ floatAbsTol = eps.asReal(floatAbsTol);
2564
+ floatRelTol = eps.asReal(floatRelTol);
2565
+ floatAbsTol = arguments.getRaw(FLOAT_ABSOLUTE_TOLERANCE).asReal(floatAbsTol);
2566
+ floatRelTol = arguments.getRaw(FLOAT_RELATIVE_TOLERANCE).asReal(floatRelTol);
2567
+
2568
+ if (arguments.getRaw(SPACE_SENSITIVE)) spaceSensitive = true;
2569
+ if (arguments.getRaw(CASE_SENSITIVE)) caseSensitive = true;
2570
+
2571
+ ::details::initialized(true);
2572
+ }
2573
+ }
2574
+
2575
+ } // namespace ValidateBase
2576
+
2577
+ namespace ConstraintsBase {
2578
+ ConstraintsLogger constraint;
2579
+
2580
+ void initConstraints() {
2581
+ if (auto file = ValidateBase::arguments[CONSTRAINT_COMMAND]) {
2582
+ constraint = ConstraintsLogger(file.asString());
2583
+ }
2584
+ }
2585
+
2586
+ } // namespace ConstraintsBase
2587
+
2588
+ //called as ./validator [arguments] < inputfile
2589
+ namespace InputValidator {
2590
+ using namespace ValidateBase;
2591
+ using namespace ConstraintsBase;
2592
+
2593
+ InputStream testIn;
2594
+
2595
+ void init(int argc, char** argv) {
2596
+ spaceSensitive = true;
2597
+ caseSensitive = true;
2598
+
2599
+ ValidateBase::details::init(argc, argv);
2600
+ juryOut = OutputStream(std::cout);
2601
+
2602
+ testIn = InputStream(std::cin, spaceSensitive, caseSensitive, WA, floatAbsTol, floatRelTol);
2603
+ initConstraints();
2604
+ }
2605
+
2606
+ } // namespace InputValidator
2607
+
2608
+ //called as ./validator input judgeanswer feedbackdir < teamoutput
2609
+ namespace OutputValidator {
2610
+ using namespace ValidateBase;
2611
+ using namespace ConstraintsBase;
2612
+
2613
+ InputStream testIn;
2614
+ InputStream juryAns;
2615
+ InputStream teamAns;
2616
+
2617
+ void init(int argc, char** argv) {
2618
+ ValidateBase::details::init(argc, argv);
2619
+ juryOut = OutputStream(std::filesystem::path(arguments[3]) / JUDGE_MESSAGE);
2620
+
2621
+ testIn = InputStream(std::filesystem::path(arguments[1]), false, caseSensitive, FAIL);
2622
+ juryAns = InputStream(std::filesystem::path(arguments[2]), false, caseSensitive, FAIL);
2623
+ teamAns = InputStream(std::cin, spaceSensitive, caseSensitive, WA);
2624
+ initConstraints();
2625
+ }
2626
+
2627
+ } // namespace OutputValidator
2628
+
2629
+ //called as ./interactor input judgeanswer feedbackdir <> teamoutput
2630
+ namespace Interactor {
2631
+ using namespace ValidateBase;
2632
+
2633
+ OutputStream toTeam;
2634
+ InputStream testIn;
2635
+ InputStream fromTeam;
2636
+
2637
+ void init(int argc, char** argv) {
2638
+ ValidateBase::details::init(argc, argv);
2639
+ juryOut = OutputStream(std::filesystem::path(arguments[3]) / JUDGE_MESSAGE);
2640
+ toTeam = OutputStream(std::cout);
2641
+
2642
+ testIn = InputStream(std::filesystem::path(arguments[1]), false, caseSensitive, FAIL);
2643
+ fromTeam = InputStream(std::cin, spaceSensitive, caseSensitive, WA);
2644
+ }
2645
+
2646
+ } // namespace Interactor
2647
+
2648
+ //called as ./generator [arguments]
2649
+ namespace Generator {
2650
+ using namespace ValidateBase;
2651
+
2652
+ OutputStream testOut;
2653
+
2654
+ void init(int argc, char** argv) {
2655
+ ValidateBase::details::init(argc, argv);
2656
+ juryOut = OutputStream(std::cerr);
2657
+ testOut = OutputStream(std::cout);
2658
+ }
2659
+
2660
+ } // namespace Generator
2661
+
2662
+ #endif
ICPC/nwerc2023_G/data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b249ebce9baacfa398b0ff98d8b596d8b9bf6bbe555580c7ef3ed1bd4d7bdd5c
3
+ size 48440558
ICPC/nwerc2023_G/init.yml ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ archive: data.zip
2
+ checker:
3
+ args:
4
+ precision: 6
5
+ name: floats
6
+ test_cases:
7
+ - in: 01-cancellation.in
8
+ out: 01-cancellation.ans
9
+ points: 1
10
+ - in: 02-min.in
11
+ out: 02-min.ans
12
+ points: 1
13
+ - in: 03-max.in
14
+ out: 03-max.ans
15
+ points: 1
16
+ - in: 04-max.in
17
+ out: 04-max.ans
18
+ points: 1
19
+ - in: 05-max.in
20
+ out: 05-max.ans
21
+ points: 1
22
+ - in: 06-max.in
23
+ out: 06-max.ans
24
+ points: 1
25
+ - in: 07-max.in
26
+ out: 07-max.ans
27
+ points: 1
28
+ - in: 08-tree.in
29
+ out: 08-tree.ans
30
+ points: 1
31
+ - in: 09-tree.in
32
+ out: 09-tree.ans
33
+ points: 1
34
+ - in: 10-near-tree.in
35
+ out: 10-near-tree.ans
36
+ points: 1
37
+ - in: 11-near-tree.in
38
+ out: 11-near-tree.ans
39
+ points: 1
40
+ - in: 12-complete.in
41
+ out: 12-complete.ans
42
+ points: 1
43
+ - in: 13-boundary.in
44
+ out: 13-boundary.ans
45
+ points: 1
46
+ - in: 14-clusters.in
47
+ out: 14-clusters.ans
48
+ points: 1
49
+ - in: 15-sphere.in
50
+ out: 15-sphere.ans
51
+ points: 1
52
+ - in: 16-random-special.in
53
+ out: 16-random-special.ans
54
+ points: 1
55
+ - in: 17-random-special.in
56
+ out: 17-random-special.ans
57
+ points: 1
58
+ - in: 18-random-special.in
59
+ out: 18-random-special.ans
60
+ points: 1
61
+ - in: 19-random-special.in
62
+ out: 19-random-special.ans
63
+ points: 1
64
+ - in: 20-random-special.in
65
+ out: 20-random-special.ans
66
+ points: 1
67
+ - in: 21-random-special.in
68
+ out: 21-random-special.ans
69
+ points: 1
70
+ - in: 22-random-special.in
71
+ out: 22-random-special.ans
72
+ points: 1
73
+ - in: 23-random-special.in
74
+ out: 23-random-special.ans
75
+ points: 1
76
+ - in: 24-random-special.in
77
+ out: 24-random-special.ans
78
+ points: 1
79
+ - in: 25-random-special.in
80
+ out: 25-random-special.ans
81
+ points: 1
82
+ - in: 26-random-small.in
83
+ out: 26-random-small.ans
84
+ points: 1
85
+ - in: 27-random-small.in
86
+ out: 27-random-small.ans
87
+ points: 1
88
+ - in: 28-random-small.in
89
+ out: 28-random-small.ans
90
+ points: 1
91
+ - in: 29-random-small.in
92
+ out: 29-random-small.ans
93
+ points: 1
94
+ - in: 30-random-small.in
95
+ out: 30-random-small.ans
96
+ points: 1
97
+ - in: 31-random-small.in
98
+ out: 31-random-small.ans
99
+ points: 1
100
+ - in: 32-random-small.in
101
+ out: 32-random-small.ans
102
+ points: 1
103
+ - in: 33-random-small.in
104
+ out: 33-random-small.ans
105
+ points: 1
106
+ - in: 34-random-small.in
107
+ out: 34-random-small.ans
108
+ points: 1
109
+ - in: 35-random-small.in
110
+ out: 35-random-small.ans
111
+ points: 1
112
+ - in: 36-random.in
113
+ out: 36-random.ans
114
+ points: 1
115
+ - in: 37-random.in
116
+ out: 37-random.ans
117
+ points: 1
118
+ - in: 38-random.in
119
+ out: 38-random.ans
120
+ points: 1
121
+ - in: 39-random.in
122
+ out: 39-random.ans
123
+ points: 1
124
+ - in: 40-random.in
125
+ out: 40-random.ans
126
+ points: 1
127
+ - in: 41-random.in
128
+ out: 41-random.ans
129
+ points: 1
130
+ - in: 42-random.in
131
+ out: 42-random.ans
132
+ points: 1
133
+ - in: 43-random.in
134
+ out: 43-random.ans
135
+ points: 1
136
+ - in: 44-random.in
137
+ out: 44-random.ans
138
+ points: 1
139
+ - in: 45-random.in
140
+ out: 45-random.ans
141
+ points: 1
142
+ - in: 46-random-small-coords.in
143
+ out: 46-random-small-coords.ans
144
+ points: 1
145
+ - in: 47-random-small-coords.in
146
+ out: 47-random-small-coords.ans
147
+ points: 1
148
+ - in: 48-random-small-coords.in
149
+ out: 48-random-small-coords.ans
150
+ points: 1
151
+ - in: 49-random-small-coords.in
152
+ out: 49-random-small-coords.ans
153
+ points: 1
154
+ - in: 50-random-small-coords.in
155
+ out: 50-random-small-coords.ans
156
+ points: 1
157
+ - in: 51-always-last.in
158
+ out: 51-always-last.ans
159
+ points: 1
160
+ - in: 52-anti-quadratic.in
161
+ out: 52-anti-quadratic.ans
162
+ points: 1
163
+ - in: 53-anti-quadratic.in
164
+ out: 53-anti-quadratic.ans
165
+ points: 1
166
+ - in: 54-anti-quadratic.in
167
+ out: 54-anti-quadratic.ans
168
+ points: 1
169
+ - in: 55-anti-quadratic.in
170
+ out: 55-anti-quadratic.ans
171
+ points: 1
172
+ - in: 56-anti-quadratic.in
173
+ out: 56-anti-quadratic.ans
174
+ points: 1