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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
120 | Winnie-the-Pooh and honey | [
"implementation",
"math"
] | null | null | As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are *n* jars of honey lined up in front of Winnie-the-Pooh, jar number *i* contains *a**i* kilos of honey. Winnie-the-Pooh eats the honey like that: each time he chooses a jar containing most honey. If the jar has less that *k* kilos of honey or if Winnie-the-Pooh has already eaten from it three times, he gives the jar to Piglet. Otherwise he eats exactly *k* kilos of honey from the jar and puts it back. Winnie does so until he gives all jars to the Piglet. Count how much honey Piglet will overall get after Winnie satisfies his hunger. | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=100,<=1<=β€<=*k*<=β€<=100). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, separated by spaces (1<=β€<=*a**i*<=β€<=100). | Print a single number β how many kilos of honey gets Piglet. | [
"3 3\n15 8 10\n"
] | [
"9\n"
] | none | [
{
"input": "3 3\n15 8 10",
"output": "9"
},
{
"input": "1 3\n3",
"output": "0"
},
{
"input": "3 4\n3 8 2",
"output": "5"
},
{
"input": "3 2\n95 25 49",
"output": "151"
},
{
"input": "3 1\n8 3 2",
"output": "5"
},
{
"input": "5 1\n4 7 9 5 7",
"output": "17"
},
{
"input": "8 6\n19 15 1 14 7 2 10 14",
"output": "16"
},
{
"input": "8 5\n5 2 17 12 16 12 17 3",
"output": "14"
},
{
"input": "10 7\n26 11 10 8 5 20 9 27 30 9",
"output": "43"
},
{
"input": "10 10\n20 82 19 82 18 96 40 99 87 2",
"output": "325"
},
{
"input": "10 10\n75 52 78 83 60 31 46 28 33 17",
"output": "233"
},
{
"input": "20 5\n33 45 36 13 46 40 15 11 29 44 43 50 14 19 46 46 46 26 42 6",
"output": "375"
},
{
"input": "20 2\n4 2 6 9 8 4 4 7 2 3 7 7 10 6 3 5 2 9 8 5",
"output": "21"
},
{
"input": "30 3\n20 37 89 77 74 6 52 87 19 58 3 38 40 38 42 12 1 23 29 38 12 65 15 1 92 45 23 94 61 73",
"output": "1021"
},
{
"input": "30 2\n10 5 46 30 28 18 24 35 73 2 10 24 72 86 97 95 71 12 14 57 27 94 81 59 43 77 22 58 16 96",
"output": "1208"
},
{
"input": "50 13\n53 55 51 81 59 22 11 20 30 80 38 17 8 38 69 52 11 74 16 38 80 97 39 74 78 56 75 28 4 58 80 88 78 89 95 8 13 70 36 29 49 15 74 44 19 52 42 59 92 37",
"output": "1012"
},
{
"input": "100 33\n84 70 12 53 10 38 4 66 42 1 100 98 42 10 31 26 22 94 19 43 86 5 37 64 77 98 81 40 17 66 52 43 5 7 79 92 44 78 9 95 10 86 42 56 34 91 12 17 26 16 24 99 11 37 89 100 60 74 32 66 13 29 3 24 41 99 93 87 85 74 5 3 70 46 23 12 43 10 24 32 95 2 57 86 29 100 29 62 17 24 4 40 40 73 29 11 69 89 10 31",
"output": "1467"
},
{
"input": "100 12\n90 59 100 12 82 31 66 28 7 13 43 42 48 94 60 32 20 92 37 39 22 55 14 23 77 56 21 55 10 89 93 79 5 80 40 80 6 15 56 82 68 61 32 100 23 7 13 92 32 82 17 85 49 85 13 75 4 7 42 14 84 22 50 12 11 75 4 85 32 96 56 13 34 100 66 37 58 58 24 58 81 63 59 55 89 97 90 69 29 11 71 58 58 43 72 96 81 72 14 64",
"output": "2377"
},
{
"input": "100 3\n92 51 91 67 32 97 40 24 78 72 93 90 57 77 66 13 55 24 17 90 65 35 69 97 79 31 85 2 90 80 49 44 73 77 34 45 74 75 35 14 34 56 60 54 36 55 16 49 12 54 92 68 70 71 5 79 67 89 64 80 20 84 4 39 55 84 53 59 68 11 89 89 15 73 67 86 91 78 49 24 58 83 55 34 82 97 27 29 78 15 20 48 9 87 41 34 91 76 82 44",
"output": "4839"
},
{
"input": "100 1\n85 75 55 65 39 26 47 16 9 11 3 4 70 23 56 64 36 34 16 13 18 28 32 80 8 79 76 4 21 75 93 51 85 86 100 88 91 71 97 28 66 22 47 87 91 95 3 56 81 53 88 90 21 30 74 45 58 73 36 40 70 51 28 75 20 54 69 52 14 48 52 53 91 81 32 68 16 48 60 66 91 32 55 42 93 51 3 46 23 64 39 1 30 42 20 83 99 29 35 59",
"output": "4801"
}
] | 218 | 0 | 3 | 726 |
|
120 | Elevator | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand.
One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed. | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=β€<=*a*<=β€<=2) which denotes the number of the rail at which the person was holding. | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 216 | 0 | 0 | 727 |
|
903 | The Modcrab | [
"greedy",
"implementation"
] | null | null | Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.
After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has *h*2 health points and an attack power of *a*2. Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle.
Vova's character has *h*1 health points and an attack power of *a*1. Also he has a large supply of healing potions, each of which increases his current amount of health points by *c*1 when Vova drinks a potion. All potions are identical to each other. It is guaranteed that *c*1<=><=*a*2.
The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by *a*1) or drink a healing potion (it increases Vova's health by *c*1; Vova's health can exceed *h*1). Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by *a*2. The battle ends when Vova's (or Modcrab's) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova's attack.
Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases.
Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win. | The first line contains three integers *h*1, *a*1, *c*1 (1<=β€<=*h*1,<=*a*1<=β€<=100, 2<=β€<=*c*1<=β€<=100) β Vova's health, Vova's attack power and the healing power of a potion.
The second line contains two integers *h*2, *a*2 (1<=β€<=*h*2<=β€<=100, 1<=β€<=*a*2<=<<=*c*1) β the Modcrab's health and his attack power. | In the first line print one integer *n* denoting the minimum number of phases required to win the battle.
Then print *n* lines. *i*-th line must be equal to HEAL if Vova drinks a potion in *i*-th phase, or STRIKE if he attacks the Modcrab.
The strategy must be valid: Vova's character must not be defeated before slaying the Modcrab, and the monster's health must be 0 or lower after Vova's last action.
If there are multiple optimal solutions, print any of them. | [
"10 6 100\n17 5\n",
"11 6 100\n12 5\n"
] | [
"4\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n",
"2\nSTRIKE\nSTRIKE\n"
] | In the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win.
In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left. | [
{
"input": "10 6 100\n17 5",
"output": "4\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE"
},
{
"input": "11 6 100\n12 5",
"output": "2\nSTRIKE\nSTRIKE"
},
{
"input": "25 27 91\n10 87",
"output": "1\nSTRIKE"
},
{
"input": "79 4 68\n9 65",
"output": "21\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nSTRIKE"
},
{
"input": "9 1 20\n4 19",
"output": "53\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nSTRIKE"
},
{
"input": "1 1 100\n100 99",
"output": "9901\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nH..."
},
{
"input": "6 6 100\n12 5",
"output": "2\nSTRIKE\nSTRIKE"
},
{
"input": "9 76 78\n86 69",
"output": "9\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nSTRIKE"
},
{
"input": "62 21 10\n47 2",
"output": "3\nSTRIKE\nSTRIKE\nSTRIKE"
},
{
"input": "50 1 2\n70 1",
"output": "90\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEA..."
},
{
"input": "4 1 2\n10 1",
"output": "16\nSTRIKE\nSTRIKE\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE"
},
{
"input": "1 1 2\n3 1",
"output": "5\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE"
},
{
"input": "14 5 2\n99 1",
"output": "26\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE"
},
{
"input": "20 1 5\n8 4",
"output": "17\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nSTRIKE"
},
{
"input": "12 12 19\n83 8",
"output": "11\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE"
},
{
"input": "5 12 11\n4 2",
"output": "1\nSTRIKE"
},
{
"input": "34 14 18\n74 14",
"output": "16\nSTRIKE\nSTRIKE\nHEAL\nHEAL\nHEAL\nSTRIKE\nHEAL\nHEAL\nHEAL\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nSTRIKE"
}
] | 140 | 0 | 0 | 728 |
|
567 | Lineland Mail | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* β a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββ*min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city | The first line of the input contains integer *n* (2<=β€<=*n*<=β€<=105) β the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=β€<=*x**i*<=β€<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
"output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000"
},
{
"input": "2\n-1000000000 1000000000",
"output": "2000000000 2000000000\n2000000000 2000000000"
},
{
"input": "10\n1 10 12 15 59 68 130 912 1239 9123",
"output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122"
},
{
"input": "5\n-2 -1 0 1 2",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "5\n-2 -1 0 1 3",
"output": "1 5\n1 4\n1 3\n1 3\n2 5"
},
{
"input": "3\n-10000 1 10000",
"output": "10001 20000\n9999 10001\n9999 20000"
},
{
"input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706",
"output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010"
},
{
"input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124",
"output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524"
},
{
"input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292",
"output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307"
},
{
"input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986",
"output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14"
},
{
"input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886",
"output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..."
},
{
"input": "3\n-1000000000 999999999 1000000000",
"output": "1999999999 2000000000\n1 1999999999\n1 2000000000"
}
] | 499 | 8,601,600 | 3 | 730 |
|
159 | String Manipulation 1.0 | [
"*special",
"binary search",
"brute force",
"data structures",
"strings"
] | null | null | One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name *s*, a user can pick number *p* and character *c* and delete the *p*-th occurrence of character *c* from the name. After the user changed his name, he can't undo the change.
For example, one can change name "arca" by removing the second occurrence of character "a" to get "arc".
Polycarpus learned that some user initially registered under nickname *t*, where *t* is a concatenation of *k* copies of string *s*. Also, Polycarpus knows the sequence of this user's name changes. Help Polycarpus figure out the user's final name. | The first line contains an integer *k* (1<=β€<=*k*<=β€<=2000). The second line contains a non-empty string *s*, consisting of lowercase Latin letters, at most 100 characters long. The third line contains an integer *n* (0<=β€<=*n*<=β€<=20000) β the number of username changes. Each of the next *n* lines contains the actual changes, one per line. The changes are written as "*p**i* *c**i*" (without the quotes), where *p**i* (1<=β€<=*p**i*<=β€<=200000) is the number of occurrences of letter *c**i*, *c**i* is a lowercase Latin letter. It is guaranteed that the operations are correct, that is, the letter to be deleted always exists, and after all operations not all letters are deleted from the name. The letters' occurrences are numbered starting from 1. | Print a single string β the user's final name after all changes are applied to it. | [
"2\nbac\n3\n2 a\n1 b\n2 c\n",
"1\nabacaba\n4\n1 a\n1 a\n1 c\n2 b\n"
] | [
"acb\n",
"baa\n"
] | Let's consider the first sample. Initially we have name "bacbac"; the first operation transforms it into "bacbc", the second one β to "acbc", and finally, the third one transforms it into "acb". | [
{
"input": "2\nbac\n3\n2 a\n1 b\n2 c",
"output": "acb"
},
{
"input": "1\nabacaba\n4\n1 a\n1 a\n1 c\n2 b",
"output": "baa"
},
{
"input": "1\naabbabbb\n7\n2 a\n1 a\n1 a\n2 b\n1 b\n3 b\n1 b",
"output": "b"
},
{
"input": "1\na\n0",
"output": "a"
},
{
"input": "4\ndb\n5\n1 d\n2 d\n2 b\n1 d\n2 b",
"output": "bdb"
},
{
"input": "10\nbabcbcbcba\n40\n24 b\n14 a\n19 b\n25 b\n26 c\n7 c\n5 c\n2 a\n4 c\n7 a\n46 b\n14 a\n28 b\n4 c\n5 a\n10 c\n4 c\n4 b\n12 a\n4 a\n30 b\n4 a\n16 b\n4 c\n4 c\n23 b\n8 c\n20 c\n12 c\n2 a\n9 c\n37 b\n11 c\n27 b\n16 c\n5 b\n6 b\n3 c\n4 b\n16 b",
"output": "babcbcbbbabbbbbbbccbbacbcbabacbbaabcbcbabbcbcbbbcbbcababcbba"
},
{
"input": "10\nbcbccaacab\n40\n37 c\n21 a\n18 a\n5 b\n1 a\n8 c\n9 a\n38 c\n10 b\n12 c\n18 a\n23 a\n20 c\n7 b\n33 c\n4 c\n22 c\n28 c\n9 a\n12 a\n22 a\n1 b\n6 a\n31 c\n19 b\n19 a\n15 a\n6 c\n11 c\n18 b\n19 c\n24 c\n8 a\n16 c\n2 c\n12 b\n8 a\n14 c\n18 b\n19 c",
"output": "cbcaabbccaaabbcccacabbccbbcbccabbcaacbbbcaacbccabbccaabbbcab"
},
{
"input": "10\nccbcabbaca\n40\n2 c\n8 b\n26 b\n12 b\n24 a\n29 a\n20 c\n17 b\n32 c\n9 c\n16 b\n13 b\n19 a\n3 c\n2 b\n18 c\n4 a\n13 c\n8 c\n5 c\n13 a\n19 c\n26 c\n13 c\n6 c\n3 c\n4 a\n5 a\n9 c\n8 b\n9 c\n2 c\n19 a\n5 a\n12 c\n10 c\n2 b\n19 c\n21 a\n16 b",
"output": "cbaaacbbbcabbcacccabbaaabcabcabaacbbacaccbcabaccbcbaacbcabbc"
},
{
"input": "10\nabaabbaaac\n40\n10 b\n24 a\n15 a\n7 b\n22 b\n23 b\n50 a\n43 a\n2 c\n24 b\n9 b\n5 c\n6 c\n18 b\n33 a\n5 c\n2 a\n3 c\n2 b\n27 a\n2 c\n4 a\n1 c\n6 a\n1 b\n12 b\n31 a\n13 b\n35 a\n2 c\n40 a\n24 a\n1 c\n31 a\n17 b\n4 b\n1 c\n12 b\n4 b\n39 a",
"output": "aabaaababaaaaabaaaaaabaaabaabbaabaabaaaaaababaaaabaaaaabbaaa"
},
{
"input": "10\nabbaa\n10\n20 a\n2 b\n25 a\n22 a\n13 a\n5 b\n17 b\n1 a\n16 b\n6 a",
"output": "baaabbaabaaabbaabbaaabbaaabbaabbaabaabaa"
}
] | 2,806 | 12,800,000 | 3 | 732 |
|
0 | none | [
"none"
] | null | null | Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of color *i*<=+<=1 for all *i* from 1 to *k*<=-<=1. Now he wonders how many different ways this can happen. | The first line of input will have one integer *k* (1<=β€<=*k*<=β€<=1000) the number of colors.
Then, *k* lines will follow. The *i*-th line will contain *c**i*, the number of balls of the *i*-th color (1<=β€<=*c**i*<=β€<=1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1<=000<=000<=007. | [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n"
] | [
"3\n",
"1680\n"
] | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | [
{
"input": "3\n2\n2\n1",
"output": "3"
},
{
"input": "4\n1\n2\n3\n4",
"output": "1680"
},
{
"input": "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "12520708"
},
{
"input": "5\n10\n10\n10\n10\n10",
"output": "425711769"
},
{
"input": "11\n291\n381\n126\n39\n19\n20\n3\n1\n20\n45\n2",
"output": "902382672"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "13\n67\n75\n76\n80\n69\n86\n75\n86\n81\n84\n73\n72\n76",
"output": "232242896"
},
{
"input": "25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\n62\n39\n40\n35\n43\n31\n42\n46\n42\n34\n33",
"output": "362689152"
},
{
"input": "47\n20\n21\n16\n18\n24\n20\n25\n13\n20\n22\n26\n24\n17\n18\n21\n22\n21\n23\n17\n15\n24\n19\n18\n21\n20\n19\n26\n25\n20\n17\n17\n17\n26\n32\n20\n21\n25\n28\n24\n21\n21\n17\n28\n20\n20\n31\n19",
"output": "295545118"
},
{
"input": "3\n343\n317\n337",
"output": "691446102"
},
{
"input": "1\n5",
"output": "1"
}
] | 202 | 2,662,400 | -1 | 734 |
|
988 | Divisibility by 25 | [
"brute force",
"greedy"
] | null | null | You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes.
In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.
What is the minimum number of moves you have to make to obtain a number that is divisible by $25$? Print -1 if it is impossible to obtain a number that is divisible by $25$. | The first line contains an integer $n$ ($1 \le n \le 10^{18}$). It is guaranteed that the first (left) digit of the number $n$ is not a zero. | If it is impossible to obtain a number that is divisible by $25$, print -1. Otherwise print the minimum number of moves required to obtain such number.
Note that you can swap only adjacent digits in the given number. | [
"5071\n",
"705\n",
"1241367\n"
] | [
"4\n",
"1\n",
"-1\n"
] | In the first example one of the possible sequences of moves is 5071 $\rightarrow$ 5701 $\rightarrow$ 7501 $\rightarrow$ 7510 $\rightarrow$ 7150. | [
{
"input": "5071",
"output": "4"
},
{
"input": "705",
"output": "1"
},
{
"input": "1241367",
"output": "-1"
},
{
"input": "7501",
"output": "2"
},
{
"input": "507",
"output": "2"
},
{
"input": "17010",
"output": "1"
},
{
"input": "52231",
"output": "6"
},
{
"input": "50267",
"output": "5"
},
{
"input": "574196831896431419",
"output": "33"
},
{
"input": "1",
"output": "-1"
},
{
"input": "10",
"output": "-1"
},
{
"input": "123456123450",
"output": "0"
},
{
"input": "1000000000000000000",
"output": "0"
},
{
"input": "100000000000762582",
"output": "2"
},
{
"input": "123456789987654321",
"output": "5"
},
{
"input": "213716413141380147",
"output": "-1"
},
{
"input": "5284691",
"output": "11"
},
{
"input": "750000000000000001",
"output": "2"
},
{
"input": "101",
"output": "-1"
},
{
"input": "275257725752725722",
"output": "3"
},
{
"input": "50932",
"output": "5"
},
{
"input": "50272",
"output": "5"
},
{
"input": "25",
"output": "0"
},
{
"input": "52",
"output": "1"
},
{
"input": "57",
"output": "1"
},
{
"input": "75",
"output": "0"
},
{
"input": "50",
"output": "0"
},
{
"input": "71",
"output": "-1"
},
{
"input": "500111117",
"output": "10"
},
{
"input": "50011117",
"output": "9"
},
{
"input": "1002",
"output": "2"
},
{
"input": "521",
"output": "3"
},
{
"input": "50011111112",
"output": "12"
},
{
"input": "50000111111112",
"output": "17"
},
{
"input": "250070000011111111",
"output": "16"
},
{
"input": "502727272727272727",
"output": "18"
},
{
"input": "500044444444442",
"output": "17"
},
{
"input": "2057",
"output": "1"
},
{
"input": "700777111111222222",
"output": "30"
},
{
"input": "50001111312",
"output": "13"
},
{
"input": "700272727272727272",
"output": "30"
},
{
"input": "700777711111222222",
"output": "30"
},
{
"input": "20029292929292929",
"output": "28"
},
{
"input": "257025702570257025",
"output": "0"
},
{
"input": "5001111117",
"output": "11"
},
{
"input": "227782777298772774",
"output": "-1"
},
{
"input": "205727272727272727",
"output": "15"
},
{
"input": "50011112",
"output": "9"
},
{
"input": "500272727272727272",
"output": "19"
},
{
"input": "222772277289624486",
"output": "-1"
},
{
"input": "5002727272727272",
"output": "17"
},
{
"input": "200000000222222222",
"output": "18"
}
] | 62 | 2,764,800 | 0 | 737 |
|
11 | Increasing Sequence | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? | The first line of the input contains two integer numbers *n* and *d* (2<=β€<=*n*<=β€<=2000,<=1<=β€<=*d*<=β€<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=β€<=*b**i*<=β€<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
{
"input": "2 7\n1 1",
"output": "1"
},
{
"input": "3 3\n18 1 9",
"output": "10"
},
{
"input": "3 3\n15 17 9",
"output": "3"
},
{
"input": "3 3\n10 9 12",
"output": "2"
},
{
"input": "10 3\n2 1 17 10 5 16 8 4 15 17",
"output": "31"
},
{
"input": "10 3\n6 11 4 12 22 15 23 26 24 26",
"output": "13"
},
{
"input": "10 3\n10 24 13 15 18 14 15 26 33 35",
"output": "29"
},
{
"input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580",
"output": "15717"
},
{
"input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327",
"output": "16133"
}
] | 124 | 0 | 3.938 | 739 |
873 | Merge Sort | [
"constructive algorithms",
"divide and conquer"
] | null | null | Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows:
1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=β€<=*i*<=<<=*r*<=-<=1 *a*[*i*]<=β€<=*a*[*i*<=+<=1]), then end the function call; 1. Let ; 1. Call *mergesort*(*a*,<=*l*,<=*mid*); 1. Call *mergesort*(*a*,<=*mid*,<=*r*); 1. Merge segments [*l*,<=*mid*) and [*mid*,<=*r*), making the segment [*l*,<=*r*) sorted in non-descending order. The merge algorithm doesn't call any other functions.
The array in this problem is 0-indexed, so to sort the whole array, you need to call *mergesort*(*a*,<=0,<=*n*).
The number of calls of function *mergesort* is very important, so Ivan has decided to calculate it while sorting the array. For example, if *a*<==<={1,<=2,<=3,<=4}, then there will be 1 call of *mergesort* β *mergesort*(0,<=4), which will check that the array is sorted and then end. If *a*<==<={2,<=1,<=3}, then the number of calls is 3: first of all, you call *mergesort*(0,<=3), which then sets *mid*<==<=1 and calls *mergesort*(0,<=1) and *mergesort*(1,<=3), which do not perform any recursive calls because segments (0,<=1) and (1,<=3) are sorted.
Ivan has implemented the program that counts the number of *mergesort* calls, but now he needs to test it. To do this, he needs to find an array *a* such that *a* is a permutation of size *n* (that is, the number of elements in *a* is *n*, and every integer number from [1,<=*n*] can be found in this array), and the number of *mergesort* calls when sorting the array is exactly *k*.
Help Ivan to find an array he wants! | The first line contains two numbers *n* and *k* (1<=β€<=*n*<=β€<=100000, 1<=β€<=*k*<=β€<=200000) β the size of a desired permutation and the number of *mergesort* calls required to sort it. | If a permutation of size *n* such that there will be exactly *k* calls of *mergesort* while sorting it doesn't exist, output <=-<=1. Otherwise output *n* integer numbers *a*[0],<=*a*[1],<=...,<=*a*[*n*<=-<=1] β the elements of a permutation that would meet the required conditions. If there are multiple answers, print any of them. | [
"3 3\n",
"4 1\n",
"5 6\n"
] | [
"2 1 3 ",
"1 2 3 4 ",
"-1\n"
] | none | [
{
"input": "3 3",
"output": "2 1 3 "
},
{
"input": "4 1",
"output": "1 2 3 4 "
},
{
"input": "5 6",
"output": "-1"
},
{
"input": "100 100",
"output": "-1"
},
{
"input": "10000 10001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "10000 20001",
"output": "-1"
},
{
"input": "10000 30001",
"output": "-1"
},
{
"input": "20000 10001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "20000 20001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "20000 30001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "30000 10001",
"output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..."
},
{
"input": "30000 20001",
"output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..."
},
{
"input": "30000 30001",
"output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..."
},
{
"input": "40000 10001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "40000 20001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "40000 30001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "50000 10001",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "50000 20001",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "50000 30001",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "60000 10001",
"output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..."
},
{
"input": "60000 20001",
"output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..."
},
{
"input": "60000 30001",
"output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..."
},
{
"input": "70000 10001",
"output": "3 1 5 2 7 4 9 6 11 8 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 32 29 33 35 31 37 34 39 36 41 38 43 40 45 42 47 44 49 46 50 52 48 54 51 56 53 58 55 60 57 62 59 64 61 66 63 67 69 65 71 68 73 70 75 72 77 74 79 76 81 78 83 80 84 86 82 88 85 90 87 92 89 94 91 96 93 98 95 100 97 101 103 99 105 102 107 104 109 106 111 108 113 110 115 112 117 114 118 120 116 122 119 124 121 126 123 128 125 130 127 132 129 134 131 135 137 133 139 136 141 138 143 140 145 142 147 144 149 146 151 148 152 154 150 156 153..."
},
{
"input": "70000 20001",
"output": "3 1 5 2 7 4 9 6 11 8 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 32 29 33 35 31 37 34 39 36 41 38 43 40 45 42 47 44 49 46 50 52 48 54 51 56 53 58 55 60 57 62 59 64 61 66 63 67 69 65 71 68 73 70 75 72 77 74 79 76 81 78 83 80 84 86 82 88 85 90 87 92 89 94 91 96 93 98 95 100 97 101 103 99 105 102 107 104 109 106 111 108 113 110 115 112 117 114 118 120 116 122 119 124 121 126 123 128 125 130 127 132 129 134 131 135 137 133 139 136 141 138 143 140 145 142 147 144 149 146 151 148 152 154 150 156 153..."
},
{
"input": "70000 30001",
"output": "3 1 5 2 7 4 9 6 11 8 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 32 29 33 35 31 37 34 39 36 41 38 43 40 45 42 47 44 49 46 50 52 48 54 51 56 53 58 55 60 57 62 59 64 61 66 63 67 69 65 71 68 73 70 75 72 77 74 79 76 81 78 83 80 84 86 82 88 85 90 87 92 89 94 91 96 93 98 95 100 97 101 103 99 105 102 107 104 109 106 111 108 113 110 115 112 117 114 118 120 116 122 119 124 121 126 123 128 125 130 127 132 129 134 131 135 137 133 139 136 141 138 143 140 145 142 147 144 149 146 151 148 152 154 150 156 153..."
},
{
"input": "80000 10001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "80000 20001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "80000 30001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..."
},
{
"input": "90000 10001",
"output": "3 1 4 6 2 8 5 9 11 7 13 10 14 16 12 17 19 15 20 22 18 24 21 25 27 23 28 30 26 31 33 29 35 32 36 38 34 39 41 37 42 44 40 46 43 47 49 45 50 52 48 53 55 51 57 54 58 60 56 61 63 59 64 66 62 68 65 69 71 67 72 74 70 75 77 73 79 76 80 82 78 83 85 81 86 88 84 90 87 91 93 89 94 96 92 97 99 95 101 98 102 104 100 105 107 103 108 110 106 112 109 113 115 111 116 118 114 119 121 117 123 120 124 126 122 127 129 125 130 132 128 134 131 135 137 133 138 140 136 141 143 139 145 142 146 148 144 149 151 147 152 154 150 156 153..."
},
{
"input": "90000 20001",
"output": "3 1 4 6 2 8 5 9 11 7 13 10 14 16 12 17 19 15 20 22 18 24 21 25 27 23 28 30 26 31 33 29 35 32 36 38 34 39 41 37 42 44 40 46 43 47 49 45 50 52 48 53 55 51 57 54 58 60 56 61 63 59 64 66 62 68 65 69 71 67 72 74 70 75 77 73 79 76 80 82 78 83 85 81 86 88 84 90 87 91 93 89 94 96 92 97 99 95 101 98 102 104 100 105 107 103 108 110 106 112 109 113 115 111 116 118 114 119 121 117 123 120 124 126 122 127 129 125 130 132 128 134 131 135 137 133 138 140 136 141 143 139 145 142 146 148 144 149 151 147 152 154 150 156 153..."
},
{
"input": "90000 30001",
"output": "3 1 4 6 2 8 5 9 11 7 13 10 14 16 12 17 19 15 20 22 18 24 21 25 27 23 28 30 26 31 33 29 35 32 36 38 34 39 41 37 42 44 40 46 43 47 49 45 50 52 48 53 55 51 57 54 58 60 56 61 63 59 64 66 62 68 65 69 71 67 72 74 70 75 77 73 79 76 80 82 78 83 85 81 86 88 84 90 87 91 93 89 94 96 92 97 99 95 101 98 102 104 100 105 107 103 108 110 106 112 109 113 115 111 116 118 114 119 121 117 123 120 124 126 122 127 129 125 130 132 128 134 131 135 137 133 138 140 136 141 143 139 145 142 146 148 144 149 151 147 152 154 150 156 153..."
},
{
"input": "100000 10001",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "100000 20001",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "100000 30001",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "100000 199999",
"output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..."
},
{
"input": "10 17",
"output": "3 1 4 6 2 8 5 9 7 10 "
}
] | 77 | 7,168,000 | 3 | 740 |
|
877 | Alex and broken contest | [
"implementation",
"strings"
] | null | null | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".
Names are case sensitive. | The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β the name of the problem. | Print "YES", if problem is from this contest, and "NO" otherwise. | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n"
] | [
"NO",
"YES",
"NO"
] | none | [
{
"input": "Alex_and_broken_contest",
"output": "NO"
},
{
"input": "NikitaAndString",
"output": "YES"
},
{
"input": "Danil_and_Olya",
"output": "NO"
},
{
"input": "Slava____and_the_game",
"output": "YES"
},
{
"input": "Olya_and_energy_drinks",
"output": "YES"
},
{
"input": "Danil_and_part_time_job",
"output": "YES"
},
{
"input": "Ann_and_books",
"output": "YES"
},
{
"input": "Olya",
"output": "YES"
},
{
"input": "Nikita",
"output": "YES"
},
{
"input": "Slava",
"output": "YES"
},
{
"input": "Vanya",
"output": "NO"
},
{
"input": "I_dont_know_what_to_write_here",
"output": "NO"
},
{
"input": "danil_and_work",
"output": "NO"
},
{
"input": "Ann",
"output": "YES"
},
{
"input": "Batman_Nananananananan_Batman",
"output": "NO"
},
{
"input": "Olya_Nikita_Ann_Slava_Danil",
"output": "NO"
},
{
"input": "its_me_Mario",
"output": "NO"
},
{
"input": "A",
"output": "NO"
},
{
"input": "Wake_up_Neo",
"output": "NO"
},
{
"input": "Hardest_problem_ever",
"output": "NO"
},
{
"input": "Nikita_Nikita",
"output": "NO"
},
{
"input": "____________________________________________________________________________________________________",
"output": "NO"
},
{
"input": "Nikitb",
"output": "NO"
},
{
"input": "Unn",
"output": "NO"
},
{
"input": "oLya_adn_smth",
"output": "NO"
},
{
"input": "FloorISLava",
"output": "NO"
},
{
"input": "ann",
"output": "NO"
},
{
"input": "aa",
"output": "NO"
},
{
"input": "AAnnnnn",
"output": "YES"
},
{
"input": "AnnAnn",
"output": "NO"
},
{
"input": "Annn",
"output": "YES"
},
{
"input": "Dilzhan",
"output": "NO"
},
{
"input": "Danilaaa",
"output": "YES"
},
{
"input": "AndAnn",
"output": "YES"
},
{
"input": "OlyaAnnAnn",
"output": "NO"
},
{
"input": "DanilDanilOlya",
"output": "NO"
},
{
"input": "DDanil",
"output": "YES"
},
{
"input": "AnnAnnDanil",
"output": "NO"
},
{
"input": "And_Danil",
"output": "YES"
},
{
"input": "abcddddDanil",
"output": "YES"
},
{
"input": "DanilOlyaOlya",
"output": "NO"
},
{
"input": "Nikitaaa",
"output": "YES"
},
{
"input": "aaabbba",
"output": "NO"
},
{
"input": "Ann_Ann_Danil",
"output": "NO"
},
{
"input": "Danil_Danil_Nikita",
"output": "NO"
},
{
"input": "AlexaaaaaaBBBBBOlyaDDDDD",
"output": "YES"
},
{
"input": "IloveDaniland",
"output": "YES"
},
{
"input": "AnAnn",
"output": "YES"
},
{
"input": "Danil_Danil_Olya",
"output": "NO"
},
{
"input": "DanilDanilSlava",
"output": "NO"
},
{
"input": "DanilDanil",
"output": "NO"
},
{
"input": "OlyOlya",
"output": "YES"
},
{
"input": "NikitaNikitb",
"output": "YES"
},
{
"input": "ababaca",
"output": "NO"
},
{
"input": "AnnNikitaNikitaNikitaNikita__good_luck",
"output": "NO"
}
] | 61 | 0 | 0 | 742 |
|
624 | Making a String | [
"greedy",
"sortings"
] | null | null | You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once. | The first line of the input contains a single integer *n* (2<=<=β€<=<=*n*<=<=β€<=<=26)Β β the number of letters in the alphabet.
The next line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=109)Β β *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string. | Print a single integer β the maximum length of the string that meets all the requirements. | [
"3\n2 5 5\n",
"3\n1 1 2\n"
] | [
"11\n",
"3\n"
] | For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc". | [
{
"input": "3\n2 5 5",
"output": "11"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "3\n1 1000000000 2",
"output": "1000000003"
},
{
"input": "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "25999999675"
},
{
"input": "2\n559476582 796461544",
"output": "1355938126"
},
{
"input": "2\n257775227 621811272",
"output": "879586499"
},
{
"input": "10\n876938317 219479349 703839299 977218449 116819315 752405530 393874852 286326991 592978634 155758306",
"output": "5075639042"
},
{
"input": "26\n72 49 87 47 94 96 36 91 43 11 19 83 36 38 10 93 95 81 4 96 60 38 97 37 36 41",
"output": "1478"
},
{
"input": "26\n243 364 768 766 633 535 502 424 502 283 592 877 137 891 837 990 681 898 831 487 595 604 747 856 805 688",
"output": "16535"
},
{
"input": "26\n775 517 406 364 548 951 680 984 466 141 960 513 660 849 152 250 176 601 199 370 971 554 141 224 724 543",
"output": "13718"
},
{
"input": "26\n475 344 706 807 925 813 974 166 578 226 624 591 419 894 574 909 544 597 170 990 893 785 399 172 792 748",
"output": "16115"
},
{
"input": "26\n130 396 985 226 487 671 188 706 106 649 38 525 210 133 298 418 953 431 577 69 12 982 264 373 283 266",
"output": "10376"
},
{
"input": "26\n605 641 814 935 936 547 524 702 133 674 173 102 318 620 248 523 77 718 318 635 322 362 306 86 8 442",
"output": "11768"
},
{
"input": "26\n220 675 725 888 725 654 546 806 379 182 604 667 734 394 889 731 572 193 850 651 844 734 163 671 820 887",
"output": "16202"
},
{
"input": "26\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "25675"
},
{
"input": "26\n1001 1001 1000 1000 1001 1000 1001 1001 1001 1000 1000 1001 1001 1000 1000 1000 1000 1001 1000 1001 1001 1000 1001 1001 1001 1000",
"output": "25701"
},
{
"input": "26\n1000 1001 1000 1001 1000 1001 1001 1000 1001 1002 1002 1000 1001 1000 1000 1000 1001 1002 1001 1000 1000 1001 1000 1002 1001 1002",
"output": "25727"
},
{
"input": "26\n1003 1002 1002 1003 1000 1000 1000 1003 1000 1001 1003 1003 1000 1002 1002 1002 1001 1003 1000 1001 1000 1001 1001 1000 1003 1003",
"output": "25753"
},
{
"input": "26\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",
"output": "1"
},
{
"input": "26\n8717 9417 1409 7205 3625 6247 8626 9486 464 4271 1698 8449 4551 1528 7456 9198 4886 2889 7534 506 7867 9410 1635 4955 2580 2580",
"output": "137188"
},
{
"input": "26\n197464663 125058028 622449215 11119637 587496049 703992162 219591040 965159268 229879004 278894000 841629744 616893922 218779915 362575332 844188865 342411376 369680019 43823059 921419789 999588082 943769007 35365522 301907919 758302419 427454397 807507709",
"output": "12776400142"
},
{
"input": "26\n907247856 970380443 957324066 929910532 947150618 944189007 998282297 988343406 981298600 943026596 953932265 972691398 950024048 923033790 996423650 972134755 946404759 918183059 902987271 965507679 906967700 982106487 933997242 972594441 977736332 928874832",
"output": "24770753129"
},
{
"input": "26\n999999061 999999688 999999587 999999429 999999110 999999563 999999120 999999111 999999794 999999890 999999004 999999448 999999770 999999543 999999460 999999034 999999361 999999305 999999201 999999778 999999432 999999844 999999133 999999342 999999600 999999319",
"output": "25999984927"
},
{
"input": "3\n587951561 282383259 612352726",
"output": "1482687546"
},
{
"input": "4\n111637338 992238139 787658714 974622806",
"output": "2866156997"
},
{
"input": "5\n694257603 528073418 726928894 596328666 652863391",
"output": "3198451972"
},
{
"input": "6\n217943380 532900593 902234882 513005821 369342573 495810412",
"output": "3031237661"
},
{
"input": "7\n446656860 478792281 77541870 429682977 85821755 826122363 563802405",
"output": "2908420511"
},
{
"input": "8\n29278125 778590752 252847858 51388836 802299938 215370803 901540149 242074772",
"output": "3273391233"
},
{
"input": "9\n552962902 724482439 133182550 673093696 518779120 604618242 534250189 847695567 403066553",
"output": "4992131258"
},
{
"input": "10\n600386086 862479376 284190454 781950823 672077209 5753052 145701234 680334621 497013634 35429365",
"output": "4565315854"
},
{
"input": "11\n183007351 103343359 164525146 698627979 388556391 926007595 483438978 580927711 659384363 201890880 920750904",
"output": "5310460657"
},
{
"input": "12\n706692128 108170535 339831134 320333838 810063277 20284739 821176722 481520801 467848308 604388203 881959821 874133307",
"output": "6436402813"
},
{
"input": "13\n525349200 54062222 810108418 237010994 821513756 409532178 158915465 87142595 630219037 770849718 843168738 617993222 504443485",
"output": "6470309028"
},
{
"input": "14\n812998169 353860693 690443110 153688149 537992938 798779618 791624505 282706982 733654279 468319337 568341847 597888944 649703235 667623671",
"output": "8107625477"
},
{
"input": "15\n336683946 299752380 865749098 775393009 959499824 893055762 365399057 419335880 896025008 575845364 529550764 341748859 30999793 464432689 19445239",
"output": "7772916672"
},
{
"input": "16\n860368723 540615364 41056086 692070164 970950302 282304201 998108096 24957674 999460249 37279175 490759681 26673285 412295352 671298115 627182888 90740349",
"output": "7766119704"
},
{
"input": "17\n148018692 545442539 980325266 313776023 687429485 376580345 40875544 925549764 161831978 144805202 451968598 475560904 262583806 468107133 60900936 281546097 912565045",
"output": "7237867357"
},
{
"input": "18\n966674765 786305522 860659958 935480883 108937371 60800080 673584584 826142855 560238516 606238013 413177515 455456626 643879364 969943855 963609881 177380550 544192822 864797474",
"output": "11417500634"
},
{
"input": "19\n490360541 496161402 330938242 852158038 120387849 686083328 247359135 431764649 427637949 8736336 843378328 435352349 494167818 766752874 161292122 368186298 470791896 813444279 170758124",
"output": "8615711557"
},
{
"input": "20\n654616375 542649443 729213190 188364665 238384327 726353863 974350390 526804424 601329631 886592063 734805196 275562411 861801362 374466292 119830901 403120565 670982545 63210795 130397643 601611646",
"output": "10304447727"
},
{
"input": "21\n942265343 252505322 904519178 810069524 954862509 115602302 548124942 132426218 999736168 584061682 696014113 960485837 712089816 581331718 317512142 593926314 302610323 716885305 477125514 813997503 535631456",
"output": "12951783229"
},
{
"input": "22\n465951120 788339601 784853870 726746679 376370396 504849742 180834982 33019308 867135601 455551901 657223030 940381560 93386374 378140736 161286599 548696254 934237100 75589518 764917898 731412064 205669368 630662937",
"output": "11305256638"
},
{
"input": "23\n989635897 498195481 255132154 643423835 387820874 894097181 223601429 228583694 265543138 153021520 618431947 684241474 943673829 174949754 358967839 444530707 801900686 965299835 347682577 648826625 406714384 129525158 958578251",
"output": "12022378269"
},
{
"input": "24\n277285866 739058464 135466846 265129694 104300056 519381429 856310469 834204489 132942572 260547547 343605057 664137197 619941683 676786476 497713592 635336455 138557168 618975345 635474960 861212482 76752297 923357675 517046816 274123722",
"output": "11607648357"
},
{
"input": "25\n95942939 979921447 310772834 181806850 525806942 613657573 194049213 734797579 531349109 721980358 304813974 113025815 470230137 473595494 695394833 590106396 770183946 567622150 218239639 778627043 41761505 127248600 134450869 860350034 901937574",
"output": "11937672853"
},
{
"input": "26\n619627716 984748623 486078822 98484005 537257421 2906012 62795060 635390669 103777246 829506385 971050595 92921538 851525695 680460920 893076074 780912144 401811723 221297659 269996214 991012900 242806521 626109821 987889730 682613155 209557740 806895799",
"output": "14070510187"
},
{
"input": "26\n10 1 20 2 23 3 14 6 7 13 26 21 11 8 16 25 12 15 19 9 17 22 24 18 5 4",
"output": "351"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "11"
},
{
"input": "5\n2 2 2 2 2",
"output": "3"
},
{
"input": "10\n10 10 10 10 10 10 10 10 1 1",
"output": "53"
},
{
"input": "10\n100 100 10 10 10 10 10 1 1 1",
"output": "240"
},
{
"input": "6\n5 3 3 3 3 1",
"output": "11"
},
{
"input": "4\n4 3 2 1",
"output": "10"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
}
] | 124 | 0 | 3 | 743 |
|
602 | Approximating a Constant Range | [
"dp",
"implementation",
"two pointers"
] | null | null | When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challengingΒ β but why not make a similar programming contest problem while we're at it?
You're given a sequence of *n* data points *a*1,<=...,<=*a**n*. There aren't any big jumps between consecutive data pointsΒ β for each 1<=β€<=*i*<=<<=*n*, it's guaranteed that |*a**i*<=+<=1<=-<=*a**i*|<=β€<=1.
A range [*l*,<=*r*] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let *M* be the maximum and *m* the minimum value of *a**i* for *l*<=β€<=*i*<=β€<=*r*; the range [*l*,<=*r*] is almost constant if *M*<=-<=*m*<=β€<=1.
Find the length of the longest almost constant range. | The first line of the input contains a single integer *n* (2<=β€<=*n*<=β€<=100<=000)Β β the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=100<=000). | Print a single numberΒ β the maximum length of an almost constant range of the given sequence. | [
"5\n1 2 3 3 2\n",
"11\n5 4 5 5 6 7 8 8 8 7 6\n"
] | [
"4\n",
"5\n"
] | In the first sample, the longest almost constant range is [2,β5]; its length (the number of data points in it) is 4.
In the second sample, there are three almost constant ranges of length 4: [1,β4], [6,β9] and [7,β10]; the only almost constant range of the maximum length 5 is [6,β10]. | [
{
"input": "5\n1 2 3 3 2",
"output": "4"
},
{
"input": "11\n5 4 5 5 6 7 8 8 8 7 6",
"output": "5"
},
{
"input": "2\n3 2",
"output": "2"
},
{
"input": "4\n1001 1000 1000 1001",
"output": "4"
},
{
"input": "4\n1 1 2 3",
"output": "3"
},
{
"input": "3\n1 2 1",
"output": "3"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "18\n10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9",
"output": "3"
},
{
"input": "3\n1 2 2",
"output": "3"
},
{
"input": "4\n10 9 10 9",
"output": "4"
},
{
"input": "4\n4 3 2 3",
"output": "3"
},
{
"input": "4\n8 8 7 7",
"output": "4"
},
{
"input": "3\n99998 99999 100000",
"output": "2"
},
{
"input": "3\n100000 99999 99998",
"output": "2"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "2\n99999 100000",
"output": "2"
},
{
"input": "2\n100000 100000",
"output": "2"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "15\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "15"
}
] | 202 | 10,035,200 | 0 | 744 |
|
320 | Magic Numbers | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=β€<=*n*<=β€<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "414",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "144144144",
"output": "YES"
},
{
"input": "1444",
"output": "NO"
},
{
"input": "11",
"output": "YES"
},
{
"input": "141414141",
"output": "YES"
},
{
"input": "11110111",
"output": "NO"
},
{
"input": "114114144",
"output": "YES"
},
{
"input": "444",
"output": "NO"
},
{
"input": "9999",
"output": "NO"
},
{
"input": "111444",
"output": "NO"
},
{
"input": "11114",
"output": "YES"
},
{
"input": "41111",
"output": "NO"
},
{
"input": "114414441",
"output": "NO"
},
{
"input": "144414441",
"output": "NO"
},
{
"input": "144244144",
"output": "NO"
},
{
"input": "111111111",
"output": "YES"
},
{
"input": "144444444",
"output": "NO"
},
{
"input": "444444444",
"output": "NO"
},
{
"input": "141441441",
"output": "YES"
},
{
"input": "441",
"output": "NO"
},
{
"input": "15",
"output": "NO"
},
{
"input": "14444",
"output": "NO"
},
{
"input": "11444",
"output": "NO"
},
{
"input": "144",
"output": "YES"
},
{
"input": "1414414",
"output": "YES"
},
{
"input": "141444",
"output": "NO"
},
{
"input": "14144",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "1144",
"output": "YES"
},
{
"input": "141111444",
"output": "NO"
},
{
"input": "14414414",
"output": "YES"
},
{
"input": "141414144",
"output": "YES"
},
{
"input": "1414",
"output": "YES"
},
{
"input": "1441",
"output": "YES"
},
{
"input": "12",
"output": "NO"
},
{
"input": "144144141",
"output": "YES"
},
{
"input": "144144",
"output": "YES"
},
{
"input": "14414411",
"output": "YES"
},
{
"input": "14414",
"output": "YES"
}
] | 92 | 0 | 0 | 746 |
|
1,006 | Polycarp's Practice | [
"greedy",
"implementation",
"sortings"
] | null | null | Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cannot skip any problem from his list. He has to solve all $n$ problems in exactly $k$ days.
Thus, each day Polycarp solves a contiguous sequence of (consecutive) problems from the start of the list. He can't skip problems or solve them multiple times. As a result, in $k$ days he will solve all the $n$ problems.
The profit of the $j$-th day of Polycarp's practice is the maximum among all the difficulties of problems Polycarp solves during the $j$-th day (i.e. if he solves problems with indices from $l$ to $r$ during a day, then the profit of the day is $\max\limits_{l \le i \le r}a_i$). The total profit of his practice is the sum of the profits over all $k$ days of his practice.
You want to help Polycarp to get the maximum possible total profit over all valid ways to solve problems. Your task is to distribute all $n$ problems between $k$ days satisfying the conditions above in such a way, that the total profit is maximum.
For example, if $n = 8, k = 3$ and $a = [5, 4, 2, 6, 5, 1, 9, 2]$, one of the possible distributions with maximum total profit is: $[5, 4, 2], [6, 5], [1, 9, 2]$. Here the total profit equals $5 + 6 + 9 = 20$. | The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) β the number of problems and the number of days, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) β difficulties of problems in Polycarp's list, in the order they are placed in the list (i.e. in the order Polycarp will solve them). | In the first line of the output print the maximum possible total profit.
In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible total profit of his practice.
If there are many possible answers, you may print any of them. | [
"8 3\n5 4 2 6 5 1 9 2\n",
"5 1\n1 1 1 1 1\n",
"4 2\n1 2000 2000 2\n"
] | [
"20\n3 2 3",
"1\n5\n",
"4000\n2 2\n"
] | The first example is described in the problem statement.
In the second example there is only one possible distribution.
In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$. | [
{
"input": "8 3\n5 4 2 6 5 1 9 2",
"output": "20\n4 1 3"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "1\n5"
},
{
"input": "4 2\n1 2000 2000 2",
"output": "4000\n2 2"
},
{
"input": "1 1\n2000",
"output": "2000\n1"
},
{
"input": "1 1\n1234",
"output": "1234\n1"
},
{
"input": "3 2\n1 1 1",
"output": "2\n2 1"
},
{
"input": "4 2\n3 5 1 1",
"output": "8\n1 3"
},
{
"input": "5 3\n5 5 6 7 1",
"output": "18\n2 1 2"
},
{
"input": "6 4\n1 1 1 1 2 2",
"output": "6\n3 1 1 1"
},
{
"input": "5 3\n5 5 6 6 4",
"output": "17\n2 1 2"
},
{
"input": "16 15\n14 4 9 12 17 1 1 8 12 13 6 9 17 2 18 12",
"output": "154\n1 1 1 1 1 2 1 1 1 1 1 1 1 1 1"
},
{
"input": "1 1\n1996",
"output": "1996\n1"
},
{
"input": "5 3\n5 5 5 9 10",
"output": "24\n3 1 1"
},
{
"input": "18 15\n18 2 13 1 18 3 2 18 18 20 9 2 20 20 4 20 9 12",
"output": "204\n1 2 2 1 2 1 1 1 1 1 1 1 1 1 1"
},
{
"input": "5 3\n1 20 20 50 50",
"output": "120\n3 1 1"
},
{
"input": "8 3\n15 14 11 19 17 14 14 8",
"output": "51\n1 3 4"
},
{
"input": "5 2\n15 20 6 19 6",
"output": "39\n2 3"
},
{
"input": "6 3\n5 5 5 5 6 9",
"output": "20\n4 1 1"
},
{
"input": "5 3\n2 2 2 3 3",
"output": "8\n3 1 1"
},
{
"input": "7 3\n2 2 2 2 2 3 3",
"output": "8\n5 1 1"
},
{
"input": "6 5\n1 1 6 6 6 6",
"output": "25\n2 1 1 1 1"
},
{
"input": "8 4\n1 2 2 2 2 3 4 5",
"output": "14\n5 1 1 1"
},
{
"input": "6 4\n1 1 1 5 5 5",
"output": "16\n3 1 1 1"
},
{
"input": "6 3\n1 2 2 2 4 5",
"output": "11\n4 1 1"
},
{
"input": "18 6\n17 17 19 14 10 20 18 16 6 7 2 15 14 16 13 6 12 11",
"output": "107\n1 1 1 3 1 11"
},
{
"input": "6 3\n1 1 2 2 3 4",
"output": "9\n4 1 1"
},
{
"input": "8 3\n5 4 2 5 6 1 9 2",
"output": "20\n4 1 3"
}
] | 93 | 307,200 | 0 | 750 |
|
347 | Difference Row | [
"constructive algorithms",
"implementation",
"sortings"
] | null | null | You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permutation of sequence *a*. The value of such an arrangement is (*x*1<=-<=*x*2)<=+<=(*x*2<=-<=*x*3)<=+<=...<=+<=(*x**n*<=-<=1<=-<=*x**n*).
Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence *x* that corresponds to an arrangement of the largest possible value. | The first line of the input contains integer *n* (2<=β€<=*n*<=β€<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=β€<=1000). | Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value. | [
"5\n100 -100 50 0 -50\n"
] | [
"100 -50 0 50 -100 \n"
] | In the sample test case, the value of the output arrangement is (100β-β(β-β50))β+β((β-β50)β-β0)β+β(0β-β50)β+β(50β-β(β-β100))β=β200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one.
Sequence *x*<sub class="lower-index">1</sub>,β*x*<sub class="lower-index">2</sub>,β... ,β*x*<sub class="lower-index">*p*</sub> is lexicographically smaller than sequence *y*<sub class="lower-index">1</sub>,β*y*<sub class="lower-index">2</sub>,β... ,β*y*<sub class="lower-index">*p*</sub> if there exists an integer *r* (0ββ€β*r*β<β*p*) such that *x*<sub class="lower-index">1</sub>β=β*y*<sub class="lower-index">1</sub>,β*x*<sub class="lower-index">2</sub>β=β*y*<sub class="lower-index">2</sub>,β... ,β*x*<sub class="lower-index">*r*</sub>β=β*y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r*β+β1</sub>β<β*y*<sub class="lower-index">*r*β+β1</sub>. | [
{
"input": "5\n100 -100 50 0 -50",
"output": "100 -50 0 50 -100 "
},
{
"input": "10\n764 -367 0 963 -939 -795 -26 -49 948 -282",
"output": "963 -795 -367 -282 -49 -26 0 764 948 -939 "
},
{
"input": "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 939",
"output": "939 -689 -678 -651 -650 -633 -621 -593 -555 -396 50 161 198 258 262 369 673 737 833 -697 "
},
{
"input": "50\n-262 -377 -261 903 547 759 -800 -53 670 92 758 109 547 877 152 -901 -318 -527 -388 24 139 -227 413 -135 811 -886 -22 -526 -643 -431 284 609 -745 -62 323 -441 743 -800 86 862 587 -513 -468 -651 -760 197 141 -414 -909 438",
"output": "903 -901 -886 -800 -800 -760 -745 -651 -643 -527 -526 -513 -468 -441 -431 -414 -388 -377 -318 -262 -261 -227 -135 -62 -53 -22 24 86 92 109 139 141 152 197 284 323 413 438 547 547 587 609 670 743 758 759 811 862 877 -909 "
},
{
"input": "100\n144 -534 -780 -1 -259 -945 -992 -967 -679 -239 -22 387 130 -908 140 -270 16 646 398 599 -631 -231 687 -505 89 77 584 162 124 132 33 271 212 734 350 -678 969 43 487 -689 -432 -225 -603 801 -828 -684 349 318 109 723 33 -247 719 368 -286 217 260 77 -618 955 408 994 -313 -341 578 609 60 900 222 -779 -507 464 -147 -789 -477 -235 -407 -432 35 300 -53 -896 -476 927 -293 -869 -852 -566 -759 95 506 -914 -405 -621 319 -622 -49 -334 328 -104",
"output": "994 -967 -945 -914 -908 -896 -869 -852 -828 -789 -780 -779 -759 -689 -684 -679 -678 -631 -622 -621 -618 -603 -566 -534 -507 -505 -477 -476 -432 -432 -407 -405 -341 -334 -313 -293 -286 -270 -259 -247 -239 -235 -231 -225 -147 -104 -53 -49 -22 -1 16 33 33 35 43 60 77 77 89 95 109 124 130 132 140 144 162 212 217 222 260 271 300 318 319 328 349 350 368 387 398 408 464 487 506 578 584 599 609 646 687 719 723 734 801 900 927 955 969 -992 "
},
{
"input": "100\n-790 341 910 905 -779 279 696 -375 525 -21 -2 751 -887 764 520 -844 850 -537 -882 -183 139 -397 561 -420 -991 691 587 -93 -701 -957 -89 227 233 545 934 309 -26 454 -336 -994 -135 -840 -320 -387 -943 650 628 -583 701 -708 -881 287 -932 -265 -312 -757 695 985 -165 -329 -4 -462 -627 798 -124 -539 843 -492 -967 -782 879 -184 -351 -385 -713 699 -477 828 219 961 -170 -542 877 -718 417 152 -905 181 301 920 685 -502 518 -115 257 998 -112 -234 -223 -396",
"output": "998 -991 -967 -957 -943 -932 -905 -887 -882 -881 -844 -840 -790 -782 -779 -757 -718 -713 -708 -701 -627 -583 -542 -539 -537 -502 -492 -477 -462 -420 -397 -396 -387 -385 -375 -351 -336 -329 -320 -312 -265 -234 -223 -184 -183 -170 -165 -135 -124 -115 -112 -93 -89 -26 -21 -4 -2 139 152 181 219 227 233 257 279 287 301 309 341 417 454 518 520 525 545 561 587 628 650 685 691 695 696 699 701 751 764 798 828 843 850 877 879 905 910 920 934 961 985 -994 "
},
{
"input": "100\n720 331 -146 -935 399 248 525 -669 614 -245 320 229 842 -894 -73 584 -458 -975 -604 -78 607 -120 -377 409 -743 862 -969 980 105 841 -795 996 696 -759 -482 624 -578 421 -717 -553 -652 -268 405 426 642 870 -650 -812 178 -882 -237 -737 -724 358 407 714 759 779 -899 -726 398 -663 -56 -736 -825 313 -746 117 -457 330 -925 497 332 -794 -506 -811 -990 -799 -343 -380 598 926 671 967 -573 -687 741 484 -641 -698 -251 -391 23 692 337 -639 126 8 -915 -386",
"output": "996 -975 -969 -935 -925 -915 -899 -894 -882 -825 -812 -811 -799 -795 -794 -759 -746 -743 -737 -736 -726 -724 -717 -698 -687 -669 -663 -652 -650 -641 -639 -604 -578 -573 -553 -506 -482 -458 -457 -391 -386 -380 -377 -343 -268 -251 -245 -237 -146 -120 -78 -73 -56 8 23 105 117 126 178 229 248 313 320 330 331 332 337 358 398 399 405 407 409 421 426 484 497 525 584 598 607 614 624 642 671 692 696 714 720 741 759 779 841 842 862 870 926 967 980 -990 "
},
{
"input": "100\n-657 320 -457 -472 -423 -227 -902 -520 702 -27 -103 149 268 -922 307 -292 377 730 117 1000 935 459 -502 796 -494 892 -523 866 166 -248 57 -606 -96 -948 988 194 -687 832 -425 28 -356 -884 688 353 225 204 -68 960 -929 -312 -479 381 512 -274 -505 -260 -506 572 226 -822 -13 325 -370 403 -714 494 339 283 356 327 159 -151 -13 -760 -159 -991 498 19 -159 583 178 -50 -421 -679 -978 334 688 -99 117 -988 371 693 946 -58 -699 -133 62 693 535 -375",
"output": "1000 -988 -978 -948 -929 -922 -902 -884 -822 -760 -714 -699 -687 -679 -657 -606 -523 -520 -506 -505 -502 -494 -479 -472 -457 -425 -423 -421 -375 -370 -356 -312 -292 -274 -260 -248 -227 -159 -159 -151 -133 -103 -99 -96 -68 -58 -50 -27 -13 -13 19 28 57 62 117 117 149 159 166 178 194 204 225 226 268 283 307 320 325 327 334 339 353 356 371 377 381 403 459 494 498 512 535 572 583 688 688 693 693 702 730 796 832 866 892 935 946 960 988 -991 "
},
{
"input": "100\n853 752 931 -453 -943 -118 -772 -814 791 191 -83 -373 -748 -136 -286 250 627 292 -48 -896 -296 736 -628 -376 -246 -495 366 610 228 664 -951 -952 811 192 -730 -377 319 799 753 166 827 501 157 -834 -776 424 655 -827 549 -487 608 -643 419 349 -88 95 231 -520 -508 -105 -727 568 -241 286 586 -956 -880 892 866 22 658 832 -216 -54 491 -500 -687 393 24 129 946 303 931 563 -269 -203 -251 647 -824 -163 248 -896 -133 749 -619 -212 -2 491 287 219",
"output": "946 -952 -951 -943 -896 -896 -880 -834 -827 -824 -814 -776 -772 -748 -730 -727 -687 -643 -628 -619 -520 -508 -500 -495 -487 -453 -377 -376 -373 -296 -286 -269 -251 -246 -241 -216 -212 -203 -163 -136 -133 -118 -105 -88 -83 -54 -48 -2 22 24 95 129 157 166 191 192 219 228 231 248 250 286 287 292 303 319 349 366 393 419 424 491 491 501 549 563 568 586 608 610 627 647 655 658 664 736 749 752 753 791 799 811 827 832 853 866 892 931 931 -956 "
},
{
"input": "100\n9 857 227 -593 -983 -439 17 -523 -354 -189 780 -267 771 -981 943 620 -832 79 761 -943 218 -966 75 131 -596 534 51 796 -612 -381 -690 -353 -170 648 804 -256 257 -16 964 -728 310 50 453 737 -228 -625 618 841 -102 974 -850 -641 -788 231 -982 -84 -917 942 -913 -768 -83 298 388 447 -490 271 -949 976 -820 -876 -822 -188 -306 877 219 854 561 -307 -920 916 -925 -591 -149 -166 -572 860 -217 -831 -552 822 355 -150 203 -710 530 910 889 964 -125 -597",
"output": "976 -982 -981 -966 -949 -943 -925 -920 -917 -913 -876 -850 -832 -831 -822 -820 -788 -768 -728 -710 -690 -641 -625 -612 -597 -596 -593 -591 -572 -552 -523 -490 -439 -381 -354 -353 -307 -306 -267 -256 -228 -217 -189 -188 -170 -166 -150 -149 -125 -102 -84 -83 -16 9 17 50 51 75 79 131 203 218 219 227 231 257 271 298 310 355 388 447 453 530 534 561 618 620 648 737 761 771 780 796 804 822 841 854 857 860 877 889 910 916 942 943 964 964 974 -983 "
},
{
"input": "2\n-1000 1000",
"output": "1000 -1000 "
},
{
"input": "2\n1000 -1000",
"output": "1000 -1000 "
},
{
"input": "2\n0 0",
"output": "0 0 "
},
{
"input": "5\n1 2 3 4 5",
"output": "5 2 3 4 1 "
},
{
"input": "6\n1 1 1 2 2 2",
"output": "2 1 1 2 2 1 "
},
{
"input": "3\n-1 -1 -1",
"output": "-1 -1 -1 "
}
] | 156 | 6,860,800 | 0 | 752 |
|
299 | Ksusha and Array | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=β€<=*n*<=β€<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β the array elements. | Print a single integer β the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
},
{
"input": "2\n500000000 1000000000",
"output": "500000000"
},
{
"input": "2\n4 6",
"output": "-1"
},
{
"input": "5\n10 8 6 4 2",
"output": "2"
},
{
"input": "2\n6 10",
"output": "-1"
},
{
"input": "1\n1000000000",
"output": "1000000000"
},
{
"input": "2\n6 8",
"output": "-1"
},
{
"input": "5\n2 2 2 2 1000000000",
"output": "2"
},
{
"input": "2\n6 4",
"output": "-1"
}
] | 156 | 0 | -1 | 753 |
|
709 | Juicer | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | The first line of the input contains three integers *n*, *b* and *d* (1<=β€<=*n*<=β€<=100<=000, 1<=β€<=*b*<=β€<=*d*<=β€<=1<=000<=000)Β β the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=1<=000<=000)Β β sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | Print one integerΒ β the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126",
"output": "12"
},
{
"input": "100 1000 1083\n992 616 818 359 609 783 263 989 501 929 362 394 919 1081 870 830 1097 975 62 346 531 367 323 457 707 360 949 334 867 116 478 417 961 963 1029 114 867 1008 988 916 983 1077 959 942 572 961 579 318 721 337 488 717 111 70 416 685 987 130 353 107 61 191 827 849 106 815 211 953 111 398 889 860 801 71 375 320 395 1059 116 222 931 444 582 74 677 655 88 173 686 491 661 186 114 832 615 814 791 464 517 850",
"output": "36"
},
{
"input": "2 6 8\n2 1",
"output": "0"
},
{
"input": "5 15 16\n7 11 5 12 8",
"output": "2"
},
{
"input": "15 759966 759967\n890397 182209 878577 548548 759966 812923 759966 860479 200595 381358 299175 339368 759966 907668 69574",
"output": "4"
},
{
"input": "5 234613 716125\n642626 494941 234613 234613 234613",
"output": "0"
},
{
"input": "50 48547 567054\n529808 597004 242355 559114 78865 537318 631455 733020 655072 645093 309010 855034 306058 625046 524574 834944 27330 664392 443637 821584 338013 490702 289520 675471 885846 258814 134220 571301 84875 94132 200425 928833 375166 521232 317961 175315 947093 89971 322071 174033 48547 998535 954205 704114 943163 438900 48547 538422 48547 48547",
"output": "0"
},
{
"input": "5 10 20\n10 10 10 10 1",
"output": "1"
},
{
"input": "5 10 11\n10 10 10 10 1",
"output": "2"
},
{
"input": "3 10 10\n4 3 3",
"output": "0"
},
{
"input": "3 5 5\n5 5 5",
"output": "1"
},
{
"input": "3 4 14\n5 5 5",
"output": "0"
},
{
"input": "2 7 10\n1234 1234",
"output": "0"
},
{
"input": "1 5 6\n10",
"output": "0"
},
{
"input": "3 4 6\n1 2 3",
"output": "0"
},
{
"input": "5 10 12\n13 13 13 13 13",
"output": "0"
},
{
"input": "3 4 5\n5 7 9",
"output": "0"
},
{
"input": "3 10 100\n5 5 5",
"output": "0"
},
{
"input": "5 1 2\n2 2 2 2 2",
"output": "0"
},
{
"input": "5 5 5\n5 5 5 5 5",
"output": "2"
},
{
"input": "2 2 5\n5 5",
"output": "0"
},
{
"input": "3 1 4\n2 2 2",
"output": "0"
}
] | 77 | 7,065,600 | 0 | 755 |
|
258 | Little Elephant and Bits | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation β the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub>β=β3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits β that results in number 11010<sub class="lower-index">2</sub>β=β26<sub class="lower-index">10</sub>. | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "111010010111",
"output": "11110010111"
},
{
"input": "11110111011100000000",
"output": "1111111011100000000"
},
{
"input": "11110010010100001110110101110011110110100111101",
"output": "1111010010100001110110101110011110110100111101"
},
{
"input": "1001011111010010100111111",
"output": "101011111010010100111111"
},
{
"input": "1111111111",
"output": "111111111"
},
{
"input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101",
"output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101"
},
{
"input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100",
"output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100"
},
{
"input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011",
"output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011"
},
{
"input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011",
"output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011"
},
{
"input": "11",
"output": "1"
},
{
"input": "111",
"output": "11"
},
{
"input": "111111",
"output": "11111"
},
{
"input": "11111",
"output": "1111"
},
{
"input": "1111",
"output": "111"
}
] | 1,434 | 9,113,600 | 3 | 758 |
|
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"
}
] | 108 | 7,168,000 | -1 | 759 |
|
358 | Dima and Continuous Line | [
"brute force",
"implementation"
] | null | null | Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the *n*-th point. Two points with coordinates (*x*1,<=0) and (*x*2,<=0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem. | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=β€<=*x**i*<=β€<=106) β the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. | In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). | [
"4\n0 10 5 15\n",
"4\n0 15 5 10\n"
] | [
"yes\n",
"no\n"
] | The first test from the statement is on the picture to the left, the second test is on the picture to the right. | [
{
"input": "4\n0 10 5 15",
"output": "yes"
},
{
"input": "4\n0 15 5 10",
"output": "no"
},
{
"input": "5\n0 1000 2000 3000 1500",
"output": "yes"
},
{
"input": "5\n-724093 710736 -383722 -359011 439613",
"output": "no"
},
{
"input": "50\n384672 661179 -775591 -989608 611120 442691 601796 502406 384323 -315945 -934146 873993 -156910 -94123 -930137 208544 816236 466922 473696 463604 794454 -872433 -149791 -858684 -467655 -555239 623978 -217138 -408658 493342 -733576 -350871 711210 884148 -426172 519986 -356885 527171 661680 977247 141654 906254 -961045 -759474 -48634 891473 -606365 -513781 -966166 27696",
"output": "yes"
},
{
"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": "no"
},
{
"input": "11\n1 11 10 2 3 9 8 4 5 7 6",
"output": "no"
},
{
"input": "10\n3 2 4 5 1 6 9 7 8 10",
"output": "yes"
},
{
"input": "11\n3 4 2 5 1 6 11 7 10 8 9",
"output": "no"
},
{
"input": "15\n0 -1 1 2 3 13 12 4 11 10 5 6 7 9 8",
"output": "no"
},
{
"input": "16\n6 7 8 9 5 10 11 12 13 14 15 4 16 2 1 3",
"output": "yes"
},
{
"input": "1\n0",
"output": "no"
},
{
"input": "4\n3 1 4 2",
"output": "yes"
},
{
"input": "5\n0 2 4 -2 5",
"output": "no"
},
{
"input": "5\n1 9 8 7 0",
"output": "yes"
},
{
"input": "3\n5 10 0",
"output": "no"
},
{
"input": "6\n1 3 -1 5 2 4",
"output": "yes"
},
{
"input": "4\n3 2 4 1",
"output": "no"
},
{
"input": "4\n10 5 15 0",
"output": "no"
},
{
"input": "2\n-5 -10",
"output": "no"
},
{
"input": "3\n1 0 3",
"output": "no"
},
{
"input": "4\n-2 -4 1 -3",
"output": "yes"
},
{
"input": "4\n3 6 0 2",
"output": "no"
},
{
"input": "4\n-9 10 -10 0",
"output": "yes"
},
{
"input": "4\n5 10 1 15",
"output": "no"
},
{
"input": "3\n1 0 2",
"output": "no"
},
{
"input": "4\n2 3 4 1",
"output": "no"
},
{
"input": "4\n7 5 9 12",
"output": "no"
}
] | 155 | 2,867,200 | 3 | 765 |
|
742 | Arpaβs obvious problem and Mehrdadβs terrible solution | [
"brute force",
"math",
"number theory"
] | null | null | There are some beautiful girls in Arpaβs land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number *x*, count the number of pairs of indices *i*,<=*j* (1<=β€<=*i*<=<<=*j*<=β€<=*n*) such that , where is bitwise xor operation (see notes for explanation).
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem. | First line contains two integers *n* and *x* (1<=β€<=*n*<=β€<=105,<=0<=β€<=*x*<=β€<=105)Β β the number of elements in the array and the integer *x*.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=105)Β β the elements of the array. | Print a single integer: the answer to the problem. | [
"2 3\n1 2\n",
"6 1\n5 1 2 3 4 1\n"
] | [
"1",
"2"
] | In the first sample there is only one pair of *i*β=β1 and *j*β=β2. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bec9071ce5b1039982fe0ae476cd31528ddfa2f3.png" style="max-width: 100.0%;max-height: 100.0%;"/> so the answer is 1.
In the second sample the only two pairs are *i*β=β3, *j*β=β4 (since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3701990d023d19c5da0b315b5057d572ec11e4fd.png" style="max-width: 100.0%;max-height: 100.0%;"/>) and *i*β=β1, *j*β=β5 (since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8c96223ca88621240a5ee6e1498acb7e4ce0eb44.png" style="max-width: 100.0%;max-height: 100.0%;"/>).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). | [
{
"input": "2 3\n1 2",
"output": "1"
},
{
"input": "6 1\n5 1 2 3 4 1",
"output": "2"
},
{
"input": "38 101\n395 5 339 366 409 150 400 180 348 200 409 20 182 409 208 74 176 401 459 158 282 207 241 406 33 484 65 245 363 337 204 197 445 445 72 435 126 423",
"output": "0"
},
{
"input": "47 117\n77 57 535 240 250 321 51 29 42 582 390 525 149 195 119 465 198 494 456 313 497 205 115 256 513 413 15 423 568 135 519 174 147 201 564 182 359 41 465 162 125 378 342 144 549 363 309",
"output": "1"
},
{
"input": "27 41\n156 148 86 161 113 80 185 15 204 185 205 95 147 146 133 187 114 8 11 120 117 167 100 171 140 102 174",
"output": "1"
},
{
"input": "10 208\n399 912 747 631 510 622 234 707 483 496",
"output": "0"
},
{
"input": "64 43\n78 90 211 205 198 4 172 43 163 21 58 145 28 66 210 68 79 90 155 123 9 119 188 151 180 157 44 163 20 71 28 120 163 141 170 206 31 34 21 195 72 194 83 163 140 40 182 208 127 128 110 72 184 157 128 189 146 35 51 206 62 8 117 61",
"output": "8"
},
{
"input": "69 25\n68 26 8 121 96 101 106 87 103 14 86 26 76 85 70 50 4 4 97 89 44 98 33 65 76 64 98 95 30 5 93 121 97 85 47 50 66 2 46 79 46 22 68 59 75 94 104 105 91 97 121 6 32 94 101 125 32 91 76 57 110 31 27 97 91 49 45 37 92",
"output": "21"
},
{
"input": "64 118\n361 547 410 294 448 377 482 490 13 116 346 50 251 330 443 128 543 580 370 489 337 509 414 291 228 71 245 308 319 314 154 39 317 288 145 248 547 152 262 278 89 108 522 238 128 575 112 469 86 230 310 492 127 270 475 25 179 72 345 444 17 332 544 338",
"output": "3"
},
{
"input": "52 231\n229 492 1005 498 786 274 773 573 316 774 977 110 709 49 131 81 1146 1028 451 451 776 470 996 363 581 484 1023 858 1115 273 1105 4 445 509 428 125 432 131 360 404 280 808 649 4 499 1097 831 512 208 996 430 1010",
"output": "0"
},
{
"input": "4 0\n1 2 3 4",
"output": "0"
},
{
"input": "3 0\n2 2 2",
"output": "3"
},
{
"input": "5 0\n1 1 1 1 1",
"output": "10"
},
{
"input": "3 0\n1 1 1",
"output": "3"
},
{
"input": "4 0\n2 2 2 2",
"output": "6"
},
{
"input": "3 0\n10 10 10",
"output": "3"
},
{
"input": "3 0\n3 3 3",
"output": "3"
},
{
"input": "4 0\n1 1 1 1",
"output": "6"
},
{
"input": "3 0\n4 4 4",
"output": "3"
},
{
"input": "2 0\n2 2",
"output": "1"
},
{
"input": "2 0\n2 3",
"output": "0"
},
{
"input": "2 0\n1 2",
"output": "0"
},
{
"input": "5 0\n5 5 5 5 5",
"output": "10"
},
{
"input": "6 0\n1 1 1 1 1 1",
"output": "15"
},
{
"input": "2 0\n1 1",
"output": "1"
},
{
"input": "4 0\n1 1 3 3",
"output": "2"
},
{
"input": "2 0\n10 10",
"output": "1"
},
{
"input": "4 0\n3 3 3 3",
"output": "6"
},
{
"input": "5 0\n1 1 1 2 2",
"output": "4"
},
{
"input": "5 0\n1 1 2 2 3",
"output": "2"
},
{
"input": "10 0\n1 1 1 1 1 1 1 1 1 1",
"output": "45"
},
{
"input": "2 0\n3 3",
"output": "1"
}
] | 77 | 4,505,600 | 0 | 766 |
|
0 | none | [
"none"
] | null | null | Let's define the sum of two permutations *p* and *q* of numbers 0,<=1,<=...,<=(*n*<=-<=1) as permutation , where *Perm*(*x*) is the *x*-th lexicographically permutation of numbers 0,<=1,<=...,<=(*n*<=-<=1) (counting from zero), and *Ord*(*p*) is the number of permutation *p* in the lexicographical order.
For example, *Perm*(0)<==<=(0,<=1,<=...,<=*n*<=-<=2,<=*n*<=-<=1), *Perm*(*n*!<=-<=1)<==<=(*n*<=-<=1,<=*n*<=-<=2,<=...,<=1,<=0)
Misha has two permutations, *p* and *q*. Your task is to find their sum.
Permutation *a*<==<=(*a*0,<=*a*1,<=...,<=*a**n*<=-<=1) is called to be lexicographically smaller than permutation *b*<==<=(*b*0,<=*b*1,<=...,<=*b**n*<=-<=1), if for some *k* following conditions hold: *a*0<==<=*b*0,<=*a*1<==<=*b*1,<=...,<=*a**k*<=-<=1<==<=*b**k*<=-<=1,<=*a**k*<=<<=*b**k*. | The first line contains an integer *n* (1<=β€<=*n*<=β€<=200<=000).
The second line contains *n* distinct integers from 0 to *n*<=-<=1, separated by a space, forming permutation *p*.
The third line contains *n* distinct integers from 0 to *n*<=-<=1, separated by spaces, forming permutation *q*. | Print *n* distinct integers from 0 to *n*<=-<=1, forming the sum of the given permutations. Separate the numbers by spaces. | [
"2\n0 1\n0 1\n",
"2\n0 1\n1 0\n",
"3\n1 2 0\n2 1 0\n"
] | [
"0 1\n",
"1 0\n",
"1 0 2\n"
] | Permutations of numbers from 0 to 1 in the lexicographical order: (0,β1),β(1,β0).
In the first sample *Ord*(*p*)β=β0 and *Ord*(*q*)β=β0, so the answer is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8ce4cd76db7c3f712f9101b410c36891976581b8.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample *Ord*(*p*)β=β0 and *Ord*(*q*)β=β1, so the answer is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5684e4e2deb5ed60419a5c9e765f0cd4cb995652.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
Permutations of numbers from 0 to 2 in the lexicographical order: (0,β1,β2),β(0,β2,β1),β(1,β0,β2),β(1,β2,β0),β(2,β0,β1),β(2,β1,β0).
In the third sample *Ord*(*p*)β=β3 and *Ord*(*q*)β=β5, so the answer is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/da14f774ebda9f417649f5334d329ec7b7c07778.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | [] | 2,000 | 85,811,200 | 0 | 768 |
|
546 | Soldier and Bananas | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*Β·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=β€<=<=*k*,<=*w*<=<=β€<=<=1000, 0<=β€<=*n*<=β€<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer β the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 31 | 0 | 3 | 769 |
|
493 | Vasya and Chess | [
"constructive algorithms",
"games",
"math"
] | null | null | Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an *n*<=Γ<=*n* chessboard. We'll denote a cell on the intersection of the *r*-th row and *c*-th column as (*r*,<=*c*). The square (1,<=1) contains the white queen and the square (1,<=*n*) contains the black queen. All other squares contain green pawns that don't belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.
Help Vasya determine who wins if both players play with an optimal strategy on the board *n*<=Γ<=*n*. | The input contains a single number *n* (2<=β€<=*n*<=β€<=109) β the size of the board. | On the first line print the answer to problem β string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers *r* and *c* representing the cell (*r*,<=*c*), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum *r*. If there are still multiple squares, print the one with the minimum *c*. | [
"2\n",
"3\n"
] | [
"white\n1 2\n",
"black\n"
] | In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2,β1).
Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2,β3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens β neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3,β1), and the black queen ends up on square (3,β3).
In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins. | [
{
"input": "2",
"output": "white\n1 2"
},
{
"input": "3",
"output": "black"
},
{
"input": "4",
"output": "white\n1 2"
},
{
"input": "6",
"output": "white\n1 2"
},
{
"input": "10",
"output": "white\n1 2"
},
{
"input": "16",
"output": "white\n1 2"
},
{
"input": "100",
"output": "white\n1 2"
},
{
"input": "10006",
"output": "white\n1 2"
},
{
"input": "99966246",
"output": "white\n1 2"
},
{
"input": "1000000000",
"output": "white\n1 2"
},
{
"input": "999999999",
"output": "black"
},
{
"input": "999999997",
"output": "black"
},
{
"input": "900001",
"output": "black"
},
{
"input": "775681",
"output": "black"
},
{
"input": "666666",
"output": "white\n1 2"
},
{
"input": "12345",
"output": "black"
},
{
"input": "111111",
"output": "black"
},
{
"input": "346367",
"output": "black"
},
{
"input": "13",
"output": "black"
},
{
"input": "11",
"output": "black"
},
{
"input": "9",
"output": "black"
},
{
"input": "7",
"output": "black"
},
{
"input": "5",
"output": "black"
},
{
"input": "19",
"output": "black"
},
{
"input": "939698497",
"output": "black"
},
{
"input": "999999996",
"output": "white\n1 2"
}
] | 140 | 0 | 3 | 771 |
|
729 | Sea Battle | [
"constructive algorithms",
"greedy",
"math"
] | null | null | Galya is playing one-dimensional Sea Battle on a 1<=Γ<=*n* grid. In this game *a* ships are placed on the grid. Each of the ships consists of *b* consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made *k* shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement. | The first line contains four positive integers *n*, *a*, *b*, *k* (1<=β€<=*n*<=β€<=2Β·105, 1<=β€<=*a*,<=*b*<=β€<=*n*, 0<=β€<=*k*<=β€<=*n*<=-<=1)Β β the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length *n*, consisting of zeros and ones. If the *i*-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly *k* ones in this string. | In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to *n*, starting from the left.
If there are multiple answers, you can print any of them. | [
"5 1 2 1\n00100\n",
"13 3 2 3\n1000000010001\n"
] | [
"2\n4 2\n",
"2\n7 11\n"
] | There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | [
{
"input": "5 1 2 1\n00100",
"output": "2\n2 5 "
},
{
"input": "13 3 2 3\n1000000010001",
"output": "2\n3 5 "
},
{
"input": "1 1 1 0\n0",
"output": "1\n1 "
},
{
"input": "2 2 1 0\n00",
"output": "1\n1 "
},
{
"input": "5 4 1 0\n00000",
"output": "2\n1 2 "
},
{
"input": "10 2 2 0\n0000000000",
"output": "4\n2 4 6 8 "
},
{
"input": "20 1 3 5\n01001010000000010010",
"output": "2\n10 13 "
},
{
"input": "100 17 4 11\n0100000100000000000000001000000000010001100000000000101000000000000000000000001000001000010000000000",
"output": "2\n6 12 "
}
] | 296 | 18,841,600 | 3 | 772 |
|
92 | Chips | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end. | The first line contains two integers *n* and *m* (1<=β€<=*n*<=β€<=50, 1<=β€<=*m*<=β€<=104) β the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes.
In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip. | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "25 9712",
"output": "11"
},
{
"input": "9 7601",
"output": "5"
},
{
"input": "1 9058",
"output": "0"
},
{
"input": "29 7772",
"output": "26"
},
{
"input": "45 9465",
"output": "14"
},
{
"input": "46 866",
"output": "5"
},
{
"input": "29 1241",
"output": "20"
},
{
"input": "17 4248",
"output": "12"
},
{
"input": "20 8082",
"output": "11"
},
{
"input": "50 9555",
"output": "0"
},
{
"input": "4 7455",
"output": "2"
},
{
"input": "36 880",
"output": "4"
},
{
"input": "24 7440",
"output": "9"
},
{
"input": "44 7888",
"output": "12"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "50 10000",
"output": "40"
},
{
"input": "1 10000",
"output": "0"
},
{
"input": "50 1",
"output": "0"
},
{
"input": "50 50",
"output": "5"
}
] | 62 | 0 | -1 | 778 |
677 | Vanya and Fence | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | The first line of the input contains two integers *n* and *h* (1<=β€<=*n*<=β€<=1000, 1<=β€<=*h*<=β€<=1000)Β β the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integerΒ β the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.
In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481 554 1000 821",
"output": "15"
},
{
"input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396",
"output": "144"
},
{
"input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366",
"output": "145"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n2",
"output": "2"
},
{
"input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19",
"output": "63"
},
{
"input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386",
"output": "31"
},
{
"input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518",
"output": "75"
},
{
"input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397",
"output": "41"
},
{
"input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118",
"output": "116"
}
] | 0 | 0 | -1 | 781 |
|
819 | Mister B and Boring Game | [
"games",
"greedy"
] | null | null | Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens.
All characters in this game are lowercase English letters. There are two players: Mister B and his competitor.
Initially the players have a string *s* consisting of the first *a* English letters in alphabetical order (for example, if *a*<==<=5, then *s* equals to "abcde").
The players take turns appending letters to string *s*. Mister B moves first.
Mister B must append exactly *b* letters on each his move. He can arbitrary choose these letters. His opponent adds exactly *a* letters on each move.
Mister B quickly understood that his opponent was just a computer that used a simple algorithm. The computer on each turn considers the suffix of string *s* of length *a* and generates a string *t* of length *a* such that all letters in the string *t* are distinct and don't appear in the considered suffix. From multiple variants of *t* lexicographically minimal is chosen (if *a*<==<=4 and the suffix is "bfdd", the computer chooses string *t* equal to "aceg"). After that the chosen string *t* is appended to the end of *s*.
Mister B soon found the game boring and came up with the following question: what can be the minimum possible number of different letters in string *s* on the segment between positions *l* and *r*, inclusive. Letters of string *s* are numerated starting from 1. | First and only line contains four space-separated integers: *a*, *b*, *l* and *r* (1<=β€<=*a*,<=*b*<=β€<=12, 1<=β€<=*l*<=β€<=*r*<=β€<=109) β the numbers of letters each player appends and the bounds of the segment. | Print one integer β the minimum possible number of different letters in the segment from position *l* to position *r*, inclusive, in string *s*. | [
"1 1 1 8\n",
"4 2 2 6\n",
"3 7 4 6\n"
] | [
"2",
"3",
"1"
] | In the first sample test one of optimal strategies generate string *s*β=β"abababab...", that's why answer is 2.
In the second sample test string *s*β=β"abcdbcaefg..." can be obtained, chosen segment will look like "bcdbc", that's why answer is 3.
In the third sample test string *s*β=β"abczzzacad..." can be obtained, chosen, segment will look like "zzz", that's why answer is 1. | [
{
"input": "1 1 1 8",
"output": "2"
},
{
"input": "4 2 2 6",
"output": "3"
},
{
"input": "3 7 4 6",
"output": "1"
},
{
"input": "4 5 1 1",
"output": "1"
},
{
"input": "12 12 1 1000",
"output": "13"
},
{
"input": "12 1 1000 1000",
"output": "1"
},
{
"input": "3 4 701 703",
"output": "3"
},
{
"input": "12 12 13 1000000000",
"output": "13"
},
{
"input": "3 4 999999999 1000000000",
"output": "1"
},
{
"input": "5 6 1000000000 1000000000",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "12 1 100000011 100000024",
"output": "13"
},
{
"input": "10 12 220000011 220000032",
"output": "11"
},
{
"input": "1 1 1 1000000000",
"output": "2"
},
{
"input": "1 1 999999999 1000000000",
"output": "1"
},
{
"input": "1 1 1000000000 1000000000",
"output": "1"
},
{
"input": "12 12 1 24",
"output": "12"
},
{
"input": "12 12 876543210 1000000000",
"output": "13"
},
{
"input": "5 11 654321106 654321117",
"output": "4"
},
{
"input": "5 11 654321117 654321140",
"output": "6"
},
{
"input": "9 12 654321114 654321128",
"output": "4"
},
{
"input": "5 12 654321101 654321140",
"output": "6"
},
{
"input": "2 12 654321104 654321122",
"output": "3"
},
{
"input": "6 1 654321100 654321115",
"output": "11"
},
{
"input": "2 1 654321122 654321129",
"output": "3"
},
{
"input": "6 2 654321100 654321140",
"output": "10"
},
{
"input": "6 2 654321113 654321123",
"output": "7"
},
{
"input": "1 7 654321103 654321105",
"output": "2"
},
{
"input": "5 3 654321111 654321117",
"output": "6"
},
{
"input": "1 3 654321122 654321140",
"output": "2"
},
{
"input": "5 8 654321118 654321137",
"output": "6"
},
{
"input": "5 8 654321103 654321106",
"output": "1"
},
{
"input": "9 8 654321109 654321126",
"output": "10"
},
{
"input": "2 2 987654333 987654335",
"output": "2"
},
{
"input": "4 8 987654341 987654343",
"output": "1"
},
{
"input": "3 12 987654345 987654347",
"output": "3"
},
{
"input": "8 1 987654349 987654354",
"output": "6"
},
{
"input": "6 8 987654322 987654327",
"output": "3"
},
{
"input": "6 10 987654330 987654337",
"output": "2"
},
{
"input": "11 4 987654330 987654343",
"output": "12"
},
{
"input": "10 7 987654339 987654340",
"output": "2"
},
{
"input": "12 12 987654321 987654328",
"output": "4"
},
{
"input": "3 10 498103029 647879228",
"output": "4"
},
{
"input": "11 3 378541409 796916287",
"output": "19"
},
{
"input": "3 3 240953737 404170887",
"output": "4"
},
{
"input": "3 8 280057261 834734290",
"output": "4"
},
{
"input": "7 8 305686738 573739036",
"output": "8"
},
{
"input": "3 8 36348920 167519590",
"output": "4"
},
{
"input": "10 2 1 1000000000",
"output": "18"
},
{
"input": "4 1 1 100000",
"output": "7"
},
{
"input": "2 1 288 300",
"output": "3"
},
{
"input": "5 1 1 100",
"output": "9"
},
{
"input": "3 3 3 8",
"output": "3"
},
{
"input": "5 1 1 100000",
"output": "9"
},
{
"input": "5 1 1 1000",
"output": "9"
},
{
"input": "6 1 1 10000",
"output": "11"
},
{
"input": "12 1 1 100",
"output": "23"
},
{
"input": "2 1 1 1000000",
"output": "3"
},
{
"input": "10 1 100 1000000000",
"output": "19"
},
{
"input": "2 2 7 12",
"output": "3"
},
{
"input": "12 1 1 1000",
"output": "23"
},
{
"input": "4 1 1 9",
"output": "7"
},
{
"input": "5 2 5 1000",
"output": "8"
},
{
"input": "3 1 4 10",
"output": "4"
},
{
"input": "12 1 1 1000000",
"output": "23"
},
{
"input": "10 5 1 1000000000",
"output": "15"
},
{
"input": "10 10 1999 3998",
"output": "11"
},
{
"input": "3 1 1 1000",
"output": "5"
},
{
"input": "10 1 1 21",
"output": "19"
},
{
"input": "5 3 15 18",
"output": "3"
},
{
"input": "4 4 2 10",
"output": "4"
}
] | 46 | 0 | 0 | 783 |
|
937 | Vile Grasshoppers | [
"brute force",
"math",
"number theory"
] | null | null | The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (more precise, from 2 to *p*) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch *x* can jump to branches .
Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.
In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible. | The only line contains two integers *p* and *y* (2<=β€<=*p*<=β€<=*y*<=β€<=109). | Output the number of the highest suitable branch. If there are none, print -1 instead. | [
"3 6\n",
"3 4\n"
] | [
"5\n",
"-1\n"
] | In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case. | [
{
"input": "3 6",
"output": "5"
},
{
"input": "3 4",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "5 50",
"output": "49"
},
{
"input": "944192806 944193066",
"output": "944192807"
},
{
"input": "1000000000 1000000000",
"output": "-1"
},
{
"input": "2 1000000000",
"output": "999999999"
},
{
"input": "28788 944193066",
"output": "944192833"
},
{
"input": "49 52",
"output": "-1"
},
{
"input": "698964997 734575900",
"output": "734575871"
},
{
"input": "287894773 723316271",
"output": "723316207"
},
{
"input": "171837140 733094070",
"output": "733094069"
},
{
"input": "37839169 350746807",
"output": "350746727"
},
{
"input": "125764821 234689174",
"output": "234689137"
},
{
"input": "413598841 430509920",
"output": "430509917"
},
{
"input": "145320418 592508508",
"output": "592508479"
},
{
"input": "155098216 476450875",
"output": "476450861"
},
{
"input": "459843315 950327842",
"output": "950327831"
},
{
"input": "469621113 834270209",
"output": "834270209"
},
{
"input": "13179877 557546766",
"output": "557546753"
},
{
"input": "541748242 723508350",
"output": "723508301"
},
{
"input": "607450717 924641194",
"output": "924641189"
},
{
"input": "786360384 934418993",
"output": "934418981"
},
{
"input": "649229491 965270051",
"output": "965270051"
},
{
"input": "144179719 953974590",
"output": "953974583"
},
{
"input": "28122086 963752388",
"output": "963752347"
},
{
"input": "268497487 501999053",
"output": "501999053"
},
{
"input": "356423140 385941420",
"output": "385941419"
},
{
"input": "71233638 269883787",
"output": "269883787"
},
{
"input": "2601 698964997",
"output": "698964983"
},
{
"input": "4096 287894773",
"output": "287894771"
},
{
"input": "5675 171837140",
"output": "171837131"
},
{
"input": "13067 350746807",
"output": "350746727"
},
{
"input": "8699 234689174",
"output": "234689137"
},
{
"input": "12190 413598841",
"output": "413598817"
},
{
"input": "20555 592508508",
"output": "592508479"
},
{
"input": "19137 476450875",
"output": "476450861"
},
{
"input": "8793 950327842",
"output": "950327831"
},
{
"input": "1541 834270209",
"output": "834270209"
},
{
"input": "1082 13179877",
"output": "13179871"
},
{
"input": "3888 723508350",
"output": "723508301"
},
{
"input": "14078 607450717",
"output": "607450703"
},
{
"input": "20869 786360384",
"output": "786360373"
},
{
"input": "13689 965270051",
"output": "965270051"
},
{
"input": "782 144179719",
"output": "144179719"
},
{
"input": "404 28122086",
"output": "28122079"
},
{
"input": "21992 501999053",
"output": "501999053"
},
{
"input": "13745 385941420",
"output": "385941419"
},
{
"input": "8711 269883787",
"output": "269883787"
},
{
"input": "31333 981756889",
"output": "981756871"
},
{
"input": "944192808 944193061",
"output": "-1"
},
{
"input": "3 9",
"output": "7"
},
{
"input": "4 5",
"output": "5"
},
{
"input": "2 13",
"output": "13"
},
{
"input": "7 53",
"output": "53"
},
{
"input": "10 1000000000",
"output": "999999997"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "4 9",
"output": "7"
}
] | 93 | 7,065,600 | 3 | 784 |
|
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"
}
] | 186 | 2,764,800 | 0 | 785 |
7 | Kalevitch and Chess | [
"brute force",
"constructive algorithms"
] | A. Kalevitch and Chess | 2 | 64 | A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.
As before, the chessboard is a square-checkered board with the squares arranged in a 8<=Γ<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.
Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.
It goes without saying that in such business one should economize on everything β for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task. | The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character β for a square painted black.
It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row). | Output the only number β the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements. | [
"WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n",
"WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n"
] | [
"3\n",
"1\n"
] | none | [
{
"input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW",
"output": "3"
},
{
"input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "1"
},
{
"input": "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "0"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "8"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBW",
"output": "14"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "14"
},
{
"input": "BBBBBBBB\nWBBBWBBW\nBBBBBBBB\nWBBBWBBW\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW",
"output": "9"
},
{
"input": "BBBBBBBB\nWBBWWWBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB",
"output": "9"
},
{
"input": "BBBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB",
"output": "8"
},
{
"input": "WWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "8"
},
{
"input": "BBBBBBBB\nWBWWBBBW\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nBBBBBBBB",
"output": "7"
},
{
"input": "WBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW",
"output": "9"
},
{
"input": "BBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "11"
},
{
"input": "WWBWBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB",
"output": "10"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nWWBWBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB",
"output": "10"
},
{
"input": "WBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nBBBBBBBB\nWBBWBBBW\nWBBWBBBW",
"output": "6"
},
{
"input": "BBBWBBBW\nBBBWBBBW\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB",
"output": "10"
},
{
"input": "BBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB\nBBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB",
"output": "9"
},
{
"input": "BBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "9"
},
{
"input": "WBBBBBWB\nBBBBBBBB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nBBBBBBBB",
"output": "8"
},
{
"input": "WBBBWWBW\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nWBBBWWBW\nWBBBWWBW",
"output": "6"
},
{
"input": "WBBBBWBB\nBBBBBBBB\nBBBBBBBB\nWBBBBWBB\nWBBBBWBB\nBBBBBBBB\nWBBBBWBB\nBBBBBBBB",
"output": "10"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB",
"output": "11"
},
{
"input": "BBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW",
"output": "9"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB",
"output": "9"
},
{
"input": "BWBBBWWB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "10"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWBWB",
"output": "12"
},
{
"input": "BWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB",
"output": "7"
},
{
"input": "WWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB\nWWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB",
"output": "6"
},
{
"input": "BWBBWWWW\nBWBBWWWW\nBWBBWWWW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWWWW\nBBBBBBBB",
"output": "7"
}
] | 124 | 0 | 3.969 | 788 |
659 | Round House | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk. | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=β€<=*n*<=β€<=100,<=1<=β€<=*a*<=β€<=*n*,<=<=-<=100<=β€<=*b*<=β€<=100)Β β the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=β€<=*k*<=β€<=*n*)Β β the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 1 -1",
"output": "100"
},
{
"input": "100 54 100",
"output": "54"
},
{
"input": "100 37 -100",
"output": "37"
},
{
"input": "99 41 0",
"output": "41"
},
{
"input": "97 37 -92",
"output": "42"
},
{
"input": "99 38 59",
"output": "97"
},
{
"input": "35 34 1",
"output": "35"
},
{
"input": "48 1 -1",
"output": "48"
},
{
"input": "87 65 -76",
"output": "76"
},
{
"input": "76 26 29",
"output": "55"
},
{
"input": "100 65 0",
"output": "65"
},
{
"input": "2 1 100",
"output": "1"
},
{
"input": "3 2 -100",
"output": "1"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "1 1 -100",
"output": "1"
},
{
"input": "3 1 -100",
"output": "3"
},
{
"input": "4 3 -100",
"output": "3"
},
{
"input": "3 2 -12",
"output": "2"
},
{
"input": "2 2 -100",
"output": "2"
},
{
"input": "3 2 -90",
"output": "2"
},
{
"input": "6 2 -10",
"output": "4"
},
{
"input": "3 3 -100",
"output": "2"
},
{
"input": "5 2 4",
"output": "1"
},
{
"input": "6 4 5",
"output": "3"
},
{
"input": "3 2 -6",
"output": "2"
},
{
"input": "5 1 -99",
"output": "2"
},
{
"input": "6 2 5",
"output": "1"
},
{
"input": "10 1 -100",
"output": "1"
},
{
"input": "2 2 1",
"output": "1"
},
{
"input": "3 3 1",
"output": "1"
},
{
"input": "6 4 4",
"output": "2"
},
{
"input": "17 17 2",
"output": "2"
},
{
"input": "6 6 1",
"output": "1"
},
{
"input": "5 3 -2",
"output": "1"
},
{
"input": "6 2 -100",
"output": "4"
},
{
"input": "5 3 -100",
"output": "3"
},
{
"input": "5 4 3",
"output": "2"
},
{
"input": "3 2 2",
"output": "1"
},
{
"input": "5 5 2",
"output": "2"
},
{
"input": "3 2 5",
"output": "1"
},
{
"input": "5 5 -1",
"output": "4"
},
{
"input": "5 3 3",
"output": "1"
},
{
"input": "4 2 3",
"output": "1"
},
{
"input": "88 76 74",
"output": "62"
}
] | 77 | 0 | 0 | 790 |
|
747 | Display Size | [
"brute force",
"math"
] | null | null | A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display β the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=β€<=*b*; - the difference *b*<=-<=*a* is as small as possible. | The first line contains the positive integer *n* (1<=β€<=*n*<=β€<=106)Β β the number of pixels display should have. | Print two integersΒ β the number of rows and columns on the display. | [
"8\n",
"64\n",
"5\n",
"999999\n"
] | [
"2 4\n",
"8 8\n",
"1 5\n",
"999 1001\n"
] | In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels. | [
{
"input": "8",
"output": "2 4"
},
{
"input": "64",
"output": "8 8"
},
{
"input": "5",
"output": "1 5"
},
{
"input": "999999",
"output": "999 1001"
},
{
"input": "716539",
"output": "97 7387"
},
{
"input": "1",
"output": "1 1"
},
{
"input": "2",
"output": "1 2"
},
{
"input": "3",
"output": "1 3"
},
{
"input": "4",
"output": "2 2"
},
{
"input": "6",
"output": "2 3"
},
{
"input": "7",
"output": "1 7"
},
{
"input": "9",
"output": "3 3"
},
{
"input": "10",
"output": "2 5"
},
{
"input": "11",
"output": "1 11"
},
{
"input": "12",
"output": "3 4"
},
{
"input": "15",
"output": "3 5"
},
{
"input": "100",
"output": "10 10"
},
{
"input": "101",
"output": "1 101"
},
{
"input": "169",
"output": "13 13"
},
{
"input": "179",
"output": "1 179"
},
{
"input": "190",
"output": "10 19"
},
{
"input": "1000",
"output": "25 40"
},
{
"input": "10000",
"output": "100 100"
},
{
"input": "10001",
"output": "73 137"
},
{
"input": "100000",
"output": "250 400"
},
{
"input": "100001",
"output": "11 9091"
},
{
"input": "1000000",
"output": "1000 1000"
},
{
"input": "999983",
"output": "1 999983"
},
{
"input": "524288",
"output": "512 1024"
},
{
"input": "954493",
"output": "971 983"
},
{
"input": "966289",
"output": "983 983"
},
{
"input": "944663",
"output": "961 983"
},
{
"input": "912673",
"output": "97 9409"
},
{
"input": "732641",
"output": "679 1079"
},
{
"input": "232897",
"output": "343 679"
},
{
"input": "16807",
"output": "49 343"
},
{
"input": "999958",
"output": "2 499979"
},
{
"input": "990151",
"output": "1 990151"
},
{
"input": "997002",
"output": "998 999"
},
{
"input": "20",
"output": "4 5"
},
{
"input": "20261",
"output": "1 20261"
},
{
"input": "999123",
"output": "3 333041"
},
{
"input": "901841",
"output": "1 901841"
}
] | 93 | 0 | 3 | 791 |
|
0 | none | [
"none"
] | null | null | Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word *t*: *a*1... *a*|*t*|. We denote the length of word *x* as |*x*|. Note that after removing one letter, the indices of other letters don't change. For example, if *t*<==<="nastya" and *a*<==<=[4,<=1,<=5,<=3,<=2,<=6] then removals make the following sequence of words "nastya" "nastya" "nastya" "nastya" "nastya" "nastya" "nastya".
Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word *p*. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.
It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. | The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=β€<=|*p*|<=<<=|*t*|<=β€<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
Next line contains a permutation *a*1,<=*a*2,<=...,<=*a*|*t*| of letter indices that specifies the order in which Nastya removes letters of *t* (1<=β€<=*a**i*<=β€<=|*t*|, all *a**i* are distinct). | Print a single integer number, the maximum number of letters that Nastya can remove. | [
"ababcba\nabb\n5 3 4 1 7 6 2\n",
"bbbabb\nbb\n1 6 3 4 2 5\n"
] | [
"3",
"4"
] | In the first sample test sequence of removing made by Nastya looks like this:
"ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba"
Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".
So, Nastya will remove only three letters. | [
{
"input": "ababcba\nabb\n5 3 4 1 7 6 2",
"output": "3"
},
{
"input": "bbbabb\nbb\n1 6 3 4 2 5",
"output": "4"
},
{
"input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2",
"output": "9"
},
{
"input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 19 17 15 14 11 20 2",
"output": "16"
},
{
"input": "aaaaaaaadbaaabbbbbddaaabdadbbbbbdbbabbbabaabdbbdababbbddddbdaabbddbbbbabbbbbabadaadabaaaadbbabbbaddb\naaaaaaaaaaaaaa\n61 52 5 43 53 81 7 96 6 9 34 78 79 12 8 63 22 76 18 46 41 56 3 20 57 21 75 73 100 94 35 69 32 4 70 95 88 44 68 10 71 98 23 89 36 62 28 51 24 30 74 55 27 80 38 48 93 1 19 84 13 11 86 60 87 33 39 29 83 91 67 72 54 2 17 85 82 14 15 90 64 50 99 26 66 65 31 49 40 45 77 37 25 42 97 47 58 92 59 16",
"output": "57"
}
] | 2,000 | 47,820,800 | 0 | 792 |
|
260 | Adding Digits | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times. | The first line contains three integers: *a*,<=*b*,<=*n* (1<=β€<=*a*,<=*b*,<=*n*<=β€<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99999 21 73839",
"output": "9999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99991 623 36438",
"output": "9999150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99999 334 94854",
"output": "9999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99252 9827 84849",
"output": "9925270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99313 9833 10561",
"output": "9931330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "94885 55815 11417",
"output": "9488550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99492 58525 53481",
"output": "9949250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99858 28531 79193",
"output": "9985850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99136 47208 42607",
"output": "9913680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "63270 19953 5555",
"output": "-1"
},
{
"input": "10240 128 100000",
"output": "1024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "12 11 3",
"output": "12100"
},
{
"input": "14 12 99998",
"output": "1440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "1 11 3",
"output": "1100"
},
{
"input": "3 40 1",
"output": "-1"
},
{
"input": "150 100 10",
"output": "1500000000000"
},
{
"input": "5 10 1",
"output": "50"
},
{
"input": "1 15 10",
"output": "15000000000"
},
{
"input": "3 13 2",
"output": "390"
}
] | 764 | 409,600 | 3 | 793 |
|
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"
}
] | 218 | 6,963,200 | 3.93253 | 801 |
259 | Little Elephant and Chess | [
"brute force",
"strings"
] | null | null | The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=Γ<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard. | The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the *j*-th character in the *i*-th line stands for the color of the *j*-th cell of the *i*-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard. | In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise. | [
"WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n",
"WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | [
{
"input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB",
"output": "YES"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB",
"output": "YES"
},
{
"input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nBWWWBWBW",
"output": "NO"
},
{
"input": "BBBBBWWW\nWBBWBWWB\nWWWWWBWW\nBWBWWBWW\nBBBWWBWW\nBBBBBWBW\nWBBBWBWB\nWBWBWWWB",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nBWWWWWBB\nBBWBWBWB\nWBWBWBWB\nWWBWWBWW\nBWBWBWBW\nWBWWBBBB",
"output": "NO"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWBWWBWBB",
"output": "NO"
},
{
"input": "WBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW",
"output": "YES"
},
{
"input": "WWWWBWWB\nBWBWBWBW\nBWBWBWBW\nWWBWBBBB\nBBWWBBBB\nBBBWWBBW\nBWWWWWWB\nBWWBBBWW",
"output": "NO"
},
{
"input": "WBBWWBWB\nBBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBBW\nWBWBBBBW\nBWWWWBWB\nBBBBBBBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nBBWWWBBB\nWBBBBBWW\nWBBBBWBB\nWBWBWBWB\nWBWWBWWB\nWBBWBBWW",
"output": "NO"
},
{
"input": "WBBBBBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBBBBBWBB\nWBBWWBWB\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBBWWBWB",
"output": "NO"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWWWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBBW",
"output": "NO"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "YES"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "YES"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "YES"
},
{
"input": "WWBBWWBB\nBWWBBWWB\nBWBWBWBW\nWWBBWWWB\nWBWWWWBB\nWBWWBBWB\nBWBBWBWW\nBWBWWWWW",
"output": "NO"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nWWBBWBBB\nWBWBWBWB\nWWWWBWWB\nWBBBBWWW\nBWBWWWBW\nWWWBWBBB",
"output": "NO"
},
{
"input": "WBWBWBWB\nBWWBWWWW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWWBBBBBW\nWWWBWWBW\nWWBBBBWW",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBBBWWB\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "YES"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "NO"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "NO"
},
{
"input": "BWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB",
"output": "NO"
},
{
"input": "WWBWWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "NO"
},
{
"input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nBBBBBBBB\nWWWWWWWW\nBBBBBBBB\nWWWWWWWW\nBBBBBBBB",
"output": "NO"
},
{
"input": "BBBBBBBB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "NO"
},
{
"input": "BBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW",
"output": "NO"
},
{
"input": "BBBWWWWW\nWWWBBBBB\nBBBWWWWW\nWWWBBBBB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "NO"
}
] | 280 | 0 | 0 | 802 |
|
628 | Bear and String Distance | [
"greedy",
"strings"
] | null | null | Limak is a little polar bear. He likes nice strings β strings of length *n*, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and .
Also, the distance between two nice strings is defined as the sum of distances of corresponding letters. For example, , and .
Limak gives you a nice string *s* and an integer *k*. He challenges you to find any nice string *s*' that . Find any *s*' satisfying the given conditions, or print "-1" if it's impossible to do so.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=105, 0<=β€<=*k*<=β€<=106).
The second line contains a string *s* of length *n*, consisting of lowercase English letters. | If there is no string satisfying the given conditions then print "-1" (without the quotes).
Otherwise, print any nice string *s*' that . | [
"4 26\nbear\n",
"2 7\naf\n",
"3 1000\nhey\n"
] | [
"roar",
"db\n",
"-1\n"
] | none | [
{
"input": "4 26\nbear",
"output": "zcar"
},
{
"input": "2 7\naf",
"output": "hf"
},
{
"input": "3 1000\nhey",
"output": "-1"
},
{
"input": "5 50\nkzsij",
"output": "zaiij"
},
{
"input": "5 500\nvsdxg",
"output": "-1"
},
{
"input": "1 0\na",
"output": "a"
},
{
"input": "1 1\ng",
"output": "f"
},
{
"input": "1 25\nr",
"output": "-1"
},
{
"input": "1 15\no",
"output": "-1"
},
{
"input": "10 100\naddaiyssyp",
"output": "zzzzcyssyp"
},
{
"input": "50 100\ntewducenaqgpilgftjcmzttrgebnyldwfgbtttrygaiqtkgbjb",
"output": "azazecenaqgpilgftjcmzttrgebnyldwfgbtttrygaiqtkgbjb"
},
{
"input": "2 1\nzz",
"output": "yz"
},
{
"input": "8 8\nabcdefgh",
"output": "ibcdefgh"
},
{
"input": "1 25\nz",
"output": "a"
},
{
"input": "1 24\nz",
"output": "b"
},
{
"input": "1 24\ny",
"output": "a"
},
{
"input": "2 49\nzz",
"output": "ab"
},
{
"input": "1 26\na",
"output": "-1"
},
{
"input": "1 25\na",
"output": "z"
},
{
"input": "4 17\nrzsq",
"output": "azsq"
},
{
"input": "69 1701\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaax"
},
{
"input": "2 9\nbc",
"output": "kc"
},
{
"input": "2 48\nab",
"output": "zy"
},
{
"input": "1 8\nc",
"output": "k"
},
{
"input": "2 25\nyd",
"output": "ac"
},
{
"input": "5 24\nizrqp",
"output": "zsrqp"
},
{
"input": "1 13\nn",
"output": "a"
},
{
"input": "5 21\nfmmqh",
"output": "zlmqh"
}
] | 218 | 716,800 | 3 | 805 |
|
451 | Sort the Array | [
"implementation",
"sortings"
] | null | null | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes. | The first line of the input contains an integer *n* (1<=β€<=*n*<=β€<=105) β the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=β€<=*a*[*i*]<=β€<=109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | [
"3\n3 2 1\n",
"4\n2 1 3 4\n",
"4\n3 1 2 4\n",
"2\n1 2\n"
] | [
"yes\n1 3\n",
"yes\n1 2\n",
"no\n",
"yes\n1 1\n"
] | Sample 1. You can reverse the entire array to get [1,β2,β3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*,β*r*] of array *a* is the sequence *a*[*l*],β*a*[*l*β+β1],β...,β*a*[*r*].
If you have an array *a* of size *n* and you reverse its segment [*l*,β*r*], the array will become:
*a*[1],β*a*[2],β...,β*a*[*l*β-β2],β*a*[*l*β-β1],β*a*[*r*],β*a*[*r*β-β1],β...,β*a*[*l*β+β1],β*a*[*l*],β*a*[*r*β+β1],β*a*[*r*β+β2],β...,β*a*[*n*β-β1],β*a*[*n*]. | [
{
"input": "3\n3 2 1",
"output": "yes\n1 3"
},
{
"input": "4\n2 1 3 4",
"output": "yes\n1 2"
},
{
"input": "4\n3 1 2 4",
"output": "no"
},
{
"input": "2\n1 2",
"output": "yes\n1 1"
},
{
"input": "2\n58 4",
"output": "yes\n1 2"
},
{
"input": "5\n69 37 27 4 2",
"output": "yes\n1 5"
},
{
"input": "9\n6 78 63 59 28 24 8 96 99",
"output": "yes\n2 7"
},
{
"input": "6\n19517752 43452931 112792556 68417469 779722934 921694415",
"output": "yes\n3 4"
},
{
"input": "6\n169793171 335736854 449917902 513287332 811627074 938727967",
"output": "yes\n1 1"
},
{
"input": "6\n509329 173849943 297546987 591032670 796346199 914588283",
"output": "yes\n1 1"
},
{
"input": "25\n46 45 37 35 26 25 21 19 11 3 1 51 54 55 57 58 59 62 66 67 76 85 88 96 100",
"output": "yes\n1 11"
},
{
"input": "46\n10 12 17 19 20 21 22 24 25 26 27 28 29 30 32 37 42 43 47 48 50 51 52 56 87 86 81 79 74 71 69 67 66 65 60 59 57 89 91 92 94 96 97 98 99 100",
"output": "yes\n25 37"
},
{
"input": "96\n1 2 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 68 69 70 71 72 73 74 75 76 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "yes\n3 22"
},
{
"input": "2\n404928771 698395106",
"output": "yes\n1 1"
},
{
"input": "2\n699573624 308238132",
"output": "yes\n1 2"
},
{
"input": "5\n75531609 242194958 437796493 433259361 942142185",
"output": "yes\n3 4"
},
{
"input": "5\n226959376 840957605 833410429 273566427 872976052",
"output": "yes\n2 4"
},
{
"input": "5\n373362086 994096202 767275079 734424844 515504383",
"output": "yes\n2 5"
},
{
"input": "5\n866379155 593548704 259097686 216134784 879911740",
"output": "yes\n1 4"
},
{
"input": "5\n738083041 719956102 420866851 307749161 257917459",
"output": "yes\n1 5"
},
{
"input": "5\n90786760 107075352 139104198 424911569 858427981",
"output": "yes\n1 1"
},
{
"input": "6\n41533825 525419745 636375901 636653266 879043107 967434399",
"output": "yes\n1 1"
},
{
"input": "40\n22993199 75843013 76710455 99749069 105296587 122559115 125881005 153961749 163646706 175409222 185819807 214465092 264449243 278246513 295514446 322935239 370349154 375773209 390474983 775646826 767329655 740310077 718820037 708508595 693119912 680958422 669537382 629123011 607511013 546574974 546572137 511951383 506996390 493995578 458256840 815612821 881161983 901337648 962275390 986568907",
"output": "yes\n20 35"
},
{
"input": "40\n3284161 23121669 24630274 33434127 178753820 231503277 271972002 272578266 346450638 355655265 372217434 376132047 386622863 387235708 389799554 427160037 466577363 491873718 492746058 502535866 535768673 551570285 557477055 583643014 586216753 588981593 592960633 605923775 611051145 643142759 632768011 634888864 736715552 750574599 867737742 924365786 927179496 934453020 954090860 977765165",
"output": "no"
},
{
"input": "40\n42131757 49645896 49957344 78716964 120937785 129116222 172128600 211446903 247833196 779340466 717548386 709969818 696716905 636153997 635635467 614115746 609201167 533608141 521874836 273044950 291514539 394083281 399369419 448830087 485128983 487192341 488673105 497678164 501864738 265305156 799595875 831638598 835155840 845617770 847736630 851436542 879757553 885618675 964068808 969215471",
"output": "no"
},
{
"input": "40\n25722567 28250400 47661056 108729970 119887370 142272261 145287693 178946020 182917658 187405805 209478929 278713296 312035195 393514697 403876943 410188367 413061616 420619615 477231590 511200584 560288373 571690007 603093961 615463729 631624043 723138759 726089658 728151980 756393077 785590533 809755752 823601179 828357990 866942019 869575503 877310377 881382070 901314141 929048602 947139655",
"output": "yes\n1 1"
},
{
"input": "40\n17927221 33153935 60257083 110553879 114654567 119809916 163899753 167741765 182812464 188486743 220036903 220127072 227545828 229552200 244963635 248298934 299478582 354141058 371400641 430054473 452548736 458695269 466968129 469000714 478004472 478693873 509342093 750631027 609759323 669427158 688490225 690701652 696893030 704668825 749028408 557906039 545356441 926901326 955586118 972642992",
"output": "no"
},
{
"input": "4\n1 4 2 3",
"output": "no"
},
{
"input": "6\n1 2 5 4 3 6",
"output": "yes\n3 5"
},
{
"input": "1\n1",
"output": "yes\n1 1"
},
{
"input": "6\n1 5 3 4 2 6",
"output": "no"
},
{
"input": "4\n3 4 1 2",
"output": "no"
},
{
"input": "5\n2 5 4 3 1",
"output": "no"
},
{
"input": "4\n2 1 4 3",
"output": "no"
},
{
"input": "6\n2 1 4 3 5 6",
"output": "no"
}
] | 15 | 0 | 0 | 809 |
|
299 | Ksusha the Squirrel | [
"brute force",
"implementation"
] | null | null | Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | The first line contains two integers *n* and *k* (2<=β€<=*n*<=β€<=3Β·105,<=1<=β€<=*k*<=β€<=3Β·105). The next line contains *n* characters β the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".". | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | [
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | [
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "YES"
},
{
"input": "2 100000\n..",
"output": "YES"
},
{
"input": "3 1\n.#.",
"output": "NO"
},
{
"input": "3 2\n.#.",
"output": "YES"
},
{
"input": "3 10000\n.#.",
"output": "YES"
}
] | 280 | 4,710,400 | 3 | 810 |
|
556 | Case of the Zeros and Ones | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number. | First line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=2Β·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "2\n01",
"output": "0"
},
{
"input": "2\n10",
"output": "0"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "3\n001",
"output": "1"
},
{
"input": "6\n110110",
"output": "2"
},
{
"input": "7\n0000011",
"output": "3"
},
{
"input": "6\n110010",
"output": "0"
},
{
"input": "6\n110100",
"output": "0"
},
{
"input": "3\n100",
"output": "1"
},
{
"input": "6\n010111",
"output": "2"
},
{
"input": "8\n01011100",
"output": "0"
},
{
"input": "6\n001011",
"output": "0"
},
{
"input": "7\n1110000",
"output": "1"
},
{
"input": "9\n011111101",
"output": "5"
}
] | 61 | 409,600 | -1 | 812 |
|
303 | Lucky Permutation Triple | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not.
A permutation triple of permutations of length *n* (*a*,<=*b*,<=*c*) is called a Lucky Permutation Triple if and only if . The sign *a**i* denotes the *i*-th element of permutation *a*. The modular equality described above denotes that the remainders after dividing *a**i*<=+<=*b**i* by *n* and dividing *c**i* by *n* are equal.
Now, he has an integer *n* and wants to find a Lucky Permutation Triple. Could you please help him? | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=105). | If no Lucky Permutation Triple of length *n* exists print -1.
Otherwise, you need to print three lines. Each line contains *n* space-seperated integers. The first line must contain permutation *a*, the second line β permutation *b*, the third β permutation *c*.
If there are multiple solutions, print any of them. | [
"5\n",
"2\n"
] | [
"1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3\n",
"-1\n"
] | In Sample 1, the permutation triple ([1,β4,β3,β2,β0],β[1,β0,β2,β4,β3],β[2,β4,β0,β1,β3]) is Lucky Permutation Triple, as following holds:
- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a6bf1b9b57809dbec5021f65f89616f259587c07.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/48cc13134296b68f459f69d78e0240859aaec702.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ac44412de7b46833e90348a6b3298f9796e3977c.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3825b0bb758208dda2ead1c5224c05d89ad9ab55.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0a72e2da40048a507839927a211267ac01c9bf89.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In Sample 2, you can easily notice that no lucky permutation triple exists. | [
{
"input": "5",
"output": "1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3"
},
{
"input": "2",
"output": "-1"
},
{
"input": "8",
"output": "-1"
},
{
"input": "9",
"output": "0 1 2 3 4 5 6 7 8 \n0 1 2 3 4 5 6 7 8 \n0 2 4 6 8 1 3 5 7 "
},
{
"input": "2",
"output": "-1"
},
{
"input": "77",
"output": "0 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 \n0 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 \n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 4..."
},
{
"input": "6",
"output": "-1"
},
{
"input": "87",
"output": "0 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 \n0 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 \n0 2 4..."
},
{
"input": "72",
"output": "-1"
},
{
"input": "1",
"output": "0 \n0 \n0 "
},
{
"input": "23",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 2 4 6 8 10 12 14 16 18 20 22 1 3 5 7 9 11 13 15 17 19 21 "
},
{
"input": "52",
"output": "-1"
},
{
"input": "32",
"output": "-1"
},
{
"input": "25",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 \n0 2 4 6 8 10 12 14 16 18 20 22 24 1 3 5 7 9 11 13 15 17 19 21 23 "
},
{
"input": "54",
"output": "-1"
},
{
"input": "39",
"output": "0 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 \n0 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 \n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 "
},
{
"input": "20",
"output": "-1"
},
{
"input": "53",
"output": "0 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 \n0 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 \n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 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 "
},
{
"input": "34",
"output": "-1"
},
{
"input": "23",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 2 4 6 8 10 12 14 16 18 20 22 1 3 5 7 9 11 13 15 17 19 21 "
},
{
"input": "37123",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "41904",
"output": "-1"
},
{
"input": "46684",
"output": "-1"
},
{
"input": "67817",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "72598",
"output": "-1"
},
{
"input": "85891",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "74320",
"output": "-1"
},
{
"input": "11805",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "16586",
"output": "-1"
},
{
"input": "5014",
"output": "-1"
},
{
"input": "73268",
"output": "-1"
},
{
"input": "61697",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "99182",
"output": "-1"
},
{
"input": "79771",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "68199",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "5684",
"output": "-1"
},
{
"input": "10465",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "31598",
"output": "-1"
},
{
"input": "36379",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "16968",
"output": "-1"
},
{
"input": "93061",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "73650",
"output": "-1"
},
{
"input": "94783",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "99564",
"output": "-1"
},
{
"input": "37049",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "25478",
"output": "-1"
},
{
"input": "30259",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "43551",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "31980",
"output": "-1"
},
{
"input": "69465",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "1",
"output": "0 \n0 \n0 "
},
{
"input": "100000",
"output": "-1"
},
{
"input": "99999",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "99998",
"output": "-1"
}
] | 1,154 | 7,475,200 | 3 | 816 |
|
88 | Keyboard | [
"implementation"
] | B. Keyboard | 1 | 256 | Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they make lowercase letters uppercase.
Vasya can press one or two keys with one hand. However, he can only press two keys if the Euclidean distance between the centers of the keys does not exceed *x*. The keys are considered as squares with a side equal to 1. There are no empty spaces between neighbouring keys.
Vasya is a very lazy boy, that's why he tries to type with one hand as he eats chips with his other one. However, it is possible that some symbol can't be typed with one hand only, because the distance between it and the closest "Shift" key is strictly larger than *x*. In this case he will have to use his other hand. Having typed the symbol, Vasya returns other hand back to the chips.
You are given Vasya's keyboard and the text. Count the minimum number of times Vasya will have to use the other hand. | The first line contains three integers *n*, *m*, *x* (1<=β€<=*n*,<=*m*<=β€<=30,<=1<=β€<=*x*<=β€<=50).
Next *n* lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly *m* keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys are marked with the "S" symbol.
Then follow the length of the text *q* (1<=β€<=*q*<=β€<=5Β·105). The last line contains the text *T*, which consists of *q* symbols, which are uppercase and lowercase Latin letters. | If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes). | [
"2 2 1\nab\ncd\n1\nA\n",
"2 2 1\nab\ncd\n1\ne\n",
"2 2 1\nab\ncS\n5\nabcBA\n",
"3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG\n"
] | [
"-1\n",
"-1\n",
"1\n",
"2\n"
] | In the first sample the symbol "A" is impossible to print as there's no "Shift" key on the keyboard.
In the second sample the symbol "e" is impossible to print as there's no such key on the keyboard.
In the fourth sample the symbols "T", "G" are impossible to print with one hand. The other letters that are on the keyboard can be printed. Those symbols come up in the text twice, thus, the answer is 2. | [
{
"input": "2 2 1\nab\ncd\n1\nA",
"output": "-1"
},
{
"input": "2 2 1\nab\ncd\n1\ne",
"output": "-1"
},
{
"input": "2 2 1\nab\ncS\n5\nabcBA",
"output": "1"
},
{
"input": "3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG",
"output": "2"
},
{
"input": "10 9 3\noboxlgpey\nyxcuwkkmp\njuqeflhwq\nsfnxqtjqS\nkkudcnyjl\nhgjlcrkjq\njnofqksxn\nqbhsnuguv\nlvahnifao\nebwnnlrwe\n35\nCodeforcesBetaRoundproblemAtestfive",
"output": "4"
},
{
"input": "2 7 4\niuqtieo\nysxcgmS\n2\nsQ",
"output": "1"
},
{
"input": "1 2 4\nbS\n8\nbBbbbBbb",
"output": "0"
},
{
"input": "7 8 5\nfqiubjpm\nqbshcsyk\ncjbxpbef\nptwpmapx\nryazscbm\nqnvsgzrf\nhtardzkz\n9\nuxrmwkayy",
"output": "0"
},
{
"input": "8 6 4\nefvmov\nkeofnw\npwajpe\nknptky\nSibruu\nrgdukk\nbsxosd\nhovgSe\n10\nECreruXmsC",
"output": "-1"
},
{
"input": "10 3 2\nukk\neqt\nfex\nqSh\ntvz\nfjn\niol\nehd\nnte\ngyx\n5\ncgQxI",
"output": "-1"
},
{
"input": "10 10 19\nowqjcaSpqn\nvgrhboqahn\nbzziocjmbu\npurqsmiSop\nxcsifctjhy\nycyytwoamk\nrnjfxsxowl\nnkgcywcdff\nbazljrisqv\nkcakigSekq\n100\nzewpATtssQVicNrlRrcoifTutTAfFMUEfDFKoNyQbSrSYxTGMadNkRpmJvoEqUsqPYgAdQreaUrwDKMNFWiwdRRCcJBPorfMVMoK",
"output": "0"
},
{
"input": "10 10 26\nwxmssptheb\nzpxbxsyxsy\nqbjkpaywqp\nfwhnuzjcgq\nycgaanzedz\njrycrbzqfs\ngswwakybus\nfhtxhljedz\noSepmyjosv\ndwviycevdn\n100\nyapwUfnyPzgZyFvAHGKWVbXQHkuhJDoUTvCAtdMMCQmKchxKkilUTECOqYJFUSHPqKiRKhDXZgHxwApDWlShdwakmVCgaeKCLOMX",
"output": "0"
},
{
"input": "10 10 3\nrvouufmnqu\nbyukrnmnhr\nzjggwxgvkz\ntcagkSitiw\nhryajgtpwc\njragfhqoks\nkgroxxkuvp\nbpgrkqiyns\njbuhjjkziw\nomjmbaggsw\n100\nCpRzrPqPngYvrVJFCWRPMRwrpXcbtiwfoFcAkRaNjzpMMKOQAzBxSrxGbIHaYgmSqhhxhZTmhFttKnhFzRfKxYXshUZRvtKJIzZq",
"output": "12"
},
{
"input": "10 10 2\nfriuxvShvg\nerslojqtgu\nzeqsmdewry\nwvhbeeyeSu\ngkofbjaavr\ntwkcdxugps\nnzlylSmafu\nstamkpxnzt\nuwxwximkrm\nmzxyboazbl\n100\nmRIfAtrLKmztpVkAmojDCiIgseBwlUilBIixDQhqNhNAqVLLIobuCIretLdSvixNNdCiouFMXtwHZFlObCeaygmIiFBfaCirbmCa",
"output": "19"
},
{
"input": "10 10 2\nbddahSqkmk\npxbocxayjs\nottvdazstk\nlaxuidqlqb\nkfjwdpdfat\nxlipuubkgv\niqyomzfktm\niwbgidmwyu\nrngqkeupsf\nbqndtekryw\n100\nMNQgWFLhHycqwjSsbTkbgMYAIHFYARRmOsinYMFjOxxnLjiKfeiBbMpoeTdzUMORPaAxRNfvdAPFaKkPdxdAjjJgGCxkDzmSasqq",
"output": "37"
},
{
"input": "10 10 2\nnxcwdrsmrv\nSyjahsosvp\nvkrqbxhgbv\nwkxywavtnn\nepkyoviqbi\nsfmpvhuwwq\nnlsostrotx\ntcdguorhny\nimixrqzSdu\nxzhdhdwibt\n100\nUzzaWiRFYbAqxIDMrRBBDoGQhSzSqSLEddAiJsZcxbemdeuddamNYdWOvzlYSCuHIRpnuxdNxAsnZMiLXBYwnrMcrbNeLrUYhZOB",
"output": "17"
},
{
"input": "10 10 23\nhtyvouoiqi\nvySvsfqadv\nxvqyqjyutq\npjcrrphzbk\nhlqfyoqfmo\nezcSwleoew\nxkwqrajxyg\nngSiftgoso\njyndgicccr\nlgjvokydhp\n100\nJzVVfotldIRcyjhTNRcFlTxFeZKRwavZxYcvdDOQyUvTmryFRuRBcRvmscegtspkPuchqlFEKbrfpTOSlSFOARsbbvSenMwNmaRj",
"output": "0"
},
{
"input": "10 10 7\nifcwalsdbj\njpykymrbei\nrylzgkyefh\noilvvexpjp\niptgodpfim\ndSrqejaixu\npksxlsniwa\nmoSenxtfbc\noqssptcenz\nqdhmouvyas\n100\nqtMDVUXJpSEFgPsLKyRJVRbfVoYaCKJDnQDLFVngVjSPzzVyMnMyuyahMRiBJuNhKtgpVqvukUolLvYEmidvXotgQUJukYwIweUW",
"output": "0"
},
{
"input": "10 10 1\nmdxafehbkr\nyuhenybjps\ntvfwmiwcoh\njmzrepzjvx\nnqyorkSnuk\ntSmztmwidv\ncmmajnlqrw\nfiqewpdwax\nuesmkdcplt\nlgkomdcqbo\n100\nmcEQmAvFqKYMXLHQUDeIulkmAMRkIUtbKihTFJwJYQfcAelNrZWSAwHunwZTrdHaRWokgCyLqbubOpEHuZiDVoFHjvkMSoBPyGOI",
"output": "39"
},
{
"input": "10 10 2\nnhfafdwqhh\neyvitpcthk\nrpiotuoqzh\nnxxnhuaxee\nyevrtirzwf\nkbtSsamyel\nfeenjvxsmo\nkqpenxjmde\nlqsamthlwp\njdyyqsbtbk\n100\nUHucxPWDaKonVpXEctuqYUAQnrFEZaTYxhoacNbHIMevlbDejXjitEzyVrTfcfBHWRMdJvaTkbkqccyHjtzpTbKmRAXwlXCtFKNX",
"output": "29"
},
{
"input": "10 10 1\nsufnxxpdnx\nvttibpllhv\nlvbrjmfdjx\ngmtexvrnfh\nygsqrsSwxd\nkxbbjxgbzs\nedutwocmzd\nfebjgknyai\nvcvquagvrs\ndrdoarhgoc\n100\nZoZJXhUWyaLgBTpgbznABKHuyFcKzJmGaMhoKkKfyOGacLwBspaKtAEdwMZJFYiZUFNDxdDIDgKSCRvsbGUOXRqalbpuEqkduYpW",
"output": "44"
},
{
"input": "10 10 2\ncstcrltzsl\nblotmquzvj\nuiitiytlgx\nwumpfdaprd\ntfxohqpztn\nvfrpsccddo\nneegusrkxw\niijfjozqjq\nioegbvuhew\npjjpqdxvqu\n100\nkPCBONfZLkeXzWVuSgvinPENazcnRoBcUHXwRzPyvNIiDlDSeKOYmiUmjooXuzTCtIRxKDAYeTLgjsenxHoymVazMALUADQpjVjV",
"output": "-1"
},
{
"input": "10 10 1\nqztnjglyrc\nnukswgzajl\nqnpbdwjvbb\nliiakzcrlz\nnolwfzzvxd\nmqvhiySttx\nqwuizSjuto\nqbgwiwjukx\nkomyvblgkc\ntkzlxzgsru\n100\nYUzTZDzLFkMUhjQWbwljJCRyZGFzgJcozvROiwPktRGxkMKiPyiTvhDrtusPYhMgVAOFIjAvlpzcrUvrMrMbhkpUiyAytKfYOGTF",
"output": "37"
},
{
"input": "10 10 1\nmgziiihbkq\niobjknuogh\nvntwahSopu\nsjsxjpaqvm\nwqgrodizst\nselzugktoi\nvbhfzvgjfn\nliqlfdcjhf\nbpbtpmimxb\npksfiydpfw\n100\nwAVZXEhKTuajdCauVTIwgnfbxWuUSmtXkjHZtNVcfTsiSAPLdpdEFdTJLZRjptUcRhAmrNjKMXmuDGatAQoaIpbddnzRGHsJrhoq",
"output": "39"
},
{
"input": "10 10 2\nshbqxycvfm\notydudkttw\nqhatsxsngz\nixvyujtyjc\nsbvqhnjbak\neggcguuuka\nxcydfgjzeb\nytpdkcdrsq\nefqlpywggu\nfcnfrhnouo\n100\nHPqtuVckdUOhsnuhnbpekWvWKUnAEaOCihpeEvmaOKOPcIZiMixGJGEuXAaOxuUNyrIesmldLEqGnvyDKPDvFkCbRebCORHmUgeV",
"output": "-1"
},
{
"input": "1 1 50\nS\n29\nargjhoaiogjiSjqfhjksdvjkSvcvn",
"output": "-1"
},
{
"input": "1 1 50\nS\n1\nS",
"output": "-1"
},
{
"input": "1 1 50\na\n29\nargjhoaiogjiSjqfhjksdvjkSvcvn",
"output": "-1"
},
{
"input": "1 1 50\nz\n29\nargjhoaiogjiSjqfhjksdvjkSvcvn",
"output": "-1"
},
{
"input": "2 1 2\nS\nc\n4\nCSSA",
"output": "-1"
}
] | 46 | 0 | 0 | 822 |
12 | Fruits | [
"greedy",
"implementation",
"sortings"
] | C. Fruits | 1 | 256 | The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags). | The first line of the input contains two integer number *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100) β the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following *m* lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to *n*. Also it is known that the seller has in stock all fruits that Valera wants to buy. | Print two numbers *a* and *b* (*a*<=β€<=*b*) β the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. | [
"5 3\n4 2 1 10 5\napple\norange\nmango\n",
"6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n"
] | [
"7 19\n",
"11 30\n"
] | none | [
{
"input": "5 3\n4 2 1 10 5\napple\norange\nmango",
"output": "7 19"
},
{
"input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange",
"output": "11 30"
},
{
"input": "2 2\n91 82\neiiofpfpmemlakcystpun\nmcnzeiiofpfpmemlakcystpunfl",
"output": "173 173"
},
{
"input": "1 4\n1\nu\nu\nu\nu",
"output": "4 4"
},
{
"input": "3 3\n4 2 3\nwivujdxzjm\nawagljmtc\nwivujdxzjm",
"output": "7 11"
},
{
"input": "3 4\n10 10 10\nodchpcsdhldqnkbhwtwnx\nldqnkbhwtwnxk\nodchpcsdhldqnkbhwtwnx\nldqnkbhwtwnxk",
"output": "40 40"
},
{
"input": "3 1\n14 26 22\naag",
"output": "14 26"
},
{
"input": "2 2\n5 5\ndcypj\npiyqiagzjlvbhgfndhfu",
"output": "10 10"
},
{
"input": "4 3\n5 3 10 3\nxzjhplrzkbbzkypfazf\nxzjhplrzkbbzkypfazf\nh",
"output": "9 25"
},
{
"input": "5 5\n10 10 6 7 9\niyerjkvzibxhllkeuagptnoqrzm\nvzibxhllkeuag\niyerjkvzibxhllkeuagptnoqrzm\nnoq\nnoq",
"output": "35 49"
},
{
"input": "10 8\n19 18 20 13 19 13 11 10 19 16\nkayangqlsqmcd\nqls\nqydawlbludrgrjfjrhd\nfjrh\nqls\nqls\nrnmmayh\nkayangqlsqmcd",
"output": "94 154"
},
{
"input": "5 15\n61 56 95 42 85\noq\ndwxivk\ntxdxzsfdj\noq\noq\ndwxivk\ntxdxzsfdj\ndwxivk\ntxdxzsfdj\nk\nk\ndwxivk\noq\nk\ntxdxzsfdj",
"output": "891 1132"
},
{
"input": "12 18\n42 44 69 16 81 64 12 68 70 75 75 67\nfm\nqamklzfmrjnqgdspwfasjnplg\nqamklzfmrjnqgdspwfasjnplg\nqamklzfmrjnqgdspwfasjnplg\nl\nl\nl\nfm\nqamklzfmrjnqgdspwfasjnplg\nl\nnplgwotfm\np\nl\namklzfm\ntkpubqamklzfmrjn\npwf\nfm\np",
"output": "606 1338"
},
{
"input": "24 24\n34 69 89 45 87 30 78 14 53 16 27 54 75 95 10 69 80 71 43 3 91 9 8 7\nswtcofrcpeyszydwkrg\nszyd\npeyszyd\nrcpeyszydwkrgfj\npeyszydwkrgf\nzydw\nsmzginydyrtua\nj\nj\ntzwsw\ngfj\nyssoqnlpsm\ninydyrtuatzw\ninydy\nlpsmzginydyrtuatzwswtcofrcpeyszy\nyssoqnlpsm\npeyszyd\nyssoqnlpsm\ninydy\npeyszyd\ninydyrtuatzw\nat\nfj\nswtcofrcpeyszydwkrg",
"output": "552 1769"
}
] | 31 | 0 | 3.9845 | 823 |
0 | none | [
"none"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits. Petya can perform operations of two types:
- replace any one digit from string *a* by its opposite (i.e., replace 4 by 7 and 7 by 4); - swap any pair of digits in string *a*.
Petya is interested in the minimum number of operations that are needed to make string *a* equal to string *b*. Help him with the task. | The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. | Print on the single line the single number β the minimum number of operations needed to convert string *a* into string *b*. | [
"47\n74\n",
"774\n744\n",
"777\n444\n"
] | [
"1\n",
"1\n",
"3\n"
] | In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites. | [
{
"input": "47\n74",
"output": "1"
},
{
"input": "774\n744",
"output": "1"
},
{
"input": "777\n444",
"output": "3"
},
{
"input": "74747474\n77777777",
"output": "4"
},
{
"input": "444444444444\n777777777777",
"output": "12"
},
{
"input": "4744744447774474447474774\n4477774777444444444777447",
"output": "8"
},
{
"input": "7\n4",
"output": "1"
},
{
"input": "4\n7",
"output": "1"
},
{
"input": "7777777777\n7777777774",
"output": "1"
},
{
"input": "47777777777\n77777777774",
"output": "1"
},
{
"input": "47747477747744447774774444444777444747474747777774\n44777444774477447777444774477777477774444477447777",
"output": "14"
},
{
"input": "44447777447744444777777747477444777444447744444\n47444747774774744474747744447744477747777777447",
"output": "13"
},
{
"input": "4447744774744774744747744774474474444447477477444747477444\n7477477444744774744744774774744474744447744774744477744477",
"output": "14"
},
{
"input": "44747744777777444\n47774747747744777",
"output": "6"
},
{
"input": "44447774444474477747774774477777474774744744477444447777477477744747477774744444744777777777747777477447744774744444747477744744\n77777474477477747774777777474474477444474777477747747777477747747744474474747774747747444777474444744744444477477777747744747477",
"output": "37"
},
{
"input": "774774747744474477447477777447477747477474777477744744747444774474477477747474477447774444774744777\n744477444747477447477777774477447444447747477747477747774477474447474477477474444777444444447474747",
"output": "27"
},
{
"input": "4747447477\n4747444744",
"output": "3"
},
{
"input": "47744447444\n74477447744",
"output": "4"
},
{
"input": "447444777744\n777747744477",
"output": "6"
},
{
"input": "474777477774444\n774747777774477",
"output": "4"
},
{
"input": "47744474447747744777777447\n44744747477474777744777477",
"output": "7"
},
{
"input": "77447447444777777744744747744747774747477774777774447447777474477477774774777\n74777777444744447447474474477747747444444447447774444444747777444747474777447",
"output": "28"
},
{
"input": "7\n7",
"output": "0"
},
{
"input": "444\n444",
"output": "0"
},
{
"input": "77747\n47474",
"output": "3"
}
] | 186 | 5,017,600 | 3 | 824 |
|
371 | K-Periodic Array | [
"greedy",
"implementation",
"math"
] | null | null | This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it has period of length *k*.
For example, any array is *n*-periodic, where *n* is the array length. Array [2,<=1,<=2,<=1,<=2,<=1] is at the same time 2-periodic and 6-periodic and array [1,<=2,<=1,<=1,<=2,<=1,<=1,<=2,<=1] is at the same time 3-periodic and 9-periodic.
For the given array *a*, consisting only of numbers one and two, find the minimum number of elements to change to make the array *k*-periodic. If the array already is *k*-periodic, then the required value equals 0. | The first line of the input contains a pair of integers *n*, *k* (1<=β€<=*k*<=β€<=*n*<=β€<=100), where *n* is the length of the array and the value *n* is divisible by *k*. The second line contains the sequence of elements of the given array *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=2), *a**i* is the *i*-th element of the array. | Print the minimum number of array elements we need to change to make the array *k*-periodic. If the array already is *k*-periodic, then print 0. | [
"6 2\n2 1 2 2 2 1\n",
"8 4\n1 1 2 1 1 1 2 1\n",
"9 3\n2 1 1 1 2 1 1 1 2\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2,β1,β2,β1,β2,β1].
In the second sample, the given array already is 4-periodic.
In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1,β1,β1,β1,β1,β1,β1,β1,β1] β this array is simultaneously 1-, 3- and 9-periodic. | [
{
"input": "6 2\n2 1 2 2 2 1",
"output": "1"
},
{
"input": "8 4\n1 1 2 1 1 1 2 1",
"output": "0"
},
{
"input": "9 3\n2 1 1 1 2 1 1 1 2",
"output": "3"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 2\n2 2",
"output": "0"
},
{
"input": "100 1\n1 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 1 2 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 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "8"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "2 2\n2 1",
"output": "0"
},
{
"input": "3 1\n2 1 2",
"output": "1"
},
{
"input": "3 3\n1 2 1",
"output": "0"
},
{
"input": "4 2\n2 1 2 2",
"output": "1"
},
{
"input": "10 2\n2 2 2 1 1 2 2 2 2 1",
"output": "3"
},
{
"input": "10 5\n2 2 1 2 1 1 2 1 1 1",
"output": "2"
},
{
"input": "20 4\n2 2 1 2 2 2 1 2 2 2 1 2 2 2 1 2 2 2 1 2",
"output": "0"
},
{
"input": "20 5\n2 2 1 1 1 2 1 1 1 1 2 2 1 1 2 2 2 1 1 2",
"output": "3"
},
{
"input": "20 10\n1 2 2 2 2 1 1 1 2 1 1 2 2 2 2 1 2 2 2 1",
"output": "2"
},
{
"input": "100 2\n2 2 1 2 1 2 1 2 1 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100 4\n1 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 2 2 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 1 1 2 1 1",
"output": "8"
},
{
"input": "100 5\n2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 1 2 2 2 1 1 2 1 2 2 2 2 2 2 2 1 2 2 2",
"output": "16"
},
{
"input": "100 10\n2 1 1 1 1 2 2 2 1 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 1 2 1 2 1 1 2 1 1 1 1 2 2 2 1 1 2 1 1 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 1 1 2 1 1 1 2 2 1 2 1 1",
"output": "6"
},
{
"input": "100 20\n2 2 2 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 2 1 2 2 2 2 1 2 1 2 1 1 1 1 2 2 2 2 1 2 1 1 2 2 2 2 1 2 1 2 1 2 1 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 2 1 1 1 1 2 2 2 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 1 1 2 2 1 2 2 1 1 1",
"output": "13"
},
{
"input": "100 25\n2 2 1 2 2 2 2 2 1 2 2 1 2 1 1 2 1 2 1 2 2 2 1 2 2 2 1 1 2 1 2 1 2 1 2 2 1 2 1 1 2 2 2 1 2 2 1 2 2 2 2 1 1 2 1 2 2 1 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 1 2 1 1 2 2 2 2 2 1 2 2 1 1 2 1 2 2 2 1 2 2 2 2 2 2",
"output": "15"
},
{
"input": "100 10\n2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1",
"output": "0"
}
] | 62 | 0 | 3 | 825 |
|
0 | none | [
"none"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375Β·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the *k*-rounding of *n*. | The only line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=109, 0<=β€<=*k*<=β€<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "2"
},
{
"input": "100 0",
"output": "100"
},
{
"input": "1000000000 0",
"output": "1000000000"
},
{
"input": "160 2",
"output": "800"
},
{
"input": "3 0",
"output": "3"
},
{
"input": "10 0",
"output": "10"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "2 1",
"output": "10"
},
{
"input": "3 1",
"output": "30"
},
{
"input": "4 1",
"output": "20"
},
{
"input": "5 1",
"output": "10"
},
{
"input": "6 1",
"output": "30"
},
{
"input": "7 1",
"output": "70"
},
{
"input": "8 1",
"output": "40"
},
{
"input": "9 1",
"output": "90"
},
{
"input": "10 1",
"output": "10"
},
{
"input": "11 1",
"output": "110"
},
{
"input": "12 1",
"output": "60"
},
{
"input": "16 2",
"output": "400"
},
{
"input": "2 2",
"output": "100"
},
{
"input": "1 2",
"output": "100"
},
{
"input": "5 2",
"output": "100"
},
{
"input": "15 2",
"output": "300"
},
{
"input": "36 2",
"output": "900"
},
{
"input": "1 8",
"output": "100000000"
},
{
"input": "8 8",
"output": "100000000"
},
{
"input": "96 8",
"output": "300000000"
},
{
"input": "175 8",
"output": "700000000"
},
{
"input": "9999995 8",
"output": "199999900000000"
},
{
"input": "999999999 8",
"output": "99999999900000000"
},
{
"input": "12345678 8",
"output": "617283900000000"
},
{
"input": "78125 8",
"output": "100000000"
},
{
"input": "390625 8",
"output": "100000000"
},
{
"input": "1953125 8",
"output": "500000000"
},
{
"input": "9765625 8",
"output": "2500000000"
},
{
"input": "68359375 8",
"output": "17500000000"
},
{
"input": "268435456 8",
"output": "104857600000000"
},
{
"input": "125829120 8",
"output": "9830400000000"
},
{
"input": "128000 8",
"output": "400000000"
},
{
"input": "300000 8",
"output": "300000000"
},
{
"input": "3711871 8",
"output": "371187100000000"
},
{
"input": "55555 8",
"output": "1111100000000"
},
{
"input": "222222222 8",
"output": "11111111100000000"
},
{
"input": "479001600 8",
"output": "7484400000000"
},
{
"input": "655360001 7",
"output": "6553600010000000"
},
{
"input": "655360001 8",
"output": "65536000100000000"
},
{
"input": "1000000000 1",
"output": "1000000000"
},
{
"input": "1000000000 7",
"output": "1000000000"
},
{
"input": "1000000000 8",
"output": "1000000000"
},
{
"input": "100000000 8",
"output": "100000000"
},
{
"input": "10000000 8",
"output": "100000000"
},
{
"input": "1000000 8",
"output": "100000000"
},
{
"input": "10000009 8",
"output": "1000000900000000"
},
{
"input": "10000005 8",
"output": "200000100000000"
},
{
"input": "10000002 8",
"output": "500000100000000"
},
{
"input": "999999997 8",
"output": "99999999700000000"
},
{
"input": "999999997 7",
"output": "9999999970000000"
},
{
"input": "999999995 8",
"output": "19999999900000000"
},
{
"input": "123 8",
"output": "12300000000"
},
{
"input": "24 2",
"output": "600"
},
{
"input": "16 4",
"output": "10000"
},
{
"input": "123456787 8",
"output": "12345678700000000"
},
{
"input": "100000000 8",
"output": "100000000"
},
{
"input": "7 1",
"output": "70"
},
{
"input": "101 1",
"output": "1010"
},
{
"input": "50 2",
"output": "100"
},
{
"input": "999999818 1",
"output": "4999999090"
},
{
"input": "2 1",
"output": "10"
},
{
"input": "123 1",
"output": "1230"
},
{
"input": "16 1",
"output": "80"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "1000000000 8",
"output": "1000000000"
},
{
"input": "15304 6",
"output": "1913000000"
},
{
"input": "3 8",
"output": "300000000"
},
{
"input": "4 2",
"output": "100"
},
{
"input": "100000 7",
"output": "10000000"
},
{
"input": "5 8",
"output": "100000000"
},
{
"input": "16724 6",
"output": "4181000000"
},
{
"input": "999999999 1",
"output": "9999999990"
},
{
"input": "999999990 8",
"output": "9999999900000000"
},
{
"input": "999999999 8",
"output": "99999999900000000"
},
{
"input": "100000 1",
"output": "100000"
},
{
"input": "8 3",
"output": "1000"
},
{
"input": "16768 6",
"output": "262000000"
},
{
"input": "123456789 1",
"output": "1234567890"
},
{
"input": "2 8",
"output": "100000000"
},
{
"input": "999999937 8",
"output": "99999993700000000"
},
{
"input": "5 1",
"output": "10"
},
{
"input": "2000000 7",
"output": "10000000"
},
{
"input": "1999998 2",
"output": "99999900"
},
{
"input": "125 3",
"output": "1000"
}
] | 1,000 | 0 | 0 | 826 |
|
776 | Molly's Chemicals | [
"binary search",
"brute force",
"data structures",
"implementation",
"math"
] | null | null | Molly Hooper has *n* different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The *i*-th of them has affection value *a**i*.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of *k*. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments. | The first line of input contains two integers, *n* and *k*, the number of chemicals and the number, such that the total affection value is a non-negative power of this number *k*. (1<=β€<=*n*<=β€<=105, 1<=β€<=|*k*|<=β€<=10).
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=β€<=*a**i*<=β€<=109)Β β affection values of chemicals. | Output a single integerΒ β the number of valid segments. | [
"4 2\n2 2 2 2\n",
"4 -3\n3 -6 -3 12\n"
] | [
"8\n",
"3\n"
] | Do keep in mind that *k*<sup class="upper-index">0</sup>β=β1.
In the first sample, Molly can get following different affection values:
- 2: segments [1,β1], [2,β2], [3,β3], [4,β4]; - 4: segments [1,β2], [2,β3], [3,β4]; - 6: segments [1,β3], [2,β4]; - 8: segments [1,β4].
Out of these, 2, 4 and 8 are powers of *k*β=β2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1,β2], [3,β3], [3,β4]. | [
{
"input": "4 2\n2 2 2 2",
"output": "8"
},
{
"input": "4 -3\n3 -6 -3 12",
"output": "3"
},
{
"input": "14 -9\n-2 -4 62 53 90 41 35 21 85 74 85 57 10 39",
"output": "0"
},
{
"input": "20 9\n90 21 -6 -61 14 -21 -17 -65 -84 -75 -48 56 67 -50 16 65 -79 -61 92 85",
"output": "1"
},
{
"input": "89 -7\n5972 4011 3914 670 3727 2913 6935 6927 2118 6645 7141 3585 9811 2859 459 8870 6578 8667 468 5152 3241 7455 7323 8817 4866 1040 5102 9146 621 5002 396 4967 9822 4200 3899 4416 5225 9415 9606 4802 5589 1798 9094 5453 7163 264 1026 6187 3918 4237 -17 4306 8960 3321 2927 9205 6248 7607 564 364 3503 8149 2235 8278 6249 3987 524 5718 9359 3549 1474 9204 3870 6996 3932 8295 612 6310 4461 1129 6441 3465 4654 7583 3274 6309 4831 4918 558",
"output": "0"
},
{
"input": "10 2\n2 4 8 16 32 64 128 256 512 1024",
"output": "10"
},
{
"input": "10 1\n-1 1 -1 1 -1 1 -1 1 -1 1",
"output": "15"
},
{
"input": "32 2\n8 16384 32768 65536 32 8388608 1048576 16777216 65536 8 16384 128 2097152 1024 16777216 4 8192 8388608 65536 1024 1024 16 8 16 128 2 1024 128 8 33554432 32768 2048",
"output": "33"
},
{
"input": "1 2\n2",
"output": "1"
},
{
"input": "14 2\n2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "45"
},
{
"input": "2 1\n1 1",
"output": "2"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "10"
},
{
"input": "4 1\n1 1 1 1",
"output": "4"
},
{
"input": "3 1\n1 1 1",
"output": "3"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "10 -1\n1 0 -1 1 0 -1 1 0 -1 1",
"output": "28"
},
{
"input": "4 1\n-1 -2 3 1",
"output": "3"
},
{
"input": "26 -1\n0 0 1 1 -1 -1 0 0 1 0 0 0 -1 1 0 0 -1 1 -1 1 -1 1 0 0 5 -4",
"output": "168"
},
{
"input": "1 -1\n-1",
"output": "1"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "1"
},
{
"input": "1 2\n1048576",
"output": "1"
},
{
"input": "4 -1\n1 1 1 1",
"output": "4"
},
{
"input": "5 -1\n1 1 1 1 1",
"output": "5"
},
{
"input": "33 2\n536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912",
"output": "141"
},
{
"input": "1 1\n-1",
"output": "0"
}
] | 577 | 14,745,600 | 0 | 828 |
|
989 | A Tide of Riverscape | [
"constructive algorithms",
"strings"
] | null | null | "Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string $s$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $p$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer $p$ is considered a period of string $s$, if for all $1 \leq i \leq \lvert s \rvert - p$, the $i$-th and $(i + p)$-th characters of $s$ are the same. Here $\lvert s \rvert$ is the length of $s$. | The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$)Β β the length of the given string and the supposed period, respectively.
The second line contains a string $s$ of $n$ charactersΒ β Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' character. | Output one lineΒ β if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)). | [
"10 7\n1.0.1.0.1.\n",
"10 6\n1.0.1.1000\n",
"10 9\n1........1\n"
] | [
"1000100010\n",
"1001101000\n",
"No\n"
] | In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different.
In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different.
In the third example, $9$ is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | [
{
"input": "10 7\n1.0.1.0.1.",
"output": "1000100010"
},
{
"input": "10 6\n1.0.1.1000",
"output": "1001101000"
},
{
"input": "10 9\n1........1",
"output": "No"
},
{
"input": "1 1\n.",
"output": "No"
},
{
"input": "5 1\n0...1",
"output": "00001"
},
{
"input": "17 10\n..1.100..1..0.100",
"output": "00101000010000100"
},
{
"input": "2 1\n0.",
"output": "01"
},
{
"input": "2 1\n..",
"output": "01"
},
{
"input": "3 1\n.0.",
"output": "001"
},
{
"input": "3 1\n00.",
"output": "001"
},
{
"input": "3 2\n0..",
"output": "001"
},
{
"input": "3 2\n0.0",
"output": "No"
},
{
"input": "3 2\n1..",
"output": "100"
},
{
"input": "3 2\n.1.",
"output": "011"
},
{
"input": "3 2\n1.0",
"output": "100"
},
{
"input": "3 3\n1..",
"output": "No"
},
{
"input": "3 3\n.00",
"output": "No"
},
{
"input": "5 3\n0.000",
"output": "01000"
},
{
"input": "10 6\n10010.1001",
"output": "No"
},
{
"input": "75 38\n00.0.1.0.0110.1.00010..100.1110..110..00.0.1.0.0110.1.00010..100.1110..110.",
"output": "000001000011001000010001000111000110000000010000110010000100010001110001101"
},
{
"input": "128 108\n01100.110...000.0001.1.11.11.010010.01100.0.1.01.0.0011.11001.000101...1.0.0..100.0110.0110.0.0101.0.0.0001.01100.110...100.0001",
"output": "01100011000000000001010110110010010001100000100100000110110010000101000100000010000110001100000101000000001001100011000010000001"
},
{
"input": "5 4\n.101.",
"output": "01011"
},
{
"input": "4 2\n101.",
"output": "1011"
},
{
"input": "5 4\n.1011",
"output": "01011"
},
{
"input": "2 1\n..",
"output": "01"
},
{
"input": "5 3\n00.11",
"output": "00011"
},
{
"input": "10 8\n1111.00000",
"output": "1111000000"
},
{
"input": "10 3\n11111111.1",
"output": "1111111101"
},
{
"input": "3 2\n1.0",
"output": "100"
},
{
"input": "6 4\n11..10",
"output": "110010"
},
{
"input": "4 2\n.111",
"output": "0111"
},
{
"input": "3 2\n01.",
"output": "011"
},
{
"input": "5 4\n10.00",
"output": "10000"
},
{
"input": "10 9\n1........0",
"output": "1000000000"
},
{
"input": "2 1\n0.",
"output": "01"
},
{
"input": "8 4\n111111..",
"output": "11111100"
},
{
"input": "3 2\n0.1",
"output": "001"
},
{
"input": "4 1\n111.",
"output": "1110"
},
{
"input": "3 1\n01.",
"output": "010"
},
{
"input": "10 7\n000....111",
"output": "0000000111"
}
] | 109 | 0 | 3 | 829 |
|
593 | 2Char | [
"brute force",
"implementation"
] | null | null | Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.
Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length. | The first line of the input contains number *n* (1<=β€<=*n*<=β€<=100)Β β the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input. | Print a single integerΒ β the maximum possible total length of words in Andrew's article. | [
"4\nabb\ncacc\naaa\nbbb\n",
"5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n"
] | [
"9",
"6"
] | In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.
In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}. | [
{
"input": "4\nabb\ncacc\naaa\nbbb",
"output": "9"
},
{
"input": "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa",
"output": "6"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\nz\nz",
"output": "2"
},
{
"input": "5\nabcde\nfghij\nklmno\npqrst\nuvwxy",
"output": "0"
},
{
"input": "6\ngggggg\ngggggg\ngggggg\ngggggg\ngggggg\ngggggg",
"output": "36"
},
{
"input": "6\naaaaaa\naaaaaa\nbbbbbb\nbbbbbb\naaabbb\nababab",
"output": "36"
},
{
"input": "1\nabc",
"output": "0"
},
{
"input": "2\nabc\nbca",
"output": "0"
},
{
"input": "3\nab\nba\nzzz",
"output": "4"
},
{
"input": "3\nab\nba\nzzzzz",
"output": "5"
},
{
"input": "5\nzzz\nzzzz\nzz\nz\naaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "37"
},
{
"input": "26\nq\nw\ne\nr\nt\ny\nu\ni\no\np\na\ns\nd\nf\ng\nh\nj\nk\nl\nz\nx\nc\nv\nb\nn\nm",
"output": "2"
},
{
"input": "5\nzzz\nzzzz\nzz\nz\naaaaaaaaaaaaaaaaaaaaaaaaaaaf",
"output": "28"
},
{
"input": "7\npavel\nerika\nalexxxxxxx\ngracio\nzhenya\nsudarev\nchelyaba",
"output": "0"
},
{
"input": "31\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml",
"output": "0"
},
{
"input": "5\nzloyfreid\ngraciocode\nschooldiary\nkazakov\nevgesha",
"output": "0"
},
{
"input": "4\nurkop\nvisualac\ngnutl\nwtf",
"output": "0"
},
{
"input": "3\naa\nb\nccc",
"output": "5"
},
{
"input": "3\na\nbd\ncaaaaaaa",
"output": "9"
},
{
"input": "4\naa\nax\nay\nxxxx",
"output": "8"
},
{
"input": "5\nc\nbb\ne\ndd\nf",
"output": "4"
},
{
"input": "2\naaaaa\naaaaa",
"output": "10"
}
] | 46 | 204,800 | -1 | 831 |
|
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 "
}
] | 46 | 0 | 3 | 835 |
|
296 | Yaroslav and Permutations | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=1000) β the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 539 896 668 36 896",
"output": "YES"
},
{
"input": "7\n674 712 674 674 674 674 674",
"output": "NO"
},
{
"input": "8\n742 742 742 742 742 289 742 742",
"output": "NO"
},
{
"input": "9\n730 351 806 806 806 630 85 757 967",
"output": "YES"
},
{
"input": "10\n324 539 83 440 834 640 440 440 440 440",
"output": "YES"
},
{
"input": "7\n925 830 925 98 987 162 356",
"output": "YES"
},
{
"input": "68\n575 32 53 351 151 942 725 967 431 108 192 8 338 458 288 754 384 946 910 210 759 222 589 423 947 507 31 414 169 901 592 763 656 411 360 625 538 549 484 596 42 603 351 292 837 375 21 597 22 349 200 669 485 282 735 54 1000 419 939 901 789 128 468 729 894 649 484 808",
"output": "YES"
},
{
"input": "22\n618 814 515 310 617 936 452 601 250 520 557 799 304 225 9 845 610 990 703 196 486 94",
"output": "YES"
},
{
"input": "44\n459 581 449 449 449 449 449 449 449 623 449 449 449 449 449 449 449 449 889 449 203 273 329 449 449 449 449 449 449 845 882 323 22 449 449 893 449 449 449 449 449 870 449 402",
"output": "NO"
},
{
"input": "90\n424 3 586 183 286 89 427 618 758 833 933 170 155 722 190 977 330 369 693 426 556 435 550 442 513 146 61 719 754 140 424 280 997 688 530 550 438 867 950 194 196 298 417 287 106 489 283 456 735 115 702 317 672 787 264 314 356 186 54 913 809 833 946 314 757 322 559 647 983 482 145 197 223 130 162 536 451 174 467 45 660 293 440 254 25 155 511 746 650 187",
"output": "YES"
},
{
"input": "14\n959 203 478 315 788 788 373 834 488 519 774 764 193 103",
"output": "YES"
},
{
"input": "81\n544 528 528 528 528 4 506 528 32 528 528 528 528 528 528 528 528 975 528 528 528 528 528 528 528 528 528 528 528 528 528 20 528 528 528 528 528 528 528 528 852 528 528 120 528 528 61 11 528 528 528 228 528 165 883 528 488 475 628 528 528 528 528 528 528 597 528 528 528 528 528 528 528 528 528 528 528 412 528 521 925",
"output": "NO"
},
{
"input": "89\n354 356 352 355 355 355 352 354 354 352 355 356 355 352 354 356 354 355 355 354 353 352 352 355 355 356 352 352 353 356 352 353 354 352 355 352 353 353 353 354 353 354 354 353 356 353 353 354 354 354 354 353 352 353 355 356 356 352 356 354 353 352 355 354 356 356 356 354 354 356 354 355 354 355 353 352 354 355 352 355 355 354 356 353 353 352 356 352 353",
"output": "YES"
},
{
"input": "71\n284 284 285 285 285 284 285 284 284 285 284 285 284 284 285 284 285 285 285 285 284 284 285 285 284 284 284 285 284 285 284 285 285 284 284 284 285 284 284 285 285 285 284 284 285 284 285 285 284 285 285 284 285 284 284 284 285 285 284 285 284 285 285 285 285 284 284 285 285 284 285",
"output": "NO"
},
{
"input": "28\n602 216 214 825 814 760 814 28 76 814 814 288 814 814 222 707 11 490 814 543 914 705 814 751 976 814 814 99",
"output": "YES"
},
{
"input": "48\n546 547 914 263 986 945 914 914 509 871 324 914 153 571 914 914 914 528 970 566 544 914 914 914 410 914 914 589 609 222 914 889 691 844 621 68 914 36 914 39 630 749 914 258 945 914 727 26",
"output": "YES"
},
{
"input": "56\n516 76 516 197 516 427 174 516 706 813 94 37 516 815 516 516 937 483 16 516 842 516 638 691 516 635 516 516 453 263 516 516 635 257 125 214 29 81 516 51 362 516 677 516 903 516 949 654 221 924 516 879 516 516 972 516",
"output": "YES"
},
{
"input": "46\n314 723 314 314 314 235 314 314 314 314 270 314 59 972 314 216 816 40 314 314 314 314 314 314 314 381 314 314 314 314 314 314 314 789 314 957 114 942 314 314 29 314 314 72 314 314",
"output": "NO"
},
{
"input": "72\n169 169 169 599 694 81 250 529 865 406 817 169 667 169 965 169 169 663 65 169 903 169 942 763 169 807 169 603 169 169 13 169 169 810 169 291 169 169 169 169 169 169 169 713 169 440 169 169 169 169 169 480 169 169 867 169 169 169 169 169 169 169 169 393 169 169 459 169 99 169 601 800",
"output": "NO"
},
{
"input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317 316 317 316 316 316 317 316 317 317 316 317 316 316 316 316 316 316 317 316 317 317 317 317 317 317 316 316 316 317 316 317 316 317 316 317 317 316 317 316 317 317 316 317 316 317 316 317 316 316 316 317 317 317 317 317 316 317 317 316 316 316 316 317 317 316 317 316 316 316 316 316 316 317 316 316 317 317 317 317 317 317 317 317 317 316 316 317",
"output": "NO"
},
{
"input": "100\n510 510 510 162 969 32 510 511 510 510 911 183 496 875 903 461 510 510 123 578 510 510 510 510 510 755 510 673 510 510 763 510 510 909 510 435 487 959 807 510 368 788 557 448 284 332 510 949 510 510 777 112 857 926 487 510 510 510 678 510 510 197 829 427 698 704 409 509 510 238 314 851 510 651 510 455 682 510 714 635 973 510 443 878 510 510 510 591 510 24 596 510 43 183 510 510 671 652 214 784",
"output": "YES"
},
{
"input": "100\n476 477 474 476 476 475 473 476 474 475 473 477 476 476 474 476 474 475 476 477 473 473 473 474 474 476 473 473 476 476 475 476 473 474 473 473 477 475 475 475 476 475 477 477 477 476 475 475 475 473 476 477 475 476 477 473 474 477 473 475 476 476 474 477 476 474 473 477 473 475 477 473 476 474 477 473 475 477 473 476 476 475 476 475 474 473 477 473 475 473 477 473 473 474 475 473 477 476 477 474",
"output": "YES"
},
{
"input": "100\n498 498 498 498 498 499 498 499 499 499 498 498 498 498 499 498 499 499 498 499 498 498 498 499 499 499 498 498 499 499 498 498 498 499 498 499 498 498 498 499 498 499 498 498 498 498 499 498 498 499 498 498 499 498 499 499 498 499 499 499 498 498 498 498 499 498 499 498 499 499 499 499 498 498 499 499 498 499 499 498 498 499 499 498 498 499 499 499 498 498 499 498 498 498 499 499 499 498 498 499",
"output": "NO"
},
{
"input": "100\n858 53 816 816 816 816 816 816 816 181 816 816 816 816 579 879 816 948 171 816 816 150 866 816 816 816 897 816 816 816 816 816 816 706 816 539 816 816 816 816 816 816 423 487 816 615 254 816 816 816 816 83 816 816 816 816 816 816 816 816 816 816 816 136 775 999 816 816 816 644 816 816 816 816 927 816 802 816 856 816 816 816 816 816 816 816 816 816 816 700 816 816 816 816 982 477 816 891 806 816",
"output": "NO"
},
{
"input": "100\n167 169 169 167 169 169 167 167 167 167 168 166 170 170 169 170 170 170 169 168 166 167 170 169 167 169 168 169 166 170 166 167 170 166 166 167 169 166 166 169 166 167 168 168 170 167 168 166 168 170 167 168 167 169 169 166 168 167 170 168 167 169 168 169 166 168 168 169 169 166 170 168 167 169 170 168 167 169 168 167 168 168 166 169 170 170 166 166 167 170 167 168 167 167 169 169 166 166 169 167",
"output": "YES"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "YES"
},
{
"input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "YES"
},
{
"input": "2\n1 1",
"output": "NO"
},
{
"input": "1\n1000",
"output": "YES"
},
{
"input": "12\n2 2 4 4 4 4 6 6 6 6 6 6",
"output": "YES"
}
] | 122 | 2,867,200 | -1 | 837 |
|
359 | Prime Number | [
"math",
"number theory"
] | null | null | Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number *t* equals *x**a*1<=+<=*a*2<=+<=...<=+<=*a**n*. Now Simon wants to reduce the resulting fraction.
Help him, find the greatest common divisor of numbers *s* and *t*. As GCD can be rather large, print it as a remainder after dividing it by number 1000000007 (109<=+<=7). | The first line contains two positive integers *n* and *x* (1<=β€<=*n*<=β€<=105, 2<=β€<=*x*<=β€<=109) β the size of the array and the prime number.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a*1<=β€<=*a*2<=β€<=...<=β€<=*a**n*<=β€<=109). | Print a single number β the answer to the problem modulo 1000000007 (109<=+<=7). | [
"2 2\n2 2\n",
"3 3\n1 2 3\n",
"2 2\n29 29\n",
"4 5\n0 0 0 0\n"
] | [
"8\n",
"27\n",
"73741817\n",
"1\n"
] | In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7745f7cc87c6c5f753e3414fad9baa3b1e3fea48.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 8.
In the second sample, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/acb3d7990f024100be499bcb59828fa6e23a867d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The answer to the problem is 27, as 351β=β13Β·27, 729β=β27Β·27.
In the third sample the answer to the problem is 1073741824Β *mod*Β 1000000007β=β73741817.
In the fourth sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/05a5fca3fb4690369838ff6dfeda521c959aa937.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 1. | [
{
"input": "2 2\n2 2",
"output": "8"
},
{
"input": "3 3\n1 2 3",
"output": "27"
},
{
"input": "2 2\n29 29",
"output": "73741817"
},
{
"input": "4 5\n0 0 0 0",
"output": "1"
},
{
"input": "1 2\n1000000000",
"output": "1"
},
{
"input": "26 2\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2",
"output": "8"
},
{
"input": "26 7\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2",
"output": "49"
},
{
"input": "3 2\n0 1 1",
"output": "4"
},
{
"input": "1 127\n1000000000",
"output": "1"
},
{
"input": "1 800000011\n800000011",
"output": "1"
},
{
"input": "1 800000011\n999999999",
"output": "1"
},
{
"input": "3 3\n1 1 1",
"output": "27"
}
] | 46 | 0 | 0 | 838 |
|
841 | Generous Kefa | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* β lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset β print Β«YESΒ», if he can, and Β«NOΒ», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. | The first line contains two integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=100) β the number of baloons and friends.
Next line contains string *s* β colors of baloons. | Answer to the task β Β«YESΒ» or Β«NOΒ» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is Β«NOΒ». | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv",
"output": "NO"
},
{
"input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "YES"
},
{
"input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod",
"output": "NO"
},
{
"input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl",
"output": "YES"
},
{
"input": "18 6\njzwtnkvmscqhmdlsxy",
"output": "YES"
},
{
"input": "21 2\nfscegcqgzesefghhwcexs",
"output": "NO"
},
{
"input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc",
"output": "YES"
},
{
"input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd",
"output": "YES"
},
{
"input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv",
"output": "YES"
},
{
"input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul",
"output": "YES"
},
{
"input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii",
"output": "NO"
},
{
"input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq",
"output": "YES"
},
{
"input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb",
"output": "YES"
},
{
"input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc",
"output": "YES"
},
{
"input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab",
"output": "YES"
},
{
"input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia",
"output": "NO"
},
{
"input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf",
"output": "YES"
},
{
"input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb",
"output": "YES"
},
{
"input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa",
"output": "NO"
},
{
"input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo",
"output": "YES"
},
{
"input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib",
"output": "YES"
},
{
"input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf",
"output": "YES"
},
{
"input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci",
"output": "YES"
},
{
"input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn",
"output": "YES"
},
{
"input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev",
"output": "YES"
},
{
"input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss",
"output": "YES"
},
{
"input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs",
"output": "NO"
},
{
"input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc",
"output": "NO"
},
{
"input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi",
"output": "NO"
},
{
"input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah",
"output": "NO"
},
{
"input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka",
"output": "YES"
},
{
"input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq",
"output": "YES"
},
{
"input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb",
"output": "YES"
},
{
"input": "14 5\nfssmmsfffmfmmm",
"output": "NO"
},
{
"input": "2 1\nff",
"output": "NO"
},
{
"input": "2 1\nhw",
"output": "YES"
},
{
"input": "2 2\nss",
"output": "YES"
},
{
"input": "1 1\nl",
"output": "YES"
},
{
"input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp",
"output": "YES"
},
{
"input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj",
"output": "YES"
},
{
"input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj",
"output": "YES"
},
{
"input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "YES"
},
{
"input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq",
"output": "YES"
},
{
"input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt",
"output": "YES"
},
{
"input": "1 2\na",
"output": "YES"
},
{
"input": "3 1\nabb",
"output": "NO"
},
{
"input": "2 1\naa",
"output": "NO"
},
{
"input": "2 1\nab",
"output": "YES"
},
{
"input": "6 2\naaaaaa",
"output": "NO"
},
{
"input": "8 4\naaaaaaaa",
"output": "NO"
},
{
"input": "4 2\naaaa",
"output": "NO"
},
{
"input": "4 3\naaaa",
"output": "NO"
},
{
"input": "1 3\na",
"output": "YES"
},
{
"input": "4 3\nzzzz",
"output": "NO"
},
{
"input": "4 1\naaaa",
"output": "NO"
},
{
"input": "3 4\nabc",
"output": "YES"
},
{
"input": "2 5\nab",
"output": "YES"
},
{
"input": "2 4\nab",
"output": "YES"
},
{
"input": "1 10\na",
"output": "YES"
},
{
"input": "5 2\nzzzzz",
"output": "NO"
},
{
"input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO"
},
{
"input": "4 1\nabab",
"output": "NO"
},
{
"input": "4 1\nabcb",
"output": "NO"
},
{
"input": "4 2\nabbb",
"output": "NO"
},
{
"input": "5 2\nabccc",
"output": "NO"
},
{
"input": "2 3\nab",
"output": "YES"
},
{
"input": "4 3\nbbbs",
"output": "YES"
},
{
"input": "10 2\nazzzzzzzzz",
"output": "NO"
},
{
"input": "1 2\nb",
"output": "YES"
},
{
"input": "1 3\nb",
"output": "YES"
},
{
"input": "4 5\nabcd",
"output": "YES"
},
{
"input": "4 6\naabb",
"output": "YES"
},
{
"input": "5 2\naaaab",
"output": "NO"
},
{
"input": "3 5\naaa",
"output": "YES"
},
{
"input": "5 3\nazzzz",
"output": "NO"
},
{
"input": "4 100\naabb",
"output": "YES"
},
{
"input": "3 10\naaa",
"output": "YES"
},
{
"input": "3 4\naaa",
"output": "YES"
},
{
"input": "12 5\naaaaabbbbbbb",
"output": "NO"
},
{
"input": "5 2\naabbb",
"output": "NO"
},
{
"input": "10 5\nzzzzzzzzzz",
"output": "NO"
},
{
"input": "2 4\naa",
"output": "YES"
},
{
"input": "1 5\na",
"output": "YES"
},
{
"input": "10 5\naaaaaaaaaa",
"output": "NO"
},
{
"input": "6 3\naaaaaa",
"output": "NO"
},
{
"input": "7 1\nabcdeee",
"output": "NO"
},
{
"input": "18 3\naaaaaabbbbbbcccccc",
"output": "NO"
},
{
"input": "8 2\naabbccdd",
"output": "YES"
},
{
"input": "4 2\nzzzz",
"output": "NO"
},
{
"input": "4 2\nabaa",
"output": "NO"
},
{
"input": "3 2\naaa",
"output": "NO"
},
{
"input": "3 1\nzzz",
"output": "NO"
},
{
"input": "5 4\nzzzzz",
"output": "NO"
},
{
"input": "6 2\naabbbc",
"output": "NO"
},
{
"input": "3 6\naaa",
"output": "YES"
},
{
"input": "2 1\nzz",
"output": "NO"
},
{
"input": "10 3\naaaeeeeeee",
"output": "NO"
},
{
"input": "4 5\naabb",
"output": "YES"
},
{
"input": "3 1\naaa",
"output": "NO"
},
{
"input": "5 2\naazzz",
"output": "NO"
},
{
"input": "6 2\nabbbbc",
"output": "NO"
},
{
"input": "4 2\nxxxx",
"output": "NO"
},
{
"input": "6 3\nzzzzzz",
"output": "NO"
},
{
"input": "3 2\nabb",
"output": "YES"
},
{
"input": "3 2\nzzz",
"output": "NO"
},
{
"input": "6 5\nzzzzzz",
"output": "NO"
},
{
"input": "6 3\nbcaaaa",
"output": "NO"
},
{
"input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "3 6\nabc",
"output": "YES"
}
] | 140 | 2,150,400 | 3 | 839 |
|
952 | A Map of the Cat | [
"brute force",
"interactive"
] | null | null | If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.
You have met a cat. Can you figure out whether it's normal or grumpy? | none | none | [] | [] | Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer. | [
{
"input": "5 0 1 2 5 3 5 4 5 5",
"output": "Correct answer 'normal'"
},
{
"input": "5 5 5 6 6 7 8 9 10 11",
"output": "Correct answer 'grumpy'"
},
{
"input": "10 6 5 7 5 6 11 5 8 9",
"output": "Correct answer 'grumpy'"
},
{
"input": "7 10 8 9 6 5 5 11 5 6",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 5 4 5 2 5 5 0 1 3",
"output": "Correct answer 'normal'"
},
{
"input": "0 4 3 5 5 5 2 1 5 5",
"output": "Correct answer 'normal'"
},
{
"input": "3 5 5 0 5 5 2 5 4 1",
"output": "Correct answer 'normal'"
},
{
"input": "5 4 5 1 5 5 0 5 2 3",
"output": "Correct answer 'normal'"
},
{
"input": "5 5 1 2 5 5 4 3 0 5",
"output": "Correct answer 'normal'"
},
{
"input": "7 10 5 5 11 6 5 9 6 8",
"output": "Correct answer 'grumpy'"
},
{
"input": "6 5 10 5 5 7 8 11 9 6",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 5 5 5 5 0 4 2 3 1",
"output": "Correct answer 'normal'"
},
{
"input": "11 5 6 5 9 5 10 8 7 6",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 9 8 10 7 11 5 6 5 6",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 8 10 11 5 6 5 6 7 9",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 5 6 11 6 10 9 5 8 7",
"output": "Correct answer 'grumpy'"
},
{
"input": "1 5 5 2 5 0 3 5 5 4",
"output": "Correct answer 'normal'"
},
{
"input": "5 5 2 5 4 5 3 1 0 5",
"output": "Correct answer 'normal'"
}
] | 93 | 0 | 0 | 841 |
|
746 | Compote | [
"implementation",
"math"
] | null | null | Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruitsΒ β lemons, apples and pearsΒ β should be put in the compote as whole fruits.
Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0. | The first line contains the positive integer *a* (1<=β€<=*a*<=β€<=1000)Β β the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=β€<=*b*<=β€<=1000)Β β the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=β€<=*c*<=β€<=1000)Β β the number of pears Nikolay has. | Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. | [
"2\n5\n7\n",
"4\n7\n13\n",
"2\n3\n2\n"
] | [
"7\n",
"21\n",
"0\n"
] | In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1β+β2β+β4β=β7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3β+β6β+β12β=β21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | [
{
"input": "2\n5\n7",
"output": "7"
},
{
"input": "4\n7\n13",
"output": "21"
},
{
"input": "2\n3\n2",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n4",
"output": "7"
},
{
"input": "1000\n1000\n1000",
"output": "1750"
},
{
"input": "1\n1\n4",
"output": "0"
},
{
"input": "1\n2\n3",
"output": "0"
},
{
"input": "1\n1000\n1000",
"output": "7"
},
{
"input": "1000\n1\n1000",
"output": "0"
},
{
"input": "1000\n2\n1000",
"output": "7"
},
{
"input": "1000\n500\n1000",
"output": "1750"
},
{
"input": "1000\n1000\n4",
"output": "7"
},
{
"input": "1000\n1000\n3",
"output": "0"
},
{
"input": "4\n8\n12",
"output": "21"
},
{
"input": "10\n20\n40",
"output": "70"
},
{
"input": "100\n200\n399",
"output": "693"
},
{
"input": "200\n400\n800",
"output": "1400"
},
{
"input": "199\n400\n800",
"output": "1393"
},
{
"input": "201\n400\n800",
"output": "1400"
},
{
"input": "200\n399\n800",
"output": "1393"
},
{
"input": "200\n401\n800",
"output": "1400"
},
{
"input": "200\n400\n799",
"output": "1393"
},
{
"input": "200\n400\n801",
"output": "1400"
},
{
"input": "139\n252\n871",
"output": "882"
},
{
"input": "109\n346\n811",
"output": "763"
},
{
"input": "237\n487\n517",
"output": "903"
},
{
"input": "161\n331\n725",
"output": "1127"
},
{
"input": "39\n471\n665",
"output": "273"
},
{
"input": "9\n270\n879",
"output": "63"
},
{
"input": "137\n422\n812",
"output": "959"
},
{
"input": "15\n313\n525",
"output": "105"
},
{
"input": "189\n407\n966",
"output": "1323"
},
{
"input": "18\n268\n538",
"output": "126"
},
{
"input": "146\n421\n978",
"output": "1022"
},
{
"input": "70\n311\n685",
"output": "490"
},
{
"input": "244\n405\n625",
"output": "1092"
},
{
"input": "168\n454\n832",
"output": "1176"
},
{
"input": "46\n344\n772",
"output": "322"
},
{
"input": "174\n438\n987",
"output": "1218"
},
{
"input": "144\n387\n693",
"output": "1008"
},
{
"input": "22\n481\n633",
"output": "154"
},
{
"input": "196\n280\n848",
"output": "980"
},
{
"input": "190\n454\n699",
"output": "1218"
},
{
"input": "231\n464\n928",
"output": "1617"
},
{
"input": "151\n308\n616",
"output": "1057"
},
{
"input": "88\n182\n364",
"output": "616"
},
{
"input": "12\n26\n52",
"output": "84"
},
{
"input": "204\n412\n824",
"output": "1428"
},
{
"input": "127\n256\n512",
"output": "889"
},
{
"input": "224\n446\n896",
"output": "1561"
},
{
"input": "146\n291\n584",
"output": "1015"
},
{
"input": "83\n164\n332",
"output": "574"
},
{
"input": "20\n38\n80",
"output": "133"
},
{
"input": "198\n393\n792",
"output": "1372"
},
{
"input": "120\n239\n480",
"output": "833"
},
{
"input": "208\n416\n831",
"output": "1449"
},
{
"input": "130\n260\n517",
"output": "903"
},
{
"input": "67\n134\n267",
"output": "462"
},
{
"input": "245\n490\n979",
"output": "1708"
},
{
"input": "182\n364\n727",
"output": "1267"
},
{
"input": "104\n208\n413",
"output": "721"
},
{
"input": "10\n2\n100",
"output": "7"
},
{
"input": "2\n100\n100",
"output": "14"
},
{
"input": "2\n3\n8",
"output": "7"
},
{
"input": "1\n2\n8",
"output": "7"
},
{
"input": "1\n2\n200",
"output": "7"
},
{
"input": "5\n4\n16",
"output": "14"
},
{
"input": "1\n10\n10",
"output": "7"
},
{
"input": "1\n4\n8",
"output": "7"
},
{
"input": "100\n4\n1000",
"output": "14"
},
{
"input": "2\n6\n12",
"output": "14"
},
{
"input": "10\n7\n4",
"output": "7"
},
{
"input": "2\n10\n100",
"output": "14"
},
{
"input": "2\n3\n4",
"output": "7"
},
{
"input": "1\n2\n999",
"output": "7"
},
{
"input": "1\n10\n20",
"output": "7"
},
{
"input": "100\n18\n20",
"output": "35"
},
{
"input": "100\n1\n100",
"output": "0"
},
{
"input": "3\n7\n80",
"output": "21"
},
{
"input": "2\n8\n24",
"output": "14"
},
{
"input": "1\n100\n100",
"output": "7"
},
{
"input": "2\n1\n8",
"output": "0"
},
{
"input": "10\n5\n23",
"output": "14"
}
] | 109 | 0 | 3 | 844 |
|
61 | Capture Valerian | [
"math"
] | C. Capture Valerian | 2 | 256 | It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.
Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captured by Shapur and Shapur is now going to capture Valerian, the Roman emperor.
Being defeated, the cowardly Valerian hid in a room at the top of one of his castles. To capture him, Shapur has to open many doors. Fortunately Valerian was too scared to make impenetrable locks for the doors.
Each door has 4 parts. The first part is an integer number *a*. The second part is either an integer number *b* or some really odd sign which looks like R. The third one is an integer *c* and the fourth part is empty! As if it was laid for writing something. Being extremely gifted, after opening the first few doors, Shapur found out the secret behind the locks.
*c* is an integer written in base *a*, to open the door we should write it in base *b*. The only bad news is that this R is some sort of special numbering system that is used only in Roman empire, so opening the doors is not just a piece of cake!
Here's an explanation of this really weird number system that even doesn't have zero:
Roman numerals are based on seven symbols: a stroke (identified with the letter I) for a unit, a chevron (identified with the letter V) for a five, a cross-stroke (identified with the letter X) for a ten, a C (identified as an abbreviation of Centum) for a hundred, etc.:
- I=1- V=5- X=10- L=50- C=100- D=500- M=1000
Symbols are iterated to produce multiples of the decimal (1, 10, 100, 1,<=000) values, with V, L, D substituted for a multiple of five, and the iteration continuing: I 1, II 2, III 3, V 5, VI 6, VII 7, etc., and the same for other bases: X 10, XX 20, XXX 30, L 50, LXXX 80; CC 200, DCC 700, etc. At the fourth and ninth iteration, a subtractive principle must be employed, with the base placed before the higher base: IV 4, IX 9, XL 40, XC 90, CD 400, CM 900.
Also in bases greater than 10 we use A for 10, B for 11, etc.
Help Shapur capture Valerian and bring peace back to Persia, especially Armenia. | The first line contains two integers *a* and *b* (2<=β€<=*a*,<=*b*<=β€<=25). Only *b* may be replaced by an R which indicates Roman numbering system.
The next line contains a single non-negative integer *c* in base *a* which may contain leading zeros but its length doesn't exceed 103.
It is guaranteed that if we have Roman numerals included the number would be less than or equal to 300010 and it won't be 0. In any other case the number won't be greater than 101510. | Write a single line that contains integer *c* in base *b*. You must omit leading zeros. | [
"10 2\n1\n",
"16 R\n5\n",
"5 R\n4\n",
"2 2\n1111001\n",
"12 13\nA\n"
] | [
"1\n",
"V\n",
"IV\n",
"1111001\n",
"A\n"
] | You can find more information about roman numerals here: http://en.wikipedia.org/wiki/Roman_numerals | [
{
"input": "10 2\n1",
"output": "1"
},
{
"input": "16 R\n5",
"output": "V"
},
{
"input": "5 R\n4",
"output": "IV"
},
{
"input": "2 2\n1111001",
"output": "1111001"
},
{
"input": "12 13\nA",
"output": "A"
},
{
"input": "6 7\n12345",
"output": "5303"
},
{
"input": "25 12\nABG",
"output": "3951"
},
{
"input": "17 10\nABACG",
"output": "892363"
},
{
"input": "18 R\nGH",
"output": "CCCV"
},
{
"input": "20 25\n4E32BB21D812",
"output": "A2II7CL2HDM"
},
{
"input": "15 11\n760595A635B24",
"output": "258AA2604713696"
},
{
"input": "10 22\n956512026633000",
"output": "1E06A57IC4H2"
},
{
"input": "5 9\n1102101401441324123301",
"output": "2733824152181178"
},
{
"input": "23 4\nDL5K6H78CAH",
"output": "2003021332111213003322000"
},
{
"input": "18 R\n36E",
"output": "MXCIV"
},
{
"input": "13 2\n1B579528314B30",
"output": "10000001011010101001110000001110001011010111010010"
},
{
"input": "8 13\n20043013541570572",
"output": "1B35CBA6B32102"
},
{
"input": "19 24\n1BH47I158EII",
"output": "2NHBDL4ECN2"
},
{
"input": "14 19\n33BC51B817C55",
"output": "1B573FFHHH12"
},
{
"input": "24 10\nE2E3EA6MJ05",
"output": "894488519782085"
},
{
"input": "25 2\nIBGNAB3C0H",
"output": "10000000001001000010100000111011000110101000001"
},
{
"input": "3 R\n2",
"output": "II"
},
{
"input": "20 20\n3HBAH9JA9EDE",
"output": "3HBAH9JA9EDE"
},
{
"input": "21 21\n2G3DK3F23905",
"output": "2G3DK3F23905"
},
{
"input": "23 R\n57F",
"output": "MMDCCCXXI"
},
{
"input": "16 6\n27774848D1D9F",
"output": "10500345245142230115"
},
{
"input": "18 7\nD9D42E745C5A",
"output": "351206225505021115"
},
{
"input": "11 R\n1A8A",
"output": "MMDCXXXIX"
},
{
"input": "12 17\n567872838B15A5",
"output": "105CA323BC110"
},
{
"input": "12 19\n78613621478844",
"output": "71A1E1HB01EB"
},
{
"input": "12 25\n51B878A1B3A7B8",
"output": "5JLBAF5JBEA"
},
{
"input": "12 R\n17BB",
"output": "MMDCCCLXXIX"
},
{
"input": "20 R\nFI",
"output": "CCCXVIII"
},
{
"input": "20 5\n1FAD98HHG13G",
"output": "340143030243121422401"
},
{
"input": "19 12\nEHIAG4GG072",
"output": "A33B813901970"
},
{
"input": "3 R\n2201120",
"output": "MCMLXXXVI"
},
{
"input": "3 R\n10210211",
"output": "MMDCCLXXVI"
},
{
"input": "3 R\n21222",
"output": "CCXV"
},
{
"input": "11 22\n172A57412774400",
"output": "11G8KLBCI95B"
},
{
"input": "17 4\n1509D9E003C5C",
"output": "2223230302121200303102203"
},
{
"input": "2 R\n101110110111",
"output": "MMCMXCIX"
},
{
"input": "25 R\n2JA",
"output": "MDCCXXXV"
},
{
"input": "23 R\n3HK",
"output": "MCMXCVIII"
},
{
"input": "10 22\n1000000000000000",
"output": "1FE6KH3A0F7A"
},
{
"input": "10 2\n999999999999993",
"output": "11100011010111111010100100110001100111111111111001"
},
{
"input": "4 21\n112233030100132210003330",
"output": "5KIIKBEFE1G"
},
{
"input": "4 10\n112233030100132210003330",
"output": "100000000000252"
},
{
"input": "4 5\n112233030100132210003330",
"output": "101101400000000002002"
},
{
"input": "2 R\n1",
"output": "I"
},
{
"input": "13 15\n33BCA79805767B",
"output": "7A924652EB469"
},
{
"input": "2 10\n0",
"output": "0"
},
{
"input": "25 2\n0",
"output": "0"
},
{
"input": "25 10\n001",
"output": "1"
},
{
"input": "17 17\n00000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "0"
},
{
"input": "10 R\n999",
"output": "CMXCIX"
},
{
"input": "2 2\n0",
"output": "0"
},
{
"input": "10 10\n100000000000",
"output": "100000000000"
},
{
"input": "10 10\n0",
"output": "0"
},
{
"input": "10 R\n900",
"output": "CM"
},
{
"input": "10 11\n12345678912345",
"output": "3A2A855993029"
},
{
"input": "10 2\n100000000000000",
"output": "10110101111001100010000011110100100000000000000"
},
{
"input": "10 R\n1983",
"output": "MCMLXXXIII"
},
{
"input": "2 R\n101110111000",
"output": "MMM"
},
{
"input": "2 R\n101110111000",
"output": "MMM"
},
{
"input": "10 11\n1000000000000000",
"output": "26A6A368906563A"
},
{
"input": "10 R\n1137",
"output": "MCXXXVII"
},
{
"input": "10 R\n100",
"output": "C"
},
{
"input": "10 25\n12343456543435",
"output": "35M8JNIJCA"
},
{
"input": "16 10\n0523456789ABC",
"output": "90384742521532"
}
] | 124 | 307,200 | 3.968428 | 846 |
862 | Mahmoud and Ehab and the xor | [
"constructive algorithms"
] | null | null | Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.
Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to find a set of *n* distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly *x*. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106. | The only line contains two integers *n* and *x* (1<=β€<=*n*<=β€<=105, 0<=β€<=*x*<=β€<=105)Β β the number of elements in the set and the desired bitwise-xor, respectively. | If there is no such set, print "NO" (without quotes).
Otherwise, on the first line print "YES" (without quotes) and on the second line print *n* distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. | [
"5 5\n",
"3 6\n"
] | [
"YES\n1 2 4 5 7",
"YES\n1 2 5"
] | You can read more about the bitwise-xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
For the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb8ccd05d3a7a41eff93c98f79d158cf85e702f9.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
For the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d05d19f05b03f8ac89b7f86ef830eeccc0050c42.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | [
{
"input": "5 5",
"output": "YES\n1 2 131072 131078 0 "
},
{
"input": "3 6",
"output": "YES\n131072 131078 0 "
},
{
"input": "3 0",
"output": "YES\n393216 131072 262144"
},
{
"input": "1 0",
"output": "YES\n0"
},
{
"input": "3 3",
"output": "YES\n131072 131075 0 "
},
{
"input": "100000 41243",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 100000",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "32 32",
"output": "YES\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 131072 131105 0 "
},
{
"input": "32 31",
"output": "YES\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 131072 131102 0 "
},
{
"input": "1 1",
"output": "YES\n1"
},
{
"input": "2 0",
"output": "NO"
},
{
"input": "3 1",
"output": "YES\n131072 131073 0 "
},
{
"input": "3 2",
"output": "YES\n131072 131074 0 "
},
{
"input": "3 5",
"output": "YES\n131072 131077 0 "
},
{
"input": "3 4",
"output": "YES\n131072 131076 0 "
},
{
"input": "3 10203",
"output": "YES\n131072 141275 0 "
},
{
"input": "3 10100",
"output": "YES\n131072 141172 0 "
},
{
"input": "5 0",
"output": "YES\n1 2 131072 131075 0 "
},
{
"input": "5 1",
"output": "YES\n1 2 131072 131074 0 "
},
{
"input": "5 2",
"output": "YES\n1 2 131072 131073 0 "
},
{
"input": "5 3",
"output": "YES\n1 2 393216 131072 262144"
},
{
"input": "5 4",
"output": "YES\n1 2 131072 131079 0 "
},
{
"input": "5 6",
"output": "YES\n1 2 131072 131077 0 "
},
{
"input": "5 7",
"output": "YES\n1 2 131072 131076 0 "
},
{
"input": "5 8",
"output": "YES\n1 2 131072 131083 0 "
},
{
"input": "5 9",
"output": "YES\n1 2 131072 131082 0 "
},
{
"input": "100000 1",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 0",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 21323",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 65536",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 65537",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 65535",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "4 2",
"output": "YES\n1 131072 131075 0 "
},
{
"input": "10 2",
"output": "YES\n1 2 3 4 5 6 7 131072 131074 0 "
},
{
"input": "1 2",
"output": "YES\n2"
},
{
"input": "1 3",
"output": "YES\n3"
},
{
"input": "2 1",
"output": "YES\n0 1"
},
{
"input": "2 2",
"output": "YES\n0 2"
},
{
"input": "2 3",
"output": "YES\n0 3"
},
{
"input": "4 0",
"output": "YES\n1 131072 131073 0 "
},
{
"input": "4 1",
"output": "YES\n1 393216 131072 262144"
},
{
"input": "4 3",
"output": "YES\n1 131072 131074 0 "
},
{
"input": "6 0",
"output": "YES\n1 2 3 393216 131072 262144"
},
{
"input": "7 1",
"output": "YES\n1 2 3 4 131072 131077 0 "
}
] | 46 | 0 | 0 | 848 |
|
31 | Sysadmin Bob | [
"greedy",
"implementation",
"strings"
] | B. Sysadmin Bob | 0 | 256 | Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in Β«BersoftΒ» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once.
Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. | The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters Β«@Β». | If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. | [
"a@aa@a\n",
"a@a@a\n",
"@aa@a\n"
] | [
"a@a,a@a\n",
"No solution\n",
"No solution\n"
] | none | [
{
"input": "a@aa@a",
"output": "a@a,a@a"
},
{
"input": "a@a@a",
"output": "No solution"
},
{
"input": "@aa@a",
"output": "No solution"
},
{
"input": "aba@caba@daba",
"output": "aba@c,aba@daba"
},
{
"input": "asd@qwasd@qwasd@qwasd@qwasd@qw",
"output": "asd@q,wasd@q,wasd@q,wasd@q,wasd@qw"
},
{
"input": "qwer@ty",
"output": "qwer@ty"
},
{
"input": "@",
"output": "No solution"
},
{
"input": "g",
"output": "No solution"
},
{
"input": "@@",
"output": "No solution"
},
{
"input": "@@@",
"output": "No solution"
},
{
"input": "r@@",
"output": "No solution"
},
{
"input": "@@r",
"output": "No solution"
},
{
"input": "@r@",
"output": "No solution"
},
{
"input": "w@",
"output": "No solution"
},
{
"input": "@e",
"output": "No solution"
},
{
"input": "jj",
"output": "No solution"
},
{
"input": "@gh",
"output": "No solution"
},
{
"input": "n@m",
"output": "n@m"
},
{
"input": "kl@",
"output": "No solution"
},
{
"input": "fpm",
"output": "No solution"
},
{
"input": "@@@@",
"output": "No solution"
},
{
"input": "q@@@",
"output": "No solution"
},
{
"input": "@d@@",
"output": "No solution"
},
{
"input": "@@v@",
"output": "No solution"
},
{
"input": "@@@c",
"output": "No solution"
},
{
"input": "@@zx",
"output": "No solution"
},
{
"input": "@x@a",
"output": "No solution"
},
{
"input": "@pq@",
"output": "No solution"
},
{
"input": "w@@e",
"output": "No solution"
},
{
"input": "e@s@",
"output": "No solution"
},
{
"input": "ec@@",
"output": "No solution"
},
{
"input": "@hjk",
"output": "No solution"
},
{
"input": "e@vb",
"output": "e@vb"
},
{
"input": "tg@q",
"output": "tg@q"
},
{
"input": "jkl@",
"output": "No solution"
},
{
"input": "werb",
"output": "No solution"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "No solution"
},
{
"input": "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
"output": "No solution"
},
{
"input": "duk@rufrxjzqbwkfrzf@sjp@mdpyrokdfmcmexxtjqaalruvtzwfsqabi@tjkxilrhkwzfeuqm@lpwnxgebirdvwplsvrtxvhmzv",
"output": "duk@r,ufrxjzqbwkfrzf@s,jp@m,dpyrokdfmcmexxtjqaalruvtzwfsqabi@t,jkxilrhkwzfeuqm@lpwnxgebirdvwplsvrtxvhmzv"
},
{
"input": "umegsn@qlmkpkyrmuclefdpfhzuhyjcoqthnvpwzhkwrdvlzfbrqpzlg@ebzycyaofyyetwcepe@nxjwyeaqbuxxbohfzrnmebuy",
"output": "umegsn@q,lmkpkyrmuclefdpfhzuhyjcoqthnvpwzhkwrdvlzfbrqpzlg@e,bzycyaofyyetwcepe@nxjwyeaqbuxxbohfzrnmebuy"
},
{
"input": "l@snuoytgflrtuexpx@txzhhdwbakfhfro@syxistypegfvdmurvuubrj@grsznzhcotagqueuxtnjgfaywzkbglwwiptjyocxcs",
"output": "l@s,nuoytgflrtuexpx@t,xzhhdwbakfhfro@s,yxistypegfvdmurvuubrj@grsznzhcotagqueuxtnjgfaywzkbglwwiptjyocxcs"
},
{
"input": "crvjlke@yqsdofatzuuspt@@uumdkiwhtg@crxiabnujfmcquylyklxaedniwnq@@f@@rfnsjtylurexmdaaykvxmgeij@jkjsyi",
"output": "No solution"
},
{
"input": "ukpcivvjubgalr@bdxangokpaxzxuxe@qlemwpvywfudffafsqlmmhhalaaolktmgmhmrwvkdcvwxcfbytnz@jgmbhpwqcmecnxc",
"output": "ukpcivvjubgalr@b,dxangokpaxzxuxe@q,lemwpvywfudffafsqlmmhhalaaolktmgmhmrwvkdcvwxcfbytnz@jgmbhpwqcmecnxc"
},
{
"input": "mehxghlvnnazggvpnjdbchdolqguiurrfghwxpwhphdbhloltwnnqovsnsdmfevlikmrlvwvkcqysefvoraorhamchghqaooxaxz",
"output": "No solution"
},
{
"input": "whazbewtogyre@wqlsswhygx@osevwzytuaukqpp@gfjbtwnhpnlxwci@ovaaat@ookd@@o@bss@wyrrwzysubw@utyltkk@hlkx",
"output": "No solution"
},
{
"input": "vpulcessdotvylvmkeonzbpncjxaaigotkyvngsbkicomikyavpsjcphlznjtdmvbqiroxvfcmcczfmqbyedujvrupzlaswbzanv",
"output": "No solution"
},
{
"input": "mhxapzklriiincpnysmegjzaxdngifbowkzivvgisqbekprdmdoqezdsrsrwwmht@hwywjqflvqdevpqisncwbftlttfkgsyetop",
"output": "mhxapzklriiincpnysmegjzaxdngifbowkzivvgisqbekprdmdoqezdsrsrwwmht@hwywjqflvqdevpqisncwbftlttfkgsyetop"
},
{
"input": "dxzqftcghawwcwh@iepanbiclstbsxbrsoep@@jwhrptgiu@zfykoravtaykvkzseqfnlsbvjnsgiajgjtgucvewlpxmqwvkghlo",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtgh@",
"output": "No solution"
},
{
"input": "@rierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "e@ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "e@ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtg@d",
"output": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtg@d"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjt@h@",
"output": "No solution"
},
{
"input": "@r@erjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "e@i@rjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierj@g@d",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtg@@",
"output": "No solution"
},
{
"input": "@@ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "e@@erjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjt@@d",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierj@@dderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "a@rierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderirjtghderierjtghderierjtghderierjthderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtgh@a",
"output": "a@r,ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderirjtghderierjtghderierjtghderierjthderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtgh@a"
},
{
"input": "d@nt@om@zz@ut@tr@ta@ap@ou@sy@sv@fg@el@rp@qr@nl@j",
"output": "d@n,t@o,m@z,z@u,t@t,r@t,a@a,p@o,u@s,y@s,v@f,g@e,l@r,p@q,r@n,l@j"
},
{
"input": "a@mc@ks@gu@rl@gq@zq@iz@da@uq@mi@nf@zs@hi@we@ej@ke@vb@az@yz@yl@rr@gh@um@nv@qe@qq@de@dy@op@gt@vx@ak@q",
"output": "a@m,c@k,s@g,u@r,l@g,q@z,q@i,z@d,a@u,q@m,i@n,f@z,s@h,i@w,e@e,j@k,e@v,b@a,z@y,z@y,l@r,r@g,h@u,m@n,v@q,e@q,q@d,e@d,y@o,p@g,t@v,x@a,k@q"
},
{
"input": "c@ir@xf@ap@fk@sp@wm@ec@qw@vg@by@iu@tr@wu@pv@lj@dd@tc@qj@ok@hm@bs@ul@ez@cg@ht@xf@ag@tr@hz@ap@tx@ly@dg@hu@nd@uv@il@ii@cn@nc@nb@cy@kp@dk@xa@da@ta@yr@yv@qg@db@je@wz@rn@yh@xi@mj@kc@uj@yu@cf@ps@ao@fo@le@d",
"output": "c@i,r@x,f@a,p@f,k@s,p@w,m@e,c@q,w@v,g@b,y@i,u@t,r@w,u@p,v@l,j@d,d@t,c@q,j@o,k@h,m@b,s@u,l@e,z@c,g@h,t@x,f@a,g@t,r@h,z@a,p@t,x@l,y@d,g@h,u@n,d@u,v@i,l@i,i@c,n@n,c@n,b@c,y@k,p@d,k@x,a@d,a@t,a@y,r@y,v@q,g@d,b@j,e@w,z@r,n@y,h@x,i@m,j@k,c@u,j@y,u@c,f@p,s@a,o@f,o@l,e@d"
},
{
"input": "m@us@ru@mg@rq@ed@ot@gt@fo@gs@lm@cx@au@rq@zt@zk@jr@xd@oa@py@kf@lk@zr@ko@lj@wv@fl@yl@gk@cx@px@kl@ic@sr@xn@hm@xs@km@tk@ui@ya@pa@xx@ze@py@ir@xj@cr@dq@lr@cm@zu@lt@bx@kq@kx@fr@lu@vb@rz@hg@iw@dl@pf@pl@wv@z",
"output": "m@u,s@r,u@m,g@r,q@e,d@o,t@g,t@f,o@g,s@l,m@c,x@a,u@r,q@z,t@z,k@j,r@x,d@o,a@p,y@k,f@l,k@z,r@k,o@l,j@w,v@f,l@y,l@g,k@c,x@p,x@k,l@i,c@s,r@x,n@h,m@x,s@k,m@t,k@u,i@y,a@p,a@x,x@z,e@p,y@i,r@x,j@c,r@d,q@l,r@c,m@z,u@l,t@b,x@k,q@k,x@f,r@l,u@v,b@r,z@h,g@i,w@d,l@p,f@p,l@w,v@z"
},
{
"input": "gjkjqjrks@eyqiia@qfijelnmigoditxjrtuhukalfl@nmwancimlqtfekzkxgjioedhtdivqajwbmu@hpdxuiwurpgenxaiqaqkcqimcvitljuisfiojlylveie@neqdjzeqdbiatjpuhujgykl@gmmlrhnlghsoeyrccygigtkjrjxdwmnkouaiaqpquluwcdqlxqb",
"output": "gjkjqjrks@e,yqiia@q,fijelnmigoditxjrtuhukalfl@n,mwancimlqtfekzkxgjioedhtdivqajwbmu@h,pdxuiwurpgenxaiqaqkcqimcvitljuisfiojlylveie@n,eqdjzeqdbiatjpuhujgykl@gmmlrhnlghsoeyrccygigtkjrjxdwmnkouaiaqpquluwcdqlxqb"
},
{
"input": "uakh@chpowdmvdywosakyyknpriverjjgklmdrgwufpawgvhabjbnemimjktgbkx@fzvqcodbceqnihl@kpsslhwwndad@@yavjafrwkqyt@urhnwgnqamn@xkc@vngzlssmtheuxkpzjlbbjq@mwiojmvpilm@hlrmxheszskhxritsieubjjazrngxlqeedfkiuwny",
"output": "No solution"
},
{
"input": "usmjophufnkamnvowbauu@wfoyceknkgeaejlbbqhtucbl@wurukjezj@irhdgrfhyfkz@fbmqgxvtxcebztirvwjf@fnav@@f@paookujny@z@fmcxgvab@@kpqbwuxxwxhsrbivlbunmdjzk@afjznrjjtkq@cafetoinfleecjqvlzpkqlspoufwmidvoblti@jbg",
"output": "No solution"
},
{
"input": "axkxcgcmlxq@v@ynnjximcujikloyls@lqvxiyca@feimaioavacmquasneqbrqftknpbrzpahtcc@ijwqmyzsuidqkm@dffuiitpugbvty@izbnqxhdjasihhlt@gjrol@vy@vnqpxuqbofzzwl@toywomxopbuttczszx@fuowtjmtqy@gypx@la@@tweln@jgyktb",
"output": "No solution"
},
{
"input": "mplxc@crww@gllecngcsbmxmksrgcb@lbrcnkwxclkcgvfeqeoymproppxhxbgm@q@bfxxvuymnnjolqklabcinwpdlxj@jcevvilhmpyiwggvlmdanfhhlgbkobnmei@bvqtdq@osijfdsuouvcqpcjxjqiuhgts@xapp@cpqvlhlfrxtgunbbjwhuafovbcbqyhmlu",
"output": "No solution"
},
{
"input": "aglvesxsmivijisod@mxcnbfcfgqfwjouidlsueaswf@obehqpvbkmukxkicyoknkbol@kutunggpoxxfpbe@qkhv@llddqqoyjeex@byvtlhbifqmvlukmrvgvpwrscwfhpuwyknwchqhrdqgarmnsdlqgf@lseltghg@bhuwbfjpsvayzk@fvwow@zapklumefauly",
"output": "aglvesxsmivijisod@m,xcnbfcfgqfwjouidlsueaswf@o,behqpvbkmukxkicyoknkbol@k,utunggpoxxfpbe@q,khv@l,lddqqoyjeex@b,yvtlhbifqmvlukmrvgvpwrscwfhpuwyknwchqhrdqgarmnsdlqgf@l,seltghg@b,huwbfjpsvayzk@f,vwow@zapklumefauly"
},
{
"input": "gbllovyerhudm@aluhtnstcp@uwgvejnmqpt@nez@ltzqjrcgwkkpzicb@ihh@wldhvjbrl@efbdzbeg@zyovsta@n@c@jutail@nclsbcihabzr@snowxeyl@jewen@aduffvhr@ifufzzt@i@kptygveumwaknmrn@edsapqpcwsqypmutggztum@ewzakeamobzxt",
"output": "No solution"
},
{
"input": "dokshhqwmtbefrynupvusfxroggoqkjqfyabzkbccjmavumncorbcoairybeknhnpnwftrlbopsvqlgjbrowmfmoeebqseneabvgbcxmujmcqomoawrooixmqmyspfgafudfdfyrnujhgnbtsehgsnvdztjdpnskyquwdtkbfjtvrfjcqzmourvqsnfgjfqjgndydpch",
"output": "No solution"
},
{
"input": "jrlhtwmotdhtgcqokodparuqypwlkbhfsxvmdpfiraokekrolwtlsqjzcuvjfnvblznyngasauzln@gjypvjcwljnotgjlxketfgtntbotwjehea@vppouyoujujlhjrxbhvltfdslaqwynwjefbdbnuehmipqmtsrivlnippgftgnkhdgqiqbfvgrtoxrznncncqcvf",
"output": "jrlhtwmotdhtgcqokodparuqypwlkbhfsxvmdpfiraokekrolwtlsqjzcuvjfnvblznyngasauzln@g,jypvjcwljnotgjlxketfgtntbotwjehea@vppouyoujujlhjrxbhvltfdslaqwynwjefbdbnuehmipqmtsrivlnippgftgnkhdgqiqbfvgrtoxrznncncqcvf"
},
{
"input": "oxkvgnggznlfhminxkkhictpiaokdsfrewnxiujpjpstlyxovfwugrsqnpooalknjnfugxojozizlicwvnbflhdevpvnvwztnfiapairpigexbaeshondqdecduewmfrxunphikvlfwmrpsxrhxyjlsgqfiaqnwzlzxcyuudhzr@twllmhyfclybxqazhrmxdtokxawc",
"output": "oxkvgnggznlfhminxkkhictpiaokdsfrewnxiujpjpstlyxovfwugrsqnpooalknjnfugxojozizlicwvnbflhdevpvnvwztnfiapairpigexbaeshondqdecduewmfrxunphikvlfwmrpsxrhxyjlsgqfiaqnwzlzxcyuudhzr@twllmhyfclybxqazhrmxdtokxawc"
}
] | 31 | 6,963,200 | 0 | 849 |
918 | Eleven | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. | The first and only line of input contains an integer *n* (1<=β€<=*n*<=β€<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo"
},
{
"input": "805",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1000",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1",
"output": "O"
},
{
"input": "2",
"output": "OO"
},
{
"input": "3",
"output": "OOO"
},
{
"input": "5",
"output": "OOOoO"
},
{
"input": "17",
"output": "OOOoOooOooooOoooo"
},
{
"input": "49",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo"
},
{
"input": "256",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo"
},
{
"input": "512",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "933",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "61",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo"
},
{
"input": "781",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "999",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
}
] | 109 | 0 | 3 | 850 |
|
830 | Office Keys | [
"binary search",
"brute force",
"dp",
"greedy",
"sortings"
] | null | null | There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all *n* people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it. | The first line contains three integers *n*, *k* and *p* (1<=β€<=*n*<=β€<=1<=000, *n*<=β€<=*k*<=β€<=2<=000, 1<=β€<=*p*<=β€<=109) β the number of people, the number of keys and the office location.
The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains *k* distinct integers *b*1,<=*b*2,<=...,<=*b**k* (1<=β€<=*b**j*<=β€<=109) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point. | Print the minimum time (in seconds) needed for all *n* to reach the office with keys. | [
"2 4 50\n20 100\n60 10 40 80\n",
"1 2 10\n11\n15 7\n"
] | [
"50\n",
"7\n"
] | In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | [
{
"input": "2 4 50\n20 100\n60 10 40 80",
"output": "50"
},
{
"input": "1 2 10\n11\n15 7",
"output": "7"
},
{
"input": "2 5 15\n10 4\n29 23 21 22 26",
"output": "23"
},
{
"input": "3 10 1500\n106 160 129\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163",
"output": "1394"
},
{
"input": "5 20 1\n314 316 328 323 321\n30 61 11 83 19 63 97 87 14 79 43 57 75 48 47 95 41 27 8 88",
"output": "327"
},
{
"input": "20 20 1000000000\n911196469 574676950 884047241 984218701 641693148 352743122 616364857 455260052 702604347 921615943 671695009 544819698 768892858 254148055 379968391 65297129 178692403 575557323 307174510 63022600\n1621 106 6866 6420 9307 6985 2741 9477 9837 5909 6757 3085 6139 1876 3726 9334 4321 1531 8534 560",
"output": "1984199027"
},
{
"input": "40 45 1000\n6 55 34 32 20 76 2 84 47 68 31 60 14 70 99 72 21 61 81 79 26 51 96 86 10 1 43 69 87 78 13 11 80 67 50 52 9 29 94 12\n1974 1232 234 28 1456 626 408 1086 1525 1209 1096 940 795 1867 548 1774 1993 1199 1112 1087 1923 1156 876 1715 1815 1027 1658 955 398 910 620 1164 749 996 113 109 500 328 800 826 766 518 1474 1038 1029",
"output": "2449"
},
{
"input": "50 55 2000\n9518 9743 9338 9956 9827 9772 9094 9644 9242 9292 9148 9205 9907 9860 9530 9814 9662 9482 9725 9227 9105 9424 9268 9427 9470 9578 9808 9976 9143 9070 9079 9896 9367 9235 9925 9009 9619 9012 9669 9077 9870 9766 9479 9598 9055 9988 9792 9197 9377 9610\n828 656 345 412 69 506 274 994 384 766 587 126 720 227 66 839 997 602 646 955 256 262 243 676 459 83 507 88 559 595 71 154 867 276 487 895 857 888 368 179 813 407 973 780 588 112 815 290 554 230 768 804 974 3 745",
"output": "10833"
},
{
"input": "1 1 1\n1\n1000000000",
"output": "1999999998"
},
{
"input": "1 1 1\n1000000000\n1",
"output": "999999999"
},
{
"input": "1 1 1000000000\n1000000000\n1",
"output": "1999999998"
},
{
"input": "1 1 1000000000\n1\n1000000000",
"output": "999999999"
},
{
"input": "2 2 4\n3 4\n5 6",
"output": "4"
},
{
"input": "2 2 5\n1 2\n3 1000000000",
"output": "1999999993"
},
{
"input": "1 1 1000000000\n1000000000\n1",
"output": "1999999998"
},
{
"input": "2 2 1\n2 3\n4 100",
"output": "196"
},
{
"input": "2 2 10\n3 12\n1 9",
"output": "11"
},
{
"input": "3 3 1\n1 2 3\n999 1000000000 1",
"output": "1999999996"
},
{
"input": "1 1 1\n1\n1",
"output": "0"
},
{
"input": "1 1 1\n1\n1000000000",
"output": "1999999998"
},
{
"input": "1 1 1000000000\n1000000000\n10",
"output": "1999999980"
},
{
"input": "2 2 7122\n123 456\n1 4444",
"output": "7243"
},
{
"input": "1 1 10\n5\n15",
"output": "15"
},
{
"input": "2 4 1000\n1000 999\n1 1000 2 999",
"output": "1"
},
{
"input": "2 2 1000\n10 1010\n1 1001",
"output": "1008"
},
{
"input": "1 1 1\n2\n1000000000",
"output": "1999999997"
},
{
"input": "2 2 3\n1 5\n5 1",
"output": "2"
},
{
"input": "2 2 5\n2 3\n4 6",
"output": "4"
},
{
"input": "2 2 10\n5 6\n4 6",
"output": "7"
},
{
"input": "3 4 10\n5 7 9\n6 8 14 4",
"output": "7"
},
{
"input": "1 1 10\n10\n10",
"output": "0"
},
{
"input": "1 1 50\n1\n1000000000",
"output": "1999999949"
},
{
"input": "1 1 42\n666\n1337",
"output": "1966"
},
{
"input": "2 2 10\n9 11\n11 8",
"output": "3"
},
{
"input": "3 10 5\n1 2 3\n10000 9999 9998 9997 9996 9995 9994 7 6 5",
"output": "6"
},
{
"input": "1 1 2\n1\n1000000000",
"output": "1999999997"
},
{
"input": "2 2 100\n99 150\n1 150",
"output": "197"
},
{
"input": "3 3 4\n1 101 102\n2 3 100",
"output": "99"
}
] | 62 | 0 | 0 | 851 |
|
8 | Obsession with Robots | [
"constructive algorithms",
"graphs",
"implementation"
] | B. Obsession with Robots | 2 | 64 | The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug β the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.
The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.
In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. | The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. | In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). | [
"LLUUUR\n",
"RRUULLDD\n"
] | [
"OK\n",
"BUG\n"
] | none | [
{
"input": "LLUUUR",
"output": "OK"
},
{
"input": "RRUULLDD",
"output": "BUG"
},
{
"input": "L",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "RR",
"output": "OK"
},
{
"input": "DL",
"output": "OK"
},
{
"input": "LD",
"output": "OK"
},
{
"input": "RUL",
"output": "BUG"
},
{
"input": "ULD",
"output": "BUG"
},
{
"input": "DDR",
"output": "OK"
},
{
"input": "RRDD",
"output": "OK"
},
{
"input": "RRLR",
"output": "BUG"
},
{
"input": "RRDL",
"output": "BUG"
},
{
"input": "LRUD",
"output": "BUG"
},
{
"input": "RDRLL",
"output": "BUG"
},
{
"input": "DRDRD",
"output": "OK"
},
{
"input": "ULURL",
"output": "BUG"
},
{
"input": "LUUDU",
"output": "BUG"
},
{
"input": "RDLUR",
"output": "BUG"
},
{
"input": "DLDLDDRR",
"output": "OK"
},
{
"input": "RDRDDD",
"output": "OK"
},
{
"input": "UULLDLUR",
"output": "BUG"
},
{
"input": "LULU",
"output": "OK"
},
{
"input": "LLDDLDLLDDDLLLDLLLLLUU",
"output": "OK"
},
{
"input": "LLDDLDLLDDDLLLDLLLLLUU",
"output": "OK"
},
{
"input": "LLDDLDLLDDDLLLDLLLLLUU",
"output": "OK"
},
{
"input": "URRRRRURRURUURRRRRDDDDLDDDRDDDDLLDLL",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "UL",
"output": "OK"
},
{
"input": "UDR",
"output": "BUG"
},
{
"input": "DDDR",
"output": "OK"
},
{
"input": "UUUDU",
"output": "BUG"
},
{
"input": "LULULL",
"output": "OK"
},
{
"input": "DLURUUU",
"output": "BUG"
},
{
"input": "UURUURRUUU",
"output": "OK"
},
{
"input": "DDDDRDDLDDDDDDDRDDLD",
"output": "OK"
},
{
"input": "URRRLULUURURLRLLLLULLRLRURLULRLULLULRRUU",
"output": "BUG"
},
{
"input": "RURRRRLURRRURRUURRRRRRRRDDULULRRURRRDRRRRRRRRRRLDR",
"output": "BUG"
},
{
"input": "RLRRRRRDRRDRRRRDLRRRRRRRDLRLDDLRRRRLDLDRDRRRRDRDRDRDLRRURRLRRRRDRRRRRRRRLDDRLRRDRRRRRRRDRDRLDRDDDRDR",
"output": "BUG"
},
{
"input": "DDUL",
"output": "BUG"
},
{
"input": "UUULLLLRDD",
"output": "BUG"
},
{
"input": "LLLLLLLLRRRRDDDDDDDUUUUUU",
"output": "BUG"
},
{
"input": "DDDDDDDDDDDDUUUUUUUUUUUURRRRRRRRRRRRRLLLLLLLLLLLLLLL",
"output": "BUG"
},
{
"input": "DDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "BUG"
},
{
"input": "DLUR",
"output": "BUG"
},
{
"input": "UUUURDLLLL",
"output": "BUG"
},
{
"input": "RRRRRRRRRRRURLLLLLLLLLLLL",
"output": "BUG"
},
{
"input": "LLLLLLLLLLLLLLLLLLLLLLLLLLRUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "BUG"
},
{
"input": "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "BUG"
},
{
"input": "DDLDRRR",
"output": "BUG"
},
{
"input": "RRUULLD",
"output": "BUG"
},
{
"input": "LUUUULLLLDDDDRRRD",
"output": "BUG"
},
{
"input": "DDDDLLLDDDRRRUURRRR",
"output": "BUG"
},
{
"input": "DDDDDDDLLDDRRURRRRRRR",
"output": "BUG"
},
{
"input": "DDDDDDDDDDLLLLLLLLLLLDDDDDDDDDDDRRRRRRRRRRRUUUUUUUUUURRRRRRRRRR",
"output": "BUG"
},
{
"input": "DDDLLLLLLLDDDDDDDRRRRRRRUUUUUURRR",
"output": "BUG"
},
{
"input": "RRRUUULLLDD",
"output": "BUG"
},
{
"input": "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDLLLLDDDDRRRRUUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "BUG"
},
{
"input": "RRRRRRRRRRRDDDDDDDDDDDDDDDDDDDRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUULLLLLLLLLLLLLLLLLLUUUUUUUUUUU",
"output": "BUG"
}
] | 248 | 20,172,800 | 0 | 854 |
837 | Flag of Berland | [
"brute force",
"implementation"
] | null | null | The flag of Berland is such rectangular field *n*<=Γ<=*m* that satisfies following conditions:
- Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. - Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. - Each color should be used in exactly one stripe.
You are given a field *n*<=Γ<=*m*, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). | The first line contains two integer numbers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100) β the sizes of the field.
Each of the following *n* lines consisting of *m* characters 'R', 'G' and 'B' β the description of the field. | Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). | [
"6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n",
"4 3\nBRG\nBRG\nBRG\nBRG\n",
"6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB\n",
"4 4\nRRRR\nRRRR\nBBBB\nGGGG\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β 2, 1 and 1. | [
{
"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG",
"output": "YES"
},
{
"input": "4 3\nBRG\nBRG\nBRG\nBRG",
"output": "YES"
},
{
"input": "6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB",
"output": "NO"
},
{
"input": "4 4\nRRRR\nRRRR\nBBBB\nGGGG",
"output": "NO"
},
{
"input": "1 3\nGRB",
"output": "YES"
},
{
"input": "3 1\nR\nG\nB",
"output": "YES"
},
{
"input": "4 3\nRGB\nGRB\nGRB\nGRB",
"output": "NO"
},
{
"input": "4 6\nGGRRBB\nGGRRBB\nGGRRBB\nRRGGBB",
"output": "NO"
},
{
"input": "100 3\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nGRB",
"output": "NO"
},
{
"input": "3 100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRG",
"output": "NO"
},
{
"input": "3 1\nR\nR\nB",
"output": "NO"
},
{
"input": "3 2\nRR\nBB\nRR",
"output": "NO"
},
{
"input": "3 2\nRR\nBG\nBG",
"output": "NO"
},
{
"input": "3 2\nBB\nRR\nBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nRRR\nRRR",
"output": "NO"
},
{
"input": "3 3\nGGG\nGGG\nGGG",
"output": "NO"
},
{
"input": "1 3\nRGG",
"output": "NO"
},
{
"input": "4 3\nRGR\nRGR\nRGR\nRGR",
"output": "NO"
},
{
"input": "3 4\nRRGG\nRRGG\nBBBB",
"output": "NO"
},
{
"input": "3 3\nBRG\nBRG\nBRG",
"output": "YES"
},
{
"input": "3 1\nR\nG\nR",
"output": "NO"
},
{
"input": "5 3\nBBG\nBBG\nBBG\nBBG\nBBG",
"output": "NO"
},
{
"input": "3 3\nRRR\nGGG\nRRR",
"output": "NO"
},
{
"input": "1 3\nRGR",
"output": "NO"
},
{
"input": "3 6\nRRBBGG\nRRBBGG\nRRBBGG",
"output": "YES"
},
{
"input": "6 6\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG",
"output": "YES"
},
{
"input": "4 3\nRRR\nGGG\nBBB\nBBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nBBB\nRRR",
"output": "NO"
},
{
"input": "3 1\nB\nR\nB",
"output": "NO"
},
{
"input": "1 3\nBGB",
"output": "NO"
},
{
"input": "3 1\nB\nB\nB",
"output": "NO"
},
{
"input": "3 4\nRRRR\nBBBB\nRRRR",
"output": "NO"
},
{
"input": "1 6\nRGGGBB",
"output": "NO"
},
{
"input": "9 3\nBBB\nBBB\nBBB\nGGG\nGGG\nGRG\nRGR\nRRR\nRRR",
"output": "NO"
},
{
"input": "4 4\nRGBB\nRGBB\nRGBB\nRGBB",
"output": "NO"
},
{
"input": "3 3\nRBR\nRBR\nRBR",
"output": "NO"
},
{
"input": "1 6\nRRRRBB",
"output": "NO"
},
{
"input": "1 6\nRRRRRR",
"output": "NO"
},
{
"input": "1 6\nRRGGGG",
"output": "NO"
},
{
"input": "4 4\nRRRR\nRRRR\nRRRR\nRRRR",
"output": "NO"
},
{
"input": "3 1\nB\nG\nB",
"output": "NO"
},
{
"input": "3 1\nR\nR\nR",
"output": "NO"
},
{
"input": "1 9\nRRRGGGBBB",
"output": "YES"
},
{
"input": "1 3\nRRR",
"output": "NO"
},
{
"input": "3 5\nRRRRR\nBBBBB\nBBBBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nGGG\nGGG",
"output": "NO"
},
{
"input": "1 1\nR",
"output": "NO"
},
{
"input": "3 3\nRGR\nRGR\nRGR",
"output": "NO"
},
{
"input": "1 3\nGGG",
"output": "NO"
},
{
"input": "3 3\nRBG\nGBR\nRGB",
"output": "NO"
},
{
"input": "3 3\nRGB\nRGB\nRGB",
"output": "YES"
},
{
"input": "1 3\nBRB",
"output": "NO"
},
{
"input": "2 1\nR\nB",
"output": "NO"
},
{
"input": "1 3\nRBR",
"output": "NO"
},
{
"input": "3 5\nRRGBB\nRRGBB\nRRGBB",
"output": "NO"
},
{
"input": "5 3\nBBR\nBBR\nBBR\nBBR\nBBR",
"output": "NO"
},
{
"input": "3 3\nRGB\nRBG\nRGB",
"output": "NO"
},
{
"input": "1 2\nRB",
"output": "NO"
},
{
"input": "4 3\nBBB\nBBB\nBBB\nBBB",
"output": "NO"
},
{
"input": "36 6\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR",
"output": "NO"
},
{
"input": "4 1\nR\nB\nG\nR",
"output": "NO"
},
{
"input": "13 12\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR",
"output": "NO"
},
{
"input": "2 2\nRR\nRR",
"output": "NO"
},
{
"input": "6 6\nRRGGBB\nGRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB",
"output": "NO"
},
{
"input": "70 3\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG",
"output": "NO"
},
{
"input": "4 3\nBBG\nBBG\nBBG\nBBG",
"output": "NO"
},
{
"input": "6 3\nBBB\nGGG\nRRR\nBRG\nBRG\nBRG",
"output": "NO"
},
{
"input": "3 6\nRRBBGG\nRBBBGG\nRBBBGG",
"output": "NO"
},
{
"input": "6 6\nGGGGGG\nGGGGGG\nBBBBBB\nBBBBBB\nGGGGGG\nGGGGGG",
"output": "NO"
},
{
"input": "6 1\nR\nB\nG\nR\nB\nG",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nBBBBB\nGGGGG\nRRRRR\nBBBBB\nGGGGG",
"output": "NO"
},
{
"input": "6 3\nRRR\nGGG\nBBB\nRRR\nGGG\nBBB",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nRRRRR\nRRRRR\nGGGGG\nGGGGG\nGGGGG",
"output": "NO"
},
{
"input": "15 28\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "NO"
},
{
"input": "21 10\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBGBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG",
"output": "NO"
},
{
"input": "3 2\nRR\nGB\nGB",
"output": "NO"
},
{
"input": "3 2\nRG\nRG\nBB",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nRRRRR\nRRRRR",
"output": "NO"
},
{
"input": "3 3\nRGB\nGBR\nBRG",
"output": "NO"
},
{
"input": "1 3\nRBB",
"output": "NO"
},
{
"input": "3 3\nBGR\nBGR\nBGR",
"output": "YES"
},
{
"input": "6 6\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB",
"output": "YES"
},
{
"input": "4 2\nRR\nGG\nRR\nBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nRRR\nGGG",
"output": "NO"
},
{
"input": "8 6\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR",
"output": "NO"
},
{
"input": "3 4\nRRRR\nRRRR\nGGGG",
"output": "NO"
},
{
"input": "3 4\nRRRR\nRRRR\nRRRR",
"output": "NO"
},
{
"input": "6 1\nR\nR\nR\nR\nR\nR",
"output": "NO"
},
{
"input": "1 6\nRRBBGG",
"output": "YES"
},
{
"input": "1 6\nRGBRGB",
"output": "NO"
},
{
"input": "3 4\nRRRR\nGGGG\nRRRR",
"output": "NO"
},
{
"input": "3 3\nRRB\nGRG\nGBB",
"output": "NO"
},
{
"input": "3 7\nRRGGBBB\nRRGGBBB\nRRGGBBB",
"output": "NO"
},
{
"input": "3 1\nG\nR\nR",
"output": "NO"
},
{
"input": "2 3\nRGG\nRBB",
"output": "NO"
},
{
"input": "3 3\nRRG\nGGG\nBBB",
"output": "NO"
},
{
"input": "3 3\nRGB\nRBB\nRGB",
"output": "NO"
},
{
"input": "3 3\nRGR\nRGB\nRGB",
"output": "NO"
},
{
"input": "3 1\nB\nR\nR",
"output": "NO"
},
{
"input": "1 3\nGRR",
"output": "NO"
},
{
"input": "4 4\nRRRR\nGGGG\nBBBB\nBBBB",
"output": "NO"
},
{
"input": "1 3\nGGR",
"output": "NO"
},
{
"input": "3 3\nRGB\nGGB\nRGB",
"output": "NO"
},
{
"input": "3 3\nRGR\nGGG\nBBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nGGGGGG\nGGGGGG\nGGGGGG\nBBBBBB\nBBBBBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nGGGGGG\nBBBBBB\nBBBBBB\nBBBBBB",
"output": "NO"
},
{
"input": "3 1\nG\nB\nR",
"output": "YES"
},
{
"input": "3 3\nGGB\nRGB\nRGB",
"output": "NO"
},
{
"input": "3 3\nGRR\nGGG\nBBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nGGGGGG\nGGGGGG\nBBBBBB\nRRRRRR",
"output": "NO"
},
{
"input": "3 3\nRRR\nGBG\nBBB",
"output": "NO"
},
{
"input": "3 8\nRRGGBBBB\nRRGGBBBB\nRRGGBBBB",
"output": "NO"
},
{
"input": "2 2\nRR\nGG",
"output": "NO"
},
{
"input": "3 3\nRGB\nRGR\nRGB",
"output": "NO"
},
{
"input": "1 3\nRBG",
"output": "YES"
},
{
"input": "2 6\nRRGGBB\nGGRRBB",
"output": "NO"
},
{
"input": "6 2\nRR\nGG\nBB\nRR\nGG\nBB",
"output": "NO"
},
{
"input": "1 5\nRRGGB",
"output": "NO"
},
{
"input": "1 2\nRG",
"output": "NO"
},
{
"input": "1 6\nRGBRBG",
"output": "NO"
},
{
"input": "1 6\nRRRGGB",
"output": "NO"
},
{
"input": "1 3\nRGB",
"output": "YES"
},
{
"input": "4 3\nRRR\nBBR\nGBB\nGGG",
"output": "NO"
},
{
"input": "6 3\nRRR\nBBB\nBBB\nBBB\nGGG\nGGG",
"output": "NO"
},
{
"input": "3 3\nRBG\nRBG\nRBG",
"output": "YES"
},
{
"input": "6 3\nRRR\nBBB\nGGG\nRRR\nBBB\nGGG",
"output": "NO"
},
{
"input": "1 4\nRGBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nRRRRR\nGGGGG\nGGGGG\nRRRRR\nRRRRR",
"output": "NO"
},
{
"input": "3 3\nRGB\nBRG\nGBR",
"output": "NO"
},
{
"input": "6 10\nRRRRRRRRRR\nGGGGGGGGGG\nBBBBBBBBBB\nRRRRRRRRRR\nGGGGGGGGGG\nBBBBBBBBBB",
"output": "NO"
},
{
"input": "20 6\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB",
"output": "YES"
},
{
"input": "4 1\nR\nG\nB\nR",
"output": "NO"
},
{
"input": "1 4\nRGBR",
"output": "NO"
},
{
"input": "2 4\nRGBB\nRRGB",
"output": "NO"
}
] | 62 | 204,800 | -1 | 855 |
|
697 | Pineapple Incident | [
"implementation",
"math"
] | null | null | Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time *x* (in seconds), so he asked you to tell him if it's gonna bark at that time. | The first and only line of input contains three integers *t*, *s* and *x* (0<=β€<=*t*,<=*x*<=β€<=109, 2<=β€<=*s*<=β€<=109)Β β the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively. | Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output. | [
"3 10 4\n",
"3 10 3\n",
"3 8 51\n",
"3 8 52\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52. | [
{
"input": "3 10 4",
"output": "NO"
},
{
"input": "3 10 3",
"output": "YES"
},
{
"input": "3 8 51",
"output": "YES"
},
{
"input": "3 8 52",
"output": "YES"
},
{
"input": "456947336 740144 45",
"output": "NO"
},
{
"input": "33 232603 599417964",
"output": "YES"
},
{
"input": "4363010 696782227 701145238",
"output": "YES"
},
{
"input": "9295078 2 6",
"output": "NO"
},
{
"input": "76079 281367 119938421",
"output": "YES"
},
{
"input": "93647 7 451664565",
"output": "YES"
},
{
"input": "5 18553 10908",
"output": "NO"
},
{
"input": "6 52 30",
"output": "NO"
},
{
"input": "6431 855039 352662",
"output": "NO"
},
{
"input": "749399100 103031711 761562532",
"output": "NO"
},
{
"input": "21 65767 55245",
"output": "NO"
},
{
"input": "4796601 66897 4860613",
"output": "NO"
},
{
"input": "8 6728951 860676",
"output": "NO"
},
{
"input": "914016 6 914019",
"output": "NO"
},
{
"input": "60686899 78474 60704617",
"output": "NO"
},
{
"input": "3 743604 201724",
"output": "NO"
},
{
"input": "571128 973448796 10",
"output": "NO"
},
{
"input": "688051712 67 51",
"output": "NO"
},
{
"input": "74619 213344 6432326",
"output": "NO"
},
{
"input": "6947541 698167 6",
"output": "NO"
},
{
"input": "83 6 6772861",
"output": "NO"
},
{
"input": "251132 67561 135026988",
"output": "NO"
},
{
"input": "8897216 734348516 743245732",
"output": "YES"
},
{
"input": "50 64536 153660266",
"output": "YES"
},
{
"input": "876884 55420 971613604",
"output": "YES"
},
{
"input": "0 6906451 366041903",
"output": "YES"
},
{
"input": "11750 8 446010134",
"output": "YES"
},
{
"input": "582692707 66997 925047377",
"output": "YES"
},
{
"input": "11 957526890 957526901",
"output": "YES"
},
{
"input": "556888 514614196 515171084",
"output": "YES"
},
{
"input": "6 328006 584834704",
"output": "YES"
},
{
"input": "4567998 4 204966403",
"output": "YES"
},
{
"input": "60 317278 109460971",
"output": "YES"
},
{
"input": "906385 342131991 685170368",
"output": "YES"
},
{
"input": "1 38 902410512",
"output": "YES"
},
{
"input": "29318 787017 587931018",
"output": "YES"
},
{
"input": "351416375 243431 368213115",
"output": "YES"
},
{
"input": "54 197366062 197366117",
"output": "YES"
},
{
"input": "586389 79039 850729874",
"output": "YES"
},
{
"input": "723634470 2814619 940360134",
"output": "YES"
},
{
"input": "0 2 0",
"output": "YES"
},
{
"input": "0 2 1",
"output": "NO"
},
{
"input": "0 2 2",
"output": "YES"
},
{
"input": "0 2 3",
"output": "YES"
},
{
"input": "0 2 1000000000",
"output": "YES"
},
{
"input": "0 10 23",
"output": "NO"
},
{
"input": "0 2 999999999",
"output": "YES"
},
{
"input": "10 5 11",
"output": "NO"
},
{
"input": "1 2 1000000000",
"output": "YES"
},
{
"input": "1 10 20",
"output": "NO"
},
{
"input": "1 2 999999937",
"output": "YES"
},
{
"input": "10 3 5",
"output": "NO"
},
{
"input": "3 2 5",
"output": "YES"
},
{
"input": "0 4 0",
"output": "YES"
},
{
"input": "0 215 403",
"output": "NO"
},
{
"input": "5 2 10",
"output": "YES"
},
{
"input": "0 2 900000000",
"output": "YES"
},
{
"input": "0 79 4000",
"output": "NO"
},
{
"input": "5 1000 1000",
"output": "NO"
},
{
"input": "1 5 103",
"output": "NO"
},
{
"input": "5 2 6",
"output": "NO"
},
{
"input": "120 2 1000000000",
"output": "YES"
},
{
"input": "2 2 1000000000",
"output": "YES"
},
{
"input": "5 5 13",
"output": "NO"
},
{
"input": "10 5 15",
"output": "YES"
},
{
"input": "11 2 0",
"output": "NO"
},
{
"input": "3 8 53",
"output": "NO"
},
{
"input": "2 2 4",
"output": "YES"
},
{
"input": "4 4 0",
"output": "NO"
},
{
"input": "1 2 3",
"output": "YES"
},
{
"input": "5 3 9",
"output": "YES"
},
{
"input": "5 6 19",
"output": "NO"
},
{
"input": "3 10 125",
"output": "NO"
},
{
"input": "5 3 8",
"output": "YES"
},
{
"input": "6 3 9",
"output": "YES"
},
{
"input": "0 3 5",
"output": "NO"
},
{
"input": "5 3 300000035",
"output": "YES"
},
{
"input": "5 2 7",
"output": "YES"
},
{
"input": "1 5 6",
"output": "YES"
},
{
"input": "4 2 6",
"output": "YES"
},
{
"input": "0 3 999999998",
"output": "NO"
},
{
"input": "0 10001 0",
"output": "YES"
},
{
"input": "6 5 3",
"output": "NO"
},
{
"input": "1 5 1000000000",
"output": "NO"
},
{
"input": "1 3 6",
"output": "NO"
},
{
"input": "3 3 1000000000",
"output": "YES"
},
{
"input": "3 3 4",
"output": "NO"
},
{
"input": "3 3 5",
"output": "NO"
},
{
"input": "3 3 0",
"output": "NO"
},
{
"input": "1 2 4",
"output": "YES"
},
{
"input": "5 5 10",
"output": "YES"
}
] | 31 | 0 | -1 | 858 |
|
493 | Vasya and Football | [
"implementation"
] | null | null | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number *n* (1<=β€<=*n*<=β€<=90) β the number of fouls.
Each of the following *n* lines contains information about a foul in the following form:
- first goes number *t* (1<=β€<=*t*<=β€<=90) β the minute when the foul occurs; - then goes letter "h" or letter "a" β if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; - then goes the player's number *m* (1<=β€<=*m*<=β€<=99); - then goes letter "y" or letter "r" β if the letter is "y", that means that the yellow card was given, otherwise the red card was given.
The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | For each event when a player received his first red card in a chronological order print a string containing the following information:
- The name of the team to which the player belongs; - the player's number in his team; - the minute when he received the card.
If no player received a card, then you do not need to print anything.
It is possible case that the program will not print anything to the output (if there were no red cards). | [
"MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r\n"
] | [
"MC 25 70\nMC 42 82\nCSKA 13 90\n"
] | none | [
{
"input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r",
"output": "MC 25 70\nMC 42 82\nCSKA 13 90"
},
{
"input": "REAL\nBARCA\n3\n27 h 7 y\n44 a 10 y\n87 h 3 r",
"output": "REAL 3 87"
},
{
"input": "MASFF\nSAFBDSRG\n5\n1 h 1 y\n15 h 1 r\n27 a 1 y\n58 a 1 y\n69 h 10 y",
"output": "MASFF 1 15\nSAFBDSRG 1 58"
},
{
"input": "ARMENIA\nBULGARIA\n12\n33 h 17 y\n42 h 21 y\n56 a 17 y\n58 a 6 y\n61 a 7 y\n68 a 10 y\n72 h 13 y\n73 h 21 y\n74 a 8 r\n75 a 4 y\n77 a 10 y\n90 a 23 y",
"output": "ARMENIA 21 73\nBULGARIA 8 74\nBULGARIA 10 77"
},
{
"input": "PORTUGAL\nNETHERLANDS\n16\n2 a 18 y\n7 a 3 y\n20 h 18 y\n31 h 6 y\n45 h 6 y\n50 h 8 y\n59 a 5 y\n60 h 7 y\n63 a 3 y\n72 a 20 y\n73 h 20 y\n74 a 10 y\n75 h 1 y\n76 h 14 y\n78 h 20 y\n90 a 5 y",
"output": "PORTUGAL 6 45\nNETHERLANDS 3 63\nPORTUGAL 20 78\nNETHERLANDS 5 90"
},
{
"input": "TANC\nXNCOR\n2\n15 h 27 r\n28 h 27 r",
"output": "TANC 27 15"
},
{
"input": "ASGDFJH\nAHGRSDXGER\n3\n23 h 15 r\n68 h 15 y\n79 h 15 y",
"output": "ASGDFJH 15 23"
},
{
"input": "ASFSHDSG\nADGYRTJNG\n5\n1 h 1 y\n2 h 1 y\n3 h 1 y\n4 h 1 r\n5 h 1 y",
"output": "ASFSHDSG 1 2"
},
{
"input": "A\nB\n42\n5 a 84 y\n8 h 28 r\n10 a 9 r\n11 h 93 y\n13 a 11 r\n15 h 3 r\n20 a 88 r\n23 a 41 y\n25 a 14 y\n27 a 38 r\n28 a 33 y\n29 h 66 r\n31 a 16 r\n32 a 80 y\n34 a 54 r\n35 a 50 y\n36 a 9 y\n39 a 22 y\n42 h 81 y\n43 a 10 y\n44 a 27 r\n47 h 39 y\n48 a 80 y\n50 h 5 y\n52 a 67 y\n54 h 63 y\n56 h 7 y\n57 h 44 y\n58 h 41 y\n61 h 32 y\n64 h 91 y\n67 a 56 y\n69 h 83 y\n71 h 59 y\n72 a 76 y\n75 h 41 y\n76 a 49 r\n77 a 4 r\n78 a 69 y\n79 a 96 r\n80 h 81 y\n86 h 85 r",
"output": "A 28 8\nB 9 10\nB 11 13\nA 3 15\nB 88 20\nB 38 27\nA 66 29\nB 16 31\nB 54 34\nB 27 44\nB 80 48\nA 41 75\nB 49 76\nB 4 77\nB 96 79\nA 81 80\nA 85 86"
},
{
"input": "ARM\nAZE\n45\n2 a 13 r\n3 a 73 r\n4 a 10 y\n5 h 42 y\n8 h 56 y\n10 h 15 y\n11 a 29 r\n13 a 79 y\n14 a 77 r\n18 h 7 y\n20 a 69 r\n22 h 19 y\n25 h 88 r\n26 a 78 y\n27 a 91 r\n28 h 10 r\n30 h 13 r\n31 a 26 r\n33 a 43 r\n34 a 91 y\n40 h 57 y\n44 h 18 y\n46 a 25 r\n48 a 29 y\n51 h 71 y\n57 a 16 r\n58 h 37 r\n59 h 92 y\n60 h 11 y\n61 a 88 y\n64 a 28 r\n65 h 71 r\n68 h 39 y\n70 h 8 r\n71 a 10 y\n72 a 32 y\n73 h 95 r\n74 a 33 y\n75 h 48 r\n78 a 44 y\n79 a 22 r\n80 h 50 r\n84 a 50 y\n88 a 90 y\n89 h 42 r",
"output": "AZE 13 2\nAZE 73 3\nAZE 29 11\nAZE 77 14\nAZE 69 20\nARM 88 25\nAZE 91 27\nARM 10 28\nARM 13 30\nAZE 26 31\nAZE 43 33\nAZE 25 46\nAZE 16 57\nARM 37 58\nAZE 28 64\nARM 71 65\nARM 8 70\nAZE 10 71\nARM 95 73\nARM 48 75\nAZE 22 79\nARM 50 80\nARM 42 89"
},
{
"input": "KASFLS\nASJBGGDLJFDDFHHTHJH\n42\n2 a 68 y\n4 h 64 r\n5 a 24 y\n6 h 20 r\n8 a 16 r\n9 a 96 y\n10 h 36 r\n12 a 44 y\n13 h 69 r\n16 a 62 r\n18 a 99 r\n20 h 12 r\n21 a 68 y\n25 h 40 y\n26 h 54 r\n28 h 91 r\n29 a 36 r\n33 a 91 y\n36 h 93 r\n37 h 60 r\n38 a 82 r\n41 a 85 y\n42 a 62 r\n46 a 22 r\n48 a 88 r\n49 a 8 r\n51 h 45 y\n54 a 84 y\n57 a 8 y\n59 h 24 y\n61 h 22 r\n64 h 11 r\n69 a 89 y\n72 h 44 r\n75 h 57 r\n76 h 80 y\n77 h 54 r\n79 a 1 y\n81 a 31 r\n82 h 8 y\n83 a 28 r\n86 h 56 y",
"output": "KASFLS 64 4\nKASFLS 20 6\nASJBGGDLJFDDFHHTHJH 16 8\nKASFLS 36 10\nKASFLS 69 13\nASJBGGDLJFDDFHHTHJH 62 16\nASJBGGDLJFDDFHHTHJH 99 18\nKASFLS 12 20\nASJBGGDLJFDDFHHTHJH 68 21\nKASFLS 54 26\nKASFLS 91 28\nASJBGGDLJFDDFHHTHJH 36 29\nKASFLS 93 36\nKASFLS 60 37\nASJBGGDLJFDDFHHTHJH 82 38\nASJBGGDLJFDDFHHTHJH 22 46\nASJBGGDLJFDDFHHTHJH 88 48\nASJBGGDLJFDDFHHTHJH 8 49\nKASFLS 22 61\nKASFLS 11 64\nKASFLS 44 72\nKASFLS 57 75\nASJBGGDLJFDDFHHTHJH 31 81\nASJBGGDLJFDDFHHTHJH 28 83"
},
{
"input": "AB\nBC\n3\n1 h 1 y\n2 h 1 y\n3 h 1 r",
"output": "AB 1 2"
}
] | 155 | 5,836,800 | 3 | 859 |
|
269 | Greenhouse Effect | [
"dp"
] | null | null | Emuskald is an avid horticulturist and owns the world's longest greenhouse β it is effectively infinite in length.
Over the years Emuskald has cultivated *n* plants in his greenhouse, of *m* different plant species numbered from 1 to *m*. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.
Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange *m*<=-<=1 borders that would divide the greenhouse into *m* sections numbered from 1 to *m* from left to right with each section housing a single species. He is free to place the borders, but in the end all of the *i*-th species plants must reside in *i*-th section from the left.
Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. | The first line of input contains two space-separated integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=5000, *n*<=β₯<=*m*), the number of plants and the number of different species. Each of the following *n* lines contain two space-separated numbers: one integer number *s**i* (1<=β€<=*s**i*<=β€<=*m*), and one real number *x**i* (0<=β€<=*x**i*<=β€<=109), the species and position of the *i*-th plant. Each *x**i* will contain no more than 6 digits after the decimal point.
It is guaranteed that all *x**i* are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their *x**i* coordinates (*x**i*<=<<=*x**i*<=+<=1,<=1<=β€<=*i*<=<<=*n*). | Output a single integer β the minimum number of plants to be replanted. | [
"3 2\n2 1\n1 2.0\n1 3.100\n",
"3 3\n1 5.0\n2 5.5\n3 6.0\n",
"6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.
In the second test case, the species are already in the correct order, so no replanting is needed. | [
{
"input": "3 2\n2 1\n1 2.0\n1 3.100",
"output": "1"
},
{
"input": "3 3\n1 5.0\n2 5.5\n3 6.0",
"output": "0"
},
{
"input": "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125",
"output": "2"
},
{
"input": "1 1\n1 0",
"output": "0"
},
{
"input": "8 2\n1 0.000000\n1 1.000000\n1 2.000000\n2 2.000001\n1 999999997.000000\n2 999999998.000000\n2 999999999.999999\n2 1000000000.000000",
"output": "1"
},
{
"input": "15 5\n4 6.039627\n2 7.255149\n2 14.469785\n2 15.108572\n4 22.570081\n5 26.642253\n5 32.129202\n5 44.288220\n5 53.231909\n5 60.548042\n4 62.386581\n2 77.828816\n1 87.998512\n3 96.163559\n2 99.412872",
"output": "6"
},
{
"input": "10 7\n4 70882.412953\n1 100461.912159\n3 100813.254090\n7 121632.112636\n2 424085.529781\n6 510966.713362\n6 543441.105338\n7 680094.776949\n1 721404.212606\n5 838754.272757",
"output": "5"
},
{
"input": "5 5\n5 0\n4 1\n3 2\n2 3\n1 4",
"output": "4"
},
{
"input": "12 5\n2 0\n2 1\n3 2\n3 3\n3 4\n1 5\n5 6\n3 7\n3 8\n3 9\n4 999999999\n4 1000000000",
"output": "2"
},
{
"input": "3 3\n2 0\n1 1\n3 2",
"output": "1"
},
{
"input": "3 3\n3 0\n1 1\n2 2",
"output": "1"
},
{
"input": "4 2\n1 10\n2 20\n1 30\n2 40",
"output": "1"
},
{
"input": "20 10\n1 0.000000\n2 0.000001\n3 0.000002\n4 0.000003\n5 0.000004\n6 0.000005\n7 0.000006\n8 0.000007\n9 0.000008\n10 0.000009\n1 999999999.999990\n2 999999999.999991\n3 999999999.999992\n4 999999999.999993\n5 999999999.999994\n6 999999999.999995\n7 999999999.999996\n8 999999999.999997\n9 999999999.999998\n10 999999999.999999",
"output": "9"
},
{
"input": "12 4\n3 0\n3 1\n3 2\n3 3\n3 4\n1 5\n1 6\n2 7\n4 8\n4 9\n2 10\n3 11",
"output": "5"
},
{
"input": "16 2\n1 0\n1 1\n2 2\n2 3\n2 4\n2 5\n1 6\n1 7\n2 8\n2 9\n1 10\n1 11\n2 12\n2 13\n2 14\n2 15",
"output": "4"
},
{
"input": "10 10\n1 100\n2 101\n3 102\n5 103\n9 1000\n8 10000\n6 100000\n7 1000000\n4 10000000\n10 100000000",
"output": "3"
},
{
"input": "10 6\n5 50837.108162\n3 111993.624183\n1 207268.919250\n6 567963.419694\n1 621364.247371\n2 630118.065585\n1 642135.221942\n6 642673.884754\n5 647004.198361\n4 735196.102629",
"output": "6"
},
{
"input": "20 2\n1 39277.770446\n1 131242.472574\n2 131745.437889\n1 261920.593789\n2 323611.256365\n1 341693.666730\n2 378611.498102\n2 568433.562368\n1 667757.789581\n1 674662.040626\n2 690065.099817\n2 724737.429934\n1 774858.513301\n2 783681.914774\n1 808327.402925\n2 867697.070403\n1 880911.396984\n1 929807.064277\n2 942269.265950\n1 999503.792481",
"output": "9"
},
{
"input": "20 15\n6 8719.787178\n10 13066.663722\n15 58623.690996\n9 184321.819759\n3 227999.294560\n2 279836.330518\n9 282806.308675\n8 311056.507765\n1 312315.562927\n5 459200.373445\n14 563454.265947\n7 647364.984868\n13 679761.613732\n4 684192.647497\n1 733119.607626\n7 748637.778398\n12 828048.945890\n11 893690.736585\n8 965323.895167\n5 967641.708962",
"output": "15"
},
{
"input": "15 3\n1 0\n2 1\n3 2\n1 3\n2 4\n3 5\n1 6\n2 7\n3 8\n1 9\n2 10\n3 11\n1 12\n2 13\n3 14",
"output": "8"
},
{
"input": "10 2\n2 0\n2 1\n2 2\n2 3\n2 4\n1 5\n1 6\n1 7\n1 8\n1 9",
"output": "5"
},
{
"input": "11 3\n2 0\n2 1\n2 2\n2 3\n2 4\n3 5\n1 6\n1 7\n1 8\n1 9\n1 10",
"output": "5"
}
] | 124 | 4,608,000 | 0 | 860 |
|
4 | Before an Exam | [
"constructive algorithms",
"greedy"
] | B. Before an Exam | 0 | 64 | Tomorrow Peter has a Biology exam. He does not like this subject much, but *d* days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than *minTime**i* and not more than *maxTime**i* hours per each *i*-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.
So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours *sumTime* spent him on preparation, and now he wants to know if he can show his parents a timetable *sΡhedule* with *d* numbers, where each number *sΡhedule**i* stands for the time in hours spent by Peter each *i*-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all *schedule**i* should equal to *sumTime*. | The first input line contains two integer numbers *d*,<=*sumTime* (1<=β€<=*d*<=β€<=30,<=0<=β€<=*sumTime*<=β€<=240) β the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following *d* lines contains two integer numbers *minTime**i*,<=*maxTime**i* (0<=β€<=*minTime**i*<=β€<=*maxTime**i*<=β€<=8), separated by a space β minimum and maximum amount of hours that Peter could spent in the *i*-th day. | In the first line print YES, and in the second line print *d* numbers (separated by a space), each of the numbers β amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them. | [
"1 48\n5 7\n",
"2 5\n0 1\n3 5\n"
] | [
"NO\n",
"YES\n1 4 "
] | none | [
{
"input": "1 48\n5 7",
"output": "NO"
},
{
"input": "2 5\n0 1\n3 5",
"output": "YES\n1 4 "
},
{
"input": "1 1\n5 6",
"output": "NO"
},
{
"input": "1 4\n2 4",
"output": "YES\n4 "
},
{
"input": "2 5\n4 6\n0 0",
"output": "YES\n5 0 "
},
{
"input": "27 97\n2 8\n0 5\n5 6\n3 6\n5 5\n1 2\n3 5\n1 8\n0 4\n3 3\n0 2\n0 0\n4 8\n5 6\n5 8\n0 7\n1 4\n0 4\n1 5\n3 7\n2 5\n5 6\n4 7\n3 8\n0 1\n3 4\n5 7",
"output": "YES\n8 5 6 6 5 2 5 8 4 3 2 0 6 5 5 0 1 0 1 3 2 5 4 3 0 3 5 "
},
{
"input": "30 92\n4 5\n4 7\n2 6\n8 8\n7 8\n4 5\n1 5\n7 8\n1 2\n6 8\n2 7\n2 4\n0 0\n1 3\n4 5\n1 1\n0 7\n2 5\n2 5\n3 3\n1 2\n1 7\n5 5\n5 8\n6 7\n0 3\n2 6\n0 7\n5 6\n2 5",
"output": "YES\n5 7 2 8 7 4 1 7 1 6 2 2 0 1 4 1 0 2 2 3 1 1 5 5 6 0 2 0 5 2 "
},
{
"input": "30 178\n1 6\n2 7\n2 5\n2 8\n1 6\n2 8\n3 4\n2 7\n0 2\n0 8\n0 3\n0 2\n2 4\n4 8\n6 8\n0 8\n0 6\n1 8\n0 3\n6 7\n4 8\n2 7\n1 1\n3 7\n3 6\n2 5\n4 7\n2 2\n1 8\n5 6",
"output": "NO"
},
{
"input": "30 71\n1 3\n0 6\n3 5\n3 6\n2 4\n2 8\n2 4\n3 8\n3 5\n2 4\n2 3\n3 7\n0 0\n5 7\n0 2\n5 8\n0 8\n4 7\n0 3\n3 7\n2 3\n4 5\n7 8\n7 7\n2 7\n1 3\n0 1\n1 5\n6 7\n5 8",
"output": "NO"
},
{
"input": "30 119\n2 7\n1 3\n0 3\n3 4\n7 7\n7 7\n0 5\n2 3\n0 8\n0 8\n0 5\n5 7\n2 2\n2 6\n2 5\n3 7\n0 8\n0 2\n1 3\n2 3\n1 4\n0 1\n3 7\n7 8\n1 2\n0 6\n1 8\n1 7\n4 8\n1 4",
"output": "YES\n7 3 3 4 7 7 5 3 8 8 5 7 2 6 5 7 8 2 1 2 1 0 3 7 1 0 1 1 4 1 "
},
{
"input": "1 0\n0 0",
"output": "YES\n0 "
},
{
"input": "30 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "YES\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 "
},
{
"input": "30 240\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8",
"output": "YES\n8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 "
},
{
"input": "30 64\n7 7\n3 4\n0 4\n5 8\n1 3\n1 1\n0 2\n0 4\n7 7\n3 5\n4 4\n0 4\n4 5\n1 4\n4 6\n5 7\n1 4\n1 2\n3 3\n0 2\n3 7\n3 4\n0 3\n3 8\n0 8\n0 1\n0 3\n4 5\n1 5\n0 3",
"output": "YES\n7 3 0 5 1 1 0 0 7 3 4 0 4 1 4 5 1 1 3 0 3 3 0 3 0 0 0 4 1 0 "
},
{
"input": "30 189\n0 8\n3 8\n5 8\n2 2\n7 7\n2 8\n7 8\n2 5\n1 7\n0 1\n3 4\n1 7\n1 6\n5 6\n3 7\n4 7\n4 7\n4 7\n5 5\n0 5\n4 7\n3 5\n0 6\n4 8\n2 5\n5 6\n5 6\n2 8\n0 7\n7 8",
"output": "YES\n8 8 8 2 7 8 8 5 7 1 4 7 6 6 7 7 7 7 5 5 7 5 6 8 5 6 6 8 7 8 "
}
] | 77 | 2,867,200 | -1 | 861 |
755 | PolandBall and Hypothesis | [
"brute force",
"graphs",
"math",
"number theory"
] | null | null | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*Β·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any *n*. | The only number in the input is *n* (1<=β€<=*n*<=β€<=1000)Β β number from the PolandBall's hypothesis. | Output such *m* that *n*Β·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=β€<=*m*<=β€<=103. It is guaranteed the the answer exists. | [
"3\n",
"4\n"
] | [
"1",
"2"
] | A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3Β·1β+β1β=β4. We can output 1.
In the second sample testcase, 4Β·1β+β1β=β5. We cannot output 1 because 5 is prime. However, *m*β=β2 is okay since 4Β·2β+β1β=β9, which is not a prime number. | [
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "153",
"output": "1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "6",
"output": "4"
},
{
"input": "7",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "11",
"output": "1"
},
{
"input": "998",
"output": "1"
},
{
"input": "996",
"output": "3"
},
{
"input": "36",
"output": "4"
},
{
"input": "210",
"output": "4"
},
{
"input": "270",
"output": "4"
},
{
"input": "306",
"output": "4"
},
{
"input": "330",
"output": "5"
},
{
"input": "336",
"output": "4"
},
{
"input": "600",
"output": "4"
},
{
"input": "726",
"output": "4"
},
{
"input": "988",
"output": "1"
},
{
"input": "12",
"output": "2"
},
{
"input": "987",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "986",
"output": "1"
},
{
"input": "14",
"output": "1"
},
{
"input": "985",
"output": "1"
},
{
"input": "15",
"output": "1"
},
{
"input": "984",
"output": "1"
},
{
"input": "16",
"output": "2"
},
{
"input": "983",
"output": "1"
},
{
"input": "17",
"output": "1"
},
{
"input": "982",
"output": "2"
},
{
"input": "18",
"output": "3"
},
{
"input": "981",
"output": "1"
},
{
"input": "19",
"output": "1"
},
{
"input": "980",
"output": "1"
},
{
"input": "20",
"output": "1"
},
{
"input": "979",
"output": "1"
},
{
"input": "21",
"output": "1"
},
{
"input": "978",
"output": "1"
},
{
"input": "22",
"output": "2"
},
{
"input": "977",
"output": "1"
},
{
"input": "23",
"output": "1"
},
{
"input": "976",
"output": "2"
},
{
"input": "24",
"output": "1"
},
{
"input": "975",
"output": "1"
},
{
"input": "25",
"output": "1"
},
{
"input": "2",
"output": "4"
},
{
"input": "6",
"output": "4"
},
{
"input": "996",
"output": "3"
},
{
"input": "8",
"output": "1"
},
{
"input": "998",
"output": "1"
},
{
"input": "330",
"output": "5"
},
{
"input": "18",
"output": "3"
},
{
"input": "12",
"output": "2"
},
{
"input": "24",
"output": "1"
},
{
"input": "999",
"output": "1"
},
{
"input": "726",
"output": "4"
},
{
"input": "876",
"output": "3"
}
] | 78 | 0 | 3 | 862 |
|
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"
}
] | 46 | 0 | 3 | 865 |
|
669 | Little Artem and Presents | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.
How many times can Artem give presents to Masha? | The only line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=109)Β β number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"
},
{
"input": "1000000000",
"output": "666666667"
},
{
"input": "5",
"output": "3"
},
{
"input": "6",
"output": "4"
},
{
"input": "999999999",
"output": "666666666"
},
{
"input": "999999998",
"output": "666666665"
},
{
"input": "999999997",
"output": "666666665"
},
{
"input": "999999996",
"output": "666666664"
},
{
"input": "999999995",
"output": "666666663"
},
{
"input": "999999994",
"output": "666666663"
},
{
"input": "999999993",
"output": "666666662"
},
{
"input": "999999992",
"output": "666666661"
},
{
"input": "999999991",
"output": "666666661"
},
{
"input": "1000",
"output": "667"
},
{
"input": "10000",
"output": "6667"
},
{
"input": "100000",
"output": "66667"
},
{
"input": "1000000",
"output": "666667"
},
{
"input": "10000000",
"output": "6666667"
},
{
"input": "100000000",
"output": "66666667"
},
{
"input": "7",
"output": "5"
}
] | 15 | 4,608,000 | 0 | 867 |
|
1,009 | Game Shopping | [
"implementation"
] | null | null | Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.
When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop.
Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.
For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 > a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$.
Your task is to get the number of games Maxim will buy. | The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) β the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet. | Print a single integer β the number of games Maxim will buy. | [
"5 4\n2 4 5 2 4\n5 3 4 6\n",
"5 2\n20 40 50 20 40\n19 20\n",
"6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n"
] | [
"3\n",
"0\n",
"4\n"
] | The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | [
{
"input": "5 4\n2 4 5 2 4\n5 3 4 6",
"output": "3"
},
{
"input": "5 2\n20 40 50 20 40\n19 20",
"output": "0"
},
{
"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000",
"output": "4"
},
{
"input": "5 1\n1 1 1 1 1\n5",
"output": "1"
},
{
"input": "5 1\n10 1 1 1 1\n1000",
"output": "1"
},
{
"input": "5 1\n100 100 100 100 100\n100",
"output": "1"
},
{
"input": "2 1\n2 1\n1",
"output": "1"
},
{
"input": "2 3\n3 1\n2 4 2",
"output": "1"
},
{
"input": "1 5\n4\n1 4 3 3 2",
"output": "0"
},
{
"input": "5 3\n4 2 3 1 1\n2 1 3",
"output": "3"
},
{
"input": "3 5\n5 2 5\n1 4 1 4 2",
"output": "0"
},
{
"input": "7 3\n9 7 10 2 1 1 1\n8 9 6",
"output": "3"
},
{
"input": "5 3\n2 5 3 3 2\n2 5 3",
"output": "3"
}
] | 155 | 0 | 3 | 871 |
|
667 | Coat of Anticubism | [
"constructive algorithms",
"geometry"
] | null | null | As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive β convex polygon.
Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The *i*-th rod is a segment of length *l**i*.
The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle .
Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing.
Help sculptor! | The first line contains an integer *n* (3<=β€<=*n*<=β€<=105) β a number of rod-blanks.
The second line contains *n* integers *l**i* (1<=β€<=*l**i*<=β€<=109) β lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso already has. | Print the only integer *z* β the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods. | [
"3\n1 2 1\n",
"5\n20 4 3 2 1\n"
] | [
"1\n",
"11\n"
] | In the first example triangle with sides {1β+β1β=β2,β2,β1} can be formed from a set of lengths {1,β1,β1,β2}.
In the second example you can make a triangle with lengths {20,β11,β4β+β3β+β2β+β1β=β10}. | [
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n20 4 3 2 1",
"output": "11"
},
{
"input": "7\n77486105 317474713 89523018 332007362 7897847 949616701 54820086",
"output": "70407571"
},
{
"input": "14\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 88059371 53742651 8489205 3528194",
"output": "360142248"
},
{
"input": "19\n479740 7703374 196076708 180202968 579604 17429 16916 11989886 30832424 6384983 8937497 431 62955 48167457 898566333 29534955 1485775 848444 372839845",
"output": "2404943"
},
{
"input": "35\n306260 278 43508628 54350745 222255 842526 39010821 10627 14916465 3059978 61449 503809 2820 1609513 196062 65695 270869 15079297 2885093 189306 4682268 422616382 1642346 82340 6 2 975464673 1388191 70110665 272855 253160079 1849635 7837751 274070 10394",
"output": "34445194"
},
{
"input": "53\n1014364 40727 75774 243769 314 406417 5272684 14138 10640282 64955 2763 5667043 2121887 204672692 567643 60183 5183 11361359 2792918 199155 174809 16182540 21 392221 19434423 9140891 159733 15438 67903 3816799 616 429181 30392293 413992581 10847741 20771 16366654 1163 414283 156163 55907108 310278 95949614 185865 976650886 197610 87 61264 4586815 107764 26390852 331828 541",
"output": "25390787"
},
{
"input": "3\n1 1 1000000000",
"output": "999999999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 1000000000",
"output": "999999956"
},
{
"input": "5\n100000000 100000000 100000000 100000000 500000000",
"output": "100000001"
},
{
"input": "3\n300000000 300000000 600000000",
"output": "1"
},
{
"input": "5\n10 4 3 2 1",
"output": "1"
},
{
"input": "3\n800000000 1 1",
"output": "799999999"
},
{
"input": "3\n1000000000 1 1",
"output": "999999999"
}
] | 46 | 5,120,000 | 0 | 873 |
|
232 | Cycles | [
"binary search",
"constructive algorithms",
"graphs",
"greedy"
] | null | null | John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly *k* cycles of length 3.
A cycle of length 3 is an unordered group of three distinct graph vertices *a*, *b* and *c*, such that each pair of them is connected by a graph edge.
John has been painting for long, but he has not been a success. Help him find such graph. Note that the number of vertices there shouldn't exceed 100, or else John will have problems painting it. | A single line contains an integer *k* (1<=β€<=*k*<=β€<=105) β the number of cycles of length 3 in the required graph. | In the first line print integer *n* (3<=β€<=*n*<=β€<=100) β the number of vertices in the found graph. In each of next *n* lines print *n* characters "0" and "1": the *i*-th character of the *j*-th line should equal "0", if vertices *i* and *j* do not have an edge between them, otherwise it should equal "1". Note that as the required graph is undirected, the *i*-th character of the *j*-th line must equal the *j*-th character of the *i*-th line. The graph shouldn't contain self-loops, so the *i*-th character of the *i*-th line must equal "0" for all *i*. | [
"1\n",
"10\n"
] | [
"3\n011\n101\n110\n",
"5\n01111\n10111\n11011\n11101\n11110\n"
] | none | [
{
"input": "1",
"output": "3\n011\n101\n110"
},
{
"input": "10",
"output": "5\n01111\n10111\n11011\n11101\n11110"
},
{
"input": "2",
"output": "4\n0111\n1011\n1100\n1100"
},
{
"input": "3",
"output": "5\n01001\n10111\n01001\n01001\n11110"
},
{
"input": "4",
"output": "4\n0111\n1011\n1101\n1110"
},
{
"input": "5",
"output": "5\n01001\n10111\n01011\n01101\n11110"
},
{
"input": "6",
"output": "6\n010010\n101111\n010110\n011010\n111101\n010010"
},
{
"input": "7",
"output": "5\n01011\n10111\n01011\n11101\n11110"
},
{
"input": "8",
"output": "6\n010110\n101111\n010110\n111010\n111101\n010010"
},
{
"input": "9",
"output": "7\n0101100\n1011111\n0100100\n1100101\n1111011\n0100100\n0101100"
},
{
"input": "12",
"output": "7\n0101101\n1011111\n0100100\n1100101\n1111011\n0100100\n1101100"
},
{
"input": "29257",
"output": "60\n011111011111111111111110111111111111111111111111101111111111\n101111111111111111111111111111111111111111111111111111111111\n110111011111111111111111111111111111111111111111101111111111\n111011011111111111111110111111111111111111111111101111111111\n111101111111111111111111111111111111111111111111111111111111\n111110011111111111111110111111111111111111111111101111111111\n010010000000000000000000000000100000010000000000000000000000\n111111001111111111111110111111111111111111111111101111111111\n11111101011..."
},
{
"input": "99990",
"output": "90\n011111110111111111111111111111111111110111111111111111111111111111111110111111011111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111110111111111111111111111111111111110111111011111111111\n111011110111111111111111111111111111110111111111111111111111111111111110111111011111110111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111011111111..."
},
{
"input": "99000",
"output": "90\n011111110111111111111111111111111111110111111111111111111111111111111110111111011111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111110111111111111111111111111111111110111111011111111111\n111011110111111111111111111111111111110111111111111111111111111111111110111111011111110111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111011111111..."
},
{
"input": "99001",
"output": "86\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11101111011111111111111111111111111111111111111111111111111111111111111111111111111111\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "99002",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99003",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99004",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99005",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99006",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111011\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99007",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99008",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99009",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111011\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99010",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99011",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99012",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99013",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111011\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99014",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99015",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111011\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99016",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99017",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99018",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111011\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99019",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99020",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111011\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99021",
"output": "90\n011111110111111111111111111111111111110111111111111111111111111111111110111111011111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111110111111111111111111111111111111110111111011111111111\n111011110111111111111111111111111111110111111111111111111111111111111110111111011111110111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111011111111..."
},
{
"input": "99022",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99023",
"output": "86\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11101111011111111111111111111111111111111111111111111111111111111111111111111111111111\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "99024",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99025",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "98770",
"output": "85\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "100000",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99999",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "97560",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "98685",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99994",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "19",
"output": "7\n0101101\n1011111\n0101100\n1110111\n1111011\n0101101\n1101110"
}
] | 156 | 102,400 | 3 | 874 |
|
342 | Xenia and Divisors | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divides *c*.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has groups of three.
Help Xenia, find the required partition or else say that it doesn't exist. | The first line contains integer *n* (3<=β€<=*n*<=β€<=99999) β the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "9\n1 3 6 6 3 1 3 1 6",
"output": "1 3 6\n1 3 6\n1 3 6"
},
{
"input": "6\n1 2 4 1 3 5",
"output": "-1"
},
{
"input": "3\n1 3 7",
"output": "-1"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "9\n1 2 4 1 2 4 1 3 6",
"output": "1 2 4\n1 2 4\n1 3 6"
},
{
"input": "12\n3 6 1 1 3 6 1 1 2 6 2 6",
"output": "1 3 6\n1 3 6\n1 2 6\n1 2 6"
},
{
"input": "9\n1 1 1 4 4 4 6 2 2",
"output": "-1"
},
{
"input": "9\n1 2 4 6 3 1 3 1 5",
"output": "-1"
},
{
"input": "15\n2 1 2 1 3 6 1 2 1 6 1 3 4 6 4",
"output": "1 2 4\n1 2 4\n1 3 6\n1 3 6\n1 2 6"
},
{
"input": "3\n2 3 6",
"output": "-1"
},
{
"input": "3\n2 4 6",
"output": "-1"
},
{
"input": "3\n2 5 6",
"output": "-1"
},
{
"input": "3\n2 4 7",
"output": "-1"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "-1"
},
{
"input": "3\n7 7 7",
"output": "-1"
},
{
"input": "6\n1 2 4 7 7 7",
"output": "-1"
},
{
"input": "6\n1 1 2 6 6 6",
"output": "-1"
},
{
"input": "9\n1 1 1 3 3 2 4 4 6",
"output": "-1"
},
{
"input": "6\n1 2 4 5 5 5",
"output": "-1"
},
{
"input": "15\n1 1 1 1 1 2 2 2 2 4 4 6 6 6 6",
"output": "-1"
},
{
"input": "6\n1 1 5 5 7 7",
"output": "-1"
},
{
"input": "9\n1 1 1 2 3 4 5 6 7",
"output": "-1"
},
{
"input": "6\n1 1 4 4 7 7",
"output": "-1"
},
{
"input": "24\n1 1 1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 4 4 4 6 6 6",
"output": "-1"
},
{
"input": "3\n1 7 6",
"output": "-1"
},
{
"input": "6\n1 1 2 4 7 7",
"output": "-1"
},
{
"input": "9\n1 1 1 7 7 7 7 7 7",
"output": "-1"
},
{
"input": "9\n1 1 1 2 3 4 6 5 5",
"output": "-1"
}
] | 46 | 0 | 0 | 875 |
|
559 | Gerald's Hexagon | [
"brute force",
"geometry",
"math"
] | null | null | Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles. | The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=β€<=*a**i*<=β€<=1000) β the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists. | Print a single integer β the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. | [
"1 1 1 1 1 1\n",
"1 2 1 2 1 2\n"
] | [
"6\n",
"13\n"
] | This is what Gerald's hexagon looks like in the first sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's what it looks like in the second sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [
{
"input": "1 1 1 1 1 1",
"output": "6"
},
{
"input": "1 2 1 2 1 2",
"output": "13"
},
{
"input": "2 4 5 3 3 6",
"output": "83"
},
{
"input": "45 19 48 18 46 21",
"output": "6099"
},
{
"input": "66 6 65 6 66 5",
"output": "5832"
},
{
"input": "7 5 4 8 4 5",
"output": "175"
},
{
"input": "3 2 1 4 1 2",
"output": "25"
},
{
"input": "7 1 7 3 5 3",
"output": "102"
},
{
"input": "9 2 9 3 8 3",
"output": "174"
},
{
"input": "1 6 1 5 2 5",
"output": "58"
},
{
"input": "41 64 48 61 44 68",
"output": "17488"
},
{
"input": "1 59 2 59 1 60",
"output": "3838"
},
{
"input": "30 36 36 32 34 38",
"output": "7052"
},
{
"input": "50 40 46 38 52 34",
"output": "11176"
},
{
"input": "4 60 4 60 4 60",
"output": "4576"
},
{
"input": "718 466 729 470 714 481",
"output": "2102808"
},
{
"input": "131 425 143 461 95 473",
"output": "441966"
},
{
"input": "125 7 128 8 124 11",
"output": "20215"
},
{
"input": "677 303 685 288 692 296",
"output": "1365807"
},
{
"input": "1 577 7 576 2 582",
"output": "342171"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "6000000"
},
{
"input": "1 1 1000 1 1 1000",
"output": "4002"
},
{
"input": "1000 1000 1 1000 1000 1",
"output": "2004000"
},
{
"input": "1000 1 1000 999 2 999",
"output": "2003997"
},
{
"input": "1 1000 1 1 1000 1",
"output": "4002"
},
{
"input": "888 888 888 887 889 887",
"output": "4729487"
}
] | 155 | 0 | 3 | 876 |
|
719 | Anatoly and Cockroaches | [
"greedy"
] | null | null | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate. | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=100<=000)Β β the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. | Print one integerΒ β the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. | [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0. | [
{
"input": "5\nrbbrr",
"output": "1"
},
{
"input": "5\nbbbbb",
"output": "2"
},
{
"input": "3\nrbr",
"output": "0"
},
{
"input": "13\nrbbbrbrrbrrbb",
"output": "3"
},
{
"input": "18\nrrrrrrrrrrrrrrrrrb",
"output": "8"
},
{
"input": "100\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbrbbbbbbbbbbbbbbbbrrrrbbbbrrrbbbbbbbrbrrbrbbbbrrrbbbbrbbrbbbrb",
"output": "34"
},
{
"input": "166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbbbbrbrbbbbbbbbbbbrbbbbbbbbbbbbbbrbbbbbbbbbbbbbbbbbbbbbb",
"output": "70"
},
{
"input": "1\nr",
"output": "0"
},
{
"input": "1\nb",
"output": "0"
},
{
"input": "2\nrb",
"output": "0"
},
{
"input": "2\nbr",
"output": "0"
},
{
"input": "2\nrr",
"output": "1"
},
{
"input": "2\nbb",
"output": "1"
},
{
"input": "8\nrbbrbrbr",
"output": "1"
},
{
"input": "7\nrrbrbrb",
"output": "1"
}
] | 124 | 409,600 | 3 | 877 |
|
275 | Lights Out | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=Γ<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{
"input": "24 54 37\n60 63 6\n1 84 26",
"output": "110\n101\n011"
},
{
"input": "23 10 40\n15 6 40\n92 80 77",
"output": "101\n100\n000"
},
{
"input": "62 74 80\n95 74 93\n2 47 95",
"output": "010\n001\n110"
},
{
"input": "80 83 48\n26 0 66\n47 76 37",
"output": "000\n000\n010"
},
{
"input": "32 15 65\n7 54 36\n5 51 3",
"output": "111\n101\n001"
},
{
"input": "22 97 12\n71 8 24\n100 21 64",
"output": "100\n001\n100"
},
{
"input": "46 37 13\n87 0 50\n90 8 55",
"output": "111\n011\n000"
},
{
"input": "57 43 58\n20 82 83\n66 16 52",
"output": "111\n010\n110"
},
{
"input": "45 56 93\n47 51 59\n18 51 63",
"output": "101\n011\n100"
},
{
"input": "47 66 67\n14 1 37\n27 81 69",
"output": "001\n001\n110"
},
{
"input": "26 69 69\n85 18 23\n14 22 74",
"output": "110\n001\n010"
},
{
"input": "10 70 65\n94 27 25\n74 66 30",
"output": "111\n010\n100"
},
{
"input": "97 1 74\n15 99 1\n88 68 86",
"output": "001\n011\n000"
},
{
"input": "36 48 42\n45 41 66\n26 64 1",
"output": "001\n111\n010"
},
{
"input": "52 81 97\n29 77 71\n66 11 2",
"output": "100\n100\n111"
},
{
"input": "18 66 33\n19 49 49\n48 46 26",
"output": "011\n100\n000"
},
{
"input": "68 79 52\n51 39 100\n29 14 26",
"output": "110\n000\n111"
},
{
"input": "91 69 77\n91 26 64\n91 88 57",
"output": "001\n011\n110"
},
{
"input": "16 69 64\n48 21 80\n81 51 51",
"output": "010\n101\n111"
},
{
"input": "96 14 2\n100 18 12\n65 34 89",
"output": "111\n010\n010"
},
{
"input": "93 95 90\n8 59 42\n53 13 19",
"output": "100\n001\n111"
},
{
"input": "71 84 18\n100 19 67\n9 76 15",
"output": "010\n010\n001"
},
{
"input": "38 93 85\n21 88 64\n4 96 25",
"output": "111\n011\n000"
},
{
"input": "75 20 20\n60 5 78\n77 4 69",
"output": "011\n001\n000"
},
{
"input": "65 70 96\n19 6 83\n33 37 82",
"output": "100\n000\n011"
},
{
"input": "11 13 60\n17 13 46\n42 21 39",
"output": "000\n011\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 0",
"output": "111\n111\n111"
},
{
"input": "0 0 0\n0 1 0\n0 0 0",
"output": "101\n000\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 1",
"output": "111\n110\n100"
}
] | 62 | 6,963,200 | 3 | 879 |
|
754 | Ilya and tic-tac-toe game | [
"brute force",
"implementation"
] | null | null | Ilya is an experienced player in tic-tac-toe on the 4<=Γ<=4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4<=Γ<=4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal). | The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn. | Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise. | [
"xx..\n.oo.\nx...\noox.\n",
"x.ox\nox..\nx.o.\noo.x\n",
"x..x\n..oo\no...\nx.xo\n",
"o.x.\no...\n.x..\nooxx\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | [
{
"input": "xx..\n.oo.\nx...\noox.",
"output": "YES"
},
{
"input": "x.ox\nox..\nx.o.\noo.x",
"output": "NO"
},
{
"input": "x..x\n..oo\no...\nx.xo",
"output": "YES"
},
{
"input": "o.x.\no...\n.x..\nooxx",
"output": "NO"
},
{
"input": ".xox\no.x.\nx.o.\n..o.",
"output": "YES"
},
{
"input": "o.oo\n.x.o\nx.x.\n.x..",
"output": "YES"
},
{
"input": "xxox\no.x.\nx.oo\nxo.o",
"output": "YES"
},
{
"input": ".xox\n.x..\nxoo.\noox.",
"output": "NO"
},
{
"input": "...x\n.x.o\n.o..\n.x.o",
"output": "NO"
},
{
"input": "oo.x\nxo.o\no.xx\n.oxx",
"output": "YES"
},
{
"input": ".x.o\n..o.\n..ox\nxox.",
"output": "NO"
},
{
"input": "....\n.x..\nx...\n..oo",
"output": "YES"
},
{
"input": "....\n....\n.x.o\n..xo",
"output": "YES"
},
{
"input": "o..o\nx..x\n.o.x\nxo..",
"output": "YES"
},
{
"input": "ox.o\nx..x\nx..o\noo.x",
"output": "NO"
},
{
"input": ".xox\n.x.o\nooxo\n..x.",
"output": "YES"
},
{
"input": "x..o\no..o\n..x.\nx.xo",
"output": "YES"
},
{
"input": "xxoo\no.oo\n...x\nx..x",
"output": "NO"
},
{
"input": "xoox\n.xx.\no..o\n..xo",
"output": "YES"
},
{
"input": "..o.\nxxox\n....\n.oxo",
"output": "YES"
},
{
"input": "xoox\nxxox\noo..\n.ox.",
"output": "YES"
},
{
"input": "..ox\n.o..\nx..o\n.oxx",
"output": "NO"
},
{
"input": ".oo.\n.x..\nx...\nox..",
"output": "YES"
},
{
"input": "o.xx\nxo.o\n...o\n..x.",
"output": "YES"
},
{
"input": "x...\n.ox.\n.oo.\n.xox",
"output": "NO"
},
{
"input": "xoxx\n..x.\no.oo\nx.o.",
"output": "YES"
},
{
"input": ".x.x\n.o.o\no.xx\nx.oo",
"output": "YES"
},
{
"input": "...o\nxo.x\n.x..\nxoo.",
"output": "YES"
},
{
"input": "o...\n...o\noxx.\n.xxo",
"output": "YES"
},
{
"input": "xxox\no..o\nx..o\noxox",
"output": "NO"
},
{
"input": "x.x.\nox.o\n.o.o\nxox.",
"output": "YES"
},
{
"input": "xxo.\n...x\nooxx\n.o.o",
"output": "YES"
},
{
"input": "xoxo\no..x\n.xo.\nox..",
"output": "YES"
},
{
"input": ".o..\nox..\n.o.x\n.x..",
"output": "NO"
},
{
"input": ".oxo\nx...\n.o..\n.xox",
"output": "NO"
},
{
"input": ".oxx\n..o.\n.o.x\n.ox.",
"output": "YES"
},
{
"input": ".xxo\n...o\n..ox\nox..",
"output": "YES"
},
{
"input": "x...\nxo..\noxo.\n..ox",
"output": "NO"
},
{
"input": "xoxo\nx.ox\n....\noxo.",
"output": "YES"
},
{
"input": "x..o\nxo.x\no.xo\nxoox",
"output": "NO"
},
{
"input": ".x..\no..x\n.oo.\nxox.",
"output": "NO"
},
{
"input": "xxox\no.x.\nxo.o\nxo.o",
"output": "NO"
},
{
"input": ".xo.\nx.oo\n...x\n.o.x",
"output": "NO"
},
{
"input": "ox.o\n...x\n..oo\nxxox",
"output": "NO"
},
{
"input": "oox.\nxoo.\no.x.\nx..x",
"output": "NO"
},
{
"input": "oxox\nx.oo\nooxx\nxxo.",
"output": "NO"
},
{
"input": "....\nxo.x\n..x.\noo..",
"output": "NO"
},
{
"input": ".ox.\nx..o\nxo.x\noxo.",
"output": "YES"
},
{
"input": ".xox\nxo..\n..oo\n.x..",
"output": "NO"
},
{
"input": "xxo.\n.oo.\n..x.\n..xo",
"output": "NO"
},
{
"input": "ox..\n..oo\n..x.\nxxo.",
"output": "NO"
},
{
"input": "xxo.\nx..x\noo.o\noxox",
"output": "YES"
},
{
"input": "xx..\noxxo\nxo.o\noox.",
"output": "YES"
},
{
"input": "x..o\no..o\no..x\nxxox",
"output": "NO"
},
{
"input": "oxo.\nxx.x\nooxx\n.o.o",
"output": "YES"
},
{
"input": ".o.x\no..o\nx..x\n..xo",
"output": "NO"
},
{
"input": "xo..\n....\nx...\n..o.",
"output": "YES"
},
{
"input": ".x..\no...\n...x\n.o..",
"output": "YES"
},
{
"input": "...x\n....\n.x.o\n..o.",
"output": "YES"
},
{
"input": "o..x\n....\n...x\n..o.",
"output": "YES"
},
{
"input": ".oo.\nx...\n....\n..x.",
"output": "YES"
},
{
"input": ".o..\n.x..\n..o.\n.x..",
"output": "YES"
},
{
"input": "..o.\n.x..\n....\no..x",
"output": "YES"
},
{
"input": "..o.\n..x.\n....\n.ox.",
"output": "YES"
},
{
"input": ".o..\no..x\n....\n.x..",
"output": "YES"
},
{
"input": "....\n..ox\n....\n.o.x",
"output": "YES"
},
{
"input": ".o..\n....\no...\nx.x.",
"output": "YES"
},
{
"input": "....\n.o..\n....\nox.x",
"output": "YES"
},
{
"input": "oxo.\nxxox\noo.o\nxoxx",
"output": "YES"
},
{
"input": ".xx.\n...x\noo.o\no..x",
"output": "YES"
},
{
"input": "x...\n.x..\n....\noo..",
"output": "YES"
},
{
"input": "oxox\n..ox\nxoxo\nxoxo",
"output": "YES"
},
{
"input": "....\n...x\n...x\noo..",
"output": "YES"
}
] | 93 | 4,915,200 | 0 | 881 |
|
967 | Watering System | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes $s_1, s_2, \ldots, s_n$. In other words, if the sum of sizes of non-blocked holes is $S$, and the $i$-th hole is not blocked, $\frac{s_i \cdot A}{S}$ liters of water will flow out of it.
What is the minimum number of holes Arkady should block to make at least $B$ liters of water flow out of the first hole? | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$)Β β the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)Β β the sizes of the holes. | Print a single integerΒ β the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not less than $20$.
In the third example Arkady has to block all holes except the first to make all water flow out of the first hole. | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 96",
"output": "8"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "1 2 1\n1",
"output": "0"
},
{
"input": "2 2 2\n1 10000",
"output": "1"
},
{
"input": "2 10000 1\n1 9999",
"output": "0"
}
] | 1,000 | 12,288,000 | 0 | 888 |
|
55 | Smallest number | [
"brute force"
] | B. Smallest number | 2 | 256 | Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. | First line contains four integers separated by space: 0<=β€<=*a*,<=*b*,<=*c*,<=*d*<=β€<=1000 β the original numbers. Second line contains three signs ('+' or '*' each) separated by space β the sequence of the operations in the order of performing. ('+' stands for addition, '*' β multiplication) | Output one integer number β the minimal result which can be obtained.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). | [
"1 1 1 1\n+ + *\n",
"2 2 2 2\n* * +\n",
"1 2 3 4\n* + +\n"
] | [
"3\n",
"8\n",
"9\n"
] | none | [
{
"input": "1 1 1 1\n+ + *",
"output": "3"
},
{
"input": "2 2 2 2\n* * +",
"output": "8"
},
{
"input": "1 2 3 4\n* + +",
"output": "9"
},
{
"input": "15 1 3 1\n* * +",
"output": "18"
},
{
"input": "8 1 7 14\n+ + +",
"output": "30"
},
{
"input": "7 17 3 25\n+ * +",
"output": "63"
},
{
"input": "13 87 4 17\n* * *",
"output": "76908"
},
{
"input": "7 0 8 15\n+ + *",
"output": "0"
},
{
"input": "52 0 43 239\n+ + +",
"output": "334"
},
{
"input": "1000 1000 999 1000\n* * *",
"output": "999000000000"
},
{
"input": "720 903 589 804\n* * *",
"output": "307887168960"
},
{
"input": "631 149 496 892\n* * +",
"output": "445884"
},
{
"input": "220 127 597 394\n* + +",
"output": "28931"
},
{
"input": "214 862 466 795\n+ + +",
"output": "2337"
},
{
"input": "346 290 587 525\n* * *",
"output": "30922279500"
},
{
"input": "323 771 559 347\n+ * *",
"output": "149067730"
},
{
"input": "633 941 836 254\n* + +",
"output": "162559"
},
{
"input": "735 111 769 553\n+ * *",
"output": "92320032"
},
{
"input": "622 919 896 120\n* * +",
"output": "667592"
},
{
"input": "652 651 142 661\n+ + +",
"output": "2106"
},
{
"input": "450 457 975 35\n* * *",
"output": "7017806250"
},
{
"input": "883 954 804 352\n* * +",
"output": "1045740"
},
{
"input": "847 206 949 358\n* + *",
"output": "62660050"
},
{
"input": "663 163 339 76\n+ + +",
"output": "1241"
},
{
"input": "990 330 253 553\n+ * +",
"output": "85033"
},
{
"input": "179 346 525 784\n* * *",
"output": "25492034400"
},
{
"input": "780 418 829 778\n+ + *",
"output": "997766"
},
{
"input": "573 598 791 124\n* * *",
"output": "33608874936"
},
{
"input": "112 823 202 223\n* * +",
"output": "137222"
},
{
"input": "901 166 994 315\n* + *",
"output": "47278294"
},
{
"input": "393 342 840 486\n+ * *",
"output": "178222356"
},
{
"input": "609 275 153 598\n+ + *",
"output": "226746"
},
{
"input": "56 828 386 57\n+ * *",
"output": "3875088"
},
{
"input": "944 398 288 986\n+ + *",
"output": "670464"
},
{
"input": "544 177 162 21\n+ + *",
"output": "18543"
},
{
"input": "105 238 316 265\n+ + +",
"output": "924"
},
{
"input": "31 353 300 911\n* * *",
"output": "2990721900"
},
{
"input": "46 378 310 194\n* * +",
"output": "77528"
},
{
"input": "702 534 357 657\n+ * *",
"output": "259077042"
},
{
"input": "492 596 219 470\n+ + *",
"output": "341202"
},
{
"input": "482 842 982 902\n+ * +",
"output": "407728"
},
{
"input": "827 578 394 351\n* * *",
"output": "66105361764"
},
{
"input": "901 884 426 451\n* + *",
"output": "170223210"
},
{
"input": "210 295 12 795\n* * +",
"output": "71490"
},
{
"input": "40 734 948 202\n+ * *",
"output": "13590560"
},
{
"input": "136 611 963 195\n+ + *",
"output": "240584"
},
{
"input": "695 74 871 760\n+ * +",
"output": "53061"
},
{
"input": "666 884 772 54\n* + +",
"output": "37620"
},
{
"input": "975 785 753 224\n+ * +",
"output": "170432"
},
{
"input": "35 187 126 596\n+ + +",
"output": "944"
},
{
"input": "243 386 431 35\n* + *",
"output": "3298015"
},
{
"input": "229 602 133 635\n* * +",
"output": "222313"
},
{
"input": "916 207 238 891\n+ + *",
"output": "423315"
},
{
"input": "922 145 883 357\n+ + *",
"output": "313490"
},
{
"input": "69 355 762 111\n* + +",
"output": "8776"
},
{
"input": "209 206 34 67\n* + *",
"output": "476374"
},
{
"input": "693 824 375 361\n* * +",
"output": "557339"
},
{
"input": "45 712 635 467\n* + +",
"output": "22362"
},
{
"input": "426 283 179 211\n+ + +",
"output": "1099"
},
{
"input": "802 387 686 12\n+ + +",
"output": "1887"
}
] | 92 | 102,400 | 0 | 892 |
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"
}
] | 1,000 | 5,222,400 | 0 | 893 |
|
250 | Restoring IPv6 | [
"implementation",
"strings"
] | null | null | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons β 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef". We'll call such format of recording an IPv6-address full.
Besides the full record of an IPv6 address there is a short record format. The record of an IPv6 address can be shortened by removing one or more leading zeroes at the beginning of each block. However, each block should contain at least one digit in the short format. For example, the leading zeroes can be removed like that: "a56f:00d3:0000:0124:0001:f19a:1000:0000" <=β<= "a56f:d3:0:0124:01:f19a:1000:00". There are more ways to shorten zeroes in this IPv6 address.
Some IPv6 addresses contain long sequences of zeroes. Continuous sequences of 16-bit zero blocks can be shortened to "::". A sequence can consist of one or several consecutive blocks, with all 16 bits equal to 0.
You can see examples of zero block shortenings below:
- "a56f:00d3:0000:0124:0001:0000:0000:0000" <=β<= "a56f:00d3:0000:0124:0001::"; - "a56f:0000:0000:0124:0001:0000:1234:0ff0" <=β<= "a56f::0124:0001:0000:1234:0ff0"; - "a56f:0000:0000:0000:0001:0000:1234:0ff0" <=β<= "a56f:0000::0000:0001:0000:1234:0ff0"; - "a56f:00d3:0000:0124:0001:0000:0000:0000" <=β<= "a56f:00d3:0000:0124:0001::0000"; - "0000:0000:0000:0000:0000:0000:0000:0000" <=β<= "::".
It is not allowed to shorten zero blocks in the address more than once. This means that the short record can't contain the sequence of characters "::" more than once. Otherwise, it will sometimes be impossible to determine the number of zero blocks, each represented by a double colon.
The format of the record of the IPv6 address after removing the leading zeroes and shortening the zero blocks is called short.
You've got several short records of IPv6 addresses. Restore their full record. | The first line contains a single integer *n* β the number of records to restore (1<=β€<=*n*<=β€<=100).
Each of the following *n* lines contains a string β the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described in the statement from some full IPv6 address. | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | [
"6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n"
] | [
"a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n"
] | none | [
{
"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0",
"output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000"
},
{
"input": "20\n0:0:9e39:9:b21:c9b:c:0\n0:0:0:0:0:a27:6b:cb0a\n2:7:4d:b:0:3:2:f401\n17:2dc6::0:89e3:0:dc:0\nca:4:0:0:d6:b999:e:0\n4af:553:b29:dd7:2:5b:0:7\n0:c981:8f:a4d:0:d4:0:f61\n0:0:1:0:dc33:0:1964:0\n84:da:0:6d6:0ecc:1:f:0\n4:fb:4d37:0:8c:4:4a52:24\nc:e:a:0:0:0:e:0\n0:3761:72ed:b7:3b0:ff7:fc:102\n5ae:8ca7:10::0:9b2:0:525a\n0::ab:8d64:86:767:2\ne6b:3cb:0:81ce:0ac4:11::1\n4:0:5238:7b:591d:ff15:0:e\n0:f9a5:0::118e:dde:0\n0:d4c:feb:b:10a:0:d:e\n0:0:0:ff38:b5d:a3c2:f3:0\n2:a:6:c50:83:4f:7f0d::",
"output": "0000:0000:9e39:0009:0b21:0c9b:000c:0000\n0000:0000:0000:0000:0000:0a27:006b:cb0a\n0002:0007:004d:000b:0000:0003:0002:f401\n0017:2dc6:0000:0000:89e3:0000:00dc:0000\n00ca:0004:0000:0000:00d6:b999:000e:0000\n04af:0553:0b29:0dd7:0002:005b:0000:0007\n0000:c981:008f:0a4d:0000:00d4:0000:0f61\n0000:0000:0001:0000:dc33:0000:1964:0000\n0084:00da:0000:06d6:0ecc:0001:000f:0000\n0004:00fb:4d37:0000:008c:0004:4a52:0024\n000c:000e:000a:0000:0000:0000:000e:0000\n0000:3761:72ed:00b7:03b0:0ff7:00fc:0102\n05ae:8ca7:0010:0000..."
},
{
"input": "10\n1::7\n0:0::1\n::1ed\n::30:44\n::eaf:ff:000b\n56fe::\ndf0:3df::\nd03:ab:0::\n85::0485:0\n::",
"output": "0001:0000:0000:0000:0000:0000:0000:0007\n0000:0000:0000:0000:0000:0000:0000:0001\n0000:0000:0000:0000:0000:0000:0000:01ed\n0000:0000:0000:0000:0000:0000:0030:0044\n0000:0000:0000:0000:0000:0eaf:00ff:000b\n56fe:0000:0000:0000:0000:0000:0000:0000\n0df0:03df:0000:0000:0000:0000:0000:0000\n0d03:00ab:0000:0000:0000:0000:0000:0000\n0085:0000:0000:0000:0000:0000:0485:0000\n0000:0000:0000:0000:0000:0000:0000:0000"
},
{
"input": "6\n0:00:000:0000::\n1:01:001:0001::\nf:0f:00f:000f::\n1:10:100:1000::\nf:f0:f00:f000::\nf:ff:fff:ffff::",
"output": "0000:0000:0000:0000:0000:0000:0000:0000\n0001:0001:0001:0001:0000:0000:0000:0000\n000f:000f:000f:000f:0000:0000:0000:0000\n0001:0010:0100:1000:0000:0000:0000:0000\n000f:00f0:0f00:f000:0000:0000:0000:0000\n000f:00ff:0fff:ffff:0000:0000:0000:0000"
},
{
"input": "3\n::\n::\n::",
"output": "0000:0000:0000:0000:0000:0000:0000:0000\n0000:0000:0000:0000:0000:0000:0000:0000\n0000:0000:0000:0000:0000:0000:0000:0000"
},
{
"input": "4\n1:2:3:4:5:6:7:8\n0:0:0:0:0:0:0:0\nf:0f:00f:000f:ff:0ff:00ff:fff\n0fff:0ff0:0f0f:f0f:0f0:f0f0:f00f:ff0f",
"output": "0001:0002:0003:0004:0005:0006:0007:0008\n0000:0000:0000:0000:0000:0000:0000:0000\n000f:000f:000f:000f:00ff:00ff:00ff:0fff\n0fff:0ff0:0f0f:0f0f:00f0:f0f0:f00f:ff0f"
}
] | 30 | 0 | -1 | 894 |
|
727 | Transformation: from A to B | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2Β·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10Β·*x*<=+<=1).
You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible.
Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*. | The first line contains two positive integers *a* and *b* (1<=β€<=*a*<=<<=*b*<=β€<=109)Β β the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k*Β β the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where:
- *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=<<=*i*<=β€<=*k*).
If there are multiple answers, print any of them. | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
{
"input": "1 1000000000",
"output": "NO"
},
{
"input": "999999999 1000000000",
"output": "NO"
},
{
"input": "1 2",
"output": "YES\n2\n1 2 "
},
{
"input": "1 536870912",
"output": "YES\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 "
},
{
"input": "11111 11111111",
"output": "YES\n4\n11111 111111 1111111 11111111 "
},
{
"input": "59139 946224",
"output": "YES\n5\n59139 118278 236556 473112 946224 "
},
{
"input": "9859 19718",
"output": "YES\n2\n9859 19718 "
},
{
"input": "25987 51974222",
"output": "YES\n5\n25987 259871 2598711 25987111 51974222 "
},
{
"input": "9411 188222222",
"output": "YES\n6\n9411 94111 941111 9411111 94111111 188222222 "
},
{
"input": "25539 510782222",
"output": "YES\n6\n25539 255391 2553911 25539111 255391111 510782222 "
},
{
"input": "76259 610072",
"output": "YES\n4\n76259 152518 305036 610072 "
},
{
"input": "92387 184774",
"output": "YES\n2\n92387 184774 "
},
{
"input": "8515 85151111",
"output": "YES\n5\n8515 85151 851511 8515111 85151111 "
},
{
"input": "91939 9193911",
"output": "YES\n3\n91939 919391 9193911 "
},
{
"input": "30518 610361",
"output": "YES\n3\n30518 61036 610361 "
},
{
"input": "46646 373168844",
"output": "YES\n7\n46646 466461 932922 9329221 93292211 186584422 373168844 "
},
{
"input": "30070 300701",
"output": "YES\n2\n30070 300701 "
},
{
"input": "13494 1079528",
"output": "YES\n5\n13494 134941 269882 539764 1079528 "
},
{
"input": "96918 775344422",
"output": "YES\n7\n96918 193836 1938361 3876722 38767221 387672211 775344422 "
},
{
"input": "13046 260921",
"output": "YES\n3\n13046 26092 260921 "
},
{
"input": "29174 5834811",
"output": "YES\n4\n29174 58348 583481 5834811 "
},
{
"input": "79894 319576421",
"output": "YES\n6\n79894 798941 1597882 15978821 31957642 319576421 "
},
{
"input": "96022 1920442",
"output": "YES\n3\n96022 960221 1920442 "
},
{
"input": "79446 6355681",
"output": "YES\n5\n79446 158892 317784 635568 6355681 "
},
{
"input": "5440 27853056",
"output": "YES\n11\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056 "
},
{
"input": "250000000 705032705",
"output": "NO"
},
{
"input": "17 35",
"output": "NO"
},
{
"input": "1 3",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
}
] | 186 | 9,318,400 | 3 | 896 |
|
492 | Vanya and Cubes | [
"implementation"
] | null | null | Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes.
Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes. | The first line contains integer *n* (1<=β€<=*n*<=β€<=104) β the number of cubes given to Vanya. | Print the maximum possible height of the pyramid in the single line. | [
"1\n",
"25\n"
] | [
"1\n",
"4\n"
] | Illustration to the second sample: | [
{
"input": "1",
"output": "1"
},
{
"input": "25",
"output": "4"
},
{
"input": "2",
"output": "1"
},
{
"input": "4115",
"output": "28"
},
{
"input": "9894",
"output": "38"
},
{
"input": "7969",
"output": "35"
},
{
"input": "6560",
"output": "33"
},
{
"input": "4",
"output": "2"
},
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "19",
"output": "3"
},
{
"input": "20",
"output": "4"
},
{
"input": "9880",
"output": "38"
},
{
"input": "9879",
"output": "37"
},
{
"input": "7770",
"output": "35"
},
{
"input": "7769",
"output": "34"
},
{
"input": "2925",
"output": "25"
},
{
"input": "220",
"output": "10"
},
{
"input": "219",
"output": "9"
},
{
"input": "3046",
"output": "25"
},
{
"input": "7590",
"output": "34"
},
{
"input": "1014",
"output": "17"
},
{
"input": "7142",
"output": "34"
},
{
"input": "9999",
"output": "38"
},
{
"input": "10000",
"output": "38"
}
] | 46 | 0 | 3 | 899 |
|
755 | PolandBall and Game | [
"binary search",
"data structures",
"games",
"greedy",
"sortings",
"strings"
] | null | null | PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally? | The first input line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=103)Β β number of words PolandBall and EnemyBall know, respectively.
Then *n* strings follow, one per lineΒ β words familiar to PolandBall.
Then *m* strings follow, one per lineΒ β words familiar to EnemyBall.
Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players.
Each word is non-empty and consists of no more than 500 lowercase English alphabet letters. | In a single line of print the answerΒ β "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. | [
"5 1\npolandball\nis\na\ncool\ncharacter\nnope\n",
"2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n",
"1 2\na\na\nb\n"
] | [
"YES",
"YES",
"NO"
] | In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | [
{
"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope",
"output": "YES"
},
{
"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska",
"output": "YES"
},
{
"input": "1 2\na\na\nb",
"output": "NO"
},
{
"input": "2 2\na\nb\nb\nc",
"output": "YES"
},
{
"input": "2 1\nc\na\na",
"output": "YES"
},
{
"input": "3 3\nab\nbc\ncd\ncd\ndf\nfg",
"output": "YES"
},
{
"input": "3 3\nc\na\nb\na\nd\ng",
"output": "YES"
},
{
"input": "1 1\naa\naa",
"output": "YES"
},
{
"input": "2 1\na\nb\na",
"output": "YES"
},
{
"input": "6 5\na\nb\nc\nd\ne\nf\nf\ne\nd\nz\ny",
"output": "YES"
},
{
"input": "3 2\na\nb\nc\nd\ne",
"output": "YES"
}
] | 187 | 5,120,000 | 3 | 901 |
|
784 | INTERCALC | [
"*special",
"implementation"
] | null | null | DO YOU EXPECT ME TO FIND THIS OUT?
WHAT BASE AND/XOR LANGUAGE INCLUDES string?
DON'T BYTE OF MORE THAN YOU CAN CHEW
YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR
SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD
THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!
I HAVE NO ARRAY AND I MUST SCREAM
ELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE | The first line of input data contains a single integer *n* (1<=β€<=*n*<=β€<=10).
The second line of input data contains *n* space-separated integers *a**i* (1<=β€<=*a**i*<=β€<=11). | Output a single integer. | [
"4\n2 5 3 1\n"
] | [
"4\n"
] | none | [
{
"input": "4\n2 5 3 1",
"output": "4"
},
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "1\n8",
"output": "0"
},
{
"input": "6\n1 1 1 3 2 9",
"output": "0"
},
{
"input": "5\n8 9 3 1 9",
"output": "0"
},
{
"input": "6\n1 5 2 1 7 11",
"output": "0"
},
{
"input": "8\n1 6 11 8 5 10 7 8",
"output": "3"
},
{
"input": "3\n4 9 6",
"output": "15"
},
{
"input": "2\n4 8",
"output": "0"
},
{
"input": "3\n1 1 5",
"output": "0"
},
{
"input": "5\n4 5 5 2 11",
"output": "0"
},
{
"input": "6\n1 7 2 8 8 2",
"output": "10"
},
{
"input": "5\n3 9 3 2 3",
"output": "10"
},
{
"input": "7\n6 6 1 1 1 2 3",
"output": "5"
},
{
"input": "7\n11 1 2 8 10 5 9",
"output": "2"
},
{
"input": "7\n4 5 1 10 10 4 1",
"output": "11"
},
{
"input": "10\n5 5 10 10 10 2 4 3 4 10",
"output": "0"
},
{
"input": "8\n4 7 11 3 11 3 1 1",
"output": "10"
},
{
"input": "2\n5 9",
"output": "0"
},
{
"input": "6\n2 1 10 2 7 5",
"output": "15"
},
{
"input": "6\n3 5 9 10 5 4",
"output": "14"
},
{
"input": "8\n3 5 8 10 3 4 2 10",
"output": "0"
},
{
"input": "7\n1 6 5 3 9 5 9",
"output": "0"
},
{
"input": "8\n7 2 6 3 6 4 1 8",
"output": "0"
},
{
"input": "10\n8 10 6 10 4 3 4 6 7 4",
"output": "14"
},
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "10\n5 6 4 8 11 4 10 4 8 4",
"output": "15"
},
{
"input": "2\n3 7",
"output": "0"
},
{
"input": "3\n4 10 3",
"output": "9"
},
{
"input": "5\n5 2 2 11 2",
"output": "9"
}
] | 46 | 4,608,000 | -1 | 906 |
|
572 | Order Book | [
"data structures",
"greedy",
"implementation",
"sortings"
] | null | null | In this task you need to process a set of stock exchange orders and use them to create order book.
An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i*, direction *d**i* β buy or sell, and integer *q**i*. This means that the participant is ready to buy or sell *q**i* stocks at price *p**i* for one stock. A value *q**i* is also known as a volume of an order.
All orders with the same price *p* and direction *d* are merged into one aggregated order with price *p* and direction *d*. The volume of such order is a sum of volumes of the initial orders.
An order book is a list of aggregated orders, the first part of which contains sell orders sorted by price in descending order, the second contains buy orders also sorted by price in descending order.
An order book of depth *s* contains *s* best aggregated orders for each direction. A buy order is better if it has higher price and a sell order is better if it has lower price. If there are less than *s* aggregated orders for some direction then all of them will be in the final order book.
You are given *n* stock exhange orders. Your task is to print order book of depth *s* for these orders. | The input starts with two positive integers *n* and *s* (1<=β€<=*n*<=β€<=1000,<=1<=β€<=*s*<=β€<=50), the number of orders and the book depth.
Next *n* lines contains a letter *d**i* (either 'B' or 'S'), an integer *p**i* (0<=β€<=*p**i*<=β€<=105) and an integer *q**i* (1<=β€<=*q**i*<=β€<=104) β direction, price and volume respectively. The letter 'B' means buy, 'S' means sell. The price of any sell order is higher than the price of any buy order. | Print no more than 2*s* lines with aggregated orders from order book of depth *s*. The output format for orders should be the same as in input. | [
"6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n"
] | [
"S 50 8\nS 40 1\nB 25 10\nB 20 4\n"
] | Denote (x, y) an order with price *x* and volume *y*. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample.
You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders. | [
{
"input": "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10",
"output": "S 50 8\nS 40 1\nB 25 10\nB 20 4"
},
{
"input": "2 1\nB 7523 5589\nS 69799 1711",
"output": "S 69799 1711\nB 7523 5589"
},
{
"input": "1 1\nB 48259 991",
"output": "B 48259 991"
},
{
"input": "1 50\nB 47828 7726",
"output": "B 47828 7726"
},
{
"input": "1 1\nS 95992 7257",
"output": "S 95992 7257"
},
{
"input": "1 50\nS 72218 8095",
"output": "S 72218 8095"
},
{
"input": "2 50\nB 758 9290\nS 86168 3367",
"output": "S 86168 3367\nB 758 9290"
},
{
"input": "3 3\nB 5878 1568\nS 60238 4895\nS 76276 1905",
"output": "S 76276 1905\nS 60238 4895\nB 5878 1568"
},
{
"input": "6 2\nB 0 1\nS 1 1\nS 1 1\nS 1 1\nB 0 1\nB 0 1",
"output": "S 1 3\nB 0 3"
},
{
"input": "2 2\nS 1 1\nB 0 2",
"output": "S 1 1\nB 0 2"
},
{
"input": "2 1\nS 10 1\nB 0 1",
"output": "S 10 1\nB 0 1"
},
{
"input": "2 10\nB 0 1\nS 100000 1",
"output": "S 100000 1\nB 0 1"
},
{
"input": "2 1\nS 1 1\nB 0 1",
"output": "S 1 1\nB 0 1"
},
{
"input": "2 1\nB 0 100\nS 1 100",
"output": "S 1 100\nB 0 100"
},
{
"input": "2 2\nB 0 3\nS 10 3",
"output": "S 10 3\nB 0 3"
},
{
"input": "2 10\nB 0 1\nS 1 1",
"output": "S 1 1\nB 0 1"
},
{
"input": "2 50\nB 2 5\nB 0 1",
"output": "B 2 5\nB 0 1"
}
] | 62 | 0 | 0 | 907 |
|
844 | Diversity | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=β€<=|*s*|<=β€<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=β€<=*k*<=β€<=26). | Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*',β'*h*',β'*o*',β'*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}.
In the third test case, it is impossible to make 7 different letters because the length of the string is 6. | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26",
"output": "14"
},
{
"input": "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26",
"output": "12"
},
{
"input": "a\n3",
"output": "impossible"
},
{
"input": "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1",
"output": "0"
},
{
"input": "cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\n4",
"output": "1"
},
{
"input": "fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\n20",
"output": "18"
},
{
"input": "swmkwaruyv\n5",
"output": "0"
},
{
"input": "tnbqpsuhkczmejirvyfdolxwga\n22",
"output": "0"
},
{
"input": "abcde\n3",
"output": "0"
},
{
"input": "abb\n1",
"output": "0"
},
{
"input": "aaaa\n1",
"output": "0"
},
{
"input": "abcde\n2",
"output": "0"
},
{
"input": "yandex\n4",
"output": "0"
},
{
"input": "aaabbbccc\n1",
"output": "0"
},
{
"input": "abcd\n2",
"output": "0"
},
{
"input": "asdfgh\n2",
"output": "0"
},
{
"input": "aab\n1",
"output": "0"
},
{
"input": "mynameissako\n5",
"output": "0"
},
{
"input": "abcde\n1",
"output": "0"
},
{
"input": "abcd\n3",
"output": "0"
},
{
"input": "abcdef\n2",
"output": "0"
},
{
"input": "abcdefg\n4",
"output": "0"
},
{
"input": "abc\n1",
"output": "0"
},
{
"input": "asdafjsgljdllgjdgkl\n5",
"output": "0"
},
{
"input": "yaay\n3",
"output": "1"
},
{
"input": "yaay\n4",
"output": "2"
},
{
"input": "zzzzzz\n2",
"output": "1"
}
] | 62 | 0 | 0 | 911 |
|
670 | Holidays | [
"brute force",
"constructive algorithms",
"greedy",
"math"
] | null | null | On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlingsΒ β 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. | The first line of the input contains a positive integer *n* (1<=β€<=*n*<=β€<=1<=000<=000)Β β the number of days in a year on Mars. | Print two integersΒ β the minimum possible and the maximum possible number of days off per year on Mars. | [
"14\n",
"2\n"
] | [
"4 4\n",
"0 2\n"
] | In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | [
{
"input": "14",
"output": "4 4"
},
{
"input": "2",
"output": "0 2"
},
{
"input": "1",
"output": "0 1"
},
{
"input": "3",
"output": "0 2"
},
{
"input": "4",
"output": "0 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "6",
"output": "1 2"
},
{
"input": "7",
"output": "2 2"
},
{
"input": "8",
"output": "2 3"
},
{
"input": "9",
"output": "2 4"
},
{
"input": "10",
"output": "2 4"
},
{
"input": "11",
"output": "2 4"
},
{
"input": "12",
"output": "2 4"
},
{
"input": "13",
"output": "3 4"
},
{
"input": "1000000",
"output": "285714 285715"
},
{
"input": "16",
"output": "4 6"
},
{
"input": "17",
"output": "4 6"
},
{
"input": "18",
"output": "4 6"
},
{
"input": "19",
"output": "4 6"
},
{
"input": "20",
"output": "5 6"
},
{
"input": "21",
"output": "6 6"
},
{
"input": "22",
"output": "6 7"
},
{
"input": "23",
"output": "6 8"
},
{
"input": "24",
"output": "6 8"
},
{
"input": "25",
"output": "6 8"
},
{
"input": "26",
"output": "6 8"
},
{
"input": "27",
"output": "7 8"
},
{
"input": "28",
"output": "8 8"
},
{
"input": "29",
"output": "8 9"
},
{
"input": "30",
"output": "8 10"
},
{
"input": "100",
"output": "28 30"
},
{
"input": "99",
"output": "28 29"
},
{
"input": "98",
"output": "28 28"
},
{
"input": "97",
"output": "27 28"
},
{
"input": "96",
"output": "26 28"
},
{
"input": "95",
"output": "26 28"
},
{
"input": "94",
"output": "26 28"
},
{
"input": "93",
"output": "26 28"
},
{
"input": "92",
"output": "26 27"
},
{
"input": "91",
"output": "26 26"
},
{
"input": "90",
"output": "25 26"
},
{
"input": "89",
"output": "24 26"
},
{
"input": "88",
"output": "24 26"
},
{
"input": "87",
"output": "24 26"
},
{
"input": "86",
"output": "24 26"
},
{
"input": "85",
"output": "24 25"
},
{
"input": "84",
"output": "24 24"
},
{
"input": "83",
"output": "23 24"
},
{
"input": "82",
"output": "22 24"
},
{
"input": "81",
"output": "22 24"
},
{
"input": "80",
"output": "22 24"
},
{
"input": "1000",
"output": "285 286"
},
{
"input": "999",
"output": "284 286"
},
{
"input": "998",
"output": "284 286"
},
{
"input": "997",
"output": "284 286"
},
{
"input": "996",
"output": "284 286"
},
{
"input": "995",
"output": "284 285"
},
{
"input": "994",
"output": "284 284"
},
{
"input": "993",
"output": "283 284"
},
{
"input": "992",
"output": "282 284"
},
{
"input": "991",
"output": "282 284"
},
{
"input": "990",
"output": "282 284"
},
{
"input": "989",
"output": "282 284"
},
{
"input": "988",
"output": "282 283"
},
{
"input": "987",
"output": "282 282"
},
{
"input": "986",
"output": "281 282"
},
{
"input": "985",
"output": "280 282"
},
{
"input": "984",
"output": "280 282"
},
{
"input": "983",
"output": "280 282"
},
{
"input": "982",
"output": "280 282"
},
{
"input": "981",
"output": "280 281"
},
{
"input": "980",
"output": "280 280"
},
{
"input": "10000",
"output": "2856 2858"
},
{
"input": "9999",
"output": "2856 2858"
},
{
"input": "9998",
"output": "2856 2858"
},
{
"input": "9997",
"output": "2856 2857"
},
{
"input": "9996",
"output": "2856 2856"
},
{
"input": "9995",
"output": "2855 2856"
},
{
"input": "9994",
"output": "2854 2856"
},
{
"input": "9993",
"output": "2854 2856"
},
{
"input": "9992",
"output": "2854 2856"
},
{
"input": "9991",
"output": "2854 2856"
},
{
"input": "9990",
"output": "2854 2855"
},
{
"input": "9989",
"output": "2854 2854"
},
{
"input": "9988",
"output": "2853 2854"
},
{
"input": "9987",
"output": "2852 2854"
},
{
"input": "9986",
"output": "2852 2854"
},
{
"input": "9985",
"output": "2852 2854"
},
{
"input": "9984",
"output": "2852 2854"
},
{
"input": "9983",
"output": "2852 2853"
},
{
"input": "9982",
"output": "2852 2852"
},
{
"input": "9981",
"output": "2851 2852"
},
{
"input": "9980",
"output": "2850 2852"
},
{
"input": "100000",
"output": "28570 28572"
},
{
"input": "99999",
"output": "28570 28572"
},
{
"input": "99998",
"output": "28570 28572"
},
{
"input": "99997",
"output": "28570 28572"
},
{
"input": "99996",
"output": "28570 28571"
},
{
"input": "99995",
"output": "28570 28570"
},
{
"input": "99994",
"output": "28569 28570"
},
{
"input": "99993",
"output": "28568 28570"
},
{
"input": "99992",
"output": "28568 28570"
},
{
"input": "99991",
"output": "28568 28570"
},
{
"input": "99990",
"output": "28568 28570"
},
{
"input": "99989",
"output": "28568 28569"
},
{
"input": "99988",
"output": "28568 28568"
},
{
"input": "99987",
"output": "28567 28568"
},
{
"input": "99986",
"output": "28566 28568"
},
{
"input": "99985",
"output": "28566 28568"
},
{
"input": "99984",
"output": "28566 28568"
},
{
"input": "99983",
"output": "28566 28568"
},
{
"input": "99982",
"output": "28566 28567"
},
{
"input": "99981",
"output": "28566 28566"
},
{
"input": "99980",
"output": "28565 28566"
},
{
"input": "999999",
"output": "285714 285714"
},
{
"input": "999998",
"output": "285713 285714"
},
{
"input": "999997",
"output": "285712 285714"
},
{
"input": "999996",
"output": "285712 285714"
},
{
"input": "999995",
"output": "285712 285714"
},
{
"input": "999994",
"output": "285712 285714"
},
{
"input": "999993",
"output": "285712 285713"
},
{
"input": "999992",
"output": "285712 285712"
},
{
"input": "999991",
"output": "285711 285712"
},
{
"input": "999990",
"output": "285710 285712"
},
{
"input": "999989",
"output": "285710 285712"
},
{
"input": "999988",
"output": "285710 285712"
},
{
"input": "999987",
"output": "285710 285712"
},
{
"input": "999986",
"output": "285710 285711"
},
{
"input": "999985",
"output": "285710 285710"
},
{
"input": "999984",
"output": "285709 285710"
},
{
"input": "999983",
"output": "285708 285710"
},
{
"input": "999982",
"output": "285708 285710"
},
{
"input": "999981",
"output": "285708 285710"
},
{
"input": "999980",
"output": "285708 285710"
},
{
"input": "234123",
"output": "66892 66893"
},
{
"input": "234122",
"output": "66892 66892"
},
{
"input": "234121",
"output": "66891 66892"
},
{
"input": "234120",
"output": "66890 66892"
},
{
"input": "234119",
"output": "66890 66892"
},
{
"input": "234118",
"output": "66890 66892"
},
{
"input": "234117",
"output": "66890 66892"
},
{
"input": "234116",
"output": "66890 66891"
},
{
"input": "234115",
"output": "66890 66890"
},
{
"input": "234114",
"output": "66889 66890"
},
{
"input": "234113",
"output": "66888 66890"
},
{
"input": "234112",
"output": "66888 66890"
},
{
"input": "234111",
"output": "66888 66890"
},
{
"input": "234110",
"output": "66888 66890"
},
{
"input": "234109",
"output": "66888 66889"
},
{
"input": "234108",
"output": "66888 66888"
},
{
"input": "234107",
"output": "66887 66888"
},
{
"input": "234106",
"output": "66886 66888"
},
{
"input": "234105",
"output": "66886 66888"
},
{
"input": "234104",
"output": "66886 66888"
},
{
"input": "234103",
"output": "66886 66888"
},
{
"input": "868531",
"output": "248151 248152"
},
{
"input": "868530",
"output": "248150 248152"
},
{
"input": "868529",
"output": "248150 248152"
},
{
"input": "868528",
"output": "248150 248152"
},
{
"input": "868527",
"output": "248150 248152"
},
{
"input": "868526",
"output": "248150 248151"
},
{
"input": "868525",
"output": "248150 248150"
},
{
"input": "868524",
"output": "248149 248150"
},
{
"input": "868523",
"output": "248148 248150"
},
{
"input": "868522",
"output": "248148 248150"
},
{
"input": "868521",
"output": "248148 248150"
},
{
"input": "868520",
"output": "248148 248150"
},
{
"input": "868519",
"output": "248148 248149"
},
{
"input": "868518",
"output": "248148 248148"
},
{
"input": "868517",
"output": "248147 248148"
},
{
"input": "868516",
"output": "248146 248148"
},
{
"input": "868515",
"output": "248146 248148"
},
{
"input": "868514",
"output": "248146 248148"
},
{
"input": "868513",
"output": "248146 248148"
},
{
"input": "868512",
"output": "248146 248147"
},
{
"input": "868511",
"output": "248146 248146"
},
{
"input": "123413",
"output": "35260 35262"
},
{
"input": "123412",
"output": "35260 35262"
},
{
"input": "123411",
"output": "35260 35261"
},
{
"input": "123410",
"output": "35260 35260"
},
{
"input": "123409",
"output": "35259 35260"
},
{
"input": "123408",
"output": "35258 35260"
},
{
"input": "123407",
"output": "35258 35260"
},
{
"input": "123406",
"output": "35258 35260"
},
{
"input": "123405",
"output": "35258 35260"
},
{
"input": "123404",
"output": "35258 35259"
},
{
"input": "123403",
"output": "35258 35258"
},
{
"input": "123402",
"output": "35257 35258"
},
{
"input": "123401",
"output": "35256 35258"
},
{
"input": "123400",
"output": "35256 35258"
},
{
"input": "123399",
"output": "35256 35258"
},
{
"input": "123398",
"output": "35256 35258"
},
{
"input": "123397",
"output": "35256 35257"
},
{
"input": "123396",
"output": "35256 35256"
},
{
"input": "123395",
"output": "35255 35256"
},
{
"input": "123394",
"output": "35254 35256"
},
{
"input": "123393",
"output": "35254 35256"
},
{
"input": "15",
"output": "4 5"
}
] | 46 | 0 | 0 | 914 |
|
614 | Gena's Code | [
"implementation",
"math"
] | null | null | It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!
There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful.
Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case. | The first line of the input contains the number of countries *n* (1<=β€<=*n*<=β€<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroesΒ β the number of tanks of the *i*-th country.
It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000. | Print a single number without leading zeroesΒ β the product of the number of tanks presented by each country. | [
"3\n5 10 1\n",
"4\n1 1 10 11\n",
"5\n0 3 1 100 1\n"
] | [
"50",
"110",
"0"
] | In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful. | [
{
"input": "3\n5 10 1",
"output": "50"
},
{
"input": "4\n1 1 10 11",
"output": "110"
},
{
"input": "5\n0 3 1 100 1",
"output": "0"
},
{
"input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100",
"output": "1824868942000000000000000000000000000000000000000000000000000"
},
{
"input": "6\n1000000000000000000000000000000000000 6643573784 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000",
"output": "6643573784000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n9",
"output": "9"
},
{
"input": "2\n10 50",
"output": "500"
},
{
"input": "3\n500 1 10",
"output": "5000"
}
] | 202 | 1,843,200 | 3 | 915 |
|
900 | Find Extra One | [
"geometry",
"implementation"
] | null | null | You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. | The first line contains a single positive integer *n* (2<=β€<=*n*<=β€<=105).
The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=β€<=109, *x**i*<=β <=0). No two points coincide. | Print "Yes" if there is such a point, "No" β otherwise.
You can print every letter in any case (upper or lower). | [
"3\n1 1\n-1 -1\n2 -1\n",
"4\n1 1\n2 2\n-1 1\n-2 2\n",
"3\n1 2\n2 1\n4 60\n"
] | [
"Yes",
"No",
"Yes"
] | In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed. | [
{
"input": "3\n1 1\n-1 -1\n2 -1",
"output": "Yes"
},
{
"input": "4\n1 1\n2 2\n-1 1\n-2 2",
"output": "No"
},
{
"input": "3\n1 2\n2 1\n4 60",
"output": "Yes"
},
{
"input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1",
"output": "Yes"
},
{
"input": "2\n1000000000 -1000000000\n1000000000 1000000000",
"output": "Yes"
},
{
"input": "23\n-1 1\n-1 2\n-2 4\n-7 -8\n-3 3\n-9 -14\n-5 3\n-6 2\n-7 11\n-4 4\n-8 5\n1 1\n-1 -1\n-1 -2\n-2 -4\n-7 8\n-3 -3\n-9 14\n-5 -3\n-6 -2\n-7 -11\n-4 -4\n-8 -5",
"output": "Yes"
},
{
"input": "4\n-1000000000 -1000000000\n1000000000 1000000000\n-1000000000 1000000000\n1000000000 -1000000000",
"output": "No"
},
{
"input": "2\n-1000000000 1000000000\n-1000000000 -1000000000",
"output": "Yes"
},
{
"input": "5\n-1 -1\n-2 2\n2 2\n2 -2\n3 2",
"output": "No"
},
{
"input": "2\n1 0\n-1 0",
"output": "Yes"
},
{
"input": "4\n-1 1\n-1 2\n-1 3\n-1 4",
"output": "Yes"
},
{
"input": "2\n-1 0\n1 0",
"output": "Yes"
},
{
"input": "2\n1 2\n-1 2",
"output": "Yes"
},
{
"input": "2\n8 0\n7 0",
"output": "Yes"
},
{
"input": "6\n-1 0\n-2 0\n-1 -1\n-1 5\n1 0\n1 1",
"output": "No"
},
{
"input": "4\n1 0\n2 0\n-1 0\n-2 0",
"output": "No"
},
{
"input": "4\n-2 0\n-1 0\n1 0\n2 0",
"output": "No"
},
{
"input": "2\n1 1\n-1 1",
"output": "Yes"
},
{
"input": "4\n-1 0\n-2 0\n1 0\n2 0",
"output": "No"
},
{
"input": "2\n4 3\n-4 -2",
"output": "Yes"
},
{
"input": "4\n1 0\n2 0\n-1 1\n-1 2",
"output": "No"
},
{
"input": "5\n1 1\n2 1\n3 1\n-1 1\n-2 1",
"output": "No"
},
{
"input": "2\n1 1\n-1 -1",
"output": "Yes"
},
{
"input": "4\n1 2\n1 0\n1 -2\n-1 2",
"output": "Yes"
},
{
"input": "5\n-2 3\n-3 3\n4 2\n3 2\n1 2",
"output": "No"
},
{
"input": "3\n2 0\n3 0\n4 0",
"output": "Yes"
},
{
"input": "5\n-3 1\n-2 1\n-1 1\n1 1\n2 1",
"output": "No"
},
{
"input": "4\n-3 0\n1 0\n2 0\n3 0",
"output": "Yes"
},
{
"input": "2\n1 0\n-1 1",
"output": "Yes"
},
{
"input": "3\n-1 0\n1 0\n2 0",
"output": "Yes"
},
{
"input": "5\n1 0\n3 0\n-1 0\n-6 0\n-4 1",
"output": "No"
},
{
"input": "5\n-1 2\n-2 2\n-3 1\n1 2\n2 3",
"output": "No"
},
{
"input": "3\n1 0\n-1 0\n-2 0",
"output": "Yes"
},
{
"input": "4\n1 0\n2 0\n3 1\n4 1",
"output": "Yes"
},
{
"input": "4\n1 0\n1 2\n1 3\n-1 5",
"output": "Yes"
},
{
"input": "4\n2 2\n2 5\n-2 3\n-2 0",
"output": "No"
},
{
"input": "4\n1 1\n-1 1\n-1 0\n-1 -1",
"output": "Yes"
},
{
"input": "4\n2 0\n3 0\n-3 -3\n-3 -4",
"output": "No"
},
{
"input": "4\n-1 0\n-2 0\n-3 0\n-4 0",
"output": "Yes"
},
{
"input": "2\n-1 1\n1 1",
"output": "Yes"
},
{
"input": "5\n1 1\n2 2\n3 3\n-4 -4\n-5 -5",
"output": "No"
},
{
"input": "5\n2 0\n3 0\n4 0\n5 0\n6 0",
"output": "Yes"
},
{
"input": "2\n-1 2\n1 2",
"output": "Yes"
},
{
"input": "4\n1 1\n2 1\n-3 0\n-4 0",
"output": "No"
},
{
"input": "4\n-1 0\n-2 0\n3 0\n4 0",
"output": "No"
},
{
"input": "3\n3 0\n2 0\n1 0",
"output": "Yes"
},
{
"input": "4\n-2 0\n-3 0\n1 -1\n3 1",
"output": "No"
},
{
"input": "3\n-1 -1\n1 1\n2 2",
"output": "Yes"
},
{
"input": "4\n-2 0\n-1 0\n2 0\n1 0",
"output": "No"
},
{
"input": "2\n-3 5\n3 5",
"output": "Yes"
},
{
"input": "2\n-1 5\n1 5",
"output": "Yes"
},
{
"input": "4\n2 0\n3 0\n-2 0\n-3 0",
"output": "No"
},
{
"input": "3\n-1 1\n1 1\n1 -1",
"output": "Yes"
},
{
"input": "2\n1 0\n2 0",
"output": "Yes"
},
{
"input": "4\n-1 1\n-2 1\n2 -1\n3 -1",
"output": "No"
},
{
"input": "5\n1 0\n2 0\n3 0\n-1 0\n-2 0",
"output": "No"
},
{
"input": "4\n-3 0\n-4 0\n-5 0\n-6 0",
"output": "Yes"
},
{
"input": "6\n-3 0\n-2 0\n-1 0\n1 0\n2 0\n3 0",
"output": "No"
},
{
"input": "4\n5 0\n5 1\n6 0\n6 1",
"output": "Yes"
}
] | 249 | 0 | 0 | 918 |
|
7 | Memory Manager | [
"implementation"
] | B. Memory Manager | 1 | 64 | There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet β the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
- alloc n β to allocate *n* bytes of the memory and return the allocated block's identifier *x*; - erase x β to erase the block with the identifier *x*; - defragment β to defragment the free memory, bringing all the blocks as close to the beginning of the memory as possible and preserving their respective order;
The memory model in this case is very simple. It is a sequence of *m* bytes, numbered for convenience from the first to the *m*-th.
The first operation alloc n takes as the only parameter the size of the memory block that is to be allocated. While processing this operation, a free block of *n* successive bytes is being allocated in the memory. If the amount of such blocks is more than one, the block closest to the beginning of the memory (i.e. to the first byte) is prefered. All these bytes are marked as not free, and the memory manager returns a 32-bit integer numerical token that is the identifier of this block. If it is impossible to allocate a free block of this size, the function returns NULL.
The second operation erase x takes as its parameter the identifier of some block. This operation frees the system memory, marking the bytes of this block as free for further use. In the case when this identifier does not point to the previously allocated block, which has not been erased yet, the function returns ILLEGAL_ERASE_ARGUMENT.
The last operation defragment does not have any arguments and simply brings the occupied memory sections closer to the beginning of the memory without changing their respective order.
In the current implementation you are to use successive integers, starting with 1, as identifiers. Each successful alloc operation procession should return following number. Unsuccessful alloc operations do not affect numeration.
You are to write the implementation of the memory manager. You should output the returned value for each alloc command. You should also output ILLEGAL_ERASE_ARGUMENT for all the failed erase commands. | The first line of the input data contains two positive integers *t* and *m* (1<=β€<=*t*<=β€<=100;1<=β€<=*m*<=β€<=100), where *t* β the amount of operations given to the memory manager for processing, and *m* β the available memory size in bytes. Then there follow *t* lines where the operations themselves are given. The first operation is alloc n (1<=β€<=*n*<=β€<=100), where *n* is an integer. The second one is erase x, where *x* is an arbitrary 32-bit integer numerical token. The third operation is defragment. | Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return integers, starting with 1, as the identifiers of the allocated blocks. | [
"6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n"
] | [
"1\n2\nNULL\n3\n"
] | none | [
{
"input": "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6",
"output": "1\n2\nNULL\n3"
},
{
"input": "6 1\ndefragment\nalloc 10\nalloc 1\nerase -1\nerase 1\nerase 1",
"output": "NULL\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT"
},
{
"input": "14 100\nalloc 99\nalloc 1\nalloc 1\nerase 2\nalloc 1\nerase 4\nerase 1\nalloc 100\nalloc 1\nalloc 99\ndefragment\nerase 4\nalloc 100\nalloc 99",
"output": "1\n2\nNULL\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\n4\nNULL\nNULL\nNULL"
},
{
"input": "26 25\ndefragment\nerase 1\nerase -1560200883\nalloc 44\ndefragment\nalloc 75\nalloc 22\ndefragment\nerase 4\ndefragment\nalloc 57\nalloc 53\nerase 4\nerase -1639632026\nerase -2121605039\nerase 3\nalloc 51\nalloc 65\ndefragment\nerase 2\nerase 4\nalloc 52\nerase 3\ndefragment\nerase -1842529282\nerase 3",
"output": "ILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\n1\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT"
},
{
"input": "22 9\nerase 1\nalloc 6\nalloc 65\nerase 1\nalloc 87\nerase -1638927047\nalloc 5\nerase 2\nalloc 70\ndefragment\nalloc 20\nalloc 48\nerase -69401977\nalloc 20\ndefragment\nerase 7\ndefragment\nerase 9\nerase 7\nerase 4\ndefragment\nalloc 66",
"output": "ILLEGAL_ERASE_ARGUMENT\n1\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL"
},
{
"input": "12 40\nerase 1\nalloc 21\nalloc 5\nalloc 7\ndefragment\ndefragment\nerase 2\nalloc 83\nerase 4\ndefragment\nalloc 59\ndefragment",
"output": "ILLEGAL_ERASE_ARGUMENT\n1\n2\n3\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL"
},
{
"input": "38 18\nalloc 72\nerase 2\nalloc 50\ndefragment\nerase 3\ndefragment\nalloc 43\nalloc 41\ndefragment\ndefragment\nalloc 26\nalloc 46\nalloc 16\nalloc 15\ndefragment\ndefragment\nalloc 95\nerase 7\nerase 7\nerase 5\nerase 2\nerase 9\nerase 7\nalloc 43\ndefragment\nerase 7\ndefragment\nalloc 48\nalloc 77\nerase 10\nerase 11\nalloc 16\nalloc 84\nerase 1\ndefragment\nalloc 86\ndefragment\nerase 13",
"output": "NULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nNULL\n1\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT"
},
{
"input": "37 74\nalloc 11\ndefragment\nerase 1\ndefragment\nerase 2\ndefragment\nalloc 90\nerase 3\nerase 2\nerase 3\nerase 1\nerase 1\nalloc 38\nalloc 19\nerase 1\nerase 3\ndefragment\nalloc 93\nerase 5\nerase 4\nalloc 66\nalloc 71\nerase 5\ndefragment\ndefragment\ndefragment\ndefragment\nerase 7\nalloc 47\nerase -95616683\nerase 2\nalloc 28\nalloc 32\nerase 11\nalloc 50\ndefragment\ndefragment",
"output": "1\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\n4\n5\nILLEGAL_ERASE_ARGUMENT\nNULL"
},
{
"input": "16 49\nerase -751005193\ndefragment\nalloc 37\nalloc 82\nerase 3\nerase 1\nalloc 80\nalloc 51\ndefragment\nalloc 74\nerase 1\nalloc 91\ndefragment\ndefragment\nalloc 98\ndefragment",
"output": "ILLEGAL_ERASE_ARGUMENT\n1\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL"
},
{
"input": "42 98\ndefragment\ndefragment\ndefragment\ndefragment\ndefragment\nalloc 5\nalloc 66\ndefragment\nerase 3\nalloc 53\ndefragment\nerase 4\nerase 2\nalloc 70\nerase 3\ndefragment\ndefragment\nerase 2\nerase 3\nerase -1327931832\nalloc 93\nalloc 64\nerase 7\nerase 6\nerase 3\nalloc 61\nalloc 12\nalloc 65\nerase 2\nalloc 46\nerase 11\nerase 9\nerase 9\nerase 6\nalloc 2\nalloc 78\ndefragment\nerase 13\nerase 6\nerase 10\nalloc 53\nalloc 46",
"output": "1\n2\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n4\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL"
},
{
"input": "19 46\nalloc 21\nerase 2\nerase 1\ndefragment\nalloc 4\ndefragment\ndefragment\nalloc 40\nerase 1\ndefragment\ndefragment\nalloc 68\nerase -388966015\nalloc 85\nalloc 53\nerase 4\ndefragment\nalloc 49\nalloc 88",
"output": "1\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL"
},
{
"input": "44 46\nalloc 28\nalloc 36\ndefragment\nerase -937404236\nalloc 71\ndefragment\nalloc 81\nalloc 51\nerase 3\ndefragment\nalloc 48\nerase 1\ndefragment\nalloc 36\ndefragment\ndefragment\nerase 1\ndefragment\ndefragment\nerase -1173350787\nalloc 94\nerase 5\ndefragment\nerase 9\nalloc 98\nerase 7\ndefragment\nerase 5\nerase 1\ndefragment\nerase 2\ndefragment\nerase 4\ndefragment\nerase 9\nalloc 8\ndefragment\nerase 9\ndefragment\ndefragment\ndefragment\nerase 1\nalloc 70\nerase 9",
"output": "1\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\n2\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT"
},
{
"input": "47 43\nerase 1\nalloc 95\nalloc 53\nerase 2\ndefragment\nalloc 100\nerase 4\nerase 2\nerase -849472053\ndefragment\nerase -638355221\nalloc 90\nerase 3\nerase 2\ndefragment\nalloc 17\nerase 5\ndefragment\nerase 6\ndefragment\nerase 3\ndefragment\ndefragment\nalloc 99\nalloc 69\nalloc 80\nerase 9\nerase 5\ndefragment\nerase 7\ndefragment\nalloc 93\ndefragment\ndefragment\nalloc 25\ndefragment\nalloc 14\nerase 8\nerase 4\ndefragment\ndefragment\nalloc 96\nerase 9\nalloc 63\nerase 8\ndefragment\nerase 10",
"output": "ILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\n2\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL..."
},
{
"input": "26 25\nalloc 25\nerase 1\nalloc 24\nerase 2\nalloc 23\nerase 3\nalloc 24\nerase 4\nalloc 24\nerase 5\nalloc 21\nerase 6\nalloc 24\nerase 7\nalloc 25\nerase 8\nalloc 25\nerase 9\nalloc 24\nerase 10\nalloc 25\nerase 11\nalloc 25\nerase 12\nalloc 25\nerase 13",
"output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13"
},
{
"input": "22 9\nalloc 9\nerase 1\nalloc 9\nerase 2\nalloc 9\nerase 3\nalloc 9\nerase 4\nalloc 9\nerase 5\nalloc 9\nerase 6\nalloc 9\nerase 7\nalloc 9\nerase 8\nalloc 9\nerase 9\nalloc 9\nerase 10\nalloc 9\nerase 11",
"output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11"
},
{
"input": "7 6\nalloc 1\nalloc 2\nalloc 3\nerase 1\ndefragment\nerase 3\nalloc 4",
"output": "1\n2\n3\n4"
},
{
"input": "3 1\nerase -1\nerase 0\nerase -2147483648",
"output": "ILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT"
},
{
"input": "7 100\nalloc 100\nerase 2147483647\nerase 1\nalloc 50\nalloc 50\nerase 3\nerase -2147483648",
"output": "1\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT"
},
{
"input": "12 10\nalloc 6\nalloc 2\nerase 1\nalloc 4\nalloc 2\nerase 3\nalloc 2\nalloc 3\nalloc 1\nalloc 1\nalloc 1\nalloc 1",
"output": "1\n2\n3\n4\n5\nNULL\n6\n7\n8\n9"
},
{
"input": "8 50\nalloc 51\ndefragment\nalloc 100\ndefragment\nerase 1\nalloc 50\ndefragment\nalloc 50",
"output": "NULL\nNULL\nILLEGAL_ERASE_ARGUMENT\n1\nNULL"
},
{
"input": "10 10\nalloc 10\nerase -1\nerase 1\nalloc 5\nerase -1\nalloc 5\nerase 0\nalloc 5\nerase 0\nalloc 5",
"output": "1\nILLEGAL_ERASE_ARGUMENT\n2\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL"
},
{
"input": "16 10\nalloc 10\ndefragment\ndefragment\ndefragment\nalloc 10\nerase 1\nerase 2\nalloc 6\ndefragment\ndefragment\nalloc 4\ndefragment\ndefragment\nerase 3\ndefragment\nalloc 6",
"output": "1\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\n3\nNULL"
},
{
"input": "16 10\nalloc 10\ndefragment\ndefragment\ndefragment\nalloc 10\nerase 1\nerase 2\nalloc 6\ndefragment\ndefragment\nalloc 4\ndefragment\ndefragment\nerase 2\ndefragment\nalloc 6",
"output": "1\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\n3\n4"
}
] | 186 | 0 | 0 | 922 |
721 | Passwords | [
"implementation",
"math",
"sortings",
"strings"
] | null | null | Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds). | The first line of the input contains two integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=100)Β β the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per lineΒ β pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords. | Print two integersΒ β time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | [
"5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"4 100\n11\n22\n1\n2\n22\n"
] | [
"1 15\n",
"3 4\n"
] | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all. | [
{
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc",
"output": "1 15"
},
{
"input": "4 100\n11\n22\n1\n2\n22",
"output": "3 4"
},
{
"input": "1 1\na1\na1",
"output": "1 1"
},
{
"input": "1 100\na1\na1",
"output": "1 1"
},
{
"input": "2 1\nabc\nAbc\nAbc",
"output": "1 7"
},
{
"input": "2 2\nabc\nAbc\nabc",
"output": "1 2"
},
{
"input": "2 1\nab\nabc\nab",
"output": "1 1"
},
{
"input": "2 2\nab\nabc\nab",
"output": "1 1"
},
{
"input": "2 1\nab\nabc\nabc",
"output": "7 7"
},
{
"input": "2 2\nab\nabc\nabc",
"output": "2 2"
},
{
"input": "10 3\nOIbV1igi\no\nZS\nQM\n9woLzI\nWreboD\nQ7yl\nA5Rb\nS9Lno72TkP\nfT97o\no",
"output": "1 1"
},
{
"input": "10 3\nHJZNMsT\nLaPcH2C\nlrhqIO\n9cxw\noTC1XwjW\nGHL9Ul6\nUyIs\nPuzwgR4ZKa\nyIByoKR5\nd3QA\nPuzwgR4ZKa",
"output": "25 25"
},
{
"input": "20 5\nvSyC787KlIL8kZ2Uv5sw\nWKWOP\n7i8J3E8EByIq\nNW2VyGweL\nmyR2sRNu\nmXusPP0\nf4jgGxra\n4wHRzRhOCpEt\npPz9kybGb\nOtSpePCRoG5nkjZ2VxRy\nwHYsSttWbJkg\nKBOP9\nQfiOiFyHPPsw3GHo8J8\nxB8\nqCpehZEeEhdq\niOLjICK6\nQ91\nHmCsfMGTFKoFFnv238c\nJKjhg\ngkEUh\nKBOP9",
"output": "3 11"
},
{
"input": "15 2\nw6S9WyU\nMVh\nkgUhQHW\nhGQNOF\nUuym\n7rGQA\nBM8vLPRB\n9E\nDs32U\no\nz1aV2C5T\n8\nzSXjrqQ\n1FO\n3kIt\nBM8vLPRB",
"output": "44 50"
},
{
"input": "20 2\ni\n5Rp6\nE4vsr\nSY\nORXx\nh13C\nk6tzC\ne\nN\nKQf4C\nWZcdL\ndiA3v\n0InQT\nuJkAr\nGCamp\nBuIRd\nY\nM\nxZYx7\n0a5A\nWZcdL",
"output": "36 65"
},
{
"input": "20 2\naWLQ6\nSgQ9r\nHcPdj\n2BNaO\n3TjNb\nnvwFM\nqsKt7\nFnb6N\nLoc0p\njxuLq\nBKAjf\nEKgZB\nBfOSa\nsMIvr\nuIWcR\nIura3\nLAqSf\ntXq3G\n8rQ8I\n8otAO\nsMIvr",
"output": "1 65"
},
{
"input": "20 15\n0ZpQugVlN7\nm0SlKGnohN\nRFXTqhNGcn\n1qm2ZbB\nQXtJWdf78P\nbc2vH\nP21dty2Z1P\nm2c71LFhCk\n23EuP1Dvh3\nanwri5RhQN\n55v6HYv288\n1u5uKOjM5r\n6vg0GC1\nDAPYiA3ns1\nUZaaJ3Gmnk\nwB44x7V4Zi\n4hgB2oyU8P\npYFQpy8gGK\ndbz\nBv\n55v6HYv288",
"output": "6 25"
},
{
"input": "3 1\na\nb\naa\naa",
"output": "13 13"
},
{
"input": "6 3\nab\nac\nad\nabc\nabd\nabe\nabc",
"output": "9 11"
},
{
"input": "4 2\n1\n2\n11\n22\n22",
"output": "8 9"
},
{
"input": "2 1\n1\n12\n12",
"output": "7 7"
},
{
"input": "3 1\nab\nabc\nabd\nabc",
"output": "7 13"
},
{
"input": "2 1\na\nab\nab",
"output": "7 7"
},
{
"input": "5 2\na\nb\nc\nab\naa\naa",
"output": "9 15"
},
{
"input": "6 1\n1\n2\n11\n22\n111\n2222\n22",
"output": "13 19"
},
{
"input": "3 1\n1\n2\n11\n11",
"output": "13 13"
},
{
"input": "10 4\na\nb\nc\nd\ne\nf\nab\ncd\nac\nad\nac",
"output": "12 20"
},
{
"input": "4 2\na\nb\nc\nd\na",
"output": "1 9"
},
{
"input": "4 1\n1\n2\n3\n4\n4",
"output": "1 19"
},
{
"input": "5 1\na\nb\nc\nd\nef\nef",
"output": "25 25"
},
{
"input": "6 4\n1\n2\n22\n33\n44\n555\n555",
"output": "11 11"
},
{
"input": "5 2\na\nb\nc\nd\nab\nab",
"output": "15 15"
},
{
"input": "6 2\n1\n2\n3\n4\n5\n23\n23",
"output": "16 16"
},
{
"input": "4 2\na\nb\naa\nbb\naa",
"output": "8 9"
},
{
"input": "5 4\na\nbb\ncc\ndd\nee\nbb",
"output": "2 10"
},
{
"input": "4 1\na\nb\nc\nab\nab",
"output": "19 19"
},
{
"input": "7 100\na\nb\nc\nd\ne\ng\nab\nab",
"output": "7 7"
},
{
"input": "6 1\na\nb\nc\nd\ne\naa\naa",
"output": "31 31"
},
{
"input": "4 1\na\nas\nasd\nasde\nasde",
"output": "19 19"
},
{
"input": "5 2\n1\n2\n3\n11\n22\n22",
"output": "9 15"
},
{
"input": "10 2\na\nb\nc\nd\nee\nff\ngg\nhh\nii\njj\nii",
"output": "15 30"
},
{
"input": "3 1\na\nab\nbc\nab",
"output": "7 13"
},
{
"input": "6 4\na\nb\nc\nbb\nbc\ncc\ncc",
"output": "4 11"
}
] | 31 | 0 | 0 | 924 |
|
735 | Ostap and Grasshopper | [
"implementation",
"strings"
] | null | null | On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect. | The first line of the input contains two integers *n* and *k* (2<=β€<=*n*<=β€<=100, 1<=β€<=*k*<=β€<=*n*<=-<=1)Β β the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once. | If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). | [
"5 2\n#G#T#\n",
"6 1\nT....G\n",
"7 3\nT..#..G\n",
"6 2\n..GT..\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is freeΒ β he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | [
{
"input": "5 2\n#G#T#",
"output": "YES"
},
{
"input": "6 1\nT....G",
"output": "YES"
},
{
"input": "7 3\nT..#..G",
"output": "NO"
},
{
"input": "6 2\n..GT..",
"output": "NO"
},
{
"input": "2 1\nGT",
"output": "YES"
},
{
"input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####T####",
"output": "YES"
},
{
"input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.#########.####.####.####.####T####",
"output": "NO"
},
{
"input": "2 1\nTG",
"output": "YES"
},
{
"input": "99 1\n...T.............................................................................................G.",
"output": "YES"
},
{
"input": "100 2\nG............#.....#...........#....#...........##............#............#......................T.",
"output": "NO"
},
{
"input": "100 1\n#.#.#.##..#..##.#....##.##.##.#....####..##.#.##..GT..##...###.#.##.#..#..##.###..#.####..#.#.##..##",
"output": "YES"
},
{
"input": "100 2\n..#####.#.#.......#.#.#...##..####..###..#.#######GT####.#.#...##...##.#..###....##.#.#..#.###....#.",
"output": "NO"
},
{
"input": "100 3\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 3\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 3\nG..................................#......#......#.......#.#..........#........#......#..........#.T",
"output": "NO"
},
{
"input": "100 3\nG..............#..........#...#..............#.#.....................#......#........#.........#...T",
"output": "NO"
},
{
"input": "100 3\nG##################################################################################################T",
"output": "NO"
},
{
"input": "100 33\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 33\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 33\nG.........#........#..........#..............#.................#............................#.#....T",
"output": "YES"
},
{
"input": "100 33\nG.......#..................#..............................#............................#..........T.",
"output": "NO"
},
{
"input": "100 33\nG#..........##...#.#.....................#.#.#.........##..#...........#....#...........##...#..###T",
"output": "YES"
},
{
"input": "100 33\nG..#.#..#..####......#......##...##...#.##........#...#...#.##....###..#...###..##.#.....#......#.T.",
"output": "NO"
},
{
"input": "100 33\nG#....#..#..##.##..#.##.#......#.#.##..##.#.#.##.##....#.#.....####..##...#....##..##..........#...T",
"output": "NO"
},
{
"input": "100 33\nG#######.#..##.##.#...#..#.###.#.##.##.#..#.###..####.##.#.##....####...##..####.#..##.##.##.#....#T",
"output": "NO"
},
{
"input": "100 33\nG#####.#.##.###########.##..##..#######..########..###.###..#.####.######.############..####..#####T",
"output": "NO"
},
{
"input": "100 99\nT..................................................................................................G",
"output": "YES"
},
{
"input": "100 99\nT..................................................................................................G",
"output": "YES"
},
{
"input": "100 99\nT.#...............................#............#..............................##...................G",
"output": "YES"
},
{
"input": "100 99\nT..#....#.##...##########.#.#.#.#...####..#.....#..##..#######.######..#.....###..###...#.......#.#G",
"output": "YES"
},
{
"input": "100 99\nG##################################################################################################T",
"output": "YES"
},
{
"input": "100 9\nT..................................................................................................G",
"output": "YES"
},
{
"input": "100 9\nT.................................................................................................G.",
"output": "NO"
},
{
"input": "100 9\nT................................................................................................G..",
"output": "NO"
},
{
"input": "100 1\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 1\nT..................................................................................................G",
"output": "YES"
},
{
"input": "100 1\n##########G.........T###############################################################################",
"output": "YES"
},
{
"input": "100 1\n#################################################################################################G.T",
"output": "YES"
},
{
"input": "100 17\n##########G################.################.################.################T#####################",
"output": "YES"
},
{
"input": "100 17\n####.#..#.G######.#########.##..##########.#.################.################T######.####.#########",
"output": "YES"
},
{
"input": "100 17\n.########.G##.####.#.######.###############..#.###########.##.#####.##.#####.#T.###..###.########.##",
"output": "YES"
},
{
"input": "100 1\nG.............................................#....................................................T",
"output": "NO"
},
{
"input": "100 1\nT.#................................................................................................G",
"output": "NO"
},
{
"input": "100 1\n##########G....#....T###############################################################################",
"output": "NO"
},
{
"input": "100 1\n#################################################################################################G#T",
"output": "NO"
},
{
"input": "100 17\nG################.#################################.################T###############################",
"output": "NO"
},
{
"input": "100 17\nG################.###############..###.######.#######.###.#######.##T######################.###.####",
"output": "NO"
},
{
"input": "100 17\nG####.##.##.#####.####....##.####.#########.##.#..#.###############.T############.#########.#.####.#",
"output": "NO"
},
{
"input": "48 1\nT..............................................G",
"output": "YES"
},
{
"input": "23 1\nT.....................G",
"output": "YES"
},
{
"input": "49 1\nG...............................................T",
"output": "YES"
},
{
"input": "3 1\nTG#",
"output": "YES"
},
{
"input": "6 2\n..TG..",
"output": "NO"
},
{
"input": "14 3\n...G.....#..T.",
"output": "NO"
},
{
"input": "5 4\n##GT#",
"output": "NO"
},
{
"input": "6 2\nT#..G.",
"output": "YES"
},
{
"input": "5 2\nT.G.#",
"output": "YES"
},
{
"input": "6 1\nT...G#",
"output": "YES"
},
{
"input": "5 1\nTG###",
"output": "YES"
},
{
"input": "5 4\n.G..T",
"output": "NO"
},
{
"input": "7 2\nT#...#G",
"output": "YES"
},
{
"input": "7 1\n##TG###",
"output": "YES"
},
{
"input": "7 1\n###GT##",
"output": "YES"
},
{
"input": "5 2\nG..T.",
"output": "NO"
},
{
"input": "5 1\nG.T##",
"output": "YES"
},
{
"input": "6 2\nG.T###",
"output": "YES"
},
{
"input": "6 2\nG#T###",
"output": "YES"
},
{
"input": "10 2\n####T..G..",
"output": "NO"
},
{
"input": "3 1\nGT#",
"output": "YES"
},
{
"input": "4 1\nTG##",
"output": "YES"
},
{
"input": "6 1\n.G..T.",
"output": "YES"
},
{
"input": "10 3\n......G..T",
"output": "YES"
},
{
"input": "3 2\nG.T",
"output": "YES"
},
{
"input": "4 1\n#G.T",
"output": "YES"
},
{
"input": "5 2\nT#G##",
"output": "YES"
},
{
"input": "4 2\nG#.T",
"output": "NO"
},
{
"input": "4 1\nGT##",
"output": "YES"
}
] | 46 | 0 | 3 | 925 |
|
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"
}
] | 124 | 6,758,400 | 3.956411 | 928 |
421 | Pasha and Hamsters | [
"constructive algorithms",
"implementation"
] | null | null | Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamsters on his own. He is going to give some apples to Arthur and some apples to Alexander. It doesn't matter how many apples each hamster gets but it is important that each hamster gets only the apples he likes. It is possible that somebody doesn't get any apples.
Help Pasha distribute all the apples between the hamsters. Note that Pasha wants to distribute all the apples, not just some of them. | The first line contains integers *n*, *a*, *b* (1<=β€<=*n*<=β€<=100;Β 1<=β€<=*a*,<=*b*<=β€<=*n*) β the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly.
The next line contains *a* distinct integers β the numbers of the apples Arthur likes. The next line contains *b* distinct integers β the numbers of the apples Alexander likes.
Assume that the apples are numbered from 1 to *n*. The input is such that the answer exists. | Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them. | [
"4 2 3\n1 2\n2 3 4\n",
"5 5 2\n3 4 1 2 5\n2 3\n"
] | [
"1 1 2 2\n",
"1 1 1 1 1\n"
] | none | [
{
"input": "4 2 3\n1 2\n2 3 4",
"output": "1 1 2 2"
},
{
"input": "5 5 2\n3 4 1 2 5\n2 3",
"output": "1 1 1 1 1"
},
{
"input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 74 76 77 78 79 80 81 82 83 89 92 94 95 97 98 99 100\n2 13 22 23 25 28 30 32 33 34 35 36 41 42 43 45 47 52 54 62 73 75 84 85 86 87 88 90 91 93 96",
"output": "1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 2 1 2 1 2 2 2 2 2 1 1 1 1 2 2 2 1 2 1 2 1 1 1 1 2 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 2 2 1 2 2 1 2 1 1 2 1 1 1 1"
},
{
"input": "100 56 44\n1 2 5 8 14 15 17 18 20 21 23 24 25 27 30 33 34 35 36 38 41 42 44 45 46 47 48 49 50 53 56 58 59 60 62 63 64 65 68 69 71 75 76 80 81 84 87 88 90 91 92 94 95 96 98 100\n3 4 6 7 9 10 11 12 13 16 19 22 26 28 29 31 32 37 39 40 43 51 52 54 55 57 61 66 67 70 72 73 74 77 78 79 82 83 85 86 89 93 97 99",
"output": "1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 2 1 1 2 1 1 2 1 1 1 2 1 2 2 1 2 2 1 1 1 1 2 1 2 2 1 1 2 1 1 1 1 1 1 1 2 2 1 2 2 1 2 1 1 1 2 1 1 1 1 2 2 1 1 2 1 2 2 2 1 1 2 2 2 1 1 2 2 1 2 2 1 1 2 1 1 1 2 1 1 1 2 1 2 1"
},
{
"input": "100 82 18\n1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 22 23 25 27 29 30 31 32 33 34 35 36 37 38 42 43 44 45 46 47 48 49 50 51 53 54 55 57 58 59 60 61 62 63 64 65 66 67 68 69 71 72 73 74 75 77 78 79 80 82 83 86 88 90 91 92 93 94 96 97 98 99 100\n12 21 24 26 28 39 40 41 52 56 70 76 81 84 85 87 89 95",
"output": "1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1"
},
{
"input": "99 72 27\n1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 20 23 25 26 28 29 30 32 33 34 35 36 39 41 42 43 44 45 46 47 50 51 52 54 55 56 58 59 60 61 62 67 70 71 72 74 75 76 77 80 81 82 84 85 86 88 90 91 92 93 94 95 96 97 98 99\n9 18 19 21 22 24 27 31 37 38 40 48 49 53 57 63 64 65 66 68 69 73 78 79 83 87 89",
"output": "1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 1 1 1 1 1 1 2 2 1 1 1 2 1 1 1 2 1 1 1 1 1 2 2 2 2 1 2 2 1 1 1 2 1 1 1 1 2 2 1 1 1 2 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1"
},
{
"input": "99 38 61\n1 3 10 15 16 22 23 28 31 34 35 36 37 38 39 43 44 49 50 53 56 60 63 68 69 70 72 74 75 77 80 81 83 85 96 97 98 99\n2 4 5 6 7 8 9 11 12 13 14 17 18 19 20 21 24 25 26 27 29 30 32 33 40 41 42 45 46 47 48 51 52 54 55 57 58 59 61 62 64 65 66 67 71 73 76 78 79 82 84 86 87 88 89 90 91 92 93 94 95",
"output": "1 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 2 2 2 2 2 1 1 2 2 2 2 1 2 2 1 2 2 1 1 1 1 1 1 2 2 2 1 1 2 2 2 2 1 1 2 2 1 2 2 1 2 2 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 1 1 2 1 2 2 1 1 2 1 2 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1"
},
{
"input": "99 84 15\n1 2 3 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 44 47 48 50 51 52 53 55 56 58 59 60 61 62 63 64 65 68 69 70 71 72 73 74 75 77 79 80 81 82 83 84 85 86 87 89 90 91 92 93 94 97 98 99\n4 18 33 45 46 49 54 57 66 67 76 78 88 95 96",
"output": "1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 2 1 1 1"
},
{
"input": "4 3 1\n1 3 4\n2",
"output": "1 2 1 1"
},
{
"input": "4 3 1\n1 2 4\n3",
"output": "1 1 2 1"
},
{
"input": "4 2 2\n2 3\n1 4",
"output": "2 1 1 2"
},
{
"input": "4 3 1\n2 3 4\n1",
"output": "2 1 1 1"
},
{
"input": "1 1 1\n1\n1",
"output": "1"
},
{
"input": "2 1 1\n2\n1",
"output": "2 1"
},
{
"input": "2 1 1\n1\n2",
"output": "1 2"
},
{
"input": "3 3 1\n1 2 3\n1",
"output": "1 1 1"
},
{
"input": "3 3 1\n1 2 3\n3",
"output": "1 1 1"
},
{
"input": "3 2 1\n1 3\n2",
"output": "1 2 1"
},
{
"input": "100 1 100\n84\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": "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2"
},
{
"input": "100 100 1\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\n17",
"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": "98 51 47\n1 2 3 4 6 7 8 10 13 15 16 18 19 21 22 23 25 26 27 29 31 32 36 37 39 40 41 43 44 48 49 50 51 52 54 56 58 59 65 66 68 79 80 84 86 88 89 90 94 95 97\n5 9 11 12 14 17 20 24 28 30 33 34 35 38 42 45 46 47 53 55 57 60 61 62 63 64 67 69 70 71 72 73 74 75 76 77 78 81 82 83 85 87 91 92 93 96 98",
"output": "1 1 1 1 2 1 1 1 2 1 2 2 1 2 1 1 2 1 1 2 1 1 1 2 1 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 1 1 2 2 2 1 1 1 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 1 2 1 2 1 1 1 2 2 2 1 1 2 1 2"
},
{
"input": "98 28 70\n1 13 15 16 19 27 28 40 42 43 46 53 54 57 61 63 67 68 69 71 75 76 78 80 88 93 97 98\n2 3 4 5 6 7 8 9 10 11 12 14 17 18 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 41 44 45 47 48 49 50 51 52 55 56 58 59 60 62 64 65 66 70 72 73 74 77 79 81 82 83 84 85 86 87 89 90 91 92 94 95 96",
"output": "1 2 2 2 2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 2 2 2 1 1 2 2 1 2 2 2 1 2 1 2 2 2 1 1 1 2 1 2 2 2 1 1 2 1 2 1 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 1 1"
},
{
"input": "97 21 76\n7 10 16 17 26 30 34 39 40 42 44 46 53 54 56 64 67 72 78 79 94\n1 2 3 4 5 6 8 9 11 12 13 14 15 18 19 20 21 22 23 24 25 27 28 29 31 32 33 35 36 37 38 41 43 45 47 48 49 50 51 52 55 57 58 59 60 61 62 63 65 66 68 69 70 71 73 74 75 76 77 80 81 82 83 84 85 86 87 88 89 90 91 92 93 95 96 97",
"output": "2 2 2 2 2 2 1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 1 2 2 2 2 1 1 2 1 2 1 2 1 2 2 2 2 2 2 1 1 2 1 2 2 2 2 2 2 2 1 2 2 1 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2"
},
{
"input": "97 21 76\n1 10 12 13 17 18 22 25 31 48 50 54 61 64 67 74 78 81 86 88 94\n2 3 4 5 6 7 8 9 11 14 15 16 19 20 21 23 24 26 27 28 29 30 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 49 51 52 53 55 56 57 58 59 60 62 63 65 66 68 69 70 71 72 73 75 76 77 79 80 82 83 84 85 87 89 90 91 92 93 95 96 97",
"output": "1 2 2 2 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 1 2 2 1 2 2 1 2 2 2 2 2 2 1 2 2 2 1 2 2 1 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2"
},
{
"input": "96 10 86\n2 5 31 37 68 69 80 82 90 91\n1 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 32 33 34 35 36 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 70 71 72 73 74 75 76 77 78 79 81 83 84 85 86 87 88 89 92 93 94 95 96",
"output": "2 1 2 2 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 1 2 2 2 2 2 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 1 1 2 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 1 1 2 2 2 2 2"
},
{
"input": "95 4 91\n58 65 70 93\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 59 60 61 62 63 64 66 67 68 69 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 94 95",
"output": "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2"
},
{
"input": "98 88 10\n1 2 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 38 39 40 41 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 62 63 64 65 66 67 68 69 71 72 73 74 75 76 77 79 80 81 83 84 85 86 87 88 89 90 92 93 94 95 96 97 98\n3 7 32 37 42 61 70 78 82 91",
"output": "1 1 2 1 1 1 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 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1"
},
{
"input": "98 96 2\n1 2 3 4 5 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\n6 7",
"output": "1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "97 97 1\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\n94",
"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"
},
{
"input": "97 97 1\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\n20",
"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"
},
{
"input": "96 96 1\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\n48",
"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"
},
{
"input": "95 95 1\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\n55",
"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"
}
] | 62 | 5,529,600 | 3 | 932 |
|
277 | Binary Tree on Plane | [
"flows",
"trees"
] | null | null | A root tree is a directed acyclic graph that contains one node (root), from which there is exactly one path to any other node.
A root tree is binary if each node has at most two outgoing arcs.
When a binary tree is painted on the plane, all arcs should be directed from top to bottom. That is, each arc going from *u* to *v* must meet the condition *y**u*<=><=*y**v*.
You've been given the coordinates of all tree nodes. Your task is to connect these nodes by arcs so as to get the binary root tree and make the total length of the arcs minimum. All arcs of the built tree must be directed from top to bottom. | The first line contains a single integer *n* (2<=β€<=*n*<=β€<=400) β the number of nodes in the tree. Then follow *n* lines, two integers per line: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=β€<=103) β coordinates of the nodes. It is guaranteed that all points are distinct. | If it is impossible to build a binary root tree on the given points, print "-1". Otherwise, print a single real number β the total length of the arcs in the minimum binary tree. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"3\n0 0\n1 0\n2 1\n",
"4\n0 0\n1 0\n2 1\n2 0\n"
] | [
"3.650281539872885\n",
"-1\n"
] | none | [] | 3,000 | 70,758,400 | 0 | 933 |
|
535 | Tavas and Karafs | [
"binary search",
"greedy",
"math"
] | null | null | Karafs is some kind of vegetable in shape of an 1<=Γ<=*h* rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the *i*-th Karafs is *s**i*<==<=*A*<=+<=(*i*<=-<=1)<=Γ<=*B*.
For a given *m*, let's define an *m*-bite operation as decreasing the height of at most *m* distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you *n* queries. In each query he gives you numbers *l*, *t* and *m* and you should find the largest number *r* such that *l*<=β€<=*r* and sequence *s**l*,<=*s**l*<=+<=1,<=...,<=*s**r* can be eaten by performing *m*-bite no more than *t* times or print -1 if there is no such number *r*. | The first line of input contains three integers *A*, *B* and *n* (1<=β€<=*A*,<=*B*<=β€<=106, 1<=β€<=*n*<=β€<=105).
Next *n* lines contain information about queries. *i*-th line contains integers *l*,<=*t*,<=*m* (1<=β€<=*l*,<=*t*,<=*m*<=β€<=106) for *i*-th query. | For each query, print its answer in a single line. | [
"2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8\n",
"1 5 2\n1 5 10\n2 7 4\n"
] | [
"4\n-1\n8\n-1\n",
"1\n2\n"
] | none | [
{
"input": "2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8",
"output": "4\n-1\n8\n-1"
},
{
"input": "1 5 2\n1 5 10\n2 7 4",
"output": "1\n2"
},
{
"input": "1 1 4\n1 1000000 1000000\n1 1 1000000\n1 1000000 1\n1 1 1",
"output": "1000000\n1\n1413\n1"
},
{
"input": "1000000 1000000 1\n1000000 1000000 1000000",
"output": "-1"
},
{
"input": "999999 1000000 1\n1 1000000 1000000",
"output": "1"
},
{
"input": "1 1000000 1\n1 1000000 1000000",
"output": "1"
},
{
"input": "1 5000 1\n1 1000000 1000000",
"output": "200"
},
{
"input": "1 1 1\n1 1000000 1000000",
"output": "1000000"
},
{
"input": "447 74474 4\n47 777474 747\n74 744744 74477\n477 477447 777\n7 477777 444444",
"output": "-1\n-1\n-1\n7"
}
] | 2,000 | 0 | 0 | 936 |
|
202 | LLPS | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=β€<= *p*1<=<<=*p*2<=<<=...<=<<=*p**k* <=β€<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".
String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| > |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=<<=|*x*|, *r*<=<<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=><=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".
String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z". | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
{
"input": "helloworld",
"output": "w"
},
{
"input": "zzzzzzzazz",
"output": "zzzzzzzzz"
},
{
"input": "testcase",
"output": "tt"
},
{
"input": "hahahahaha",
"output": "hhhhh"
},
{
"input": "abbbbbbbbb",
"output": "bbbbbbbbb"
},
{
"input": "zaz",
"output": "zz"
},
{
"input": "aza",
"output": "z"
},
{
"input": "dcbaedcba",
"output": "e"
},
{
"input": "abcdeabcd",
"output": "e"
},
{
"input": "edcbabcde",
"output": "ee"
},
{
"input": "aaaaaaaaab",
"output": "b"
},
{
"input": "testzzzzzz",
"output": "zzzzzz"
},
{
"input": "zzzzzzwait",
"output": "zzzzzz"
},
{
"input": "rrrrrqponm",
"output": "rrrrr"
},
{
"input": "zzyzyy",
"output": "zzz"
},
{
"input": "aababb",
"output": "bbb"
},
{
"input": "zanzibar",
"output": "zz"
},
{
"input": "hhgfedcbaa",
"output": "hh"
},
{
"input": "aabcdefghh",
"output": "hh"
},
{
"input": "aruaru",
"output": "uu"
},
{
"input": "uraura",
"output": "uu"
},
{
"input": "aru",
"output": "u"
},
{
"input": "aburvabur",
"output": "v"
},
{
"input": "ura",
"output": "u"
},
{
"input": "eurottat",
"output": "u"
},
{
"input": "referee",
"output": "rr"
},
{
"input": "joking",
"output": "o"
},
{
"input": "seriously",
"output": "y"
},
{
"input": "sets",
"output": "t"
},
{
"input": "test",
"output": "tt"
},
{
"input": "klmgameklm",
"output": "mmm"
},
{
"input": "dfkjafdkdd",
"output": "kk"
},
{
"input": "zzzzzzzzzz",
"output": "zzzzzzzzzz"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaa"
},
{
"input": "buzz",
"output": "zz"
},
{
"input": "b",
"output": "b"
},
{
"input": "y",
"output": "y"
},
{
"input": "yy",
"output": "yy"
},
{
"input": "zz",
"output": "zz"
},
{
"input": "bb",
"output": "bb"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "a",
"output": "a"
},
{
"input": "z",
"output": "z"
},
{
"input": "zz",
"output": "zz"
},
{
"input": "zzazazzzaz",
"output": "zzzzzzz"
},
{
"input": "hellhellhe",
"output": "llll"
},
{
"input": "hellohello",
"output": "oo"
},
{
"input": "refer",
"output": "rr"
}
] | 92 | 0 | 3 | 937 |
|
952 | Ravioli Sort | [
"implementation"
] | null | null | Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you...
You come up with the following algorithm. For each number in the array *a**i*, build a stack of *a**i* ravioli. The image shows the stack for *a**i*<==<=4.
Arrange the stacks in one row in the order in which the corresponding numbers appear in the input array. Find the tallest one (if there are several stacks of maximal height, use the leftmost one). Remove it and add its height to the end of the output array. Shift the stacks in the row so that there is no gap between them. Repeat the procedure until all stacks have been removed.
At first you are very happy with your algorithm, but as you try it on more inputs you realize that it doesn't always produce the right sorted array. Turns out when two stacks of ravioli are next to each other (at any step of the process) and differ in height by two or more, the top ravioli of the taller stack slides down on top of the lower stack.
Given an input array, figure out whether the described algorithm will sort it correctly. | The first line of input contains a single number *n* (1<=β€<=*n*<=β€<=10) β the size of the array.
The second line of input contains *n* space-separated integers *a**i* (1<=β€<=*a**i*<=β€<=100) β the elements of the array. | Output "YES" if the array can be sorted using the described procedure and "NO" if it can not. | [
"3\n1 2 3\n",
"3\n3 1 2\n"
] | [
"YES\n",
"NO\n"
] | In the second example the array will change even before the tallest stack is chosen for the first time: ravioli from stack of height 3 will slide on the stack of height 1, and the algorithm will output an array {2,β2,β2}. | [
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n3 1 2",
"output": "NO"
},
{
"input": "1\n13",
"output": "YES"
},
{
"input": "10\n67 67 67 67 67 67 67 67 67 67",
"output": "YES"
},
{
"input": "10\n16 17 16 15 14 15 16 17 16 15",
"output": "YES"
},
{
"input": "4\n54 54 54 55",
"output": "YES"
},
{
"input": "3\n68 67 67",
"output": "YES"
},
{
"input": "5\n46 46 47 46 45",
"output": "YES"
},
{
"input": "4\n14 15 15 16",
"output": "YES"
},
{
"input": "6\n59 59 60 60 59 58",
"output": "YES"
},
{
"input": "3\n40 40 40",
"output": "YES"
},
{
"input": "4\n90 91 90 91",
"output": "YES"
},
{
"input": "10\n9 9 9 10 10 9 8 8 9 9",
"output": "YES"
},
{
"input": "3\n22 23 24",
"output": "YES"
},
{
"input": "9\n71 71 70 70 71 70 69 70 71",
"output": "YES"
},
{
"input": "9\n15 14 14 13 13 12 13 13 14",
"output": "YES"
},
{
"input": "4\n61 60 60 60",
"output": "YES"
},
{
"input": "4\n16 17 17 18",
"output": "YES"
},
{
"input": "6\n87 86 86 86 85 86",
"output": "YES"
},
{
"input": "5\n64 63 63 62 61",
"output": "YES"
},
{
"input": "9\n13 80 13 38 98 85 11 73 74",
"output": "NO"
},
{
"input": "10\n2 83 18 65 58 95 37 51 86 47",
"output": "NO"
},
{
"input": "6\n47 100 96 2 96 43",
"output": "NO"
},
{
"input": "10\n28 61 23 73 61 33 45 55 18 43",
"output": "NO"
},
{
"input": "10\n95 51 52 8 44 39 77 17 96 88",
"output": "NO"
},
{
"input": "5\n14 91 91 91 84",
"output": "NO"
},
{
"input": "4\n92 18 29 93",
"output": "NO"
},
{
"input": "7\n23 37 39 8 72 31 85",
"output": "NO"
},
{
"input": "4\n61 28 3 81",
"output": "NO"
},
{
"input": "4\n83 100 81 75",
"output": "NO"
},
{
"input": "9\n95 7 97 61 90 7 30 65 39",
"output": "NO"
},
{
"input": "3\n90 39 98",
"output": "NO"
},
{
"input": "3\n76 9 12",
"output": "NO"
},
{
"input": "3\n69 26 73",
"output": "NO"
},
{
"input": "10\n55 39 93 42 97 40 36 38 11 97",
"output": "NO"
},
{
"input": "5\n21 57 40 94 17",
"output": "NO"
},
{
"input": "7\n35 91 87 78 17 71 63",
"output": "NO"
},
{
"input": "7\n20 21 95 73 49 98 53",
"output": "NO"
},
{
"input": "8\n46 4 30 85 52 6 84 13",
"output": "NO"
},
{
"input": "10\n79 84 22 38 23 22 33 42 13 96",
"output": "NO"
}
] | 109 | 0 | 0 | 938 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.