contestId
int64
0
1.01k
name
stringlengths
2
58
tags
sequencelengths
0
11
title
stringclasses
523 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
sequencelengths
0
7
demo-output
sequencelengths
0
7
note
stringlengths
0
5.24k
test_cases
listlengths
0
402
timeConsumedMillis
int64
0
8k
memoryConsumedBytes
int64
0
537M
score
float64
-1
3.99
__index_level_0__
int64
0
621k
578
A Problem about Polyline
[ "geometry", "math" ]
null
null
There is a polyline going through points (0,<=0)<=–<=(*x*,<=*x*)<=–<=(2*x*,<=0)<=–<=(3*x*,<=*x*)<=–<=(4*x*,<=0)<=–<=...<=-<=(2*kx*,<=0)<=–<=(2*kx*<=+<=*x*,<=*x*)<=–<=.... We know that the polyline passes through the point (*a*,<=*b*). Find minimum positive value *x* such that it is true or determine that there is no such *x*.
Only one line containing two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109).
Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. If there is no such *x* then output <=-<=1 as the answer.
[ "3 1\n", "1 3\n", "4 1\n" ]
[ "1.000000000000\n", "-1\n", "1.250000000000\n" ]
You can see following graphs for sample 1 and sample 3.
[ { "input": "3 1", "output": "1.000000000000" }, { "input": "1 3", "output": "-1" }, { "input": "4 1", "output": "1.250000000000" }, { "input": "1000000000 1000000000", "output": "1000000000.000000000000" }, { "input": "1000000000 1", "output": "1.000000001000" }, { "input": "991691248 43166756", "output": "47039000.181818180000" }, { "input": "973970808 679365826", "output": "826668317.000000000000" }, { "input": "404878182 80324806", "output": "80867164.666666672000" }, { "input": "405262931 391908625", "output": "398585778.000000000000" }, { "input": "758323881 37209930", "output": "39776690.549999997000" }, { "input": "405647680 36668977", "output": "36859721.416666664000" }, { "input": "750322953 61458580", "output": "67648461.083333328000" }, { "input": "406032429 31993512", "output": "36502161.750000000000" }, { "input": "1000000000 111111111", "output": "111111111.099999990000" }, { "input": "999999999 111111111", "output": "111111111.000000000000" }, { "input": "999999998 111111111", "output": "138888888.625000000000" }, { "input": "888888888 111111111", "output": "124999999.875000000000" }, { "input": "1 1000000000", "output": "-1" }, { "input": "999899988 13", "output": "13.000000117012" }, { "input": "481485937 21902154", "output": "22881276.863636363000" }, { "input": "836218485 1720897", "output": "1724155.106995884800" }, { "input": "861651807 2239668", "output": "2249717.382812500000" }, { "input": "829050416 2523498", "output": "2535286.323170731800" }, { "input": "1000000000 999999999", "output": "999999999.500000000000" }, { "input": "999999999 1000000000", "output": "-1" }, { "input": "11 5", "output": "8.000000000000" }, { "input": "100000000 1", "output": "1.000000010000" }, { "input": "1488 1", "output": "1.000672043011" }, { "input": "11 3", "output": "3.500000000000" }, { "input": "30 5", "output": "5.833333333333" }, { "input": "5 1", "output": "1.000000000000" } ]
93
0
3
9,156
665
Simple Subset
[ "constructive algorithms", "greedy", "number theory" ]
null
null
A tuple of positive integers {*x*1,<=*x*2,<=...,<=*x**k*} is called simple if for all pairs of positive integers (*i*,<=<=*j*) (1<=<=≤<=*i*<=<=&lt;<=<=*j*<=≤<=*k*), *x**i*<=<=+<=<=*x**j* is a prime. You are given an array *a* with *n* positive integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (not necessary distinct). You want to find a simple subset of the array *a* with the maximum size. A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. Let's define a subset of the array *a* as a tuple that can be obtained from *a* by removing some (possibly all) elements of it.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of integers in the array *a*. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
On the first line print integer *m* — the maximum possible size of simple subset of *a*. On the second line print *m* integers *b**l* — the elements of the simple subset of the array *a* with the maximum size. If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
[ "2\n2 3\n", "2\n2 2\n", "3\n2 1 1\n", "2\n83 14\n" ]
[ "2\n3 2\n", "1\n2\n", "3\n1 1 2\n", "2\n14 83\n" ]
none
[ { "input": "2\n2 3", "output": "2\n3 2" }, { "input": "2\n2 2", "output": "1\n2" }, { "input": "3\n2 1 1", "output": "3\n1 1 2" }, { "input": "2\n83 14", "output": "2\n14 83" }, { "input": "10\n10 10 1 2 3 3 1 2 1 5", "output": "4\n1 1 10 1" }, { "input": "100\n314 905 555 526 981 360 424 104 920 814 143 872 741 592 105 573 837 962 220 692 560 493 889 824 145 491 828 960 889 87 375 486 609 423 386 323 124 830 206 446 899 522 514 696 786 783 268 483 318 261 675 445 1000 896 812 277 131 264 860 514 701 678 792 394 324 244 483 357 69 931 590 452 626 451 976 317 722 564 809 40 265 709 13 700 769 869 131 834 712 478 661 369 805 668 512 184 477 896 808 168", "output": "2\n104 905" }, { "input": "100\n174 816 593 727 182 151 842 277 1 942 307 939 447 738 823 744 319 394 515 451 875 950 319 789 384 292 190 758 927 103 246 1 675 42 398 631 382 893 646 2 773 157 992 425 804 565 500 242 2 657 611 647 4 331 99 1 694 18 119 364 458 569 94 999 72 7 297 102 982 859 786 868 178 393 642 254 707 41 103 764 934 70 775 41 188 199 767 64 84 899 626 224 279 188 659 374 105 178 154 758", "output": "4\n1 1 738 1" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1" }, { "input": "100\n966 680 370 134 202 826 254 620 700 336 938 344 368 108 732 130 134 700 996 904 644 734 184 134 996 46 146 928 320 664 304 160 358 306 330 132 674 16 338 138 926 994 196 960 972 972 756 276 600 982 588 978 868 572 446 578 692 976 780 434 882 344 980 536 856 916 966 936 178 300 294 568 984 54 238 718 582 400 572 142 118 306 222 850 948 954 682 256 70 550 830 980 646 970 688 56 552 592 200 682", "output": "1\n966" }, { "input": "100\n598 236 971 958 277 96 651 366 629 50 601 822 744 326 276 330 413 531 791 655 450 173 992 80 401 760 227 64 350 711 258 545 212 690 996 515 983 835 388 311 970 608 185 164 491 419 295 293 274 93 339 761 155 307 991 857 309 957 563 232 328 682 779 637 312 888 305 184 15 556 427 211 327 313 516 815 914 588 592 988 151 839 828 339 196 462 752 454 865 479 356 529 320 59 908 840 294 882 189 6", "output": "2\n96 277" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 204239 1 194239 216480", "output": "18\n1 1 1 1 1 1 1 216480 1 1 1 1 1 1 1 1 1 1" }, { "input": "10\n4 3 1 1 1 1 1 1 1 1", "output": "9\n4 1 1 1 1 1 1 1 1" }, { "input": "2\n1000000 1000000", "output": "1\n1000000" }, { "input": "1\n4", "output": "1\n4" }, { "input": "1\n1", "output": "1\n1" }, { "input": "2\n999997 999994", "output": "1\n999997" }, { "input": "5\n1 1 1 8 9", "output": "3\n1 1 1" }, { "input": "3\n1 5 8", "output": "2\n8 5" }, { "input": "2\n999996 999997", "output": "2\n999997 999996" }, { "input": "2\n1 2", "output": "2\n1 2" }, { "input": "3\n1 8 9", "output": "2\n9 8" }, { "input": "2\n1 1", "output": "2\n1 1" }, { "input": "2\n1 3", "output": "1\n1" }, { "input": "3\n1 9 8", "output": "2\n8 9" }, { "input": "6\n1 3 3 3 3 20", "output": "2\n20 3" }, { "input": "1\n3", "output": "1\n3" }, { "input": "2\n3 3", "output": "1\n3" }, { "input": "5\n1 1 1 8 3", "output": "3\n1 1 1" }, { "input": "1\n9", "output": "1\n9" }, { "input": "3\n2 4 7", "output": "2\n7 4" }, { "input": "6\n2 5 1 1 1 1", "output": "5\n2 1 1 1 1" }, { "input": "3\n1 3 14", "output": "2\n14 3" }, { "input": "1\n6", "output": "1\n6" }, { "input": "3\n2 7 12", "output": "2\n12 7" }, { "input": "3\n3 6 7", "output": "2\n7 6" }, { "input": "3\n7 3 2", "output": "2\n2 3" }, { "input": "3\n1 8 5", "output": "2\n5 8" }, { "input": "2\n1000000 999993", "output": "2\n999993 1000000" }, { "input": "5\n1 5 8 1 1", "output": "3\n1 1 1" }, { "input": "1\n8", "output": "1\n8" }, { "input": "3\n1 13 13", "output": "1\n1" }, { "input": "3\n5 8 1", "output": "2\n8 5" }, { "input": "3\n8 1 5", "output": "2\n5 8" }, { "input": "3\n1 3 8", "output": "2\n8 3" }, { "input": "2\n1 9", "output": "1\n1" }, { "input": "2\n5 5", "output": "1\n5" }, { "input": "1\n5", "output": "1\n5" }, { "input": "3\n1 83 14", "output": "2\n14 83" }, { "input": "5\n123445 32892 32842 432721 39234", "output": "1\n123445" } ]
373
31,641,600
3
9,158
123
String
[ "string suffix structures" ]
null
null
You are given a string *s*. Each pair of numbers *l* and *r* that fulfill the condition 1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|, correspond to a substring of the string *s*, starting in the position *l* and ending in the position *r* (inclusive). Let's define the function of two strings *F*(*x*,<=*y*) like this. We'll find a list of such pairs of numbers for which the corresponding substrings of string *x* are equal to string *y*. Let's sort this list of pairs according to the pair's first number's increasing. The value of function *F*(*x*,<=*y*) equals the number of non-empty continuous sequences in the list. For example: *F*(*babbabbababbab*,<=*babb*)<==<=6. The list of pairs is as follows: (1,<=4),<=(4,<=7),<=(9,<=12) Its continuous sequences are: - (1,<=4) - (4,<=7) - (9,<=12) - (1,<=4),<=(4,<=7) - (4,<=7),<=(9,<=12) - (1,<=4),<=(4,<=7),<=(9,<=12) Your task is to calculate for the given string *s* the sum *F*(*s*,<=*x*) for all *x*, that *x* belongs to the set of all substrings of a string *s*.
The only line contains the given string *s*, consisting only of small Latin letters (1<=≤<=|*s*|<=≤<=105).
Print the single number — the sought sum. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "aaaa\n", "abcdef\n", "abacabadabacaba\n" ]
[ "20\n", "21\n", "188\n" ]
In the first sample the function values at *x* equal to "a", "aa", "aaa" and "aaaa" equal 10, 6, 3 and 1 correspondingly. In the second sample for any satisfying *x* the function value is 1.
[ { "input": "aaaa", "output": "20" }, { "input": "abcdef", "output": "21" }, { "input": "abacabadabacaba", "output": "188" }, { "input": "tkth", "output": "11" }, { "input": "eqkrqe", "output": "23" }, { "input": "cwuiax", "output": "21" }, { "input": "hhhhqhqh", "output": "59" }, { "input": "gmxfmcgp", "output": "38" }, { "input": "eleellleeee", "output": "104" }, { "input": "usussubuubbbbs", "output": "138" }, { "input": "lhmpaugvnqzrfxke", "output": "136" }, { "input": "xkkkkkkkkkkkkkkkkxkkkk", "output": "1098" }, { "input": "pprppppriiriiiirprppprriir", "output": "512" }, { "input": "jsoxkutcvyshsinfmtrpujedcbmyqlojzco", "output": "646" }, { "input": "emcegmekgnlefkeguqkfffnduqhfhhhndlfhlfdqdncefnn", "output": "1227" }, { "input": "ffffdjfddffdjdfffddjfffffffjfffjdjfffjfjfdjjfjdjjdjjjdffd", "output": "2564" }, { "input": "cxvhmeyouudwuglhbwndzwmjjsgrnuwnzwaycfspyyrdckjcidfsabvdxzjkvm", "output": "2023" }, { "input": "cahdktuxuukmbuqcqactqhqdcxpkqcuumckttdpmpqxxkacpappxuqkxbuahqdphhddhquthqaapm", "output": "3258" }, { "input": "hhwhhwhhhwhwwhhwwwhwhhhwhwwwhhwhwhhhhhhwhwhwwwhhwwwhhwhhhhwhwwhwhwwwwhhwwhwhwwwhhhwwhwhwhhwwwhwhhhwwwhwhw", "output": "10856" }, { "input": "cnrkvxbljhitbvoysdpghhhnymktvburpvxybnvugkzudmnmpuhevzyjpbtraaepszhhssmcozkgbjayztrvqwdfmjlhtvarkkdsbnjrabqexpfjozmjzfbmdsihovoxmmtjgtfyaisllysnekdxozhdwu", "output": "12399" }, { "input": "qasiyhdivaiyyhdqiqsvqhtqsetxqvaeqatxesxehisyqiivhvayaxvsxhsydiesaxydysqhedxqhsqivvidqtsitiiveexiehsqdteahyxtsyqetahviyhqvytexethsqssxiytqhxxxdihxietsyxqhtitheyeateeyhythxhhqaad", "output": "17103" }, { "input": "ggwgwwgwwkggwgwwkgwwwggwwwggkgkgwkwgkkgkwwgwkkggwggkwgwgkgwwkwkkkkwggwwkwkkkgwkwwwwwgwkwkkwkggwwgggkkwwkgkgkwgkgkwggkwgggwwkgkwgkwkkgwkkkkggwwwgkggkwwgkwkgwgggkggkkkwwwwwkkgkwggwgkwwwwggwwgkkggwkkwkkgkwggggggkkwkkgkkkwkwwkwggwkkwggggwg", "output": "41166" }, { "input": "tmoqyzoikohtgkybnwjizgjypzycmtstmsizrqrmczmqmpewxiwlqzcaufxkchqyjegktxihlksisbgogpyxkltioovelwaqcbebgcyygxsshsirkwvtsvhpqtbomueaszkrlixueyeiccvfiuoogomjlhjkacnxtimkprmjttpmeaminvmcqagrpjighsvaosojymcjoyopsvkrphzbnckcvvckicmjwpvawjuzkofnuvcahwhzjpfngwyobiufivsjnekjcloobvzawrvosnkvalmr", "output": "42165" }, { "input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrbrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrbrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr", "output": "2214420" }, { "input": "zzzzooozzzoozozoozzzzzzozooozoozoozzozzozoooozzzzzzoooozzozooozoozzzozozoooooozzzozozooooozozozozzooozozzooozzzzozozoozoozzzozooozzzzoozzzzozzzzoooozozozozozzoooozzzooozzoooooooozozzozozooozzzooooozozooozozzozozoozzozzzzooozzoozozozzozozoozozzzoozozoooozzooozozooooozzzzzoozoozzzozzzoozzoozozzooozzzzzzoozzozzoozzzoozozzooozoozzzozooozozzoozoozozzzzzoozoozzzooooozooooooozooooozzoozoozzzooooozoozozozozzzoozzzzzoozzzzzzooooooozzzzozzozzo", "output": "190205" } ]
30
0
0
9,208
599
Spongebob and Joke
[ "implementation" ]
null
null
While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence *a*1,<=*a*2,<=...,<=*a**m* of length *m*, consisting of integers from 1 to *n*, not necessarily distinct. Then he picked some sequence *f*1,<=*f*2,<=...,<=*f**n* of length *n* and for each number *a**i* got number *b**i*<==<=*f**a**i*. To finish the prank he erased the initial sequence *a**i*. It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — the lengths of sequences *f**i* and *b**i* respectively. The second line contains *n* integers, determining sequence *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*). The last line contains *m* integers, determining sequence *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*).
Print "Possible" if there is exactly one sequence *a**i*, such that *b**i*<==<=*f**a**i* for all *i* from 1 to *m*. Then print *m* integers *a*1,<=*a*2,<=...,<=*a**m*. If there are multiple suitable sequences *a**i*, print "Ambiguity". If Spongebob has made a mistake in his calculations and no suitable sequence *a**i* exists, print "Impossible".
[ "3 3\n3 2 1\n1 2 3\n", "3 3\n1 1 1\n1 1 1\n", "3 3\n1 2 1\n3 3 3\n" ]
[ "Possible\n3 2 1 \n", "Ambiguity\n", "Impossible\n" ]
In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique. In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence. In the third sample *f*<sub class="lower-index">*i*</sub> ≠ 3 for all *i*, so no sequence *a*<sub class="lower-index">*i*</sub> transforms into such *b*<sub class="lower-index">*i*</sub> and we can say for sure that Spongebob has made a mistake.
[ { "input": "3 3\n3 2 1\n1 2 3", "output": "Possible\n3 2 1 " }, { "input": "3 3\n1 1 1\n1 1 1", "output": "Ambiguity" }, { "input": "3 3\n1 2 1\n3 3 3", "output": "Impossible" }, { "input": "2 100\n2 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "Possible\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "5 6\n5 2 4 3 5\n1 2 3 4 4 5", "output": "Impossible" }, { "input": "7 10\n1 2 2 1 3 7 5\n1 2 1 2 3 7 5 4 4 4", "output": "Impossible" }, { "input": "1 1\n1\n1", "output": "Possible\n1 " }, { "input": "1 10\n1\n1 1 1 1 1 1 1 1 1 1", "output": "Possible\n1 1 1 1 1 1 1 1 1 1 " }, { "input": "10 1\n1 2 3 4 5 6 1 8 9 10\n7", "output": "Impossible" }, { "input": "3 3\n2 2 2\n2 3 3", "output": "Impossible" }, { "input": "4 4\n1 1 1 4\n1 1 1 3", "output": "Impossible" }, { "input": "3 3\n1 1 2\n1 2 3", "output": "Impossible" }, { "input": "3 3\n2 2 1\n2 3 1", "output": "Impossible" }, { "input": "3 2\n1 1 3\n1 2", "output": "Impossible" }, { "input": "3 3\n1 1 1\n1 2 2", "output": "Impossible" }, { "input": "3 1\n1 1 2\n2", "output": "Possible\n3 " }, { "input": "3 3\n1 1 1\n1 1 2", "output": "Impossible" }, { "input": "5 5\n1 1 5 5 5\n1 2 3 4 5", "output": "Impossible" }, { "input": "2 2\n1 1\n1 2", "output": "Impossible" }, { "input": "3 3\n1 1 2\n1 1 3", "output": "Impossible" }, { "input": "3 2\n1 1 2\n1 3", "output": "Impossible" }, { "input": "4 10\n1 2 3 3\n1 2 1 2 1 2 1 2 3 3", "output": "Ambiguity" }, { "input": "3 3\n1 2 1\n2 2 2", "output": "Possible\n2 2 2 " }, { "input": "4 2\n4 3 2 3\n4 4", "output": "Possible\n1 1 " } ]
280
13,824,000
3
9,269
523
Statistics of Recompressing Videos
[ "*special", "data structures", "implementation" ]
null
null
A social network for dogs called DH (DogHouse) has *k* special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network. We know that each server takes one second to recompress a one minute fragment. Thus, any server takes *m* seconds to recompress a *m* minute video. We know the time when each of the *n* videos were uploaded to the network (in seconds starting from the moment all servers started working). All videos appear at different moments of time and they are recompressed in the order they appear. If some video appeared at time *s*, then its recompressing can start at that very moment, immediately. Some videos can await recompressing when all the servers are busy. In this case, as soon as a server is available, it immediately starts recompressing another video. The videos that await recompressing go in a queue. If by the moment the videos started being recompressed some servers are available, then any of them starts recompressing the video. For each video find the moment it stops being recompressed.
The first line of the input contains integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=5·105) — the number of videos and servers, respectively. Next *n* lines contain the descriptions of the videos as pairs of integers *s**i*,<=*m**i* (1<=≤<=*s**i*,<=*m**i*<=≤<=109), where *s**i* is the time in seconds when the *i*-th video appeared and *m**i* is its duration in minutes. It is guaranteed that all the *s**i*'s are distinct and the videos are given in the chronological order of upload, that is in the order of increasing *s**i*.
Print *n* numbers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the time in seconds after the servers start working, when the *i*-th video will be recompressed.
[ "3 2\n1 5\n2 5\n3 5\n", "6 1\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n5 1000000000\n6 3\n" ]
[ "6\n7\n11\n", "1000000001\n2000000001\n3000000001\n4000000001\n5000000001\n5000000004\n" ]
none
[ { "input": "3 2\n1 5\n2 5\n3 5", "output": "6\n7\n11" }, { "input": "6 1\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n5 1000000000\n6 3", "output": "1000000001\n2000000001\n3000000001\n4000000001\n5000000001\n5000000004" }, { "input": "1 1\n1 1", "output": "2" }, { "input": "1 1\n1000000000 10000", "output": "1000010000" }, { "input": "10 6\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1", "output": "2\n3\n4\n5\n6\n7\n8\n9\n10\n11" }, { "input": "10 4\n1 1\n2 2\n3 1\n4 1\n5 1\n6 1\n7 1\n8 2\n9 1\n10 1", "output": "2\n4\n4\n5\n6\n7\n8\n10\n10\n11" }, { "input": "10 2\n1 5650\n2 4753\n3 7632\n4 688\n5 8853\n6 284\n7 4659\n8 5650\n9 9768\n10 3905", "output": "5651\n4755\n12387\n6339\n15192\n12671\n17330\n20842\n27098\n24747" }, { "input": "10 8\n1 5036\n7 9294\n8 6011\n10 8273\n11 9203\n12 7037\n14 383\n16 4568\n18 8136\n19 8288", "output": "5037\n9301\n6019\n8283\n9214\n7049\n397\n4584\n8533\n12872" }, { "input": "10 2\n4 2\n7 2\n8 2\n9 1\n10 2\n12 2\n14 1\n15 2\n17 2\n19 1", "output": "6\n9\n10\n10\n12\n14\n15\n17\n19\n20" }, { "input": "10 7\n195901104 7859\n265432683 5489\n290824505 5754\n346976046 4969\n406206484 8390\n522669517 6810\n800443397 4979\n839536223 1825\n918231479 8117\n941210310 1322", "output": "195908963\n265438172\n290830259\n346981015\n406214874\n522676327\n800448376\n839538048\n918239596\n941211632" }, { "input": "10 4\n126995987 385321200\n195616854 752754110\n197489309 899442094\n285439286 247570387\n308620877 957032819\n428385669 227675453\n673115425 94614781\n766412355 105231165\n943783548 855684033\n994356572 699602107", "output": "512317187\n948370964\n1096931403\n533009673\n1469350006\n760685126\n855299907\n960531072\n1804054997\n1693958679" }, { "input": "10 10\n999999991 1000000000\n999999992 1000000000\n999999993 1000000000\n999999994 1000000000\n999999995 1000000000\n999999996 1000000000\n999999997 1000000000\n999999998 1000000000\n999999999 1000000000\n1000000000 1000000000", "output": "1999999991\n1999999992\n1999999993\n1999999994\n1999999995\n1999999996\n1999999997\n1999999998\n1999999999\n2000000000" } ]
3,000
3,174,400
0
9,276
407
Long Path
[ "dp", "implementation" ]
null
null
One day, little Vasya found himself in a maze consisting of (*n*<=+<=1) rooms, numbered from 1 to (*n*<=+<=1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (*n*<=+<=1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number *i* (1<=≤<=*i*<=≤<=*n*), someone can use the first portal to move from it to room number (*i*<=+<=1), also someone can use the second portal to move from it to room number *p**i*, where 1<=≤<=*p**i*<=≤<=*i*. In order not to get lost, Vasya decided to act as follows. - Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. - Let's assume that Vasya is in room *i* and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room *p**i*), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (*n*<=+<=1) in the end.
The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of rooms. The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*i*). Each *p**i* denotes the number of the room, that someone can reach, if he will use the second portal in the *i*-th room.
Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109<=+<=7).
[ "2\n1 2\n", "4\n1 1 2 3\n", "5\n1 1 1 1 1\n" ]
[ "4\n", "20\n", "62\n" ]
none
[ { "input": "2\n1 2", "output": "4" }, { "input": "4\n1 1 2 3", "output": "20" }, { "input": "5\n1 1 1 1 1", "output": "62" }, { "input": "7\n1 2 1 3 1 2 1", "output": "154" }, { "input": "1\n1", "output": "2" }, { "input": "3\n1 1 3", "output": "8" }, { "input": "10\n1 1 3 2 2 1 3 4 7 5", "output": "858" }, { "input": "20\n1 2 2 2 2 1 4 7 8 6 5 3 5 3 8 11 5 10 16 10", "output": "433410" }, { "input": "32\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "589934534" }, { "input": "10\n1 1 3 2 2 1 3 4 7 5", "output": "858" }, { "input": "30\n1 1 2 2 5 6 4 3 4 7 3 5 12 12 2 15 3 8 3 10 12 3 14 1 10 4 22 11 22 27", "output": "132632316" }, { "input": "70\n1 1 2 3 4 3 5 2 2 4 8 6 13 6 13 3 5 4 5 10 11 9 11 8 12 24 21 6 9 29 25 31 17 27 3 17 35 5 21 11 27 14 33 7 33 44 22 33 21 11 38 46 53 46 3 22 5 27 55 22 41 25 56 61 27 28 11 66 68 13", "output": "707517223" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "2046" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "2097150" }, { "input": "102\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "810970229" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "20" }, { "input": "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "output": "40" }, { "input": "107\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107", "output": "214" }, { "input": "129\n1 1 3 3 1 4 7 4 3 5 8 11 3 9 15 4 11 17 1 6 18 9 11 13 17 22 8 18 26 13 16 20 3 16 35 26 23 28 27 30 39 29 43 8 14 6 17 32 26 31 2 18 3 47 52 21 57 1 35 35 53 47 16 26 30 65 48 2 32 11 10 5 4 1 4 53 71 21 53 8 58 49 17 6 19 80 1 49 43 60 12 60 35 25 86 45 47 97 52 74 10 91 93 31 69 41 80 90 67 4 94 92 82 36 27 18 65 8 45 90 42 115 34 61 16 97 20 43 104", "output": "931883285" }, { "input": "100\n1 1 3 1 5 1 1 1 8 9 7 3 11 11 15 14 4 10 11 12 1 10 13 11 7 23 8 12 18 23 27 17 14 29 1 33 5 24 26 29 25 14 40 8 43 29 43 40 34 18 21 31 3 8 20 14 28 29 3 54 14 3 59 1 45 9 13 11 50 48 26 57 17 33 9 52 21 46 24 20 16 58 69 77 52 36 80 2 31 3 44 36 64 90 84 8 21 25 65 67", "output": "264413610" }, { "input": "31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29", "output": "758096363" }, { "input": "104\n1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102", "output": "740446116" } ]
93
20,172,800
3
9,284
215
Olympic Medal
[ "greedy", "math" ]
null
null
The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=&lt;<=*r*2<=&lt;<=*r*1) made of metal with density *p*1 g/cm3. The second part is an inner disk with radius *r*2 cm, it is made of metal with density *p*2 g/cm3. The disk is nested inside the ring. The Olympic jury decided that *r*1 will take one of possible values of *x*1,<=*x*2,<=...,<=*x**n*. It is up to jury to decide which particular value *r*1 will take. Similarly, the Olympic jury decided that *p*1 will take one of possible value of *y*1,<=*y*2,<=...,<=*y**m*, and *p*2 will take a value from list *z*1,<=*z*2,<=...,<=*z**k*. According to most ancient traditions the ratio between the outer ring mass *m**out* and the inner disk mass *m**in* must equal , where *A*,<=*B* are constants taken from ancient books. Now, to start making medals, the jury needs to take values for *r*1, *p*1, *p*2 and calculate the suitable value of *r*2. The jury wants to choose the value that would maximize radius *r*2. Help the jury find the sought value of *r*2. Value *r*2 doesn't have to be an integer. Medal has a uniform thickness throughout the area, the thickness of the inner disk is the same as the thickness of the outer ring.
The first input line contains an integer *n* and a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*. The second input line contains an integer *m* and a sequence of integers *y*1,<=*y*2,<=...,<=*y**m*. The third input line contains an integer *k* and a sequence of integers *z*1,<=*z*2,<=...,<=*z**k*. The last line contains two integers *A* and *B*. All numbers given in the input are positive and do not exceed 5000. Each of the three sequences contains distinct numbers. The numbers in the lines are separated by spaces.
Print a single real number — the sought value *r*2 with absolute or relative error of at most 10<=-<=6. It is guaranteed that the solution that meets the problem requirements exists.
[ "3 1 2 3\n1 2\n3 3 2 1\n1 2\n", "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1\n" ]
[ "2.683281573000\n", "2.267786838055\n" ]
In the first sample the jury should choose the following values: *r*<sub class="lower-index">1</sub> = 3, *p*<sub class="lower-index">1</sub> = 2, *p*<sub class="lower-index">2</sub> = 1.
[ { "input": "3 1 2 3\n1 2\n3 3 2 1\n1 2", "output": "2.683281573000" }, { "input": "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1", "output": "2.267786838055" }, { "input": "1 5\n1 3\n1 7\n515 892", "output": "3.263613058533" }, { "input": "2 3 2\n3 2 3 1\n2 2 1\n733 883", "output": "2.655066678191" }, { "input": "2 4 2\n3 1 2 3\n2 2 3\n676 769", "output": "3.176161549164" }, { "input": "2 4 2\n3 2 3 1\n2 3 1\n772 833", "output": "3.496252962144" }, { "input": "2 1 2\n3 2 3 1\n2 1 3\n452 219", "output": "1.539383784060" }, { "input": "2 3 2\n3 3 2 1\n2 3 2\n417 202", "output": "1.946150045603" }, { "input": "2 1 2\n3 1 2 3\n2 3 2\n596 206", "output": "1.168651298016" }, { "input": "2 1 2\n3 3 1 2\n2 2 3\n306 406", "output": "1.631654093847" }, { "input": "2 3 2\n3 3 1 2\n2 2 1\n881 165", "output": "1.799345811354" }, { "input": "2 2 4\n3 1 2 3\n2 2 1\n618 401", "output": "3.251156175034" }, { "input": "10 24 2621 2533 3148 3544 4273 4921 2950 3780 4483\n10 1687 4906 4246 2814 1874 3020 3039 3971 102 492\n10 3458 2699 2463 4395 3607 550 1608 958 3970 3077\n4 891", "output": "4919.762124668494" }, { "input": "1 5000\n1 5000\n1 1\n1 5000", "output": "4999.999900000003" }, { "input": "1 1\n1 1\n1 5000\n5000 1", "output": "0.000199999996" }, { "input": "3 5000 4999 4998\n3 5000 4999 4998\n4 1 2 3 4\n1 5000", "output": "4999.999900000003" }, { "input": "3 1 2 3\n3 1 2 3\n3 5000 4999 4998\n5000 1", "output": "0.001039438331" }, { "input": "3 1 2 3\n1 2\n3 3 2 1\n54 58", "output": "2.478139719747" }, { "input": "3 1 2 3\n1 2\n3 3 2 1\n52 56", "output": "2.479181611624" }, { "input": "3 1 2 3\n1 2\n3 3 2 1\n51 55", "output": "2.479731502196" }, { "input": "3 1 2 3\n1 2\n3 3 2 1\n55 59", "output": "2.477645721991" }, { "input": "3 1 2 3\n1 2\n3 1 2 3\n53 57", "output": "2.478651362102" }, { "input": "13 1 2 3 4 5 6 7 8 9 10 11 12 13\n1 14\n2 15 16\n17 18", "output": "9.165151389912" } ]
186
0
0
9,290
0
none
[ "none" ]
null
null
On vacations *n* pupils decided to go on excursion and gather all together. They need to overcome the path with the length *l* meters. Each of the pupils will go with the speed equal to *v*1. To get to the excursion quickly, it was decided to rent a bus, which has seats for *k* people (it means that it can't fit more than *k* people at the same time) and the speed equal to *v*2. In order to avoid seasick, each of the pupils want to get into the bus no more than once. Determine the minimum time required for all *n* pupils to reach the place of excursion. Consider that the embarkation and disembarkation of passengers, as well as the reversal of the bus, take place immediately and this time can be neglected.
The first line of the input contains five positive integers *n*, *l*, *v*1, *v*2 and *k* (1<=≤<=*n*<=≤<=10<=000, 1<=≤<=*l*<=≤<=109, 1<=≤<=*v*1<=&lt;<=*v*2<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of pupils, the distance from meeting to the place of excursion, the speed of each pupil, the speed of bus and the number of seats in the bus.
Print the real number — the minimum time in which all pupils can reach the place of excursion. Your answer will be considered correct if its absolute or relative error won't exceed 10<=-<=6.
[ "5 10 1 2 5\n", "3 6 1 2 1\n" ]
[ "5.0000000000\n", "4.7142857143\n" ]
In the first sample we should immediately put all five pupils to the bus. The speed of the bus equals 2 and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.
[ { "input": "5 10 1 2 5", "output": "5.0000000000" }, { "input": "3 6 1 2 1", "output": "4.7142857143" }, { "input": "39 252 51 98 26", "output": "3.5344336938" }, { "input": "59 96 75 98 9", "output": "1.2315651330" }, { "input": "87 237 3 21 40", "output": "33.8571428571" }, { "input": "11 81 31 90 1", "output": "2.3331983806" }, { "input": "39 221 55 94 1", "output": "3.9608012268" }, { "input": "59 770 86 94 2", "output": "8.9269481589" }, { "input": "10000 1000000000 1 2 1", "output": "999925003.7498125093" }, { "input": "10000 1 999999999 1000000000 1", "output": "0.0000000010" }, { "input": "9102 808807765 95894 96529 2021", "output": "8423.2676366126" }, { "input": "87 422 7 90 3", "output": "49.2573051579" }, { "input": "15 563 38 51 5", "output": "13.4211211456" }, { "input": "39 407 62 63 2", "output": "6.5592662969" }, { "input": "18 518 99 100 4", "output": "5.2218163471" }, { "input": "8367 515267305 49370 57124 723", "output": "10310.3492287628" }, { "input": "6592 724149457 54877 85492 6302", "output": "10543.9213545882" }, { "input": "8811 929128198 57528 84457 6629", "output": "13306.2878107183" }, { "input": "8861 990217735 49933 64765 6526", "output": "17403.1926037323" }, { "input": "9538 765513348 52584 86675 8268", "output": "11295.6497404812" }, { "input": "9274 783669740 44989 60995 6973", "output": "14946.9402371816" }, { "input": "9103 555078149 86703 93382 8235", "output": "6168.7893283125" }, { "input": "9750 980765213 40044 94985 4226", "output": "18012.2266672490" }, { "input": "5884 943590784 42695 98774 3117", "output": "14275.9991046103" }, { "input": "1 1 1 2 1", "output": "0.5000000000" }, { "input": "10000 1000000000 1 1000000000 1", "output": "19998.6000479986" }, { "input": "10000 1000000000 1 1000000000 10000", "output": "1.0000000000" }, { "input": "10000 1000000000 999999999 1000000000 3", "output": "1.0000000010" }, { "input": "9999 1000000 10 20 3", "output": "99977.5011249438" }, { "input": "1 1 1 1000000000 1", "output": "0.0000000010" }, { "input": "1 1 999999999 1000000000 1", "output": "0.0000000010" }, { "input": "1 1000000000 1 2 1", "output": "500000000.0000000000" }, { "input": "1 1000000000 1 1000000000 1", "output": "1.0000000000" }, { "input": "1 1000000000 999999999 1000000000 1", "output": "1.0000000000" }, { "input": "10000 1 1 2 1", "output": "0.9999250037" }, { "input": "10000 1 1 2 10000", "output": "0.5000000000" }, { "input": "10000 1 1 1000000000 1", "output": "0.0000199986" }, { "input": "10000 1 1 1000000000 10000", "output": "0.0000000010" }, { "input": "10000 1 999999999 1000000000 10000", "output": "0.0000000010" }, { "input": "10000 1000000000 1 2 10000", "output": "500000000.0000000000" }, { "input": "10000 1000000000 999999999 1000000000 1", "output": "1.0000000010" }, { "input": "10000 1000000000 999999999 1000000000 10000", "output": "1.0000000000" } ]
46
0
0
9,321
794
Naming Company
[ "games", "greedy", "sortings" ]
null
null
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play a game. The company name will consist of *n* letters. Oleg and Igor each have a set of *n* letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by *n* question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters *c* in his set and replace any of the question marks with *c*. Then, a copy of the letter *c* is removed from his set. The game ends when all the question marks has been replaced by some letter. For example, suppose Oleg has the set of letters {*i*,<=*o*,<=*i*} and Igor has the set of letters {*i*,<=*m*,<=*o*}. One possible game is as follows : Initially, the company name is ???. Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {*i*,<=*o*}. Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {*i*,<=*m*}. Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {*i*}. In the end, the company name is oio. Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally? A string *s*<==<=*s*1*s*2...*s**m* is called lexicographically smaller than a string *t*<==<=*t*1*t*2...*t**m* (where *s*<=≠<=*t*) if *s**i*<=&lt;<=*t**i* where *i* is the smallest index such that *s**i*<=≠<=*t**i*. (so *s**j*<==<=*t**j* for all *j*<=&lt;<=*i*)
The first line of input contains a string *s* of length *n* (1<=≤<=*n*<=≤<=3·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially. The second line of input contains a string *t* of length *n*. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
The output should contain a string of *n* lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
[ "tinkoff\nzscoder\n", "xxxxxx\nxxxxxx\n", "ioi\nimo\n" ]
[ "fzfsirk\n", "xxxxxx\n", "ioi\n" ]
One way to play optimally in the first sample is as follows : - Initially, the company name is ???????.- Oleg replaces the first question mark with 'f'. The company name becomes f??????.- Igor replaces the second question mark with 'z'. The company name becomes fz?????.- Oleg replaces the third question mark with 'f'. The company name becomes fzf????.- Igor replaces the fourth question mark with 's'. The company name becomes fzfs???.- Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??.- Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?.- Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk. For the second sample, no matter how they play, the company name will always be xxxxxx.
[ { "input": "tinkoff\nzscoder", "output": "fzfsirk" }, { "input": "xxxxxx\nxxxxxx", "output": "xxxxxx" }, { "input": "ioi\nimo", "output": "ioi" }, { "input": "abc\naaa", "output": "aab" }, { "input": "reddit\nabcdef", "output": "dfdeed" }, { "input": "cbxz\naaaa", "output": "abac" }, { "input": "bcdef\nabbbc", "output": "bccdb" }, { "input": "z\ny", "output": "z" }, { "input": "y\nz", "output": "y" } ]
31
0
-1
9,337
241
Old Peykan
[ "greedy" ]
null
null
There are *n* cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as *c*1,<=*c*2,<=...,<=*c**n*. The Old Peykan wants to travel from city *c*1 to *c**n* using roads. There are (*n*<=-<=1) one way roads, the *i*-th road goes from city *c**i* to city *c**i*<=+<=1 and is *d**i* kilometers long. The Old Peykan travels 1 kilometer in 1 hour and consumes 1 liter of fuel during this time. Each city *c**i* (except for the last city *c**n*) has a supply of *s**i* liters of fuel which immediately transfers to the Old Peykan if it passes the city or stays in it. This supply refreshes instantly *k* hours after it transfers. The Old Peykan can stay in a city for a while and fill its fuel tank many times. Initially (at time zero) the Old Peykan is at city *c*1 and *s*1 liters of fuel is transferred to it's empty tank from *c*1's supply. The Old Peykan's fuel tank capacity is unlimited. Old Peykan can not continue its travel if its tank is emptied strictly between two cities. Find the minimum time the Old Peykan needs to reach city *c**n*.
The first line of the input contains two space-separated integers *m* and *k* (1<=≤<=*m*,<=*k*<=≤<=1000). The value *m* specifies the number of roads between cities which is equal to *n*<=-<=1. The next line contains *m* space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=1000) and the following line contains *m* space-separated integers *s*1,<=*s*2,<=...,<=*s**m* (1<=≤<=*s**i*<=≤<=1000).
In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city *c**n* from city *c*1.
[ "4 6\n1 2 5 2\n2 3 3 4\n", "2 3\n5 6\n5 5\n" ]
[ "10\n", "14\n" ]
In the second sample above, the Old Peykan stays in *c*<sub class="lower-index">1</sub> for 3 hours.
[ { "input": "4 6\n1 2 5 2\n2 3 3 4", "output": "10" }, { "input": "2 3\n5 6\n5 5", "output": "14" }, { "input": "24 3\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3", "output": "862" }, { "input": "43 5\n6 7 15 12 15 7 22 33 38 15 7 23 31 21 26 41 25 14 26 33 5 28 22 6 35 17 19 32 41 27 20 25 5 32 37 19 40 9 25 22 10 24 9\n3 5 3 6 5 4 5 3 3 3 3 6 6 3 3 3 3 3 3 3 3 6 3 3 4 3 4 3 6 4 3 6 3 4 6 3 4 5 4 4 3 3 5", "output": "1566" }, { "input": "62 5\n12 12 10 7 27 7 32 15 33 3 23 13 24 30 32 22 21 31 27 27 37 7 5 31 19 16 10 20 24 32 36 42 33 14 41 8 13 3 8 8 12 27 36 15 24 17 23 33 31 5 32 17 14 41 37 31 23 31 41 23 36 12\n4 5 4 3 4 3 5 3 4 3 3 3 3 3 3 3 3 3 5 3 4 3 6 4 4 5 3 4 3 3 3 4 3 5 5 3 4 3 3 3 3 5 3 3 5 3 6 3 3 3 3 4 3 3 4 3 5 3 3 3 4 3", "output": "2406" }, { "input": "81 4\n15 20 14 10 39 4 26 8 8 30 13 43 7 7 4 6 23 42 24 35 12 19 21 31 5 20 8 17 25 31 8 31 9 14 29 35 39 35 19 13 35 11 24 3 22 3 22 41 26 32 17 42 21 16 15 44 12 5 16 20 19 38 15 11 36 14 6 21 5 27 15 40 6 9 32 33 35 4 10 15 26\n3 5 4 3 4 6 4 7 5 4 3 4 3 3 4 3 4 3 3 4 6 5 5 3 3 6 6 5 3 3 5 3 3 6 4 4 3 6 4 3 3 5 6 6 7 3 3 3 3 3 7 3 3 5 3 3 3 4 6 4 6 4 5 3 3 6 4 3 3 3 7 5 4 5 3 5 4 3 3 4 3", "output": "2419" }, { "input": "100 6\n15 20 32 8 29 10 33 15 9 26 28 21 34 7 41 23 9 17 16 15 14 29 25 31 24 26 13 18 19 40 9 16 36 32 39 11 4 31 37 28 32 40 7 18 45 21 15 45 6 15 27 22 27 41 28 7 22 43 25 40 6 7 32 31 36 14 5 27 31 28 23 9 13 14 7 25 28 33 40 22 44 9 29 26 41 30 16 15 31 42 13 40 36 44 17 29 32 29 38 13\n4 4 3 4 3 4 3 3 4 3 4 4 5 6 5 3 3 5 3 5 3 3 5 6 3 4 4 5 4 3 4 3 3 4 4 4 3 5 4 4 4 4 3 3 4 4 6 4 4 5 6 6 4 4 3 5 3 4 3 6 5 3 5 4 4 4 4 3 5 4 3 5 3 3 3 4 3 4 5 4 3 6 5 3 7 3 5 4 5 4 3 5 5 3 5 4 3 5 3 4", "output": "4491" } ]
92
0
0
9,339
656
Out of Controls
[ "*special" ]
null
null
You are given a complete undirected graph. For each pair of vertices you are given the length of the edge that connects them. Find the shortest paths between each pair of vertices in the graph and return the length of the longest of them.
The first line of the input contains a single integer *N* (3<=≤<=*N*<=≤<=10). The following *N* lines each contain *N* space-separated integers. *j*th integer in *i*th line *a**ij* is the length of the edge that connects vertices *i* and *j*. *a**ij*<==<=*a**ji*, *a**ii*<==<=0, 1<=≤<=*a**ij*<=≤<=100 for *i*<=≠<=*j*.
Output the maximum length of the shortest path between any pair of vertices in the graph.
[ "3\n0 1 1\n1 0 4\n1 4 0\n", "4\n0 1 2 3\n1 0 4 5\n2 4 0 6\n3 5 6 0\n" ]
[ "2\n", "5\n" ]
You're running short of keywords, so you can't use some of them:
[ { "input": "3\n0 1 1\n1 0 4\n1 4 0", "output": "2" }, { "input": "4\n0 1 2 3\n1 0 4 5\n2 4 0 6\n3 5 6 0", "output": "5" }, { "input": "10\n0 16 67 7 82 44 25 13 25 42\n16 0 24 37 63 20 19 87 55 99\n67 24 0 81 19 71 35 6 20 91\n7 37 81 0 82 89 34 80 7 32\n82 63 19 82 0 42 66 96 42 99\n44 20 71 89 42 0 65 94 24 45\n25 19 35 34 66 65 0 97 100 22\n13 87 6 80 96 94 97 0 10 58\n25 55 20 7 42 24 100 10 0 29\n42 99 91 32 99 45 22 58 29 0", "output": "64" }, { "input": "10\n0 1 1 1 1 1 1 1 1 100\n1 0 1 1 1 1 1 1 1 1\n1 1 0 1 1 1 1 1 1 1\n1 1 1 0 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1\n1 1 1 1 1 0 1 1 1 1\n1 1 1 1 1 1 0 1 1 1\n1 1 1 1 1 1 1 0 1 1\n1 1 1 1 1 1 1 1 0 1\n100 1 1 1 1 1 1 1 1 0", "output": "2" }, { "input": "10\n0 1 100 100 100 100 100 100 100 100\n1 0 1 100 100 100 100 100 100 100\n100 1 0 1 100 100 100 100 100 100\n100 100 1 0 1 100 100 100 100 100\n100 100 100 1 0 1 100 100 100 100\n100 100 100 100 1 0 1 100 100 100\n100 100 100 100 100 1 0 1 100 100\n100 100 100 100 100 100 1 0 1 100\n100 100 100 100 100 100 100 1 0 1\n100 100 100 100 100 100 100 100 1 0", "output": "9" }, { "input": "3\n0 1 1\n1 0 1\n1 1 0", "output": "1" }, { "input": "6\n0 74 60 92 18 86\n74 0 96 55 30 81\n60 96 0 6 28 30\n92 55 6 0 5 89\n18 30 28 5 0 11\n86 81 30 89 11 0", "output": "48" }, { "input": "6\n0 92 9 24 50 94\n92 0 70 73 57 87\n9 70 0 31 14 100\n24 73 31 0 66 25\n50 57 14 66 0 81\n94 87 100 25 81 0", "output": "87" }, { "input": "8\n0 6 39 40 67 19 77 93\n6 0 25 9 67 48 26 65\n39 25 0 72 62 45 26 88\n40 9 72 0 69 19 88 4\n67 67 62 69 0 2 51 1\n19 48 45 19 2 0 60 14\n77 26 26 88 51 60 0 1\n93 65 88 4 1 14 1 0", "output": "31" }, { "input": "6\n0 67 17 21 20 86\n67 0 32 80 24 36\n17 32 0 20 37 90\n21 80 20 0 58 98\n20 24 37 58 0 22\n86 36 90 98 22 0", "output": "63" }, { "input": "8\n0 12 11 41 75 73 22 1\n12 0 84 11 48 5 68 87\n11 84 0 85 87 64 14 5\n41 11 85 0 75 13 36 11\n75 48 87 75 0 41 15 14\n73 5 64 13 41 0 63 50\n22 68 14 36 15 63 0 90\n1 87 5 11 14 50 90 0", "output": "37" }, { "input": "4\n0 98 25 16\n98 0 89 1\n25 89 0 2\n16 1 2 0", "output": "18" }, { "input": "4\n0 59 70 47\n59 0 63 78\n70 63 0 93\n47 78 93 0", "output": "93" }, { "input": "10\n0 62 27 62 65 11 82 74 46 40\n62 0 8 11 15 28 83 3 14 26\n27 8 0 21 14 12 69 52 26 41\n62 11 21 0 34 35 9 71 100 15\n65 15 14 34 0 95 13 69 20 65\n11 28 12 35 95 0 35 19 57 40\n82 83 69 9 13 35 0 21 97 12\n74 3 52 71 69 19 21 0 82 62\n46 14 26 100 20 57 97 82 0 96\n40 26 41 15 65 40 12 62 96 0", "output": "46" }, { "input": "6\n0 45 91 95 34 82\n45 0 73 77 9 38\n91 73 0 61 74 71\n95 77 61 0 93 17\n34 9 74 93 0 73\n82 38 71 17 73 0", "output": "95" }, { "input": "9\n0 62 15 44 79 3 30 46 49\n62 0 79 42 86 71 78 68 98\n15 79 0 2 34 34 97 71 76\n44 42 2 0 11 76 4 64 25\n79 86 34 11 0 45 48 75 81\n3 71 34 76 45 0 73 5 40\n30 78 97 4 48 73 0 50 16\n46 68 71 64 75 5 50 0 14\n49 98 76 25 81 40 16 14 0", "output": "67" }, { "input": "9\n0 76 66 78 46 55 92 18 81\n76 0 99 62 23 53 45 41 10\n66 99 0 18 3 37 34 26 91\n78 62 18 0 98 36 59 5 27\n46 23 3 98 0 79 92 9 39\n55 53 37 36 79 0 89 60 25\n92 45 34 59 92 89 0 26 94\n18 41 26 5 9 60 26 0 19\n81 10 91 27 39 25 94 19 0", "output": "67" }, { "input": "10\n0 27 56 32 37 99 71 93 98 50\n27 0 21 57 7 77 88 40 90 81\n56 21 0 20 45 98 82 69 15 23\n32 57 20 0 15 74 72 95 49 56\n37 7 45 15 0 25 17 60 7 80\n99 77 98 74 25 0 80 62 31 63\n71 88 82 72 17 80 0 38 43 9\n93 40 69 95 60 62 38 0 7 53\n98 90 15 49 7 31 43 7 0 48\n50 81 23 56 80 63 9 53 48 0", "output": "59" }, { "input": "6\n0 41 81 77 80 79\n41 0 64 36 15 77\n81 64 0 36 89 40\n77 36 36 0 59 70\n80 15 89 59 0 90\n79 77 40 70 90 0", "output": "90" }, { "input": "3\n0 35 50\n35 0 28\n50 28 0", "output": "50" }, { "input": "8\n0 73 45 10 61 98 24 80\n73 0 47 29 65 96 46 36\n45 47 0 63 48 19 57 99\n10 29 63 0 11 13 79 84\n61 65 48 11 0 60 71 27\n98 96 19 13 60 0 41 44\n24 46 57 79 71 41 0 13\n80 36 99 84 27 44 13 0", "output": "63" }, { "input": "3\n0 72 17\n72 0 8\n17 8 0", "output": "25" }, { "input": "7\n0 50 95 10 100 75 71\n50 0 53 70 70 26 91\n95 53 0 16 33 90 98\n10 70 16 0 43 48 87\n100 70 33 43 0 63 34\n75 26 90 48 63 0 17\n71 91 98 87 34 17 0", "output": "71" }, { "input": "3\n0 86 45\n86 0 54\n45 54 0", "output": "86" }, { "input": "7\n0 67 86 9 33 16 99\n67 0 77 68 97 59 33\n86 77 0 37 11 83 99\n9 68 37 0 51 27 70\n33 97 11 51 0 32 91\n16 59 83 27 32 0 71\n99 33 99 70 91 71 0", "output": "99" }, { "input": "6\n0 41 48 86 94 14\n41 0 1 30 59 39\n48 1 0 9 31 49\n86 30 9 0 48 30\n94 59 31 48 0 33\n14 39 49 30 33 0", "output": "47" }, { "input": "6\n0 44 27 40 72 96\n44 0 87 1 83 45\n27 87 0 43 81 64\n40 1 43 0 89 90\n72 83 81 89 0 37\n96 45 64 90 37 0", "output": "86" }, { "input": "9\n0 89 47 24 63 68 12 27 61\n89 0 48 62 96 82 74 99 47\n47 48 0 72 63 47 25 95 72\n24 62 72 0 54 93 10 95 88\n63 96 63 54 0 19 6 18 3\n68 82 47 93 19 0 68 98 30\n12 74 25 10 6 68 0 21 88\n27 99 95 95 18 98 21 0 3\n61 47 72 88 3 30 88 3 0", "output": "69" }, { "input": "9\n0 83 88 2 30 55 89 28 96\n83 0 46 27 71 81 81 37 86\n88 46 0 11 28 55 7 71 31\n2 27 11 0 27 65 24 94 23\n30 71 28 27 0 16 57 18 88\n55 81 55 65 16 0 68 92 71\n89 81 7 24 57 68 0 29 70\n28 37 71 94 18 92 29 0 21\n96 86 31 23 88 71 70 21 0", "output": "70" }, { "input": "9\n0 29 71 8 12 39 50 26 21\n29 0 76 87 29 91 99 94 57\n71 76 0 74 12 38 24 46 49\n8 87 74 0 62 22 23 44 25\n12 29 12 62 0 97 38 47 39\n39 91 38 22 97 0 69 62 50\n50 99 24 23 38 69 0 4 75\n26 94 46 44 47 62 4 0 100\n21 57 49 25 39 50 75 100 0", "output": "59" }, { "input": "10\n0 65 97 17 34 86 3 22 92 98\n65 0 71 14 76 35 22 69 82 89\n97 71 0 58 6 62 45 100 76 14\n17 14 58 0 100 42 83 3 1 21\n34 76 6 100 0 15 90 77 69 32\n86 35 62 42 15 0 3 96 40 6\n3 22 45 83 90 3 0 65 28 87\n22 69 100 3 77 96 65 0 70 73\n92 82 76 1 69 40 28 70 0 39\n98 89 14 21 32 6 87 73 39 0", "output": "45" }, { "input": "8\n0 24 87 58 2 2 69 62\n24 0 58 43 98 29 18 33\n87 58 0 71 43 37 4 31\n58 43 71 0 30 77 19 46\n2 98 43 30 0 48 18 64\n2 29 37 77 48 0 57 77\n69 18 4 19 18 57 0 52\n62 33 31 46 64 77 52 0", "output": "57" }, { "input": "3\n0 99 73\n99 0 8\n73 8 0", "output": "81" }, { "input": "7\n0 41 2 49 25 23 43\n41 0 21 3 1 35 74\n2 21 0 63 45 6 55\n49 3 63 0 90 92 9\n25 1 45 90 0 11 11\n23 35 6 92 11 0 77\n43 74 55 9 11 77 0", "output": "30" }, { "input": "5\n0 92 34 49 44\n92 0 5 54 57\n34 5 0 8 24\n49 54 8 0 76\n44 57 24 76 0", "output": "44" }, { "input": "8\n0 25 9 7 32 10 42 77\n25 0 18 90 53 83 1 50\n9 18 0 21 12 83 68 79\n7 90 21 0 97 67 51 16\n32 53 12 97 0 83 29 6\n10 83 83 67 83 0 50 69\n42 1 68 51 29 50 0 70\n77 50 79 16 6 69 70 0", "output": "36" }, { "input": "5\n0 1 6 73 37\n1 0 4 29 76\n6 4 0 74 77\n73 29 74 0 45\n37 76 77 45 0", "output": "45" } ]
46
4,915,200
-1
9,350
0
none
[ "none" ]
null
null
You've gotten an *n*<=×<=*m* sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as *A*. Set *A* is connected. Your task is to find the minimum number of squares that we can delete from set *A* to make it not connected. A set of painted squares is called connected, if for every two squares *a* and *b* from this set there is a sequence of squares from the set, beginning in *a* and ending in *b*, such that in this sequence any square, except for the last one, shares a common side with the square that follows next in the sequence. An empty set and a set consisting of exactly one square are connected by definition.
The first input line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the sizes of the sheet of paper. Each of the next *n* lines contains *m* characters — the description of the sheet of paper: the *j*-th character of the *i*-th line equals either "#", if the corresponding square is painted (belongs to set *A*), or equals "." if the corresponding square is not painted (does not belong to set *A*). It is guaranteed that the set of all painted squares *A* is connected and isn't empty.
On the first line print the minimum number of squares that need to be deleted to make set *A* not connected. If it is impossible, print -1.
[ "5 4\n####\n#..#\n#..#\n#..#\n####\n", "5 5\n#####\n#...#\n#####\n#...#\n#####\n" ]
[ "2\n", "2\n" ]
In the first sample you can delete any two squares that do not share a side. After that the set of painted squares is not connected anymore. The note to the second sample is shown on the figure below. To the left there is a picture of the initial set of squares. To the right there is a set with deleted squares. The deleted squares are marked with crosses.
[ { "input": "5 4\n####\n#..#\n#..#\n#..#\n####", "output": "2" }, { "input": "5 5\n#####\n#...#\n#####\n#...#\n#####", "output": "2" }, { "input": "1 10\n.########.", "output": "1" }, { "input": "1 1\n#", "output": "-1" }, { "input": "3 3\n.#.\n###\n.#.", "output": "1" }, { "input": "1 2\n##", "output": "-1" }, { "input": "2 1\n#\n#", "output": "-1" }, { "input": "3 3\n###\n#.#\n###", "output": "2" }, { "input": "2 2\n##\n#.", "output": "1" }, { "input": "2 2\n##\n##", "output": "2" }, { "input": "2 2\n.#\n##", "output": "1" }, { "input": "2 2\n.#\n.#", "output": "-1" }, { "input": "9 9\n#########\n#.......#\n#.#####.#\n#.#.#.#.#\n#.#.#.#.#\n#.#.#.#.#\n#.#####.#\n#...#...#\n#########", "output": "1" }, { "input": "50 1\n#\n#\n#\n#\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.", "output": "1" }, { "input": "3 50\n....##############################################\n....#.......#...#..#....#..............#.........#\n....##############################################", "output": "2" }, { "input": "2 2\n##\n..", "output": "-1" }, { "input": "5 5\n#####\n#####\n#....\n#####\n#####", "output": "1" }, { "input": "3 5\n##.##\n#####\n##.##", "output": "1" }, { "input": "4 4\n####\n####\n####\n####", "output": "2" }, { "input": "5 7\n.#####.\n.#...#.\n###.###\n#.#.#.#\n###.###", "output": "1" }, { "input": "2 5\n#####\n##.##", "output": "1" }, { "input": "6 2\n##\n##\n#.\n##\n##\n##", "output": "1" }, { "input": "2 5\n##.##\n#####", "output": "1" }, { "input": "5 5\n#####\n#####\n##.##\n##.##\n##.##", "output": "2" }, { "input": "5 3\n###\n###\n.#.\n###\n###", "output": "1" }, { "input": "5 5\n###..\n###..\n#..##\n#####\n#####", "output": "1" } ]
2,000
30,515,200
0
9,383
768
Game of Stones
[ "bitmasks", "dp", "games" ]
null
null
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: - The game starts with *n* piles of stones indexed from 1 to *n*. The *i*-th pile contains *s**i* stones.- The players make their moves alternatively. A move is considered as removal of some number of stones from a pile. Removal of 0 stones does not count as a move.- The player who is unable to make a move loses. Now Jon believes that he is ready for battle, but Sam does not think so. To prove his argument, Sam suggested that they play a modified version of the game. In this modified version, no move can be made more than once on a pile. For example, if 4 stones are removed from a pile, 4 stones cannot be removed from that pile again. Sam sets up the game and makes the first move. Jon believes that Sam is just trying to prevent him from going to battle. Jon wants to know if he can win if both play optimally.
First line consists of a single integer *n* (1<=≤<=*n*<=≤<=106) — the number of piles. Each of next *n* lines contains an integer *s**i* (1<=≤<=*s**i*<=≤<=60) — the number of stones in *i*-th pile.
Print a single line containing "YES" (without quotes) if Jon wins, otherwise print "NO" (without quotes)
[ "1\n5\n", "2\n1\n2\n" ]
[ "NO", "YES" ]
In the first case, Sam removes all the stones and Jon loses. In second case, the following moves are possible by Sam: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/53b9c060b675da85f39a960b8ab29df7fe51f6e3.png" style="max-width: 100.0%;max-height: 100.0%;"/> In each of these cases, last move can be made by Jon to win the game as follows: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5089ff5bcdbeb10a07b0bf16566d6f4703e99334.png" style="max-width: 100.0%;max-height: 100.0%;"/>
[ { "input": "1\n5", "output": "NO" }, { "input": "2\n1\n2", "output": "YES" }, { "input": "3\n34\n44\n21", "output": "NO" }, { "input": "6\n34\n44\n21\n55\n1\n36", "output": "NO" }, { "input": "14\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32", "output": "NO" }, { "input": "10\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59", "output": "NO" }, { "input": "12\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40", "output": "NO" }, { "input": "118\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32\n43\n48\n16\n5\n35\n20\n21\n36\n15\n2\n11\n56\n58\n2\n40\n47\n29\n21\n4\n21\n1\n25\n51\n55\n17\n40\n56\n35\n51\n1\n34\n18\n54\n44\n1\n43\n16\n28\n21\n14\n57\n53\n29\n44\n59\n54\n47\n21\n43\n41\n11\n37\n30\n4\n39\n47\n40\n50\n52\n9\n32\n1\n19\n30\n20\n6\n25\n42\n34\n38\n42\n46\n35\n28\n20\n47\n60\n46\n35\n59\n24\n11\n25\n27\n9\n51\n39\n35\n22\n24\n10\n48\n6\n30\n10\n33\n51\n45\n38\n8\n51\n8\n7\n46", "output": "NO" }, { "input": "124\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32\n43\n48\n16\n5\n35\n20\n21\n36\n15\n2\n11\n56\n58\n2\n40\n47\n29\n21\n4\n21\n1\n25\n51\n55\n17\n40\n56\n35\n51\n1\n34\n18\n54\n44\n1\n43\n16\n28\n21\n14\n57\n53\n29\n44\n59\n54\n47\n21\n43\n41\n11\n37\n30\n4\n39\n47\n40\n50\n52\n9\n32\n1\n19\n30\n20\n6\n25\n42\n34\n38\n42\n46\n35\n28\n20\n47\n60\n46\n35\n59\n24\n11\n25\n27\n9\n51\n39\n35\n22\n24\n10\n48\n6\n30\n10\n33\n51\n45\n38\n8\n51\n8\n7\n46\n49\n27\n16\n13\n4\n54", "output": "NO" }, { "input": "15\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32\n43", "output": "NO" }, { "input": "2\n34\n44", "output": "NO" } ]
3,000
10,956,800
0
9,385
0
none
[ "none" ]
null
null
Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams! Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to invite them to go to a cafe so that each of them could drink a bottle of... fresh cow milk. Having entered the cafe, the *m* friends found *n* different kinds of milk on the menu, that's why they ordered *n* bottles — one bottle of each kind. We know that the volume of milk in each bottle equals *w*. When the bottles were brought in, they decided to pour all the milk evenly among the *m* cups, so that each got a cup. As a punishment for not passing the test Igor was appointed the person to pour the milk. He protested that he was afraid to mix something up and suggested to distribute the drink so that the milk from each bottle was in no more than two different cups. His friends agreed but they suddenly faced the following problem — and what is actually the way to do it? Help them and write the program that will help to distribute the milk among the cups and drink it as quickly as possible! Note that due to Igor K.'s perfectly accurate eye and unswerving hands, he can pour any fractional amount of milk from any bottle to any cup.
The only input data file contains three integers *n*, *w* and *m* (1<=≤<=*n*<=≤<=50, 100<=≤<=*w*<=≤<=1000, 2<=≤<=*m*<=≤<=50), where *n* stands for the number of ordered bottles, *w* stands for the volume of each of them and *m* stands for the number of friends in the company.
Print on the first line "YES" if it is possible to pour the milk so that the milk from each bottle was in no more than two different cups. If there's no solution, print "NO". If there is a solution, then print *m* more lines, where the *i*-th of them describes the content of the *i*-th student's cup. The line should consist of one or more pairs that would look like "*b* *v*". Each such pair means that *v* (*v*<=&gt;<=0) units of milk were poured into the *i*-th cup from bottle *b* (1<=≤<=*b*<=≤<=*n*). All numbers *b* on each line should be different. If there are several variants to solve the problem, print any of them. Print the real numbers with no less than 6 digits after the decimal point.
[ "2 500 3\n", "4 100 5\n", "4 100 7\n", "5 500 2\n" ]
[ "YES\n1 333.333333\n2 333.333333\n2 166.666667 1 166.666667\n", "YES\n3 20.000000 4 60.000000\n1 80.000000\n4 40.000000 2 40.000000\n3 80.000000\n2 60.000000 1 20.000000\n", "NO\n", "YES\n4 250.000000 5 500.000000 2 500.000000\n3 500.000000 1 500.000000 4 250.000000\n" ]
none
[ { "input": "2 500 3", "output": "YES\n1 333.333333\n2 333.333333\n2 166.666667 1 166.666667" }, { "input": "4 100 5", "output": "YES\n3 20.000000 4 60.000000\n1 80.000000\n4 40.000000 2 40.000000\n3 80.000000\n2 60.000000 1 20.000000" }, { "input": "4 100 7", "output": "NO" }, { "input": "5 500 2", "output": "YES\n4 250.000000 5 500.000000 2 500.000000\n3 500.000000 1 500.000000 4 250.000000" }, { "input": "4 100 8", "output": "YES\n3 50.000000\n1 50.000000\n2 50.000000\n4 50.000000\n1 50.000000\n3 50.000000\n2 50.000000\n4 50.000000" }, { "input": "1 1000 2", "output": "YES\n1 500.000000\n1 500.000000" }, { "input": "2 500 4", "output": "YES\n2 250.000000\n2 250.000000\n1 250.000000\n1 250.000000" }, { "input": "2 500 5", "output": "NO" }, { "input": "9 1000 12", "output": "YES\n3 750.000000\n6 750.000000\n7 250.000000 2 500.000000\n5 750.000000\n9 250.000000 2 500.000000\n4 500.000000 8 250.000000\n6 250.000000 1 500.000000\n4 500.000000 5 250.000000\n7 750.000000\n8 750.000000\n1 500.000000 3 250.000000\n9 750.000000" }, { "input": "20 1000 30", "output": "YES\n5 666.666667\n18 666.666667\n19 666.666667\n9 333.333333 18 333.333333\n14 666.666667\n1 666.666667\n20 333.333333 8 333.333333\n2 666.666667\n1 333.333333 12 333.333333\n12 666.666667\n8 666.666667\n16 666.666667\n16 333.333333 5 333.333333\n10 666.666667\n20 666.666667\n4 666.666667\n9 666.666667\n4 333.333333 7 333.333333\n13 333.333333 2 333.333333\n15 333.333333 14 333.333333\n6 666.666667\n19 333.333333 6 333.333333\n7 666.666667\n3 666.666667\n11 333.333333 17 333.333333\n15 666.666667\n10 333...." }, { "input": "50 1000 50", "output": "YES\n50 1000.000000\n46 1000.000000\n15 1000.000000\n32 1000.000000\n11 1000.000000\n24 1000.000000\n12 1000.000000\n16 1000.000000\n1 1000.000000\n36 1000.000000\n40 1000.000000\n25 1000.000000\n2 1000.000000\n44 1000.000000\n33 1000.000000\n31 1000.000000\n38 1000.000000\n47 1000.000000\n30 1000.000000\n34 1000.000000\n19 1000.000000\n5 1000.000000\n4 1000.000000\n42 1000.000000\n49 1000.000000\n35 1000.000000\n27 1000.000000\n43 1000.000000\n22 1000.000000\n8 1000.000000\n28 1000.000000\n37 1000.000000\n..." }, { "input": "50 1000 49", "output": "YES\n1 81.632653 50 938.775510\n46 816.326531 19 204.081633\n15 142.857143 14 877.551020\n32 857.142857 30 163.265306\n11 306.122449 40 714.285714\n24 714.285714 34 306.122449\n6 571.428571 12 448.979592\n29 938.775510 16 81.632653\n28 102.040816 1 918.367347\n36 326.530612 11 693.877551\n26 734.693878 40 285.714286\n25 102.040816 16 918.367347\n10 40.816327 2 979.591837\n44 224.489796 17 795.918367\n33 755.102041 41 265.306122\n8 510.204082 31 510.204082\n15 857.142857 38 163.265306\n33 244.897959 47 775...." }, { "input": "49 1000 50", "output": "YES\n40 280.000000 11 700.000000\n19 220.000000 47 760.000000\n13 20.000000 2 960.000000\n30 180.000000 46 800.000000\n15 860.000000 14 120.000000\n35 480.000000 31 500.000000\n17 200.000000 44 780.000000\n30 820.000000 32 160.000000\n3 380.000000 5 600.000000\n3 620.000000 22 360.000000\n12 440.000000 7 540.000000\n40 720.000000 26 260.000000\n10 940.000000 2 40.000000\n1 100.000000 28 880.000000\n23 460.000000 35 520.000000\n32 840.000000 37 140.000000\n16 80.000000 25 900.000000\n20 40.000000 29 940.000..." }, { "input": "40 1000 50", "output": "YES\n12 800.000000\n34 800.000000\n35 800.000000\n26 200.000000 4 600.000000\n16 600.000000 30 200.000000\n12 200.000000 7 600.000000\n20 400.000000 23 400.000000\n24 400.000000 39 400.000000\n27 200.000000 38 600.000000\n40 800.000000\n1 200.000000 28 600.000000\n18 200.000000 21 600.000000\n25 800.000000\n31 800.000000\n2 600.000000 13 200.000000\n18 800.000000\n10 400.000000 2 400.000000\n14 600.000000 17 200.000000\n9 200.000000 20 600.000000\n27 800.000000\n15 200.000000 36 600.000000\n36 400.000000 1..." }, { "input": "48 1000 50", "output": "YES\n20 40.000000 29 920.000000\n24 400.000000 41 560.000000\n6 200.000000 5 760.000000\n42 720.000000 21 240.000000\n40 480.000000 26 480.000000\n44 600.000000 17 360.000000\n3 280.000000 22 680.000000\n1 800.000000 45 160.000000\n41 440.000000 33 520.000000\n25 160.000000 14 800.000000\n7 120.000000 12 840.000000\n34 360.000000 24 600.000000\n22 320.000000 43 640.000000\n23 80.000000 48 880.000000\n31 40.000000 8 920.000000\n31 960.000000\n23 920.000000 35 40.000000\n45 840.000000 10 120.000000\n30 640.0..." }, { "input": "45 1000 50", "output": "YES\n15 700.000000 14 200.000000\n14 800.000000 25 100.000000\n12 900.000000\n32 200.000000 37 700.000000\n40 900.000000\n5 700.000000 6 200.000000\n8 200.000000 31 700.000000\n13 100.000000 2 800.000000\n1 500.000000 28 400.000000\n41 500.000000 24 400.000000\n42 900.000000\n2 200.000000 10 700.000000\n5 300.000000 3 600.000000\n34 300.000000 24 600.000000\n42 100.000000 27 800.000000\n44 700.000000 4 200.000000\n9 300.000000 20 600.000000\n23 500.000000 20 400.000000\n12 100.000000 6 800.000000\n16 900.0..." }, { "input": "30 1000 40", "output": "YES\n7 250.000000 8 500.000000\n11 250.000000 23 500.000000\n14 500.000000 15 250.000000\n18 500.000000 9 250.000000\n27 500.000000 17 250.000000\n13 750.000000\n7 750.000000\n3 750.000000\n17 750.000000\n3 250.000000 8 500.000000\n6 500.000000 12 250.000000\n24 750.000000\n21 750.000000\n29 750.000000\n10 750.000000\n1 500.000000 25 250.000000\n28 250.000000 1 500.000000\n27 500.000000 4 250.000000\n19 500.000000 29 250.000000\n19 500.000000 16 250.000000\n4 750.000000\n20 250.000000 23 500.000000\n5 750...." }, { "input": "20 1000 25", "output": "YES\n16 400.000000 19 400.000000\n13 800.000000\n15 800.000000\n9 600.000000 18 200.000000\n7 800.000000\n12 600.000000 1 200.000000\n5 800.000000\n2 400.000000 10 400.000000\n12 400.000000 8 400.000000\n8 600.000000 20 200.000000\n20 800.000000\n6 800.000000\n6 200.000000 19 600.000000\n10 600.000000 3 200.000000\n16 600.000000 5 200.000000\n3 800.000000\n4 600.000000 7 200.000000\n11 600.000000 17 200.000000\n13 200.000000 2 600.000000\n17 800.000000\n14 400.000000 11 400.000000\n15 200.000000 14 600.000..." }, { "input": "21 1000 27", "output": "NO" }, { "input": "21 1000 28", "output": "YES\n2 500.000000 10 250.000000\n16 250.000000 19 500.000000\n4 750.000000\n17 750.000000\n1 500.000000 3 250.000000\n15 750.000000\n7 500.000000 4 250.000000\n5 250.000000 20 500.000000\n21 750.000000\n12 750.000000\n13 750.000000\n5 750.000000\n3 750.000000\n6 750.000000\n16 750.000000\n7 500.000000 17 250.000000\n8 750.000000\n15 250.000000 14 500.000000\n19 500.000000 6 250.000000\n21 250.000000 18 500.000000\n18 500.000000 9 250.000000\n9 750.000000\n1 500.000000 12 250.000000\n10 750.000000\n8 250.00..." }, { "input": "21 1000 29", "output": "NO" }, { "input": "22 1000 30", "output": "NO" }, { "input": "3 356 14", "output": "NO" }, { "input": "9 120 13", "output": "NO" }, { "input": "1 301 20", "output": "NO" }, { "input": "11 489 14", "output": "NO" }, { "input": "6 218 16", "output": "NO" }, { "input": "2 632 19", "output": "NO" }, { "input": "14 157 19", "output": "NO" }, { "input": "12 430 14", "output": "YES\n9 122.857143 7 245.714286\n1 122.857143 3 245.714286\n9 307.142857 6 61.428571\n4 307.142857 8 61.428571\n10 245.714286 2 122.857143\n1 307.142857 12 61.428571\n4 122.857143 5 245.714286\n7 184.285714 5 184.285714\n10 184.285714 3 184.285714\n8 368.571429\n12 368.571429\n11 368.571429\n2 307.142857 11 61.428571\n6 368.571429" }, { "input": "16 980 19", "output": "NO" }, { "input": "1 736 10", "output": "NO" }, { "input": "4 650 19", "output": "NO" }, { "input": "3 953 13", "output": "NO" }, { "input": "10 524 8", "output": "YES\n4 262.000000 5 393.000000\n8 131.000000 6 524.000000\n10 262.000000 3 393.000000\n7 524.000000 5 131.000000\n3 131.000000 1 524.000000\n2 131.000000 9 524.000000\n10 262.000000 2 393.000000\n8 393.000000 4 262.000000" }, { "input": "6 283 11", "output": "NO" }, { "input": "5 825 16", "output": "NO" }, { "input": "13 557 13", "output": "YES\n5 557.000000\n7 557.000000\n6 557.000000\n4 557.000000\n3 557.000000\n1 557.000000\n10 557.000000\n9 557.000000\n8 557.000000\n12 557.000000\n11 557.000000\n13 557.000000\n2 557.000000" }, { "input": "13 503 9", "output": "YES\n6 223.555556 11 503.000000\n5 335.333333 4 391.222222\n2 223.555556 13 503.000000\n9 447.111111 6 279.444444\n12 391.222222 1 335.333333\n4 111.777778 12 111.777778 8 503.000000\n3 503.000000 10 55.888889 1 167.666667\n2 279.444444 10 447.111111\n9 55.888889 7 503.000000 5 167.666667" }, { "input": "12 255 8", "output": "YES\n11 255.000000 2 127.500000\n4 127.500000 8 255.000000\n2 127.500000 10 255.000000\n12 255.000000 1 127.500000\n1 127.500000 3 255.000000\n4 127.500000 5 255.000000\n6 255.000000 9 127.500000\n9 127.500000 7 255.000000" }, { "input": "11 827 13", "output": "NO" }, { "input": "4 381 16", "output": "NO" }, { "input": "18 624 32", "output": "NO" }, { "input": "30 864 48", "output": "NO" }, { "input": "26 637 16", "output": "YES\n26 318.500000 12 637.000000 1 79.625000\n6 238.875000 16 159.250000 19 637.000000\n14 637.000000 24 398.125000\n5 79.625000 26 318.500000 22 637.000000\n4 79.625000 21 637.000000 18 318.500000\n9 637.000000 18 318.500000 20 79.625000\n8 637.000000 3 398.125000\n23 477.750000 20 557.375000\n7 159.250000 17 637.000000 24 238.875000\n2 238.875000 10 637.000000 25 159.250000\n23 159.250000 3 238.875000 11 637.000000\n1 557.375000 25 477.750000\n16 477.750000 5 557.375000\n13 637.000000 2 398.125000\n4 557..." }, { "input": "13 322 43", "output": "NO" }, { "input": "12 792 38", "output": "NO" }, { "input": "30 628 23", "output": "YES\n19 273.043478 16 546.086957\n26 327.652174 28 491.478261\n23 518.782609 11 300.347826\n10 245.739130 25 573.391304\n12 382.260870 6 436.869565\n13 628.000000 2 191.130435\n24 409.565217 17 409.565217\n14 600.695652 24 218.434783\n12 245.739130 7 573.391304\n15 628.000000 29 163.826087 14 27.304348\n23 109.217391 9 81.913043 20 628.000000\n8 628.000000 7 54.608696 3 136.521739\n27 600.695652 17 218.434783\n9 546.086957 18 273.043478\n1 628.000000 28 136.521739 25 54.608696\n22 518.782609 26 300.347826\n..." }, { "input": "2 190 29", "output": "NO" }, { "input": "33 353 40", "output": "NO" }, { "input": "21 608 35", "output": "NO" }, { "input": "46 328 27", "output": "YES\n9 182.222222 20 328.000000 23 48.592593\n4 170.074074 17 60.740741 44 328.000000\n25 97.185185 15 133.629630 14 328.000000\n30 170.074074 32 328.000000 37 60.740741\n8 182.222222 35 48.592593 31 328.000000\n28 291.555556 37 267.259259\n21 242.962963 42 315.851852\n9 145.777778 21 85.037037 18 328.000000\n6 315.851852 12 242.962963\n29 303.703704 19 255.111111\n26 328.000000 40 72.888889 4 157.925926\n3 218.666667 6 12.148148 5 328.000000\n45 194.370370 1 328.000000 28 36.444444\n34 218.666667 27 328.0..." }, { "input": "44 371 47", "output": "NO" }, { "input": "9 615 50", "output": "NO" }, { "input": "4 574 9", "output": "NO" }, { "input": "13 751 24", "output": "NO" }, { "input": "5 556 43", "output": "NO" }, { "input": "2 449 45", "output": "NO" }, { "input": "21 665 45", "output": "NO" }, { "input": "26 905 31", "output": "NO" }, { "input": "26 856 49", "output": "NO" }, { "input": "6 804 32", "output": "NO" }, { "input": "15 737 26", "output": "NO" }, { "input": "35 462 50", "output": "NO" }, { "input": "34 948 42", "output": "NO" }, { "input": "9 929 41", "output": "NO" }, { "input": "11 324 24", "output": "NO" }, { "input": "2 227 11", "output": "NO" }, { "input": "3 606 41", "output": "NO" }, { "input": "21 452 43", "output": "NO" }, { "input": "19 134 48", "output": "NO" }, { "input": "28 595 48", "output": "NO" }, { "input": "36 371 42", "output": "YES\n5 53.000000 6 265.000000\n34 212.000000 27 106.000000\n26 53.000000 32 265.000000\n4 318.000000\n3 318.000000\n31 318.000000\n18 265.000000 21 53.000000\n30 159.000000 16 159.000000\n33 318.000000\n36 212.000000 11 106.000000\n28 318.000000\n35 318.000000\n8 265.000000 31 53.000000\n24 212.000000 14 106.000000\n5 318.000000\n2 265.000000 13 53.000000\n17 53.000000 11 265.000000\n36 159.000000 15 159.000000\n13 318.000000\n19 106.000000 16 212.000000\n17 318.000000\n18 106.000000 9 212.000000\n25 159.0..." }, { "input": "23 511 24", "output": "YES\n7 149.041667 17 340.666667\n16 212.916667 19 276.791667\n3 85.166667 1 404.541667\n21 404.541667 18 85.166667\n2 468.416667 13 21.291667\n22 170.333333 5 319.375000\n22 340.666667 8 149.041667\n4 127.750000 7 361.958333\n12 127.750000 8 361.958333\n23 489.708333\n13 489.708333\n19 234.208333 6 255.500000\n5 191.625000 16 298.083333\n6 255.500000 15 234.208333\n4 383.250000 21 106.458333\n1 106.458333 12 383.250000\n20 42.583333 9 447.125000\n11 191.625000 14 298.083333\n18 425.833333 9 63.875000\n23 2..." }, { "input": "24 836 25", "output": "YES\n13 802.560000\n17 535.040000 7 267.520000\n14 468.160000 24 334.400000\n2 769.120000 13 33.440000\n15 434.720000 14 367.840000\n3 702.240000 10 100.320000\n6 434.720000 19 367.840000\n8 234.080000 22 568.480000\n23 769.120000 11 33.440000\n20 735.680000 23 66.880000\n6 401.280000 15 401.280000\n18 668.800000 9 133.760000\n7 568.480000 4 234.080000\n21 200.640000 4 601.920000\n5 535.040000 22 267.520000\n5 300.960000 16 501.600000\n11 802.560000\n20 100.320000 9 702.240000\n10 735.680000 2 66.880000\n1..." }, { "input": "28 380 29", "output": "YES\n18 262.068966 9 104.827586\n28 78.620690 26 288.275862\n5 117.931034 16 248.965517\n4 235.862069 21 131.034483\n11 65.517241 23 301.379310\n15 209.655172 6 157.241379\n3 327.586207 8 39.310345\n6 222.758621 19 144.137931\n27 157.241379 17 209.655172\n23 78.620690 20 288.275862\n14 196.551724 15 170.344828\n20 91.724138 9 275.172414\n2 353.793103 13 13.103448\n10 340.689655 2 26.206897\n13 366.896552\n25 327.586207 10 39.310345\n24 183.448276 14 183.448276\n24 196.551724 17 170.344828\n4 144.137931 27 ..." }, { "input": "24 704 30", "output": "YES\n13 563.200000\n14 422.400000 15 140.800000\n6 563.200000\n13 140.800000 2 422.400000\n19 422.400000 6 140.800000\n10 422.400000 3 140.800000\n5 140.800000 16 422.400000\n12 281.600000 8 281.600000\n20 281.600000 23 281.600000\n21 281.600000 4 281.600000\n19 281.600000 16 281.600000\n9 140.800000 20 422.400000\n24 281.600000 14 281.600000\n17 140.800000 24 422.400000\n11 563.200000\n9 563.200000\n18 563.200000\n4 422.400000 7 140.800000\n10 281.600000 2 281.600000\n15 563.200000\n17 563.200000\n12 422...." }, { "input": "30 565 40", "output": "YES\n7 141.250000 8 282.500000\n11 141.250000 23 282.500000\n14 282.500000 15 141.250000\n18 282.500000 9 141.250000\n27 282.500000 17 141.250000\n13 423.750000\n7 423.750000\n3 423.750000\n17 423.750000\n3 141.250000 8 282.500000\n6 282.500000 12 141.250000\n24 423.750000\n21 423.750000\n29 423.750000\n10 423.750000\n1 282.500000 25 141.250000\n28 141.250000 1 282.500000\n27 282.500000 4 141.250000\n19 282.500000 29 141.250000\n19 282.500000 16 141.250000\n4 423.750000\n20 141.250000 23 282.500000\n5 423...." }, { "input": "35 948 42", "output": "YES\n7 632.000000 8 158.000000\n33 474.000000 29 316.000000\n21 632.000000 18 158.000000\n28 790.000000\n3 790.000000\n17 632.000000 11 158.000000\n16 158.000000 30 632.000000\n19 158.000000 29 632.000000\n10 474.000000 25 316.000000\n16 790.000000\n11 790.000000\n18 790.000000\n32 474.000000 26 316.000000\n8 790.000000\n1 790.000000\n15 474.000000 22 316.000000\n9 790.000000\n5 158.000000 6 632.000000\n4 474.000000 27 316.000000\n31 158.000000 35 632.000000\n31 790.000000\n20 632.000000 9 158.000000\n20 3..." }, { "input": "6 578 9", "output": "YES\n1 385.333333\n1 192.666667 6 192.666667\n3 385.333333\n5 192.666667 2 192.666667\n4 385.333333\n4 192.666667 3 192.666667\n2 385.333333\n6 385.333333\n5 385.333333" }, { "input": "24 619 28", "output": "YES\n13 530.571429\n14 176.857143 24 353.714286\n15 530.571429\n2 442.142857 13 88.428571\n6 530.571429\n3 265.285714 10 265.285714\n16 353.714286 19 176.857143\n8 530.571429\n11 530.571429\n21 88.428571 18 442.142857\n19 442.142857 6 88.428571\n23 442.142857 11 88.428571\n24 265.285714 17 265.285714\n17 353.714286 7 176.857143\n22 442.142857 8 88.428571\n23 176.857143 20 353.714286\n9 265.285714 20 265.285714\n21 530.571429\n10 353.714286 2 176.857143\n14 442.142857 15 88.428571\n4 88.428571 7 442.142857\n..." }, { "input": "30 986 32", "output": "YES\n22 493.000000 26 431.375000\n6 862.750000 5 61.625000\n27 862.750000 17 61.625000\n8 308.125000 3 616.250000\n9 616.250000 18 308.125000\n13 924.375000\n29 246.500000 19 677.875000\n7 246.500000 8 677.875000\n18 677.875000 21 246.500000\n16 369.750000 30 554.625000\n5 924.375000\n21 739.500000 4 184.875000\n11 431.375000 23 493.000000\n24 924.375000\n10 184.875000 25 739.500000\n28 616.250000 1 308.125000\n28 369.750000 26 554.625000\n20 554.625000 9 369.750000\n24 61.625000 14 862.750000\n14 123.2500..." }, { "input": "26 381 28", "output": "YES\n9 163.285714 18 190.500000\n12 163.285714 26 190.500000\n22 217.714286 5 136.071429\n23 272.142857 11 81.642857\n11 299.357143 3 54.428571\n3 326.571429 8 27.214286\n14 27.214286 24 326.571429\n23 108.857143 20 244.928571\n8 353.785714\n2 326.571429 13 27.214286\n7 108.857143 4 244.928571\n10 299.357143 2 54.428571\n18 190.500000 21 163.285714\n21 217.714286 4 136.071429\n19 81.642857 16 272.142857\n7 272.142857 17 81.642857\n15 353.785714\n22 163.285714 26 190.500000\n14 353.785714\n13 353.785714\n12..." }, { "input": "24 743 32", "output": "YES\n13 557.250000\n15 557.250000\n19 371.500000 6 185.750000\n13 185.750000 2 371.500000\n16 185.750000 19 371.500000\n10 557.250000\n5 557.250000\n12 557.250000\n9 557.250000\n7 371.500000 4 185.750000\n16 557.250000\n18 371.500000 9 185.750000\n14 371.500000 15 185.750000\n24 185.750000 14 371.500000\n20 185.750000 23 371.500000\n18 371.500000 21 185.750000\n21 557.250000\n7 371.500000 17 185.750000\n10 185.750000 2 371.500000\n11 185.750000 23 371.500000\n24 557.250000\n11 557.250000\n5 185.750000 22 3..." }, { "input": "24 459 27", "output": "YES\n13 408.000000\n17 51.000000 24 357.000000\n15 255.000000 14 153.000000\n2 357.000000 13 51.000000\n15 204.000000 6 204.000000\n10 153.000000 3 255.000000\n16 102.000000 19 306.000000\n8 357.000000 22 51.000000\n9 255.000000 20 153.000000\n18 204.000000 9 204.000000\n19 153.000000 6 255.000000\n11 408.000000\n17 408.000000\n7 408.000000\n22 408.000000\n11 51.000000 23 357.000000\n23 102.000000 20 306.000000\n21 153.000000 18 255.000000\n10 306.000000 2 102.000000\n24 102.000000 14 306.000000\n4 357.000..." }, { "input": "25 531 26", "output": "YES\n7 183.807692 17 326.769231\n5 183.807692 16 326.769231\n18 122.538462 21 388.038462\n10 469.730769 2 40.846154\n4 367.615385 21 142.961538\n15 265.500000 14 245.076923\n25 81.692308 1 428.884615\n9 428.884615 20 81.692308\n13 20.423077 2 490.153846\n18 408.461538 9 102.115385\n19 306.346154 16 204.230769\n3 20.423077 11 490.153846\n19 224.653846 6 285.923077\n13 510.576923\n25 449.307692 10 61.269231\n8 388.038462 12 122.538462\n5 347.192308 22 163.384615\n3 510.576923\n23 61.269231 20 449.307692\n12 ..." }, { "input": "40 897 42", "output": "YES\n15 555.285714 36 299.000000\n21 811.571429 18 42.714286\n6 512.571429 12 341.714286\n30 512.571429 32 341.714286\n29 384.428571 19 469.857143\n15 341.714286 22 512.571429\n7 598.000000 8 256.285714\n38 128.142857 27 726.142857\n9 854.285714\n13 854.285714\n28 256.285714 37 598.000000\n23 768.857143 20 85.428571\n1 683.428571 25 170.857143\n6 384.428571 5 469.857143\n2 811.571429 13 42.714286\n23 128.142857 35 726.142857\n2 85.428571 10 768.857143\n24 256.285714 39 598.000000\n8 640.714286 31 213.57142..." }, { "input": "24 371 26", "output": "YES\n13 342.461538\n24 85.615385 17 256.846154\n14 313.923077 15 28.538462\n13 28.538462 2 313.923077\n15 342.461538\n3 256.846154 10 85.615385\n6 28.538462 19 313.923077\n8 199.769231 22 142.692308\n20 285.384615 23 57.076923\n9 256.846154 20 85.615385\n6 342.461538\n21 199.769231 18 142.692308\n17 114.153846 7 228.307692\n7 142.692308 4 199.769231\n5 114.153846 22 228.307692\n11 342.461538\n11 28.538462 23 313.923077\n18 228.307692 9 114.153846\n10 285.384615 2 57.076923\n24 285.384615 14 57.076923\n21 1..." }, { "input": "18 169 20", "output": "YES\n17 118.300000 7 33.800000\n6 50.700000 15 101.400000\n15 67.600000 14 84.500000\n8 50.700000 12 101.400000\n18 135.200000 5 16.900000\n10 50.700000 3 101.400000\n10 118.300000 2 33.800000\n7 135.200000 4 16.900000\n16 16.900000 9 135.200000\n2 135.200000 13 16.900000\n9 33.800000 6 118.300000\n16 152.100000\n4 152.100000\n8 118.300000 18 33.800000\n14 84.500000 11 67.600000\n17 50.700000 11 101.400000\n5 152.100000\n1 84.500000 12 67.600000\n1 84.500000 3 67.600000\n13 152.100000" }, { "input": "24 264 25", "output": "YES\n13 253.440000\n17 168.960000 7 84.480000\n14 147.840000 24 105.600000\n2 242.880000 13 10.560000\n15 137.280000 14 116.160000\n3 221.760000 10 31.680000\n6 137.280000 19 116.160000\n8 73.920000 22 179.520000\n23 242.880000 11 10.560000\n20 232.320000 23 21.120000\n6 126.720000 15 126.720000\n18 211.200000 9 42.240000\n7 179.520000 4 73.920000\n21 63.360000 4 190.080000\n5 168.960000 22 84.480000\n5 95.040000 16 158.400000\n11 253.440000\n20 31.680000 9 221.760000\n10 232.320000 2 21.120000\n17 95.0400..." }, { "input": "27 884 28", "output": "YES\n6 378.857143 15 473.571429\n13 31.571429 2 820.857143\n18 631.428571 9 221.000000\n26 221.000000 22 631.428571\n13 852.428571\n23 726.142857 11 126.285714\n20 694.571429 23 157.857143\n10 789.285714 2 63.142857\n1 726.142857 25 126.285714\n4 568.285714 21 284.142857\n25 757.714286 10 94.714286\n27 347.285714 17 505.142857\n5 599.857143 22 252.571429\n18 252.571429 21 599.857143\n7 852.428571\n8 63.142857 3 789.285714\n14 442.000000 15 410.428571\n19 536.714286 16 315.714286\n3 94.714286 11 757.714286\n..." }, { "input": "18 922 21", "output": "YES\n11 395.142857 17 395.142857\n6 790.285714\n15 790.285714\n12 790.285714\n8 131.714286 18 658.571429\n4 790.285714\n10 526.857143 2 263.428571\n17 526.857143 7 263.428571\n16 526.857143 9 263.428571\n2 658.571429 13 131.714286\n9 658.571429 6 131.714286\n5 395.142857 16 395.142857\n4 131.714286 7 658.571429\n8 790.285714\n15 131.714286 14 658.571429\n14 263.428571 11 526.857143\n18 263.428571 5 526.857143\n12 131.714286 1 658.571429\n3 526.857143 1 263.428571\n13 790.285714\n3 395.142857 10 395.142857\n..." }, { "input": "37 772 38", "output": "YES\n16 203.157895 19 548.526316\n35 284.421053 23 467.263158\n27 426.631579 34 325.052632\n11 60.947368 36 690.736842\n28 121.894737 37 629.789474\n5 609.473684 3 142.210526\n26 751.684211\n9 345.368421 18 406.315789\n10 60.947368 25 690.736842\n19 223.473684 29 528.210526\n4 406.315789 27 345.368421\n7 223.473684 8 528.210526\n23 304.736842 20 446.947368\n24 467.263158 14 284.421053\n26 20.315789 17 731.368421\n6 182.842105 12 568.842105\n3 629.789474 22 121.894737\n18 365.684211 21 386.000000\n5 162.526..." }, { "input": "32 610 40", "output": "YES\n17 122.000000 24 366.000000\n13 488.000000\n9 122.000000 20 366.000000\n29 488.000000\n30 488.000000\n19 244.000000 16 244.000000\n7 366.000000 12 122.000000\n24 244.000000 14 244.000000\n22 488.000000\n31 488.000000\n6 488.000000\n27 488.000000\n3 244.000000 5 244.000000\n1 488.000000\n7 244.000000 8 244.000000\n9 488.000000\n28 244.000000 26 244.000000\n26 366.000000 32 122.000000\n2 366.000000 13 122.000000\n15 488.000000\n15 122.000000 14 366.000000\n21 366.000000 18 122.000000\n25 122.000000 10 3..." }, { "input": "22 771 23", "output": "YES\n13 33.521739 2 703.956522\n7 569.869565 4 167.608696\n14 301.695652 15 435.782609\n6 402.260870 15 335.217391\n8 234.652174 22 502.826087\n5 301.695652 16 435.782609\n6 368.739130 19 368.739130\n9 703.956522 20 33.521739\n17 234.652174 11 502.826087\n11 268.173913 14 469.304348\n3 134.086957 1 603.391304\n4 603.391304 21 134.086957\n13 737.478261\n16 335.217391 19 402.260870\n21 636.913043 18 100.565217\n22 268.173913 5 469.304348\n12 201.130435 8 536.347826\n9 67.043478 18 670.434783\n10 670.434783 2..." }, { "input": "22 792 24", "output": "YES\n13 66.000000 2 660.000000\n7 396.000000 17 330.000000\n6 66.000000 15 660.000000\n6 726.000000\n8 462.000000 22 264.000000\n5 594.000000 16 132.000000\n19 726.000000\n9 132.000000 18 594.000000\n14 198.000000 11 528.000000\n14 594.000000 15 132.000000\n1 462.000000 3 264.000000\n7 396.000000 4 330.000000\n13 726.000000\n16 660.000000 19 66.000000\n4 462.000000 21 264.000000\n22 528.000000 5 198.000000\n12 396.000000 8 330.000000\n21 528.000000 18 198.000000\n10 594.000000 2 132.000000\n20 66.000000 9 ..." }, { "input": "40 100 48", "output": "YES\n5 16.666667 6 66.666667\n27 66.666667 34 16.666667\n31 83.333333\n14 66.666667 17 16.666667\n16 83.333333\n6 33.333333 12 50.000000\n35 33.333333 23 50.000000\n24 83.333333\n38 50.000000 21 33.333333\n4 50.000000 26 33.333333\n28 83.333333\n18 83.333333\n25 66.666667 1 16.666667\n8 83.333333\n13 16.666667 2 66.666667\n9 83.333333\n10 50.000000 2 33.333333\n33 50.000000 29 33.333333\n23 50.000000 20 33.333333\n27 33.333333 38 50.000000\n11 83.333333\n40 83.333333\n9 16.666667 20 66.666667\n7 33.333333 ..." }, { "input": "42 501 48", "output": "YES\n28 375.750000 37 62.625000\n25 250.500000 10 187.875000\n24 438.375000\n34 375.750000 24 62.625000\n26 125.250000 4 313.125000\n16 313.125000 30 125.250000\n19 250.500000 29 187.875000\n37 438.375000\n31 250.500000 8 187.875000\n28 125.250000 1 313.125000\n3 313.125000 5 125.250000\n12 62.625000 7 375.750000\n33 375.750000 41 62.625000\n20 438.375000\n3 187.875000 22 250.500000\n29 313.125000 33 125.250000\n32 438.375000\n15 313.125000 36 125.250000\n17 313.125000 39 125.250000\n1 187.875000 25 250.50..." }, { "input": "36 100 39", "output": "YES\n3 53.846154 22 38.461538\n4 53.846154 27 38.461538\n30 30.769231 32 61.538462\n18 38.461538 21 53.846154\n15 69.230769 36 23.076923\n8 15.384615 7 76.923077\n20 23.076923 9 69.230769\n16 76.923077 19 15.384615\n33 7.692308 14 84.615385\n6 61.538462 12 30.769231\n26 46.153846 28 46.153846\n8 84.615385 31 7.692308\n12 69.230769 7 23.076923\n34 69.230769 24 23.076923\n15 30.769231 22 61.538462\n13 7.692308 2 84.615385\n10 76.923077 2 15.384615\n17 92.307692\n13 92.307692\n29 7.692308 19 84.615385\n30 69...." }, { "input": "42 171 49", "output": "YES\n28 146.571429\n25 73.285714 10 73.285714\n24 97.714286 41 48.857143\n24 73.285714 34 73.285714\n26 146.571429\n16 73.285714 30 73.285714\n19 122.142857 29 24.428571\n37 146.571429\n31 146.571429\n1 122.142857 28 24.428571\n5 146.571429\n7 97.714286 8 48.857143\n33 146.571429\n20 73.285714 9 73.285714\n3 146.571429\n38 146.571429\n32 122.142857 37 24.428571\n22 48.857143 15 97.714286\n14 73.285714 17 73.285714\n25 97.714286 1 48.857143\n2 48.857143 10 97.714286\n3 24.428571 22 122.142857\n4 122.142857 ..." }, { "input": "17 100 10", "output": "YES\n17 30.000000 14 40.000000 11 100.000000\n4 100.000000 8 20.000000 5 50.000000\n17 70.000000 7 100.000000\n9 20.000000 16 100.000000 5 50.000000\n3 40.000000 10 100.000000 2 30.000000\n12 90.000000 8 80.000000\n15 100.000000 6 10.000000 14 60.000000\n3 60.000000 12 10.000000 1 100.000000\n2 70.000000 13 100.000000\n9 80.000000 6 90.000000" }, { "input": "5 100 7", "output": "NO" } ]
15
0
0
9,446
432
Football Kit
[ "brute force", "greedy", "implementation" ]
null
null
Consider a football tournament where *n* teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the *i*-th team has color *x**i* and the kit for away games of this team has color *y**i* (*x**i*<=≠<=*y**i*). In the tournament, each team plays exactly one home game and exactly one away game with each other team (*n*(*n*<=-<=1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit. Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of teams. Next *n* lines contain the description of the teams. The *i*-th line contains two space-separated numbers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=105; *x**i*<=≠<=*y**i*) — the color numbers for the home and away kits of the *i*-th team.
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
[ "2\n1 2\n2 1\n", "3\n1 2\n2 1\n1 3\n" ]
[ "2 0\n2 0\n", "3 1\n4 0\n2 2\n" ]
none
[ { "input": "2\n1 2\n2 1", "output": "2 0\n2 0" }, { "input": "3\n1 2\n2 1\n1 3", "output": "3 1\n4 0\n2 2" }, { "input": "2\n1 2\n1 2", "output": "1 1\n1 1" }, { "input": "2\n1 2\n3 4", "output": "1 1\n1 1" }, { "input": "3\n1 100000\n1 100000\n100000 2", "output": "3 1\n3 1\n2 2" }, { "input": "5\n3 2\n3 4\n2 5\n3 2\n4 3", "output": "5 3\n5 3\n4 4\n5 3\n7 1" }, { "input": "6\n2 3\n2 1\n2 1\n3 2\n3 2\n3 1", "output": "8 2\n5 5\n5 5\n8 2\n8 2\n5 5" }, { "input": "10\n2 1\n1 3\n4 1\n2 3\n4 1\n1 4\n2 4\n2 1\n2 3\n3 4", "output": "11 7\n10 8\n11 7\n10 8\n11 7\n11 7\n11 7\n11 7\n10 8\n11 7" }, { "input": "30\n1 10\n1 7\n6 10\n2 6\n10 2\n1 8\n3 8\n10 2\n7 4\n10 4\n9 1\n3 7\n1 8\n2 5\n3 4\n2 7\n3 1\n6 9\n8 10\n4 1\n5 1\n7 8\n6 7\n9 8\n7 3\n6 2\n9 1\n7 1\n8 9\n9 6", "output": "32 26\n33 25\n32 26\n33 25\n32 26\n31 27\n31 27\n32 26\n30 28\n30 28\n33 25\n33 25\n31 27\n30 28\n30 28\n33 25\n33 25\n33 25\n32 26\n33 25\n33 25\n31 27\n33 25\n31 27\n33 25\n32 26\n33 25\n33 25\n33 25\n33 25" }, { "input": "30\n14 1\n12 5\n16 18\n17 9\n17 5\n13 4\n5 17\n10 8\n13 9\n11 9\n11 5\n15 11\n12 17\n10 7\n20 4\n9 8\n4 18\n10 6\n6 18\n3 16\n14 9\n8 17\n12 14\n18 11\n3 10\n1 15\n4 17\n7 20\n11 18\n18 13", "output": "30 28\n30 28\n31 27\n30 28\n30 28\n31 27\n31 27\n30 28\n30 28\n30 28\n30 28\n32 26\n31 27\n30 28\n31 27\n30 28\n31 27\n30 28\n31 27\n30 28\n30 28\n31 27\n31 27\n32 26\n32 26\n30 28\n31 27\n30 28\n31 27\n31 27" }, { "input": "30\n25 8\n25 4\n21 9\n25 1\n7 16\n23 21\n22 17\n27 29\n7 29\n20 3\n13 23\n7 13\n16 18\n25 14\n13 17\n28 15\n10 23\n25 18\n2 3\n23 13\n30 8\n13 15\n20 15\n11 29\n10 23\n5 16\n4 14\n4 30\n7 20\n11 1", "output": "29 29\n31 27\n29 29\n29 29\n30 28\n30 28\n29 29\n29 29\n29 29\n29 29\n31 27\n32 26\n29 29\n29 29\n29 29\n29 29\n31 27\n29 29\n29 29\n32 26\n29 29\n29 29\n29 29\n29 29\n31 27\n30 28\n29 29\n30 28\n31 27\n29 29" }, { "input": "2\n100000 1\n1 100000", "output": "2 0\n2 0" }, { "input": "20\n1 100000\n2 100000\n3 100000\n4 100000\n5 100000\n6 100000\n7 100000\n8 100000\n9 100000\n10 100000\n11 100000\n12 100000\n13 100000\n14 100000\n15 100000\n16 100000\n17 100000\n18 100000\n19 100000\n20 100000", "output": "19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19" } ]
545
2,764,800
3
9,477
244
Dividing Orange
[ "implementation" ]
null
null
One day Ms Swan bought an orange in a shop. The orange consisted of *n*·*k* segments, numbered with integers from 1 to *n*·*k*. There were *k* children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the *i*-th (1<=≤<=*i*<=≤<=*k*) child wrote the number *a**i* (1<=≤<=*a**i*<=≤<=*n*·*k*). All numbers *a**i* accidentally turned out to be different. Now the children wonder, how to divide the orange so as to meet these conditions: - each child gets exactly *n* orange segments; - the *i*-th child gets the segment with number *a**i* for sure; - no segment goes to two children simultaneously. Help the children, divide the orange and fulfill the requirements, described above.
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=30). The second line contains *k* space-separated integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*·*k*), where *a**i* is the number of the orange segment that the *i*-th child would like to get. It is guaranteed that all numbers *a**i* are distinct.
Print exactly *n*·*k* distinct integers. The first *n* integers represent the indexes of the segments the first child will get, the second *n* integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces. You can print a child's segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them.
[ "2 2\n4 1\n", "3 1\n2\n" ]
[ "2 4 \n1 3 \n", "3 2 1 \n" ]
none
[ { "input": "2 2\n4 1", "output": "2 4 \n1 3 " }, { "input": "3 1\n2", "output": "3 2 1 " }, { "input": "5 5\n25 24 23 22 21", "output": "2 3 1 25 4 \n7 6 8 5 24 \n10 12 9 23 11 \n13 15 14 16 22 \n19 21 20 17 18 " }, { "input": "1 30\n8 22 13 25 10 30 12 27 6 4 7 2 20 16 26 14 15 17 23 3 24 9 5 11 29 1 19 28 21 18", "output": "8 \n22 \n13 \n25 \n10 \n30 \n12 \n27 \n6 \n4 \n7 \n2 \n20 \n16 \n26 \n14 \n15 \n17 \n23 \n3 \n24 \n9 \n5 \n11 \n29 \n1 \n19 \n28 \n21 \n18 " }, { "input": "30 1\n29", "output": "8 20 17 12 5 26 13 2 19 22 28 16 10 4 6 11 3 25 1 27 15 9 30 24 21 18 14 23 29 7 " }, { "input": "10 10\n13 39 6 75 84 94 96 21 85 71", "output": "9 3 1 13 5 7 4 2 10 8 \n17 12 19 11 39 14 15 18 16 20 \n22 27 6 24 25 30 26 28 23 29 \n36 33 75 34 38 31 35 40 37 32 \n43 44 49 42 46 48 47 45 84 41 \n51 94 52 56 57 54 50 55 53 58 \n64 60 62 61 66 59 63 96 67 65 \n72 69 76 77 70 78 73 21 74 68 \n81 85 87 88 80 83 89 86 79 82 \n93 91 100 99 98 71 90 95 92 97 " }, { "input": "10 15\n106 109 94 50 3 143 147 10 89 145 29 28 87 126 110", "output": "9 4 1 106 6 7 5 2 11 8 \n17 13 19 12 109 14 15 18 16 20 \n21 26 94 23 24 31 25 27 22 30 \n37 34 50 35 39 32 36 40 38 33 \n43 44 49 42 46 48 47 45 3 41 \n52 143 53 57 58 55 51 56 54 59 \n65 61 63 62 67 60 64 147 68 66 \n72 70 75 76 71 77 73 10 74 69 \n80 89 84 85 79 82 86 83 78 81 \n92 90 98 97 96 145 88 93 91 95 \n100 104 105 103 102 108 99 101 29 107 \n111 114 112 116 119 118 28 113 117 115 \n128 120 122 125 129 127 87 124 123 121 \n133 136 130 134 132 131 135 126 137 138 \n142 141 144 148 146 149 110 140..." }, { "input": "15 10\n126 111 12 6 28 47 51 116 53 35", "output": "9 13 1 14 5 16 15 2 10 8 126 3 11 4 7 \n111 22 21 26 20 30 17 23 18 19 24 31 27 25 29 \n43 40 41 39 42 12 45 44 34 37 32 36 38 33 46 \n59 6 57 56 58 49 62 54 50 52 63 61 48 55 60 \n70 67 71 75 69 77 72 65 68 73 76 74 28 64 66 \n80 89 86 79 87 91 81 78 88 83 85 82 90 84 47 \n95 93 51 99 104 98 103 101 100 102 97 96 94 92 105 \n120 115 113 118 109 119 110 116 114 106 121 117 108 107 112 \n135 133 128 125 123 131 129 122 124 53 134 132 130 127 136 \n148 139 141 143 146 144 147 138 137 145 142 149 140 150 35 \n..." }, { "input": "30 30\n455 723 796 90 7 881 40 736 147 718 560 619 468 363 161 767 282 19 111 369 443 850 871 242 713 789 208 435 135 411", "output": "9 22 18 13 5 28 14 2 21 24 30 17 11 4 6 12 3 27 1 29 16 10 31 26 23 20 15 25 455 8 \n723 52 49 60 45 48 34 59 58 44 32 57 61 56 51 33 42 37 41 38 47 53 36 50 54 55 46 39 43 35 \n89 71 796 74 78 70 88 67 84 85 63 83 82 62 72 79 81 80 73 91 69 66 65 87 77 75 64 68 86 76 \n115 90 102 121 104 106 109 98 112 120 119 105 103 97 113 93 100 118 107 96 117 92 94 116 95 101 110 108 114 99 \n136 133 148 123 144 139 149 142 7 140 138 127 150 129 122 130 143 126 134 152 132 145 131 146 125 151 137 128 124 141 \n154 177..." }, { "input": "1 1\n1", "output": "1 " }, { "input": "2 1\n1", "output": "2 1 " }, { "input": "1 2\n2 1", "output": "2 \n1 " }, { "input": "1 3\n2 3 1", "output": "2 \n3 \n1 " }, { "input": "2 3\n3 2 1", "output": "4 3 \n2 5 \n1 6 " }, { "input": "3 3\n6 7 8", "output": "2 6 1 \n7 4 3 \n5 9 8 " }, { "input": "3 1\n3", "output": "2 3 1 " }, { "input": "3 2\n5 4", "output": "2 5 1 \n4 6 3 " }, { "input": "12 13\n149 22 133 146 151 64 45 88 77 126 92 134 143", "output": "8 11 1 10 5 6 4 2 9 7 149 3 \n14 13 19 12 17 16 22 20 21 23 15 18 \n133 28 34 32 31 25 30 33 24 29 26 27 \n35 42 38 40 43 46 39 41 44 146 36 37 \n56 51 48 49 50 54 53 151 57 52 47 55 \n61 58 65 68 67 59 62 66 69 63 64 60 \n80 70 75 74 76 81 45 72 78 73 79 71 \n94 85 88 83 90 87 86 89 93 82 84 91 \n99 104 98 96 103 105 102 97 77 95 101 100 \n116 109 107 111 115 113 126 108 112 110 114 106 \n127 121 125 118 120 128 123 92 119 122 117 124 \n139 132 136 130 131 140 141 134 137 138 135 129 \n150 142 144 155 154..." }, { "input": "30 29\n427 740 444 787 193 268 19 767 46 276 245 468 661 348 402 62 665 425 398 503 89 455 200 772 355 442 863 416 164", "output": "8 21 17 12 5 27 13 2 20 23 29 16 10 4 6 11 3 26 1 28 15 9 30 25 22 18 14 24 427 7 \n740 51 48 59 43 47 33 58 57 42 31 56 60 55 50 32 40 36 39 37 45 52 35 49 53 54 44 38 41 34 \n90 71 444 74 78 70 88 67 84 85 63 83 82 61 72 79 81 80 73 91 69 66 65 87 77 75 64 68 86 76 \n114 787 102 120 104 106 109 98 111 119 118 105 103 97 112 93 100 117 107 96 116 92 94 115 95 101 110 108 113 99 \n134 132 145 122 142 137 146 140 193 138 136 126 147 128 121 129 141 125 133 149 131 143 130 144 124 148 135 127 123 139 \n151 1..." }, { "input": "29 30\n173 601 360 751 194 411 708 598 236 812 855 647 100 106 59 38 822 196 529 417 606 159 384 389 300 172 544 726 702 799", "output": "8 20 17 12 5 26 13 2 19 22 28 16 10 4 6 11 3 25 1 27 15 9 7 24 21 18 14 23 173 \n47 36 37 35 45 51 49 41 31 33 29 32 46 57 52 48 54 34 55 53 56 30 601 44 43 39 40 42 50 \n77 79 84 86 64 72 75 60 76 78 81 73 80 58 82 69 70 67 83 65 68 62 360 71 61 63 85 66 74 \n90 107 751 110 105 93 98 96 95 97 116 91 109 102 115 87 99 104 114 88 92 113 94 111 101 89 103 112 108 \n140 127 144 134 118 125 141 137 119 133 128 139 124 121 130 126 120 142 136 122 132 117 194 131 129 143 138 123 135 \n147 168 163 154 174 160 146..." }, { "input": "29 29\n669 371 637 18 176 724 137 757 407 420 658 737 188 408 185 416 425 293 178 557 8 104 139 819 268 403 255 63 793", "output": "9 22 19 13 5 28 14 2 21 24 30 17 11 4 6 12 3 27 1 29 16 10 7 26 23 20 15 25 669 \n48 38 39 37 46 52 50 42 33 35 31 34 47 58 53 49 55 36 56 54 57 32 371 45 44 40 41 43 51 \n78 80 85 87 65 73 76 60 77 79 82 74 81 59 83 70 71 68 84 66 69 62 637 72 61 64 86 67 75 \n91 107 18 110 106 94 99 97 96 98 116 92 109 102 115 88 100 105 114 89 93 113 95 111 101 90 103 112 108 \n142 127 146 134 118 125 143 138 119 133 128 141 124 121 130 126 120 144 136 122 132 117 176 131 129 145 140 123 135 \n149 169 164 156 173 161 14..." }, { "input": "28 29\n771 736 590 366 135 633 68 789 193 459 137 370 216 692 730 712 537 356 752 757 796 541 804 27 431 162 196 630 684", "output": "8 20 17 12 5 26 13 2 19 22 771 16 10 4 6 11 3 25 1 28 15 9 7 24 21 18 14 23 \n34 55 49 41 54 45 33 37 35 53 29 40 30 32 43 31 36 51 736 44 39 46 38 50 48 52 47 42 \n77 65 78 73 63 56 72 590 76 62 74 57 83 69 58 80 60 79 66 59 64 82 67 70 81 61 71 75 \n107 104 92 94 106 109 84 88 86 99 98 105 366 93 103 101 89 87 95 90 100 85 91 102 97 108 110 96 \n124 125 113 123 119 120 121 134 127 132 117 129 116 130 138 111 118 131 122 139 128 114 112 126 115 136 133 135 \n141 633 142 153 160 152 149 156 166 158 161 144..." }, { "input": "29 29\n669 371 637 18 176 724 137 757 407 420 658 737 188 408 185 416 425 293 178 557 8 104 139 819 268 403 255 63 793", "output": "9 22 19 13 5 28 14 2 21 24 30 17 11 4 6 12 3 27 1 29 16 10 7 26 23 20 15 25 669 \n48 38 39 37 46 52 50 42 33 35 31 34 47 58 53 49 55 36 56 54 57 32 371 45 44 40 41 43 51 \n78 80 85 87 65 73 76 60 77 79 82 74 81 59 83 70 71 68 84 66 69 62 637 72 61 64 86 67 75 \n91 107 18 110 106 94 99 97 96 98 116 92 109 102 115 88 100 105 114 89 93 113 95 111 101 90 103 112 108 \n142 127 146 134 118 125 143 138 119 133 128 141 124 121 130 126 120 144 136 122 132 117 176 131 129 145 140 123 135 \n149 169 164 156 173 161 14..." }, { "input": "27 3\n12 77 80", "output": "8 21 18 13 5 27 14 2 20 23 12 17 10 4 6 11 3 26 1 24 16 9 7 25 22 19 15 \n43 32 46 48 51 37 41 49 77 30 40 28 34 38 44 35 31 45 52 50 47 29 36 53 42 39 33 \n62 61 78 63 81 55 70 79 67 73 58 69 59 64 80 54 56 57 68 72 65 60 71 66 74 75 76 " }, { "input": "3 27\n77 9 32 56 7 65 58 24 64 19 49 62 47 44 28 79 76 71 21 4 18 23 51 53 12 6 20", "output": "2 77 1 \n9 5 3 \n8 10 32 \n13 56 11 \n15 7 14 \n65 17 16 \n22 58 25 \n24 26 27 \n29 64 30 \n31 33 19 \n35 34 49 \n62 37 36 \n47 38 39 \n44 40 41 \n42 43 28 \n46 45 79 \n48 50 76 \n71 54 52 \n57 21 55 \n60 4 59 \n61 18 63 \n66 23 67 \n68 51 69 \n72 70 53 \n12 73 74 \n75 6 78 \n81 20 80 " }, { "input": "10 30\n165 86 241 45 144 43 95 250 28 240 42 15 295 211 48 99 199 156 206 109 100 194 229 224 57 10 220 79 44 203", "output": "8 3 1 165 5 6 4 2 9 7 \n17 12 19 11 86 13 14 18 16 20 \n21 26 241 23 24 30 25 27 22 29 \n36 33 45 34 38 31 35 39 37 32 \n46 47 53 41 50 52 51 49 144 40 \n55 43 56 61 62 59 54 60 58 63 \n69 65 67 66 71 64 68 95 72 70 \n76 74 80 81 75 82 77 250 78 73 \n85 28 90 91 84 88 92 89 83 87 \n97 94 104 103 102 240 93 98 96 101 \n106 111 112 110 108 114 105 107 42 113 \n115 118 116 120 123 122 15 117 121 119 \n131 124 126 129 132 130 295 128 127 125 \n136 139 133 137 135 134 138 211 140 141 \n146 145 147 149 148 150 4..." }, { "input": "30 10\n71 146 274 157 190 85 32 152 25 278", "output": "8 20 17 12 5 27 13 2 19 22 29 16 10 4 6 11 3 26 1 28 15 9 30 24 21 18 14 23 71 7 \n146 51 48 59 44 47 34 58 57 43 31 56 60 55 50 33 41 37 40 38 46 52 36 49 53 54 45 39 42 35 \n90 70 274 74 78 69 89 66 84 86 62 83 82 61 72 79 81 80 73 91 68 65 64 88 77 75 63 67 87 76 \n114 157 102 120 104 106 109 98 111 119 118 105 103 97 112 93 100 117 107 96 116 92 94 115 95 101 110 108 113 99 \n134 132 145 122 142 137 147 140 190 138 136 126 148 128 121 129 141 125 133 150 131 143 130 144 124 149 135 127 123 139 \n153 17..." }, { "input": "7 1\n5", "output": "2 3 1 5 6 7 4 " }, { "input": "6 1\n5", "output": "2 3 1 5 6 4 " } ]
124
6,963,200
3
9,484
710
Two Arithmetic Progressions
[ "math", "number theory" ]
null
null
You are given two arithmetic progressions: *a*1*k*<=+<=*b*1 and *a*2*l*<=+<=*b*2. Find the number of integers *x* such that *L*<=≤<=*x*<=≤<=*R* and *x*<==<=*a*1*k*'<=+<=*b*1<==<=*a*2*l*'<=+<=*b*2, for some integers *k*',<=*l*'<=≥<=0.
The only line contains six integers *a*1,<=*b*1,<=*a*2,<=*b*2,<=*L*,<=*R* (0<=&lt;<=*a*1,<=*a*2<=≤<=2·109,<=<=-<=2·109<=≤<=*b*1,<=*b*2,<=*L*,<=*R*<=≤<=2·109,<=*L*<=≤<=*R*).
Print the desired number of integers *x*.
[ "2 0 3 3 5 21\n", "2 4 3 0 6 17\n" ]
[ "3\n", "2\n" ]
none
[ { "input": "2 0 3 3 5 21", "output": "3" }, { "input": "2 4 3 0 6 17", "output": "2" }, { "input": "2 0 4 2 -39 -37", "output": "0" }, { "input": "1 9 3 11 49 109", "output": "20" }, { "input": "3 81 5 72 -1761 501", "output": "28" }, { "input": "8 -89 20 67 8771 35222", "output": "661" }, { "input": "1 -221 894 86403 -687111 141371", "output": "62" }, { "input": "1 -1074 271 17741 -2062230 1866217", "output": "6821" }, { "input": "3 2408 819 119198 -8585197 7878219", "output": "9474" }, { "input": "1 341 8581 3946733 -59420141 33253737", "output": "3416" }, { "input": "1 10497 19135 2995296 -301164547 -180830773", "output": "0" }, { "input": "8 40306 2753 1809818 254464419 340812028", "output": "3921" }, { "input": "2 21697 9076 1042855 -319348358 236269755", "output": "25918" }, { "input": "4 2963 394 577593 125523962 628140505", "output": "637839" }, { "input": "75 61736 200 200511 160330870 609945842", "output": "749358" }, { "input": "34 64314 836 5976 591751179 605203191", "output": "946" }, { "input": "1 30929 25249 95822203 -1076436442 705164517", "output": "24134" }, { "input": "3 -1208 459 933808 603490653 734283665", "output": "284952" }, { "input": "1 35769 16801 47397023 -82531776 1860450454", "output": "107914" }, { "input": "1 -3078 36929 51253687 -754589746 -53412627", "output": "0" }, { "input": "1 -32720 3649 7805027 408032642 925337350", "output": "141766" }, { "input": "1 -2000000000 1 -2000000000 -2000000000 2000000000", "output": "4000000001" }, { "input": "1 -2000000000 2 -2000000000 -2000000000 2000000000", "output": "2000000001" }, { "input": "3 -2000000000 2 -2000000000 -2000000000 2000000000", "output": "666666667" }, { "input": "999999999 999999998 1000000000 999999999 1 10000", "output": "0" }, { "input": "1 -2000000000 1 2000000000 1 10", "output": "0" }, { "input": "1 -2000000000 2 2000000000 -2000000000 2000000000", "output": "1" }, { "input": "2 0 2 1 0 1000000000", "output": "0" }, { "input": "1000000000 0 1 0 0 2000000000", "output": "3" }, { "input": "4 0 4 1 5 100", "output": "0" }, { "input": "1000000000 1 999999999 0 1 100000000", "output": "0" }, { "input": "1 30929 1 1 1 1", "output": "0" }, { "input": "1 1 1 1 -2000000000 2000000000", "output": "2000000000" }, { "input": "4 0 4 1 0 100", "output": "0" }, { "input": "1 -2000000000 1 2000000000 5 5", "output": "0" }, { "input": "51 -1981067352 71 -414801558 -737219217 1160601982", "output": "435075" }, { "input": "2 -1500000000 4 -1499999999 1600000000 1700000000", "output": "0" }, { "input": "135 -1526277729 32 1308747737 895574 1593602399", "output": "65938" }, { "input": "1098197640 6 994625382 6 -474895292 -101082478", "output": "0" }, { "input": "12 -696575903 571708420 236073275 2 14", "output": "0" }, { "input": "1 -9 2 -10 -10 -9", "output": "0" }, { "input": "2 -11 2 -9 -11 -9", "output": "1" }, { "input": "40 54 15 74 -180834723 1373530127", "output": "11446084" }, { "input": "2 57 1 56 -1773410854 414679043", "output": "207339494" }, { "input": "9 12 1 40 624782492 883541397", "output": "28750990" }, { "input": "4 -1000000000 2 4 100 1000", "output": "226" }, { "input": "66 90 48 84 -1709970247 1229724777", "output": "2329024" }, { "input": "1000000000 1 2000000000 0 -2000000000 200000000", "output": "0" }, { "input": "2 0 2 1 -1000000000 1000000000", "output": "0" }, { "input": "2 -1000000000 2 -999999999 -1000000000 1000000000", "output": "0" }, { "input": "26 1885082760 30 -1612707510 -1113844607 1168679422", "output": "0" }, { "input": "76 -19386 86 -6257 164862270 1443198941", "output": "0" }, { "input": "5 -2000000000 5 1000000000 1000000000 2000000000", "output": "200000001" }, { "input": "505086589 -4 1288924334 -4 -5 -4", "output": "1" }, { "input": "91 -193581878 2 1698062870 -819102473 1893630769", "output": "1074549" }, { "input": "8 11047 45 12730 -45077355 1727233357", "output": "4797835" }, { "input": "35 8673 6 -19687 -111709844 1321584980", "output": "6293220" }, { "input": "71 1212885043 55 1502412287 970234397 1952605611", "output": "115287" }, { "input": "274497829 -12 9 -445460655 -5 4", "output": "0" }, { "input": "1509527550 3 7 -134101853 2 7", "output": "1" }, { "input": "43 -1478944506 45 494850401 634267177 1723176461", "output": "562743" }, { "input": "25 479638866 50 -874479027 -2000000000 2000000000", "output": "0" }, { "input": "11 -10 1 -878946597 -11127643 271407906", "output": "24673447" }, { "input": "15 -738862158 12 -3 -3 12", "output": "1" }, { "input": "70 -835526513 23 687193329 -1461506792 1969698938", "output": "796587" }, { "input": "124 1413 15321 312133 3424 1443242", "output": "0" }, { "input": "75 -13580 14 4508 -67634192 1808916097", "output": "1722773" }, { "input": "915583842 -15 991339476 -12 -15 -5", "output": "0" }, { "input": "85 -18257 47 -7345 -76967244 1349252598", "output": "337737" }, { "input": "178 331734603 162 -73813367 -577552570 1005832995", "output": "46754" }, { "input": "8 -17768 34 963 -2000000000 2000000000", "output": "0" }, { "input": "26 1885082760 30 -1612707510 -2000000000 2000000000", "output": "294660" }, { "input": "4 -1999999999 6 -1999999998 -999999999 1999999999", "output": "0" }, { "input": "121826 1323 1327 304172 -1521910750 860413213", "output": "5" }, { "input": "36281 170 1917 927519 -1767064448 -177975414", "output": "0" }, { "input": "37189 -436 464 797102 -1433652908 1847752465", "output": "107" }, { "input": "81427 -688 1720 -221771 -77602716 1593447723", "output": "11" }, { "input": "11 -1609620737 1315657088 -7 -162162918 287749240", "output": "0" }, { "input": "1480269313 -1048624081 1314841531 -8 295288505 358226461", "output": "0" }, { "input": "13 -15 19 -2 -334847526 1334632952", "output": "5403373" }, { "input": "1254161381 -7 821244830 -7 -698761303 941496965", "output": "1" }, { "input": "1269100557 -5 6 -5 -12 -6", "output": "0" }, { "input": "847666888 -6 1327933031 -6 -5 -2", "output": "0" }, { "input": "1465846675 1002489474 9 -1250811979 1030017372 1391560043", "output": "0" }, { "input": "8 -1915865359 867648990 9 -5 -4", "output": "0" }, { "input": "3 -1164702220 906446587 -1868913852 222249893 1493113759", "output": "0" }, { "input": "15 -8 17 3 -393290856 231975525", "output": "909708" }, { "input": "734963978 0 17 0 -12 -5", "output": "0" }, { "input": "1090004357 5 1124063714 -840327001 -448110704 128367602", "output": "0" }, { "input": "18 -1071025614 1096150070 0 -6 0", "output": "1" }, { "input": "451525105 -8 1256335024 -8 -718788747 928640626", "output": "1" }, { "input": "4 3 5 -1292190012 -97547955 250011754", "output": "12500588" }, { "input": "14 -7 14 -1488383431 -1044342357 842171605", "output": "0" }, { "input": "1384140089 5 16 -1661922737 442287491 1568124284", "output": "0" }, { "input": "16 -11 14 -1466771835 -1192555694 -2257860", "output": "0" }, { "input": "1676164235 -1589020998 1924931103 1189158232 6 12", "output": "0" }, { "input": "15 16 12 -5 11 23", "output": "0" }, { "input": "16 -16 5 20 -9 7", "output": "0" }, { "input": "4 -9 1 -2 -13 -1", "output": "1" }, { "input": "18 -17 9 -17 -29 17", "output": "2" }, { "input": "735463638 620656007 878587644 536507630 -1556948056 1714374073", "output": "0" }, { "input": "1789433851 -633540112 1286318222 -1728151682 1438333624 1538194890", "output": "0" }, { "input": "15 -1264610276 1157160166 -336457087 -496892962 759120142", "output": "0" }, { "input": "831644204 422087925 17 -1288230412 -1090082747 1271113499", "output": "1" }, { "input": "17 -13 223959272 -1081245422 -1756575771 38924201", "output": "1" }, { "input": "1228969457 -1826233120 11 -1063855654 -819177202 1039858319", "output": "0" }, { "input": "1186536442 -1691684240 17 -1 -702600351 1121394816", "output": "1" }, { "input": "1132421757 -1481846636 515765656 -12 -622203577 552143596", "output": "0" }, { "input": "18 -1123473160 1826212361 -10 -12 1", "output": "1" }, { "input": "1197045662 7 15 -1445473718 -1406137199 800415943", "output": "1" }, { "input": "18 565032929 13 735553852 107748471 1945959489", "output": "5172673" }, { "input": "1734271904 1 19 -1826828681 0 4", "output": "1" }, { "input": "1614979757 -1237127436 12 75067457 -933537920 451911806", "output": "1" }, { "input": "8 -335942902 1179386720 -723257398 -13 -12", "output": "0" }, { "input": "989432982 2 9 366779468 -1427636085 985664909", "output": "0" }, { "input": "7 -1390956935 1404528667 -4 -15 0", "output": "1" }, { "input": "1370475975 841789607 733784598 467967887 -7 15", "output": "0" }, { "input": "6 -7 9 -1 -10 1", "output": "1" }, { "input": "960716652 1417038753 1222139305 -4 -1570098546 -931528535", "output": "0" }, { "input": "1744394473 5 1523286739 629247513 -6 1", "output": "0" }, { "input": "2627 -4960 2627 -4960 -4960 4960", "output": "4" }, { "input": "6 -364562196 7 -803430276 0 11", "output": "0" }, { "input": "1955378240 -837482305 1743607821 -1623988108 -653286850 178227154", "output": "0" }, { "input": "9 -1642366642 1499382371 -6 -822052389 1405478033", "output": "0" }, { "input": "9 -1 8 -1 -711474975 237571596", "output": "3299606" }, { "input": "1497677869 -1313800455 11 12 -1157529918 1754001465", "output": "1" }, { "input": "11 -80049925 1600186381 -1454831688 -1384227392 1621203975", "output": "0" }, { "input": "1042015302 -56794440 1727095321 -1037110962 -9 11", "output": "0" }, { "input": "13 0 1419591662 -1360930956 343359607 1283114457", "output": "0" }, { "input": "752411560 -6 857048450 -405514986 -5 0", "output": "0" }, { "input": "12 2 18 2 -6 3", "output": "1" }, { "input": "11 -1 15 -1 -13 2", "output": "1" }, { "input": "1446642133 -7 9 -1719422944 -916435667 36154654", "output": "1" }, { "input": "1689390799 501112014 13 -1621132473 398367938 709483101", "output": "0" }, { "input": "1932547151 -725726769 782679113 -10 -184530763 498112212", "output": "0" } ]
0
0
-1
9,539
431
Shower Line
[ "brute force", "implementation" ]
null
null
Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower. Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2*i*<=-<=1)-th man in the line (for the current moment) talks with the (2*i*)-th one. Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower. We know that if students *i* and *j* talk, then the *i*-th student's happiness increases by *g**ij* and the *j*-th student's happiness increases by *g**ji*. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.
The input consists of five lines, each line contains five space-separated integers: the *j*-th number in the *i*-th line shows *g**ij* (0<=≤<=*g**ij*<=≤<=105). It is guaranteed that *g**ii*<==<=0 for all *i*. Assume that the students are numbered from 1 to 5.
Print a single integer — the maximum possible total happiness of the students.
[ "0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0\n", "0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0\n" ]
[ "32\n", "620\n" ]
In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:
[ { "input": "0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0", "output": "32" }, { "input": "0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0", "output": "620" }, { "input": "0 4 2 4 9\n6 0 2 5 0\n2 5 0 6 3\n6 3 3 0 10\n0 3 1 3 0", "output": "63" }, { "input": "0 65 90 2 32\n69 0 9 97 67\n77 97 0 16 84\n18 50 94 0 63\n69 12 82 16 0", "output": "947" }, { "input": "0 70 10 0 0\n70 0 50 90 0\n10 50 0 80 0\n0 90 80 0 100\n0 0 0 100 0", "output": "960" }, { "input": "0 711 647 743 841\n29 0 109 38 682\n329 393 0 212 512\n108 56 133 0 579\n247 92 933 164 0", "output": "6265" }, { "input": "0 9699 6962 6645 7790\n9280 0 6215 8661 6241\n2295 7817 0 7373 9681\n693 6298 1381 0 4633\n7626 3761 694 4073 0", "output": "93667" }, { "input": "0 90479 71577 33797 88848\n45771 0 96799 78707 72708\n5660 26421 0 10991 22757\n78919 24804 90645 0 48665\n92787 43671 38727 17302 0", "output": "860626" }, { "input": "0 61256 85109 94834 32902\n55269 0 67023 1310 85444\n23497 84998 0 55618 80701\n30324 1713 62127 0 55041\n47799 52448 40072 28971 0", "output": "822729" }, { "input": "0 7686 20401 55871 74372\n29526 0 15486 2152 84700\n27854 30093 0 62418 14297\n43903 76036 36194 0 50522\n29743 9945 38831 75882 0", "output": "605229" }, { "input": "0 5271 65319 64976 13673\n80352 0 41169 66004 47397\n33603 44407 0 55079 36122\n4277 9834 92810 0 80276\n1391 1145 92132 51595 0", "output": "744065" }, { "input": "0 75763 33154 32389 12897\n5095 0 6375 61517 46063\n35354 82789 0 24814 310\n37373 45993 61355 0 76865\n24383 84258 71887 71430 0", "output": "714904" }, { "input": "0 89296 32018 98206 22395\n15733 0 69391 74253 50419\n80450 89589 0 20583 51716\n38629 93129 67730 0 69703\n44054 83018 21382 64478 0", "output": "874574" }, { "input": "0 14675 94714 27735 99544\n45584 0 43621 94734 66110\n72838 45781 0 47389 99394\n75870 95368 33311 0 63379\n21974 70489 53797 23747 0", "output": "974145" }, { "input": "0 9994 14841 63916 37926\n80090 0 90258 96988 18217\n674 69024 0 17641 54436\n35046 21380 14213 0 67188\n49360 19086 68337 70856 0", "output": "801116" }, { "input": "0 28287 52158 19163 10096\n93438 0 19260 88892 12429\n22525 60034 0 78163 18126\n11594 8506 56066 0 17732\n59561 82486 23419 57406 0", "output": "654636" }, { "input": "0 35310 30842 63415 91022\n30553 0 25001 38944 92355\n48906 33736 0 96880 80893\n80507 79652 45299 0 38212\n72488 77736 19203 56436 0", "output": "953303" }, { "input": "0 42865 18485 37168 43099\n41476 0 58754 73410 51163\n76093 44493 0 51611 93773\n87223 80979 58422 0 63327\n51215 63346 84797 52809 0", "output": "864938" }, { "input": "0 63580 51022 25392 84354\n39316 0 17516 63801 92440\n5447 2074 0 11758 4772\n26329 55642 62442 0 75330\n6164 83831 10741 15214 0", "output": "738415" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 1 1 1 0\n1 0 0 1 0\n0 1 0 0 1\n1 1 0 0 0\n1 0 0 1 0", "output": "10" }, { "input": "0 3 6 9 8\n2 0 8 7 7\n4 6 0 6 1\n9 0 3 0 6\n6 5 0 2 0", "output": "90" }, { "input": "0 97 67 53 6\n96 0 100 57 17\n27 79 0 66 16\n89 46 71 0 28\n27 26 27 12 0", "output": "926" }, { "input": "0 670 904 349 56\n446 0 941 590 993\n654 888 0 423 752\n16 424 837 0 433\n418 655 459 897 0", "output": "9752" }, { "input": "0 4109 129 1340 7124\n7815 0 8991 2828 909\n5634 799 0 5691 9604\n3261 7013 8062 0 5160\n2433 4742 694 4786 0", "output": "69867" }, { "input": "0 14299 32984 96001 30445\n77723 0 75669 14101 55389\n30897 9956 0 52675 29987\n36518 90812 92955 0 64020\n91242 50085 86272 62454 0", "output": "783459" }, { "input": "0 46183 30304 63049 13191\n37244 0 23076 12594 43885\n98470 1788 0 37335 7775\n33822 50804 27921 0 56734\n38313 67579 77714 46687 0", "output": "666175" }, { "input": "0 39037 87960 13497 38526\n5528 0 44220 23338 92550\n87887 86544 0 30269 82845\n24590 60325 90979 0 20186\n64959 69875 93564 68355 0", "output": "950600" }, { "input": "0 27677 88187 87515 82582\n98177 0 22852 28214 99977\n52662 14066 0 79760 68188\n56883 30561 91843 0 79777\n12461 14821 29284 54372 0", "output": "878207" }, { "input": "0 37330 91942 67667 42061\n1978 0 84218 17 10834\n11303 6279 0 48597 26591\n82688 5437 34983 0 92556\n79574 32231 23167 16637 0", "output": "718057" }, { "input": "0 3 0 0 0\n3 0 2 0 0\n0 2 0 1 0\n0 0 1 0 1\n0 0 0 1 0", "output": "24" } ]
62
0
3
9,548
29
Ant on the Tree
[ "constructive algorithms", "dfs and similar", "trees" ]
D. Ant on the Tree
2
256
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are *n* vertexes in the tree, and they are connected by *n*<=-<=1 edges so that there is a path between any pair of vertexes. A leaf is a distinct from root vertex, which is connected with exactly one other vertex. The ant wants to visit every vertex in the tree and return to the root, passing every edge twice. In addition, he wants to visit the leaves in a specific order. You are to find some possible route of the ant.
The first line contains integer *n* (3<=≤<=*n*<=≤<=300) — amount of vertexes in the tree. Next *n*<=-<=1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The last line contains *k* integers, where *k* is amount of leaves in the tree. These numbers describe the order in which the leaves should be visited. It is guaranteed that each leaf appears in this order exactly once.
If the required route doesn't exist, output -1. Otherwise, output 2*n*<=-<=1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.
[ "3\n1 2\n2 3\n3\n", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3\n", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6\n" ]
[ "1 2 3 2 1 ", "1 2 4 5 4 6 4 2 1 3 1 ", "-1\n" ]
none
[ { "input": "3\n1 2\n2 3\n3", "output": "1 2 3 2 1 " }, { "input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "output": "1 2 4 5 4 6 4 2 1 3 1 " }, { "input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6", "output": "-1" }, { "input": "10\n8 10\n2 1\n7 5\n5 4\n6 10\n2 3\n3 10\n2 9\n7 2\n6 9 4 8", "output": "-1" }, { "input": "8\n4 3\n6 7\n8 6\n6 1\n4 6\n6 5\n6 2\n3 2 7 8 5", "output": "1 6 4 3 4 6 2 6 7 6 8 6 5 6 1 " }, { "input": "8\n4 3\n1 4\n8 5\n7 6\n3 5\n7 3\n4 2\n2 6 8", "output": "1 4 2 4 3 7 6 7 3 5 8 5 3 4 1 " }, { "input": "20\n4 13\n17 7\n19 10\n18 1\n5 15\n2 6\n11 7\n3 6\n5 1\n20 16\n12 5\n10 17\n14 18\n8 13\n13 15\n19 1\n9 19\n6 13\n17 20\n14 12 4 2 3 9 8 11 16", "output": "-1" }, { "input": "37\n27 3\n27 35\n6 8\n12 21\n4 7\n32 27\n27 17\n24 14\n1 10\n3 23\n20 8\n12 4\n16 33\n2 34\n15 36\n5 31\n31 14\n5 9\n8 28\n29 12\n33 35\n24 10\n18 25\n33 18\n2 37\n17 5\n36 29\n12 26\n20 26\n22 11\n23 8\n15 30\n34 6\n13 7\n22 4\n23 19\n37 11 9 32 28 16 21 30 25 19 13", "output": "-1" }, { "input": "51\n28 3\n42 40\n40 51\n48 20\n13 28\n18 40\n44 40\n22 5\n22 27\n45 34\n40 9\n34 46\n40 34\n22 1\n22 11\n40 7\n28 40\n40 22\n14 40\n34 30\n40 20\n47 40\n12 34\n28 23\n40 24\n40 43\n41 40\n28 15\n49 32\n40 8\n32 10\n40 50\n40 36\n40 21\n16 33\n40 38\n34 2\n28 16\n34 4\n17 34\n19 40\n32 35\n40 29\n6 40\n40 39\n22 26\n37 40\n32 40\n31 20\n34 25\n35 15 7 9 12 31 36 50 19 17 29 46 5 42 8 13 10 24 44 25 41 2 38 23 43 30 18 3 26 47 37 11 39 33 49 14 4 45 6 51 48 21 27", "output": "-1" }, { "input": "3\n1 2\n1 3\n2 3", "output": "1 2 1 3 1 " }, { "input": "3\n1 2\n1 3\n3 2", "output": "1 3 1 2 1 " }, { "input": "4\n1 2\n1 3\n1 4\n4 3 2", "output": "1 4 1 3 1 2 1 " }, { "input": "5\n1 2\n4 3\n1 4\n4 5\n5 2 3", "output": "-1" } ]
248
512,000
0
9,566
56
Changing a String
[ "dp" ]
D. Changing a String
2
256
There is a string *s*, consisting of capital Latin letters. Let's denote its current length as |*s*|. During one move it is allowed to apply one of the following operations to it: - INSERT *pos* *ch* — insert a letter *ch* in the string *s* in the position *pos* (1<=≤<=*pos*<=≤<=|*s*|<=+<=1,<=*A*<=≤<=*ch*<=≤<=*Z*). The letter *ch* becomes the *pos*-th symbol of the string *s*, at that the letters shift aside and the length of the string increases by 1. - DELETE *pos* — delete a character number *pos* (1<=≤<=*pos*<=≤<=|*s*|) from the string *s*. At that the letters shift together and the length of the string decreases by 1. - REPLACE *pos* *ch* — the letter in the position *pos* of the line *s* is replaced by *ch* (1<=≤<=*pos*<=≤<=|*s*|,<=*A*<=≤<=*ch*<=≤<=*Z*). At that the length of the string does not change. Your task is to find in which minimal number of moves one can get a *t* string from an *s* string. You should also find the sequence of actions leading to the required results.
The first line contains *s*, the second line contains *t*. The lines consist only of capital Latin letters, their lengths are positive numbers from 1 to 1000.
In the first line print the number of moves *k* in the given sequence of operations. The number should be the minimal possible one. Then print *k* lines containing one operation each. Print the operations in the format, described above. If there are several solutions, print any of them.
[ "ABA\nABBBA\n", "ACCEPTED\nWRONGANSWER\n" ]
[ "2\nINSERT 3 B\nINSERT 4 B\n", "10\nREPLACE 1 W\nREPLACE 2 R\nREPLACE 3 O\nREPLACE 4 N\nREPLACE 5 G\nREPLACE 6 A\nINSERT 7 N\nINSERT 8 S\nINSERT 9 W\nREPLACE 11 R\n" ]
none
[ { "input": "ABA\nABBBA", "output": "2\nINSERT 3 B\nINSERT 4 B" }, { "input": "ACCEPTED\nWRONGANSWER", "output": "10\nREPLACE 1 W\nREPLACE 2 R\nREPLACE 3 O\nREPLACE 4 N\nREPLACE 5 G\nREPLACE 6 A\nINSERT 7 N\nINSERT 8 S\nINSERT 9 W\nREPLACE 11 R" }, { "input": "V\nBNBNE", "output": "5\nREPLACE 1 B\nINSERT 2 N\nINSERT 3 B\nINSERT 4 N\nINSERT 5 E" }, { "input": "UB\nPWL", "output": "3\nREPLACE 1 P\nREPLACE 2 W\nINSERT 3 L" }, { "input": "JOYXNKYPF\nGDV", "output": "9\nREPLACE 1 G\nREPLACE 2 D\nREPLACE 3 V\nDELETE 4\nDELETE 4\nDELETE 4\nDELETE 4\nDELETE 4\nDELETE 4" }, { "input": "SZDAWSVGK\nUM", "output": "9\nREPLACE 1 U\nREPLACE 2 M\nDELETE 3\nDELETE 3\nDELETE 3\nDELETE 3\nDELETE 3\nDELETE 3\nDELETE 3" }, { "input": "TJHGFKKCDOHRNAXZROCWIYFF\nZBWUEHEVEOUATECAGLZIQMUDXEMHRSOZMAUJRWLQMPPZOUMXHAMWUGEDIKVKBLVMXWUOFMPAFDPRBCFTEWOULCZWRQHCTBTBXRHHODWBCXWIMNCNEXOSKSUJLISGCLLLXOKRSBNOZTHAJNNLILYFFMSYKOFPTXRNEFBSOUHFOLTIQAINRPXWRQ", "output": "164\nINSERT 1 Z\nINSERT 2 B\nINSERT 3 W\nINSERT 4 U\nINSERT 5 E\nINSERT 6 H\nINSERT 7 E\nINSERT 8 V\nINSERT 9 E\nINSERT 10 O\nINSERT 11 U\nINSERT 12 A\nINSERT 14 E\nINSERT 15 C\nINSERT 16 A\nINSERT 17 G\nINSERT 18 L\nINSERT 19 Z\nINSERT 20 I\nINSERT 21 Q\nINSERT 22 M\nINSERT 23 U\nINSERT 24 D\nINSERT 25 X\nINSERT 26 E\nINSERT 27 M\nINSERT 28 H\nINSERT 29 R\nINSERT 30 S\nINSERT 31 O\nINSERT 32 Z\nINSERT 33 M\nINSERT 34 A\nINSERT 35 U\nINSERT 37 R\nINSERT 38 W\nINSERT 39 L\nINSERT 40 Q\nINSERT 41 M\nINSERT 4..." }, { "input": "GXPLMUNZIRBHFJOOJHOMQNIKHVQSGFYSJLSWJQBUWYWHLQHLZYLPZWBOMPOLOLUGSBMHHLYGEIOUWDKPFIAAIRKYRLXTIFAZOPOLLPSNZHCIZDRTJPCYSCDTXBTMFSGEPRNOHJHNXZFYJPAMSHNOVZZYWCVEXLLOVHGAJBANAXVNTWCYTCUMQPEUUESQZTSDANIMUVJGDJCDLIAZKIAYAUQKPXRYKFRBVQJDRSUQZQZTIHWZDXQND\nYTJUCSBGESVMVRIDTBJTMPVBCWWDWKBPEBVMGDXGIVLWQXVEETNSDXKTVJPXOPERWSGDPPMKNMWDIGEHFXNUQADIS", "output": "209\nREPLACE 1 Y\nREPLACE 2 T\nREPLACE 3 J\nDELETE 4\nDELETE 4\nREPLACE 5 C\nREPLACE 6 S\nDELETE 7\nDELETE 7\nREPLACE 8 G\nREPLACE 9 E\nREPLACE 10 S\nREPLACE 11 V\nDELETE 12\nDELETE 12\nDELETE 12\nDELETE 12\nREPLACE 13 V\nREPLACE 14 R\nREPLACE 16 D\nREPLACE 17 T\nREPLACE 18 B\nDELETE 19\nDELETE 19\nDELETE 19\nDELETE 19\nDELETE 19\nDELETE 19\nREPLACE 20 T\nREPLACE 21 M\nREPLACE 22 P\nREPLACE 23 V\nDELETE 24\nREPLACE 25 C\nDELETE 27\nREPLACE 28 D\nREPLACE 29 W\nREPLACE 30 K\nREPLACE 31 B\nDELETE 32\nDELETE 3..." }, { "input": "BPYEOOTCVXAZPTHUEAIUZURZPHBWOEHGVHSDBYNXLHGOPBPCLPWQWVRYJGILKOOLASFSFYFGIMPVFGRRINJOXENOIMETWXUWCKXYBPBPPYRTMOZSBMBVJENPUSAEUPMQDGAQXUDIFUPOHYXPUWZLJP\nYRWPQARABPMMBLUZJHDVOUODHRNLMOOVGVJIZDDLXEWCPUFYYPKCDDYGYOLTNHAVURLLEKNOLC", "output": "123\nDELETE 1\nDELETE 1\nREPLACE 2 R\nREPLACE 3 W\nREPLACE 4 P\nREPLACE 5 Q\nREPLACE 6 A\nREPLACE 7 R\nDELETE 8\nREPLACE 9 B\nREPLACE 11 M\nREPLACE 12 M\nREPLACE 13 B\nREPLACE 14 L\nDELETE 15\nDELETE 15\nREPLACE 17 J\nDELETE 18\nDELETE 18\nDELETE 18\nREPLACE 19 D\nREPLACE 20 V\nREPLACE 22 U\nREPLACE 23 O\nDELETE 24\nDELETE 24\nDELETE 24\nDELETE 24\nDELETE 25\nDELETE 25\nDELETE 25\nDELETE 25\nDELETE 25\nDELETE 26\nDELETE 26\nDELETE 26\nDELETE 26\nDELETE 26\nDELETE 26\nDELETE 26\nDELETE 26\nDELETE 26\nDELETE..." }, { "input": "YWJJBIRAPVSKOZUBVXOEMSCFWLSGNDUUBAOGTFAIOWJIZLVJCUKUYCYSAAHVLGCUAXDGYKJQMNOIFUDWFOSAVKRMAKLEKMPPISHARHVGEWRKUADEQZCJUXDVRQIIGO\nYWJJBIRAPVSKOZUBVXOEMSCFWLSGNDUUBAOGTFAIOWJIZLVJCUKUYCYSAAHVLGCUAXDGYKJQMNOIFUDWFOSAVKRMAKLEKMPISHARHVGEWRKUADEQZCJUXDVRQIIGO", "output": "1\nDELETE 96" }, { "input": "A\nC", "output": "1\nREPLACE 1 C" }, { "input": "Z\nZ", "output": "0" } ]
2,000
1,228,800
0
9,574
272
Dima and Staircase
[ "data structures", "implementation" ]
null
null
Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*). Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i* and height *h**i*. Dima throws each box vertically down on the first *w**i* stairs of the staircase, that is, the box covers stairs with numbers 1,<=2,<=...,<=*w**i*. Each thrown box flies vertically down until at least one of the two following events happen: - the bottom of the box touches the top of a stair; - the bottom of the box touches the top of a box, thrown earlier. We only consider touching of the horizontal sides of stairs and boxes, at that touching with the corners isn't taken into consideration. Specifically, that implies that a box with width *w**i* cannot touch the stair number *w**i*<=+<=1. You are given the description of the staircase and the sequence in which Dima threw the boxes at it. For each box, determine how high the bottom of the box after landing will be. Consider a box to fall after the previous one lands.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109; *a**i*<=≤<=*a**i*<=+<=1). The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of boxes. Each of the following *m* lines contains a pair of integers *w**i*,<=*h**i* (1<=≤<=*w**i*<=≤<=*n*; 1<=≤<=*h**i*<=≤<=109) — the size of the *i*-th thrown box. The numbers in the lines are separated by spaces.
Print *m* integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n", "3\n1 2 3\n2\n1 1\n3 1\n", "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n" ]
[ "1\n3\n4\n6\n", "1\n3\n", "1\n3\n13\n23\n33\n" ]
The first sample are shown on the picture.
[ { "input": "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3", "output": "1\n3\n4\n6" }, { "input": "3\n1 2 3\n2\n1 1\n3 1", "output": "1\n3" }, { "input": "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10", "output": "1\n3\n13\n23\n33" }, { "input": "8\n6 10 18 23 30 31 31 33\n1\n5 3", "output": "30" }, { "input": "7\n8 13 19 21 25 30 32\n3\n5 4\n6 5\n1 2", "output": "25\n30\n35" }, { "input": "5\n4 7 10 12 12\n9\n3 9\n2 1\n3 5\n4 7\n1 1\n5 1\n1 7\n2 4\n4 10", "output": "10\n19\n20\n25\n32\n33\n34\n41\n45" }, { "input": "3\n1 6 8\n5\n3 4\n3 9\n3 3\n1 2\n1 6", "output": "8\n12\n21\n24\n26" }, { "input": "3\n2 10 15\n1\n1 830", "output": "2" }, { "input": "2\n1 6\n5\n2 6\n1 2\n1 1\n1 2\n1 7", "output": "6\n12\n14\n15\n17" }, { "input": "1\n9\n8\n1 4\n1 10\n1 9\n1 9\n1 7\n1 1\n1 9\n1 2", "output": "9\n13\n23\n32\n41\n48\n49\n58" }, { "input": "1\n8\n1\n1 42", "output": "8" }, { "input": "1\n1\n1\n1 1", "output": "1" }, { "input": "5\n1 2 3 6 6\n25\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000", "output": "1\n1000000001\n2000000001\n3000000001\n4000000001\n5000000001\n6000000001\n7000000001\n8000000001\n9000000001\n10000000001\n11000000001\n12000000001\n13000000001\n14000000001\n15000000001\n16000000001\n17000000001\n18000000001\n19000000001\n20000000001\n21000000001\n22000000001\n23000000001\n24000000001" }, { "input": "1\n1000000000\n6\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000", "output": "1000000000\n2000000000\n3000000000\n4000000000\n5000000000\n6000000000" } ]
872
15,155,200
3
9,605
889
Mod Mod Mod
[ "binary search", "dp", "math" ]
null
null
You are given a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. Let , and for 1<=≤<=*i*<=&lt;<=*n*. Here, denotes the modulus operation. Find the maximum value of *f*(*x*,<=1) over all nonnegative integers *x*.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200000) — the length of the sequence. The second lines contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1013) — the elements of the sequence.
Output a single integer — the maximum value of *f*(*x*,<=1) over all nonnegative integers *x*.
[ "2\n10 5\n", "5\n5 4 3 2 1\n", "4\n5 10 5 10\n" ]
[ "13\n", "6\n", "16\n" ]
In the first example you can choose, for example, *x* = 19. In the second example you can choose, for example, *x* = 3 or *x* = 2.
[]
1,247
0
0
9,613
932
Escape Through Leaf
[ "data structures", "dp", "geometry" ]
null
null
You are given a tree with *n* nodes (numbered from 1 to *n*) rooted at node 1. Also, each node has two values associated with it. The values for *i*-th node are *a**i* and *b**i*. You can jump from a node to any node in its subtree. The cost of one jump from node *x* to node *y* is the product of *a**x* and *b**y*. The total cost of a path formed by one or more jumps is sum of costs of individual jumps. For every node, calculate the minimum total cost to reach any leaf from that node. Pay attention, that root can never be leaf, even if it has degree 1. Note that you cannot jump from a node to itself.
The first line of input contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of nodes in the tree. The second line contains *n* space-separated integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n*(<=-<=105<=<=≤<=<=*a**i*<=<=≤<=<=105). The third line contains *n* space-separated integers *b*1,<=<=*b*2,<=<=...,<=<=*b**n*(<=-<=105<=<=≤<=<=*b**i*<=<=≤<=<=105). Next *n*<=<=-<=<=1 lines contains two space-separated integers *u**i* and *v**i* (1<=≤<=*u**i*,<=<=*v**i*<=≤<=<=*n*) describing edge between nodes *u**i* and *v**i* in the tree.
Output *n* space-separated integers, *i*-th of which denotes the minimum cost of a path from node *i* to reach any leaf.
[ "3\n2 10 -1\n7 -7 5\n2 3\n2 1\n", "4\n5 -10 5 7\n-8 -80 -3 -10\n2 1\n2 4\n1 3\n" ]
[ "10 50 0 ", "-300 100 0 0 " ]
In the first example, node 3 is already a leaf, so the cost is 0. For node 2, jump to node 3 with cost *a*<sub class="lower-index">2</sub> × *b*<sub class="lower-index">3</sub> = 50. For node 1, jump directly to node 3 with cost *a*<sub class="lower-index">1</sub> × *b*<sub class="lower-index">3</sub> = 10. In the second example, node 3 and node 4 are leaves, so the cost is 0. For node 2, jump to node 4 with cost *a*<sub class="lower-index">2</sub> × *b*<sub class="lower-index">4</sub> = 100. For node 1, jump to node 2 with cost *a*<sub class="lower-index">1</sub> × *b*<sub class="lower-index">2</sub> =  - 400 followed by a jump from 2 to 4 with cost *a*<sub class="lower-index">2</sub> × *b*<sub class="lower-index">4</sub> = 100.
[ { "input": "3\n2 10 -1\n7 -7 5\n2 3\n2 1", "output": "10 50 0 " }, { "input": "4\n5 -10 5 7\n-8 -80 -3 -10\n2 1\n2 4\n1 3", "output": "-300 100 0 0 " }, { "input": "5\n7 -8 -8 -3 -10\n6 1 -6 7 5\n3 1\n2 5\n1 4\n4 5", "output": "-42 0 0 -25 -10 " }, { "input": "6\n4 -8 9 -1 -2 -7\n8 -7 -6 1 1 0\n6 1\n5 1\n2 1\n4 1\n3 6", "output": "-28 0 0 0 0 42 " }, { "input": "2\n4 5\n-10 6\n2 1", "output": "24 0 " } ]
0
0
-1
9,615
45
Event Dates
[ "greedy", "meet-in-the-middle", "sortings" ]
D. Event Dates
2
256
On a history lesson the teacher asked Vasya to name the dates when *n* famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [*l**i*,<=*r**i*] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such *n* dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of known events. Then follow *n* lines containing two integers *l**i* and *r**i* each (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=107) — the earliest acceptable date and the latest acceptable date of the *i*-th event.
Print *n* numbers — the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
[ "3\n1 2\n2 3\n3 4\n", "2\n1 3\n1 3\n" ]
[ "1 2 3 \n", "1 2 \n" ]
none
[ { "input": "3\n1 2\n2 3\n3 4", "output": "1 2 3 " }, { "input": "2\n1 3\n1 3", "output": "1 2 " }, { "input": "10\n1 10\n3 4\n8 10\n3 4\n5 9\n1 4\n7 10\n1 9\n1 8\n4 10", "output": "7 3 10 4 6 1 9 5 2 8 " }, { "input": "10\n1 1\n8 10\n1 7\n6 8\n5 7\n1 9\n8 8\n6 10\n1 4\n3 4", "output": "1 10 4 6 5 7 8 9 2 3 " }, { "input": "10\n1 2\n1 3\n1 9\n10 10\n4 4\n5 9\n2 5\n7 8\n2 10\n7 10", "output": "1 2 5 10 4 6 3 7 8 9 " }, { "input": "10\n4 12\n2 8\n1 12\n6 8\n4 6\n12 12\n3 10\n1 10\n3 3\n1 10", "output": "9 2 8 6 4 12 7 1 3 5 " }, { "input": "10\n6 7\n5 11\n5 10\n9 10\n11 12\n6 12\n7 11\n1 1\n5 9\n2 8", "output": "6 8 7 9 12 11 10 1 5 2 " }, { "input": "10\n3 11\n2 12\n7 12\n5 5\n6 6\n1 11\n11 11\n1 12\n1 10\n7 11", "output": "3 8 9 5 6 2 11 4 1 7 " }, { "input": "10\n1 4\n1 12\n5 7\n5 5\n2 5\n1 7\n1 10\n7 9\n8 9\n9 11", "output": "1 10 6 5 2 3 4 7 8 9 " }, { "input": "10\n1 2\n10 12\n5 12\n1 7\n1 6\n11 12\n3 8\n7 9\n11 12\n5 6", "output": "1 10 6 3 2 11 4 7 12 5 " }, { "input": "10\n6 9\n1 8\n6 12\n8 15\n2 5\n1 2\n7 15\n12 15\n5 12\n8 15", "output": "6 3 7 9 2 1 8 12 5 10 " }, { "input": "10\n2 4\n10 13\n1 10\n6 13\n9 12\n1 10\n13 15\n1 11\n1 7\n5 6", "output": "2 10 3 7 9 4 13 6 1 5 " }, { "input": "10\n15 15\n6 6\n1 6\n7 15\n3 13\n10 15\n6 13\n1 9\n2 14\n12 13", "output": "15 6 1 8 3 10 7 2 4 12 " }, { "input": "10\n10 10\n13 15\n6 14\n3 15\n4 15\n11 12\n11 15\n8 15\n1 11\n1 9", "output": "10 13 6 3 4 11 12 8 2 1 " }, { "input": "10\n12 12\n6 13\n5 9\n7 11\n1 12\n11 15\n3 13\n1 14\n6 8\n10 10", "output": "12 8 5 7 1 11 3 2 6 10 " }, { "input": "10\n1 6\n4 10\n1 5\n5 10\n1 8\n4 5\n1 8\n4 8\n5 10\n10 10", "output": "2 7 1 8 3 4 5 6 9 10 " }, { "input": "10\n2 8\n8 10\n1 6\n1 10\n7 10\n1 9\n6 8\n3 4\n1 3\n5 8", "output": "4 10 2 8 9 7 6 3 1 5 " } ]
186
20,172,800
0
9,625
712
Memory and Casinos
[ "data structures", "math", "probabilities" ]
null
null
There are *n* casinos lined in a row. If Memory plays at casino *i*, he has probability *p**i* to win and move to the casino on the right (*i*<=+<=1) or exit the row (if *i*<==<=*n*), and a probability 1<=-<=*p**i* to lose and move to the casino on the left (*i*<=-<=1) or also exit the row (if *i*<==<=1). We say that Memory dominates on the interval *i*... *j* if he completes a walk such that, - He starts on casino *i*. - He never looses in casino *i*. - He finishes his walk by winning in casino *j*. Note that Memory can still walk left of the 1-st casino and right of the casino *n* and that always finishes the process. Now Memory has some requests, in one of the following forms: - 1 *i* *a* *b*: Set . - 2 *l* *r*: Print the probability that Memory will dominate on the interval *l*... *r*, i.e. compute the probability that Memory will first leave the segment *l*... *r* after winning at casino *r*, if she starts in casino *l*. It is guaranteed that at any moment of time *p* is a non-decreasing sequence, i.e. *p**i*<=≤<=*p**i*<=+<=1 for all *i* from 1 to *n*<=-<=1. Please help Memory by answering all his requests!
The first line of the input contains two integers *n* and *q*(1<=≤<=*n*,<=*q*<=≤<=100<=000),  — number of casinos and number of requests respectively. The next *n* lines each contain integers *a**i* and *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=109)  — is the probability *p**i* of winning in casino *i*. The next *q* lines each contain queries of one of the types specified above (1<=≤<=*a*<=&lt;<=*b*<=≤<=109, 1<=≤<=*i*<=≤<=*n*, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*). It's guaranteed that there will be at least one query of type 2, i.e. the output will be non-empty. Additionally, it is guaranteed that *p* forms a non-decreasing sequence at all times.
Print a real number for every request of type 2 — the probability that boy will "dominate" on that interval. Your answer will be considered correct if its absolute error does not exceed 10<=-<=4. Namely: let's assume that one of your answers is *a*, and the corresponding answer of the jury is *b*. The checker program will consider your answer correct if |*a*<=-<=*b*|<=≤<=10<=-<=4.
[ "3 13\n1 3\n1 2\n2 3\n2 1 1\n2 1 2\n2 1 3\n2 2 2\n2 2 3\n2 3 3\n1 2 2 3\n2 1 1\n2 1 2\n2 1 3\n2 2 2\n2 2 3\n2 3 3\n" ]
[ "0.3333333333\n0.2000000000\n0.1666666667\n0.5000000000\n0.4000000000\n0.6666666667\n0.3333333333\n0.2500000000\n0.2222222222\n0.6666666667\n0.5714285714\n0.6666666667\n" ]
none
[]
46
0
0
9,628
763
Timofey and a tree
[ "dfs and similar", "dp", "dsu", "graphs", "implementation", "trees" ]
null
null
Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*. Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex in hands, while all the other vertices move down so that the tree becomes rooted at the chosen vertex. After that Timofey brings the tree to a trash can. Timofey doesn't like it when many colors are mixing together. A subtree annoys him if there are vertices of different color in it. Timofey wants to find a vertex which he should take in hands so that there are no subtrees that annoy him. He doesn't consider the whole tree as a subtree since he can't see the color of the root vertex. A subtree of some vertex is a subgraph containing that vertex and all its descendants. Your task is to determine if there is a vertex, taking which in hands Timofey wouldn't be annoyed.
The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the number of vertices in the tree. Each of the next *n*<=-<=1 lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*), denoting there is an edge between vertices *u* and *v*. It is guaranteed that the given graph is a tree. The next line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105), denoting the colors of the vertices.
Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him. Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them.
[ "4\n1 2\n2 3\n3 4\n1 2 1 1\n", "3\n1 2\n2 3\n1 2 3\n", "4\n1 2\n2 3\n3 4\n1 2 1 2\n" ]
[ "YES\n2", "YES\n2", "NO" ]
none
[ { "input": "4\n1 2\n2 3\n3 4\n1 2 1 1", "output": "YES\n2" }, { "input": "3\n1 2\n2 3\n1 2 3", "output": "YES\n2" }, { "input": "4\n1 2\n2 3\n3 4\n1 2 1 2", "output": "NO" }, { "input": "3\n2 1\n2 3\n1 2 3", "output": "YES\n2" }, { "input": "4\n1 2\n2 4\n4 3\n1 1 3 2", "output": "YES\n4" }, { "input": "2\n1 2\n1 1", "output": "YES\n1" }, { "input": "10\n5 7\n4 5\n10 2\n3 6\n1 2\n3 4\n8 5\n4 9\n2 3\n15 15 15 15 5 15 26 18 15 15", "output": "YES\n5" }, { "input": "8\n1 2\n1 3\n3 5\n3 6\n1 4\n4 7\n4 8\n1 3 1 1 1 1 1 2", "output": "NO" }, { "input": "3\n2 1\n2 3\n4 4 4", "output": "YES\n1" }, { "input": "3\n1 2\n1 3\n1 2 2", "output": "YES\n1" }, { "input": "4\n1 4\n2 4\n3 4\n1 2 3 1", "output": "YES\n4" }, { "input": "4\n1 2\n1 3\n1 4\n1 2 3 4", "output": "YES\n1" }, { "input": "9\n1 2\n2 3\n3 4\n4 5\n2 7\n7 6\n2 8\n8 9\n1 1 2 2 2 3 3 4 4", "output": "YES\n2" }, { "input": "3\n2 1\n2 3\n4 4 5", "output": "YES\n2" }, { "input": "4\n1 2\n2 3\n3 4\n1 2 2 1", "output": "NO" } ]
951
14,950,400
3
9,646
252
Unsorting Array
[ "brute force", "sortings" ]
null
null
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of *n* elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements. Array *a* (the array elements are indexed from 1) consisting of *n* elements is called sorted if it meets at least one of the following two conditions: 1. *a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*; 1. *a*1<=≥<=*a*2<=≥<=...<=≥<=*a**n*. Help Petya find the two required positions to swap or else say that they do not exist.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* non-negative space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to *n*.
[ "1\n1\n", "2\n1 2\n", "4\n1 2 3 4\n", "3\n1 1 1\n" ]
[ "-1\n", "-1\n", "1 2\n", "-1\n" ]
In the first two samples the required pairs obviously don't exist. In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
[ { "input": "1\n1", "output": "-1" }, { "input": "2\n1 2", "output": "-1" }, { "input": "4\n1 2 3 4", "output": "1 2" }, { "input": "3\n1 1 1", "output": "-1" }, { "input": "3\n1 2 2", "output": "1 2" }, { "input": "5\n1 1 1 1 2", "output": "2 5" }, { "input": "6\n1 2 3 3 2 1", "output": "1 2" }, { "input": "7\n6 5 4 3 2 1 0", "output": "1 2" }, { "input": "10\n1 2 1 2 1 2 1 2 1 2", "output": "1 2" }, { "input": "11\n1 1 1 1 1 2 2 2 2 2 1", "output": "1 6" }, { "input": "3\n1 2 1", "output": "-1" }, { "input": "4\n562617869 961148050 596819899 951133776", "output": "1 2" }, { "input": "4\n562617869 596819899 951133776 961148050", "output": "1 2" }, { "input": "4\n961148050 951133776 596819899 562617869", "output": "1 2" }, { "input": "4\n596819899 562617869 951133776 961148050", "output": "1 3" }, { "input": "4\n562617869 596819899 951133776 0", "output": "1 2" }, { "input": "4\n951133776 961148050 596819899 562617869", "output": "1 3" }, { "input": "4\n961148050 951133776 596819899 0", "output": "1 2" }, { "input": "4\n562617869 562617869 562617869 562617869", "output": "-1" }, { "input": "4\n961148050 961148050 562617869 961148050", "output": "2 3" }, { "input": "4\n562617869 961148050 961148050 961148050", "output": "1 2" }, { "input": "4\n961148050 961148050 961148050 562617869", "output": "2 4" }, { "input": "4\n961148050 562617869 961148050 961148050", "output": "2 3" }, { "input": "4\n562617869 961148050 961148050 961148050", "output": "1 2" }, { "input": "4\n562617869 961148050 562617869 562617869", "output": "2 3" }, { "input": "4\n562617869 562617869 562617869 961148050", "output": "2 4" }, { "input": "4\n961148050 562617869 562617869 562617869", "output": "1 2" }, { "input": "4\n961148050 562617869 961148050 961148050", "output": "2 3" }, { "input": "4\n961148050 961148050 562617869 961148050", "output": "2 3" }, { "input": "4\n562617869 562617869 961148050 562617869", "output": "2 3" }, { "input": "4\n562617869 961148050 562617869 562617869", "output": "2 3" }, { "input": "3\n2 1 3", "output": "1 3" }, { "input": "4\n2 1 3 4", "output": "1 3" }, { "input": "3\n2 1 2", "output": "-1" }, { "input": "5\n1 1 2 1 1", "output": "2 3" }, { "input": "3\n1 3 1", "output": "-1" }, { "input": "3\n1 3 2", "output": "1 2" }, { "input": "3\n3 2 3", "output": "-1" } ]
186
12,902,400
3
9,654
807
T-Shirt Hunt
[ "brute force", "implementation" ]
null
null
Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt. Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place *p*. Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let *s* be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed: Here "div" is the integer division operator, "mod" is the modulo (the remainder of division) operator. As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of *s*. You're in the lead of the elimination round of 8VC Venture Cup 2017, having *x* points. You believe that having at least *y* points in the current round will be enough for victory. To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It's difficult to do successful hacks, though. You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?
The only line contains three integers *p*, *x* and *y* (26<=≤<=*p*<=≤<=500; 1<=≤<=*y*<=≤<=*x*<=≤<=20000) — your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.
Output a single integer — the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt. It's guaranteed that your goal is achievable for any valid input data.
[ "239 10880 9889\n", "26 7258 6123\n", "493 8000 8000\n", "101 6800 6500\n", "329 19913 19900\n" ]
[ "0\n", "2\n", "24\n", "0\n", "8\n" ]
In the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places: In the second example, you have to do two successful and one unsuccessful hack to make your score equal to 7408. In the third example, you need to do as many as 24 successful hacks to make your score equal to 10400. In the fourth example, it's sufficient to do 6 unsuccessful hacks (and no successful ones) to make your score equal to 6500, which is just enough for winning the current round and also getting the T-shirt.
[ { "input": "239 10880 9889", "output": "0" }, { "input": "26 7258 6123", "output": "2" }, { "input": "493 8000 8000", "output": "24" }, { "input": "101 6800 6500", "output": "0" }, { "input": "329 19913 19900", "output": "8" }, { "input": "264 19252 10888", "output": "0" }, { "input": "176 9670 9174", "output": "6" }, { "input": "42 11 6", "output": "27" }, { "input": "412 17647 15917", "output": "8" }, { "input": "91 4883 4302", "output": "12" }, { "input": "200 16031 15842", "output": "24" }, { "input": "186 18666 18329", "output": "23" }, { "input": "486 9748 9598", "output": "25" }, { "input": "180 4213 4207", "output": "27" }, { "input": "329 19989 1", "output": "0" }, { "input": "390 11676 2570", "output": "0" }, { "input": "173 7017 4512", "output": "0" }, { "input": "38 6404 5034", "output": "0" }, { "input": "364 17243 16625", "output": "0" }, { "input": "57 11066 9738", "output": "1" }, { "input": "419 9142 8622", "output": "1" }, { "input": "31 12956 10515", "output": "2" }, { "input": "412 5027 4975", "output": "2" }, { "input": "94 1231 986", "output": "3" }, { "input": "173 7783 7674", "output": "3" }, { "input": "338 8291 8008", "output": "7" }, { "input": "424 10906 10346", "output": "13" }, { "input": "168 2953 2292", "output": "17" }, { "input": "406 16527 16314", "output": "22" }, { "input": "368 1597 1506", "output": "26" }, { "input": "111 14627 14479", "output": "26" }, { "input": "400 15224 15212", "output": "27" }, { "input": "427 19269 19231", "output": "27" }, { "input": "26 10232 10220", "output": "27" }, { "input": "500 7030 7023", "output": "27" }, { "input": "26 13819 13682", "output": "0" }, { "input": "500 18737 18069", "output": "0" }, { "input": "26 20000 20000", "output": "7" }, { "input": "26 1 1", "output": "6" }, { "input": "26 20000 1", "output": "0" }, { "input": "68 51 1", "output": "0" }, { "input": "198 6550 6549", "output": "5" }, { "input": "68 50 49", "output": "5" }, { "input": "239 10927 10880", "output": "11" }, { "input": "239 10830 9889", "output": "1" }, { "input": "329 2150 1900", "output": "0" }, { "input": "164 49 48", "output": "1" }, { "input": "329 2150 2101", "output": "6" } ]
30
0
-1
9,668
7
Defining Macros
[ "dp", "expression parsing", "implementation" ]
E. Defining Macros
3
256
Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use. In this problem we consider the following model of #define constructions (also called macros). Each macro has its name and value. The generic syntax for declaring a macro is the following: #define macro_name macro_value After the macro has been declared, "macro_name" is replaced with "macro_value" each time it is met in the program (only the whole tokens can be replaced; i.e. "macro_name" is replaced only when it is surrounded by spaces or other non-alphabetic symbol). A "macro_value" within our model can only be an arithmetic expression consisting of variables, four arithmetic operations, brackets, and also the names of previously declared macros (in this case replacement is performed sequentially). The process of replacing macros with their values is called substitution. One of the main problems arising while using macros — the situation when as a result of substitution we get an arithmetic expression with the changed order of calculation because of different priorities of the operations. Let's consider the following example. Say, we declared such a #define construction: #define sum x + y and further in the program the expression "2 * sum" is calculated. After macro substitution is performed we get "2 * x + y", instead of intuitively expected "2 * (x + y)". Let's call the situation "suspicious", if after the macro substitution the order of calculation changes, falling outside the bounds of some macro. Thus, your task is to find out by the given set of #define definitions and the given expression if this expression is suspicious or not. Let's speak more formally. We should perform an ordinary macros substitution in the given expression. Moreover, we should perform a "safe" macros substitution in the expression, putting in brackets each macro value; after this, guided by arithmetic rules of brackets expansion, we can omit some of the brackets. If there exist a way to get an expression, absolutely coinciding with the expression that is the result of an ordinary substitution (character-by-character, but ignoring spaces), then this expression and the macros system are called correct, otherwise — suspicious. Note that we consider the "/" operation as the usual mathematical division, not the integer division like in C/C++. That's why, for example, in the expression "a*(b/c)" we can omit brackets to get the expression "a*b/c".
The first line contains the only number *n* (0<=≤<=*n*<=≤<=100) — the amount of #define constructions in the given program. Then there follow *n* lines, each of them contains just one #define construction. Each construction has the following syntax: #define name expression where - name — the macro name, - expression — the expression with which the given macro will be replaced. An expression is a non-empty string, containing digits,names of variables, names of previously declared macros, round brackets and operational signs +-*/. It is guaranteed that the expression (before and after macros substitution) is a correct arithmetic expression, having no unary operations. The expression contains only non-negative integers, not exceeding 109. All the names (#define constructions' names and names of their arguments) are strings of case-sensitive Latin characters. It is guaranteed that the name of any variable is different from any #define construction. Then, the last line contains an expression that you are to check. This expression is non-empty and satisfies the same limitations as the expressions in #define constructions. The input lines may contain any number of spaces anywhere, providing these spaces do not break the word "define" or the names of constructions and variables. In particular, there can be any number of spaces before and after the "#" symbol. The length of any line from the input file does not exceed 100 characters.
Output "OK", if the expression is correct according to the above given criterion, otherwise output "Suspicious".
[ "1\n#define sum x + y\n1 * sum\n", "1\n#define sum (x + y)\nsum - sum\n", "4\n#define sum x + y\n#define mul a * b\n#define div a / b\n#define expr sum + mul * div * mul\nexpr\n", "3\n#define SumSafe (a+b)\n#define DivUnsafe a/b\n#define DenominatorUnsafe a*b\n((SumSafe) + DivUnsafe/DivUnsafe + x/DenominatorUnsafe)\n" ]
[ "Suspicious\n", "OK\n", "OK\n", "Suspicious\n" ]
none
[ { "input": "1\n#define sum x + y\n1 * sum", "output": "Suspicious" }, { "input": "1\n#define sum (x + y)\nsum - sum", "output": "OK" }, { "input": "4\n#define sum x + y\n#define mul a * b\n#define div a / b\n#define expr sum + mul * div * mul\nexpr", "output": "OK" }, { "input": "3\n#define SumSafe (a+b)\n#define DivUnsafe a/b\n#define DenominatorUnsafe a*b\n((SumSafe) + DivUnsafe/DivUnsafe + x/DenominatorUnsafe)", "output": "Suspicious" }, { "input": "0\naa + b - c * (ddd * eee / fff * a / b * c + d - b + c - (a + b)) - d", "output": "OK" }, { "input": "2\n#define a b\n#define c d\na + b + c + d + 1234567 -10*(2-2+1000*1000*1000*1000*1000)", "output": "OK" }, { "input": "2\n # define macros ( x + y ) \n # define Macros (x+y)\nmacros/Macros", "output": "OK" }, { "input": "2\n#define A v\n#define a v/v/v\nv/A", "output": "OK" }, { "input": "2\n#define A v\n#define a v/v/v\nv/a", "output": "Suspicious" }, { "input": "2\n#define A v\n#define a v/v/v\nv/(a)", "output": "OK" }, { "input": "1\n#define a x*y\nc/a", "output": "Suspicious" }, { "input": "1\n#define a b*c\na/a*a", "output": "Suspicious" }, { "input": "3\n#define mul x*y\n#define bad x/mul\n#define good x/(mul)\ngood", "output": "OK" }, { "input": "4\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define mult a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nsum+difference+(sum)*(difference)-mult+mult*division+division*mult+division/(mult+sum-(difference))", "output": "OK" }, { "input": "4\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define multiplication a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n(difference/division)+sum", "output": "Suspicious" }, { "input": "4\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define multiplication a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n(difference)*sum", "output": "Suspicious" }, { "input": "4\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define multiplication a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n(sum)/multiplication", "output": "Suspicious" }, { "input": "4\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define multiplication a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nsum/(multiplication)", "output": "Suspicious" }, { "input": "5\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define multiplication a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n#define res (0-difference)\nsum+res*multiplication", "output": "Suspicious" }, { "input": "4\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define multiplication a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\ndivision/(multiplication/(division)/DIVISION/(sum-division-multiplication-(difference)))", "output": "OK" }, { "input": "3\n#define sum x + y\n#define SomeBad (2 * sum)\n#define SomePossiblyGood 0 * SomeBad + (x + x - 2*x) * SomeBad\nSomePossiblyGood", "output": "Suspicious" }, { "input": "2\n#define a 0\n#define b (a-a)*(x/x-1)\nb-b/b*b", "output": "Suspicious" }, { "input": "2\n#define fkdsjfslkjfsdk x/0\n#define fkdsjfslkjfsdksdds 0/(0-0)\nfkdsjfslkjfsdk + fkdsjfslkjfsdks + fkdsjfslkjfsdkssds", "output": "OK" }, { "input": "3\n#define null x/0\n#define some x/x\n#define bad 1/x\nbad/0+0/bad+0/0*bad", "output": "Suspicious" }, { "input": "3\n#define MWjGY x+x*53 *x\n#define ovqZ 2/926+x/A\n#define uU 55-qRj*A*2\nx*A/x-A", "output": "OK" }, { "input": "4\n#define zz 5+7/x*x*9\n#define mlTL 6+x/7+x/x\n#define DUO 7*7-x+zz\n#define IH 6*4-x+x\n67/(5)-IH", "output": "Suspicious" }, { "input": "5\n#define Oc 9/51+65+vN\n#define gga 53/ 94/x/x\n#define ArB x/x/9-77-8\n#define j 76-6/93+vN\n#define cALNN Oc+60499\n8*6-66/x*x", "output": "OK" }, { "input": "3\n#define fSdvwOj (W)*W+73\n#define NAZjc 7695*55-x\n#define AHGGglVwch (6-a-W)\n((5))+W+W", "output": "OK" }, { "input": "4\n#define m bJJD +x \n#define yYkQNzjR (x*19)-892\n#define MNvfxqfbq (x-6*x/8)\n#define nJZdvO 8/4 *m/m\n 9+m/x+x", "output": "Suspicious" }, { "input": "5\n#define Sl x*7-(x)/O\n#define srAOHccTln 3+x*2*O\n#define OFAZk 239751817\n#define JYWrOEgazV (x-O/4)-x\n#define XsOZvalgOh 89905879/7\nx/Sl-(Sl)", "output": "Suspicious" }, { "input": "3\n#define uYdw ((9-x-3) )\n#define fy (((x+21)))\n#define nY ((2+x)-46)\n141141432", "output": "OK" }, { "input": "4\n#define GCvqH (58 )-(x)\n#define g ((x/x+x))\n#define spst hQTJ\n#define i GCvqH\n(((x+6)))", "output": "OK" }, { "input": "5\n#define rg (67)+((x))\n#define ya x-(6/x)*rg\n#define anTxe 10*ya*(x)\n#define xcmo ((x)*(vT))\n#define eg ((vT)) -ya\n((x*(Ii)))", "output": "OK" }, { "input": "3\n#define T ((b/1 +1))\n#define pm (s)-43-(s)\n#define jkNBpvDZl ((x ))/65\n(((58*7)))", "output": "OK" }, { "input": "4\n#define cJitUt 21/(4)+4+4\n#define zHwBOLIvF 4*((41/x))\n#define GbtYVo (E)+(x+3)\n#define zTcZBaby (58)+x-x+x\n(E+E)/8 *4", "output": "OK" }, { "input": "5\n#define mBURKdeKvy 266693986\n#define nWi ( ((x))-4)\n#define iYreeOt ((7/x+42))\n#define laLzP ((aB/35)) \n#define dXjRJ (((B*hX)))\n(1*2+(67))", "output": "OK" }, { "input": "3\n#define UVMQLGvEqOxaAgRkvJH tBd\n#define QoAsBMaUcJzXai x/x-hm/83+8*8/5/hm /x/hm\n#define QtxtzEHCmidm 75 +491928441\n((x)/VUpYoEdDUtLFanGyqfQR )", "output": "OK" }, { "input": "4\n#define efemx 2/1*3*69+81+10/690445104\n#define AyjrEzAjMKZpRPfCOaO 21*9+( j*40+3*4)*ND+w-j*j+x*55\n#define YkJkHcNhXcci 85*3215/40/365819568\n#define MUzvOZSXJujI 9-4/j*j-7-w*23*5+j+9-9*ND*2/37\nND/j*28 -1* ND+22889023/j/j/j", "output": "OK" }, { "input": "5\n#define QNUkjqPcGWF 6*4/908975666-7/10-x*7\n#define xqwhNWiiMaZOcmgiXYY 3936*(e*5*H+2)-TsA+(e)/1-25\n#define tRsSqfqJt ((uT*82/e)+e/(23+(45)-9)+(50))\n#define DtIOWRkYe (8*3/9)*e*x *60041512*2-(e)\n#define qgPgxja (4/x+e/uT*16358009- 6/13*5)\ne+x*e/84/x+uT*H", "output": "OK" }, { "input": "3\n#define lTCUUO JQmj\n#define oUeQMB (12*x+x+x)-75-(79/1)-(7)*1/mr\n#define LAQu xwvBtky\n8654 *1*5-mr-3*J/oUeQMB/x/6/9", "output": "Suspicious" }, { "input": "4\n#define VLuQIO 1-x/33+ Fk+wS/35-wS-(x*iz )\n#define BCIsIR 5*(wS)/x/iz/1+x-x-4-x/68/x/8*x\n#define QPUpmTiB 21-x/895912506+2\n#define wcZLUIqJS 7/65-x*61-(24+iz)+x+315670+x/x\nBCIsIR/VLuQIO", "output": "Suspicious" }, { "input": "5\n#define FDmMYOENCOKmYwYlOl 6-(L)/((((ud/x))/ud-26*8-5))\n#define QkopKBjKdJxhc (6)*4/7-L/781844832 \n#define UjgTieUBXTSTbiLFAhkV 3*1*(52)/6-6*65/x+((L-56))+x+x\n#define yWVYDuqliezpKLwnI 8/4+1+88+97946+(1)-((68))-L/L\n#define AvvED 719901121+95/2/78/1-10+37\n(1*x+ 528176190+17/ud)", "output": "OK" }, { "input": "3\n#define e x *R/5+(x)+4/18/x*R/x-8+1+R\n#define GgGqGYjXoJjIezAVu (( 491563947*R))*9-e-3/4\n#define XgznGUWMxQwh (8/R+4*(e)+10/4*x+24*R+21)-224\n (82493582)", "output": "OK" }, { "input": "4\n#define MrKSTrKhPLeJqOcEPvv (x+x/x)/Qdf-x-x-(2/23)+9442-x\n#define zPHUgmIYE 10- 7*x/x+VwRUuIRezDR*80\n#define OsfThxasHeFZCEZTfD 271456028-(x*x)-8+2*x*x*x+(x)\n#define zVYasB x/x -x-(51)-x*x*((x)) /x \n(x/64-x*( (5+x+x)-(37)/3*22))", "output": "OK" }, { "input": "5\n#define WREol (fcdGZaLzhiFpVQmhHO)\n#define lDTNxcMqPPP 3+(57)/x/91540-x*71-x*6-((1))\n#define afFJVBkr ((12*x-8+9 *lDlx+7+lDlx))\n#define mYEizEWrNtRSQNCcDQrn 732480960+9+x-78-x/1+12*x\n#define IZTmjheAahbNSNFa ((x-x*7+407643063 ))\nXQvMxLNpQnhpimNhAkfX", "output": "OK" }, { "input": "3\n#define Mc x+x*55231- x/x/x+35/x*(5*(x)) -5*x*(1-2-(29/1))\n#define afSVLCdjvylSu bgqv/6+4*x*((Mc/1318/x-8-4)-Mc/Mc/(9))\n#define ZOSV (1+2/x+6* 174806683)-x/x*Mc+52*x-x\nbgqv-x-6*x/72/(x )/afSVLCdjvylSu", "output": "Suspicious" }, { "input": "4\n#define RJIiiGQqn dmpWFcrqQeM+V-o* 55/9*o-o/V*V*o\n#define ElDZlrtzDkeKgsX 498718105* 3/(y)/(4)-(5*x)*1\n#define qwKl jHqPHX\n#define qXzAZkCuchBYR (qy*qwKl-6+5*1+2)-7-3+(38)-o*4/4-1-V*x/6+1*x/o\no*((V))-o+2+((((2*V)/V-o*V/4)))/o*33+y/7 -x+x ", "output": "OK" }, { "input": "5\n#define WTovyGexUNjGMRJv (MQG*18-6)/x/x*x/x-x*akNyw*x+x-x/2/x*20\n#define hpextyhVCa 70*x/67-x*87931-(497612505-7*x-MQG)-x\n#define MRkKnCXFt x-5-21962-x/sOmThNSS/x/6-4+(65+57+x+x+7-7+x/x)\n#define ajsczBLLklBSqqh nGj-38*9 *x/47/8*5/5-72/x*x-x*x*31 /7-44-3+64\n#define jgqfv WTovyGexUNjGMRJv\n 4+338/x*x+13 -795*3-74*2/4+563-x/76401438/83025", "output": "OK" }, { "input": "3\n#define G u+13-35348/2-(u/u)-u/u*u*(OC)-OC -u-u/u*u/9 \n#define RNRQ G*G*u+G/755750/G/G +((u-6*G+6)*2)- 5*96+5/u*275-u\n#define Zg 94363/u*u-41+Gm*G-81/5-1-G*G*x-(5517*5/4)*21 +75\n406690013/WM*G+(u+u)*Zg+2", "output": "Suspicious" }, { "input": "4\n#define RMWAZhIp x*x+12+94*12*5*1-x-141915293\n#define EeguG 9-55+x/29+x+x/E*8*81/x-x*75-4*17-81/x/6+619978*x*x\n#define HvUYEvQTyYmBGvqHSb 454574730/644135926*x/23+E-sy/14\n#define BqMGcT x/(43)+819897061-x*(7/x)-(x)+sy-E-x*79-E+(x)/6/63\n76+3/x/8*x+E-76+sy-sy+9*6/66/sy-77+x-x*sy+E/50/64", "output": "OK" }, { "input": "5\n#define cbt ((((d))+9-3+ (d)/d/6*SDDNqj*50/d+d-m+8/d/1)) \n#define gLrUE 18+ 70*d/3-d*d-d/35 +33-5/9+d-d*387+d-1\n#define AvjmK 9-d-8+(d+m+5/2/x*d+1)/x/d-5-2*(m)+d+17/d+ 4/52/8\n#define SjrJ 90/7/5/d+ 254877982+(m) *x-19\n#define PlykoqfDbwxR 540304590 +d*x/11-(m+d-d-4)*(d-3-1)/d\nd-2+1+46-29620+9-(9*3 /d)*6*m/d+9+(1670)/cbt/d+d", "output": "OK" }, { "input": "3\n#define BuAiJLgAlkj x-3+419032556/409023036-(17*84)+x+8+A\n#define wU 516506880\n#define HeyDGlnaGxBaHjzelvF iRSPqHfgHw/4-(99)*(I)+A+I-9*46*x\nI/CRklg-HeyDGlnaGxBaHjzelvF/3+5 ", "output": "Suspicious" }, { "input": "4\n#define SOlTohcPGckDyF ((D)/G-83+KHGSuJFLHqD/5)\n#define KEUXeOYpg 9+x-8-8/x/9-65-6+4+55*x-58/x+84+D*2-7+D/x-x*G/4-2\n#define YZl (1/67*x*6/2*G)-D/1595107*D+6/x*1+D+3/9/x/26-6+9 \n#define gCatFsZn uBBqilYclMhpVfKKTkGK\n(28682537+ YZl*(4*52) )*x/8- gCatFsZn*x/54/7", "output": "Suspicious" }, { "input": "5\n#define iiXEqDYeyVmIYsOaO fj/x-9-6/x*x+ 1/ 7*2-x -x+9+235*23*Ww+x-2*K+2-x/70\n#define XVgLzhoTUxoBr ( x+x/x/x*6-x)* x+K/24206-2 /5/8-x-7/Ww/K-x+6 \n#define QdfRBaJk 470551685-( 54-x)-30\n#define gEJcAGnF x+x-x+(x/x+9)/x-41-1/fj/1157561+x/x -x/26/x+K*x\n#define lO 7-1*(x*58 )-K*fj /722113691/x/K+2\n2+4*85/86/x*27 /49252-x*x/6-83-7/x+x+K-lO+8-K-x", "output": "Suspicious" }, { "input": "1\n#define sum x+y\nr-sum", "output": "Suspicious" }, { "input": "1\n#define sum x+y\nr+sum", "output": "OK" }, { "input": "1\n#define sum x+y\nr*sum", "output": "Suspicious" }, { "input": "1\n#define sum x+y\nr/sum", "output": "Suspicious" }, { "input": "1\n#define sum x-y\nr+sum", "output": "OK" }, { "input": "1\n#define sum x-y\nr-sum", "output": "Suspicious" }, { "input": "1\n#define sum x-y\nr*sum", "output": "Suspicious" }, { "input": "1\n#define sum x-y\nr/sum", "output": "Suspicious" }, { "input": "1\n#define sum x*y\nr+sum", "output": "OK" }, { "input": "1\n#define sum x*y\nr-sum", "output": "OK" }, { "input": "1\n#define sum x*y\nr*sum", "output": "OK" }, { "input": "1\n#define sum x*y\nr/sum", "output": "Suspicious" }, { "input": "1\n#define sum x/y\nr+sum", "output": "OK" }, { "input": "1\n#define sum x/y\nr-sum", "output": "OK" }, { "input": "1\n#define sum x/y\nr*sum", "output": "OK" }, { "input": "1\n#define sum x/y\nr/sum", "output": "Suspicious" }, { "input": "1\n#define sum x+y\nsum+r", "output": "OK" }, { "input": "1\n#define sum x+y\nsum-r", "output": "OK" }, { "input": "1\n#define sum x+y\nsum*r", "output": "Suspicious" }, { "input": "1\n#define sum x+y\nsum/r", "output": "Suspicious" }, { "input": "1\n#define sum x-y\nsum+r", "output": "OK" }, { "input": "1\n#define sum x-y\nsum-r", "output": "OK" }, { "input": "1\n#define sum x-y\nsum*r", "output": "Suspicious" }, { "input": "1\n#define sum x-y\nsum/r", "output": "Suspicious" }, { "input": "1\n#define sum x*y\nsum+r", "output": "OK" }, { "input": "1\n#define sum x*y\nsum-r", "output": "OK" }, { "input": "1\n#define sum x*y\nsum*r", "output": "OK" }, { "input": "1\n#define sum x*y\nsum/r", "output": "OK" }, { "input": "1\n#define sum x/y\nsum+r", "output": "OK" }, { "input": "1\n#define sum x/y\nsum-r", "output": "OK" }, { "input": "1\n#define sum x/y\nsum*r", "output": "OK" }, { "input": "1\n#define sum x/y\nsum/r", "output": "OK" }, { "input": "1\n#define x 3/2\n2*x", "output": "OK" }, { "input": "2\n # define sum 1000000000 + 1000000000 + 1000000000 \n # define a b + 45 * sum \n a ", "output": "Suspicious" } ]
280
1,228,800
0
9,673
0
none
[ "none" ]
null
null
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly *n* skills. Each skill is represented by a non-negative integer *a**i* — the current skill level. All skills have the same maximum level *A*. Along with the skills, global ranking of all players was added. Players are ranked according to the so-called Force. The Force of a player is the sum of the following values: - The number of skills that a character has perfected (i.e., such that *a**i*<==<=*A*), multiplied by coefficient *c**f*.- The minimum skill level among all skills (*min* *a**i*), multiplied by coefficient *c**m*. Now Lesha has *m* hacknetian currency units, which he is willing to spend. Each currency unit can increase the current level of any skill by 1 (if it's not equal to *A* yet). Help him spend his money in order to achieve the maximum possible value of the Force.
The first line of the input contains five space-separated integers *n*, *A*, *c**f*, *c**m* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*A*<=≤<=109, 0<=≤<=*c**f*,<=*c**m*<=≤<=1000, 0<=≤<=*m*<=≤<=1015). The second line contains exactly *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*A*), separated by spaces, — the current levels of skills.
On the first line print the maximum value of the Force that the character can achieve using no more than *m* currency units. On the second line print *n* integers *a*'*i* (*a**i*<=≤<=*a*'*i*<=≤<=*A*), skill levels which one must achieve in order to reach the specified value of the Force, while using no more than *m* currency units. Numbers should be separated by spaces.
[ "3 5 10 1 5\n1 3 1\n", "3 5 10 1 339\n1 3 1\n" ]
[ "12\n2 5 2 \n", "35\n5 5 5 \n" ]
In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by 1. In the second test one should increase all skills to maximum.
[ { "input": "3 5 10 1 5\n1 3 1", "output": "12\n2 5 2 " }, { "input": "3 5 10 1 339\n1 3 1", "output": "35\n5 5 5 " }, { "input": "2 6 0 1 4\n5 1", "output": "5\n5 5 " }, { "input": "1 1000000000 1000 1000 1000000000000000\n0", "output": "1000000001000\n1000000000 " }, { "input": "1 100 1 2 30\n1", "output": "62\n31 " }, { "input": "1 100 1 2 30\n71", "output": "201\n100 " }, { "input": "1 1000000000 1000 1000 1000000000000000\n1000000000", "output": "1000000001000\n1000000000 " }, { "input": "5 5 10 20 50\n0 0 0 0 0", "output": "150\n5 5 5 5 5 " }, { "input": "5 5 10 20 50\n3 3 3 3 3", "output": "150\n5 5 5 5 5 " }, { "input": "4 5 3 7 15\n4 3 3 1", "output": "47\n5 5 5 5 " }, { "input": "3 6 4 6 8\n6 4 5", "output": "48\n6 6 6 " } ]
93
23,142,400
0
9,684
81
Average Score
[ "greedy", "math", "sortings" ]
C. Average Score
2
256
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received *n* marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark. Now it's time to show the journal to his strict parents. Polycarp knows that recently at the Parent Meeting the parents were told that he received *a* Safety Studies marks and *b* PE marks (*a*<=+<=*b*<==<=*n*). Now Polycarp wants to write a subject's name in front of each mark so that: - there are exactly *a* Safety Studies marks, - there are exactly *b* PE marks, - the total average score in both subjects is maximum. An average subject grade is the sum of all marks in it, divided by the number of them. Of course, the division is performed in real numbers without rounding up or down. Polycarp aims to maximize the *x*1<=+<=*x*2, where *x*1 is the average score in the first subject (Safety Studies), and *x*2 is the average score in the second one (Physical Education).
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105), *n* is the number of marks in Polycarp's Journal. The second line contains two positive integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=*n*<=-<=1,<=*a*<=+<=*b*<==<=*n*). The third line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=5), they are Polycarp's marks.
Print the sequence of integers *f*1,<=*f*2,<=...,<=*f**n*, where *f**i* (1<=≤<=*f**i*<=≤<=2) is the number of a subject to which the *i*-th mark should be attributed. If there are several possible solutions, then print such that the sequence *f*1,<=*f*2,<=...,<=*f**n* is the smallest lexicographically. The sequence *p*1,<=*p*2,<=...,<=*p**n* is lexicographically less than *q*1,<=*q*2,<=...,<=*q**n* if there exists such *j* (1<=≤<=*j*<=≤<=*n*) that *p**i*<==<=*q**i* for all 1<=≤<=*i*<=&lt;<=*j*, аnd *p**j*<=&lt;<=*q**j*.
[ "5\n3 2\n4 4 5 4 4\n", "4\n2 2\n3 5 4 5\n", "6\n1 5\n4 4 4 5 4 4\n" ]
[ "1 1 2 1 2 ", "1 1 2 2 ", "2 2 2 1 2 2 " ]
In the first sample the average score in the first subject is equal to 4, and in the second one — to 4.5. The total average score is 8.5.
[ { "input": "5\n3 2\n4 4 5 4 4", "output": "1 1 2 1 2 " }, { "input": "4\n2 2\n3 5 4 5", "output": "1 1 2 2 " }, { "input": "6\n1 5\n4 4 4 5 4 4", "output": "2 2 2 1 2 2 " }, { "input": "4\n2 2\n2 1 3 3", "output": "1 1 2 2 " }, { "input": "9\n3 6\n4 5 4 1 2 2 2 4 5", "output": "1 1 2 2 2 2 2 2 1 " }, { "input": "2\n1 1\n4 4", "output": "1 2 " }, { "input": "2\n1 1\n5 1", "output": "1 2 " }, { "input": "3\n2 1\n1 2 2", "output": "1 1 2 " }, { "input": "3\n1 2\n1 2 2", "output": "2 1 2 " }, { "input": "3\n1 2\n1 2 3", "output": "2 2 1 " }, { "input": "3\n2 1\n5 5 5", "output": "1 1 2 " }, { "input": "4\n2 2\n1 2 2 3", "output": "1 1 2 2 " }, { "input": "4\n1 3\n2 1 2 2", "output": "1 2 2 2 " }, { "input": "4\n3 1\n2 1 2 2", "output": "1 1 1 2 " }, { "input": "4\n3 1\n2 1 3 3", "output": "1 1 1 2 " }, { "input": "4\n1 3\n2 3 3 3", "output": "2 1 2 2 " }, { "input": "5\n1 4\n1 1 3 3 2", "output": "2 2 1 2 2 " }, { "input": "5\n2 3\n4 3 3 3 3", "output": "1 1 2 2 2 " }, { "input": "5\n3 2\n2 5 2 2 2", "output": "1 2 1 1 2 " }, { "input": "5\n4 1\n4 4 1 4 4", "output": "1 1 1 1 2 " }, { "input": "6\n1 5\n4 4 5 4 4 1", "output": "2 2 1 2 2 2 " }, { "input": "6\n2 4\n4 4 4 4 4 4", "output": "1 1 2 2 2 2 " }, { "input": "6\n3 3\n1 4 3 4 4 3", "output": "1 1 1 2 2 2 " }, { "input": "6\n4 2\n5 2 3 2 3 5", "output": "2 1 1 1 1 2 " }, { "input": "6\n5 1\n2 1 2 5 4 5", "output": "1 1 1 1 1 2 " }, { "input": "9\n1 8\n1 2 1 5 1 5 5 1 1", "output": "2 2 2 1 2 2 2 2 2 " }, { "input": "9\n2 7\n4 2 4 4 2 5 1 2 5", "output": "2 2 2 2 2 1 2 2 1 " }, { "input": "9\n4 5\n3 3 3 5 3 1 4 5 1", "output": "1 2 2 1 2 2 1 1 2 " }, { "input": "9\n5 4\n2 2 2 1 2 1 1 1 1", "output": "2 2 2 1 2 1 1 1 1 " }, { "input": "13\n7 6\n2 3 2 2 3 4 3 2 2 3 2 3 5", "output": "1 1 1 1 2 2 2 1 1 2 1 2 2 " }, { "input": "100\n45 55\n3 5 3 4 1 1 1 1 5 2 1 3 1 5 3 5 1 1 3 1 1 3 5 5 1 1 1 5 5 1 3 1 1 1 3 3 1 1 1 4 3 1 5 1 3 1 4 5 4 3 3 1 1 5 5 1 3 5 1 1 5 1 1 3 5 5 1 1 3 3 4 1 1 4 5 3 1 3 1 5 1 5 4 5 1 1 1 1 4 5 4 5 3 1 1 5 1 5 1 4", "output": "1 1 1 1 2 2 2 2 1 2 2 1 2 1 1 1 2 2 1 2 2 1 1 1 2 2 2 1 1 2 1 2 2 2 1 1 2 2 2 1 1 2 1 2 1 2 1 1 1 2 2 2 2 1 1 2 2 1 2 2 1 2 2 2 1 1 2 2 2 2 1 2 2 1 1 2 2 2 2 1 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 2 1 2 1 " }, { "input": "2\n1 1\n1 2", "output": "1 2 " }, { "input": "3\n1 2\n1 1 1", "output": "1 2 2 " } ]
2,000
2,662,400
0
9,695
609
Gadgets for dollars and pounds
[ "binary search", "greedy", "two pointers" ]
null
null
Nura wants to buy *k* gadgets. She has only *s* burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of currency and the cost in that currency are not changing. Nura can buy gadgets for *n* days. For each day you know the exchange rates of dollar and pound, so you know the cost of conversion burles to dollars or to pounds. Each day (from 1 to *n*) Nura can buy some gadgets by current exchange rate. Each day she can buy any gadgets she wants, but each gadget can be bought no more than once during *n* days. Help Nura to find the minimum day index when she will have *k* gadgets. Nura always pays with burles, which are converted according to the exchange rate of the purchase day. Nura can't buy dollars or pounds, she always stores only burles. Gadgets are numbered with integers from 1 to *m* in order of their appearing in input.
First line contains four integers *n*,<=*m*,<=*k*,<=*s* (1<=≤<=*n*<=≤<=2·105,<=1<=≤<=*k*<=≤<=*m*<=≤<=2·105,<=1<=≤<=*s*<=≤<=109) — number of days, total number and required number of gadgets, number of burles Nura has. Second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the cost of one dollar in burles on *i*-th day. Third line contains *n* integers *b**i* (1<=≤<=*b**i*<=≤<=106) — the cost of one pound in burles on *i*-th day. Each of the next *m* lines contains two integers *t**i*,<=*c**i* (1<=≤<=*t**i*<=≤<=2,<=1<=≤<=*c**i*<=≤<=106) — type of the gadget and it's cost. For the gadgets of the first type cost is specified in dollars. For the gadgets of the second type cost is specified in pounds.
If Nura can't buy *k* gadgets print the only line with the number -1. Otherwise the first line should contain integer *d* — the minimum day index, when Nura will have *k* gadgets. On each of the next *k* lines print two integers *q**i*,<=*d**i* — the number of gadget and the day gadget should be bought. All values *q**i* should be different, but the values *d**i* can coincide (so Nura can buy several gadgets at one day). The days are numbered from 1 to *n*. In case there are multiple possible solutions, print any of them.
[ "5 4 2 2\n1 2 3 2 1\n3 2 1 2 3\n1 1\n2 1\n1 2\n2 2\n", "4 3 2 200\n69 70 71 72\n104 105 106 107\n1 1\n2 2\n1 2\n", "4 3 1 1000000000\n900000 910000 940000 990000\n990000 999000 999900 999990\n1 87654\n2 76543\n1 65432\n" ]
[ "3\n1 1\n2 3\n", "-1\n", "-1\n" ]
none
[ { "input": "5 4 2 2\n1 2 3 2 1\n3 2 1 2 3\n1 1\n2 1\n1 2\n2 2", "output": "3\n1 1\n2 3" }, { "input": "4 3 2 200\n69 70 71 72\n104 105 106 107\n1 1\n2 2\n1 2", "output": "-1" }, { "input": "4 3 1 1000000000\n900000 910000 940000 990000\n990000 999000 999900 999990\n1 87654\n2 76543\n1 65432", "output": "-1" }, { "input": "5 5 3 1000000\n921 853 547 187 164\n711 462 437 307 246\n2 94\n2 230\n1 373\n1 476\n2 880", "output": "1\n1 1\n2 1\n5 1" }, { "input": "10 10 10 1000000\n836 842 645 671 499 554 462 288 89 104\n880 722 623 651 591 573 154 532 136 59\n1 47\n1 169\n2 486\n1 262\n2 752\n2 498\n2 863\n2 616\n1 791\n1 656", "output": "9\n1 9\n2 9\n4 9\n10 9\n9 9\n3 9\n6 9\n8 9\n5 9\n7 9" }, { "input": "1 2 2 1000000\n96\n262\n1 699\n2 699", "output": "1\n1 1\n2 1" }, { "input": "1 2 2 1000000\n793\n33\n1 733\n2 406", "output": "1\n1 1\n2 1" }, { "input": "1 2 2 10000\n82\n996\n2 574\n2 217", "output": "-1" }, { "input": "1 2 2 1000000\n778\n62\n2 119\n2 220", "output": "1\n1 1\n2 1" }, { "input": "1 2 2 1000000\n963\n25\n2 961\n1 327", "output": "1\n2 1\n1 1" }, { "input": "10 20 20 1000000\n809 909 795 661 635 613 534 199 188 3\n475 585 428 379 185 177 66 104 15 38\n2 454\n1 863\n2 14\n2 104\n1 663\n2 885\n1 650\n1 967\n2 650\n2 483\n2 846\n1 283\n1 187\n2 533\n2 112\n2 938\n2 553\n1 816\n1 549\n2 657", "output": "10\n13 10\n12 10\n19 10\n7 10\n5 10\n18 10\n2 10\n8 10\n3 9\n4 9\n15 9\n1 9\n10 9\n14 9\n17 9\n9 9\n20 9\n11 9\n6 9\n16 9" }, { "input": "10 20 19 1000000\n650 996 972 951 904 742 638 93 339 151\n318 565 849 579 521 965 286 189 196 307\n2 439\n1 333\n2 565\n1 602\n2 545\n2 596\n2 821\n2 929\n1 614\n2 647\n2 909\n1 8\n2 135\n1 301\n1 597\n1 632\n1 437\n2 448\n2 631\n2 969", "output": "-1" }, { "input": "10 20 18 10000\n916 582 790 449 578 502 411 196 218 144\n923 696 788 609 455 570 330 435 284 113\n2 736\n1 428\n1 861\n2 407\n2 320\n1 340\n1 88\n1 172\n1 788\n2 633\n2 612\n2 571\n2 536\n2 30\n2 758\n2 90\n2 8\n1 970\n1 20\n1 22", "output": "-1" }, { "input": "10 20 16 1000000\n317 880 696 304 260 180 214 245 79 37\n866 621 940 89 718 674 195 267 12 49\n2 825\n2 197\n1 657\n1 231\n1 728\n2 771\n2 330\n2 943\n1 60\n1 89\n2 721\n2 959\n1 926\n2 215\n1 583\n2 680\n1 799\n2 887\n1 709\n1 316", "output": "6\n9 6\n10 6\n4 6\n20 6\n15 6\n3 6\n2 4\n14 4\n7 4\n16 4\n11 4\n6 4\n1 4\n18 4\n8 4\n12 4" }, { "input": "10 20 20 10000\n913 860 844 775 297 263 247 71 50 6\n971 938 890 854 643 633 427 418 190 183\n1 556\n2 579\n1 315\n2 446\n1 327\n1 724\n2 12\n1 142\n1 627\n1 262\n1 681\n1 802\n1 886\n1 350\n2 383\n1 191\n1 717\n1 968\n2 588\n1 57", "output": "-1" }, { "input": "1 93 46 46\n1\n1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2", "output": "1\n2 1\n4 1\n6 1\n8 1\n10 1\n12 1\n14 1\n16 1\n18 1\n20 1\n22 1\n24 1\n26 1\n28 1\n30 1\n32 1\n34 1\n36 1\n38 1\n40 1\n42 1\n44 1\n46 1\n48 1\n50 1\n52 1\n54 1\n56 1\n58 1\n60 1\n62 1\n64 1\n66 1\n68 1\n70 1\n72 1\n74 1\n76 1\n78 1\n80 1\n82 1\n84 1\n86 1\n88 1\n90 1\n92 1" } ]
46
0
0
9,699
392
Yet Another Number Sequence
[ "combinatorics", "math", "matrices" ]
null
null
Everyone knows what the Fibonacci sequence is. This sequence can be defined by the recurrence relation: We'll define a new number sequence *A**i*(*k*) by the formula: In this problem, your task is to calculate the following sum: *A*1(*k*)<=+<=*A*2(*k*)<=+<=...<=+<=*A**n*(*k*). The answer can be very large, so print it modulo 1000000007 (109<=+<=7).
The first line contains two space-separated integers *n*, *k* (1<=≤<=*n*<=≤<=1017; 1<=≤<=*k*<=≤<=40).
Print a single integer — the sum of the first *n* elements of the sequence *A**i*(*k*) modulo 1000000007 (109<=+<=7).
[ "1 1\n", "4 1\n", "5 2\n", "7 4\n" ]
[ "1\n", "34\n", "316\n", "73825\n" ]
none
[]
1,000
614,400
0
9,731
0
none
[ "none" ]
null
null
The employees of the F company have lots of ways to entertain themselves. Today they invited a famous magician who shows a trick with plastic cups and a marble. The point is to trick the spectator's attention. Initially, the spectator stands in front of a line of *n* plastic cups. Then the magician places a small marble under one cup and shuffles the cups. Then the spectator should guess which cup hides the marble. But the head coder of the F company isn't easy to trick. When he saw the performance, he noticed several important facts: - each cup contains a mark — a number from 1 to *n*; all marks on the cups are distinct; - the magician shuffles the cups in *m* operations, each operation looks like that: take a cup marked *x**i*, sitting at position *y**i* in the row of cups (the positions are numbered from left to right, starting from 1) and shift it to the very beginning of the cup row (on the first position). When the head coder came home after work he wanted to re-do the trick. Unfortunately, he didn't remember the starting or the final position of the cups. He only remembered which operations the magician performed. Help the coder: given the operations in the order they were made find at least one initial permutation of the cups that can go through the described operations in the given order. Otherwise, state that such permutation doesn't exist.
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=106). Each of the next *m* lines contains a couple of integers. The *i*-th line contains integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the description of the *i*-th operation of the magician. Note that the operations are given in the order in which the magician made them and the coder wants to make them in the same order.
If the described permutation doesn't exist (the programmer remembered wrong operations), print -1. Otherwise, print *n* distinct integers, each from 1 to *n*: the *i*-th number should represent the mark on the cup that initially is in the row in position *i*. If there are multiple correct answers, you should print the lexicographically minimum one.
[ "2 1\n2 1\n", "3 2\n1 2\n1 1\n", "3 3\n1 3\n2 3\n1 3\n" ]
[ "2 1 \n", "2 1 3 \n", "-1\n" ]
none
[]
62
0
0
9,745
848
Rooter's Song
[ "constructive algorithms", "data structures", "geometry", "implementation", "sortings", "two pointers" ]
null
null
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size *w*<=×<=*h*, represented by a rectangle with corners (0,<=0), (*w*,<=0), (*w*,<=*h*) and (0,<=*h*). It can be seen that no collisions will happen before one enters the stage. On the sides of the stage stand *n* dancers. The *i*-th of them falls into one of the following groups: - Vertical: stands at (*x**i*,<=0), moves in positive *y* direction (upwards); - Horizontal: stands at (0,<=*y**i*), moves in positive *x* direction (rightwards). According to choreography, the *i*-th dancer should stand still for the first *t**i* milliseconds, and then start moving in the specified direction at 1 unit per millisecond, until another border is reached. It is guaranteed that no two dancers have the same group, position and waiting time at the same time. When two dancers collide (i.e. are on the same point at some time when both of them are moving), they immediately exchange their moving directions and go on. Dancers stop when a border of the stage is reached. Find out every dancer's stopping position.
The first line of input contains three space-separated positive integers *n*, *w* and *h* (1<=≤<=*n*<=≤<=100<=000, 2<=≤<=*w*,<=*h*<=≤<=100<=000) — the number of dancers and the width and height of the stage, respectively. The following *n* lines each describes a dancer: the *i*-th among them contains three space-separated integers *g**i*, *p**i*, and *t**i* (1<=≤<=*g**i*<=≤<=2, 1<=≤<=*p**i*<=≤<=99<=999, 0<=≤<=*t**i*<=≤<=100<=000), describing a dancer's group *g**i* (*g**i*<==<=1 — vertical, *g**i*<==<=2 — horizontal), position, and waiting time. If *g**i*<==<=1 then *p**i*<==<=*x**i*; otherwise *p**i*<==<=*y**i*. It's guaranteed that 1<=≤<=*x**i*<=≤<=*w*<=-<=1 and 1<=≤<=*y**i*<=≤<=*h*<=-<=1. It is guaranteed that no two dancers have the same group, position and waiting time at the same time.
Output *n* lines, the *i*-th of which contains two space-separated integers (*x**i*,<=*y**i*) — the stopping position of the *i*-th dancer in the input.
[ "8 10 8\n1 1 10\n1 4 13\n1 7 1\n1 8 2\n2 2 0\n2 5 14\n2 6 0\n2 6 1\n", "3 2 3\n1 1 2\n2 1 1\n1 1 5\n" ]
[ "4 8\n10 5\n8 8\n10 6\n10 2\n1 8\n7 8\n10 6\n", "1 3\n2 1\n1 3\n" ]
The first example corresponds to the initial setup in the legend, and the tracks of dancers are marked with different colours in the following figure. In the second example, no dancers collide.
[ { "input": "8 10 8\n1 1 10\n1 4 13\n1 7 1\n1 8 2\n2 2 0\n2 5 14\n2 6 0\n2 6 1", "output": "4 8\n10 5\n8 8\n10 6\n10 2\n1 8\n7 8\n10 6" }, { "input": "3 2 3\n1 1 2\n2 1 1\n1 1 5", "output": "1 3\n2 1\n1 3" }, { "input": "1 10 10\n1 8 1", "output": "8 10" }, { "input": "3 4 5\n1 3 9\n2 1 9\n1 2 8", "output": "3 5\n4 1\n2 5" }, { "input": "10 500 500\n2 88 59\n2 470 441\n1 340 500\n2 326 297\n1 74 45\n1 302 273\n1 132 103\n2 388 359\n1 97 68\n2 494 465", "output": "500 494\n97 500\n340 500\n302 500\n500 470\n500 88\n500 326\n132 500\n500 388\n74 500" }, { "input": "20 50000 50000\n2 45955 55488\n1 19804 29337\n2 3767 90811\n2 24025 33558\n1 46985 56518\n2 21094 30627\n2 5787 15320\n1 4262 91306\n2 37231 46764\n1 18125 27658\n1 36532 12317\n1 31330 40863\n1 18992 28525\n1 29387 38920\n1 44654 54187\n2 45485 55018\n2 36850 46383\n1 44649 54182\n1 40922 50455\n2 12781 99825", "output": "18125 50000\n50000 45955\n50000 12781\n31330 50000\n50000 5787\n40922 50000\n44649 50000\n50000 3767\n19804 50000\n44654 50000\n36532 50000\n50000 37231\n46985 50000\n50000 45485\n50000 21094\n18992 50000\n29387 50000\n50000 24025\n50000 36850\n4262 50000" }, { "input": "20 15 15\n2 7 100000\n1 2 100000\n2 1 100000\n1 9 100000\n2 4 100000\n2 3 100000\n2 14 100000\n1 6 100000\n1 10 100000\n2 5 100000\n2 13 100000\n1 8 100000\n1 13 100000\n1 14 100000\n2 10 100000\n1 5 100000\n1 11 100000\n1 12 100000\n1 1 100000\n2 2 100000", "output": "15 7\n15 2\n1 15\n9 15\n15 4\n15 3\n14 15\n6 15\n15 10\n5 15\n13 15\n8 15\n15 13\n15 14\n10 15\n15 5\n11 15\n12 15\n15 1\n2 15" }, { "input": "5 20 20\n1 15 3\n2 15 3\n2 3 1\n2 1 0\n1 16 4", "output": "16 20\n15 20\n20 3\n20 1\n20 15" }, { "input": "15 80 80\n2 36 4\n2 65 5\n1 31 2\n2 3 1\n2 62 0\n2 37 5\n1 16 4\n2 47 2\n1 17 5\n1 9 5\n2 2 0\n2 62 5\n2 34 2\n1 33 1\n2 69 3", "output": "80 37\n80 65\n31 80\n80 3\n80 62\n33 80\n16 80\n80 47\n17 80\n9 80\n80 2\n80 62\n80 36\n80 34\n80 69" }, { "input": "15 15 15\n1 10 1\n2 11 0\n2 6 4\n1 1 0\n1 7 5\n1 14 3\n1 3 1\n1 4 2\n1 9 0\n2 10 1\n1 12 1\n2 2 0\n1 5 3\n2 3 0\n2 4 2", "output": "15 10\n12 15\n3 15\n1 15\n15 2\n15 11\n7 15\n15 6\n10 15\n9 15\n14 15\n5 15\n15 4\n15 3\n4 15" }, { "input": "5 5 5\n1 1 0\n2 1 0\n2 2 1\n1 2 1\n2 4 3", "output": "5 2\n5 4\n2 5\n5 1\n1 5" } ]
1,200
39,628,800
3
9,746
533
Board Game
[ "games", "greedy", "implementation", "math" ]
null
null
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (*x*,<=*y*) to (*x*<=-<=1,<=*y*) or (*x*,<=*y*<=-<=1). Vasiliy can move his pawn from (*x*,<=*y*) to one of cells: (*x*<=-<=1,<=*y*),<=(*x*<=-<=1,<=*y*<=-<=1) and (*x*,<=*y*<=-<=1). Both players are also allowed to skip move. There are some additional restrictions — a player is forbidden to move his pawn to a cell with negative *x*-coordinate or *y*-coordinate or to the cell containing opponent's pawn The winner is the first person to reach cell (0,<=0). You are given the starting coordinates of both pawns. Determine who will win if both of them play optimally well.
The first line contains four integers: *x**p*,<=*y**p*,<=*x**v*,<=*y**v* (0<=≤<=*x**p*,<=*y**p*,<=*x**v*,<=*y**v*<=≤<=105) — Polycarp's and Vasiliy's starting coordinates. It is guaranteed that in the beginning the pawns are in different cells and none of them is in the cell (0,<=0).
Output the name of the winner: "Polycarp" or "Vasiliy".
[ "2 1 2 2\n", "4 7 7 4\n" ]
[ "Polycarp\n", "Vasiliy\n" ]
In the first sample test Polycarp starts in (2, 1) and will move to (1, 1) in the first turn. No matter what his opponent is doing, in the second turn Polycarp can move to (1, 0) and finally to (0, 0) in the third turn.
[ { "input": "2 1 2 2", "output": "Polycarp" }, { "input": "4 7 7 4", "output": "Vasiliy" }, { "input": "20 0 7 22", "output": "Polycarp" }, { "input": "80 100 83 97", "output": "Vasiliy" }, { "input": "80 100 77 103", "output": "Vasiliy" }, { "input": "55000 60000 55003 60100", "output": "Polycarp" }, { "input": "100000 100000 100000 99999", "output": "Vasiliy" }, { "input": "100000 99999 100000 100000", "output": "Polycarp" }, { "input": "0 100000 100000 99999", "output": "Polycarp" }, { "input": "0 100000 99999 100000", "output": "Polycarp" }, { "input": "0 90000 89999 89999", "output": "Vasiliy" }, { "input": "0 1 0 2", "output": "Polycarp" }, { "input": "0 1 1 0", "output": "Polycarp" }, { "input": "0 1 1 1", "output": "Polycarp" }, { "input": "0 1 1 2", "output": "Polycarp" }, { "input": "0 1 2 0", "output": "Polycarp" }, { "input": "0 1 2 1", "output": "Polycarp" }, { "input": "0 1 2 2", "output": "Polycarp" }, { "input": "0 2 0 1", "output": "Vasiliy" }, { "input": "0 2 1 0", "output": "Vasiliy" }, { "input": "0 2 1 1", "output": "Vasiliy" }, { "input": "0 2 1 2", "output": "Polycarp" }, { "input": "0 2 2 0", "output": "Polycarp" }, { "input": "0 2 2 1", "output": "Polycarp" }, { "input": "0 2 2 2", "output": "Polycarp" }, { "input": "1 0 0 1", "output": "Polycarp" }, { "input": "1 0 0 2", "output": "Polycarp" }, { "input": "1 0 1 1", "output": "Polycarp" }, { "input": "1 0 1 2", "output": "Polycarp" }, { "input": "1 0 2 0", "output": "Polycarp" }, { "input": "1 0 2 1", "output": "Polycarp" }, { "input": "1 0 2 2", "output": "Polycarp" }, { "input": "1 1 0 1", "output": "Vasiliy" }, { "input": "1 1 0 2", "output": "Polycarp" }, { "input": "1 1 1 0", "output": "Vasiliy" }, { "input": "1 1 1 2", "output": "Polycarp" }, { "input": "1 1 2 0", "output": "Polycarp" }, { "input": "1 1 2 1", "output": "Polycarp" }, { "input": "1 1 2 2", "output": "Polycarp" }, { "input": "1 2 0 1", "output": "Vasiliy" }, { "input": "1 2 0 2", "output": "Vasiliy" }, { "input": "1 2 1 0", "output": "Vasiliy" }, { "input": "1 2 1 1", "output": "Vasiliy" }, { "input": "1 2 2 0", "output": "Vasiliy" }, { "input": "1 2 2 1", "output": "Vasiliy" }, { "input": "1 2 2 2", "output": "Polycarp" }, { "input": "2 0 0 1", "output": "Vasiliy" }, { "input": "2 0 0 2", "output": "Polycarp" }, { "input": "2 0 1 0", "output": "Vasiliy" }, { "input": "2 0 1 1", "output": "Vasiliy" }, { "input": "2 0 1 2", "output": "Polycarp" }, { "input": "2 0 2 1", "output": "Polycarp" }, { "input": "2 0 2 2", "output": "Polycarp" }, { "input": "2 1 0 1", "output": "Vasiliy" }, { "input": "2 1 0 2", "output": "Vasiliy" }, { "input": "2 1 1 0", "output": "Vasiliy" }, { "input": "2 1 1 1", "output": "Vasiliy" }, { "input": "2 1 1 2", "output": "Vasiliy" }, { "input": "2 1 2 0", "output": "Vasiliy" }, { "input": "2 1 2 2", "output": "Polycarp" }, { "input": "2 2 0 1", "output": "Vasiliy" }, { "input": "2 2 0 2", "output": "Vasiliy" }, { "input": "2 2 1 0", "output": "Vasiliy" }, { "input": "2 2 1 1", "output": "Vasiliy" }, { "input": "2 2 1 2", "output": "Vasiliy" }, { "input": "2 2 2 0", "output": "Vasiliy" }, { "input": "2 2 2 1", "output": "Vasiliy" }, { "input": "13118 79593 32785 22736", "output": "Vasiliy" }, { "input": "23039 21508 54113 76824", "output": "Polycarp" }, { "input": "32959 49970 75441 55257", "output": "Polycarp" }, { "input": "91573 91885 61527 58038", "output": "Vasiliy" }, { "input": "70620 15283 74892 15283", "output": "Polycarp" }, { "input": "43308 1372 53325 1370", "output": "Polycarp" }, { "input": "74005 7316 74004 7412", "output": "Vasiliy" }, { "input": "53208 42123 95332 85846", "output": "Polycarp" }, { "input": "14969 66451 81419 29039", "output": "Vasiliy" }, { "input": "50042 34493 84536 17892", "output": "Polycarp" }, { "input": "67949 70623 71979 70623", "output": "Polycarp" }, { "input": "67603 35151 67603 39519", "output": "Polycarp" }, { "input": "27149 26539 53690 17953", "output": "Polycarp" }, { "input": "36711 38307 75018 72040", "output": "Polycarp" }, { "input": "4650 67347 71998 50474", "output": "Polycarp" }, { "input": "4075 33738 4561 33738", "output": "Polycarp" }, { "input": "35868 55066 47754 55066", "output": "Polycarp" }, { "input": "41150 1761 41152 1841", "output": "Polycarp" }, { "input": "63557 16718 38133 80275", "output": "Polycarp" }, { "input": "8956 24932 30356 33887", "output": "Polycarp" }, { "input": "27338 8401 27337 12321", "output": "Vasiliy" }, { "input": "56613 48665 66408 48665", "output": "Polycarp" }, { "input": "34750 34886 34751 44842", "output": "Polycarp" }, { "input": "7591 24141 31732 23276", "output": "Polycarp" }, { "input": "2333 91141 93473 66469", "output": "Vasiliy" }, { "input": "9 0 8 0", "output": "Vasiliy" }, { "input": "0 1000 100 99", "output": "Vasiliy" }, { "input": "4 4 2 2", "output": "Vasiliy" }, { "input": "0 4 4 3", "output": "Polycarp" }, { "input": "100 1 1 100", "output": "Vasiliy" }, { "input": "9 17 14 16", "output": "Vasiliy" }, { "input": "0 3 3 1", "output": "Polycarp" }, { "input": "10 0 0 10", "output": "Polycarp" }, { "input": "5 0 0 4", "output": "Vasiliy" }, { "input": "2 1 1 3", "output": "Polycarp" }, { "input": "4 5 5 5", "output": "Polycarp" }, { "input": "0 3 2 2", "output": "Vasiliy" }, { "input": "3 0 0 10", "output": "Polycarp" } ]
124
1,638,400
3
9,784
621
Wet Shark and Blocks
[ "dp", "matrices" ]
null
null
There are *b* blocks of digits. Each one consisting of the same *n* digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate all of those digits together to form one large integer. For example, if he chooses digit 1 from the first block and digit 2 from the second block, he gets the integer 12. Wet Shark then takes this number modulo *x*. Please, tell him how many ways he can choose one digit from each block so that he gets exactly *k* as the final result. As this number may be too large, print it modulo 109<=+<=7. Note, that the number of ways to choose some digit in the block is equal to the number of it's occurrences. For example, there are 3 ways to choose digit 5 from block 3 5 6 7 8 9 5 1 1 1 1 5.
The first line of the input contains four space-separated integers, *n*, *b*, *k* and *x* (2<=≤<=*n*<=≤<=50<=000,<=1<=≤<=*b*<=≤<=109,<=0<=≤<=*k*<=&lt;<=*x*<=≤<=100,<=*x*<=≥<=2) — the number of digits in one block, the number of blocks, interesting remainder modulo *x* and modulo *x* itself. The next line contains *n* space separated integers *a**i* (1<=≤<=*a**i*<=≤<=9), that give the digits contained in each block.
Print the number of ways to pick exactly one digit from each blocks, such that the resulting integer equals *k* modulo *x*.
[ "12 1 5 10\n3 5 6 7 8 9 5 1 1 1 1 5\n", "3 2 1 2\n6 2 2\n", "3 2 1 2\n3 1 2\n" ]
[ "3\n", "0\n", "6\n" ]
In the second sample possible integers are 22, 26, 62 and 66. None of them gives the remainder 1 modulo 2. In the third sample integers 11, 13, 21, 23, 31 and 33 have remainder 1 modulo 2. There is exactly one way to obtain each of these integers, so the total answer is 6.
[ { "input": "12 1 5 10\n3 5 6 7 8 9 5 1 1 1 1 5", "output": "3" }, { "input": "3 2 1 2\n6 2 2", "output": "0" }, { "input": "3 2 1 2\n3 1 2", "output": "6" }, { "input": "3 2 1 2\n6 3 2", "output": "3" }, { "input": "3 2 1 2\n3 6 3", "output": "6" }, { "input": "3 2 0 2\n3 3 9", "output": "0" }, { "input": "3 2 0 2\n4 5 1", "output": "3" }, { "input": "3 2 0 2\n1 3 2", "output": "3" }, { "input": "3 2 1 2\n5 9 3", "output": "9" }, { "input": "3 2 1 2\n7 2 4", "output": "3" }, { "input": "6 5 2 12\n2 8 9 6 6 1", "output": "1017" }, { "input": "6 5 9 11\n8 1 2 1 8 2", "output": "640" }, { "input": "6 5 7 10\n9 6 9 8 8 8", "output": "0" }, { "input": "6 5 12 23\n5 8 2 6 5 5", "output": "294" }, { "input": "6 5 6 22\n6 1 6 1 4 1", "output": "680" }, { "input": "100 1000000000 42 97\n2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2", "output": "590949100" } ]
2,000
921,600
0
9,809
254
Jury Size
[ "brute force", "implementation" ]
null
null
In 2013, the writers of Berland State University should prepare problems for *n* Olympiads. We will assume that the Olympiads are numbered with consecutive integers from 1 to *n*. For each Olympiad we know how many members of the jury must be involved in its preparation, as well as the time required to prepare the problems for her. Namely, the Olympiad number *i* should be prepared by *p**i* people for *t**i* days, the preparation for the Olympiad should be a continuous period of time and end exactly one day before the Olympiad. On the day of the Olympiad the juries who have prepared it, already do not work on it. For example, if the Olympiad is held on December 9th and the preparation takes 7 people and 6 days, all seven members of the jury will work on the problems of the Olympiad from December, 3rd to December, 8th (the jury members won't be working on the problems of this Olympiad on December 9th, that is, some of them can start preparing problems for some other Olympiad). And if the Olympiad is held on November 3rd and requires 5 days of training, the members of the jury will work from October 29th to November 2nd. In order not to overload the jury the following rule was introduced: one member of the jury can not work on the same day on the tasks for different Olympiads. Write a program that determines what the minimum number of people must be part of the jury so that all Olympiads could be prepared in time.
The first line contains integer *n* — the number of Olympiads in 2013 (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains four integers *m**i*, *d**i*, *p**i* and *t**i* — the month and day of the Olympiad (given without leading zeroes), the needed number of the jury members and the time needed to prepare the *i*-th Olympiad (1<=≤<=*m**i*<=≤<=12, *d**i*<=≥<=1, 1<=≤<=*p**i*,<=*t**i*<=≤<=100), *d**i* doesn't exceed the number of days in month *m**i*. The Olympiads are given in the arbitrary order. Several Olympiads can take place in one day. Use the modern (Gregorian) calendar in the solution. Note that all dates are given in the year 2013. This is not a leap year, so February has 28 days. Please note, the preparation of some Olympiad can start in 2012 year.
Print a single number — the minimum jury size.
[ "2\n5 23 1 2\n3 13 2 3\n", "3\n12 9 2 1\n12 8 1 3\n12 8 2 2\n", "1\n1 10 1 13\n" ]
[ "2\n", "3\n", "1\n" ]
none
[ { "input": "2\n5 23 1 2\n3 13 2 3", "output": "2" }, { "input": "3\n12 9 2 1\n12 8 1 3\n12 8 2 2", "output": "3" }, { "input": "1\n1 10 1 13", "output": "1" }, { "input": "3\n3 16 25 1\n3 15 9 34\n3 14 90 87", "output": "99" }, { "input": "4\n2 15 52 53\n2 15 35 81\n2 15 39 96\n2 14 87 7", "output": "213" }, { "input": "5\n3 6 40 89\n3 4 24 64\n2 28 83 1\n3 3 15 32\n3 8 54 28", "output": "216" }, { "input": "10\n8 8 4 18\n8 10 100 36\n8 9 17 51\n8 10 90 8\n8 10 64 45\n8 10 90 81\n8 11 20 86\n8 10 5 41\n8 9 3 91\n8 10 20 68", "output": "413" }, { "input": "15\n10 15 100 22\n9 19 26 16\n9 24 72 99\n9 29 54 83\n9 18 17 6\n9 6 51 59\n9 28 55 77\n9 1 8 89\n11 17 87 21\n9 14 39 93\n9 17 49 37\n10 28 78 84\n8 24 73 5\n11 22 34 59\n10 7 42 96", "output": "521" }, { "input": "20\n6 1 65 16\n5 24 34 85\n5 25 35 53\n5 15 2 63\n5 16 90 38\n5 17 86 79\n5 19 93 59\n5 21 74 87\n5 25 43 99\n5 24 81 66\n5 13 17 91\n5 25 45 46\n5 29 52 22\n5 31 38 56\n5 27 73 20\n5 13 36 13\n5 30 59 89\n5 27 98 44\n5 31 40 1\n5 28 29 21", "output": "985" }, { "input": "20\n10 1 90 91\n10 20 22 46\n10 1 73 39\n9 16 47 65\n10 17 65 68\n10 2 45 10\n10 15 17 60\n10 14 97 95\n10 21 91 62\n9 17 38 19\n9 7 46 82\n10 10 24 26\n9 21 7 54\n9 19 35 29\n10 20 17 24\n10 10 45 62\n9 27 11 29\n10 17 87 39\n10 7 36 56\n10 14 22 78", "output": "807" }, { "input": "25\n6 16 72 38\n6 16 88 2\n6 18 81 85\n6 15 86 24\n6 16 78 16\n6 19 63 25\n6 19 47 11\n6 18 8 81\n6 18 81 41\n6 15 73 89\n6 16 2 82\n6 16 55 39\n6 17 41 80\n6 18 97 16\n6 17 94 53\n6 17 60 10\n6 18 2 80\n6 15 100 26\n6 16 13 97\n6 18 24 99\n6 18 28 83\n6 18 11 32\n6 16 38 16\n6 15 42 45\n6 17 100 40", "output": "1384" }, { "input": "25\n4 25 70 67\n8 13 28 53\n11 1 91 37\n8 27 13 66\n5 10 38 96\n10 11 22 30\n8 7 59 14\n2 19 71 67\n11 8 58 6\n6 1 11 11\n3 16 34 55\n8 13 91 75\n2 1 59 22\n5 14 11 19\n5 14 20 25\n7 28 75 72\n11 2 27 72\n5 2 67 22\n7 21 70 95\n3 11 37 41\n3 30 69 78\n9 4 96 80\n3 27 39 29\n3 31 18 63\n9 17 87 11", "output": "373" }, { "input": "25\n1 18 59 56\n1 19 82 8\n2 6 8 2\n1 17 92 33\n1 25 26 36\n2 22 37 96\n2 5 42 22\n2 12 82 49\n1 20 57 44\n1 30 11 61\n2 4 14 15\n2 7 40 93\n2 15 59 77\n1 20 89 17\n2 5 81 36\n2 3 54 83\n1 19 67 1\n2 15 6 70\n2 15 64 21\n1 22 77 21\n2 4 62 85\n2 23 81 17\n2 1 47 51\n2 5 56 19\n1 29 73 57", "output": "1076" }, { "input": "40\n2 20 53 27\n2 20 19 50\n2 20 80 69\n2 20 55 44\n2 20 26 27\n2 20 19 48\n2 20 64 15\n2 20 44 76\n2 20 22 88\n2 20 74 99\n2 20 32 38\n2 20 27 22\n2 20 2 50\n2 20 37 79\n2 20 15 48\n2 20 15 46\n2 20 69 57\n2 20 99 49\n2 20 7 89\n2 20 52 72\n2 20 15 78\n2 20 91 55\n2 20 52 36\n2 20 36 69\n2 20 17 78\n2 20 12 57\n2 20 84 53\n2 20 97 30\n2 20 82 8\n2 20 2 75\n2 20 19 11\n2 20 96 95\n2 20 98 49\n2 20 38 29\n2 20 39 30\n2 20 90 92\n2 20 9 70\n2 20 57 93\n2 20 47 92\n2 20 5 44", "output": "1797" }, { "input": "40\n10 10 48 86\n10 10 34 79\n10 9 85 56\n10 8 60 27\n10 7 36 17\n10 7 23 48\n10 7 56 96\n10 8 10 2\n10 7 24 54\n10 10 10 23\n10 7 53 77\n10 10 70 10\n10 9 51 41\n10 8 99 100\n10 6 82 45\n10 10 7 22\n10 7 56 33\n10 9 12 70\n10 8 33 35\n10 6 58 77\n10 9 71 52\n10 9 9 73\n10 8 92 30\n10 10 58 73\n10 9 93 12\n10 9 90 83\n10 6 29 99\n10 10 59 58\n10 9 27 59\n10 8 78 21\n10 8 5 93\n10 10 4 99\n10 6 38 85\n10 8 52 33\n10 10 83 31\n10 10 31 46\n10 6 7 65\n10 10 25 6\n10 9 84 71\n10 9 16 51", "output": "1848" }, { "input": "40\n10 23 54 73\n11 10 58 84\n11 9 65 84\n11 20 45 92\n11 11 35 96\n11 6 66 16\n11 12 1 13\n11 15 8 18\n11 18 72 86\n10 24 62 38\n10 27 79 12\n11 11 24 59\n11 14 6 99\n11 6 33 100\n11 10 37 60\n11 10 67 8\n11 6 73 25\n11 8 91 3\n10 28 45 32\n11 14 64 37\n11 21 15 79\n10 29 79 53\n11 13 29 29\n10 23 76 76\n11 18 90 94\n10 30 99 49\n11 21 97 78\n10 24 27 8\n10 23 58 11\n11 3 16 30\n11 17 14 53\n11 6 13 59\n11 10 21 20\n11 15 60 24\n11 2 18 59\n11 14 69 21\n11 19 69 53\n10 26 34 43\n11 11 50 17\n11 7 50 47", "output": "1683" }, { "input": "40\n10 30 51 50\n9 16 29 39\n9 30 84 87\n9 9 6 22\n10 12 95 1\n9 2 37 64\n8 17 8 96\n9 15 23 7\n11 1 8 68\n10 7 29 81\n8 19 96 50\n9 6 14 25\n9 25 3 98\n11 4 62 17\n8 30 8 9\n8 18 93 81\n10 29 94 31\n8 10 28 69\n8 30 89 63\n10 15 40 8\n10 15 59 91\n11 15 46 89\n9 6 59 8\n11 13 42 60\n10 13 57 50\n10 23 81 71\n11 1 63 85\n9 4 9 14\n10 7 5 92\n8 26 43 81\n9 27 56 95\n9 15 65 17\n9 12 81 41\n8 10 50 58\n10 27 5 64\n11 15 88 16\n9 25 17 81\n9 21 97 96\n11 13 88 95\n9 19 54 14", "output": "1095" }, { "input": "2\n10 25 31 91\n11 14 4 85", "output": "35" }, { "input": "3\n4 20 49 95\n4 19 74 81\n4 20 85 50", "output": "208" }, { "input": "1\n9 30 34 20", "output": "34" }, { "input": "2\n1 1 1 100\n1 1 1 100", "output": "2" }, { "input": "2\n1 1 5 66\n1 1 7 55", "output": "12" }, { "input": "2\n1 5 7 3\n1 1 10 6", "output": "10" } ]
218
409,600
3
9,812
524
Фото на память - 2 (round version)
[ "dp", "greedy" ]
null
null
Прошло много лет, и на вечеринке снова встретились *n* друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке. Упрощенно процесс фотографирования можно описать следующим образом. На фотографии каждый из друзей занимает прямоугольник из пикселей: в стоячем положении *i*-й из них занимает прямоугольник ширины *w**i* пикселей и высоты *h**i* пикселей. Но также, при фотографировании каждый человек может лечь, и тогда он будет занимать прямоугольник ширины *h**i* пикселей и высоты *w**i* пикселей. Общая фотография будет иметь размеры *W*<=×<=*H*, где *W* — суммарная ширина всех прямоугольников-людей, а *H* — максимальная из высот. Друзья хотят определить, какую минимальную площадь может иметь общая фотография. Помогите им в этом.
В первой строке следует целое число *n* (1<=≤<=*n*<=≤<=1000) — количество друзей. В последующих *n* строках следуют по два целых числа *w**i*,<=*h**i* (1<=≤<=*w**i*,<=*h**i*<=≤<=1000), обозначающие размеры прямоугольника, соответствующего *i*-му из друзей.
Выведите единственное целое число, равное минимальной возможной площади фотографии, вмещающей всех друзей.
[ "3\n10 1\n20 2\n30 3\n", "3\n3 1\n2 2\n4 3\n", "1\n5 10\n" ]
[ "180\n", "21\n", "50\n" ]
none
[ { "input": "3\n10 1\n20 2\n30 3", "output": "180" }, { "input": "3\n3 1\n2 2\n4 3", "output": "21" }, { "input": "1\n5 10", "output": "50" }, { "input": "10\n168 538\n836 439\n190 873\n206 47\n891 591\n939 481\n399 898\n859 466\n701 777\n629 222", "output": "3478056" }, { "input": "42\n13 62\n114 242\n265 839\n756 349\n298 476\n533 704\n348 277\n554 573\n654 112\n429 836\n574 766\n909 415\n163 891\n532 983\n873 457\n719 117\n1 302\n170 634\n166 585\n721 231\n208 609\n128 246\n845 726\n604 119\n859 110\n568 515\n656 913\n113 166\n794 566\n834 860\n983 596\n545 819\n167 9\n960 73\n260 607\n173 378\n417 938\n362 819\n800 939\n246 834\n746 440\n42 643", "output": "13474964" }, { "input": "3\n379 820\n923 407\n916 853", "output": "1512797" }, { "input": "3\n99 768\n477 885\n169 118", "output": "614190" }, { "input": "3\n227 612\n223 259\n423 895", "output": "731790" }, { "input": "3\n651 161\n480 32\n485 672", "output": "455616" }, { "input": "3\n779 301\n34 214\n442 937", "output": "728049" }, { "input": "3\n203 145\n780 692\n992 713", "output": "1366821" }, { "input": "3\n627 286\n37 65\n53 490", "output": "235752" }, { "input": "3\n755 938\n487 543\n307 459", "output": "1307660" }, { "input": "3\n475 487\n41 20\n368 236", "output": "352925" }, { "input": "3\n922 71\n719 26\n462 700", "output": "515398" }, { "input": "2\n881 4\n788 2", "output": "5286" }, { "input": "2\n1 304\n8 892", "output": "8028" }, { "input": "3\n227 2\n223 9\n423 5", "output": "6768" }, { "input": "3\n7 612\n3 259\n3 895", "output": "11635" }, { "input": "4\n573 7\n169 9\n447 7\n947 3", "output": "19224" }, { "input": "4\n3 817\n9 729\n7 407\n7 433", "output": "21242" }, { "input": "10\n864 874\n534 702\n73 363\n856 895\n827 72\n435 468\n888 921\n814 703\n648 715\n384 781", "output": "4909752" }, { "input": "10\n489 685\n857 870\n736 221\n687 697\n166 360\n265 200\n738 519\n393 760\n66 176\n798 160", "output": "3231747" }, { "input": "1\n1 1", "output": "1" }, { "input": "1\n1000 1000", "output": "1000000" }, { "input": "1\n1 1000", "output": "1000" }, { "input": "2\n1 1000\n1000 1", "output": "2000" }, { "input": "2\n1 1\n1000 1000", "output": "1001000" }, { "input": "1\n1000 1", "output": "1000" }, { "input": "2\n1 1\n1 1", "output": "2" }, { "input": "3\n1 4\n1 4\n1 1", "output": "9" }, { "input": "2\n2 1\n3 1", "output": "5" }, { "input": "2\n4 3\n2 1", "output": "15" }, { "input": "5\n78 94\n8 53\n81 8\n41 11\n57 57", "output": "14418" }, { "input": "8\n1 8\n1 8\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "22" } ]
31
0
0
9,827
0
none
[ "none" ]
null
null
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on. During cooking, Julia goes to the kitchen every *d* minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs *t* minutes to be cooked on the stove, if it is turned on, and 2*t* minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
The single line contains three integers *k*, *d* and *t* (1<=≤<=*k*,<=*d*,<=*t*<=≤<=1018).
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10<=-<=9. Namely, let's assume that your answer is *x* and the answer of the jury is *y*. The checker program will consider your answer correct if .
[ "3 2 6\n", "4 2 20\n" ]
[ "6.5\n", "20.0\n" ]
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cce5d3f2f46552034d5ae5d487725705429ec7a5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a10fa55d1324328f9ba60c9343ed0ecb0506d678.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, after four minutes the chicken will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6fcc8bd6c2188b260d9d18e7b6c9e3908848df71.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/87a86c8e9632089279245fff912c077126c4e704.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
[ { "input": "3 2 6", "output": "6.5" }, { "input": "4 2 20", "output": "20.0" }, { "input": "8 10 9", "output": "10.0" }, { "input": "43 50 140", "output": "150.5" }, { "input": "251 79 76", "output": "76.0" }, { "input": "892 67 1000", "output": "1023.0" }, { "input": "1000 1000 1000", "output": "1000.0" }, { "input": "87 4 1000", "output": "1005.5" }, { "input": "1 629 384378949109878497", "output": "767537647587662141" }, { "input": "2124 6621 12695", "output": "19018" }, { "input": "27548 68747 111", "output": "111.0" }, { "input": "74974 46016 1000000000", "output": "1102134775.0" }, { "input": "223 844 704", "output": "1014.5" }, { "input": "1 558 743", "output": "1483" }, { "input": "43 387 402", "output": "718" }, { "input": "972 2 763", "output": "763.0" }, { "input": "330 167 15", "output": "15.0" }, { "input": "387 43 650", "output": "650.0" }, { "input": "1 314 824", "output": "1642" }, { "input": "2 4 18", "output": "24.0" }, { "input": "3 5 127", "output": "158.0" }, { "input": "3260 4439 6837", "output": "7426.5" }, { "input": "3950 7386 195", "output": "195.0" }, { "input": "18036 47899 1000000000", "output": "1452914012" }, { "input": "29 46 1000000000", "output": "1226666661.0" }, { "input": "403 957 1000000000000000000", "output": "1407352941176470446" }, { "input": "999999999999999999 1000000000000000000 1000000000000000000", "output": "1000000000000000000.5" }, { "input": "9 1000000000000000000 1000000000000000000", "output": "1999999999999999982" }, { "input": "1 2 1000000000000000000", "output": "1333333333333333333.0" }, { "input": "2 5 1000000000000000000", "output": "1428571428571428571.0" }, { "input": "81413279254461199 310548139128293806 1000000000000000000", "output": "1572837149684581517.5" }, { "input": "6 3 417701740543616353", "output": "417701740543616353.0" }, { "input": "17 68 4913", "output": "7854" }, { "input": "68 17 4913", "output": "4913.0" }, { "input": "121 395 621154158314692955", "output": "950991831528308936" }, { "input": "897 443 134730567336441375", "output": "160877739434079591.0" }, { "input": "200 10 979220166595737684", "output": "979220166595737684.0" }, { "input": "740 251 930540301905511549", "output": "938642796161889076.5" }, { "input": "4 232 801899894850800409", "output": "1576616742418522838" }, { "input": "472 499 166288453006087540", "output": "170912333779686266.5" }, { "input": "42 9 1000000000000000000", "output": "1034482758620689654.0" }, { "input": "312 93 1000000000000000000", "output": "1087719298245614020.0" }, { "input": "1000 1000 1000000000000000000", "output": "1000000000000000000.0" }, { "input": "6000 1000 1000000000", "output": "1000000000.0" }, { "input": "9999999999 33333 1000000000", "output": "1000000000.0" }, { "input": "33333 9999999999 1000000000", "output": "1999966667" }, { "input": "25441360464 2658201820 1000000000", "output": "1000000000.0" }, { "input": "20958318104 46685 253251869", "output": "253251869.0" }, { "input": "963276084 698548036 1000000000", "output": "1036723916" }, { "input": "574520976350867177 413897686591532160 1000000000000000000", "output": "1126637198416098571.5" }, { "input": "575556838390916379 15 1000000000000000000", "output": "1000000000000000003.0" }, { "input": "1000000000000000000 1000000000000000000 1000000000000000000", "output": "1000000000000000000.0" }, { "input": "1 1000000000000000000 1000000000000000000", "output": "1999999999999999998" }, { "input": "8 1000000000000000000 1000000000000000000", "output": "1999999999999999984" }, { "input": "1 976958144546785462 1000000000000000000", "output": "1999999999999999997" }, { "input": "3 10 1000000000000000000", "output": "1538461538461538461.0" }, { "input": "312200625484460654 543737694709247394 1000000000000000000", "output": "1231537069224786740.0" }, { "input": "2 99 53", "output": "102" }, { "input": "900000000000000000 1 1234", "output": "1234.0" } ]
61
21,401,600
0
9,836
612
Square Root of Permutation
[ "combinatorics", "constructive algorithms", "dfs and similar", "graphs", "math" ]
null
null
A permutation of length *n* is an array containing each integer from 1 to *n* exactly once. For example, *q*<==<=[4,<=5,<=1,<=2,<=3] is a permutation. For the permutation *q* the square of permutation is the permutation *p* that *p*[*i*]<==<=*q*[*q*[*i*]] for each *i*<==<=1... *n*. For example, the square of *q*<==<=[4,<=5,<=1,<=2,<=3] is *p*<==<=*q*2<==<=[2,<=3,<=4,<=5,<=1]. This problem is about the inverse operation: given the permutation *p* you task is to find such permutation *q* that *q*2<==<=*p*. If there are several such *q* find any of them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=106) — the number of elements in permutation *p*. The second line contains *n* distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the elements of permutation *p*.
If there is no permutation *q* such that *q*2<==<=*p* print the number "-1". If the answer exists print it. The only line should contain *n* different integers *q**i* (1<=≤<=*q**i*<=≤<=*n*) — the elements of the permutation *q*. If there are several solutions print any of them.
[ "4\n2 1 4 3\n", "4\n2 1 3 4\n", "5\n2 3 4 5 1\n" ]
[ "3 4 2 1\n", "-1\n", "4 5 1 2 3\n" ]
none
[ { "input": "4\n2 1 4 3", "output": "3 4 2 1" }, { "input": "4\n2 1 3 4", "output": "-1" }, { "input": "5\n2 3 4 5 1", "output": "4 5 1 2 3" }, { "input": "1\n1", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "10\n8 2 10 3 4 6 1 7 9 5", "output": "-1" }, { "input": "10\n3 5 1 2 10 8 7 6 4 9", "output": "6 9 8 10 4 3 7 1 5 2" }, { "input": "100\n11 9 35 34 51 74 16 67 26 21 14 80 84 79 7 61 28 3 53 43 42 5 56 36 69 30 22 88 1 27 65 91 46 31 59 50 17 96 25 18 64 55 78 2 63 24 95 48 93 13 38 76 89 94 15 90 45 81 52 87 83 73 44 49 23 82 85 75 86 33 47 19 58 97 37 20 40 10 92 4 6 68 77 54 71 12 62 60 100 39 41 99 72 29 57 8 70 32 66 98", "output": "-1" }, { "input": "100\n94 22 24 99 58 97 20 29 67 30 38 64 77 50 15 44 92 88 39 42 25 70 2 76 84 6 37 49 17 71 31 19 26 79 10 35 65 63 32 95 5 8 52 27 83 18 53 93 13 81 48 68 54 82 34 60 87 23 16 86 55 40 61 45 28 7 74 41 14 91 3 72 33 11 98 89 90 69 78 36 80 59 56 21 43 1 75 46 47 12 96 73 57 51 4 85 9 100 66 62", "output": "78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 32 54 84 68 43 4 21 28 73 6 16 62 31 39 65 86 98 75 33 45 19 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 38 26 47 90 70 51 41 40 72 37 12 35 99 67 94 1 87 57 8 61 25 23 79 36 18 66 74 5 27 81 69 24 58 13 10 89 30" } ]
841
144,896,000
3
9,843
560
Gerald is into Art
[ "constructive algorithms", "implementation" ]
null
null
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an *a*1<=×<=*b*1 rectangle, the paintings have shape of a *a*2<=×<=*b*2 and *a*3<=×<=*b*3 rectangles. Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough?
The first line contains two space-separated numbers *a*1 and *b*1 — the sides of the board. Next two lines contain numbers *a*2,<=*b*2,<=*a*3 and *b*3 — the sides of the paintings. All numbers *a**i*,<=*b**i* in the input are integers and fit into the range from 1 to 1000.
If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes).
[ "3 2\n1 3\n2 1\n", "5 5\n3 3\n3 3\n", "4 2\n2 3\n1 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
That's how we can place the pictures in the first test: <img class="tex-graphics" src="https://espresso.codeforces.com/b41bf40c649073c6d3dd62eb7ae7adfc4bd131bd.png" style="max-width: 100.0%;max-height: 100.0%;"/> And that's how we can do it in the third one. <img class="tex-graphics" src="https://espresso.codeforces.com/dafdf616eaa5ef10cd3c9ccdc7fba7ece392268c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
[ { "input": "3 2\n1 3\n2 1", "output": "YES" }, { "input": "5 5\n3 3\n3 3", "output": "NO" }, { "input": "4 2\n2 3\n1 2", "output": "YES" }, { "input": "3 3\n1 1\n1 1", "output": "YES" }, { "input": "1000 1000\n999 999\n1 1000", "output": "YES" }, { "input": "7 7\n5 5\n2 4", "output": "YES" }, { "input": "3 3\n2 2\n2 2", "output": "NO" }, { "input": "2 9\n5 1\n3 2", "output": "YES" }, { "input": "9 9\n3 8\n5 2", "output": "YES" }, { "input": "10 10\n10 5\n4 3", "output": "YES" }, { "input": "10 6\n10 1\n5 7", "output": "YES" }, { "input": "6 10\n6 3\n6 2", "output": "YES" }, { "input": "7 10\n7 5\n1 7", "output": "YES" }, { "input": "10 10\n7 4\n3 5", "output": "YES" }, { "input": "4 10\n1 1\n9 3", "output": "YES" }, { "input": "8 7\n1 7\n3 2", "output": "YES" }, { "input": "5 10\n5 2\n3 5", "output": "YES" }, { "input": "9 9\n9 7\n2 9", "output": "YES" }, { "input": "8 10\n3 8\n7 4", "output": "YES" }, { "input": "10 10\n6 6\n4 9", "output": "YES" }, { "input": "8 9\n7 6\n2 3", "output": "YES" }, { "input": "10 10\n9 10\n6 1", "output": "YES" }, { "input": "90 100\n52 76\n6 47", "output": "YES" }, { "input": "84 99\n82 54\n73 45", "output": "YES" }, { "input": "100 62\n93 3\n100 35", "output": "YES" }, { "input": "93 98\n75 32\n63 7", "output": "YES" }, { "input": "86 100\n2 29\n71 69", "output": "YES" }, { "input": "96 100\n76 21\n78 79", "output": "YES" }, { "input": "99 100\n95 68\n85 32", "output": "YES" }, { "input": "97 100\n95 40\n70 60", "output": "YES" }, { "input": "100 100\n6 45\n97 54", "output": "YES" }, { "input": "99 100\n99 72\n68 1", "output": "YES" }, { "input": "88 100\n54 82\n86 45", "output": "YES" }, { "input": "91 100\n61 40\n60 88", "output": "YES" }, { "input": "100 100\n36 32\n98 68", "output": "YES" }, { "input": "78 86\n63 8\n9 4", "output": "YES" }, { "input": "72 93\n38 5\n67 64", "output": "YES" }, { "input": "484 1000\n465 2\n9 535", "output": "YES" }, { "input": "808 1000\n583 676\n527 416", "output": "YES" }, { "input": "965 1000\n606 895\n533 394", "output": "YES" }, { "input": "824 503\n247 595\n151 570", "output": "YES" }, { "input": "970 999\n457 305\n542 597", "output": "YES" }, { "input": "332 834\n312 23\n505 272", "output": "YES" }, { "input": "886 724\n830 439\n102 594", "output": "YES" }, { "input": "958 1000\n326 461\n836 674", "output": "YES" }, { "input": "903 694\n104 488\n567 898", "output": "YES" }, { "input": "800 1000\n614 163\n385 608", "output": "YES" }, { "input": "926 1000\n813 190\n187 615", "output": "YES" }, { "input": "541 1000\n325 596\n403 56", "output": "YES" }, { "input": "881 961\n139 471\n323 731", "output": "YES" }, { "input": "993 1000\n201 307\n692 758", "output": "YES" }, { "input": "954 576\n324 433\n247 911", "output": "YES" }, { "input": "7 3\n7 8\n1 5", "output": "NO" }, { "input": "5 9\n2 7\n8 10", "output": "NO" }, { "input": "10 4\n4 3\n5 10", "output": "NO" }, { "input": "2 7\n8 3\n2 7", "output": "NO" }, { "input": "1 4\n7 2\n3 2", "output": "NO" }, { "input": "5 8\n5 1\n10 5", "output": "NO" }, { "input": "3 5\n3 6\n10 7", "output": "NO" }, { "input": "6 2\n6 6\n1 2", "output": "NO" }, { "input": "10 3\n6 6\n4 7", "output": "NO" }, { "input": "9 10\n4 8\n5 6", "output": "YES" }, { "input": "3 8\n3 2\n8 7", "output": "NO" }, { "input": "3 3\n3 4\n3 6", "output": "NO" }, { "input": "6 10\n1 8\n3 2", "output": "YES" }, { "input": "8 1\n7 5\n3 9", "output": "NO" }, { "input": "9 7\n5 2\n4 1", "output": "YES" }, { "input": "100 30\n42 99\n78 16", "output": "NO" }, { "input": "64 76\n5 13\n54 57", "output": "YES" }, { "input": "85 19\n80 18\n76 70", "output": "NO" }, { "input": "57 74\n99 70\n86 29", "output": "NO" }, { "input": "22 21\n73 65\n92 35", "output": "NO" }, { "input": "90 75\n38 2\n100 61", "output": "NO" }, { "input": "62 70\n48 12\n75 51", "output": "NO" }, { "input": "23 17\n34 71\n98 34", "output": "NO" }, { "input": "95 72\n65 31\n89 50", "output": "NO" }, { "input": "68 19\n39 35\n95 65", "output": "NO" }, { "input": "28 65\n66 27\n5 72", "output": "NO" }, { "input": "100 16\n41 76\n24 15", "output": "NO" }, { "input": "21 63\n28 73\n60 72", "output": "NO" }, { "input": "85 18\n37 84\n35 62", "output": "NO" }, { "input": "58 64\n98 30\n61 52", "output": "NO" }, { "input": "32 891\n573 351\n648 892", "output": "NO" }, { "input": "796 846\n602 302\n600 698", "output": "NO" }, { "input": "665 289\n608 360\n275 640", "output": "NO" }, { "input": "237 595\n318 161\n302 838", "output": "NO" }, { "input": "162 742\n465 429\n571 29", "output": "NO" }, { "input": "222 889\n491 923\n76 195", "output": "NO" }, { "input": "794 140\n166 622\n378 905", "output": "NO" }, { "input": "663 287\n193 212\n615 787", "output": "NO" }, { "input": "427 433\n621 441\n868 558", "output": "NO" }, { "input": "1000 388\n332 49\n735 699", "output": "NO" }, { "input": "868 535\n409 690\n761 104", "output": "YES" }, { "input": "632 786\n710 208\n436 290", "output": "YES" }, { "input": "501 932\n463 636\n363 918", "output": "NO" }, { "input": "73 79\n626 483\n924 517", "output": "NO" }, { "input": "190 34\n653 163\n634 314", "output": "NO" }, { "input": "2 4\n1 3\n1 4", "output": "YES" }, { "input": "3 10\n1 1\n1 11", "output": "NO" }, { "input": "5 4\n3 3\n2 6", "output": "NO" }, { "input": "3 4\n1 6\n2 3", "output": "NO" } ]
62
5,120,000
0
9,871
773
Prairie Partition
[ "binary search", "constructive algorithms", "greedy", "math" ]
null
null
It can be shown that any positive integer *x* can be uniquely represented as *x*<==<=1<=+<=2<=+<=4<=+<=...<=+<=2*k*<=-<=1<=+<=*r*, where *k* and *r* are integers, *k*<=≥<=0, 0<=&lt;<=*r*<=≤<=2*k*. Let's call that representation prairie partition of *x*. For example, the prairie partitions of 12, 17, 7 and 1 are: 17<==<=1<=+<=2<=+<=4<=+<=8<=+<=2, 7<==<=1<=+<=2<=+<=4, 1<==<=1. Alice took a sequence of positive integers (possibly with repeating elements), replaced every element with the sequence of summands in its prairie partition, arranged the resulting numbers in non-decreasing order and gave them to Borys. Now Borys wonders how many elements Alice's original sequence could contain. Find all possible options!
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of numbers given from Alice to Borys. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1012; *a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*) — the numbers given from Alice to Borys.
Output, in increasing order, all possible values of *m* such that there exists a sequence of positive integers of length *m* such that if you replace every element with the summands in its prairie partition and arrange the resulting numbers in non-decreasing order, you will get the sequence given in the input. If there are no such values of *m*, output a single integer -1.
[ "8\n1 1 2 2 3 4 5 8\n", "6\n1 1 1 2 2 2\n", "5\n1 2 4 4 4\n" ]
[ "2 \n", "2 3 \n", "-1\n" ]
In the first example, Alice could get the input sequence from [6, 20] as the original sequence. In the second example, Alice's original sequence could be either [4, 5] or [3, 3, 3].
[ { "input": "8\n1 1 2 2 3 4 5 8", "output": "2 " }, { "input": "6\n1 1 1 2 2 2", "output": "2 3 " }, { "input": "5\n1 2 4 4 4", "output": "-1" }, { "input": "20\n1 1 1 1 2 2 2 2 4 4 4 4 8 8 8 8 8 10 10 11", "output": "4 " }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2", "output": "9 10 11 12 13 14 15 16 17 " }, { "input": "25\n1 1 1 1 2 2 2 2 4 4 4 4 8 8 8 8 13 15 16 16 31 32 36 41 55", "output": "-1" }, { "input": "25\n1 1 1 1 2 2 2 2 4 4 4 4 8 8 8 9 16 16 32 40 43 53 61 64 128", "output": "-1" }, { "input": "45\n1 1 1 1 1 2 2 2 2 2 2 2 4 4 4 4 4 4 8 8 8 8 8 8 16 16 16 16 16 32 32 32 32 32 41 64 64 64 64 128 128 128 256 256 512", "output": "5 " }, { "input": "100\n1 1 1 1 1 1 1 2 2 2 2 2 2 2 4 4 4 4 4 4 4 6 8 8 8 8 8 8 8 10 16 16 16 16 16 16 16 17 22 24 24 30 32 32 32 32 32 32 48 62 64 64 65 65 67 70 74 88 89 98 99 101 101 109 121 127 128 128 137 143 152 153 155 156 160 161 170 183 186 196 196 214 220 226 228 230 238 240 241 245 249 249 250 253 254 256 256 512 1024 1703", "output": "-1" }, { "input": "101\n1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 7 8 8 8 8 8 8 8 8 8 8 8 16 16 16 16 16 16 16 16 16 16 16 32 32 32 32 32 32 32 32 32 32 64 64 64 64 64 64 64 64 64 128 128 128 128 128 128 128 128 239 256 256 256 256 256 373 512 512 512 512 695 1024 1024 1024", "output": "11 12 " }, { "input": "101\n1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 5 8 8 8 8 8 8 8 8 8 8 8 8 16 16 16 16 16 16 16 16 16 16 16 16 26 32 32 32 32 32 32 32 32 49 58 64 64 64 64 64 64 122 128 128 128 128 128 128 256 256 256 256 256 491 512 512 512 512 718 1024 1024 1024 2935 3123", "output": "-1" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 6 6 6 8 8 8 8 8 8 8 8 11 13 14", "output": "27 28 29 30 31 32 33 34 35 36 37 38 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n1 2", "output": "1 " }, { "input": "2\n1 1", "output": "1 2 " }, { "input": "1\n2", "output": "-1" }, { "input": "1\n1000000000000", "output": "-1" }, { "input": "2\n1 1000000000000", "output": "-1" }, { "input": "40\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888", "output": "1 " }, { "input": "41\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888 1000000000000", "output": "1 " }, { "input": "41\n1 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888", "output": "1 2 " }, { "input": "96\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 8 8 8 8 8 8 8 8 8 8 8 9 12 12 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 18 21", "output": "-1" } ]
546
13,414,400
3
9,881
847
Preparing for Merge Sort
[ "binary search", "data structures" ]
null
null
Ivan has an array consisting of *n* different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into one sorted array. Ivan represent his array with increasing sequences with help of the following algorithm. While there is at least one unused number in array Ivan repeats the following procedure: - iterate through array from the left to the right; - Ivan only looks at unused numbers on current iteration; - if current number is the first unused number on this iteration or this number is greater than previous unused number on current iteration, then Ivan marks the number as used and writes it down. For example, if Ivan's array looks like [1, 3, 2, 5, 4] then he will perform two iterations. On first iteration Ivan will use and write numbers [1, 3, 5], and on second one — [2, 4]. Write a program which helps Ivan and finds representation of the given array with one or several increasing sequences in accordance with algorithm described above.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of elements in Ivan's array. The second line contains a sequence consisting of distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — Ivan's array.
Print representation of the given array in the form of one or more increasing sequences in accordance with the algorithm described above. Each sequence must be printed on a new line.
[ "5\n1 3 2 5 4\n", "4\n4 3 2 1\n", "4\n10 30 50 101\n" ]
[ "1 3 5 \n2 4 \n", "4 \n3 \n2 \n1 \n", "10 30 50 101 \n" ]
none
[ { "input": "5\n1 3 2 5 4", "output": "1 3 5 \n2 4 " }, { "input": "4\n4 3 2 1", "output": "4 \n3 \n2 \n1 " }, { "input": "4\n10 30 50 101", "output": "10 30 50 101 " }, { "input": "1\n1", "output": "1 " }, { "input": "1\n200000", "output": "200000 " }, { "input": "2\n1 2", "output": "1 2 " }, { "input": "2\n2 1", "output": "2 \n1 " }, { "input": "2\n1 200000", "output": "1 200000 " }, { "input": "2\n200000 1", "output": "200000 \n1 " }, { "input": "10\n71550121 446173607 640274071 402690754 802030518 598196518 796619138 96204862 983359971 799843967", "output": "71550121 446173607 640274071 802030518 983359971 \n402690754 598196518 796619138 799843967 \n96204862 " }, { "input": "3\n1 100 1000000000", "output": "1 100 1000000000 " }, { "input": "3\n1000000000 100 1", "output": "1000000000 \n100 \n1 " } ]
2,000
42,291,200
0
9,882
770
Draw Brackets!
[ "*special", "implementation" ]
null
null
A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" — are regular, at the same time "][", "[[]" and "[[]]][" — are irregular. Draw the given sequence using a minimalistic pseudographics in the strip of the lowest possible height — use symbols '+', '-' and '|'. For example, the sequence "[[][]][]" should be represented as: Each bracket should be represented with the hepl of one or more symbols '|' (the vertical part) and symbols '+' and '-' as on the example which is given above. Brackets should be drawn without spaces one by one, only dividing pairs of consecutive pairwise brackets with a single-space bar (so that the two brackets do not visually merge into one symbol). The image should have the minimum possible height. The enclosed bracket is always smaller than the surrounding bracket, but each bracket separately strives to maximize the height of the image. So the pair of final brackets in the example above occupies the entire height of the image. Study carefully the examples below, they adequately explain the condition of the problem. Pay attention that in this problem the answer (the image) is unique.
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=100) — the length of the sequence of brackets. The second line contains the sequence of brackets — these are *n* symbols "[" and "]". It is guaranteed that the given sequence of brackets is regular.
Print the drawn bracket sequence in the format which is given in the condition. Don't print extra (unnecessary) spaces.
[ "8\n[[][]][]\n", "6\n[[[]]]\n", "6\n[[][]]\n", "2\n[]\n", "4\n[][]\n" ]
[ "+- -++- -+\n|+- -++- -+|| |\n|| || ||| |\n|+- -++- -+|| |\n+- -++- -+\n", "+- -+\n|+- -+|\n||+- -+||\n||| |||\n||+- -+||\n|+- -+|\n+- -+\n", "+- -+\n|+- -++- -+|\n|| || ||\n|+- -++- -+|\n+- -+\n", "+- -+\n| |\n+- -+\n", "+- -++- -+\n| || |\n+- -++- -+\n" ]
none
[ { "input": "8\n[[][]][]", "output": "+- -++- -+\n|+- -++- -+|| |\n|| || ||| |\n|+- -++- -+|| |\n+- -++- -+" }, { "input": "6\n[[[]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n||| |||\n||+- -+||\n|+- -+|\n+- -+" }, { "input": "6\n[[][]]", "output": "+- -+\n|+- -++- -+|\n|| || ||\n|+- -++- -+|\n+- -+" }, { "input": "2\n[]", "output": "+- -+\n| |\n+- -+" }, { "input": "4\n[][]", "output": "+- -++- -+\n| || |\n+- -++- -+" }, { "input": "4\n[[]]", "output": "+- -+\n|+- -+|\n|| ||\n|+- -+|\n+- -+" }, { "input": "6\n[][][]", "output": "+- -++- -++- -+\n| || || |\n+- -++- -++- -+" }, { "input": "6\n[][[]]", "output": "+- -++- -+\n| ||+- -+|\n| ||| ||\n| ||+- -+|\n+- -++- -+" }, { "input": "6\n[[]][]", "output": "+- -++- -+\n|+- -+|| |\n|| ||| |\n|+- -+|| |\n+- -++- -+" }, { "input": "100\n[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- ..." }, { "input": "100\n[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", "output": "+- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -+\n| || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || || |\n+- -++-..." }, { "input": "8\n[[]][[]]", "output": "+- -++- -+\n|+- -+||+- -+|\n|| |||| ||\n|+- -+||+- -+|\n+- -++- -+" }, { "input": "10\n[[[]][[]]]", "output": "+- -+\n|+- -++- -+|\n||+- -+||+- -+||\n||| |||| |||\n||+- -+||+- -+||\n|+- -++- -+|\n+- -+" }, { "input": "24\n[[][[[[[[[[][]][]]]]]]]]", "output": "+- -+\n|+- -++- -+|\n|| ||+- -+||\n|| |||+- -+|||\n|| ||||+- -+||||\n|| |||||+- -+|||||\n|| ||||||+- -+||||||\n|| |||||||+- -++- -+|||||||\n|| ||||||||+- -++- -+|| ||||||||\n|| ||||||||| || ||| ||||||||\n|| ||||||||+- -++- -+|| ||||||||\n|| |||||||+- -++- -+|||||||\n|| ||||||+- -+||||||\n|| |||||+- ..." }, { "input": "26\n[[[[[][]]][[[][]][]][][]]]", "output": "+- -+\n|+- -+|\n||+- -++- -++- -++- -+||\n|||+- -+||+- -++- -+|| || |||\n||||+- -++- -+||||+- -++- -+|| ||| || |||\n||||| || |||||| || ||| ||| || |||\n||||+- -++- -+||||+- -++- -+|| ||| || |||\n|||+- -+||+- -++- -+|| || |||\n||+- -++- -++- -++- -+||\n|+- -+|\n+- ..." }, { "input": "28\n[[[[[]]]]][][[[[[][]][]]][]]", "output": "+- -++- -++- -+\n|+- -+|| ||+- -++- -+|\n||+- -+||| |||+- -+|| ||\n|||+- -+|||| ||||+- -++- -+||| ||\n||||+- -+||||| |||||+- -++- -+|| |||| ||\n||||| |||||| |||||| || ||| |||| ||\n||||+- -+||||| |||||+- -++- -+|| |||| ||\n|||+- -+|||| ||||+- -++- -+||| ||\n||+- -+||| |||+- -+|| ||\n|+- -+|| ||+- -++- -+|\n+- -++- -++- ..." }, { "input": "36\n[[[[[[[[]]][[[[[]][][][][]]]]][]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -++- -+||||\n|||||+- -++- -+|| |||||\n||||||+- -+||+- -+||| |||||\n|||||||+- -+||||+- -+|||| |||||\n|||||||| ||||||+- -++- -++- -++- -+..." }, { "input": "38\n[[[[]][[]][[[][]][][]][]][][[]][][]][]", "output": "+- -++- -+\n|+- -++- -++- -++- -++- -+|| |\n||+- -++- -++- -++- -+|| ||+- -+|| || ||| |\n|||+- -+||+- -+||+- -++- -++- -+|| ||| ||| ||| || ||| |\n|||| |||| ||||+- -++- -+|| || ||| ||| ||| ||| || ||| |\n|||| |||| ||||| || ||| || ||| ||| ||| ||| || ||| |\n|||| |||| ||||+- -++- -+|| || ||| ||| ||| ..." }, { "input": "40\n[[[][[]][[][]][]][[]][[]][]][][][][][][]", "output": "+- -++- -++- -++- -++- -++- -++- -+\n|+- -++- -++- -++- -+|| || || || || || |\n||+- -++- -++- -++- -+||+- -+||+- -+|| ||| || || || || || |\n||| ||+- -+||+- -++- -+|| |||| |||| ||| ||| || || || || || |\n||| ||| |||| || ||| |||| |||| ||| ||| || || || || || |\n||| ||+- -+||+- -++- -+|| |||| |||| ||| ||| || || || || || |\n||+- -+..." }, { "input": "48\n[[[]]][[[[[[[[[[[[[[]][[]][[[[][]]]]]]]]]]]]]]]]", "output": "+- -++- -+\n|+- -+||+- -+|\n||+- -+||||+- -+||\n||| ||||||+- -+|||\n||| |||||||+- -+||||\n||| ||||||||+- -+|||||\n||| |||||||||+- -+||||||\n||| ||||||||||+- -+..." }, { "input": "50\n[[[[[[[[[[[[]][[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n|||||+- -+|||||\n||||||+- -+||||||\n|||||||+- -+|||||||\n||||||||+- -..." }, { "input": "52\n[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n|||||+- -+|||||\n||||||+- -+||||||\n|||||||+- -+|||||||\n||||||||+- -+||||||||..." }, { "input": "60\n[[[[[[][][][][]][[]][]][][]][][[]][]][[]][][]][[][]][[]][][]", "output": "+- -++- -++- -++- -++- -+\n|+- -++- -++- -++- -+||+- -++- -+||+- -+|| || |\n||+- -++- -++- -++- -+||+- -+|| || |||| || |||| ||| || |\n|||+- -++- -++- -+|| ||+- -+|| |||| ||| || |||| || |||| ||| || |\n||||+- ..." }, { "input": "62\n[[[[[[[[[[[[[[[[[[[[[[]]]]]]]][[[[[[[]]]]][[]]]]]]]]]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n|||||+- -+|||||\n||||||+- -+||||||\n..." }, { "input": "64\n[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]][][[[[]]]]]]]]]]]]][[]]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n|||||+- -+|||||\n||||||+- ..." }, { "input": "70\n[[[]][[[]]]][[[[[][[[[]]]]][[]]]]][[[]][][[[[[[]]]]]][[][[[[]][][]]]]]", "output": "+- -++- -++- -+\n|+- -++- -+||+- -+||+- -++- -++- -++- -+|\n||+- -+||+- -+||||+- -+||||+- -+|| ||+- -+||+- -++- -+||\n||| ||||+- -+||||||+- -++- -+|||||| ||| |||+- -+|||| ||+- -+|||\n||| ||||| ||||||||+- -++- -+||+- -+||||||| ||| ||||+- -+|||||..." }, { "input": "72\n[[[[[[][]][[[]][]]]]]][[[[[[[[[]][]]]][[[[[]]][[[[[[][]][[][]]]]]]]]]]]]", "output": "+- -++- -+\n|+- -+||+- -+|\n||+- -+||||+- -+||\n|||+- -+||||||+- -+|||\n||||+- -++- -+||||||||+- -++- ..." }, { "input": "74\n[[[[[[[[[]][]]]]]][[[[][][]]][[]]]]][[[[[[]][[]][]][[[][[]]][]][[[]][]]]]]", "output": "+- -++- -+\n|+- -+||+- -+|\n||+- -++- -+||||+- -+||\n|||+- -+||+- -++- -+||||||+- -++- -++- -+|||\n||||+- -+||||+- ..." }, { "input": "76\n[[[][][]][[][]]][[[[[]][][[]][]]][[][][]][[[]][[][][]][[]]][][]][[[]][]][][]", "output": "+- -++- -++- -++- -++- -+\n|+- -++- -+||+- -++- -++- -++- -++- -+||+- -++- -+|| || |\n||+- -++- -++- -+||+- -++- -+||||+- -+||+- -++- -++- -+||+- -++- -++- -+|| || ||||+- -+|| ||| || |\n||| || || |||| || ||||||+- -++- -++- -++- -+|||| || ..." }, { "input": "78\n[[[[[[[[[[]]][[][]]]]]]]][[][]][][]][[[][][]]][[][]][[[[[]][]][[[[]][[]]]][]]]", "output": "+- -++- -++- -++- -+\n|+- -++- -++- -++- -+||+- -+||+- -++- -+||+- -+|\n||+- -+||+- -++- -+|| || ||||+- -++- -++- -+|||| || ||||+- -++- -++- -+||\n|||+- -+|||| || ||| || ||||| || || ||||| || |||||+- -++- -+||+- ..." }, { "input": "80\n[[[[[[]][]][[][]][[][]][][]][[[[[][]]]][[[]][][[][]]][][][]]][[[]]][][]][[[]]][]", "output": "+- -++- -++- -+\n|+- -++- -++- -++- -+||+- -+|| |\n||+- -++- -+||+- -+|| || ||||+- -+||| |\n|||+- -++- -++- -++- -++- -+||+- ..." }, { "input": "82\n[[[]][]][[[[[]][]][][[]][]][[[][]][[]][][[][]][][]][[[[][]]][]][]][[][[]][]][][][]", "output": "+- -++- -++- -++- -++- -++- -+\n|+- -++- -+||+- -++- -++- -++- -+||+- -++- -++- -+|| || || |\n||+- -+|| ||||+- -++- -++- -++- -+||+- -++- -++- -++- -++- -++- -+||+- -++- -+|| |||| ||+- -+|| ||| || || |\n||| ||| |||||+- -++- -+|| ..." }, { "input": "84\n[[][]][[[[[][]][[[]][]][]][[][][][[]][]][[[][]][[]][]]][][][][[]][]][[][][]][[]][][]", "output": "+- -++- -++- -++- -++- -++- -+\n|+- -++- -+||+- -++- -++- -++- -++- -++- -+||+- -++- -++- -+||+- -+|| || |\n|| || ||||+- -++- -++- -+|| || || ||+- -+|| |||| || || |||| ||| || |\n|| || ..." }, { "input": "86\n[[[[[[[[[[[[[[[[[[[[[[[[[][]]][[[]]]]]]]]]]]]]]]]]][[[[]][[[[[[]]]][[[[]]]]]]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- ..." }, { "input": "88\n[[[[[[][]]]][[[]][[[[]]]]]][[][[][][[[][[][]][]][[[]]]][]][[[[]][[[]][][]]][[]][]]]][[]]", "output": "+- -++- -+\n|+- -++- -+||+- -+|\n||+- -++- -+||+- -++- -++- -+|||| ||\n|||+- -+||+- -++- -+|||| ||+- -++- -++- ..." }, { "input": "90\n[[[[[]][[]][][][]][][[][]][[][]]][[][[]]][[[[[[[[[]][][][]][][]]]][][[]][]]][[]][][]][][]]", "output": "+- -+\n|+- -++- -++- -++- -++- -+|\n||+- -++- -++- -++- -+||+- -++- -+||+- -++- -++- -++- -+|| || ||\n|..." }, { "input": "92\n[[[[[[[[[[[[[[[[][]]]]]]]]]]][[]]]]][[[]]][[[[][[][[[[[]]]]]]][[[]]]]][[[[]]]][[[[[]]]][]]]]", "output": "+- -+\n|+- -+|\n||+- -++- -++- -++- -++- -+||\n|||+- -+||+- -+||+- -+||+- -+||+- -++- -+|||\n|||..." }, { "input": "94\n[[[[[][][][]][[[]][[[]]]][[][]]][[][]][[][[]]][]][[[[[][]]][][]][[[]][[][]][[[]]][][[[]][]]]]]", "output": "+- -+\n|+- -++- -+|\n||+- -++- -++- -++- -+||+- -++- -+||\n|||+- ..." }, { "input": "96\n[[[[[[[[[[[[[[[[[[]]][[[[[[[][[[[[[[[]]]]]]]]]]]]]]]]][[[[[[[[[]]]]]]]][[][[[[]]]]]]]]]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- ..." }, { "input": "98\n[[[[[[[[]][]]]]][]]][[[[[[[[[[]]][]][[[][]][][]]][[[[[[[[[[[]]][][]]]]][[[[]]]]]]][][]][[]][]]]]]]", "output": "+- -++- -+\n|+- -+||+- -+|\n||+- -++- -+||||+- -+||\n|||+- -+|| ||||||+- ..." }, { "input": "100\n[[[[][[][]][]][[]][]][[]][[][]][]][[[[[[][][]][][][[]][[]][]][[]][[][]][[]][][][]]][[[[]][]][]][][]]", "output": "+- -++- -+\n|+- -++- -++- -++- -+||+- -++- -++- -++- -+|\n||+- -++- -++- -+||+- -+||+- -++- -+|| ||||+- ..." }, { "input": "100\n[[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]]", "output": "+- -+\n|+- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -++- -+|\n|| || || ..." }, { "input": "8\n[][][][]", "output": "+- -++- -++- -++- -+\n| || || || |\n+- -++- -++- -++- -+" }, { "input": "8\n[[][][]]", "output": "+- -+\n|+- -++- -++- -+|\n|| || || ||\n|+- -++- -++- -+|\n+- -+" }, { "input": "8\n[[][[]]]", "output": "+- -+\n|+- -++- -+|\n|| ||+- -+||\n|| ||| |||\n|| ||+- -+||\n|+- -++- -+|\n+- -+" }, { "input": "8\n[[[]][]]", "output": "+- -+\n|+- -++- -+|\n||+- -+|| ||\n||| ||| ||\n||+- -+|| ||\n|+- -++- -+|\n+- -+" }, { "input": "8\n[][[][]]", "output": "+- -++- -+\n| ||+- -++- -+|\n| ||| || ||\n| ||+- -++- -+|\n+- -++- -+" }, { "input": "8\n[[]][[]]", "output": "+- -++- -+\n|+- -+||+- -+|\n|| |||| ||\n|+- -+||+- -+|\n+- -++- -+" }, { "input": "8\n[[]][][]", "output": "+- -++- -++- -+\n|+- -+|| || |\n|| ||| || |\n|+- -+|| || |\n+- -++- -++- -+" }, { "input": "8\n[][[]][]", "output": "+- -++- -++- -+\n| ||+- -+|| |\n| ||| ||| |\n| ||+- -+|| |\n+- -++- -++- -+" }, { "input": "8\n[][][[]]", "output": "+- -++- -++- -+\n| || ||+- -+|\n| || ||| ||\n| || ||+- -+|\n+- -++- -++- -+" }, { "input": "8\n[[[][]]]", "output": "+- -+\n|+- -+|\n||+- -++- -+||\n||| || |||\n||+- -++- -+||\n|+- -+|\n+- -+" }, { "input": "10\n[[[[[]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n||||| |||||\n||||+- -+||||\n|||+- -+|||\n||+- -+||\n|+- -+|\n+- -+" }, { "input": "14\n[[[][[[[]]]]]]", "output": "+- -+\n|+- -+|\n||+- -++- -+||\n||| ||+- -+|||\n||| |||+- -+||||\n||| ||||+- -+|||||\n||| ||||| ||||||\n||| ||||+- -+|||||\n||| |||+- -+||||\n||| ||+- -+|||\n||+- -++- -+||\n|+- -+|\n+- -+" }, { "input": "30\n[[[[[[[[][]]]][[[[[[]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -++- -+||||\n|||||+- -+||+- -+|||||\n||||||+- -+||||+- -+||||||\n|||||||+- -++- -+||||||+- -+|||||||\n|||||||| || ||||||||+- -+||||||||\n|||||||| || |||||||||+- -+|||||||||\n|||||||| || |||||||||| ||||||||||\n|||||||| || |||||||||+- -+|||||||||\n|||||||| || |||..." }, { "input": "100\n[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]][[]]]][[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- ..." }, { "input": "10\n[[[[[]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n||||| |||||\n||||+- -+||||\n|||+- -+|||\n||+- -+||\n|+- -+|\n+- -+" }, { "input": "14\n[[[[]][[[]]]]]", "output": "+- -+\n|+- -+|\n||+- -++- -+||\n|||+- -+||+- -+|||\n|||| ||||+- -+||||\n|||| ||||| |||||\n|||| ||||+- -+||||\n|||+- -+||+- -+|||\n||+- -++- -+||\n|+- -+|\n+- -+" }, { "input": "30\n[[[[[[[]]]][[[][[[[[]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -++- -+|||\n||||+- -+||+- -+||||\n|||||+- -+||||+- -++- -+|||||\n||||||+- -+|||||| ||+- -+||||||\n||||||| ||||||| |||+- -+|||||||\n||||||| ||||||| ||||+- -+||||||||\n||||||| ||||||| |||||+- -+|||||||||\n||||||| ||||||| |||||| ||||||||||\n||||||| ||||||| |||||+- -+|||||||||\n||||||| ||||||| ..." }, { "input": "100\n[[[[[[[[[[[[[[[[]][[[[[[[[[]]]]]]]]][[[[]]]]]]]][[[[[[]]][]]]][[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- ..." }, { "input": "10\n[[[[][]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -++- -+|||\n|||| || ||||\n|||+- -++- -+|||\n||+- -+||\n|+- -+|\n+- -+" }, { "input": "14\n[[[[[[[]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n|||||+- -+|||||\n||||||+- -+||||||\n||||||| |||||||\n||||||+- -+||||||\n|||||+- -+|||||\n||||+- -+||||\n|||+- -+|||\n||+- -+||\n|+- -+|\n+- -+" }, { "input": "30\n[[[[[[[[[[[[[[]]]]]][]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n|||||+- -+|||||\n||||||+- -+||||||\n|||||||+- -+|||||||\n||||||||+- -++- -+||||||||\n|||||||||+- -+|| |||||||||\n||||||||||+- -+||| |||||||||\n|||||||||||+- -+|||| |||||||||\n||||||||||||+- -+||||| |||||||||\n|||||||||||||+- -..." }, { "input": "100\n[[[[[]][[[[[[[[[[[[[[[[[[[[[[[]]][[[]]]]]]]]]]]]][[[[[[[[[[[][[[[]]]]][[]]]][]]]]]]]]]]]]][]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -++- -+|||\n||||+- ..." }, { "input": "10\n[[[][[]]]]", "output": "+- -+\n|+- -+|\n||+- -++- -+||\n||| ||+- -+|||\n||| ||| ||||\n||| ||+- -+|||\n||+- -++- -+||\n|+- -+|\n+- -+" }, { "input": "14\n[[[[[]][][]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -++- -++- -+|||\n||||+- -+|| || ||||\n||||| ||| || ||||\n||||+- -+|| || ||||\n|||+- -++- -++- -+|||\n||+- -+||\n|+- -+|\n+- -+" }, { "input": "30\n[[[[[[][[[[][[]]][[][]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n|||||+- -++- -+|||||\n|||||| ||+- -+||||||\n|||||| |||+- -++- -+|||||||\n|||||| ||||+- -++- -+||+- -++- -+||||||||\n|||||| ||||| ||+- -+|||| || |||||||||\n|||||| ||||| ||| ||||| || |||||..." }, { "input": "100\n[[[[[[[[[[[]]][[[[]][[[]]]]]][[[[]]]]]]]]]][[[[[[]]]]][[[[[[[[[[[[[[[]]]]][[[[]][][[]]]]]]]]]]]]]]]]", "output": "+- -+\n|+- -++- -+|\n||+- -+||+- -++- -+||\n|||+- -+||||+- -+||+- -+..." }, { "input": "10\n[[[]]][[]]", "output": "+- -++- -+\n|+- -+||+- -+|\n||+- -+|||| ||\n||| ||||| ||\n||+- -+|||| ||\n|+- -+||+- -+|\n+- -++- -+" }, { "input": "14\n[[[[[[[]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n|||||+- -+|||||\n||||||+- -+||||||\n||||||| |||||||\n||||||+- -+||||||\n|||||+- -+|||||\n||||+- -+||||\n|||+- -+|||\n||+- -+||\n|+- -+|\n+- -+" }, { "input": "30\n[[[[[]]]][[[[[]]][[[[[]]]]]]]]", "output": "+- -+\n|+- -++- -+|\n||+- -+||+- -+||\n|||+- -+||||+- -++- -+|||\n||||+- -+||||||+- -+||+- -+||||\n||||| ||||||||+- -+||||+- -+|||||\n||||| ||||||||| ||||||+- -+||||||\n||||| ||||||||| |||||||+- -+|||||||\n||||| ||||||||| |||||||| ||||||||\n||||| ||||||||| |||||||+- -+|||||||\n||||| ||||||||| ||||||+- -+||||||\n||||| ||||||||+- -+||||+- -+|||||\n||||+- -+||||||+- ..." }, { "input": "100\n[[[[[[[[[[[[][[]]]][[[[[[]][]]]]]]]]]][[[[[[[[[[[]]][[]]]]]]]]][[[[[[[[]]]]][[[[][]]][[[]]]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- ..." }, { "input": "10\n[[][[[]]]]", "output": "+- -+\n|+- -++- -+|\n|| ||+- -+||\n|| |||+- -+|||\n|| |||| ||||\n|| |||+- -+|||\n|| ||+- -+||\n|+- -++- -+|\n+- -+" }, { "input": "14\n[[[[[]]]][[]]]", "output": "+- -+\n|+- -++- -+|\n||+- -+||+- -+||\n|||+- -+|||| |||\n||||+- -+||||| |||\n||||| |||||| |||\n||||+- -+||||| |||\n|||+- -+|||| |||\n||+- -+||+- -+||\n|+- -++- -+|\n+- -+" }, { "input": "30\n[[[[[][[[]]][]][[[[[]][]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -++- -+|||\n||||+- -++- -++- -+||+- -+||||\n||||| ||+- -+|| ||||+- -+|||||\n||||| |||+- -+||| |||||+- -++- -+||||||\n||||| |||| |||| ||||||+- -+|| |||||||\n||||| |||| |||| ||||||| ||| |||||||\n||||| |||| |||| ||||||+- -+|| |||||||\n||||| |||+- -+||| |||||+- -++- -+||..." }, { "input": "100\n[[[[][]][[[[[[[[[][[][[[]]]][[][][[]][]]]]]][[[[[[][]][[[[[]]]][][]]]]]][[[[[[]][[[[][]]]]]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -++- -+||\n|||+- -++- -+||+- ..." }, { "input": "10\n[[[][]]][]", "output": "+- -++- -+\n|+- -+|| |\n||+- -++- -+||| |\n||| || |||| |\n||+- -++- -+||| |\n|+- -+|| |\n+- -++- -+" }, { "input": "14\n[[[[[]]]]][[]]", "output": "+- -++- -+\n|+- -+||+- -+|\n||+- -+|||| ||\n|||+- -+||||| ||\n||||+- -+|||||| ||\n||||| ||||||| ||\n||||+- -+|||||| ||\n|||+- -+||||| ||\n||+- -+|||| ||\n|+- -+||+- -+|\n+- -++- -+" }, { "input": "30\n[[[[[[[[[]]]]]]][[[[]][[]]]]]]", "output": "+- -+\n|+- -+|\n||+- -++- -+||\n|||+- -+||+- -+|||\n||||+- -+||||+- -++- -+||||\n|||||+- -+||||||+- -+||+- -+|||||\n||||||+- -+|||||||| |||| ||||||\n|||||||+- -+||||||||| |||| ||||||\n||||||||+- -+|||||||||| |||| ||||||\n||||||||| ||||||||||| |||| ||||||\n||||||||+- -+|||||||||| |||| ||||||\n|||||||+- -+||||||||| |||| ||||||\n||||||+- -+||||..." }, { "input": "100\n[[[[][]]]][[[[[[[[[[[[[[[][]]]][][[]]]]]][][[[]][[[]][[]]]][[[]]]][[[[[[[[[][[]]]]]]]]]]]][][[]]]]]]", "output": "+- -++- -+\n|+- -+||+- -+|\n||+- -+||||+- -+||\n|||+- -++- -+||||||+- ..." }, { "input": "10\n[[[][]]][]", "output": "+- -++- -+\n|+- -+|| |\n||+- -++- -+||| |\n||| || |||| |\n||+- -++- -+||| |\n|+- -+|| |\n+- -++- -+" }, { "input": "14\n[[[[]][]][[]]]", "output": "+- -+\n|+- -++- -+|\n||+- -++- -+||+- -+||\n|||+- -+|| |||| |||\n|||| ||| |||| |||\n|||+- -+|| |||| |||\n||+- -++- -+||+- -+||\n|+- -++- -+|\n+- -+" }, { "input": "30\n[[[[[[[][[[[[[[[]]]]]]]]]]]]]]", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n|||||+- -+|||||\n||||||+- -++- -+||||||\n||||||| ||+- -+|||||||\n||||||| |||+- -+||||||||\n||||||| ||||+- -+|||||||||\n||||||| |||||+- -+||||||||||\n||||||| ||||||+- -+|||||||||||\n||||||| |||||||+- -+||||||||||||\n||||||| |||||||..." }, { "input": "100\n[[[[[[[[[]][][[[]]][]]]]][[[[[[[[[]]]]]][[]]][]]]][[[[[]]][][[[]][][]]]]]][][[[[[[[]][][[]]]]][][]]]", "output": "+- -++- -++- -+\n|+- -+|| ||+- -+|\n||+- -++- -+||| |||+- -++- -++- -+||\n|||+- -++- ..." }, { "input": "10\n[[]][][[]]", "output": "+- -++- -++- -+\n|+- -+|| ||+- -+|\n|| ||| ||| ||\n|+- -+|| ||+- -+|\n+- -++- -++- -+" }, { "input": "14\n[[][]][[]][][]", "output": "+- -++- -++- -++- -+\n|+- -++- -+||+- -+|| || |\n|| || |||| ||| || |\n|+- -++- -+||+- -+|| || |\n+- -++- -++- -++- -+" }, { "input": "30\n[[[]][][][][[[]]]][[[[[]][]]]]", "output": "+- -++- -+\n|+- -++- -++- -++- -++- -+||+- -+|\n||+- -+|| || || ||+- -+||||+- -+||\n||| ||| || || |||+- -+||||||+- -++- -+|||\n||| ||| || || |||| ||||||||+- -+|| ||||\n||| ||| || || |||| ||||||||| ||| ||||\n||| ||| || || |||| ||||||||+- -+|| ||||\n||| ||| || || |||+- -+||||||+- -++- -+|||\n||+- -+|| || || ||+- -+||||+- -+||\n|+- -++- -++- -++- -++- -+||..." }, { "input": "100\n[[[[[]]]][]][[[[[][[[[]][[]]]][][][][]][[[[[[]]][[[[[][]]]]]][[[]][][]][[[]][[][]]]]]]]][[[]]][[][]]", "output": "+- -++- -++- -++- -+\n|+- -++- -+||+- -+||+- -+||+- -++- -+|\n||+- -+|| ||||+- -+||||+- -+|||| || ||\n|||+- -+||| ..." }, { "input": "10\n[[]][[[]]]", "output": "+- -++- -+\n|+- -+||+- -+|\n|| ||||+- -+||\n|| ||||| |||\n|| ||||+- -+||\n|+- -+||+- -+|\n+- -++- -+" }, { "input": "14\n[[[]]][[[[]]]]", "output": "+- -++- -+\n|+- -+||+- -+|\n||+- -+||||+- -+||\n||| ||||||+- -+|||\n||| ||||||| ||||\n||| ||||||+- -+|||\n||+- -+||||+- -+||\n|+- -+||+- -+|\n+- -++- -+" }, { "input": "30\n[[[[[[[[[]]]]]][]]][[[]][][]]]", "output": "+- -+\n|+- -++- -+|\n||+- -+||+- -++- -++- -+||\n|||+- -++- -+||||+- -+|| || |||\n||||+- -+|| |||||| ||| || |||\n|||||+- -+||| |||||| ||| || |||\n||||||+- -+|||| |||||| ||| || |||\n|||||||+- -+||||| |||||| ||| || |||\n||||||||+- -+|||||| |||||| ||| || |||\n||||||||| ||||||| |||||| ||| || |||\n||||||||+- -+|||||| |||||| ||| || ..." }, { "input": "100\n[[[[[]][[][[]]]]]][[[[][[]]][[]][]][[[[]][][[][[[[[][]][]]]][]]]]][[[[[][]][]]][[[[[]]]]][[[]][[]]]]", "output": "+- -++- -++- -+\n|+- -+||+- -++- -+||+- -++- -++- -+|\n||+- -+||||+- -++- -++- -+||+- -+||||+- -+||+- -+||+- -++- -+||\n|||+- -++- -+|..." }, { "input": "10\n[[[[]]][]]", "output": "+- -+\n|+- -++- -+|\n||+- -+|| ||\n|||+- -+||| ||\n|||| |||| ||\n|||+- -+||| ||\n||+- -+|| ||\n|+- -++- -+|\n+- -+" }, { "input": "14\n[[[]][]][[]][]", "output": "+- -++- -++- -+\n|+- -++- -+||+- -+|| |\n||+- -+|| |||| ||| |\n||| ||| |||| ||| |\n||+- -+|| |||| ||| |\n|+- -++- -+||+- -+|| |\n+- -++- -++- -+" }, { "input": "30\n[[[[]][[]]][][]][[[][[[][]]]]]", "output": "+- -++- -+\n|+- -++- -++- -+||+- -+|\n||+- -++- -+|| || ||||+- -++- -+||\n|||+- -+||+- -+||| || ||||| ||+- -+|||\n|||| |||| |||| || ||||| |||+- -++- -+||||\n|||| |||| |||| || ||||| |||| || |||||\n|||| |||| |||| || ||||| |||+- -++- -+||||\n|||+- -+||+- -+||| || ||||| ||+- -+|||\n||+- -++- -+|| || ||||+- -++- -+||\n|+- -++- -++- -+||+- ..." }, { "input": "100\n[[[]][[[[[[][]]][[[][]][[[[[][[[][[[]]]]]]][][]]]]]]]][[[[]][]]][[[[[][]]][][]][[[][[[]]]][[[]][]]]]", "output": "+- -++- -++- -+\n|+- -++- -+||+- -+||+- -++- -+|\n||+- -+||+- -+||||+- -++- -+||||+- -++- -++- -+||+- -++- -+||\n||| ||||+- ..." }, { "input": "10\n[[[][]]][]", "output": "+- -++- -+\n|+- -+|| |\n||+- -++- -+||| |\n||| || |||| |\n||+- -++- -+||| |\n|+- -+|| |\n+- -++- -+" }, { "input": "14\n[[[[[]]][]]][]", "output": "+- -++- -+\n|+- -+|| |\n||+- -++- -+||| |\n|||+- -+|| |||| |\n||||+- -+||| |||| |\n||||| |||| |||| |\n||||+- -+||| |||| |\n|||+- -+|| |||| |\n||+- -++- -+||| |\n|+- -+|| |\n+- -++- -+" }, { "input": "30\n[[[]][[[]]][][]][[[[[][][]]]]]", "output": "+- -++- -+\n|+- -++- -++- -++- -+||+- -+|\n||+- -+||+- -+|| || ||||+- -+||\n||| ||||+- -+||| || |||||+- -+|||\n||| ||||| |||| || ||||||+- -++- -++- -+||||\n||| ||||| |||| || ||||||| || || |||||\n||| ||||| |||| || ||||||+- -++- -++- -+||||\n||| ||||+- -+||| || |||||+- -+|||\n||+- -+||+- -+|| || ||||+- -+||\n|+- -++- -++- -++- -+||+- ..." }, { "input": "100\n[[[[][[[][][]]][[[]][]][]][[[[[]][]]]]]][[[[[[]][][]]]][[[[[]][[][]]]]][]][[][[]][]][[[[]][]]][][[]]", "output": "+- -++- -++- -++- -++- -++- -+\n|+- -+||+- -++- -++- -+||+- -++- -++- -+||+- -+|| ||+- -+|\n||+- -++- -+||||+- -+||+- -+|| |||| ||+- -+|| ||||+- -++- -+||| ||| ||..." }, { "input": "10\n[[][[]][]]", "output": "+- -+\n|+- -++- -++- -+|\n|| ||+- -+|| ||\n|| ||| ||| ||\n|| ||+- -+|| ||\n|+- -++- -++- -+|\n+- -+" }, { "input": "14\n[[]][][[]][][]", "output": "+- -++- -++- -++- -++- -+\n|+- -+|| ||+- -+|| || |\n|| ||| ||| ||| || |\n|+- -+|| ||+- -+|| || |\n+- -++- -++- -++- -++- -+" }, { "input": "30\n[[[[[][]][[]][[[][]]]]]][[][]]", "output": "+- -++- -+\n|+- -+||+- -++- -+|\n||+- -+|||| || ||\n|||+- -++- -++- -+||||| || ||\n||||+- -++- -+||+- -+||+- -+|||||| || ||\n||||| || |||| ||||+- -++- -+||||||| || ||\n||||| || |||| ||||| || |||||||| || ||\n||||| || |||| ||||+- -++- -+||||||| || ||\n||||+- -++- -+||+- -+||+- -+|||||| || ||\n|||+- -++- -++- ..." }, { "input": "100\n[[[[[[[[[][]][[[]][]][[][]]][[][[[][][]][][]]][[[]][[]]][]][][[]][[]][]]]][[[][]][[][][[]]]][[]][]]]", "output": "+- -+\n|+- -+|\n||+- -++- ..." }, { "input": "10\n[][[[][]]]", "output": "+- -++- -+\n| ||+- -+|\n| |||+- -++- -+||\n| |||| || |||\n| |||+- -++- -+||\n| ||+- -+|\n+- -++- -+" }, { "input": "14\n[[]][][[]][[]]", "output": "+- -++- -++- -++- -+\n|+- -+|| ||+- -+||+- -+|\n|| ||| ||| |||| ||\n|+- -+|| ||+- -+||+- -+|\n+- -++- -++- -++- -+" }, { "input": "30\n[[]][[[][[[]][]][]][[][][]]][]", "output": "+- -++- -++- -+\n|+- -+||+- -++- -+|| |\n|| ||||+- -++- -++- -+||+- -++- -++- -+||| |\n|| ||||| ||+- -++- -+|| |||| || || |||| |\n|| ||||| |||+- -+|| ||| |||| || || |||| |\n|| ||||| |||| ||| ||| |||| || || |||| |\n|| ||||| |||+- -+|| ||| |||| || || |||| |\n|| ||||| ||+- -++- -+|| |||| || || |||| |\n|| ||||+- -++- -++- -+||+- -..." }, { "input": "100\n[[[[][]][[[[[]][][]][[[[[[][[][][]][][]]][]]]][[[][]][][[]][][]][[]][][]][][[]]]]][[[[[[][]]]]]][[]]", "output": "+- -++- -++- -+\n|+- -+||+- -+||+- -+|\n||+- -++- -+||..." }, { "input": "10\n[[[][][]]]", "output": "+- -+\n|+- -+|\n||+- -++- -++- -+||\n||| || || |||\n||+- -++- -++- -+||\n|+- -+|\n+- -+" }, { "input": "14\n[[][][]][[][]]", "output": "+- -++- -+\n|+- -++- -++- -+||+- -++- -+|\n|| || || |||| || ||\n|+- -++- -++- -+||+- -++- -+|\n+- -++- -+" }, { "input": "30\n[[[[][]][]]][][[[][[]]][[]][]]", "output": "+- -++- -++- -+\n|+- -+|| ||+- -++- -++- -+|\n||+- -++- -+||| |||+- -++- -+||+- -+|| ||\n|||+- -++- -+|| |||| |||| ||+- -+|||| ||| ||\n|||| || ||| |||| |||| ||| ||||| ||| ||\n|||+- -++- -+|| |||| |||| ||+- -+|||| ||| ||\n||+- -++- -+||| |||+- -++- -+||+- -+|| ||\n|+- -+|| ||+- -++- -++- -+|\n+- -++- -++- -+" }, { "input": "100\n[[[[[][][]][[][][][]]][[[[[]][[]][[[]]]][[[]]]][[][[][[]][]][]]]][[][[[]]][][]][[[[[][]]]][[]]][[]]]", "output": "+- -+\n|+- -++- -++- -++- -+|\n||+- -++- -+||+- -++- -++- -++- -+||+- -++- -+..." }, { "input": "10\n[[][]][][]", "output": "+- -++- -++- -+\n|+- -++- -+|| || |\n|| || ||| || |\n|+- -++- -+|| || |\n+- -++- -++- -+" }, { "input": "14\n[[][][][][]][]", "output": "+- -++- -+\n|+- -++- -++- -++- -++- -+|| |\n|| || || || || ||| |\n|+- -++- -++- -++- -++- -+|| |\n+- -++- -+" }, { "input": "30\n[[]][[[[]]][]][[[[][]][]]][[]]", "output": "+- -++- -++- -++- -+\n|+- -+||+- -++- -+||+- -+||+- -+|\n|| ||||+- -+|| ||||+- -++- -+|||| ||\n|| |||||+- -+||| |||||+- -++- -+|| ||||| ||\n|| |||||| |||| |||||| || ||| ||||| ||\n|| |||||+- -+||| |||||+- -++- -+|| ||||| ||\n|| ||||+- -+|| ||||+- -++- -+|||| ||\n|+- -+||+- -++- -+||+- -+||+- -+|\n+- -++- -++- -++- -+" }, { "input": "100\n[[]][[[[[[]][][]][[[]][][[][]][]][[[[][]][][]][[]][]]]][]][[[[[][]][[]]][]][[]][]][][[[][]][]][[]][]", "output": "+- -++- -++- -++- -++- -++- -++- -+\n|+- -+||+- -++- -+||+- -++- -++- -+|| ||+- -++- -+||+- -+|| |\n|| ||||+- -+|| ||||+- -++- -+||+- ..." }, { "input": "10\n[][[]][][]", "output": "+- -++- -++- -++- -+\n| ||+- -+|| || |\n| ||| ||| || |\n| ||+- -+|| || |\n+- -++- -++- -++- -+" }, { "input": "14\n[[]][[[]][][]]", "output": "+- -++- -+\n|+- -+||+- -++- -++- -+|\n|| ||||+- -+|| || ||\n|| ||||| ||| || ||\n|| ||||+- -+|| || ||\n|+- -+||+- -++- -++- -+|\n+- -++- -+" }, { "input": "30\n[[[[][][]]][[[[]][]][]]][[][]]", "output": "+- -++- -+\n|+- -++- -+||+- -++- -+|\n||+- -+||+- -++- -+|||| || ||\n|||+- -++- -++- -+||||+- -++- -+|| ||||| || ||\n|||| || || ||||||+- -+|| ||| ||||| || ||\n|||| || || ||||||| ||| ||| ||||| || ||\n|||| || || ||||||+- -+|| ||| ||||| || ||\n|||+- -++- -++- -+||||+- -++- -+|| ||||| || ||\n||+- -+||+- -++- -+|||| || ||\n|+- ..." }, { "input": "100\n[[[][[[[]][][]][]][[]][[][][]][[]][[]]][[[[[][[[]]][]]][]][[[[[]][][]][]][[][]][][]]][[[][]][][]][]]", "output": "+- -+\n|+- -++- -++- -++- -+|\n||+- -++- -++- -++- -++- -++- -+||+- -++- ..." }, { "input": "10\n[[[][]][]]", "output": "+- -+\n|+- -++- -+|\n||+- -++- -+|| ||\n||| || ||| ||\n||+- -++- -+|| ||\n|+- -++- -+|\n+- -+" }, { "input": "14\n[[[]][]][[]][]", "output": "+- -++- -++- -+\n|+- -++- -+||+- -+|| |\n||+- -+|| |||| ||| |\n||| ||| |||| ||| |\n||+- -+|| |||| ||| |\n|+- -++- -+||+- -+|| |\n+- -++- -++- -+" }, { "input": "30\n[[[[][]][[][]][]][[]]][][][][]", "output": "+- -++- -++- -++- -++- -+\n|+- -++- -+|| || || || |\n||+- -++- -++- -+||+- -+||| || || || |\n|||+- -++- -+||+- -++- -+|| |||| |||| || || || |\n|||| || |||| || ||| |||| |||| || || || |\n|||+- -++- -+||+- -++- -+|| |||| |||| || || || |\n||+- -++- -++- -+||+- -+||| || || || |\n|+- -++- -+|| || || || |\n+- ..." }, { "input": "100\n[[]][[[][]][[][]]][[[][[[[][[]][][[]][][]][[]][]]][[][]][][][]][[[]][[[]][]][]][[]][[][]][[]][[]][]]", "output": "+- -++- -++- -+\n|+- -+||+- -++- -+||+- -++- -++- -++- -++- -++- -++- -+|\n|| ||||+- -++- -+||+- -++- -+||||+- -++- -++- -++- -++- -++- -+||+- -++- ..." }, { "input": "10\n[[[]]][][]", "output": "+- -++- -++- -+\n|+- -+|| || |\n||+- -+||| || |\n||| |||| || |\n||+- -+||| || |\n|+- -+|| || |\n+- -++- -++- -+" }, { "input": "14\n[[[][][]][][]]", "output": "+- -+\n|+- -++- -++- -+|\n||+- -++- -++- -+|| || ||\n||| || || ||| || ||\n||+- -++- -++- -+|| || ||\n|+- -++- -++- -+|\n+- -+" }, { "input": "30\n[][[][[][][][]][]][][[][]][][]", "output": "+- -++- -++- -++- -++- -++- -+\n| ||+- -++- -++- -+|| ||+- -++- -+|| || |\n| ||| ||+- -++- -++- -++- -+|| ||| ||| || ||| || |\n| ||| ||| || || || ||| ||| ||| || ||| || |\n| ||| ||+- -++- -++- -++- -+|| ||| ||| || ||| || |\n| ||+- -++- -++- -+|| ||+- -++- -+|| || |\n+- -++- -++- -++- -++- -++- -+" }, { "input": "100\n[[[][][[]][]][[][][]][[][]][[][[]][]][]][[[]][][][]][][[[[]][]][][][]][[[][][]][[[[]][]][][][]][[]]]", "output": "+- -++- -++- -++- -++- -+\n|+- -++- -++- -++- -++- -+||+- -++- -++- -++- -+|| ||+- -++- -++- -++- -+||+- -++- -++- -+|\n||+- -++- -++- -++- -+||+- -++- -++- -+||+- -++- -+||+- -++- -++- -+|| ||||+- -+|| || || ||| |||+- ..." }, { "input": "10\n[[]][][][]", "output": "+- -++- -++- -++- -+\n|+- -+|| || || |\n|| ||| || || |\n|+- -+|| || || |\n+- -++- -++- -++- -+" }, { "input": "14\n[[][]][][][][]", "output": "+- -++- -++- -++- -++- -+\n|+- -++- -+|| || || || |\n|| || ||| || || || |\n|+- -++- -+|| || || || |\n+- -++- -++- -++- -++- -+" }, { "input": "30\n[[[]][[[]][]][][]][[[]][]][][]", "output": "+- -++- -++- -++- -+\n|+- -++- -++- -++- -+||+- -++- -+|| || |\n||+- -+||+- -++- -+|| || ||||+- -+|| ||| || |\n||| ||||+- -+|| ||| || ||||| ||| ||| || |\n||| ||||| ||| ||| || ||||| ||| ||| || |\n||| ||||+- -+|| ||| || ||||| ||| ||| || |\n||+- -+||+- -++- -+|| || ||||+- -+|| ||| || |\n|+- -++- -++- -++- -+||+- -++- -+|| || |\n+- -++- ..." }, { "input": "100\n[[[][][]][[[[[[]][][]][[]][][]][[[][]][][]][[[][]][][]][][]][][][]][[][][]][[][]][[[]][]][][][]][][]", "output": "+- -++- -++- -+\n|+- -++- -++- -++- -++- -++- -++- -++- -+|| || |\n||+- -++- -++- -+||+- ..." } ]
46
0
3
9,887
0
none
[ "none" ]
null
null
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it. That element can store information about the matrix of integers size *n*<=×<=*m*. There are *n*<=+<=*m* inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to *n* from top to bottom, while columns are numbered with integers from 1 to *m* from left to right. Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of *q* turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix. Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
The first line of the input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*q*<=≤<=10<=000) — dimensions of the matrix and the number of turns in the experiment, respectively. Next *q* lines contain turns descriptions, one per line. Each description starts with an integer *t**i* (1<=≤<=*t**i*<=≤<=3) that defines the type of the operation. For the operation of first and second type integer *r**i* (1<=≤<=*r**i*<=≤<=*n*) or *c**i* (1<=≤<=*c**i*<=≤<=*m*) follows, while for the operations of the third type three integers *r**i*, *c**i* and *x**i* (1<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*c**i*<=≤<=*m*, <=-<=109<=≤<=*x**i*<=≤<=109) are given. Operation of the first type (*t**i*<==<=1) means that signal comes to the input corresponding to row *r**i*, that is it will shift cyclically. Operation of the second type (*t**i*<==<=2) means that column *c**i* will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row *r**i* and column *c**i* stores value *x**i*.
Print the description of any valid initial matrix as *n* lines containing *m* integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
[ "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8\n", "3 3 2\n1 2\n3 2 2 5\n" ]
[ "8 2 \n1 8 \n", "0 0 0 \n0 0 5 \n0 0 0 \n" ]
none
[ { "input": "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "output": "8 2 \n1 8 " }, { "input": "3 3 2\n1 2\n3 2 2 5", "output": "0 0 0 \n0 0 5 \n0 0 0 " }, { "input": "5 5 1\n1 5", "output": "0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "1 1 3\n1 1\n2 1\n3 1 1 1000000000", "output": "1000000000 " }, { "input": "1 1 3\n1 1\n2 1\n3 1 1 -1000000000", "output": "-1000000000 " }, { "input": "2 2 6\n2 1\n2 2\n3 1 1 -1\n3 2 2 -1\n3 1 2 -1\n3 2 1 -1", "output": "-1 -1 \n-1 -1 " }, { "input": "1 4 5\n1 1\n3 1 1 1\n3 1 2 2\n3 1 3 3\n3 1 4 4", "output": "4 1 2 3 " }, { "input": "4 2 5\n2 1\n3 1 1 5\n3 2 1 6\n3 3 1 7\n3 4 1 9", "output": "9 0 \n5 0 \n6 0 \n7 0 " }, { "input": "3 10 2\n1 2\n3 2 7 5", "output": "0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 5 0 0 \n0 0 0 0 0 0 0 0 0 0 " }, { "input": "1 2 2\n1 1\n3 1 2 15", "output": "15 0 " } ]
342
29,593,600
3
9,926
0
none
[ "none" ]
null
null
You are given *n* distinct points on a plane with integral coordinates. For each point you can either draw a vertical line through it, draw a horizontal line through it, or do nothing. You consider several coinciding straight lines as a single one. How many distinct pictures you can get? Print the answer modulo 109<=+<=7.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of points. *n* lines follow. The (*i*<=+<=1)-th of these lines contains two integers *x**i*, *y**i* (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109) — coordinates of the *i*-th point. It is guaranteed that all points are distinct.
Print the number of possible distinct pictures modulo 109<=+<=7.
[ "4\n1 1\n1 2\n2 1\n2 2\n", "2\n-1 -1\n0 1\n" ]
[ "16\n", "9\n" ]
In the first example there are two vertical and two horizontal lines passing through the points. You can get pictures with any subset of these lines. For example, you can get the picture containing all four lines in two ways (each segment represents a line containing it). In the second example you can work with two points independently. The number of pictures is 3<sup class="upper-index">2</sup> = 9.
[]
30
0
0
9,936
0
none
[ "none" ]
null
null
Pupils decided to go to amusement park. Some of them were with parents. In total, *n* people came to the park and they all want to get to the most extreme attraction and roll on it exactly once. Tickets for group of *x* people are sold on the attraction, there should be at least one adult in each group (it is possible that the group consists of one adult). The ticket price for such group is *c*1<=+<=*c*2·(*x*<=-<=1)2 (in particular, if the group consists of one person, then the price is *c*1). All pupils who came to the park and their parents decided to split into groups in such a way that each visitor join exactly one group, and the total price of visiting the most extreme attraction is as low as possible. You are to determine this minimum possible total price. There should be at least one adult in each group.
The first line contains three integers *n*, *c*1 and *c*2 (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*c*1,<=*c*2<=≤<=107) — the number of visitors and parameters for determining the ticket prices for a group. The second line contains the string of length *n*, which consists of zeros and ones. If the *i*-th symbol of the string is zero, then the *i*-th visitor is a pupil, otherwise the *i*-th person is an adult. It is guaranteed that there is at least one adult. It is possible that there are no pupils.
Print the minimum price of visiting the most extreme attraction for all pupils and their parents. Each of them should roll on the attraction exactly once.
[ "3 4 1\n011\n", "4 7 2\n1101\n" ]
[ "8\n", "18\n" ]
In the first test one group of three people should go to the attraction. Then they have to pay 4 + 1 * (3 - 1)<sup class="upper-index">2</sup> = 8. In the second test it is better to go to the attraction in two groups. The first group should consist of two adults (for example, the first and the second person), the second should consist of one pupil and one adult (the third and the fourth person). Then each group will have a size of two and for each the price of ticket is 7 + 2 * (2 - 1)<sup class="upper-index">2</sup> = 9. Thus, the total price for two groups is 18.
[ { "input": "3 4 1\n011", "output": "8" }, { "input": "4 7 2\n1101", "output": "18" }, { "input": "1 2 2\n1", "output": "2" }, { "input": "2 3 10\n01", "output": "13" }, { "input": "5 10 3\n11100", "output": "35" }, { "input": "10 2 2\n1111101111", "output": "20" }, { "input": "20 3 13\n01111110011111010101", "output": "120" }, { "input": "50 13 44\n11101110100110111100010110001111001001110010111011", "output": "1270" }, { "input": "100 1000 1000\n0000010100101100110100101111001111111111100101111100111011110001011110110111111010000000101000111000", "output": "100000" } ]
2,000
5,529,600
0
9,949
804
Find Amir
[ "constructive algorithms", "greedy", "math" ]
null
null
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* and *j* costs and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools.
Print single integer: the minimum cost of tickets needed to visit all schools.
[ "2\n", "10\n" ]
[ "0\n", "4\n" ]
In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
[ { "input": "2", "output": "0" }, { "input": "10", "output": "4" }, { "input": "43670", "output": "21834" }, { "input": "4217", "output": "2108" }, { "input": "17879", "output": "8939" }, { "input": "31809", "output": "15904" }, { "input": "40873", "output": "20436" }, { "input": "77859", "output": "38929" }, { "input": "53022", "output": "26510" }, { "input": "79227", "output": "39613" }, { "input": "100000", "output": "49999" }, { "input": "82801", "output": "41400" }, { "input": "5188", "output": "2593" }, { "input": "86539", "output": "43269" }, { "input": "12802", "output": "6400" }, { "input": "20289", "output": "10144" }, { "input": "32866", "output": "16432" }, { "input": "33377", "output": "16688" }, { "input": "31775", "output": "15887" }, { "input": "60397", "output": "30198" }, { "input": "100000", "output": "49999" }, { "input": "99999", "output": "49999" }, { "input": "99998", "output": "49998" }, { "input": "99997", "output": "49998" }, { "input": "99996", "output": "49997" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "1", "output": "0" }, { "input": "3", "output": "1" } ]
46
0
0
9,966
0
none
[ "none" ]
null
null
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with *n* vertices and *m* edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not. To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle. It is guaranteed that the graph contains no multiple edges and self-loops.
The first line contains two integers — the number of vertices *n* and the number of edges *m* of the graph (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=). Each of the following *m* lines contains a pair of integers *x* and *y*, that show that an edge exists between vertices *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself.
Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.
[ "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4\n", "6 5\n5 6\n4 6\n3 1\n5 1\n1 2\n" ]
[ "FHTAGN!", "NO" ]
Let us denote as a simple cycle a set of *v* vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., *v* - 1 and *v*, *v* and 1. A tree is a connected undirected graph consisting of *n* vertices and *n* - 1 edges (*n* &gt; 0). A rooted tree is a tree where one vertex is selected to be the root.
[ { "input": "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4", "output": "FHTAGN!" }, { "input": "6 5\n5 6\n4 6\n3 1\n5 1\n1 2", "output": "NO" }, { "input": "10 10\n4 10\n8 5\n2 8\n4 9\n9 3\n2 7\n10 6\n10 2\n9 8\n1 8", "output": "FHTAGN!" }, { "input": "5 4\n1 5\n1 3\n1 4\n3 2", "output": "NO" }, { "input": "12 12\n4 12\n4 7\n4 9\n7 2\n5 12\n2 1\n5 9\n8 6\n10 12\n2 5\n10 9\n12 3", "output": "NO" }, { "input": "12 15\n3 2\n11 12\n1 9\n2 1\n1 8\n9 6\n11 5\n9 5\n9 10\n11 3\n7 11\n5 6\n11 10\n4 6\n4 2", "output": "NO" }, { "input": "12 10\n1 11\n3 6\n5 7\n4 7\n6 8\n11 7\n3 12\n11 12\n7 9\n12 2", "output": "NO" }, { "input": "1 0", "output": "NO" }, { "input": "2 1\n1 2", "output": "NO" }, { "input": "3 1\n1 3", "output": "NO" }, { "input": "3 2\n1 2\n2 3", "output": "NO" }, { "input": "3 3\n1 2\n2 3\n3 1", "output": "FHTAGN!" }, { "input": "4 4\n1 2\n3 4\n4 1\n2 4", "output": "FHTAGN!" }, { "input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "NO" }, { "input": "2 0", "output": "NO" }, { "input": "3 0", "output": "NO" }, { "input": "100 0", "output": "NO" }, { "input": "100 1\n11 23", "output": "NO" }, { "input": "10 10\n5 7\n8 1\n10 3\n6 4\n10 6\n5 3\n5 6\n2 6\n4 3\n2 10", "output": "NO" }, { "input": "20 20\n9 10\n4 19\n9 20\n12 20\n1 15\n2 12\n19 10\n19 15\n4 10\n4 8\n8 9\n20 8\n6 2\n2 15\n7 19\n20 4\n3 16\n1 20\n9 1\n20 10", "output": "NO" }, { "input": "30 30\n17 6\n16 29\n16 13\n16 20\n29 26\n17 5\n27 28\n24 16\n7 18\n24 10\n1 27\n12 17\n27 30\n6 1\n3 30\n5 19\n18 13\n16 2\n30 1\n5 8\n14 16\n26 18\n7 19\n5 6\n23 14\n6 8\n23 8\n18 8\n18 3\n5 21", "output": "NO" }, { "input": "100 66\n41 14\n19 13\n70 43\n79 62\n9 62\n71 40\n53 86\n80 4\n34 33\n72 68\n40 96\n84 59\n36 77\n55 50\n40 3\n79 81\n3 43\n33 47\n22 98\n33 90\n56 49\n69 28\n73 30\n65 22\n98 20\n9 52\n54 20\n32 70\n51 80\n63 12\n21 48\n35 17\n48 87\n25 43\n65 80\n42 3\n86 35\n95 98\n43 59\n51 46\n66 37\n88 34\n32 47\n24 42\n21 44\n92 59\n81 6\n100 82\n85 6\n58 25\n66 6\n14 32\n59 85\n3 98\n44 4\n85 51\n69 41\n80 70\n81 24\n75 71\n93 9\n82 55\n70 46\n66 32\n77 58\n11 46", "output": "NO" }, { "input": "4 4\n1 2\n4 3\n2 3\n3 1", "output": "FHTAGN!" }, { "input": "5 5\n2 3\n2 4\n5 4\n4 1\n1 2", "output": "FHTAGN!" }, { "input": "10 10\n1 10\n5 9\n6 2\n8 9\n9 1\n5 4\n2 8\n1 3\n6 3\n4 1", "output": "NO" }, { "input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "NO" }, { "input": "4 3\n1 2\n2 3\n3 1", "output": "NO" }, { "input": "6 5\n1 2\n2 3\n3 1\n1 4\n1 5", "output": "NO" } ]
122
409,600
3
9,968
822
Crossword solving
[ "brute force", "implementation", "strings" ]
null
null
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple task. You are able to do it too, aren't you? Leha has two strings *s* and *t*. The hacker wants to change the string *s* at such way, that it can be found in *t* as a substring. All the changes should be the following: Leha chooses one position in the string *s* and replaces the symbol in this position with the question mark "?". The hacker is sure that the question mark in comparison can play the role of an arbitrary symbol. For example, if he gets string *s*="ab?b" as a result, it will appear in *t*="aabrbb" as a substring. Guaranteed that the length of the string *s* doesn't exceed the length of the string *t*. Help the hacker to replace in *s* as few symbols as possible so that the result of the replacements can be found in *t* as a substring. The symbol "?" should be considered equal to any other symbol.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=*m*<=≤<=1000) — the length of the string *s* and the length of the string *t* correspondingly. The second line contains *n* lowercase English letters — string *s*. The third line contains *m* lowercase English letters — string *t*.
In the first line print single integer *k* — the minimal number of symbols that need to be replaced. In the second line print *k* distinct integers denoting the positions of symbols in the string *s* which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering of the positions begins from one.
[ "3 5\nabc\nxaybz\n", "4 10\nabcd\nebceabazcd\n" ]
[ "2\n2 3 \n", "1\n2 \n" ]
none
[ { "input": "3 5\nabc\nxaybz", "output": "2\n2 3 " }, { "input": "4 10\nabcd\nebceabazcd", "output": "1\n2 " }, { "input": "1 1\na\na", "output": "0" }, { "input": "1 1\na\nz", "output": "1\n1 " }, { "input": "3 5\naaa\naaaaa", "output": "0" }, { "input": "3 5\naaa\naabaa", "output": "1\n3 " }, { "input": "5 5\ncoder\ncored", "output": "2\n3 5 " }, { "input": "1 1\nz\nz", "output": "0" }, { "input": "1 2\nf\nrt", "output": "1\n1 " }, { "input": "1 2\nf\nfg", "output": "0" }, { "input": "1 2\nf\ngf", "output": "0" }, { "input": "2 5\naa\naabaa", "output": "0" }, { "input": "2 5\naa\navaca", "output": "1\n2 " }, { "input": "3 5\naaa\nbbbbb", "output": "3\n1 2 3 " }, { "input": "3 5\naba\ncbcbc", "output": "2\n1 3 " }, { "input": "3 5\naba\nbbbbb", "output": "2\n1 3 " }, { "input": "3 5\naaa\naabvd", "output": "1\n3 " }, { "input": "3 5\nvvv\nbqavv", "output": "1\n1 " }, { "input": "10 100\nmpmmpmmmpm\nmppppppmppmmpmpppmpppmmpppmpppppmpppmmmppmpmpmmmpmmpmppmmpppppmpmppppmmppmpmppmmmmpmmppmmmpmpmmmpppp", "output": "2\n5 6 " }, { "input": "26 26\nabcdefghijklmnopqrstuvwxyz\nffffffffffffffffffffffffff", "output": "25\n1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 " }, { "input": "3 5\nabc\nxyzab", "output": "3\n1 2 3 " }, { "input": "4 4\nabcd\nxabc", "output": "4\n1 2 3 4 " }, { "input": "3 4\nabc\nabcd", "output": "0" }, { "input": "3 3\nabc\nxxa", "output": "3\n1 2 3 " }, { "input": "3 5\naab\nzfhka", "output": "3\n1 2 3 " }, { "input": "3 3\nabc\nxya", "output": "3\n1 2 3 " }, { "input": "3 3\nabc\ncab", "output": "3\n1 2 3 " }, { "input": "5 5\nabcde\nxxabc", "output": "5\n1 2 3 4 5 " }, { "input": "3 10\nass\nabcdefssss", "output": "1\n1 " }, { "input": "4 4\nabcd\neeab", "output": "4\n1 2 3 4 " }, { "input": "3 4\nabh\nbhaa", "output": "3\n1 2 3 " }, { "input": "2 3\nzb\naaz", "output": "2\n1 2 " }, { "input": "2 3\nab\ndda", "output": "2\n1 2 " }, { "input": "3 3\ncba\nbac", "output": "3\n1 2 3 " }, { "input": "3 4\nabc\nxxxa", "output": "3\n1 2 3 " }, { "input": "2 3\nab\nbbb", "output": "1\n1 " }, { "input": "10 15\nsdkjeaafww\nefjklffnkddkfey", "output": "9\n1 2 4 5 6 7 8 9 10 " }, { "input": "3 3\nabc\nzbc", "output": "1\n1 " }, { "input": "3 7\nabc\neeeeeab", "output": "3\n1 2 3 " }, { "input": "2 6\nab\nxyxbab", "output": "0" }, { "input": "4 7\nabcd\nzzzzabc", "output": "4\n1 2 3 4 " }, { "input": "3 5\nabc\nabzzz", "output": "1\n3 " }, { "input": "3 3\naaz\nzaa", "output": "2\n1 3 " }, { "input": "3 6\nabc\nxaybzd", "output": "2\n2 3 " }, { "input": "4 5\naaaa\naaaap", "output": "0" } ]
46
0
0
9,988
724
Dense Subsequence
[ "data structures", "greedy", "strings" ]
null
null
You are given a string *s*, consisting of lowercase English letters, and the integer *m*. One should choose some symbols from the given string so that any contiguous subsegment of length *m* has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves. Then one uses the chosen symbols to form a new string. All symbols from the chosen position should be used, but we are allowed to rearrange them in any order. Formally, we choose a subsequence of indices 1<=≤<=*i*1<=&lt;<=*i*2<=&lt;<=...<=&lt;<=*i**t*<=≤<=|*s*|. The selected sequence must meet the following condition: for every *j* such that 1<=≤<=*j*<=≤<=|*s*|<=-<=*m*<=+<=1, there must be at least one selected index that belongs to the segment [*j*,<= *j*<=+<=*m*<=-<=1], i.e. there should exist a *k* from 1 to *t*, such that *j*<=≤<=*i**k*<=≤<=*j*<=+<=*m*<=-<=1. Then we take any permutation *p* of the selected indices and form a new string *s**i**p*1*s**i**p*2... *s**i**p**t*. Find the lexicographically smallest string, that can be obtained using this procedure.
The first line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=100<=000). The second line contains the string *s* consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100<=000. It is also guaranteed that the number *m* doesn't exceed the length of the string *s*.
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
[ "3\ncbabc\n", "2\nabcab\n", "3\nbcabcbaccba\n" ]
[ "a\n", "aab\n", "aaabb\n" ]
In the first sample, one can choose the subsequence {3} and form a string "a". In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".
[ { "input": "3\ncbabc", "output": "a" }, { "input": "2\nabcab", "output": "aab" }, { "input": "3\nbcabcbaccba", "output": "aaabb" }, { "input": "5\nimmaydobun", "output": "ab" }, { "input": "5\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzknetdibv", "output": "aaaabbcccccddeeeeeefggggggghiijjjjjjkkllmmnnnnoppppqqrrrrrrrrsstttttu" }, { "input": "10\nefispvmzuutsrpxzfrykhabznxiyquwvhwhrksrgzodtuepfvamilfdynapzhzyhncorhzuewrrkcduvuhwsrprjrmgctnvrdtpj", "output": "aaabcccddddeeeffffgghhhhhhhiiijjkkklm" }, { "input": "20\nhlicqhxayiodyephxlfoetfketnaabpfegqcrjzlshkxfzjssvpvzhzylgowwovgxznzowvpklbwbzhwtkkaomjkenhpedmbmjic", "output": "aaaabbbbcccddeeeeeeffffg" }, { "input": "50\ntyhjolxuexoffdkdwimsjujorgeksyiyvvqecvhpjsuayqnibijtipuqhkulxpysotlmtrsgygpkdhkrtntwqzrpfckiscaphyhv", "output": "aab" }, { "input": "1\nbaaa", "output": "aaab" }, { "input": "5\nbbbbba", "output": "ab" }, { "input": "10\nbbabcbbaabcbcbcbaabbccaacccbbbcaaacabbbbaaaccbcccacbbccaccbbaacaccbabcaaaacaccacbaaccaaccbaacabbbaac", "output": "aaaaaaaaaaa" } ]
46
0
0
10,000
792
Divide by Three
[ "dp", "greedy", "math", "number theory" ]
null
null
A positive integer number *n* is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zeroes and is a multiple of 3. For example, 0, 99, 10110 are beautiful numbers, and 00, 03, 122 are not. Write a program which for the given *n* will find a beautiful number such that *n* can be transformed into this number by erasing as few digits as possible. You can erase an arbitraty set of digits. For example, they don't have to go one after another in the number *n*. If it's impossible to obtain a beautiful number, print -1. If there are multiple answers, print any of them.
The first line of input contains *n* — a positive integer number without leading zeroes (1<=≤<=*n*<=&lt;<=10100000).
Print one number — any beautiful number obtained by erasing as few as possible digits. If there is no answer, print <=-<=1.
[ "1033\n", "10\n", "11\n" ]
[ "33\n", "0\n", "-1\n" ]
In the first example it is enough to erase only the first digit to obtain a multiple of 3. But if we erase the first digit, then we obtain a number with a leading zero. So the minimum number of digits to be erased is two.
[ { "input": "1033", "output": "33" }, { "input": "10", "output": "0" }, { "input": "11", "output": "-1" }, { "input": "3", "output": "3" }, { "input": "1", "output": "-1" }, { "input": "117", "output": "117" }, { "input": "518", "output": "18" }, { "input": "327", "output": "327" }, { "input": "270461", "output": "70461" }, { "input": "609209", "output": "60909" }, { "input": "110930", "output": "930" }, { "input": "37616145150713688775", "output": "3616145150713688775" }, { "input": "98509135612114839419", "output": "9509135612114839419" }, { "input": "41674994051436988162", "output": "1674994051436988162" }, { "input": "82547062721736129804", "output": "82547062721736129804" }, { "input": "4902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798814", "output": "490501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798814" }, { "input": "1291007209605301446874998623691572528836214969878676835460982410817526074579818247646933326771899122", "output": "1291007209605301446874998623691572528836214969878676835460982410817526074579818247646933326771899122" }, { "input": "5388306043547446322173224045662327678394712363272776811399689704247387317165308057863239568137902157", "output": "538830603547446322173224045662327678394712363272776811399689704247387317165308057863239568137902157" }, { "input": "20000111", "output": "200001" }, { "input": "100222", "output": "1002" }, { "input": "202", "output": "0" }, { "input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000033", "output": "33" }, { "input": "101", "output": "0" }, { "input": "1000000222", "output": "10000002" }, { "input": "1001", "output": "0" }, { "input": "205", "output": "0" }, { "input": "102211", "output": "10221" }, { "input": "100000002022", "output": "1000000002" }, { "input": "20203", "output": "3" }, { "input": "1002001", "output": "100200" }, { "input": "10002223", "output": "100023" }, { "input": "1002223", "output": "10023" }, { "input": "100000231", "output": "10000023" }, { "input": "220", "output": "0" }, { "input": "322", "output": "3" }, { "input": "100000222", "output": "1000002" }, { "input": "10033", "output": "33" }, { "input": "2003302", "output": "330" }, { "input": "10011001", "output": "1001001" }, { "input": "20000000011001111", "output": "200000000001111" }, { "input": "100000000", "output": "0" }, { "input": "1000", "output": "0" }, { "input": "200000000000000000000000000008", "output": "0" }, { "input": "1000000000000222", "output": "10000000000002" }, { "input": "100000000000000000222", "output": "1000000000000000002" }, { "input": "29512", "output": "2952" }, { "input": "88888888888888", "output": "888888888888" }, { "input": "100000000000222", "output": "1000000000002" }, { "input": "11000000", "output": "0" }, { "input": "2200", "output": "0" }, { "input": "10000555", "output": "100005" }, { "input": "1000222", "output": "10002" }, { "input": "10021", "output": "1002" }, { "input": "223", "output": "3" }, { "input": "1013", "output": "3" }, { "input": "100020001", "output": "10002000" }, { "input": "20000000000000000000932", "output": "93" }, { "input": "1010", "output": "0" }, { "input": "2000000002222", "output": "20000000022" }, { "input": "10213", "output": "1023" }, { "input": "109111", "output": "10911" }, { "input": "1010101010", "output": "10001010" }, { "input": "300055", "output": "3000" }, { "input": "200200", "output": "0" }, { "input": "202222", "output": "2022" }, { "input": "4000888", "output": "40008" }, { "input": "200000111", "output": "2000001" }, { "input": "2000000111", "output": "20000001" }, { "input": "1000000", "output": "0" }, { "input": "1003301", "output": "330" }, { "input": "100001", "output": "0" }, { "input": "40000000000000000000888", "output": "400000000000000000008" }, { "input": "100000", "output": "0" }, { "input": "4000000888", "output": "40000008" }, { "input": "334733", "output": "3333" }, { "input": "1000002220", "output": "10000020" }, { "input": "100321", "output": "10032" }, { "input": "101111", "output": "1011" }, { "input": "100000000222", "output": "1000000002" }, { "input": "10001", "output": "0" }, { "input": "7", "output": "-1" }, { "input": "2000000000111", "output": "20000000001" }, { "input": "100000001", "output": "0" }, { "input": "10000000000222", "output": "100000000002" }, { "input": "200000000000000111", "output": "2000000000000001" }, { "input": "404044", "output": "40044" }, { "input": "30202", "output": "300" }, { "input": "20000000000000000111", "output": "200000000000000001" }, { "input": "707", "output": "0" }, { "input": "20000300000000003000050000003", "output": "30000000000300000000003" }, { "input": "400000888", "output": "4000008" }, { "input": "2888", "output": "888" }, { "input": "200111", "output": "2001" }, { "input": "10000000888", "output": "100000008" }, { "input": "40000888", "output": "400008" }, { "input": "40404044", "output": "400044" }, { "input": "5500000000", "output": "0" }, { "input": "100012", "output": "10002" }, { "input": "1000007", "output": "0" }, { "input": "200093", "output": "93" }, { "input": "10000000222", "output": "100000002" }, { "input": "20000000002", "output": "0" }, { "input": "74333", "output": "333" }, { "input": "200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008", "output": "0" }, { "input": "10000000111", "output": "1000000011" }, { "input": "100007", "output": "0" }, { "input": "20000006711", "output": "200000061" }, { "input": "8059", "output": "9" }, { "input": "8008", "output": "0" }, { "input": "88", "output": "-1" }, { "input": "2002", "output": "0" }, { "input": "2000111", "output": "20001" }, { "input": "100000000100000002", "output": "10000000000000002" }, { "input": "1000000000000000000000000000000000", "output": "0" }, { "input": "10000000000000000222", "output": "100000000000000002" }, { "input": "1000001", "output": "0" }, { "input": "200000000000111", "output": "2000000000001" }, { "input": "2000000002", "output": "0" }, { "input": "2010000100001", "output": "10000100001" }, { "input": "200330", "output": "330" }, { "input": "10000222", "output": "100002" }, { "input": "2005", "output": "0" }, { "input": "100000000000822", "output": "1000000000002" }, { "input": "10000000000000000000000", "output": "0" }, { "input": "7046", "output": "6" }, { "input": "4000117", "output": "400017" }, { "input": "971", "output": "9" }, { "input": "404", "output": "0" }, { "input": "5", "output": "-1" }, { "input": "164", "output": "6" }, { "input": "140", "output": "0" }, { "input": "74", "output": "-1" }, { "input": "2058232", "output": "20232" }, { "input": "4", "output": "-1" }, { "input": "20206", "output": "6" }, { "input": "103310", "output": "330" }, { "input": "100", "output": "0" }, { "input": "417179", "output": "7179" }, { "input": "70558", "output": "558" }, { "input": "298", "output": "9" }, { "input": "7003", "output": "3" }, { "input": "2212", "output": "222" }, { "input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "0" }, { "input": "2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002", "output": "0" }, { "input": "1002200", "output": "100200" }, { "input": "1222", "output": "222" }, { "input": "101200100", "output": "10100100" }, { "input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003", "output": "3" }, { "input": "20020201", "output": "2002020" }, { "input": "12122", "output": "1122" }, { "input": "20200", "output": "0" }, { "input": "2", "output": "-1" }, { "input": "1000000000000258", "output": "10000000000008" } ]
140
0
0
10,018
935
Fafa and the Gates
[ "implementation" ]
null
null
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin. The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation *x*<==<=*y*). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0,<=0), (1,<=1), (2,<=2), ...). The wall and the gates do not belong to any of the kingdoms. Fafa is at the gate at position (0,<=0) and he wants to walk around in the two kingdoms. He knows the sequence *S* of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (*x*,<=*y*) to (*x*,<=*y*<=+<=1)) and 'R' (move one step right, from (*x*,<=*y*) to (*x*<=+<=1,<=*y*)). Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence *S*. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0,<=0), i. e. he is initially on the side he needs.
The first line of the input contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of moves in the walking sequence. The second line contains a string *S* of length *n* consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence *S* in order from left to right.
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence *S*.
[ "1\nU\n", "6\nRURUUR\n", "7\nURRRUUU\n" ]
[ "0\n", "1\n", "2\n" ]
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
[ { "input": "1\nU", "output": "0" }, { "input": "6\nRURUUR", "output": "1" }, { "input": "7\nURRRUUU", "output": "2" }, { "input": "100\nRUURUURRUURUUUUURRUUURRRRUURRURRURRRRUUUUUURRUURRRRURUUURUURURRRRRURUURRUURUURRUUURUUUUUURRUUUURUUUR", "output": "3" }, { "input": "7\nURURRUR", "output": "1" }, { "input": "15\nRUURRRRURRUUUUU", "output": "3" }, { "input": "6\nUURRRU", "output": "1" }, { "input": "7\nRRRRRRR", "output": "0" }, { "input": "2\nUR", "output": "0" }, { "input": "2\nUU", "output": "0" } ]
46
0
0
10,032
901
GCD of Polynomials
[ "constructive algorithms", "math" ]
null
null
Suppose you have two polynomials and . Then polynomial can be uniquely represented in the following way: This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, denotes the degree of polynomial *P*(*x*). is called the remainder of division of polynomial by polynomial , it is also denoted as . Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials . If the polynomial is zero, the result is , otherwise the result is the value the algorithm returns for pair . On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question. You are given an integer *n*. You have to build two polynomials with degrees not greater than *n*, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of *x*) are equal to one, and the described Euclid's algorithm performs exactly *n* steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair to pair .
You are given a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of steps of the algorithm you need to reach.
Print two polynomials in the following format. In the first line print a single integer *m* (0<=≤<=*m*<=≤<=*n*) — the degree of the polynomial. In the second line print *m*<=+<=1 integers between <=-<=1 and 1 — the coefficients of the polynomial, from constant to leading. The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly *n* steps when called using these polynomials. If there is no answer for the given *n*, print -1. If there are multiple answer, print any of them.
[ "1\n", "2\n" ]
[ "1\n0 1\n0\n1\n", "2\n-1 0 1\n1\n0 1\n" ]
In the second example you can print polynomials *x*<sup class="upper-index">2</sup> - 1 and *x*. The sequence of transitions is There are two steps in it.
[ { "input": "1", "output": "1\n0 1\n0\n1" }, { "input": "2", "output": "2\n-1 0 1\n1\n0 1" }, { "input": "3", "output": "3\n0 0 0 1\n2\n-1 0 1" }, { "input": "4", "output": "4\n1 0 -1 0 1\n3\n0 0 0 1" }, { "input": "5", "output": "5\n0 1 0 0 0 1\n4\n1 0 -1 0 1" }, { "input": "6", "output": "6\n1 0 0 0 1 0 1\n5\n0 1 0 0 0 1" }, { "input": "7", "output": "7\n0 0 0 0 0 0 0 1\n6\n1 0 0 0 1 0 1" }, { "input": "8", "output": "8\n-1 0 0 0 -1 0 -1 0 1\n7\n0 0 0 0 0 0 0 1" }, { "input": "9", "output": "9\n0 -1 0 0 0 -1 0 0 0 1\n8\n-1 0 0 0 -1 0 -1 0 1" }, { "input": "10", "output": "10\n1 0 -1 0 1 0 0 0 -1 0 1\n9\n0 -1 0 0 0 -1 0 0 0 1" }, { "input": "11", "output": "11\n0 0 0 -1 0 0 0 0 0 0 0 1\n10\n1 0 -1 0 1 0 0 0 -1 0 1" }, { "input": "12", "output": "12\n1 0 -1 0 0 0 0 0 -1 0 1 0 1\n11\n0 0 0 -1 0 0 0 0 0 0 0 1" }, { "input": "13", "output": "13\n0 1 0 0 0 0 0 0 0 -1 0 0 0 1\n12\n1 0 -1 0 0 0 0 0 -1 0 1 0 1" }, { "input": "14", "output": "14\n1 0 0 0 0 0 0 0 -1 0 0 0 1 0 1\n13\n0 1 0 0 0 0 0 0 0 -1 0 0 0 1" }, { "input": "15", "output": "15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n14\n1 0 0 0 0 0 0 0 -1 0 0 0 1 0 1" }, { "input": "16", "output": "16\n-1 0 0 0 0 0 0 0 1 0 0 0 -1 0 -1 0 1\n15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1" }, { "input": "17", "output": "17\n0 -1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 1\n16\n-1 0 0 0 0 0 0 0 1 0 0 0 -1 0 -1 0 1" }, { "input": "18", "output": "18\n1 0 -1 0 0 0 0 0 -1 0 1 0 1 0 0 0 -1 0 1\n17\n0 -1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 1" }, { "input": "19", "output": "19\n0 0 0 -1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1\n18\n1 0 -1 0 0 0 0 0 -1 0 1 0 1 0 0 0 -1 0 1" }, { "input": "20", "output": "20\n-1 0 1 0 -1 0 0 0 1 0 -1 0 0 0 0 0 1 0 -1 0 1\n19\n0 0 0 -1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1" }, { "input": "21", "output": "21\n0 -1 0 0 0 -1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1\n20\n-1 0 1 0 -1 0 0 0 1 0 -1 0 0 0 0 0 1 0 -1 0 1" }, { "input": "22", "output": "22\n-1 0 0 0 -1 0 -1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1\n21\n0 -1 0 0 0 -1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1" }, { "input": "23", "output": "23\n0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n22\n-1 0 0 0 -1 0 -1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1" }, { "input": "24", "output": "24\n-1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 1\n23\n0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1" }, { "input": "25", "output": "25\n0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1\n24\n-1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 1" }, { "input": "26", "output": "26\n1 0 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 -1 0 0 0 -1 0 1\n25\n0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1" }, { "input": "27", "output": "27\n0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1\n26\n1 0 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 -1 0 0 0 -1 0 1" }, { "input": "28", "output": "28\n1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 0 0 0 0 -1 0 1 0 1\n27\n0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1" }, { "input": "29", "output": "29\n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 1\n28\n1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 0 0 0 0 -1 0 1 0 1" }, { "input": "30", "output": "30\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 1 0 1\n29\n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 1" }, { "input": "31", "output": "31\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n30\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 1 0 1" }, { "input": "32", "output": "32\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 -1 0 -1 0 1\n31\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1" }, { "input": "33", "output": "33\n0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 1\n32\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 -1 0 -1 0 1" }, { "input": "34", "output": "34\n1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 0 0 0 0 -1 0 1 0 1 0 0 0 -1 0 1\n33\n0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 1" }, { "input": "35", "output": "35\n0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1\n34\n1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 0 0 0 0 -1 0 1 0 1 0 0 0 -1 0 1" }, { "input": "36", "output": "36\n-1 0 1 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 -1 0 1 0 0 0 1 0 -1 0 0 0 0 0 1 0 -1 0 1\n35\n0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1" }, { "input": "37", "output": "37\n0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1\n36\n-1 0 1 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 -1 0 1 0 0 0 1 0 -1 0 0 0 0 0 1 0 -1 0 1" }, { "input": "38", "output": "38\n-1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1\n37\n0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1" }, { "input": "39", "output": "39\n0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n38\n-1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1" }, { "input": "40", "output": "40\n1 0 0 0 1 0 1 0 -1 0 0 0 0 0 0 0 -1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 -1 0 1\n39\n0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1" }, { "input": "41", "output": "41\n0 1 0 0 0 1 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 0 0 1\n40\n1 0 0 0 1 0 1 0 -1 0 0 0 0 0 0 0 -1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 -1 0 1" }, { "input": "42", "output": "42\n-1 0 1 0 -1 0 0 0 1 0 -1 0 0 0 0 0 1 0 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 -1 0 1 0 0 0 -1 0 1\n41\n0 1 0 0 0 1 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 0 0 1" }, { "input": "43", "output": "43\n0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 1\n42\n-1 0 1 0 -1 0 0 0 1 0 -1 0 0 0 0 0 1 0 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 -1 0 1 0 0 0 -1 0 1" }, { "input": "44", "output": "44\n-1 0 1 0 0 0 0 0 1 0 -1 0 -1 0 0 0 1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 -1 0 0 0 0 0 -1 0 1 0 1\n43\n0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 1" }, { "input": "45", "output": "45\n0 -1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 1\n44\n-1 0 1 0 0 0 0 0 1 0 -1 0 -1 0 0 0 1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 -1 0 0 0 0 0 -1 0 1 0 1" }, { "input": "46", "output": "46\n-1 0 0 0 0 0 0 0 1 0 0 0 -1 0 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 1 0 1\n45\n0 -1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 1" }, { "input": "47", "output": "47\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n46\n-1 0 0 0 0 0 0 0 1 0 0 0 -1 0 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 1 0 1" }, { "input": "48", "output": "48\n-1 0 0 0 0 0 0 0 1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 1 0 1 0 1\n47\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1" }, { "input": "49", "output": "49\n0 -1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 1 0 0 0 1\n48\n-1 0 0 0 0 0 0 0 1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 1 0 1 0 1" }, { "input": "50", "output": "50\n1 0 -1 0 0 0 0 0 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 0 0 0 0 1 0 -1 0 -1 0 0 0 -1 0 1\n49\n0 -1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 1 0 0 0 1" }, { "input": "51", "output": "51\n0 0 0 -1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 1\n50\n1 0 -1 0 0 0 0 0 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 0 0 0 0 1 0 -1 0 -1 0 0 0 -1 0 1" }, { "input": "52", "output": "52\n-1 0 1 0 -1 0 0 0 1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 -1 0 1 0 0 0 -1 0 1 0 0 0 0 0 1 0 -1 0 1\n51\n0 0 0 -1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 1" }, { "input": "53", "output": "53\n0 -1 0 0 0 -1 0 0 0 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 0 0 -1 0 0 0 -1 0 -1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 -1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1\n149\n0 1 0 0 0 1 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 ..." } ]
124
0
3
10,094
630
Challenge Pennants
[ "combinatorics", "math" ]
null
null
Because of budget cuts one IT company established new non-financial reward system instead of bonuses. Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature" pennant on his table. Because of the limited budget of the new reward system only 5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought. In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of the earlier awarded "I suggested a new feature" pennants is passed on to his table. One man can have several pennants of one type and of course he can have pennants of both types on his table. There are *n* tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
The only line of the input contains one integer *n* (1<=≤<=*n*<=≤<=500) — the number of tables in the IT company.
Output one integer — the amount of ways to place the pennants on *n* tables.
[ "2\n" ]
[ "24" ]
none
[ { "input": "2", "output": "24" }, { "input": "1", "output": "1" }, { "input": "3", "output": "210" }, { "input": "4", "output": "1120" }, { "input": "5", "output": "4410" }, { "input": "6", "output": "14112" }, { "input": "7", "output": "38808" }, { "input": "12", "output": "1589952" }, { "input": "28", "output": "817586560" }, { "input": "43", "output": "21766594410" }, { "input": "139", "output": "212332162372330" }, { "input": "321", "output": "163013183025830865" }, { "input": "100", "output": "15789964684000" }, { "input": "498", "output": "5392730685240975000" }, { "input": "500", "output": "5567867859752100000" } ]
30
0
0
10,096
427
Match & Catch
[ "dp", "string suffix structures", "strings" ]
null
null
Police headquarter is monitoring signal on different frequency levels. They have got two suspiciously encoded strings *s*1 and *s*2 from two different frequencies as signals. They are suspecting that these two strings are from two different criminals and they are planning to do some evil task. Now they are trying to find a common substring of minimum length between these two strings. The substring must occur only once in the first string, and also it must occur only once in the second string. Given two strings *s*1 and *s*2 consist of lowercase Latin letters, find the smallest (by length) common substring *p* of both *s*1 and *s*2, where *p* is a unique substring in *s*1 and also in *s*2. See notes for formal definition of substring and uniqueness.
The first line of input contains *s*1 and the second line contains *s*2 (1<=≤<=|*s*1|,<=|*s*2|<=≤<=5000). Both strings consist of lowercase Latin letters.
Print the length of the smallest common unique substring of *s*1 and *s*2. If there are no common unique substrings of *s*1 and *s*2 print -1.
[ "apple\npepperoni\n", "lover\ndriver\n", "bidhan\nroy\n", "testsetses\nteeptes\n" ]
[ "2\n", "1\n", "-1\n", "3\n" ]
Imagine we have string *a* = *a*<sub class="lower-index">1</sub>*a*<sub class="lower-index">2</sub>*a*<sub class="lower-index">3</sub>...*a*<sub class="lower-index">|*a*|</sub>, where |*a*| is the length of string *a*, and *a*<sub class="lower-index">*i*</sub> is the *i*<sup class="upper-index">*th*</sup> letter of the string. We will call string *a*<sub class="lower-index">*l*</sub>*a*<sub class="lower-index">*l* + 1</sub>*a*<sub class="lower-index">*l* + 2</sub>...*a*<sub class="lower-index">*r*</sub> (1 ≤ *l* ≤ *r* ≤ |*a*|) the substring [*l*, *r*] of the string *a*. The substring [*l*, *r*] is unique in *a* if and only if there is no pair *l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index">1</sub> such that *l*<sub class="lower-index">1</sub> ≠ *l* and the substring [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index">1</sub>] is equal to the substring [*l*, *r*] in *a*.
[]
1,000
10,342,400
0
10,150
174
File List
[ "dp", "greedy", "implementation" ]
null
null
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where: - name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters; - ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters. For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not. Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string. Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
The input data consists of a single string *s*, its length is from 1 to 4·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
In the first line print "YES" (without the quotes), if it is possible to divide *s* into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in *s*. The required partition can contain the same file names. If there are multiple solutions, print any of them. If the solution does not exist, then print in a single line "NO" (without the quotes).
[ "read.meexample.txtb.cpp\n", "version.infontldrcontestdata.zip\n" ]
[ "YES\nread.m\neexample.t\nxtb.cpp\n", "NO\n" ]
none
[ { "input": "read.meexample.txtb.cpp", "output": "YES\nread.m\neexample.t\nxtb.cpp" }, { "input": "version.infontldrcontestdata.zip", "output": "NO" }, { "input": "thisis.text.txt", "output": "YES\nthisis.t\next.txt" }, { "input": "oops.t", "output": "YES\noops.t" }, { "input": "thisislongfilename", "output": "NO" }, { "input": "double..dot", "output": "NO" }, { "input": "one.one.one.one.one.one.one.one.one.one", "output": "YES\none.o\nne.o\nne.o\nne.o\nne.o\nne.o\nne.o\nne.o\nne.one" }, { "input": ".", "output": "NO" }, { "input": "z", "output": "NO" }, { "input": "a.", "output": "NO" }, { "input": ".a", "output": "NO" }, { "input": "za", "output": "NO" }, { "input": "..", "output": "NO" }, { "input": "xlq", "output": "NO" }, { "input": ".r.", "output": "NO" }, { "input": "ulmc", "output": "NO" }, { "input": "nja.", "output": "NO" }, { "input": "t..kz", "output": "NO" }, { "input": "twaha", "output": "NO" }, { "input": "m..dw.", "output": "NO" }, { "input": "utsvfg.", "output": "NO" }, { "input": ".we.voae", "output": "NO" }, { "input": "kw.gkcxk.", "output": "NO" }, { "input": ".c.v.hpehh", "output": "NO" }, { "input": "....e.afx.h", "output": "NO" }, { "input": "akymwh", "output": "NO" }, { "input": "jx.lqv.", "output": "NO" }, { "input": "qkwtq.zw", "output": "YES\nqkwtq.zw" }, { "input": "yxwvlk..b", "output": "NO" }, { "input": "ph..qlr.pt", "output": "NO" }, { "input": "cab.ab.bac", "output": "YES\ncab.a\nb.bac" }, { "input": "badaba.ae", "output": "YES\nbadaba.ae" }, { "input": "badabaca.mor", "output": "YES\nbadabaca.mor" }, { "input": "bae.a", "output": "YES\nbae.a" }, { "input": "b.baba.ebpbac.iabaeabac.abab.adabacaba.ahcggibij.adaacab.ebaba.aa.abacaba.dacabada.daqjcpc.jadab.dab", "output": "YES\nb.b\naba.e\nbpbac.i\nabaeabac.a\nbab.a\ndabacaba.a\nhcggibij.a\ndaacab.e\nbaba.a\na.a\nbacaba.d\nacabada.d\naqjcpc.j\nadab.dab" }, { "input": ".ab", "output": "NO" }, { "input": "aa.aa.aaaabbbbccc.ddd.ee", "output": "YES\naa.a\na.aaa\nabbbbccc.d\ndd.ee" }, { "input": "a.aaaa", "output": "NO" }, { "input": "aaaaread.meexample.txtb.cpp", "output": "YES\naaaaread.m\neexample.t\nxtb.cpp" }, { "input": "abcdabcd.a", "output": "YES\nabcdabcd.a" }, { "input": "qwertyuio.qwe", "output": "NO" }, { "input": "asd.", "output": "NO" }, { "input": "aaaaaaaa.", "output": "NO" }, { "input": "a.txtaaaaaaaaa.txt", "output": "NO" }, { "input": ".abcde.cpp", "output": "NO" }, { "input": ".abc.cpp", "output": "NO" }, { "input": "abcdefgh.aaaabcdefgh.bbb", "output": "YES\nabcdefgh.aaa\nabcdefgh.bbb" }, { "input": "filename.exe", "output": "YES\nfilename.exe" }, { "input": ".abcd.cpp", "output": "NO" }, { "input": "abc.bcdabcdabcd.abc", "output": "YES\nabc.bcd\nabcdabcd.abc" }, { "input": "abc.abcde", "output": "NO" }, { "input": "a.cp", "output": "YES\na.cp" }, { "input": "a.b.c", "output": "NO" }, { "input": ".ha", "output": "NO" }, { "input": "a.a.a.a", "output": "NO" }, { "input": "a.a.a", "output": "NO" }, { "input": "qwertyui.cp", "output": "YES\nqwertyui.cp" }, { "input": "ss.aaaaaaaaaaaa.aa", "output": "NO" }, { "input": "name.extnamename.ext", "output": "YES\nname.ext\nnamename.ext" }, { "input": ".aaaa.aaa", "output": "NO" }, { "input": "aaaaaaaaaaaaaaaaaaaa.a", "output": "NO" }, { "input": ".filena.exe", "output": "NO" }, { "input": "a.aaaaaaaaaaa.a", "output": "YES\na.aaa\naaaaaaaa.a" }, { "input": ".aa.w", "output": "NO" } ]
592
10,240,000
3
10,168
95
Hockey
[ "implementation", "strings" ]
A. Hockey
2
256
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name *w* and the collection of forbidden substrings *s*1,<=*s*2,<=...,<=*s**n*. All those strings consist of uppercase and lowercase Latin letters. String *w* has the length of |*w*|, its characters are numbered from 1 to |*w*|. First Petya should find all the occurrences of forbidden substrings in the *w* string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal. After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position *i* should be replaced by any other one if for position *i* in string *w* there exist pair of indices *l*,<=*r* (1<=≤<=*l*<=≤<=*i*<=≤<=*r*<=≤<=|*w*|) such that substring *w*[*l* ... *r*] is contained in the collection *s*1,<=*s*2,<=...,<=*s**n*, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring. Letter *letter* (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the *letter* occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically. Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of forbidden substrings in the collection. Next *n* lines contain these substrings. The next line contains string *w*. All those *n*<=+<=1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter *letter*.
Output the only line — Petya's resulting string with the maximum number of letters *letter*. If there are several answers then output the one that comes first lexicographically. The lexicographical comparison is performed by the standard &lt; operator in modern programming languages. The line *a* is lexicographically smaller than the line *b*, if *a* is a prefix of *b*, or there exists such an *i* (1<=≤<=*i*<=≤<=|*a*|), that *a**i*<=&lt;<=*b**i*, and for any *j* (1<=≤<=*j*<=&lt;<=*i*) *a**j*<==<=*b**j*. |*a*| stands for the length of string *a*.
[ "3\nbers\nucky\nelu\nPetrLoveLuckyNumbers\nt\n", "4\nhello\nparty\nabefglghjdhfgj\nIVan\npetrsmatchwin\na\n", "2\naCa\ncba\nabAcaba\nc\n" ]
[ "PetrLovtTttttNumtttt\n", "petrsmatchwin\n", "abCacba\n" ]
none
[ { "input": "3\nbers\nucky\nelu\nPetrLoveLuckyNumbers\nt", "output": "PetrLovtTttttNumtttt" }, { "input": "4\nhello\nparty\nabefglghjdhfgj\nIVan\npetrsmatchwin\na", "output": "petrsmatchwin" }, { "input": "2\naCa\ncba\nabAcaba\nc", "output": "abCacba" }, { "input": "3\nlol\nhello\neho\nPetrUnited\nt", "output": "PetrUnited" }, { "input": "2\ntrsd\ndream\nPetrsDreamOh\ny", "output": "PeyyyYyyyyOh" }, { "input": "1\nPetrsDreamOh\nPetrsDreamOh\nh", "output": "HhhhhHhhhhHa" }, { "input": "3\netr\ned\nied\nPetrUnited\nd", "output": "PdddUnitda" }, { "input": "3\netr\ned\nied\nPetrUnited\nz", "output": "PzzzUnitzz" }, { "input": "3\nab\nBa\naB\nABBA\na", "output": "BAAB" }, { "input": "3\nab\nBa\naB\nABBAC\nb", "output": "BAABC" }, { "input": "7\na\nb\ng\nk\ne\nt\nt\nA\na", "output": "B" }, { "input": "4\nEfron\nKeyt\ncesho\ncool\nCodeForcesHockeyTeam\np", "output": "CodeForpppPpcpppPeam" }, { "input": "4\nEfron\nKeyt\ncesho\ncool\nCodeForcesOldHockeyNewTeam\np", "output": "CodeForcesOldHockeyNewTeam" }, { "input": "2\nA\nB\nabababBabaBBaBBBBAaaaAAAAA\na", "output": "bababaAbabAAbAAAABbbbBBBBB" }, { "input": "7\nS\nT\ng\ni\nO\nr\nq\nkljpfP\nv", "output": "kljpfP" }, { "input": "47\nV\nS\ng\nr\nC\nR\nB\nb\nl\nW\nJ\ni\nU\nn\nq\nq\nj\nL\nR\nu\nQ\nC\nf\nC\nU\nu\nx\nh\nq\nE\nY\nu\nK\nt\nM\nU\nA\nA\ns\ni\nV\nT\nj\nb\nk\nW\nN\nNlVwRlWzQQWoCI\nz", "output": "ZzZzZzZzZZZoZZ" }, { "input": "47\njw\nL\nxIp\nW\nI\naI\nEp\nylG\nNe\nEglZ\noYkyo\nwDuZK\nDVh\nuoAoF\nGWj\nt\nP\nuNQz\nbPSg\neqru\nxvll\nO\nmb\nCM\nwnmvv\nYpFsq\nFYID\nc\nr\nrhbl\nYseyB\nRGcRj\nhDtz\nW\nQlQWB\nY\nftSl\nyPlAd\nLPgVw\nEIGOF\nTQ\nQrFcr\nspu\nK\nIJ\nfXUd\nGhpV\nDxUhKXELSLIiJMIOsbrpPQPXFwH\nw", "output": "DxUhWXEWSWWwWMWWsbwwWQWXFaH" }, { "input": "74\nPjc\nZcOWk\nM\nyMyp\ncH\nTzmX\nA\nXgl\nKVB\nbljv\nIH\nu\nnu\nLdahF\nt\nO\nSv\nuzFT\nzfNd\nUM\nbXR\nUQbXk\nAA\ngVmH\nng\nF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nxZ\nbl\nur\nkf\ndf\nLS\nUW\nMy\nhR\nsh\nNh\nog\nCW\nor\nzo\nrO\nao\nXH\nDq\nKa\nlL\nYQ\nOh\nRZ\nAx\nta\nko\nDn\nNg\nNy\nDB\nYD\njO\nAp\nFT\noB\nNc\nwB\nHO\neW\nAc\nDr\nMt\nDf\nbF\nFP\nRa\nnF\nhF\nXC\nnG\nan\nZY\nuB\nHP\nOR\nKN\nUv\nLe\nIj\nlH\nVw\njb\nXn\nqu\nJo\nzL\nKW\nLS\naV\nLs\nBX\nMY\noK\nfh\ngP\nTB\npBWBEkqznLlZykhmPrfidzWbQMNDdBaDLykOfdvOZjKoUxCqKwJdGuhseuxaYcVyAGTSTwXYmKweRMUdbyfxssSNGLSAhckIknDj\nd", "output": "pBDDDkqznDdDdkhmPrfiddDdQDDDaDaDLydDfdvOZjDdUdDqDdJdGuhseuxaYcVdDGTSTwXYmDdeRMUadyfxssSDDDDAhckIddDj" }, { "input": "3\na\nA\na\nA\na", "output": "B" }, { "input": "3\na\nA\na\nA\nb", "output": "B" }, { "input": "4\na\nA\ni\nA\nPetyaIsVeryCoolGuy\np", "output": "PetypPsVeryCoolGuy" }, { "input": "3\njap\nthd\ndshipssinceW\nJapanisexperiencingitsgreatesthardshipssinceWorldWarIIthardshipssinceWorldWarIItesthardshixper\nc", "output": "CccanisexperiencingitsgreatestharcccccccccacCorldWarIItharcccccccccacCorldWarIItesthardshixper" }, { "input": "3\njap\nthd\ndshipssinceW\nJapanisexperiencingitsgreatesthardshipssinceWorldWarIIthardshipssinceWorldWarIItesthardshixper\na", "output": "AbaanisexperiencingitsgreatestharaaaaaaaaaaaAorldWarIItharaaaaaaaaaaaAorldWarIItesthardshixper" }, { "input": "7\na\nh\nu\np\nfgh\nwyz\ndefghijkl\nabcdefghijklmnopqrstuvwxyz\na", "output": "bbcaaaaaaaaamnoaqrstavwxyz" }, { "input": "9\na\nh\nu\np\nz\nfgh\nwyz\ndefghijkl\nghijklmnopqrstu\nabcdefghijklmnopqrstuvwxyz\na", "output": "bbcaaaaaaaaaaaaaaaaaavwxya" }, { "input": "3\nab\nBa\naB\nABBA\nl", "output": "LLLL" } ]
216
0
0
10,170
271
Prime Matrix
[ "binary search", "brute force", "math", "number theory" ]
null
null
You've got an *n*<=×<=*m* matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors: itself and number one. For example, numbers 2, 3, 5 are prime and numbers 1, 4, 6 are not. A matrix is prime if at least one of the two following conditions fulfills: - the matrix has a row with prime numbers only; - the matrix has a column with prime numbers only; Your task is to count the minimum number of moves needed to get a prime matrix from the one you've got.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=500) — the number of rows and columns in the matrix, correspondingly. Each of the following *n* lines contains *m* integers — the initial matrix. All matrix elements are positive integers. All numbers in the initial matrix do not exceed 105. The numbers in the lines are separated by single spaces.
Print a single integer — the minimum number of moves needed to get a prime matrix from the one you've got. If you've got a prime matrix, print 0.
[ "3 3\n1 2 3\n5 6 1\n4 4 1\n", "2 3\n4 8 8\n9 2 9\n", "2 2\n1 3\n4 2\n" ]
[ "1\n", "3\n", "0\n" ]
In the first sample you need to increase number 1 in cell (1, 1). Thus, the first row will consist of prime numbers: 2, 2, 3. In the second sample you need to increase number 8 in cell (1, 2) three times. Thus, the second column will consist of prime numbers: 11, 2. In the third sample you don't have to do anything as the second column already consists of prime numbers: 3, 2.
[ { "input": "3 3\n1 2 3\n5 6 1\n4 4 1", "output": "1" }, { "input": "2 3\n4 8 8\n9 2 9", "output": "3" }, { "input": "2 2\n1 3\n4 2", "output": "0" }, { "input": "1 1\n14", "output": "3" }, { "input": "5 3\n2 14 8\n8 8 2\n8 10 10\n1 2 1\n100 100 8", "output": "2" }, { "input": "6 5\n8 8 8 8 20\n13 8 16 13 9\n11 5 3 14 18\n13 8 6 18 6\n6 8 9 14 7\n2 14 14 9 3", "output": "4" }, { "input": "5 7\n9 5 3 9 2 8 2\n15 7 9 8 18 4 6\n2 9 14 3 6 13 18\n4 13 3 14 11 13 8\n14 10 1 14 18 5 6", "output": "3" }, { "input": "3 3\n1 7 6\n4 6 2\n3 3 3", "output": "0" }, { "input": "1 5\n14 14 8 14 14", "output": "3" }, { "input": "10 10\n20 53 6 97 74 12 92 48 13 97\n96 47 32 75 21 69 75 95 54 1\n97 36 1 41 87 1 23 39 44 27\n97 73 1 1 26 6 3 48 69 5\n70 93 42 35 5 12 22 33 29 13\n96 8 13 69 40 91 5 19 16 33\n61 92 54 82 60 24 63 64 59 65\n76 44 60 37 29 16 50 74 59 59\n77 58 95 30 52 25 34 2 49 92\n37 65 12 77 68 33 30 39 16 85", "output": "11" }, { "input": "10 1\n19\n9\n14\n14\n19\n5\n5\n18\n10\n17", "output": "0" }, { "input": "8 5\n11 29 11 1 27\n24 16 17 4 19\n13 4 4 20 7\n26 18 23 11 13\n22 20 14 20 16\n18 22 1 22 24\n22 5 11 14 26\n30 16 25 6 9", "output": "3" }, { "input": "5 9\n14 19 30 23 24 27 24 25 4\n12 43 42 30 49 34 33 33 1\n21 41 29 33 31 30 10 41 40\n19 24 14 40 16 34 42 26 19\n3 30 27 32 44 34 3 8 42", "output": "4" }, { "input": "1 1\n99992", "output": "11" }, { "input": "1 1\n100000", "output": "3" }, { "input": "2 2\n10000 99999\n10000 99999", "output": "8" }, { "input": "4 3\n2 1 1\n2 1 1\n2 1 1\n1 1 1", "output": "1" }, { "input": "1 1\n20000", "output": "11" } ]
62
0
0
10,171
928
Autocompletion
[ "*special", "strings", "trees" ]
null
null
Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor. Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (including line feed) requires one keyboard click in order to be printed. Moreover, when Arcady has a non-empty prefix of some word on the screen, the editor proposes a possible autocompletion for this word, more precisely one of the already printed words such that its prefix matches the currently printed prefix if this word is unique. For example, if Arcady has already printed «codeforces», «coding» and «codeforces» once again, then there will be no autocompletion attempt for «cod», but if he proceeds with «code», the editor will propose «codeforces». With a single click Arcady can follow the editor's proposal, i.e. to transform the current prefix to it. Note that no additional symbols are printed after the autocompletion (no spaces, line feeds, etc). What is the minimum number of keyboard clicks Arcady has to perform to print the entire text, if he is not allowed to move the cursor or erase the already printed symbols? A word here is a contiguous sequence of latin letters bordered by spaces, punctuation signs and line/text beginnings/ends. Arcady uses only lowercase letters. For example, there are 20 words in «it's well-known that tic-tac-toe is a paper-and-pencil game for two players, x and o.».
The only line contains Arcady's text, consisting only of lowercase latin letters, spaces, line feeds and the following punctuation signs: «.», «,», «?», «!», «'» and «-». The total amount of symbols doesn't exceed 3·105. It's guaranteed that all lines are non-empty.
Print a single integer — the minimum number of clicks.
[ "snow affects sports such as skiing, snowboarding, and snowmachine travel.\nsnowboarding is a recreational activity and olympic and paralympic sport.\n", "'co-co-co, codeforces?!'\n", "thun-thun-thunder, thunder, thunder\nthunder, thun-, thunder\nthun-thun-thunder, thunder\nthunder, feel the thunder\nlightning then the thunder\nthunder, feel the thunder\nlightning then the thunder\nthunder, thunder\n" ]
[ "141\n", "25\n", "183\n" ]
In sample case one it's optimal to use autocompletion for the first instance of «snowboarding» after typing up «sn» and for the second instance of «snowboarding» after typing up «snowb». This will save 7 clicks. In sample case two it doesn't matter whether to use autocompletion or not.
[ { "input": "snow affects sports such as skiing, snowboarding, and snowmachine travel.\nsnowboarding is a recreational activity and olympic and paralympic sport.", "output": "141" }, { "input": "'co-co-co, codeforces?!'", "output": "25" }, { "input": "thun-thun-thunder, thunder, thunder\nthunder, thun-, thunder\nthun-thun-thunder, thunder\nthunder, feel the thunder\nlightning then the thunder\nthunder, feel the thunder\nlightning then the thunder\nthunder, thunder", "output": "183" }, { "input": "a'b-c-aa'ab.ac.ba!bb-bc-ca?cb-cc.aaa,aab'aac'aba-abb'abc-aca.acb!acc?baa'bab'bac!bba-bbb.bbc.bca", "output": "97" }, { "input": "aaa!bbb'ccc?aaaaaa,aaabbb.aaaccc,bbbaaa-bbbbbb-bbbccc,cccaaa,cccbbb.cccccc'aaaaaaaaa-aaaaaabbb", "output": "91" }, { "input": "bca'bbc,bbb!bba!bac'bab.baa,acc?acb.aca'abc?abb?aba?aac,aab?aaa?cc?cb'ca'bc!bb.ba-ac!ab.aa!c,b.a", "output": "97" }, { "input": "a'aa!aaa.aab,aac,ab!aba,abb.abc'ac.aca'acb,acc!b'ba.baa.bab,bac!bb.bba,bbb,bbc,bc,bca'c?ca.cb,cc", "output": "97" }, { "input": "aaa?c?ba,ac?cc?b.abb-bab.cb-a'aac'bb'aab-bbc'bca.ca.acb-baa.acc-aba?aa-bbb.bac?bc,aca-bba!abc!ab", "output": "97" }, { "input": "baacbcaac-bcaabbaabaacccacc'acbb.b!-ababcab!b'a'aacaccaacbab!c\nb\nbca'bbcc!!", "output": "76" }, { "input": "aaa aaaaaa", "output": "10" } ]
46
5,632,000
-1
10,172
730
Bottles
[ "dp" ]
null
null
Nick has *n* bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda *a**i* and bottle volume *b**i* (*a**i*<=≤<=*b**i*). Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends *x* seconds to pour *x* units of soda from one bottle to another. Nick asks you to help him to determine *k* — the minimal number of bottles to store all remaining soda and *t* — the minimal time to pour soda into *k* bottles. A bottle can't store more soda than its volume. All remaining soda should be saved.
The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the amount of soda remaining in the *i*-th bottle. The third line contains *n* positive integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=100), where *b**i* is the volume of the *i*-th bottle. It is guaranteed that *a**i*<=≤<=*b**i* for any *i*.
The only line should contain two integers *k* and *t*, where *k* is the minimal number of bottles that can store all the soda and *t* is the minimal time to pour the soda into *k* bottles.
[ "4\n3 3 4 3\n4 7 6 5\n", "2\n1 1\n100 100\n", "5\n10 30 5 6 24\n10 41 7 8 24\n" ]
[ "2 6\n", "1 1\n", "3 11\n" ]
In the first example Nick can pour soda from the first bottle to the second bottle. It will take 3 seconds. After it the second bottle will contain 3 + 3 = 6 units of soda. Then he can pour soda from the fourth bottle to the second bottle and to the third bottle: one unit to the second and two units to the third. It will take 1 + 2 = 3 seconds. So, all the soda will be in two bottles and he will spend 3 + 3 = 6 seconds to do it.
[ { "input": "4\n3 3 4 3\n4 7 6 5", "output": "2 6" }, { "input": "2\n1 1\n100 100", "output": "1 1" }, { "input": "5\n10 30 5 6 24\n10 41 7 8 24", "output": "3 11" }, { "input": "1\n1\n100", "output": "1 0" }, { "input": "1\n100\n100", "output": "1 0" }, { "input": "1\n50\n100", "output": "1 0" }, { "input": "10\n18 42 5 1 26 8 40 34 8 29\n18 71 21 67 38 13 99 37 47 76", "output": "3 100" }, { "input": "20\n24 22 4 34 76 13 78 1 81 51 72 11 25 46 22 33 60 42 25 19\n40 81 10 34 84 16 90 38 99 81 100 19 79 65 26 80 62 47 76 47", "output": "9 217" }, { "input": "30\n29 3 2 13 3 12 73 22 37 48 59 17 2 13 69 43 32 14 4 2 61 22 40 30 1 4 46 5 65 17\n55 3 3 92 25 27 97 40 55 74 91 31 7 33 72 62 61 40 16 2 70 61 67 72 8 5 48 9 75 84", "output": "10 310" }, { "input": "40\n9 18 41 31 27 24 76 32 4 38 1 35 21 3 26 32 31 13 41 31 39 14 45 15 12 5 7 14 3 14 19 11 1 81 1 4 7 28 4 62\n70 21 95 63 66 30 100 42 4 80 83 39 34 6 27 55 72 38 43 48 81 53 54 30 63 23 9 59 3 83 83 95 1 81 30 40 35 58 8 66", "output": "11 560" }, { "input": "50\n48 29 72 22 99 27 40 23 39 4 46 29 39 16 47 35 79 7 15 23 50 34 35 22 9 2 51 10 2 42 4 3 30 2 72 19 50 20 11 29 1 2 1 7 7 6 7 75 40 69\n81 36 76 26 100 41 99 39 52 73 83 51 54 86 73 49 79 27 83 90 100 40 49 81 22 54 85 21 26 79 36 96 73 10 98 31 65 39 89 39 1 32 5 20 71 39 87 80 60 86", "output": "17 563" }, { "input": "60\n3 3 22 46 23 19 2 27 3 26 34 18 8 50 13 18 23 26 9 14 7 2 17 12 63 25 4 71 14 47 70 13 6 38 28 22 94 10 51 7 29 1 54 12 8 5 4 34 11 24 2 14 54 65 11 30 3 23 12 11\n4 54 69 97 45 53 2 41 4 74 78 66 85 59 19 38 82 28 11 41 15 43 41 43 77 77 50 75 46 66 97 93 50 44 69 22 94 23 61 27 44 1 56 25 31 63 8 37 23 57 6 17 54 68 14 40 43 31 31 60", "output": "19 535" }, { "input": "70\n17 70 52 31 15 51 8 38 3 43 2 34 7 16 58 29 73 23 41 88 9 24 24 90 33 84 10 29 67 17 47 72 11 79 22 5 8 65 23 7 29 31 11 42 11 14 9 3 54 22 38 34 2 4 39 13 11 34 3 35 22 18 3 57 23 21 13 23 78 7\n18 72 58 55 87 56 9 39 60 79 74 82 9 39 66 32 89 25 46 95 26 31 28 94 36 96 19 37 77 61 50 82 22 81 37 9 11 96 33 12 90 74 11 42 88 86 24 3 85 31 82 81 3 7 69 47 27 51 49 98 33 40 5 94 83 35 21 24 89 49", "output": "26 756" }, { "input": "80\n2 8 36 12 22 41 1 42 6 66 62 94 37 1 5 1 82 8 9 31 14 8 15 5 21 8 5 22 1 17 1 44 1 12 8 45 37 38 13 4 13 4 8 8 3 15 13 53 22 8 19 14 16 7 7 49 1 10 31 33 7 47 61 6 9 48 6 25 16 4 43 1 5 34 8 22 31 38 59 45\n33 90 47 22 28 67 4 44 13 76 65 94 40 8 12 21 88 15 74 37 37 22 19 53 91 26 88 99 1 61 3 75 2 14 8 96 41 76 13 96 41 44 66 48 40 17 41 60 48 9 62 46 56 46 31 63 6 84 68 43 7 88 62 36 52 92 23 27 46 87 52 9 50 44 33 30 33 63 79 72", "output": "21 909" }, { "input": "90\n4 2 21 69 53 39 2 2 8 58 7 5 2 82 7 9 13 10 2 44 1 7 2 1 50 42 36 17 14 46 19 1 50 20 51 46 9 59 73 61 76 4 19 22 1 43 53 2 5 5 32 7 5 42 30 14 32 6 6 15 20 24 13 8 5 19 9 9 7 20 7 2 55 36 5 33 64 20 22 22 9 30 67 38 68 2 13 19 2 9\n48 4 39 85 69 70 11 42 65 77 61 6 60 84 67 15 99 12 2 84 51 17 10 3 50 45 57 53 20 52 64 72 74 44 80 83 70 61 82 81 88 17 22 53 1 44 66 21 10 84 39 11 5 77 93 74 90 17 83 85 70 36 28 87 6 48 22 23 100 22 97 64 96 89 52 49 95 93 34 37 18 69 69 43 83 70 14 54 2 30", "output": "25 955" }, { "input": "10\n96 4 51 40 89 36 35 38 4 82\n99 8 56 42 94 46 35 43 4 84", "output": "8 8" }, { "input": "20\n59 35 29 57 85 70 26 53 56 3 11 56 43 20 81 72 77 72 36 61\n67 53 80 69 100 71 30 63 60 3 20 56 75 23 97 80 81 85 49 80", "output": "13 187" }, { "input": "30\n33 4 1 42 86 85 35 51 45 88 23 35 79 92 81 46 47 32 41 17 18 36 28 58 31 15 17 38 49 78\n36 4 1 49 86 86 43 51 64 93 24 42 82 98 92 47 56 41 41 25 20 53 32 61 53 26 20 38 49 98", "output": "22 123" }, { "input": "40\n31 72 17 63 89 13 72 42 39 30 23 29 5 61 88 37 7 23 49 32 41 25 17 15 9 25 30 61 29 66 24 40 75 67 69 22 61 22 13 35\n32 73 20 68 98 13 74 79 41 33 27 85 5 68 95 44 9 24 95 36 45 26 20 31 10 53 37 72 51 84 24 59 80 75 74 22 72 27 13 39", "output": "24 290" }, { "input": "50\n72 9 46 38 43 75 63 73 70 11 9 48 32 93 33 24 46 44 27 78 43 2 26 84 42 78 35 34 76 36 67 79 82 63 17 26 30 43 35 34 54 37 13 65 8 37 8 8 70 79\n96 19 54 54 44 75 66 80 71 12 9 54 38 95 39 25 48 52 39 86 44 2 27 99 54 99 35 44 80 36 86 93 98 73 27 30 39 43 80 34 61 38 13 69 9 37 8 9 75 97", "output": "34 283" }, { "input": "60\n70 19 46 34 43 19 75 42 47 14 66 64 63 58 55 79 38 45 49 80 72 54 96 26 63 41 12 55 14 56 79 51 12 9 14 77 70 75 46 27 45 10 76 59 40 67 55 24 26 90 50 75 12 93 27 39 46 58 66 31\n73 23 48 49 53 23 76 62 65 14 67 89 66 71 59 90 40 47 68 82 81 61 96 48 99 53 13 60 21 63 83 75 15 12 16 80 74 87 66 31 45 12 76 61 45 88 55 32 28 90 50 75 12 94 29 51 57 85 84 38", "output": "42 368" }, { "input": "70\n67 38 59 72 9 64 12 3 51 58 50 4 16 46 62 77 58 73 7 92 48 9 90 50 35 9 61 57 50 20 48 61 27 77 47 6 83 28 78 14 68 32 2 2 22 57 34 71 26 74 3 76 41 66 30 69 34 16 29 7 14 19 11 5 13 66 19 19 17 55\n69 41 84 91 10 77 12 7 70 74 55 7 30 63 66 79 89 88 10 93 89 15 91 81 41 26 65 67 55 37 73 94 34 94 47 6 90 31 100 25 69 33 2 3 43 97 37 95 35 85 3 78 50 86 30 73 34 21 32 13 21 32 11 5 13 80 23 20 17 58", "output": "38 484" }, { "input": "80\n36 80 23 45 68 72 2 69 84 33 3 43 6 64 82 54 15 15 17 4 3 29 74 14 53 50 52 27 32 18 60 62 50 29 28 48 77 11 24 17 3 55 58 20 4 32 55 16 27 60 5 77 23 31 11 60 21 65 38 39 82 58 51 78 24 30 75 79 5 41 94 10 14 7 1 26 21 41 6 52\n37 93 24 46 99 74 2 93 86 33 3 44 6 71 88 65 15 19 24 4 3 40 82 14 62 81 56 30 33 30 62 62 70 29 31 53 78 13 27 31 3 65 61 20 5 41 58 25 27 61 6 87 26 31 13 62 25 71 44 45 82 75 62 95 24 44 82 94 6 50 94 10 15 15 1 29 35 60 8 68", "output": "50 363" }, { "input": "10\n5 12 10 18 10 9 2 20 5 20\n70 91 36 94 46 15 10 73 55 43", "output": "2 71" }, { "input": "20\n8 1 44 1 12 1 9 11 1 1 5 2 9 16 16 2 1 5 4 1\n88 2 80 33 55 3 74 61 17 11 11 16 42 81 88 14 4 81 60 10", "output": "2 90" }, { "input": "30\n10 1 8 10 2 6 45 7 3 7 1 3 1 1 14 2 5 19 4 1 13 3 5 6 1 5 1 1 23 1\n98 4 43 41 56 58 85 51 47 55 20 85 93 12 49 15 95 72 20 4 68 24 16 97 21 52 18 69 89 15", "output": "3 122" }, { "input": "40\n10 32 10 7 10 6 25 3 18 4 24 4 8 14 6 15 11 8 2 8 2 5 19 9 5 5 3 34 5 1 6 6 1 4 5 26 34 2 21 1\n35 66 54 11 58 68 75 12 69 94 80 33 23 48 45 66 94 53 25 53 83 30 64 49 69 84 73 85 26 41 10 65 23 56 58 93 58 7 100 7", "output": "5 281" }, { "input": "50\n2 1 2 2 38 19 1 2 7 1 2 5 5 1 14 53 21 1 17 9 4 1 24 8 1 1 1 5 4 14 37 1 15 1 4 15 1 3 3 16 17 1 10 18 36 14 25 8 8 48\n45 24 8 12 83 37 6 20 88 9 10 11 28 9 60 98 76 20 84 95 15 45 74 48 37 2 46 34 99 57 94 70 31 22 11 88 58 25 20 73 64 64 81 80 59 64 92 31 43 89", "output": "6 337" }, { "input": "60\n9 9 11 16 58 6 25 6 3 23 1 14 1 8 4 2 1 18 10 1 13 4 23 1 38 6 1 13 5 1 1 1 2 1 1 17 1 24 18 20 2 1 9 26 1 12 3 6 7 17 18 1 2 9 3 6 3 30 7 12\n47 82 78 52 99 51 90 23 58 49 2 98 100 60 25 60 6 69 79 6 91 47 69 18 99 46 30 51 11 3 42 17 33 61 14 81 16 76 72 94 13 5 51 88 26 43 80 31 26 70 93 76 18 67 25 86 60 81 40 38", "output": "7 368" }, { "input": "70\n20 7 5 7 3 10 1 14 33 1 5 3 4 21 7 7 1 2 2 2 8 15 18 2 7 1 1 1 15 2 27 2 6 21 4 2 7 5 1 6 13 36 13 1 10 5 8 13 24 2 10 16 11 9 4 1 1 8 6 26 9 3 3 2 8 5 17 9 1 13\n85 36 76 36 65 24 37 56 78 42 33 13 29 93 31 38 1 59 71 31 28 55 70 14 33 9 1 5 41 22 86 41 92 89 88 10 39 54 6 32 58 82 49 22 62 44 29 19 54 12 59 54 51 80 66 16 22 74 8 68 35 34 24 8 22 14 55 76 32 75", "output": "7 426" }, { "input": "80\n11 6 9 6 5 18 21 11 6 6 2 9 4 1 10 12 2 9 1 14 6 12 16 14 4 5 1 16 3 4 6 1 11 30 2 4 1 11 1 6 1 3 2 14 6 14 13 1 10 2 4 14 11 8 28 2 2 3 1 6 26 3 11 4 1 1 29 4 5 4 3 5 1 4 2 12 59 3 18 1\n94 43 36 86 12 75 50 80 55 14 5 97 17 25 28 86 51 56 17 88 48 40 31 39 51 58 4 75 70 30 11 8 61 88 10 25 35 46 31 51 20 79 22 54 19 67 31 89 42 70 30 37 35 78 95 31 31 51 31 50 54 90 63 27 6 2 92 80 48 9 27 33 61 63 30 38 95 46 86 45", "output": "8 434" }, { "input": "90\n1 9 3 3 14 3 2 32 17 3 1 1 4 1 18 1 1 21 9 1 2 10 6 9 27 15 5 1 3 37 1 2 1 12 6 1 8 4 1 5 1 3 8 9 1 9 23 1 1 2 1 2 2 19 2 6 5 6 1 7 12 35 1 2 8 1 11 32 7 4 12 9 18 8 9 27 31 15 16 4 16 13 2 2 1 4 12 17 10 1\n8 52 13 56 42 40 8 98 64 47 84 11 12 1 97 8 8 66 35 4 6 62 22 38 68 57 50 28 28 88 7 57 9 81 14 37 71 57 33 24 2 21 54 58 58 27 79 3 55 13 2 95 17 97 61 22 28 85 78 72 68 80 12 41 98 18 35 70 40 22 98 85 51 70 79 100 68 29 73 45 89 64 53 6 16 29 73 53 24 69", "output": "8 562" }, { "input": "32\n4 1 1 6 2 5 8 6 5 6 3 2 1 3 1 9 1 2 1 5 2 1 6 5 3 7 3 3 2 5 1 1\n8 1 3 6 4 7 9 8 6 8 10 2 5 3 2 10 1 10 9 5 4 1 8 7 8 7 4 10 4 6 9 2", "output": "13 46" }, { "input": "38\n2 1 1 1 1 9 5 2 1 3 4 3 1 7 4 4 8 7 1 5 4 9 1 6 3 4 1 4 1 5 5 1 8 3 1 3 6 3\n2 1 6 2 9 10 6 2 1 5 4 6 1 7 4 6 10 8 8 6 4 10 1 6 4 4 6 4 4 8 5 2 10 7 3 5 6 3", "output": "19 40" }, { "input": "35\n9 7 34 3 2 6 36 3 26 12 17 8 5 32 55 10 24 19 2 3 30 17 14 1 33 36 42 14 51 1 2 22 13 34 28\n9 9 55 17 16 12 37 14 27 58 51 16 10 37 69 15 43 26 14 60 86 34 54 1 37 50 58 18 92 66 7 24 25 92 30", "output": "10 307" }, { "input": "35\n21 2 68 56 41 25 42 17 21 20 29 26 38 37 29 77 43 13 32 48 38 31 15 8 52 6 63 45 70 2 21 13 3 14 47\n46 83 100 87 59 95 47 33 56 60 38 76 63 75 60 92 65 43 56 94 70 80 46 40 64 6 83 50 75 19 52 66 13 88 62", "output": "14 432" }, { "input": "69\n24 32 19 37 36 7 15 10 54 12 15 46 3 25 12 16 3 8 55 21 23 57 17 45 11 4 25 35 39 3 69 24 78 40 12 39 1 44 4 75 53 60 1 6 30 7 6 39 44 13 31 6 4 4 32 11 52 58 81 2 33 7 29 19 21 26 22 60 24\n57 56 50 64 40 58 31 20 81 14 43 64 48 38 56 71 58 26 98 92 52 88 71 93 11 20 79 39 56 7 92 54 88 58 19 85 12 71 4 87 78 90 29 18 89 13 86 71 100 24 65 95 46 8 91 35 62 66 96 36 80 24 81 58 53 86 89 67 73", "output": "22 801" }, { "input": "63\n8 23 6 19 1 34 23 1 15 58 22 10 5 14 41 1 16 48 68 5 13 19 1 4 35 2 42 8 45 24 52 44 59 78 5 11 14 41 10 26 60 26 9 15 34 1 14 5 2 6 19 7 4 26 49 39 13 40 18 62 66 8 4\n17 25 39 45 2 44 40 1 82 68 80 27 7 58 90 20 100 80 79 21 53 62 2 11 51 98 78 55 48 37 89 74 83 91 64 30 20 50 24 74 81 94 33 64 56 28 57 9 27 50 81 34 18 33 53 61 39 89 44 77 86 40 89", "output": "18 638" }, { "input": "73\n69 67 34 35 10 27 30 27 31 48 25 18 81 54 32 54 5 62 20 4 94 2 60 4 6 11 62 68 14 18 42 18 33 71 72 2 29 7 36 60 10 25 17 2 38 77 34 36 74 76 63 32 42 29 22 14 5 1 6 2 14 19 20 19 41 31 16 17 50 49 2 22 51\n73 70 58 54 10 71 59 35 91 61 52 65 90 70 37 80 12 94 78 34 97 4 62 95 10 11 93 100 14 38 56 42 96 96 84 71 69 43 50 79 11 83 95 76 39 79 61 42 89 90 71 62 43 38 39 21 5 40 27 13 21 73 30 46 47 34 23 22 57 59 6 25 72", "output": "30 808" }, { "input": "90\n1 43 87 1 6 12 49 6 3 9 38 1 64 49 11 18 5 1 46 25 30 82 17 4 8 9 5 5 4 1 10 4 13 42 44 90 1 11 27 23 25 4 12 19 48 3 59 48 39 14 1 5 64 46 39 24 28 77 25 20 3 14 28 2 20 63 2 1 13 11 44 49 61 76 20 1 3 42 38 8 69 17 27 18 29 54 2 1 2 7\n8 96 91 1 11 20 83 34 41 88 54 4 65 82 48 60 62 18 76 74 75 89 87 8 11 32 67 7 5 1 92 88 57 92 76 95 35 58 68 23 30 25 12 31 85 5 89 84 71 23 1 5 76 56 57 57 76 94 33 34 66 20 54 5 22 69 2 19 28 62 74 88 91 86 30 6 3 48 80 10 84 20 44 37 81 100 12 3 6 8", "output": "26 899" }, { "input": "85\n20 47 52 6 5 15 35 42 5 84 4 8 61 47 7 50 20 24 15 27 86 28 1 39 1 2 63 2 31 33 47 4 33 68 20 4 4 42 20 67 7 10 46 4 22 36 30 40 4 15 51 2 39 50 65 48 34 6 50 19 32 48 8 23 42 70 69 8 29 81 5 1 7 21 3 30 78 6 2 1 3 69 34 34 18\n74 64 89 61 5 17 75 43 13 87 30 51 93 54 7 76 44 44 98 77 86 97 1 41 1 3 69 3 80 87 67 6 90 100 31 5 7 46 99 67 9 44 56 7 39 39 55 80 80 33 77 9 89 79 86 53 49 49 72 87 43 84 24 23 43 94 74 17 54 96 28 64 14 42 91 60 87 69 20 1 30 95 44 50 20", "output": "29 987" }, { "input": "81\n21 13 1 25 14 33 33 41 53 89 2 18 61 8 3 35 15 59 2 2 3 5 75 37 1 34 7 12 33 66 6 4 14 78 3 16 12 45 3 2 1 17 17 45 4 30 68 40 44 3 1 21 64 63 14 19 75 63 7 9 12 75 20 28 16 20 53 26 13 46 18 8 28 32 9 29 1 11 75 4 21\n45 90 21 31 36 68 71 47 59 89 61 32 98 67 7 53 90 86 6 28 4 83 93 62 8 56 18 35 33 92 36 37 23 98 44 21 23 79 10 4 2 18 48 87 29 86 79 74 45 3 6 23 79 71 17 39 88 73 50 15 13 92 33 47 83 48 73 33 15 63 43 14 90 72 9 95 1 22 83 20 29", "output": "26 754" }, { "input": "2\n1 1\n1 1", "output": "2 0" }, { "input": "1\n1\n1", "output": "1 0" }, { "input": "1\n1\n2", "output": "1 0" }, { "input": "2\n1 1\n1 100", "output": "1 1" }, { "input": "2\n1 1\n100 1", "output": "1 1" }, { "input": "86\n5 1 3 1 1 1 1 9 4 1 3 1 4 6 3 2 2 7 1 1 3 1 2 1 1 5 4 3 6 3 3 4 8 2 1 3 1 2 7 2 5 4 2 1 1 2 1 3 2 9 1 4 2 1 1 9 6 1 8 1 7 9 4 3 4 1 3 1 1 3 1 1 3 1 1 10 7 7 4 1 1 3 1 6 1 3\n10 2 5 7 1 4 7 9 4 7 3 1 5 6 3 8 4 10 5 1 9 3 4 2 1 5 7 4 7 7 7 5 9 5 3 3 6 4 7 2 9 7 3 4 2 3 1 5 6 9 10 4 8 10 10 9 7 8 10 1 7 10 10 7 8 5 8 2 1 4 1 2 3 8 1 10 9 7 4 2 1 3 4 9 2 3", "output": "32 101" }, { "input": "90\n9 2 2 3 4 1 9 8 3 3 1 1 1 1 2 2 1 3 4 8 8 1 2 7 3 4 5 6 1 2 9 4 2 5 6 1 1 2 6 5 1 4 3 2 4 1 1 3 1 1 3 1 8 3 1 4 1 2 2 3 5 2 8 6 2 5 2 1 4 2 1 5 4 2 1 1 2 1 1 6 4 4 3 4 1 4 4 6 2 3\n10 6 2 3 10 1 10 10 6 4 1 3 6 1 2 5 3 7 7 9 9 2 3 8 3 4 9 7 8 4 10 7 8 10 9 5 1 4 6 5 1 9 10 4 6 4 1 3 3 1 6 1 9 4 1 6 4 5 5 10 7 9 9 10 4 5 2 1 4 2 1 7 6 5 3 9 2 5 1 8 6 4 6 10 1 7 5 9 6 4", "output": "35 109" }, { "input": "33\n33 20 33 40 58 50 5 6 13 12 4 33 11 50 12 19 16 36 68 57 23 17 6 22 39 58 49 21 10 35 35 17 12\n62 22 53 44 66 60 97 7 33 18 10 59 33 77 55 63 91 86 87 86 27 62 65 53 46 69 64 63 10 53 52 23 24", "output": "13 356" }, { "input": "83\n13 20 5 29 48 53 88 17 11 5 44 15 85 13 2 55 6 16 57 29 12 15 12 92 21 25 1 2 4 5 2 22 8 18 22 2 3 10 43 71 3 41 1 73 6 18 32 63 26 13 6 75 19 10 41 30 15 12 14 8 15 77 73 7 5 39 83 19 2 2 3 61 53 43 3 15 76 29 8 46 19 3 8\n54 34 15 58 50 67 100 43 30 15 46 26 94 75 2 58 85 38 68 98 83 51 82 100 61 27 5 5 41 89 17 34 10 48 48 4 15 13 71 75 4 44 2 82 18 82 59 96 26 13 66 95 81 33 85 45 16 92 41 37 85 78 83 17 7 72 83 38 69 24 18 76 71 66 3 66 78 31 73 72 43 89 49", "output": "26 944" }, { "input": "70\n13 42 8 56 21 58 39 2 49 39 15 26 62 45 26 8 47 40 9 36 41 2 4 38 6 55 2 41 72 18 10 2 6 11 4 39 19 39 14 59 5 42 19 79 12 3 1 1 21 6 5 9 36 6 38 2 7 26 8 15 66 7 1 30 93 34 45 24 12 20\n26 56 25 60 26 79 99 7 68 92 99 32 81 48 39 97 49 95 18 82 59 4 99 41 10 63 43 54 76 97 73 7 17 43 4 84 35 86 20 63 8 59 87 80 34 3 8 13 49 55 14 11 68 8 41 33 14 39 43 31 89 13 7 88 93 51 84 73 26 30", "output": "21 867" }, { "input": "77\n19 34 39 56 1 2 47 8 17 28 23 45 18 7 5 3 11 20 30 24 13 34 11 1 4 14 68 23 13 33 3 8 1 5 8 23 12 1 19 14 22 67 26 55 10 1 63 82 82 6 38 5 6 11 1 62 1 12 5 40 19 20 37 9 5 3 2 44 13 20 44 32 11 29 12 19 35\n28 41 43 68 1 36 57 13 84 89 26 92 47 19 7 94 79 75 74 42 32 44 46 23 96 46 82 86 91 33 25 11 12 68 22 31 89 14 81 32 50 94 27 66 50 39 98 90 91 11 69 6 45 19 15 74 22 31 7 92 23 98 88 32 8 4 2 51 79 69 70 43 16 60 29 20 98", "output": "19 937" }, { "input": "77\n44 2 13 14 8 46 65 14 1 39 12 18 15 10 2 40 71 40 17 1 16 72 13 7 41 23 81 12 4 1 19 18 41 35 23 56 21 5 17 47 88 1 24 15 48 15 1 13 50 5 31 16 21 47 4 1 49 2 15 23 46 47 27 22 23 40 29 4 30 50 51 12 20 14 41 25 12\n57 16 72 59 28 80 74 19 4 60 52 52 97 20 5 69 84 66 63 38 50 79 24 84 58 92 99 36 38 97 66 79 41 48 26 95 28 38 28 72 95 71 30 15 63 17 7 69 90 29 89 40 21 83 73 24 51 14 15 74 100 88 74 27 46 61 38 4 32 52 52 51 47 51 81 75 19", "output": "24 932" } ]
140
37,171,200
0
10,183
445
DZY Loves Chemistry
[ "dfs and similar", "dsu", "greedy" ]
null
null
DZY loves chemistry, and he enjoys mixing chemicals. DZY has *n* chemicals, and *m* pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order. Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pours a chemical, if there are already one or more chemicals in the test tube that can react with it, the danger of the test tube will be multiplied by 2. Otherwise the danger remains as it is. Find the maximum possible danger after pouring all the chemicals one by one in optimal order.
The first line contains two space-separated integers *n* and *m* . Each of the next *m* lines contains two space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=&lt;<=*y**i*<=≤<=*n*). These integers mean that the chemical *x**i* will react with the chemical *y**i*. Each pair of chemicals will appear at most once in the input. Consider all the chemicals numbered from 1 to *n* in some order.
Print a single integer — the maximum possible danger.
[ "1 0\n", "2 1\n1 2\n", "3 2\n1 2\n2 3\n" ]
[ "1\n", "2\n", "4\n" ]
In the first sample, there's only one way to pour, and the danger won't increase. In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2. In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that is the numbers of the chemicals in order of pouring).
[ { "input": "1 0", "output": "1" }, { "input": "2 1\n1 2", "output": "2" }, { "input": "3 2\n1 2\n2 3", "output": "4" }, { "input": "10 10\n1 8\n4 10\n4 6\n5 10\n2 3\n1 7\n3 4\n3 6\n6 9\n3 7", "output": "512" }, { "input": "20 20\n6 8\n13 20\n7 13\n6 17\n5 15\n1 12\n2 15\n5 17\n5 14\n6 14\n12 20\n7 20\n1 6\n1 7\n2 19\n14 17\n1 10\n11 15\n9 18\n2 12", "output": "32768" }, { "input": "30 30\n7 28\n16 26\n14 24\n16 18\n20 29\n4 28\n19 21\n8 26\n1 25\n14 22\n13 23\n4 15\n15 16\n2 19\n29 30\n12 20\n3 4\n3 26\n3 11\n22 27\n5 16\n2 24\n2 18\n7 16\n17 21\n17 25\n8 15\n23 27\n12 21\n5 30", "output": "67108864" }, { "input": "40 40\n28 33\n15 21\n12 29\n14 31\n2 26\n3 12\n25 34\n6 30\n6 25\n5 28\n9 17\n23 29\n30 36\n3 21\n35 37\n7 25\n29 39\n15 19\n12 35\n24 34\n15 25\n19 33\n26 31\n7 29\n1 40\n11 27\n6 9\n6 27\n36 39\n10 14\n6 16\n23 25\n2 38\n3 24\n30 31\n29 30\n4 12\n11 13\n14 40\n22 39", "output": "34359738368" }, { "input": "50 50\n16 21\n23 47\n23 30\n2 12\n23 41\n3 16\n14 20\n4 49\n2 47\n19 29\n13 42\n5 8\n24 38\n13 32\n34 37\n38 46\n3 20\n27 50\n7 42\n33 45\n2 48\n41 47\n9 48\n15 26\n27 37\n32 34\n17 24\n1 39\n27 30\n10 33\n38 47\n32 33\n14 39\n35 50\n2 19\n3 12\n27 34\n18 25\n12 23\n31 44\n5 35\n28 45\n38 39\n13 44\n34 38\n16 46\n5 15\n26 30\n47 49\n2 10", "output": "4398046511104" }, { "input": "50 0", "output": "1" }, { "input": "50 7\n16 32\n31 34\n4 16\n4 39\n1 50\n43 49\n1 33", "output": "128" }, { "input": "7 20\n2 3\n3 6\n1 6\n1 2\n3 5\n1 7\n4 5\n4 7\n1 3\n2 6\n2 7\n4 6\n3 4\n1 4\n3 7\n1 5\n2 5\n5 6\n5 7\n2 4", "output": "64" }, { "input": "5 4\n1 2\n2 3\n3 4\n4 5", "output": "16" }, { "input": "10 7\n1 2\n2 3\n1 5\n2 7\n7 8\n1 9\n9 10", "output": "128" }, { "input": "20 15\n1 3\n3 4\n3 5\n4 6\n1 7\n1 8\n1 9\n7 11\n8 12\n5 13\n3 16\n1 17\n3 18\n1 19\n17 20", "output": "32768" }, { "input": "30 24\n2 3\n3 4\n1 5\n4 6\n6 7\n1 8\n1 9\n4 10\n9 11\n5 12\n6 13\n10 14\n14 15\n12 16\n14 17\n2 18\n8 19\n3 20\n10 21\n11 24\n3 25\n1 26\n7 27\n4 29", "output": "16777216" }, { "input": "40 28\n1 2\n2 4\n3 5\n1 7\n1 8\n7 9\n6 10\n7 11\n2 12\n9 13\n11 15\n12 16\n1 18\n10 19\n7 21\n7 23\n20 25\n24 27\n14 28\n9 29\n23 30\n27 31\n11 34\n21 35\n32 36\n23 38\n7 39\n20 40", "output": "268435456" }, { "input": "50 41\n1 2\n1 3\n2 4\n1 5\n2 7\n4 8\n7 9\n2 11\n10 13\n11 14\n12 15\n14 16\n4 19\n7 20\n14 21\n8 23\n16 24\n16 25\n16 26\n19 27\n2 28\n3 29\n21 30\n12 31\n20 32\n23 33\n30 34\n6 35\n34 36\n34 37\n33 38\n34 40\n30 41\n3 42\n39 43\n5 44\n8 45\n40 46\n20 47\n31 49\n34 50", "output": "2199023255552" }, { "input": "50 39\n1 2\n1 4\n5 6\n4 7\n5 8\n7 9\n9 10\n10 11\n2 12\n8 14\n11 15\n11 17\n3 18\n13 19\n17 20\n7 21\n6 22\n22 23\n14 24\n22 25\n23 26\n26 27\n27 28\n15 29\n8 30\n26 31\n32 33\n21 35\n14 36\n30 37\n17 38\n12 40\n11 42\n14 43\n12 44\n1 45\n29 46\n22 47\n47 50", "output": "549755813888" }, { "input": "50 38\n1 2\n2 3\n3 4\n3 5\n4 7\n5 10\n9 11\n9 12\n11 13\n12 14\n6 15\n8 16\n2 18\n15 19\n3 20\n10 21\n4 22\n9 24\n2 25\n23 26\n3 28\n20 29\n14 30\n4 32\n24 33\n20 36\n1 38\n19 39\n39 40\n22 41\n18 42\n19 43\n40 45\n45 46\n9 47\n6 48\n9 49\n25 50", "output": "274877906944" }, { "input": "50 41\n1 3\n1 4\n2 5\n2 7\n1 8\n2 10\n4 11\n5 12\n12 13\n4 14\n10 17\n1 18\n1 21\n5 22\n14 23\n19 24\n13 25\n3 26\n11 27\n6 28\n26 29\n21 30\n17 31\n15 32\n1 33\n12 34\n23 36\n6 37\n15 38\n37 39\n31 40\n15 41\n25 42\n19 43\n20 44\n32 45\n44 46\n31 47\n2 48\n32 49\n27 50", "output": "2199023255552" }, { "input": "50 47\n1 2\n1 3\n1 4\n1 5\n5 6\n2 7\n2 8\n2 9\n2 10\n8 11\n5 12\n11 13\n10 14\n6 15\n9 16\n1 17\n1 18\n8 19\n5 20\n5 21\n11 22\n2 23\n22 24\n24 25\n5 26\n21 27\n27 28\n8 29\n2 30\n4 31\n11 32\n17 33\n22 34\n25 35\n28 36\n28 37\n11 38\n17 39\n19 42\n6 43\n11 44\n29 45\n2 46\n24 47\n7 48\n3 49\n44 50", "output": "140737488355328" }, { "input": "11 20\n3 6\n2 6\n2 9\n4 5\n9 11\n6 8\n5 6\n1 6\n4 11\n9 10\n5 10\n4 6\n3 8\n2 3\n1 7\n1 11\n2 7\n1 3\n3 7\n1 8", "output": "1024" }, { "input": "26 17\n1 2\n2 3\n1 6\n6 7\n7 8\n2 9\n4 10\n3 11\n11 12\n9 13\n6 14\n2 16\n5 18\n6 19\n11 22\n15 24\n6 26", "output": "131072" }, { "input": "48 43\n1 2\n1 3\n3 4\n4 5\n2 6\n5 7\n7 9\n4 10\n6 11\n3 12\n6 13\n3 14\n6 15\n13 16\n4 17\n12 18\n18 19\n1 20\n1 21\n16 22\n9 23\n3 24\n22 25\n2 26\n10 27\n18 28\n13 30\n3 31\n24 33\n29 34\n15 35\n16 36\n23 37\n21 38\n34 39\n37 40\n39 41\n19 42\n15 43\n23 44\n22 45\n14 47\n10 48", "output": "8796093022208" }, { "input": "8 5\n1 2\n1 3\n1 4\n5 6\n7 8", "output": "32" }, { "input": "8 7\n1 2\n2 3\n3 4\n1 4\n5 6\n6 7\n7 8", "output": "64" } ]
46
307,200
0
10,237
148
Bag of mice
[ "dp", "games", "math", "probabilities" ]
null
null
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chance. They take turns drawing a mouse from a bag which initially contains *w* white and *b* black mice. The person who is the first to draw a white mouse wins. After each mouse drawn by the dragon the rest of mice in the bag panic, and one of them jumps out of the bag itself (the princess draws her mice carefully and doesn't scare other mice). Princess draws first. What is the probability of the princess winning? If there are no more mice in the bag and nobody has drawn a white mouse, the dragon wins. Mice which jump out of the bag themselves are not considered to be drawn (do not define the winner). Once a mouse has left the bag, it never returns to it. Every mouse is drawn from the bag with the same probability as every other one, and every mouse jumps out of the bag with the same probability as every other one.
The only line of input data contains two integers *w* and *b* (0<=≤<=*w*,<=*b*<=≤<=1000).
Output the probability of the princess winning. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=9.
[ "1 3\n", "5 5\n" ]
[ "0.500000000\n", "0.658730159\n" ]
Let's go through the first sample. The probability of the princess drawing a white mouse on her first turn and winning right away is 1/4. The probability of the dragon drawing a black mouse and not winning on his first turn is 3/4 * 2/3 = 1/2. After this there are two mice left in the bag — one black and one white; one of them jumps out, and the other is drawn by the princess on her second turn. If the princess' mouse is white, she wins (probability is 1/2 * 1/2 = 1/4), otherwise nobody gets the white mouse, so according to the rule the dragon wins.
[ { "input": "1 3", "output": "0.500000000" }, { "input": "5 5", "output": "0.658730159" }, { "input": "100 100", "output": "0.666295063" }, { "input": "100 1", "output": "0.990099010" }, { "input": "1 100", "output": "0.336633663" }, { "input": "67 420", "output": "0.536897227" }, { "input": "0 1000", "output": "0.000000000" }, { "input": "1000 0", "output": "1.000000000" }, { "input": "0 0", "output": "0.000000000" }, { "input": "1000 1000", "output": "0.666629617" }, { "input": "32 1000", "output": "0.507870202" }, { "input": "581 406", "output": "0.708455368" }, { "input": "459 52", "output": "0.907503322" }, { "input": "900 853", "output": "0.672635039" }, { "input": "778 218", "output": "0.820333392" }, { "input": "219 20", "output": "0.922525319" }, { "input": "815 665", "output": "0.689921745" }, { "input": "773 467", "output": "0.726347987" }, { "input": "215 269", "output": "0.642626672" }, { "input": "93 633", "output": "0.534192877" }, { "input": "267 270", "output": "0.665290172" }, { "input": "226 72", "output": "0.805082561" }, { "input": "666 436", "output": "0.716435071" }, { "input": "544 519", "output": "0.671862905" }, { "input": "141 883", "output": "0.536951107" }, { "input": "581 685", "output": "0.648844385" }, { "input": "459 487", "output": "0.660077510" }, { "input": "980 133", "output": "0.893190920" }, { "input": "858 934", "output": "0.657333867" }, { "input": "455 299", "output": "0.715932720" }, { "input": "962 35", "output": "0.966054554" }, { "input": "840 837", "output": "0.667020172" }, { "input": "1000 483", "output": "0.754259888" }, { "input": "958 285", "output": "0.813405050" }, { "input": "399 649", "output": "0.617507391" }, { "input": "277 451", "output": "0.617396161" }, { "input": "155 534", "output": "0.563323504" }, { "input": "315 898", "output": "0.574579114" }, { "input": "193 700", "output": "0.560544099" }, { "input": "713 65", "output": "0.922816830" }, { "input": "377 720", "output": "0.603697168" }, { "input": "817 522", "output": "0.719439426" }, { "input": "695 168", "output": "0.836944656" }, { "input": "574 969", "output": "0.614216493" }, { "input": "95 334", "output": "0.562182792" }, { "input": "691 417", "output": "0.726476058" }, { "input": "132 781", "output": "0.538939829" }, { "input": "10 583", "output": "0.504240929" }, { "input": "888 385", "output": "0.767717438" }, { "input": "329 31", "output": "0.920544382" }, { "input": "73 405", "output": "0.541293398" }, { "input": "513 488", "output": "0.672187379" }, { "input": "391 852", "output": "0.593281183" }, { "input": "551 654", "output": "0.648141838" }, { "input": "429 19", "output": "0.959234268" }, { "input": "387 102", "output": "0.827219303" }, { "input": "827 466", "output": "0.735005881" }, { "input": "705 268", "output": "0.783946132" }, { "input": "864 70", "output": "0.930218970" }, { "input": "743 715", "output": "0.670910005" }, { "input": "50 372", "output": "0.531448979" } ]
154
614,400
0
10,242
356
Xenia and Hamming
[ "implementation", "math" ]
null
null
Xenia is an amateur programmer. Today on the IT lesson she learned about the Hamming distance. The Hamming distance between two strings *s*<==<=*s*1*s*2... *s**n* and *t*<==<=*t*1*t*2... *t**n* of equal length *n* is value . Record [*s**i*<=≠<=*t**i*] is the Iverson notation and represents the following: if *s**i*<=≠<=*t**i*, it is one, otherwise — zero. Now Xenia wants to calculate the Hamming distance between two long strings *a* and *b*. The first string *a* is the concatenation of *n* copies of string *x*, that is, . The second string *b* is the concatenation of *m* copies of string *y*. Help Xenia, calculate the required Hamming distance, given *n*,<=*x*,<=*m*,<=*y*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1012). The second line contains a non-empty string *x*. The third line contains a non-empty string *y*. Both strings consist of at most 106 lowercase English letters. It is guaranteed that strings *a* and *b* that you obtain from the input have the same length.
Print a single integer — the required Hamming distance. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "100 10\na\naaaaaaaaaa\n", "1 1\nabacaba\nabzczzz\n", "2 3\nrzr\naz\n" ]
[ "0\n", "4\n", "5\n" ]
In the first test case string *a* is the same as string *b* and equals 100 letters a. As both strings are equal, the Hamming distance between them is zero. In the second test case strings *a* and *b* differ in their 3-rd, 5-th, 6-th and 7-th characters. Thus, the Hamming distance equals 4. In the third test case string *a* is rzrrzr and string *b* is azazaz. The strings differ in all characters apart for the second one, the Hamming distance between them equals 5.
[]
1,000
13,619,200
0
10,261
0
none
[ "none" ]
null
null
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name *w* and the collection of forbidden substrings *s*1,<=*s*2,<=...,<=*s**n*. All those strings consist of uppercase and lowercase Latin letters. String *w* has the length of |*w*|, its characters are numbered from 1 to |*w*|. First Petya should find all the occurrences of forbidden substrings in the *w* string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal. After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position *i* should be replaced by any other one if for position *i* in string *w* there exist pair of indices *l*,<=*r* (1<=≤<=*l*<=≤<=*i*<=≤<=*r*<=≤<=|*w*|) such that substring *w*[*l* ... *r*] is contained in the collection *s*1,<=*s*2,<=...,<=*s**n*, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring. Letter *letter* (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the *letter* occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically. Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of forbidden substrings in the collection. Next *n* lines contain these substrings. The next line contains string *w*. All those *n*<=+<=1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter *letter*.
Output the only line — Petya's resulting string with the maximum number of letters *letter*. If there are several answers then output the one that comes first lexicographically. The lexicographical comparison is performed by the standard &lt; operator in modern programming languages. The line *a* is lexicographically smaller than the line *b*, if *a* is a prefix of *b*, or there exists such an *i* (1<=≤<=*i*<=≤<=|*a*|), that *a**i*<=&lt;<=*b**i*, and for any *j* (1<=≤<=*j*<=&lt;<=*i*) *a**j*<==<=*b**j*. |*a*| stands for the length of string *a*.
[ "3\nbers\nucky\nelu\nPetrLoveLuckyNumbers\nt\n", "4\nhello\nparty\nabefglghjdhfgj\nIVan\npetrsmatchwin\na\n", "2\naCa\ncba\nabAcaba\nc\n" ]
[ "PetrLovtTttttNumtttt\n", "petrsmatchwin\n", "abCacba\n" ]
none
[]
92
0
0
10,275
0
none
[ "none" ]
null
null
We'll call an array of *n* non-negative integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] interesting, if it meets *m* constraints. The *i*-th of the *m* constraints consists of three integers *l**i*, *r**i*, *q**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) meaning that value should be equal to *q**i*. Your task is to find any interesting array of *n* elements or state that such array doesn't exist. Expression *x*&amp;*y* means the bitwise AND of numbers *x* and *y*. In programming languages C++, Java and Python this operation is represented as "&amp;", in Pascal — as "and".
The first line contains two integers *n*, *m* (1<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=105) — the number of elements in the array and the number of limits. Each of the next *m* lines contains three integers *l**i*, *r**i*, *q**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*, 0<=≤<=*q**i*<=&lt;<=230) describing the *i*-th limit.
If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print *n* integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] (0<=≤<=*a*[*i*]<=&lt;<=230) decribing the interesting array. If there are multiple answers, print any of them. If the interesting array doesn't exist, print "NO" (without the quotes) in the single line.
[ "3 1\n1 3 3\n", "3 2\n1 3 3\n1 3 2\n" ]
[ "YES\n3 3 3\n", "NO\n" ]
none
[ { "input": "3 1\n1 3 3", "output": "YES\n3 3 3" }, { "input": "3 2\n1 3 3\n1 3 2", "output": "NO" }, { "input": "3 2\n1 2 536870912\n2 3 536870911", "output": "YES\n536870912 1073741823 536870911" }, { "input": "1 1\n1 1 10", "output": "YES\n10" }, { "input": "1 2\n1 1 10\n1 1 5", "output": "NO" }, { "input": "1 2\n1 1 1\n1 1 3", "output": "NO" } ]
109
12,595,200
0
10,284
226
Flying Saucer Segments
[ "math" ]
null
null
An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!). The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the 2-nd one, the 2-nd one — to the 1-st and the 3-rd ones, the 3-rd one — only to the 2-nd one. The transitions are possible only between the adjacent sections. The spacecraft team consists of *n* aliens. Each of them is given a rank — an integer from 1 to *n*. The ranks of all astronauts are distinct. The rules established on the Saucer, state that an alien may move from section *a* to section *b* only if it is senior in rank to all aliens who are in the segments *a* and *b* (besides, the segments *a* and *b* are of course required to be adjacent). Any alien requires exactly 1 minute to make a move. Besides, safety regulations require that no more than one alien moved at the same minute along the ship. Alien *A* is senior in rank to alien *B*, if the number indicating rank *A*, is more than the corresponding number for *B*. At the moment the whole saucer team is in the 3-rd segment. They all need to move to the 1-st segment. One member of the crew, the alien with the identification number CFR-140, decided to calculate the minimum time (in minutes) they will need to perform this task. Help CFR-140, figure out the minimum time (in minutes) that all the astronauts will need to move from the 3-rd segment to the 1-st one. Since this number can be rather large, count it modulo *m*.
The first line contains two space-separated integers: *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the number of aliens on the saucer and the number, modulo which you should print the answer, correspondingly.
Print a single number — the answer to the problem modulo *m*.
[ "1 10\n", "3 8\n" ]
[ "2\n", "2\n" ]
In the first sample the only crew member moves from segment 3 to segment 2, and then from segment 2 to segment 1 without any problems. Thus, the whole moving will take two minutes. To briefly describe the movements in the second sample we will use value <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4c7c8e716067e9c6251e8ca82a4ca7fde74fbacb.png" style="max-width: 100.0%;max-height: 100.0%;"/>, which would correspond to an alien with rank *i* moving from the segment in which it is at the moment, to the segment number *j*. Using these values, we will describe the movements between the segments in the second sample: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7668900e59f9bc3ccc78b0a77dca322fcb02fa04.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1adb8798904e42944c35bd49feff02db6c3ea10b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/954e2f634474269f53df1edbf2e7b214d8a2611c.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7668900e59f9bc3ccc78b0a77dca322fcb02fa04.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/be5f59dacfc6f7ded42f8f260c7b7aedf17ec1f0.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d4fd9e68a9c6a277942eb188291d6d2744ea21d3.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7668900e59f9bc3ccc78b0a77dca322fcb02fa04.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1adb8798904e42944c35bd49feff02db6c3ea10b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b73a9870e1b41a5e048c3ab3e3fd4b92c336c9ec.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7668900e59f9bc3ccc78b0a77dca322fcb02fa04.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/be5f59dacfc6f7ded42f8f260c7b7aedf17ec1f0.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/954e2f634474269f53df1edbf2e7b214d8a2611c.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7668900e59f9bc3ccc78b0a77dca322fcb02fa04.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1adb8798904e42944c35bd49feff02db6c3ea10b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/49b1ffd4dcd2e0da0acec04559e0c3efc7854b07.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7668900e59f9bc3ccc78b0a77dca322fcb02fa04.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/be5f59dacfc6f7ded42f8f260c7b7aedf17ec1f0.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ef8b3f32ee76c86f57fa63f7251fa290642f17f8.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7668900e59f9bc3ccc78b0a77dca322fcb02fa04.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1adb8798904e42944c35bd49feff02db6c3ea10b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/954e2f634474269f53df1edbf2e7b214d8a2611c.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7668900e59f9bc3ccc78b0a77dca322fcb02fa04.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/be5f59dacfc6f7ded42f8f260c7b7aedf17ec1f0.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d4fd9e68a9c6a277942eb188291d6d2744ea21d3.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7668900e59f9bc3ccc78b0a77dca322fcb02fa04.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1adb8798904e42944c35bd49feff02db6c3ea10b.png" style="max-width: 100.0%;max-height: 100.0%;"/>; In total: the aliens need 26 moves. The remainder after dividing 26 by 8 equals 2, so the answer to this test is 2.
[ { "input": "1 10", "output": "2" }, { "input": "3 8", "output": "2" }, { "input": "8 12", "output": "8" }, { "input": "4 84", "output": "80" }, { "input": "9 95", "output": "17" }, { "input": "331358794 820674098", "output": "2619146" }, { "input": "5 56", "output": "18" }, { "input": "10 22", "output": "0" }, { "input": "8 73", "output": "63" }, { "input": "7 63", "output": "44" }, { "input": "1 57", "output": "2" }, { "input": "6 5", "output": "3" }, { "input": "6 25", "output": "3" }, { "input": "1 39", "output": "2" }, { "input": "3 60", "output": "26" }, { "input": "2 81", "output": "8" }, { "input": "5 35", "output": "32" }, { "input": "8 100", "output": "60" }, { "input": "6 29", "output": "3" }, { "input": "7 90", "output": "26" }, { "input": "1 37", "output": "2" }, { "input": "7 34", "output": "10" }, { "input": "3 49", "output": "26" }, { "input": "1 38", "output": "2" }, { "input": "7 88", "output": "74" }, { "input": "9 30", "output": "2" }, { "input": "333734901 647005907", "output": "40746267" }, { "input": "140068687 419634856", "output": "40442298" }, { "input": "725891944 969448805", "output": "599793690" }, { "input": "792362041 423498933", "output": "182386349" }, { "input": "108260816 609551797", "output": "237749529" }, { "input": "593511479 711449475", "output": "641995841" }, { "input": "853906091 809812670", "output": "50540996" }, { "input": "549662082 945236243", "output": "239869294" }, { "input": "296519935 960061928", "output": "171150618" }, { "input": "854939092 4244941", "output": "2105846" }, { "input": "519976508 777084731", "output": "290288763" }, { "input": "264926775 887044705", "output": "448954191" }, { "input": "602799218 494169337", "output": "105935725" }, { "input": "880162386 653879733", "output": "193558859" }, { "input": "868095112 994962872", "output": "606909752" }, { "input": "622152471 448257864", "output": "210299666" }, { "input": "523061914 144515354", "output": "127493116" }, { "input": "596386879 356583466", "output": "134606022" }, { "input": "592821498 42617080", "output": "2923848" }, { "input": "647732356 84460643", "output": "28044795" }, { "input": "451688701 6561", "output": "6560" }, { "input": "661983283 9", "output": "8" }, { "input": "474026177 729", "output": "728" }, { "input": "822957727 6561", "output": "6560" }, { "input": "286996517 27", "output": "26" }, { "input": "321823343 19683", "output": "19682" }, { "input": "422262807 3", "output": "2" }, { "input": "624216668 19683", "output": "19682" }, { "input": "514853447 9", "output": "8" }, { "input": "916546405 6561", "output": "6560" }, { "input": "238972792 59049", "output": "59048" }, { "input": "450526186 6561", "output": "6560" }, { "input": "591892483 729", "output": "728" }, { "input": "357780112 9", "output": "8" }, { "input": "528551307 729", "output": "728" }, { "input": "199154351 3", "output": "2" }, { "input": "234899623 6561", "output": "6560" }, { "input": "576449056 59049", "output": "59048" }, { "input": "508185014 3", "output": "2" }, { "input": "969271595 9", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "2 9", "output": "8" }, { "input": "3 27", "output": "26" }, { "input": "2 3", "output": "2" }, { "input": "1 3", "output": "2" }, { "input": "3 9", "output": "8" }, { "input": "10 3", "output": "2" }, { "input": "4 81", "output": "80" }, { "input": "1 2", "output": "0" }, { "input": "4 27", "output": "26" }, { "input": "3 1", "output": "0" }, { "input": "3 3", "output": "2" } ]
62
0
0
10,289
630
Selection of Personnel
[ "combinatorics", "math" ]
null
null
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received *n* resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate.
The only line of the input contains one integer *n* (7<=≤<=*n*<=≤<=777) — the number of potential employees that sent resumes.
Output one integer — the number of different variants of group composition.
[ "7\n" ]
[ "29" ]
none
[ { "input": "7", "output": "29" }, { "input": "8", "output": "92" }, { "input": "9", "output": "246" }, { "input": "10", "output": "582" }, { "input": "321", "output": "66715035255088" }, { "input": "624", "output": "7147161340917624" }, { "input": "666", "output": "11292070960994226" }, { "input": "700", "output": "16017044425409540" }, { "input": "776", "output": "33019955679376860" }, { "input": "777", "output": "33319741730082870" } ]
77
1,536,000
3
10,296
464
Restore Cube
[ "brute force", "geometry" ]
null
null
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers — coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations. When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.
Each of the eight lines contains three space-separated integers — the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.
If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers — the restored coordinates of the points. The numbers in the *i*-th output line must be a permutation of the numbers in *i*-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them. If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.
[ "0 0 0\n0 0 1\n0 0 1\n0 0 1\n0 1 1\n0 1 1\n0 1 1\n1 1 1\n", "0 0 0\n0 0 0\n0 0 0\n0 0 0\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n" ]
[ "YES\n0 0 0\n0 0 1\n0 1 0\n1 0 0\n0 1 1\n1 0 1\n1 1 0\n1 1 1\n", "NO\n" ]
none
[ { "input": "0 0 0\n0 0 1\n0 0 1\n0 0 1\n0 1 1\n0 1 1\n0 1 1\n1 1 1", "output": "YES\n0 0 0\n0 0 1\n0 1 0\n1 0 0\n0 1 1\n1 0 1\n1 1 0\n1 1 1" }, { "input": "0 0 0\n0 0 0\n0 0 0\n0 0 0\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "output": "NO" }, { "input": "0 0 0\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1", "output": "YES\n0 0 0\n0 0 1\n0 1 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1" }, { "input": "6 -2 -2\n-5 1 -6\n6 -6 7\n6 3 4\n9 -7 8\n-9 -2 -6\n-9 1 6\n-9 -1 0", "output": "NO" }, { "input": "-5 -3 -8\n-8 8 -5\n-3 3 6\n6 3 8\n-8 6 -3\n8 -8 6\n-3 -5 3\n-5 3 8", "output": "YES\n-8 -5 -3\n-8 -5 8\n3 6 -3\n3 6 8\n-8 6 -3\n-8 6 8\n3 -5 -3\n3 -5 8" }, { "input": "-6 1 3\n-6 1 3\n-5 0 0\n-3 -3 7\n-2 6 6\n0 4 9\n0 4 9\n3 3 10", "output": "YES\n-6 1 3\n3 1 -6\n0 -5 0\n-3 7 -3\n6 -2 6\n0 4 9\n9 4 0\n3 10 3" }, { "input": "-6 -10 -13\n2 -13 -15\n2 -6 -10\n2 2 -15\n6 -1 -13\n6 2 -1\n11 -3 -13\n11 2 -3", "output": "YES\n-13 -10 -6\n-13 2 -15\n2 -10 -6\n2 2 -15\n-13 -1 6\n2 -1 6\n-13 11 -3\n2 11 -3" }, { "input": "-6 -8 0\n-6 4 16\n-6 8 -12\n-6 20 4\n14 -8 0\n14 4 16\n14 8 -12\n14 20 4", "output": "YES\n-8 -6 0\n4 -6 16\n8 -6 -12\n20 -6 4\n-8 14 0\n4 14 16\n8 14 -12\n20 14 4" }, { "input": "5 6 5\n5 3 3\n3 3 3\n5 5 3\n5 3 3\n5 3 3\n5 5 3\n3 5 5", "output": "NO" }, { "input": "5 2 0\n3 -3 -4\n3 -6 0\n4 3 -4\n-1 -2 5\n-6 -3 1\n-5 6 -1\n2 0 6", "output": "NO" }, { "input": "-369 846 805\n-293 846 -369\n729 846 805\n-252 -369 805\n846 -293 729\n805 729 -252\n-252 -369 -293\n729 -293 -252", "output": "YES\n-369 805 846\n-369 -293 846\n729 805 846\n-369 805 -252\n729 -293 846\n729 805 -252\n-369 -293 -252\n729 -293 -252" }, { "input": "-4897 -1234 2265\n-4897 -3800 2265\n-4897 -1234 -301\n-3800 -2331 -301\n-2331 -1234 2265\n-2331 -1234 -301\n-3800 -2331 2265\n-4897 -3800 -301", "output": "YES\n-4897 -1234 2265\n-4897 -3800 2265\n-4897 -1234 -301\n-2331 -3800 -301\n-2331 -1234 2265\n-2331 -1234 -301\n-2331 -3800 2265\n-4897 -3800 -301" }, { "input": "93 68 15\n93 43 23\n40 40 -30\n43 40 23\n93 -2 -5\n68 40 15\n93 40 -30\n40 -2 -5", "output": "YES\n15 68 93\n43 23 93\n-30 40 40\n43 23 40\n-2 -5 93\n15 68 40\n-30 40 93\n-2 -5 40" }, { "input": "887691 577079 -337\n-193088 -342950 -683216\n740176 -59645 -120545\n592743 -30828 -283642\n724594 652051 -193925\n87788 -179853 -845476\n665286 -133780 -846313\n828383 -75309 -786168", "output": "YES\n-337 577079 887691\n-193088 -683216 -342950\n-59645 740176 -120545\n592743 -30828 -283642\n652051 -193925 724594\n-845476 87788 -179853\n-133780 -846313 665286\n-786168 -75309 828383" }, { "input": "-745038 -470013 -245590\n168756 -684402 -45561\n-75879 -670042 -603554\n-168996 -611497 -184954\n-609406 -27512 -217363\n207089 -195060 33124\n-542918 348573 -255696\n229392 -187045 -108360", "output": "YES\n-745038 -470013 -245590\n-684402 -45561 168756\n-603554 -75879 -670042\n-168996 -611497 -184954\n-27512 -217363 -609406\n33124 207089 -195060\n-542918 348573 -255696\n-108360 -187045 229392" }, { "input": "-407872 -56765 -493131\n188018 -394436 -612309\n62413 -209242 162348\n-705817 -294501 -652655\n88703 241800 -871148\n-413679 -990326 -109927\n-533477 360978 -507187\n-275258 386648 43170", "output": "YES\n-493131 -407872 -56765\n-612309 188018 -394436\n162348 -209242 62413\n-294501 -705817 -652655\n241800 88703 -871148\n-413679 -109927 -990326\n360978 -507187 -533477\n43170 386648 -275258" }, { "input": "411586 -316610 -430676\n-305714 -461321 402733\n-451106 423163 -312524\n-339083 407500 -437486\n391156 -440891 -309800\n387070 -332273 -447701\n-468131 -328187 398647\n-334997 419077 -457916", "output": "YES\n-430676 -316610 411586\n-461321 -305714 402733\n-451106 -312524 423163\n-437486 -339083 407500\n-440891 -309800 391156\n-447701 -332273 387070\n-468131 -328187 398647\n-457916 -334997 419077" }, { "input": "-604518 -792421 -794968\n-639604 -845386 -664545\n-668076 -739456 -703162\n-770475 -692569 -880696\n-933661 -784375 -706917\n-774006 -756127 -774766\n-600987 -731410 -898351\n-847933 -827731 -710448", "output": "YES\n-794968 -792421 -604518\n-639604 -845386 -664545\n-703162 -739456 -668076\n-692569 -880696 -770475\n-784375 -933661 -706917\n-756127 -774766 -774006\n-731410 -898351 -600987\n-847933 -827731 -710448" }, { "input": "-83163 759234 174591\n77931 -88533 920334\n72567 974034 158481\n18861 169227 893484\n-61689 8127 839784\n678684 34971 13497\n174597 115521 732384\n77937 255141 812934", "output": "YES\n-83163 174591 759234\n-88533 77931 920334\n72567 158481 974034\n169227 18861 893484\n8127 -61689 839784\n13497 34971 678684\n174597 115521 732384\n77937 255141 812934" }, { "input": "-845276 245666 -196657\n-353213 152573 375200\n-725585 -73510 322004\n-565997 524945 282107\n228911 298862 -938369\n-103564 -126706 -632492\n99377 -50368 -260120\n-143461 471749 -472904", "output": "YES\n-845276 -196657 245666\n-353213 375200 152573\n-725585 322004 -73510\n-565997 282107 524945\n-938369 228911 298862\n-632492 -103564 -126706\n-260120 -50368 99377\n-472904 -143461 471749" }, { "input": "554547 757123 -270279\n935546 -159145 137545\n-160481 19278 -805548\n655167 -983971 121234\n119898 315968 -261101\n833590 -576147 -592458\n-58525 452591 -91856\n-694414 17942 -397724", "output": "YES\n-270279 554547 757123\n137545 -159145 935546\n-805548 19278 -160481\n-983971 121234 655167\n315968 -261101 119898\n-576147 -592458 833590\n-91856 452591 -58525\n-397724 -694414 17942" }, { "input": "36924 92680 350843\n697100 521211 -77688\n-351925 -610088 36924\n867468 -160261 -98984\n-181557 697100 -780456\n-588792 -133444 329547\n207292 -330629 71384\n526732 -759160 499915", "output": "YES\n36924 92680 350843\n697100 -77688 521211\n36924 -610088 -351925\n867468 -98984 -160261\n697100 -780456 -181557\n-133444 -588792 329547\n207292 71384 -330629\n526732 -759160 499915" }, { "input": "-593659 350000 928723\n620619 638757 388513\n620619 -882416 -632172\n600244 312515 -843903\n292140 -535799 -881388\n-940276 -573284 -574312\n330653 696617 -573284\n-265180 658104 -901763", "output": "YES\n-593659 350000 928723\n638757 388513 620619\n-632172 -882416 620619\n600244 -843903 312515\n292140 -535799 -881388\n-940276 -574312 -573284\n330653 696617 -573284\n-901763 658104 -265180" }, { "input": "861017 -462500 -274005\n652263 66796 629450\n232201 -329899 -968706\n497126 89886 993064\n-197575 -694067 -406329\n463768 728693 -836382\n-164771 -429142 519939\n-561466 761497 -42438", "output": "YES\n-462500 -274005 861017\n66796 652263 629450\n232201 -968706 -329899\n993064 89886 497126\n-694067 -406329 -197575\n463768 -836382 728693\n-164771 519939 -429142\n761497 -42438 -561466" }, { "input": "484554 -73939 147289\n333153 -73939 -152694\n-737739 33170 970401\n670418 784537 -73939\n333153 -152694 -737739\n-737739 670418 784537\n33170 -73939 970401\n-737739 484555 147289", "output": "NO" }, { "input": "-37445 372374 21189\n398542 125861 400869\n479373 -209864 -50773\n-364789 163030 67227\n505541 -260117 189198\n374701 -520 335205\n41059 -155444 -236032\n-26688 230533 -63613", "output": "NO" }, { "input": "163459 129764 357112\n277260 476888 633667\n476888 504608 -146791\n163459 633667 277260\n705 476888 781163\n163459 781163 705\n-146791 163459 504608\n357112 129764 476888", "output": "YES\n129764 163459 357112\n277260 476888 633667\n-146791 476888 504608\n277260 163459 633667\n705 476888 781163\n705 163459 781163\n-146791 163459 504608\n129764 476888 357112" }, { "input": "486623 24823 303304\n-389873 -376490 -388969\n170755 -644350 631652\n291143 -838926 -571066\n984320 -169753 36666\n-157910 -911574 643812\n365331 -194393 -49365\n-716998 -37204 292047", "output": "NO" }, { "input": "120639 -932662 -1032\n983000 -56439 15066\n-322992 -369232 -780849\n339080 -136928 -886422\n419570 845049 337026\n900456 201129 -288742\n-700359 578496 274688\n764559 -224350 -564462", "output": "NO" }, { "input": "-223515 128661 119249\n-83250 119249 203469\n278216 128661 -223515\n-298323 268926 278216\n278216 -158058 343734\n119249 -158058 343734\n-83250 278216 203469\n119249 -298323 -391850", "output": "NO" }, { "input": "802442 276413 311941\n132940 -916927 26771\n-629566 336080 371608\n-165395 813416 86438\n-404063 742775 288571\n848944 86438 -200923\n-689233 -344396 -379924\n97412 26771 -881399", "output": "NO" }, { "input": "830446 -93089 -271247\n50376 285279 761701\n509464 371358 90913\n-242554 -825792 165148\n-552177 744367 417385\n-403353 -293940 446078\n-437405 141814 -586870\n101762 55735 -896493", "output": "NO" }, { "input": "-110591 329051 328269\n611888 45432 657925\n493733 776570 273666\n163587 -119250 273667\n392312 557286 877991\n557286 -220671 265008\n713309 173028 -55989\n891924 227630 429690", "output": "NO" }, { "input": "-431644 -468238 -47168\n-152500 38126 -96046\n-507008 604168 -871390\n33597 -320912 410318\n231976 -765065 -282142\n90050 317270 -485921\n-693104 -301158 -245547\n-134816 689462 -299825", "output": "NO" }, { "input": "-1 1 1\n0 1 1\n1 1 0\n1 0 0\n0 1 0\n1 1 1\n0 0 0\n0 0 1", "output": "NO" }, { "input": "-1000000 1000000 1000000\n-1000000 -1000000 -1000000\n-1000000 1000000 -1000000\n1000000 1000000 1000000\n1000000 -1000000 -1000000\n-1000000 1000000 1000000\n-1000000 -1000000 1000000\n1000000 1000000 -1000000", "output": "YES\n-1000000 1000000 1000000\n-1000000 -1000000 -1000000\n-1000000 -1000000 1000000\n1000000 1000000 1000000\n-1000000 1000000 -1000000\n1000000 -1000000 1000000\n1000000 -1000000 -1000000\n1000000 1000000 -1000000" }, { "input": "-1000000 1000000 1000000\n-1000000 1000000 -1000000\n-1000000 1000000 -1000000\n1000000 -1000000 1000000\n1000000 1000000 1000000\n-1000000 -1000000 1000000\n999999 1000000 -1000000\n-1000000 -1000000 -1000000", "output": "NO" }, { "input": "-96608 -96608 100000\n100000 100000 -96608\n100000 -96608 -96608\n-96608 -96608 -96608\n-96608 100000 100000\n100000 100000 100000\n100000 100000 -96608\n-96608 -96608 100000", "output": "YES\n-96608 -96608 100000\n-96608 100000 100000\n-96608 100000 -96608\n-96608 -96608 -96608\n100000 -96608 100000\n100000 100000 100000\n100000 100000 -96608\n100000 -96608 -96608" }, { "input": "65536 0 65536\n65536 0 0\n0 65536 0\n65536 65536 65536\n65536 0 65536\n0 0 0\n0 0 65536\n65536 0 65536", "output": "YES\n0 65536 65536\n0 0 65536\n0 65536 0\n65536 65536 65536\n65536 0 65536\n0 0 0\n65536 0 0\n65536 65536 0" }, { "input": "-524288 -524288 -524288\n-524288 524288 -524288\n-524288 -524288 524288\n-524288 524288 524288\n524288 -524288 -524288\n-524288 524288 524288\n524288 524288 524288\n524288 524288 -524288", "output": "YES\n-524288 -524288 -524288\n-524288 -524288 524288\n-524288 524288 -524288\n-524288 524288 524288\n524288 -524288 -524288\n524288 -524288 524288\n524288 524288 524288\n524288 524288 -524288" }, { "input": "524288 -524288 524288\n-524288 -524288 -524288\n524288 -524288 -524288\n524288 524288 -524288\n524288 -524288 524288\n524288 524288 524288\n-524288 524288 -524288\n-524289 524288 -524288", "output": "NO" }, { "input": "0 0 0\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n5 5 5\n6 6 6\n7 7 7", "output": "NO" }, { "input": "0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0", "output": "NO" }, { "input": "0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0", "output": "NO" }, { "input": "1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "output": "NO" }, { "input": "0 0 1\n0 0 1\n0 0 1\n0 0 1\n0 0 1\n0 0 1\n0 0 1\n0 0 1", "output": "NO" }, { "input": "0 0 0\n0 0 939177\n0 0 939177\n0 0 939177\n0 939177 939177\n0 939177 939177\n0 939177 939177\n939177 939177 939177", "output": "YES\n0 0 0\n0 0 939177\n0 939177 0\n939177 0 0\n0 939177 939177\n939177 0 939177\n939177 939177 0\n939177 939177 939177" } ]
15
0
-1
10,299
5
Follow Traffic Rules
[ "implementation", "math" ]
D. Follow Traffic Rules
1
64
Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit peculiar, because they limit the speed only at that point on the road where they are placed. Right after passing the sign it is allowed to drive at any speed. It is known that the car of an average Berland citizen has the acceleration (deceleration) speed of *a* km/h2, and has maximum speed of *v* km/h. The road has the length of *l* km, and the speed sign, limiting the speed to *w* km/h, is placed *d* km (1<=≤<=*d*<=&lt;<=*l*) away from the capital of Berland. The car has a zero speed at the beginning of the journey. Find the minimum time that an average Berland citizen will need to get from the capital to Bercouver, if he drives at the optimal speed. The car can enter Bercouver at any speed.
The first line of the input file contains two integer numbers *a* and *v* (1<=≤<=*a*,<=*v*<=≤<=10000). The second line contains three integer numbers *l*, *d* and *w* (2<=≤<=*l*<=≤<=10000; 1<=≤<=*d*<=&lt;<=*l*; 1<=≤<=*w*<=≤<=10000).
Print the answer with at least five digits after the decimal point.
[ "1 1\n2 1 3\n", "5 70\n200 170 40\n" ]
[ "2.500000000000\n", "8.965874696353\n" ]
none
[ { "input": "1 1\n2 1 3", "output": "2.500000000000" }, { "input": "5 70\n200 170 40", "output": "8.965874696353" }, { "input": "6 80\n100 50 10", "output": "7.312347829731" }, { "input": "7 80\n100 50 50", "output": "5.345224838248" }, { "input": "8 80\n100 50 199", "output": "5.000000000000" }, { "input": "200 1000\n3 2 1", "output": "0.290249882934" }, { "input": "200 1000\n3 2 10000", "output": "0.173205080757" }, { "input": "200 1000\n1000 500 1023", "output": "3.162277660168" }, { "input": "200 1000\n1000 999 10", "output": "4.482261988326" }, { "input": "20 40\n10000 1 30", "output": "251.000000000000" }, { "input": "20 40\n10000 799 30", "output": "251.125000000000" }, { "input": "20 40\n9958 9799 30", "output": "250.075000000000" }, { "input": "9998 9999\n3 2 1", "output": "0.042231317453" }, { "input": "9998 9999\n3 2 6580", "output": "0.024497347285" }, { "input": "9998 9999\n800 40 10000", "output": "0.400040006001" }, { "input": "9998 9999\n800 516 124", "output": "0.668565367679" }, { "input": "4 120\n5112 3000 130", "output": "57.600000000000" }, { "input": "4 120\n5112 3000 113", "output": "57.702083333333" }, { "input": "9000 1\n10000 9999 1", "output": "10000.000055555556" }, { "input": "2 10000\n270 64 16", "output": "16.431676725155" }, { "input": "2 20\n270 64 16", "output": "18.500000000000" }, { "input": "2 16\n270 64 16", "output": "20.875000000000" }, { "input": "2000 10000\n8000 4000 4000", "output": "2.828427124746" }, { "input": "2000 4000\n8000 4000 4000", "output": "3.000000000000" }, { "input": "2000 10\n8000 4000 4000", "output": "800.002500000000" }, { "input": "7143 4847\n4193 2677 1991", "output": "1.438097228927" }, { "input": "5744 5873\n3706 1656 8898", "output": "1.142252435725" }, { "input": "7992 3250\n9987 6772 5806", "output": "3.276251405251" }, { "input": "240 4275\n6270 1836 6361", "output": "7.228416147400" }, { "input": "5369 9035\n1418 879 3344", "output": "0.726785762909" }, { "input": "7062 9339\n2920 1289 8668", "output": "0.909374070882" }, { "input": "8755 9643\n1193 27 3992", "output": "0.522044043034" }, { "input": "448 3595\n2696 1020 5667", "output": "3.469252698452" }, { "input": "2141 3899\n968 262 991", "output": "0.967126013479" }, { "input": "3834 4202\n2471 607 6315", "output": "1.136044961574" }, { "input": "5527 8154\n3974 3550 1639", "output": "1.555031897139" }, { "input": "7220 8458\n2246 1326 6963", "output": "0.788771617656" }, { "input": "8914 8762\n3749 1899 2287", "output": "1.172208101814" }, { "input": "607 2714\n2021 1483 3963", "output": "2.580499677039" }, { "input": "9788 8432\n2795 2025 3436", "output": "0.863942827831" }, { "input": "26 12\n17 13 29", "output": "1.647435897436" }, { "input": "12 42\n6 5 19", "output": "1.000000000000" }, { "input": "50 22\n42 1 12", "output": "2.129090909091" }, { "input": "38 3\n47 16 4", "output": "15.706140350877" }, { "input": "24 33\n35 2 45", "output": "1.748106060606" }, { "input": "11 13\n24 15 37", "output": "2.437062937063" }, { "input": "49 43\n12 6 30", "output": "0.699854212224" }, { "input": "35 23\n17 12 20", "output": "1.078881987578" }, { "input": "23 4\n5 2 13", "output": "1.336956521739" }, { "input": "8 28\n22 4 29", "output": "2.345207879912" }, { "input": "38 35\n16 12 38", "output": "0.917662935482" }, { "input": "21 41\n26 18 47", "output": "1.573591584939" }, { "input": "2 50\n21 1 6", "output": "4.582575694956" }, { "input": "32 7\n15 6 17", "output": "2.252232142857" }, { "input": "15 13\n10 3 26", "output": "1.202564102564" }, { "input": "46 20\n4 2 35", "output": "0.417028828114" }, { "input": "26 28\n46 9 44", "output": "2.181318681319" }, { "input": "9 35\n41 22 3", "output": "4.577276992968" }, { "input": "39 42\n35 19 12", "output": "1.803482716151" }, { "input": "28 24\n31 13 21", "output": "1.733630952381" } ]
154
20,172,800
0
10,301
291
Command Line Arguments
[ "*special", "implementation", "strings" ]
null
null
The problem describes the properties of a command line. The description somehow resembles the one you usually see in real operating systems. However, there are differences in the behavior. Please make sure you've read the statement attentively and use it as a formal document. In the Pindows operating system a strings are the lexemes of the command line — the first of them is understood as the name of the program to run and the following lexemes are its arguments. For example, as we execute the command " run.exe one, two . ", we give four lexemes to the Pindows command line: "run.exe", "one,", "two", ".". More formally, if we run a command that can be represented as string *s* (that has no quotes), then the command line lexemes are maximal by inclusion substrings of string *s* that contain no spaces. To send a string with spaces or an empty string as a command line lexeme, we can use double quotes. The block of characters that should be considered as one lexeme goes inside the quotes. Embedded quotes are prohibited — that is, for each occurrence of character """ we should be able to say clearly that the quotes are opening or closing. For example, as we run the command ""run.exe o" "" " ne, " two . " " ", we give six lexemes to the Pindows command line: "run.exe o", "" (an empty string), " ne, ", "two", ".", " " (a single space). It is guaranteed that each lexeme of the command line is either surrounded by spaces on both sides or touches the corresponding command border. One of its consequences is: the opening brackets are either the first character of the string or there is a space to the left of them. You have a string that consists of uppercase and lowercase English letters, digits, characters ".,?!"" and spaces. It is guaranteed that this string is a correct OS Pindows command line string. Print all lexemes of this command line string. Consider the character """ to be used only in order to denote a single block of characters into one command line lexeme. In particular, the consequence is that the given string has got an even number of such characters.
The single line contains a non-empty string *s*. String *s* consists of at most 105 characters. Each character is either an uppercase or a lowercase English letter, or a digit, or one of the ".,?!"" signs, or a space. It is guaranteed that the given string is some correct command line string of the OS Pindows. It is guaranteed that the given command line string contains at least one lexeme.
In the first line print the first lexeme, in the second line print the second one and so on. To make the output clearer, print the "&lt;" (less) character to the left of your lexemes and the "&gt;" (more) character to the right. Print the lexemes in the order in which they occur in the command. Please, follow the given output format strictly. For more clarifications on the output format see the test samples.
[ "\"RUn.exe O\" \"\" \" 2ne, \" two! . \" \"\n", "firstarg second \"\" \n" ]
[ "&lt;RUn.exe O&gt;\n&lt;&gt;\n&lt; 2ne, &gt;\n&lt;two!&gt;\n&lt;.&gt;\n&lt; &gt;\n", "&lt;firstarg&gt;\n&lt;second&gt;\n&lt;&gt;\n" ]
none
[ { "input": "\"RUn.exe O\" \"\" \" 2ne, \" two! . \" \"", "output": "<RUn.exe O>\n<>\n< 2ne, >\n<two!>\n<.>\n< >" }, { "input": " firstarg second \"\" ", "output": "<firstarg>\n<second>\n<>" }, { "input": " \" \" ", "output": "< >" }, { "input": " a \" \" a \"\" a ", "output": "<a>\n< >\n<a>\n<>\n<a>" }, { "input": "A", "output": "<A>" }, { "input": "\"\"", "output": "<>" }, { "input": "\" \"", "output": "< >" }, { "input": "\" \" \"wu\" \"\" \" \" \"\" \"\" \"\" ", "output": "< >\n<wu>\n<>\n< >\n<>\n<>\n<>" }, { "input": "\"7\" \"W \" \"\" \"\" \"a \" \"\" \"\" \"\" y ", "output": "<7>\n<W >\n<>\n<>\n<a >\n<>\n<>\n<>\n<y>" }, { "input": "\"\" \"\" \". \" \"A\" \"\" \"\" \"\" k \"\" ", "output": "<>\n<>\n<. >\n<A>\n<>\n<>\n<>\n<k>\n<>" }, { "input": " \"\" ZX \"\" \"\" \"b\" \"\" \" \" C \"\" \"\" \"\"", "output": "<>\n<ZX>\n<>\n<>\n<b>\n<>\n< >\n<C>\n<>\n<>\n<>" }, { "input": " \"\" N 3 \"\" \"4\" \"A\" \"k\" \" \" \"\" \"\" ", "output": "<>\n<N>\n<3>\n<>\n<4>\n<A>\n<k>\n< >\n<>\n<>" }, { "input": "B", "output": "<B>" }, { "input": "b ", "output": "<b>" }, { "input": "j ", "output": "<j>" }, { "input": " \"\"", "output": "<>" }, { "input": " Lii", "output": "<Lii>" }, { "input": " m Z \"\" \" p\"", "output": "<m>\n<Z>\n<>\n< p>" } ]
857
11,366,400
3
10,343
246
Beauty Pageant
[ "brute force", "constructive algorithms", "greedy" ]
null
null
General Payne has a battalion of *n* soldiers. The soldiers' beauty contest is coming up, it will last for *k* days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The value *a**i* represents the beauty of the *i*-th soldier. On each of *k* days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of *k* days the beauty of the sent detachment should be unique. In other words, all *k* beauties of the sent detachments must be distinct numbers. Help Payne choose *k* detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
The first line contains two integers *n*, *k* (1<=≤<=*n*<=≤<=50; 1<=≤<=*k*<=≤<= ) — the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=107) — the beauties of the battalion soldiers. It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Print *k* lines: in the *i*-th line print the description of the detachment that will participate in the pageant on the *i*-th day. The description consists of integer *c**i* (1<=≤<=*c**i*<=≤<=*n*) — the number of soldiers in the detachment on the *i*-th day of the pageant and *c**i* distinct integers *p*1,<=*i*,<=*p*2,<=*i*,<=...,<=*p**c**i*,<=*i* — the beauties of the soldiers in the detachment on the *i*-th day of the pageant. The beauties of the soldiers are allowed to print in any order. Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
[ "3 3\n1 2 3\n", "2 1\n7 12\n" ]
[ "1 1\n1 2\n2 3 2\n", "1 12 \n" ]
none
[ { "input": "3 3\n1 2 3", "output": "1 1\n1 2\n2 3 2" }, { "input": "2 1\n7 12", "output": "1 12 " }, { "input": "1 1\n1000", "output": "1 1000 " }, { "input": "5 8\n10 3 8 31 20", "output": "1 31 \n1 20 \n1 10 \n1 8 \n1 3 \n2 31 20 \n2 31 10 \n2 31 8 " }, { "input": "5 15\n1 2 3 4 5", "output": "1 5 \n1 4 \n1 3 \n1 2 \n1 1 \n2 5 4 \n2 5 3 \n2 5 2 \n2 5 1 \n3 5 4 3 \n3 5 4 2 \n3 5 4 1 \n4 5 4 3 2 \n4 5 4 3 1 \n5 5 4 3 2 1 " }, { "input": "8 25\n6 8 3 7 2 1 4 9", "output": "1 9 \n1 8 \n1 7 \n1 6 \n1 4 \n1 3 \n1 2 \n1 1 \n2 9 8 \n2 9 7 \n2 9 6 \n2 9 4 \n2 9 3 \n2 9 2 \n2 9 1 \n3 9 8 7 \n3 9 8 6 \n3 9 8 4 \n3 9 8 3 \n3 9 8 2 \n3 9 8 1 \n4 9 8 7 6 \n4 9 8 7 4 \n4 9 8 7 3 \n4 9 8 7 2 " }, { "input": "10 9\n5 10 2 14 15 6 3 11 4 1", "output": "1 15 \n1 14 \n1 11 \n1 10 \n1 6 \n1 5 \n1 4 \n1 3 \n1 2 " }, { "input": "10 27\n17 53 94 95 57 36 47 68 48 16", "output": "1 95 \n1 94 \n1 68 \n1 57 \n1 53 \n1 48 \n1 47 \n1 36 \n1 17 \n1 16 \n2 95 94 \n2 95 68 \n2 95 57 \n2 95 53 \n2 95 48 \n2 95 47 \n2 95 36 \n2 95 17 \n2 95 16 \n3 95 94 68 \n3 95 94 57 \n3 95 94 53 \n3 95 94 48 \n3 95 94 47 \n3 95 94 36 \n3 95 94 17 \n3 95 94 16 " }, { "input": "6 5\n17 35 15 11 33 39", "output": "1 39 \n1 35 \n1 33 \n1 17 \n1 15 " }, { "input": "10 27\n17 53 94 95 57 36 47 68 48 16", "output": "1 95 \n1 94 \n1 68 \n1 57 \n1 53 \n1 48 \n1 47 \n1 36 \n1 17 \n1 16 \n2 95 94 \n2 95 68 \n2 95 57 \n2 95 53 \n2 95 48 \n2 95 47 \n2 95 36 \n2 95 17 \n2 95 16 \n3 95 94 68 \n3 95 94 57 \n3 95 94 53 \n3 95 94 48 \n3 95 94 47 \n3 95 94 36 \n3 95 94 17 \n3 95 94 16 " }, { "input": "30 122\n5858 8519 5558 2397 3059 3710 6238 8547 2167 9401 471 9160 8505 5876 4373 1596 2535 2592 7630 6304 3761 8752 60 3735 6760 999 4616 8695 5471 4107", "output": "1 9401 \n1 9160 \n1 8752 \n1 8695 \n1 8547 \n1 8519 \n1 8505 \n1 7630 \n1 6760 \n1 6304 \n1 6238 \n1 5876 \n1 5858 \n1 5558 \n1 5471 \n1 4616 \n1 4373 \n1 4107 \n1 3761 \n1 3735 \n1 3710 \n1 3059 \n1 2592 \n1 2535 \n1 2397 \n1 2167 \n1 1596 \n1 999 \n1 471 \n1 60 \n2 9401 9160 \n2 9401 8752 \n2 9401 8695 \n2 9401 8547 \n2 9401 8519 \n2 9401 8505 \n2 9401 7630 \n2 9401 6760 \n2 9401 6304 \n2 9401 6238 \n2 9401 5876 \n2 9401 5858 \n2 9401 5558 \n2 9401 5471 \n2 9401 4616 \n2 9401 4373 \n2 9401 4107 \n2 9401 ..." }, { "input": "40 57\n126032 9927136 5014907 292040 7692407 6366126 7729668 2948494 7684624 1116536 1647501 1431473 9383644 973174 1470440 700000 7802576 6112611 3601596 892656 6128849 2872763 8432319 3811223 7102327 9934716 5184890 6025259 9459149 3290088 738057 6728294 2688654 8600385 5985112 7644837 6567914 2828556 7564262 6794404", "output": "1 9934716 \n1 9927136 \n1 9459149 \n1 9383644 \n1 8600385 \n1 8432319 \n1 7802576 \n1 7729668 \n1 7692407 \n1 7684624 \n1 7644837 \n1 7564262 \n1 7102327 \n1 6794404 \n1 6728294 \n1 6567914 \n1 6366126 \n1 6128849 \n1 6112611 \n1 6025259 \n1 5985112 \n1 5184890 \n1 5014907 \n1 3811223 \n1 3601596 \n1 3290088 \n1 2948494 \n1 2872763 \n1 2828556 \n1 2688654 \n1 1647501 \n1 1470440 \n1 1431473 \n1 1116536 \n1 973174 \n1 892656 \n1 738057 \n1 700000 \n1 292040 \n1 126032 \n2 9934716 9927136 \n2 9934716 9459149..." }, { "input": "50 813\n7449220 5273373 3201959 2504940 1861950 5457724 7770654 5521932 3601175 8613797 5015473 3267679 5852552 317709 8222785 3095558 7401768 8363473 1465064 9308012 4880614 7406265 9829434 9196038 3063370 237239 8633093 2256018 5444025 8093607 7099410 9798618 7512880 5806095 3225443 3861872 1158790 4245341 4542965 378481 7628588 4918701 1031421 1230404 8413677 7381891 9338029 3206618 1658288 4721546", "output": "1 9829434 \n1 9798618 \n1 9338029 \n1 9308012 \n1 9196038 \n1 8633093 \n1 8613797 \n1 8413677 \n1 8363473 \n1 8222785 \n1 8093607 \n1 7770654 \n1 7628588 \n1 7512880 \n1 7449220 \n1 7406265 \n1 7401768 \n1 7381891 \n1 7099410 \n1 5852552 \n1 5806095 \n1 5521932 \n1 5457724 \n1 5444025 \n1 5273373 \n1 5015473 \n1 4918701 \n1 4880614 \n1 4721546 \n1 4542965 \n1 4245341 \n1 3861872 \n1 3601175 \n1 3267679 \n1 3225443 \n1 3206618 \n1 3201959 \n1 3095558 \n1 3063370 \n1 2504940 \n1 2256018 \n1 1861950 \n1 16582..." }, { "input": "50 836\n43 33 24 13 29 34 11 17 39 14 40 23 35 26 38 28 8 32 4 25 46 9 5 21 45 7 6 30 37 12 2 10 3 41 42 22 50 1 18 49 48 44 47 19 15 36 20 31 16 27", "output": "1 50 \n1 49 \n1 48 \n1 47 \n1 46 \n1 45 \n1 44 \n1 43 \n1 42 \n1 41 \n1 40 \n1 39 \n1 38 \n1 37 \n1 36 \n1 35 \n1 34 \n1 33 \n1 32 \n1 31 \n1 30 \n1 29 \n1 28 \n1 27 \n1 26 \n1 25 \n1 24 \n1 23 \n1 22 \n1 21 \n1 20 \n1 19 \n1 18 \n1 17 \n1 16 \n1 15 \n1 14 \n1 13 \n1 12 \n1 11 \n1 10 \n1 9 \n1 8 \n1 7 \n1 6 \n1 5 \n1 4 \n1 3 \n1 2 \n1 1 \n2 50 49 \n2 50 48 \n2 50 47 \n2 50 46 \n2 50 45 \n2 50 44 \n2 50 43 \n2 50 42 \n2 50 41 \n2 50 40 \n2 50 39 \n2 50 38 \n2 50 37 \n2 50 36 \n2 50 35 \n2 50 34 \n2 50 33 \n..." }, { "input": "50 423\n49 38 12 5 15 14 18 23 39 3 43 28 20 16 25 42 22 17 21 37 31 27 30 41 10 36 13 40 35 44 48 46 7 24 9 8 33 29 26 19 32 2 4 11 6 47 50 34 1 45", "output": "1 50 \n1 49 \n1 48 \n1 47 \n1 46 \n1 45 \n1 44 \n1 43 \n1 42 \n1 41 \n1 40 \n1 39 \n1 38 \n1 37 \n1 36 \n1 35 \n1 34 \n1 33 \n1 32 \n1 31 \n1 30 \n1 29 \n1 28 \n1 27 \n1 26 \n1 25 \n1 24 \n1 23 \n1 22 \n1 21 \n1 20 \n1 19 \n1 18 \n1 17 \n1 16 \n1 15 \n1 14 \n1 13 \n1 12 \n1 11 \n1 10 \n1 9 \n1 8 \n1 7 \n1 6 \n1 5 \n1 4 \n1 3 \n1 2 \n1 1 \n2 50 49 \n2 50 48 \n2 50 47 \n2 50 46 \n2 50 45 \n2 50 44 \n2 50 43 \n2 50 42 \n2 50 41 \n2 50 40 \n2 50 39 \n2 50 38 \n2 50 37 \n2 50 36 \n2 50 35 \n2 50 34 \n2 50 33 \n..." }, { "input": "50 870\n39 13 35 11 30 26 53 22 28 56 16 25 3 48 5 14 51 32 46 59 40 18 60 21 50 23 17 57 34 10 2 9 55 42 24 36 12 4 52 58 20 1 54 33 44 8 31 37 41 15", "output": "1 60 \n1 59 \n1 58 \n1 57 \n1 56 \n1 55 \n1 54 \n1 53 \n1 52 \n1 51 \n1 50 \n1 48 \n1 46 \n1 44 \n1 42 \n1 41 \n1 40 \n1 39 \n1 37 \n1 36 \n1 35 \n1 34 \n1 33 \n1 32 \n1 31 \n1 30 \n1 28 \n1 26 \n1 25 \n1 24 \n1 23 \n1 22 \n1 21 \n1 20 \n1 18 \n1 17 \n1 16 \n1 15 \n1 14 \n1 13 \n1 12 \n1 11 \n1 10 \n1 9 \n1 8 \n1 5 \n1 4 \n1 3 \n1 2 \n1 1 \n2 60 59 \n2 60 58 \n2 60 57 \n2 60 56 \n2 60 55 \n2 60 54 \n2 60 53 \n2 60 52 \n2 60 51 \n2 60 50 \n2 60 48 \n2 60 46 \n2 60 44 \n2 60 42 \n2 60 41 \n2 60 40 \n2 60 39 ..." }, { "input": "50 379\n67 54 43 61 55 58 11 21 24 5 41 30 65 19 32 31 39 28 40 27 14 2 8 64 60 23 66 20 53 63 51 57 34 48 4 49 25 47 7 44 62 15 52 13 36 9 38 1 17 10", "output": "1 67 \n1 66 \n1 65 \n1 64 \n1 63 \n1 62 \n1 61 \n1 60 \n1 58 \n1 57 \n1 55 \n1 54 \n1 53 \n1 52 \n1 51 \n1 49 \n1 48 \n1 47 \n1 44 \n1 43 \n1 41 \n1 40 \n1 39 \n1 38 \n1 36 \n1 34 \n1 32 \n1 31 \n1 30 \n1 28 \n1 27 \n1 25 \n1 24 \n1 23 \n1 21 \n1 20 \n1 19 \n1 17 \n1 15 \n1 14 \n1 13 \n1 11 \n1 10 \n1 9 \n1 8 \n1 7 \n1 5 \n1 4 \n1 2 \n1 1 \n2 67 66 \n2 67 65 \n2 67 64 \n2 67 63 \n2 67 62 \n2 67 61 \n2 67 60 \n2 67 58 \n2 67 57 \n2 67 55 \n2 67 54 \n2 67 53 \n2 67 52 \n2 67 51 \n2 67 49 \n2 67 48 \n2 67 47 ..." }, { "input": "50 270\n72 67 3 27 47 45 69 79 55 46 48 10 13 26 1 37 32 54 78 40 80 29 49 57 73 53 70 5 71 33 52 17 8 6 65 23 63 64 16 56 44 36 39 59 41 58 43 22 35 4", "output": "1 80 \n1 79 \n1 78 \n1 73 \n1 72 \n1 71 \n1 70 \n1 69 \n1 67 \n1 65 \n1 64 \n1 63 \n1 59 \n1 58 \n1 57 \n1 56 \n1 55 \n1 54 \n1 53 \n1 52 \n1 49 \n1 48 \n1 47 \n1 46 \n1 45 \n1 44 \n1 43 \n1 41 \n1 40 \n1 39 \n1 37 \n1 36 \n1 35 \n1 33 \n1 32 \n1 29 \n1 27 \n1 26 \n1 23 \n1 22 \n1 17 \n1 16 \n1 13 \n1 10 \n1 8 \n1 6 \n1 5 \n1 4 \n1 3 \n1 1 \n2 80 79 \n2 80 78 \n2 80 73 \n2 80 72 \n2 80 71 \n2 80 70 \n2 80 69 \n2 80 67 \n2 80 65 \n2 80 64 \n2 80 63 \n2 80 59 \n2 80 58 \n2 80 57 \n2 80 56 \n2 80 55 \n2 80 54..." }, { "input": "50 144\n9 97 15 22 69 27 7 23 84 73 74 60 94 43 98 13 4 63 49 31 93 6 75 32 99 68 48 16 54 20 38 40 65 34 28 21 55 79 50 2 18 95 25 56 77 71 52 10 47 36", "output": "1 99 \n1 98 \n1 97 \n1 95 \n1 94 \n1 93 \n1 84 \n1 79 \n1 77 \n1 75 \n1 74 \n1 73 \n1 71 \n1 69 \n1 68 \n1 65 \n1 63 \n1 60 \n1 56 \n1 55 \n1 54 \n1 52 \n1 50 \n1 49 \n1 48 \n1 47 \n1 43 \n1 40 \n1 38 \n1 36 \n1 34 \n1 32 \n1 31 \n1 28 \n1 27 \n1 25 \n1 23 \n1 22 \n1 21 \n1 20 \n1 18 \n1 16 \n1 15 \n1 13 \n1 10 \n1 9 \n1 7 \n1 6 \n1 4 \n1 2 \n2 99 98 \n2 99 97 \n2 99 95 \n2 99 94 \n2 99 93 \n2 99 84 \n2 99 79 \n2 99 77 \n2 99 75 \n2 99 74 \n2 99 73 \n2 99 71 \n2 99 69 \n2 99 68 \n2 99 65 \n2 99 63 \n2 99 6..." }, { "input": "50 263\n110 98 17 54 76 31 195 77 207 168 104 229 37 88 29 164 130 156 261 181 8 113 232 234 132 53 179 59 3 141 178 61 276 152 163 85 148 129 235 79 135 94 108 69 117 2 18 158 275 174", "output": "1 276 \n1 275 \n1 261 \n1 235 \n1 234 \n1 232 \n1 229 \n1 207 \n1 195 \n1 181 \n1 179 \n1 178 \n1 174 \n1 168 \n1 164 \n1 163 \n1 158 \n1 156 \n1 152 \n1 148 \n1 141 \n1 135 \n1 132 \n1 130 \n1 129 \n1 117 \n1 113 \n1 110 \n1 108 \n1 104 \n1 98 \n1 94 \n1 88 \n1 85 \n1 79 \n1 77 \n1 76 \n1 69 \n1 61 \n1 59 \n1 54 \n1 53 \n1 37 \n1 31 \n1 29 \n1 18 \n1 17 \n1 8 \n1 3 \n1 2 \n2 276 275 \n2 276 261 \n2 276 235 \n2 276 234 \n2 276 232 \n2 276 229 \n2 276 207 \n2 276 195 \n2 276 181 \n2 276 179 \n2 276 178 \n2 ..." }, { "input": "50 1260\n4 20 37 50 46 19 25 47 10 6 34 12 41 9 22 28 40 42 15 27 8 38 17 13 7 30 48 23 11 16 2 32 18 24 14 33 49 35 44 39 3 36 31 45 1 29 5 43 26 21", "output": "1 50 \n1 49 \n1 48 \n1 47 \n1 46 \n1 45 \n1 44 \n1 43 \n1 42 \n1 41 \n1 40 \n1 39 \n1 38 \n1 37 \n1 36 \n1 35 \n1 34 \n1 33 \n1 32 \n1 31 \n1 30 \n1 29 \n1 28 \n1 27 \n1 26 \n1 25 \n1 24 \n1 23 \n1 22 \n1 21 \n1 20 \n1 19 \n1 18 \n1 17 \n1 16 \n1 15 \n1 14 \n1 13 \n1 12 \n1 11 \n1 10 \n1 9 \n1 8 \n1 7 \n1 6 \n1 5 \n1 4 \n1 3 \n1 2 \n1 1 \n2 50 49 \n2 50 48 \n2 50 47 \n2 50 46 \n2 50 45 \n2 50 44 \n2 50 43 \n2 50 42 \n2 50 41 \n2 50 40 \n2 50 39 \n2 50 38 \n2 50 37 \n2 50 36 \n2 50 35 \n2 50 34 \n2 50 33 \n..." }, { "input": "49 1221\n30 1 8 22 39 19 49 48 7 43 24 31 29 3 44 14 38 27 4 23 32 25 15 36 40 35 10 13 28 20 21 45 9 2 33 6 5 42 47 18 37 26 17 41 46 11 34 12 16", "output": "1 49 \n1 48 \n1 47 \n1 46 \n1 45 \n1 44 \n1 43 \n1 42 \n1 41 \n1 40 \n1 39 \n1 38 \n1 37 \n1 36 \n1 35 \n1 34 \n1 33 \n1 32 \n1 31 \n1 30 \n1 29 \n1 28 \n1 27 \n1 26 \n1 25 \n1 24 \n1 23 \n1 22 \n1 21 \n1 20 \n1 19 \n1 18 \n1 17 \n1 16 \n1 15 \n1 14 \n1 13 \n1 12 \n1 11 \n1 10 \n1 9 \n1 8 \n1 7 \n1 6 \n1 5 \n1 4 \n1 3 \n1 2 \n1 1 \n2 49 48 \n2 49 47 \n2 49 46 \n2 49 45 \n2 49 44 \n2 49 43 \n2 49 42 \n2 49 41 \n2 49 40 \n2 49 39 \n2 49 38 \n2 49 37 \n2 49 36 \n2 49 35 \n2 49 34 \n2 49 33 \n2 49 32 \n2 49 31..." }, { "input": "40 816\n816843 900330 562275 683341 469585 146423 911678 402115 930078 168816 916945 431061 334812 205026 264126 227854 913266 866210 54081 956450 449344 904851 624237 701550 596898 291551 23284 479098 80555 289147 187677 980472 283817 162917 795597 631748 710693 76839 632833 204451", "output": "1 980472 \n1 956450 \n1 930078 \n1 916945 \n1 913266 \n1 911678 \n1 904851 \n1 900330 \n1 866210 \n1 816843 \n1 795597 \n1 710693 \n1 701550 \n1 683341 \n1 632833 \n1 631748 \n1 624237 \n1 596898 \n1 562275 \n1 479098 \n1 469585 \n1 449344 \n1 431061 \n1 402115 \n1 334812 \n1 291551 \n1 289147 \n1 283817 \n1 264126 \n1 227854 \n1 205026 \n1 204451 \n1 187677 \n1 168816 \n1 162917 \n1 146423 \n1 80555 \n1 76839 \n1 54081 \n1 23284 \n2 980472 956450 \n2 980472 930078 \n2 980472 916945 \n2 980472 913266 \n2 9..." }, { "input": "50 1267\n7449220 5273373 3201959 2504940 1861950 5457724 7770654 5521932 3601175 8613797 5015473 3267679 5852552 317709 8222785 3095558 7401768 8363473 1465064 9308012 4880614 7406265 9829434 9196038 3063370 237239 8633093 2256018 5444025 8093607 7099410 9798618 7512880 5806095 3225443 3861872 1158790 4245341 4542965 378481 7628588 4918701 1031421 1230404 8413677 7381891 9338029 3206618 1658288 4721546", "output": "1 9829434 \n1 9798618 \n1 9338029 \n1 9308012 \n1 9196038 \n1 8633093 \n1 8613797 \n1 8413677 \n1 8363473 \n1 8222785 \n1 8093607 \n1 7770654 \n1 7628588 \n1 7512880 \n1 7449220 \n1 7406265 \n1 7401768 \n1 7381891 \n1 7099410 \n1 5852552 \n1 5806095 \n1 5521932 \n1 5457724 \n1 5444025 \n1 5273373 \n1 5015473 \n1 4918701 \n1 4880614 \n1 4721546 \n1 4542965 \n1 4245341 \n1 3861872 \n1 3601175 \n1 3267679 \n1 3225443 \n1 3206618 \n1 3201959 \n1 3095558 \n1 3063370 \n1 2504940 \n1 2256018 \n1 1861950 \n1 16582..." }, { "input": "35 623\n5575 9829 2987 3856 893 1590 706 1270 3993 7532 4168 9800 7425 138 7824 5229 5204 3485 3591 3046 2844 7435 6180 1647 7885 4947 248 2797 4453 7217 9085 3406 8332 5288 6537", "output": "1 9829 \n1 9800 \n1 9085 \n1 8332 \n1 7885 \n1 7824 \n1 7532 \n1 7435 \n1 7425 \n1 7217 \n1 6537 \n1 6180 \n1 5575 \n1 5288 \n1 5229 \n1 5204 \n1 4947 \n1 4453 \n1 4168 \n1 3993 \n1 3856 \n1 3591 \n1 3485 \n1 3406 \n1 3046 \n1 2987 \n1 2844 \n1 2797 \n1 1647 \n1 1590 \n1 1270 \n1 893 \n1 706 \n1 248 \n1 138 \n2 9829 9800 \n2 9829 9085 \n2 9829 8332 \n2 9829 7885 \n2 9829 7824 \n2 9829 7532 \n2 9829 7435 \n2 9829 7425 \n2 9829 7217 \n2 9829 6537 \n2 9829 6180 \n2 9829 5575 \n2 9829 5288 \n2 9829 5229 \n2 98..." }, { "input": "50 1275\n10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 62", "output": "1 62 \n1 59 \n1 58 \n1 57 \n1 56 \n1 55 \n1 54 \n1 53 \n1 52 \n1 51 \n1 50 \n1 49 \n1 48 \n1 47 \n1 46 \n1 45 \n1 44 \n1 43 \n1 42 \n1 41 \n1 40 \n1 39 \n1 38 \n1 37 \n1 36 \n1 35 \n1 34 \n1 32 \n1 31 \n1 30 \n1 29 \n1 28 \n1 27 \n1 26 \n1 25 \n1 24 \n1 23 \n1 22 \n1 21 \n1 20 \n1 19 \n1 18 \n1 17 \n1 16 \n1 15 \n1 14 \n1 13 \n1 12 \n1 11 \n1 10 \n2 62 59 \n2 62 58 \n2 62 57 \n2 62 56 \n2 62 55 \n2 62 54 \n2 62 53 \n2 62 52 \n2 62 51 \n2 62 50 \n2 62 49 \n2 62 48 \n2 62 47 \n2 62 46 \n2 62 45 \n2 62 44 \n2..." }, { "input": "50 1275\n11 84 1000000 1000001 1000002 1000003 1000004 1000005 1000006 1000007 1000008 1000009 1000010 1000011 1000012 1000013 1000014 1000015 1000016 1000017 1000018 1000019 1000020 1000021 1000022 1000023 1000024 1000025 1000026 1000028 1000030 1000031 1000032 1000033 1000034 1000035 1000036 1000037 1000038 1000039 1000040 1000041 1000042 1000043 1000044 1000045 1000046 1000047 1000048 1000049", "output": "1 1000049 \n1 1000048 \n1 1000047 \n1 1000046 \n1 1000045 \n1 1000044 \n1 1000043 \n1 1000042 \n1 1000041 \n1 1000040 \n1 1000039 \n1 1000038 \n1 1000037 \n1 1000036 \n1 1000035 \n1 1000034 \n1 1000033 \n1 1000032 \n1 1000031 \n1 1000030 \n1 1000028 \n1 1000026 \n1 1000025 \n1 1000024 \n1 1000023 \n1 1000022 \n1 1000021 \n1 1000020 \n1 1000019 \n1 1000018 \n1 1000017 \n1 1000016 \n1 1000015 \n1 1000014 \n1 1000013 \n1 1000012 \n1 1000011 \n1 1000010 \n1 1000009 \n1 1000008 \n1 1000007 \n1 1000006 \n1 10000..." }, { "input": "50 1275\n1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 52 56", "output": "1 56 \n1 52 \n1 50 \n1 49 \n1 48 \n1 47 \n1 46 \n1 45 \n1 43 \n1 42 \n1 41 \n1 40 \n1 39 \n1 38 \n1 37 \n1 36 \n1 35 \n1 34 \n1 33 \n1 32 \n1 31 \n1 30 \n1 29 \n1 28 \n1 27 \n1 26 \n1 25 \n1 24 \n1 23 \n1 22 \n1 21 \n1 20 \n1 19 \n1 18 \n1 17 \n1 16 \n1 15 \n1 14 \n1 13 \n1 12 \n1 11 \n1 10 \n1 9 \n1 8 \n1 7 \n1 5 \n1 4 \n1 3 \n1 2 \n1 1 \n2 56 52 \n2 56 50 \n2 56 49 \n2 56 48 \n2 56 47 \n2 56 46 \n2 56 45 \n2 56 43 \n2 56 42 \n2 56 41 \n2 56 40 \n2 56 39 \n2 56 38 \n2 56 37 \n2 56 36 \n2 56 35 \n2 56 34 \n..." }, { "input": "50 1275\n1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 56", "output": "1 56 \n1 51 \n1 50 \n1 49 \n1 48 \n1 47 \n1 46 \n1 45 \n1 44 \n1 43 \n1 42 \n1 41 \n1 40 \n1 39 \n1 38 \n1 37 \n1 36 \n1 35 \n1 34 \n1 33 \n1 32 \n1 31 \n1 30 \n1 28 \n1 27 \n1 26 \n1 25 \n1 24 \n1 23 \n1 22 \n1 21 \n1 20 \n1 19 \n1 18 \n1 17 \n1 16 \n1 15 \n1 14 \n1 13 \n1 12 \n1 11 \n1 10 \n1 9 \n1 8 \n1 7 \n1 6 \n1 4 \n1 3 \n1 2 \n1 1 \n2 56 51 \n2 56 50 \n2 56 49 \n2 56 48 \n2 56 47 \n2 56 46 \n2 56 45 \n2 56 44 \n2 56 43 \n2 56 42 \n2 56 41 \n2 56 40 \n2 56 39 \n2 56 38 \n2 56 37 \n2 56 36 \n2 56 35 \n..." }, { "input": "50 1275\n2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 58", "output": "1 58 \n1 52 \n1 51 \n1 50 \n1 49 \n1 48 \n1 47 \n1 46 \n1 45 \n1 44 \n1 43 \n1 42 \n1 41 \n1 40 \n1 39 \n1 38 \n1 37 \n1 36 \n1 35 \n1 34 \n1 33 \n1 32 \n1 31 \n1 30 \n1 29 \n1 28 \n1 27 \n1 26 \n1 25 \n1 24 \n1 22 \n1 21 \n1 20 \n1 19 \n1 18 \n1 17 \n1 16 \n1 15 \n1 14 \n1 13 \n1 12 \n1 11 \n1 10 \n1 9 \n1 8 \n1 7 \n1 6 \n1 4 \n1 3 \n1 2 \n2 58 52 \n2 58 51 \n2 58 50 \n2 58 49 \n2 58 48 \n2 58 47 \n2 58 46 \n2 58 45 \n2 58 44 \n2 58 43 \n2 58 42 \n2 58 41 \n2 58 40 \n2 58 39 \n2 58 38 \n2 58 37 \n2 58 36 ..." }, { "input": "50 1275\n4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 30 31 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47 48 49 50 51 52 53 56 59", "output": "1 59 \n1 56 \n1 53 \n1 52 \n1 51 \n1 50 \n1 49 \n1 48 \n1 47 \n1 46 \n1 45 \n1 44 \n1 43 \n1 42 \n1 41 \n1 40 \n1 38 \n1 37 \n1 36 \n1 35 \n1 34 \n1 33 \n1 32 \n1 31 \n1 30 \n1 28 \n1 27 \n1 26 \n1 25 \n1 24 \n1 23 \n1 22 \n1 21 \n1 20 \n1 19 \n1 18 \n1 17 \n1 16 \n1 15 \n1 14 \n1 13 \n1 12 \n1 11 \n1 10 \n1 9 \n1 8 \n1 7 \n1 6 \n1 5 \n1 4 \n2 59 56 \n2 59 53 \n2 59 52 \n2 59 51 \n2 59 50 \n2 59 49 \n2 59 48 \n2 59 47 \n2 59 46 \n2 59 45 \n2 59 44 \n2 59 43 \n2 59 42 \n2 59 41 \n2 59 40 \n2 59 38 \n2 59 37..." }, { "input": "50 1275\n6 9 10 11 12 13 14 16 17 18 19 20 22 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 41 43 44 45 46 47 48 49 50 51 52 54 55 64 66 67 68 84 88 90 92", "output": "1 92 \n1 90 \n1 88 \n1 84 \n1 68 \n1 67 \n1 66 \n1 64 \n1 55 \n1 54 \n1 52 \n1 51 \n1 50 \n1 49 \n1 48 \n1 47 \n1 46 \n1 45 \n1 44 \n1 43 \n1 41 \n1 40 \n1 39 \n1 38 \n1 37 \n1 36 \n1 35 \n1 34 \n1 33 \n1 31 \n1 30 \n1 29 \n1 28 \n1 27 \n1 26 \n1 25 \n1 24 \n1 22 \n1 20 \n1 19 \n1 18 \n1 17 \n1 16 \n1 14 \n1 13 \n1 12 \n1 11 \n1 10 \n1 9 \n1 6 \n2 92 90 \n2 92 88 \n2 92 84 \n2 92 68 \n2 92 67 \n2 92 66 \n2 92 64 \n2 92 55 \n2 92 54 \n2 92 52 \n2 92 51 \n2 92 50 \n2 92 49 \n2 92 48 \n2 92 47 \n2 92 46 \n2 9..." }, { "input": "50 1275\n6 7 9 10 11 12 13 14 15 16 17 19 20 22 23 24 25 26 28 29 31 32 33 34 35 36 37 38 39 40 41 43 44 46 48 50 51 52 53 54 55 11656 22042 30478 68064 70277 74455 88403 93743 99342", "output": "1 99342 \n1 93743 \n1 88403 \n1 74455 \n1 70277 \n1 68064 \n1 30478 \n1 22042 \n1 11656 \n1 55 \n1 54 \n1 53 \n1 52 \n1 51 \n1 50 \n1 48 \n1 46 \n1 44 \n1 43 \n1 41 \n1 40 \n1 39 \n1 38 \n1 37 \n1 36 \n1 35 \n1 34 \n1 33 \n1 32 \n1 31 \n1 29 \n1 28 \n1 26 \n1 25 \n1 24 \n1 23 \n1 22 \n1 20 \n1 19 \n1 17 \n1 16 \n1 15 \n1 14 \n1 13 \n1 12 \n1 11 \n1 10 \n1 9 \n1 7 \n1 6 \n2 99342 93743 \n2 99342 88403 \n2 99342 74455 \n2 99342 70277 \n2 99342 68064 \n2 99342 30478 \n2 99342 22042 \n2 99342 11656 \n2 99342 5..." }, { "input": "3 6\n1 2 3", "output": "1 3 \n1 2 \n1 1 \n2 3 2 \n2 3 1 \n3 3 2 1 " } ]
154
0
0
10,365
926
Large Bouquets
[]
null
null
A flower shop has got *n* bouquets, and the *i*-th bouquet consists of *a**i* flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a large bouquet should be odd. Each of the initial bouquets can be a part of at most one large bouquet. If an initial bouquet becomes a part of a large bouquet, all its flowers are included in the large bouquet. Determine the maximum possible number of large bouquets Vasya can make.
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of initial bouquets. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the number of flowers in each of the initial bouquets.
Print the maximum number of large bouquets Vasya can make.
[ "5\n2 3 4 2 7\n", "6\n2 2 6 8 6 12\n", "3\n11 4 10\n" ]
[ "2\n", "0\n", "1\n" ]
In the first example Vasya can make 2 large bouquets. For example, the first bouquet can contain the first and the fifth initial bouquets (the total number of flowers is then equal to 9), and the second bouquet can consist of the second and the third initial bouquets (the total number of flowers is then equal to 7). The fourth initial bouquet is unused in this scheme. In the second example it is not possible to form a single bouquet with odd number of flowers. In the third example Vasya can make one large bouquet. For example, he can make it using all three initial bouquets. The size of the large bouquet is then equal to 11 + 4 + 10 = 25.
[ { "input": "5\n2 3 4 2 7", "output": "2" }, { "input": "6\n2 2 6 8 6 12", "output": "0" }, { "input": "3\n11 4 10", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "1\n999999", "output": "0" }, { "input": "1\n1000000", "output": "0" }, { "input": "4\n943543 151729 379602 589828", "output": "2" }, { "input": "2\n468463 62253", "output": "0" }, { "input": "3\n352987 849349 967007", "output": "1" }, { "input": "20\n274039 899325 798709 157662 963297 276599 529230 80095 252956 980560 358150 82383 29856 901568 123794 275349 512273 508369 120076 170206", "output": "10" }, { "input": "25\n742168 377547 485672 437223 96307 902863 759104 747933 512899 410317 588598 666688 823202 257684 520631 910066 168864 71499 899972 565350 764848 754913 929040 864132 289976", "output": "10" } ]
139
13,107,200
3
10,370
383
Milking cows
[ "data structures", "greedy" ]
null
null
Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk). Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, where *a**i* is 0 if the cow number *i* is facing left, and 1 if it is facing right.
Print a single integer, the minimum amount of lost milk. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "4\n0 0 1 0\n", "5\n1 0 1 0 1\n" ]
[ "1", "3" ]
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
[ { "input": "4\n0 0 1 0", "output": "1" }, { "input": "5\n1 0 1 0 1", "output": "3" }, { "input": "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0", "output": "416" }, { "input": "100\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 1 0 0 1 0 0 1 1 0 1 1 1 1 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 1 1 0 0 1 0 0", "output": "1446" }, { "input": "1\n1", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "2\n0 1", "output": "0" }, { "input": "2\n1 0", "output": "1" }, { "input": "2\n0 0", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "4\n1 1 1 1", "output": "0" } ]
78
0
0
10,379
852
Neural Network country
[ "dp", "matrices" ]
null
null
Due to the recent popularity of the Deep learning new countries are starting to look like Neural Networks. That is, the countries are being built deep with many layers, each layer possibly having many cities. They also have one entry, and one exit point. There are exactly *L* layers, each having *N* cities. Let us look at the two adjacent layers *L*1 and *L*2. Each city from the layer *L*1 is connected to each city from the layer *L*2 with the traveling cost *c**ij* for , and each pair of adjacent layers has the same cost in between their cities as any other pair (they just stacked the same layers, as usual). Also, the traveling costs to each city from the layer *L*2 are same for all cities in the *L*1, that is *c**ij* is the same for , and fixed *j*. Doctor G. needs to speed up his computations for this country so he asks you to find the number of paths he can take from entry to exit point such that his traveling cost is divisible by given number *M*.
The first line of input contains *N* (1<=≤<=*N*<=≤<=106), *L* (2<=≤<=*L*<=≤<=105) and *M* (2<=≤<=*M*<=≤<=100), the number of cities in each layer, the number of layers and the number that travelling cost should be divisible by, respectively. Second, third and fourth line contain *N* integers each denoting costs 0<=≤<=*cost*<=≤<=*M* from entry point to the first layer, costs between adjacent layers as described above, and costs from the last layer to the exit point.
Output a single integer, the number of paths Doctor G. can take which have total cost divisible by *M*, modulo 109<=+<=7.
[ "2 3 13\n4 6\n2 1\n3 4\n" ]
[ "2" ]
<img class="tex-graphics" src="https://espresso.codeforces.com/959c8bea1eef9daad659ecab34d36a2f692c5e88.png" style="max-width: 100.0%;max-height: 100.0%;"/> This is a country with 3 layers, each layer having 2 cities. Paths <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea33f7ca0560180dc03b2657e6a1f9fd874e5adc.png" style="max-width: 100.0%;max-height: 100.0%;"/>, and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4b3fe7f211ecca3ab05c72cd3b995d28d037ab45.png" style="max-width: 100.0%;max-height: 100.0%;"/> are the only paths having total cost divisible by 13. Notice that input edges for layer cities have the same cost, and that they are same for all layers.
[ { "input": "2 3 13\n4 6\n2 1\n3 4", "output": "2" }, { "input": "2 4 5\n1 1\n1 1\n1 1", "output": "16" }, { "input": "1 1234 5\n1\n1\n1", "output": "1" }, { "input": "3 2 2\n0 1 0\n0 0 1\n1 1 0", "output": "3" }, { "input": "5 4 3\n2 1 0 1 2\n0 1 2 1 0\n1 2 1 0 2", "output": "209" }, { "input": "4 4 4\n0 1 3 2\n1 2 0 3\n2 3 1 0", "output": "64" } ]
46
0
0
10,384
928
Dependency management
[ "*special", "graphs", "implementation" ]
null
null
Polycarp is currently developing a project in Vaja language and using a popular dependency management system called Vamen. From Vamen's point of view both Vaja project and libraries are treated projects for simplicity. A project in Vaja has its own uniqie non-empty name consisting of lowercase latin letters with length not exceeding 10 and version — positive integer from 1 to 106. Each project (keep in mind that it is determined by both its name and version) might depend on other projects. For sure, there are no cyclic dependencies. You're given a list of project descriptions. The first of the given projects is the one being developed by Polycarp at this moment. Help Polycarp determine all projects that his project depends on (directly or via a certain chain). It's possible that Polycarp's project depends on two different versions of some project. In this case collision resolving is applied, i.e. for each such project the system chooses the version that minimizes the distance from it to Polycarp's project. If there are several options, the newer (with the maximum version) is preferred. This version is considered actual; other versions and their dependencies are ignored. More formal, choose such a set of projects of minimum possible size that the following conditions hold: - Polycarp's project is chosen; - Polycarp's project depends (directly or indirectly) on all other projects in the set; - no two projects share the name; - for each project *x* that some other project in the set depends on we have either *x* or some *y* with other version and shorter chain to Polycarp's project chosen. In case of ties the newer one is chosen. Output all Polycarp's project's dependencies (Polycarp's project itself should't be printed) in lexicographical order.
The first line contains an only integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of projects in Vaja. The following lines contain the project descriptions. Each project is described by a line consisting of its name and version separated by space. The next line gives the number of direct dependencies (from 0 to *n*<=-<=1) and the dependencies themselves (one in a line) in arbitrary order. Each dependency is specified by its name and version. The projects are also given in arbitrary order, but the first of them is always Polycarp's. Project descriptions are separated by one empty line. Refer to samples for better understanding. It's guaranteed that there are no cyclic dependencies.
Output all Polycarp's project's dependencies in lexicographical order.
[ "4\na 3\n2\nb 1\nc 1\n \nb 2\n0\n \nb 1\n1\nb 2\n \nc 1\n1\nb 2\n", "9\ncodehorses 5\n3\nwebfrmk 6\nmashadb 1\nmashadb 2\n \ncommons 2\n0\n \nmashadb 3\n0\n \nwebfrmk 6\n2\nmashadb 3\ncommons 2\n \nextra 4\n1\nextra 3\n \nextra 3\n0\n \nextra 1\n0\n \nmashadb 1\n1\nextra 3\n \nmashadb 2\n1\nextra 1\n", "3\nabc 1\n2\nabc 3\ncba 2\n\nabc 3\n0\n\ncba 2\n0\n" ]
[ "2\nb 1\nc 1\n", "4\ncommons 2\nextra 1\nmashadb 2\nwebfrmk 6\n", "1\ncba 2\n" ]
The first sample is given in the pic below. Arrow from *A* to *B* means that *B* directly depends on *A*. Projects that Polycarp's project «a» (version 3) depends on are painted black. The second sample is again given in the pic below. Arrow from *A* to *B* means that *B* directly depends on *A*. Projects that Polycarp's project «codehorses» (version 5) depends on are paint it black. Note that «extra 1» is chosen instead of «extra 3» since «mashadb 1» and all of its dependencies are ignored due to «mashadb 2».
[ { "input": "4\na 3\n2\nb 1\nc 1\n\nb 2\n0\n\nb 1\n1\nb 2\n\nc 1\n1\nb 2", "output": "2\nb 1\nc 1" }, { "input": "9\ncodehorses 5\n3\nwebfrmk 6\nmashadb 1\nmashadb 2\n\ncommons 2\n0\n\nmashadb 3\n0\n\nwebfrmk 6\n2\nmashadb 3\ncommons 2\n\nextra 4\n1\nextra 3\n\nextra 3\n0\n\nextra 1\n0\n\nmashadb 1\n1\nextra 3\n\nmashadb 2\n1\nextra 1", "output": "4\ncommons 2\nextra 1\nmashadb 2\nwebfrmk 6" }, { "input": "3\nabc 1\n2\nabc 3\ncba 2\n\nabc 3\n0\n\ncba 2\n0", "output": "1\ncba 2" }, { "input": "1\nabc 1000000\n0", "output": "0" }, { "input": "3\nppdpd 283157\n1\npddpdpp 424025\n\nppdpd 529292\n1\nppdpd 283157\n\npddpdpp 424025\n0", "output": "1\npddpdpp 424025" }, { "input": "5\nabbzzz 646068\n0\n\nzabza 468048\n2\nbb 902619\nzabza 550912\n\nzabza 217401\n2\nabbzzz 646068\nbb 902619\n\nzabza 550912\n1\nzabza 217401\n\nbb 902619\n1\nabbzzz 646068", "output": "0" }, { "input": "5\nyyyy 223967\n1\nyyyyyyy 254197\n\nyyyyyyy 254197\n0\n\ny 442213\n0\n\ny 965022\n1\nyyyyyyy 254197\n\nyyyy 766922\n4\nyyyyyyy 254197\ny 442213\nyyyy 223967\ny 965022", "output": "1\nyyyyyyy 254197" }, { "input": "3\nvvgvvgv 991444\n1\ngvgvgvgvgg 206648\n\nvvgvvgv 296188\n0\n\ngvgvgvgvgg 206648\n1\nvvgvvgv 296188", "output": "1\ngvgvgvgvgg 206648" }, { "input": "5\ntctocototo 984516\n1\ncttocottt 486791\n\ntctocototo 688522\n2\ncttocottt 486791\ntctocototo 984516\n\ncttocottt 486791\n0\n\ntctocototo 676435\n1\ntctocototo 394244\n\ntctocototo 394244\n2\ntctocototo 688522\ncttocottt 486791", "output": "1\ncttocottt 486791" }, { "input": "5\nggggggggg 202537\n4\ngggggggg 868552\ngggg 234633\ngggg 402994\ngggggggg 86863\n\ngggg 402994\n0\n\ngggggggg 868552\n1\ngggg 234633\n\ngggg 234633\n1\ngggg 402994\n\ngggggggg 86863\n0", "output": "2\ngggg 402994\ngggggggg 868552" }, { "input": "4\ncf 1\n2\ndb 1\ndb 2\n\ndb 2\n0\n\ndb 1\n1\nold 1\n\nold 1\n0", "output": "1\ndb 2" }, { "input": "5\ncf 1\n2\ndb 1\ndb 2\n\ndb 2\n1\nold 1\n\ndb 1\n1\nold 2\n\nold 1\n0\n\nold 2\n0", "output": "2\ndb 2\nold 1" } ]
61
5,734,400
0
10,396
690
Collective Mindsets (easy)
[]
null
null
Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage. They will be *N* guests tonight: *N*<=-<=1 real zombies and a fake one, our Heidi. The living-dead love hierarchies as much as they love brains: each one has a unique rank in the range 1 to *N*<=-<=1, and Heidi, who still appears slightly different from the others, is attributed the highest rank, *N*. Tonight there will be a chest with brains on display and every attendee sees how many there are. These will then be split among the attendees according to the following procedure: The zombie of the highest rank makes a suggestion on who gets how many brains (every brain is an indivisible entity). A vote follows. If at least half of the attendees accept the offer, the brains are shared in the suggested way and the feast begins. But if majority is not reached, then the highest-ranked zombie is killed, and the next zombie in hierarchy has to make a suggestion. If he is killed too, then the third highest-ranked makes one, etc. (It's enough to have exactly half of the votes – in case of a tie, the vote of the highest-ranked alive zombie counts twice, and he will of course vote in favor of his own suggestion in order to stay alive.) You should know that zombies are very greedy and sly, and they know this too – basically all zombie brains are alike. Consequently, a zombie will never accept an offer which is suboptimal for him. That is, if an offer is not strictly better than a potential later offer, he will vote against it. And make no mistake: while zombies may normally seem rather dull, tonight their intellects are perfect. Each zombie's priorities for tonight are, in descending order: 1. survive the event (they experienced death already once and know it is no fun), 1. get as many brains as possible. Heidi goes first and must make an offer which at least half of the attendees will accept, and which allocates at least one brain for Heidi herself. What is the smallest number of brains that have to be in the chest for this to be possible?
The only line of input contains one integer: *N*, the number of attendees (1<=≤<=*N*<=≤<=109).
Output one integer: the smallest number of brains in the chest which allows Heidi to take one brain home.
[ "1\n", "4\n" ]
[ "1\n", "2\n" ]
[ { "input": "1", "output": "1" }, { "input": "4", "output": "2" }, { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "5", "output": "3" }, { "input": "6", "output": "3" }, { "input": "7", "output": "4" }, { "input": "8", "output": "4" }, { "input": "9", "output": "5" }, { "input": "10", "output": "5" }, { "input": "11", "output": "6" }, { "input": "12", "output": "6" }, { "input": "13", "output": "7" }, { "input": "14", "output": "7" }, { "input": "15", "output": "8" }, { "input": "16", "output": "8" }, { "input": "17", "output": "9" }, { "input": "18", "output": "9" }, { "input": "19", "output": "10" }, { "input": "20", "output": "10" }, { "input": "100", "output": "50" }, { "input": "9999", "output": "5000" }, { "input": "21736", "output": "10868" }, { "input": "873467", "output": "436734" }, { "input": "4124980", "output": "2062490" }, { "input": "536870910", "output": "268435455" }, { "input": "536870912", "output": "268435456" }, { "input": "876543210", "output": "438271605" }, { "input": "987654321", "output": "493827161" }, { "input": "1000000000", "output": "500000000" } ]
0
0
-1
10,403
0
none
[ "none" ]
null
null
You can perfectly predict the price of a certain stock for the next *N* days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you don't own any. At the end of the *N* days you would like to again own zero shares, but want to have as much money as possible.
Input begins with an integer *N* (2<=≤<=*N*<=≤<=3·105), the number of days. Following this is a line with exactly *N* integers *p*1,<=*p*2,<=...,<=*p**N* (1<=≤<=*p**i*<=≤<=106). The price of one share of stock on the *i*-th day is given by *p**i*.
Print the maximum amount of money you can end up with at the end of *N* days.
[ "9\n10 5 4 7 9 12 6 2 10\n", "20\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4\n" ]
[ "20\n", "41\n" ]
In the first example, buy a share at 5, buy another at 4, sell one at 9 and another at 12. Then buy at 2 and sell at 10. The total profit is  - 5 - 4 + 9 + 12 - 2 + 10 = 20.
[ { "input": "9\n10 5 4 7 9 12 6 2 10", "output": "20" }, { "input": "20\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4", "output": "41" }, { "input": "20\n9 29 8 9 13 4 14 27 16 11 27 14 4 29 23 17 3 9 30 19", "output": "147" }, { "input": "100\n411 642 560 340 276 440 515 519 182 314 35 227 390 136 97 5 502 584 567 79 543 444 413 463 455 316 545 329 437 443 9 435 291 384 328 501 603 234 285 297 453 587 550 72 130 163 282 298 605 349 270 198 24 179 243 92 115 56 83 26 3 456 622 325 366 360 299 153 140 552 216 117 61 307 278 189 496 562 38 527 566 503 303 16 36 286 632 196 395 452 194 77 321 615 356 250 381 174 139 123", "output": "13765" }, { "input": "20\n499559 302871 194704 903169 447219 409938 42087 753609 589270 719332 855199 609182 315644 980473 966759 851389 900793 905536 258772 453222", "output": "4620235" }, { "input": "47\n403136 169462 358897 935260 150614 688938 111490 148144 462915 753991 551831 303917 772190 188564 854800 7094 491120 997932 271873 236736 797113 427200 681780 911765 217707 339475 313125 56785 749677 313468 902148 993064 747609 387815 768631 41886 68862 707668 32853 653517 941150 858711 562604 867235 840369 337814 129019", "output": "12525965" }, { "input": "2\n4 77", "output": "73" } ]
46
0
0
10,404
939
Hamster Farm
[ "implementation" ]
null
null
Dima has a hamsters farm. Soon *N* hamsters will grow up on it and Dima will sell them in a city nearby. Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely full with hamsters. Dima can buy boxes at a factory. The factory produces boxes of *K* kinds, boxes of the *i*-th kind can contain in themselves *a**i* hamsters. Dima can buy any amount of boxes, but he should buy boxes of only one kind to get a wholesale discount. Of course, Dima would buy boxes in such a way that each box can be completely filled with hamsters and transported to the city. If there is no place for some hamsters, Dima will leave them on the farm. Find out how many boxes and of which type should Dima buy to transport maximum number of hamsters.
The first line contains two integers *N* and *K* (0<=≤<=*N*<=≤<=1018, 1<=≤<=*K*<=≤<=105) — the number of hamsters that will grow up on Dima's farm and the number of types of boxes that the factory produces. The second line contains *K* integers *a*1, *a*2, ..., *a**K* (1<=≤<=*a**i*<=≤<=1018 for all *i*) — the capacities of boxes.
Output two integers: the type of boxes that Dima should buy and the number of boxes of that type Dima should buy. Types of boxes are numbered from 1 to *K* in the order they are given in input. If there are many correct answers, output any of them.
[ "19 3\n5 4 10\n", "28 3\n5 6 30\n" ]
[ "2 4\n", "1 5\n" ]
none
[ { "input": "19 3\n5 4 10", "output": "2 4" }, { "input": "28 3\n5 6 30", "output": "1 5" }, { "input": "1 1\n1", "output": "1 1" }, { "input": "0 2\n2 3", "output": "1 0" }, { "input": "30 4\n4 5 5 4", "output": "2 6" }, { "input": "120 7\n109 92 38 38 49 38 92", "output": "3 3" }, { "input": "357 40\n12 10 12 11 12 12 12 10 10 10 12 12 12 12 12 10 12 10 10 10 11 10 12 10 12 10 12 10 10 12 12 12 12 10 10 10 12 12 12 12", "output": "4 32" }, { "input": "587 100\n92 92 76 95 61 60 64 79 64 96 63 92 60 61 95 71 60 61 65 63 84 76 98 63 90 61 61 71 63 61 95 90 79 71 77 67 63 61 63 60 100 71 98 88 67 95 60 61 79 76 70 61 64 65 64 77 96 95 84 100 67 60 84 92 70 100 63 79 61 77 92 74 60 90 84 80 76 61 88 79 64 61 79 60 61 67 98 98 92 76 61 60 80 77 77 76 63 88 99 70", "output": "19 9" }, { "input": "98765 30\n89 841 599 240 356 599 92 305 305 536 356 92 622 1000 751 522 89 149 356 598 305 518 996 92 622 536 356 91 779 770", "output": "28 1085" }, { "input": "947264836 50\n977141206 956777871 186433588 538218068 759102378 327484438 88827268 266300062 670616672 756092978 414181331 913675814 898008516 343057716 99416265 236586817 52751842 550467703 684435578 844649988 917709231 550467703 493542638 707106470 414181331 198095018 913675814 99416265 550467703 679553907 186433588 355713982 670616672 977141206 504598561 327484438 414181331 463431413 546229641 132582931 463431413 759102378 273063720 683939057 924604119 759102378 463431413 52751842 552131077 903126340", "output": "16 4" }, { "input": "600003000040000507 10\n334302557805985467 334302557805985467 681026146296527968 157006854340095780 188330644415015186 803011712275585087 638039699540420111 638039699540420111 600874219702299205 923891462598005659", "output": "5 3" }, { "input": "666 2\n1 300", "output": "1 666" }, { "input": "899999999999999991 1\n199999999999999998", "output": "1 4" }, { "input": "10 1\n11", "output": "1 0" }, { "input": "999999999999999999 1\n500000000000000000", "output": "1 1" }, { "input": "2 1\n2", "output": "1 1" }, { "input": "199999999999999999 1\n100000000000000000", "output": "1 1" }, { "input": "999999999999999999 1\n1000000000000000000", "output": "1 0" }, { "input": "1000000000000000000 1\n500000000000000001", "output": "1 1" }, { "input": "1000000000000000000 1\n2", "output": "1 500000000000000000" }, { "input": "1000000000000000000 5\n500000000000000010 500000000000000010 500000000000000010 500000000000000010 500000000000000030", "output": "5 1" }, { "input": "1000000000000000000 1\n900000000000000000", "output": "1 1" } ]
140
10,342,400
3
10,416
384
Multitasking
[ "greedy", "implementation", "sortings", "two pointers" ]
null
null
Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort *n* arrays simultaneously, each array consisting of *m* integers. Iahub can choose a pair of distinct indices *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*m*,<=*i*<=≠<=*j*). Then in each array the values at positions *i* and *j* are swapped only if the value at position *i* is strictly greater than the value at position *j*. Iahub wants to find an array of pairs of distinct indices that, chosen in order, sort all of the *n* arrays in ascending or descending order (the particular order is given in input). The size of the array can be at most (at most pairs). Help Iahub, find any suitable array.
The first line contains three integers *n* (1<=≤<=<=*n*<=≤<=1000), *m* (1<=≤<=*m*<=≤<=<=100) and *k*. Integer *k* is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line *i* of the next *n* lines contains *m* integers separated by a space, representing the *i*-th array. For each element *x* of the array *i*, 1<=≤<=*x*<=≤<=106 holds.
On the first line of the output print an integer *p*, the size of the array (*p* can be at most ). Each of the next *p* lines must contain two distinct integers *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*m*,<=*i*<=≠<=*j*), representing the chosen indices. If there are multiple correct answers, you can print any.
[ "2 5 0\n1 3 2 5 4\n1 4 3 2 5\n", "3 2 1\n1 2\n2 3\n3 4\n" ]
[ "3\n2 4\n2 3\n4 5\n", "1\n2 1\n" ]
Consider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5].
[ { "input": "2 5 0\n1 3 2 5 4\n1 4 3 2 5", "output": "3\n2 4\n2 3\n4 5" }, { "input": "3 2 1\n1 2\n2 3\n3 4", "output": "1\n2 1" }, { "input": "2 5 0\n836096 600367 472071 200387 79763\n714679 505282 233544 157810 152591", "output": "10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5" }, { "input": "2 5 1\n331081 525217 574775 753333 840639\n225591 347017 538639 620341 994088", "output": "10\n2 1\n3 1\n4 1\n5 1\n3 2\n4 2\n5 2\n4 3\n5 3\n5 4" }, { "input": "1 1 0\n1", "output": "0" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "2 1 0\n1\n2", "output": "0" }, { "input": "1 2 1\n2 1", "output": "1\n2 1" }, { "input": "2 2 0\n2 1\n3 1", "output": "1\n1 2" }, { "input": "2 2 0\n2 1\n1 3", "output": "1\n1 2" }, { "input": "2 2 1\n2 1\n3 1", "output": "1\n2 1" } ]
92
3,481,600
3
10,428
0
none
[ "none" ]
null
null
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following. You have an array *a* of length 2*n* and *m* queries on it. The *i*-th query is described by an integer *q**i*. In order to perform the *i*-th query you must: - split the array into 2*n*<=-<=*q**i* parts, where each part is a subarray consisting of 2*q**i* numbers; the *j*-th subarray (1<=≤<=*j*<=≤<=2*n*<=-<=*q**i*) should contain the elements *a*[(*j*<=-<=1)·2*q**i*<=+<=1],<=*a*[(*j*<=-<=1)·2*q**i*<=+<=2],<=...,<=*a*[(*j*<=-<=1)·2*q**i*<=+<=2*q**i*]; - reverse each of the subarrays; - join them into a single array in the same order (this array becomes new array *a*); - output the number of inversions in the new *a*. Given initial array *a* and all the queries. Answer all the queries. Please, note that the changes from some query is saved for further queries.
The first line of input contains a single integer *n* (0<=≤<=*n*<=≤<=20). The second line of input contains 2*n* space-separated integers *a*[1],<=*a*[2],<=...,<=*a*[2*n*] (1<=≤<=*a*[*i*]<=≤<=109), the initial array. The third line of input contains a single integer *m* (1<=≤<=*m*<=≤<=106). The fourth line of input contains *m* space-separated integers *q*1,<=*q*2,<=...,<=*q**m* (0<=≤<=*q**i*<=≤<=*n*), the queries. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.
Output *m* lines. In the *i*-th line print the answer (the number of inversions) for the *i*-th query.
[ "2\n2 1 4 3\n4\n1 2 0 2\n", "1\n1 2\n3\n0 1 1\n" ]
[ "0\n6\n6\n0\n", "0\n1\n0\n" ]
If we reverse an array *x*[1], *x*[2], ..., *x*[*n*] it becomes new array *y*[1], *y*[2], ..., *y*[*n*], where *y*[*i*] = *x*[*n* - *i* + 1] for each *i*. The number of inversions of an array *x*[1], *x*[2], ..., *x*[*n*] is the number of pairs of indices *i*, *j* such that: *i* &lt; *j* and *x*[*i*] &gt; *x*[*j*].
[]
30
0
0
10,446
717
Potions Homework
[ "implementation", "sortings" ]
null
null
Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the *n* students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence *a*, where *a**i* represents both the laziness level of the *i*-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10<=007.
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of tasks. The next *n* lines contain exactly one integer number *a**i* (1<=≤<=*a**i*<=≤<=100<=000) — both the difficulty of the initial task and the laziness of the *i*-th students.
Print the minimum total time to finish all tasks modulo 10<=007.
[ "2\n1\n3\n" ]
[ "6\n" ]
In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.
[ { "input": "2\n1\n3", "output": "6" } ]
108
2,457,600
0
10,474
475
Kamal-ol-molk's Painting
[ "brute force", "constructive algorithms", "greedy" ]
null
null
Rumors say that one of Kamal-ol-molk's paintings has been altered. A rectangular brush has been moved right and down on the painting. Consider the painting as a *n*<=×<=*m* rectangular grid. At the beginning an *x*<=×<=*y* rectangular brush is placed somewhere in the frame, with edges parallel to the frame, (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*). Then the brush is moved several times. Each time the brush is moved one unit right or down. The brush has been strictly inside the frame during the painting. The brush alters every cell it has covered at some moment. You have found one of the old Kamal-ol-molk's paintings. You want to know if it's possible that it has been altered in described manner. If yes, you also want to know minimum possible area of the brush.
The first line of input contains two integers *n* and *m*, (1<=≤<=*n*,<=*m*<=≤<=1000), denoting the height and width of the painting. The next *n* lines contain the painting. Each line has *m* characters. Character 'X' denotes an altered cell, otherwise it's showed by '.'. There will be at least one altered cell in the painting.
Print the minimum area of the brush in a line, if the painting is possibly altered, otherwise print <=-<=1.
[ "4 4\nXX..\nXX..\nXXXX\nXXXX\n", "4 4\n....\n.XXX\n.XXX\n....\n", "4 5\nXXXX.\nXXXX.\n.XX..\n.XX..\n" ]
[ "4\n", "2\n", "-1\n" ]
none
[ { "input": "4 4\nXX..\nXX..\nXXXX\nXXXX", "output": "4" }, { "input": "4 5\nXXXX.\nXXXX.\n.XX..\n.XX..", "output": "-1" }, { "input": "5 6\n.XXX..\n.XXXX.\n.XXXX.\n..XXX.\n..XXX.", "output": "6" }, { "input": "5 6\n.XXXX.\n.XXXXX\n...XXX\n...XXX\n...XXX", "output": "-1" }, { "input": "10 10\n..........\n..........\n..XXXX....\n..XXXX....\n..XXXXXX..\n..XXXXXX..\n....XXXXXX\n....XXXXXX\n......XXXX\n......XXX.", "output": "-1" }, { "input": "10 10\nXXX.......\nXXXXXXXXXX\nXXXXXXXXXX\n.XXXXXXXXX\n.XXXXXXXXX\n.XXXXXXXXX\n.XXXXXXXXX\n.XXXXXXXXX\n.XXXXXXXXX\n.XXXXXXXXX", "output": "-1" }, { "input": "10 10\n..........\n..........\n..........\n..........\n..........\n...X......\n...XXXX...\n......X...\n......XXX.\n........XX", "output": "1" }, { "input": "10 10\n..........\n..........\n..........\nXXX.......\n..X.......\n..X.......\n..X.......\n..XX......\n...XXXX...\n......XXXX", "output": "1" }, { "input": "1 1\nX", "output": "1" } ]
2,000
1,536,000
0
10,486
177
Encrypting Messages
[ "brute force" ]
null
null
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Encryption uses a key which is a sequence of *m* integers *b*1,<=*b*2,<=...,<=*b**m* (*m*<=≤<=*n*). All numbers from the message and from the key belong to the interval from 0 to *c*<=-<=1, inclusive, and all the calculations are performed modulo *c*. Encryption is performed in *n*<=-<=*m*<=+<=1 steps. On the first step we add to each number *a*1,<=*a*2,<=...,<=*a**m* a corresponding number *b*1,<=*b*2,<=...,<=*b**m*. On the second step we add to each number *a*2,<=*a*3,<=...,<=*a**m*<=+<=1 (changed on the previous step) a corresponding number *b*1,<=*b*2,<=...,<=*b**m*. And so on: on step number *i* we add to each number *a**i*,<=*a**i*<=+<=1,<=...,<=*a**i*<=+<=*m*<=-<=1 a corresponding number *b*1,<=*b*2,<=...,<=*b**m*. The result of the encryption is the sequence *a*1,<=*a*2,<=...,<=*a**n* after *n*<=-<=*m*<=+<=1 steps. Help the Beaver to write a program that will encrypt messages in the described manner.
The first input line contains three integers *n*, *m* and *c*, separated by single spaces. The second input line contains *n* integers *a**i* (0<=≤<=*a**i*<=&lt;<=*c*), separated by single spaces — the original message. The third input line contains *m* integers *b**i* (0<=≤<=*b**i*<=&lt;<=*c*), separated by single spaces — the encryption key. The input limitations for getting 30 points are: - 1<=≤<=*m*<=≤<=*n*<=≤<=103 - 1<=≤<=*c*<=≤<=103 The input limitations for getting 100 points are: - 1<=≤<=*m*<=≤<=*n*<=≤<=105 - 1<=≤<=*c*<=≤<=103
Print *n* space-separated integers — the result of encrypting the original message.
[ "4 3 2\n1 1 1 1\n1 1 1\n", "3 1 5\n1 2 3\n4\n" ]
[ "0 1 1 0\n", "0 1 2\n" ]
In the first sample the encryption is performed in two steps: after the first step *a* = (0, 0, 0, 1) (remember that the calculations are performed modulo 2), after the second step *a* = (0, 1, 1, 0), and that is the answer.
[ { "input": "4 3 2\n1 1 1 1\n1 1 1", "output": "0 1 1 0" }, { "input": "3 1 5\n1 2 3\n4", "output": "0 1 2" }, { "input": "5 2 7\n0 0 1 2 4\n3 5", "output": "3 1 2 3 2" }, { "input": "20 15 17\n4 9 14 11 15 16 15 4 0 10 7 12 10 1 8 6 7 14 1 13\n6 3 14 8 8 11 16 4 5 9 2 13 6 14 15", "output": "10 1 3 8 3 15 7 14 1 12 3 10 15 16 16 5 4 15 13 11" }, { "input": "80 6 99\n48 97 9 77 73 21 86 78 48 5 71 16 42 67 90 27 30 52 41 86 53 4 60 17 66 38 94 46 51 51 70 11 1 16 74 53 17 12 82 95 51 33 83 70 45 27 90 57 67 2 68 15 20 61 47 90 11 5 95 33 69 35 79 51 95 45 10 17 12 88 93 43 31 31 85 68 85 81 70 43\n47 92 59 85 73 38", "output": "95 38 9 63 33 19 84 76 46 3 69 14 40 65 88 25 28 50 39 84 51 2 58 15 64 36 92 44 49 49 68 9 98 14 72 51 15 10 80 93 49 31 81 68 43 25 88 55 65 0 66 13 18 59 45 88 9 3 93 31 67 33 77 49 93 43 8 15 10 86 91 41 29 29 83 19 43 79 82 81" } ]
216
2,048,000
3
10,518
549
Sasha Circle
[ "geometry", "math" ]
null
null
Berlanders like to eat cones after a hard day. Misha Square and Sasha Circle are local authorities of Berland. Each of them controls its points of cone trade. Misha has *n* points, Sasha — *m*. Since their subordinates constantly had conflicts with each other, they decided to build a fence in the form of a circle, so that the points of trade of one businessman are strictly inside a circle, and points of the other one are strictly outside. It doesn't matter which of the two gentlemen will have his trade points inside the circle. Determine whether they can build a fence or not.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=10000), numbers of Misha's and Sasha's trade points respectively. The next *n* lines contains pairs of space-separated integers *M**x*,<=*M**y* (<=-<=104<=≤<=*M**x*,<=*M**y*<=≤<=104), coordinates of Misha's trade points. The next *m* lines contains pairs of space-separated integers *S**x*,<=*S**y* (<=-<=104<=≤<=*S**x*,<=*S**y*<=≤<=104), coordinates of Sasha's trade points. It is guaranteed that all *n*<=+<=*m* points are distinct.
The only output line should contain either word "YES" without quotes in case it is possible to build a such fence or word "NO" in the other case.
[ "2 2\n-1 0\n1 0\n0 -1\n0 1\n", "4 4\n1 0\n0 1\n-1 0\n0 -1\n1 1\n-1 1\n-1 -1\n1 -1\n" ]
[ "NO\n", "YES\n" ]
In the first sample there is no possibility to separate points, because any circle that contains both points ( - 1, 0), (1, 0) also contains at least one point from the set (0,  - 1), (0, 1), and vice-versa: any circle that contains both points (0,  - 1), (0, 1) also contains at least one point from the set ( - 1, 0), (1, 0) In the second sample one of the possible solution is shown below. Misha's points are marked with red colour and Sasha's are marked with blue. <img class="tex-graphics" src="https://espresso.codeforces.com/91e76198f6d74c0a8b0f92c94460d887bfebc9fa.png" style="max-width: 100.0%;max-height: 100.0%;"/>
[ { "input": "2 2\n-1 0\n1 0\n0 -1\n0 1", "output": "NO" }, { "input": "4 4\n1 0\n0 1\n-1 0\n0 -1\n1 1\n-1 1\n-1 -1\n1 -1", "output": "YES" }, { "input": "2 3\n-1 0\n1 0\n0 -2\n0 0\n0 2", "output": "NO" }, { "input": "3 3\n-3 -4\n3 2\n1 5\n4 0\n5 2\n-2 -1", "output": "NO" }, { "input": "3 4\n-9998 -10000\n-10000 -9998\n-9999 -9999\n-9997 9996\n-9996 9997\n-9998 9995\n-9995 9998", "output": "YES" }, { "input": "1 1\n-1908 8645\n-8559 3388", "output": "YES" }, { "input": "1 2\n8961 -7819\n-3068 -3093\n-742 4108", "output": "YES" }, { "input": "2 1\n-7087 5671\n7159 -5255\n-9508 -2160", "output": "YES" }, { "input": "2 2\n3782 2631\n2352 -5158\n-1702 -700\n-3472 -117", "output": "YES" }, { "input": "2 10\n-1 0\n1 0\n9 9\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8", "output": "YES" }, { "input": "3 3\n-9140 650\n-9126 669\n-9112 688\n-9084 726\n-9098 707\n-9070 745", "output": "YES" }, { "input": "3 3\n8410 -3760\n8419 -3752\n8428 -3744\n8455 -3720\n8446 -3728\n8437 -3736", "output": "YES" }, { "input": "3 3\n9551 -9949\n-48 50\n-24 25\n0 0\n9575 -9974\n-9599 9999", "output": "YES" }, { "input": "3 2\n9599 -9999\n-9599 9999\n0 0\n-9575 9974\n9575 -9974", "output": "NO" }, { "input": "10 10\n971 -2437\n-3336 3332\n-7503 -8713\n-9337 -9607\n-927 -9162\n-4375 -3790\n-913 -257\n-5916 5783\n5131 -7304\n9993 -9999\n-2774 8057\n8670 -7936\n8388 3302\n8718 -4865\n3329 -3334\n5088 -1539\n5050 8130\n4710 -2803\n8124 -4062\n-10000 9997", "output": "YES" }, { "input": "3 3\n-1852 -9408\n-2082 -9212\n-1967 -9310\n-1737 -9506\n-1507 -9702\n-1622 -9604", "output": "YES" }, { "input": "2 10\n-1 0\n0 -1\n-9 -9\n0 0\n-1 -1\n-2 -2\n-3 -3\n-4 -4\n-5 -5\n-6 -6\n-7 -7\n-8 -8", "output": "NO" }, { "input": "2 10\n1 0\n0 1\n9 9\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8", "output": "NO" }, { "input": "2 3\n0 -1\n0 1\n-2 0\n0 0\n2 0", "output": "NO" }, { "input": "2 10\n-1 0\n1 0\n-9 -9\n0 0\n-1 -1\n-2 -2\n-3 -3\n-4 -4\n-5 -5\n-6 -6\n-7 -7\n-8 -8", "output": "YES" } ]
61
307,200
0
10,529
976
Lara Croft and the New Game
[ "implementation", "math" ]
null
null
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy. Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of *n* rows and *m* columns. Cell (*x*,<=*y*) is the cell in the *x*-th row in the *y*-th column. Lara can move between the neighbouring by side cells in all four directions. Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1,<=1), that is top left corner of the matrix. Then she goes down all the way to cell (*n*,<=1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. *n* and *m* given are such that she always end up in cell (1,<=2). Lara has already moved to a neighbouring cell *k* times. Can you determine her current position?
The only line contains three integers *n*, *m* and *k* (2<=≤<=*n*,<=*m*<=≤<=109, *n* is always even, 0<=≤<=*k*<=&lt;<=*n*·*m*). Note that *k* doesn't fit into 32-bit integer type!
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves *k* times.
[ "4 3 0\n", "4 3 11\n", "4 3 7\n" ]
[ "1 1\n", "1 2\n", "3 2\n" ]
Here is her path on matrix 4 by 3:
[ { "input": "4 3 0", "output": "1 1" }, { "input": "4 3 11", "output": "1 2" }, { "input": "4 3 7", "output": "3 2" }, { "input": "1000000000 2 1999999999", "output": "1 2" }, { "input": "1000000000 1000000000 999999999999999999", "output": "1 2" }, { "input": "1000000000 1000000000 999999999", "output": "1000000000 1" }, { "input": "1000000000 1000000000 2000000500", "output": "999999999 999999499" }, { "input": "2 2 2", "output": "2 2" }, { "input": "28 3 1", "output": "2 1" }, { "input": "2 3 3", "output": "2 3" }, { "input": "4 6 8", "output": "4 6" }, { "input": "6 6 18", "output": "4 4" }, { "input": "4 3 8", "output": "2 2" }, { "input": "4 3 4", "output": "4 2" }, { "input": "4 4 10", "output": "2 2" }, { "input": "4 5 4", "output": "4 2" }, { "input": "4 3 9", "output": "2 3" }, { "input": "4 3 6", "output": "3 3" }, { "input": "4 5 5", "output": "4 3" }, { "input": "6 4 8", "output": "6 4" }, { "input": "4 4 12", "output": "2 4" }, { "input": "10 6 15", "output": "9 6" }, { "input": "6666 969696 6667", "output": "6666 3" }, { "input": "4 5 13", "output": "2 3" }, { "input": "84 68 4248", "output": "22 12" }, { "input": "6 6 9", "output": "6 5" }, { "input": "4 5 17", "output": "1 4" }, { "input": "2 3 4", "output": "1 3" }, { "input": "4 3 5", "output": "4 3" }, { "input": "2 3 2", "output": "2 2" }, { "input": "4 5 12", "output": "2 2" }, { "input": "6 6 16", "output": "4 2" }, { "input": "4 4 6", "output": "4 4" }, { "input": "10 3 18", "output": "6 2" }, { "input": "2 4 5", "output": "1 4" }, { "input": "6 9 43", "output": "2 7" }, { "input": "4 7 8", "output": "4 6" }, { "input": "500 100 800", "output": "497 97" }, { "input": "2 5 5", "output": "2 5" }, { "input": "4 6 15", "output": "2 3" }, { "input": "9213788 21936127 8761236", "output": "8761237 1" }, { "input": "2 5 6", "output": "1 5" }, { "input": "43534 432423 53443", "output": "43534 9911" }, { "input": "999999998 999999998 999999995000000005", "output": "2 999999997" }, { "input": "999999924 999999983 999999906999879972", "output": "1 121321" }, { "input": "6 5 18", "output": "3 5" }, { "input": "4 4 5", "output": "4 3" }, { "input": "6 6 6", "output": "6 2" }, { "input": "99999998 8888888 77777777777", "output": "99991260 6683175" }, { "input": "6 5 6", "output": "6 2" }, { "input": "6 5 17", "output": "4 5" }, { "input": "6 4 12", "output": "4 2" }, { "input": "999995712 999993076 999988788028978212", "output": "1 711901" }, { "input": "999994900 999993699 999988599028973300", "output": "1 3161801" }, { "input": "978642410 789244500 12348616164", "output": "978642396 320550770" }, { "input": "999993774 999998283 999992057010529542", "output": "1 160501" }, { "input": "4 7 10", "output": "3 7" }, { "input": "6 4 9", "output": "5 4" }, { "input": "1000000000 789 788999999000", "output": "2 578" }, { "input": "978642410 789244500 1234861616400", "output": "978640847 495422447" }, { "input": "999999596 999999631 999999226999090676", "output": "1 1058401" }, { "input": "4 7 16", "output": "2 2" }, { "input": "2 2 3", "output": "1 2" }, { "input": "21726 5447 14771", "output": "14772 1" }, { "input": "4 2 6", "output": "2 2" }, { "input": "621282132 311996010 98597740967720109", "output": "305259691 311996002" }, { "input": "803521870 958373820 689637244594465863", "output": "83930798 27" }, { "input": "887584278 701990442 578292377747447929", "output": "63794746 41" }, { "input": "656369902 872526042 566305269065863364", "output": "7328794 36" }, { "input": "839664176 535164910 441498526835463771", "output": "14687578 15" }, { "input": "636553724 546535019 115079316355948443", "output": "425992073 546535018" }, { "input": "2182 23967 52288026", "output": "1 7969" }, { "input": "548492800 434105920 179638683192075937", "output": "134679777 434105920" }, { "input": "4 4 4", "output": "4 2" }, { "input": "6 8 15", "output": "5 6" }, { "input": "6 3 7", "output": "6 3" }, { "input": "949547590 305226065 138144146668766087", "output": "496951426 3" }, { "input": "1000000000 1000000000 3000000000", "output": "999999998 4" }, { "input": "999999998 1000000000 1000000998999999", "output": "998999998 3" }, { "input": "999381438 840037557 128928432510450944", "output": "845902072 12" }, { "input": "742860584 671970249 260211607929646490", "output": "355623786 4" }, { "input": "1000000000 1000000000 1999999998", "output": "1000000000 1000000000" }, { "input": "993142186 628701115 555947810764442157", "output": "108862204 25" }, { "input": "595261150 794915864 332353903994901365", "output": "177161677 794915848" } ]
124
512,000
3
10,543
710
Magic Odd Square
[ "constructive algorithms", "math" ]
null
null
Find an *n*<=×<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd.
The only line contains odd integer *n* (1<=≤<=*n*<=≤<=49).
Print *n* lines with *n* integers. All the integers should be different and from 1 to *n*2. The sum in each row, column and both main diagonals should be odd.
[ "1\n", "3\n" ]
[ "1\n", "2 1 4\n3 5 7\n6 9 8\n" ]
none
[ { "input": "1", "output": "1" }, { "input": "3", "output": "2 1 4\n3 5 7\n6 9 8" }, { "input": "5", "output": "2 4 1 6 8\n10 3 5 7 12\n9 11 13 15 17\n14 19 21 23 16\n18 20 25 22 24" }, { "input": "7", "output": "2 4 6 1 8 10 12\n14 16 3 5 7 18 20\n22 9 11 13 15 17 24\n19 21 23 25 27 29 31\n26 33 35 37 39 41 28\n30 32 43 45 47 34 36\n38 40 42 49 44 46 48" }, { "input": "9", "output": "2 4 6 8 1 10 12 14 16\n18 20 22 3 5 7 24 26 28\n30 32 9 11 13 15 17 34 36\n38 19 21 23 25 27 29 31 40\n33 35 37 39 41 43 45 47 49\n42 51 53 55 57 59 61 63 44\n46 48 65 67 69 71 73 50 52\n54 56 58 75 77 79 60 62 64\n66 68 70 72 81 74 76 78 80" }, { "input": "11", "output": "2 4 6 8 10 1 12 14 16 18 20\n22 24 26 28 3 5 7 30 32 34 36\n38 40 42 9 11 13 15 17 44 46 48\n50 52 19 21 23 25 27 29 31 54 56\n58 33 35 37 39 41 43 45 47 49 60\n51 53 55 57 59 61 63 65 67 69 71\n62 73 75 77 79 81 83 85 87 89 64\n66 68 91 93 95 97 99 101 103 70 72\n74 76 78 105 107 109 111 113 80 82 84\n86 88 90 92 115 117 119 94 96 98 100\n102 104 106 108 110 121 112 114 116 118 120" }, { "input": "13", "output": "2 4 6 8 10 12 1 14 16 18 20 22 24\n26 28 30 32 34 3 5 7 36 38 40 42 44\n46 48 50 52 9 11 13 15 17 54 56 58 60\n62 64 66 19 21 23 25 27 29 31 68 70 72\n74 76 33 35 37 39 41 43 45 47 49 78 80\n82 51 53 55 57 59 61 63 65 67 69 71 84\n73 75 77 79 81 83 85 87 89 91 93 95 97\n86 99 101 103 105 107 109 111 113 115 117 119 88\n90 92 121 123 125 127 129 131 133 135 137 94 96\n98 100 102 139 141 143 145 147 149 151 104 106 108\n110 112 114 116 153 155 157 159 161 118 120 122 124\n126 128 130 132 134 163 165 167 136 ..." }, { "input": "15", "output": "2 4 6 8 10 12 14 1 16 18 20 22 24 26 28\n30 32 34 36 38 40 3 5 7 42 44 46 48 50 52\n54 56 58 60 62 9 11 13 15 17 64 66 68 70 72\n74 76 78 80 19 21 23 25 27 29 31 82 84 86 88\n90 92 94 33 35 37 39 41 43 45 47 49 96 98 100\n102 104 51 53 55 57 59 61 63 65 67 69 71 106 108\n110 73 75 77 79 81 83 85 87 89 91 93 95 97 112\n99 101 103 105 107 109 111 113 115 117 119 121 123 125 127\n114 129 131 133 135 137 139 141 143 145 147 149 151 153 116\n118 120 155 157 159 161 163 165 167 169 171 173 175 122 124\n126 128 1..." }, { "input": "17", "output": "2 4 6 8 10 12 14 16 1 18 20 22 24 26 28 30 32\n34 36 38 40 42 44 46 3 5 7 48 50 52 54 56 58 60\n62 64 66 68 70 72 9 11 13 15 17 74 76 78 80 82 84\n86 88 90 92 94 19 21 23 25 27 29 31 96 98 100 102 104\n106 108 110 112 33 35 37 39 41 43 45 47 49 114 116 118 120\n122 124 126 51 53 55 57 59 61 63 65 67 69 71 128 130 132\n134 136 73 75 77 79 81 83 85 87 89 91 93 95 97 138 140\n142 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 144\n129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161..." }, { "input": "19", "output": "2 4 6 8 10 12 14 16 18 1 20 22 24 26 28 30 32 34 36\n38 40 42 44 46 48 50 52 3 5 7 54 56 58 60 62 64 66 68\n70 72 74 76 78 80 82 9 11 13 15 17 84 86 88 90 92 94 96\n98 100 102 104 106 108 19 21 23 25 27 29 31 110 112 114 116 118 120\n122 124 126 128 130 33 35 37 39 41 43 45 47 49 132 134 136 138 140\n142 144 146 148 51 53 55 57 59 61 63 65 67 69 71 150 152 154 156\n158 160 162 73 75 77 79 81 83 85 87 89 91 93 95 97 164 166 168\n170 172 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 174 176\n178..." }, { "input": "21", "output": "2 4 6 8 10 12 14 16 18 20 1 22 24 26 28 30 32 34 36 38 40\n42 44 46 48 50 52 54 56 58 3 5 7 60 62 64 66 68 70 72 74 76\n78 80 82 84 86 88 90 92 9 11 13 15 17 94 96 98 100 102 104 106 108\n110 112 114 116 118 120 122 19 21 23 25 27 29 31 124 126 128 130 132 134 136\n138 140 142 144 146 148 33 35 37 39 41 43 45 47 49 150 152 154 156 158 160\n162 164 166 168 170 51 53 55 57 59 61 63 65 67 69 71 172 174 176 178 180\n182 184 186 188 73 75 77 79 81 83 85 87 89 91 93 95 97 190 192 194 196\n198 200 202 99 101 103 ..." }, { "input": "23", "output": "2 4 6 8 10 12 14 16 18 20 22 1 24 26 28 30 32 34 36 38 40 42 44\n46 48 50 52 54 56 58 60 62 64 3 5 7 66 68 70 72 74 76 78 80 82 84\n86 88 90 92 94 96 98 100 102 9 11 13 15 17 104 106 108 110 112 114 116 118 120\n122 124 126 128 130 132 134 136 19 21 23 25 27 29 31 138 140 142 144 146 148 150 152\n154 156 158 160 162 164 166 33 35 37 39 41 43 45 47 49 168 170 172 174 176 178 180\n182 184 186 188 190 192 51 53 55 57 59 61 63 65 67 69 71 194 196 198 200 202 204\n206 208 210 212 214 73 75 77 79 81 83 85 87 89 ..." }, { "input": "25", "output": "2 4 6 8 10 12 14 16 18 20 22 24 1 26 28 30 32 34 36 38 40 42 44 46 48\n50 52 54 56 58 60 62 64 66 68 70 3 5 7 72 74 76 78 80 82 84 86 88 90 92\n94 96 98 100 102 104 106 108 110 112 9 11 13 15 17 114 116 118 120 122 124 126 128 130 132\n134 136 138 140 142 144 146 148 150 19 21 23 25 27 29 31 152 154 156 158 160 162 164 166 168\n170 172 174 176 178 180 182 184 33 35 37 39 41 43 45 47 49 186 188 190 192 194 196 198 200\n202 204 206 208 210 212 214 51 53 55 57 59 61 63 65 67 69 71 216 218 220 222 224 226 228\n..." }, { "input": "27", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 1 28 30 32 34 36 38 40 42 44 46 48 50 52\n54 56 58 60 62 64 66 68 70 72 74 76 3 5 7 78 80 82 84 86 88 90 92 94 96 98 100\n102 104 106 108 110 112 114 116 118 120 122 9 11 13 15 17 124 126 128 130 132 134 136 138 140 142 144\n146 148 150 152 154 156 158 160 162 164 19 21 23 25 27 29 31 166 168 170 172 174 176 178 180 182 184\n186 188 190 192 194 196 198 200 202 33 35 37 39 41 43 45 47 49 204 206 208 210 212 214 216 218 220\n222 224 226 228 230 232 234 236 51 53 55 57 59 61..." }, { "input": "29", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 1 30 32 34 36 38 40 42 44 46 48 50 52 54 56\n58 60 62 64 66 68 70 72 74 76 78 80 82 3 5 7 84 86 88 90 92 94 96 98 100 102 104 106 108\n110 112 114 116 118 120 122 124 126 128 130 132 9 11 13 15 17 134 136 138 140 142 144 146 148 150 152 154 156\n158 160 162 164 166 168 170 172 174 176 178 19 21 23 25 27 29 31 180 182 184 186 188 190 192 194 196 198 200\n202 204 206 208 210 212 214 216 218 220 33 35 37 39 41 43 45 47 49 222 224 226 228 230 232 234 236 238 240\n242 244 2..." }, { "input": "31", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 1 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60\n62 64 66 68 70 72 74 76 78 80 82 84 86 88 3 5 7 90 92 94 96 98 100 102 104 106 108 110 112 114 116\n118 120 122 124 126 128 130 132 134 136 138 140 142 9 11 13 15 17 144 146 148 150 152 154 156 158 160 162 164 166 168\n170 172 174 176 178 180 182 184 186 188 190 192 19 21 23 25 27 29 31 194 196 198 200 202 204 206 208 210 212 214 216\n218 220 222 224 226 228 230 232 234 236 238 33 35 37 39 41 43 45 47 49 240 242 244 24..." }, { "input": "33", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 1 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64\n66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 3 5 7 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124\n126 128 130 132 134 136 138 140 142 144 146 148 150 152 9 11 13 15 17 154 156 158 160 162 164 166 168 170 172 174 176 178 180\n182 184 186 188 190 192 194 196 198 200 202 204 206 19 21 23 25 27 29 31 208 210 212 214 216 218 220 222 224 226 228 230 232\n234 236 238 240 242 244 246 248 250 252 254 256 33 35..." }, { "input": "35", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 1 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68\n70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 3 5 7 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132\n134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 9 11 13 15 17 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192\n194 196 198 200 202 204 206 208 210 212 214 216 218 220 19 21 23 25 27 29 31 222 224 226 228 230 232 234 236 238 240 242 244 246 248\n250 252 254 256 258 2..." }, { "input": "37", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 1 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72\n74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 3 5 7 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140\n142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 9 11 13 15 17 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204\n206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 19 21 23 25 27 29 31 236 238 240 242 244 246 248 250 252 254 256 258 26..." }, { "input": "39", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 1 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76\n78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 3 5 7 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148\n150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 9 11 13 15 17 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216\n218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 19 21 23 25 27 29 31 250 252 254 256 258 26..." }, { "input": "41", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 1 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80\n82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 3 5 7 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156\n158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 9 11 13 15 17 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228\n230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 19 21 23 25 27 ..." }, { "input": "43", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 1 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84\n86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 3 5 7 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164\n166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 9 11 13 15 17 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240\n242 244 246 248 250 252 254 256 258 260 262 264 266 268 270..." }, { "input": "45", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 1 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88\n90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 3 5 7 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172\n174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 9 11 13 15 17 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252\n254 256 258 260 262 264 266 268 270..." }, { "input": "47", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 1 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92\n94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 3 5 7 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180\n182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 9 11 13 15 17 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264\n266 268 270..." }, { "input": "49", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 1 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96\n98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 3 5 7 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188\n190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 9 11 13 15 17 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 ..." } ]
30
0
0
10,568
172
Pseudorandom Sequence Period
[ "*special", "implementation", "number theory" ]
null
null
Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: (for *i*<=≥<=1). Here *a*, *b*, *m* are constants, fixed for the given realization of the pseudorandom numbers generator, *r*0 is the so-called *randseed* (this value can be set from the program using functions like RandSeed(r) or srand(n)), and denotes the operation of taking the remainder of division. For example, if *a*<==<=2,<=*b*<==<=6,<=*m*<==<=12,<=*r*0<==<=11, the generated sequence will be: 4,<=2,<=10,<=2,<=10,<=2,<=10,<=2,<=10,<=2,<=10,<=.... Polycarpus realized that any such sequence will sooner or later form a cycle, but the cycle may occur not in the beginning, so there exist a preperiod and a period. The example above shows a preperiod equal to 1 and a period equal to 2. Your task is to find the period of a sequence defined by the given values of *a*,<=*b*,<=*m* and *r*0. Formally, you have to find such minimum positive integer *t*, for which exists such positive integer *k*, that for any *i*<=≥<=*k*: *r**i*<==<=*r**i*<=+<=*t*.
The single line of the input contains four integers *a*, *b*, *m* and *r*0 (1<=≤<=*m*<=≤<=105,<=0<=≤<=*a*,<=*b*<=≤<=1000,<=0<=≤<=*r*0<=&lt;<=*m*), separated by single spaces.
Print a single integer — the period of the sequence.
[ "2 6 12 11\n", "2 3 5 1\n", "3 6 81 9\n" ]
[ "2\n", "4\n", "1\n" ]
The first sample is described above. In the second sample the sequence is (starting from the first element): 0, 3, 4, 1, 0, 3, 4, 1, 0, ... In the third sample the sequence is (starting from the first element): 33, 24, 78, 78, 78, 78, ...
[ { "input": "2 6 12 11", "output": "2" }, { "input": "2 3 5 1", "output": "4" }, { "input": "3 6 81 9", "output": "1" }, { "input": "10 11 12 3", "output": "3" }, { "input": "4 4 5 4", "output": "2" }, { "input": "0 1 6 5", "output": "1" }, { "input": "1 0 7 3", "output": "1" }, { "input": "25 154 200 68", "output": "4" }, { "input": "0 0 1 0", "output": "1" }, { "input": "1 1 100000 0", "output": "100000" }, { "input": "73 778 36193 20163", "output": "1064" }, { "input": "65 101 43738 16242", "output": "3450" }, { "input": "177 329 83469 5951", "output": "9274" }, { "input": "452 53 51476 50033", "output": "3024" }, { "input": "900 209 34129 21607", "output": "4266" }, { "input": "137 936 79151 3907", "output": "79150" }, { "input": "687 509 56521 48466", "output": "3409" }, { "input": "977 461 14937 9343", "output": "2292" }, { "input": "545 541 43487 31725", "output": "43486" }, { "input": "550 5 88379 9433", "output": "44189" }, { "input": "173 105 24791 23343", "output": "5718" }, { "input": "239 695 50503 18287", "output": "25251" }, { "input": "397 24 21491 18004", "output": "21490" }, { "input": "887 265 55829 22027", "output": "55828" }, { "input": "821 163 39195 20770", "output": "660" }, { "input": "491 3 64907 3847", "output": "115" }, { "input": "503 233 5683 3462", "output": "1894" }, { "input": "367 701 18523 11701", "output": "882" }, { "input": "349 673 81953 56773", "output": "81952" }, { "input": "619 37 37223 877", "output": "18611" }, { "input": "643 863 77551 25943", "output": "38775" }, { "input": "937 859 7333 2141", "output": "7332" }, { "input": "271 761 99991 75353", "output": "49995" }, { "input": "1 1 10000 0", "output": "10000" }, { "input": "0 0 16709 12233", "output": "1" }, { "input": "0 1 55305 6822", "output": "1" }, { "input": "1 0 54062 35990", "output": "1" }, { "input": "0 0 23896 0", "output": "1" }, { "input": "0 1 53172 0", "output": "1" }, { "input": "1 0 54652 0", "output": "1" }, { "input": "6 0 99991 1", "output": "99990" }, { "input": "101 0 100000 1", "output": "1000" }, { "input": "2 0 99989 1", "output": "99988" }, { "input": "2 0 54539 1", "output": "54538" }, { "input": "3 0 42953 1", "output": "42952" }, { "input": "7 0 67129 1", "output": "67128" }, { "input": "2 0 89261 1", "output": "89260" }, { "input": "11 0 35311 1", "output": "35310" }, { "input": "0 0 2 0", "output": "1" }, { "input": "1 0 2 0", "output": "1" }, { "input": "0 1 2 0", "output": "1" }, { "input": "1 1 2 0", "output": "2" }, { "input": "0 0 2 1", "output": "1" }, { "input": "1 0 2 1", "output": "1" }, { "input": "0 1 2 1", "output": "1" }, { "input": "1 1 2 1", "output": "2" } ]
2,000
0
0
10,575
402
Strictly Positive Matrix
[ "graphs", "math" ]
null
null
You have matrix *a* of size *n*<=×<=*n*. Let's number the rows of the matrix from 1 to *n* from top to bottom, let's number the columns from 1 to *n* from left to right. Let's use *a**ij* to represent the element on the intersection of the *i*-th row and the *j*-th column. Matrix *a* meets the following two conditions: - for any numbers *i*,<=*j* (1<=≤<=*i*,<=*j*<=≤<=*n*) the following inequality holds: *a**ij*<=≥<=0; - . Matrix *b* is strictly positive, if for any numbers *i*,<=*j* (1<=≤<=*i*,<=*j*<=≤<=*n*) the inequality *b**ij*<=&gt;<=0 holds. You task is to determine if there is such integer *k*<=≥<=1, that matrix *a**k* is strictly positive.
The first line contains integer *n* (2<=≤<=*n*<=≤<=2000) — the number of rows and columns in matrix *a*. The next *n* lines contain the description of the rows of matrix *a*. The *i*-th line contains *n* non-negative integers *a**i*1,<=*a**i*2,<=...,<=*a**in* (0<=≤<=*a**ij*<=≤<=50). It is guaranteed that .
If there is a positive integer *k*<=≥<=1, such that matrix *a**k* is strictly positive, print "YES" (without the quotes). Otherwise, print "NO" (without the quotes).
[ "2\n1 0\n0 1\n", "5\n4 5 6 1 2\n1 2 3 4 5\n6 4 1 2 4\n1 1 1 1 1\n4 4 4 4 4\n" ]
[ "NO\n", "YES\n" ]
none
[ { "input": "2\n1 0\n0 1", "output": "NO" }, { "input": "5\n4 5 6 1 2\n1 2 3 4 5\n6 4 1 2 4\n1 1 1 1 1\n4 4 4 4 4", "output": "YES" }, { "input": "5\n1 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 1 1\n0 0 0 0 1", "output": "NO" }, { "input": "5\n1 0 0 0 0\n1 1 0 0 0\n0 1 1 0 0\n0 0 1 1 0\n0 0 0 1 1", "output": "NO" }, { "input": "10\n1 0 1 1 0 1 1 1 0 1\n0 1 0 0 1 0 0 0 1 0\n1 0 1 1 0 1 1 1 0 1\n1 0 1 1 0 1 1 1 0 1\n0 1 0 0 1 0 0 0 1 0\n1 0 1 1 0 1 1 1 0 1\n1 0 1 1 0 1 1 1 0 1\n1 0 1 1 0 1 1 1 0 1\n0 1 0 0 1 0 0 0 1 0\n1 0 1 1 0 1 1 1 0 1", "output": "NO" }, { "input": "10\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 1 0 0\n0 0 0 1 0 0 0 0 0 0\n1 0 0 0 0 0 0 0 0 0\n0 0 0 0 1 0 1 0 0 0\n0 0 1 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 1\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 1 0 0 0 0 0", "output": "YES" }, { "input": "3\n1 1 0\n0 0 1\n1 0 0", "output": "YES" }, { "input": "10\n16 7 11 41 25 6 8 40 38 13\n0 0 37 22 0 34 5 43 38 34\n13 3 0 38 13 7 41 45 2 20\n50 41 12 22 24 43 38 3 0 0\n33 0 5 47 3 48 3 0 48 17\n28 2 43 43 20 6 12 13 47 28\n38 45 47 49 33 2 26 26 43 0\n39 0 11 39 15 31 5 5 39 22\n27 15 0 18 19 47 3 18 14 40\n20 32 33 25 43 10 0 0 15 43", "output": "YES" }, { "input": "9\n22 32 19 16 27 0 8 31 36\n49 2 13 16 7 38 36 45 48\n9 24 19 45 6 18 19 11 2\n3 23 48 7 13 42 16 44 33\n30 8 37 0 4 12 27 29 11\n9 1 7 2 11 15 21 15 40\n41 23 0 38 17 36 15 2 10\n13 37 39 18 26 20 41 48 17\n13 12 43 10 46 8 46 22 46", "output": "YES" }, { "input": "2\n33 50\n20 27", "output": "YES" }, { "input": "5\n0 1 0 0 0\n0 0 0 1 0\n1 0 0 0 0\n0 0 0 1 1\n0 0 1 0 0", "output": "YES" }, { "input": "2\n0 1\n1 1", "output": "YES" }, { "input": "5\n0 1 1 0 1\n1 1 1 0 0\n1 1 0 0 0\n0 0 0 1 1\n0 0 0 1 0", "output": "NO" }, { "input": "5\n0 1 1 0 0\n1 1 1 0 0\n1 1 0 0 0\n0 0 0 1 1\n1 0 0 1 0", "output": "NO" }, { "input": "10\n0 1 1 1 1 1 1 0 0 0\n1 0 1 1 1 1 1 0 0 0\n1 1 0 1 1 1 1 0 0 0\n1 1 1 0 1 1 1 0 0 0\n1 1 1 1 1 1 1 0 0 0\n1 1 1 1 1 0 1 0 0 0\n1 1 1 1 1 1 0 0 0 0\n0 0 0 0 0 0 0 1 1 1\n0 0 0 0 0 0 0 1 0 1\n0 1 0 0 0 0 0 1 1 0", "output": "NO" }, { "input": "5\n0 1 0 0 0\n1 0 0 0 0\n0 0 1 1 0\n0 0 0 1 1\n0 0 1 0 1", "output": "NO" }, { "input": "4\n1 1 0 0\n1 1 0 0\n0 0 1 1\n0 0 1 1", "output": "NO" }, { "input": "5\n0 1 0 0 0\n1 0 1 0 0\n0 0 1 1 0\n0 0 0 1 1\n0 0 1 0 1", "output": "NO" }, { "input": "3\n1 2 0\n0 0 3\n0 0 0", "output": "NO" }, { "input": "2\n1 1\n0 1", "output": "NO" }, { "input": "4\n1 1 0 0\n1 0 1 0\n0 0 0 1\n0 0 1 0", "output": "NO" }, { "input": "4\n1 1 1 1\n0 1 1 0\n0 1 1 0\n1 1 1 1", "output": "NO" }, { "input": "3\n1 1 0\n0 1 1\n0 0 1", "output": "NO" }, { "input": "4\n1 0 0 1\n0 1 1 0\n0 1 1 0\n1 0 0 1", "output": "NO" }, { "input": "4\n1 1 0 0\n1 1 0 0\n1 1 1 1\n1 1 1 1", "output": "NO" }, { "input": "5\n1 1 0 0 0\n1 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1\n0 0 1 0 1", "output": "NO" }, { "input": "2\n1 1\n0 0", "output": "NO" }, { "input": "15\n1 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 0 0 0 0 0 0 0 0 0 0 0\n0 0 1 1 1 0 0 0 0 0 0 0 0 0 0\n0 0 0 1 1 1 0 0 0 0 0 0 0 0 0\n0 0 0 0 1 1 1 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 1 1 0 0 0 0 0 0 0\n0 0 0 0 0 0 1 1 1 0 0 0 0 0 0\n0 0 0 0 0 0 0 1 1 1 0 0 0 0 0\n0 0 0 0 0 0 0 0 1 1 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 1 1 1 0 0 0\n0 0 0 0 0 0 0 0 0 0 1 1 1 0 0\n0 0 0 0 0 0 0 0 0 0 0 1 1 1 0\n0 0 0 0 0 0 0 0 0 0 0 0 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 1 1", "output": "YES" }, { "input": "4\n1 1 0 0\n1 0 0 0\n0 1 0 1\n0 0 1 0", "output": "NO" }, { "input": "6\n1 1 0 0 0 0\n0 1 1 0 0 0\n1 0 1 0 0 0\n0 0 0 1 1 0\n0 0 0 0 1 1\n0 0 0 1 0 1", "output": "NO" }, { "input": "3\n1 1 1\n0 0 0\n0 0 0", "output": "NO" } ]
30
0
0
10,577
802
Send the Fool Further! (easy)
[ "dfs and similar", "graphs", "trees" ]
null
null
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's *n* friends are labeled 0 through *n*<=-<=1, and their network of connections forms a tree. In other words, every two of her friends *a*, *b* know each other, possibly indirectly (there is a sequence of friends starting from *a* and ending on *b* and such that each two consecutive friends in the sequence know each other directly), and there are exactly *n*<=-<=1 pairs of friends who know each other directly. Jenny is given the number 0.
The first line of the input contains the number of friends *n* (3<=≤<=*n*<=≤<=100). The next *n*<=-<=1 lines each contain three space-separated integers *u*, *v* and *c* (0<=≤<=*u*,<=*v*<=≤<=*n*<=-<=1, 1<=≤<=*c*<=≤<=104), meaning that *u* and *v* are friends (know each other directly) and the cost for travelling between *u* and *v* is *c*. It is guaranteed that the social network of the input forms a tree.
Output a single integer – the maximum sum of costs.
[ "4\n0 1 4\n0 2 2\n2 3 3\n", "6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10\n", "11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378\n" ]
[ "5\n", "105\n", "5551\n" ]
In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2).
[ { "input": "4\n0 1 4\n0 2 2\n2 3 3", "output": "5" }, { "input": "3\n1 0 5987\n2 0 8891", "output": "8891" }, { "input": "10\n1 0 518\n2 0 4071\n3 1 121\n4 2 3967\n5 3 9138\n6 2 9513\n7 3 3499\n8 2 2337\n9 4 7647", "output": "15685" }, { "input": "11\n1 0 6646\n2 0 8816\n3 2 9375\n4 2 5950\n5 1 8702\n6 2 2657\n7 2 885\n8 7 2660\n9 2 5369\n10 6 3798", "output": "18191" }, { "input": "10\n0 1 7171\n0 2 2280\n1 3 9126\n2 4 2598\n5 4 8320\n6 2 1855\n3 7 9204\n7 8 2145\n4 9 10", "output": "27646" }, { "input": "6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10", "output": "105" }, { "input": "11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378", "output": "5551" } ]
155
20,172,800
3
10,604
723
One-Way Reform
[ "constructive algorithms", "dfs and similar", "flows", "graphs", "greedy" ]
null
null
There are *n* cities and *m* two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itself. It is possible that there is no way to get from one city to some other city using only these roads. The road minister decided to make a reform in Berland and to orient all roads in the country, i.e. to make each road one-way. The minister wants to maximize the number of cities, for which the number of roads that begins in the city equals to the number of roads that ends in it.
The first line contains a positive integer *t* (1<=≤<=*t*<=≤<=200) — the number of testsets in the input. Each of the testsets is given in the following way. The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=200, 0<=≤<=*m*<=≤<=*n*·(*n*<=-<=1)<=/<=2) — the number of cities and the number of roads in Berland. The next *m* lines contain the description of roads in Berland. Each line contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*) — the cities the corresponding road connects. It's guaranteed that there are no self-loops and multiple roads. It is possible that there is no way along roads between a pair of cities. It is guaranteed that the total number of cities in all testset of input data doesn't exceed 200. Pay attention that for hacks, you can only use tests consisting of one testset, so *t* should be equal to one.
For each testset print the maximum number of such cities that the number of roads that begins in the city, is equal to the number of roads that ends in it. In the next *m* lines print oriented roads. First print the number of the city where the road begins and then the number of the city where the road ends. If there are several answers, print any of them. It is allowed to print roads in each test in arbitrary order. Each road should be printed exactly once.
[ "2\n5 5\n2 1\n4 5\n2 3\n1 3\n3 5\n7 2\n3 7\n4 2\n" ]
[ "3\n1 3\n3 5\n5 4\n3 2\n2 1\n3\n2 4\n3 7\n" ]
none
[ { "input": "2\n5 5\n2 1\n4 5\n2 3\n1 3\n3 5\n7 2\n3 7\n4 2", "output": "3\n1 3\n3 5\n5 4\n3 2\n2 1\n3\n2 4\n3 7" }, { "input": "4\n9 17\n3 6\n2 6\n6 9\n4 1\n2 8\n1 9\n7 9\n8 5\n1 7\n4 9\n6 7\n3 4\n9 3\n8 4\n2 1\n3 8\n2 7\n5 6\n2 5\n3 4\n1 3\n4 5\n5 3\n2 3\n12 8\n10 2\n9 2\n6 9\n10 6\n8 2\n4 10\n11 2\n4 11\n19 10\n6 2\n3 12\n17 7\n2 19\n17 4\n1 13\n7 1\n13 7\n6 8\n11 7", "output": "7\n1 9\n9 7\n7 6\n6 9\n5 8\n8 4\n4 9\n9 3\n3 8\n8 2\n2 7\n7 1\n1 4\n4 3\n3 6\n6 2\n2 1\n3\n5 4\n4 3\n3 5\n5 2\n2 3\n3 1\n10\n2 11\n11 4\n4 10\n10 6\n6 9\n9 2\n2 10\n8 2\n13\n1 13\n13 7\n7 17\n17 4\n11 7\n7 1\n2 19\n8 6\n6 2\n3 12" }, { "input": "1\n200 0", "output": "200" }, { "input": "1\n13 9\n13 12\n3 11\n12 10\n12 9\n2 11\n3 8\n1 3\n2 13\n13 11", "output": "5\n1 3\n3 11\n11 13\n11 2\n2 13\n13 12\n12 10\n12 9\n8 3" }, { "input": "1\n4 6\n1 3\n4 1\n3 2\n1 2\n4 3\n4 2", "output": "0\n1 4\n4 2\n4 3\n3 1\n3 2\n2 1" }, { "input": "1\n6 7\n3 2\n3 1\n6 4\n1 2\n5 4\n3 4\n5 6", "output": "4\n1 3\n3 4\n4 6\n6 5\n5 4\n3 2\n2 1" }, { "input": "1\n5 4\n1 2\n2 3\n2 4\n2 5", "output": "1\n3 2\n2 5\n4 2\n2 1" } ]
46
0
0
10,642
70
Text Messaging
[ "expression parsing", "greedy", "strings" ]
B. Text Messaging
1
256
Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing *n* characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: SPACE stands for the symbol of a space. So, how many messages did Fangy send?
The first line contains an integer *n*, which is the size of one message (2<=≤<=*n*<=≤<=255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty.
On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes.
[ "25\nHello. I am a little walrus.\n", "2\nHow are you?\n", "19\nHello! Do you like fish? Why?\n" ]
[ "2\n", "Impossible\n", "3\n" ]
Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".
[ { "input": "25\nHello. I am a little walrus.", "output": "2" }, { "input": "2\nHow are you?", "output": "Impossible" }, { "input": "19\nHello! Do you like fish? Why?", "output": "3" }, { "input": "4\na. A.", "output": "2" }, { "input": "191\nEvx vnxZtUSgtzH yDNXCsTaxCKQus gVZLHppOplkGGekIK xbme. krbusMqUs YEnBBTJpjNicZPlx TqEtBPcbejZMzvn fFTub CHYWLmiOFkDdzR! LoQmXPfHJ KVnfrbrFooVSkj xwAZwrRr DdILZ kpco cLoRmJbVKhnbOEhnHKpci. PgYhxFPXdlvlrp mDLZBnVRf AgRMUjxepFuLyKlIAhLS wtmEiLDNUAHpZEsKnkOu!", "output": "2" }, { "input": "146\niIQVkDsPqzAJyBrtHk EhBSN gzDoigItCMzETerb cIbXhTPbKYMdMoYqyFTEN. qcrrseVwmaZEiQUQoGT SUyErST lJDejKkjqTdoUrHR tsZYDyI? pmuNNHYqQUISxdZfWOB XdEECvNz hnNmVfODaIC qjhRIEPAlEsQBxo apZ! gCpqoiUFIwWLBOmYubywj qJojFVhLd dCpovICpXHfgihydEOoij?", "output": "2" }, { "input": "151\nayDIuxJXWNqu OImqJLodviANkQNxZ OpDpwyoPQdZyosXJpqRx! ZFQNQJPnoEVUEEbjqs iyfUYK HuGCOtlsEllsCiHIdEuW ZmlRSWVOmLAD MSYsC? CGKxobjmddejDDdF qbQsAWi qxViwV iLmPHfhLjP ZfNCItjZikwaQyhQGC? bvSaaZhwHdbNKSiiI bEJXRjANEasfrElNHPA UuQCajtuODHgxwgL qbssJss TqT.", "output": "2" }, { "input": "123\nOjg CVJm qfE RnHislFds nNKKt TCPLWukqNGAsVBplYbTfq? VeYKjfFGTzXWA ydpVZLIImNub yApKnAHv iXQmqv GjQvxrnAgtfTApiQyCKtg. GdmapGwvI udRqxTbnzgnOUNZx slAuEuLGCJycZJvtCczQ vommS xuuT eIK! DOJeFEaubbz HYLGlIIlNKfyaJQKVN eFNnUvKKCQLXvGhwX gjmRscMkedELUlHq? aTbyMGB EofzX wcAEjyRQpxghWvXhdJb cwIz FEUsEFicYZ.", "output": "3" }, { "input": "126\ntjQvloOnRednqfvIRudX wAPhGdwEZ BiuuuAW EfSzDuRTdC rptjpHnxyM? FkLaTBruN IwuIQMdpdUpn etTVVJUsKztaR YNY EAENiDgJwYXDDrayjyuKp! yKqRNHznLRpnTqjisR LuapWDnWmwYDE NcClOZBNzMYrpa? SEZdSZIgBekpCPvyEiO AMjztArkFRJuS ilycvolFExqxrXJK. sLvBUxjIOomxUqYd jZsOXWN iBtqSykbeUbAsQgRVs DinPLrpzt.", "output": "3" }, { "input": "118\ngweVo bjbEKaZQw PpSi AWOYt sQSvAHNRswh vUaGuLbtExNECz! USsQxMCjaGOmUESwHvyY SshkERibaWkmNLSZOtWZy FFTUWQgekPRjLRetAdSFt! sIhcimZTisFvndrYioLF HetLn wjoaDUKfbkagupl QdYb fFiV GNqBygStKQw. XLiYZEOGnTLSHmCwktEr pVBePMoRGopNt LdEujxuxzmlbycQdR?", "output": "4" }, { "input": "16\nAbacaba. Abacaba. abacaba. abacab.", "output": "3" }, { "input": "21\nHello. I am a little walrus.", "output": "2" }, { "input": "16\nAbacaba. Abacab. abacaba. abacaba.", "output": "3" }, { "input": "10\nhello! how are you?", "output": "Impossible" }, { "input": "5\nabc. abcd.", "output": "2" }, { "input": "16\nabacaba. abacab. Abacaba. Abacaba.", "output": "3" }, { "input": "5\na. b. c. d.", "output": "2" }, { "input": "8\nabc! ab.", "output": "1" }, { "input": "2\na. b.", "output": "2" } ]
46
0
0
10,683
0
none
[ "none" ]
null
null
Есть *n*-подъездный дом, в каждом подъезде по *m* этажей, и на каждом этаже каждого подъезда ровно *k* квартир. Таким образом, в доме всего *n*·*m*·*k* квартир. Они пронумерованы естественным образом от 1 до *n*·*m*·*k*, то есть первая квартира на первом этаже в первом подъезде имеет номер 1, первая квартира на втором этаже первого подъезда имеет номер *k*<=+<=1 и так далее. Особенность этого дома состоит в том, что он круглый. То есть если обходить его по часовой стрелке, то после подъезда номер 1 следует подъезд номер 2, затем подъезд номер 3 и так далее до подъезда номер *n*. После подъезда номер *n* снова идёт подъезд номер 1. Эдвард живёт в квартире номер *a*, а Наташа — в квартире номер *b*. Переход на 1 этаж вверх или вниз по лестнице занимает 5 секунд, переход от двери подъезда к двери соседнего подъезда — 15 секунд, а переход в пределах одного этажа одного подъезда происходит мгновенно. Также в каждом подъезде дома есть лифт. Он устроен следующим образом: он всегда приезжает ровно через 10 секунд после вызова, а чтобы переместить пассажира на один этаж вверх или вниз, лифт тратит ровно 1 секунду. Посадка и высадка происходят мгновенно. Помогите Эдварду найти минимальное время, за которое он сможет добраться до квартиры Наташи. Считайте, что Эдвард может выйти из подъезда только с первого этажа соответствующего подъезда (это происходит мгновенно). Если Эдвард стоит перед дверью какого-то подъезда, он может зайти в него и сразу окажется на первом этаже этого подъезда (это также происходит мгновенно). Эдвард может выбирать, в каком направлении идти вокруг дома.
В первой строке входных данных следуют три числа *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — количество подъездов в доме, количество этажей в каждом подъезде и количество квартир на каждом этаже каждого подъезда соответственно. Во второй строке входных данных записаны два числа *a* и *b* (1<=≤<=*a*,<=*b*<=≤<=*n*·*m*·*k*) — номера квартир, в которых живут Эдвард и Наташа, соответственно. Гарантируется, что эти номера различны.
Выведите единственное целое число — минимальное время (в секундах), за которое Эдвард сможет добраться от своей квартиры до квартиры Наташи.
[ "4 10 5\n200 6\n", "3 1 5\n7 2\n" ]
[ "39\n", "15\n" ]
В первом тестовом примере Эдвард находится в 4 подъезде на 10 этаже, а Наташа находится в 1 подъезде на 2 этаже. Поэтому Эдварду выгодно сначала спуститься на лифте на первый этаж (на это он потратит 19 секунд, из которых 10 — на ожидание и 9 — на поездку на лифте), затем обойти дом против часовой стрелки до подъезда номер 1 (на это он потратит 15 секунд), и наконец подняться по лестнице на этаж номер 2 (на это он потратит 5 секунд). Таким образом, ответ равен 19 + 15 + 5 = 39. Во втором тестовом примере Эдвард живёт в подъезде 2 на этаже 1, а Наташа находится в подъезде 1 на этаже 1. Поэтому Эдварду выгодно просто обойти дом по часовой стрелке до подъезда 1, на это он потратит 15 секунд.
[ { "input": "4 10 5\n200 6", "output": "39" }, { "input": "3 1 5\n7 2", "output": "15" }, { "input": "100 100 100\n1 1000000", "output": "124" }, { "input": "1000 1000 1000\n1 1000000000", "output": "1024" }, { "input": "125 577 124\n7716799 6501425", "output": "1268" }, { "input": "624 919 789\n436620192 451753897", "output": "509" }, { "input": "314 156 453\n9938757 14172410", "output": "1104" }, { "input": "301 497 118\n11874825 13582548", "output": "994" }, { "input": "491 980 907\n253658701 421137262", "output": "3985" }, { "input": "35 296 7\n70033 65728", "output": "499" }, { "input": "186 312 492\n19512588 5916903", "output": "1560" }, { "input": "149 186 417\n11126072 11157575", "output": "85" }, { "input": "147 917 539\n55641190 66272443", "output": "952" }, { "input": "200 970 827\n113595903 145423943", "output": "1484" }, { "input": "32 15 441\n163561 23326", "output": "202" }, { "input": "748 428 661\n136899492 11286206", "output": "5347" }, { "input": "169 329 585\n30712888 19040968", "output": "1430" }, { "input": "885 743 317\n191981621 16917729", "output": "2825" }, { "input": "245 168 720\n24072381 125846", "output": "726" }, { "input": "593 174 843\n72930566 9954376", "output": "2650" }, { "input": "41 189 839\n6489169 411125", "output": "351" }, { "input": "437 727 320\n93935485 28179924", "output": "3007" }, { "input": "722 42 684\n18861511 1741045", "output": "1958" }, { "input": "324 584 915\n61572963 155302434", "output": "2756" }, { "input": "356 444 397\n1066682 58120717", "output": "860" }, { "input": "266 675 472\n11637902 74714734", "output": "1739" }, { "input": "841 727 726\n101540521 305197765", "output": "6264" }, { "input": "828 68 391\n3563177 21665321", "output": "2288" }, { "input": "666 140 721\n30509638 63426599", "output": "4995" }, { "input": "151 489 61\n2561086 4227874", "output": "1640" }, { "input": "713 882 468\n5456682 122694685", "output": "4687" }, { "input": "676 53 690\n1197227 20721162", "output": "2221" }, { "input": "618 373 56\n531564 11056643", "output": "2020" }, { "input": "727 645 804\n101269988 374485315", "output": "3289" }, { "input": "504 982 254\n101193488 5004310", "output": "2556" }, { "input": "872 437 360\n5030750 15975571", "output": "1736" }, { "input": "448 297 806\n60062303 9056580", "output": "3730" }, { "input": "165 198 834\n16752490 5105535", "output": "1354" }, { "input": "816 145 656\n32092038 5951215", "output": "4281" }, { "input": "28 883 178\n2217424 1296514", "output": "424" }, { "input": "24 644 653\n1326557 3894568", "output": "377" }, { "input": "717 887 838\n46183300 63974260", "output": "556" }, { "input": "101 315 916\n1624396 1651649", "output": "40" }, { "input": "604 743 433\n78480401 16837572", "output": "3833" }, { "input": "100 100 100\n1 10000", "output": "109" }, { "input": "100 100 100\n1000000 990001", "output": "109" }, { "input": "1 1 2\n1 2", "output": "0" }, { "input": "34 34 34\n20000 20001", "output": "0" }, { "input": "139 252 888\n24732218 24830663", "output": "121" }, { "input": "859 96 634\n26337024 26313792", "output": "47" }, { "input": "987 237 891\n41648697 41743430", "output": "117" }, { "input": "411 81 149\n4799008 4796779", "output": "25" }, { "input": "539 221 895\n18072378 18071555", "output": "5" }, { "input": "259 770 448\n19378646 19320867", "output": "139" }, { "input": "387 422 898\n89303312 89285292", "output": "30" }, { "input": "515 563 451\n12182093 12047399", "output": "309" }, { "input": "939 407 197\n42361632 42370846", "output": "57" }, { "input": "518 518 71\n3540577 3556866", "output": "239" }, { "input": "100 1 1\n55 1", "output": "690" }, { "input": "1000 1000 1000\n1 10000000", "output": "1144" }, { "input": "1000 1000 1000\n1000000000 990000001", "output": "1144" }, { "input": "340 340 340\n200000 200001", "output": "0" }, { "input": "1000 1 1\n556 1", "output": "6675" }, { "input": "2 3 4\n1 2", "output": "0" }, { "input": "2 3 4\n1 3", "output": "0" }, { "input": "2 3 4\n1 4", "output": "0" }, { "input": "2 3 4\n1 5", "output": "5" }, { "input": "2 3 4\n1 6", "output": "5" }, { "input": "2 3 4\n1 7", "output": "5" }, { "input": "2 3 4\n1 8", "output": "5" }, { "input": "2 3 4\n7 8", "output": "0" }, { "input": "2 3 4\n7 9", "output": "5" }, { "input": "2 3 4\n7 10", "output": "5" }, { "input": "2 3 4\n7 11", "output": "5" }, { "input": "2 3 4\n7 12", "output": "5" }, { "input": "2 3 4\n11 12", "output": "0" }, { "input": "2 3 4\n12 13", "output": "25" }, { "input": "2 3 4\n12 14", "output": "25" }, { "input": "2 3 4\n12 24", "output": "35" }, { "input": "1000 1000 1000\n600400021 600400051", "output": "0" }, { "input": "1 2 4\n7 8", "output": "0" }, { "input": "1 1000 1\n42 43", "output": "5" }, { "input": "10 10 1\n2 3", "output": "5" }, { "input": "1 3 1\n2 3", "output": "5" }, { "input": "1 9 1\n6 9", "output": "13" }, { "input": "4 10 5\n6 7", "output": "0" }, { "input": "1 10 10\n40 80", "output": "14" }, { "input": "1 5 1\n5 4", "output": "5" }, { "input": "1 1000 1\n42 228", "output": "196" }, { "input": "4 10 5\n200 199", "output": "0" }, { "input": "1 9 1\n6 7", "output": "5" }, { "input": "2 5 1\n10 9", "output": "5" }, { "input": "1 5 1\n1 5", "output": "14" }, { "input": "1 5 1\n2 5", "output": "13" }, { "input": "3 3 2\n3 5", "output": "5" }, { "input": "1 5 1\n4 5", "output": "5" }, { "input": "1 4 1\n2 4", "output": "10" }, { "input": "1 9 1\n3 6", "output": "13" } ]
30
4,608,000
0
10,687
212
IT Restaurants
[ "dfs and similar", "dp", "trees" ]
null
null
Сity N. has a huge problem with roads, food and IT-infrastructure. In total the city has *n* junctions, some pairs of them are connected by bidirectional roads. The road network consists of *n*<=-<=1 roads, you can get from any junction to any other one by these roads. Yes, you're right — the road network forms an undirected tree. Recently, the Mayor came up with a way that eliminates the problems with the food and the IT-infrastructure at the same time! He decided to put at the city junctions restaurants of two well-known cafe networks for IT professionals: "iMac D0naldz" and "Burger Bing". Since the network owners are not friends, it is strictly prohibited to place two restaurants of different networks on neighboring junctions. There are other requirements. Here's the full list: - each junction must have at most one restaurant; - each restaurant belongs either to "iMac D0naldz", or to "Burger Bing"; - each network should build at least one restaurant; - there is no pair of junctions that are connected by a road and contains restaurants of different networks. The Mayor is going to take a large tax from each restaurant, so he is interested in making the total number of the restaurants as large as possible. Help the Mayor to analyze the situation. Find all such pairs of (*a*,<=*b*) that *a* restaurants can belong to "iMac D0naldz", *b* restaurants can belong to "Burger Bing", and the sum of *a*<=+<=*b* is as large as possible.
The first input line contains integer *n* (3<=≤<=*n*<=≤<=5000) — the number of junctions in the city. Next *n*<=-<=1 lines list all roads one per line. Each road is given as a pair of integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the indexes of connected junctions. Consider the junctions indexed from 1 to *n*. It is guaranteed that the given road network is represented by an undirected tree with *n* vertexes.
Print on the first line integer *z* — the number of sought pairs. Then print all sought pairs (*a*,<=*b*) in the order of increasing of the first component *a*.
[ "5\n1 2\n2 3\n3 4\n4 5\n", "10\n1 2\n2 3\n3 4\n5 6\n6 7\n7 4\n8 9\n9 10\n10 4\n" ]
[ "3\n1 3\n2 2\n3 1\n", "6\n1 8\n2 7\n3 6\n6 3\n7 2\n8 1\n" ]
The figure below shows the answers to the first test case. The junctions with "iMac D0naldz" restaurants are marked red and "Burger Bing" restaurants are marked blue. <img class="tex-graphics" src="https://espresso.codeforces.com/acf0a2618a71a09921a44d636776197510b78cd4.png" style="max-width: 100.0%;max-height: 100.0%;"/>
[ { "input": "5\n1 2\n2 3\n3 4\n4 5", "output": "3\n1 3\n2 2\n3 1" }, { "input": "10\n1 2\n2 3\n3 4\n5 6\n6 7\n7 4\n8 9\n9 10\n10 4", "output": "6\n1 8\n2 7\n3 6\n6 3\n7 2\n8 1" }, { "input": "3\n3 1\n2 1", "output": "1\n1 1" }, { "input": "4\n4 3\n4 1\n4 2", "output": "2\n1 2\n2 1" }, { "input": "5\n5 4\n4 1\n5 2\n3 2", "output": "3\n1 3\n2 2\n3 1" }, { "input": "5\n1 4\n2 1\n5 1\n1 3", "output": "3\n1 3\n2 2\n3 1" }, { "input": "6\n1 5\n3 4\n6 1\n3 2\n3 1", "output": "4\n1 4\n2 3\n3 2\n4 1" }, { "input": "6\n5 1\n1 2\n1 3\n6 1\n4 1", "output": "4\n1 4\n2 3\n3 2\n4 1" }, { "input": "6\n5 4\n2 1\n2 5\n3 4\n3 6", "output": "4\n1 4\n2 3\n3 2\n4 1" }, { "input": "18\n7 12\n14 8\n11 4\n6 3\n2 3\n15 10\n8 16\n6 16\n15 18\n18 16\n5 9\n11 17\n13 9\n10 7\n8 9\n7 1\n4 3", "output": "12\n1 16\n2 15\n3 14\n4 13\n5 12\n6 11\n11 6\n12 5\n13 4\n14 3\n15 2\n16 1" }, { "input": "7\n6 1\n7 4\n2 5\n3 7\n6 4\n5 4", "output": "4\n1 5\n2 4\n4 2\n5 1" }, { "input": "8\n7 3\n7 8\n5 6\n7 4\n2 5\n5 4\n1 8", "output": "6\n1 6\n2 5\n3 4\n4 3\n5 2\n6 1" }, { "input": "9\n7 3\n3 8\n2 1\n7 2\n8 4\n1 9\n6 5\n7 6", "output": "6\n1 7\n2 6\n3 5\n5 3\n6 2\n7 1" }, { "input": "9\n7 3\n3 8\n2 1\n7 2\n8 4\n1 9\n6 5\n7 6", "output": "6\n1 7\n2 6\n3 5\n5 3\n6 2\n7 1" }, { "input": "10\n4 5\n9 7\n1 6\n2 5\n7 4\n6 10\n8 3\n4 3\n6 7", "output": "8\n1 8\n2 7\n3 6\n4 5\n5 4\n6 3\n7 2\n8 1" }, { "input": "11\n6 11\n2 9\n11 3\n7 10\n4 6\n8 3\n2 5\n7 9\n11 2\n3 1", "output": "9\n1 9\n2 8\n3 7\n4 6\n5 5\n6 4\n7 3\n8 2\n9 1" }, { "input": "15\n7 11\n9 15\n6 12\n15 8\n4 2\n6 15\n6 5\n1 10\n14 9\n12 3\n10 3\n5 11\n13 2\n11 2", "output": "12\n1 13\n2 12\n3 11\n4 10\n5 9\n6 8\n8 6\n9 5\n10 4\n11 3\n12 2\n13 1" }, { "input": "16\n4 10\n2 12\n6 15\n12 5\n6 16\n7 16\n14 16\n10 15\n5 3\n11 15\n8 16\n13 8\n1 3\n5 9\n6 5", "output": "12\n1 14\n2 13\n3 12\n4 11\n5 10\n6 9\n9 6\n10 5\n11 4\n12 3\n13 2\n14 1" }, { "input": "20\n16 10\n8 6\n9 17\n9 5\n4 5\n3 7\n13 6\n19 5\n13 9\n10 8\n12 2\n2 14\n17 11\n18 20\n3 14\n18 19\n12 15\n9 14\n1 15", "output": "16\n1 18\n2 17\n3 16\n4 15\n5 14\n6 13\n7 12\n9 10\n10 9\n12 7\n13 6\n14 5\n15 4\n16 3\n17 2\n18 1" }, { "input": "20\n3 4\n17 11\n8 15\n7 20\n1 11\n5 4\n6 10\n19 6\n12 5\n7 19\n14 12\n14 16\n19 2\n18 7\n9 13\n17 13\n12 18\n9 18\n6 15", "output": "16\n1 18\n2 17\n3 16\n4 15\n5 14\n6 13\n7 12\n8 11\n11 8\n12 7\n13 6\n14 5\n15 4\n16 3\n17 2\n18 1" } ]
31
0
0
10,704
914
Ember and Storm's Tree Game
[ "combinatorics", "dp", "games", "trees" ]
null
null
Ember and Storm play a game. First, Ember picks a labelled tree *T* of *n* vertices, such that the degree of every vertex is at most *d*. Then, Storm picks two distinct vertices *u* and *v* in this tree and writes down the labels of the vertices in the path from *u* to *v* in a sequence *a*1,<=*a*2... *a**k*. Finally, Ember picks any index *i* (1<=≤<=*i*<=&lt;<=*k*) in the array. Now he performs one of the following two operations exactly once: - flip the subrange [*i*<=+<=1,<=*k*] and add *a**i* to it. After this, the sequence becomes *a*1,<=... *a**i*,<=*a**k*<=+<=*a**i*,<=*a**k*<=-<=1<=+<=*a**i*,<=... *a**i*<=+<=1<=+<=*a**i* - negate the subrange [*i*<=+<=1,<=*k*] and add *a**i* to it. i.e., the array becomes *a*1,<=... *a**i*,<=<=-<=*a**i*<=+<=1<=+<=*a**i*,<=<=-<=*a**i*<=+<=2<=+<=*a**i*,<=...<=-<=*a**k*<=+<=*a**i* Ember wins if the array is monotonically increasing or decreasing after this. Otherwise Storm wins. The game can be described by the tuple (*T*,<=*u*,<=*v*,<=*i*,<=*op*) where *op* is «flip» or «negate» depending on the action Ember chose in the last turn. Find the number of tuples that can occur if Ember and Storm play optimally. When they play optimally, if there are multiple moves by which they are guaranteed to win, then they may play any of the winning moves. Otherwise, if someone loses no matter what they play, then they may play any of the possible moves. Report the answer modulo *m*.
The input consists of a single line containing three integers *n*, *d* and *m* (2<=≤<=*n*<=≤<=200,<=1<=≤<=*d*<=&lt;<=*n*,<=1<=≤<=*m*<=≤<=2·109).
Print a single number  — the number of possible tuples if Ember and Storm play as described, modulo *m*.
[ "2 1 1000000007\n", "3 1 250\n", "3 2 100\n" ]
[ "4\n", "0\n", "36\n" ]
In the first sample case, there is only one possible tree. There are two possible paths, 1 to 2 and 2 to 1. For both paths, *i* can only be 1, and *op* can take both possibilities. Therefore, the answer is 4. In the second sample, there are no possible trees. In the third sample, there are three possible trees.
[]
15
0
0
10,706
285
Permutation Sum
[ "bitmasks", "combinatorics", "dp", "implementation", "meet-in-the-middle" ]
null
null
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. Petya decided to introduce the sum operation on the set of permutations of length *n*. Let's assume that we are given two permutations of length *n*: *a*1,<=*a*2,<=...,<=*a**n* and *b*1,<=*b*2,<=...,<=*b**n*. Petya calls the sum of permutations *a* and *b* such permutation *c* of length *n*, where *c**i*<==<=((*a**i*<=-<=1<=+<=*b**i*<=-<=1) *mod* *n*)<=+<=1 (1<=≤<=*i*<=≤<=*n*). Operation means taking the remainder after dividing number *x* by number *y*. Obviously, not for all permutations *a* and *b* exists permutation *c* that is sum of *a* and *b*. That's why Petya got sad and asked you to do the following: given *n*, count the number of such pairs of permutations *a* and *b* of length *n*, that exists permutation *c* that is sum of *a* and *b*. The pair of permutations *x*,<=*y* (*x*<=≠<=*y*) and the pair of permutations *y*,<=*x* are considered distinct pairs. As the answer can be rather large, print the remainder after dividing it by 1000000007 (109<=+<=7).
The single line contains integer *n* (1<=≤<=*n*<=≤<=16).
In the single line print a single non-negative integer — the number of such pairs of permutations *a* and *b*, that exists permutation *c* that is sum of *a* and *b*, modulo 1000000007 (109<=+<=7).
[ "3\n", "5\n" ]
[ "18\n", "1800\n" ]
none
[ { "input": "3", "output": "18" }, { "input": "5", "output": "1800" }, { "input": "13", "output": "695720788" }, { "input": "1", "output": "1" }, { "input": "2", "output": "0" }, { "input": "4", "output": "0" }, { "input": "6", "output": "0" }, { "input": "15", "output": "150347555" }, { "input": "16", "output": "0" }, { "input": "7", "output": "670320" }, { "input": "8", "output": "0" }, { "input": "9", "output": "734832000" }, { "input": "10", "output": "0" }, { "input": "11", "output": "890786230" }, { "input": "12", "output": "0" }, { "input": "14", "output": "0" } ]
122
0
3
10,750
586
Laurenty and Shop
[ "implementation" ]
null
null
A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese. The town where Laurenty lives in is not large. The houses in it are located in two rows, *n* houses in each row. Laurenty lives in the very last house of the second row. The only shop in town is placed in the first house of the first row. The first and second rows are separated with the main avenue of the city. The adjacent houses of one row are separated by streets. Each crosswalk of a street or an avenue has some traffic lights. In order to cross the street, you need to press a button on the traffic light, wait for a while for the green light and cross the street. Different traffic lights can have different waiting time. The traffic light on the crosswalk from the *j*-th house of the *i*-th row to the (*j*<=+<=1)-th house of the same row has waiting time equal to *a**ij* (1<=≤<=*i*<=≤<=2,<=1<=≤<=*j*<=≤<=*n*<=-<=1). For the traffic light on the crossing from the *j*-th house of one row to the *j*-th house of another row the waiting time equals *b**j* (1<=≤<=*j*<=≤<=*n*). The city doesn't have any other crossings. The boy wants to get to the store, buy the products and go back. The main avenue of the city is wide enough, so the boy wants to cross it exactly once on the way to the store and exactly once on the way back home. The boy would get bored if he had to walk the same way again, so he wants the way home to be different from the way to the store in at least one crossing. Help Laurenty determine the minimum total time he needs to wait at the crossroads.
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=50) — the number of houses in each row. Each of the next two lines contains *n*<=-<=1 space-separated integer — values *a**ij* (1<=≤<=*a**ij*<=≤<=100). The last line contains *n* space-separated integers *b**j* (1<=≤<=*b**j*<=≤<=100).
Print a single integer — the least total time Laurenty needs to wait at the crossroads, given that he crosses the avenue only once both on his way to the store and on his way back home.
[ "4\n1 2 3\n3 2 1\n3 2 2 3\n", "3\n1 2\n3 3\n2 1 3\n", "2\n1\n1\n1 1\n" ]
[ "12\n", "11\n", "4\n" ]
The first sample is shown on the figure above. In the second sample, Laurenty's path can look as follows: - Laurenty crosses the avenue, the waiting time is 3; - Laurenty uses the second crossing in the first row, the waiting time is 2; - Laurenty uses the first crossing in the first row, the waiting time is 1; - Laurenty uses the first crossing in the first row, the waiting time is 1; - Laurenty crosses the avenue, the waiting time is 1; - Laurenty uses the second crossing in the second row, the waiting time is 3. In the last sample Laurenty visits all the crossings, so the answer is 4.
[ { "input": "4\n1 2 3\n3 2 1\n3 2 2 3", "output": "12" }, { "input": "3\n1 2\n3 3\n2 1 3", "output": "11" }, { "input": "2\n1\n1\n1 1", "output": "4" }, { "input": "2\n1\n1\n2 1", "output": "5" }, { "input": "3\n1 100\n1 1\n100 100 100", "output": "204" }, { "input": "4\n5 6 7\n8 9 10\n1 8 8 1", "output": "47" }, { "input": "4\n1 2 3\n2 2 3\n2 3 4 3", "output": "18" }, { "input": "48\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "96" }, { "input": "48\n2 1 1 2 1 1 1 1 2 2 2 1 2 2 2 1 1 2 1 2 1 2 2 2 2 1 1 2 2 1 1 2 2 1 1 1 2 2 2 2 1 2 1 1 1 1 1\n1 1 1 1 1 1 2 1 2 1 1 2 2 1 2 2 2 1 2 2 2 2 1 1 1 2 1 1 2 2 1 2 2 1 2 2 1 2 2 1 1 2 2 1 1 2 2\n2 1 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 1 1 1 2 1 1 2 1 1 2 2 2 1 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1", "output": "143" }, { "input": "48\n7 3 1 5 3 8 5 6 4 6 8 7 7 6 9 6 4 1 10 3 2 7 6 9 4 9 1 10 6 10 9 1 5 7 8 8 1 1 3 2 2 10 3 7 8 4 7\n4 9 9 4 2 6 2 4 3 9 2 9 7 3 10 1 5 2 2 10 2 1 6 2 10 5 4 6 10 2 5 10 3 1 8 1 2 6 5 2 3 5 8 1 1 8 4\n4 6 4 3 10 4 8 9 1 10 4 2 2 10 4 7 4 5 4 1 10 6 10 8 4 9 4 10 8 5 3 2 10 10 1 10 10 10 6 10 1 7 6 10 5 8 6 4", "output": "435" }, { "input": "48\n47 3 47 2 29 33 39 16 27 34 31 9 2 40 16 28 15 8 37 9 25 36 14 5 24 48 49 26 43 47 46 23 31 27 30 44 34 12 41 21 2 9 27 49 42 27 9\n6 46 24 12 19 6 39 50 37 30 39 44 14 9 39 47 13 13 1 28 36 22 15 28 43 22 2 19 36 48 34 45 44 9 24 28 41 20 39 8 19 23 25 36 37 16 21\n1 35 9 12 25 39 4 27 26 20 15 4 28 30 21 46 34 30 39 22 6 2 31 2 27 44 3 16 47 12 8 32 37 37 47 8 40 2 2 4 33 38 20 25 3 43 45 45", "output": "2404" }, { "input": "48\n25 48 43 29 32 6 22 4 33 17 25 2 50 19 39 45 38 8 5 3 23 14 24 31 35 11 20 37 10 13 14 43 18 6 42 44 14 37 29 28 2 20 12 3 30 11 24\n46 14 32 22 21 37 6 42 26 20 10 45 18 20 2 36 41 44 17 17 10 21 45 23 26 41 6 45 16 4 16 48 2 6 26 8 15 1 48 30 20 27 39 24 49 27 36\n10 29 17 21 21 13 27 43 27 3 33 20 22 39 37 21 9 41 7 23 30 17 31 4 45 49 9 43 41 42 38 30 5 49 45 30 43 3 2 43 29 35 11 47 12 12 15 43", "output": "2243" }, { "input": "48\n3 42 46 11 44 25 1 42 38 49 14 42 44 10 4 12 2 20 27 44 14 50 33 10 42 27 41 48 26 42 40 18 9 42 1 2 47 8 20 39 45 42 47 8 19 41 32\n36 32 45 48 26 26 38 38 10 7 31 50 23 23 15 17 18 25 24 44 29 12 29 30 16 14 18 20 50 10 3 1 10 7 32 35 43 36 20 40 16 26 12 8 20 38 5\n19 15 33 18 13 29 50 17 28 48 2 36 13 2 12 43 47 6 17 40 8 28 27 15 14 9 10 37 47 25 10 19 11 11 32 3 45 9 11 33 18 35 43 14 13 27 31 34", "output": "2202" }, { "input": "48\n26 55 85 65 66 16 31 85 42 78 14 83 42 52 22 32 73 68 30 92 82 18 43 40 43 36 87 77 64 61 46 79 88 86 92 16 28 47 89 34 58 47 76 24 100 27 80\n78 15 79 90 84 28 98 65 60 65 5 65 89 9 72 9 52 52 85 77 66 9 78 76 4 76 3 26 77 91 58 76 76 17 50 83 64 83 40 1 6 61 37 20 55 7 82\n61 19 9 30 98 19 6 4 36 32 54 99 18 46 28 24 12 1 21 15 38 23 39 82 66 92 95 88 65 97 98 4 22 62 96 79 1 8 85 82 38 71 50 82 4 81 58 57", "output": "4754" }, { "input": "48\n54 99 43 46 23 80 6 77 2 60 54 26 32 93 45 41 92 23 49 33 31 100 52 19 4 61 4 38 89 27 72 58 79 22 5 20 58 14 30 49 55 69 65 79 97 15 92\n22 41 46 100 36 13 14 61 94 56 26 12 93 12 77 48 34 83 38 66 86 100 16 25 90 91 15 2 12 48 45 25 84 68 98 14 88 22 16 65 53 11 56 54 68 10 39\n74 17 18 74 36 43 75 82 41 15 73 65 17 9 45 95 88 66 93 78 70 88 88 39 35 60 100 70 63 27 75 10 78 78 90 2 57 14 97 29 88 72 45 99 55 46 24 6", "output": "4262" }, { "input": "48\n82 39 88 16 77 57 94 61 57 42 93 70 26 26 60 58 14 85 67 85 83 78 57 3 61 69 25 91 97 97 94 24 66 55 10 24 88 85 68 60 52 80 46 33 85 98 3\n58 59 5 18 92 6 46 57 36 47 51 67 5 24 94 83 7 15 3 42 13 98 50 78 76 6 19 77 42 8 28 78 88 22 54 40 12 56 76 37 95 53 74 92 88 22 100\n83 8 34 25 78 60 48 57 42 10 91 35 8 72 69 71 75 31 65 28 2 45 30 87 91 16 1 55 64 56 55 99 46 93 89 24 6 15 97 72 39 73 24 24 14 15 86 47", "output": "4664" }, { "input": "48\n2 92 42 94 30 34 65 53 13 24 37 14 17 63 83 79 37 31 93 26 28 60 67 74 22 77 42 52 17 67 20 95 54 91 15 36 18 60 6 62 45 94 31 92 78 82 15\n2 73 72 31 32 92 67 49 75 30 72 22 13 31 3 22 89 50 69 27 33 89 84 26 59 33 34 48 72 64 15 35 4 65 10 70 36 91 48 4 46 2 93 26 1 29 69\n92 2 42 76 12 84 29 19 43 93 10 97 3 31 86 42 51 96 29 87 26 10 79 40 64 79 7 49 66 90 27 93 7 5 83 38 50 21 6 11 85 77 14 41 69 83 52 95", "output": "4018" }, { "input": "48\n30 36 96 71 92 99 48 41 72 3 77 61 7 97 98 96 51 93 11 67 76 45 84 57 79 85 63 13 34 38 39 77 53 23 27 32 39 35 43 81 42 13 16 46 75 66 22\n46 91 30 49 88 81 95 45 9 13 93 69 17 42 20 57 79 73 34 16 57 88 18 83 57 44 46 24 2 20 2 80 12 20 66 97 59 34 12 68 92 56 16 64 17 32 34\n97 100 50 24 58 100 99 93 45 88 24 66 93 98 10 17 38 72 98 46 50 83 21 100 32 35 4 34 60 20 7 95 59 12 73 60 2 27 10 55 35 74 9 58 32 48 18 36", "output": "4492" }, { "input": "49\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "98" }, { "input": "49\n1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 2 2 2 2 1 2 2 1 1 2 1 2 1 1 1 1 1 2 2 2 1 2 1 2 2 2 2 2 2 1 2\n2 2 2 1 1 2 1 1 2 2 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 1 1 1 2 1 1 2 2 2 2 2 2 2 2 2 2 2 1 1\n2 2 1 2 2 1 1 1 2 2 1 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 2 2 2 1 2 2 1 1 1 2 1 2 2 2 1 2 2 1 1 1", "output": "136" }, { "input": "49\n5 1 1 2 6 1 10 9 5 5 1 3 6 7 2 3 4 5 7 10 6 7 1 1 5 10 7 5 5 8 6 3 6 5 8 10 4 8 2 1 6 7 3 3 2 6 1 9\n9 7 2 1 10 9 9 4 10 5 9 8 1 7 7 4 6 5 6 4 3 3 3 10 7 8 9 3 6 6 1 8 8 6 7 7 2 5 4 9 5 10 8 5 8 8 4 2\n9 10 9 9 7 3 10 5 7 8 2 6 3 1 7 3 1 3 6 4 4 5 10 2 7 9 7 10 1 2 6 2 2 8 9 9 10 10 8 10 9 7 8 9 3 8 8 3 7", "output": "476" }, { "input": "49\n9 3 7 10 7 8 5 1 10 7 10 2 2 8 7 2 7 9 6 9 7 1 10 2 2 7 8 6 1 8 2 6 3 8 3 6 3 9 4 2 9 1 4 10 1 3 5 9\n7 6 9 7 3 8 5 8 7 6 8 2 2 10 6 2 3 10 1 2 4 7 8 7 2 9 8 7 8 3 6 6 9 8 8 1 5 2 3 2 4 9 6 7 9 3 1 3\n8 1 1 3 10 7 1 2 4 10 10 9 8 1 6 8 3 4 8 7 4 2 10 2 2 4 1 10 3 6 8 3 4 10 1 4 3 4 8 7 1 4 9 3 3 6 2 4 2", "output": "523" }, { "input": "49\n37 26 4 44 25 50 32 7 34 46 49 12 7 41 26 30 17 1 27 50 35 48 42 29 30 21 17 26 16 36 13 22 49 17 38 21 11 9 5 36 44 47 17 36 13 28 29 15\n29 42 5 42 1 43 22 15 34 35 42 13 41 40 2 35 35 35 30 4 35 6 13 19 10 25 4 8 50 14 36 33 45 43 7 1 42 44 10 30 12 48 30 4 28 33 31 43\n27 36 12 11 35 41 36 14 5 39 30 39 46 3 46 10 46 47 2 21 12 43 1 2 26 14 24 19 8 29 16 45 7 19 2 50 49 46 20 45 39 2 35 43 46 4 41 20 20", "output": "2472" }, { "input": "49\n11 20 15 26 29 19 7 45 43 28 39 9 47 24 49 1 32 13 45 49 38 26 5 12 41 37 38 33 32 3 39 4 36 3 35 29 45 30 42 43 49 11 10 49 1 16 45 1\n47 9 19 36 32 18 14 49 25 10 47 26 45 49 41 13 9 50 15 31 34 32 7 9 25 37 29 46 2 1 39 48 50 49 33 25 23 12 24 30 11 16 10 20 35 48 40 42\n43 37 4 35 12 8 37 9 19 5 28 2 21 25 26 24 6 6 34 36 12 50 19 8 32 41 18 49 34 26 22 11 5 37 4 2 15 43 13 42 22 23 40 8 16 49 48 31 29", "output": "2542" }, { "input": "49\n35 14 11 50 36 42 45 37 49 10 28 49 45 4 14 10 4 13 17 44 28 12 15 41 48 49 5 44 49 23 7 21 36 35 48 30 21 5 26 50 42 30 37 3 2 49 2 45\n19 18 36 37 30 42 10 34 16 27 2 34 6 16 27 45 44 15 50 5 25 20 6 41 48 2 50 30 8 38 46 2 50 5 17 48 16 30 45 23 11 35 44 29 39 13 49 28\n1 39 4 2 36 32 38 42 42 25 19 11 37 50 9 35 28 10 7 47 3 6 42 26 29 27 16 29 11 24 37 26 42 9 11 11 16 36 9 39 17 44 49 26 32 47 1 29 37", "output": "2612" }, { "input": "49\n75 32 47 38 45 100 90 67 82 21 4 16 61 69 49 86 95 13 79 70 92 98 92 48 64 1 95 47 90 31 41 12 89 98 22 95 62 54 94 57 43 1 72 8 12 71 98 41\n40 31 71 13 20 32 48 81 17 13 68 6 48 50 44 17 37 8 76 100 57 65 91 15 51 33 83 64 44 66 22 20 44 69 18 32 50 91 43 25 95 42 28 20 16 68 69 70\n52 51 67 93 7 99 59 90 53 66 35 25 8 89 80 64 49 80 87 76 3 38 71 86 88 18 41 91 55 27 12 84 44 81 14 51 35 82 33 93 1 50 62 30 65 60 41 12 85", "output": "4518" }, { "input": "49\n99 77 96 11 98 68 62 59 38 4 44 64 51 6 60 3 10 71 97 18 44 75 9 28 25 9 16 4 7 9 63 90 84 31 35 91 96 29 31 60 32 16 57 66 8 55 6 77\n54 98 89 57 9 52 40 15 99 34 23 10 52 59 79 99 72 66 56 24 56 99 48 2 66 45 58 95 1 53 75 36 94 22 45 60 85 63 14 71 41 72 65 37 20 33 82 65\n60 98 13 18 76 61 60 85 63 28 34 84 32 64 60 29 21 39 15 37 53 94 40 41 94 3 39 21 35 17 77 92 42 7 58 53 39 30 79 93 96 68 25 94 31 9 48 26 35", "output": "4427" }, { "input": "49\n27 21 50 89 60 45 49 47 1 82 88 11 49 43 87 20 32 26 19 63 93 61 14 11 82 22 33 61 23 76 81 61 79 67 36 99 30 4 69 70 37 38 34 21 1 38 21 21\n72 57 11 8 2 81 44 49 90 55 70 18 63 72 18 73 3 27 41 47 47 33 93 88 85 49 29 29 61 44 32 44 53 78 75 84 24 23 86 18 91 91 3 53 31 2 91 59\n68 49 48 34 49 40 57 76 82 90 32 43 49 31 48 89 89 93 43 9 94 55 97 1 99 89 45 54 7 7 33 15 37 22 10 59 48 73 25 90 87 85 76 63 1 57 55 25 94", "output": "4541" }, { "input": "49\n51 65 96 71 14 18 24 31 56 68 27 51 40 81 98 29 55 84 41 4 41 43 28 90 39 38 55 22 35 46 8 31 66 95 48 3 55 79 6 85 30 49 19 75 90 22 29 65\n90 23 25 64 88 1 40 96 77 76 25 22 66 81 53 54 27 92 26 67 46 71 41 74 100 60 5 55 21 31 77 60 95 38 5 8 59 99 50 65 40 10 29 66 38 63 9 53\n84 100 94 58 22 14 58 63 4 60 19 2 73 7 23 58 61 52 67 74 48 3 65 65 1 82 38 84 95 13 1 27 27 44 58 64 48 8 80 86 77 10 35 28 59 98 62 36 53", "output": "4447" }, { "input": "49\n75 14 49 48 71 87 8 23 20 50 75 95 30 14 25 50 77 38 59 57 82 21 45 69 100 46 80 83 56 16 34 9 57 32 57 7 89 50 44 96 31 71 12 34 86 10 40 1\n4 82 38 4 73 33 32 30 68 1 80 35 77 98 89 28 62 54 7 95 37 5 94 61 24 76 80 89 65 18 30 64 50 90 40 27 94 59 22 11 94 28 67 82 49 28 14 47\n92 48 28 74 4 88 59 58 23 21 18 73 90 78 7 23 26 14 3 31 90 56 22 20 98 68 36 18 71 3 57 35 21 66 2 70 56 51 18 99 60 27 98 97 29 51 69 38 12", "output": "4688" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "50\n19 43 43 6 20 8 25 17 19 22 27 30 50 1 16 18 6 48 28 26 15 12 38 6 11 13 4 9 24 47 38 11 27 15 3 7 17 40 32 25 38 21 7 20 23 19 44 13 25\n40 21 42 10 13 34 13 8 39 13 29 43 7 4 22 47 50 45 10 1 43 5 44 11 46 40 24 44 27 9 26 18 24 34 25 49 19 39 24 36 32 6 2 25 33 35 44 6 41\n37 48 32 4 4 41 5 5 30 15 48 11 6 29 5 45 40 13 16 34 19 10 44 24 42 27 3 11 29 8 13 12 25 43 14 36 2 1 48 4 24 42 5 4 22 19 25 21 8 41", "output": "2189" }, { "input": "50\n47 38 39 30 32 23 9 5 28 4 17 20 36 31 35 39 29 6 46 20 14 40 47 35 18 21 13 23 40 18 14 32 18 1 16 12 43 11 19 40 31 32 38 16 12 48 9 7 39\n3 35 43 7 33 30 43 49 14 19 37 46 13 39 4 32 16 30 30 42 27 4 39 34 7 7 9 4 10 12 34 15 34 14 49 38 45 3 21 36 47 44 15 29 48 44 35 15 42\n29 14 5 20 5 28 19 21 17 24 14 29 40 40 15 4 26 28 15 37 38 15 38 10 36 11 29 1 43 23 11 27 23 49 23 29 49 47 39 22 33 11 17 45 33 34 34 41 36 32", "output": "2553" }, { "input": "50\n30 98 29 67 86 51 9 45 25 85 75 2 91 37 7 29 14 92 46 14 8 4 98 40 62 90 10 41 77 95 16 74 11 4 86 64 66 21 33 99 74 1 29 31 66 20 91 14 15\n28 41 39 21 17 86 46 45 41 52 62 9 93 44 26 18 97 81 57 97 68 65 2 58 30 54 96 68 20 18 78 56 84 43 92 33 66 60 25 97 8 71 55 79 58 33 47 59 63\n90 82 54 3 42 44 43 71 16 93 91 64 43 51 30 3 87 22 60 83 13 24 64 3 9 73 64 24 29 60 63 49 61 63 9 34 85 83 23 80 17 63 53 100 70 20 19 92 66 63", "output": "4675" }, { "input": "50\n55 51 83 45 43 16 84 33 80 71 23 46 82 74 34 46 28 43 68 59 60 90 8 23 19 99 32 98 85 61 42 56 6 40 95 72 100 92 71 18 67 24 6 89 55 8 3 50 41\n90 59 91 11 45 78 81 35 58 7 70 12 98 79 8 53 54 66 80 88 6 17 88 73 45 29 26 24 7 71 82 2 44 74 16 76 38 28 72 43 34 5 72 90 23 43 41 76 14\n24 94 31 77 43 27 62 25 7 52 8 39 26 16 94 58 11 83 9 39 77 92 62 96 3 3 36 22 94 71 53 71 13 69 18 77 32 80 14 1 76 23 19 45 77 23 73 66 44 58", "output": "4620" }, { "input": "50\n83 91 33 26 97 92 67 25 36 49 62 89 72 7 45 56 54 5 86 100 1 68 17 6 80 11 53 55 9 28 60 26 1 72 7 68 22 67 9 24 68 34 99 44 52 91 14 94 55\n53 81 43 92 66 74 19 18 79 58 83 23 15 14 90 85 16 50 4 87 32 66 74 88 57 96 60 84 94 16 98 53 92 4 36 11 10 96 18 96 57 43 84 94 84 52 35 84 62\n66 14 4 51 44 22 80 94 2 15 32 6 6 81 66 21 43 43 55 88 46 47 63 82 8 36 24 20 54 87 48 94 53 75 18 16 70 77 9 22 31 92 85 93 80 30 32 36 23 45", "output": "4859" }, { "input": "50\n3 35 86 4 51 65 51 9 95 31 6 29 66 36 68 77 73 59 4 49 49 50 34 86 37 27 74 16 22 98 91 93 93 9 8 80 52 38 46 35 60 49 84 2 40 79 26 38 74\n16 99 87 89 98 66 53 5 100 9 87 27 24 53 63 8 81 31 28 86 66 15 61 3 69 76 90 32 77 69 6 7 44 30 60 46 70 68 61 46 76 81 5 5 45 61 29 92 9\n4 31 74 17 49 5 95 56 100 82 49 82 89 46 38 79 67 4 4 40 7 11 65 67 2 66 100 14 10 3 46 8 5 81 30 55 24 81 96 39 90 61 47 42 91 36 87 6 6 44", "output": "4472" }, { "input": "50\n31 80 40 85 12 38 30 97 51 18 45 81 56 82 91 94 95 13 26 93 98 35 44 69 98 39 83 77 38 68 13 71 80 41 21 80 81 17 88 46 61 67 65 49 29 55 37 74 88\n71 8 42 74 14 70 100 96 25 56 95 38 41 88 45 43 46 16 55 77 100 68 51 30 73 51 25 88 64 26 22 50 4 57 88 85 45 32 11 96 94 19 9 12 10 66 24 8 60\n46 55 55 95 50 96 13 26 91 41 74 53 65 10 11 30 99 77 46 93 71 67 70 44 100 96 73 8 74 14 32 30 62 87 31 3 71 78 82 60 41 26 17 87 98 39 45 80 84 39", "output": "4804" }, { "input": "50\n55 24 86 55 70 15 9 89 6 96 85 20 47 11 6 11 18 75 44 34 50 13 53 40 59 48 4 30 54 34 31 46 75 73 26 85 15 92 21 56 58 81 54 3 26 42 53 18 6\n37 22 90 56 39 67 34 83 46 11 7 49 58 27 23 74 100 1 83 76 38 17 41 45 84 26 51 48 47 75 26 4 60 87 7 20 13 3 58 45 13 57 22 23 79 75 18 17 7\n80 71 24 69 51 91 35 92 90 100 90 28 52 71 67 89 31 42 92 53 40 26 75 38 98 30 53 6 34 30 31 52 6 92 43 46 17 75 73 74 4 95 79 35 5 46 4 58 63 26", "output": "3834" } ]
62
0
3
10,754
618
Guess the Permutation
[ "constructive algorithms" ]
null
null
Bob has a permutation of integers from 1 to *n*. Denote this permutation as *p*. The *i*-th element of *p* will be denoted as *p**i*. For all pairs of distinct integers *i*,<=*j* between 1 and *n*, he wrote the number *a**i*,<=*j*<==<=*min*(*p**i*,<=*p**j*). He writes *a**i*,<=*i*<==<=0 for all integer *i* from 1 to *n*. Bob gave you all the values of *a**i*,<=*j* that he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given.
The first line of the input will contain a single integer *n* (2<=≤<=*n*<=≤<=50). The next *n* lines will contain the values of *a**i*,<=*j*. The *j*-th number on the *i*-th line will represent *a**i*,<=*j*. The *i*-th number on the *i*-th line will be 0. It's guaranteed that *a**i*,<=*j*<==<=*a**j*,<=*i* and there is at least one solution consistent with the information given.
Print *n* space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
[ "2\n0 1\n1 0\n", "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0\n" ]
[ "2 1\n", "2 5 4 1 3\n" ]
In the first case, the answer can be {1, 2} or {2, 1}. In the second case, another possible answer is {2, 4, 5, 1, 3}.
[ { "input": "2\n0 1\n1 0", "output": "2 1" }, { "input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "output": "2 5 4 1 3" }, { "input": "10\n0 1 5 2 5 3 4 5 5 5\n1 0 1 1 1 1 1 1 1 1\n5 1 0 2 6 3 4 6 6 6\n2 1 2 0 2 2 2 2 2 2\n5 1 6 2 0 3 4 8 8 7\n3 1 3 2 3 0 3 3 3 3\n4 1 4 2 4 3 0 4 4 4\n5 1 6 2 8 3 4 0 9 7\n5 1 6 2 8 3 4 9 0 7\n5 1 6 2 7 3 4 7 7 0", "output": "5 1 6 2 8 3 4 10 9 7" }, { "input": "4\n0 1 3 2\n1 0 1 1\n3 1 0 2\n2 1 2 0", "output": "4 1 3 2" }, { "input": "7\n0 3 2 4 1 4 4\n3 0 2 3 1 3 3\n2 2 0 2 1 2 2\n4 3 2 0 1 5 5\n1 1 1 1 0 1 1\n4 3 2 5 1 0 6\n4 3 2 5 1 6 0", "output": "4 3 2 5 1 7 6" }, { "input": "10\n0 4 4 1 4 4 4 2 3 4\n4 0 5 1 6 8 9 2 3 7\n4 5 0 1 5 5 5 2 3 5\n1 1 1 0 1 1 1 1 1 1\n4 6 5 1 0 6 6 2 3 6\n4 8 5 1 6 0 8 2 3 7\n4 9 5 1 6 8 0 2 3 7\n2 2 2 1 2 2 2 0 2 2\n3 3 3 1 3 3 3 2 0 3\n4 7 5 1 6 7 7 2 3 0", "output": "4 10 5 1 6 8 9 2 3 7" }, { "input": "13\n0 5 5 2 5 4 5 5 3 5 5 5 1\n5 0 6 2 6 4 6 6 3 6 6 6 1\n5 6 0 2 10 4 7 10 3 8 10 9 1\n2 2 2 0 2 2 2 2 2 2 2 2 1\n5 6 10 2 0 4 7 12 3 8 11 9 1\n4 4 4 2 4 0 4 4 3 4 4 4 1\n5 6 7 2 7 4 0 7 3 7 7 7 1\n5 6 10 2 12 4 7 0 3 8 11 9 1\n3 3 3 2 3 3 3 3 0 3 3 3 1\n5 6 8 2 8 4 7 8 3 0 8 8 1\n5 6 10 2 11 4 7 11 3 8 0 9 1\n5 6 9 2 9 4 7 9 3 8 9 0 1\n1 1 1 1 1 1 1 1 1 1 1 1 0", "output": "5 6 10 2 13 4 7 12 3 8 11 9 1" } ]
77
5,632,000
3
10,762
896
Welcome home, Chtholly
[ "data structures", "dsu" ]
null
null
— I... I survived. — Welcome home, Chtholly. — I kept my promise... — I made it... I really made it! After several days of fighting, Chtholly Nota Seniorious miraculously returned from the fierce battle. As promised, Willem is now baking butter cake for her. However, although Willem is skilled in making dessert, he rarely bakes butter cake. This time, Willem made a big mistake — he accidentally broke the oven! Fortunately, Chtholly decided to help him. Willem puts *n* cakes on a roll, cakes are numbered from 1 to *n*, the *i*-th cake needs *a**i* seconds of baking. Willem needs Chtholly to do *m* operations to bake the cakes. Operation 1: 1 *l* *r* *x* Willem asks Chtholly to check each cake in the range [*l*,<=*r*], if the cake needs to be baked for more than *x* seconds, he would bake it for *x* seconds and put it back in its place. More precisely, for every *i* in range [*l*,<=*r*], if *a**i* is strictly more than *x*, *a**i* becomes equal *a**i*<=-<=*x*. Operation 2: 2 *l* *r* *x* Willem asks Chtholly to count the number of cakes in the range [*l*,<=*r*] that needs to be cooked for exactly *x* seconds. More formally you should find number of such *i* in range [*l*,<=*r*], that *a**i*<==<=*x*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers, *i*-th of them is *a**i* (1<=≤<=*a**i*<=≤<=105). The next *m* lines are the *m* operations described above. It is guaranteed that 1<=≤<=*l*<=≤<=*r*<=≤<=*n* and 1<=≤<=*x*<=≤<=105.
For each operation of the second type, print the answer.
[ "5 6\n1 5 5 5 8\n2 2 5 5\n1 2 4 3\n2 2 5 2\n2 2 5 5\n1 3 5 1\n2 1 5 1\n", "7 7\n1 9 2 6 8 1 7\n2 1 7 1\n2 2 5 2\n1 4 7 7\n2 2 4 2\n1 3 4 5\n2 3 3 3\n2 3 7 2\n", "8 13\n75 85 88 100 105 120 122 128\n1 1 8 70\n2 3 8 30\n1 3 8 3\n2 2 5 15\n1 2 4 10\n2 1 5 5\n1 2 7 27\n2 1 5 5\n1 3 7 12\n1 1 7 4\n2 1 8 1\n1 4 8 5\n2 1 8 1\n" ]
[ "3\n3\n0\n3\n", "2\n1\n1\n0\n1\n", "1\n2\n3\n4\n5\n6\n" ]
none
[]
30
5,529,600
0
10,777