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&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&White",
"#Black&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\nxxxXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXxXXxXXXxXX",
"output": "3\nXXXXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXxXXxXXXxXX"
},
{
"input": "200\nxxXXxxXXxXxxXxxXxXxxXxXxXxXxxxxxXXxXXxxXXXXxXXXxXXxXxXxxxxXxxXXXxxxXxXxxxXxxXXxXxXxxxxxxxXxxXxXxxXxXXXxxXxXXXXxxXxxxXxXXXXXXxXxXXxxxxXxxxXxxxXxXXXxXxXXXXxXXxxxXxXXxxXXxxxXxXxXXxXXXxXxXxxxXXxxxxXXxXXXX",
"output": "4\nXXXXXXXXxXxxXxxXxXxxXxXxXxXxxxxxXXxXXxxXXXXxXXXxXXxXxXxxxxXxxXXXxxxXxXxxxXxxXXxXxXxxxxxxxXxxXxXxxXxXXXxxXxXXXXxxXxxxXxXXXXXXxXxXXxxxxXxxxXxxxXxXXXxXxXXXXxXXxxxXxXXxxXXxxxXxXxXXxXXXxXxXxxxXXxxxxXXxXXXX"
},
{
"input": "198\nxXxxXxxXxxXXxXxXxXxxXXXxxXxxxxXXXXxxXxxxxXXXXxXxXXxxxXXXXXXXxXXXxxxxXXxXXxXxXXxxxxXxXXXXXXxXxxXxXxxxXxXXXXxxXXxxXxxxXXxXxXXxXxXXxXXXXxxxxxXxXXxxxXxXXXXxXxXXxxXxXXxXxXXxxxXxXXXXxXxxXxXXXxxxxXxXXXXxXx",
"output": "5\nxxxxxxxxxxxxxXxXxXxxXXXxxXxxxxXXXXxxXxxxxXXXXxXxXXxxxXXXXXXXxXXXxxxxXXxXXxXxXXxxxxXxXXXXXXxXxxXxXxxxXxXXXXxxXXxxXxxxXXxXxXXxXxXXxXXXXxxxxxXxXXxxxXxXXXXxXxXXxxXxXXxXxXXxxxXxXXXXxXxxXxXXXxxxxXxXXXXxXx"
},
{
"input": "200\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "100\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"input": "198\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "99\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"input": "200\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"output": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
{
"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*<=<<=*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*<=<<=*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* < *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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "100000",
"output": "50000\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 ..."
},
{
"input": "7",
"output": "3\n2 2 3"
},
{
"input": "4",
"output": "2\n2 2"
},
{
"input": "8",
"output": "4\n2 2 2 2"
},
{
"input": "9",
"output": "4\n2 2 2 3"
},
{
"input": "99995",
"output": "49997\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 ..."
},
{
"input": "99996",
"output": "49998\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 ..."
},
{
"input": "10",
"output": "5\n2 2 2 2 2"
},
{
"input": "11",
"output": "5\n2 2 2 2 3"
},
{
"input": "99997",
"output": "49998\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 ..."
},
{
"input": "99998",
"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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "12",
"output": "6\n2 2 2 2 2 2"
},
{
"input": "13",
"output": "6\n2 2 2 2 2 3"
},
{
"input": "99993",
"output": "49996\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 ..."
},
{
"input": "99994",
"output": "49997\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 ..."
},
{
"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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "530",
"output": "265\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": "7166",
"output": "3583\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": "9294",
"output": "4647\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": "2422",
"output": "1211\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": "15326",
"output": "7663\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": "11454",
"output": "5727\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": "14878",
"output": "7439\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": "90672",
"output": "45336\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 ..."
},
{
"input": "99544",
"output": "49772\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 ..."
},
{
"input": "90472",
"output": "45236\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 ..."
},
{
"input": "23",
"output": "11\n2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "93",
"output": "46\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 3"
},
{
"input": "19",
"output": "9\n2 2 2 2 2 2 2 2 3"
},
{
"input": "11110",
"output": "5555\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..."
}
] | 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*<=><=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*<=><=*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*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*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 |
864 | Make a Permutation! | [
"greedy",
"implementation",
"math"
] | null | null | Ivan has an array consisting of *n* elements. Each of the elements is an integer from 1 to *n*.
Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his array in such a way that his array becomes a permutation (i.e. each of the integers from 1 to *n* was encountered in his array exactly once). If there are multiple ways to do it he wants to find the lexicographically minimal permutation among them.
Thus minimizing the number of changes has the first priority, lexicographical minimizing has the second priority.
In order to determine which of the two permutations is lexicographically smaller, we compare their first elements. If they are equal — compare the second, and so on. If we have two permutations *x* and *y*, then *x* is lexicographically smaller if *x**i*<=<<=*y**i*, where *i* is the first index in which the permutations *x* and *y* differ.
Determine the array Ivan will obtain after performing all the changes. | The first line contains an single integer *n* (2<=≤<=*n*<=≤<=200<=000) — the number of elements in Ivan's array.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the description of Ivan's array. | In the first line print *q* — the minimum number of elements that need to be changed in Ivan's array in order to make his array a permutation. In the second line, print the lexicographically minimal permutation which can be obtained from array with *q* changes. | [
"4\n3 2 2 3\n",
"6\n4 5 6 3 2 1\n",
"10\n6 8 4 6 7 1 6 3 4 5\n"
] | [
"2\n1 2 4 3 \n",
"0\n4 5 6 3 2 1 \n",
"3\n2 8 4 6 7 1 9 3 10 5 \n"
] | In the first example Ivan needs to replace number three in position 1 with number one, and number two in position 3 with number four. Then he will get a permutation [1, 2, 4, 3] with only two changed numbers — this permutation is lexicographically minimal among all suitable.
In the second example Ivan does not need to change anything because his array already is a permutation. | [
{
"input": "4\n3 2 2 3",
"output": "2\n1 2 4 3 "
},
{
"input": "6\n4 5 6 3 2 1",
"output": "0\n4 5 6 3 2 1 "
},
{
"input": "10\n6 8 4 6 7 1 6 3 4 5",
"output": "3\n2 8 4 6 7 1 9 3 10 5 "
},
{
"input": "6\n5 5 5 6 4 6",
"output": "3\n1 2 5 3 4 6 "
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "49\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": "50\n1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "48\n1 3 2 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": "50\n2 4 1 2 3 7 2 2 1 1 3 4 2 12 4 3 2 1 2 5 1 3 3 7 9 6 10 5 7 1 4 3 6 2 3 12 1 3 2 6 2 2 2 4 1 6 1 3 7 13",
"output": "39\n2 4 1 8 3 7 11 14 15 16 17 18 19 12 20 21 22 23 24 5 25 26 27 28 9 6 10 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 13 "
},
{
"input": "50\n26 46 50 31 47 40 25 47 41 47 31 30 50 40 46 44 26 48 37 19 28 19 50 22 42 38 47 22 44 44 35 30 50 45 49 34 19 37 36 32 50 29 50 42 34 49 40 50 8 50",
"output": "25\n1 2 3 4 5 6 25 7 41 9 31 10 11 12 46 13 26 48 14 15 28 16 17 18 20 38 47 22 21 44 35 30 23 45 24 27 19 37 36 32 33 29 39 42 34 49 40 43 8 50 "
},
{
"input": "20\n15 18 20 6 19 13 20 17 20 16 19 17 17 19 16 12 14 19 20 20",
"output": "10\n15 18 1 6 2 13 3 4 5 7 8 9 17 10 16 12 14 19 11 20 "
},
{
"input": "50\n48 37 47 50 46 43 42 46 36 40 45 41 40 50 35 49 37 42 44 45 49 44 31 47 45 49 48 41 45 45 48 20 34 43 43 41 47 50 41 48 38 48 43 48 46 48 32 37 47 45",
"output": "31\n1 2 3 4 5 6 7 8 36 9 10 11 40 12 35 13 14 42 15 16 17 44 31 18 19 49 21 22 23 24 25 20 34 26 27 28 29 50 41 30 38 33 43 39 46 48 32 37 47 45 "
},
{
"input": "26\n26 26 23 25 22 26 26 24 26 26 25 18 25 22 24 24 24 24 24 26 26 25 24 26 26 23",
"output": "20\n1 2 3 4 5 6 7 8 9 10 11 18 12 22 13 14 15 16 17 19 20 25 24 21 26 23 "
},
{
"input": "50\n50 50 50 49 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 49 50 49 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 49",
"output": "48\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 50 49 "
},
{
"input": "50\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": "49\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": "50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "49\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": "50\n18 42 38 38 38 50 50 38 49 49 38 38 42 18 49 49 49 49 18 50 18 38 38 49 49 50 49 42 38 49 42 38 38 49 38 49 50 49 49 49 18 49 18 38 42 50 42 49 18 49",
"output": "45\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 18 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 39 40 41 43 44 45 38 42 50 46 47 48 49 "
},
{
"input": "50\n4 50 27 48 32 32 37 33 18 24 38 6 32 17 1 46 36 16 10 9 9 25 26 40 28 2 1 5 15 50 2 4 18 39 42 46 25 3 10 42 37 23 28 41 33 45 25 11 13 18",
"output": "17\n4 7 27 48 8 12 14 19 18 24 38 6 32 17 1 20 36 16 10 9 21 22 26 40 28 2 29 5 15 50 30 31 34 39 35 46 25 3 43 42 37 23 44 41 33 45 47 11 13 49 "
},
{
"input": "50\n39 49 43 21 22 27 28 41 35 6 31 9 4 39 27 27 7 41 9 28 43 37 20 47 28 37 8 46 23 14 50 48 21 47 9 31 9 37 34 17 15 17 18 16 29 6 43 33 16 17",
"output": "20\n1 49 2 3 22 5 10 11 35 6 12 9 4 39 13 27 7 41 19 24 25 26 20 30 28 32 8 46 23 14 50 48 21 47 36 31 38 37 34 17 15 40 18 16 29 42 43 33 44 45 "
},
{
"input": "2\n1 2",
"output": "0\n1 2 "
},
{
"input": "2\n2 1",
"output": "0\n2 1 "
},
{
"input": "2\n1 1",
"output": "1\n1 2 "
},
{
"input": "2\n2 2",
"output": "1\n1 2 "
},
{
"input": "3\n1 1 1",
"output": "2\n1 2 3 "
},
{
"input": "3\n2 2 2",
"output": "2\n1 2 3 "
},
{
"input": "3\n3 3 3",
"output": "2\n1 2 3 "
},
{
"input": "3\n1 2 2",
"output": "1\n1 2 3 "
},
{
"input": "3\n2 1 3",
"output": "0\n2 1 3 "
},
{
"input": "3\n3 2 1",
"output": "0\n3 2 1 "
},
{
"input": "3\n2 2 3",
"output": "1\n1 2 3 "
},
{
"input": "3\n3 1 3",
"output": "1\n2 1 3 "
},
{
"input": "3\n2 2 1",
"output": "1\n2 3 1 "
},
{
"input": "3\n3 1 2",
"output": "0\n3 1 2 "
}
] | 0 | 0 | -1 | 37 |
|
9 | Die Roll | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 92 | 409,600 | 0 | 38 |
554 | Kyoya and Photobooks | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?
Please help Haruhi solve this problem. | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"input": "xulsyfkuizjauadjjopu",
"output": "526"
},
{
"input": "e",
"output": "51"
},
{
"input": "zv",
"output": "76"
},
{
"input": "jgv",
"output": "101"
},
{
"input": "zsfo",
"output": "126"
},
{
"input": "jselr",
"output": "151"
},
{
"input": "dwemig",
"output": "176"
},
{
"input": "mddoxsf",
"output": "201"
},
{
"input": "jgirkrmi",
"output": "226"
},
{
"input": "spkxurcum",
"output": "251"
},
{
"input": "fykkiubdkt",
"output": "276"
},
{
"input": "fznbcxsxygs",
"output": "301"
},
{
"input": "qcrvrdqcbtou",
"output": "326"
},
{
"input": "qktrbjzrqgmlr",
"output": "351"
},
{
"input": "foamodbvptlxxg",
"output": "376"
},
{
"input": "ydzpjhsidipricw",
"output": "401"
},
{
"input": "lpfpndmjfvqejdgf",
"output": "426"
},
{
"input": "ofkvparuvjtggnmab",
"output": "451"
},
{
"input": "xxncfutrtxcwdzwbgs",
"output": "476"
},
{
"input": "zovhffccflkgqncsdte",
"output": "501"
},
{
"input": "cskgsxywlvfeicoueglr",
"output": "526"
},
{
"input": "gggggggggggggggggggg",
"output": "526"
},
{
"input": "qdqdddqddqqddqddqdqd",
"output": "526"
},
{
"input": "takttttaakaaktakttkt",
"output": "526"
},
{
"input": "coccoooogogcgocccmcg",
"output": "526"
},
{
"input": "kskkskkkssksssk",
"output": "401"
},
{
"input": "lllllllllllllll",
"output": "401"
}
] | 109 | 0 | 3 | 39 |
|
522 | Reposts | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.
Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.
We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user. | Print a single integer — the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe reposted PoLyCaRp\n"
] | [
"6\n",
"2\n",
"2\n"
] | none | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp",
"output": "2"
},
{
"input": "1\nSoMeStRaNgEgUe reposted PoLyCaRp",
"output": "2"
},
{
"input": "1\niuNtwVf reposted POlYcarP",
"output": "2"
},
{
"input": "10\ncs reposted poLYCaRp\nAFIkDrY7Of4V7Mq reposted CS\nsoBiwyN7KOvoFUfbhux reposted aFikDry7Of4v7MQ\nvb6LbwA reposted sObIWYN7KOvoFufBHUx\nDtWKIcVwIHgj4Rcv reposted vb6lbwa\nkt reposted DTwKicvwihgJ4rCV\n75K reposted kT\njKzyxx1 reposted 75K\nuoS reposted jkZyXX1\npZJskHTCIqE3YyZ5ME reposted uoS",
"output": "11"
},
{
"input": "10\nvxrUpCXvx8Isq reposted pOLYcaRP\nICb1 reposted vXRUpCxvX8ISq\nJFMt4b8jZE7iF2m8by7y2 reposted Icb1\nqkG6ZkMIf9QRrBFQU reposted ICb1\nnawsNfcR2palIMnmKZ reposted pOlYcaRP\nKksyH reposted jFMT4b8JzE7If2M8by7y2\nwJtWwQS5FvzN0h8CxrYyL reposted NawsNfcR2paLIMnmKz\nDpBcBPYAcTXEdhldI6tPl reposted NaWSnFCr2pALiMnmkZ\nlEnwTVnlwdQg2vaIRQry reposted kKSYh\nQUVFgwllaWO reposted Wjtwwqs5FVzN0H8cxRyyl",
"output": "6"
},
{
"input": "10\nkkuLGEiHv reposted POLYcArp\n3oX1AoUqyw1eR3nCADY9hLwd reposted kkuLGeIHV\nwf97dqq5bx1dPIchCoT reposted 3OX1AOuQYW1eR3ncAdY9hLwD\nWANr8h reposted Wf97dQQ5bx1dpIcHcoT\n3Fb736lkljZK2LtSbfL reposted wANR8h\n6nq9xLOn reposted 3fB736lKlJZk2LtSbFL\nWL reposted 3Fb736lKLjZk2LTSbfl\ndvxn4Xtc6SBcvKf1 reposted wF97DQq5bX1dPiChCOt\nMCcPLIMISqxDzrj reposted 6nQ9XLOn\nxsQL4Z2Iu reposted MCcpLiMiSqxdzrj",
"output": "9"
},
{
"input": "10\nsMA4 reposted pOLyCARP\nlq3 reposted pOlycARp\nEa16LSFTQxLJnE reposted polYcARp\nkvZVZhJwXcWsnC7NA1DV2WvS reposted polYCArp\nEYqqlrjRwddI reposted pOlyCArP\nsPqQCA67Y6PBBbcaV3EhooO reposted ea16LSFTqxLJne\njjPnneZdF6WLZ3v reposted Ea16LSFTqxLjNe\nWEoi6UpnfBUx79 reposted ea16LSFtqXljNe\nqi4yra reposted eYqqlRJrWDDI\ncw7E1UCSUD reposted eYqqLRJRwDdI",
"output": "3"
}
] | 62 | 6,758,400 | 3 | 40 |
|
938 | Buy a Ticket | [
"data structures",
"graphs",
"shortest paths"
] | null | null | Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well.
There are *n* cities in Berland. People can travel between cities using two-directional train routes; there are exactly *m* routes, *i*-th route can be used to go from city *v**i* to city *u**i* (and from *u**i* to *v**i*), and it costs *w**i* coins to use this route.
Each city will be visited by "Flayer", and the cost of the concert ticket in *i*-th city is *a**i* coins.
You have friends in every city of Berland, and they, knowing about your programming skills, asked you to calculate the minimum possible number of coins they have to pay to visit the concert. For every city *i* you have to compute the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*).
Formally, for every you have to calculate , where *d*(*i*,<=*j*) is the minimum number of coins you have to spend to travel from city *i* to city *j*. If there is no way to reach city *j* from city *i*, then we consider *d*(*i*,<=*j*) to be infinitely large. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=2·105, 1<=≤<=*m*<=≤<=2·105).
Then *m* lines follow, *i*-th contains three integers *v**i*, *u**i* and *w**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*,<=*v**i*<=≠<=*u**i*, 1<=≤<=*w**i*<=≤<=1012) denoting *i*-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each (*v*,<=*u*) neither extra (*v*,<=*u*) nor (*u*,<=*v*) present in input.
The next line contains *n* integers *a*1,<=*a*2,<=... *a**k* (1<=≤<=*a**i*<=≤<=1012) — price to attend the concert in *i*-th city. | Print *n* integers. *i*-th of them must be equal to the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*). | [
"4 2\n1 2 4\n2 3 7\n6 20 1 25\n",
"3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20\n"
] | [
"6 14 1 25 \n",
"12 10 12 \n"
] | none | [
{
"input": "4 2\n1 2 4\n2 3 7\n6 20 1 25",
"output": "6 14 1 25 "
},
{
"input": "3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20",
"output": "12 10 12 "
},
{
"input": "7 7\n1 6 745325\n2 3 3581176\n2 4 19\n3 6 71263060078\n5 4 141198\n7 4 163953\n5 6 15994\n1 297404206755 82096176217 14663411 187389745 21385 704393",
"output": "1 335807 7498159 335769 53373 21385 663675 "
}
] | 77 | 512,000 | 0 | 41 |
|
573 | Bear and Blocks | [
"binary search",
"data structures",
"dp",
"math"
] | null | null | Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sample.
Limak will repeat the following operation till everything is destroyed.
Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.
Limak is ready to start. You task is to count how many operations will it take him to destroy all towers. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109) — sizes of towers. | Print the number of operations needed to destroy all towers. | [
"6\n2 1 4 6 2 2\n",
"7\n3 3 3 1 3 3 3\n"
] | [
"3\n",
"2\n"
] | The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color. | [
{
"input": "6\n2 1 4 6 2 2",
"output": "3"
},
{
"input": "7\n3 3 3 1 3 3 3",
"output": "2"
},
{
"input": "7\n5128 5672 5805 5452 5882 5567 5032",
"output": "4"
},
{
"input": "10\n1 2 2 3 5 5 5 4 2 1",
"output": "5"
},
{
"input": "14\n20 20 20 20 20 20 3 20 20 20 20 20 20 20",
"output": "5"
},
{
"input": "50\n3 2 4 3 5 3 4 5 3 2 3 3 3 4 5 4 2 2 3 3 4 4 3 2 3 3 2 3 4 4 5 2 5 2 3 5 4 4 2 2 3 5 2 5 2 2 5 4 5 4",
"output": "4"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n1049 1098",
"output": "1"
},
{
"input": "2\n100 100",
"output": "1"
},
{
"input": "5\n1 2 3 2 1",
"output": "3"
},
{
"input": "15\n2 2 1 1 2 2 2 2 2 2 2 2 2 1 2",
"output": "2"
},
{
"input": "28\n415546599 415546599 415546599 415546599 415546599 415546599 415546599 415546599 415546599 2 802811737 802811737 802811737 802811737 802811737 802811737 802811737 802811737 1 550595901 550595901 550595901 550595901 550595901 550595901 550595901 550595901 550595901",
"output": "6"
},
{
"input": "45\n3 12 13 11 13 13 10 11 14 15 15 13 14 12 13 11 14 10 10 14 14 11 10 12 11 11 13 14 10 11 14 13 14 11 11 11 12 15 1 10 15 12 14 14 14",
"output": "13"
},
{
"input": "84\n1 3 4 5 6 5 6 7 8 9 7 4 5 4 2 5 1 1 1 3 2 7 7 8 10 9 5 6 5 2 3 3 3 3 3 2 4 8 6 5 8 9 8 7 9 3 4 4 4 2 2 1 6 4 9 5 9 9 10 7 10 4 5 4 2 4 3 3 4 4 6 6 6 9 10 12 7 5 9 8 5 3 3 2",
"output": "8"
},
{
"input": "170\n1 2 1 2 1 1 1 1 2 3 2 1 1 2 2 1 2 1 2 1 1 2 3 3 2 1 1 1 1 1 1 1 1 2 1 2 3 3 2 1 2 2 1 2 3 2 1 1 2 3 2 1 2 1 1 1 2 3 3 2 1 2 1 2 1 1 1 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 2 2 1 2 1 2 3 2 1 1 2 3 4 4 3 2 1 2 1 2 1 2 3 3 2 1 2 1 1 1 1 1 1 1 2 2 1 1 2 1 1 1 1 2 1 1 2 3 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 3 2 1 2 1 1 1 2 3 4 5 4 3 2 1 1 2 1 2 3 4 3 2 1",
"output": "5"
},
{
"input": "1\n5",
"output": "1"
}
] | 78 | 13,312,000 | 0 | 42 |
|
25 | IQ test | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 218 | 0 | 0 | 43 |
1,008 | Romaji | [
"implementation",
"strings"
] | null | null | Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.
Help Vitya find out if a word $s$ is Berlanese. | The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. | Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"sumimasen\n",
"ninja\n",
"codeforces\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | [
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"input": "n",
"output": "YES"
},
{
"input": "necnei",
"output": "NO"
},
{
"input": "nternn",
"output": "NO"
},
{
"input": "aucunuohja",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"input": "b",
"output": "NO"
},
{
"input": "nn",
"output": "YES"
},
{
"input": "nnnzaaa",
"output": "YES"
},
{
"input": "zn",
"output": "NO"
},
{
"input": "ab",
"output": "NO"
},
{
"input": "aaaaaaaaaa",
"output": "YES"
},
{
"input": "aaaaaaaaab",
"output": "NO"
},
{
"input": "aaaaaaaaan",
"output": "YES"
},
{
"input": "baaaaaaaaa",
"output": "YES"
},
{
"input": "naaaaaaaaa",
"output": "YES"
},
{
"input": "nbaaaaaaaa",
"output": "YES"
},
{
"input": "bbaaaaaaaa",
"output": "NO"
},
{
"input": "bnaaaaaaaa",
"output": "NO"
},
{
"input": "eonwonojannonnufimiiniewuqaienokacevecinfuqihatenhunliquuyebayiaenifuexuanenuaounnboancaeowonu",
"output": "YES"
},
{
"input": "uixinnepnlinqaingieianndeakuniooudidonnnqeaituioeneiroionxuowudiooonayenfeonuino",
"output": "NO"
},
{
"input": "nnnnnyigaveteononnnnxaalenxuiiwannntoxonyoqonlejuoxuoconnnentoinnul",
"output": "NO"
},
{
"input": "ndonneasoiunhomuunnhuitonnntunntoanerekonoupunanuauenu",
"output": "YES"
},
{
"input": "anujemogawautiedoneobninnibonuunaoennnyoorufonxionntinimiboonununnnnnleenqunminzayoutanlalo",
"output": "NO"
},
{
"input": "y",
"output": "NO"
},
{
"input": "by",
"output": "NO"
},
{
"input": "yy",
"output": "NO"
},
{
"input": "nbn",
"output": "NO"
},
{
"input": "nz",
"output": "NO"
},
{
"input": "king",
"output": "NO"
},
{
"input": "g",
"output": "NO"
},
{
"input": "az",
"output": "NO"
},
{
"input": "x",
"output": "NO"
},
{
"input": "z",
"output": "NO"
},
{
"input": "yn",
"output": "NO"
},
{
"input": "aeo",
"output": "YES"
},
{
"input": "nb",
"output": "NO"
},
{
"input": "npn",
"output": "NO"
},
{
"input": "kini",
"output": "YES"
},
{
"input": "pya",
"output": "NO"
},
{
"input": "m",
"output": "NO"
},
{
"input": "p",
"output": "NO"
},
{
"input": "aaaaaaaak",
"output": "NO"
},
{
"input": "aab",
"output": "NO"
},
{
"input": "d",
"output": "NO"
},
{
"input": "at",
"output": "NO"
},
{
"input": "aaaaaak",
"output": "NO"
},
{
"input": "aaz",
"output": "NO"
},
{
"input": "aaab",
"output": "NO"
},
{
"input": "s",
"output": "NO"
},
{
"input": "nzzen",
"output": "NO"
},
{
"input": "aeionnhhhn",
"output": "NO"
},
{
"input": "h",
"output": "NO"
},
{
"input": "ny",
"output": "NO"
}
] | 77 | 0 | 0 | 44 |
|
597 | Restaurant | [
"dp",
"greedy",
"sortings"
] | null | null | A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**i* (*l**i*<=≤<=*r**i*).
Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?
No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both. | The first line contains integer number *n* (1<=≤<=*n*<=≤<=5·105) — number of orders. The following *n* lines contain integer values *l**i* and *r**i* each (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109). | Print the maximal number of orders that can be accepted. | [
"2\n7 11\n4 7\n",
"5\n1 2\n2 3\n3 4\n4 5\n5 6\n",
"6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8\n"
] | [
"1\n",
"3\n",
"2\n"
] | none | [
{
"input": "2\n7 11\n4 7",
"output": "1"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5\n5 6",
"output": "3"
},
{
"input": "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8",
"output": "2"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "2\n4 6\n4 8",
"output": "1"
},
{
"input": "3\n22 22\n14 21\n9 25",
"output": "2"
},
{
"input": "4\n20 59\n30 62\n29 45\n29 32",
"output": "1"
},
{
"input": "5\n40 124\n40 117\n67 106\n36 121\n38 102",
"output": "1"
},
{
"input": "6\n124 155\n50 93\n45 120\n54 171\n46 190\n76 179",
"output": "2"
},
{
"input": "7\n94 113\n54 248\n64 325\n280 306\n62 328\n49 341\n90 324",
"output": "2"
},
{
"input": "8\n116 416\n104 472\n84 476\n100 486\n199 329\n169 444\n171 487\n134 441",
"output": "1"
},
{
"input": "9\n90 667\n366 539\n155 462\n266 458\n323 574\n101 298\n90 135\n641 661\n122 472",
"output": "3"
},
{
"input": "10\n195 443\n229 602\n200 948\n229 876\n228 904\n296 656\n189 818\n611 626\n215 714\n403 937",
"output": "2"
},
{
"input": "1\n28 74",
"output": "1"
},
{
"input": "2\n28 92\n2 59",
"output": "1"
},
{
"input": "3\n5 92\n1 100\n39 91",
"output": "1"
},
{
"input": "4\n4 92\n29 43\n13 73\n10 79",
"output": "1"
},
{
"input": "5\n64 86\n61 61\n46 54\n83 94\n19 46",
"output": "3"
},
{
"input": "6\n80 84\n21 24\n44 80\n14 53\n5 10\n61 74",
"output": "4"
},
{
"input": "7\n32 92\n32 86\n13 25\n45 75\n16 65\n1 99\n17 98",
"output": "2"
},
{
"input": "8\n3 59\n22 94\n26 97\n18 85\n7 84\n1 100\n4 100\n26 93",
"output": "1"
},
{
"input": "9\n11 90\n8 95\n62 95\n43 96\n16 84\n3 70\n23 93\n4 96\n11 86",
"output": "1"
},
{
"input": "10\n30 45\n5 8\n51 83\n37 52\n49 75\n28 92\n94 99\n4 13\n61 83\n36 96",
"output": "4"
},
{
"input": "11\n38 92\n16 85\n32 43\n65 84\n63 100\n21 45\n13 92\n29 58\n56 94\n18 83\n50 81",
"output": "2"
},
{
"input": "12\n66 78\n41 97\n55 69\n55 61\n36 64\n14 97\n96 99\n28 58\n44 93\n2 100\n42 88\n1 2",
"output": "4"
},
{
"input": "13\n50 85\n38 65\n5 51\n50 96\n4 92\n23 94\n2 99\n2 84\n1 98\n2 100\n12 100\n21 97\n7 84",
"output": "1"
},
{
"input": "14\n17 92\n7 96\n49 96\n10 99\n7 98\n12 85\n10 52\n2 99\n23 75\n4 98\n7 100\n2 69\n6 99\n20 87",
"output": "1"
},
{
"input": "15\n1 58\n15 21\n53 55\n59 90\n68 71\n29 51\n52 81\n32 52\n38 44\n57 59\n47 60\n27 32\n49 86\n26 94\n44 45",
"output": "6"
},
{
"input": "16\n4 80\n16 46\n15 16\n60 63\n8 54\n18 49\n67 99\n72 80\n1 8\n19 64\n1 54\n46 94\n2 89\n67 78\n21 47\n5 29",
"output": "5"
},
{
"input": "17\n34 42\n31 84\n8 96\n63 88\n11 99\n80 99\n1 96\n11 12\n27 28\n4 30\n1 79\n16 86\n15 86\n13 80\n3 98\n37 89\n59 88",
"output": "4"
},
{
"input": "18\n11 94\n12 85\n25 90\n7 61\n63 88\n6 87\n49 88\n16 76\n12 78\n61 84\n3 84\n20 91\n1 84\n17 100\n43 80\n8 86\n9 98\n35 97",
"output": "2"
},
{
"input": "19\n24 63\n23 86\n5 89\n10 83\n31 92\n8 96\n21 63\n1 83\n2 100\n5 96\n18 98\n9 77\n11 91\n44 95\n1 98\n22 60\n5 98\n22 91\n1 96",
"output": "1"
},
{
"input": "20\n22 77\n13 50\n55 64\n16 52\n67 96\n49 51\n59 95\n2 25\n69 91\n2 24\n4 46\n50 74\n45 63\n39 55\n31 33\n9 33\n6 72\n14 67\n56 98\n69 94",
"output": "5"
},
{
"input": "1\n1 1000000000",
"output": "1"
},
{
"input": "4\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000",
"output": "1"
},
{
"input": "2\n1000000000 1000000000\n1 1",
"output": "2"
},
{
"input": "4\n1 10000\n2 3\n4 5\n6 7",
"output": "3"
},
{
"input": "3\n1 10\n2 4\n6 8",
"output": "2"
},
{
"input": "2\n1 4\n2 3",
"output": "1"
},
{
"input": "3\n1 100\n2 3\n4 5",
"output": "2"
},
{
"input": "4\n1 10\n2 3\n4 5\n6 7",
"output": "3"
},
{
"input": "3\n1 5\n2 3\n4 4",
"output": "2"
},
{
"input": "3\n1 1000\n1 5\n6 1000",
"output": "2"
},
{
"input": "3\n1 10000\n3 5\n7 8",
"output": "2"
},
{
"input": "4\n1 5\n6 15\n8 10\n11 17",
"output": "3"
},
{
"input": "4\n1 3\n6 800\n7 9\n10 11",
"output": "3"
},
{
"input": "5\n1 10\n2 3\n4 5\n6 7\n8 9",
"output": "4"
},
{
"input": "3\n1 5\n1 3\n4 6",
"output": "2"
},
{
"input": "3\n1 10\n2 3\n4 5",
"output": "2"
},
{
"input": "2\n1 3\n2 4",
"output": "1"
}
] | 78 | 0 | -1 | 45 |
|
82 | Double Cola | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the *n*-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"input": "4",
"output": "Rajesh"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "10",
"output": "Penny"
},
{
"input": "534",
"output": "Rajesh"
},
{
"input": "5033",
"output": "Howard"
},
{
"input": "10010",
"output": "Howard"
},
{
"input": "500000000",
"output": "Penny"
},
{
"input": "63",
"output": "Rajesh"
},
{
"input": "841",
"output": "Leonard"
},
{
"input": "3667",
"output": "Penny"
},
{
"input": "38614",
"output": "Howard"
},
{
"input": "282798",
"output": "Rajesh"
},
{
"input": "9266286",
"output": "Rajesh"
},
{
"input": "27385966",
"output": "Leonard"
},
{
"input": "121580142",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "300",
"output": "Howard"
},
{
"input": "1745",
"output": "Leonard"
},
{
"input": "8302",
"output": "Rajesh"
},
{
"input": "184518",
"output": "Sheldon"
},
{
"input": "1154414",
"output": "Rajesh"
},
{
"input": "28643950",
"output": "Leonard"
},
{
"input": "159222638",
"output": "Howard"
},
{
"input": "24",
"output": "Penny"
},
{
"input": "505",
"output": "Penny"
},
{
"input": "4425",
"output": "Rajesh"
},
{
"input": "12079",
"output": "Sheldon"
},
{
"input": "469726",
"output": "Penny"
},
{
"input": "3961838",
"output": "Penny"
},
{
"input": "57710446",
"output": "Leonard"
},
{
"input": "80719470",
"output": "Howard"
},
{
"input": "1000000000",
"output": "Penny"
},
{
"input": "999999999",
"output": "Penny"
},
{
"input": "999999998",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
}
] | 109 | 0 | 0 | 46 |
0 | none | [
"none"
] | null | null | You are given a string *S* of length *n* with each character being one of the first *m* lowercase English letters.
Calculate how many different strings *T* of length *n* composed from the first *m* lowercase English letters exist such that the length of LCS (longest common subsequence) between *S* and *T* is *n*<=-<=1.
Recall that LCS of two strings *S* and *T* is the longest string *C* such that *C* both in *S* and *T* as a subsequence. | The first line contains two numbers *n* and *m* denoting the length of string *S* and number of first English lowercase characters forming the character set for strings (1<=≤<=*n*<=≤<=100<=000, 2<=≤<=*m*<=≤<=26).
The second line contains string *S*. | Print the only line containing the answer. | [
"3 3\naaa\n",
"3 3\naab\n",
"1 2\na\n",
"10 9\nabacadefgh\n"
] | [
"6\n",
"11\n",
"1\n",
"789\n"
] | For the first sample, the 6 possible strings *T* are: aab, aac, aba, aca, baa, caa.
For the second sample, the 11 possible strings *T* are: aaa, aac, aba, abb, abc, aca, acb, baa, bab, caa, cab.
For the third sample, the only possible string *T* is b. | [
{
"input": "3 3\naaa",
"output": "6"
},
{
"input": "3 3\naab",
"output": "11"
},
{
"input": "1 2\na",
"output": "1"
},
{
"input": "10 9\nabacadefgh",
"output": "789"
},
{
"input": "15 3\nabababababababa",
"output": "345"
},
{
"input": "100 26\njysrixyptvsesnapfljeqkytlpeepjopspmkviqdqbdkylvfiawhdjjdvqqvcjmmsgfdmpjwahuwhgsyfcgnefzmqlvtvqqfbfsf",
"output": "237400"
},
{
"input": "1 26\nz",
"output": "25"
}
] | 46 | 0 | 0 | 47 |
|
577 | Multiplication Table | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*. | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 1000000000",
"output": "0"
},
{
"input": "100000 1000000000",
"output": "16"
},
{
"input": "100000 362880",
"output": "154"
},
{
"input": "1 4",
"output": "0"
},
{
"input": "9 12",
"output": "4"
},
{
"input": "10 123",
"output": "0"
},
{
"input": "9551 975275379",
"output": "0"
},
{
"input": "17286 948615687",
"output": "0"
},
{
"input": "58942 936593001",
"output": "0"
},
{
"input": "50000 989460910",
"output": "4"
},
{
"input": "22741 989460910",
"output": "0"
},
{
"input": "22740 989460910",
"output": "0"
},
{
"input": "100000 989460910",
"output": "4"
},
{
"input": "100000 98280",
"output": "128"
},
{
"input": "100000 997920",
"output": "222"
},
{
"input": "100000 720720",
"output": "226"
},
{
"input": "100000 2162160",
"output": "282"
},
{
"input": "100000 4324320",
"output": "320"
},
{
"input": "100000 8648640",
"output": "348"
},
{
"input": "100000 183783600",
"output": "438"
},
{
"input": "100000 551350800",
"output": "392"
},
{
"input": "40000 551350800",
"output": "150"
},
{
"input": "20000 400000000",
"output": "1"
},
{
"input": "19999 400000000",
"output": "0"
},
{
"input": "19999 399960001",
"output": "1"
},
{
"input": "31621 999887641",
"output": "1"
},
{
"input": "31622 999887641",
"output": "1"
},
{
"input": "31620 999887641",
"output": "0"
},
{
"input": "100000 999887641",
"output": "3"
},
{
"input": "100000 25",
"output": "3"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "100000 3628800",
"output": "220"
},
{
"input": "100000 39916800",
"output": "328"
},
{
"input": "100000 479001600",
"output": "254"
},
{
"input": "4 9",
"output": "1"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "20 100",
"output": "3"
},
{
"input": "10 3",
"output": "2"
},
{
"input": "4 4",
"output": "3"
},
{
"input": "2 4",
"output": "1"
},
{
"input": "89874 1",
"output": "1"
}
] | 514 | 268,390,400 | 0 | 48 |
|
69 | Young Physicist | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 60 | 0 | 0 | 49 |
236 | Boy or Girl | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},
{
"input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn",
"output": "IGNORE HIM!"
},
{
"input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx",
"output": "CHAT WITH HER!"
},
{
"input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt",
"output": "IGNORE HIM!"
},
{
"input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk",
"output": "IGNORE HIM!"
},
{
"input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz",
"output": "IGNORE HIM!"
},
{
"input": "tgcdptnkc",
"output": "IGNORE HIM!"
},
{
"input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi",
"output": "IGNORE HIM!"
},
{
"input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp",
"output": "IGNORE HIM!"
},
{
"input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia",
"output": "IGNORE HIM!"
},
{
"input": "fpellxwskyekoyvrfnuf",
"output": "CHAT WITH HER!"
},
{
"input": "xninyvkuvakfbs",
"output": "IGNORE HIM!"
},
{
"input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak",
"output": "CHAT WITH HER!"
},
{
"input": "kmsk",
"output": "IGNORE HIM!"
},
{
"input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz",
"output": "CHAT WITH HER!"
},
{
"input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq",
"output": "CHAT WITH HER!"
},
{
"input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm",
"output": "IGNORE HIM!"
},
{
"input": "ppcpbnhwoizajrl",
"output": "IGNORE HIM!"
},
{
"input": "sgubujztzwkzvztitssxxxwzanfmddfqvv",
"output": "CHAT WITH HER!"
},
{
"input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw",
"output": "IGNORE HIM!"
},
{
"input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu",
"output": "CHAT WITH HER!"
},
{
"input": "ojjvpnkrxibyevxk",
"output": "CHAT WITH HER!"
},
{
"input": "wjweqcrqfuollfvfbiyriijovweg",
"output": "IGNORE HIM!"
},
{
"input": "hkdbykboclchfdsuovvpknwqr",
"output": "IGNORE HIM!"
},
{
"input": "stjvyfrfowopwfjdveduedqylerqugykyu",
"output": "IGNORE HIM!"
},
{
"input": "rafcaanqytfclvfdegak",
"output": "CHAT WITH HER!"
},
{
"input": "xczn",
"output": "CHAT WITH HER!"
},
{
"input": "arcoaeozyeawbveoxpmafxxzdjldsielp",
"output": "IGNORE HIM!"
},
{
"input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika",
"output": "CHAT WITH HER!"
},
{
"input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh",
"output": "CHAT WITH HER!"
},
{
"input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg",
"output": "CHAT WITH HER!"
},
{
"input": "udlpagtpq",
"output": "CHAT WITH HER!"
},
{
"input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy",
"output": "CHAT WITH HER!"
},
{
"input": "qagzrqjomdwhagkhrjahhxkieijyten",
"output": "CHAT WITH HER!"
},
{
"input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb",
"output": "CHAT WITH HER!"
},
{
"input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr",
"output": "CHAT WITH HER!"
},
{
"input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc",
"output": "IGNORE HIM!"
},
{
"input": "lnpdosnceumubvk",
"output": "IGNORE HIM!"
},
{
"input": "efrk",
"output": "CHAT WITH HER!"
},
{
"input": "temnownneghnrujforif",
"output": "IGNORE HIM!"
},
{
"input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta",
"output": "IGNORE HIM!"
},
{
"input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh",
"output": "IGNORE HIM!"
},
{
"input": "gwntwbpj",
"output": "IGNORE HIM!"
},
{
"input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim",
"output": "IGNORE HIM!"
},
{
"input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd",
"output": "CHAT WITH HER!"
},
{
"input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx",
"output": "IGNORE HIM!"
},
{
"input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks",
"output": "CHAT WITH HER!"
},
{
"input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx",
"output": "CHAT WITH HER!"
},
{
"input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc",
"output": "CHAT WITH HER!"
},
{
"input": "yzlzmesxdttfcztooypjztlgxwcr",
"output": "IGNORE HIM!"
},
{
"input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc",
"output": "IGNORE HIM!"
},
{
"input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq",
"output": "CHAT WITH HER!"
},
{
"input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj",
"output": "IGNORE HIM!"
},
{
"input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom",
"output": "CHAT WITH HER!"
},
{
"input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo",
"output": "CHAT WITH HER!"
},
{
"input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh",
"output": "IGNORE HIM!"
},
{
"input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa",
"output": "CHAT WITH HER!"
},
{
"input": "oh",
"output": "CHAT WITH HER!"
},
{
"input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri",
"output": "IGNORE HIM!"
},
{
"input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp",
"output": "CHAT WITH HER!"
},
{
"input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp",
"output": "CHAT WITH HER!"
},
{
"input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo",
"output": "CHAT WITH HER!"
},
{
"input": "mnmbupgo",
"output": "IGNORE HIM!"
},
{
"input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl",
"output": "IGNORE HIM!"
},
{
"input": "yocxrzspinchmhtmqo",
"output": "CHAT WITH HER!"
},
{
"input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv",
"output": "CHAT WITH HER!"
},
{
"input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad",
"output": "IGNORE HIM!"
},
{
"input": "ubvhyaebyxoghakajqrpqpctwbrfqzli",
"output": "CHAT WITH HER!"
},
{
"input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy",
"output": "IGNORE HIM!"
},
{
"input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd",
"output": "IGNORE HIM!"
},
{
"input": "acrzbavz",
"output": "CHAT WITH HER!"
},
{
"input": "drvzznznvrzskftnrhvvzxcalwutxmdza",
"output": "IGNORE HIM!"
},
{
"input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws",
"output": "CHAT WITH HER!"
},
{
"input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff",
"output": "CHAT WITH HER!"
},
{
"input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu",
"output": "CHAT WITH HER!"
},
{
"input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw",
"output": "IGNORE HIM!"
},
{
"input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy",
"output": "CHAT WITH HER!"
},
{
"input": "rhh",
"output": "CHAT WITH HER!"
},
{
"input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo",
"output": "IGNORE HIM!"
},
{
"input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn",
"output": "CHAT WITH HER!"
},
{
"input": "urigreuzpxnej",
"output": "CHAT WITH HER!"
}
] | 124 | 0 | 0 | 50 |
|
427 | Police Recruits | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time. | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5",
"output": "5"
},
{
"input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -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": "13"
},
{
"input": "3\n-1 5 4",
"output": "1"
},
{
"input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1",
"output": "5"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n1 -1",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n-1 -1",
"output": "2"
},
{
"input": "4\n10 -1 -1 -1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "4\n-1 -1 1 1",
"output": "2"
}
] | 62 | 9,318,400 | 3 | 51 |
|
405 | Gravity Flip | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch! | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20 1 80",
"output": "1 20 40 60 80 100 "
},
{
"input": "10\n10 8 6 7 5 3 4 2 9 1",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91",
"output": "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100 "
},
{
"input": "100\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 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 "
},
{
"input": "10\n1 9 7 6 2 4 7 8 1 3",
"output": "1 1 2 3 4 6 7 7 8 9 "
},
{
"input": "20\n53 32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59",
"output": "20 20 22 30 32 41 50 53 54 59 60 61 64 66 68 72 74 80 97 97 "
},
{
"input": "30\n7 17 4 18 16 12 14 10 1 13 2 16 13 17 8 16 13 14 9 17 17 5 13 5 1 7 6 20 18 12",
"output": "1 1 2 4 5 5 6 7 7 8 9 10 12 12 13 13 13 13 14 14 16 16 16 17 17 17 17 18 18 20 "
},
{
"input": "40\n22 58 68 58 48 53 52 1 16 78 75 17 63 15 36 32 78 75 49 14 42 46 66 54 49 82 40 43 46 55 12 73 5 45 61 60 1 11 31 84",
"output": "1 1 5 11 12 14 15 16 17 22 31 32 36 40 42 43 45 46 46 48 49 49 52 53 54 55 58 58 60 61 63 66 68 73 75 75 78 78 82 84 "
},
{
"input": "70\n1 3 3 1 3 3 1 1 1 3 3 2 3 3 1 1 1 2 3 1 3 2 3 3 3 2 2 3 1 3 3 2 1 1 2 1 2 1 2 2 1 1 1 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3 3 3 1 1 3 3 1 1 1 1 3 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52",
"output": "2 3 4 5 5 5 6 6 6 7 7 7 7 10 10 11 11 15 16 17 17 17 18 19 19 20 21 21 21 23 24 24 27 27 30 34 40 43 43 44 46 46 48 48 49 49 50 51 51 51 52 52 53 55 55 58 63 64 65 66 66 66 67 71 71 73 75 75 76 76 77 79 82 85 85 88 88 90 91 91 92 93 95 95 95 96 98 99 100 100 "
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "100\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6",
"output": "1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 "
},
{
"input": "100\n12 10 5 11 13 12 14 13 7 15 15 12 13 19 12 18 14 10 10 3 1 10 16 11 19 8 10 15 5 10 12 16 11 13 11 15 14 12 16 8 11 8 15 2 18 2 14 13 15 20 8 8 4 12 14 7 10 3 9 1 7 19 6 7 2 14 8 20 7 17 18 20 3 18 18 9 6 10 4 1 4 19 9 13 3 3 12 11 11 20 8 2 13 6 7 12 1 4 17 3",
"output": "1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 "
},
{
"input": "100\n5 13 1 40 30 10 23 32 33 12 6 4 15 29 31 17 23 5 36 31 32 38 24 11 34 39 19 21 6 19 31 35 1 15 6 29 22 15 17 15 1 17 2 34 20 8 27 2 29 26 13 9 22 27 27 3 20 40 4 40 33 29 36 30 35 16 19 28 26 11 36 24 29 5 40 10 38 34 33 23 34 39 31 7 10 31 22 6 36 24 14 31 34 23 2 4 26 16 2 32",
"output": "1 1 1 2 2 2 2 3 4 4 4 5 5 5 6 6 6 6 7 8 9 10 10 10 11 11 12 13 13 14 15 15 15 15 16 16 17 17 17 19 19 19 20 20 21 22 22 22 23 23 23 23 24 24 24 26 26 26 27 27 27 28 29 29 29 29 29 30 30 31 31 31 31 31 31 32 32 32 33 33 33 34 34 34 34 34 35 35 36 36 36 36 38 38 39 39 40 40 40 40 "
},
{
"input": "100\n72 44 34 74 9 60 26 37 55 77 74 69 28 66 54 55 8 36 57 31 31 48 32 66 40 70 77 43 64 28 37 10 21 58 51 32 60 28 51 52 28 35 7 33 1 68 38 70 57 71 8 20 42 57 59 4 58 10 17 47 22 48 16 3 76 67 32 37 64 47 33 41 75 69 2 76 39 9 27 75 20 21 52 25 71 21 11 29 38 10 3 1 45 55 63 36 27 7 59 41",
"output": "1 1 2 3 3 4 7 7 8 8 9 9 10 10 10 11 16 17 20 20 21 21 21 22 25 26 27 27 28 28 28 28 29 31 31 32 32 32 33 33 34 35 36 36 37 37 37 38 38 39 40 41 41 42 43 44 45 47 47 48 48 51 51 52 52 54 55 55 55 57 57 57 58 58 59 59 60 60 63 64 64 66 66 67 68 69 69 70 70 71 71 72 74 74 75 75 76 76 77 77 "
},
{
"input": "100\n75 18 61 10 56 53 42 57 79 80 31 2 50 45 54 99 84 52 71 21 86 3 19 98 14 37 40 62 63 68 5 10 87 8 81 85 52 52 57 94 2 7 56 96 19 76 1 13 81 6 80 47 22 59 99 32 9 5 36 88 98 91 70 70 12 93 12 22 85 1 97 48 94 16 84 84 51 34 62 7 68 51 30 2 37 82 4 7 27 1 80 9 61 16 59 55 12 96 94 82",
"output": "1 1 1 2 2 2 3 4 5 5 6 7 7 7 8 9 9 10 10 12 12 12 13 14 16 16 18 19 19 21 22 22 27 30 31 32 34 36 37 37 40 42 45 47 48 50 51 51 52 52 52 53 54 55 56 56 57 57 59 59 61 61 62 62 63 68 68 70 70 71 75 76 79 80 80 80 81 81 82 82 84 84 84 85 85 86 87 88 91 93 94 94 94 96 96 97 98 98 99 99 "
},
{
"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": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"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": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100\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 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 50",
"output": "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 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 50 50 "
},
{
"input": "49\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 "
},
{
"input": "30\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88",
"output": "1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 "
},
{
"input": "100\n100 51 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 51 100 "
},
{
"input": "10\n100 90 80 70 60 50 40 30 20 10",
"output": "10 20 30 40 50 60 70 80 90 100 "
},
{
"input": "1\n10",
"output": "10 "
}
] | 15 | 0 | 0 | 52 |
|
777 | Alyona and Spreadsheet | [
"binary search",
"data structures",
"dp",
"greedy",
"implementation",
"two pointers"
] | null | null | During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the table is sorted in non-decreasing order in the column *j* if *a**i*,<=*j*<=≤<=*a**i*<=+<=1,<=*j* for all *i* from 1 to *n*<=-<=1.
Teacher gave Alyona *k* tasks. For each of the tasks two integers *l* and *r* are given and Alyona has to answer the following question: if one keeps the rows from *l* to *r* inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such *j* that *a**i*,<=*j*<=≤<=*a**i*<=+<=1,<=*j* for all *i* from *l* to *r*<=-<=1 inclusive.
Alyona is too small to deal with this task and asks you to help! | The first line of the input contains two positive integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=100<=000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following *n* lines contains *m* integers. The *j*-th integers in the *i* of these lines stands for *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=109).
The next line of the input contains an integer *k* (1<=≤<=*k*<=≤<=100<=000) — the number of task that teacher gave to Alyona.
The *i*-th of the next *k* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print "Yes" to the *i*-th line of the output if the table consisting of rows from *l**i* to *r**i* inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No". | [
"5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n"
] | [
"Yes\nNo\nYes\nYes\nYes\nNo\n"
] | In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3. | [
{
"input": "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5",
"output": "Yes\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "1 1\n1\n1\n1 1",
"output": "Yes"
},
{
"input": "10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n386865653\n67832626\n53360557\n17\n4 5\n4 7\n8 8\n9 9\n3 9\n8 10\n8 9\n7 9\n4 5\n2 9\n4 6\n2 4\n2 6\n4 6\n7 9\n2 4\n8 10",
"output": "No\nNo\nYes\nYes\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo"
},
{
"input": "15 1\n556231456\n573340933\n626155933\n397229387\n10255952\n376567394\n906742013\n269437009\n31298788\n712285290\n620239975\n379221898\n229140718\n95080095\n997123854\n18\n5 15\n1 12\n4 10\n2 15\n12 15\n15 15\n2 2\n15 15\n15 15\n13 13\n10 14\n3 6\n14 15\n3 6\n4 4\n14 15\n12 14\n1 9",
"output": "No\nNo\nNo\nNo\nNo\nYes\nYes\nYes\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nYes\nNo\nNo"
},
{
"input": "11 1\n501465490\n366941771\n415080944\n385243536\n445132523\n697044413\n894369800\n812743722\n23684788\n466526046\n953916313\n45\n2 4\n8 9\n7 7\n4 9\n2 9\n2 11\n4 4\n5 7\n1 2\n5 10\n4 6\n1 7\n4 4\n1 6\n4 7\n10 11\n1 8\n6 11\n8 8\n8 10\n1 1\n5 10\n9 10\n6 9\n6 11\n1 1\n9 9\n5 11\n1 2\n9 11\n2 6\n3 7\n11 11\n6 7\n11 11\n7 8\n5 8\n11 11\n5 6\n4 5\n2 6\n5 10\n9 9\n1 1\n1 1",
"output": "No\nNo\nYes\nNo\nNo\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nNo\nYes\nNo\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nYes\nYes\nYes"
}
] | 1,000 | 8,601,600 | 0 | 53 |
|
758 | Holiday Of Equality | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281",
"output": "5464380"
},
{
"input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353",
"output": "9535765"
},
{
"input": "3\n1 3 2",
"output": "3"
},
{
"input": "3\n2 1 3",
"output": "3"
},
{
"input": "3\n2 3 1",
"output": "3"
},
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "3"
},
{
"input": "1\n228503",
"output": "0"
},
{
"input": "2\n32576 550340",
"output": "517764"
},
{
"input": "3\n910648 542843 537125",
"output": "741328"
},
{
"input": "4\n751720 572344 569387 893618",
"output": "787403"
},
{
"input": "6\n433864 631347 597596 794426 713555 231193",
"output": "1364575"
},
{
"input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107",
"output": "4647430"
},
{
"input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025",
"output": "13488674"
},
{
"input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763",
"output": "21993384"
},
{
"input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351",
"output": "26984185"
},
{
"input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642",
"output": "32816391"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "99000000"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n5 0 0",
"output": "10"
},
{
"input": "5\n2 10 0 0 0",
"output": "38"
}
] | 46 | 0 | 3 | 54 |
|
373 | Making Sequences is Fun | [
"binary search",
"implementation",
"math"
] | null | null | We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6.
You want to make a consecutive integer sequence starting from number *m* (*m*,<=*m*<=+<=1,<=...). But you need to pay *S*(*n*)·*k* to add the number *n* to the sequence.
You can spend a cost up to *w*, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length. | The first line contains three integers *w* (1<=≤<=*w*<=≤<=1016), *m* (1<=≤<=*m*<=≤<=1016), *k* (1<=≤<=*k*<=≤<=109).
Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | The first line should contain a single integer — the answer to the problem. | [
"9 1 1\n",
"77 7 7\n",
"114 5 14\n",
"1 1 2\n"
] | [
"9\n",
"7\n",
"6\n",
"0\n"
] | none | [
{
"input": "9 1 1",
"output": "9"
},
{
"input": "77 7 7",
"output": "7"
},
{
"input": "114 5 14",
"output": "6"
},
{
"input": "1 1 2",
"output": "0"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "10000000000000000 1 1",
"output": "674074074074073"
},
{
"input": "2155990066796462 2710473050636183 563261158",
"output": "239230"
},
{
"input": "552719169048748 7822730034794389 374302919",
"output": "92291"
},
{
"input": "6895788044242644 3474119895793364 732614708",
"output": "588285"
},
{
"input": "9230573804495452 8577408935470783 90893866",
"output": "6347082"
},
{
"input": "5363062262667637 2932858345469643 449197576",
"output": "746200"
},
{
"input": "1951414609070432 8979282171178729 260239468",
"output": "468658"
},
{
"input": "6289344232651169 4170875805886064 618522710",
"output": "635520"
},
{
"input": "111984789523940 8017182602114316 976839488",
"output": "7164"
},
{
"input": "3663662721733869 4845943245608254 787880219",
"output": "290626"
},
{
"input": "10000000000000000 10000000000000000 1",
"output": "588235294117647"
},
{
"input": "10000000000000000 9999999999999999 1",
"output": "588235294117647"
},
{
"input": "9999999999999999 1 1",
"output": "674074074074073"
},
{
"input": "3 1 4",
"output": "0"
},
{
"input": "9999999999999998 1 1",
"output": "674074074074072"
},
{
"input": "1 1000000000000000 1",
"output": "0"
},
{
"input": "1 1000000000000000 1000000000",
"output": "0"
},
{
"input": "10000000000000000 10000000000000000 1000000000",
"output": "588235"
},
{
"input": "10000000000000000 10000000000000000 1",
"output": "588235294117647"
},
{
"input": "121212121 3434343434 56",
"output": "216450"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "98 55 1",
"output": "47"
},
{
"input": "1 10000000000000000 123456",
"output": "0"
},
{
"input": "10000000000000000 1000000000000001 1000000000",
"output": "625000"
}
] | 109 | 0 | 3 | 55 |
|
979 | Pizza, Pizza, Pizza!!! | [
"math"
] | null | null | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.
She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.
Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.
As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem? | A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. | A single integer — the number of straight cuts Shiro needs. | [
"3\n",
"4\n"
] | [
"2",
"5"
] | To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | [
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "5"
},
{
"input": "10",
"output": "11"
},
{
"input": "10000000000",
"output": "10000000001"
},
{
"input": "1234567891",
"output": "617283946"
},
{
"input": "7509213957",
"output": "3754606979"
},
{
"input": "99999999999999999",
"output": "50000000000000000"
},
{
"input": "21",
"output": "11"
},
{
"input": "712394453192",
"output": "712394453193"
},
{
"input": "172212168",
"output": "172212169"
},
{
"input": "822981260158260519",
"output": "411490630079130260"
},
{
"input": "28316250877914571",
"output": "14158125438957286"
},
{
"input": "779547116602436424",
"output": "779547116602436425"
},
{
"input": "578223540024979436",
"output": "578223540024979437"
},
{
"input": "335408917861648766",
"output": "335408917861648767"
},
{
"input": "74859962623690078",
"output": "74859962623690079"
},
{
"input": "252509054433933439",
"output": "126254527216966720"
},
{
"input": "760713016476190622",
"output": "760713016476190623"
},
{
"input": "919845426262703496",
"output": "919845426262703497"
},
{
"input": "585335723211047194",
"output": "585335723211047195"
},
{
"input": "522842184971407769",
"output": "261421092485703885"
},
{
"input": "148049062628894320",
"output": "148049062628894321"
},
{
"input": "84324828731963974",
"output": "84324828731963975"
},
{
"input": "354979173822804781",
"output": "177489586911402391"
},
{
"input": "1312150450968413",
"output": "656075225484207"
},
{
"input": "269587449430302150",
"output": "269587449430302151"
},
{
"input": "645762258982631926",
"output": "645762258982631927"
},
{
"input": "615812229161735895",
"output": "307906114580867948"
},
{
"input": "0",
"output": "0"
},
{
"input": "349993004923078531",
"output": "174996502461539266"
},
{
"input": "891351282707723851",
"output": "445675641353861926"
},
{
"input": "563324731189330734",
"output": "563324731189330735"
},
{
"input": "520974001910286909",
"output": "260487000955143455"
},
{
"input": "666729339802329204",
"output": "666729339802329205"
},
{
"input": "856674611404539671",
"output": "428337305702269836"
},
{
"input": "791809296303238499",
"output": "395904648151619250"
},
{
"input": "711066337317063338",
"output": "711066337317063339"
},
{
"input": "931356503492686566",
"output": "931356503492686567"
},
{
"input": "234122432773361866",
"output": "234122432773361867"
},
{
"input": "1000000000000000000",
"output": "1000000000000000001"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "7",
"output": "4"
},
{
"input": "63",
"output": "32"
},
{
"input": "24",
"output": "25"
},
{
"input": "8",
"output": "9"
},
{
"input": "15",
"output": "8"
}
] | 109 | 0 | 0 | 56 |
|
659 | Bicycle Race | [
"geometry",
"implementation",
"math"
] | null | null | Maria participates in a bicycle race.
The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.
Let's introduce a system of coordinates, directing the *Ox* axis from west to east, and the *Oy* axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa).
Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored.
Help Maria get ready for the competition — determine the number of dangerous turns on the track. | The first line of the input contains an integer *n* (4<=≤<=*n*<=≤<=1000) — the number of straight sections of the track.
The following (*n*<=+<=1)-th line contains pairs of integers (*x**i*,<=*y**i*) (<=-<=10<=000<=≤<=*x**i*,<=*y**i*<=≤<=10<=000). The first of these points is the starting position. The *i*-th straight section of the track begins at the point (*x**i*,<=*y**i*) and ends at the point (*x**i*<=+<=1,<=*y**i*<=+<=1).
It is guaranteed that:
- the first straight section is directed to the north; - the southernmost (and if there are several, then the most western of among them) point of the track is the first point; - the last point coincides with the first one (i.e., the start position); - any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point); - no pair of points (except for the first and last one) is the same; - no two adjacent straight sections are directed in the same direction or in opposite directions. | Print a single integer — the number of dangerous turns on the track. | [
"6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0\n",
"16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1\n"
] | [
"1\n",
"6\n"
] | The first sample corresponds to the picture:
The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1. | [
{
"input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0",
"output": "1"
},
{
"input": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1",
"output": "6"
},
{
"input": "4\n-10000 -10000\n-10000 10000\n10000 10000\n10000 -10000\n-10000 -10000",
"output": "0"
},
{
"input": "4\n6 8\n6 9\n7 9\n7 8\n6 8",
"output": "0"
},
{
"input": "8\n-10000 -10000\n-10000 5000\n0 5000\n0 10000\n10000 10000\n10000 0\n0 0\n0 -10000\n-10000 -10000",
"output": "2"
},
{
"input": "20\n-4286 -10000\n-4286 -7778\n-7143 -7778\n-7143 -3334\n-10000 -3334\n-10000 1110\n-4286 1110\n-4286 -3334\n4285 -3334\n4285 -1112\n7142 -1112\n7142 3332\n4285 3332\n4285 9998\n9999 9998\n9999 -3334\n7142 -3334\n7142 -5556\n-1429 -5556\n-1429 -10000\n-4286 -10000",
"output": "8"
},
{
"input": "24\n-10000 -10000\n-10000 9998\n9998 9998\n9998 -10000\n-6364 -10000\n-6364 6362\n6362 6362\n6362 -6364\n-2728 -6364\n-2728 2726\n2726 2726\n2726 -910\n908 -910\n908 908\n-910 908\n-910 -4546\n4544 -4546\n4544 4544\n-4546 4544\n-4546 -8182\n8180 -8182\n8180 8180\n-8182 8180\n-8182 -10000\n-10000 -10000",
"output": "10"
},
{
"input": "12\n-10000 -10000\n-10000 10000\n10000 10000\n10000 6000\n-6000 6000\n-6000 2000\n10000 2000\n10000 -2000\n-6000 -2000\n-6000 -6000\n10000 -6000\n10000 -10000\n-10000 -10000",
"output": "4"
},
{
"input": "12\n-10000 -10000\n-10000 10000\n10000 10000\n10000 6000\n-9800 6000\n-9800 2000\n10000 2000\n10000 -2000\n-9800 -2000\n-9800 -6000\n10000 -6000\n10000 -10000\n-10000 -10000",
"output": "4"
},
{
"input": "4\n0 0\n0 10000\n10000 10000\n10000 0\n0 0",
"output": "0"
},
{
"input": "4\n-10000 -10000\n-10000 10000\n10000 10000\n10000 -10000\n-10000 -10000",
"output": "0"
}
] | 109 | 307,200 | 3 | 57 |
|
357 | Flag Day | [
"constructive algorithms",
"implementation"
] | null | null | In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:
- overall, there must be *m* dances;- exactly three people must take part in each dance;- each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland).
The agency has *n* dancers, and their number can be less than 3*m*. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance.
You considered all the criteria and made the plan for the *m* dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the *n* dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances. | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=105) and *m* (1<=≤<=*m*<=≤<=105) — the number of dancers and the number of dances, correspondingly. Then *m* lines follow, describing the dances in the order of dancing them. The *i*-th line contains three distinct integers — the numbers of the dancers that take part in the *i*-th dance. The dancers are numbered from 1 to *n*. Each dancer takes part in at least one dance. | Print *n* space-separated integers: the *i*-th number must represent the color of the *i*-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists. | [
"7 3\n1 2 3\n1 4 5\n4 6 7\n",
"9 3\n3 6 9\n2 5 8\n1 4 7\n",
"5 2\n4 1 5\n3 1 2\n"
] | [
"1 2 3 3 2 2 1 \n",
"1 1 1 2 2 2 3 3 3 \n",
"2 3 1 1 3 \n"
] | none | [
{
"input": "7 3\n1 2 3\n1 4 5\n4 6 7",
"output": "1 2 3 3 2 2 1 "
},
{
"input": "9 3\n3 6 9\n2 5 8\n1 4 7",
"output": "1 1 1 2 2 2 3 3 3 "
},
{
"input": "5 2\n4 1 5\n3 1 2",
"output": "2 3 1 1 3 "
},
{
"input": "14 5\n1 5 3\n13 10 11\n6 3 8\n14 9 2\n7 4 12",
"output": "1 3 3 2 2 2 1 1 2 2 3 3 1 1 "
},
{
"input": "14 6\n14 3 13\n10 14 5\n6 2 10\n7 13 9\n12 11 8\n1 4 9",
"output": "2 2 2 3 2 1 2 3 1 3 2 1 3 1 "
},
{
"input": "14 6\n11 13 10\n3 10 14\n2 7 12\n13 1 9\n5 11 4\n8 6 5",
"output": "1 1 2 2 3 2 2 1 3 3 1 3 2 1 "
},
{
"input": "13 5\n13 6 2\n13 3 8\n11 4 7\n10 9 5\n1 12 6",
"output": "3 3 3 2 3 2 3 2 2 1 1 1 1 "
},
{
"input": "14 6\n5 4 8\n5 7 12\n3 6 12\n7 11 14\n10 13 2\n10 1 9",
"output": "3 3 3 2 1 1 3 3 2 1 2 2 2 1 "
},
{
"input": "14 5\n4 13 2\n7 2 11\n6 1 5\n14 12 8\n10 3 9",
"output": "2 3 2 1 3 1 2 3 3 1 1 2 2 1 "
},
{
"input": "14 6\n2 14 5\n3 4 5\n6 13 14\n7 13 12\n8 10 11\n9 6 1",
"output": "1 1 1 2 3 3 3 1 2 2 3 2 1 2 "
},
{
"input": "14 6\n7 14 12\n6 1 12\n13 5 2\n2 3 9\n7 4 11\n5 8 10",
"output": "2 3 2 3 2 1 1 1 1 3 2 3 1 2 "
},
{
"input": "13 6\n8 7 6\n11 7 3\n13 9 3\n12 1 13\n8 10 4\n2 7 5",
"output": "3 1 3 2 3 3 2 1 2 3 1 2 1 "
},
{
"input": "13 5\n8 4 3\n1 9 5\n6 2 11\n12 10 4\n7 10 13",
"output": "1 2 3 2 3 1 3 1 2 1 3 3 2 "
},
{
"input": "20 8\n16 19 12\n13 3 5\n1 5 17\n10 19 7\n8 18 2\n3 11 14\n9 20 12\n4 15 6",
"output": "2 3 2 1 3 3 3 1 1 1 1 3 1 3 2 1 1 2 2 2 "
},
{
"input": "19 7\n10 18 14\n5 9 11\n9 17 7\n3 15 4\n6 8 12\n1 2 18\n13 16 19",
"output": "3 1 1 3 1 1 3 2 2 1 3 3 1 3 2 2 1 2 3 "
},
{
"input": "18 7\n17 4 13\n7 1 6\n16 9 13\n9 2 5\n11 12 17\n14 8 10\n3 15 18",
"output": "2 1 1 2 3 3 1 2 2 3 2 3 3 1 2 1 1 3 "
},
{
"input": "20 7\n8 5 11\n3 19 20\n16 1 17\n9 6 2\n7 18 13\n14 12 18\n10 4 15",
"output": "2 3 1 2 2 2 1 1 1 1 3 1 3 3 3 1 3 2 2 3 "
},
{
"input": "20 7\n6 11 20\n19 5 2\n15 10 12\n3 7 8\n9 1 6\n13 17 18\n14 16 4",
"output": "3 3 1 3 2 1 2 3 2 2 2 3 1 1 1 2 2 3 1 3 "
},
{
"input": "18 7\n15 5 1\n6 11 4\n14 8 17\n11 12 13\n3 8 16\n9 4 7\n2 18 10",
"output": "3 1 1 3 2 1 1 2 2 3 2 1 3 1 1 3 3 2 "
},
{
"input": "19 7\n3 10 8\n17 7 4\n1 19 18\n2 9 5\n12 11 15\n11 14 6\n13 9 16",
"output": "1 1 1 3 3 3 2 3 2 2 2 1 1 1 3 3 1 3 2 "
},
{
"input": "19 7\n18 14 4\n3 11 6\n8 10 7\n10 19 16\n17 13 15\n5 1 14\n12 9 2",
"output": "1 3 1 3 3 3 3 1 2 2 2 1 2 2 3 3 1 1 1 "
},
{
"input": "20 7\n18 7 15\n17 5 20\n9 19 12\n16 13 10\n3 6 1\n3 8 11\n4 2 14",
"output": "3 2 1 1 2 2 2 3 1 3 2 3 2 3 3 1 1 1 2 3 "
},
{
"input": "18 7\n8 4 6\n13 17 3\n9 8 12\n12 16 5\n18 2 7\n11 1 10\n5 15 14",
"output": "2 2 3 2 3 3 3 1 3 3 1 2 1 1 2 1 2 1 "
},
{
"input": "99 37\n40 10 7\n10 3 5\n10 31 37\n87 48 24\n33 47 38\n34 87 2\n2 35 28\n99 28 76\n66 51 97\n72 77 9\n18 17 67\n23 69 98\n58 89 99\n42 44 52\n65 41 80\n70 92 74\n62 88 45\n68 27 61\n6 83 95\n39 85 49\n57 75 77\n59 54 81\n56 20 82\n96 4 53\n90 7 11\n16 43 84\n19 25 59\n68 8 93\n73 94 78\n15 71 79\n26 12 50\n30 32 4\n14 22 29\n46 21 36\n60 55 86\n91 8 63\n13 1 64",
"output": "2 2 1 2 3 1 3 3 3 2 1 2 1 1 1 1 2 1 2 2 2 2 1 3 3 1 2 3 3 3 1 1 1 3 1 3 3 3 1 1 2 1 2 2 3 1 2 2 3 3 2 3 3 2 2 1 3 3 1 1 3 1 1 3 1 1 3 1 2 1 2 1 1 3 1 1 2 3 3 3 3 3 2 3 2 3 1 2 1 2 2 2 2 2 3 1 3 3 2 "
},
{
"input": "99 41\n11 70 20\n57 11 76\n52 11 64\n49 70 15\n19 61 17\n71 77 21\n77 59 39\n37 64 68\n17 84 36\n46 11 90\n35 11 14\n36 25 80\n12 43 48\n18 78 42\n82 94 15\n22 10 84\n63 86 4\n98 86 50\n92 60 9\n73 42 65\n21 5 27\n30 24 23\n7 88 49\n40 97 45\n81 56 17\n79 61 33\n13 3 77\n54 6 28\n99 58 8\n29 95 24\n89 74 32\n51 89 66\n87 91 96\n22 34 38\n1 53 72\n55 97 26\n41 16 44\n2 31 47\n83 67 91\n75 85 69\n93 47 62",
"output": "1 1 1 3 2 2 2 3 3 1 1 1 3 2 3 2 3 1 1 3 3 3 3 2 3 3 1 3 3 1 2 3 3 2 3 1 1 1 3 1 1 3 2 3 3 3 3 3 1 3 3 3 2 1 1 2 3 2 1 2 2 1 1 2 1 2 1 3 3 2 1 3 2 2 1 2 2 2 1 2 1 1 3 2 2 2 1 3 1 2 2 1 2 2 1 3 2 1 1 "
},
{
"input": "99 38\n70 56 92\n61 70 68\n18 92 91\n82 43 55\n37 5 43\n47 27 26\n64 63 40\n20 61 57\n69 80 59\n60 89 50\n33 25 86\n38 15 73\n96 85 90\n3 12 64\n95 23 48\n66 30 9\n38 99 45\n67 88 71\n74 11 81\n28 51 79\n72 92 34\n16 77 31\n65 18 94\n3 41 2\n36 42 81\n22 77 83\n44 24 52\n10 75 97\n54 21 53\n4 29 32\n58 39 98\n46 62 16\n76 5 84\n8 87 13\n6 41 14\n19 21 78\n7 49 93\n17 1 35",
"output": "2 3 2 1 1 3 1 1 3 1 2 3 3 2 2 1 1 2 1 2 2 1 2 2 2 3 2 1 2 2 3 3 1 1 3 1 3 1 2 3 1 2 2 1 2 2 1 3 2 3 2 3 3 1 3 2 1 1 3 1 3 3 2 1 1 1 1 2 1 1 3 2 3 1 2 3 2 3 3 2 3 1 3 2 2 3 2 2 2 3 1 3 3 3 1 1 3 3 3 "
},
{
"input": "98 38\n70 23 73\n73 29 86\n93 82 30\n6 29 10\n7 22 78\n55 61 87\n98 2 12\n11 5 54\n44 56 60\n89 76 50\n37 72 43\n47 41 61\n85 40 38\n48 93 20\n90 64 29\n31 68 25\n83 57 41\n51 90 3\n91 97 66\n96 95 1\n50 84 71\n53 19 5\n45 42 28\n16 17 89\n63 58 15\n26 47 39\n21 24 19\n80 74 38\n14 46 75\n88 65 36\n77 92 33\n17 59 34\n35 69 79\n13 94 39\n8 52 4\n67 27 9\n65 62 18\n81 32 49",
"output": "3 2 1 3 2 1 1 1 3 3 1 3 2 1 3 2 3 3 1 2 2 2 2 3 3 2 2 3 2 3 1 2 3 1 1 3 1 3 1 2 1 2 3 1 1 2 3 3 3 3 2 2 3 3 1 2 3 2 2 3 2 1 1 1 2 3 1 2 2 1 1 2 3 2 3 2 1 3 3 1 1 2 2 2 1 1 3 1 1 3 1 2 1 3 2 1 2 1 "
},
{
"input": "99 42\n61 66 47\n10 47 96\n68 86 67\n21 29 10\n55 44 47\n12 82 4\n45 71 55\n86 3 95\n16 99 93\n14 92 82\n12 59 20\n73 24 8\n79 72 48\n44 87 39\n87 84 97\n47 70 37\n49 77 95\n39 75 28\n75 25 5\n44 41 36\n76 86 78\n73 6 90\n8 22 58\n9 72 63\n81 42 14\n1 21 35\n91 54 15\n30 13 39\n56 89 79\n11 2 76\n19 65 52\n23 85 74\n7 38 24\n57 94 81\n43 34 60\n62 82 27\n69 64 53\n18 32 17\n24 31 88\n51 50 33\n40 80 98\n83 46 26",
"output": "2 3 1 3 3 3 3 3 1 2 2 1 2 3 3 1 3 1 1 2 3 2 1 2 1 3 3 1 1 1 1 2 3 2 1 3 1 1 3 1 1 2 1 2 2 2 3 3 1 2 1 3 3 2 1 2 2 1 3 3 1 1 3 2 2 2 3 1 1 2 3 2 1 3 2 1 2 3 1 2 1 2 1 3 2 2 1 3 3 2 1 1 3 3 3 1 2 3 2 "
}
] | 46 | 0 | 0 | 59 |
|
1,004 | Sonya and Exhibition | [
"constructive algorithms",
"greedy",
"implementation",
"math"
] | null | null | Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions should contain exactly one flower: a rose or a lily.
She knows that exactly $m$ people will visit this exhibition. The $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible. | The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively.
Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. | Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any. | [
"5 3\n1 3\n2 4\n2 5\n",
"6 3\n5 6\n1 4\n4 6\n"
] | [
"01100",
"110010"
] | In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
- in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots5]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$.
The total beauty is equal to $2+2+4=8$.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
- in the segment $[5\ldots6]$, there are one rose and one lily, so the beauty is equal to $1\cdot 1=1$; - in the segment $[1\ldots4]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$; - in the segment $[4\ldots6]$, there are two roses and one lily, so the beauty is equal to $2\cdot 1=2$.
The total beauty is equal to $1+4+2=7$. | [
{
"input": "5 3\n1 3\n2 4\n2 5",
"output": "01010"
},
{
"input": "6 3\n5 6\n1 4\n4 6",
"output": "010101"
},
{
"input": "10 4\n3 3\n1 6\n9 9\n10 10",
"output": "0101010101"
},
{
"input": "1 1\n1 1",
"output": "0"
},
{
"input": "1000 10\n3 998\n2 1000\n1 999\n2 1000\n3 998\n2 1000\n3 998\n1 1000\n2 1000\n3 999",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 20\n50 109\n317 370\n710 770\n440 488\n711 757\n236 278\n314 355\n131 190\n115 162\n784 834\n16 56\n677 730\n802 844\n632 689\n23 74\n647 702\n930 986\n926 983\n769 822\n508 558",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 10\n138 238\n160 260\n716 816\n504 604\n98 198\n26 126\n114 214\n217 317\n121 221\n489 589",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 5\n167 296\n613 753\n650 769\n298 439\n71 209",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 5\n349 415\n714 773\n125 179\n1 80\n148 242",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "914 10\n587 646\n770 843\n825 875\n439 485\n465 521\n330 387\n405 480\n477 521\n336 376\n715 771",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "571 10\n13 94\n450 510\n230 293\n302 375\n304 354\n421 504\n24 87\n122 181\n221 296\n257 307",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "6 2\n1 6\n1 4",
"output": "010101"
},
{
"input": "2 1\n1 2",
"output": "01"
}
] | 186 | 1,331,200 | 3 | 60 |
|
765 | Table Tennis Game 2 | [
"math"
] | null | null | Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins.
Across all the sets Misha scored *a* points in total, and Vanya scored *b* points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets. | The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=><=0). | If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets. | [
"11 11 5\n",
"11 2 3\n"
] | [
"1\n",
"-1\n"
] | Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem. | [
{
"input": "11 11 5",
"output": "1"
},
{
"input": "11 2 3",
"output": "-1"
},
{
"input": "1 5 9",
"output": "14"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "1 1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 3 5",
"output": "3"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "2"
},
{
"input": "1 0 1",
"output": "1"
},
{
"input": "101 99 97",
"output": "-1"
},
{
"input": "1000000000 0 1",
"output": "-1"
},
{
"input": "137 137 136",
"output": "1"
},
{
"input": "255 255 255",
"output": "2"
},
{
"input": "1 0 1000000000",
"output": "1000000000"
},
{
"input": "123 456 789",
"output": "9"
},
{
"input": "666666 6666666 666665",
"output": "-1"
},
{
"input": "1000000000 999999999 999999999",
"output": "-1"
},
{
"input": "100000000 100000001 99999999",
"output": "-1"
},
{
"input": "3 2 1000000000",
"output": "-1"
},
{
"input": "999999999 1000000000 999999998",
"output": "-1"
},
{
"input": "12938621 192872393 102739134",
"output": "21"
},
{
"input": "666666666 1230983 666666666",
"output": "1"
},
{
"input": "123456789 123456789 123456787",
"output": "1"
},
{
"input": "5 6 0",
"output": "-1"
},
{
"input": "11 0 12",
"output": "-1"
},
{
"input": "2 11 0",
"output": "-1"
},
{
"input": "2 1 0",
"output": "-1"
},
{
"input": "10 11 12",
"output": "2"
},
{
"input": "11 12 5",
"output": "-1"
},
{
"input": "11 12 3",
"output": "-1"
},
{
"input": "11 15 4",
"output": "-1"
},
{
"input": "2 3 1",
"output": "-1"
},
{
"input": "11 12 0",
"output": "-1"
},
{
"input": "11 13 2",
"output": "-1"
},
{
"input": "11 23 22",
"output": "4"
},
{
"input": "10 21 0",
"output": "-1"
},
{
"input": "11 23 1",
"output": "-1"
},
{
"input": "11 10 12",
"output": "-1"
},
{
"input": "11 1 12",
"output": "-1"
},
{
"input": "11 5 12",
"output": "-1"
},
{
"input": "11 8 12",
"output": "-1"
},
{
"input": "11 12 1",
"output": "-1"
},
{
"input": "5 4 6",
"output": "-1"
},
{
"input": "10 1 22",
"output": "-1"
},
{
"input": "2 3 0",
"output": "-1"
},
{
"input": "11 23 2",
"output": "-1"
},
{
"input": "2 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "11 0 15",
"output": "-1"
},
{
"input": "11 5 0",
"output": "-1"
},
{
"input": "11 5 15",
"output": "-1"
},
{
"input": "10 0 13",
"output": "-1"
},
{
"input": "4 7 0",
"output": "-1"
},
{
"input": "10 2 8",
"output": "-1"
},
{
"input": "11 5 22",
"output": "2"
},
{
"input": "11 13 0",
"output": "-1"
},
{
"input": "2 0 3",
"output": "-1"
},
{
"input": "10 10 0",
"output": "1"
},
{
"input": "10 11 10",
"output": "2"
},
{
"input": "3 5 4",
"output": "2"
},
{
"input": "11 22 3",
"output": "2"
},
{
"input": "11 12 10",
"output": "-1"
},
{
"input": "10 2 13",
"output": "-1"
},
{
"input": "5 6 1",
"output": "-1"
},
{
"input": "10 21 5",
"output": "-1"
},
{
"input": "10 11 9",
"output": "-1"
},
{
"input": "10 17 7",
"output": "-1"
},
{
"input": "3 4 1",
"output": "-1"
},
{
"input": "4 5 3",
"output": "-1"
},
{
"input": "11 3 23",
"output": "-1"
},
{
"input": "11 3 12",
"output": "-1"
},
{
"input": "2 5 0",
"output": "-1"
},
{
"input": "10 21 2",
"output": "-1"
},
{
"input": "5 1 6",
"output": "-1"
},
{
"input": "10 11 0",
"output": "-1"
},
{
"input": "10 9 11",
"output": "-1"
},
{
"input": "7 10 5",
"output": "-1"
},
{
"input": "5 7 2",
"output": "-1"
},
{
"input": "6 5 7",
"output": "-1"
},
{
"input": "11 16 2",
"output": "-1"
},
{
"input": "11 1000000000 10",
"output": "-1"
},
{
"input": "10 2 21",
"output": "-1"
},
{
"input": "10 15 1",
"output": "-1"
},
{
"input": "5 2 8",
"output": "-1"
},
{
"input": "11 10000000 10",
"output": "-1"
},
{
"input": "10 1 101",
"output": "-1"
},
{
"input": "20 24 2",
"output": "-1"
},
{
"input": "11 24 0",
"output": "-1"
},
{
"input": "11 17 4",
"output": "-1"
},
{
"input": "11 13 1",
"output": "-1"
},
{
"input": "10 11 2",
"output": "-1"
},
{
"input": "11 23 3",
"output": "-1"
},
{
"input": "10 99 0",
"output": "-1"
},
{
"input": "6 7 4",
"output": "-1"
},
{
"input": "11 1 22",
"output": "2"
},
{
"input": "11 2 13",
"output": "-1"
},
{
"input": "2 1 3",
"output": "-1"
},
{
"input": "11 6 18",
"output": "-1"
},
{
"input": "11 122 4",
"output": "-1"
},
{
"input": "11 21 10",
"output": "-1"
},
{
"input": "3 2 4",
"output": "-1"
},
{
"input": "9 11 2",
"output": "-1"
},
{
"input": "11 0 7",
"output": "-1"
},
{
"input": "5 9 4",
"output": "-1"
},
{
"input": "100 105 5",
"output": "-1"
},
{
"input": "11 15 0",
"output": "-1"
},
{
"input": "5 6 4",
"output": "-1"
},
{
"input": "3 4 2",
"output": "-1"
},
{
"input": "2 9 0",
"output": "-1"
},
{
"input": "11 13 11",
"output": "2"
},
{
"input": "11 15 5",
"output": "-1"
},
{
"input": "11 4 15",
"output": "-1"
},
{
"input": "10 1 0",
"output": "-1"
},
{
"input": "11 16 8",
"output": "-1"
},
{
"input": "10 43 0",
"output": "-1"
},
{
"input": "11 13 5",
"output": "-1"
},
{
"input": "11 22 0",
"output": "2"
},
{
"input": "5 6 3",
"output": "-1"
},
{
"input": "2 1 11",
"output": "-1"
},
{
"input": "4 5 1",
"output": "-1"
},
{
"input": "11 23 0",
"output": "-1"
},
{
"input": "11 4 12",
"output": "-1"
},
{
"input": "12 13 1",
"output": "-1"
},
{
"input": "10 19 9",
"output": "-1"
},
{
"input": "3 7 2",
"output": "-1"
},
{
"input": "12 18 0",
"output": "-1"
},
{
"input": "11 25 3",
"output": "-1"
},
{
"input": "11 23 5",
"output": "-1"
},
{
"input": "2 1 5",
"output": "-1"
},
{
"input": "2 0 5",
"output": "-1"
},
{
"input": "11 24 1",
"output": "-1"
},
{
"input": "10 11 4",
"output": "-1"
},
{
"input": "2 0 1",
"output": "-1"
},
{
"input": "10 0 21",
"output": "-1"
},
{
"input": "3 0 7",
"output": "-1"
},
{
"input": "18 11 21",
"output": "-1"
},
{
"input": "3 7 0",
"output": "-1"
},
{
"input": "5 11 0",
"output": "-1"
},
{
"input": "11 5 13",
"output": "-1"
},
{
"input": "11 9 34",
"output": "-1"
},
{
"input": "11 13 9",
"output": "-1"
},
{
"input": "10 0 22",
"output": "-1"
},
{
"input": "5 1 12",
"output": "-1"
},
{
"input": "11 2 12",
"output": "-1"
},
{
"input": "11 9 12",
"output": "-1"
},
{
"input": "11 24 2",
"output": "-1"
},
{
"input": "11 23 6",
"output": "-1"
},
{
"input": "11 20 4",
"output": "-1"
},
{
"input": "2 5 1",
"output": "-1"
},
{
"input": "120 132 133",
"output": "2"
},
{
"input": "11 111 4",
"output": "-1"
},
{
"input": "10 7 11",
"output": "-1"
},
{
"input": "6 13 0",
"output": "-1"
},
{
"input": "5 11 1",
"output": "-1"
},
{
"input": "11 5 27",
"output": "-1"
},
{
"input": "11 15 3",
"output": "-1"
},
{
"input": "11 0 13",
"output": "-1"
},
{
"input": "11 13 10",
"output": "-1"
},
{
"input": "11 25 5",
"output": "-1"
},
{
"input": "4 3 5",
"output": "-1"
},
{
"input": "100 199 100",
"output": "2"
},
{
"input": "11 2 22",
"output": "2"
},
{
"input": "10 20 2",
"output": "2"
},
{
"input": "5 5 0",
"output": "1"
},
{
"input": "10 11 1",
"output": "-1"
},
{
"input": "11 12 2",
"output": "-1"
},
{
"input": "5 16 3",
"output": "-1"
},
{
"input": "12 14 1",
"output": "-1"
},
{
"input": "10 22 2",
"output": "-1"
},
{
"input": "2 4 0",
"output": "2"
},
{
"input": "11 34 7",
"output": "-1"
},
{
"input": "6 13 1",
"output": "-1"
},
{
"input": "11 0 23",
"output": "-1"
},
{
"input": "20 21 19",
"output": "-1"
},
{
"input": "11 33 22",
"output": "5"
},
{
"input": "10 4 41",
"output": "-1"
},
{
"input": "3 4 0",
"output": "-1"
},
{
"input": "11 15 7",
"output": "-1"
},
{
"input": "5 0 6",
"output": "-1"
},
{
"input": "11 3 22",
"output": "2"
},
{
"input": "2 6 0",
"output": "3"
},
{
"input": "10 11 11",
"output": "2"
},
{
"input": "11 33 0",
"output": "3"
},
{
"input": "4 6 2",
"output": "-1"
},
{
"input": "11 76 2",
"output": "-1"
},
{
"input": "7 9 4",
"output": "-1"
},
{
"input": "10 43 1",
"output": "-1"
},
{
"input": "22 25 5",
"output": "-1"
},
{
"input": "3 5 2",
"output": "-1"
},
{
"input": "11 1 24",
"output": "-1"
},
{
"input": "12 25 3",
"output": "-1"
},
{
"input": "11 0 22",
"output": "2"
},
{
"input": "4 2 5",
"output": "-1"
},
{
"input": "11 13 3",
"output": "-1"
},
{
"input": "11 12 9",
"output": "-1"
},
{
"input": "11 35 1",
"output": "-1"
},
{
"input": "5 3 6",
"output": "-1"
},
{
"input": "5 11 4",
"output": "-1"
},
{
"input": "12 8 14",
"output": "-1"
},
{
"input": "10 12 9",
"output": "-1"
},
{
"input": "11 12 13",
"output": "2"
},
{
"input": "11 15 2",
"output": "-1"
},
{
"input": "11 23 4",
"output": "-1"
},
{
"input": "5 3 11",
"output": "-1"
},
{
"input": "6 13 2",
"output": "-1"
},
{
"input": "4 1 0",
"output": "-1"
},
{
"input": "11 32 10",
"output": "-1"
},
{
"input": "2 11 1",
"output": "-1"
},
{
"input": "10 11 7",
"output": "-1"
},
{
"input": "11 26 0",
"output": "-1"
},
{
"input": "100 205 5",
"output": "-1"
},
{
"input": "4 0 2",
"output": "-1"
},
{
"input": "10 11 8",
"output": "-1"
},
{
"input": "11 22 5",
"output": "2"
},
{
"input": "4 0 5",
"output": "-1"
},
{
"input": "11 87 22",
"output": "9"
},
{
"input": "4 8 0",
"output": "2"
},
{
"input": "9 8 17",
"output": "-1"
},
{
"input": "10 20 0",
"output": "2"
},
{
"input": "10 9 19",
"output": "-1"
},
{
"input": "12 2 13",
"output": "-1"
},
{
"input": "11 24 5",
"output": "-1"
},
{
"input": "10 1 11",
"output": "-1"
},
{
"input": "4 0 9",
"output": "-1"
},
{
"input": "3 0 1",
"output": "-1"
},
{
"input": "11 12 4",
"output": "-1"
},
{
"input": "3 8 2",
"output": "-1"
},
{
"input": "11 17 10",
"output": "-1"
},
{
"input": "6 1 13",
"output": "-1"
},
{
"input": "11 25 0",
"output": "-1"
},
{
"input": "12 0 13",
"output": "-1"
},
{
"input": "10 5 20",
"output": "2"
},
{
"input": "11 89 2",
"output": "-1"
},
{
"input": "2 4 1",
"output": "2"
},
{
"input": "10 31 0",
"output": "-1"
},
{
"input": "11 34 1",
"output": "-1"
},
{
"input": "999 6693 8331",
"output": "14"
},
{
"input": "10 55 1",
"output": "-1"
},
{
"input": "11 12 8",
"output": "-1"
},
{
"input": "1 9 22",
"output": "31"
},
{
"input": "7572 9186 895",
"output": "-1"
},
{
"input": "3 2 11",
"output": "-1"
},
{
"input": "2 1 4",
"output": "2"
},
{
"input": "11 10 19",
"output": "-1"
},
{
"input": "100 199 99",
"output": "-1"
},
{
"input": "2537 8926 1523",
"output": "-1"
},
{
"input": "11 0 5",
"output": "-1"
},
{
"input": "5 1 11",
"output": "-1"
},
{
"input": "12 13 5",
"output": "-1"
},
{
"input": "10 12 0",
"output": "-1"
},
{
"input": "5 4 7",
"output": "-1"
},
{
"input": "12 25 1",
"output": "-1"
},
{
"input": "7 9 0",
"output": "-1"
},
{
"input": "4 15 0",
"output": "-1"
},
{
"input": "5 11 2",
"output": "-1"
},
{
"input": "11 58 3",
"output": "-1"
},
{
"input": "10 11 5",
"output": "-1"
},
{
"input": "10 3 1003",
"output": "-1"
},
{
"input": "11 14 0",
"output": "-1"
},
{
"input": "11 8 23",
"output": "-1"
},
{
"input": "11 22 4",
"output": "2"
},
{
"input": "5 2 0",
"output": "-1"
},
{
"input": "11 1 35",
"output": "-1"
},
{
"input": "12 25 5",
"output": "-1"
},
{
"input": "11 37 4",
"output": "-1"
},
{
"input": "20 42 3",
"output": "-1"
},
{
"input": "10 12 2",
"output": "-1"
},
{
"input": "4 1 5",
"output": "-1"
},
{
"input": "5 16 0",
"output": "-1"
},
{
"input": "11 13 7",
"output": "-1"
},
{
"input": "5 0 3",
"output": "-1"
},
{
"input": "11 2 11",
"output": "1"
},
{
"input": "3 2 2000",
"output": "-1"
},
{
"input": "3 0 4241",
"output": "-1"
},
{
"input": "2 12 11",
"output": "11"
},
{
"input": "10 2 82",
"output": "-1"
},
{
"input": "11 0 11",
"output": "1"
},
{
"input": "11 20 20",
"output": "2"
},
{
"input": "5 0 10",
"output": "2"
},
{
"input": "11 1 0",
"output": "-1"
},
{
"input": "11 13 13",
"output": "2"
}
] | 140 | 20,172,800 | 3 | 61 |
|
228 | Is your horseshoe on the other hoof? | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 586975278",
"output": "1"
},
{
"input": "259504825 377489979 588153796 377489979",
"output": "1"
},
{
"input": "652588203 931100304 931100304 652588203",
"output": "2"
},
{
"input": "391958720 651507265 391958720 651507265",
"output": "2"
},
{
"input": "90793237 90793237 90793237 90793237",
"output": "3"
},
{
"input": "551651653 551651653 551651653 551651653",
"output": "3"
},
{
"input": "156630260 609654355 668943582 973622757",
"output": "0"
},
{
"input": "17061017 110313588 434481173 796661222",
"output": "0"
},
{
"input": "24975422 256716298 337790533 690960249",
"output": "0"
},
{
"input": "255635360 732742923 798648949 883146723",
"output": "0"
},
{
"input": "133315691 265159773 734556507 265159773",
"output": "1"
},
{
"input": "28442865 741657755 978106882 978106882",
"output": "1"
},
{
"input": "131245479 174845575 497483467 131245479",
"output": "1"
},
{
"input": "139159884 616215581 958341883 616215581",
"output": "1"
},
{
"input": "147784432 947653080 947653080 947653080",
"output": "2"
},
{
"input": "94055790 756126496 756126496 94055790",
"output": "2"
},
{
"input": "240458500 511952208 240458500 511952208",
"output": "2"
},
{
"input": "681828506 972810624 972810624 681828506",
"output": "2"
},
{
"input": "454961014 454961014 454961014 454961014",
"output": "3"
},
{
"input": "915819430 915819430 915819430 915819430",
"output": "3"
},
{
"input": "671645142 671645142 671645142 671645142",
"output": "3"
},
{
"input": "132503558 132503558 132503558 132503558",
"output": "3"
},
{
"input": "5 5 999999 6",
"output": "1"
},
{
"input": "1 1 2 5",
"output": "1"
},
{
"input": "2 1 2 3",
"output": "1"
},
{
"input": "1 1 3 5",
"output": "1"
},
{
"input": "1 1 3 3",
"output": "2"
},
{
"input": "2 2 2 1",
"output": "2"
},
{
"input": "3 1 1 1",
"output": "2"
},
{
"input": "1 2 2 2",
"output": "2"
}
] | 30 | 0 | 0 | 62 |
|
14 | Camels | [
"dp"
] | E. Camels | 2 | 64 | Bob likes to draw camels: with a single hump, two humps, three humps, etc. He draws a camel by connecting points on a coordinate plane. Now he's drawing camels with *t* humps, representing them as polylines in the plane. Each polyline consists of *n* vertices with coordinates (*x*1,<=*y*1), (*x*2,<=*y*2), ..., (*x**n*,<=*y**n*). The first vertex has a coordinate *x*1<==<=1, the second — *x*2<==<=2, etc. Coordinates *y**i* might be any, but should satisfy the following conditions:
- there should be *t* humps precisely, i.e. such indexes *j* (2<=≤<=*j*<=≤<=*n*<=-<=1), so that *y**j*<=-<=1<=<<=*y**j*<=><=*y**j*<=+<=1, - there should be precisely *t*<=-<=1 such indexes *j* (2<=≤<=*j*<=≤<=*n*<=-<=1), so that *y**j*<=-<=1<=><=*y**j*<=<<=*y**j*<=+<=1, - no segment of a polyline should be parallel to the *Ox*-axis, - all *y**i* are integers between 1 and 4.
For a series of his drawings of camels with *t* humps Bob wants to buy a notebook, but he doesn't know how many pages he will need. Output the amount of different polylines that can be drawn to represent camels with *t* humps for a given number *n*. | The first line contains a pair of integers *n* and *t* (3<=≤<=*n*<=≤<=20, 1<=≤<=*t*<=≤<=10). | Output the required amount of camels with *t* humps. | [
"6 1\n",
"4 2\n"
] | [
"6\n",
"0\n"
] | In the first sample test sequences of *y*-coordinates for six camels are: 123421, 123431, 123432, 124321, 134321 и 234321 (each digit corresponds to one value of *y*<sub class="lower-index">*i*</sub>). | [
{
"input": "6 1",
"output": "6"
},
{
"input": "4 2",
"output": "0"
},
{
"input": "3 1",
"output": "14"
},
{
"input": "3 2",
"output": "0"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "3 10",
"output": "0"
},
{
"input": "4 1",
"output": "22"
},
{
"input": "4 3",
"output": "0"
},
{
"input": "4 9",
"output": "0"
},
{
"input": "5 1",
"output": "16"
},
{
"input": "5 2",
"output": "70"
},
{
"input": "5 3",
"output": "0"
},
{
"input": "5 5",
"output": "0"
},
{
"input": "5 9",
"output": "0"
},
{
"input": "5 10",
"output": "0"
},
{
"input": "6 1",
"output": "6"
},
{
"input": "6 2",
"output": "232"
},
{
"input": "6 3",
"output": "0"
},
{
"input": "6 4",
"output": "0"
},
{
"input": "6 10",
"output": "0"
},
{
"input": "19 1",
"output": "0"
},
{
"input": "19 2",
"output": "0"
},
{
"input": "19 3",
"output": "1"
},
{
"input": "19 4",
"output": "32632"
},
{
"input": "19 5",
"output": "4594423"
},
{
"input": "19 6",
"output": "69183464"
},
{
"input": "19 7",
"output": "197939352"
},
{
"input": "19 8",
"output": "109824208"
},
{
"input": "19 9",
"output": "5846414"
},
{
"input": "19 10",
"output": "0"
},
{
"input": "20 1",
"output": "0"
},
{
"input": "20 2",
"output": "0"
},
{
"input": "20 3",
"output": "0"
},
{
"input": "20 4",
"output": "12628"
},
{
"input": "20 5",
"output": "3715462"
},
{
"input": "20 6",
"output": "96046590"
},
{
"input": "20 7",
"output": "468541040"
},
{
"input": "20 8",
"output": "503245466"
},
{
"input": "20 9",
"output": "90700276"
},
{
"input": "20 10",
"output": "0"
}
] | 92 | 102,400 | 3.976237 | 63 |
725 | Jumping Ball | [
"implementation"
] | null | null | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position *i* it goes one position to the right (to the position *i*<=+<=1) if the type of this bumper is '>', or one position to the left (to *i*<=-<=1) if the type of the bumper at position *i* is '<'. If there is no such position, in other words if *i*<=-<=1<=<<=1 or *i*<=+<=1<=><=*n*, the ball falls from the game field.
Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | [
"4\n<<><\n",
"5\n>>>>>\n",
"4\n>><<\n"
] | [
"2",
"5",
"0"
] | In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | [
{
"input": "4\n<<><",
"output": "2"
},
{
"input": "5\n>>>>>",
"output": "5"
},
{
"input": "4\n>><<",
"output": "0"
},
{
"input": "3\n<<>",
"output": "3"
},
{
"input": "3\n<<<",
"output": "3"
},
{
"input": "3\n><<",
"output": "0"
},
{
"input": "1\n<",
"output": "1"
},
{
"input": "2\n<>",
"output": "2"
},
{
"input": "3\n<>>",
"output": "3"
},
{
"input": "3\n><>",
"output": "1"
},
{
"input": "2\n><",
"output": "0"
},
{
"input": "2\n>>",
"output": "2"
},
{
"input": "2\n<<",
"output": "2"
},
{
"input": "1\n>",
"output": "1"
},
{
"input": "3\n>><",
"output": "0"
},
{
"input": "3\n>>>",
"output": "3"
},
{
"input": "3\n<><",
"output": "1"
},
{
"input": "10\n<<<><<<>>>",
"output": "6"
},
{
"input": "20\n><><<><<<>>>>>>>>>>>",
"output": "11"
},
{
"input": "20\n<<<<<<<<<<><<<<>>>>>",
"output": "15"
},
{
"input": "50\n<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>",
"output": "50"
},
{
"input": "100\n<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>",
"output": "49"
},
{
"input": "100\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><",
"output": "50"
},
{
"input": "100\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",
"output": "100"
},
{
"input": "100\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
"output": "100"
},
{
"input": "12\n<<>><<>><<>>",
"output": "4"
},
{
"input": "6\n<<><>>",
"output": "4"
},
{
"input": "6\n><>>>>",
"output": "4"
},
{
"input": "8\n>>>><<<>",
"output": "1"
},
{
"input": "4\n<><>",
"output": "2"
},
{
"input": "4\n><><",
"output": "0"
},
{
"input": "7\n<<>>><>",
"output": "3"
},
{
"input": "10\n><><>>>>>>",
"output": "6"
},
{
"input": "5\n<><>>",
"output": "3"
},
{
"input": "12\n<><<<<>>>>>>",
"output": "7"
},
{
"input": "6\n<>><<>",
"output": "2"
},
{
"input": "6\n>>><>>",
"output": "2"
},
{
"input": "10\n><><>>>><>",
"output": "1"
},
{
"input": "5\n><>>>",
"output": "3"
},
{
"input": "5\n<<><>",
"output": "3"
},
{
"input": "5\n<><<<",
"output": "1"
},
{
"input": "4\n<><<",
"output": "1"
},
{
"input": "8\n<<>><<>>",
"output": "4"
},
{
"input": "7\n<<><>>>",
"output": "5"
},
{
"input": "5\n><<>>",
"output": "2"
},
{
"input": "10\n<<<<<>>>>>",
"output": "10"
},
{
"input": "6\n><<<<<",
"output": "0"
},
{
"input": "8\n<<><><>>",
"output": "4"
},
{
"input": "10\n<<<<><<<><",
"output": "4"
},
{
"input": "12\n<<<>>>><<>>>",
"output": "6"
},
{
"input": "4\n><>>",
"output": "2"
},
{
"input": "11\n<<><<>><<>>",
"output": "4"
}
] | 109 | 0 | 0 | 64 |
|
143 | Help Vasilisa the Wise 2 | [
"brute force",
"math"
] | null | null | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2<=×<=2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task. | The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers *d*1 and *d*2 that define the required sums of numbers on the main and on the side diagonals of the square (1<=≤<=*r*1,<=*r*2,<=*c*1,<=*c*2,<=*d*1,<=*d*2<=≤<=20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement. | Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any. | [
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] | [
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] | Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | [
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
},
{
"input": "12 17\n10 19\n13 16",
"output": "-1"
},
{
"input": "11 11\n17 5\n12 10",
"output": "9 2\n8 3"
},
{
"input": "12 11\n11 12\n16 7",
"output": "-1"
},
{
"input": "5 9\n7 7\n8 6",
"output": "3 2\n4 5"
},
{
"input": "10 7\n4 13\n11 6",
"output": "-1"
},
{
"input": "18 10\n16 12\n12 16",
"output": "-1"
},
{
"input": "13 6\n10 9\n6 13",
"output": "-1"
},
{
"input": "14 16\n16 14\n18 12",
"output": "-1"
},
{
"input": "16 10\n16 10\n12 14",
"output": "-1"
},
{
"input": "11 9\n12 8\n11 9",
"output": "-1"
},
{
"input": "5 14\n10 9\n10 9",
"output": "-1"
},
{
"input": "2 4\n1 5\n3 3",
"output": "-1"
},
{
"input": "17 16\n14 19\n18 15",
"output": "-1"
},
{
"input": "12 12\n14 10\n16 8",
"output": "9 3\n5 7"
},
{
"input": "15 11\n16 10\n9 17",
"output": "7 8\n9 2"
},
{
"input": "8 10\n9 9\n13 5",
"output": "6 2\n3 7"
},
{
"input": "13 7\n10 10\n5 15",
"output": "4 9\n6 1"
},
{
"input": "14 11\n9 16\n16 9",
"output": "-1"
},
{
"input": "12 8\n14 6\n8 12",
"output": "-1"
},
{
"input": "10 6\n6 10\n4 12",
"output": "-1"
},
{
"input": "10 8\n10 8\n4 14",
"output": "-1"
},
{
"input": "14 13\n9 18\n14 13",
"output": "-1"
},
{
"input": "9 14\n8 15\n8 15",
"output": "-1"
},
{
"input": "3 8\n2 9\n6 5",
"output": "-1"
},
{
"input": "14 17\n18 13\n15 16",
"output": "-1"
},
{
"input": "16 14\n15 15\n17 13",
"output": "9 7\n6 8"
},
{
"input": "14 11\n16 9\n13 12",
"output": "9 5\n7 4"
},
{
"input": "13 10\n11 12\n7 16",
"output": "4 9\n7 3"
},
{
"input": "14 8\n11 11\n13 9",
"output": "8 6\n3 5"
},
{
"input": "12 11\n13 10\n10 13",
"output": "-1"
},
{
"input": "6 5\n2 9\n5 6",
"output": "-1"
},
{
"input": "7 8\n8 7\n12 3",
"output": "-1"
},
{
"input": "7 11\n7 11\n6 12",
"output": "-1"
},
{
"input": "8 5\n11 2\n8 5",
"output": "-1"
},
{
"input": "10 16\n14 12\n14 12",
"output": "-1"
},
{
"input": "7 9\n4 12\n5 11",
"output": "-1"
},
{
"input": "11 13\n19 5\n12 12",
"output": "-1"
},
{
"input": "8 12\n5 15\n11 9",
"output": "2 6\n3 9"
},
{
"input": "16 5\n13 8\n10 11",
"output": "9 7\n4 1"
},
{
"input": "3 14\n8 9\n10 7",
"output": "2 1\n6 8"
},
{
"input": "12 14\n11 15\n9 17",
"output": "3 9\n8 6"
},
{
"input": "13 7\n9 11\n14 6",
"output": "8 5\n1 6"
},
{
"input": "13 8\n15 6\n11 10",
"output": "9 4\n6 2"
},
{
"input": "9 6\n5 10\n3 12",
"output": "1 8\n4 2"
},
{
"input": "12 7\n5 14\n8 11",
"output": "3 9\n2 5"
},
{
"input": "9 12\n3 17\n10 10",
"output": "-1"
},
{
"input": "3 8\n4 6\n5 5",
"output": "-1"
}
] | 124 | 0 | 3 | 65 |
|
931 | World Cup | [
"constructive algorithms",
"implementation"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over.
Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids *a* and *b* can meet. | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round. | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
},
{
"input": "2 1 2",
"output": "Final!"
},
{
"input": "2 2 1",
"output": "Final!"
},
{
"input": "4 1 3",
"output": "Final!"
},
{
"input": "4 1 4",
"output": "Final!"
},
{
"input": "4 2 1",
"output": "1"
},
{
"input": "4 2 3",
"output": "Final!"
},
{
"input": "4 2 4",
"output": "Final!"
},
{
"input": "4 3 1",
"output": "Final!"
},
{
"input": "4 3 2",
"output": "Final!"
},
{
"input": "4 3 4",
"output": "1"
},
{
"input": "4 4 1",
"output": "Final!"
},
{
"input": "4 4 2",
"output": "Final!"
},
{
"input": "4 4 3",
"output": "1"
},
{
"input": "8 8 7",
"output": "1"
},
{
"input": "8 8 5",
"output": "2"
},
{
"input": "8 8 1",
"output": "Final!"
},
{
"input": "16 4 3",
"output": "1"
},
{
"input": "16 2 4",
"output": "2"
},
{
"input": "16 14 11",
"output": "3"
},
{
"input": "16 3 11",
"output": "Final!"
},
{
"input": "32 10 9",
"output": "1"
},
{
"input": "32 25 28",
"output": "2"
},
{
"input": "32 22 18",
"output": "3"
},
{
"input": "32 17 25",
"output": "4"
},
{
"input": "32 18 3",
"output": "Final!"
},
{
"input": "64 40 39",
"output": "1"
},
{
"input": "64 60 58",
"output": "2"
},
{
"input": "64 34 37",
"output": "3"
},
{
"input": "64 26 24",
"output": "4"
},
{
"input": "64 50 43",
"output": "5"
},
{
"input": "64 17 42",
"output": "Final!"
},
{
"input": "128 116 115",
"output": "1"
},
{
"input": "128 35 33",
"output": "2"
},
{
"input": "128 61 59",
"output": "3"
},
{
"input": "128 116 123",
"output": "4"
},
{
"input": "128 17 15",
"output": "5"
},
{
"input": "128 124 77",
"output": "6"
},
{
"input": "128 4 80",
"output": "Final!"
},
{
"input": "256 224 223",
"output": "1"
},
{
"input": "256 24 22",
"output": "2"
},
{
"input": "256 199 196",
"output": "3"
},
{
"input": "256 148 159",
"output": "4"
},
{
"input": "256 178 166",
"output": "5"
},
{
"input": "256 75 97",
"output": "6"
},
{
"input": "256 185 200",
"output": "7"
},
{
"input": "256 3 238",
"output": "Final!"
},
{
"input": "256 128 129",
"output": "Final!"
},
{
"input": "256 255 129",
"output": "7"
},
{
"input": "256 255 128",
"output": "Final!"
},
{
"input": "256 129 256",
"output": "7"
},
{
"input": "128 98 69",
"output": "6"
},
{
"input": "128 47 83",
"output": "Final!"
},
{
"input": "16 2 3",
"output": "2"
},
{
"input": "64 32 30",
"output": "2"
},
{
"input": "8 4 5",
"output": "Final!"
},
{
"input": "8 7 8",
"output": "1"
},
{
"input": "8 2 3",
"output": "2"
},
{
"input": "8 2 5",
"output": "Final!"
}
] | 108 | 20,172,800 | 3 | 66 |
|
526 | Om Nom and Candies | [
"brute force",
"greedy",
"math"
] | null | null | A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place?
One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs *W**r* grams and each blue candy weighs *W**b* grams. Eating a single red candy gives Om Nom *H**r* joy units and eating a single blue candy gives Om Nom *H**b* joy units.
Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than *C* grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat. | The single line contains five integers *C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b* (1<=≤<=*C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b*<=≤<=109). | Print a single integer — the maximum number of joy units that Om Nom can get. | [
"10 3 5 2 3\n"
] | [
"16\n"
] | In the sample test Om Nom can eat two candies of each type and thus get 16 joy units. | [
{
"input": "10 3 5 2 3",
"output": "16"
},
{
"input": "5 3 1 6 7",
"output": "0"
},
{
"input": "982068341 55 57 106 109",
"output": "513558662"
},
{
"input": "930064129 32726326 25428197 83013449 64501049",
"output": "363523396"
},
{
"input": "927155987 21197 15994 54746 41309",
"output": "358983713"
},
{
"input": "902303498 609628987 152407246 8 2",
"output": "68758795931537065"
},
{
"input": "942733698 9180 9072 1020 1008",
"output": "8484603228"
},
{
"input": "951102310 39876134 24967176 70096104 43888451",
"output": "539219654"
},
{
"input": "910943911 107 105 60 59",
"output": "1624516635"
},
{
"input": "910943911 38162 31949 67084 56162",
"output": "518210503"
},
{
"input": "910943911 9063 9045 1007 1005",
"output": "8198495199"
},
{
"input": "903796108 270891702 270891702 1 1",
"output": "244830865957095816"
},
{
"input": "936111602 154673223 309346447 1 2",
"output": "144791399037089047"
},
{
"input": "947370735 115930744 347792233 1 3",
"output": "109829394468167085"
},
{
"input": "958629867 96557265 386229061 1 4",
"output": "92562678344491221"
},
{
"input": "969889000 84931386 424656931 1 5",
"output": "82374017230131800"
},
{
"input": "925819493 47350513 28377591 83230978 49881078",
"output": "520855643"
},
{
"input": "934395168 119 105 67 59",
"output": "1662906651"
},
{
"input": "934395168 29208 38362 51342 67432",
"output": "531576348"
},
{
"input": "934395168 9171 9045 1019 1005",
"output": "8409556512"
},
{
"input": "946401698 967136832 483568416 2 1",
"output": "457649970001570368"
},
{
"input": "962693577 967217455 967217455 2 2",
"output": "465567015261784540"
},
{
"input": "989976325 646076560 969114840 2 3",
"output": "319800249268721000"
},
{
"input": "901235456 485501645 971003291 2 4",
"output": "218775648435471424"
},
{
"input": "912494588 389153108 972882772 2 5",
"output": "177550052841687584"
},
{
"input": "995503930 29205027 18903616 51333090 33226507",
"output": "565303099"
},
{
"input": "983935533 115 108 65 61",
"output": "1742049794"
},
{
"input": "983935533 33986 27367 59737 48104",
"output": "559787479"
},
{
"input": "983935533 7105 7056 1015 1008",
"output": "6887548731"
},
{
"input": "994040035 740285170 246761723 3 1",
"output": "245291032098926983"
},
{
"input": "905299166 740361314 493574209 3 2",
"output": "223416160034288041"
},
{
"input": "911525551 740437472 740437472 3 3",
"output": "224975891301803200"
},
{
"input": "922784684 566833132 755777509 3 4",
"output": "174354977531116762"
},
{
"input": "955100178 462665160 771108601 3 5",
"output": "147297192414486195"
},
{
"input": "949164751 36679609 23634069 64467968 41539167",
"output": "537909080"
},
{
"input": "928443151 60 63 106 112",
"output": "525533853"
},
{
"input": "928443151 25031 33442 43995 58778",
"output": "528241752"
},
{
"input": "928443151 1006 1012 1006 1012",
"output": "928443150"
},
{
"input": "936645623 540336743 135084185 4 1",
"output": "126526011319256470"
},
{
"input": "947904756 540408420 270204210 4 2",
"output": "128063927875111380"
},
{
"input": "959163888 540480074 405360055 4 3",
"output": "129602242291091928"
},
{
"input": "970423020 540551739 540551739 4 4",
"output": "131140962756657945"
},
{
"input": "976649406 455467553 569334442 4 5",
"output": "111208028918928288"
},
{
"input": "923881933 18531902 53987967 32570076 94884602",
"output": "524563246"
},
{
"input": "977983517 57 63 101 112",
"output": "551931291"
},
{
"input": "977983517 29808 22786 52389 40047",
"output": "556454318"
},
{
"input": "977983517 9009 9108 1001 1012",
"output": "8801851608"
},
{
"input": "984283960 367291526 73458305 5 1",
"output": "72303831537144592"
},
{
"input": "990510345 367358723 146943489 5 2",
"output": "72774523091497887"
},
{
"input": "901769477 367425909 220455545 5 3",
"output": "66266693959035917"
},
{
"input": "907995862 367493085 293994468 5 4",
"output": "66736440098722854"
},
{
"input": "924287742 367560271 367560271 5 5",
"output": "67946290439275508"
},
{
"input": "1000000000 1000 999 100 1000000000",
"output": "10000000000"
},
{
"input": "999999999 10 499999995 2 99999999",
"output": "4999999995"
},
{
"input": "999999999 1 1000000000 2 1000000000",
"output": "499999999"
},
{
"input": "999999997 2 999999997 2 999999997",
"output": "999999997"
},
{
"input": "1000000000 1 1 11 11",
"output": "90909090"
},
{
"input": "999999999 999999998 5 999999999 5",
"output": "999999998"
},
{
"input": "100000001 3 100000000 3 100000001",
"output": "100000000"
},
{
"input": "999999999 2 3 1 2",
"output": "1999999998"
},
{
"input": "1000000000 2 1 3 4",
"output": "666666666"
},
{
"input": "999999999 10000 494999 2 99",
"output": "4999999994999"
},
{
"input": "1000000000 1 1 1 1",
"output": "1000000000"
},
{
"input": "998999 1000 999 1000 999",
"output": "998999"
},
{
"input": "3 100 101 2 3",
"output": "101"
},
{
"input": "345415838 13999 13997 13999 13997",
"output": "345415838"
},
{
"input": "5000005 3 2 5 1",
"output": "10000010"
},
{
"input": "1000000000 1 1 1 1000000000",
"output": "1000000000"
},
{
"input": "999999999 3 2 10 3",
"output": "666666666"
},
{
"input": "1000000000 1000 1000 1 1",
"output": "1000000000000"
},
{
"input": "200000001 100000002 1 100000001 1",
"output": "200000002"
},
{
"input": "100000000 1000000000 1 100000001 1",
"output": "100000000"
},
{
"input": "1000000000 99 100 1 2",
"output": "99000000000"
},
{
"input": "1000000000 5 5 1 1",
"output": "5000000000"
},
{
"input": "1000000000 1 1000000000 1 1000000000",
"output": "1000000000"
}
] | 1,000 | 0 | 0 | 67 |
|
622 | Infinite Sequence | [
"implementation",
"math"
] | null | null | Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the *n*-th position of the sequence. | The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | Print the element in the *n*-th position of the sequence (the elements are numerated from one). | [
"3\n",
"5\n",
"10\n",
"55\n",
"56\n"
] | [
"2\n",
"2\n",
"4\n",
"10\n",
"1\n"
] | none | [
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "55",
"output": "10"
},
{
"input": "56",
"output": "1"
},
{
"input": "1000000000000",
"output": "88209"
},
{
"input": "847194127849",
"output": "255708"
},
{
"input": "294719472984",
"output": "593358"
},
{
"input": "999999911791",
"output": "1414213"
},
{
"input": "999999911792",
"output": "1"
},
{
"input": "100000000000000",
"output": "1749820"
},
{
"input": "1",
"output": "1"
},
{
"input": "99993",
"output": "312"
},
{
"input": "99994",
"output": "313"
},
{
"input": "99995",
"output": "314"
},
{
"input": "99990",
"output": "309"
},
{
"input": "2",
"output": "1"
},
{
"input": "99991",
"output": "310"
},
{
"input": "99992",
"output": "311"
},
{
"input": "99996",
"output": "315"
},
{
"input": "99997",
"output": "316"
},
{
"input": "99998",
"output": "317"
},
{
"input": "99999",
"output": "318"
},
{
"input": "1021",
"output": "31"
},
{
"input": "4",
"output": "1"
},
{
"input": "23",
"output": "2"
},
{
"input": "9994",
"output": "124"
},
{
"input": "99939",
"output": "258"
},
{
"input": "99999998250180",
"output": "14142135"
},
{
"input": "6",
"output": "3"
},
{
"input": "8",
"output": "2"
},
{
"input": "35",
"output": "7"
},
{
"input": "100",
"output": "9"
},
{
"input": "10101010",
"output": "745"
},
{
"input": "103",
"output": "12"
},
{
"input": "102",
"output": "11"
},
{
"input": "101",
"output": "10"
}
] | 530 | 1,331,200 | 3 | 68 |
|
581 | Vasya the Hipster | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 46 | 0 | 3 | 69 |
|
50 | Domino piling | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 124 | 0 | 3.969 | 70 |
500 | New Year Transportation | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system. | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1",
"output": "YES"
},
{
"input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1",
"output": "NO"
},
{
"input": "10 3\n8 3 5 4 2 3 2 2 1",
"output": "NO"
},
{
"input": "10 9\n8 3 5 4 2 3 2 2 1",
"output": "YES"
},
{
"input": "3 2\n1 1",
"output": "YES"
},
{
"input": "3 2\n2 1",
"output": "NO"
},
{
"input": "4 2\n2 1 1",
"output": "NO"
},
{
"input": "4 4\n2 2 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 1 1",
"output": "YES"
},
{
"input": "3 3\n2 1",
"output": "YES"
},
{
"input": "4 4\n1 1 1",
"output": "YES"
},
{
"input": "8 8\n1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5 5\n1 1 1 1",
"output": "YES"
}
] | 109 | 4,710,400 | 3 | 72 |
|
820 | Mister B and Book Reading | [
"implementation"
] | null | null | Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at second — *v*0<=+<=*a* pages, at third — *v*0<=+<=2*a* pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than *v*1 pages per day.
Also, to refresh his memory, every day, starting from the second, Mister B had to reread last *l* pages he read on the previous day. Mister B finished the book when he read the last page for the first time.
Help Mister B to calculate how many days he needed to finish the book. | First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=<<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading. | Print one integer — the number of days Mister B needed to finish the book. | [
"5 5 10 5 4\n",
"12 4 12 4 1\n",
"15 1 100 0 0\n"
] | [
"1\n",
"3\n",
"15\n"
] | In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished in 15 days. | [
{
"input": "5 5 10 5 4",
"output": "1"
},
{
"input": "12 4 12 4 1",
"output": "3"
},
{
"input": "15 1 100 0 0",
"output": "15"
},
{
"input": "1 1 1 0 0",
"output": "1"
},
{
"input": "1000 999 1000 1000 998",
"output": "2"
},
{
"input": "1000 2 2 5 1",
"output": "999"
},
{
"input": "1000 1 1 1000 0",
"output": "1000"
},
{
"input": "737 41 74 12 11",
"output": "13"
},
{
"input": "1000 1000 1000 0 999",
"output": "1"
},
{
"input": "765 12 105 5 7",
"output": "17"
},
{
"input": "15 2 2 1000 0",
"output": "8"
},
{
"input": "1000 1 1000 1000 0",
"output": "2"
},
{
"input": "20 3 7 1 2",
"output": "6"
},
{
"input": "1000 500 500 1000 499",
"output": "501"
},
{
"input": "1 1000 1000 1000 0",
"output": "1"
},
{
"input": "1000 2 1000 56 0",
"output": "7"
},
{
"input": "1000 2 1000 802 0",
"output": "3"
},
{
"input": "16 1 8 2 0",
"output": "4"
},
{
"input": "20 6 10 2 2",
"output": "3"
},
{
"input": "8 2 12 4 1",
"output": "3"
},
{
"input": "8 6 13 2 5",
"output": "2"
},
{
"input": "70 4 20 87 0",
"output": "5"
},
{
"input": "97 8 13 234 5",
"output": "13"
},
{
"input": "16 4 23 8 3",
"output": "3"
},
{
"input": "65 7 22 7 4",
"output": "5"
},
{
"input": "93 10 18 11 7",
"output": "9"
},
{
"input": "86 13 19 15 9",
"output": "9"
},
{
"input": "333 17 50 10 16",
"output": "12"
},
{
"input": "881 16 55 10 12",
"output": "23"
},
{
"input": "528 11 84 3 9",
"output": "19"
},
{
"input": "896 2 184 8 1",
"output": "16"
},
{
"input": "236 10 930 9 8",
"output": "8"
},
{
"input": "784 1 550 14 0",
"output": "12"
},
{
"input": "506 1 10 4 0",
"output": "53"
},
{
"input": "460 1 3 2 0",
"output": "154"
},
{
"input": "701 1 3 1 0",
"output": "235"
},
{
"input": "100 49 50 1000 2",
"output": "3"
},
{
"input": "100 1 100 100 0",
"output": "2"
},
{
"input": "12 1 4 2 0",
"output": "4"
},
{
"input": "22 10 12 0 0",
"output": "3"
},
{
"input": "20 10 15 1 4",
"output": "3"
},
{
"input": "1000 5 10 1 4",
"output": "169"
},
{
"input": "1000 1 1000 1 0",
"output": "45"
},
{
"input": "4 1 2 2 0",
"output": "3"
},
{
"input": "1 5 5 1 1",
"output": "1"
},
{
"input": "19 10 11 0 2",
"output": "3"
},
{
"input": "1 2 3 0 0",
"output": "1"
},
{
"input": "10 1 4 10 0",
"output": "4"
},
{
"input": "20 3 100 1 1",
"output": "5"
},
{
"input": "1000 5 9 5 0",
"output": "112"
},
{
"input": "1 11 12 0 10",
"output": "1"
},
{
"input": "1 1 1 1 0",
"output": "1"
},
{
"input": "1000 1 20 1 0",
"output": "60"
},
{
"input": "9 1 4 2 0",
"output": "4"
},
{
"input": "129 2 3 4 0",
"output": "44"
},
{
"input": "4 2 2 0 1",
"output": "3"
},
{
"input": "1000 1 10 100 0",
"output": "101"
},
{
"input": "100 1 100 1 0",
"output": "14"
},
{
"input": "8 3 4 2 0",
"output": "3"
},
{
"input": "20 1 6 4 0",
"output": "5"
},
{
"input": "8 2 4 2 0",
"output": "3"
},
{
"input": "11 5 6 7 2",
"output": "3"
},
{
"input": "100 120 130 120 0",
"output": "1"
},
{
"input": "7 1 4 1 0",
"output": "4"
},
{
"input": "5 3 10 0 2",
"output": "3"
},
{
"input": "5 2 2 0 0",
"output": "3"
},
{
"input": "1000 10 1000 10 0",
"output": "14"
},
{
"input": "25 3 50 4 2",
"output": "4"
},
{
"input": "9 10 10 10 9",
"output": "1"
},
{
"input": "17 10 12 6 5",
"output": "2"
},
{
"input": "15 5 10 3 0",
"output": "3"
},
{
"input": "8 3 5 1 0",
"output": "3"
},
{
"input": "19 1 12 5 0",
"output": "4"
},
{
"input": "1000 10 1000 1 0",
"output": "37"
},
{
"input": "100 1 2 1000 0",
"output": "51"
},
{
"input": "20 10 11 1000 9",
"output": "6"
},
{
"input": "16 2 100 1 1",
"output": "5"
},
{
"input": "18 10 13 2 5",
"output": "3"
},
{
"input": "12 3 5 3 1",
"output": "4"
},
{
"input": "17 3 11 2 0",
"output": "4"
},
{
"input": "4 2 100 1 1",
"output": "2"
},
{
"input": "7 4 5 2 3",
"output": "3"
},
{
"input": "100 1 2 2 0",
"output": "51"
},
{
"input": "50 4 5 5 0",
"output": "11"
},
{
"input": "1 2 2 0 1",
"output": "1"
},
{
"input": "1000 2 3 10 1",
"output": "500"
},
{
"input": "500 10 500 1000 0",
"output": "2"
},
{
"input": "1000 4 12 1 0",
"output": "87"
},
{
"input": "18 10 13 1 5",
"output": "3"
},
{
"input": "7 3 6 2 2",
"output": "3"
},
{
"input": "15 5 100 1 2",
"output": "4"
},
{
"input": "100 1 10 1 0",
"output": "15"
},
{
"input": "8 2 7 5 1",
"output": "2"
},
{
"input": "11 2 4 1 1",
"output": "5"
},
{
"input": "1000 500 900 100 300",
"output": "3"
},
{
"input": "7 1 2 5 0",
"output": "4"
},
{
"input": "7 3 5 3 2",
"output": "3"
},
{
"input": "7 3 10 2 1",
"output": "2"
},
{
"input": "1000 501 510 1 499",
"output": "50"
},
{
"input": "1000 1 1000 2 0",
"output": "32"
},
{
"input": "1 5 5 0 0",
"output": "1"
},
{
"input": "18 10 15 1 5",
"output": "3"
},
{
"input": "100 4 1000 1 2",
"output": "13"
},
{
"input": "20 2 40 1 1",
"output": "6"
},
{
"input": "1 11 1000 100 1",
"output": "1"
},
{
"input": "6 4 4 1 2",
"output": "2"
},
{
"input": "8 3 5 3 1",
"output": "3"
},
{
"input": "10 5 7 1 2",
"output": "3"
},
{
"input": "400 100 198 1 99",
"output": "25"
},
{
"input": "3 1 2 5 0",
"output": "2"
}
] | 124 | 23,142,400 | 3 | 73 |
|
1 | Theatre Square | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 31 | 0 | 0 | 74 |
61 | Ultra-Fast Mathematician | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 46 | 0 | 3.9885 | 75 |
356 | Knight Tournament | [
"data structures",
"dsu"
] | null | null | Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tournament (it was a weekend, after all). Now you are really curious about the results of the tournament. This time the tournament in Berland went as follows:
- There are *n* knights participating in the tournament. Each knight was assigned his unique number — an integer from 1 to *n*. - The tournament consisted of *m* fights, in the *i*-th fight the knights that were still in the game with numbers at least *l**i* and at most *r**i* have fought for the right to continue taking part in the tournament. - After the *i*-th fight among all participants of the fight only one knight won — the knight number *x**i*, he continued participating in the tournament. Other knights left the tournament. - The winner of the last (the *m*-th) fight (the knight number *x**m*) became the winner of the tournament.
You fished out all the information about the fights from your friends. Now for each knight you want to know the name of the knight he was conquered by. We think that the knight number *b* was conquered by the knight number *a*, if there was a fight with both of these knights present and the winner was the knight number *a*.
Write the code that calculates for each knight, the name of the knight that beat him. | The first line contains two integers *n*, *m* (2<=≤<=*n*<=≤<=3·105; 1<=≤<=*m*<=≤<=3·105) — the number of knights and the number of fights. Each of the following *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*; *l**i*<=≤<=*x**i*<=≤<=*r**i*) — the description of the *i*-th fight.
It is guaranteed that the input is correct and matches the problem statement. It is guaranteed that at least two knights took part in each battle. | Print *n* integers. If the *i*-th knight lost, then the *i*-th number should equal the number of the knight that beat the knight number *i*. If the *i*-th knight is the winner, then the *i*-th number must equal 0. | [
"4 3\n1 2 1\n1 3 3\n1 4 4\n",
"8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n"
] | [
"3 1 4 0 ",
"0 8 4 6 4 8 6 1 "
] | Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won. | [
{
"input": "4 3\n1 2 1\n1 3 3\n1 4 4",
"output": "3 1 4 0 "
},
{
"input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1",
"output": "0 8 4 6 4 8 6 1 "
},
{
"input": "2 1\n1 2 1",
"output": "0 1 "
},
{
"input": "2 1\n1 2 2",
"output": "2 0 "
},
{
"input": "3 1\n1 3 1",
"output": "0 1 1 "
},
{
"input": "3 1\n1 3 2",
"output": "2 0 2 "
},
{
"input": "3 1\n1 3 3",
"output": "3 3 0 "
},
{
"input": "3 2\n1 2 1\n1 3 3",
"output": "3 1 0 "
},
{
"input": "3 2\n1 2 2\n1 3 2",
"output": "2 0 2 "
},
{
"input": "3 2\n2 3 3\n1 3 3",
"output": "3 3 0 "
},
{
"input": "11 6\n1 2 2\n7 8 7\n3 4 4\n6 9 6\n5 10 10\n2 11 11",
"output": "2 11 4 11 10 10 6 7 6 11 0 "
},
{
"input": "10 6\n9 10 10\n6 7 7\n2 4 2\n2 5 5\n1 7 5\n4 10 8",
"output": "5 5 2 2 8 7 5 0 10 8 "
},
{
"input": "11 8\n3 5 5\n8 9 9\n4 6 6\n8 10 10\n5 7 7\n2 7 2\n10 11 11\n1 11 1",
"output": "0 1 5 5 6 7 2 9 10 11 1 "
},
{
"input": "10 7\n7 8 7\n7 9 9\n5 9 5\n5 10 10\n1 2 2\n3 4 4\n2 10 4",
"output": "2 4 4 0 10 5 9 7 5 4 "
},
{
"input": "11 5\n8 10 9\n6 10 7\n6 11 11\n3 5 5\n1 11 1",
"output": "0 1 5 5 1 7 11 9 7 9 1 "
},
{
"input": "10 6\n6 7 6\n5 7 5\n3 7 4\n2 8 2\n2 10 10\n1 10 10",
"output": "10 10 4 2 4 5 6 2 10 0 "
},
{
"input": "11 7\n7 8 8\n5 6 5\n1 3 3\n7 9 9\n5 10 10\n10 11 11\n1 11 4",
"output": "3 3 4 0 10 5 8 9 10 11 4 "
},
{
"input": "10 7\n8 9 9\n3 4 3\n2 3 2\n1 5 2\n6 7 6\n6 10 10\n1 10 10",
"output": "2 10 2 3 2 10 6 9 10 0 "
},
{
"input": "11 6\n1 2 1\n8 9 9\n3 5 5\n3 6 6\n9 10 10\n1 11 10",
"output": "10 1 5 5 6 10 10 9 10 0 10 "
},
{
"input": "10 5\n1 2 1\n8 10 8\n3 6 4\n4 7 7\n1 8 7",
"output": "7 1 4 7 4 4 0 7 8 8 "
},
{
"input": "4 3\n1 2 2\n1 3 3\n1 4 4",
"output": "2 3 4 0 "
}
] | 1,715 | 11,468,800 | 0 | 76 |
|
600 | Queries about less or equal elements | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -929612742 -787653860 -684738874",
"output": "11 9 8 2 2 1 5 5 0 0 1"
},
{
"input": "20 22\n858276994 -568758442 -918490847 -983345984 -172435358 389604931 200224783 486556113 413281867 -258259500 -627945379 -584563643 444685477 -602481243 -370745158 965672503 630955806 -626138773 -997221880 633102929\n-61330638 -977252080 -212144219 385501731 669589742 954357160 563935906 584468977 -895883477 405774444 853372186 186056475 -964575261 -952431965 632332084 -388829939 -23011650 310957048 -770695392 977376693 321435214 199223897",
"output": "11 2 10 12 18 19 16 16 3 13 18 11 2 2 17 8 11 12 3 20 12 11"
},
{
"input": "5 9\n1 3 5 7 9\n1 2 3 4 5 6 7 8 9",
"output": "1 1 2 2 3 3 4 4 5"
},
{
"input": "22 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22\n1",
"output": "1"
},
{
"input": "5 1\n1 3 3 3 5\n3",
"output": "4"
},
{
"input": "4 5\n1 1 1 4\n1 5 5 4 3",
"output": "3 4 4 4 3"
},
{
"input": "5 4\n0 5 5 5 6\n5 1 6 3",
"output": "4 1 5 1"
},
{
"input": "1 3\n0\n-1 0 1",
"output": "0 1 1"
},
{
"input": "96 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1",
"output": "96"
},
{
"input": "7 1\n1 2 3 4 5 6 7\n1",
"output": "1"
},
{
"input": "13 13\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000",
"output": "7 13 7 13 7 13 7 13 7 13 7 13 7"
},
{
"input": "9 5\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5",
"output": "1 2 3 4 5"
},
{
"input": "3 8\n1 1 1\n1 1 1 1 1 1 1 1",
"output": "3 3 3 3 3 3 3 3"
},
{
"input": "1 1\n-11111\n-5938",
"output": "1"
},
{
"input": "1 1\n1\n400000009",
"output": "1"
},
{
"input": "1 1\n1\n300000009",
"output": "1"
},
{
"input": "1 1\n1\n200000009",
"output": "1"
},
{
"input": "1 1\n1\n200000003",
"output": "1"
}
] | 15 | 0 | 0 | 77 |
|
579 | Raising Bacteria | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days? | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697681824",
"output": "14"
},
{
"input": "41313494",
"output": "14"
},
{
"input": "673935585",
"output": "13"
},
{
"input": "117422204",
"output": "19"
},
{
"input": "954746654",
"output": "15"
},
{
"input": "536838144",
"output": "14"
},
{
"input": "1000000000",
"output": "13"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "1"
},
{
"input": "6",
"output": "2"
},
{
"input": "7",
"output": "3"
},
{
"input": "9",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "999999999",
"output": "21"
},
{
"input": "999999998",
"output": "20"
},
{
"input": "999999997",
"output": "20"
},
{
"input": "999999996",
"output": "19"
},
{
"input": "999999995",
"output": "20"
},
{
"input": "999999994",
"output": "19"
},
{
"input": "999999993",
"output": "19"
},
{
"input": "999999992",
"output": "18"
},
{
"input": "999999991",
"output": "20"
},
{
"input": "999999990",
"output": "19"
},
{
"input": "536870910",
"output": "28"
},
{
"input": "536870912",
"output": "1"
},
{
"input": "536870913",
"output": "2"
},
{
"input": "536870914",
"output": "2"
},
{
"input": "22",
"output": "3"
},
{
"input": "14",
"output": "3"
}
] | 30 | 0 | 0 | 79 |
|
58 | Chat room | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 31 | 0 | 0 | 80 |
799 | Aquarium decoration | [
"data structures",
"greedy",
"two pointers"
] | null | null | Arkady and Masha want to choose decorations for thier aquarium in Fishdom game. They have *n* decorations to choose from, each of them has some cost. To complete a task Arkady and Masha need to choose exactly *m* decorations from given, and they want to spend as little money as possible.
There is one difficulty: Masha likes some *a* of the given decorations, Arkady likes some *b* of the given decorations. Some decorations may be liked by both Arkady and Masha, or not be liked by both. The friends want to choose such decorations so that each of them likes at least *k* decorations among the chosen. Help Masha and Arkady find the minimum sum of money they need to spend. | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=200000, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=*n*) — the number of decorations, how many decorations the friends should choose, how many decorations each of them should like among the chosen.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=109) — decorations costs.
The third line contains single integer *a* (1<=≤<=*a*<=≤<=*n*) — the number of decorations liked by Masha. The fourth line contains *a* distinct integers *x*1,<=*x*2,<=...,<=*x**a* (1<=≤<=*x**i*<=≤<=*n*) — the ids of decorations liked by Masha.
The next two lines describe decorations liked by Arkady in the same format. | Print single integer: the minimum sum of money the friends should spend to fulfill all constraints. If it is not possible, print -1. | [
"4 3 2\n3 2 2 1\n2\n1 2\n2\n1 3\n",
"4 3 2\n3 2 2 1\n2\n1 2\n3\n4 1 3\n",
"4 2 2\n3 2 2 1\n2\n1 2\n3\n4 1 3\n"
] | [
"7\n",
"6\n",
"-1\n"
] | In the first example the only possible variant to choose 3 decorations having all conditions satisfied is to choose decorations 1, 2, 3.
In the second example friends can choose decoration 4 instead of decoration 3, because this one is one coin cheaper.
In the third example it's not possible to choose 2 decorations in a way that both are liked by both Masha and Arkady. | [
{
"input": "4 3 2\n3 2 2 1\n2\n1 2\n2\n1 3",
"output": "7"
},
{
"input": "4 3 2\n3 2 2 1\n2\n1 2\n3\n4 1 3",
"output": "6"
},
{
"input": "4 2 2\n3 2 2 1\n2\n1 2\n3\n4 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1\n1\n1\n1\n1",
"output": "1"
},
{
"input": "2 1 1\n1 2\n1\n1\n1\n1",
"output": "1"
},
{
"input": "2 2 1\n1 2\n1\n1\n1\n2",
"output": "3"
},
{
"input": "2 1 2\n1 2\n1\n1\n1\n1",
"output": "-1"
},
{
"input": "2 1 2\n1 2\n1\n2\n1\n1",
"output": "-1"
},
{
"input": "6 6 5\n5 6 9 4 9 6\n6\n5 3 2 1 4 6\n6\n2 4 1 5 3 6",
"output": "39"
},
{
"input": "8 6 2\n2 6 2 1 5 5 4 8\n2\n7 5\n2\n7 1",
"output": "19"
},
{
"input": "10 8 5\n3 6 8 5 6 14 16 8 20 17\n6\n2 9 5 1 8 4\n6\n7 6 4 9 8 2",
"output": "66"
},
{
"input": "12 10 5\n8 1 3 8 5 10 7 12 1 11 2 1\n5\n6 12 10 9 1\n5\n5 4 3 2 11",
"output": "50"
},
{
"input": "10 8 9\n12 2 7 2 4 1 20 19 1 5\n10\n3 10 1 6 7 5 8 2 4 9\n10\n6 9 3 8 5 10 2 7 4 1",
"output": "-1"
},
{
"input": "10 8 6\n1 5 9 7 5 1 2 3 3 8\n7\n8 4 10 6 9 2 7\n7\n5 6 2 1 4 8 7",
"output": "27"
},
{
"input": "10 9 6\n18 12 15 3 17 20 6 18 11 12\n7\n5 7 9 10 2 1 4\n8\n9 2 6 1 5 3 7 8",
"output": "112"
},
{
"input": "6 5 1\n1 2 3 4 5 1000\n2\n1 6\n3\n1 2 6",
"output": "15"
},
{
"input": "6 1 1\n1 2 3 4 5 1000\n2\n1 6\n3\n1 2 6",
"output": "1"
},
{
"input": "6 5 2\n1 2 3 4 5 1000\n2\n1 6\n3\n4 5 6",
"output": "1010"
},
{
"input": "6 4 2\n1 2 3 4 5 1000\n3\n1 2 6\n3\n4 5 6",
"output": "12"
},
{
"input": "6 3 2\n1 2 3 4 5 1000\n3\n1 2 6\n3\n4 5 6",
"output": "1005"
}
] | 46 | 0 | 0 | 81 |
|
991 | If at first you don't succeed... | [
"implementation"
] | null | null | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time? | The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). | If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$. | [
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] | [
"5",
"-1",
"-1"
] | The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible. | [
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
},
{
"input": "6 7 5 8",
"output": "-1"
},
{
"input": "6 7 5 9",
"output": "1"
},
{
"input": "6 7 5 7",
"output": "-1"
},
{
"input": "50 50 1 100",
"output": "1"
},
{
"input": "8 3 2 12",
"output": "3"
},
{
"input": "10 19 6 25",
"output": "2"
},
{
"input": "1 0 0 99",
"output": "98"
},
{
"input": "0 1 0 98",
"output": "97"
},
{
"input": "1 1 0 97",
"output": "95"
},
{
"input": "1 1 1 96",
"output": "95"
},
{
"input": "0 0 0 0",
"output": "-1"
},
{
"input": "100 0 0 0",
"output": "-1"
},
{
"input": "0 100 0 0",
"output": "-1"
},
{
"input": "100 100 0 0",
"output": "-1"
},
{
"input": "0 0 100 0",
"output": "-1"
},
{
"input": "100 0 100 0",
"output": "-1"
},
{
"input": "0 100 100 0",
"output": "-1"
},
{
"input": "100 100 100 0",
"output": "-1"
},
{
"input": "0 0 0 100",
"output": "100"
},
{
"input": "100 0 0 100",
"output": "-1"
},
{
"input": "0 100 0 100",
"output": "-1"
},
{
"input": "100 100 0 100",
"output": "-1"
},
{
"input": "0 0 100 100",
"output": "-1"
},
{
"input": "100 0 100 100",
"output": "-1"
},
{
"input": "0 100 100 100",
"output": "-1"
},
{
"input": "100 100 100 100",
"output": "-1"
},
{
"input": "10 45 7 52",
"output": "4"
},
{
"input": "38 1 1 68",
"output": "30"
},
{
"input": "8 45 2 67",
"output": "16"
},
{
"input": "36 36 18 65",
"output": "11"
},
{
"input": "10 30 8 59",
"output": "27"
},
{
"input": "38 20 12 49",
"output": "3"
},
{
"input": "8 19 4 38",
"output": "15"
},
{
"input": "36 21 17 72",
"output": "32"
},
{
"input": "14 12 12 89",
"output": "75"
},
{
"input": "38 6 1 44",
"output": "1"
},
{
"input": "13 4 6 82",
"output": "-1"
},
{
"input": "5 3 17 56",
"output": "-1"
},
{
"input": "38 5 29 90",
"output": "-1"
},
{
"input": "22 36 18 55",
"output": "15"
},
{
"input": "13 0 19 75",
"output": "-1"
},
{
"input": "62 65 10 89",
"output": "-1"
},
{
"input": "2 29 31 72",
"output": "-1"
},
{
"input": "1 31 19 55",
"output": "-1"
},
{
"input": "1 25 28 88",
"output": "-1"
},
{
"input": "34 32 28 33",
"output": "-1"
},
{
"input": "43 36 1 100",
"output": "22"
},
{
"input": "16 39 55 70",
"output": "-1"
},
{
"input": "2 3 0 91",
"output": "86"
},
{
"input": "55 29 12 48",
"output": "-1"
},
{
"input": "7 33 20 88",
"output": "-1"
},
{
"input": "40 38 27 99",
"output": "48"
},
{
"input": "18 28 14 84",
"output": "52"
},
{
"input": "34 25 25 92",
"output": "58"
},
{
"input": "4 24 5 76",
"output": "-1"
},
{
"input": "5 22 16 96",
"output": "-1"
},
{
"input": "1 1 0 4",
"output": "2"
},
{
"input": "5 5 3 1",
"output": "-1"
},
{
"input": "0 0 0 1",
"output": "1"
},
{
"input": "2 3 0 8",
"output": "3"
},
{
"input": "5 5 2 5",
"output": "-1"
},
{
"input": "1 2 1 3",
"output": "1"
},
{
"input": "3 0 0 4",
"output": "1"
},
{
"input": "0 0 0 5",
"output": "5"
},
{
"input": "5 5 0 3",
"output": "-1"
},
{
"input": "5 6 1 7",
"output": "-1"
},
{
"input": "10 10 10 11",
"output": "1"
},
{
"input": "0 0 0 10",
"output": "10"
},
{
"input": "5 15 5 30",
"output": "15"
},
{
"input": "3 2 0 7",
"output": "2"
}
] | 108 | 0 | 0 | 82 |
|
393 | Nineteen | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters.
Help her to find the maximum number of "nineteen"s that she can get in her string. | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss",
"output": "1"
},
{
"input": "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs",
"output": "2"
},
{
"input": "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi",
"output": "2"
},
{
"input": "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn",
"output": "1"
},
{
"input": "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti",
"output": "2"
},
{
"input": "rmeetriiitijmrenmeiijt",
"output": "0"
},
{
"input": "ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne",
"output": "1"
},
{
"input": "rhtsnmnesieernhstjnmmirthhieejsjttsiierhihhrrijhrrnejsjer",
"output": "2"
},
{
"input": "emmtjsjhretehmiiiestmtmnmissjrstnsnjmhimjmststsitemtttjrnhsrmsenjtjim",
"output": "2"
},
{
"input": "nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm",
"output": "3"
},
{
"input": "hsntijjetmehejtsitnthietssmeenjrhhetsnjrsethisjrtrhrierjtmimeenjnhnijeesjttrmn",
"output": "3"
},
{
"input": "jnirirhmirmhisemittnnsmsttesjhmjnsjsmntisheneiinsrjsjirnrmnjmjhmistntersimrjni",
"output": "1"
},
{
"input": "neithjhhhtmejjnmieishethmtetthrienrhjmjenrmtejerernmthmsnrthhtrimmtmshm",
"output": "2"
},
{
"input": "sithnrsnemhijsnjitmijjhejjrinejhjinhtisttteermrjjrtsirmessejireihjnnhhemiirmhhjeet",
"output": "3"
},
{
"input": "jrjshtjstteh",
"output": "0"
},
{
"input": "jsihrimrjnnmhttmrtrenetimemjnshnimeiitmnmjishjjneisesrjemeshjsijithtn",
"output": "2"
},
{
"input": "hhtjnnmsemermhhtsstejehsssmnesereehnnsnnremjmmieethmirjjhn",
"output": "2"
},
{
"input": "tmnersmrtsehhntsietttrehrhneiireijnijjejmjhei",
"output": "1"
},
{
"input": "mtstiresrtmesritnjriirehtermtrtseirtjrhsejhhmnsineinsjsin",
"output": "2"
},
{
"input": "ssitrhtmmhtnmtreijteinimjemsiiirhrttinsnneshintjnin",
"output": "1"
},
{
"input": "rnsrsmretjiitrjthhritniijhjmm",
"output": "0"
},
{
"input": "hntrteieimrimteemenserntrejhhmijmtjjhnsrsrmrnsjseihnjmehtthnnithirnhj",
"output": "3"
},
{
"input": "nmmtsmjrntrhhtmimeresnrinstjnhiinjtnjjjnthsintmtrhijnrnmtjihtinmni",
"output": "0"
},
{
"input": "eihstiirnmteejeehimttrijittjsntjejmessstsemmtristjrhenithrrsssihnthheehhrnmimssjmejjreimjiemrmiis",
"output": "2"
},
{
"input": "srthnimimnemtnmhsjmmmjmmrsrisehjseinemienntetmitjtnnneseimhnrmiinsismhinjjnreehseh",
"output": "3"
},
{
"input": "etrsmrjehntjjimjnmsresjnrthjhehhtreiijjminnheeiinseenmmethiemmistsei",
"output": "3"
},
{
"input": "msjeshtthsieshejsjhsnhejsihisijsertenrshhrthjhiirijjneinjrtrmrs",
"output": "1"
},
{
"input": "mehsmstmeejrhhsjihntjmrjrihssmtnensttmirtieehimj",
"output": "1"
},
{
"input": "mmmsermimjmrhrhejhrrejermsneheihhjemnehrhihesnjsehthjsmmjeiejmmnhinsemjrntrhrhsmjtttsrhjjmejj",
"output": "2"
},
{
"input": "rhsmrmesijmmsnsmmhertnrhsetmisshriirhetmjihsmiinimtrnitrseii",
"output": "1"
},
{
"input": "iihienhirmnihh",
"output": "0"
},
{
"input": "ismtthhshjmhisssnmnhe",
"output": "0"
},
{
"input": "rhsmnrmhejshinnjrtmtsssijimimethnm",
"output": "0"
},
{
"input": "eehnshtiriejhiirntminrirnjihmrnittnmmnjejjhjtennremrnssnejtntrtsiejjijisermj",
"output": "3"
},
{
"input": "rnhmeesnhttrjintnhnrhristjrthhrmehrhjmjhjehmstrijemjmmistes",
"output": "2"
},
{
"input": "ssrmjmjeeetrnimemrhimes",
"output": "0"
},
{
"input": "n",
"output": "0"
},
{
"input": "ni",
"output": "0"
},
{
"input": "nine",
"output": "0"
},
{
"input": "nineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteen",
"output": "13"
},
{
"input": "ninetee",
"output": "0"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwynd",
"output": "0"
},
{
"input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdch",
"output": "0"
},
{
"input": "rtzxovxqfapkdmelxiyjroohufhbakpmmvaxq",
"output": "0"
},
{
"input": "zninetneeineteeniwnteeennieteenineteenineteenineteenineteenineteenineteenineteenineteeninetzeenz",
"output": "13"
},
{
"input": "nnnnnnniiiiiiiiiiiitttttttttteeeeeeeeeeeeeeeeee",
"output": "3"
},
{
"input": "ttttiiiieeeeeeeeeeeennnnnnnnn",
"output": "4"
},
{
"input": "ttttttttteeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiinnnnnnn",
"output": "3"
},
{
"input": "nnnnnnnnnneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiiiiitttttttttttttttttttt",
"output": "4"
},
{
"input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiittttttttttttttttnnnnnnn",
"output": "3"
},
{
"input": "nineeen",
"output": "0"
},
{
"input": "nineteeeeeeeeeeeeeeeeettttttttttttttttttiiiiiiiiiiiiiiiiii",
"output": "0"
},
{
"input": "nineteenieteenieteenieteenieteenieteenieteen",
"output": "4"
},
{
"input": "nineteenineteenineteenineteenineteen",
"output": "5"
}
] | 108 | 0 | 0 | 83 |
|
3 | Tic-tac-toe | [
"brute force",
"games",
"implementation"
] | C. Tic-tac-toe | 1 | 64 | Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.
You are given a 3<=×<=3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:
- illegal — if the given board layout can't appear during a valid game; - the first player won — if in the given board layout the first player has just won; - the second player won — if in the given board layout the second player has just won; - draw — if the given board layout has just let to a draw. | The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero). | Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw. | [
"X0X\n.0.\n.X.\n"
] | [
"second\n"
] | none | [
{
"input": "X0X\n.0.\n.X.",
"output": "second"
},
{
"input": "0.X\nXX.\n000",
"output": "illegal"
},
{
"input": "XXX\n.0.\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n000",
"output": "illegal"
},
{
"input": "X.X\nX..\n00.",
"output": "second"
},
{
"input": "X.X\nX.0\n0.0",
"output": "first"
},
{
"input": "XXX\nX00\nX00",
"output": "the first player won"
},
{
"input": "000\nX.X\nX.X",
"output": "illegal"
},
{
"input": "XXX\n0.0\n0..",
"output": "illegal"
},
{
"input": "X0X\n0X0\nX0X",
"output": "the first player won"
},
{
"input": "XX.\nX0X\nX..",
"output": "illegal"
},
{
"input": "X0X\n0X0\nX..",
"output": "the first player won"
},
{
"input": "XX0\n0..\n000",
"output": "illegal"
},
{
"input": "XXX\n0..\n.0.",
"output": "the first player won"
},
{
"input": "XXX\nX..\n.00",
"output": "illegal"
},
{
"input": "X00\n0.0\nXX0",
"output": "illegal"
},
{
"input": "0.0\n0XX\n..0",
"output": "illegal"
},
{
"input": ".00\nX.X\n0..",
"output": "illegal"
},
{
"input": "..0\n.00\n.0X",
"output": "illegal"
},
{
"input": "..0\n0..\n00X",
"output": "illegal"
},
{
"input": "..0\n.XX\nX..",
"output": "illegal"
},
{
"input": "0.X\n0X0\n.00",
"output": "illegal"
},
{
"input": "..X\n0X0\n0X.",
"output": "first"
},
{
"input": "0X0\nX..\nX.0",
"output": "first"
},
{
"input": ".0.\nX.X\n0..",
"output": "first"
},
{
"input": "0X0\n00X\n.00",
"output": "illegal"
},
{
"input": ".0.\n.X0\nX..",
"output": "first"
},
{
"input": "00X\n0.X\n00X",
"output": "illegal"
},
{
"input": "00X\n0XX\n0X.",
"output": "the second player won"
},
{
"input": "X00\n..0\nX.X",
"output": "first"
},
{
"input": "X00\nX00\n.X0",
"output": "illegal"
},
{
"input": "X0X\n.X0\n0..",
"output": "first"
},
{
"input": "..0\nXXX\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n.0.",
"output": "illegal"
},
{
"input": "0..\n000\nX0X",
"output": "illegal"
},
{
"input": ".00\n0X.\n0.0",
"output": "illegal"
},
{
"input": "X..\nX00\n0.0",
"output": "illegal"
},
{
"input": ".X0\nXX0\nX.X",
"output": "illegal"
},
{
"input": "X.X\n0.0\nX..",
"output": "second"
},
{
"input": "00X\n.00\n..0",
"output": "illegal"
},
{
"input": "..0\n0.X\n00.",
"output": "illegal"
},
{
"input": "0.X\nX0X\n.X0",
"output": "illegal"
},
{
"input": "0X.\n.X.\n0X0",
"output": "illegal"
},
{
"input": "00.\nX0.\n..X",
"output": "illegal"
},
{
"input": "..X\n.00\nXX.",
"output": "second"
},
{
"input": ".00\n.0.\n.X.",
"output": "illegal"
},
{
"input": "XX0\nX.0\nXX0",
"output": "illegal"
},
{
"input": "00.\n00.\nX.X",
"output": "illegal"
},
{
"input": "X00\nX.0\nX.0",
"output": "illegal"
},
{
"input": "0X.\n0XX\n000",
"output": "illegal"
},
{
"input": "00.\n00.\n.X.",
"output": "illegal"
},
{
"input": "X0X\n00.\n0.X",
"output": "illegal"
},
{
"input": "XX0\nXXX\n0X0",
"output": "illegal"
},
{
"input": "XX0\n..X\nXX0",
"output": "illegal"
},
{
"input": "0X.\n..X\nX..",
"output": "illegal"
},
{
"input": "...\nX0.\nXX0",
"output": "second"
},
{
"input": "..X\n.0.\n0..",
"output": "illegal"
},
{
"input": "00X\nXX.\n00X",
"output": "first"
},
{
"input": "..0\nXX0\n..X",
"output": "second"
},
{
"input": ".0.\n.00\nX00",
"output": "illegal"
},
{
"input": "X00\n.XX\n00.",
"output": "illegal"
},
{
"input": ".00\n0.X\n000",
"output": "illegal"
},
{
"input": "X0.\n..0\nX.0",
"output": "illegal"
},
{
"input": "X0X\n.XX\n00.",
"output": "second"
},
{
"input": "0X.\n00.\n.X.",
"output": "illegal"
},
{
"input": ".0.\n...\n0.0",
"output": "illegal"
},
{
"input": "..X\nX00\n0.0",
"output": "illegal"
},
{
"input": "0XX\n...\nX0.",
"output": "second"
},
{
"input": "X.X\n0X.\n.0X",
"output": "illegal"
},
{
"input": "XX0\nX.X\n00.",
"output": "second"
},
{
"input": ".0X\n.00\n00.",
"output": "illegal"
},
{
"input": ".XX\nXXX\n0..",
"output": "illegal"
},
{
"input": "XX0\n.X0\n.0.",
"output": "first"
},
{
"input": "X00\n0.X\nX..",
"output": "first"
},
{
"input": "X..\n.X0\nX0.",
"output": "second"
},
{
"input": ".0X\nX..\nXXX",
"output": "illegal"
},
{
"input": "X0X\nXXX\nX.X",
"output": "illegal"
},
{
"input": ".00\nX0.\n00X",
"output": "illegal"
},
{
"input": "0XX\n.X0\n0.0",
"output": "illegal"
},
{
"input": "00X\nXXX\n..0",
"output": "the first player won"
},
{
"input": "X0X\n...\n.X.",
"output": "illegal"
},
{
"input": ".X0\n...\n0X.",
"output": "first"
},
{
"input": "X..\n0X0\nX.0",
"output": "first"
},
{
"input": "..0\n.00\nX.0",
"output": "illegal"
},
{
"input": ".XX\n.0.\nX0X",
"output": "illegal"
},
{
"input": "00.\n0XX\n..0",
"output": "illegal"
},
{
"input": ".0.\n00.\n00.",
"output": "illegal"
},
{
"input": "00.\n000\nX.X",
"output": "illegal"
},
{
"input": "0X0\n.X0\n.X.",
"output": "illegal"
},
{
"input": "00X\n0..\n0..",
"output": "illegal"
},
{
"input": ".X.\n.X0\nX.0",
"output": "second"
},
{
"input": ".0.\n0X0\nX0X",
"output": "illegal"
},
{
"input": "...\nX.0\n0..",
"output": "illegal"
},
{
"input": "..0\nXX.\n00X",
"output": "first"
},
{
"input": "0.X\n.0X\nX00",
"output": "illegal"
},
{
"input": "..X\n0X.\n.0.",
"output": "first"
},
{
"input": "..X\nX.0\n.0X",
"output": "second"
},
{
"input": "X0.\n.0X\nX0X",
"output": "illegal"
},
{
"input": "...\n.0.\n.X0",
"output": "illegal"
},
{
"input": ".X0\nXX0\n0..",
"output": "first"
},
{
"input": "0X.\n...\nX..",
"output": "second"
},
{
"input": ".0.\n0.0\n0.X",
"output": "illegal"
},
{
"input": "XX.\n.X0\n.0X",
"output": "illegal"
},
{
"input": ".0.\nX0X\nX00",
"output": "illegal"
},
{
"input": "0X.\n.X0\nX..",
"output": "second"
},
{
"input": "..0\n0X.\n000",
"output": "illegal"
},
{
"input": "0.0\nX.X\nXX.",
"output": "illegal"
},
{
"input": ".X.\n.XX\nX0.",
"output": "illegal"
},
{
"input": "X.X\n.XX\n0X.",
"output": "illegal"
},
{
"input": "X.0\n0XX\n..0",
"output": "first"
},
{
"input": "X.0\n0XX\n.X0",
"output": "second"
},
{
"input": "X00\n0XX\n.X0",
"output": "first"
},
{
"input": "X00\n0XX\nXX0",
"output": "draw"
},
{
"input": "X00\n0XX\n0X0",
"output": "illegal"
},
{
"input": "XXX\nXXX\nXXX",
"output": "illegal"
},
{
"input": "000\n000\n000",
"output": "illegal"
},
{
"input": "XX0\n00X\nXX0",
"output": "draw"
},
{
"input": "X00\n00X\nXX0",
"output": "illegal"
},
{
"input": "X.0\n00.\nXXX",
"output": "the first player won"
},
{
"input": "X..\nX0.\nX0.",
"output": "the first player won"
},
{
"input": ".XX\n000\nXX0",
"output": "the second player won"
},
{
"input": "X0.\nX.X\nX00",
"output": "the first player won"
},
{
"input": "00X\nX00\nXXX",
"output": "the first player won"
},
{
"input": "XXX\n.00\nX0.",
"output": "the first player won"
},
{
"input": "XX0\n000\nXX.",
"output": "the second player won"
},
{
"input": ".X0\n0.0\nXXX",
"output": "the first player won"
},
{
"input": "0XX\nX00\n0XX",
"output": "draw"
},
{
"input": "0XX\nX0X\n00X",
"output": "the first player won"
},
{
"input": "XX0\n0XX\n0X0",
"output": "the first player won"
},
{
"input": "0X0\nX0X\nX0X",
"output": "draw"
},
{
"input": "X0X\n0XX\n00X",
"output": "the first player won"
},
{
"input": "0XX\nX0.\nX00",
"output": "the second player won"
},
{
"input": "X.0\n0X0\nXX0",
"output": "the second player won"
},
{
"input": "X0X\nX0X\n0X0",
"output": "draw"
},
{
"input": "X.0\n00X\n0XX",
"output": "the second player won"
},
{
"input": "00X\nX0X\n.X0",
"output": "the second player won"
},
{
"input": "X0X\n.00\nX0X",
"output": "the second player won"
},
{
"input": "0XX\nX00\nX0X",
"output": "draw"
},
{
"input": "000\nX0X\n.XX",
"output": "the second player won"
},
{
"input": "0.0\n0.X\nXXX",
"output": "the first player won"
},
{
"input": "X.0\nX0.\n0X.",
"output": "the second player won"
},
{
"input": "X0X\n0X0\n..X",
"output": "the first player won"
},
{
"input": "0X0\nXX0\n.X.",
"output": "the first player won"
},
{
"input": "X0.\n.X.\n0.X",
"output": "the first player won"
},
{
"input": "0XX\nX00\n.X0",
"output": "the second player won"
},
{
"input": "0.0\nXXX\n0.X",
"output": "the first player won"
},
{
"input": ".0X\n.X.\nX.0",
"output": "the first player won"
},
{
"input": "XXX\nX.0\n0.0",
"output": "the first player won"
},
{
"input": "XX0\nX..\nX00",
"output": "the first player won"
},
{
"input": "XXX\n00X\n00X",
"output": "the first player won"
},
{
"input": "X00\n00X\nXXX",
"output": "the first player won"
},
{
"input": "0X0\nX0X\n0X.",
"output": "the second player won"
},
{
"input": "XX0\nX00\n0X.",
"output": "the second player won"
},
{
"input": "..X\n0X0\nX..",
"output": "the first player won"
},
{
"input": "X0.\n00.\nXXX",
"output": "the first player won"
},
{
"input": "0.X\nX00\nXX0",
"output": "the second player won"
},
{
"input": "X0.\n0X.\n..X",
"output": "the first player won"
},
{
"input": "00X\nX0.\nXX0",
"output": "the second player won"
},
{
"input": "XX.\n000\n0XX",
"output": "the second player won"
},
{
"input": "..X\n0.X\n.0X",
"output": "the first player won"
},
{
"input": "X00\n.0X\n0XX",
"output": "the second player won"
},
{
"input": "00X\n0X.\nXX.",
"output": "the first player won"
},
{
"input": "X00\nXX.\n0.X",
"output": "the first player won"
},
{
"input": "XXX\n00X\n0X0",
"output": "the first player won"
},
{
"input": "X00\nXX0\n0XX",
"output": "the first player won"
},
{
"input": "0X0\nX00\nXXX",
"output": "the first player won"
},
{
"input": "XX0\nX00\n.X0",
"output": "the second player won"
}
] | 124 | 5,529,600 | 3.896801 | 84 |
887 | Div. 64 | [
"implementation"
] | null | null | Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system. | In the only line given a non-empty binary string *s* with length up to 100. | Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. | [
"100010001\n",
"100\n"
] | [
"yes",
"no"
] | In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | [
{
"input": "100010001",
"output": "yes"
},
{
"input": "100",
"output": "no"
},
{
"input": "0000001000000",
"output": "yes"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111",
"output": "no"
},
{
"input": "0111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"input": "1111011111111111111111111111110111110111111111111111111111011111111111111110111111111111111111111111",
"output": "no"
},
{
"input": "1111111111101111111111111111111111111011111111111111111111111101111011111101111111111101111111111111",
"output": "yes"
},
{
"input": "0110111111111111111111011111111110110111110111111111111111111111111111111111111110111111111111111111",
"output": "yes"
},
{
"input": "1100110001111011001101101000001110111110011110111110010100011000100101000010010111100000010001001101",
"output": "yes"
},
{
"input": "000000",
"output": "no"
},
{
"input": "0001000",
"output": "no"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "no"
},
{
"input": "1000000",
"output": "yes"
},
{
"input": "0",
"output": "no"
},
{
"input": "1",
"output": "no"
},
{
"input": "10000000000",
"output": "yes"
},
{
"input": "0000000000",
"output": "no"
},
{
"input": "0010000",
"output": "no"
},
{
"input": "000000011",
"output": "no"
},
{
"input": "000000000",
"output": "no"
},
{
"input": "00000000",
"output": "no"
},
{
"input": "000000000011",
"output": "no"
},
{
"input": "0000000",
"output": "no"
},
{
"input": "00000000011",
"output": "no"
},
{
"input": "000000001",
"output": "no"
},
{
"input": "000000000000000000000000000",
"output": "no"
},
{
"input": "0000001",
"output": "no"
},
{
"input": "00000001",
"output": "no"
},
{
"input": "00000000100",
"output": "no"
},
{
"input": "00000000000000000000",
"output": "no"
},
{
"input": "0000000000000000000",
"output": "no"
},
{
"input": "00001000",
"output": "no"
},
{
"input": "0000000000010",
"output": "no"
},
{
"input": "000000000010",
"output": "no"
},
{
"input": "000000000000010",
"output": "no"
},
{
"input": "0100000",
"output": "no"
},
{
"input": "00010000",
"output": "no"
},
{
"input": "00000000000000000",
"output": "no"
},
{
"input": "00000000000",
"output": "no"
},
{
"input": "000001000",
"output": "no"
},
{
"input": "000000000000",
"output": "no"
},
{
"input": "100000000000000",
"output": "yes"
},
{
"input": "000010000",
"output": "no"
},
{
"input": "00000100",
"output": "no"
},
{
"input": "0001100000",
"output": "no"
},
{
"input": "000000000000000000000000001",
"output": "no"
},
{
"input": "000000100",
"output": "no"
},
{
"input": "0000000000001111111111",
"output": "no"
},
{
"input": "00000010",
"output": "no"
},
{
"input": "0001110000",
"output": "no"
},
{
"input": "0000000000000000000000",
"output": "no"
},
{
"input": "000000010010",
"output": "no"
},
{
"input": "0000100",
"output": "no"
},
{
"input": "0000000001",
"output": "no"
},
{
"input": "000000111",
"output": "no"
},
{
"input": "0000000000000",
"output": "no"
},
{
"input": "000000000000000000",
"output": "no"
},
{
"input": "0000000000000000000000000",
"output": "no"
},
{
"input": "000000000000000",
"output": "no"
},
{
"input": "0010000000000100",
"output": "yes"
},
{
"input": "0000001000",
"output": "no"
},
{
"input": "00000000000000000001",
"output": "no"
},
{
"input": "100000000",
"output": "yes"
},
{
"input": "000000000001",
"output": "no"
},
{
"input": "0000011001",
"output": "no"
},
{
"input": "000",
"output": "no"
},
{
"input": "000000000000000000000",
"output": "no"
},
{
"input": "0000000000011",
"output": "no"
},
{
"input": "0000000000000000",
"output": "no"
},
{
"input": "00000000000000001",
"output": "no"
},
{
"input": "00000000000000",
"output": "no"
},
{
"input": "0000000000000000010",
"output": "no"
},
{
"input": "00000000000000000000000000000000000000000000000000000000",
"output": "no"
},
{
"input": "000011000",
"output": "no"
},
{
"input": "00000011",
"output": "no"
},
{
"input": "0000000000001100",
"output": "no"
},
{
"input": "00000",
"output": "no"
},
{
"input": "000000000000000000000000000111111111111111",
"output": "no"
},
{
"input": "000000010",
"output": "no"
},
{
"input": "00000000111",
"output": "no"
},
{
"input": "000000000000001",
"output": "no"
},
{
"input": "0000000000000011111111111111111",
"output": "no"
},
{
"input": "0000000010",
"output": "no"
},
{
"input": "0000000000000000000000000000000000000000000000000",
"output": "no"
},
{
"input": "00000000010",
"output": "no"
},
{
"input": "101000000000",
"output": "yes"
},
{
"input": "00100000",
"output": "no"
},
{
"input": "00000000000001",
"output": "no"
},
{
"input": "0000000000100",
"output": "no"
},
{
"input": "0000",
"output": "no"
},
{
"input": "00000000000111",
"output": "no"
},
{
"input": "0000000000000011",
"output": "no"
},
{
"input": "0000000000000000000000000000000000000000",
"output": "no"
},
{
"input": "0000000000000010",
"output": "no"
},
{
"input": "0010101010",
"output": "no"
},
{
"input": "0000000000000001",
"output": "no"
},
{
"input": "1010101",
"output": "no"
}
] | 124 | 0 | 3 | 85 |
|
538 | Quasi Binary | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them. | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201",
"output": "2\n100 10101 "
},
{
"input": "314159",
"output": "9\n1 1 1 1 11 1011 101011 101011 111111 "
},
{
"input": "999999",
"output": "9\n111111 111111 111111 111111 111111 111111 111111 111111 111111 "
},
{
"input": "2",
"output": "2\n1 1 "
},
{
"input": "10",
"output": "1\n10 "
},
{
"input": "21",
"output": "2\n10 11 "
},
{
"input": "98",
"output": "9\n10 11 11 11 11 11 11 11 11 "
},
{
"input": "102030",
"output": "3\n10 1010 101010 "
},
{
"input": "909090",
"output": "9\n101010 101010 101010 101010 101010 101010 101010 101010 101010 "
},
{
"input": "909823",
"output": "9\n101000 101100 101100 101100 101100 101100 101101 101111 101111 "
},
{
"input": "1000000",
"output": "1\n1000000 "
},
{
"input": "111111",
"output": "1\n111111 "
},
{
"input": "123456",
"output": "6\n1 11 111 1111 11111 111111 "
},
{
"input": "987654",
"output": "9\n100000 110000 111000 111100 111110 111111 111111 111111 111111 "
},
{
"input": "908172",
"output": "9\n100000 101000 101010 101010 101010 101010 101010 101011 101111 "
},
{
"input": "8",
"output": "8\n1 1 1 1 1 1 1 1 "
},
{
"input": "100009",
"output": "9\n1 1 1 1 1 1 1 1 100001 "
},
{
"input": "900000",
"output": "9\n100000 100000 100000 100000 100000 100000 100000 100000 100000 "
},
{
"input": "1435",
"output": "5\n1 101 111 111 1111 "
},
{
"input": "1453",
"output": "5\n10 110 111 111 1111 "
}
] | 77 | 0 | 0 | 87 |
|
637 | Chat Order | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"output": "ypg"
},
{
"input": "3\nexhll\nexhll\narruapexj",
"output": "arruapexj\nexhll"
},
{
"input": "3\nfv\nle\nle",
"output": "le\nfv"
},
{
"input": "8\nm\nm\nm\nm\nm\nm\nm\nm",
"output": "m"
},
{
"input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr",
"output": "r\nu\nb\nk\nw\ni"
},
{
"input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok",
"output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne"
},
{
"input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe",
"output": "we\nklrj"
},
{
"input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh",
"output": "zncybqmh\naeebef\nn"
},
{
"input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo",
"output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj"
},
{
"input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn",
"output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy"
},
{
"input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg",
"output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg"
},
{
"input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh",
"output": "vhh\nfa"
},
{
"input": "2\naa\nbb",
"output": "bb\naa"
},
{
"input": "2\naa\na",
"output": "a\naa"
},
{
"input": "3\naa\naa\naa",
"output": "aa"
},
{
"input": "5\naa\na\naa\na\naa",
"output": "aa\na"
},
{
"input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa",
"output": "aaa\naaaaaaa\naa\na\naaaa"
},
{
"input": "5\na\naa\naaa\naaaa\na",
"output": "a\naaaa\naaa\naa"
},
{
"input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa",
"output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa"
},
{
"input": "3\na\naa\naaa",
"output": "aaa\naa\na"
},
{
"input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz",
"output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz"
}
] | 3,000 | 1,126,400 | 0 | 88 |
|
929 | Прокат велосипедов | [
"*special",
"greedy",
"implementation"
] | null | null | Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат или сдать его. Первый велопрокат находится в точке *x*1 километров вдоль улицы, второй — в точке *x*2 и так далее, *n*-й велопрокат находится в точке *x**n*. Школа Аркадия находится в точке *x*1 (то есть там же, где и первый велопрокат), а дом — в точке *x**n* (то есть там же, где и *n*-й велопрокат). Известно, что *x**i*<=<<=*x**i*<=+<=1 для всех 1<=≤<=*i*<=<<=*n*.
Согласно правилам пользования велопроката, Аркадий может брать велосипед в прокат только на ограниченное время, после этого он должен обязательно вернуть его в одной из точек велопроката, однако, он тут же может взять новый велосипед, и отсчет времени пойдет заново. Аркадий может брать не более одного велосипеда в прокат одновременно. Если Аркадий решает взять велосипед в какой-то точке проката, то он сдаёт тот велосипед, на котором он до него доехал, берёт ровно один новый велосипед и продолжает на нём своё движение.
За отведенное время, независимо от выбранного велосипеда, Аркадий успевает проехать не больше *k* километров вдоль улицы.
Определите, сможет ли Аркадий доехать на велосипедах от школы до дома, и если да, то какое минимальное число раз ему необходимо будет взять велосипед в прокат, включая первый велосипед? Учтите, что Аркадий не намерен сегодня ходить пешком. | В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде.
В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=<<=*x*2<=<<=...<=<<=*x**n*<=≤<=100<=000) — координаты точек, в которых находятся велопрокаты. Гарантируется, что координаты велопрокатов заданы в порядке возрастания. | Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката. | [
"4 4\n3 6 8 10\n",
"2 9\n10 20\n",
"12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n"
] | [
"2\n",
"-1\n",
"6\n"
] | В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы добраться от школы до дома.
Во втором примере всего два велопроката, расстояние между которыми 10. Но максимальное расстояние, которое можно проехать на одном велосипеде, равно 9. Поэтому Аркадий не сможет добраться от школы до дома только на велосипедах. | [
{
"input": "4 4\n3 6 8 10",
"output": "2"
},
{
"input": "2 9\n10 20",
"output": "-1"
},
{
"input": "12 3\n4 6 7 9 10 11 13 15 17 18 20 21",
"output": "6"
},
{
"input": "2 1\n11164 11165",
"output": "1"
},
{
"input": "3 7\n45823 45825 45829",
"output": "1"
},
{
"input": "2 100000\n0 100000",
"output": "1"
},
{
"input": "50 15001\n1269 1580 5431 5916 6642 14145 15760 19922 20589 22062 24138 33454 33505 35916 37012 42577 43140 49457 54720 55188 56205 56639 56870 57997 58379 59088 59297 61805 61861 63005 64013 68848 71182 71497 72715 73008 75616 76042 76614 80690 83089 85033 86408 92392 92763 93833 95085 95815 97152 99379",
"output": "8"
},
{
"input": "5 7\n6219 6222 6229 6231 6236",
"output": "3"
},
{
"input": "10 448\n78449 78573 78599 78742 78748 78759 78853 79091 79298 79324",
"output": "3"
},
{
"input": "20 19191\n11272 12386 14108 24663 24932 26547 29656 44677 45436 45654 48562 62367 71049 71238 78182 84042 88736 92026 96836 99343",
"output": "6"
},
{
"input": "2 100000\n1 100000",
"output": "1"
},
{
"input": "2 99999\n0 100000",
"output": "-1"
},
{
"input": "2 2\n1 3",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "2 2\n1 4",
"output": "-1"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
}
] | 62 | 5,632,000 | 3 | 89 |
|
621 | Wet Shark and Odd and Even | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\n59 96 34 48 8 72 67 90 15 85 7 90 97 47 25",
"output": "840"
},
{
"input": "15\n87 37 91 29 58 45 51 74 70 71 47 38 91 89 44",
"output": "922"
},
{
"input": "15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59",
"output": "674"
},
{
"input": "15\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82",
"output": "848"
},
{
"input": "15\n59 70 48 54 26 67 84 39 40 18 77 69 70 88 93",
"output": "902"
},
{
"input": "15\n87 22 98 32 88 36 72 31 100 97 17 16 60 22 20",
"output": "798"
},
{
"input": "15\n15 63 51 13 37 9 43 19 55 79 57 60 50 59 31",
"output": "632"
},
{
"input": "1\n4",
"output": "4"
},
{
"input": "2\n1 4",
"output": "4"
},
{
"input": "3\n1 2 4",
"output": "6"
},
{
"input": "2\n9 3",
"output": "12"
},
{
"input": "2\n1000000000 1001",
"output": "1000000000"
},
{
"input": "3\n1 8 4",
"output": "12"
},
{
"input": "3\n7 4 4",
"output": "8"
},
{
"input": "5\n2 3 4 5 3",
"output": "14"
},
{
"input": "2\n4 5",
"output": "4"
},
{
"input": "3\n2 4 5",
"output": "6"
},
{
"input": "3\n2 2 3",
"output": "4"
},
{
"input": "2\n2 3",
"output": "2"
},
{
"input": "4\n2 3 7 7",
"output": "16"
},
{
"input": "2\n999999999 2",
"output": "2"
},
{
"input": "2\n2 5",
"output": "2"
},
{
"input": "3\n5 3 1",
"output": "8"
},
{
"input": "4\n3 2 5 7",
"output": "14"
}
] | 93 | 0 | 0 | 90 |
|
363 | Fence | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible.
Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence. | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"input": "2 2\n20 10",
"output": "1"
},
{
"input": "2 1\n20 1",
"output": "2"
},
{
"input": "3 1\n1 2 3",
"output": "1"
},
{
"input": "3 1\n2 1 3",
"output": "2"
},
{
"input": "3 1\n3 2 1",
"output": "3"
},
{
"input": "3 2\n1 2 3",
"output": "1"
},
{
"input": "3 2\n3 2 1",
"output": "2"
},
{
"input": "3 3\n1 2 3",
"output": "1"
},
{
"input": "4 2\n9 8 11 7",
"output": "1"
},
{
"input": "4 2\n10 1 2 3",
"output": "2"
},
{
"input": "6 3\n56 56 56 2 1 2",
"output": "4"
},
{
"input": "8 3\n1 1 1 1 2 60 90 1",
"output": "1"
},
{
"input": "4 1\n1 5 2 2",
"output": "1"
},
{
"input": "4 2\n4 6 7 4",
"output": "1"
},
{
"input": "10 4\n1 1 1 4 4 4 4 4 4 3",
"output": "1"
},
{
"input": "6 3\n1 2 1 3 1 1",
"output": "1"
},
{
"input": "5 2\n100 100 100 1 1",
"output": "4"
}
] | 61 | 15,360,000 | 0 | 91 |
|
946 | Weird Subtraction Process | [
"math",
"number theory"
] | null | null | You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process.
Initially the values of *a* and *b* are positive integers, and so the process will be finite.
You have to determine the values of *a* and *b* after the process ends. | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*. | Print two integers — the values of *a* and *b* after the end of the process. | [
"12 5\n",
"31 12\n"
] | [
"0 1\n",
"7 12\n"
] | Explanations to the samples:
1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12. | [
{
"input": "12 5",
"output": "0 1"
},
{
"input": "31 12",
"output": "7 12"
},
{
"input": "1000000000000000000 7",
"output": "8 7"
},
{
"input": "31960284556200 8515664064180",
"output": "14928956427840 8515664064180"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1000000000000000000 1000000000000000000"
},
{
"input": "1 1000",
"output": "1 0"
},
{
"input": "1 1000000",
"output": "1 0"
},
{
"input": "1 1000000000000000",
"output": "1 0"
},
{
"input": "1 99999999999999999",
"output": "1 1"
},
{
"input": "1 4",
"output": "1 0"
},
{
"input": "1000000000000001 500000000000000",
"output": "1 0"
},
{
"input": "1 1000000000000000000",
"output": "1 0"
},
{
"input": "2 4",
"output": "2 0"
},
{
"input": "2 1",
"output": "0 1"
},
{
"input": "6 19",
"output": "6 7"
},
{
"input": "22 5",
"output": "0 1"
},
{
"input": "10000000000000000 100000000000000001",
"output": "0 1"
},
{
"input": "1 1000000000000",
"output": "1 0"
},
{
"input": "2 1000000000000000",
"output": "2 0"
},
{
"input": "2 10",
"output": "2 2"
},
{
"input": "51 100",
"output": "51 100"
},
{
"input": "3 1000000000000000000",
"output": "3 4"
},
{
"input": "1000000000000000000 3",
"output": "4 3"
},
{
"input": "1 10000000000000000",
"output": "1 0"
},
{
"input": "8796203 7556",
"output": "1019 1442"
},
{
"input": "5 22",
"output": "1 0"
},
{
"input": "1000000000000000000 1",
"output": "0 1"
},
{
"input": "1 100000000000",
"output": "1 0"
},
{
"input": "2 1000000000000",
"output": "2 0"
},
{
"input": "5 4567865432345678",
"output": "5 8"
},
{
"input": "576460752303423487 288230376151711743",
"output": "1 1"
},
{
"input": "499999999999999999 1000000000000000000",
"output": "3 2"
},
{
"input": "1 9999999999999",
"output": "1 1"
},
{
"input": "103 1000000000000000000",
"output": "103 196"
},
{
"input": "7 1",
"output": "1 1"
},
{
"input": "100000000000000001 10000000000000000",
"output": "1 0"
},
{
"input": "5 10",
"output": "5 0"
},
{
"input": "7 11",
"output": "7 11"
},
{
"input": "1 123456789123456",
"output": "1 0"
},
{
"input": "5000000000000 100000000000001",
"output": "0 1"
},
{
"input": "1000000000000000 1",
"output": "0 1"
},
{
"input": "1000000000000000000 499999999999999999",
"output": "2 3"
},
{
"input": "10 5",
"output": "0 5"
},
{
"input": "9 18917827189272",
"output": "9 0"
},
{
"input": "179 100000000000497000",
"output": "179 270"
},
{
"input": "5 100000000000001",
"output": "1 1"
},
{
"input": "5 20",
"output": "5 0"
},
{
"input": "100000001 50000000",
"output": "1 0"
},
{
"input": "345869461223138161 835002744095575440",
"output": "1 0"
},
{
"input": "8589934592 4294967296",
"output": "0 4294967296"
},
{
"input": "4 8",
"output": "4 0"
},
{
"input": "1 100000000000000000",
"output": "1 0"
},
{
"input": "1000000000000000000 333333333333333",
"output": "1000 1333"
},
{
"input": "25 12",
"output": "1 0"
},
{
"input": "24 54",
"output": "0 6"
},
{
"input": "6 12",
"output": "6 0"
},
{
"input": "129200000000305 547300000001292",
"output": "1 0"
},
{
"input": "1000000000000000000 49999999999999999",
"output": "20 39"
},
{
"input": "1 2",
"output": "1 0"
},
{
"input": "1 123456789876",
"output": "1 0"
},
{
"input": "2 3",
"output": "2 3"
},
{
"input": "1 3",
"output": "1 1"
},
{
"input": "1 1",
"output": "1 1"
},
{
"input": "19 46",
"output": "3 2"
},
{
"input": "3 6",
"output": "3 0"
},
{
"input": "129 1000000000000000000",
"output": "1 0"
},
{
"input": "12 29",
"output": "0 1"
},
{
"input": "8589934592 2147483648",
"output": "0 2147483648"
},
{
"input": "2147483648 8589934592",
"output": "2147483648 0"
},
{
"input": "5 6",
"output": "5 6"
},
{
"input": "1000000000000000000 2",
"output": "0 2"
},
{
"input": "2 7",
"output": "2 3"
},
{
"input": "17174219820754872 61797504734333370",
"output": "17174219820754872 27449065092823626"
},
{
"input": "49 100",
"output": "1 0"
},
{
"input": "7 17",
"output": "1 1"
},
{
"input": "1000000000000000000 10000001",
"output": "0 1"
},
{
"input": "49999999999999999 2",
"output": "3 2"
},
{
"input": "49999999999999999 1",
"output": "1 1"
},
{
"input": "576460752303423487 2",
"output": "3 2"
},
{
"input": "19395 19395",
"output": "19395 19395"
},
{
"input": "19394 19394",
"output": "19394 19394"
}
] | 1,000 | 0 | 0 | 92 |
|
1,007 | Reorder the Array | [
"combinatorics",
"data structures",
"math",
"sortings",
"two pointers"
] | null | null | You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20>10$, $40>20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case.
Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal. | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array. | Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array. | [
"7\n10 1 1 1 5 5 3\n",
"5\n1 1 1 1 1\n"
] | [
"4\n",
"0\n"
] | In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.
In the second sample, there is no way to increase any element with a permutation, so the answer is 0. | [
{
"input": "7\n10 1 1 1 5 5 3",
"output": "4"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000",
"output": "3"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "7\n3 5 2 2 5 2 4",
"output": "4"
},
{
"input": "5\n1 5 4 2 3",
"output": "4"
}
] | 2,000 | 11,878,400 | 0 | 93 |
|
37 | Towers | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible. | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20 96 51 110 129 24 116 9 47 32 82 105 114 116 75 154 151 70 42 162",
"output": "2 23"
},
{
"input": "45\n802 664 442 318 318 827 417 878 711 291 231 414 807 553 657 392 279 202 386 606 465 655 658 112 887 15 25 502 95 44 679 775 942 609 209 871 31 234 4 231 150 110 22 823 193",
"output": "2 43"
},
{
"input": "63\n93 180 116 7 8 179 268 279 136 94 221 153 264 190 278 19 19 63 153 26 158 225 25 49 89 218 111 149 255 225 197 122 243 80 3 224 107 178 202 17 53 92 69 42 228 24 81 205 95 8 265 82 228 156 127 241 172 159 106 60 67 155 111",
"output": "2 57"
},
{
"input": "83\n246 535 994 33 390 927 321 97 223 922 812 705 79 80 977 457 476 636 511 137 6 360 815 319 717 674 368 551 714 628 278 713 761 553 184 414 623 753 428 214 581 115 439 61 677 216 772 592 187 603 658 310 439 559 870 376 109 321 189 337 277 26 70 734 796 907 979 693 570 227 345 650 737 633 701 914 134 403 972 940 371 6 642",
"output": "2 80"
},
{
"input": "105\n246 57 12 204 165 123 246 68 191 310 3 152 386 333 374 257 158 104 333 50 80 290 8 340 101 76 221 316 388 289 138 359 316 26 93 290 105 178 81 195 41 196 218 180 244 292 187 97 315 323 174 119 248 239 92 312 31 2 101 180 307 170 338 314 163 281 217 31 142 238 280 190 190 156 70 74 329 113 151 8 141 313 366 40 253 116 168 124 135 230 294 266 353 389 371 359 195 200 183 237 93 102 315 118 188",
"output": "2 92"
},
{
"input": "123\n112 277 170 247 252 115 157 293 256 143 196 90 12 164 164 42 8 223 167 109 175 232 239 111 148 51 9 254 93 32 268 162 231 91 47 162 161 191 195 145 247 292 129 199 230 94 144 217 18 205 176 20 143 198 121 243 211 262 230 277 195 255 108 290 220 275 158 2 286 200 60 267 278 207 123 150 123 116 131 13 12 226 33 244 30 275 263 45 158 192 254 149 242 176 62 224 221 288 250 160 155 225 132 143 276 293 218 145 197 175 33 129 79 206 210 192 222 262 190 52 274 243 233",
"output": "3 101"
},
{
"input": "5\n5 5 5 5 5",
"output": "5 1"
},
{
"input": "3\n1000 1000 1000",
"output": "3 1"
},
{
"input": "1\n1000",
"output": "1 1"
},
{
"input": "1\n1",
"output": "1 1"
},
{
"input": "5\n1 1000 1000 1000 1000",
"output": "4 2"
},
{
"input": "5\n1000 1000 1000 8 7",
"output": "3 3"
}
] | 122 | 0 | 3.9695 | 94 |
174 | File List | [
"dp",
"greedy",
"implementation"
] | null | null | Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
- name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters; - ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names. | The input data consists of a single string *s*, its length is from 1 to 4·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.'). | In the first line print "YES" (without the quotes), if it is possible to divide *s* into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in *s*. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes). | [
"read.meexample.txtb.cpp\n",
"version.infontldrcontestdata.zip\n"
] | [
"YES\nread.m\neexample.t\nxtb.cpp\n",
"NO\n"
] | none | [
{
"input": "read.meexample.txtb.cpp",
"output": "YES\nread.m\neexample.t\nxtb.cpp"
},
{
"input": "version.infontldrcontestdata.zip",
"output": "NO"
},
{
"input": "thisis.text.txt",
"output": "YES\nthisis.t\next.txt"
},
{
"input": "oops.t",
"output": "YES\noops.t"
},
{
"input": "thisislongfilename",
"output": "NO"
},
{
"input": "double..dot",
"output": "NO"
},
{
"input": "one.one.one.one.one.one.one.one.one.one",
"output": "YES\none.o\nne.o\nne.o\nne.o\nne.o\nne.o\nne.o\nne.o\nne.one"
},
{
"input": ".",
"output": "NO"
},
{
"input": "z",
"output": "NO"
},
{
"input": "a.",
"output": "NO"
},
{
"input": ".a",
"output": "NO"
},
{
"input": "za",
"output": "NO"
},
{
"input": "..",
"output": "NO"
},
{
"input": "xlq",
"output": "NO"
},
{
"input": ".r.",
"output": "NO"
},
{
"input": "ulmc",
"output": "NO"
},
{
"input": "nja.",
"output": "NO"
},
{
"input": "t..kz",
"output": "NO"
},
{
"input": "twaha",
"output": "NO"
},
{
"input": "m..dw.",
"output": "NO"
},
{
"input": "utsvfg.",
"output": "NO"
},
{
"input": ".we.voae",
"output": "NO"
},
{
"input": "kw.gkcxk.",
"output": "NO"
},
{
"input": ".c.v.hpehh",
"output": "NO"
},
{
"input": "....e.afx.h",
"output": "NO"
},
{
"input": "akymwh",
"output": "NO"
},
{
"input": "jx.lqv.",
"output": "NO"
},
{
"input": "qkwtq.zw",
"output": "YES\nqkwtq.zw"
},
{
"input": "yxwvlk..b",
"output": "NO"
},
{
"input": "ph..qlr.pt",
"output": "NO"
},
{
"input": "cab.ab.bac",
"output": "YES\ncab.a\nb.bac"
},
{
"input": "badaba.ae",
"output": "YES\nbadaba.ae"
},
{
"input": "badabaca.mor",
"output": "YES\nbadabaca.mor"
},
{
"input": "bae.a",
"output": "YES\nbae.a"
},
{
"input": "b.baba.ebpbac.iabaeabac.abab.adabacaba.ahcggibij.adaacab.ebaba.aa.abacaba.dacabada.daqjcpc.jadab.dab",
"output": "YES\nb.b\naba.e\nbpbac.i\nabaeabac.a\nbab.a\ndabacaba.a\nhcggibij.a\ndaacab.e\nbaba.a\na.a\nbacaba.d\nacabada.d\naqjcpc.j\nadab.dab"
},
{
"input": ".ab",
"output": "NO"
},
{
"input": "aa.aa.aaaabbbbccc.ddd.ee",
"output": "YES\naa.a\na.aaa\nabbbbccc.d\ndd.ee"
},
{
"input": "a.aaaa",
"output": "NO"
},
{
"input": "aaaaread.meexample.txtb.cpp",
"output": "YES\naaaaread.m\neexample.t\nxtb.cpp"
},
{
"input": "abcdabcd.a",
"output": "YES\nabcdabcd.a"
},
{
"input": "qwertyuio.qwe",
"output": "NO"
},
{
"input": "asd.",
"output": "NO"
},
{
"input": "aaaaaaaa.",
"output": "NO"
},
{
"input": "a.txtaaaaaaaaa.txt",
"output": "NO"
},
{
"input": ".abcde.cpp",
"output": "NO"
},
{
"input": ".abc.cpp",
"output": "NO"
},
{
"input": "abcdefgh.aaaabcdefgh.bbb",
"output": "YES\nabcdefgh.aaa\nabcdefgh.bbb"
},
{
"input": "filename.exe",
"output": "YES\nfilename.exe"
},
{
"input": ".abcd.cpp",
"output": "NO"
},
{
"input": "abc.bcdabcdabcd.abc",
"output": "YES\nabc.bcd\nabcdabcd.abc"
},
{
"input": "abc.abcde",
"output": "NO"
},
{
"input": "a.cp",
"output": "YES\na.cp"
},
{
"input": "a.b.c",
"output": "NO"
},
{
"input": ".ha",
"output": "NO"
},
{
"input": "a.a.a.a",
"output": "NO"
},
{
"input": "a.a.a",
"output": "NO"
},
{
"input": "qwertyui.cp",
"output": "YES\nqwertyui.cp"
},
{
"input": "ss.aaaaaaaaaaaa.aa",
"output": "NO"
},
{
"input": "name.extnamename.ext",
"output": "YES\nname.ext\nnamename.ext"
},
{
"input": ".aaaa.aaa",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaaaaaaa.a",
"output": "NO"
},
{
"input": ".filena.exe",
"output": "NO"
},
{
"input": "a.aaaaaaaaaaa.a",
"output": "YES\na.aaa\naaaaaaaa.a"
},
{
"input": ".aa.w",
"output": "NO"
}
] | 124 | 0 | 0 | 96 |
|
272 | Dima and Two Sequences | [
"combinatorics",
"math",
"sortings"
] | null | null | Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*).
Now Dima wants to count the number of distinct sequences of points of length 2·*n* that can be assembled from these sequences, such that the *x*-coordinates of points in the assembled sequence will not decrease. Help him with that. Note that each element of the initial sequences should be used exactly once in the assembled sequence.
Dima considers two assembled sequences (*p*1,<=*q*1),<=(*p*2,<=*q*2),<=...,<=(*p*2·*n*,<=*q*2·*n*) and (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x*2·*n*,<=*y*2·*n*) distinct, if there is such *i* (1<=≤<=*i*<=≤<=2·*n*), that (*p**i*,<=*q**i*)<=≠<=(*x**i*,<=*y**i*).
As the answer can be rather large, print the remainder from dividing the answer by number *m*. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=109). The numbers in the lines are separated by spaces.
The last line contains integer *m* (2<=≤<=*m*<=≤<=109<=+<=7). | In the single line print the remainder after dividing the answer to the problem by number *m*. | [
"1\n1\n2\n7\n",
"2\n1 2\n2 3\n11\n"
] | [
"1\n",
"2\n"
] | In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2. | [
{
"input": "1\n1\n2\n7",
"output": "1"
},
{
"input": "2\n1 2\n2 3\n11",
"output": "2"
},
{
"input": "100\n1 8 10 6 5 3 2 3 4 2 3 7 1 1 5 1 4 1 8 1 5 5 6 5 3 7 4 5 5 3 8 7 8 6 8 9 10 7 8 5 8 9 1 3 7 2 6 1 7 7 2 8 1 5 4 2 10 4 9 8 1 10 1 5 9 8 1 9 5 1 5 7 1 6 7 8 8 2 2 3 3 7 2 10 6 3 6 3 5 3 10 4 4 6 9 9 3 2 6 6\n4 3 8 4 4 2 4 6 6 3 3 5 8 4 1 6 2 7 6 1 6 10 7 9 2 9 2 9 10 1 1 1 1 7 4 5 3 6 8 6 10 4 3 4 8 6 5 3 1 2 2 4 1 9 1 3 1 9 6 8 9 4 8 8 4 2 1 4 6 2 6 3 4 7 7 7 8 10 7 8 8 6 4 10 10 7 4 5 5 8 3 8 2 8 6 4 5 2 10 2\n29056621",
"output": "5236748"
},
{
"input": "100\n6 1 10 4 8 7 7 3 2 4 6 3 2 5 3 7 1 6 9 8 3 10 1 6 8 1 4 2 5 6 3 5 4 6 3 10 2 8 10 4 2 6 4 5 3 1 8 6 9 8 5 2 7 1 10 5 10 2 9 1 6 4 9 5 2 4 6 7 10 10 10 6 6 9 2 3 3 1 2 4 1 6 9 8 4 10 10 9 9 2 5 7 10 1 9 7 6 6 4 5\n4 9 2 5 5 4 6 9 1 2 6 3 8 9 4 4 4 3 1 3 6 2 9 1 10 6 5 1 9 10 6 2 10 9 8 7 8 2 1 5 8 4 3 2 10 9 5 7 1 8 4 4 4 2 1 3 4 5 3 6 10 3 8 9 5 6 3 9 3 6 5 1 9 1 4 3 8 4 4 8 10 6 4 9 8 4 2 3 1 9 9 1 4 1 8 4 7 9 10 9\n66921358",
"output": "12938646"
},
{
"input": "100\n2 2 10 3 5 6 4 7 9 8 2 7 5 5 1 7 5 9 2 2 10 3 6 10 9 9 10 7 3 9 7 8 8 3 9 3 9 3 3 6 3 7 9 9 7 10 9 1 1 3 6 2 9 5 9 9 6 2 6 5 6 8 2 10 1 1 6 8 8 4 5 2 6 8 8 5 9 2 3 3 7 7 10 5 4 2 10 6 7 6 5 4 10 6 10 3 9 9 1 5\n3 5 6 4 2 3 2 9 3 8 3 1 10 7 4 3 6 9 3 5 9 5 3 10 4 7 9 7 4 3 3 6 9 8 1 1 10 9 1 6 8 8 8 2 1 6 10 1 8 6 3 5 7 7 10 4 6 6 9 1 5 3 5 10 4 4 1 7 9 7 5 10 6 5 4 1 9 6 4 5 7 3 1 10 2 10 6 6 1 10 7 5 1 4 2 9 2 7 3 10\n727992321",
"output": "340960284"
},
{
"input": "100\n2 5 5 6 5 2 8 10 6 1 5 3 10 3 8 6 4 5 7 9 7 1 3 3 5 2 3 7 9 3 7 2 7 6 7 10 5 9 2 4 8 2 3 8 6 6 8 4 1 2 10 5 2 8 4 3 1 3 8 3 2 4 4 6 8 1 9 8 9 9 1 7 1 9 2 4 6 2 1 9 2 7 9 6 6 7 1 9 3 1 6 10 3 9 10 5 3 3 9 8\n6 5 3 1 3 3 8 6 5 4 2 3 9 3 9 9 10 5 10 6 7 8 8 7 8 4 2 4 4 9 1 3 1 5 8 4 8 9 7 9 7 8 4 9 9 9 4 2 9 1 3 10 6 4 5 3 2 8 1 5 1 8 10 10 3 3 7 1 2 4 4 3 3 5 9 8 9 8 5 9 4 8 10 6 7 4 1 9 4 7 1 8 3 3 5 9 8 6 5 4\n608692736",
"output": "550164992"
},
{
"input": "2\n1 2\n1 2\n4",
"output": "1"
},
{
"input": "4\n1 2 3 4\n4 3 2 1\n1009",
"output": "16"
},
{
"input": "5\n1 2 3 3 5\n1 2 3 5 3\n12",
"output": "0"
},
{
"input": "1\n1000000000\n1000000000\n2",
"output": "1"
},
{
"input": "2\n1 2\n2 2\n4",
"output": "3"
}
] | 154 | 0 | 0 | 97 |
|
858 | Did you mean... | [
"dp",
"greedy",
"implementation"
] | null | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem. | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | [
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] | [
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] | none | [
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx",
"output": "jxegx xx "
},
{
"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz",
"output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz "
},
{
"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte",
"output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te "
},
{
"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz",
"output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz "
},
{
"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf",
"output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf "
},
{
"input": "mvjajoyeg",
"output": "mv jajoyeg "
},
{
"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq",
"output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q "
},
{
"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef",
"output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef "
},
{
"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj",
"output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j "
},
{
"input": "hzxkuwqxonsulnndlhygvmallghjerwp",
"output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p "
},
{
"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd",
"output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d "
},
{
"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr",
"output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r "
},
{
"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu",
"output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu "
},
{
"input": "a",
"output": "a "
},
{
"input": "b",
"output": "b "
},
{
"input": "aa",
"output": "aa "
},
{
"input": "ab",
"output": "ab "
},
{
"input": "ba",
"output": "ba "
},
{
"input": "bb",
"output": "bb "
},
{
"input": "aaa",
"output": "aaa "
},
{
"input": "aab",
"output": "aab "
},
{
"input": "aba",
"output": "aba "
},
{
"input": "abb",
"output": "abb "
},
{
"input": "baa",
"output": "baa "
},
{
"input": "bab",
"output": "bab "
},
{
"input": "bba",
"output": "bba "
},
{
"input": "bbb",
"output": "bbb "
},
{
"input": "bbc",
"output": "bb c "
},
{
"input": "bcb",
"output": "bc b "
},
{
"input": "cbb",
"output": "cb b "
},
{
"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc",
"output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc "
},
{
"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb",
"output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b "
},
{
"input": "helllllooooo",
"output": "helllllooooo "
},
{
"input": "bbbzxxx",
"output": "bbb zx xx "
},
{
"input": "ffff",
"output": "ffff "
},
{
"input": "cdddddddddddddddddd",
"output": "cd ddddddddddddddddd "
},
{
"input": "bbbc",
"output": "bbb c "
},
{
"input": "lll",
"output": "lll "
},
{
"input": "bbbbb",
"output": "bbbbb "
},
{
"input": "llll",
"output": "llll "
},
{
"input": "bbbbbbccc",
"output": "bbbbbb ccc "
},
{
"input": "lllllb",
"output": "lllll b "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "lllll",
"output": "lllll "
},
{
"input": "bbbbbbbbbc",
"output": "bbbbbbbbb c "
},
{
"input": "helllllno",
"output": "helllll no "
},
{
"input": "nnnnnnnnnnnn",
"output": "nnnnnnnnnnnn "
},
{
"input": "bbbbbccc",
"output": "bbbbb ccc "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "nnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "hhhh",
"output": "hhhh "
},
{
"input": "nnnnnnnnnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzz",
"output": "zzzzzzzzzz "
},
{
"input": "dddd",
"output": "dddd "
},
{
"input": "heffffffgggggghhhhhh",
"output": "heffffff gggggg hhhhhh "
},
{
"input": "bcddd",
"output": "bc ddd "
},
{
"input": "x",
"output": "x "
},
{
"input": "nnn",
"output": "nnn "
},
{
"input": "xxxxxxxx",
"output": "xxxxxxxx "
},
{
"input": "cclcc",
"output": "cc lc c "
},
{
"input": "tttttttttttttt",
"output": "tttttttttttttt "
},
{
"input": "xxxxxxx",
"output": "xxxxxxx "
},
{
"input": "ccccb",
"output": "cccc b "
},
{
"input": "bcecccc",
"output": "bcecccc "
},
{
"input": "jjja",
"output": "jjja "
},
{
"input": "zzz",
"output": "zzz "
},
{
"input": "xxxxxxxxxzzzzzzzzzzzz",
"output": "xxxxxxxxx zzzzzzzzzzzz "
},
{
"input": "alllewww",
"output": "alllewww "
},
{
"input": "bbbbbbbbb",
"output": "bbbbbbbbb "
},
{
"input": "jjj",
"output": "jjj "
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbb "
},
{
"input": "kkkkkkkkkklllllllllllllll",
"output": "kkkkkkkkkk lllllllllllllll "
},
{
"input": "helllllllllllo",
"output": "helllllllllllo "
},
{
"input": "ttttsttttt",
"output": "tttt st tttt "
},
{
"input": "tttttttsssssss",
"output": "ttttttt sssssss "
},
{
"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss",
"output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss "
},
{
"input": "xxxxx",
"output": "xxxxx "
},
{
"input": "bbbhbbb",
"output": "bbb hb bb "
},
{
"input": "bbbbbbbb",
"output": "bbbbbbbb "
}
] | 31 | 0 | -1 | 98 |
|
155 | I_love_\%username\% | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
},
{
"input": "5\n7 36 53 81 100",
"output": "4"
},
{
"input": "5\n100 81 53 36 7",
"output": "4"
},
{
"input": "10\n8 6 3 4 9 10 7 7 1 3",
"output": "5"
},
{
"input": "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862",
"output": "6"
},
{
"input": "10\n1 3 3 4 6 7 7 8 9 10",
"output": "7"
},
{
"input": "10\n1952 1862 1812 1746 1675 1627 1488 1390 1324 1137",
"output": "9"
},
{
"input": "25\n1448 4549 2310 2725 2091 3509 1565 2475 2232 3989 4231 779 2967 2702 608 3739 721 1552 2767 530 3114 665 1940 48 4198",
"output": "5"
},
{
"input": "33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101",
"output": "5"
},
{
"input": "34\n821 5536 2491 6074 7216 9885 764 1603 778 8736 8987 771 617 1587 8943 7922 439 7367 4115 8886 7878 6899 8811 5752 3184 3401 9760 9400 8995 4681 1323 6637 6554 6498",
"output": "7"
},
{
"input": "68\n6764 6877 6950 6768 6839 6755 6726 6778 6699 6805 6777 6985 6821 6801 6791 6805 6940 6761 6677 6999 6911 6699 6959 6933 6903 6843 6972 6717 6997 6756 6789 6668 6735 6852 6735 6880 6723 6834 6810 6694 6780 6679 6698 6857 6826 6896 6979 6968 6957 6988 6960 6700 6919 6892 6984 6685 6813 6678 6715 6857 6976 6902 6780 6686 6777 6686 6842 6679",
"output": "9"
},
{
"input": "60\n9000 9014 9034 9081 9131 9162 9174 9199 9202 9220 9221 9223 9229 9235 9251 9260 9268 9269 9270 9298 9307 9309 9313 9323 9386 9399 9407 9495 9497 9529 9531 9544 9614 9615 9627 9627 9643 9654 9656 9657 9685 9699 9701 9736 9745 9758 9799 9827 9843 9845 9854 9854 9885 9891 9896 9913 9942 9963 9986 9992",
"output": "57"
},
{
"input": "100\n7 61 12 52 41 16 34 99 30 44 48 89 31 54 21 1 48 52 61 15 35 87 21 76 64 92 44 81 16 93 84 92 32 15 68 76 53 39 26 4 11 26 7 4 99 99 61 65 55 85 65 67 47 39 2 74 63 49 98 87 5 94 22 30 25 42 31 84 49 23 89 60 16 26 92 27 9 57 75 61 94 35 83 47 99 100 63 24 91 88 79 10 15 45 22 64 3 11 89 83",
"output": "4"
},
{
"input": "100\n9999 9999 9999 9998 9998 9998 9997 9996 9996 9995 9993 9993 9991 9990 9989 9986 9984 9984 9983 9981 9981 9980 9980 9980 9979 9977 9977 9977 9977 9977 9976 9976 9975 9975 9973 9972 9972 9972 9972 9971 9969 9969 9969 9968 9967 9965 9962 9962 9962 9962 9960 9958 9958 9955 9954 9954 9954 9954 9950 9949 9949 9947 9943 9943 9940 9940 9939 9937 9937 9937 9936 9935 9932 9932 9931 9929 9927 9927 9926 9923 9919 9919 9918 9918 9918 9917 9917 9916 9916 9915 9914 9911 9910 9907 9907 9906 9905 9905 9904 9901",
"output": "57"
},
{
"input": "100\n158 159 157 156 155 154 160 153 161 152 162 163 151 164 150 165 149 148 147 166 146 167 145 144 143 142 168 141 169 170 140 139 138 137 171 136 135 134 172 173 174 133 175 132 177 178 131 179 180 130 129 181 128 127 182 126 183 125 124 184 123 122 121 120 119 118 117 185 186 187 188 189 116 190 115 191 192 193 114 113 112 111 110 109 108 194 195 107 106 105 196 197 104 198 199 103 102 200 101 100",
"output": "99"
},
{
"input": "2\n0 10000",
"output": "1"
},
{
"input": "2\n5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n10 10",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
}
] | 92 | 0 | 3 | 99 |
|
15 | Industrial Nim | [
"games"
] | C. Industrial Nim | 2 | 64 | There are *n* stone quarries in Petrograd.
Each quarry owns *m**i* dumpers (1<=≤<=*i*<=≤<=*n*). It is known that the first dumper of the *i*-th quarry has *x**i* stones in it, the second dumper has *x**i*<=+<=1 stones in it, the third has *x**i*<=+<=2, and the *m**i*-th dumper (the last for the *i*-th quarry) has *x**i*<=+<=*m**i*<=-<=1 stones in it.
Two oligarchs play a well-known game Nim. Players take turns removing stones from dumpers. On each turn, a player can select any dumper and remove any non-zero amount of stones from it. The player who cannot take a stone loses.
Your task is to find out which oligarch will win, provided that both of them play optimally. The oligarchs asked you not to reveal their names. So, let's call the one who takes the first stone «tolik» and the other one «bolik». | The first line of the input contains one integer number *n* (1<=≤<=*n*<=≤<=105) — the amount of quarries. Then there follow *n* lines, each of them contains two space-separated integers *x**i* and *m**i* (1<=≤<=*x**i*,<=*m**i*<=≤<=1016) — the amount of stones in the first dumper of the *i*-th quarry and the number of dumpers at the *i*-th quarry. | Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise. | [
"2\n2 1\n3 2\n",
"4\n1 1\n1 1\n1 1\n1 1\n"
] | [
"tolik\n",
"bolik\n"
] | none | [
{
"input": "2\n2 1\n3 2",
"output": "tolik"
},
{
"input": "4\n1 1\n1 1\n1 1\n1 1",
"output": "bolik"
},
{
"input": "10\n2 3\n1 4\n5 8\n4 10\n10 8\n7 2\n1 2\n1 7\n4 10\n5 3",
"output": "tolik"
},
{
"input": "20\n8 6\n6 3\n2 9\n7 8\n9 1\n2 4\n3 6\n6 3\n5 6\n5 3\n6 5\n2 10\n2 9\n6 3\n10 6\n10 10\n10 7\n3 9\n16 1\n1 3",
"output": "bolik"
},
{
"input": "30\n53 12\n13 98\n21 60\n76 58\n39 5\n62 58\n73 80\n13 75\n37 45\n44 86\n1 85\n13 33\n17 50\n12 26\n97 48\n52 40\n2 71\n95 79\n38 76\n24 54\n91 39\n97 92\n94 80\n50 61\n33 56\n22 91\n39 94\n31 56\n28 16\n20 44",
"output": "tolik"
},
{
"input": "1\n3737203222172202 1",
"output": "tolik"
},
{
"input": "1\n3737203222172202 1",
"output": "tolik"
}
] | 2,000 | 9,728,000 | 0 | 100 |
166 | Rank List | [
"binary search",
"implementation",
"sortings"
] | null | null | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.
You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=><=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=<<=*t**b*.
It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place.
Your task is to count what number of teams from the given list shared the *k*-th place. | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces. | In the only line print the sought number of teams that got the *k*-th place in the final results' table. | [
"7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n",
"5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n"
] | [
"3\n",
"4\n"
] | The final results' table for the first sample is:
- 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10
The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.
The final table for the second sample is:
- 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1
The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | [
{
"input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10",
"output": "3"
},
{
"input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1",
"output": "4"
},
{
"input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2",
"output": "2"
},
{
"input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5",
"output": "1"
},
{
"input": "5 5\n3 1\n10 2\n2 2\n1 10\n10 2",
"output": "1"
},
{
"input": "3 2\n3 3\n3 3\n3 3",
"output": "3"
},
{
"input": "4 3\n10 3\n6 10\n5 2\n5 2",
"output": "2"
},
{
"input": "5 3\n10 10\n10 10\n1 1\n10 10\n4 3",
"output": "3"
},
{
"input": "3 1\n2 1\n1 1\n1 2",
"output": "1"
},
{
"input": "1 1\n28 28",
"output": "1"
},
{
"input": "2 2\n1 2\n1 2",
"output": "2"
},
{
"input": "5 3\n2 3\n4 2\n5 3\n2 4\n3 5",
"output": "1"
},
{
"input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8",
"output": "1"
},
{
"input": "50 6\n11 20\n18 13\n1 13\n3 11\n4 17\n15 10\n15 8\n9 16\n11 17\n16 3\n3 20\n14 13\n12 15\n9 10\n14 2\n12 12\n13 17\n6 10\n20 9\n2 8\n13 7\n7 20\n15 3\n1 20\n2 13\n2 5\n14 7\n10 13\n15 12\n15 5\n17 6\n9 11\n18 5\n10 1\n15 14\n3 16\n6 12\n4 1\n14 9\n7 14\n8 17\n17 13\n4 6\n19 16\n5 6\n3 15\n4 19\n15 20\n2 10\n20 10",
"output": "1"
},
{
"input": "50 12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "50"
},
{
"input": "50 28\n2 2\n1 1\n2 1\n1 2\n1 1\n1 1\n1 1\n2 2\n2 2\n2 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n2 2\n2 1\n2 1\n2 2\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n2 1\n1 1\n2 2\n2 2\n2 2\n2 2",
"output": "13"
},
{
"input": "50 40\n2 3\n3 1\n2 1\n2 1\n2 1\n3 1\n1 1\n1 2\n2 3\n1 3\n1 3\n2 1\n3 1\n1 1\n3 1\n3 1\n2 2\n1 1\n3 3\n3 1\n3 2\n2 3\n3 3\n3 1\n1 3\n2 3\n2 1\n3 2\n3 3\n3 1\n2 1\n2 2\n1 3\n3 3\n1 1\n3 2\n1 2\n2 3\n2 1\n2 2\n3 2\n1 3\n3 1\n1 1\n3 3\n2 3\n2 1\n2 3\n2 3\n1 2",
"output": "5"
},
{
"input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3",
"output": "1"
},
{
"input": "50 32\n6 6\n4 2\n5 5\n1 1\n2 4\n6 5\n2 3\n6 5\n2 3\n6 3\n1 4\n1 6\n3 3\n2 4\n3 2\n6 2\n4 1\n3 3\n3 1\n5 5\n1 2\n2 1\n5 4\n3 1\n4 4\n5 6\n4 1\n2 5\n3 1\n4 6\n2 3\n1 1\n6 5\n2 6\n3 3\n2 6\n2 3\n2 6\n3 4\n2 6\n4 5\n5 4\n1 6\n3 2\n5 1\n4 1\n4 6\n4 2\n1 2\n5 2",
"output": "1"
},
{
"input": "50 48\n5 1\n6 4\n3 2\n2 1\n4 7\n3 6\n7 1\n7 5\n6 5\n5 6\n4 7\n5 7\n5 7\n5 5\n7 3\n3 5\n4 3\n5 4\n6 2\n1 6\n6 3\n6 5\n5 2\n4 2\n3 1\n1 1\n5 6\n1 3\n6 5\n3 7\n1 5\n7 5\n6 5\n3 6\n2 7\n5 3\n5 3\n4 7\n5 2\n6 5\n5 7\n7 1\n2 3\n5 5\n2 6\n4 1\n6 2\n6 5\n3 3\n1 6",
"output": "1"
},
{
"input": "50 8\n5 3\n7 3\n4 3\n7 4\n2 2\n4 4\n5 4\n1 1\n7 7\n4 8\n1 1\n6 3\n1 5\n7 3\n6 5\n4 5\n8 6\n3 6\n2 1\n3 2\n2 5\n7 6\n5 8\n1 3\n5 5\n8 4\n4 5\n4 4\n8 8\n7 2\n7 2\n3 6\n2 8\n8 3\n3 2\n4 5\n8 1\n3 2\n8 7\n6 3\n2 3\n5 1\n3 4\n7 2\n6 3\n7 3\n3 3\n6 4\n2 2\n5 1",
"output": "3"
},
{
"input": "20 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "20"
},
{
"input": "20 20\n1 2\n2 2\n1 1\n2 1\n2 2\n1 1\n1 1\n2 1\n1 1\n1 2\n2 2\n1 2\n1 2\n2 2\n2 2\n1 2\n2 1\n2 1\n1 2\n2 2",
"output": "6"
},
{
"input": "30 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "30"
},
{
"input": "30 22\n2 1\n1 2\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n2 2\n1 2\n2 2\n1 2\n1 2\n2 1\n1 2\n2 2\n2 2\n1 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 2\n2 2\n1 2\n2 2\n2 1\n1 1",
"output": "13"
},
{
"input": "30 22\n1 1\n1 3\n2 3\n3 1\n2 3\n3 1\n1 2\n3 3\n2 1\n2 1\n2 2\n3 1\n3 2\n2 3\n3 1\n1 3\n2 3\n3 1\n1 2\n1 2\n2 3\n2 1\n3 3\n3 2\n1 3\n3 3\n3 3\n3 3\n3 3\n3 1",
"output": "5"
},
{
"input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3",
"output": "1"
},
{
"input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8",
"output": "1"
},
{
"input": "50 22\n29 15\n18 10\n6 23\n38 28\n34 40\n40 1\n16 26\n22 33\n14 30\n26 7\n15 16\n22 40\n14 15\n6 28\n32 27\n33 3\n38 22\n40 17\n16 27\n21 27\n34 26\n5 15\n34 9\n38 23\n7 36\n17 6\n19 37\n40 1\n10 28\n9 14\n8 31\n40 8\n14 2\n24 16\n38 33\n3 37\n2 9\n21 21\n40 26\n28 33\n24 31\n10 12\n27 27\n17 4\n38 5\n21 31\n5 12\n29 7\n39 12\n26 14",
"output": "1"
},
{
"input": "50 14\n4 20\n37 50\n46 19\n20 25\n47 10\n6 34\n12 41\n47 9\n22 28\n41 34\n47 40\n12 42\n9 4\n15 15\n27 8\n38 9\n4 17\n8 13\n47 7\n9 38\n30 48\n50 7\n41 34\n23 11\n16 37\n2 32\n18 46\n37 48\n47 41\n13 9\n24 50\n46 14\n33 49\n9 50\n35 30\n49 44\n42 49\n39 15\n33 42\n3 18\n44 15\n44 28\n9 17\n16 4\n10 36\n4 22\n47 17\n24 12\n2 31\n6 30",
"output": "2"
},
{
"input": "2 1\n50 50\n50 50",
"output": "2"
},
{
"input": "2 2\n50 50\n50 50",
"output": "2"
},
{
"input": "2 1\n50 50\n50 49",
"output": "1"
},
{
"input": "2 2\n50 50\n50 49",
"output": "1"
},
{
"input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50",
"output": "50"
},
{
"input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n49 50",
"output": "1"
},
{
"input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 49",
"output": "49"
},
{
"input": "10 1\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4",
"output": "1"
},
{
"input": "4 3\n1 1\n1 2\n2 1\n2 2",
"output": "1"
},
{
"input": "4 2\n1 2\n1 3\n1 5\n1 2",
"output": "2"
},
{
"input": "6 1\n4 3\n4 2\n5 1\n5 2\n5 3\n5 3",
"output": "1"
},
{
"input": "5 3\n2 1\n1 3\n1 2\n1 1\n1 1",
"output": "2"
},
{
"input": "3 1\n1 1\n1 2\n1 3",
"output": "1"
},
{
"input": "10 10\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4",
"output": "4"
},
{
"input": "5 1\n5 5\n5 6\n5 7\n5 8\n5 5",
"output": "2"
},
{
"input": "4 1\n1 1\n1 1\n1 2\n1 3",
"output": "2"
}
] | 154 | 3,584,000 | 3 | 101 |
|
527 | Playing with Paper | [
"implementation",
"math"
] | null | null | One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson? | The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=<<=*a*<=≤<=1012) — the sizes of the original sheet of paper. | Print a single integer — the number of ships that Vasya will make. | [
"2 1\n",
"10 7\n",
"1000000000000 1\n"
] | [
"2\n",
"6\n",
"1000000000000\n"
] | Pictures to the first and second sample test. | [
{
"input": "2 1",
"output": "2"
},
{
"input": "10 7",
"output": "6"
},
{
"input": "1000000000000 1",
"output": "1000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "3 2",
"output": "3"
},
{
"input": "4 2",
"output": "2"
},
{
"input": "1000 700",
"output": "6"
},
{
"input": "959986566087 524054155168",
"output": "90"
},
{
"input": "4 3",
"output": "4"
},
{
"input": "7 6",
"output": "7"
},
{
"input": "1000 999",
"output": "1000"
},
{
"input": "1000 998",
"output": "500"
},
{
"input": "1000 997",
"output": "336"
},
{
"input": "42 1",
"output": "42"
},
{
"input": "1000 1",
"output": "1000"
},
{
"input": "8 5",
"output": "5"
},
{
"input": "13 8",
"output": "6"
},
{
"input": "987 610",
"output": "15"
},
{
"input": "442 42",
"output": "22"
},
{
"input": "754 466",
"output": "13"
},
{
"input": "1000000000000 999999999999",
"output": "1000000000000"
},
{
"input": "1000000000000 999999999998",
"output": "500000000000"
},
{
"input": "941 14",
"output": "74"
},
{
"input": "998 2",
"output": "499"
},
{
"input": "1000 42",
"output": "32"
},
{
"input": "1000 17",
"output": "66"
},
{
"input": "5 1",
"output": "5"
},
{
"input": "5 2",
"output": "4"
},
{
"input": "5 3",
"output": "4"
},
{
"input": "5 4",
"output": "5"
},
{
"input": "293 210",
"output": "17"
},
{
"input": "787878787878 424242424242",
"output": "8"
},
{
"input": "956722026041 591286729879",
"output": "58"
},
{
"input": "956722026041 365435296162",
"output": "58"
},
{
"input": "628625247282 464807889701",
"output": "102"
},
{
"input": "695928431619 424778620208",
"output": "167"
},
{
"input": "1000000000000 42",
"output": "23809523821"
},
{
"input": "987654345678 23",
"output": "42941493300"
},
{
"input": "10000000001 2",
"output": "5000000002"
},
{
"input": "1000000000000 2",
"output": "500000000000"
},
{
"input": "1000000000000 3",
"output": "333333333336"
},
{
"input": "100000000000 3",
"output": "33333333336"
},
{
"input": "100000000000 23",
"output": "4347826109"
},
{
"input": "999999999997 7",
"output": "142857142861"
},
{
"input": "8589934592 4294967296",
"output": "2"
}
] | 124 | 6,656,000 | 3 | 102 |
|
344 | Magnets | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",
"output": "3"
},
{
"input": "1\n01",
"output": "1"
},
{
"input": "2\n01\n01",
"output": "1"
},
{
"input": "2\n10\n01",
"output": "2"
},
{
"input": "3\n01\n01\n01",
"output": "1"
},
{
"input": "3\n10\n10\n01",
"output": "2"
},
{
"input": "3\n01\n10\n10",
"output": "2"
},
{
"input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10",
"output": "55"
}
] | 1,000 | 11,059,200 | 0 | 103 |
|
535 | Tavas and SaDDas | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You are given a lucky number *n*. 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.
If we sort all lucky numbers in increasing order, what's the 1-based index of *n*?
Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back. | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"output": "8"
},
{
"input": "774",
"output": "13"
},
{
"input": "4",
"output": "1"
},
{
"input": "4447747",
"output": "140"
},
{
"input": "7747474",
"output": "233"
},
{
"input": "4444",
"output": "15"
},
{
"input": "4447",
"output": "16"
},
{
"input": "7",
"output": "2"
},
{
"input": "4",
"output": "1"
},
{
"input": "4447744",
"output": "139"
},
{
"input": "77474",
"output": "57"
},
{
"input": "7747",
"output": "28"
},
{
"input": "444",
"output": "7"
},
{
"input": "7",
"output": "2"
},
{
"input": "7774477",
"output": "242"
},
{
"input": "4477774",
"output": "157"
},
{
"input": "7444",
"output": "23"
},
{
"input": "7474747",
"output": "212"
},
{
"input": "77",
"output": "6"
},
{
"input": "774477",
"output": "114"
},
{
"input": "7",
"output": "2"
},
{
"input": "47",
"output": "4"
},
{
"input": "747777",
"output": "110"
},
{
"input": "444444444",
"output": "511"
},
{
"input": "777777777",
"output": "1022"
},
{
"input": "477477447",
"output": "728"
},
{
"input": "777744747",
"output": "996"
}
] | 109 | 0 | 3 | 105 |
|
12 | Super Agent | [
"implementation"
] | A. Super Agent | 2 | 256 | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.
Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=×<=3 with digits from 1 to 9.
Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations. | Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». | Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. | [
"XX.\n...\n.XX\n",
"X.X\nX..\n...\n"
] | [
"YES\n",
"NO\n"
] | If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | [
{
"input": "XX.\n...\n.XX",
"output": "YES"
},
{
"input": ".X.\n.X.\n.X.",
"output": "YES"
},
{
"input": "XXX\nXXX\nXXX",
"output": "YES"
},
{
"input": "XXX\nX.X\nXXX",
"output": "YES"
},
{
"input": "X..\n.X.\n..X",
"output": "YES"
},
{
"input": "...\nX.X\nX..",
"output": "NO"
},
{
"input": ".X.\nX.X\n.X.",
"output": "YES"
},
{
"input": "X.X\n.X.\nX.X",
"output": "YES"
},
{
"input": "...\n...\n..X",
"output": "NO"
},
{
"input": "XXX\n...\nXXX",
"output": "YES"
},
{
"input": "..X\nX..\n..X",
"output": "NO"
},
{
"input": ".X.\n...\nX.X",
"output": "NO"
},
{
"input": "X.X\nX.X\nX.X",
"output": "YES"
},
{
"input": ".X.\nX.X\nXX.",
"output": "NO"
},
{
"input": "...\nXXX\nXXX",
"output": "NO"
},
{
"input": "XXX\n..X\nXXX",
"output": "NO"
},
{
"input": "X..\nX.X\n.X.",
"output": "NO"
},
{
"input": "...\n..X\nXXX",
"output": "NO"
},
{
"input": "..X\nX.X\nX..",
"output": "YES"
},
{
"input": "..X\n..X\nXXX",
"output": "NO"
},
{
"input": "X..\nX..\nX..",
"output": "NO"
},
{
"input": "XXX\n.X.\nXXX",
"output": "YES"
},
{
"input": "..X\n...\nX..",
"output": "YES"
},
{
"input": "...\n...\nX..",
"output": "NO"
},
{
"input": "...\n...\n.X.",
"output": "NO"
},
{
"input": "...\n...\n..X",
"output": "NO"
},
{
"input": "...\n.X.\nX..",
"output": "NO"
}
] | 92 | 0 | 3.977 | 106 |
378 | Semifinals | [
"implementation",
"sortings"
] | null | null | Two semifinals have just been in the running tournament. Each semifinal had *n* participants. There are *n* participants advancing to the finals, they are chosen as follows: from each semifinal, we choose *k* people (0<=≤<=2*k*<=≤<=*n*) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top *k* in their semifinal but got to the *n*<=-<=2*k* of the best among the others.
The tournament organizers hasn't yet determined the *k* value, so the participants want to know who else has any chance to get to the finals and who can go home. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of participants in each semifinal.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=109) — the results of the *i*-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences *a*1, *a*2, ..., *a**n* and *b*1, *b*2, ..., *b**n* are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal. | Print two strings consisting of *n* characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The *i*-th character in the *j*-th line should equal "1" if the *i*-th participant of the *j*-th semifinal has any chances to advance to the finals, otherwise it should equal a "0". | [
"4\n9840 9920\n9860 9980\n9930 10020\n10040 10090\n",
"4\n9900 9850\n9940 9930\n10000 10020\n10060 10110\n"
] | [
"1110\n1100\n",
"1100\n1100\n"
] | Consider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090.
- If *k* = 0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. - If *k* = 1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). - If *k* = 2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds. | [
{
"input": "4\n9840 9920\n9860 9980\n9930 10020\n10040 10090",
"output": "1110\n1100"
},
{
"input": "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110",
"output": "1100\n1100"
},
{
"input": "1\n1 2",
"output": "1\n0"
},
{
"input": "1\n2 1",
"output": "0\n1"
},
{
"input": "2\n1 2\n3 4",
"output": "10\n10"
},
{
"input": "2\n3 1\n4 2",
"output": "10\n11"
},
{
"input": "3\n1 3\n2 5\n4 6",
"output": "110\n100"
},
{
"input": "3\n2 1\n4 3\n5 6",
"output": "100\n110"
},
{
"input": "3\n1 4\n2 5\n3 6",
"output": "111\n100"
},
{
"input": "4\n5 1\n6 2\n7 3\n8 4",
"output": "1100\n1111"
},
{
"input": "2\n1 2\n4 3",
"output": "10\n10"
},
{
"input": "3\n1 2\n3 5\n4 6",
"output": "110\n100"
},
{
"input": "3\n1 2\n3 4\n5 6",
"output": "110\n100"
},
{
"input": "3\n1 3\n2 4\n5 6",
"output": "110\n100"
},
{
"input": "3\n1 3\n2 4\n6 5",
"output": "110\n100"
},
{
"input": "3\n2 1\n3 4\n6 5",
"output": "110\n100"
},
{
"input": "3\n1 2\n4 3\n6 5",
"output": "100\n110"
},
{
"input": "3\n2 1\n3 5\n4 6",
"output": "110\n100"
},
{
"input": "4\n1 4\n2 5\n3 6\n8 7",
"output": "1110\n1100"
},
{
"input": "4\n1 3\n2 4\n7 5\n8 6",
"output": "1100\n1100"
},
{
"input": "4\n2 1\n3 4\n6 5\n7 8",
"output": "1100\n1100"
},
{
"input": "8\n100 101\n200 201\n300 301\n310 400\n320 500\n330 600\n340 700\n350 800",
"output": "11111000\n11110000"
}
] | 1,000 | 24,780,800 | 0 | 107 |