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
315
Sereja and Bottles
[ "brute force" ]
null
null
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
In a single line print a single integer — the answer to the problem.
[ "4\n1 1\n2 2\n3 3\n4 4\n", "4\n1 2\n2 3\n3 4\n4 1\n" ]
[ "4\n", "0\n" ]
none
[ { "input": "4\n1 1\n2 2\n3 3\n4 4", "output": "4" }, { "input": "4\n1 2\n2 3\n3 4\n4 1", "output": "0" }, { "input": "3\n2 828\n4 392\n4 903", "output": "3" }, { "input": "4\n2 3\n1 772\n3 870\n3 668", "output": "2" }, { "input": "5\n1 4\n6 6\n4 3\n3 4\n4 758", "output": "2" }, { "input": "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730", "output": "6" }, { "input": "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624", "output": "6" }, { "input": "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\n659 930\n705 987", "output": "6" }, { "input": "9\n162 942\n637 967\n356 108\n768 53\n656 656\n575 32\n32 575\n53 53\n351 222", "output": "6" }, { "input": "10\n423 360\n947 538\n507 484\n31 947\n414 351\n169 901\n901 21\n592 22\n763 200\n656 485", "output": "8" }, { "input": "1\n1000 1000", "output": "1" }, { "input": "1\n500 1000", "output": "1" }, { "input": "11\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11", "output": "11" }, { "input": "49\n1 758\n5 3\n5 3\n4 2\n4 36\n3 843\n5 107\n1 943\n1 649\n2 806\n3 730\n2 351\n2 102\n1 4\n3 4\n3 955\n2 841\n2 377\n5 2\n3 440\n4 324\n3 3\n3 83\n2 2\n2 1\n4 1\n1 931\n3 4\n2 5\n2 5\n4 73\n5 830\n3 4\n3 5\n5 291\n1 2\n5 3\n4 4\n2 3\n3 151\n4 2\n4 431\n5 1\n2 5\n2 4\n4 2\n4 4\n3 1\n5 2", "output": "0" }, { "input": "50\n507 31\n31 250\n414 763\n169 304\n901 9\n592 610\n763 414\n656 789\n411 422\n360 468\n625 504\n538 201\n549 619\n484 797\n596 282\n42 310\n603 656\n351 623\n292 293\n837 180\n375 658\n21 192\n597 729\n22 512\n349 635\n200 56\n669 647\n485 887\n282 939\n735 808\n54 417\n1000 310\n419 652\n939 617\n901 669\n789 390\n128 549\n468 511\n729 837\n894 729\n649 894\n484 22\n808 586\n422 286\n311 427\n618 656\n814 933\n515 901\n310 894\n617 330", "output": "30" }, { "input": "2\n7 7\n5 359", "output": "2" }, { "input": "2\n465 706\n706 706", "output": "1" }, { "input": "2\n1 1\n1 1", "output": "0" }, { "input": "3\n1 1\n1 1\n2 2", "output": "1" }, { "input": "5\n1 1\n1 2\n2 3\n3 4\n4 3", "output": "1" }, { "input": "3\n1 2\n1 2\n1 1", "output": "1" } ]
154
3,379,200
-1
0
233
Perfect Permutation
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*.
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", "output": "-1" }, { "input": "20", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 " }, { "input": "8", "output": "2 1 4 3 6 5 8 7 " }, { "input": "9", "output": "-1" }, { "input": "10", "output": "2 1 4 3 6 5 8 7 10 9 " }, { "input": "11", "output": "-1" }, { "input": "21", "output": "-1" }, { "input": "50", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 " }, { "input": "51", "output": "-1" }, { "input": "52", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 " }, { "input": "84", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 " }, { "input": "86", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 " }, { "input": "100", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 " }, { "input": "98", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 " }, { "input": "96", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 " }, { "input": "33", "output": "-1" }, { "input": "34", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 " }, { "input": "36", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 " }, { "input": "38", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 " }, { "input": "40", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 " }, { "input": "42", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 " }, { "input": "44", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 " }, { "input": "46", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 " }, { "input": "48", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 " } ]
92
0
-1
1
34
Reconnaissance 2
[ "implementation" ]
A. Reconnaissance 2
2
256
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
[ "5\n10 12 13 15 10\n", "4\n10 20 30 40\n" ]
[ "5 1\n", "1 2\n" ]
none
[ { "input": "5\n10 12 13 15 10", "output": "5 1" }, { "input": "4\n10 20 30 40", "output": "1 2" }, { "input": "6\n744 359 230 586 944 442", "output": "2 3" }, { "input": "5\n826 747 849 687 437", "output": "1 2" }, { "input": "5\n999 999 993 969 999", "output": "1 2" }, { "input": "5\n4 24 6 1 15", "output": "3 4" }, { "input": "2\n511 32", "output": "1 2" }, { "input": "3\n907 452 355", "output": "2 3" }, { "input": "4\n303 872 764 401", "output": "4 1" }, { "input": "10\n684 698 429 694 956 812 594 170 937 764", "output": "1 2" }, { "input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695", "output": "7 8" }, { "input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000", "output": "12 13" }, { "input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58", "output": "16 17" }, { "input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000", "output": "1 2" }, { "input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4", "output": "1 2" }, { "input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438", "output": "86 87" }, { "input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25", "output": "7 8" }, { "input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964", "output": "1 2" }, { "input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967", "output": "81 82" }, { "input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17", "output": "36 37" } ]
218
307,200
3.944928
2
707
Brain's Photos
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B", "output": "#Color" }, { "input": "1 6\nC M Y W G B", "output": "#Color" }, { "input": "1 3\nW G B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G C", "output": "#Color" }, { "input": "2 3\nW W W\nB G M", "output": "#Color" }, { "input": "3 3\nC B W\nB Y M\nB B W", "output": "#Color" }, { "input": "1 3\nW C W", "output": "#Color" }, { "input": "3 3\nB W B\nB C W\nB W W", "output": "#Color" }, { "input": "1 2\nW Y", "output": "#Color" }, { "input": "1 1\nG", "output": "#Black&White" }, { "input": "1 3\nB G W", "output": "#Black&White" }, { "input": "2 2\nW W\nB C", "output": "#Color" }, { "input": "1 1\nM", "output": "#Color" }, { "input": "1 2\nW C", "output": "#Color" }, { "input": "2 3\nW W M\nW W M", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB C", "output": "#Color" }, { "input": "2 3\nW W C\nW W W", "output": "#Color" }, { "input": "1 3\nG G G", "output": "#Black&White" }, { "input": "1 1\nC", "output": "#Color" }, { "input": "1 2\nC W", "output": "#Color" }, { "input": "1 3\nW W C", "output": "#Color" }, { "input": "2 2\nW B\nB G", "output": "#Black&White" }, { "input": "2 2\nB B\nY Y", "output": "#Color" }, { "input": "2 2\nG G\nC C", "output": "#Color" }, { "input": "1 2\nB C", "output": "#Color" }, { "input": "1 4\nG G G C", "output": "#Color" }, { "input": "1 1\nB", "output": "#Black&White" }, { "input": "2 1\nY\nB", "output": "#Color" } ]
31
0
0
3
507
Amr and Music
[ "greedy", "implementation", "sortings" ]
null
null
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments. Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument.
In the first line output one integer *m* representing the maximum number of instruments Amr can learn. In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
[ "4 10\n4 3 1 2\n", "5 6\n4 3 1 1 2\n", "1 3\n4\n" ]
[ "4\n1 2 3 4", "3\n1 3 4", "0\n" ]
In the first test Amr can learn all 4 instruments. In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}. In the third test Amr doesn't have enough time to learn the only presented instrument.
[ { "input": "4 10\n4 3 1 2", "output": "4\n1 2 3 4" }, { "input": "5 6\n4 3 1 1 2", "output": "3\n3 4 5" }, { "input": "1 3\n4", "output": "0" }, { "input": "2 100\n100 100", "output": "1\n1" }, { "input": "3 150\n50 50 50", "output": "3\n1 2 3" }, { "input": "4 0\n100 100 100 100", "output": "0" }, { "input": "100 7567\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "75\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" }, { "input": "68 3250\n95 84 67 7 82 75 100 39 31 45 69 100 8 97 13 58 74 40 88 69 35 91 94 28 62 85 51 97 37 15 87 51 24 96 89 49 53 54 35 17 23 54 51 91 94 18 26 92 79 63 23 37 98 43 16 44 82 25 100 59 97 3 60 92 76 58 56 50", "output": "60\n1 2 3 4 5 6 8 9 10 11 13 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 54 55 56 57 58 60 62 63 64 65 66 67 68" }, { "input": "100 10000\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100\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" }, { "input": "25 1293\n96 13 7 2 81 72 39 45 5 88 47 23 60 81 54 46 63 52 41 57 2 87 90 28 93", "output": "25\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" }, { "input": "98 7454\n71 57 94 76 52 90 76 81 67 60 99 88 98 61 73 61 80 91 88 93 53 55 88 64 71 55 81 76 52 63 87 99 84 66 65 52 83 99 92 62 95 81 90 67 64 57 80 80 67 75 77 58 71 85 97 50 97 55 52 59 55 96 57 53 85 100 95 95 74 51 78 88 66 98 97 86 94 81 56 64 61 57 67 95 85 82 85 60 76 95 69 95 76 91 74 100 69 76", "output": "98\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" }, { "input": "5 249\n96 13 7 2 81", "output": "5\n1 2 3 4 5" }, { "input": "61 3331\n12 63 99 56 57 70 53 21 41 82 97 63 42 91 18 84 99 78 85 89 6 63 76 28 33 78 100 46 78 78 32 13 11 12 73 50 34 60 12 73 9 19 88 100 28 51 50 45 51 10 78 38 25 22 8 40 71 55 56 83 44", "output": "61\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" }, { "input": "99 10000\n42 88 21 63 59 38 23 100 86 37 57 86 11 22 19 89 6 19 15 64 18 77 83 29 14 26 80 73 8 51 14 19 9 98 81 96 47 77 22 19 86 71 91 61 84 8 80 28 6 25 33 95 96 21 57 92 96 57 31 88 38 32 70 19 25 67 29 78 18 90 37 50 62 33 49 16 47 39 9 33 88 69 69 29 14 66 75 76 41 98 40 52 65 25 33 47 39 24 80", "output": "99\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" }, { "input": "89 4910\n44 9 31 70 85 72 55 9 85 84 63 43 92 85 10 34 83 28 73 45 62 7 34 52 89 58 24 10 28 6 72 45 57 36 71 34 26 24 38 59 5 15 48 82 58 99 8 77 49 84 14 58 29 46 88 50 13 7 58 23 40 63 96 23 46 31 17 8 59 93 12 76 69 20 43 44 91 78 68 94 37 27 100 65 40 25 52 30 97", "output": "89\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" }, { "input": "40 2110\n91 18 52 22 26 67 59 10 55 43 97 78 20 81 99 36 33 12 86 32 82 87 70 63 48 48 45 94 78 23 77 15 68 17 71 54 44 98 54 8", "output": "39\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 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" }, { "input": "27 1480\n38 95 9 36 21 70 19 89 35 46 7 31 88 25 10 72 81 32 65 83 68 57 50 20 73 42 12", "output": "27\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" }, { "input": "57 2937\n84 73 23 62 93 64 23 17 53 100 47 67 52 53 90 58 19 84 33 69 46 47 50 28 73 74 40 42 92 70 32 29 57 52 23 82 42 32 46 83 45 87 40 58 50 51 48 37 57 52 78 26 21 54 16 66 93", "output": "55\n1 2 3 4 5 6 7 8 9 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" }, { "input": "6 41\n6 8 9 8 9 8", "output": "5\n1 2 3 4 6" }, { "input": "9 95\n9 11 12 11 12 11 8 11 10", "output": "9\n1 2 3 4 5 6 7 8 9" }, { "input": "89 6512\n80 87 61 91 85 51 58 69 79 57 81 67 74 55 88 70 77 61 55 81 56 76 79 67 92 52 54 73 67 72 81 54 72 81 65 88 83 57 83 92 62 66 63 58 61 66 92 77 73 66 71 85 92 73 82 65 76 64 58 62 64 51 90 59 79 70 86 89 86 51 72 61 60 71 52 74 58 72 77 91 91 60 76 56 64 55 61 81 52", "output": "89\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" }, { "input": "5 29\n6 3 7 2 1", "output": "5\n1 2 3 4 5" }, { "input": "5 49\n16 13 7 2 1", "output": "5\n1 2 3 4 5" }, { "input": "6 84\n16 21 25 6 17 16", "output": "5\n1 2 4 5 6" }, { "input": "4 9\n7 4 2 1", "output": "3\n2 3 4" }, { "input": "50 2500\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50", "output": "50\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" }, { "input": "100 10000\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 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" }, { "input": "100 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 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" }, { "input": "96 514\n6 3 7 2 1 2 9 5 5 8 7 3 10 1 4 6 3 2 1 7 2 7 10 8 3 8 10 4 8 8 2 5 3 2 1 4 4 8 4 3 3 7 4 4 2 7 8 3 9 2 2 6 3 4 8 6 7 5 4 3 10 7 6 5 10 1 7 10 7 7 8 2 1 2 3 10 9 8 8 2 7 1 2 7 10 1 2 2 3 8 6 2 9 6 9 6", "output": "96\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" }, { "input": "47 350\n6 1 9 12 8 8 11 4 4 8 8 3 3 2 12 7 7 7 12 2 9 1 5 10 6 1 5 2 6 3 9 13 8 3 10 10 10 10 6 9 10 10 8 5 12 11 3", "output": "47\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" }, { "input": "100 200\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 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": "100\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" }, { "input": "2 10000\n1 1", "output": "2\n1 2" }, { "input": "1 2\n1", "output": "1\n1" }, { "input": "1 3\n2", "output": "1\n1" }, { "input": "34 4964\n37 27 90 83 36 59 80 7 28 41 97 72 64 8 40 30 76 4 92 51 52 44 42 13 38 64 60 66 47 93 30 35 71 71", "output": "34\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" }, { "input": "2 2\n1 10", "output": "1\n1" }, { "input": "2 5\n1 1", "output": "2\n1 2" }, { "input": "1 4\n3", "output": "1\n1" }, { "input": "4 384\n1 2 3 4", "output": "4\n1 2 3 4" } ]
109
0
3
4
41
Translation
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "output": "NO" }, { "input": "z\na", "output": "NO" }, { "input": "asd\ndsa", "output": "YES" }, { "input": "abcdef\nfecdba", "output": "NO" }, { "input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "output": "NO" }, { "input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf", "output": "NO" }, { "input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp", "output": "NO" }, { "input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb", "output": "NO" }, { "input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh", "output": "NO" }, { "input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy", "output": "NO" }, { "input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko", "output": "NO" }, { "input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv", "output": "NO" }, { "input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd", "output": "NO" }, { "input": "w\nw", "output": "YES" }, { "input": "vz\nzv", "output": "YES" }, { "input": "ry\nyr", "output": "YES" }, { "input": "xou\nuox", "output": "YES" }, { "input": "axg\ngax", "output": "NO" }, { "input": "zdsl\nlsdz", "output": "YES" }, { "input": "kudl\nldku", "output": "NO" }, { "input": "zzlzwnqlcl\nlclqnwzlzz", "output": "YES" }, { "input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv", "output": "YES" }, { "input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar", "output": "NO" }, { "input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn", "output": "YES" }, { "input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum", "output": "YES" }, { "input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv", "output": "YES" }, { "input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm", "output": "NO" }, { "input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd", "output": "NO" }, { "input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg", "output": "YES" }, { "input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis", "output": "YES" }, { "input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy", "output": "NO" }, { "input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw", "output": "YES" }, { "input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi", "output": "YES" }, { "input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib", "output": "YES" } ]
154
0
3.9615
5
732
Buy a Shovel
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", "output": "1" }, { "input": "1000 9", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "999 9", "output": "1" }, { "input": "999 8", "output": "2" }, { "input": "105 6", "output": "2" }, { "input": "403 9", "output": "3" }, { "input": "546 4", "output": "4" }, { "input": "228 9", "output": "5" }, { "input": "57 2", "output": "6" }, { "input": "437 9", "output": "7" }, { "input": "997 6", "output": "8" }, { "input": "109 1", "output": "9" }, { "input": "998 9", "output": "5" }, { "input": "4 2", "output": "3" }, { "input": "9 3", "output": "7" }, { "input": "8 2", "output": "4" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "1 7", "output": "7" }, { "input": "1 8", "output": "8" }, { "input": "100 3", "output": "1" }, { "input": "1000 2", "output": "1" }, { "input": "1000 4", "output": "1" }, { "input": "1000 5", "output": "1" }, { "input": "1000 6", "output": "1" }, { "input": "1000 7", "output": "1" }, { "input": "1000 8", "output": "1" }, { "input": "23 4", "output": "8" }, { "input": "33 1", "output": "7" }, { "input": "33 2", "output": "4" }, { "input": "666 5", "output": "5" }, { "input": "2 3", "output": "5" }, { "input": "5 5", "output": "1" }, { "input": "3 6", "output": "2" }, { "input": "12 4", "output": "2" }, { "input": "15 5", "output": "1" }, { "input": "2 5", "output": "5" }, { "input": "25 5", "output": "1" }, { "input": "2 9", "output": "5" }, { "input": "6 7", "output": "5" }, { "input": "8 9", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "4 7", "output": "5" }, { "input": "2 1", "output": "5" }, { "input": "261 1", "output": "1" } ]
46
0
0
6
334
Candy Bags
[ "implementation" ]
null
null
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies. Help him give *n* bags of candies to each brother so that all brothers got the same number of candies.
The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers.
Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the lines in any order. It is guaranteed that the solution exists at the given limits.
[ "2\n" ]
[ "1 4\n2 3\n" ]
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
[ { "input": "2", "output": "1 4\n2 3" }, { "input": "4", "output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9" }, { "input": "6", "output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19" }, { "input": "8", "output": "1 64 2 63 3 62 4 61\n5 60 6 59 7 58 8 57\n9 56 10 55 11 54 12 53\n13 52 14 51 15 50 16 49\n17 48 18 47 19 46 20 45\n21 44 22 43 23 42 24 41\n25 40 26 39 27 38 28 37\n29 36 30 35 31 34 32 33" }, { "input": "10", "output": "1 100 2 99 3 98 4 97 5 96\n6 95 7 94 8 93 9 92 10 91\n11 90 12 89 13 88 14 87 15 86\n16 85 17 84 18 83 19 82 20 81\n21 80 22 79 23 78 24 77 25 76\n26 75 27 74 28 73 29 72 30 71\n31 70 32 69 33 68 34 67 35 66\n36 65 37 64 38 63 39 62 40 61\n41 60 42 59 43 58 44 57 45 56\n46 55 47 54 48 53 49 52 50 51" }, { "input": "100", "output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951\n51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 993..." }, { "input": "62", "output": "1 3844 2 3843 3 3842 4 3841 5 3840 6 3839 7 3838 8 3837 9 3836 10 3835 11 3834 12 3833 13 3832 14 3831 15 3830 16 3829 17 3828 18 3827 19 3826 20 3825 21 3824 22 3823 23 3822 24 3821 25 3820 26 3819 27 3818 28 3817 29 3816 30 3815 31 3814\n32 3813 33 3812 34 3811 35 3810 36 3809 37 3808 38 3807 39 3806 40 3805 41 3804 42 3803 43 3802 44 3801 45 3800 46 3799 47 3798 48 3797 49 3796 50 3795 51 3794 52 3793 53 3792 54 3791 55 3790 56 3789 57 3788 58 3787 59 3786 60 3785 61 3784 62 3783\n63 3782 64 3781 65 378..." }, { "input": "66", "output": "1 4356 2 4355 3 4354 4 4353 5 4352 6 4351 7 4350 8 4349 9 4348 10 4347 11 4346 12 4345 13 4344 14 4343 15 4342 16 4341 17 4340 18 4339 19 4338 20 4337 21 4336 22 4335 23 4334 24 4333 25 4332 26 4331 27 4330 28 4329 29 4328 30 4327 31 4326 32 4325 33 4324\n34 4323 35 4322 36 4321 37 4320 38 4319 39 4318 40 4317 41 4316 42 4315 43 4314 44 4313 45 4312 46 4311 47 4310 48 4309 49 4308 50 4307 51 4306 52 4305 53 4304 54 4303 55 4302 56 4301 57 4300 58 4299 59 4298 60 4297 61 4296 62 4295 63 4294 64 4293 65 4292..." }, { "input": "18", "output": "1 324 2 323 3 322 4 321 5 320 6 319 7 318 8 317 9 316\n10 315 11 314 12 313 13 312 14 311 15 310 16 309 17 308 18 307\n19 306 20 305 21 304 22 303 23 302 24 301 25 300 26 299 27 298\n28 297 29 296 30 295 31 294 32 293 33 292 34 291 35 290 36 289\n37 288 38 287 39 286 40 285 41 284 42 283 43 282 44 281 45 280\n46 279 47 278 48 277 49 276 50 275 51 274 52 273 53 272 54 271\n55 270 56 269 57 268 58 267 59 266 60 265 61 264 62 263 63 262\n64 261 65 260 66 259 67 258 68 257 69 256 70 255 71 254 72 253\n73 252 7..." }, { "input": "68", "output": "1 4624 2 4623 3 4622 4 4621 5 4620 6 4619 7 4618 8 4617 9 4616 10 4615 11 4614 12 4613 13 4612 14 4611 15 4610 16 4609 17 4608 18 4607 19 4606 20 4605 21 4604 22 4603 23 4602 24 4601 25 4600 26 4599 27 4598 28 4597 29 4596 30 4595 31 4594 32 4593 33 4592 34 4591\n35 4590 36 4589 37 4588 38 4587 39 4586 40 4585 41 4584 42 4583 43 4582 44 4581 45 4580 46 4579 47 4578 48 4577 49 4576 50 4575 51 4574 52 4573 53 4572 54 4571 55 4570 56 4569 57 4568 58 4567 59 4566 60 4565 61 4564 62 4563 63 4562 64 4561 65 4560..." }, { "input": "86", "output": "1 7396 2 7395 3 7394 4 7393 5 7392 6 7391 7 7390 8 7389 9 7388 10 7387 11 7386 12 7385 13 7384 14 7383 15 7382 16 7381 17 7380 18 7379 19 7378 20 7377 21 7376 22 7375 23 7374 24 7373 25 7372 26 7371 27 7370 28 7369 29 7368 30 7367 31 7366 32 7365 33 7364 34 7363 35 7362 36 7361 37 7360 38 7359 39 7358 40 7357 41 7356 42 7355 43 7354\n44 7353 45 7352 46 7351 47 7350 48 7349 49 7348 50 7347 51 7346 52 7345 53 7344 54 7343 55 7342 56 7341 57 7340 58 7339 59 7338 60 7337 61 7336 62 7335 63 7334 64 7333 65 7332..." }, { "input": "96", "output": "1 9216 2 9215 3 9214 4 9213 5 9212 6 9211 7 9210 8 9209 9 9208 10 9207 11 9206 12 9205 13 9204 14 9203 15 9202 16 9201 17 9200 18 9199 19 9198 20 9197 21 9196 22 9195 23 9194 24 9193 25 9192 26 9191 27 9190 28 9189 29 9188 30 9187 31 9186 32 9185 33 9184 34 9183 35 9182 36 9181 37 9180 38 9179 39 9178 40 9177 41 9176 42 9175 43 9174 44 9173 45 9172 46 9171 47 9170 48 9169\n49 9168 50 9167 51 9166 52 9165 53 9164 54 9163 55 9162 56 9161 57 9160 58 9159 59 9158 60 9157 61 9156 62 9155 63 9154 64 9153 65 9152..." }, { "input": "12", "output": "1 144 2 143 3 142 4 141 5 140 6 139\n7 138 8 137 9 136 10 135 11 134 12 133\n13 132 14 131 15 130 16 129 17 128 18 127\n19 126 20 125 21 124 22 123 23 122 24 121\n25 120 26 119 27 118 28 117 29 116 30 115\n31 114 32 113 33 112 34 111 35 110 36 109\n37 108 38 107 39 106 40 105 41 104 42 103\n43 102 44 101 45 100 46 99 47 98 48 97\n49 96 50 95 51 94 52 93 53 92 54 91\n55 90 56 89 57 88 58 87 59 86 60 85\n61 84 62 83 63 82 64 81 65 80 66 79\n67 78 68 77 69 76 70 75 71 74 72 73" }, { "input": "88", "output": "1 7744 2 7743 3 7742 4 7741 5 7740 6 7739 7 7738 8 7737 9 7736 10 7735 11 7734 12 7733 13 7732 14 7731 15 7730 16 7729 17 7728 18 7727 19 7726 20 7725 21 7724 22 7723 23 7722 24 7721 25 7720 26 7719 27 7718 28 7717 29 7716 30 7715 31 7714 32 7713 33 7712 34 7711 35 7710 36 7709 37 7708 38 7707 39 7706 40 7705 41 7704 42 7703 43 7702 44 7701\n45 7700 46 7699 47 7698 48 7697 49 7696 50 7695 51 7694 52 7693 53 7692 54 7691 55 7690 56 7689 57 7688 58 7687 59 7686 60 7685 61 7684 62 7683 63 7682 64 7681 65 7680..." }, { "input": "28", "output": "1 784 2 783 3 782 4 781 5 780 6 779 7 778 8 777 9 776 10 775 11 774 12 773 13 772 14 771\n15 770 16 769 17 768 18 767 19 766 20 765 21 764 22 763 23 762 24 761 25 760 26 759 27 758 28 757\n29 756 30 755 31 754 32 753 33 752 34 751 35 750 36 749 37 748 38 747 39 746 40 745 41 744 42 743\n43 742 44 741 45 740 46 739 47 738 48 737 49 736 50 735 51 734 52 733 53 732 54 731 55 730 56 729\n57 728 58 727 59 726 60 725 61 724 62 723 63 722 64 721 65 720 66 719 67 718 68 717 69 716 70 715\n71 714 72 713 73 712 74 7..." }, { "input": "80", "output": "1 6400 2 6399 3 6398 4 6397 5 6396 6 6395 7 6394 8 6393 9 6392 10 6391 11 6390 12 6389 13 6388 14 6387 15 6386 16 6385 17 6384 18 6383 19 6382 20 6381 21 6380 22 6379 23 6378 24 6377 25 6376 26 6375 27 6374 28 6373 29 6372 30 6371 31 6370 32 6369 33 6368 34 6367 35 6366 36 6365 37 6364 38 6363 39 6362 40 6361\n41 6360 42 6359 43 6358 44 6357 45 6356 46 6355 47 6354 48 6353 49 6352 50 6351 51 6350 52 6349 53 6348 54 6347 55 6346 56 6345 57 6344 58 6343 59 6342 60 6341 61 6340 62 6339 63 6338 64 6337 65 6336..." }, { "input": "48", "output": "1 2304 2 2303 3 2302 4 2301 5 2300 6 2299 7 2298 8 2297 9 2296 10 2295 11 2294 12 2293 13 2292 14 2291 15 2290 16 2289 17 2288 18 2287 19 2286 20 2285 21 2284 22 2283 23 2282 24 2281\n25 2280 26 2279 27 2278 28 2277 29 2276 30 2275 31 2274 32 2273 33 2272 34 2271 35 2270 36 2269 37 2268 38 2267 39 2266 40 2265 41 2264 42 2263 43 2262 44 2261 45 2260 46 2259 47 2258 48 2257\n49 2256 50 2255 51 2254 52 2253 53 2252 54 2251 55 2250 56 2249 57 2248 58 2247 59 2246 60 2245 61 2244 62 2243 63 2242 64 2241 65 224..." }, { "input": "54", "output": "1 2916 2 2915 3 2914 4 2913 5 2912 6 2911 7 2910 8 2909 9 2908 10 2907 11 2906 12 2905 13 2904 14 2903 15 2902 16 2901 17 2900 18 2899 19 2898 20 2897 21 2896 22 2895 23 2894 24 2893 25 2892 26 2891 27 2890\n28 2889 29 2888 30 2887 31 2886 32 2885 33 2884 34 2883 35 2882 36 2881 37 2880 38 2879 39 2878 40 2877 41 2876 42 2875 43 2874 44 2873 45 2872 46 2871 47 2870 48 2869 49 2868 50 2867 51 2866 52 2865 53 2864 54 2863\n55 2862 56 2861 57 2860 58 2859 59 2858 60 2857 61 2856 62 2855 63 2854 64 2853 65 285..." }, { "input": "58", "output": "1 3364 2 3363 3 3362 4 3361 5 3360 6 3359 7 3358 8 3357 9 3356 10 3355 11 3354 12 3353 13 3352 14 3351 15 3350 16 3349 17 3348 18 3347 19 3346 20 3345 21 3344 22 3343 23 3342 24 3341 25 3340 26 3339 27 3338 28 3337 29 3336\n30 3335 31 3334 32 3333 33 3332 34 3331 35 3330 36 3329 37 3328 38 3327 39 3326 40 3325 41 3324 42 3323 43 3322 44 3321 45 3320 46 3319 47 3318 48 3317 49 3316 50 3315 51 3314 52 3313 53 3312 54 3311 55 3310 56 3309 57 3308 58 3307\n59 3306 60 3305 61 3304 62 3303 63 3302 64 3301 65 330..." }, { "input": "64", "output": "1 4096 2 4095 3 4094 4 4093 5 4092 6 4091 7 4090 8 4089 9 4088 10 4087 11 4086 12 4085 13 4084 14 4083 15 4082 16 4081 17 4080 18 4079 19 4078 20 4077 21 4076 22 4075 23 4074 24 4073 25 4072 26 4071 27 4070 28 4069 29 4068 30 4067 31 4066 32 4065\n33 4064 34 4063 35 4062 36 4061 37 4060 38 4059 39 4058 40 4057 41 4056 42 4055 43 4054 44 4053 45 4052 46 4051 47 4050 48 4049 49 4048 50 4047 51 4046 52 4045 53 4044 54 4043 55 4042 56 4041 57 4040 58 4039 59 4038 60 4037 61 4036 62 4035 63 4034 64 4033\n65 403..." }, { "input": "44", "output": "1 1936 2 1935 3 1934 4 1933 5 1932 6 1931 7 1930 8 1929 9 1928 10 1927 11 1926 12 1925 13 1924 14 1923 15 1922 16 1921 17 1920 18 1919 19 1918 20 1917 21 1916 22 1915\n23 1914 24 1913 25 1912 26 1911 27 1910 28 1909 29 1908 30 1907 31 1906 32 1905 33 1904 34 1903 35 1902 36 1901 37 1900 38 1899 39 1898 40 1897 41 1896 42 1895 43 1894 44 1893\n45 1892 46 1891 47 1890 48 1889 49 1888 50 1887 51 1886 52 1885 53 1884 54 1883 55 1882 56 1881 57 1880 58 1879 59 1878 60 1877 61 1876 62 1875 63 1874 64 1873 65 187..." } ]
156
307,200
3
7
862
Mahmoud and Ehab and the MEX
[ "greedy", "implementation" ]
null
null
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go. Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0,<=2,<=4} is 1 and the MEX of the set {1,<=2,<=3} is 0 . Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?
The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX. The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set.
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
[ "5 3\n0 4 5 6 7\n", "1 0\n0\n", "5 0\n1 2 3 4 5\n" ]
[ "2\n", "1\n", "0\n" ]
For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations. For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0. In the third test case the set is already evil.
[ { "input": "5 3\n0 4 5 6 7", "output": "2" }, { "input": "1 0\n0", "output": "1" }, { "input": "5 0\n1 2 3 4 5", "output": "0" }, { "input": "10 5\n57 1 47 9 93 37 76 70 78 15", "output": "4" }, { "input": "10 5\n99 98 93 97 95 100 92 94 91 96", "output": "5" }, { "input": "10 5\n1 2 3 4 59 45 0 58 51 91", "output": "0" }, { "input": "100 100\n79 13 21 11 3 87 28 40 29 4 96 34 8 78 61 46 33 45 99 30 92 67 22 97 39 86 73 31 74 44 62 55 57 2 54 63 80 69 25 48 77 98 17 93 15 16 89 12 43 23 37 95 14 38 83 90 49 56 72 10 20 0 50 71 70 88 19 1 76 81 52 41 82 68 85 47 6 7 35 60 18 64 75 84 27 9 65 91 94 42 53 24 66 26 59 36 51 32 5 58", "output": "0" }, { "input": "100 50\n95 78 46 92 80 18 79 58 30 72 19 89 39 29 44 65 15 100 59 8 96 9 62 67 41 42 82 14 57 32 71 77 40 5 7 51 28 53 85 23 16 35 3 91 6 11 75 61 17 66 13 47 36 56 10 22 83 60 48 24 26 97 4 33 76 86 70 0 34 64 52 43 21 49 55 74 1 73 81 25 54 63 94 84 20 68 87 12 31 88 38 93 37 90 98 69 99 45 27 2", "output": "0" }, { "input": "100 33\n28 11 79 92 88 62 77 72 7 41 96 97 67 84 44 8 81 35 38 1 64 68 46 17 98 83 31 12 74 21 2 22 47 6 36 75 65 61 37 26 25 45 59 48 100 51 93 76 78 49 3 57 16 4 87 29 55 82 70 39 53 0 60 15 24 71 58 20 66 89 95 42 13 43 63 90 85 52 50 30 54 40 56 23 27 34 32 18 10 19 69 9 99 73 91 14 5 80 94 86", "output": "0" }, { "input": "99 33\n25 76 41 95 55 20 47 59 58 84 87 92 16 27 35 65 72 63 93 54 36 96 15 86 5 69 24 46 67 73 48 60 40 6 61 74 97 10 100 8 52 26 77 18 7 62 37 2 14 66 11 56 68 91 0 64 75 99 30 21 53 1 89 81 3 98 12 88 39 38 29 83 22 90 9 28 45 43 78 44 32 57 4 50 70 17 13 51 80 85 71 94 82 19 34 42 23 79 49", "output": "1" }, { "input": "100 100\n65 56 84 46 44 33 99 74 62 72 93 67 43 92 75 88 38 34 66 12 55 76 58 90 78 8 14 45 97 59 48 32 64 18 39 89 31 51 54 81 29 36 70 77 40 22 49 27 3 1 73 13 98 42 87 37 2 57 4 6 50 25 23 79 28 86 68 61 80 17 19 10 15 63 52 11 35 60 21 16 24 85 30 91 7 5 69 20 71 82 53 94 41 95 96 9 26 83 0 47", "output": "0" }, { "input": "100 100\n58 88 12 71 22 1 40 19 73 20 67 48 57 17 69 36 100 35 33 37 72 55 52 8 89 85 47 42 78 70 81 86 11 9 68 99 6 16 21 61 53 98 23 62 32 59 51 0 87 24 50 30 65 10 80 95 7 92 25 74 60 79 91 5 13 31 75 38 90 94 46 66 93 34 14 41 28 2 76 84 43 96 3 56 49 82 27 77 64 63 4 45 18 29 54 39 15 26 83 44", "output": "2" }, { "input": "89 100\n58 96 17 41 86 34 28 84 18 40 8 77 87 89 68 79 33 35 53 49 0 6 22 12 72 90 48 55 21 50 56 62 75 2 37 95 69 74 14 20 44 46 27 32 31 59 63 60 10 85 71 70 38 52 94 30 61 51 80 26 36 23 39 47 76 45 100 57 15 78 97 66 54 13 99 16 93 73 24 4 83 5 98 81 92 25 29 88 65", "output": "13" }, { "input": "100 50\n7 95 24 76 81 78 60 69 83 84 100 1 65 31 48 92 73 39 18 89 38 97 10 42 8 55 98 51 21 90 62 77 16 91 0 94 4 37 19 17 67 35 45 41 56 20 15 85 75 28 59 27 12 54 61 68 36 5 79 93 66 11 70 49 50 34 30 25 96 46 64 14 32 22 47 40 58 23 43 9 87 82 26 53 80 52 3 86 13 99 33 71 6 88 57 74 2 44 72 63", "output": "2" }, { "input": "77 0\n27 8 20 92 21 41 53 98 17 65 67 35 81 11 55 49 61 44 2 66 51 89 40 28 52 62 86 91 64 24 18 5 94 82 96 99 71 6 39 83 26 29 16 30 45 97 80 90 69 12 13 33 76 73 46 19 78 56 88 38 42 34 57 77 47 4 59 58 7 100 95 72 9 74 15 43 54", "output": "0" }, { "input": "100 50\n55 36 0 32 81 6 17 43 24 13 30 19 8 59 71 45 15 74 3 41 99 42 86 47 2 94 35 1 66 95 38 49 4 27 96 89 34 44 92 25 51 39 54 28 80 77 20 14 48 40 68 56 31 63 33 78 69 37 18 26 83 70 23 82 91 65 67 52 61 53 7 22 60 21 12 73 72 87 75 100 90 29 64 79 98 85 5 62 93 84 50 46 97 58 57 16 9 10 76 11", "output": "1" }, { "input": "77 0\n12 8 19 87 9 54 55 86 97 7 27 85 25 48 94 73 26 1 13 57 72 69 76 39 38 91 75 40 42 28 93 21 70 84 65 11 60 90 20 95 66 89 59 47 34 99 6 61 52 100 50 3 77 81 82 53 15 24 0 45 44 14 68 96 58 5 18 35 10 98 29 74 92 49 83 71 17", "output": "1" }, { "input": "100 70\n25 94 66 65 10 99 89 6 70 31 7 40 20 92 64 27 21 72 77 98 17 43 47 44 48 81 38 56 100 39 90 22 88 76 3 83 86 29 33 55 82 79 49 11 2 16 12 78 85 69 32 97 26 15 53 24 23 91 51 67 34 35 52 5 62 50 95 18 71 13 75 8 30 42 93 36 45 60 63 46 57 41 87 0 84 54 74 37 4 58 28 19 96 61 80 9 1 14 73 68", "output": "2" }, { "input": "89 19\n14 77 85 81 79 38 91 45 55 51 50 11 62 67 73 76 2 27 16 23 3 29 65 98 78 17 4 58 22 20 34 66 64 31 72 5 32 44 12 75 80 47 18 25 99 0 61 56 71 84 48 88 10 7 86 8 49 24 43 21 37 28 33 54 46 57 40 89 36 97 6 96 39 95 26 74 1 69 9 100 52 30 83 87 68 60 92 90 35", "output": "2" }, { "input": "89 100\n69 61 56 45 11 41 42 32 28 29 0 76 7 65 13 35 36 82 10 39 26 34 38 40 92 12 17 54 24 46 88 70 66 27 100 52 85 62 22 48 86 68 21 49 53 94 67 20 1 90 77 84 31 87 58 47 95 33 4 72 93 83 8 51 91 80 99 43 71 19 44 59 98 97 64 9 81 16 79 63 25 37 3 75 2 55 50 6 18", "output": "13" }, { "input": "77 0\n38 76 24 74 42 88 29 75 96 46 90 32 59 97 98 60 41 57 80 37 100 49 25 63 95 31 61 68 53 78 27 66 84 48 94 83 30 26 36 99 71 62 45 47 70 28 35 54 34 85 79 43 91 72 86 33 67 92 77 65 69 52 82 55 87 64 56 40 50 44 51 73 89 81 58 93 39", "output": "0" }, { "input": "89 100\n38 90 80 64 35 44 56 11 15 89 23 12 49 70 72 60 63 85 92 10 45 83 8 88 41 33 16 6 61 76 62 71 87 13 25 77 74 0 1 37 96 93 7 94 21 82 34 78 4 73 65 20 81 95 50 32 48 17 69 55 68 5 51 27 53 43 91 67 59 46 86 84 99 24 22 3 97 98 40 36 26 58 57 9 42 30 52 2 47", "output": "11" }, { "input": "77 0\n55 71 78 86 68 35 53 10 59 32 81 19 74 97 62 61 93 87 96 44 25 18 43 82 84 16 34 48 92 39 64 36 49 91 45 76 95 31 57 29 75 79 13 2 14 24 52 23 33 20 47 99 63 15 5 80 58 67 12 3 85 6 1 27 73 90 4 42 37 70 8 11 89 77 9 22 94", "output": "0" }, { "input": "77 0\n12 75 31 71 44 8 3 82 21 77 50 29 57 74 40 10 15 42 84 2 100 9 28 72 92 0 49 11 90 55 17 36 19 54 68 52 4 69 97 91 5 39 59 45 89 62 53 83 16 94 76 60 95 47 30 51 7 48 20 70 67 32 58 78 63 34 56 93 99 88 24 1 66 22 25 14 13", "output": "1" }, { "input": "100 70\n91 82 8 85 26 25 95 97 40 87 81 93 7 73 38 94 64 96 74 18 90 19 65 68 72 61 23 43 36 41 60 88 30 33 71 24 52 39 15 3 16 89 86 79 55 4 9 58 67 44 46 29 6 48 84 69 27 21 78 54 51 57 80 53 76 50 47 77 45 12 34 10 100 0 17 31 56 99 98 11 92 5 2 42 32 59 66 62 37 63 28 75 35 1 22 13 83 49 20 14", "output": "0" }, { "input": "77 0\n51 5 81 62 30 22 11 0 83 16 79 85 52 70 69 10 8 47 58 3 24 34 44 14 82 66 99 17 28 31 64 67 23 49 94 45 4 12 27 15 21 6 43 72 87 2 63 92 35 39 59 9 90 78 93 20 65 36 60 89 50 41 61 84 77 86 76 100 38 68 53 97 96 95 7 19 88", "output": "1" }, { "input": "1 100\n0", "output": "99" }, { "input": "1 0\n100", "output": "0" }, { "input": "1 100\n100", "output": "101" }, { "input": "2 100\n0 100", "output": "100" }, { "input": "5 5\n1 2 3 4 5", "output": "2" }, { "input": "5 3\n0 3 4 5 6", "output": "3" }, { "input": "7 10\n0 1 2 3 4 5 10", "output": "5" }, { "input": "2 2\n0 2", "output": "2" }, { "input": "2 1\n1 2", "output": "2" }, { "input": "5 1\n1 2 3 4 5", "output": "2" }, { "input": "5 2\n1 2 3 4 5", "output": "2" }, { "input": "5 6\n0 1 2 3 4", "output": "1" }, { "input": "3 2\n3 4 5", "output": "2" } ]
109
0
3
8
424
Squats
[ "implementation" ]
null
null
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?
The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting.
In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.
[ "4\nxxXx\n", "2\nXX\n", "6\nxXXxXx\n" ]
[ "1\nXxXx\n", "1\nxX\n", "0\nxXXxXx\n" ]
none
[ { "input": "4\nxxXx", "output": "1\nXxXx" }, { "input": "2\nXX", "output": "1\nxX" }, { "input": "6\nxXXxXx", "output": "0\nxXXxXx" }, { "input": "4\nxXXX", "output": "1\nxxXX" }, { "input": "2\nXx", "output": "0\nXx" }, { "input": "22\nXXxXXxxXxXxXXXXXXXXXxx", "output": "4\nxxxxxxxXxXxXXXXXXXXXxx" }, { "input": "30\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx", "output": "0\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx" }, { "input": "104\nxxXxXxxXXXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX", "output": "4\nxxxxxxxxxXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX" }, { "input": "78\nxxxXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, { "input": "198\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "output": "99\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, { "input": "2\nxx", "output": "1\nXx" }, { "input": "2\nXx", "output": "0\nXx" }, { "input": "2\nxX", "output": "0\nxX" }, { "input": "4\nXXXX", "output": "2\nxxXX" }, { "input": "4\nxxxx", "output": "2\nXXxx" }, { "input": "4\nxxXX", "output": "0\nxxXX" }, { "input": "4\nXXxx", "output": "0\nXXxx" }, { "input": "4\nxXxx", "output": "1\nXXxx" }, { "input": "4\nXxxx", "output": "1\nXXxx" }, { "input": "4\nxxxX", "output": "1\nXxxX" }, { "input": "4\nxxXx", "output": "1\nXxXx" }, { "input": "4\nXXXx", "output": "1\nxXXx" }, { "input": "4\nxXXX", "output": "1\nxxXX" }, { "input": "4\nXxXX", "output": "1\nxxXX" }, { "input": "4\nXXxX", "output": "1\nxXxX" }, { "input": "4\nXxXx", "output": "0\nXxXx" }, { "input": "6\nxXXxXX", "output": "1\nxxXxXX" } ]
62
0
0
9
630
Moore's Law
[ "math" ]
null
null
The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times.
The only line of the input contains a pair of integers *n* (1000<=≤<=*n*<=≤<=10 000) and *t* (0<=≤<=*t*<=≤<=2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time.
Output one number — the estimate of the number of transistors in a dence integrated circuit in *t* seconds since the initial time. The relative error of your answer should not be greater than 10<=-<=6.
[ "1000 1000000\n" ]
[ "1011.060722383550382782399454922040\n" ]
none
[ { "input": "1000 1000000", "output": "1011.060722383550382782399454922040" }, { "input": "1000 0", "output": "1000" }, { "input": "1000 1", "output": "1000.000011000" }, { "input": "1000 2", "output": "1000.000022000000121000" }, { "input": "10000 3", "output": "10000.000330000003630000013310000" }, { "input": "10000 2000000000", "output": "35849124123571.66604124267909180280" }, { "input": "4907 244618708", "output": "72346.60521729832602747499118899866" }, { "input": "9030 982505993", "output": "446019624.4250800721903194914485562" }, { "input": "4054 287739817", "output": "96047.41901816849953518710733057692" }, { "input": "1587 1941728048", "output": "2996928752532.893524588882808611548" } ]
46
0
3
10
257
Sockets
[ "greedy", "implementation", "sortings" ]
null
null
Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets. Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of *k* electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity. What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) — number *a**i* stands for the number of sockets on the *i*-th supply-line filter.
Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
[ "3 5 3\n3 1 2\n", "4 7 2\n3 3 2 4\n", "5 5 1\n1 3 1 2 1\n" ]
[ "1\n", "2\n", "-1\n" ]
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices. One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
[ { "input": "3 5 3\n3 1 2", "output": "1" }, { "input": "4 7 2\n3 3 2 4", "output": "2" }, { "input": "5 5 1\n1 3 1 2 1", "output": "-1" }, { "input": "4 5 8\n3 2 4 3", "output": "0" }, { "input": "5 10 1\n4 3 4 2 4", "output": "3" }, { "input": "7 13 2\n5 3 4 1 2 1 2", "output": "5" }, { "input": "7 17 5\n1 6 2 1 1 4 3", "output": "-1" }, { "input": "10 25 7\n5 7 4 8 3 3 5 4 5 5", "output": "4" }, { "input": "10 8 4\n1 1 2 1 3 1 3 1 4 2", "output": "2" }, { "input": "13 20 9\n2 9 2 2 5 11 10 10 13 4 6 11 14", "output": "1" }, { "input": "9 30 8\n3 6 10 8 1 5 3 9 3", "output": "3" }, { "input": "15 26 4\n3 6 7 1 5 2 4 4 7 3 8 7 2 4 8", "output": "4" }, { "input": "20 20 3\n6 6 5 1 7 8 8 6 10 7 8 5 6 8 1 7 10 6 2 7", "output": "2" }, { "input": "10 30 5\n4 5 3 3 4 4 4 3 5 1", "output": "9" }, { "input": "20 30 1\n12 19 16 2 11 19 1 15 13 13 3 10 1 18 7 5 6 8 9 1", "output": "2" }, { "input": "50 50 2\n2 2 4 5 2 1 5 4 5 4 5 2 1 2 3 3 5 1 2 2 1 3 4 5 5 4 3 2 2 1 3 2 3 2 4 4 1 3 5 4 3 2 4 3 4 4 4 4 3 4", "output": "14" }, { "input": "5 50 6\n2 1 3 1 3", "output": "-1" }, { "input": "20 50 10\n5 4 3 6 3 7 2 3 7 8 6 3 8 3 3 5 1 9 6 2", "output": "7" }, { "input": "40 40 3\n2 1 4 2 4 2 3 3 3 3 1 2 3 2 2 3 4 2 3 1 2 4 1 4 1 4 3 3 1 1 3 1 3 4 4 3 1 1 2 4", "output": "14" }, { "input": "33 49 16\n40 16 48 49 30 28 8 6 48 39 48 6 24 28 30 35 12 23 49 29 31 8 40 18 16 34 43 15 12 33 14 24 13", "output": "1" }, { "input": "10 49 11\n5 18 1 19 11 11 16 5 6 6", "output": "3" }, { "input": "50 30 1\n2 1 2 1 2 3 3 1 2 2 3 2 1 3 1 3 1 2 2 3 2 1 3 1 1 2 3 2 2 1 1 3 3 2 2 2 3 2 3 3 3 3 1 1 3 1 1 3 1 3", "output": "15" }, { "input": "50 50 2\n1 2 3 2 1 2 4 2 3 4 3 1 3 2 2 3 1 4 2 1 4 4 2 2 2 3 2 3 1 1 4 4 1 1 2 3 4 2 2 3 4 3 4 3 3 3 2 3 1 1", "output": "19" }, { "input": "49 49 3\n8 8 8 7 5 6 6 8 1 3 1 8 8 3 2 1 2 2 5 4 4 7 8 7 6 4 2 5 7 3 4 2 3 2 3 4 5 7 3 3 4 5 5 8 2 5 1 1 7", "output": "7" }, { "input": "4 50 1\n3 11 5 5", "output": "-1" }, { "input": "50 5 1\n1 1 1 1 1 1 1 2 1 1 2 2 2 2 1 2 1 2 1 2 2 1 1 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 1 2 1 1 2 1 1 2 1 2", "output": "4" }, { "input": "50 23 2\n2 1 2 2 3 2 1 2 3 3 3 1 3 1 3 2 1 3 2 2 1 1 3 2 2 1 1 3 2 1 2 3 2 2 2 2 1 3 1 2 2 3 3 1 3 3 3 1 2 3", "output": "11" }, { "input": "49 19 2\n3 2 3 2 3 3 2 3 3 1 2 1 2 3 2 3 1 3 1 3 1 3 2 2 2 2 3 3 1 1 2 3 2 3 1 2 3 3 1 1 3 1 1 3 1 1 1 2 3", "output": "9" }, { "input": "10 50 5\n23 18 15 23 26 23 4 29 15 25", "output": "2" }, { "input": "15 38 3\n3 5 5 5 4 1 3 1 5 4 2 4 3 1 1", "output": "-1" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "3 6 3\n2 2 2", "output": "3" }, { "input": "1 7 4\n1", "output": "-1" }, { "input": "47 7 4\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", "output": "-1" } ]
280
20,172,800
0
11
409
A + B Strikes Back
[ "*special", "brute force", "constructive algorithms", "dsu", "implementation" ]
null
null
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try?
The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space.
Output the sum of the given integers.
[ "5 14\n", "381 492\n" ]
[ "19\n", "873\n" ]
none
[ { "input": "5 14", "output": "19" }, { "input": "381 492", "output": "873" }, { "input": "536 298", "output": "834" }, { "input": "143 522", "output": "665" }, { "input": "433 126", "output": "559" }, { "input": "723 350", "output": "1073" }, { "input": "632 264", "output": "896" }, { "input": "923 488", "output": "1411" }, { "input": "522 92", "output": "614" }, { "input": "953 553", "output": "1506" }, { "input": "242 86", "output": "328" }, { "input": "151 691", "output": "842" }, { "input": "441 915", "output": "1356" }, { "input": "740 519", "output": "1259" }, { "input": "339 433", "output": "772" }, { "input": "629 657", "output": "1286" }, { "input": "538 261", "output": "799" }, { "input": "828 485", "output": "1313" }, { "input": "117 399", "output": "516" }, { "input": "399 280", "output": "679" } ]
0
0
0
12
268
Games
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28", "output": "1" }, { "input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77", "output": "6" }, { "input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35", "output": "4" }, { "input": "2\n46 6\n6 46", "output": "2" }, { "input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11", "output": "10" }, { "input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33", "output": "6" }, { "input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73", "output": "0" }, { "input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2", "output": "1" }, { "input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100", "output": "8" }, { "input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1", "output": "450" }, { "input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3", "output": "0" }, { "input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5", "output": "20" }, { "input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2", "output": "108" }, { "input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2", "output": "312" }, { "input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6", "output": "96" }, { "input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97", "output": "210" }, { "input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78", "output": "73" }, { "input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80", "output": "277" }, { "input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21", "output": "154" }, { "input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17", "output": "418" }, { "input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80", "output": "74" }, { "input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9", "output": "59" }, { "input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67", "output": "100" }, { "input": "4\n8 7\n8 7\n7 8\n7 8", "output": "8" }, { "input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1", "output": "10" }, { "input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1", "output": "72" }, { "input": "4\n1 2\n1 2\n2 1\n2 1", "output": "8" } ]
216
0
3
13
368
Sereja and Suffixes
[ "data structures", "dp" ]
null
null
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
[ "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n" ]
none
[ { "input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1" }, { "input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "output": "3\n4\n5" }, { "input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "output": "3\n5\n2\n4\n3\n3\n2\n5\n1\n3" }, { "input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2", "output": "7\n7" }, { "input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1", "output": "7" }, { "input": "2 2\n8 4\n1\n1", "output": "2\n2" }, { "input": "1 5\n5\n1\n1\n1\n1\n1", "output": "1\n1\n1\n1\n1" }, { "input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4", "output": "1\n4\n3\n2\n3\n1\n1" }, { "input": "4 3\n9 1 7 1\n1\n4\n2", "output": "3\n1\n2" }, { "input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7", "output": "4\n3\n2" }, { "input": "1 1\n1\n1", "output": "1" } ]
15
0
0
14
604
Uncowed Forces
[ "implementation" ]
null
null
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score. Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack. All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.
The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted. The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≤<=*w**i*<=≤<=10) is Kevin's number of wrong submissions on problem *i*. The last line contains two space-separated integers *h**s* and *h**u* (0<=≤<=*h**s*,<=*h**u*<=≤<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.
Print a single integer, the value of Kevin's final score.
[ "20 40 60 80 100\n0 1 2 3 4\n1 0\n", "119 119 119 119 119\n0 0 0 0 0\n10 0\n" ]
[ "4900\n", "4930\n" ]
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.
[ { "input": "20 40 60 80 100\n0 1 2 3 4\n1 0", "output": "4900" }, { "input": "119 119 119 119 119\n0 0 0 0 0\n10 0", "output": "4930" }, { "input": "3 6 13 38 60\n6 10 10 3 8\n9 9", "output": "5088" }, { "input": "21 44 11 68 75\n6 2 4 8 4\n2 8", "output": "4522" }, { "input": "16 112 50 114 68\n1 4 8 4 9\n19 11", "output": "5178" }, { "input": "55 66 75 44 47\n6 0 6 6 10\n19 0", "output": "6414" }, { "input": "47 11 88 5 110\n6 10 4 2 3\n10 6", "output": "5188" }, { "input": "5 44 61 103 92\n9 0 10 4 8\n15 7", "output": "4914" }, { "input": "115 53 96 62 110\n7 8 1 7 9\n7 16", "output": "3416" }, { "input": "102 83 26 6 11\n3 4 1 8 3\n17 14", "output": "6704" }, { "input": "36 102 73 101 19\n5 9 2 2 6\n4 13", "output": "4292" }, { "input": "40 115 93 107 113\n5 7 2 6 8\n6 17", "output": "2876" }, { "input": "53 34 53 107 81\n4 3 1 10 8\n7 7", "output": "4324" }, { "input": "113 37 4 84 66\n2 0 10 3 0\n20 19", "output": "6070" }, { "input": "10 53 101 62 1\n8 0 9 7 9\n0 11", "output": "4032" }, { "input": "45 45 75 36 76\n6 2 2 0 0\n8 17", "output": "5222" }, { "input": "47 16 44 78 111\n7 9 8 0 2\n1 19", "output": "3288" }, { "input": "7 54 39 102 31\n6 0 2 10 1\n18 3", "output": "6610" }, { "input": "0 46 86 72 40\n1 5 5 5 9\n6 5", "output": "4924" }, { "input": "114 4 45 78 113\n0 4 8 10 2\n10 12", "output": "4432" }, { "input": "56 56 96 105 107\n4 9 10 4 8\n2 1", "output": "3104" }, { "input": "113 107 59 50 56\n3 7 10 6 3\n10 12", "output": "4586" }, { "input": "96 104 9 94 84\n6 10 7 8 3\n14 11", "output": "4754" }, { "input": "98 15 116 43 55\n4 3 0 9 3\n10 7", "output": "5400" }, { "input": "0 26 99 108 35\n0 4 3 0 10\n9 5", "output": "5388" }, { "input": "89 24 51 49 84\n5 6 2 2 9\n2 14", "output": "4066" }, { "input": "57 51 76 45 96\n1 0 4 3 6\n12 15", "output": "5156" }, { "input": "79 112 37 36 116\n2 8 4 7 5\n4 12", "output": "3872" }, { "input": "71 42 60 20 7\n7 1 1 10 6\n1 7", "output": "5242" }, { "input": "86 10 66 80 55\n0 2 5 10 5\n15 6", "output": "5802" }, { "input": "66 109 22 22 62\n3 1 5 4 5\n10 5", "output": "5854" }, { "input": "97 17 43 84 58\n2 8 3 8 6\n10 7", "output": "5028" }, { "input": "109 83 5 114 104\n6 0 3 9 5\n5 2", "output": "4386" }, { "input": "94 18 24 91 105\n2 0 7 10 3\n1 4", "output": "4118" }, { "input": "64 17 86 59 45\n8 0 10 2 2\n4 4", "output": "5144" }, { "input": "70 84 31 57 2\n7 0 0 2 7\n12 5", "output": "6652" }, { "input": "98 118 117 86 4\n2 10 9 7 5\n11 15", "output": "4476" }, { "input": "103 110 101 97 70\n4 2 1 0 5\n7 5", "output": "4678" }, { "input": "78 96 6 97 62\n7 7 9 2 9\n10 3", "output": "4868" }, { "input": "95 28 3 31 115\n1 9 0 7 3\n10 13", "output": "5132" }, { "input": "45 17 116 58 3\n8 8 7 6 4\n3 19", "output": "3992" }, { "input": "19 12 0 113 77\n3 0 10 9 2\n8 6", "output": "5040" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0", "output": "7500" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n20 0", "output": "9500" }, { "input": "119 119 119 119 119\n10 10 10 10 10\n0 20", "output": "1310" }, { "input": "0 0 0 0 0\n10 10 10 10 10\n0 20", "output": "4150" }, { "input": "119 0 0 0 0\n10 0 0 0 0\n5 5", "output": "7400" }, { "input": "0 119 0 0 0\n0 10 0 0 0\n5 5", "output": "7050" }, { "input": "0 0 119 0 0\n0 0 10 0 0\n0 0", "output": "6450" }, { "input": "0 0 0 119 0\n0 0 0 10 0\n5 5", "output": "6350" }, { "input": "0 0 0 0 119\n0 0 0 0 10\n5 5", "output": "6060" }, { "input": "119 0 0 0 0\n2 0 0 0 0\n5 5", "output": "7412" }, { "input": "0 119 0 0 0\n0 2 0 0 0\n5 5", "output": "7174" }, { "input": "0 0 119 0 0\n0 0 2 0 0\n5 5", "output": "6936" }, { "input": "0 0 0 119 0\n0 0 0 2 0\n5 5", "output": "6698" }, { "input": "0 0 0 0 119\n0 0 0 0 2\n5 5", "output": "6460" }, { "input": "119 0 0 0 0\n0 0 0 0 0\n4 9", "output": "7212" } ]
46
0
3
15
522
Photo to Remember
[ "*special", "data structures", "dp", "implementation" ]
null
null
One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the *i*-th of them occupies the rectangle of width *w**i* pixels and height *h**i* pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is *W*<=×<=*H*, where *W* is the total sum of all widths and *H* is the maximum height of all the photographed friends. As is usually the case, the friends made *n* photos — the *j*-th (1<=≤<=*j*<=≤<=*n*) photo had everybody except for the *j*-th friend as he was the photographer. Print the minimum size of each made photo in pixels.
The first line contains integer *n* (2<=≤<=*n*<=≤<=200<=000) — the number of friends. Then *n* lines follow: the *i*-th line contains information about the *i*-th friend. The line contains a pair of integers *w**i*,<=*h**i* (1<=≤<=*w**i*<=≤<=10,<=1<=≤<=*h**i*<=≤<=1000) — the width and height in pixels of the corresponding rectangle.
Print *n* space-separated numbers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* — the total number of pixels on the minimum photo containing all friends expect for the *i*-th one.
[ "3\n1 10\n5 5\n10 1\n", "3\n2 1\n1 2\n2 1\n" ]
[ "75 110 60 ", "6 4 6 " ]
none
[ { "input": "3\n1 10\n5 5\n10 1", "output": "75 110 60 " }, { "input": "3\n2 1\n1 2\n2 1", "output": "6 4 6 " }, { "input": "2\n1 5\n2 3", "output": "6 5 " }, { "input": "2\n2 3\n1 1", "output": "1 6 " }, { "input": "3\n1 10\n2 10\n3 10", "output": "50 40 30 " }, { "input": "3\n2 10\n1 9\n3 7", "output": "36 50 30 " }, { "input": "3\n1 1\n3 2\n2 3", "output": "15 9 8 " }, { "input": "3\n3 123\n1 456\n2 789", "output": "2367 3945 1824 " }, { "input": "3\n2 987\n3 654\n1 321", "output": "2616 2961 4935 " }, { "input": "3\n3 143\n2 543\n1 893", "output": "2679 3572 2715 " }, { "input": "2\n1 1\n1 2", "output": "2 1 " }, { "input": "3\n2 22\n1 11\n2 22", "output": "66 88 66 " }, { "input": "3\n1 11\n1 12\n1 13", "output": "26 26 24 " }, { "input": "3\n1 11\n1 12\n2 10", "output": "36 33 24 " }, { "input": "10\n6 20\n1 175\n1 758\n1 169\n2 490\n2 600\n4 463\n7 377\n9 40\n4 961", "output": "29791 34596 34596 34596 33635 33635 31713 28830 26908 25014 " }, { "input": "10\n8 158\n1 709\n6 766\n4 335\n5 356\n2 972\n1 108\n4 235\n3 631\n1 414", "output": "26244 33048 28188 30132 29160 25278 33048 30132 31104 33048 " }, { "input": "10\n7 549\n9 115\n8 141\n3 650\n5 730\n3 841\n7 18\n9 170\n2 217\n1 155", "output": "39527 37845 38686 42891 41209 37230 39527 37845 43732 44573 " }, { "input": "10\n6 386\n9 816\n9 268\n9 481\n8 284\n10 715\n9 351\n7 580\n4 327\n7 392", "output": "58752 49335 56304 56304 57120 55488 56304 57936 60384 57936 " }, { "input": "10\n9 292\n4 6\n6 638\n8 461\n10 970\n10 488\n9 769\n10 644\n8 280\n5 334", "output": "67900 72750 70810 68870 53061 66930 67900 66930 68870 71780 " }, { "input": "10\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000", "output": "90000 90000 90000 90000 90000 90000 90000 90000 90000 90000 " } ]
1,731
18,534,400
3
16
714
Meeting of Old Friends
[ "implementation", "math" ]
null
null
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive. Calculate the number of minutes they will be able to spend together.
The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
[ "1 10 9 20 1\n", "1 100 50 200 75\n" ]
[ "2\n", "50\n" ]
In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
[ { "input": "1 10 9 20 1", "output": "2" }, { "input": "1 100 50 200 75", "output": "50" }, { "input": "6 6 5 8 9", "output": "1" }, { "input": "1 1000000000 1 1000000000 1", "output": "999999999" }, { "input": "5 100 8 8 8", "output": "0" }, { "input": "1 1000000000000000000 2 99999999999999999 1000000000", "output": "99999999999999997" }, { "input": "1 1 1 1 1", "output": "0" }, { "input": "1 2 3 4 5", "output": "0" }, { "input": "1 1000000000 2 999999999 3141592", "output": "999999997" }, { "input": "24648817341102 41165114064236 88046848035 13602161452932 10000831349205", "output": "0" }, { "input": "1080184299348 34666828555290 6878390132365 39891656267344 15395310291636", "output": "27788438422925" }, { "input": "11814 27385 22309 28354 23595", "output": "5076" }, { "input": "4722316546398 36672578279675 796716437180 33840047334985 13411035401708", "output": "29117730788587" }, { "input": "14300093617438 14381698008501 6957847034861 32510754974307 66056597033082", "output": "81604391064" }, { "input": "700062402405871919 762322967106512617 297732773882447821 747309903322652819 805776739998108178", "output": "47247500916780901" }, { "input": "59861796371397621 194872039092923459 668110259718450585 841148673332698972 928360292123223779", "output": "0" }, { "input": "298248781360904821 346420922793050061 237084570581741798 726877079564549183 389611850470532358", "output": "48172141432145241" }, { "input": "420745791717606818 864206437350900994 764928840030524015 966634105370748487 793326512080703489", "output": "99277597320376979" }, { "input": "519325240668210886 776112702001665034 360568516809443669 875594219634943179 994594983925273138", "output": "256787461333454149" }, { "input": "170331212821058551 891149660635282032 125964175621755330 208256491683509799 526532153531983174", "output": "37925278862451249" }, { "input": "1 3 3 5 3", "output": "0" }, { "input": "1 5 8 10 9", "output": "0" }, { "input": "1 2 4 5 10", "output": "0" }, { "input": "1 2 2 3 5", "output": "1" }, { "input": "2 4 3 7 3", "output": "1" }, { "input": "1 2 9 10 1", "output": "0" }, { "input": "5 15 1 10 5", "output": "5" }, { "input": "1 4 9 20 25", "output": "0" }, { "input": "2 4 1 2 5", "output": "1" }, { "input": "10 1000 1 100 2", "output": "91" }, { "input": "1 3 3 8 10", "output": "1" }, { "input": "4 6 6 8 9", "output": "1" }, { "input": "2 3 1 4 3", "output": "1" }, { "input": "1 2 2 3 100", "output": "1" }, { "input": "1 2 100 120 2", "output": "0" }, { "input": "1 3 5 7 4", "output": "0" }, { "input": "1 3 5 7 5", "output": "0" }, { "input": "1 4 8 10 6", "output": "0" }, { "input": "1 2 5 6 100", "output": "0" }, { "input": "1 2 5 10 20", "output": "0" }, { "input": "1 2 5 6 7", "output": "0" }, { "input": "2 5 7 12 6", "output": "0" }, { "input": "10 20 50 100 80", "output": "0" }, { "input": "1 2 5 10 2", "output": "0" }, { "input": "1 2 5 6 4", "output": "0" }, { "input": "5 9 1 2 3", "output": "0" }, { "input": "50 100 1 20 3", "output": "0" }, { "input": "10 20 3 7 30", "output": "0" }, { "input": "1 5 10 10 100", "output": "0" }, { "input": "100 101 1 2 3", "output": "0" }, { "input": "1 5 10 20 6", "output": "0" }, { "input": "1 10 15 25 5", "output": "0" }, { "input": "1 2 5 10 3", "output": "0" }, { "input": "2 3 5 6 100", "output": "0" }, { "input": "1 2 4 5 6", "output": "0" }, { "input": "6 10 1 2 40", "output": "0" }, { "input": "20 30 1 5 1", "output": "0" }, { "input": "20 40 50 100 50", "output": "0" }, { "input": "1 1 4 9 2", "output": "0" }, { "input": "1 2 5 6 1", "output": "0" }, { "input": "1 100 400 500 450", "output": "0" }, { "input": "5 6 1 2 5", "output": "0" }, { "input": "1 10 21 30 50", "output": "0" }, { "input": "100 200 300 400 101", "output": "0" }, { "input": "2 8 12 16 9", "output": "0" }, { "input": "1 5 7 9 6", "output": "0" }, { "input": "300 400 100 200 101", "output": "0" }, { "input": "1 2 2 3 10", "output": "1" }, { "input": "1 10 100 200 5", "output": "0" }, { "input": "1 3 3 4 4", "output": "1" }, { "input": "10 20 30 40 25", "output": "0" }, { "input": "1 2 5 10 1", "output": "0" }, { "input": "2 4 8 10 1", "output": "0" }, { "input": "2 5 10 15 7", "output": "0" }, { "input": "100 200 5 10 1", "output": "0" }, { "input": "1 2 100 200 300", "output": "0" }, { "input": "30 100 10 20 25", "output": "0" }, { "input": "10 20 1 5 6", "output": "0" }, { "input": "4 5 1 2 4", "output": "0" }, { "input": "11 100 1 9 1000", "output": "0" }, { "input": "1 1 10 10 228", "output": "0" }, { "input": "5 7 10 20 15", "output": "0" }, { "input": "1 3 8 9 7", "output": "0" }, { "input": "1 10 2 8 8", "output": "6" }, { "input": "1 5 9 15 1", "output": "0" }, { "input": "1 3 5 6 12", "output": "0" }, { "input": "1 100 500 1000 3", "output": "0" }, { "input": "1 1 1 1 2", "output": "1" }, { "input": "1 1000 100 1000 200", "output": "900" }, { "input": "4 5 1 4 1", "output": "1" }, { "input": "1 5 5 7 3", "output": "1" }, { "input": "1 4 4 10 11", "output": "1" }, { "input": "1 1 3 4 100", "output": "0" }, { "input": "1 4 3 5 6", "output": "2" }, { "input": "10 100 20 30 40", "output": "11" }, { "input": "5 9 1 11 7", "output": "4" } ]
46
6,758,400
0
17
855
Helga Hufflepuff's Cup
[ "dp", "trees" ]
null
null
Harry, Ron and Hermione have figured out that Helga Hufflepuff's cup is a horcrux. Through her encounter with Bellatrix Lestrange, Hermione came to know that the cup is present in Bellatrix's family vault in Gringott's Wizarding Bank. The Wizarding bank is in the form of a tree with total *n* vaults where each vault has some type, denoted by a number between 1 to *m*. A tree is an undirected connected graph with no cycles. The vaults with the highest security are of type *k*, and all vaults of type *k* have the highest security. There can be at most *x* vaults of highest security. Also, if a vault is of the highest security, its adjacent vaults are guaranteed to not be of the highest security and their type is guaranteed to be less than *k*. Harry wants to consider every possibility so that he can easily find the best path to reach Bellatrix's vault. So, you have to tell him, given the tree structure of Gringotts, the number of possible ways of giving each vault a type such that the above conditions hold.
The first line of input contains two space separated integers, *n* and *m* — the number of vaults and the number of different vault types possible. (1<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=109). Each of the next *n*<=-<=1 lines contain two space separated integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*) representing the *i*-th edge, which shows there is a path between the two vaults *u**i* and *v**i*. It is guaranteed that the given graph is a tree. The last line of input contains two integers *k* and *x* (1<=≤<=*k*<=≤<=*m*,<=1<=≤<=*x*<=≤<=10), the type of the highest security vault and the maximum possible number of vaults of highest security.
Output a single integer, the number of ways of giving each vault a type following the conditions modulo 109<=+<=7.
[ "4 2\n1 2\n2 3\n1 4\n1 2\n", "3 3\n1 2\n1 3\n2 1\n", "3 1\n1 2\n1 3\n1 1\n" ]
[ "1\n", "13\n", "0\n" ]
In test case 1, we cannot have any vault of the highest security as its type is 1 implying that its adjacent vaults would have to have a vault type less than 1, which is not allowed. Thus, there is only one possible combination, in which all the vaults have type 2.
[ { "input": "4 2\n1 2\n2 3\n1 4\n1 2", "output": "1" }, { "input": "3 3\n1 2\n1 3\n2 1", "output": "13" }, { "input": "3 1\n1 2\n1 3\n1 1", "output": "0" }, { "input": "3 1000000000\n2 3\n3 1\n585430050 9", "output": "91592837" }, { "input": "4 50000\n2 1\n4 2\n2 3\n42169 9", "output": "542369366" }, { "input": "15 100000\n9 7\n15 13\n1 13\n14 5\n6 10\n5 12\n4 14\n4 6\n8 3\n8 2\n9 3\n10 15\n11 8\n10 3\n16283 7", "output": "770195687" } ]
77
0
0
18
559
Equivalent Strings
[ "divide and conquer", "hashing", "sortings", "strings" ]
null
null
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1 As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent. Gerald has already completed this home task. Now it's your turn!
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length.
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
[ "aaba\nabaa\n", "aabb\nabab\n" ]
[ "YES\n", "NO\n" ]
In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a". In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".
[ { "input": "aaba\nabaa", "output": "YES" }, { "input": "aabb\nabab", "output": "NO" }, { "input": "a\na", "output": "YES" }, { "input": "a\nb", "output": "NO" }, { "input": "ab\nab", "output": "YES" }, { "input": "ab\nba", "output": "YES" }, { "input": "ab\nbb", "output": "NO" }, { "input": "zzaa\naazz", "output": "YES" }, { "input": "azza\nzaaz", "output": "YES" }, { "input": "abc\nabc", "output": "YES" }, { "input": "abc\nacb", "output": "NO" }, { "input": "azzz\nzzaz", "output": "YES" }, { "input": "abcd\ndcab", "output": "YES" }, { "input": "abcd\ncdab", "output": "YES" }, { "input": "abcd\ndcba", "output": "YES" }, { "input": "abcd\nacbd", "output": "NO" }, { "input": "oloaxgddgujq\noloaxgujqddg", "output": "YES" }, { "input": "uwzwdxfmosmqatyv\ndxfmzwwusomqvyta", "output": "YES" }, { "input": "hagnzomowtledfdotnll\nledfdotnllomowthagnz", "output": "YES" }, { "input": "snyaydaeobufdg\nsnyaydaeobufdg", "output": "YES" }, { "input": "baaaaa\nabaaaa", "output": "NO" }, { "input": "hhiisug\nmzdjwju", "output": "NO" }, { "input": "bbbabbabaaab\naaaabbabbbbb", "output": "NO" }, { "input": "bbaaab\naababb", "output": "NO" }, { "input": "aabbaaaa\naaaaabab", "output": "NO" }, { "input": "aab\naba", "output": "NO" }, { "input": "abcddd\nbacddd", "output": "NO" }, { "input": "qgiufelsfhanx\naaaaaaaaaaaaa", "output": "NO" }, { "input": "aabaababaaba\naababaaababa", "output": "NO" }, { "input": "nocdqzdriyyil\naaaaaaaaaaaaa", "output": "NO" }, { "input": "zdmctxl\nkojqhgw", "output": "NO" }, { "input": "yhwepqwyhwepqwyhwepqweahnqtueahnqtueahnqtuyhwepqwyhwepqwyhwepqwyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtueahnqtueahnqtueahnqtueahnqtu\neahnqtueahnqtueahnqtuyhwepqweahnqtuyhwepqwyhwepqweahnqtuyhwepqweahnqtuyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtuyhwepqwyhwepqwyhwepqw", "output": "NO" }, { "input": "abc\nbac", "output": "NO" }, { "input": "ottceez\npcstdvz", "output": "NO" } ]
2,000
1,638,400
0
19
702
Powers of Two
[ "brute force", "data structures", "implementation", "math" ]
null
null
You are given *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Find the number of pairs of indexes *i*,<=*j* (*i*<=&lt;<=*j*) that *a**i*<=+<=*a**j* is a power of 2 (i. e. some integer *x* exists so that *a**i*<=+<=*a**j*<==<=2*x*).
The first line contains the single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print the number of pairs of indexes *i*,<=*j* (*i*<=&lt;<=*j*) that *a**i*<=+<=*a**j* is a power of 2.
[ "4\n7 3 2 1\n", "3\n1 1 1\n" ]
[ "2\n", "3\n" ]
In the first example the following pairs of indexes include in answer: (1, 4) and (2, 4). In the second example all pairs of indexes (*i*, *j*) (where *i* &lt; *j*) include in answer.
[ { "input": "4\n7 3 2 1", "output": "2" }, { "input": "3\n1 1 1", "output": "3" }, { "input": "1\n1000000000", "output": "0" }, { "input": "10\n2827343 1373647 96204862 723505 796619138 71550121 799843967 5561265 402690754 446173607", "output": "2" }, { "input": "10\n6 6 7 3 9 14 15 7 2 2", "output": "9" }, { "input": "100\n3 6 12 1 16 4 9 5 4 4 5 8 12 4 6 14 5 1 2 2 2 1 7 1 9 10 6 13 7 8 3 11 8 11 7 5 15 6 14 10 4 2 10 9 1 8 14 9 5 11 3 4 1 12 6 8 13 4 8 5 4 13 13 1 3 9 14 7 14 10 7 3 12 8 9 8 6 15 9 10 12 14 15 4 16 8 8 4 8 7 5 10 16 4 10 13 6 16 16 5", "output": "532" }, { "input": "1\n2", "output": "0" }, { "input": "2\n1 1", "output": "1" } ]
171
19,558,400
3
20
109
Lucky Sum of Digits
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "output": "444" }, { "input": "1000000", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "47", "output": "44477777" }, { "input": "100", "output": "4444777777777777" }, { "input": "700", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "485", "output": "44447777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "111", "output": "444447777777777777" }, { "input": "85", "output": "4477777777777" }, { "input": "114", "output": "444477777777777777" }, { "input": "474", "output": "444777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "74", "output": "47777777777" }, { "input": "1000", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "1024", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "4444", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "45784", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10000", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9854", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "186", "output": "477777777777777777777777777" }, { "input": "10416", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10417", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "3840", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "100000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9876", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "99999", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "777777", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "854759", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "11000", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "18951", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999999", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "888887", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999998", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "40008", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10691", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "5", "output": "-1" }, { "input": "6", "output": "-1" }, { "input": "9", "output": "-1" }, { "input": "8", "output": "44" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "-1" }, { "input": "999997", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999996", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999990", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999980", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "800000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "980000", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." } ]
468
102,400
3.882809
21
540
Combination Lock
[ "implementation" ]
null
null
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
[ "5\n82195\n64723\n" ]
[ "13\n" ]
In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
[ { "input": "5\n82195\n64723", "output": "13" }, { "input": "12\n102021090898\n010212908089", "output": "16" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "10\n0728592530\n1362615763", "output": "27" }, { "input": "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746", "output": "245" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "3\n607\n684", "output": "5" }, { "input": "4\n0809\n0636", "output": "8" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8037856825987124762280548\n9519431339078678836940020", "output": "72" }, { "input": "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024", "output": "305" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8037856825987124762285484\n9519431339078678836940202", "output": "74" }, { "input": "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831", "output": "357" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8378525987476228048406972\n9194339078883694020217816", "output": "55" }, { "input": "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599", "output": "274" }, { "input": "1\n0\n0", "output": "0" }, { "input": "1\n7\n7", "output": "0" }, { "input": "1\n0\n5", "output": "5" }, { "input": "1\n2\n7", "output": "5" }, { "input": "1\n7\n9", "output": "2" }, { "input": "1\n9\n7", "output": "2" }, { "input": "1\n2\n9", "output": "3" }, { "input": "1\n9\n2", "output": "3" }, { "input": "25\n3164978461316464614169874\n9413979197249127496597357", "output": "66" }, { "input": "4\n9999\n9999", "output": "0" }, { "input": "2\n11\n11", "output": "0" } ]
0
0
-1
22
3
Shortest path of the king
[ "greedy", "shortest paths" ]
A. Shortest path of the king
1
64
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
[ "a8\nh1\n" ]
[ "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n" ]
none
[ { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "b2\nb4", "output": "2\nU\nU" }, { "input": "a5\na5", "output": "0" }, { "input": "h1\nb2", "output": "6\nLU\nL\nL\nL\nL\nL" }, { "input": "c5\nh2", "output": "5\nRD\nRD\nRD\nR\nR" }, { "input": "e1\nf2", "output": "1\nRU" }, { "input": "g4\nd2", "output": "3\nLD\nLD\nL" }, { "input": "a8\nb2", "output": "6\nRD\nD\nD\nD\nD\nD" }, { "input": "d4\nh2", "output": "4\nRD\nRD\nR\nR" }, { "input": "c5\na2", "output": "3\nLD\nLD\nD" }, { "input": "h5\nf8", "output": "3\nLU\nLU\nU" }, { "input": "e6\nb6", "output": "3\nL\nL\nL" }, { "input": "a6\ng4", "output": "6\nRD\nRD\nR\nR\nR\nR" }, { "input": "f7\nc2", "output": "5\nLD\nLD\nLD\nD\nD" }, { "input": "b7\nh8", "output": "6\nRU\nR\nR\nR\nR\nR" }, { "input": "g7\nd6", "output": "3\nLD\nL\nL" }, { "input": "c8\na3", "output": "5\nLD\nLD\nD\nD\nD" }, { "input": "h8\nf1", "output": "7\nLD\nLD\nD\nD\nD\nD\nD" }, { "input": "d1\nb7", "output": "6\nLU\nLU\nU\nU\nU\nU" }, { "input": "a7\ne5", "output": "4\nRD\nRD\nR\nR" }, { "input": "d6\nb1", "output": "5\nLD\nLD\nD\nD\nD" }, { "input": "f5\ng5", "output": "1\nR" }, { "input": "h4\nd1", "output": "4\nLD\nLD\nLD\nL" }, { "input": "b3\na5", "output": "2\nLU\nU" }, { "input": "d2\nf1", "output": "2\nRD\nR" }, { "input": "f1\nc5", "output": "4\nLU\nLU\nLU\nU" }, { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "c7\ne5", "output": "2\nRD\nRD" }, { "input": "e7\nb1", "output": "6\nLD\nLD\nLD\nD\nD\nD" }, { "input": "g8\na8", "output": "6\nL\nL\nL\nL\nL\nL" }, { "input": "g6\nf2", "output": "4\nLD\nD\nD\nD" }, { "input": "g4\nc4", "output": "4\nL\nL\nL\nL" }, { "input": "g2\na6", "output": "6\nLU\nLU\nLU\nLU\nL\nL" }, { "input": "f8\nf8", "output": "0" }, { "input": "f5\nd2", "output": "3\nLD\nLD\nD" } ]
184
0
3.908
23
144
Arrival of the General
[ "implementation" ]
null
null
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important. For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong. Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different.
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
[ "4\n33 44 11 22\n", "7\n10 10 58 31 63 40 76\n" ]
[ "2\n", "10\n" ]
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10)
[ { "input": "4\n33 44 11 22", "output": "2" }, { "input": "7\n10 10 58 31 63 40 76", "output": "10" }, { "input": "2\n88 89", "output": "1" }, { "input": "5\n100 95 100 100 88", "output": "0" }, { "input": "7\n48 48 48 48 45 45 45", "output": "0" }, { "input": "10\n68 47 67 29 63 71 71 65 54 56", "output": "10" }, { "input": "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92", "output": "4" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14", "output": "0" }, { "input": "35\n37 41 46 39 47 39 44 47 44 42 44 43 47 39 46 39 38 42 39 37 40 44 41 42 41 42 39 42 36 36 42 36 42 42 42", "output": "7" }, { "input": "40\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99", "output": "47" }, { "input": "50\n48 52 44 54 53 56 62 49 39 41 53 39 40 64 53 50 62 48 40 52 51 48 40 52 61 62 62 61 48 64 55 57 56 40 48 58 41 60 60 56 64 50 64 45 48 45 46 63 59 57", "output": "50" }, { "input": "57\n7 24 17 19 6 19 10 11 12 22 14 5 5 11 13 10 24 19 24 24 24 11 21 20 4 14 24 24 18 13 24 3 20 3 3 3 3 9 3 9 22 22 16 3 3 3 15 11 3 3 8 17 10 13 3 14 13", "output": "3" }, { "input": "65\n58 50 35 44 35 37 36 58 38 36 58 56 56 49 48 56 58 43 40 44 52 44 58 58 57 50 43 35 55 39 38 49 53 56 50 42 41 56 34 57 49 38 34 51 56 38 58 40 53 46 48 34 38 43 49 49 58 56 41 43 44 34 38 48 36", "output": "3" }, { "input": "69\n70 48 49 48 49 71 48 53 55 69 48 53 54 58 53 63 48 48 69 67 72 75 71 75 74 74 57 63 65 60 48 48 65 48 48 51 50 49 62 53 76 68 76 56 76 76 64 76 76 57 61 76 73 51 59 76 65 50 69 50 76 67 76 63 62 74 74 58 73", "output": "73" }, { "input": "75\n70 65 64 71 71 64 71 64 68 71 65 64 65 68 71 66 66 69 68 63 69 65 71 69 68 68 71 67 71 65 65 65 71 71 65 69 63 66 62 67 64 63 62 64 67 65 62 69 62 64 69 62 67 64 67 70 64 63 64 64 69 62 62 64 70 62 62 68 67 69 62 64 66 70 68", "output": "7" }, { "input": "84\n92 95 84 85 94 80 90 86 80 92 95 84 86 83 86 83 93 91 95 92 84 88 82 84 84 84 80 94 93 80 94 80 95 83 85 80 95 95 80 84 86 92 83 81 90 87 81 89 92 93 80 87 90 85 93 85 93 94 93 89 94 83 93 91 80 83 90 94 95 80 95 92 85 84 93 94 94 82 91 95 95 89 85 94", "output": "15" }, { "input": "90\n86 87 72 77 82 71 75 78 61 67 79 90 64 94 94 74 85 87 73 76 71 71 60 69 77 73 76 80 82 57 62 57 57 83 76 72 75 87 72 94 77 85 59 82 86 69 62 80 95 73 83 94 79 85 91 68 85 74 93 95 68 75 89 93 83 78 95 78 83 77 81 85 66 92 63 65 75 78 67 91 77 74 59 86 77 76 90 67 70 64", "output": "104" }, { "input": "91\n94 98 96 94 95 98 98 95 98 94 94 98 95 95 99 97 97 94 95 98 94 98 96 98 96 98 97 95 94 94 94 97 94 96 98 98 98 94 96 95 94 95 97 97 97 98 94 98 96 95 98 96 96 98 94 97 96 98 97 95 97 98 94 95 94 94 97 94 96 97 97 93 94 95 95 94 96 98 97 96 94 98 98 96 96 96 96 96 94 96 97", "output": "33" }, { "input": "92\n44 28 32 29 41 41 36 39 40 39 41 35 41 28 35 27 41 34 28 38 43 43 41 38 27 26 28 36 30 29 39 32 35 35 32 30 39 30 37 27 41 41 28 30 43 31 35 33 36 28 44 40 41 35 31 42 37 38 37 34 39 40 27 40 33 33 44 43 34 33 34 34 35 38 38 37 30 39 35 41 45 42 41 32 33 33 31 30 43 41 43 43", "output": "145" }, { "input": "93\n46 32 52 36 39 30 57 63 63 30 32 44 27 59 46 38 40 45 44 62 35 36 51 48 39 58 36 51 51 51 48 58 59 36 29 35 31 49 64 60 34 38 42 56 33 42 52 31 63 34 45 51 35 45 33 53 33 62 31 38 66 29 51 54 28 61 32 45 57 41 36 34 47 36 31 28 67 48 52 46 32 40 64 58 27 53 43 57 34 66 43 39 26", "output": "76" }, { "input": "94\n56 55 54 31 32 42 46 29 24 54 40 40 20 45 35 56 32 33 51 39 26 56 21 56 51 27 29 39 56 52 54 43 43 55 48 51 44 49 52 49 23 19 19 28 20 26 45 33 35 51 42 36 25 25 38 23 21 35 54 50 41 20 37 28 42 20 22 43 37 34 55 21 24 38 19 41 45 34 19 33 44 54 38 31 23 53 35 32 47 40 39 31 20 34", "output": "15" }, { "input": "95\n57 71 70 77 64 64 76 81 81 58 63 75 81 77 71 71 71 60 70 70 69 67 62 64 78 64 69 62 76 76 57 70 68 77 70 68 73 77 79 73 60 57 69 60 74 65 58 75 75 74 73 73 65 75 72 57 81 62 62 70 67 58 76 57 79 81 68 64 58 77 70 59 79 64 80 58 71 59 81 71 80 64 78 80 78 65 70 68 78 80 57 63 64 76 81", "output": "11" }, { "input": "96\n96 95 95 95 96 97 95 97 96 95 98 96 97 95 98 96 98 96 98 96 98 95 96 95 95 95 97 97 95 95 98 98 95 96 96 95 97 96 98 96 95 97 97 95 97 97 95 94 96 96 97 96 97 97 96 94 94 97 95 95 95 96 95 96 95 97 97 95 97 96 95 94 97 97 97 96 97 95 96 94 94 95 97 94 94 97 97 97 95 97 97 95 94 96 95 95", "output": "13" }, { "input": "97\n14 15 12 12 13 15 12 15 12 12 12 12 12 14 15 15 13 12 15 15 12 12 12 13 14 15 15 13 14 15 14 14 14 14 12 13 12 13 13 12 15 12 13 13 15 12 15 13 12 13 13 13 14 13 12 15 14 13 14 15 13 14 14 13 14 12 15 12 14 12 13 14 15 14 13 15 13 12 15 15 15 13 15 15 13 14 16 16 16 13 15 13 15 14 15 15 15", "output": "104" }, { "input": "98\n37 69 35 70 58 69 36 47 41 63 60 54 49 35 55 50 35 53 52 43 35 41 40 49 38 35 48 70 42 35 35 65 56 54 44 59 59 48 51 49 59 67 35 60 69 35 58 50 35 44 48 69 41 58 44 45 35 47 70 61 49 47 37 39 35 51 44 70 72 65 36 41 63 63 48 66 45 50 50 71 37 52 72 67 72 39 72 39 36 64 48 72 69 49 45 72 72 67", "output": "100" }, { "input": "99\n31 31 16 15 19 31 19 22 29 27 12 22 28 30 25 33 26 25 19 22 34 21 17 33 31 22 16 26 22 30 31 17 13 33 13 17 28 25 18 33 27 22 31 22 13 27 20 22 23 15 24 32 29 13 16 20 32 33 14 33 19 27 16 28 25 17 17 28 18 26 32 33 19 23 30 13 14 23 24 28 14 28 22 20 30 14 24 23 17 29 18 28 29 21 28 18 16 24 32", "output": "107" }, { "input": "100\n37 54 39 29 32 49 21 13 34 21 16 42 34 27 16 26 7 34 51 9 11 27 16 40 36 7 48 52 30 42 42 52 51 11 32 26 6 7 28 54 48 51 6 54 42 20 51 48 46 4 4 31 47 6 9 16 8 23 36 50 49 30 47 37 45 24 48 26 8 50 18 24 27 13 39 7 37 34 5 43 42 19 34 23 52 38 35 6 29 11 53 49 21 29 36 22 45 33 51 22", "output": "50" }, { "input": "100\n41 5 20 23 5 47 28 28 64 5 12 14 34 56 22 48 6 52 39 55 62 40 24 54 39 28 56 27 35 51 14 24 38 10 55 20 39 62 52 2 30 55 49 48 15 23 59 44 31 28 66 29 62 59 31 13 28 12 50 45 41 47 29 27 64 66 14 39 62 22 44 63 24 5 63 17 42 7 25 41 49 33 31 51 63 3 37 66 19 9 2 40 16 45 56 21 34 29 39 61", "output": "59" }, { "input": "100\n66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95", "output": "99" }, { "input": "100\n81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "0" }, { "input": "3\n2 1 2", "output": "1" }, { "input": "2\n100 99", "output": "0" }, { "input": "100\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", "output": "197" }, { "input": "100\n87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87", "output": "0" }, { "input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "3\n1 3 2", "output": "2" } ]
30
0
-1
24
676
Vasya and String
[ "binary search", "dp", "strings", "two pointers" ]
null
null
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve?
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters.
[ "4 2\nabba\n", "8 1\naabaabaa\n" ]
[ "4\n", "5\n" ]
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
[ { "input": "4 2\nabba", "output": "4" }, { "input": "8 1\naabaabaa", "output": "5" }, { "input": "1 0\na", "output": "1" }, { "input": "1 1\nb", "output": "1" }, { "input": "1 0\nb", "output": "1" }, { "input": "1 1\na", "output": "1" }, { "input": "10 10\nbbbbbbbbbb", "output": "10" }, { "input": "10 2\nbbbbbbbbbb", "output": "10" }, { "input": "10 1\nbbabbabbba", "output": "6" }, { "input": "10 10\nbbabbbaabb", "output": "10" }, { "input": "10 9\nbabababbba", "output": "10" }, { "input": "10 4\nbababbaaab", "output": "9" }, { "input": "10 10\naabaaabaaa", "output": "10" }, { "input": "10 10\naaaabbbaaa", "output": "10" }, { "input": "10 1\nbaaaaaaaab", "output": "9" }, { "input": "10 5\naaaaabaaaa", "output": "10" }, { "input": "10 4\naaaaaaaaaa", "output": "10" }, { "input": "100 10\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "100" }, { "input": "100 7\nbbbbabbbbbaabbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbab", "output": "93" }, { "input": "100 30\nbbaabaaabbbbbbbbbbaababababbbbbbaabaabbbbbbbbabbbbbabbbbabbbbbbbbaabbbbbbbbbabbbbbabbbbbbbbbaaaaabba", "output": "100" }, { "input": "100 6\nbaababbbaabbabbaaabbabbaabbbbbbbbaabbbabbbbaabbabbbbbabababbbbabbbbbbabbbbbbbbbaaaabbabbbbaabbabaabb", "output": "34" }, { "input": "100 45\naabababbabbbaaabbbbbbaabbbabbaabbbbbabbbbbbbbabbbbbbabbaababbaabbababbbbbbababbbbbaabbbbbbbaaaababab", "output": "100" }, { "input": "100 2\nababaabababaaababbaaaabbaabbbababbbaaabbbbabababbbabababaababaaabaabbbbaaabbbabbbbbabbbbbbbaabbabbba", "output": "17" }, { "input": "100 25\nbabbbaaababaaabbbaabaabaabbbabbabbbbaaaaaaabaaabaaaaaaaaaabaaaabaaabbbaaabaaababaaabaabbbbaaaaaaaaaa", "output": "80" }, { "input": "100 14\naabaaaaabababbabbabaaaabbaaaabaaabbbaaabaaaaaaaabaaaaabbaaaaaaaaabaaaaaaabbaababaaaababbbbbabaaaabaa", "output": "61" }, { "input": "100 8\naaaaabaaaabaabaaaaaaaabaaaabaaaaaaaaaaaaaabaaaaabaaaaaaaaaaaaaaaaabaaaababaabaaaaaaaaaaaaabbabaaaaaa", "output": "76" }, { "input": "100 12\naaaaaaaaaaaaaaaabaaabaaaaaaaaaabbaaaabbabaaaaaaaaaaaaaaaaaaaaabbaaabaaaaaaaaaaaabaaaaaaaabaaaaaaaaaa", "output": "100" }, { "input": "100 65\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "100" }, { "input": "10 0\nbbbbbbbbbb", "output": "10" }, { "input": "10 0\nbbbbabbbbb", "output": "5" }, { "input": "10 0\nbbabbbabba", "output": "3" }, { "input": "10 0\nbaabbbbaba", "output": "4" }, { "input": "10 0\naababbbbaa", "output": "4" }, { "input": "10 2\nabbbbbaaba", "output": "8" }, { "input": "10 0\nabbaaabaaa", "output": "3" }, { "input": "10 0\naabbaaabaa", "output": "3" }, { "input": "10 1\naaaaaababa", "output": "8" }, { "input": "10 0\nbaaaaaaaaa", "output": "9" }, { "input": "10 0\naaaaaaaaaa", "output": "10" }, { "input": "100 0\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "100" }, { "input": "100 0\nbbbbbbbbbbabbbbaaabbbbbbbbbbbabbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbabbbbbbbbbbbbbab", "output": "40" }, { "input": "100 11\nbaabbbbbababbbbabbbbbbbabbbbbbbbbbbbbbabbbbbbababbbbababbbbaaabbbbabbbbbabbbbbbbbabababbbabbbbbbbabb", "output": "65" }, { "input": "100 8\nbbababbbbbaabbbaaababbbbababababbbbababbabbbabbbbbaabbbabbbababbabbbbabbbabbbbaabbbbabbbaabbbbaaaabb", "output": "33" }, { "input": "100 21\nabbaaaabbbababaabbbababbbbbbbbabbaababababbbabbbaaabbaaabbbbabbabbbabbbabaababbbabbbbbabbbbbbabbbbab", "output": "65" }, { "input": "100 9\nabbbaabaabaaaaaaabbabbbababbaaabbbaaabbaabaaaaabbbbbabbaabaabbbbbaaaaababbaaabbabaabaaabababbaababbb", "output": "26" }, { "input": "100 5\naababababbaaaaaaaabbbabaaaabbabaaaabbaabaaaaabababbabaabaaabaaaaaaaabaababbabbaaabaabbabbaaaaabbabba", "output": "22" }, { "input": "100 9\naababaabaaaaaaaaabbbaabaaaaaaabaaaaaaaaaaaaabaaabaabaabbbbabbaababbabbaaaabbababaabaababaabaaaaaaaaa", "output": "49" }, { "input": "100 6\naaaaabbaaaaaaaaaaabaaaabaaaaaaaaabaaabaaaaaabaaaaaaaaaaabaabaaaabaaaaaaaaaaaaaaabaabbaaaaaaaaaaaaaaa", "output": "56" }, { "input": "100 7\nabaaabaabaabaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaabaaaaaaabbabaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaba", "output": "86" }, { "input": "100 0\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "100" } ]
124
102,400
3
25
955
Feed the cat
[ "greedy", "math" ]
null
null
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points. At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs *C* roubles and decreases hunger by *N* points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts. Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero.
The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening. The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102).
Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
[ "19 00\n255 1 100 1\n", "17 41\n1000 6 15 11\n" ]
[ "25200.0000\n", "1365.0000\n" ]
In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles. In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles.
[ { "input": "19 00\n255 1 100 1", "output": "25200.0000" }, { "input": "17 41\n1000 6 15 11", "output": "1365.0000" }, { "input": "16 34\n61066 14 50 59", "output": "43360.0000" }, { "input": "18 18\n23331 86 87 41", "output": "49590.0000" }, { "input": "10 48\n68438 8 18 29", "output": "36187.2000" }, { "input": "08 05\n63677 9 83 25", "output": "186252.0000" }, { "input": "00 00\n100000 100 100 100", "output": "100000.0000" }, { "input": "20 55\n100000 100 100 100", "output": "80000.0000" }, { "input": "23 59\n100000 100 100 100", "output": "80000.0000" }, { "input": "00 00\n1 100 100 100", "output": "100.0000" }, { "input": "21 26\n33193 54 97 66", "output": "39032.8000" }, { "input": "20 45\n33756 24 21 1", "output": "567100.8000" }, { "input": "14 33\n92062 59 89 72", "output": "110146.4000" }, { "input": "01 24\n92730 5 35 29", "output": "94920.0000" }, { "input": "20 58\n93398 43 86 99", "output": "64947.2000" }, { "input": "23 04\n37170 81 32 64", "output": "14873.6000" }, { "input": "01 38\n70542 27 74 26", "output": "200836.0000" }, { "input": "04 28\n38505 65 25 95", "output": "10150.0000" }, { "input": "00 10\n33077 21 40 22", "output": "60160.0000" }, { "input": "10 44\n66449 67 90 83", "output": "72090.0000" }, { "input": "05 51\n10220 5 33 48", "output": "7029.0000" }, { "input": "20 19\n68886 28 48 94", "output": "28147.2000" }, { "input": "01 49\n11621 55 78 46", "output": "19734.0000" }, { "input": "21 28\n78549 91 4 98", "output": "2566.4000" }, { "input": "18 06\n88580 22 35 59", "output": "43232.0000" }, { "input": "22 28\n55507 53 61 11", "output": "246293.6000" }, { "input": "18 58\n22434 84 91 59", "output": "34143.2000" }, { "input": "15 36\n32466 27 22 15", "output": "46464.0000" }, { "input": "17 31\n9603 53 73 74", "output": "9490.0000" }, { "input": "14 53\n76530 92 4 22", "output": "13916.0000" }, { "input": "18 31\n10753 23 30 74", "output": "4152.0000" }, { "input": "17 43\n16290 46 90 94", "output": "15660.0000" }, { "input": "18 38\n3652 11 53 94", "output": "2067.0000" }, { "input": "19 57\n3 4 7 6", "output": "7.0000" } ]
30
0
0
27
764
Taymyr is calling you
[ "brute force", "implementation", "math" ]
null
null
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
[ "1 1 10\n", "1 2 5\n", "2 3 9\n" ]
[ "10\n", "2\n", "1\n" ]
Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
[ { "input": "1 1 10", "output": "10" }, { "input": "1 2 5", "output": "2" }, { "input": "2 3 9", "output": "1" }, { "input": "4 8 9", "output": "1" }, { "input": "7 9 2", "output": "0" }, { "input": "10000 10000 10000", "output": "1" }, { "input": "24 22 9235", "output": "34" }, { "input": "74 8 417", "output": "1" }, { "input": "972 1 203", "output": "0" }, { "input": "550 1 754", "output": "1" }, { "input": "860 1 884", "output": "1" }, { "input": "358 2 809", "output": "2" }, { "input": "33 27 216", "output": "0" }, { "input": "2940 1 9311", "output": "3" }, { "input": "4624 1 1953", "output": "0" }, { "input": "2696 2 7345", "output": "2" }, { "input": "3443 2 6701", "output": "0" }, { "input": "3 613 2275", "output": "1" }, { "input": "1 10000 10000", "output": "1" }, { "input": "10000 1 10000", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1 10000", "output": "10000" }, { "input": "34 27 10000", "output": "10" }, { "input": "2 2 9999", "output": "4999" }, { "input": "2 2 1", "output": "0" }, { "input": "6 4 36", "output": "3" }, { "input": "33 6 3005", "output": "45" }, { "input": "5 1 20", "output": "4" }, { "input": "1 2 10", "output": "5" }, { "input": "2 1 100", "output": "50" }, { "input": "10 20 10000", "output": "500" }, { "input": "8 12 12", "output": "0" } ]
1,000
1,024,000
0
28
525
Vitaliy and Pie
[ "greedy", "hashing", "strings" ]
null
null
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (*n*<=-<=1)-th room to the *n*-th room. Thus, you can go to room *x* only from room *x*<=-<=1. The potato pie is located in the *n*-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room *x* from room *x*<=-<=1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type *t* can open the door of type *T* if and only if *t* and *T* are the same letter, written in different cases. For example, key f can open door F. Each of the first *n*<=-<=1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door. Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room *n*. Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room *n*, which has a delicious potato pie. Write a program that will help Vitaly find out this number.
The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house. The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position *i* of the given string *s* contains a lowercase Latin letter — the type of the key that lies in room number (*i*<=+<=1)<=/<=2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position *i* of the given string *s* contains an uppercase letter — the type of the door that leads from room *i*<=/<=2 to room *i*<=/<=2<=+<=1.
Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*.
[ "3\naAbB\n", "4\naBaCaB\n", "5\nxYyXzZaZ\n" ]
[ "0\n", "3\n", "2\n" ]
none
[ { "input": "3\naAbB", "output": "0" }, { "input": "4\naBaCaB", "output": "3" }, { "input": "5\nxYyXzZaZ", "output": "2" }, { "input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY", "output": "0" }, { "input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSgTfUeVdWcXbY", "output": "13" }, { "input": "5\naArRaRaR", "output": "2" }, { "input": "2\ndA", "output": "1" }, { "input": "2\ncB", "output": "1" }, { "input": "10\nhNcMeXsSlHsUwYeMcA", "output": "7" }, { "input": "100\nqDpInBmCrFwXpDbFgOzVvOcEmJrUcToAdEwEgTvBvBfWwRpGyEaXgDdRwVlQnYgWmWhMrHaIzPyXvGaFlRsVzHhZrOuVpXrKxFzAmWwPlFtNfPtJxVmLuHjKfYyArHrEnSwSzOvDpQhCgCqLlAcNpGhXrEeFuCmAqIkXyYtSsQwIxJzNiIuTgEbVuWrMwPrAlLyKaZ", "output": "42" }, { "input": "2\ndD", "output": "0" }, { "input": "2\ndE", "output": "1" }, { "input": "3\ndDdD", "output": "0" }, { "input": "3\ndEdD", "output": "1" }, { "input": "3\ndEeD", "output": "1" }, { "input": "3\ndEeF", "output": "2" } ]
140
409,600
3
29
915
Permute Digits
[ "dp", "greedy" ]
null
null
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allowed to leave *a* as it is.
The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*.
[ "123\n222\n", "3921\n10000\n", "4940\n5000\n" ]
[ "213\n", "9321\n", "4940\n" ]
none
[ { "input": "123\n222", "output": "213" }, { "input": "3921\n10000", "output": "9321" }, { "input": "4940\n5000", "output": "4940" }, { "input": "23923472834\n23589234723", "output": "23498743322" }, { "input": "102391019\n491010301", "output": "399211100" }, { "input": "123456789123456789\n276193619183618162", "output": "276193618987554432" }, { "input": "1000000000000000000\n1000000000000000000", "output": "1000000000000000000" }, { "input": "1\n1000000000000000000", "output": "1" }, { "input": "999999999999999999\n1000000000000000000", "output": "999999999999999999" }, { "input": "2475345634895\n3455834583479", "output": "3455834579642" }, { "input": "15778899\n98715689", "output": "98598771" }, { "input": "4555\n5454", "output": "4555" }, { "input": "122112\n221112", "output": "221112" }, { "input": "199999999999991\n191000000000000", "output": "119999999999999" }, { "input": "13\n31", "output": "31" }, { "input": "212\n211", "output": "122" }, { "input": "222234\n322223", "output": "243222" }, { "input": "123456789\n987654311", "output": "987654231" }, { "input": "20123\n21022", "output": "20321" }, { "input": "10101\n11000", "output": "10110" }, { "input": "592\n924", "output": "592" }, { "input": "5654456\n5634565", "output": "5566544" }, { "input": "655432\n421631", "output": "365542" }, { "input": "200\n200", "output": "200" }, { "input": "123456789987654321\n121111111111111111", "output": "119988776655443322" }, { "input": "12345\n21344", "output": "15432" }, { "input": "120\n200", "output": "120" }, { "input": "123\n212", "output": "132" }, { "input": "2184645\n5213118", "output": "5186442" }, { "input": "9912346\n9912345", "output": "9694321" }, { "input": "5003\n5000", "output": "3500" }, { "input": "12345\n31234", "output": "25431" }, { "input": "5001\n5000", "output": "1500" }, { "input": "53436\n53425", "output": "53364" }, { "input": "9329\n3268", "output": "2993" }, { "input": "1234567890\n9000000001", "output": "8976543210" }, { "input": "321\n212", "output": "132" }, { "input": "109823464\n901234467", "output": "896443210" }, { "input": "6543\n6542", "output": "6534" }, { "input": "555441\n555100", "output": "554541" }, { "input": "472389479\n327489423", "output": "327487994" }, { "input": "45645643756464352\n53465475637456247", "output": "53465475636654442" }, { "input": "254\n599", "output": "542" }, { "input": "5232222345652321\n5000000000000000", "output": "4655533322222221" }, { "input": "201\n200", "output": "120" }, { "input": "14362799391220361\n45160821596433661", "output": "43999766332221110" }, { "input": "3453\n5304", "output": "4533" }, { "input": "989\n998", "output": "998" }, { "input": "5200000000234\n5200000000311", "output": "5200000000243" }, { "input": "5555132\n1325442", "output": "1255553" }, { "input": "123\n211", "output": "132" }, { "input": "65689\n66123", "output": "65986" }, { "input": "123451234567890\n123456789012345", "output": "123456789012345" }, { "input": "22115\n22015", "output": "21521" }, { "input": "123\n311", "output": "231" }, { "input": "12222\n21111", "output": "12222" }, { "input": "765\n567", "output": "567" }, { "input": "9087645\n9087640", "output": "9087564" }, { "input": "1111111122222333\n2220000000000000", "output": "2213332221111111" }, { "input": "7901\n7108", "output": "7091" }, { "input": "215489\n215488", "output": "214985" }, { "input": "102\n200", "output": "120" }, { "input": "19260817\n20011213", "output": "19876210" }, { "input": "12345\n53200", "output": "53142" }, { "input": "1040003001\n1040003000", "output": "1040001300" }, { "input": "295\n924", "output": "592" }, { "input": "20000000000000001\n20000000000000000", "output": "12000000000000000" }, { "input": "99988877\n99887766", "output": "99879887" }, { "input": "12\n12", "output": "12" }, { "input": "199999999999999999\n900000000000000000", "output": "199999999999999999" }, { "input": "1234\n4310", "output": "4231" }, { "input": "100011\n100100", "output": "100011" }, { "input": "328899\n328811", "output": "299883" }, { "input": "646722972346\n397619201220", "output": "397476664222" }, { "input": "1203\n1200", "output": "1032" }, { "input": "1\n2", "output": "1" }, { "input": "1112\n2110", "output": "1211" }, { "input": "4545\n5540", "output": "5454" }, { "input": "3053\n5004", "output": "3530" }, { "input": "3503\n5004", "output": "3530" }, { "input": "351731653766064847\n501550303749042658", "output": "501548777666643331" }, { "input": "10123456789013451\n26666666666666666", "output": "26598754433111100" }, { "input": "1110111\n1100000", "output": "1011111" }, { "input": "30478\n32265", "output": "30874" }, { "input": "456546546549874615\n441554543131214545", "output": "441554498766665554" }, { "input": "214\n213", "output": "142" }, { "input": "415335582799619283\n133117803602859310", "output": "132999887655543321" }, { "input": "787\n887", "output": "877" }, { "input": "3333222288889999\n3333222288881111", "output": "3332999988883222" }, { "input": "495779862481416791\n836241745208800994", "output": "829998777665444111" }, { "input": "139\n193", "output": "193" }, { "input": "9568\n6500", "output": "5986" }, { "input": "3208899\n3228811", "output": "3209988" }, { "input": "27778\n28710", "output": "27877" }, { "input": "62345\n46415", "output": "46352" }, { "input": "405739873179209\n596793907108871", "output": "594998777332100" }, { "input": "365\n690", "output": "653" }, { "input": "8388731334391\n4710766672578", "output": "4398887333311" }, { "input": "1230\n1200", "output": "1032" }, { "input": "1025\n5000", "output": "2510" }, { "input": "4207799\n4027711", "output": "2997740" }, { "input": "4444222277779999\n4444222277771111", "output": "4442999977774222" }, { "input": "7430\n3047", "output": "3047" }, { "input": "649675735\n540577056", "output": "539776654" }, { "input": "26\n82", "output": "62" }, { "input": "241285\n207420", "output": "185422" }, { "input": "3\n3", "output": "3" }, { "input": "12\n21", "output": "21" }, { "input": "481287\n826607", "output": "824871" }, { "input": "40572351\n59676984", "output": "57543210" }, { "input": "268135787269\n561193454469", "output": "539887766221" }, { "input": "4\n9", "output": "4" }, { "input": "5\n6", "output": "5" }, { "input": "60579839\n33370073", "output": "30998765" }, { "input": "49939\n39200", "output": "34999" }, { "input": "2224\n4220", "output": "2422" }, { "input": "427799\n427711", "output": "299774" }, { "input": "49\n90", "output": "49" }, { "input": "93875\n82210", "output": "79853" }, { "input": "78831\n7319682", "output": "88731" }, { "input": "937177\n7143444", "output": "977731" }, { "input": "499380628\n391990337", "output": "390988642" }, { "input": "2090909\n2900000", "output": "2099900" }, { "input": "112233445566778890\n987654321987654320", "output": "987654321876543210" }, { "input": "48257086\n80903384", "output": "80876542" }, { "input": "112233445566778890\n900654321987654320", "output": "898776655443322110" }, { "input": "112233445566778890\n123456789123456788", "output": "123456789123456780" }, { "input": "5207799\n5027711", "output": "2997750" }, { "input": "200000000000000001\n200000000000000000", "output": "120000000000000000" }, { "input": "597402457\n797455420", "output": "797455420" }, { "input": "90\n94", "output": "90" }, { "input": "86888\n88683", "output": "86888" }, { "input": "419155888\n588151913", "output": "588151894" }, { "input": "408919130\n191830070", "output": "191830049" }, { "input": "524975\n554924", "output": "554792" }, { "input": "53029\n30524", "output": "30295" }, { "input": "5549\n5542", "output": "5495" }, { "input": "6\n9", "output": "6" }, { "input": "87\n810", "output": "87" }, { "input": "920491855\n281495062", "output": "281495059" }, { "input": "6691\n6910", "output": "6691" }, { "input": "533\n335", "output": "335" }, { "input": "999999999999999998\n999999999999999997", "output": "999999999999999989" }, { "input": "21111111111111111\n21111111111111110", "output": "12111111111111111" }, { "input": "2\n12", "output": "2" }, { "input": "76544\n45744", "output": "45674" }, { "input": "2000000000000001\n2000000000000000", "output": "1200000000000000" }, { "input": "740867\n467701", "output": "467087" }, { "input": "2\n6", "output": "2" }, { "input": "103\n130", "output": "130" }, { "input": "2423712\n8466235", "output": "7432221" }, { "input": "84\n48", "output": "48" }, { "input": "1210\n12113", "output": "2110" }, { "input": "2430\n20786", "output": "4320" }, { "input": "100\n999", "output": "100" }, { "input": "19325\n21903", "output": "21593" }, { "input": "1969\n23251", "output": "9961" } ]
62
0
0
30
749
Bachgold Problem
[ "greedy", "implementation", "math", "number theory" ]
null
null
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*.
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
[ "5\n", "6\n" ]
[ "2\n2 3\n", "3\n2 2 2\n" ]
none
[ { "input": "5", "output": "2\n2 3" }, { "input": "6", "output": "3\n2 2 2" }, { "input": "2", "output": "1\n2" }, { "input": "3", "output": "1\n3" }, { "input": "99999", "output": "49999\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 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 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 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 ..." }, { "input": "14", "output": "7\n2 2 2 2 2 2 2" }, { "input": "15", "output": "7\n2 2 2 2 2 2 3" }, { "input": "53", "output": "26\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 3" }, { "input": "57", "output": "28\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 3" }, { "input": "61", "output": "30\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 3" }, { "input": "774", "output": "387\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 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 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 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 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 2 2 2 ..." }, { "input": "202", "output": "101\n2 2 2 2 2 2 2 2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]
46
102,400
3
32
204
Little Elephant and Interval
[ "binary search", "combinatorics", "dp" ]
null
null
The Little Elephant very much loves sums on intervals. This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), that the first digit of integer *x* equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not. Help him and count the number of described numbers *x* for a given pair *l* and *r*.
The single line contains a pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018) — the boundaries of the interval. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
On a single line print a single integer — the answer to the problem.
[ "2 47\n", "47 1024\n" ]
[ "12\n", "98\n" ]
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
[ { "input": "2 47", "output": "12" }, { "input": "47 1024", "output": "98" }, { "input": "1 1000", "output": "108" }, { "input": "1 10000", "output": "1008" }, { "input": "47 8545", "output": "849" }, { "input": "1000 1000", "output": "0" }, { "input": "47547 4587554587754542", "output": "458755458770699" }, { "input": "1 1000000", "output": "100008" }, { "input": "47 74", "output": "2" }, { "input": "10001 10000002", "output": "999001" }, { "input": "10000 100000", "output": "9000" }, { "input": "458754 4588754", "output": "413001" }, { "input": "111 111", "output": "1" }, { "input": "110 147", "output": "4" }, { "input": "1 1000000000", "output": "100000008" }, { "input": "12 10000000000", "output": "999999998" }, { "input": "1000000000 1000000000", "output": "0" }, { "input": "1 1000000000000000000", "output": "100000000000000008" }, { "input": "11 111111111111111100", "output": "11111111111111109" }, { "input": "100000000000000000 1000000000000000000", "output": "90000000000000000" }, { "input": "45481484484 848469844684844", "output": "84842436320036" }, { "input": "975400104587000 48754000000000001", "output": "4777859989541300" }, { "input": "11220451511 51511665251233335", "output": "5151165403078183" }, { "input": "77 77", "output": "1" }, { "input": "99 102", "output": "2" }, { "input": "9997 87878000008", "output": "8787799002" }, { "input": "10000000001 111111111111100001", "output": "11111110111110001" }, { "input": "7777 88888", "output": "8112" }, { "input": "999999999 10000000000", "output": "900000001" }, { "input": "235 236", "output": "0" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "4 7", "output": "4" }, { "input": "7 10", "output": "3" }, { "input": "1 11", "output": "10" }, { "input": "1 10", "output": "9" }, { "input": "7 8", "output": "2" }, { "input": "88 990", "output": "91" }, { "input": "458985985498001244 985458425544874008", "output": "52647244004687276" }, { "input": "115998725487587451 245744899758754501", "output": "12974617427116705" }, { "input": "595754249475458004 615044544745124547", "output": "1929029526966655" }, { "input": "9754875457700 1000000000000000000", "output": "99999024512454230" }, { "input": "8758754570000 999999999999999999", "output": "99999124124543000" }, { "input": "111111111111111111 333333333444444445", "output": "22222222233333334" }, { "input": "822981258385599125 841978899930248528", "output": "1899764154464941" }, { "input": "779547115376367013 980561039207670775", "output": "20101392383130376" }, { "input": "335408916782916802 416495628489807285", "output": "8108671170689049" }, { "input": "252509053898415172 285803555062529649", "output": "3329450116411448" }, { "input": "919845424847912645 970651082117950285", "output": "5080565727003764" }, { "input": "522842183413115088 853628713003942530", "output": "33078652959082744" }, { "input": "84324827171274023 607953653548585226", "output": "52362882637731121" }, { "input": "1312148742261681 277460340506883334", "output": "27614819176462166" }, { "input": "645762257531682046 885295120956158518", "output": "23953286342447648" }, { "input": "819875140559301752 946247219812473271", "output": "12637207925317152" }, { "input": "4 19", "output": "7" }, { "input": "5 45", "output": "9" }, { "input": "9999999999999987 99999999999999711", "output": "8999999999999973" }, { "input": "2 3", "output": "2" }, { "input": "1827171 232817181719384635", "output": "23281718171755747" }, { "input": "999999999999999999 1000000000000000000", "output": "1" }, { "input": "73 678", "output": "61" } ]
92
0
0
33
294
Shaass and Oskols
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51", "output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52" }, { "input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1", "output": "0\n0" }, { "input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5", "output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21" }, { "input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0", "output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95" }, { "input": "1\n100\n1\n1 100", "output": "0" }, { "input": "1\n100\n1\n1 1", "output": "0" }, { "input": "1\n50\n1\n1 25", "output": "0" }, { "input": "2\n50 0\n1\n1 1", "output": "0\n49" }, { "input": "1\n10\n0", "output": "10" } ]
124
0
3
34
0
none
[ "none" ]
null
null
Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to play a game. They put multiple cards and on each one they wrote a letter, either 'A', or the letter 'B'. Then they began to remove the cards one by one from left to right, every time they removed a card with the letter 'A', Alice gave Bob all the fruits she had at that moment and took out of the bag as many apples and as many oranges as she had before. Thus the number of oranges and apples Alice had, did not change. If the card had written letter 'B', then Bob did the same, that is, he gave Alice all the fruit that he had, and took from the bag the same set of fruit. After the last card way removed, all the fruit in the bag were over. You know how many oranges and apples was in the bag at first. Your task is to find any sequence of cards that Alice and Bob could have played with.
The first line of the input contains two integers, *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=1018,<=*xy*<=&gt;<=1) — the number of oranges and apples that were initially in the bag.
Print any sequence of cards that would meet the problem conditions as a compressed string of characters 'A' and 'B. That means that you need to replace the segments of identical consecutive characters by the number of repetitions of the characters and the actual character. For example, string AAABAABBB should be replaced by string 3A1B2A3B, but cannot be replaced by 2A1A1B2A3B or by 3AB2A3B. See the samples for clarifications of the output format. The string that you print should consist of at most 106 characters. It is guaranteed that if the answer exists, its compressed representation exists, consisting of at most 106 characters. If there are several possible answers, you are allowed to print any of them. If the sequence of cards that meet the problem statement does not not exist, print a single word Impossible.
[ "1 4\n", "2 2\n", "3 2\n" ]
[ "3B\n", "Impossible\n", "1A1B\n" ]
In the first sample, if the row contained three cards with letter 'B', then Bob should give one apple to Alice three times. So, in the end of the game Alice has one orange and three apples, and Bob has one apple, in total it is one orange and four apples. In second sample, there is no answer since one card is not enough for game to finish, and two cards will produce at least three apples or three oranges. In the third sample, cards contain letters 'AB', so after removing the first card Bob has one orange and one apple, and after removal of second card Alice has two oranges and one apple. So, in total it is three oranges and two apples.
[ { "input": "1 4", "output": "3B" }, { "input": "2 2", "output": "Impossible" }, { "input": "3 2", "output": "1A1B" }, { "input": "2 1", "output": "1A" }, { "input": "5 3", "output": "1A1B1A" }, { "input": "5 2", "output": "2A1B" }, { "input": "8 5", "output": "1A1B1A1B" }, { "input": "97 101", "output": "1B24A3B" }, { "input": "1 3", "output": "2B" }, { "input": "1000000000000000000 999999999999999999", "output": "1A999999999999999998B" }, { "input": "55 89", "output": "1B1A1B1A1B1A1B1A1B" }, { "input": "610 987", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A" }, { "input": "4181 6765", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A" }, { "input": "46368 75025", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B" }, { "input": "832040 514229", "output": "1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B" }, { "input": "5702887 9227465", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B" }, { "input": "701408733 433494437", "output": "1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B" }, { "input": "956722026041 591286729879", "output": "1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A" }, { "input": "498454011879264 806515533049393", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B" }, { "input": "420196140727489673 679891637638612258", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B" }, { "input": "1000000000000000000 1000000000000000000", "output": "Impossible" }, { "input": "1000000000000000000 1", "output": "999999999999999999A" }, { "input": "2 1000000000000000000", "output": "Impossible" }, { "input": "999999999999999999 999999999999999998", "output": "1A999999999999999997B" }, { "input": "616274828435574301 10268395600356301", "output": "60A60B60A60B60A60B60A60B60A60B" }, { "input": "10808314049304201 270039182096201", "output": "40A40B40A40B40A40B40A40B40A40B" }, { "input": "1000100020001 100010001", "output": "10000A10000B10000A" }, { "input": "152139002499 367296043199", "output": "2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A" }, { "input": "25220791 839761", "output": "30A30B30A30B30A" }, { "input": "27961 931", "output": "30A30B30A" }, { "input": "127601 6382601", "output": "50B50A50B50A" }, { "input": "1 1000000000000000000", "output": "999999999999999999B" }, { "input": "242 100", "output": "Impossible" }, { "input": "507769900974602687 547261784951014891", "output": "Impossible" }, { "input": "585026192452577797 570146946822492493", "output": "1A38B3A7B23A2B1A1B1A8B2A1B5A117B2A1B1A2B12A3B10A5B3A2B3A11B2A1B7A" }, { "input": "568679881256193737 513570106829158157", "output": "1A9B3A7B2A3B1A1B1A2B3A2B1A3B2A82B1A7B2A14B2A1B1A4B5A3B2A1B9A1B2A1B4A1B3A1B3A2B" }, { "input": "567036128564717939 510505130335113937", "output": "1A9B32A1B2A1B368A1B1A1B2A4B1A1B23A14B21A5B1A1B2A4B1A1B3A1B1A1B3A1B5A1B1A9B" }, { "input": "519421744863260201 572972909476222789", "output": "1B9A1B2A3B21A1B1A21B2A1B2A12B1A4B1A1B5A160B4A1B1A138B1A1B9A4B3A2B6A" }, { "input": "529495319593227313 631186172547690847", "output": "1B5A4B1A4B1A76B3A2B11A3B7A5B1A1B2A2B7A2B2A8B5A3B143A1B3A8B1A5B1A" }, { "input": "540431588408227541 540431588408227541", "output": "Impossible" }, { "input": "410218934960967047 378596216455001869", "output": "Impossible" }, { "input": "395130552422107969 382562323268297483", "output": "Impossible" }, { "input": "416445288135075809 416445288135075809", "output": "Impossible" }, { "input": "402725448165665593 481342602240996343", "output": "1B5A8B6A2B2A1B20A3B9A5B2A1B4A5B2A4B1A268B9A4B1A1B4A3B2A2B1A2B1A1B3A" }, { "input": "412177780967225699 432177937877609093", "output": "1B20A1B1A1B1A3B1A58B1A4B1A13B206A2B2A5B5A22B3A45B1A7B5A1B1A6B1A1B" }, { "input": "423506197818989927 442863139846534733", "output": "1B21A1B7A4B76A1B3A2B82A1B18A4B1A13B1A3B6A1B1A2B1A22B1A3B2A1B1A2B27A" }, { "input": "453151988636162147 474019690903735841", "output": "1B21A1B2A1B1A16B1A1B1A4B300A1B4A1B11A47B1A6B8A1B1A1B1A2B2A5B3A2B1A7B1A5B1A" }, { "input": "408962762283480959 444443583457646111", "output": "1B11A1B1A9B253A1B5A22B6A1B11A4B3A2B1A1B4A1B13A2B4A1B50A1B6A1B5A3B" }, { "input": "976540997167958951 969335176443917693", "output": "1A134B1A1B11A3B26A2B3A1B1A2B22A1B3A3B1A1B66A63B36A2B1A13B5A3B" }, { "input": "957591654759084713 981022104435698593", "output": "1B40A1B6A1B1A1B68A1B18A2B3A1B2A2B2A1B1A4B1A3B2A1B12A3B604A5B1A1B39A1B1A" }, { "input": "962890278562476113 969978235623119279", "output": "1B135A1B5A1B1A1B1A2B1A1B3A4B2A1B2A2B1A5B3A1B2A2B2A1B2A1B3A2B67A1B1A6B3A1B14A1B3A19B" }, { "input": "963716517445592213 976351630941239591", "output": "1B76A3B1A1B1A52B1A6B2A7B35A1B1A2B17A5B5A4B5A9B3A2B13A1B2A3B1A7B" }, { "input": "964542760623675601 965233603018687501", "output": "1B1396A5B2A4B2A2B1A18B4A1B1A1B2A3B3A1B10A2B3A1B3A1B5A1B1A1B2A10B3A9B1A1B3A2B" }, { "input": "977367244641009653 977367244641009653", "output": "Impossible" } ]
62
0
3
35
80
Panoramix's Prediction
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", "output": "YES" }, { "input": "5 7", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "11 13", "output": "YES" }, { "input": "13 17", "output": "YES" }, { "input": "17 19", "output": "YES" }, { "input": "19 23", "output": "YES" }, { "input": "23 29", "output": "YES" }, { "input": "29 31", "output": "YES" }, { "input": "31 37", "output": "YES" }, { "input": "37 41", "output": "YES" }, { "input": "41 43", "output": "YES" }, { "input": "43 47", "output": "YES" }, { "input": "2 5", "output": "NO" }, { "input": "2 7", "output": "NO" }, { "input": "2 6", "output": "NO" }, { "input": "2 11", "output": "NO" }, { "input": "3 6", "output": "NO" }, { "input": "3 7", "output": "NO" }, { "input": "3 9", "output": "NO" }, { "input": "5 6", "output": "NO" }, { "input": "5 9", "output": "NO" }, { "input": "5 11", "output": "NO" }, { "input": "5 13", "output": "NO" }, { "input": "5 15", "output": "NO" }, { "input": "7 8", "output": "NO" }, { "input": "7 13", "output": "NO" }, { "input": "13 15", "output": "NO" }, { "input": "13 17", "output": "YES" }, { "input": "19 21", "output": "NO" }, { "input": "13 20", "output": "NO" }, { "input": "41 49", "output": "NO" }, { "input": "43 49", "output": "NO" }, { "input": "47 50", "output": "NO" }, { "input": "47 49", "output": "NO" }, { "input": "47 48", "output": "NO" }, { "input": "23 25", "output": "NO" }, { "input": "2 50", "output": "NO" }, { "input": "31 33", "output": "NO" } ]
218
6,963,200
3.93253
36
README.md exists but content is empty.
Downloads last month
8