contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
sequencelengths 0
11
| title
stringclasses 522
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
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
697 | A | Pineapple Incident | PROGRAMMING | 900 | [
"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. | 500 | [
{
"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"
}
] | 1,525,513,301 | 101 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 7,065,600 | t, s, x = map(int, input().split())
if t <= x and (x - t) % s == 0:
print("YES")
else:
print("NO") | Title: Pineapple Incident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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.
Input Specification:
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.
Output Specification:
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.
Demo Input:
['3 10 4\n', '3 10 3\n', '3 8 51\n', '3 8 52\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n', 'YES\n']
Note:
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. | ```python
t, s, x = map(int, input().split())
if t <= x and (x - t) % s == 0:
print("YES")
else:
print("NO")
``` | 0 |
|
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
{
"input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1",
"output": "10"
},
{
"input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1",
"output": "29"
},
{
"input": "1\n1 1 1",
"output": "1"
},
{
"input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1",
"output": "4"
},
{
"input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "16"
}
] | 1,696,922,647 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | ProblemCount = int(input())
AcceptedSolutions = 0
for i in range(ProblemCount):
Problems = input().split(" ")
Votes = 0
for Vote in Problems:
if Vote == "1":
Votes += 1
if Votes >= 2:
AcceptedSolutions += 1
print(AcceptedSolutions)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Output Specification:
Print a single integer — the number of problems the friends will implement on the contest.
Demo Input:
['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | ```python
ProblemCount = int(input())
AcceptedSolutions = 0
for i in range(ProblemCount):
Problems = input().split(" ")
Votes = 0
for Vote in Problems:
if Vote == "1":
Votes += 1
if Votes >= 2:
AcceptedSolutions += 1
print(AcceptedSolutions)
``` | 3 |
|
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct. | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different. | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10) | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"input": "10\n68 47 67 29 63 71 71 65 54 56",
"output": "10"
},
{
"input": "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92",
"output": "4"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14",
"output": "0"
},
{
"input": "35\n37 41 46 39 47 39 44 47 44 42 44 43 47 39 46 39 38 42 39 37 40 44 41 42 41 42 39 42 36 36 42 36 42 42 42",
"output": "7"
},
{
"input": "40\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99",
"output": "47"
},
{
"input": "50\n48 52 44 54 53 56 62 49 39 41 53 39 40 64 53 50 62 48 40 52 51 48 40 52 61 62 62 61 48 64 55 57 56 40 48 58 41 60 60 56 64 50 64 45 48 45 46 63 59 57",
"output": "50"
},
{
"input": "57\n7 24 17 19 6 19 10 11 12 22 14 5 5 11 13 10 24 19 24 24 24 11 21 20 4 14 24 24 18 13 24 3 20 3 3 3 3 9 3 9 22 22 16 3 3 3 15 11 3 3 8 17 10 13 3 14 13",
"output": "3"
},
{
"input": "65\n58 50 35 44 35 37 36 58 38 36 58 56 56 49 48 56 58 43 40 44 52 44 58 58 57 50 43 35 55 39 38 49 53 56 50 42 41 56 34 57 49 38 34 51 56 38 58 40 53 46 48 34 38 43 49 49 58 56 41 43 44 34 38 48 36",
"output": "3"
},
{
"input": "69\n70 48 49 48 49 71 48 53 55 69 48 53 54 58 53 63 48 48 69 67 72 75 71 75 74 74 57 63 65 60 48 48 65 48 48 51 50 49 62 53 76 68 76 56 76 76 64 76 76 57 61 76 73 51 59 76 65 50 69 50 76 67 76 63 62 74 74 58 73",
"output": "73"
},
{
"input": "75\n70 65 64 71 71 64 71 64 68 71 65 64 65 68 71 66 66 69 68 63 69 65 71 69 68 68 71 67 71 65 65 65 71 71 65 69 63 66 62 67 64 63 62 64 67 65 62 69 62 64 69 62 67 64 67 70 64 63 64 64 69 62 62 64 70 62 62 68 67 69 62 64 66 70 68",
"output": "7"
},
{
"input": "84\n92 95 84 85 94 80 90 86 80 92 95 84 86 83 86 83 93 91 95 92 84 88 82 84 84 84 80 94 93 80 94 80 95 83 85 80 95 95 80 84 86 92 83 81 90 87 81 89 92 93 80 87 90 85 93 85 93 94 93 89 94 83 93 91 80 83 90 94 95 80 95 92 85 84 93 94 94 82 91 95 95 89 85 94",
"output": "15"
},
{
"input": "90\n86 87 72 77 82 71 75 78 61 67 79 90 64 94 94 74 85 87 73 76 71 71 60 69 77 73 76 80 82 57 62 57 57 83 76 72 75 87 72 94 77 85 59 82 86 69 62 80 95 73 83 94 79 85 91 68 85 74 93 95 68 75 89 93 83 78 95 78 83 77 81 85 66 92 63 65 75 78 67 91 77 74 59 86 77 76 90 67 70 64",
"output": "104"
},
{
"input": "91\n94 98 96 94 95 98 98 95 98 94 94 98 95 95 99 97 97 94 95 98 94 98 96 98 96 98 97 95 94 94 94 97 94 96 98 98 98 94 96 95 94 95 97 97 97 98 94 98 96 95 98 96 96 98 94 97 96 98 97 95 97 98 94 95 94 94 97 94 96 97 97 93 94 95 95 94 96 98 97 96 94 98 98 96 96 96 96 96 94 96 97",
"output": "33"
},
{
"input": "92\n44 28 32 29 41 41 36 39 40 39 41 35 41 28 35 27 41 34 28 38 43 43 41 38 27 26 28 36 30 29 39 32 35 35 32 30 39 30 37 27 41 41 28 30 43 31 35 33 36 28 44 40 41 35 31 42 37 38 37 34 39 40 27 40 33 33 44 43 34 33 34 34 35 38 38 37 30 39 35 41 45 42 41 32 33 33 31 30 43 41 43 43",
"output": "145"
},
{
"input": "93\n46 32 52 36 39 30 57 63 63 30 32 44 27 59 46 38 40 45 44 62 35 36 51 48 39 58 36 51 51 51 48 58 59 36 29 35 31 49 64 60 34 38 42 56 33 42 52 31 63 34 45 51 35 45 33 53 33 62 31 38 66 29 51 54 28 61 32 45 57 41 36 34 47 36 31 28 67 48 52 46 32 40 64 58 27 53 43 57 34 66 43 39 26",
"output": "76"
},
{
"input": "94\n56 55 54 31 32 42 46 29 24 54 40 40 20 45 35 56 32 33 51 39 26 56 21 56 51 27 29 39 56 52 54 43 43 55 48 51 44 49 52 49 23 19 19 28 20 26 45 33 35 51 42 36 25 25 38 23 21 35 54 50 41 20 37 28 42 20 22 43 37 34 55 21 24 38 19 41 45 34 19 33 44 54 38 31 23 53 35 32 47 40 39 31 20 34",
"output": "15"
},
{
"input": "95\n57 71 70 77 64 64 76 81 81 58 63 75 81 77 71 71 71 60 70 70 69 67 62 64 78 64 69 62 76 76 57 70 68 77 70 68 73 77 79 73 60 57 69 60 74 65 58 75 75 74 73 73 65 75 72 57 81 62 62 70 67 58 76 57 79 81 68 64 58 77 70 59 79 64 80 58 71 59 81 71 80 64 78 80 78 65 70 68 78 80 57 63 64 76 81",
"output": "11"
},
{
"input": "96\n96 95 95 95 96 97 95 97 96 95 98 96 97 95 98 96 98 96 98 96 98 95 96 95 95 95 97 97 95 95 98 98 95 96 96 95 97 96 98 96 95 97 97 95 97 97 95 94 96 96 97 96 97 97 96 94 94 97 95 95 95 96 95 96 95 97 97 95 97 96 95 94 97 97 97 96 97 95 96 94 94 95 97 94 94 97 97 97 95 97 97 95 94 96 95 95",
"output": "13"
},
{
"input": "97\n14 15 12 12 13 15 12 15 12 12 12 12 12 14 15 15 13 12 15 15 12 12 12 13 14 15 15 13 14 15 14 14 14 14 12 13 12 13 13 12 15 12 13 13 15 12 15 13 12 13 13 13 14 13 12 15 14 13 14 15 13 14 14 13 14 12 15 12 14 12 13 14 15 14 13 15 13 12 15 15 15 13 15 15 13 14 16 16 16 13 15 13 15 14 15 15 15",
"output": "104"
},
{
"input": "98\n37 69 35 70 58 69 36 47 41 63 60 54 49 35 55 50 35 53 52 43 35 41 40 49 38 35 48 70 42 35 35 65 56 54 44 59 59 48 51 49 59 67 35 60 69 35 58 50 35 44 48 69 41 58 44 45 35 47 70 61 49 47 37 39 35 51 44 70 72 65 36 41 63 63 48 66 45 50 50 71 37 52 72 67 72 39 72 39 36 64 48 72 69 49 45 72 72 67",
"output": "100"
},
{
"input": "99\n31 31 16 15 19 31 19 22 29 27 12 22 28 30 25 33 26 25 19 22 34 21 17 33 31 22 16 26 22 30 31 17 13 33 13 17 28 25 18 33 27 22 31 22 13 27 20 22 23 15 24 32 29 13 16 20 32 33 14 33 19 27 16 28 25 17 17 28 18 26 32 33 19 23 30 13 14 23 24 28 14 28 22 20 30 14 24 23 17 29 18 28 29 21 28 18 16 24 32",
"output": "107"
},
{
"input": "100\n37 54 39 29 32 49 21 13 34 21 16 42 34 27 16 26 7 34 51 9 11 27 16 40 36 7 48 52 30 42 42 52 51 11 32 26 6 7 28 54 48 51 6 54 42 20 51 48 46 4 4 31 47 6 9 16 8 23 36 50 49 30 47 37 45 24 48 26 8 50 18 24 27 13 39 7 37 34 5 43 42 19 34 23 52 38 35 6 29 11 53 49 21 29 36 22 45 33 51 22",
"output": "50"
},
{
"input": "100\n41 5 20 23 5 47 28 28 64 5 12 14 34 56 22 48 6 52 39 55 62 40 24 54 39 28 56 27 35 51 14 24 38 10 55 20 39 62 52 2 30 55 49 48 15 23 59 44 31 28 66 29 62 59 31 13 28 12 50 45 41 47 29 27 64 66 14 39 62 22 44 63 24 5 63 17 42 7 25 41 49 33 31 51 63 3 37 66 19 9 2 40 16 45 56 21 34 29 39 61",
"output": "59"
},
{
"input": "100\n66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95",
"output": "99"
},
{
"input": "100\n81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "1"
},
{
"input": "2\n100 99",
"output": "0"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "197"
},
{
"input": "100\n87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87",
"output": "0"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 3 2",
"output": "2"
}
] | 1,683,810,807 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | t=int(input())
l=list(map(int,input().split()))
s=0
ma=0
mi=0
m2=min(l)
for i in range(len(l)):
ma=l.index(max(l))
if l[i]==m2:
mi=i
s=ma+t-1-mi
print(s)
| Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
Input Specification:
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different.
Output Specification:
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
Demo Input:
['4\n33 44 11 22\n', '7\n10 10 58 31 63 40 76\n']
Demo Output:
['2\n', '10\n']
Note:
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10) | ```python
t=int(input())
l=list(map(int,input().split()))
s=0
ma=0
mi=0
m2=min(l)
for i in range(len(l)):
ma=l.index(max(l))
if l[i]==m2:
mi=i
s=ma+t-1-mi
print(s)
``` | 0 |
|
421 | A | Pasha and Hamsters | PROGRAMMING | 800 | [
"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 | 500 | [
{
"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"
}
] | 1,607,388,880 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 108 | 307,200 | n,a,b=map(int,input().split())
a_likes=list(map(int,input().strip().split()))
b_likes=list(map(int,input().strip().split()))
a_likes_set=set(a_likes)
b_likes_set=set(b_likes)
if a_likes_set & b_likes_set:
common=list(a_likes_set & b_likes_set)
for i in range(1,n+1):
if i in a_likes or i in common:
print("1",end=" ")
else:
print("2",end=" ") | Title: Pasha and Hamsters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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.
Input Specification:
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.
Output Specification:
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.
Demo Input:
['4 2 3\n1 2\n2 3 4\n', '5 5 2\n3 4 1 2 5\n2 3\n']
Demo Output:
['1 1 2 2\n', '1 1 1 1 1\n']
Note:
none | ```python
n,a,b=map(int,input().split())
a_likes=list(map(int,input().strip().split()))
b_likes=list(map(int,input().strip().split()))
a_likes_set=set(a_likes)
b_likes_set=set(b_likes)
if a_likes_set & b_likes_set:
common=list(a_likes_set & b_likes_set)
for i in range(1,n+1):
if i in a_likes or i in common:
print("1",end=" ")
else:
print("2",end=" ")
``` | -1 |
|
39 | B | Company Income Growth | PROGRAMMING | 1,300 | [
"greedy"
] | B. Company Income Growth | 2 | 64 | Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to *a*1 billion bourles, in 2002 — to *a*2 billion, ..., and in the current (2000<=+<=*n*)-th year — *a**n* billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year — 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers *a**i* can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers *a**i* from the sequence and leave only some subsequence that has perfect growth.
Thus Petya has to choose a sequence of years *y*1, *y*2, ..., *y**k*,so that in the year *y*1 the company income amounted to 1 billion bourles, in the year *y*2 — 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *a**i* (<=-<=100<=≤<=*a**i*<=≤<=100). The number *a**i* determines the income of BerSoft company in the (2000<=+<=*i*)-th year. The numbers in the line are separated by spaces. | Output *k* — the maximum possible length of a perfect sequence. In the next line output the sequence of years *y*1, *y*2, ..., *y**k*. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0. | [
"10\n-2 1 1 3 2 3 4 -10 -2 5\n",
"3\n-1 -2 -3\n"
] | [
"5\n2002 2005 2006 2007 2010\n",
"0\n"
] | none | 0 | [
{
"input": "10\n-2 1 1 3 2 3 4 -10 -2 5",
"output": "5\n2002 2005 2006 2007 2010 "
},
{
"input": "3\n-1 -2 -3",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1\n2002 "
},
{
"input": "2\n-1 1",
"output": "1\n2002 "
},
{
"input": "2\n-2 0",
"output": "0"
},
{
"input": "2\n3 -3",
"output": "0"
},
{
"input": "3\n1 1 1",
"output": "1\n2001 "
},
{
"input": "3\n-2 -2 1",
"output": "1\n2003 "
},
{
"input": "4\n-4 2 3 -1",
"output": "0"
},
{
"input": "5\n-3 -3 -4 2 -2",
"output": "0"
},
{
"input": "100\n-1 -9 0 -2 -7 -3 -1 -1 6 -5 -3 5 10 -5 7 7 4 9 -6 1 0 3 0 1 -9 -9 6 -8 3 7 -9 -4 -5 -6 8 2 2 7 2 2 0 -6 5 3 9 7 -7 -7 -2 6 -3 -4 10 3 3 -4 2 -9 9 9 -6 -1 -7 -3 -6 10 10 -1 -8 -3 8 1 10 9 -9 10 4 -10 -6 9 7 8 5 -3 2 2 2 -7 -6 0 -4 -1 4 -2 -4 -1 2 -8 10 9",
"output": "5\n2020 2036 2044 2077 2083 "
},
{
"input": "100\n5 -1 6 0 2 10 -6 6 -10 0 10 6 -10 3 8 4 2 6 3 -9 1 -1 -8 6 -6 -10 0 -3 -1 -6 -7 -9 -5 -5 5 -10 -3 4 -6 8 -4 2 2 8 2 -7 -4 -4 -9 4 -9 6 -4 -10 -8 -6 2 6 -4 3 3 4 -1 -9 8 9 -6 5 3 9 -4 0 -9 -10 3 -10 2 5 7 0 9 4 5 -3 5 -5 9 -4 6 -7 4 -1 -10 -1 -2 2 -1 4 -10 6",
"output": "6\n2021 2042 2060 2062 2068 2089 "
},
{
"input": "100\n10 9 -10 0 -9 1 10 -6 -3 8 0 5 -7 -9 9 -1 1 4 9 0 4 -7 3 10 -3 -10 -6 4 -3 0 -7 8 -6 -1 5 0 -6 1 5 -7 10 10 -2 -10 -4 -1 -1 2 5 1 6 -7 3 -1 1 10 4 2 4 -3 -10 9 4 5 1 -10 -1 -9 -8 -2 4 -4 -10 -9 -5 -9 -1 -3 -3 -8 -8 -3 6 -3 6 10 -4 -1 -3 8 -9 0 -2 2 1 6 -4 -7 -9 3",
"output": "6\n2006 2048 2053 2057 2064 2083 "
},
{
"input": "100\n-8 -3 -4 2 1 -9 5 4 4 -8 -8 6 -7 -1 9 -6 -1 1 -5 9 6 10 -8 -5 -2 10 7 10 -5 8 -7 5 -4 0 3 9 -9 -5 -4 -2 4 -1 -4 -5 -9 6 2 7 0 -2 2 3 -9 6 -10 6 5 -4 -9 -9 1 -7 -9 -3 -5 -8 4 0 4 10 -8 -6 -8 -9 5 -8 -6 -9 10 5 -6 -7 6 -5 8 3 1 3 7 3 -1 0 5 4 4 7 -7 5 -8 -2",
"output": "7\n2005 2047 2052 2067 2075 2083 2089 "
},
{
"input": "100\n-15 8 -20 -2 -16 3 -19 -15 16 19 -1 -17 -14 9 7 2 20 -16 8 20 10 3 17 -3 2 5 9 15 3 3 -17 12 7 17 -19 -15 -5 16 -10 -4 10 -15 -16 9 -15 15 -16 7 -15 12 -17 7 4 -8 9 -2 -19 14 12 -1 17 -6 19 14 19 -9 -12 3 14 -10 5 7 19 11 5 10 18 2 -6 -12 7 5 -9 20 10 2 -20 6 -10 -16 -6 -5 -15 -2 15 -12 0 -18 2 -5",
"output": "0"
},
{
"input": "100\n11 18 14 -19 -12 -5 -14 -3 13 14 -20 11 -6 12 -2 19 -16 -2 -4 -4 -18 -2 -15 5 -7 -18 11 5 -8 16 17 1 6 8 -20 13 17 -15 -20 7 16 -3 -17 -1 1 -18 2 9 4 2 -18 13 16 -14 -18 -14 16 19 13 4 -14 3 5 -7 5 -17 -14 13 20 16 -13 7 12 15 0 4 16 -16 -6 -15 18 -19 2 8 -4 -8 14 -4 20 -15 -20 14 7 -10 -17 -20 13 -1 -11 -4",
"output": "4\n2032 2047 2062 2076 "
},
{
"input": "100\n3 99 47 -26 96 90 21 -74 -19 -17 80 -43 -24 -82 -39 -40 44 84 87 72 -78 -94 -82 -87 96 71 -29 -90 66 49 -87 19 -31 97 55 -29 -98 16 -23 68 84 -54 74 -71 -60 -32 -72 95 -55 -17 -49 -73 63 39 -31 -91 40 -29 -60 -33 -33 49 93 -56 -81 -18 38 45 -29 63 -37 27 75 13 -100 52 -51 75 -38 -49 28 39 -7 -37 -86 100 -8 28 -89 -57 -17 -52 -98 -92 56 -49 -24 92 28 31",
"output": "0"
},
{
"input": "100\n-36 -88 -23 -71 33 53 21 49 97 -50 -91 24 -83 -100 -77 88 -56 -31 -27 7 -74 -69 -75 -59 78 -66 53 21 -41 72 -31 -93 26 98 58 78 -95 -64 -2 34 74 14 23 -25 -51 -94 -46 100 -44 79 46 -8 79 25 -55 16 35 67 29 58 49 75 -53 80 63 -50 -59 -5 -71 -72 -57 75 -71 6 -5 -44 34 -2 -10 -58 -98 67 -42 22 95 46 -58 88 62 82 85 -74 -94 -5 -64 12 -8 44 -57 87",
"output": "0"
},
{
"input": "100\n-76 -73 -93 85 -30 66 -29 -79 13 -82 -12 90 8 -68 86 15 -5 55 -91 92 80 5 83 19 59 -1 -17 83 52 44 25 -3 83 -51 62 -66 -91 58 20 51 15 -70 -77 22 -92 -4 -70 55 -33 -27 -59 6 94 60 -79 -28 -20 -38 -83 100 -20 100 51 -35 -44 -82 44 -5 88 -6 -26 -79 -16 -2 -61 12 -81 -80 68 -68 -23 96 -77 80 -75 -57 93 97 12 20 -65 -46 -90 81 16 -77 -43 -3 8 -58",
"output": "0"
},
{
"input": "100\n-64 -18 -21 46 28 -100 21 -98 49 -44 -38 52 -85 62 42 -85 19 -27 88 -45 28 -86 -20 15 34 61 17 88 95 21 -40 -2 -12 90 -61 30 7 -13 -74 43 -57 43 -30 51 -19 -51 -22 -2 -76 85 1 -53 -31 -77 96 -61 61 88 -62 88 -6 -59 -70 18 -65 90 91 -27 -86 37 8 -92 -82 -78 -57 -81 17 -53 3 29 -88 -92 -28 49 -2 -41 32 -89 -38 49 22 37 -17 -1 -78 -80 -12 36 -95 30",
"output": "1\n2051 "
},
{
"input": "1\n1",
"output": "1\n2001 "
},
{
"input": "2\n1 2",
"output": "2\n2001 2002 "
},
{
"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": "100\n2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 "
},
{
"input": "100\n-29 -92 -94 81 -100 1 -29 2 3 97 -37 4 5 -52 6 7 -81 86 8 9 10 98 36 -99 11 -18 12 -46 13 14 15 16 17 18 19 20 21 23 53 22 23 24 6 17 45 25 99 26 -53 -51 48 -11 71 27 -56 28 29 -36 30 31 61 -53 -64 32 33 89 -90 34 35 54 36 -89 13 -89 5 37 38 39 -57 26 55 80 40 63 41 42 43 44 92 45 46 47 -10 -10 -32 48 49 50 -10 -99",
"output": "50\n2006 2008 2009 2012 2013 2015 2016 2019 2020 2021 2025 2027 2029 2030 2031 2032 2033 2034 2035 2036 2037 2040 2041 2042 2046 2048 2054 2056 2057 2059 2060 2064 2065 2068 2069 2071 2076 2077 2078 2083 2085 2086 2087 2088 2090 2091 2092 2096 2097 2098 "
},
{
"input": "100\n1 2 84 -97 3 -59 30 -55 4 -6 80 5 6 7 -8 8 3 -96 88 9 10 -20 -95 11 12 67 5 4 -15 -62 -74 13 14 15 16 17 18 19 20 21 22 -15 23 -35 -17 24 25 -99 26 27 69 2 -92 -96 -77 28 29 -95 -75 30 -36 31 17 -88 10 52 32 33 34 -94 35 -38 -16 36 37 38 31 -58 39 -81 83 46 40 41 42 43 -44 44 4 49 -60 17 64 45 46 47 48 49 -38 50",
"output": "50\n2001 2002 2005 2009 2012 2013 2014 2016 2020 2021 2024 2025 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2043 2046 2047 2049 2050 2056 2057 2060 2062 2067 2068 2069 2071 2074 2075 2076 2079 2083 2084 2085 2086 2088 2094 2095 2096 2097 2098 2100 "
},
{
"input": "100\n1 2 80 30 95 51 -3 -12 3 -11 4 -90 5 6 7 8 -18 52 77 -82 9 10 11 -51 -16 70 12 13 14 15 16 17 58 18 36 19 -86 20 21 40 -53 94 22 23 27 67 24 -90 -38 17 -71 40 25 72 -82 26 27 -4 28 29 30 31 32 67 33 34 90 42 -52 35 36 37 -6 38 39 -11 30 40 41 42 -42 21 -96 43 -50 44 -73 16 45 90 46 47 48 2 -37 -88 49 -27 -43 50",
"output": "50\n2001 2002 2009 2011 2013 2014 2015 2016 2021 2022 2023 2027 2028 2029 2030 2031 2032 2034 2036 2038 2039 2043 2044 2047 2053 2056 2057 2059 2060 2061 2062 2063 2065 2066 2070 2071 2072 2074 2075 2078 2079 2080 2084 2086 2089 2091 2092 2093 2097 2100 "
},
{
"input": "100\n1 2 3 -72 6 4 5 6 7 8 9 10 11 -57 12 13 14 -37 74 15 16 17 3 18 19 20 21 22 -6 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 -24 39 40 41 42 43 44 45 -52 46 -65 47 -82 48 49 50 47 -28 51 52 53 54 55 -30 56 57 58 59 12 60 61 62 63 -14 64 65 66 67 -77 68 69 70 71 72 73 74 -4 -6 -75 75 -26 76 49 77 -86",
"output": "77\n2001 2002 2003 2006 2007 2008 2009 2010 2011 2012 2013 2015 2016 2017 2020 2021 2022 2024 2025 2026 2027 2028 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2047 2048 2049 2050 2051 2052 2053 2055 2057 2059 2060 2061 2064 2065 2066 2067 2068 2070 2071 2072 2073 2075 2076 2077 2078 2080 2081 2082 2083 2085 2086 2087 2088 2089 2090 2091 2095 2097 2099 "
},
{
"input": "100\n10 5 -69 1 -79 -57 -80 87 -38 -54 -91 33 29 81 20 -58 -97 70 2 -13 71 57 -15 98 -18 100 34 -25 -39 75 100 -88 3 95 48 -92 -20 -13 5 4 -19 -99 4 -46 -35 12 -43 -30 -37 -51 77 90 -47 -87 3 -84 -62 -51 69 -38 74 -63 -5 5 6 7 -65 90 -33 -23 8 19 -69 -98 24 28 100 9 -90 -34 -69 72 -15 8 27 -80 6 33 62 -57 -4 10 40 81 -78 58 43 83 57 21",
"output": "10\n2004 2019 2033 2040 2064 2065 2066 2071 2078 2092 "
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "10\n2 3 1 3 3 2 1 2 1 2",
"output": "2\n2003 2006 "
},
{
"input": "15\n4 1 4 6 3 2 1 1 3 2 4 4 1 4 1",
"output": "4\n2002 2006 2009 2011 "
},
{
"input": "15\n3 3 3 2 2 2 1 1 1 2 2 2 4 4 4",
"output": "2\n2007 2010 "
},
{
"input": "15\n6 5 2 3 4 1 3 2 4 5 1 2 6 4 4",
"output": "2\n2006 2008 "
}
] | 1,582,375,003 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 218 | 0 | n = int(input())
a = list(map(int, input().split()))
j = 1
ans = []
for i in range(len(a)):
if a[i] == j:
ans.append(2000 + i + 1)
j += 1
if len(ans) == 0:
print(0)
else:
print(len(ans))
print(*ans) | Title: Company Income Growth
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to *a*1 billion bourles, in 2002 — to *a*2 billion, ..., and in the current (2000<=+<=*n*)-th year — *a**n* billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year — 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers *a**i* can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers *a**i* from the sequence and leave only some subsequence that has perfect growth.
Thus Petya has to choose a sequence of years *y*1, *y*2, ..., *y**k*,so that in the year *y*1 the company income amounted to 1 billion bourles, in the year *y*2 — 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *a**i* (<=-<=100<=≤<=*a**i*<=≤<=100). The number *a**i* determines the income of BerSoft company in the (2000<=+<=*i*)-th year. The numbers in the line are separated by spaces.
Output Specification:
Output *k* — the maximum possible length of a perfect sequence. In the next line output the sequence of years *y*1, *y*2, ..., *y**k*. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
Demo Input:
['10\n-2 1 1 3 2 3 4 -10 -2 5\n', '3\n-1 -2 -3\n']
Demo Output:
['5\n2002 2005 2006 2007 2010\n', '0\n']
Note:
none | ```python
n = int(input())
a = list(map(int, input().split()))
j = 1
ans = []
for i in range(len(a)):
if a[i] == j:
ans.append(2000 + i + 1)
j += 1
if len(ans) == 0:
print(0)
else:
print(len(ans))
print(*ans)
``` | 3.9455 |
380 | A | Sereja and Prefixes | PROGRAMMING | 1,600 | [
"binary search",
"brute force"
] | null | null | Sereja loves number sequences very much. That's why he decided to make himself a new one following a certain algorithm.
Sereja takes a blank piece of paper. Then he starts writing out the sequence in *m* stages. Each time he either adds a new number to the end of the sequence or takes *l* first elements of the current sequence and adds them *c* times to the end. More formally, if we represent the current sequence as *a*1,<=*a*2,<=...,<=*a**n*, then after we apply the described operation, the sequence transforms into *a*1,<=*a*2,<=...,<=*a**n*[,<=*a*1,<=*a*2,<=...,<=*a**l*] (the block in the square brackets must be repeated *c* times).
A day has passed and Sereja has completed the sequence. He wonders what are the values of some of its elements. Help Sereja. | The first line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of stages to build a sequence.
Next *m* lines contain the description of the stages in the order they follow. The first number in the line is a type of stage (1 or 2). Type 1 means adding one number to the end of the sequence, in this case the line contains integer *x**i* (1<=≤<=*x**i*<=≤<=105) — the number to add. Type 2 means copying a prefix of length *l**i* to the end *c**i* times, in this case the line further contains two integers *l**i*,<=*c**i* (1<=≤<=*l**i*<=≤<=105,<=1<=≤<=*c**i*<=≤<=104), *l**i* is the length of the prefix, *c**i* is the number of copyings. It is guaranteed that the length of prefix *l**i* is never larger than the current length of the sequence.
The next line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements Sereja is interested in. The next line contains the numbers of elements of the final sequence Sereja is interested in. The numbers are given in the strictly increasing order. It is guaranteed that all numbers are strictly larger than zero and do not exceed the length of the resulting sequence. Consider the elements of the final sequence numbered starting from 1 from the beginning to the end of the sequence.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the elements that Sereja is interested in, in the order in which their numbers occur in the input. | [
"6\n1 1\n1 2\n2 2 1\n1 3\n2 5 2\n1 4\n16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n"
] | [
"1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4\n"
] | none | 500 | [
{
"input": "6\n1 1\n1 2\n2 2 1\n1 3\n2 5 2\n1 4\n16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16",
"output": "1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4"
},
{
"input": "2\n1 33085\n1 44638\n2\n1 2",
"output": "33085 44638"
},
{
"input": "10\n1 57757\n1 45234\n1 80807\n1 38496\n1 27469\n1 42645\n1 72643\n1 33235\n1 10843\n1 80598\n10\n1 2 3 4 5 6 7 8 9 10",
"output": "57757 45234 80807 38496 27469 42645 72643 33235 10843 80598"
},
{
"input": "3\n1 97601\n1 32580\n1 70519\n3\n1 2 3",
"output": "97601 32580 70519"
},
{
"input": "7\n1 53989\n1 47249\n1 71935\n2 1 3\n1 84520\n1 84185\n2 6 1\n14\n1 2 3 4 5 6 7 8 9 10 11 12 13 14",
"output": "53989 47249 71935 53989 53989 53989 84520 84185 53989 47249 71935 53989 53989 53989"
},
{
"input": "1\n1 1\n1\n1",
"output": "1"
}
] | 1,579,418,377 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 78 | 307,200 | from bisect import bisect_left
def fun(ind,alr,ll,sll):
if ind in alr:
return alr[ind]
k = bisect_left(sll,ind)
md = ll[k]
return fun(ind%md,alr,ll,sll)
pos = {}
m = int(input())
l = 0
cp = []
cpl = []
for _ in range(0,m):
q = [int(i) for i in input().split()]
if q[0] == 1:
pos[l] = q[1]
l += 1
else:
cp.append(q[1])
l += q[1]*q[2]
cpl.append(l)
n = int(input())
qq = [int(i)-1 for i in input().split()]
ans = [fun(i,pos,cp,cpl) for i in qq]
print(*ans)
| Title: Sereja and Prefixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja loves number sequences very much. That's why he decided to make himself a new one following a certain algorithm.
Sereja takes a blank piece of paper. Then he starts writing out the sequence in *m* stages. Each time he either adds a new number to the end of the sequence or takes *l* first elements of the current sequence and adds them *c* times to the end. More formally, if we represent the current sequence as *a*1,<=*a*2,<=...,<=*a**n*, then after we apply the described operation, the sequence transforms into *a*1,<=*a*2,<=...,<=*a**n*[,<=*a*1,<=*a*2,<=...,<=*a**l*] (the block in the square brackets must be repeated *c* times).
A day has passed and Sereja has completed the sequence. He wonders what are the values of some of its elements. Help Sereja.
Input Specification:
The first line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of stages to build a sequence.
Next *m* lines contain the description of the stages in the order they follow. The first number in the line is a type of stage (1 or 2). Type 1 means adding one number to the end of the sequence, in this case the line contains integer *x**i* (1<=≤<=*x**i*<=≤<=105) — the number to add. Type 2 means copying a prefix of length *l**i* to the end *c**i* times, in this case the line further contains two integers *l**i*,<=*c**i* (1<=≤<=*l**i*<=≤<=105,<=1<=≤<=*c**i*<=≤<=104), *l**i* is the length of the prefix, *c**i* is the number of copyings. It is guaranteed that the length of prefix *l**i* is never larger than the current length of the sequence.
The next line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements Sereja is interested in. The next line contains the numbers of elements of the final sequence Sereja is interested in. The numbers are given in the strictly increasing order. It is guaranteed that all numbers are strictly larger than zero and do not exceed the length of the resulting sequence. Consider the elements of the final sequence numbered starting from 1 from the beginning to the end of the sequence.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print the elements that Sereja is interested in, in the order in which their numbers occur in the input.
Demo Input:
['6\n1 1\n1 2\n2 2 1\n1 3\n2 5 2\n1 4\n16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n']
Demo Output:
['1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4\n']
Note:
none | ```python
from bisect import bisect_left
def fun(ind,alr,ll,sll):
if ind in alr:
return alr[ind]
k = bisect_left(sll,ind)
md = ll[k]
return fun(ind%md,alr,ll,sll)
pos = {}
m = int(input())
l = 0
cp = []
cpl = []
for _ in range(0,m):
q = [int(i) for i in input().split()]
if q[0] == 1:
pos[l] = q[1]
l += 1
else:
cp.append(q[1])
l += q[1]*q[2]
cpl.append(l)
n = int(input())
qq = [int(i)-1 for i in input().split()]
ans = [fun(i,pos,cp,cpl) for i in qq]
print(*ans)
``` | 0 |
|
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"output": "-1"
},
{
"input": "1000000000000000 1000000000",
"output": "-1"
},
{
"input": "1000000000000000 100",
"output": "1953125"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "4 3",
"output": "4"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "9 3",
"output": "9"
},
{
"input": "21 3",
"output": "7"
},
{
"input": "67280421310721 1",
"output": "1"
},
{
"input": "6 3",
"output": "3"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "16 3",
"output": "4"
},
{
"input": "1 1000",
"output": "-1"
},
{
"input": "16 4",
"output": "8"
},
{
"input": "36 8",
"output": "18"
},
{
"input": "49 4",
"output": "-1"
},
{
"input": "9 4",
"output": "-1"
},
{
"input": "16 1",
"output": "1"
},
{
"input": "16 6",
"output": "-1"
},
{
"input": "16 5",
"output": "16"
},
{
"input": "25 4",
"output": "-1"
},
{
"input": "4010815561 2",
"output": "63331"
},
{
"input": "49 3",
"output": "49"
},
{
"input": "36 6",
"output": "9"
},
{
"input": "36 10",
"output": "-1"
},
{
"input": "25 3",
"output": "25"
},
{
"input": "22876792454961 28",
"output": "7625597484987"
},
{
"input": "1234 2",
"output": "2"
},
{
"input": "179458711 2",
"output": "179458711"
},
{
"input": "900104343024121 100000",
"output": "-1"
},
{
"input": "8 3",
"output": "4"
},
{
"input": "100 6",
"output": "20"
},
{
"input": "15500 26",
"output": "-1"
},
{
"input": "111111 1",
"output": "1"
},
{
"input": "100000000000000 200",
"output": "160000000000"
},
{
"input": "1000000000000 100",
"output": "6400000"
},
{
"input": "100 10",
"output": "-1"
},
{
"input": "1000000000039 2",
"output": "1000000000039"
},
{
"input": "64 5",
"output": "16"
},
{
"input": "999999961946176 33",
"output": "63245552"
},
{
"input": "376219076689 3",
"output": "376219076689"
},
{
"input": "999999961946176 63",
"output": "999999961946176"
},
{
"input": "1048576 12",
"output": "2048"
},
{
"input": "745 21",
"output": "-1"
},
{
"input": "748 6",
"output": "22"
},
{
"input": "999999961946176 50",
"output": "161082468097"
},
{
"input": "10 3",
"output": "5"
},
{
"input": "1099511627776 22",
"output": "2097152"
},
{
"input": "1000000007 100010",
"output": "-1"
},
{
"input": "3 1",
"output": "1"
},
{
"input": "100 8",
"output": "50"
},
{
"input": "100 7",
"output": "25"
},
{
"input": "7 2",
"output": "7"
},
{
"input": "999999961946176 64",
"output": "-1"
},
{
"input": "20 5",
"output": "10"
},
{
"input": "999999999999989 2",
"output": "999999999999989"
},
{
"input": "100000000000000 114",
"output": "10240000"
},
{
"input": "99999640000243 3",
"output": "9999991"
},
{
"input": "999998000001 566",
"output": "333332666667"
},
{
"input": "99999820000081 2",
"output": "9999991"
},
{
"input": "49000042000009 3",
"output": "49000042000009"
},
{
"input": "151491429961 4",
"output": "-1"
},
{
"input": "32416190071 2",
"output": "32416190071"
},
{
"input": "1000 8",
"output": "25"
},
{
"input": "1999967841 15",
"output": "1999967841"
},
{
"input": "26880 26880",
"output": "-1"
},
{
"input": "151491429961 3",
"output": "151491429961"
},
{
"input": "90000000000 300",
"output": "100000000"
},
{
"input": "98765004361 10",
"output": "-1"
},
{
"input": "15 2",
"output": "3"
},
{
"input": "16 2",
"output": "2"
},
{
"input": "1996 2",
"output": "2"
},
{
"input": "1997 2",
"output": "1997"
},
{
"input": "1999 2",
"output": "1999"
},
{
"input": "1998 2",
"output": "2"
},
{
"input": "1998 1",
"output": "1"
},
{
"input": "1998 7",
"output": "27"
},
{
"input": "1998 8",
"output": "37"
},
{
"input": "100000380000361 2",
"output": "10000019"
},
{
"input": "15 1",
"output": "1"
},
{
"input": "100000000000000 226",
"output": "-1"
},
{
"input": "844030857550613 517",
"output": "-1"
},
{
"input": "4567890 14",
"output": "430"
},
{
"input": "123123123 123123123",
"output": "-1"
},
{
"input": "24 4",
"output": "4"
},
{
"input": "999999993568952 17",
"output": "31622777"
},
{
"input": "99999999994190 9",
"output": "241656799"
},
{
"input": "999997874844049 4",
"output": "-1"
},
{
"input": "99999999999931 2",
"output": "99999999999931"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "67280421310721 2",
"output": "67280421310721"
}
] | 1,599,417,466 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 614,400 | from _collections import OrderedDict
n,k=map(int,input().split());r=[]
for i in range(1,int(n**.5)+1):
if n%i==0:
r.append(i)
r.append(n//i)
r=sorted(OrderedDict.fromkeys(r))
print(-1 if k>len(r) else r[k-1]) | Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109).
Output Specification:
If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*.
Demo Input:
['4 2\n', '5 3\n', '12 5\n']
Demo Output:
['2\n', '-1\n', '6\n']
Note:
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | ```python
from _collections import OrderedDict
n,k=map(int,input().split());r=[]
for i in range(1,int(n**.5)+1):
if n%i==0:
r.append(i)
r.append(n//i)
r=sorted(OrderedDict.fromkeys(r))
print(-1 if k>len(r) else r[k-1])
``` | 0 |
|
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party? | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "9 240",
"output": "0"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "9 235",
"output": "1"
},
{
"input": "9 236",
"output": "0"
},
{
"input": "5 225",
"output": "2"
},
{
"input": "5 226",
"output": "1"
},
{
"input": "4 210",
"output": "3"
},
{
"input": "4 211",
"output": "2"
},
{
"input": "4 191",
"output": "3"
},
{
"input": "10 165",
"output": "5"
},
{
"input": "10 166",
"output": "4"
},
{
"input": "8 100",
"output": "7"
},
{
"input": "8 101",
"output": "6"
},
{
"input": "8 60",
"output": "8"
},
{
"input": "8 61",
"output": "7"
},
{
"input": "10 15",
"output": "9"
},
{
"input": "10 16",
"output": "8"
},
{
"input": "4 100",
"output": "4"
},
{
"input": "4 101",
"output": "4"
},
{
"input": "7 167",
"output": "4"
},
{
"input": "10 164",
"output": "5"
},
{
"input": "9 170",
"output": "4"
},
{
"input": "8 160",
"output": "5"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "8 123",
"output": "6"
},
{
"input": "2 99",
"output": "2"
},
{
"input": "10 88",
"output": "7"
},
{
"input": "1 235",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 240",
"output": "0"
},
{
"input": "1 55",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "3 240",
"output": "0"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "2 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "2 236",
"output": "0"
},
{
"input": "10 2",
"output": "9"
},
{
"input": "3 239",
"output": "0"
},
{
"input": "1 237",
"output": "0"
},
{
"input": "7 8",
"output": "7"
},
{
"input": "10 235",
"output": "1"
}
] | 1,685,164,680 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | n, k = map(int, input().split())
problems_solved = 0
time_left = 240 - k
time_taken = 0
while time_taken <= time_left:
if time_taken + (5 * problems_solved + 1) < time_left and problems_solved + 1 <= n:
problems_solved += 1
time_taken += (5 * problems_solved)
print(problems_solved) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party?
Input Specification:
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Output Specification:
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
Demo Input:
['3 222\n', '4 190\n', '7 1\n']
Demo Output:
['2\n', '4\n', '7\n']
Note:
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | ```python
n, k = map(int, input().split())
problems_solved = 0
time_left = 240 - k
time_taken = 0
while time_taken <= time_left:
if time_taken + (5 * problems_solved + 1) < time_left and problems_solved + 1 <= n:
problems_solved += 1
time_taken += (5 * problems_solved)
print(problems_solved)
``` | 0 |
|
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds. | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G". | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"output": "GBBGBB"
},
{
"input": "8 3\nBBGBGBGB",
"output": "GGBGBBBB"
},
{
"input": "10 3\nBBGBBBBBBG",
"output": "GBBBBBGBBB"
},
{
"input": "22 7\nGBGGBGGGGGBBBGGBGBGBBB",
"output": "GGGGGGGGBGGBGGBBBBBBBB"
},
{
"input": "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG",
"output": "GGBGBGBGBGBGGGBBGBGBGBGBBBGBGBGBGBGBGBGBGBGBGGBGBB"
},
{
"input": "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG",
"output": "GGGGGGGGGGGGBGGBGBGBGBGBGGGGGGBGBGBGBGBGBGGBGGBGBB"
},
{
"input": "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBGBGGGGGBGBBGBGBGGG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "20 20\nBBGGBGGGGBBBGBBGGGBB",
"output": "GGGGGGGGGGBBBBBBBBBB"
},
{
"input": "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB",
"output": "GGGGGGGBGBGBGGGGGBGBBBBBBBB"
},
{
"input": "46 11\nBGGGGGBGBGGBGGGBBGBBGBBGGBBGBBGBGGGGGGGBGBGBGB",
"output": "GGGGGGGGGGGBGGGGGBBGBGBGBGBGBGBGBGBGBGBGBBBBBB"
},
{
"input": "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB",
"output": "GGGGBBBBBGBGBGBGBBBGBBBBBBGBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 8\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGB",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBB"
},
{
"input": "50 13\nGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "GGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "1 1\nB",
"output": "B"
},
{
"input": "1 1\nG",
"output": "G"
},
{
"input": "1 50\nB",
"output": "B"
},
{
"input": "1 50\nG",
"output": "G"
},
{
"input": "50 50\nBBBBBBBBGGBBBBBBGBBBBBBBBBBBGBBBBBBBBBBBBBBGBBBBBB",
"output": "GGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 50\nGGBBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBGGGGGGBG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBB"
},
{
"input": "6 3\nGGBBBG",
"output": "GGGBBB"
},
{
"input": "26 3\nGBBGBBBBBGGGBGBGGGBGBGGBBG",
"output": "GGBBBBGBGBGBGGGBGBGGGBGBBB"
},
{
"input": "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB",
"output": "GGGGBGBGGGBBBBBGBGBGBGGGBGGBGBGBGBGBGBGBGBBBBB"
},
{
"input": "44 8\nBGBBBBBBBBBGGBBGBGBGGBBBBBGBBGBBBBBBBBBGBBGB",
"output": "GBBGBGBGBGBGBGBBBBGBBGBBBBBBBBBGBBGBBBBBBBBB"
},
{
"input": "20 20\nBBGGBGGGGBBBGBBGGGBB",
"output": "GGGGGGGGGGBBBBBBBBBB"
},
{
"input": "30 25\nBGGBBGBGGBGBGBBGBGGGGBGBGGBBBB",
"output": "GGGGGGGGGGGGGGGBBBBBBBBBBBBBBB"
},
{
"input": "17 42\nBBGBGBGGGGGGBBGGG",
"output": "GGGGGGGGGGGBBBBBB"
},
{
"input": "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG",
"output": "GGGGGGGGGGGGGGGGGGBBBBBBBBBBBB"
},
{
"input": "31 33\nBBGGBBGGBGBBBBGGBGBBBGBGGBBGBBB",
"output": "GGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB"
},
{
"input": "2 2\nBG",
"output": "GB"
},
{
"input": "8 8\nGGGBGGBB",
"output": "GGGGGBBB"
},
{
"input": "34 34\nBGGBBBBGGBBGBGGGGGGBBGGGGGBGGBGGGB",
"output": "GGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBB"
},
{
"input": "34 20\nBBBBGBGGGBGGGBGBGGBBBBGGBBGGGBGBBG",
"output": "GGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBB"
},
{
"input": "50 50\nBBGBBBBBBBBBBBBGBBBGBBBBBBBGBBBBBBGBBBGBBGBBGBBBGG",
"output": "GGGGGGGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "10 10\nGGGGGGGGGG",
"output": "GGGGGGGGGG"
},
{
"input": "10 10\nBBBBBBBBBB",
"output": "BBBBBBBBBB"
},
{
"input": "10 10\nBGBGBGBGBG",
"output": "GGGGGBBBBB"
},
{
"input": "1 1\nB",
"output": "B"
}
] | 1,697,536,935 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | #266B:Queue at the School
n,t=map(int,input().split())
s=input()
ans=[]
for i in range(len(s)):
ans.append(s[i])
for j in range(t):
for i in range(len(s)-1):
if s[i]=="B" and s[i+1]=="G":
ans[i]="G"
ans[i+1]="B"
for i in range(len(s)):
print(ans[i],end="") | Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
Output Specification:
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
Demo Input:
['5 1\nBGGBG\n', '5 2\nBGGBG\n', '4 1\nGGGB\n']
Demo Output:
['GBGGB\n', 'GGBGB\n', 'GGGB\n']
Note:
none | ```python
#266B:Queue at the School
n,t=map(int,input().split())
s=input()
ans=[]
for i in range(len(s)):
ans.append(s[i])
for j in range(t):
for i in range(len(s)-1):
if s[i]=="B" and s[i+1]=="G":
ans[i]="G"
ans[i+1]="B"
for i in range(len(s)):
print(ans[i],end="")
``` | 0 |
|
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving each other one candy more than they received in the previous turn.
This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
"output": "Valera"
},
{
"input": "999963734 999994456",
"output": "Vladik"
},
{
"input": "1000000000 1000000000",
"output": "Vladik"
},
{
"input": "946 879",
"output": "Valera"
},
{
"input": "10819 45238",
"output": "Vladik"
},
{
"input": "101357 236928",
"output": "Vladik"
},
{
"input": "1033090 7376359",
"output": "Vladik"
},
{
"input": "9754309 9525494",
"output": "Valera"
},
{
"input": "90706344 99960537",
"output": "Vladik"
},
{
"input": "965161805 908862070",
"output": "Valera"
},
{
"input": "9 11",
"output": "Valera"
},
{
"input": "3 2",
"output": "Vladik"
},
{
"input": "6 6",
"output": "Vladik"
},
{
"input": "4 4",
"output": "Valera"
},
{
"input": "5 5",
"output": "Valera"
},
{
"input": "5 4",
"output": "Valera"
},
{
"input": "12345680 1",
"output": "Valera"
},
{
"input": "9 10",
"output": "Valera"
},
{
"input": "678 76687",
"output": "Vladik"
},
{
"input": "1 678",
"output": "Vladik"
},
{
"input": "45 1678",
"output": "Vladik"
},
{
"input": "3 3",
"output": "Vladik"
},
{
"input": "10 11",
"output": "Valera"
},
{
"input": "2 1",
"output": "Valera"
},
{
"input": "1 2",
"output": "Vladik"
},
{
"input": "2 2",
"output": "Vladik"
},
{
"input": "4 5",
"output": "Valera"
},
{
"input": "9 6",
"output": "Valera"
},
{
"input": "1 5",
"output": "Vladik"
},
{
"input": "7 8",
"output": "Vladik"
},
{
"input": "1000000000 999982505",
"output": "Valera"
},
{
"input": "12 12",
"output": "Vladik"
},
{
"input": "1000 950",
"output": "Valera"
},
{
"input": "10 9",
"output": "Valera"
},
{
"input": "100 9",
"output": "Valera"
},
{
"input": "1000 996",
"output": "Vladik"
},
{
"input": "9 5",
"output": "Valera"
}
] | 1,534,007,188 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 109 | 0 | a, b = map(int, input().split())
temp = int(b ** 0.5)
A = int(a ** 0.5)
B = temp - (temp * (temp + 1) > b)
print(('Vladik', 'Valera')[A > B])
| Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving each other one candy more than they received in the previous turn.
This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
Input Specification:
Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively.
Output Specification:
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
Demo Input:
['1 1\n', '7 6\n']
Demo Output:
['Valera\n', 'Vladik\n']
Note:
Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
a, b = map(int, input().split())
temp = int(b ** 0.5)
A = int(a ** 0.5)
B = temp - (temp * (temp + 1) > b)
print(('Vladik', 'Valera')[A > B])
``` | 3 |
|
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"output": "ypg"
},
{
"input": "3\nexhll\nexhll\narruapexj",
"output": "arruapexj\nexhll"
},
{
"input": "3\nfv\nle\nle",
"output": "le\nfv"
},
{
"input": "8\nm\nm\nm\nm\nm\nm\nm\nm",
"output": "m"
},
{
"input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr",
"output": "r\nu\nb\nk\nw\ni"
},
{
"input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok",
"output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne"
},
{
"input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe",
"output": "we\nklrj"
},
{
"input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh",
"output": "zncybqmh\naeebef\nn"
},
{
"input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo",
"output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj"
},
{
"input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn",
"output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy"
},
{
"input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg",
"output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg"
},
{
"input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh",
"output": "vhh\nfa"
},
{
"input": "2\naa\nbb",
"output": "bb\naa"
},
{
"input": "2\naa\na",
"output": "a\naa"
},
{
"input": "3\naa\naa\naa",
"output": "aa"
},
{
"input": "5\naa\na\naa\na\naa",
"output": "aa\na"
},
{
"input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa",
"output": "aaa\naaaaaaa\naa\na\naaaa"
},
{
"input": "5\na\naa\naaa\naaaa\na",
"output": "a\naaaa\naaa\naa"
},
{
"input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa",
"output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa"
},
{
"input": "3\na\naa\naaa",
"output": "aaa\naa\na"
},
{
"input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz",
"output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz"
}
] | 1,656,317,114 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,198,400 | di={}
for i in range (int(input())):
x=input()
if x in di:
di[x]+=1
else:
di[x]=1
print(sorted(di.values(),reverse=True))
for i in di.keys():
print(i) | Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output Specification:
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Demo Input:
['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n']
Demo Output:
['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n']
Note:
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | ```python
di={}
for i in range (int(input())):
x=input()
if x in di:
di[x]+=1
else:
di[x]=1
print(sorted(di.values(),reverse=True))
for i in di.keys():
print(i)
``` | 0 |
|
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.
Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments coincide. | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 7\n4 7\n2 8",
"output": "-1"
},
{
"input": "3\n2 5\n3 4\n2 3",
"output": "1"
},
{
"input": "16\n15 15\n8 12\n6 9\n15 16\n8 14\n3 12\n7 19\n9 13\n5 16\n9 17\n10 15\n9 14\n9 9\n18 19\n5 15\n6 19",
"output": "-1"
},
{
"input": "9\n1 10\n7 8\n6 7\n1 4\n5 9\n2 8\n3 10\n1 1\n2 3",
"output": "1"
},
{
"input": "1\n1 100000",
"output": "1"
},
{
"input": "6\n2 2\n3 3\n3 5\n4 5\n1 1\n1 5",
"output": "6"
},
{
"input": "33\n2 18\n4 14\n2 16\n10 12\n4 6\n9 17\n2 8\n4 12\n8 20\n1 10\n11 14\n11 17\n8 15\n3 16\n3 4\n6 9\n6 19\n4 17\n17 19\n6 16\n3 12\n1 7\n6 20\n8 16\n12 19\n1 3\n12 18\n6 11\n7 20\n16 18\n4 15\n3 15\n15 19",
"output": "-1"
},
{
"input": "34\n3 8\n5 9\n2 9\n1 4\n3 7\n3 3\n8 9\n6 10\n4 7\n6 7\n5 8\n5 10\n1 5\n8 8\n2 5\n3 5\n7 7\n2 8\n4 5\n1 1\n7 9\n5 6\n2 3\n1 2\n2 4\n8 10\n7 8\n1 3\n4 8\n9 10\n1 7\n10 10\n2 2\n1 8",
"output": "-1"
},
{
"input": "55\n3 4\n6 8\n9 10\n3 9\n9 9\n2 5\n4 8\n3 8\n8 10\n1 1\n4 9\n10 10\n6 6\n8 8\n1 8\n5 5\n4 5\n5 9\n2 2\n3 10\n4 6\n3 6\n1 6\n1 7\n6 10\n2 6\n3 7\n2 4\n4 4\n5 10\n1 4\n2 9\n1 3\n7 9\n7 8\n1 9\n1 10\n2 8\n8 9\n6 7\n1 2\n6 9\n7 7\n4 7\n3 3\n2 7\n4 10\n7 10\n2 3\n2 10\n5 7\n3 5\n5 8\n1 5\n5 6",
"output": "37"
},
{
"input": "1\n999999999 1000000000",
"output": "1"
},
{
"input": "3\n1 20\n2 22\n3 18",
"output": "-1"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "2\n100001 100008\n100005 100006",
"output": "1"
},
{
"input": "1\n1000000 10000000",
"output": "1"
},
{
"input": "3\n3 6\n2 4\n1 5",
"output": "-1"
},
{
"input": "2\n3 5\n1 2",
"output": "-1"
}
] | 1,669,272,624 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 1,496 | 31,539,200 | from collections import Counter as cnt
l,x=[],[]
for pratyush in range(int(input())):
a,b=list(map(int,input().split()))
x.append([a,b])
l.append(b-a)
c,m=cnt(l),max(l)
if c[m]==1:
r,f=l.index(m),0
a,b=x[r]
for i,j in x:
if a<=i and b>=j:
continue
else:
f=1
break
if f: print(-1)
else: print(r+1)
else:
print(-1) | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.
Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments coincide.
Output Specification:
Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n']
Demo Output:
['-1\n', '3\n']
Note:
none | ```python
from collections import Counter as cnt
l,x=[],[]
for pratyush in range(int(input())):
a,b=list(map(int,input().split()))
x.append([a,b])
l.append(b-a)
c,m=cnt(l),max(l)
if c[m]==1:
r,f=l.index(m),0
a,b=x[r]
for i,j in x:
if a<=i and b>=j:
continue
else:
f=1
break
if f: print(-1)
else: print(r+1)
else:
print(-1)
``` | 3 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,611,659,527 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | a,i=list(map(int,input().split()))
if(a>>i & 1==1):
print('true')
else:
print('false') | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
a,i=list(map(int,input().split()))
if(a>>i & 1==1):
print('true')
else:
print('false')
``` | 0 |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
Can you help B find out exactly what two errors he corrected? | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one. | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 388684428 9301599 656422756 784303821 460626451 277246428",
"output": "25720377\n661369649"
},
{
"input": "3\n796067435 964699482 819602309\n964699482 796067435\n964699482",
"output": "819602309\n796067435"
},
{
"input": "3\n374054998 726316780 902899520\n902899520 726316780\n726316780",
"output": "374054998\n902899520"
},
{
"input": "3\n168638990 939116221 323703261\n168638990 323703261\n168638990",
"output": "939116221\n323703261"
},
{
"input": "3\n77 77 77\n77 77\n77",
"output": "77\n77"
},
{
"input": "3\n84 30 9\n9 84\n9",
"output": "30\n84"
},
{
"input": "6\n5 4 3 3 5 5\n3 5 5 4 3\n3 5 4 3",
"output": "5\n5"
},
{
"input": "4\n1 5 7 8\n1 5 7\n1 5",
"output": "8\n7"
}
] | 1,676,884,388 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n = int(input())
c1 = input().split()
c2 = input().split()
c3 = input().split()
for i in c3:
if i in c1:
del c1[c1.index(i)]
for i in c1:
print(i) | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
Can you help B find out exactly what two errors he corrected?
Input Specification:
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Output Specification:
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
Demo Input:
['5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n', '6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n']
Demo Output:
['8\n123\n', '1\n3\n']
Note:
In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | ```python
n = int(input())
c1 = input().split()
c2 = input().split()
c3 = input().split()
for i in c3:
if i in c1:
del c1[c1.index(i)]
for i in c1:
print(i)
``` | 0 |
|
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not. | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length. | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "YES"
},
{
"input": "qxolmbkkt\naovlajmlf",
"output": "NO"
},
{
"input": "b\ng",
"output": "NO"
},
{
"input": "ab\naba",
"output": "NO"
},
{
"input": "ba\na",
"output": "NO"
},
{
"input": "a\nab",
"output": "NO"
},
{
"input": "a\naa",
"output": "NO"
},
{
"input": "a\nz",
"output": "NO"
},
{
"input": "aabb\nbbaa",
"output": "NO"
},
{
"input": "ab\nbd",
"output": "NO"
},
{
"input": "bac\ndae",
"output": "NO"
},
{
"input": "abc\nakl",
"output": "NO"
},
{
"input": "cb\naa",
"output": "NO"
},
{
"input": "abaab\naabba",
"output": "NO"
},
{
"input": "aab\naaa",
"output": "NO"
},
{
"input": "abcde\nedcba",
"output": "NO"
},
{
"input": "abab\nbaba",
"output": "NO"
},
{
"input": "ab\nbac",
"output": "NO"
},
{
"input": "abcd\naqcb",
"output": "NO"
},
{
"input": "abc\nbad",
"output": "NO"
},
{
"input": "ab\nca",
"output": "NO"
},
{
"input": "abc\nab",
"output": "NO"
},
{
"input": "ab\nbae",
"output": "NO"
},
{
"input": "aaaabcccca\naaaadccccb",
"output": "NO"
},
{
"input": "acaa\nabca",
"output": "NO"
},
{
"input": "aba\naab",
"output": "YES"
},
{
"input": "ah\nla",
"output": "NO"
},
{
"input": "aab\naa",
"output": "NO"
},
{
"input": "abab\nabcd",
"output": "NO"
},
{
"input": "ed\nab",
"output": "NO"
}
] | 1,568,900,653 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 30 | 342 | 2,457,600 | s1=input()
s2=input()
def func():
if len(s1)!=len(s2):
return "NO"
m={}
for item in s1:
if item in m:
m[item]+=1
else:
m[item]=1
for item in s2:
if item in m:
m[item]-=1
else:
return "NO"
x=any([x for x in m.values() if x])
if x:
return "NO"
return "YES"
print(func())
| Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.
Input Specification:
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.
Output Specification:
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
Demo Input:
['ab\nba\n', 'aa\nab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | ```python
s1=input()
s2=input()
def func():
if len(s1)!=len(s2):
return "NO"
m={}
for item in s1:
if item in m:
m[item]+=1
else:
m[item]=1
for item in s2:
if item in m:
m[item]-=1
else:
return "NO"
x=any([x for x in m.values() if x])
if x:
return "NO"
return "YES"
print(func())
``` | 0 |
|
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string. | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
},
{
"input": "5\naaaaa",
"output": "aaaaa"
},
{
"input": "3\naabaaaaabb",
"output": "-1"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "2\nbabac",
"output": "-1"
},
{
"input": "3\nbbbccc",
"output": "bcbcbc"
},
{
"input": "2\naa",
"output": "aa"
},
{
"input": "250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece",
"output": "cececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece"
},
{
"input": "15\nabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaa",
"output": "aaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbc"
},
{
"input": "1\naaa",
"output": "aaa"
},
{
"input": "1\naabaab",
"output": "aaaabb"
},
{
"input": "2\naabbbbccccccdddddddd",
"output": "abbcccddddabbcccdddd"
},
{
"input": "3\naaaaaaaaacccdddddd",
"output": "aaacddaaacddaaacdd"
},
{
"input": "3\naaaaaaaaacccbbbbbb",
"output": "aaabbcaaabbcaaabbc"
},
{
"input": "2\naazzzz",
"output": "azzazz"
},
{
"input": "2\naaaa",
"output": "aaaa"
},
{
"input": "2\naaaazz",
"output": "aazaaz"
},
{
"input": "2\naaaabb",
"output": "aabaab"
},
{
"input": "2\naabbbb",
"output": "abbabb"
},
{
"input": "2\naaaazzzz",
"output": "aazzaazz"
},
{
"input": "2\naaazz",
"output": "-1"
},
{
"input": "2\nbbbbaa",
"output": "abbabb"
},
{
"input": "2\naaaaaabbbb",
"output": "aaabbaaabb"
},
{
"input": "2\naaaaaazz",
"output": "aaazaaaz"
},
{
"input": "2\naaaabbbb",
"output": "aabbaabb"
},
{
"input": "2\naabaab",
"output": "aabaab"
},
{
"input": "1\naaaaa",
"output": "aaaaa"
},
{
"input": "2\nbbaaaa",
"output": "aabaab"
},
{
"input": "2\nacaccc",
"output": "accacc"
}
] | 1,628,685,852 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 154 | 20,172,800 | dic={}
n=int(input())
data=input()
for i in data:
try:
dic[i]+=1
except:
dic[i]=1
flag=0
for val in dic.values():
if val!=n:
flag=1
print(-1)
break
if flag==0:
data=("".join(dic.keys()))
print(data*n)
| Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
Input Specification:
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
Output Specification:
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes).
Demo Input:
['2\naazz\n', '3\nabcabcabz\n']
Demo Output:
['azaz\n', '-1\n']
Note:
none | ```python
dic={}
n=int(input())
data=input()
for i in data:
try:
dic[i]+=1
except:
dic[i]=1
flag=0
for val in dic.values():
if val!=n:
flag=1
print(-1)
break
if flag==0:
data=("".join(dic.keys()))
print(data*n)
``` | 0 |
|
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition. | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people. | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": "1000000000 1",
"output": "499999999500000000 499999999500000000"
},
{
"input": "5000000 12",
"output": "1041664166668 12499942500066"
},
{
"input": "1833 195",
"output": "7722 1342341"
},
{
"input": "1000000000 1000000000",
"output": "0 0"
},
{
"input": "1000000000 1000000",
"output": "499500000000 499000500499500000"
},
{
"input": "1000000000 32170",
"output": "15541930838100 499967831017438365"
},
{
"input": "1000000 1000",
"output": "499500000 499000999500"
},
{
"input": "1234 1123",
"output": "111 6216"
},
{
"input": "599222887 298488",
"output": "601178656545 179355218158217800"
},
{
"input": "999999999 500000000",
"output": "499999999 124999999750000000"
},
{
"input": "1000000000 384842119",
"output": "845473643 189209609585784021"
},
{
"input": "1000000000 384842119",
"output": "845473643 189209609585784021"
},
{
"input": "1000000000 2",
"output": "249999999500000000 499999998500000001"
},
{
"input": "1000000000 999999999",
"output": "1 1"
},
{
"input": "38447 383",
"output": "1910550 724453080"
},
{
"input": "100000000 99999799",
"output": "201 20301"
},
{
"input": "1 1",
"output": "0 0"
},
{
"input": "2 1",
"output": "1 1"
},
{
"input": "2 2",
"output": "0 0"
},
{
"input": "10 10",
"output": "0 0"
}
] | 1,658,752,843 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 31 | 0 | from math import comb
n = input().split()
part = int(n[0])
teams = int(n[1])
num = part-(teams - 1)
maxx = 0
minn = 0
if num >= 2:
maxx = comb(num, 2)
repeat = part / teams
reminder = part % teams
num3 = int(part/teams)
if num3 < 2 and reminder>1:
minn = comb(num3+1,2)*reminder
else:
minn = comb(num3, 2) * (teams - reminder) + comb(num3+1 , 2)*reminder
print(minn)
print(maxx)
| Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.
Input Specification:
The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively.
Output Specification:
The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
Demo Input:
['5 1\n', '3 2\n', '6 3\n']
Demo Output:
['10 10\n', '1 1\n', '3 6\n']
Note:
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people. | ```python
from math import comb
n = input().split()
part = int(n[0])
teams = int(n[1])
num = part-(teams - 1)
maxx = 0
minn = 0
if num >= 2:
maxx = comb(num, 2)
repeat = part / teams
reminder = part % teams
num3 = int(part/teams)
if num3 < 2 and reminder>1:
minn = comb(num3+1,2)*reminder
else:
minn = comb(num3, 2) * (teams - reminder) + comb(num3+1 , 2)*reminder
print(minn)
print(maxx)
``` | 3 |
|
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b",
"output": "f jpggvr b hnxsd b"
},
{
"input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb",
"output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs"
},
{
"input": "1 1\namit am\namit",
"output": "am"
},
{
"input": "1 1\na c\na",
"output": "a"
}
] | 1,680,428,642 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 307,200 | n,m=map(int,input().split())
d={}
for i in range(m):
k,v=map(str,input().split())
d[k]=v
l=list(map(str,input().split()))
for i in l:
j=d[i]
if len(j)<len(i):
print(j)
else:
print(i) | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input Specification:
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output Specification:
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Demo Input:
['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n']
Demo Output:
['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n']
Note:
none | ```python
n,m=map(int,input().split())
d={}
for i in range(m):
k,v=map(str,input().split())
d[k]=v
l=list(map(str,input().split()))
for i in l:
j=d[i]
if len(j)<len(i):
print(j)
else:
print(i)
``` | 3 |
|
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second.
The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse.
Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight. | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively. | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n500\n500",
"output": "0.5"
},
{
"input": "1000\n1\n1",
"output": "500"
},
{
"input": "1000\n1\n500",
"output": "1.996007984"
},
{
"input": "1000\n500\n1",
"output": "998.003992"
},
{
"input": "1000\n500\n500",
"output": "500"
},
{
"input": "101\n11\n22",
"output": "33.66666667"
},
{
"input": "987\n1\n3",
"output": "246.75"
},
{
"input": "258\n25\n431",
"output": "14.14473684"
},
{
"input": "979\n39\n60",
"output": "385.6666667"
},
{
"input": "538\n479\n416",
"output": "287.9351955"
},
{
"input": "583\n112\n248",
"output": "181.3777778"
},
{
"input": "978\n467\n371",
"output": "545.0190931"
},
{
"input": "980\n322\n193",
"output": "612.7378641"
},
{
"input": "871\n401\n17",
"output": "835.576555"
},
{
"input": "349\n478\n378",
"output": "194.885514"
},
{
"input": "425\n458\n118",
"output": "337.9340278"
},
{
"input": "919\n323\n458",
"output": "380.0729834"
},
{
"input": "188\n59\n126",
"output": "59.95675676"
},
{
"input": "644\n428\n484",
"output": "302.2280702"
},
{
"input": "253\n80\n276",
"output": "56.85393258"
},
{
"input": "745\n152\n417",
"output": "199.0158172"
},
{
"input": "600\n221\n279",
"output": "265.2"
},
{
"input": "690\n499\n430",
"output": "370.6243272"
},
{
"input": "105\n68\n403",
"output": "15.15923567"
},
{
"input": "762\n462\n371",
"output": "422.6218487"
},
{
"input": "903\n460\n362",
"output": "505.3284672"
},
{
"input": "886\n235\n95",
"output": "630.9393939"
},
{
"input": "655\n203\n18",
"output": "601.6515837"
},
{
"input": "718\n29\n375",
"output": "51.53960396"
},
{
"input": "296\n467\n377",
"output": "163.7819905"
},
{
"input": "539\n61\n56",
"output": "281.017094"
},
{
"input": "133\n53\n124",
"output": "39.82485876"
},
{
"input": "998\n224\n65",
"output": "773.5363322"
},
{
"input": "961\n173\n47",
"output": "755.6954545"
},
{
"input": "285\n468\n62",
"output": "251.6603774"
},
{
"input": "496\n326\n429",
"output": "214.1668874"
},
{
"input": "627\n150\n285",
"output": "216.2068966"
},
{
"input": "961\n443\n50",
"output": "863.535497"
},
{
"input": "623\n422\n217",
"output": "411.4334898"
},
{
"input": "678\n295\n29",
"output": "617.3148148"
}
] | 1,556,872,958 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | s = float(input())
x = float(input())
y = float(input())
print("%.4f"%float(s/(x+y)*max(x,y)))
| Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second.
The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse.
Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight.
Input Specification:
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.
Output Specification:
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
Demo Input:
['100\n50\n50\n', '199\n60\n40\n']
Demo Output:
['50\n', '119.4\n']
Note:
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | ```python
s = float(input())
x = float(input())
y = float(input())
print("%.4f"%float(s/(x+y)*max(x,y)))
``` | 0 |
|
765 | C | Table Tennis Game 2 | PROGRAMMING | 1,200 | [
"math"
] | null | null | Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins.
Across all the sets Misha scored *a* points in total, and Vanya scored *b* points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets. | The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=><=0). | If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets. | [
"11 11 5\n",
"11 2 3\n"
] | [
"1\n",
"-1\n"
] | Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem. | 1,250 | [
{
"input": "11 11 5",
"output": "1"
},
{
"input": "11 2 3",
"output": "-1"
},
{
"input": "1 5 9",
"output": "14"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "1 1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 3 5",
"output": "3"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "2"
},
{
"input": "1 0 1",
"output": "1"
},
{
"input": "101 99 97",
"output": "-1"
},
{
"input": "1000000000 0 1",
"output": "-1"
},
{
"input": "137 137 136",
"output": "1"
},
{
"input": "255 255 255",
"output": "2"
},
{
"input": "1 0 1000000000",
"output": "1000000000"
},
{
"input": "123 456 789",
"output": "9"
},
{
"input": "666666 6666666 666665",
"output": "-1"
},
{
"input": "1000000000 999999999 999999999",
"output": "-1"
},
{
"input": "100000000 100000001 99999999",
"output": "-1"
},
{
"input": "3 2 1000000000",
"output": "-1"
},
{
"input": "999999999 1000000000 999999998",
"output": "-1"
},
{
"input": "12938621 192872393 102739134",
"output": "21"
},
{
"input": "666666666 1230983 666666666",
"output": "1"
},
{
"input": "123456789 123456789 123456787",
"output": "1"
},
{
"input": "5 6 0",
"output": "-1"
},
{
"input": "11 0 12",
"output": "-1"
},
{
"input": "2 11 0",
"output": "-1"
},
{
"input": "2 1 0",
"output": "-1"
},
{
"input": "10 11 12",
"output": "2"
},
{
"input": "11 12 5",
"output": "-1"
},
{
"input": "11 12 3",
"output": "-1"
},
{
"input": "11 15 4",
"output": "-1"
},
{
"input": "2 3 1",
"output": "-1"
},
{
"input": "11 12 0",
"output": "-1"
},
{
"input": "11 13 2",
"output": "-1"
},
{
"input": "11 23 22",
"output": "4"
},
{
"input": "10 21 0",
"output": "-1"
},
{
"input": "11 23 1",
"output": "-1"
},
{
"input": "11 10 12",
"output": "-1"
},
{
"input": "11 1 12",
"output": "-1"
},
{
"input": "11 5 12",
"output": "-1"
},
{
"input": "11 8 12",
"output": "-1"
},
{
"input": "11 12 1",
"output": "-1"
},
{
"input": "5 4 6",
"output": "-1"
},
{
"input": "10 1 22",
"output": "-1"
},
{
"input": "2 3 0",
"output": "-1"
},
{
"input": "11 23 2",
"output": "-1"
},
{
"input": "2 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "11 0 15",
"output": "-1"
},
{
"input": "11 5 0",
"output": "-1"
},
{
"input": "11 5 15",
"output": "-1"
},
{
"input": "10 0 13",
"output": "-1"
},
{
"input": "4 7 0",
"output": "-1"
},
{
"input": "10 2 8",
"output": "-1"
},
{
"input": "11 5 22",
"output": "2"
},
{
"input": "11 13 0",
"output": "-1"
},
{
"input": "2 0 3",
"output": "-1"
},
{
"input": "10 10 0",
"output": "1"
},
{
"input": "10 11 10",
"output": "2"
},
{
"input": "3 5 4",
"output": "2"
},
{
"input": "11 22 3",
"output": "2"
},
{
"input": "11 12 10",
"output": "-1"
},
{
"input": "10 2 13",
"output": "-1"
},
{
"input": "5 6 1",
"output": "-1"
},
{
"input": "10 21 5",
"output": "-1"
},
{
"input": "10 11 9",
"output": "-1"
},
{
"input": "10 17 7",
"output": "-1"
},
{
"input": "3 4 1",
"output": "-1"
},
{
"input": "4 5 3",
"output": "-1"
},
{
"input": "11 3 23",
"output": "-1"
},
{
"input": "11 3 12",
"output": "-1"
},
{
"input": "2 5 0",
"output": "-1"
},
{
"input": "10 21 2",
"output": "-1"
},
{
"input": "5 1 6",
"output": "-1"
},
{
"input": "10 11 0",
"output": "-1"
},
{
"input": "10 9 11",
"output": "-1"
},
{
"input": "7 10 5",
"output": "-1"
},
{
"input": "5 7 2",
"output": "-1"
},
{
"input": "6 5 7",
"output": "-1"
},
{
"input": "11 16 2",
"output": "-1"
},
{
"input": "11 1000000000 10",
"output": "-1"
},
{
"input": "10 2 21",
"output": "-1"
},
{
"input": "10 15 1",
"output": "-1"
},
{
"input": "5 2 8",
"output": "-1"
},
{
"input": "11 10000000 10",
"output": "-1"
},
{
"input": "10 1 101",
"output": "-1"
},
{
"input": "20 24 2",
"output": "-1"
},
{
"input": "11 24 0",
"output": "-1"
},
{
"input": "11 17 4",
"output": "-1"
},
{
"input": "11 13 1",
"output": "-1"
},
{
"input": "10 11 2",
"output": "-1"
},
{
"input": "11 23 3",
"output": "-1"
},
{
"input": "10 99 0",
"output": "-1"
},
{
"input": "6 7 4",
"output": "-1"
},
{
"input": "11 1 22",
"output": "2"
},
{
"input": "11 2 13",
"output": "-1"
},
{
"input": "2 1 3",
"output": "-1"
},
{
"input": "11 6 18",
"output": "-1"
},
{
"input": "11 122 4",
"output": "-1"
},
{
"input": "11 21 10",
"output": "-1"
},
{
"input": "3 2 4",
"output": "-1"
},
{
"input": "9 11 2",
"output": "-1"
},
{
"input": "11 0 7",
"output": "-1"
},
{
"input": "5 9 4",
"output": "-1"
},
{
"input": "100 105 5",
"output": "-1"
},
{
"input": "11 15 0",
"output": "-1"
},
{
"input": "5 6 4",
"output": "-1"
},
{
"input": "3 4 2",
"output": "-1"
},
{
"input": "2 9 0",
"output": "-1"
},
{
"input": "11 13 11",
"output": "2"
},
{
"input": "11 15 5",
"output": "-1"
},
{
"input": "11 4 15",
"output": "-1"
},
{
"input": "10 1 0",
"output": "-1"
},
{
"input": "11 16 8",
"output": "-1"
},
{
"input": "10 43 0",
"output": "-1"
},
{
"input": "11 13 5",
"output": "-1"
},
{
"input": "11 22 0",
"output": "2"
},
{
"input": "5 6 3",
"output": "-1"
},
{
"input": "2 1 11",
"output": "-1"
},
{
"input": "4 5 1",
"output": "-1"
},
{
"input": "11 23 0",
"output": "-1"
},
{
"input": "11 4 12",
"output": "-1"
},
{
"input": "12 13 1",
"output": "-1"
},
{
"input": "10 19 9",
"output": "-1"
},
{
"input": "3 7 2",
"output": "-1"
},
{
"input": "12 18 0",
"output": "-1"
},
{
"input": "11 25 3",
"output": "-1"
},
{
"input": "11 23 5",
"output": "-1"
},
{
"input": "2 1 5",
"output": "-1"
},
{
"input": "2 0 5",
"output": "-1"
},
{
"input": "11 24 1",
"output": "-1"
},
{
"input": "10 11 4",
"output": "-1"
},
{
"input": "2 0 1",
"output": "-1"
},
{
"input": "10 0 21",
"output": "-1"
},
{
"input": "3 0 7",
"output": "-1"
},
{
"input": "18 11 21",
"output": "-1"
},
{
"input": "3 7 0",
"output": "-1"
},
{
"input": "5 11 0",
"output": "-1"
},
{
"input": "11 5 13",
"output": "-1"
},
{
"input": "11 9 34",
"output": "-1"
},
{
"input": "11 13 9",
"output": "-1"
},
{
"input": "10 0 22",
"output": "-1"
},
{
"input": "5 1 12",
"output": "-1"
},
{
"input": "11 2 12",
"output": "-1"
},
{
"input": "11 9 12",
"output": "-1"
},
{
"input": "11 24 2",
"output": "-1"
},
{
"input": "11 23 6",
"output": "-1"
},
{
"input": "11 20 4",
"output": "-1"
},
{
"input": "2 5 1",
"output": "-1"
},
{
"input": "120 132 133",
"output": "2"
},
{
"input": "11 111 4",
"output": "-1"
},
{
"input": "10 7 11",
"output": "-1"
},
{
"input": "6 13 0",
"output": "-1"
},
{
"input": "5 11 1",
"output": "-1"
},
{
"input": "11 5 27",
"output": "-1"
},
{
"input": "11 15 3",
"output": "-1"
},
{
"input": "11 0 13",
"output": "-1"
},
{
"input": "11 13 10",
"output": "-1"
},
{
"input": "11 25 5",
"output": "-1"
},
{
"input": "4 3 5",
"output": "-1"
},
{
"input": "100 199 100",
"output": "2"
},
{
"input": "11 2 22",
"output": "2"
},
{
"input": "10 20 2",
"output": "2"
},
{
"input": "5 5 0",
"output": "1"
},
{
"input": "10 11 1",
"output": "-1"
},
{
"input": "11 12 2",
"output": "-1"
},
{
"input": "5 16 3",
"output": "-1"
},
{
"input": "12 14 1",
"output": "-1"
},
{
"input": "10 22 2",
"output": "-1"
},
{
"input": "2 4 0",
"output": "2"
},
{
"input": "11 34 7",
"output": "-1"
},
{
"input": "6 13 1",
"output": "-1"
},
{
"input": "11 0 23",
"output": "-1"
},
{
"input": "20 21 19",
"output": "-1"
},
{
"input": "11 33 22",
"output": "5"
},
{
"input": "10 4 41",
"output": "-1"
},
{
"input": "3 4 0",
"output": "-1"
},
{
"input": "11 15 7",
"output": "-1"
},
{
"input": "5 0 6",
"output": "-1"
},
{
"input": "11 3 22",
"output": "2"
},
{
"input": "2 6 0",
"output": "3"
},
{
"input": "10 11 11",
"output": "2"
},
{
"input": "11 33 0",
"output": "3"
},
{
"input": "4 6 2",
"output": "-1"
},
{
"input": "11 76 2",
"output": "-1"
},
{
"input": "7 9 4",
"output": "-1"
},
{
"input": "10 43 1",
"output": "-1"
},
{
"input": "22 25 5",
"output": "-1"
},
{
"input": "3 5 2",
"output": "-1"
},
{
"input": "11 1 24",
"output": "-1"
},
{
"input": "12 25 3",
"output": "-1"
},
{
"input": "11 0 22",
"output": "2"
},
{
"input": "4 2 5",
"output": "-1"
},
{
"input": "11 13 3",
"output": "-1"
},
{
"input": "11 12 9",
"output": "-1"
},
{
"input": "11 35 1",
"output": "-1"
},
{
"input": "5 3 6",
"output": "-1"
},
{
"input": "5 11 4",
"output": "-1"
},
{
"input": "12 8 14",
"output": "-1"
},
{
"input": "10 12 9",
"output": "-1"
},
{
"input": "11 12 13",
"output": "2"
},
{
"input": "11 15 2",
"output": "-1"
},
{
"input": "11 23 4",
"output": "-1"
},
{
"input": "5 3 11",
"output": "-1"
},
{
"input": "6 13 2",
"output": "-1"
},
{
"input": "4 1 0",
"output": "-1"
},
{
"input": "11 32 10",
"output": "-1"
},
{
"input": "2 11 1",
"output": "-1"
},
{
"input": "10 11 7",
"output": "-1"
},
{
"input": "11 26 0",
"output": "-1"
},
{
"input": "100 205 5",
"output": "-1"
},
{
"input": "4 0 2",
"output": "-1"
},
{
"input": "10 11 8",
"output": "-1"
},
{
"input": "11 22 5",
"output": "2"
},
{
"input": "4 0 5",
"output": "-1"
},
{
"input": "11 87 22",
"output": "9"
},
{
"input": "4 8 0",
"output": "2"
},
{
"input": "9 8 17",
"output": "-1"
},
{
"input": "10 20 0",
"output": "2"
},
{
"input": "10 9 19",
"output": "-1"
},
{
"input": "12 2 13",
"output": "-1"
},
{
"input": "11 24 5",
"output": "-1"
},
{
"input": "10 1 11",
"output": "-1"
},
{
"input": "4 0 9",
"output": "-1"
},
{
"input": "3 0 1",
"output": "-1"
},
{
"input": "11 12 4",
"output": "-1"
},
{
"input": "3 8 2",
"output": "-1"
},
{
"input": "11 17 10",
"output": "-1"
},
{
"input": "6 1 13",
"output": "-1"
},
{
"input": "11 25 0",
"output": "-1"
},
{
"input": "12 0 13",
"output": "-1"
},
{
"input": "10 5 20",
"output": "2"
},
{
"input": "11 89 2",
"output": "-1"
},
{
"input": "2 4 1",
"output": "2"
},
{
"input": "10 31 0",
"output": "-1"
},
{
"input": "11 34 1",
"output": "-1"
},
{
"input": "999 6693 8331",
"output": "14"
},
{
"input": "10 55 1",
"output": "-1"
},
{
"input": "11 12 8",
"output": "-1"
},
{
"input": "1 9 22",
"output": "31"
},
{
"input": "7572 9186 895",
"output": "-1"
},
{
"input": "3 2 11",
"output": "-1"
},
{
"input": "2 1 4",
"output": "2"
},
{
"input": "11 10 19",
"output": "-1"
},
{
"input": "100 199 99",
"output": "-1"
},
{
"input": "2537 8926 1523",
"output": "-1"
},
{
"input": "11 0 5",
"output": "-1"
},
{
"input": "5 1 11",
"output": "-1"
},
{
"input": "12 13 5",
"output": "-1"
},
{
"input": "10 12 0",
"output": "-1"
},
{
"input": "5 4 7",
"output": "-1"
},
{
"input": "12 25 1",
"output": "-1"
},
{
"input": "7 9 0",
"output": "-1"
},
{
"input": "4 15 0",
"output": "-1"
},
{
"input": "5 11 2",
"output": "-1"
},
{
"input": "11 58 3",
"output": "-1"
},
{
"input": "10 11 5",
"output": "-1"
},
{
"input": "10 3 1003",
"output": "-1"
},
{
"input": "11 14 0",
"output": "-1"
},
{
"input": "11 8 23",
"output": "-1"
},
{
"input": "11 22 4",
"output": "2"
},
{
"input": "5 2 0",
"output": "-1"
},
{
"input": "11 1 35",
"output": "-1"
},
{
"input": "12 25 5",
"output": "-1"
},
{
"input": "11 37 4",
"output": "-1"
},
{
"input": "20 42 3",
"output": "-1"
},
{
"input": "10 12 2",
"output": "-1"
},
{
"input": "4 1 5",
"output": "-1"
},
{
"input": "5 16 0",
"output": "-1"
},
{
"input": "11 13 7",
"output": "-1"
},
{
"input": "5 0 3",
"output": "-1"
},
{
"input": "11 2 11",
"output": "1"
},
{
"input": "3 2 2000",
"output": "-1"
},
{
"input": "3 0 4241",
"output": "-1"
},
{
"input": "2 12 11",
"output": "11"
},
{
"input": "10 2 82",
"output": "-1"
},
{
"input": "11 0 11",
"output": "1"
},
{
"input": "11 20 20",
"output": "2"
},
{
"input": "5 0 10",
"output": "2"
},
{
"input": "11 1 0",
"output": "-1"
},
{
"input": "11 13 13",
"output": "2"
}
] | 1,487,065,677 | 6,177 | Python 3 | CHALLENGED | CHALLENGES | 9 | 62 | 4,608,000 | k,a,b = list(map(int,input().split()))
a1 = ( (a) // k )
b1 = ( (b) // k )
ans = a1 + b1
if( ans == 0 ):
print("-1")
else:
print( ans ) | Title: Table Tennis Game 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins.
Across all the sets Misha scored *a* points in total, and Vanya scored *b* points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input Specification:
The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=><=0).
Output Specification:
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Demo Input:
['11 11 5\n', '11 2 3\n']
Demo Output:
['1\n', '-1\n']
Note:
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem. | ```python
k,a,b = list(map(int,input().split()))
a1 = ( (a) // k )
b1 = ( (b) // k )
ans = a1 + b1
if( ans == 0 ):
print("-1")
else:
print( ans )
``` | -1 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given.
Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n"
] | [
"Yes\nYes\nYes\nNo\nNo\nYes\n"
] | First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | 0 | [
{
"input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000",
"output": "Yes\nYes\nYes\nNo\nNo\nYes"
},
{
"input": "3\n1 1\n8 27\n1000 1331",
"output": "Yes\nNo\nNo"
},
{
"input": "1\n12004 18012002",
"output": "Yes"
},
{
"input": "1\n3331 11095561",
"output": "Yes"
},
{
"input": "1\n2 3",
"output": "No"
},
{
"input": "1\n1062961 1031",
"output": "Yes"
},
{
"input": "1\n6 12",
"output": "No"
},
{
"input": "1\n3 1",
"output": "No"
},
{
"input": "1\n3 10",
"output": "No"
},
{
"input": "1\n31159 970883281",
"output": "Yes"
},
{
"input": "1\n9907 98148649",
"output": "Yes"
},
{
"input": "1\n16 8",
"output": "No"
},
{
"input": "1\n90 72",
"output": "No"
}
] | 1,501,430,097 | 4,797 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 61 | 4,608,000 | def bs(f, l, val):
if(f==l-1):
return f
mid=(f+l)//2
if(mid**3>val):return bs(f,mid,val)
return bs(mid,l,val)
n=int(input())
for i in range(0,n):
a,b=map(int,input().split())
t=a*b
q=bs(1,10**6,t)
if(q**3==t):
print("YES")
else:
print("NO")
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
Input Specification:
In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given.
Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly.
Output Specification:
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
Demo Input:
['6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n']
Demo Output:
['Yes\nYes\nYes\nNo\nNo\nYes\n']
Note:
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | ```python
def bs(f, l, val):
if(f==l-1):
return f
mid=(f+l)//2
if(mid**3>val):return bs(f,mid,val)
return bs(mid,l,val)
n=int(input())
for i in range(0,n):
a,b=map(int,input().split())
t=a*b
q=bs(1,10**6,t)
if(q**3==t):
print("YES")
else:
print("NO")
``` | 0 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,665,470,337 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | a,b=input().split()
c=int(a)*int(b)
if(c%2==0):
print(c//2)
else:
print((c-1)//2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
a,b=input().split()
c=int(a)*int(b)
if(c%2==0):
print(c//2)
else:
print((c-1)//2)
``` | 3.977 |
332 | B | Maximum Absurdity | PROGRAMMING | 1,500 | [
"data structures",
"dp",
"implementation"
] | null | null | Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2*k* laws. He decided to choose exactly two non-intersecting segments of integers from 1 to *n* of length *k* and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers *a*, *b* (1<=≤<=*a*<=≤<=*b*<=≤<=*n*<=-<=*k*<=+<=1,<=*b*<=-<=*a*<=≥<=*k*) and sign all laws with numbers lying in the segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105, 0<=<<=2*k*<=≤<=*n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the absurdity of each law (1<=≤<=*x**i*<=≤<=109). | Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple solutions, print the one with the minimum *b*. | [
"5 2\n3 6 1 1 6\n",
"6 2\n1 1 1 1 1 1\n"
] | [
"1 4\n",
"1 3\n"
] | In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4. | 1,000 | [
{
"input": "5 2\n3 6 1 1 6",
"output": "1 4"
},
{
"input": "6 2\n1 1 1 1 1 1",
"output": "1 3"
},
{
"input": "6 2\n1 4 1 2 5 6",
"output": "1 5"
},
{
"input": "4 1\n1 2 2 2",
"output": "2 3"
},
{
"input": "6 3\n15 20 1 15 43 6",
"output": "1 4"
},
{
"input": "12 3\n1 2 1 15 2 3 6 8 3 3 8 6",
"output": "4 7"
},
{
"input": "14 2\n2 1 2 3 1 2 2 3 1 2 2 3 2 3",
"output": "3 7"
},
{
"input": "2 1\n1 1",
"output": "1 2"
},
{
"input": "2 1\n1000000000 999999999",
"output": "1 2"
},
{
"input": "3 1\n100 30 563",
"output": "1 3"
},
{
"input": "3 1\n547468 78578678 6467834",
"output": "2 3"
},
{
"input": "4 1\n90000 34567 90000 90001",
"output": "1 4"
},
{
"input": "4 2\n999999 8888888 7777777 666666",
"output": "1 3"
},
{
"input": "5 1\n2 1 2 1 2",
"output": "1 3"
},
{
"input": "5 2\n98 96 98 96 96",
"output": "1 3"
},
{
"input": "6 2\n4 4 7 1 1 7",
"output": "2 5"
},
{
"input": "98 24\n91 20 12 75 44 22 22 67 28 100 8 41 31 47 95 87 5 54 7 49 32 46 42 37 45 22 29 15 54 98 46 94 69 47 60 1 15 76 17 82 46 22 32 34 91 37 30 26 92 77 69 11 59 78 24 66 88 15 32 49 46 14 57 20 5 69 53 99 81 70 67 22 54 31 49 52 46 51 46 2 53 59 8 66 28 53 54 5 85 75 15 55 87 16 68 6 36 98",
"output": "30 67"
},
{
"input": "6 3\n1 2 2 2 1 1",
"output": "1 4"
},
{
"input": "10 4\n9 3 3 9 1 9 9 4 4 9",
"output": "1 6"
},
{
"input": "7 3\n1 2 5 5 5 5 5",
"output": "2 5"
}
] | 1,595,894,404 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 21,811,200 | n,k=map(int,input().split())
l=list(map(int,input().split()))
ls=[]
xs=0
for i in range(k):
xs+=l[i]
ls.append(xs)
for i in range(k,n):
xs+=l[i]
ys=l[i-k]
xs-=ys
ls.append(xs)
q=[]
for i in range(k,len(ls)):
while len(q) and q[-1][0]<ls[i]:
q.pop(-1)
q.append((ls[i],i))
temp=[]
for i in range(len(ls)):
while len(q) and (q[0][1]-i)<k:
q.pop(0)
if len(q)!=0:
x,y=q[0][0],q[0][1]
xs=ls[i]+x
temp.append((xs,y))
a,b=0,0
xs=0
for i in range(len(temp)):
x,y=temp[i][0],temp[i][1]
if x>xs:
a=i
b=y
xs=x
print(a+1,end=' ')
print(b+1) | Title: Maximum Absurdity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2*k* laws. He decided to choose exactly two non-intersecting segments of integers from 1 to *n* of length *k* and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers *a*, *b* (1<=≤<=*a*<=≤<=*b*<=≤<=*n*<=-<=*k*<=+<=1,<=*b*<=-<=*a*<=≥<=*k*) and sign all laws with numbers lying in the segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105, 0<=<<=2*k*<=≤<=*n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the absurdity of each law (1<=≤<=*x**i*<=≤<=109).
Output Specification:
Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple solutions, print the one with the minimum *b*.
Demo Input:
['5 2\n3 6 1 1 6\n', '6 2\n1 1 1 1 1 1\n']
Demo Output:
['1 4\n', '1 3\n']
Note:
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4. | ```python
n,k=map(int,input().split())
l=list(map(int,input().split()))
ls=[]
xs=0
for i in range(k):
xs+=l[i]
ls.append(xs)
for i in range(k,n):
xs+=l[i]
ys=l[i-k]
xs-=ys
ls.append(xs)
q=[]
for i in range(k,len(ls)):
while len(q) and q[-1][0]<ls[i]:
q.pop(-1)
q.append((ls[i],i))
temp=[]
for i in range(len(ls)):
while len(q) and (q[0][1]-i)<k:
q.pop(0)
if len(q)!=0:
x,y=q[0][0],q[0][1]
xs=ls[i]+x
temp.append((xs,y))
a,b=0,0
xs=0
for i in range(len(temp)):
x,y=temp[i][0],temp[i][1]
if x>xs:
a=i
b=y
xs=x
print(a+1,end=' ')
print(b+1)
``` | 0 |
|
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation.
But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
},
{
"input": "693\n970",
"output": "NO"
},
{
"input": "981\n1",
"output": "YES"
},
{
"input": "352\n276",
"output": "YES"
},
{
"input": "164\n691",
"output": "YES"
},
{
"input": "110036\n43",
"output": "YES"
},
{
"input": "100\n1000",
"output": "NO"
},
{
"input": "1000000000\n1000000000",
"output": "YES"
},
{
"input": "999999999\n999999999",
"output": "YES"
},
{
"input": "6\n4",
"output": "NO"
},
{
"input": "123456\n876543",
"output": "YES"
},
{
"input": "1234567\n9876543",
"output": "NO"
},
{
"input": "1111111\n1119111",
"output": "NO"
},
{
"input": "10502405\n40403403",
"output": "YES"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "5\n4",
"output": "YES"
},
{
"input": "1\n6",
"output": "YES"
},
{
"input": "40\n17",
"output": "NO"
},
{
"input": "35\n81",
"output": "YES"
},
{
"input": "347\n908",
"output": "NO"
},
{
"input": "2081\n7450",
"output": "NO"
},
{
"input": "84355694\n373629503",
"output": "NO"
},
{
"input": "885992048\n510468672",
"output": "NO"
},
{
"input": "540144752\n647307841",
"output": "NO"
},
{
"input": "341781108\n784147010",
"output": "NO"
},
{
"input": "960440938\n572334653",
"output": "NO"
},
{
"input": "657414510\n768771903",
"output": "NO"
},
{
"input": "501871728\n725074574",
"output": "NO"
},
{
"input": "968\n851",
"output": "YES"
},
{
"input": "943\n939",
"output": "YES"
},
{
"input": "347\n908",
"output": "NO"
},
{
"input": "611\n41",
"output": "YES"
},
{
"input": "737\n289",
"output": "NO"
},
{
"input": "168\n571",
"output": "YES"
},
{
"input": "868\n463",
"output": "YES"
},
{
"input": "815732007\n913882008",
"output": "NO"
},
{
"input": "459039901\n453033850",
"output": "NO"
},
{
"input": "975305404\n484601256",
"output": "NO"
}
] | 1,683,068,412 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 92 | 0 | x = input()
y = input()
z = int(x) + int(y)
new_x = ""
new_y = ""
q = ""
for i in range(len(x)):
if x[i] != '0':
new_x += x[i]
else:
continue
for i in range(len(y)):
if y[i] != '0':
new_y += y[i]
else:
continue
z = str(z)
for i in range(len(z)):
if z[i] != '0':
q += z[i]
else:
continue
p = int(new_x) + int(new_y)
q = int(q)
if q == p:
print("YES")
else:
print("NO") | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation.
But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
Input Specification:
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
Output Specification:
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
Demo Input:
['101\n102\n', '105\n106\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
x = input()
y = input()
z = int(x) + int(y)
new_x = ""
new_y = ""
q = ""
for i in range(len(x)):
if x[i] != '0':
new_x += x[i]
else:
continue
for i in range(len(y)):
if y[i] != '0':
new_y += y[i]
else:
continue
z = str(z)
for i in range(len(z)):
if z[i] != '0':
q += z[i]
else:
continue
p = int(new_x) + int(new_y)
q = int(q)
if q == p:
print("YES")
else:
print("NO")
``` | 3.977 |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".
Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.
Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.
Help Igor K. restore his ISQ account by the encrypted password and encryption specification. | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000\n"
] | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000",
"output": "30234919"
},
{
"input": "00010101101110110101100110101100010101100010101111000101011010011010110010000011\n0101010110\n0001001101\n1001101011\n0000100011\n0010101111\n1110110101\n0001010110\n0110111000\n0000111110\n0010000011",
"output": "65264629"
},
{
"input": "10100100010010010011011001101000100100110110011010011001101011000100110110011010\n1111110011\n1001000111\n1001000100\n1100010011\n0110011010\n0010000001\n1110101110\n0010000110\n0010010011\n1010010001",
"output": "98484434"
},
{
"input": "00101100011111010001001000000110110000000110010011001111111010110010001011000000\n0010000001\n0110010011\n0010000010\n1011001000\n0011111110\n0110001000\n1111010001\n1011000000\n0000100110\n0010110001",
"output": "96071437"
},
{
"input": "10001110111110000001000010001010001110110000100010100010111101101101010000100010\n0000010110\n1101010111\n1000101111\n0001011110\n0011110101\n0101100100\n0110110101\n0000100010\n1000111011\n1110000001",
"output": "89787267"
},
{
"input": "10010100011001010001010101001101010100110100111011001010111100011001000010100000\n0011100000\n1001100100\n0001100100\n0010100000\n0101010011\n0010101110\n0010101111\n0100111011\n1001010001\n1111111110",
"output": "88447623"
},
{
"input": "01101100111000000101011011001110000001011111111000111111100001011010001001011001\n1000000101\n0101101000\n0101110101\n1101011110\n0000101100\n1111111000\n0001001101\n0110111011\n0110110011\n1001011001",
"output": "80805519"
},
{
"input": "11100011000100010110010011101010101010011110001100011010111110011000011010110111\n1110001100\n0110101111\n0100111010\n0101000000\n1001100001\n1010101001\n0000100010\n1010110111\n1100011100\n0100010110",
"output": "09250147"
},
{
"input": "10000110110000010100000010001000111101110110101011110111000100001101000000100010\n0000010100\n0000110001\n0110101011\n1101110001\n1000011011\n0000110100\n0011110111\n1000110010\n0000100010\n0000011011",
"output": "40862358"
},
{
"input": "01000000010000000110100101000110110000100100000001101100001000011111111001010001\n1011000010\n1111101010\n0111110011\n0000000110\n0000001001\n0001111111\n0110010010\n0100000001\n1011001000\n1001010001",
"output": "73907059"
},
{
"input": "01111000111110011001110101110011110000111110010001101100110110100111101011001101\n1110010001\n1001100000\n1100001000\n1010011110\n1011001101\n0111100011\n1101011100\n1110011001\n1111000011\n0010000101",
"output": "57680434"
},
{
"input": "01001100101000100010001011110001000101001001100010010000001001001100101001011111\n1001011111\n1110010111\n0111101011\n1000100010\n0011100101\n0100000010\n0010111100\n0100010100\n1001100010\n0100110010",
"output": "93678590"
},
{
"input": "01110111110000111011101010110110101011010100110111000011101101110101011101001000\n0110000101\n1010101101\n1101010111\n1101011100\n0100110111\n0111011111\n1100011001\n0111010101\n0000111011\n1101001000",
"output": "58114879"
},
{
"input": "11101001111100110101110011010100110011011110100111010110110011000111000011001101\n1100011100\n1100110101\n1011101000\n0011011110\n0011001101\n0100010001\n1110100111\n1010101100\n1110110100\n0101101100",
"output": "61146904"
},
{
"input": "10101010001011010001001001011000100101100001011011101010101110101010001010101000\n0010110101\n1010011010\n1010101000\n1011010001\n1010101011\n0010010110\n0110100010\n1010100101\n0001011011\n0110100001",
"output": "23558422"
},
{
"input": "11110101001100010000110100001110101011011111010100110001000001001010001001101111\n0101101100\n1001101111\n1010101101\n0100101000\n1111110000\n0101010010\n1100010000\n1111010100\n1101000011\n1011111111",
"output": "76827631"
},
{
"input": "10001100110000110111100011001101111110110011110101000011011100001101110000110111\n0011110101\n0101100011\n1000110011\n1011011001\n0111111011\n0101111011\n0000110111\n0100001110\n1000000111\n0110110111",
"output": "26240666"
},
{
"input": "10000100010000111101100100111101111011101000001001100001000110000010010000111101\n1001001111\n0000111101\n1000010001\n0110011101\n0110101000\n1011111001\n0111101110\n1000001001\n1101011111\n0001010100",
"output": "21067271"
},
{
"input": "01101111000110111100011011110001101111001010001100101000110001010101100100000010\n1010001100\n0011010011\n0101010110\n1111001100\n1100011000\n0100101100\n1001100101\n0110111100\n0011001101\n0100000010",
"output": "77770029"
},
{
"input": "10100111011010001011111000000111100000010101000011000010111101010000111010011101\n1010011101\n1010111111\n0110100110\n1111000100\n1110000001\n0000101111\n0011111000\n1000110001\n0101000011\n1010001011",
"output": "09448580"
},
{
"input": "10000111111000011111001010101010010011111001001111000010010100100011000010001100\n1101101110\n1001001111\n0000100101\n1100111010\n0010101010\n1110000110\n1100111101\n0010001100\n1110000001\n1000011111",
"output": "99411277"
},
{
"input": "10110110111011001111101100111100111111011011011011001111110110010011100010000111\n0111010011\n0111101100\n1001101010\n0101000101\n0010000111\n0011111101\n1011001111\n1101111000\n1011011011\n1001001110",
"output": "86658594"
},
{
"input": "01001001100101100011110110111100000110001111001000100000110111110010000000011000\n0100100110\n1000001011\n1000111110\n0000011000\n0101100011\n1101101111\n1111001000\n1011011001\n1000001101\n0010101000",
"output": "04536863"
},
{
"input": "10010100011101000011100100001100101111000010111100000010010000001001001101011101\n1001000011\n1101000011\n1001010001\n1101011101\n1000010110\n0011111101\n0010111100\n0000100100\n1010001000\n0101000110",
"output": "21066773"
},
{
"input": "01111111110101111111011111111111010010000001100000101000100100111001011010001001\n0111111111\n0101111111\n0100101101\n0001100000\n0011000101\n0011100101\n1101001000\n0010111110\n1010001001\n1111000111",
"output": "01063858"
},
{
"input": "00100011111001001010001111000011101000001110100000000100101011101000001001001010\n0010001111\n1001001010\n1010011001\n0011100111\n1000111000\n0011110000\n0000100010\n0001001010\n1111110111\n1110100000",
"output": "01599791"
},
{
"input": "11011101000100110100110011010101100011111010011010010011010010010010100110101111\n0100110100\n1001001010\n0001111101\n1101011010\n1101110100\n1100110101\n0110101111\n0110001111\n0001101000\n1010011010",
"output": "40579016"
},
{
"input": "10000010111101110110011000111110000011100110001111100100000111000011011000001011\n0111010100\n1010110110\n1000001110\n1110000100\n0110001111\n1101110110\n1100001101\n1000001011\n0000000101\n1001000001",
"output": "75424967"
},
{
"input": "11101100101110111110111011111010001111111111000001001001000010001111111110110010\n0101100001\n1111010011\n1110111110\n0100110100\n1110011111\n1000111111\n0010010000\n1110110010\n0011000010\n1111000001",
"output": "72259657"
},
{
"input": "01011110100101111010011000001001100000101001110011010111101011010000110110010101\n0100111100\n0101110011\n0101111010\n0110000010\n0101001111\n1101000011\n0110010101\n0111011010\n0001101110\n1001110011",
"output": "22339256"
},
{
"input": "01100000100101111000100001100010000110000010100100100001100000110011101001110000\n0101111000\n1001110000\n0001000101\n0110110111\n0010100100\n1000011000\n1101110110\n0110000010\n0001011010\n0011001110",
"output": "70554591"
},
{
"input": "11110011011000001001111100110101001000010100100000110011001110011111100100100001\n1010011000\n1111001101\n0100100001\n1111010011\n0100100000\n1001111110\n1010100111\n1000100111\n1000001001\n1100110011",
"output": "18124952"
},
{
"input": "10001001011000100101010110011101011001110010000001010110000101000100101111101010\n0101100001\n1100001100\n1111101010\n1000100101\n0010000001\n0100010010\n0010110110\n0101100111\n0000001110\n1101001110",
"output": "33774052"
},
{
"input": "00110010000111001001001100100010010111101011011110001011111100000101000100000001\n0100000001\n1011011110\n0010111111\n0111100111\n0100111001\n0000010100\n1001011110\n0111001001\n0100010011\n0011001000",
"output": "97961250"
},
{
"input": "01101100001000110101101100101111101110010011010111100011010100010001101000110101\n1001101001\n1000110101\n0110110000\n0111100100\n0011010111\n1110111001\n0001000110\n0000000100\n0001101001\n1011001011",
"output": "21954161"
},
{
"input": "10101110000011010110101011100000101101000110100000101101101101110101000011110010\n0110100000\n1011011011\n0011110010\n0001110110\n0010110100\n1100010010\n0001101011\n1010111000\n0011010110\n0111010100",
"output": "78740192"
},
{
"input": "11000101011100100111010000010001000001001100101100000011000000001100000101011010\n1100010101\n1111101011\n0101011010\n0100000100\n1000110111\n1100100111\n1100101100\n0111001000\n0000110000\n0110011111",
"output": "05336882"
},
{
"input": "11110100010000101110010110001000001011100101100010110011011011111110001100110110\n0101100010\n0100010001\n0000101110\n1100110110\n0101000101\n0011001011\n1111010001\n1000110010\n1111111000\n1010011111",
"output": "62020383"
},
{
"input": "00011001111110000011101011010001010111100110100101000110011111011001100000001100\n0111001101\n0101011110\n0001100111\n1101011111\n1110000011\n0000001100\n0111010001\n1101100110\n1010110100\n0110100101",
"output": "24819275"
},
{
"input": "10111110010011111001001111100101010111010011111001001110101000111110011001111101\n0011111001\n0101011101\n0100001010\n0001110010\n1001111101\n0011101010\n1111001001\n1100100001\n1001101000\n1011111001",
"output": "90010504"
},
{
"input": "01111101111100101010001001011110111001110111110111011111011110110111111011011111\n1111110111\n0010000101\n0110000100\n0111111011\n1011100111\n1100101010\n1011011111\n1100010001\n0111110111\n0010010111",
"output": "85948866"
},
{
"input": "01111100000111110000110010111001111100001001101010110010111010001000101001101010\n0100010101\n1011110101\n1010100100\n1010000001\n1001101010\n0101100110\n1000100010\n0111110000\n1100101110\n0110010110",
"output": "77874864"
},
{
"input": "11100011010000000010011110010111001011111001000111000000001000000000100111100101\n0000000010\n1110001101\n0011010101\n0111100101\n1001000111\n1101001111\n0111010110\n1100101111\n0110000000\n1101101011",
"output": "10374003"
},
{
"input": "01111011100111101110011001000110001111101000111110100100100001011111001011100010\n0110010100\n1100010001\n0111101110\n1001001000\n1010011011\n1000111110\n0010110101\n1011100010\n0101111100\n0110010001",
"output": "22955387"
},
{
"input": "11011010001100000011000100110011010101000110011110110000001100111100001000011111\n0000100010\n1000011111\n1101101000\n0110011110\n0011110000\n1100000011\n0010001100\n0101101000\n0001001100\n1101010100",
"output": "25893541"
},
{
"input": "01011001011111010010101111011001000011001100011101101111011011010011101011110110\n0100001100\n0101100101\n1111111011\n1111010010\n1111101100\n1100011101\n1011000011\n1101001110\n1011110110\n0110001010",
"output": "13805878"
},
{
"input": "11110011011000111111001100111110001111111100000010111100110100110011111111001101\n1111001101\n1001101010\n1100110010\n0011001111\n0001011110\n1000110011\n1000111111\n0110001010\n1001011101\n1100000010",
"output": "06369030"
},
{
"input": "01110011110010000011011001011000001000010110010110011001100001100110001100101000\n0000100001\n0110011000\n1010000010\n1110011101\n0111001111\n1100101000\n0010000011\n0110010000\n1100100101\n0110010110",
"output": "46909115"
},
{
"input": "00001011001111110111111111011111111101110101110100010111010010100101100001010110\n1111110111\n0001010110\n0111011011\n0111000001\n1010010110\n0101110100\n0001000101\n0000111000\n0110100001\n0000101100",
"output": "90005541"
}
] | 1,576,276,259 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 404 | 2,355,200 | s=input()
d={}
for i in range(0,10):
d[input()]=i
for i in range(8):
s1+=d[s[:10]]
s=s[10:] | Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".
Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.
Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.
Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
Input Specification:
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Output Specification:
Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
Demo Input:
['01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n', '10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000\n']
Demo Output:
['12345678\n', '30234919\n']
Note:
none | ```python
s=input()
d={}
for i in range(0,10):
d[input()]=i
for i in range(8):
s1+=d[s[:10]]
s=s[10:]
``` | -1 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,589,686,766 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 218 | 6,656,000 | a,b=map(int,input().split())
x=max(a,b)
t=7-x
if(t==0):
A=0
B=1
elif(6%t!=0):
A=t
B=6
else:
A=1
B=6//t
print(str(A)+'/'+str(B)) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
a,b=map(int,input().split())
x=max(a,b)
t=7-x
if(t==0):
A=0
B=1
elif(6%t!=0):
A=t
B=6
else:
A=1
B=6//t
print(str(A)+'/'+str(B))
``` | 0 |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "480",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "49",
"output": "YES"
},
{
"input": "56",
"output": "YES"
},
{
"input": "124",
"output": "YES"
},
{
"input": "1000",
"output": "YES"
},
{
"input": "999",
"output": "NO"
},
{
"input": "298",
"output": "NO"
},
{
"input": "274",
"output": "NO"
},
{
"input": "998",
"output": "NO"
},
{
"input": "42",
"output": "YES"
},
{
"input": "788",
"output": "YES"
},
{
"input": "70",
"output": "YES"
},
{
"input": "444",
"output": "YES"
},
{
"input": "777",
"output": "YES"
},
{
"input": "799",
"output": "YES"
},
{
"input": "25",
"output": "NO"
},
{
"input": "882",
"output": "YES"
},
{
"input": "88",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "7",
"output": "YES"
},
{
"input": "8",
"output": "YES"
},
{
"input": "94",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "141",
"output": "YES"
}
] | 1,698,357,100 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 92 | 0 | misschien_geluk = int(input())
print("YES" if misschien_geluk%4 == 0 or misschien_geluk%7 == 0 or misschien_geluk in [4, 47, 744] else "NO") | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
Input Specification:
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
Output Specification:
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['47\n', '16\n', '78\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | ```python
misschien_geluk = int(input())
print("YES" if misschien_geluk%4 == 0 or misschien_geluk%7 == 0 or misschien_geluk in [4, 47, 744] else "NO")
``` | 0 |
|
747 | E | Comments | PROGRAMMING | 1,700 | [
"dfs and similar",
"expression parsing",
"implementation",
"strings"
] | null | null | A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.
Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment except root comments (comments of the highest level) has exactly one parent comment.
When Polycarp wants to save comments to his hard drive he uses the following format. Each comment he writes in the following format:
- at first, the text of the comment is written; - after that the number of comments is written, for which this comment is a parent comment (i. e. the number of the replies to this comments); - after that the comments for which this comment is a parent comment are written (the writing of these comments uses the same algorithm).
For example, if the comments look like:
then the first comment is written as "hello,2,ok,0,bye,0", the second is written as "test,0", the third comment is written as "one,1,two,2,a,0,b,0". The whole comments feed is written as: "hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0". For a given comments feed in the format specified above print the comments in a different format:
- at first, print a integer *d* — the maximum depth of nesting comments; - after that print *d* lines, the *i*-th of them corresponds to nesting level *i*; - for the *i*-th row print comments of nesting level *i* in the order of their appearance in the Policarp's comments feed, separated by space. | The first line contains non-empty comments feed in the described format. It consists of uppercase and lowercase letters of English alphabet, digits and commas.
It is guaranteed that each comment is a non-empty string consisting of uppercase and lowercase English characters. Each of the number of comments is integer (consisting of at least one digit), and either equals 0 or does not contain leading zeros.
The length of the whole string does not exceed 106. It is guaranteed that given structure of comments is valid. | Print comments in a format that is given in the statement. For each level of nesting, comments should be printed in the order they are given in the input. | [
"hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0\n",
"a,5,A,0,a,0,A,0,a,0,A,0\n",
"A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0\n"
] | [
"3\nhello test one \nok bye two \na b \n",
"2\na \nA a A a A \n",
"4\nA K M \nB F H L N O \nC D G I P \nE J \n"
] | The first example is explained in the statements. | 2,000 | [
{
"input": "hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0",
"output": "3\nhello test one \nok bye two \na b "
},
{
"input": "a,5,A,0,a,0,A,0,a,0,A,0",
"output": "2\na \nA a A a A "
},
{
"input": "A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0",
"output": "4\nA K M \nB F H L N O \nC D G I P \nE J "
},
{
"input": "BA,0",
"output": "1\nBA "
},
{
"input": "Tu,1,dU,1,zncD,0",
"output": "3\nTu \ndU \nzncD "
},
{
"input": "nwEwA,2,C,1,aG,0,xgv,0",
"output": "3\nnwEwA \nC xgv \naG "
},
{
"input": "aa,0",
"output": "1\naa "
},
{
"input": "ab,0,ba,0",
"output": "1\nab ba "
},
{
"input": "aa,0,ab,1,a,0",
"output": "2\naa ab \na "
},
{
"input": "a,0,bb,1,a,1,bb,0",
"output": "3\na bb \na \nbb "
},
{
"input": "a,2,b,0,bb,1,a,1,a,0",
"output": "4\na \nb bb \na \na "
},
{
"input": "bb,0,b,1,a,1,b,1,a,0,b,0",
"output": "4\nbb b b \na \nb \na "
},
{
"input": "b,2,b,0,b,0,b,1,b,0,ba,1,b,0",
"output": "2\nb b ba \nb b b b "
},
{
"input": "bb,0,bb,0,b,1,ab,0,b,0,a,2,ab,0,bb,0",
"output": "2\nbb bb b b a \nab ab bb "
},
{
"input": "ba,0,aa,1,a,0,bb,1,a,0,a,0,a,0,a,1,a,0",
"output": "2\nba aa bb a a a \na a a "
},
{
"input": "a,3,aa,0,b,0,b,0,b,0,a,0,b,2,aa,1,a,0,ab,0",
"output": "3\na b a b \naa b b aa ab \na "
}
] | 1,645,381,185 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 685 | 113,049,600 | from sys import stdin
input = lambda: stdin.buffer.readline().decode().strip()
s, stk, levels, ans = input().split(','), [], [[] for _ in range(4 * 10 ** 5)], 0
for i in range(0, len(s), 2):
s[i + 1] = int(s[i + 1])
while stk and s[stk[-1] + 1] == 0:
stk.pop()
if stk:
s[stk[-1] + 1] -= 1
stk.append(i)
levels[len(stk)].append(s[stk[-1]])
ans = max(ans, len(stk))
print(ans)
[print(*levels[i]) for i in range(1, ans + 1)]
| Title: Comments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.
Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment except root comments (comments of the highest level) has exactly one parent comment.
When Polycarp wants to save comments to his hard drive he uses the following format. Each comment he writes in the following format:
- at first, the text of the comment is written; - after that the number of comments is written, for which this comment is a parent comment (i. e. the number of the replies to this comments); - after that the comments for which this comment is a parent comment are written (the writing of these comments uses the same algorithm).
For example, if the comments look like:
then the first comment is written as "hello,2,ok,0,bye,0", the second is written as "test,0", the third comment is written as "one,1,two,2,a,0,b,0". The whole comments feed is written as: "hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0". For a given comments feed in the format specified above print the comments in a different format:
- at first, print a integer *d* — the maximum depth of nesting comments; - after that print *d* lines, the *i*-th of them corresponds to nesting level *i*; - for the *i*-th row print comments of nesting level *i* in the order of their appearance in the Policarp's comments feed, separated by space.
Input Specification:
The first line contains non-empty comments feed in the described format. It consists of uppercase and lowercase letters of English alphabet, digits and commas.
It is guaranteed that each comment is a non-empty string consisting of uppercase and lowercase English characters. Each of the number of comments is integer (consisting of at least one digit), and either equals 0 or does not contain leading zeros.
The length of the whole string does not exceed 106. It is guaranteed that given structure of comments is valid.
Output Specification:
Print comments in a format that is given in the statement. For each level of nesting, comments should be printed in the order they are given in the input.
Demo Input:
['hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0\n', 'a,5,A,0,a,0,A,0,a,0,A,0\n', 'A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0\n']
Demo Output:
['3\nhello test one \nok bye two \na b \n', '2\na \nA a A a A \n', '4\nA K M \nB F H L N O \nC D G I P \nE J \n']
Note:
The first example is explained in the statements. | ```python
from sys import stdin
input = lambda: stdin.buffer.readline().decode().strip()
s, stk, levels, ans = input().split(','), [], [[] for _ in range(4 * 10 ** 5)], 0
for i in range(0, len(s), 2):
s[i + 1] = int(s[i + 1])
while stk and s[stk[-1] + 1] == 0:
stk.pop()
if stk:
s[stk[-1] + 1] -= 1
stk.append(i)
levels[len(stk)].append(s[stk[-1]])
ans = max(ans, len(stk))
print(ans)
[print(*levels[i]) for i in range(1, ans + 1)]
``` | 3 |
|
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"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. | 500 | [
{
"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"
}
] | 1,564,628,892 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n=int(input())
print((2*n-1)//3) | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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?
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday.
Output Specification:
Print the maximum possible number of times Artem can give presents to Masha.
Demo Input:
['1\n', '2\n', '3\n', '4\n']
Demo Output:
['1\n', '1\n', '2\n', '3\n']
Note:
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. | ```python
n=int(input())
print((2*n-1)//3)
``` | 0 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,582,452,187 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 0 | n=int(input())
a=list(map(int,input().split()))
if(a[i]==1):
for i in range(0,n):
if(a[i]!=1):
print(i+1)
break
else:
for i in range(0,n):
if(a[i]!=2*(i+1)):
print(i+1)
break | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n=int(input())
a=list(map(int,input().split()))
if(a[i]==1):
for i in range(0,n):
if(a[i]!=1):
print(i+1)
break
else:
for i in range(0,n):
if(a[i]!=2*(i+1)):
print(i+1)
break
``` | -1 |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"input": "8\n4\n1\n10\n59392",
"output": "59392"
},
{
"input": "4\n1\n8\n7\n44835",
"output": "44835"
},
{
"input": "6\n1\n7\n2\n62982",
"output": "62982"
},
{
"input": "2\n7\n4\n9\n56937",
"output": "35246"
},
{
"input": "2\n9\n8\n1\n75083",
"output": "75083"
},
{
"input": "8\n7\n7\n6\n69038",
"output": "24656"
},
{
"input": "4\n4\n2\n3\n54481",
"output": "36320"
},
{
"input": "6\n4\n9\n8\n72628",
"output": "28244"
},
{
"input": "9\n7\n8\n10\n42357",
"output": "16540"
},
{
"input": "5\n6\n4\n3\n60504",
"output": "36302"
},
{
"input": "7\n2\n3\n8\n21754",
"output": "15539"
},
{
"input": "1\n2\n10\n4\n39901",
"output": "39901"
},
{
"input": "3\n4\n7\n1\n58048",
"output": "58048"
},
{
"input": "9\n10\n4\n6\n52003",
"output": "21956"
},
{
"input": "5\n10\n9\n3\n70149",
"output": "32736"
},
{
"input": "5\n5\n5\n10\n55592",
"output": "11118"
},
{
"input": "1\n5\n2\n6\n49547",
"output": "49547"
},
{
"input": "3\n7\n7\n7\n84046",
"output": "36019"
},
{
"input": "10\n2\n1\n8\n63537",
"output": "63537"
},
{
"input": "7\n2\n10\n5\n81684",
"output": "53678"
},
{
"input": "7\n1\n6\n8\n99831",
"output": "99831"
},
{
"input": "3\n9\n3\n3\n61082",
"output": "20360"
},
{
"input": "5\n5\n8\n9\n79228",
"output": "29931"
},
{
"input": "1\n5\n5\n6\n89535",
"output": "89535"
},
{
"input": "5\n5\n2\n1\n7682",
"output": "7682"
},
{
"input": "7\n4\n8\n8\n25829",
"output": "9224"
},
{
"input": "3\n4\n3\n3\n87079",
"output": "43539"
},
{
"input": "5\n8\n4\n9\n5226",
"output": "2438"
},
{
"input": "4\n9\n6\n6\n1070",
"output": "415"
},
{
"input": "10\n10\n10\n10\n100000",
"output": "10000"
},
{
"input": "1\n1\n1\n1\n1",
"output": "1"
},
{
"input": "10\n10\n10\n10\n1",
"output": "0"
},
{
"input": "10\n10\n1\n10\n10",
"output": "10"
},
{
"input": "10\n10\n1\n10\n100",
"output": "100"
},
{
"input": "2\n2\n2\n2\n1",
"output": "0"
}
] | 1,687,202,811 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 512,000 | nums = []
mult = []
dmg = []
j = 0
for i in range(4):
nums.append(int(input()))
d = int(input())
while dmg != d and j != 4:
for i in range(1, d+1):
if i % nums[j] == 0 and i not in dmg:
dmg.append(i)
j += 1
print(len(dmg))
| Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
Input Specification:
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output Specification:
Output the number of damaged dragons.
Demo Input:
['1\n2\n3\n4\n12\n', '2\n3\n4\n5\n24\n']
Demo Output:
['12\n', '17\n']
Note:
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | ```python
nums = []
mult = []
dmg = []
j = 0
for i in range(4):
nums.append(int(input()))
d = int(input())
while dmg != d and j != 4:
for i in range(1, d+1):
if i % nums[j] == 0 and i not in dmg:
dmg.append(i)
j += 1
print(len(dmg))
``` | 0 |
|
682 | B | Alyona and Mex | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.
Formally, after applying some operations Alyona will get an array of *n* positive integers *b*1,<=*b*2,<=...,<=*b**n* such that 1<=≤<=*b**i*<=≤<=*a**i* for every 1<=≤<=*i*<=≤<=*n*. Your task is to determine the maximum possible value of mex of this array.
Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array.
The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. | [
"5\n1 3 3 3 6\n",
"2\n2 1\n"
] | [
"5\n",
"3\n"
] | In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | 1,000 | [
{
"input": "5\n1 3 3 3 6",
"output": "5"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "1\n1000000000",
"output": "2"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n1 3",
"output": "3"
},
{
"input": "2\n2 2",
"output": "3"
},
{
"input": "2\n2 3",
"output": "3"
},
{
"input": "2\n3 3",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "3"
},
{
"input": "3\n3 1 1",
"output": "3"
},
{
"input": "3\n1 1 4",
"output": "3"
},
{
"input": "3\n2 1 2",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "4"
},
{
"input": "3\n2 4 1",
"output": "4"
},
{
"input": "3\n3 3 1",
"output": "4"
},
{
"input": "3\n1 3 4",
"output": "4"
},
{
"input": "3\n4 1 4",
"output": "4"
},
{
"input": "3\n2 2 2",
"output": "3"
},
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "3\n4 2 2",
"output": "4"
},
{
"input": "3\n2 3 3",
"output": "4"
},
{
"input": "3\n4 2 3",
"output": "4"
},
{
"input": "3\n4 4 2",
"output": "4"
},
{
"input": "3\n3 3 3",
"output": "4"
},
{
"input": "3\n4 3 3",
"output": "4"
},
{
"input": "3\n4 3 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "4\n1 1 1 1",
"output": "2"
},
{
"input": "4\n1 1 2 1",
"output": "3"
},
{
"input": "4\n1 1 3 1",
"output": "3"
},
{
"input": "4\n1 4 1 1",
"output": "3"
},
{
"input": "4\n1 2 1 2",
"output": "3"
},
{
"input": "4\n1 3 2 1",
"output": "4"
},
{
"input": "4\n2 1 4 1",
"output": "4"
},
{
"input": "4\n3 3 1 1",
"output": "4"
},
{
"input": "4\n1 3 4 1",
"output": "4"
},
{
"input": "4\n1 1 4 4",
"output": "4"
},
{
"input": "4\n2 2 2 1",
"output": "3"
},
{
"input": "4\n1 2 2 3",
"output": "4"
},
{
"input": "4\n2 4 1 2",
"output": "4"
},
{
"input": "4\n3 3 1 2",
"output": "4"
},
{
"input": "4\n2 3 4 1",
"output": "5"
},
{
"input": "4\n1 4 2 4",
"output": "5"
},
{
"input": "4\n3 1 3 3",
"output": "4"
},
{
"input": "4\n3 4 3 1",
"output": "5"
},
{
"input": "4\n1 4 4 3",
"output": "5"
},
{
"input": "4\n4 1 4 4",
"output": "5"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "4\n2 2 3 2",
"output": "4"
},
{
"input": "4\n2 2 2 4",
"output": "4"
},
{
"input": "4\n2 2 3 3",
"output": "4"
},
{
"input": "4\n2 2 3 4",
"output": "5"
},
{
"input": "4\n2 4 4 2",
"output": "5"
},
{
"input": "4\n2 3 3 3",
"output": "4"
},
{
"input": "4\n2 4 3 3",
"output": "5"
},
{
"input": "4\n4 4 2 3",
"output": "5"
},
{
"input": "4\n4 4 4 2",
"output": "5"
},
{
"input": "4\n3 3 3 3",
"output": "4"
},
{
"input": "4\n3 3 3 4",
"output": "5"
},
{
"input": "4\n4 3 3 4",
"output": "5"
},
{
"input": "4\n4 4 3 4",
"output": "5"
},
{
"input": "4\n4 4 4 4",
"output": "5"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 3 3",
"output": "4"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8",
"output": "9"
},
{
"input": "4\n2 2 2 3",
"output": "4"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "15\n1 2 2 20 23 25 28 60 66 71 76 77 79 99 100",
"output": "15"
},
{
"input": "7\n1 2 2 2 5 5 1",
"output": "5"
},
{
"input": "4\n1 1 1 2",
"output": "3"
},
{
"input": "5\n1 1 1 1 10000",
"output": "3"
},
{
"input": "5\n1 1 1 1 2",
"output": "3"
},
{
"input": "7\n1 3 3 3 3 3 6",
"output": "5"
},
{
"input": "4\n1 1 1 3",
"output": "3"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 100",
"output": "3"
},
{
"input": "4\n1 1 2 2",
"output": "3"
},
{
"input": "5\n1 1 1 3 4",
"output": "4"
},
{
"input": "8\n1 1 1 1 2 2 3 40",
"output": "5"
},
{
"input": "5\n1 1 1 1 1",
"output": "2"
},
{
"input": "7\n1 2 2 2 2 2 4",
"output": "4"
},
{
"input": "10\n1 1 1 10000000 10000000 10000000 10000000 10000000 10000000 10000000",
"output": "9"
},
{
"input": "10\n1 1 1 1 1 1 1 1 2 3",
"output": "4"
},
{
"input": "4\n8 8 8 8",
"output": "5"
},
{
"input": "5\n5 6 6 6 7",
"output": "6"
}
] | 1,662,453,025 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 127 | 93 | 13,516,800 | n = int(input())
l = list(map(int,input().split()))
l.sort()
# d = {}
# for i in l:
# d[i] = d.get(i,0)+1
i = 0
mex = 1
while i<n:
if l[i]>=mex:
mex += 1
i+=1
print(mex) | Title: Alyona and Mex
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.
Formally, after applying some operations Alyona will get an array of *n* positive integers *b*1,<=*b*2,<=...,<=*b**n* such that 1<=≤<=*b**i*<=≤<=*a**i* for every 1<=≤<=*i*<=≤<=*n*. Your task is to determine the maximum possible value of mex of this array.
Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array.
The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
Output Specification:
Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
Demo Input:
['5\n1 3 3 3 6\n', '2\n2 1\n']
Demo Output:
['5\n', '3\n']
Note:
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | ```python
n = int(input())
l = list(map(int,input().split()))
l.sort()
# d = {}
# for i in l:
# d[i] = d.get(i,0)+1
i = 0
mex = 1
while i<n:
if l[i]>=mex:
mex += 1
i+=1
print(mex)
``` | 3 |
|
17 | A | Noldbach problem | PROGRAMMING | 1,000 | [
"brute force",
"math",
"number theory"
] | A. Noldbach problem | 2 | 64 | Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.
Two prime numbers are called neighboring if there are no other prime numbers between them.
You are to help Nick, and find out if he is right or wrong. | The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). | Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. | [
"27 2\n",
"45 7\n"
] | [
"YES",
"NO"
] | In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | 0 | [
{
"input": "27 2",
"output": "YES"
},
{
"input": "45 7",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "15 1",
"output": "YES"
},
{
"input": "17 1",
"output": "YES"
},
{
"input": "34 5",
"output": "NO"
},
{
"input": "37 4",
"output": "YES"
},
{
"input": "43 5",
"output": "YES"
},
{
"input": "47 7",
"output": "NO"
},
{
"input": "50 5",
"output": "YES"
},
{
"input": "57 6",
"output": "YES"
},
{
"input": "60 8",
"output": "NO"
},
{
"input": "62 7",
"output": "YES"
},
{
"input": "76 9",
"output": "NO"
},
{
"input": "69 7",
"output": "YES"
},
{
"input": "113 10",
"output": "YES"
},
{
"input": "141 11",
"output": "YES"
},
{
"input": "207 16",
"output": "NO"
},
{
"input": "231 18",
"output": "NO"
},
{
"input": "296 19",
"output": "YES"
},
{
"input": "332 20",
"output": "YES"
},
{
"input": "378 24",
"output": "NO"
},
{
"input": "428 23",
"output": "YES"
},
{
"input": "497 27",
"output": "NO"
},
{
"input": "640 32",
"output": "YES"
},
{
"input": "798 35",
"output": "YES"
},
{
"input": "802 35",
"output": "YES"
},
{
"input": "864 40",
"output": "NO"
},
{
"input": "953 44",
"output": "NO"
},
{
"input": "995 44",
"output": "YES"
},
{
"input": "1000 44",
"output": "YES"
},
{
"input": "1000 0",
"output": "YES"
},
{
"input": "1000 1000",
"output": "NO"
},
{
"input": "2 1000",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
}
] | 1,584,989,647 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 154 | 307,200 | import math
def primenum(x):
count=0
for i in range(2,int(math.floor(math.sqrt(x)))+1):
if(x%i==0):
count=count+1
if(count==0):
return True
else:
return False
n,k=map(int,input().split())
l=[]
m=[]
c=0
if(k>n or k==0):
print('NO')
else:
for i in range(2,n+1):
if (primenum(i)==True):
l.append(i)
for i in range(len(l)-1):
m.append(l[i]+l[i+1]+1)
for i in range(len(m)):
if m[i] in l:
c=c+1
if(c>=k):
print('YES')
else:
print('NO')
| Title: Noldbach problem
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.
Two prime numbers are called neighboring if there are no other prime numbers between them.
You are to help Nick, and find out if he is right or wrong.
Input Specification:
The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000).
Output Specification:
Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO.
Demo Input:
['27 2\n', '45 7\n']
Demo Output:
['YES', 'NO']
Note:
In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | ```python
import math
def primenum(x):
count=0
for i in range(2,int(math.floor(math.sqrt(x)))+1):
if(x%i==0):
count=count+1
if(count==0):
return True
else:
return False
n,k=map(int,input().split())
l=[]
m=[]
c=0
if(k>n or k==0):
print('NO')
else:
for i in range(2,n+1):
if (primenum(i)==True):
l.append(i)
for i in range(len(l)-1):
m.append(l[i]+l[i+1]+1)
for i in range(len(m)):
if m[i] in l:
c=c+1
if(c>=k):
print('YES')
else:
print('NO')
``` | 0 |
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"output": "YES"
},
{
"input": "1\n999993399999",
"output": "NO"
},
{
"input": "9\n111 121 131 111 121 131 111 121 131",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO"
},
{
"input": "1\n1",
"output": "NO"
},
{
"input": "1\n10",
"output": "NO"
},
{
"input": "1\n976197352729",
"output": "NO"
},
{
"input": "1\n1000000000000",
"output": "NO"
},
{
"input": "1\n9",
"output": "YES"
},
{
"input": "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "3\n223092870 6469693230 200560490130",
"output": "NO\nNO\nNO"
},
{
"input": "2\n81 25",
"output": "NO\nYES"
},
{
"input": "1\n16",
"output": "NO"
},
{
"input": "22\n1 2 3 4 5 6 7 8 9 10 12752041 64 121 144 27550356289 124 24657 23756 135153365 25235235235 42351351 81",
"output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "1\n225",
"output": "NO"
},
{
"input": "1\n1521",
"output": "NO"
},
{
"input": "1\n81",
"output": "NO"
}
] | 1,697,021,174 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 60 | 0 | def prime(num):
sum = 0
for i in range(2,min(100,num)):
if num% i == 0:
sum += 1
if sum == 1:
return True
else:
return False
a = int(input())
arr = list(map(int,input().split()))
for l in arr:
if prime(l):
print("YES")
else:
print("NO")
| Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
Input Specification:
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
Demo Input:
['3\n4 5 6\n']
Demo Output:
['YES\nNO\nNO\n']
Note:
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | ```python
def prime(num):
sum = 0
for i in range(2,min(100,num)):
if num% i == 0:
sum += 1
if sum == 1:
return True
else:
return False
a = int(input())
arr = list(map(int,input().split()))
for l in arr:
if prime(l):
print("YES")
else:
print("NO")
``` | 0 |
|
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,690,020,300 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | a, b = map(int,input().split())
c1 = 0
c2 = 0
while a > 0 and b > 0 :
a -= 1
b -= 1
c1 += 1
if a == 0 :
while b > 0 and a > 1 :
b-= 2
c2 += 1
if b == 0 and a > 1 :
while a > 0 :
a-= 2
c2 += 1
print(c1, c2)
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | ```python
a, b = map(int,input().split())
c1 = 0
c2 = 0
while a > 0 and b > 0 :
a -= 1
b -= 1
c1 += 1
if a == 0 :
while b > 0 and a > 1 :
b-= 2
c2 += 1
if b == 0 and a > 1 :
while a > 0 :
a-= 2
c2 += 1
print(c1, c2)
``` | 0 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,661,108,152 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | def convert(string):
list1 = []
list1[:0] = string
return list1
a = input()
l1 = convert(a)
lower = 0
upper = 0
for i in l1:
if i.isupper():
upper += 1
else:
lower += 1
if upper>lower:
print(a.upper())
else:
print(a.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
def convert(string):
list1 = []
list1[:0] = string
return list1
a = input()
l1 = convert(a)
lower = 0
upper = 0
for i in l1:
if i.isupper():
upper += 1
else:
lower += 1
if upper>lower:
print(a.upper())
else:
print(a.lower())
``` | 3.969 |
810 | B | Summer sell-off | PROGRAMMING | 1,300 | [
"greedy",
"sortings"
] | null | null | Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manager knows exactly, that in *i*-th day *k**i* products will be put up for sale and exactly *l**i* clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.
For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any *f* days from *n* next for sell-outs. On each of *f* chosen days the number of products were put up for sale would be doubled. Thus, if on *i*-th day shop planned to put up for sale *k**i* products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·*k**i* products. Consequently, there is an opportunity to sell two times more products on days of sell-out.
Noora's task is to choose *f* days to maximize total number of sold products. She asks you to help her with such a difficult problem. | The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denoting the number of products on the shelves of the shop on the *i*-th day and the number of clients that will come to the shop on *i*-th day. | Print a single integer denoting the maximal number of products that shop can sell. | [
"4 2\n2 1\n3 5\n2 3\n1 5\n",
"4 1\n0 2\n0 3\n3 5\n0 6\n"
] | [
"10",
"5"
] | In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the second example it is possible to sell 5 products, if you choose third day for sell-out. | 1,000 | [
{
"input": "4 2\n2 1\n3 5\n2 3\n1 5",
"output": "10"
},
{
"input": "4 1\n0 2\n0 3\n3 5\n0 6",
"output": "5"
},
{
"input": "1 1\n5 8",
"output": "8"
},
{
"input": "2 1\n8 12\n6 11",
"output": "19"
},
{
"input": "2 1\n6 7\n5 7",
"output": "13"
},
{
"input": "2 1\n5 7\n6 7",
"output": "13"
},
{
"input": "2 1\n7 8\n3 6",
"output": "13"
},
{
"input": "2 1\n9 10\n5 8",
"output": "17"
},
{
"input": "2 1\n3 6\n7 8",
"output": "13"
},
{
"input": "1 0\n10 20",
"output": "10"
},
{
"input": "2 1\n99 100\n3 6",
"output": "105"
},
{
"input": "4 2\n2 10\n3 10\n9 9\n5 10",
"output": "27"
},
{
"input": "2 1\n3 4\n2 8",
"output": "7"
},
{
"input": "50 2\n74 90\n68 33\n49 88\n52 13\n73 21\n77 63\n27 62\n8 52\n60 57\n42 83\n98 15\n79 11\n77 46\n55 91\n72 100\n70 86\n50 51\n57 39\n20 54\n64 95\n66 22\n79 64\n31 28\n11 89\n1 36\n13 4\n75 62\n16 62\n100 35\n43 96\n97 54\n86 33\n62 63\n94 24\n19 6\n20 58\n38 38\n11 76\n70 40\n44 24\n32 96\n28 100\n62 45\n41 68\n90 52\n16 0\n98 32\n81 79\n67 82\n28 2",
"output": "1889"
},
{
"input": "2 1\n10 5\n2 4",
"output": "9"
},
{
"input": "2 1\n50 51\n30 40",
"output": "90"
},
{
"input": "3 2\n5 10\n5 10\n7 9",
"output": "27"
},
{
"input": "3 1\n1000 1000\n50 100\n2 2",
"output": "1102"
},
{
"input": "2 1\n2 4\n12 12",
"output": "16"
},
{
"input": "2 1\n4 4\n1 2",
"output": "6"
},
{
"input": "2 1\n4000 4000\n1 2",
"output": "4002"
},
{
"input": "2 1\n5 6\n2 4",
"output": "9"
},
{
"input": "3 2\n10 10\n10 10\n1 2",
"output": "22"
},
{
"input": "10 5\n9 1\n11 1\n12 1\n13 1\n14 1\n2 4\n2 4\n2 4\n2 4\n2 4",
"output": "25"
},
{
"input": "2 1\n30 30\n10 20",
"output": "50"
},
{
"input": "1 1\n1 1",
"output": "1"
},
{
"input": "2 1\n10 2\n2 10",
"output": "6"
},
{
"input": "2 1\n4 5\n3 9",
"output": "10"
},
{
"input": "2 1\n100 100\n5 10",
"output": "110"
},
{
"input": "2 1\n14 28\n15 28",
"output": "43"
},
{
"input": "2 1\n100 1\n20 40",
"output": "41"
},
{
"input": "2 1\n5 10\n6 10",
"output": "16"
},
{
"input": "2 1\n29 30\n10 20",
"output": "49"
},
{
"input": "1 0\n12 12",
"output": "12"
},
{
"input": "2 1\n7 8\n4 7",
"output": "14"
},
{
"input": "2 1\n5 5\n2 4",
"output": "9"
},
{
"input": "2 1\n1 2\n228 2",
"output": "4"
},
{
"input": "2 1\n5 10\n100 20",
"output": "30"
},
{
"input": "2 1\n1000 1001\n2 4",
"output": "1004"
},
{
"input": "2 1\n3 9\n7 7",
"output": "13"
},
{
"input": "2 0\n1 1\n1 1",
"output": "2"
},
{
"input": "4 1\n10 10\n10 10\n10 10\n4 6",
"output": "36"
},
{
"input": "18 13\n63 8\n87 100\n18 89\n35 29\n66 81\n27 85\n64 51\n60 52\n32 94\n74 22\n86 31\n43 78\n12 2\n36 2\n67 23\n2 16\n78 71\n34 64",
"output": "772"
},
{
"input": "2 1\n10 18\n17 19",
"output": "35"
},
{
"input": "3 0\n1 1\n1 1\n1 1",
"output": "3"
},
{
"input": "2 1\n4 7\n8 9",
"output": "15"
},
{
"input": "4 2\n2 10\n3 10\n9 10\n5 10",
"output": "27"
},
{
"input": "2 1\n5 7\n3 6",
"output": "11"
},
{
"input": "2 1\n3 4\n12 12",
"output": "16"
},
{
"input": "2 1\n10 11\n9 20",
"output": "28"
},
{
"input": "2 1\n7 8\n2 4",
"output": "11"
},
{
"input": "2 1\n5 10\n7 10",
"output": "17"
},
{
"input": "4 2\n2 10\n3 10\n5 10\n9 10",
"output": "27"
},
{
"input": "2 1\n99 100\n5 10",
"output": "109"
},
{
"input": "4 2\n2 10\n3 10\n5 10\n9 9",
"output": "27"
},
{
"input": "2 1\n3 7\n5 7",
"output": "11"
},
{
"input": "2 1\n10 10\n3 6",
"output": "16"
},
{
"input": "2 1\n100 1\n2 4",
"output": "5"
},
{
"input": "5 0\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "5"
},
{
"input": "3 1\n3 7\n4 5\n2 3",
"output": "12"
},
{
"input": "2 1\n3 9\n7 8",
"output": "13"
},
{
"input": "2 1\n10 2\n3 4",
"output": "6"
},
{
"input": "2 1\n40 40\n3 5",
"output": "45"
},
{
"input": "2 1\n5 3\n1 2",
"output": "5"
},
{
"input": "10 5\n9 5\n10 5\n11 5\n12 5\n13 5\n2 4\n2 4\n2 4\n2 4\n2 4",
"output": "45"
},
{
"input": "3 1\n1 5\n1 5\n4 4",
"output": "7"
},
{
"input": "4 0\n1 1\n1 1\n1 1\n1 1",
"output": "4"
},
{
"input": "4 1\n1000 1001\n1000 1001\n2 4\n1 2",
"output": "2005"
},
{
"input": "2 1\n15 30\n50 59",
"output": "80"
},
{
"input": "2 1\n8 8\n3 5",
"output": "13"
},
{
"input": "2 1\n4 5\n2 5",
"output": "8"
},
{
"input": "3 2\n3 3\n1 2\n1 2",
"output": "7"
},
{
"input": "3 1\n2 5\n2 5\n4 4",
"output": "10"
},
{
"input": "2 1\n3 10\n50 51",
"output": "56"
},
{
"input": "4 2\n2 4\n2 4\n9 10\n9 10",
"output": "26"
},
{
"input": "2 1\n3 5\n8 8",
"output": "13"
},
{
"input": "2 1\n100 150\n70 150",
"output": "240"
},
{
"input": "2 1\n4 5\n3 6",
"output": "10"
},
{
"input": "2 1\n20 10\n3 5",
"output": "15"
},
{
"input": "15 13\n76167099 92301116\n83163126 84046805\n45309500 65037149\n29982002 77381688\n76738161 52935441\n37889502 25466134\n55955619 14197941\n31462620 12999429\n64648384 8824773\n3552934 68992494\n2823376 9338427\n86832070 3763091\n67753633 2162190\n302887 92011825\n84894984 410533",
"output": "435467000"
},
{
"input": "2 1\n8 7\n3 6",
"output": "13"
},
{
"input": "2 1\n7 8\n3 5",
"output": "12"
},
{
"input": "2 1\n10 10\n1 3",
"output": "12"
},
{
"input": "2 1\n9 10\n2 4",
"output": "13"
},
{
"input": "3 1\n10 11\n12 13\n8 10",
"output": "32"
},
{
"input": "2 1\n5 10\n7 7",
"output": "17"
},
{
"input": "4 2\n90 91\n2 10\n2 10\n2 10",
"output": "100"
},
{
"input": "2 1\n2 4\n4 4",
"output": "8"
},
{
"input": "2 1\n2 3\n4 3",
"output": "6"
},
{
"input": "2 1\n40 45\n50 52",
"output": "95"
},
{
"input": "3 1\n1 4\n2 4\n3 4",
"output": "8"
},
{
"input": "2 1\n1 2\n1000 1000",
"output": "1002"
},
{
"input": "2 1\n80 100\n70 95",
"output": "175"
}
] | 1,656,988,320 | 2,147,483,647 | Python 3 | OK | TESTS | 159 | 342 | 2,764,800 | n,f = map(int,input().split())
days = []
total = 0
for i in range(n):
k,l = map(int,input().split())
if k == 0:
continue
sales = min(k,l)
total +=sales
l -=sales
days.append(min(k,l))
days.sort(reverse=1)
# print(days)
print(total + sum(days[:f])) | Title: Summer sell-off
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manager knows exactly, that in *i*-th day *k**i* products will be put up for sale and exactly *l**i* clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.
For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any *f* days from *n* next for sell-outs. On each of *f* chosen days the number of products were put up for sale would be doubled. Thus, if on *i*-th day shop planned to put up for sale *k**i* products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·*k**i* products. Consequently, there is an opportunity to sell two times more products on days of sell-out.
Noora's task is to choose *f* days to maximize total number of sold products. She asks you to help her with such a difficult problem.
Input Specification:
The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denoting the number of products on the shelves of the shop on the *i*-th day and the number of clients that will come to the shop on *i*-th day.
Output Specification:
Print a single integer denoting the maximal number of products that shop can sell.
Demo Input:
['4 2\n2 1\n3 5\n2 3\n1 5\n', '4 1\n0 2\n0 3\n3 5\n0 6\n']
Demo Output:
['10', '5']
Note:
In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the second example it is possible to sell 5 products, if you choose third day for sell-out. | ```python
n,f = map(int,input().split())
days = []
total = 0
for i in range(n):
k,l = map(int,input().split())
if k == 0:
continue
sales = min(k,l)
total +=sales
l -=sales
days.append(min(k,l))
days.sort(reverse=1)
# print(days)
print(total + sum(days[:f]))
``` | 3 |
|
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"output": "99"
},
{
"input": "gngvi",
"output": "44"
},
{
"input": "aaaaa",
"output": "0"
},
{
"input": "a",
"output": "0"
},
{
"input": "z",
"output": "1"
},
{
"input": "vyadeehhikklnoqrs",
"output": "28"
},
{
"input": "jjiihhhhgggfedcccbazyxx",
"output": "21"
},
{
"input": "fyyptqqxuciqvwdewyppjdzur",
"output": "117"
},
{
"input": "fqcnzmzmbobmancqcoalzmanaobpdse",
"output": "368"
},
{
"input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza",
"output": "8"
},
{
"input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy",
"output": "644"
},
{
"input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss",
"output": "8"
},
{
"input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl",
"output": "421"
},
{
"input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa",
"output": "84"
},
{
"input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco",
"output": "666"
},
{
"input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww",
"output": "22"
},
{
"input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh",
"output": "643"
},
{
"input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib",
"output": "245"
},
{
"input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro",
"output": "468"
},
{
"input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned",
"output": "523"
},
{
"input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna",
"output": "130"
},
{
"input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh",
"output": "163"
},
{
"input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb",
"output": "155"
},
{
"input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp",
"output": "57"
},
{
"input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs",
"output": "1236"
},
{
"input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx",
"output": "49"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt",
"output": "331"
},
{
"input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte",
"output": "692"
},
{
"input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh",
"output": "1293"
},
{
"input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg",
"output": "16"
},
{
"input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple",
"output": "616"
},
{
"input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl",
"output": "605"
},
{
"input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud",
"output": "549"
},
{
"input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore",
"output": "688"
},
{
"input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc",
"output": "604"
},
{
"input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa",
"output": "572"
},
{
"input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp",
"output": "609"
},
{
"input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl",
"output": "223"
},
{
"input": "aa",
"output": "0"
}
] | 1,670,312,560 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | s=input()
pos=ord('a')
s1=0
for i in s:
s1+=min(26-abs(ord(i)-pos),abs(ord(i)-pos))
pos=ord(i)
print(s1)
| Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
Input Specification:
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Output Specification:
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
Demo Input:
['zeus\n', 'map\n', 'ares\n']
Demo Output:
['18\n', '35\n', '34\n']
Note:
To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | ```python
s=input()
pos=ord('a')
s1=0
for i in s:
s1+=min(26-abs(ord(i)-pos),abs(ord(i)-pos))
pos=ord(i)
print(s1)
``` | 3 |
|
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=><=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen.
For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.
You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything. | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word. | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1. | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
"input": "3 5\n1 10 20",
"output": "1"
},
{
"input": "3 10\n1 2 3",
"output": "3"
},
{
"input": "2 1\n1 100",
"output": "1"
},
{
"input": "3 1\n1 2 10",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "2"
}
] | 1,683,278,470 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 77 | 13,209,600 | n,c = map(int,input().split())
a = list(map(int,input().split()))
m = 0
for i in range(1,len(a)):
if((a[-i] - a[-(i+1)]) <= c):
m = m+1
continue
else:
break
print(m+1)
| Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=><=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen.
For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.
You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
Input Specification:
The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word.
Output Specification:
Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*.
Demo Input:
['6 5\n1 3 8 14 19 20\n', '6 1\n1 3 5 7 9 10\n']
Demo Output:
['3', '2']
Note:
The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1. | ```python
n,c = map(int,input().split())
a = list(map(int,input().split()))
m = 0
for i in range(1,len(a)):
if((a[-i] - a[-(i+1)]) <= c):
m = m+1
continue
else:
break
print(m+1)
``` | 3 |
|
246 | B | Increase and Decrease | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i*, *a**j* (*i*<=≠<=*j*); - he simultaneously increases number *a**i* by 1 and decreases number *a**j* by 1, that is, executes *a**i*<==<=*a**i*<=+<=1 and *a**j*<==<=*a**j*<=-<=1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | [
"2\n2 1\n",
"3\n1 4 1\n"
] | [
"1\n",
"3\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 4 1",
"output": "3"
},
{
"input": "4\n2 -7 -2 -6",
"output": "3"
},
{
"input": "4\n2 0 -2 -1",
"output": "3"
},
{
"input": "6\n-1 1 0 0 -1 -1",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"output": "5"
},
{
"input": "100\n968 793 -628 -416 942 -308 977 168 728 -879 952 781 -425 -475 -480 738 -740 142 -319 -116 -701 -183 41 324 -918 -391 -176 781 763 888 475 -617 134 -802 -133 -211 855 -869 -236 503 550 387 137 -221 -957 -800 -56 -673 440 -791 -217 -959 -892 886 -593 427 890 223 -425 -342 -262 693 -137 924 860 156 -110 444 -12 703 421 -638 725 -551 597 -206 -80 393 -441 -759 617 424 -506 209 579 -685 -861 507 312 597 -81 -491 424 222 -892 629 512 743 -452 -504",
"output": "99"
}
] | 1,586,501,990 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 216 | 0 | n=int(input())
a=[int(a) for a in input().split()]
if sum(a)%2==0:
print (n)
else:
print (n-1)
| Title: Increase and Decrease
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i*, *a**j* (*i*<=≠<=*j*); - he simultaneously increases number *a**i* by 1 and decreases number *a**j* by 1, that is, executes *a**i*<==<=*a**i*<=+<=1 and *a**j*<==<=*a**j*<=-<=1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array.
Output Specification:
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Demo Input:
['2\n2 1\n', '3\n1 4 1\n']
Demo Output:
['1\n', '3\n']
Note:
none | ```python
n=int(input())
a=[int(a) for a in input().split()]
if sum(a)%2==0:
print (n)
else:
print (n-1)
``` | 0 |
|
276 | B | Little Girl and Game | PROGRAMMING | 1,300 | [
"games",
"greedy"
] | null | null | The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second. | The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters. | In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. | [
"aba\n",
"abca\n"
] | [
"First\n",
"Second\n"
] | none | 1,000 | [
{
"input": "aba",
"output": "First"
},
{
"input": "abca",
"output": "Second"
},
{
"input": "aabb",
"output": "First"
},
{
"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo",
"output": "Second"
},
{
"input": "gevqgtaorjixsxnbcoybr",
"output": "First"
},
{
"input": "xvhtcbtouuddhylxhplgjxwlo",
"output": "First"
},
{
"input": "knaxhkbokmtfvnjvlsbrfoefpjpkqwlumeqqbeohodnwevhllkylposdpjuoizyunuxivzrjofiyxxiliuwhkjqpkqxukxroivfhikxjdtwcqngqswptdwrywxszxrqojjphzwzxqftnfhkapeejdgckfyrxtpuipfljsjwgpjfatmxpylpnerllshuvkbomlpghjrxcgxvktgeyuhrcwgvdmppqnkdmjtxukzlzqhfbgrishuhkyggkpstvqabpxoqjuovwjwcmazmvpfpnljdgpokpatjnvwacotkvxheorzbsrazldsquijzkmtmqahakjrjvzkquvayxpqrmqqcknilpqpjapagezonfpz",
"output": "Second"
},
{
"input": "desktciwoidfuswycratvovutcgjrcyzmilsmadzaegseetexygedzxdmorxzxgiqhcuppshcsjcozkopebegfmxzxxagzwoymlghgjexcgfojychyt",
"output": "First"
},
{
"input": "gfhuidxgxpxduqrfnqrnefgtyxgmrtehmddjkddwdiayyilaknxhlxszeslnsjpcrwnoqubmbpcehiftteirkfvbtfyibiikdaxmondnawtvqccctdxrjcfxqwqhvvrqmhqflbzskrayvruqvqijrmikucwzodxvufwxpxxjxlifdjzxrttjzatafkbzsjupsiefmipdufqltedjlytphzppoevxawjdhbxgennevbvdgpoeihasycctyddenzypoprchkoioouhcexjqwjflxvkgpgjatstlmledxasecfhwvabzwviywsiaryqrxyeceefblherqjevdzkfxslqiytwzz",
"output": "First"
},
{
"input": "fezzkpyctjvvqtncmmjsitrxaliyhirspnjjngvzdoudrkkvvdiwcwtcxobpobzukegtcrwsgxxzlcphdxkbxdximqbycaicfdeqlvzboptfimkzvjzdsvahorqqhcirpkhtwjkplitpacpkpbhnxtoxuoqsxcxnhtrmzvexmpvlethbkvmlzftimjnidrzvcunbpysvukzgwghjmwrvstsunaocnoqohcsggtrwxiworkliqejajewbrtdwgnyynpupbrrvtfqtlaaq",
"output": "Second"
},
{
"input": "tsvxmeixijyavdalmrvscwohzubhhgsocdvnjmjtctojbxxpezzbgfltixwgzmkfwdnlhidhrdgyajggmrvmwaoydodjmzqvgabyszfqcuhwdncyfqvmackvijgpjyiauxljvvwgiofdxccwmybdfcfcrqppbvbagmnvvvhngxauwbpourviyfokwjweypzzrrzjcmddnpoaqgqfgglssjnlshrerfffmrwhapzknxveiqixflykjbnpivogtdpyjakwrdoklsbvbkjhdojfnuwbpcfdycwxecysbyjfvoykxsxgg",
"output": "First"
},
{
"input": "upgqmhfmfnodsyosgqswugfvpdxhtkxvhlsxrjiqlojchoddxkpsamwmuvopdbncymcgrkurwlxerexgswricuqxhvqvgekeofkgqabypamozmyjyfvpifsaotnyzqydcenphcsmplekinwkmwzpjnlapfdbhxjdcnarlgkfgxzfbpgsuxqfyhnxjhtojrlnprnxprfbkkcyriqztjeeepkzgzcaiutvbqqofyhddfebozhvtvrigtidxqmydjxegxipakzjcnenjkdroyjmxugj",
"output": "Second"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccddddddddddeeeeeeeeeeffffgggghhhhiiiijjjjqqqqwwwweeeerrrrttttyyyyuuuuiiiiooooppppaaaassssddddffffgggghhhhjjjjkkkkllllzzzzxxxxccccvvvvbbbbnnnnmmmm",
"output": "First"
},
{
"input": "vnvtvnxjrtffdhrfvczzoyeokjabxcilmmsrhwuakghvuabcmfpmblyroodmhfivmhqoiqhapoglwaluewhqkunzitmvijaictjdncivccedfpaezcnpwemlohbhjjlqsonuclaumgbzjamsrhuzqdqtitygggsnruuccdtxkgbdd",
"output": "First"
},
{
"input": "vqdtkbvlbdyndheoiiwqhnvcmmhnhsmwwrvesnpdfxvprqbwzbodoihrywagphlsrcbtnvppjsquuuzkjazaenienjiyctyajsqdfsdiedzugkymgzllvpxfetkwfabbiotjcknzdwsvmbbuqrxrulvgljagvxdmfsqtcczhifhoghqgffkbviphbabwiaqburerfkbqfjbptkwlahysrrfwjbqfnrgnsnsukqqcxxwqtuhvdzqmpfwrbqzdwxcaifuyhvojgurmchh",
"output": "First"
},
{
"input": "hxueikegwnrctlciwguepdsgupguykrntbszeqzzbpdlouwnmqgzcxejidstxyxhdlnttnibxstduwiflouzfswfikdudkazoefawm",
"output": "Second"
},
{
"input": "ershkhsywqftixappwqzoojtnamvqjbyfauvuubwpctspioqusnnivwsiyszfhlrskbswaiaczurygcioonjcndntwvrlaejyrghfnecltqytfmkvjxuujifgtujrqsisdawpwgttxynewiqhdhronamabysvpxankxeybcjqttbqnciwuqiehzyfjoedaradqnfthuuwrezwrkjiytpgwfwbslawbiezdbdltenjlaygwaxddplgseiaojndqjcopvolqbvnacuvfvirzbrnlnyjixngeevcggmirzatenjihpgnyfjhgsjgzepohbyhmzbatfwuorwutavlqsogrvcjpqziuifrhurq",
"output": "First"
},
{
"input": "qilwpsuxogazrfgfznngwklnioueuccyjfatjoizcctgsweitzofwkyjustizbopzwtaqxbtovkdrxeplukrcuozhpymldstbbfynkgsmafigetvzkxloxqtphvtwkgfjkiczttcsxkjpsoutdpzxytrsqgjtbdljjrbmkudrkodfvcwkcuggbsthxdyogeeyfuyhmnwgyuatfkvchavpzadfacckdurlbqjkthqbnirzzbpusxcenkpgtizayjmsahvobobudfeaewcqmrlxxnocqzmkessnguxkiccrxyvnxxlqnqfwuzmupk",
"output": "First"
},
{
"input": "opfokvwzpllctflkphutcrkferbjyyrasqqkrcvoymyrxwaudgsugcqveccymdplxmtlzfoptmrapfeizpnnhbzlkuyznwacnswibxhqunazbhdvrlidghisuqunstbuevjzimvlfvopgqxrvahhngnaumgywscfrfwfpnfxwhfrelbunmedvkssykwjyartxjiplerntzkpiiaalijiwhyuhxlvhxpkgfypvrpqqsacuwocdampnnhvibsbolyduvscsjfayxpldyvqzjbqojjxdvxtctwtifcdfcaoonzbgegyllngwvjivtxeezoabhsihcuvgvdsgjtzbzwovjshvwrljkxavowovzrfpdufpogdtujkerdorpboufrxhyswirjehgsxthlvjufvahdpeajidqipwaxokbeycrievgcfkyuyavaq",
"output": "Second"
},
{
"input": "a",
"output": "First"
},
{
"input": "ab",
"output": "Second"
},
{
"input": "abacaba",
"output": "First"
},
{
"input": "abazaba",
"output": "First"
},
{
"input": "zz",
"output": "First"
},
{
"input": "aassddxyz",
"output": "First"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "Second"
},
{
"input": "aabc",
"output": "Second"
},
{
"input": "abcabc",
"output": "First"
},
{
"input": "aaabbbccdd",
"output": "Second"
},
{
"input": "aabbcccc",
"output": "First"
}
] | 1,683,682,494 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | s = input().strip()
letters = set()
for c in s:
if c in letters:
letters.discard(c)
else:
letters.add(c)
print('First' if len(letters)&1 else 'Second') | Title: Little Girl and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
Input Specification:
The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters.
Output Specification:
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
Demo Input:
['aba\n', 'abca\n']
Demo Output:
['First\n', 'Second\n']
Note:
none | ```python
s = input().strip()
letters = set()
for c in s:
if c in letters:
letters.discard(c)
else:
letters.add(c)
print('First' if len(letters)&1 else 'Second')
``` | 0 |
|
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system. | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1",
"output": "YES"
},
{
"input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1",
"output": "NO"
},
{
"input": "10 3\n8 3 5 4 2 3 2 2 1",
"output": "NO"
},
{
"input": "10 9\n8 3 5 4 2 3 2 2 1",
"output": "YES"
},
{
"input": "3 2\n1 1",
"output": "YES"
},
{
"input": "3 2\n2 1",
"output": "NO"
},
{
"input": "4 2\n2 1 1",
"output": "NO"
},
{
"input": "4 4\n2 2 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 1 1",
"output": "YES"
},
{
"input": "3 3\n2 1",
"output": "YES"
},
{
"input": "4 4\n1 1 1",
"output": "YES"
},
{
"input": "8 8\n1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5 5\n1 1 1 1",
"output": "YES"
}
] | 1,645,609,496 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 46 | 1,536,000 | n, t = map(int, input().split())
arr = list(map(int, input().split()))
con = True
i = 0
while i<n-1:
if i == t-1:
print('YES')
con = False
break
i += arr[i]
if con: print('NO') | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
Input Specification:
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
Output Specification:
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
Demo Input:
['8 4\n1 2 1 2 1 2 1\n', '8 5\n1 2 1 2 1 1 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | ```python
n, t = map(int, input().split())
arr = list(map(int, input().split()))
con = True
i = 0
while i<n-1:
if i == t-1:
print('YES')
con = False
break
i += arr[i]
if con: print('NO')
``` | 0 |
|
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n1 2 3 3 4",
"output": "3"
},
{
"input": "4\n1 2 2 3",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n1 2 1",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 1 2",
"output": "2"
},
{
"input": "11\n1 2 3 1 2 3 2 1 2 3 4",
"output": "4"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n3 2 1",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "7"
},
{
"input": "1\n1234394",
"output": "1"
}
] | 1,678,363,326 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 13,516,800 | #a=int(input())
#sum=0
#x = list(map(int, input().split()))
#print("List of students: ", x)
#for b in x:
# sum =sum+b
#sum=(sum/(a*100))
#print(100*sum)
#quant=int(input())
# :5 X 4,:3 x 2 ,:2
tam=int(input())
max=1
resp=1
a=list(map(int, input().split()))
for i in range (tam):
if(max >resp):
resp=max
max=1
for i1 in range(i+1,tam):
if (a[i1]>a[i1-1]):
max=max +1
else :
break
print(resp)
| Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Input Specification:
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print the maximum length of an increasing subarray of the given array.
Demo Input:
['5\n1 7 2 11 15\n', '6\n100 100 100 100 100 100\n', '3\n1 2 3\n']
Demo Output:
['3\n', '1\n', '3\n']
Note:
none | ```python
#a=int(input())
#sum=0
#x = list(map(int, input().split()))
#print("List of students: ", x)
#for b in x:
# sum =sum+b
#sum=(sum/(a*100))
#print(100*sum)
#quant=int(input())
# :5 X 4,:3 x 2 ,:2
tam=int(input())
max=1
resp=1
a=list(map(int, input().split()))
for i in range (tam):
if(max >resp):
resp=max
max=1
for i1 in range(i+1,tam):
if (a[i1]>a[i1-1]):
max=max +1
else :
break
print(resp)
``` | 0 |
|
991 | C | Candies | PROGRAMMING | 1,500 | [
"binary search",
"implementation"
] | null | null | After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $k$, same for all days. After that, in the morning he eats $k$ candies from the box (if there are less than $k$ candies in the box, he eats them all), then in the evening Petya eats $10\%$ of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats $k$ candies again, and Petya — $10\%$ of the candies left in a box, and so on.
If the amount of candies in the box is not divisible by $10$, Petya rounds the amount he takes from the box down. For example, if there were $97$ candies in the box, Petya would eat only $9$ of them. In particular, if there are less than $10$ candies in a box, Petya won't eat any at all.
Your task is to find out the minimal amount of $k$ that can be chosen by Vasya so that he would eat at least half of the $n$ candies he initially got. Note that the number $k$ must be integer. | The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box. | Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got. | [
"68\n"
] | [
"3\n"
] | In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first):
$68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$.
In total, Vasya would eat $39$ candies, while Petya — $29$. | 1,250 | [
{
"input": "68",
"output": "3"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "42",
"output": "1"
},
{
"input": "43",
"output": "2"
},
{
"input": "756",
"output": "29"
},
{
"input": "999999972",
"output": "39259423"
},
{
"input": "999999973",
"output": "39259424"
},
{
"input": "1000000000000000000",
"output": "39259424579862572"
},
{
"input": "6",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "5",
"output": "1"
},
{
"input": "66",
"output": "2"
},
{
"input": "67",
"output": "3"
},
{
"input": "1000",
"output": "39"
},
{
"input": "10000",
"output": "392"
},
{
"input": "100500",
"output": "3945"
},
{
"input": "1000000",
"output": "39259"
},
{
"input": "10000000",
"output": "392594"
},
{
"input": "100000000",
"output": "3925942"
},
{
"input": "123456789",
"output": "4846842"
},
{
"input": "543212345",
"output": "21326204"
},
{
"input": "505050505",
"output": "19827992"
},
{
"input": "777777777",
"output": "30535108"
},
{
"input": "888888871",
"output": "34897266"
},
{
"input": "1000000000",
"output": "39259424"
},
{
"input": "999999999999999973",
"output": "39259424579862572"
},
{
"input": "999999999999999998",
"output": "39259424579862572"
},
{
"input": "999999999999999999",
"output": "39259424579862573"
},
{
"input": "100000000000000000",
"output": "3925942457986257"
},
{
"input": "540776028375043656",
"output": "21230555700587649"
},
{
"input": "210364830044445976",
"output": "8258802179385535"
},
{
"input": "297107279239074256",
"output": "11664260821414605"
},
{
"input": "773524766411950187",
"output": "30368137227605772"
},
{
"input": "228684941775227220",
"output": "8978039224174797"
},
{
"input": "878782039723446310",
"output": "34500477210660436"
},
{
"input": "615090701338187389",
"output": "24148106998961343"
},
{
"input": "325990422297859188",
"output": "12798196397960353"
},
{
"input": "255163492355051023",
"output": "10017571883647466"
},
{
"input": "276392003308849171",
"output": "10850991008380891"
},
{
"input": "601",
"output": "23"
},
{
"input": "983",
"output": "38"
},
{
"input": "729",
"output": "29"
},
{
"input": "70",
"output": "3"
},
{
"input": "703",
"output": "28"
},
{
"input": "257",
"output": "10"
},
{
"input": "526",
"output": "20"
},
{
"input": "466",
"output": "18"
},
{
"input": "738",
"output": "29"
},
{
"input": "116",
"output": "5"
},
{
"input": "888888888888888887",
"output": "34897266293211176"
},
{
"input": "888888888888888888",
"output": "34897266293211176"
},
{
"input": "888888888888888889",
"output": "34897266293211176"
},
{
"input": "999999999999999969",
"output": "39259424579862571"
},
{
"input": "999999999999999970",
"output": "39259424579862571"
},
{
"input": "999999999999999971",
"output": "39259424579862572"
},
{
"input": "999999999999999943",
"output": "39259424579862571"
},
{
"input": "999999999999999944",
"output": "39259424579862570"
},
{
"input": "999999999999999945",
"output": "39259424579862571"
},
{
"input": "999999999999999917",
"output": "39259424579862570"
},
{
"input": "999999999999999918",
"output": "39259424579862569"
},
{
"input": "999999999999999919",
"output": "39259424579862570"
},
{
"input": "99999999999999957",
"output": "3925942457986255"
},
{
"input": "99999999999999958",
"output": "3925942457986255"
},
{
"input": "99999999999999959",
"output": "3925942457986256"
},
{
"input": "888888888888888853",
"output": "34897266293211174"
},
{
"input": "888888888888888854",
"output": "34897266293211174"
},
{
"input": "888888888888888855",
"output": "34897266293211175"
}
] | 1,549,188,330 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long li;
li check(li num, li k) {
li ans = 0;
while (num != 0) {
ans += min(num, k);
num -= min(num, k);
num -= num / 10;
}
return ans;
}
int main() {
li n;
cin >> n;
li l = 1;
li r = n;
while (r - l > 1){
li mb = check(n, (r + l) / 2);
if (mb >= n / 2){
r = (r + l) / 2;
}
else l = (r + l) / 2;
}
if (check(n, l) >= n / 2) cout << l;
else cout << r;
return 0;
} | Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $k$, same for all days. After that, in the morning he eats $k$ candies from the box (if there are less than $k$ candies in the box, he eats them all), then in the evening Petya eats $10\%$ of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats $k$ candies again, and Petya — $10\%$ of the candies left in a box, and so on.
If the amount of candies in the box is not divisible by $10$, Petya rounds the amount he takes from the box down. For example, if there were $97$ candies in the box, Petya would eat only $9$ of them. In particular, if there are less than $10$ candies in a box, Petya won't eat any at all.
Your task is to find out the minimal amount of $k$ that can be chosen by Vasya so that he would eat at least half of the $n$ candies he initially got. Note that the number $k$ must be integer.
Input Specification:
The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box.
Output Specification:
Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got.
Demo Input:
['68\n']
Demo Output:
['3\n']
Note:
In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first):
$68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$.
In total, Vasya would eat $39$ candies, while Petya — $29$. | ```python
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long li;
li check(li num, li k) {
li ans = 0;
while (num != 0) {
ans += min(num, k);
num -= min(num, k);
num -= num / 10;
}
return ans;
}
int main() {
li n;
cin >> n;
li l = 1;
li r = n;
while (r - l > 1){
li mb = check(n, (r + l) / 2);
if (mb >= n / 2){
r = (r + l) / 2;
}
else l = (r + l) / 2;
}
if (check(n, l) >= n / 2) cout << l;
else cout << r;
return 0;
}
``` | -1 |
|
938 | D | Buy a Ticket | PROGRAMMING | 2,000 | [
"data structures",
"graphs",
"shortest paths"
] | null | null | Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well.
There are *n* cities in Berland. People can travel between cities using two-directional train routes; there are exactly *m* routes, *i*-th route can be used to go from city *v**i* to city *u**i* (and from *u**i* to *v**i*), and it costs *w**i* coins to use this route.
Each city will be visited by "Flayer", and the cost of the concert ticket in *i*-th city is *a**i* coins.
You have friends in every city of Berland, and they, knowing about your programming skills, asked you to calculate the minimum possible number of coins they have to pay to visit the concert. For every city *i* you have to compute the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*).
Formally, for every you have to calculate , where *d*(*i*,<=*j*) is the minimum number of coins you have to spend to travel from city *i* to city *j*. If there is no way to reach city *j* from city *i*, then we consider *d*(*i*,<=*j*) to be infinitely large. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=2·105, 1<=≤<=*m*<=≤<=2·105).
Then *m* lines follow, *i*-th contains three integers *v**i*, *u**i* and *w**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*,<=*v**i*<=≠<=*u**i*, 1<=≤<=*w**i*<=≤<=1012) denoting *i*-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each (*v*,<=*u*) neither extra (*v*,<=*u*) nor (*u*,<=*v*) present in input.
The next line contains *n* integers *a*1,<=*a*2,<=... *a**k* (1<=≤<=*a**i*<=≤<=1012) — price to attend the concert in *i*-th city. | Print *n* integers. *i*-th of them must be equal to the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*). | [
"4 2\n1 2 4\n2 3 7\n6 20 1 25\n",
"3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20\n"
] | [
"6 14 1 25 \n",
"12 10 12 \n"
] | none | 0 | [
{
"input": "4 2\n1 2 4\n2 3 7\n6 20 1 25",
"output": "6 14 1 25 "
},
{
"input": "3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20",
"output": "12 10 12 "
},
{
"input": "7 7\n1 6 745325\n2 3 3581176\n2 4 19\n3 6 71263060078\n5 4 141198\n7 4 163953\n5 6 15994\n1 297404206755 82096176217 14663411 187389745 21385 704393",
"output": "1 335807 7498159 335769 53373 21385 663675 "
}
] | 1,604,730,344 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 1,512 | 56,012,800 | from sys import stdin, stdout
n, m = map(int, stdin.readline().split())
city_price = [0 for i in range(n)]
ady = [[] for i in range(n)]
for i in range(m):
u,v,w = map(int,stdin.readline().split())
ady[u-1].append((v-1,2*w))
ady[v-1].append((u-1,2*w))
d_xcity = list(map(int,stdin.readline().split()))
pq = [[i,d_xcity[i]] for i in range(n)]
index = [i for i in range(n)]
h_size = n
parent = lambda i: (1+i)//2-1
lc = lambda i: 2*i +1
rc = lambda i: 2*i +2
def heapify_dw(i):
posMin = i
izq = lc(i)
der = rc(i)
if izq < h_size and pq[izq][1] < pq[posMin][1]:
posMin = izq
if der < h_size and pq[der][1]< pq[posMin][1]:
posMin = der
if posMin!= i:
u,v = pq[i][0],pq[posMin][0]
index[u],index[v] = posMin,i
pq[i], pq[posMin] = pq[posMin], pq[i]
heapify_dw(posMin)
def heapify_up(i):
p = parent(i)
if p < 0 or pq[p][1] < pq[i][1]:
pass
else:
u,v = pq[i][0],pq[p][0]
index[u],index[v] = p,i
pq[p],pq[i] = pq[i],pq[p]
heapify_up(p)
def decrese_d(v,d):
i = index[v]
pq[i][1] = d
heapify_up(i)
def build_heap():
for i in range(h_size//2 -1,-1):
heapify_dw(i)
def pop_min():
if h_size == 0:
return pq[0]
t = pq[0]
pq[0] = pq[h_size]
heapify_dw(0)
return t
build_heap()
while h_size>0:
h_size = h_size -1
u,du = pop_min()
for v,w in ady[u]:
if d_xcity[v] > d_xcity[u] + w:
d_xcity[v] = d_xcity[u] + w
decrese_d(v,d_xcity[v])
stdout.write(' '.join(map(str,d_xcity))) | Title: Buy a Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well.
There are *n* cities in Berland. People can travel between cities using two-directional train routes; there are exactly *m* routes, *i*-th route can be used to go from city *v**i* to city *u**i* (and from *u**i* to *v**i*), and it costs *w**i* coins to use this route.
Each city will be visited by "Flayer", and the cost of the concert ticket in *i*-th city is *a**i* coins.
You have friends in every city of Berland, and they, knowing about your programming skills, asked you to calculate the minimum possible number of coins they have to pay to visit the concert. For every city *i* you have to compute the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*).
Formally, for every you have to calculate , where *d*(*i*,<=*j*) is the minimum number of coins you have to spend to travel from city *i* to city *j*. If there is no way to reach city *j* from city *i*, then we consider *d*(*i*,<=*j*) to be infinitely large.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=2·105, 1<=≤<=*m*<=≤<=2·105).
Then *m* lines follow, *i*-th contains three integers *v**i*, *u**i* and *w**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*,<=*v**i*<=≠<=*u**i*, 1<=≤<=*w**i*<=≤<=1012) denoting *i*-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each (*v*,<=*u*) neither extra (*v*,<=*u*) nor (*u*,<=*v*) present in input.
The next line contains *n* integers *a*1,<=*a*2,<=... *a**k* (1<=≤<=*a**i*<=≤<=1012) — price to attend the concert in *i*-th city.
Output Specification:
Print *n* integers. *i*-th of them must be equal to the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*).
Demo Input:
['4 2\n1 2 4\n2 3 7\n6 20 1 25\n', '3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20\n']
Demo Output:
['6 14 1 25 \n', '12 10 12 \n']
Note:
none | ```python
from sys import stdin, stdout
n, m = map(int, stdin.readline().split())
city_price = [0 for i in range(n)]
ady = [[] for i in range(n)]
for i in range(m):
u,v,w = map(int,stdin.readline().split())
ady[u-1].append((v-1,2*w))
ady[v-1].append((u-1,2*w))
d_xcity = list(map(int,stdin.readline().split()))
pq = [[i,d_xcity[i]] for i in range(n)]
index = [i for i in range(n)]
h_size = n
parent = lambda i: (1+i)//2-1
lc = lambda i: 2*i +1
rc = lambda i: 2*i +2
def heapify_dw(i):
posMin = i
izq = lc(i)
der = rc(i)
if izq < h_size and pq[izq][1] < pq[posMin][1]:
posMin = izq
if der < h_size and pq[der][1]< pq[posMin][1]:
posMin = der
if posMin!= i:
u,v = pq[i][0],pq[posMin][0]
index[u],index[v] = posMin,i
pq[i], pq[posMin] = pq[posMin], pq[i]
heapify_dw(posMin)
def heapify_up(i):
p = parent(i)
if p < 0 or pq[p][1] < pq[i][1]:
pass
else:
u,v = pq[i][0],pq[p][0]
index[u],index[v] = p,i
pq[p],pq[i] = pq[i],pq[p]
heapify_up(p)
def decrese_d(v,d):
i = index[v]
pq[i][1] = d
heapify_up(i)
def build_heap():
for i in range(h_size//2 -1,-1):
heapify_dw(i)
def pop_min():
if h_size == 0:
return pq[0]
t = pq[0]
pq[0] = pq[h_size]
heapify_dw(0)
return t
build_heap()
while h_size>0:
h_size = h_size -1
u,du = pop_min()
for v,w in ady[u]:
if d_xcity[v] > d_xcity[u] + w:
d_xcity[v] = d_xcity[u] + w
decrese_d(v,d_xcity[v])
stdout.write(' '.join(map(str,d_xcity)))
``` | 0 |
|
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted. | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000 1000",
"output": "100"
},
{
"input": "8\n200000 1 200000 1 200000 1 200000 2",
"output": "1"
},
{
"input": "5\n20000 1 2 3 4",
"output": "20000"
},
{
"input": "2\n200000 1",
"output": "200000"
},
{
"input": "3\n2 100 2",
"output": "100"
},
{
"input": "2\n10 1",
"output": "10"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n5 5 5",
"output": "5"
},
{
"input": "2\n5 1",
"output": "5"
}
] | 1,510,509,567 | 6,867 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 46 | 0 | n = int(input())
m = list(map(int, input().split(" ")))
c = list()
for i in range(int(1, n+1)):
if m[-i] not in c:
c.append(m[-i])
print(c[-1]) | Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input Specification:
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output Specification:
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Demo Input:
['5\n1 3 2 1 2\n', '6\n2 1 2 2 4 1\n']
Demo Output:
['3\n', '2\n']
Note:
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | ```python
n = int(input())
m = list(map(int, input().split(" ")))
c = list()
for i in range(int(1, n+1)):
if m[-i] not in c:
c.append(m[-i])
print(c[-1])
``` | -1 |
|
277 | A | Learning Languages | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | null | null | The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.
Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating). | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages.
Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next, the *i*-th line contains *k**i* integers — *a**ij* (1<=≤<=*a**ij*<=≤<=*m*) — the identifiers of languages the *i*-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.
The numbers in the lines are separated by single spaces. | Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). | [
"5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"2 2\n1 2\n0\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | 500 | [
{
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5",
"output": "0"
},
{
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1",
"output": "2"
},
{
"input": "2 2\n1 2\n0",
"output": "1"
},
{
"input": "2 2\n0\n0",
"output": "2"
},
{
"input": "5 5\n1 3\n0\n0\n2 4 1\n0",
"output": "4"
},
{
"input": "6 2\n0\n0\n2 1 2\n1 1\n1 1\n0",
"output": "3"
},
{
"input": "7 3\n3 1 3 2\n3 2 1 3\n2 2 3\n1 1\n2 2 3\n3 3 2 1\n3 2 3 1",
"output": "0"
},
{
"input": "8 4\n0\n0\n4 2 3 1 4\n4 2 1 4 3\n3 4 3 1\n1 2\n2 4 1\n2 4 2",
"output": "2"
},
{
"input": "10 10\n5 7 5 2 8 1\n7 10 6 9 5 8 2 4\n2 2 7\n5 8 6 9 10 1\n2 9 5\n3 6 5 2\n6 5 8 7 9 10 4\n0\n1 1\n2 8 6",
"output": "1"
},
{
"input": "11 42\n4 20 26 9 24\n14 34 7 28 32 12 15 26 4 10 38 21 20 8 11\n4 21 8 36 6\n11 32 1 39 11 21 10 25 17 26 15 4\n2 8 12\n2 21 31\n8 17 10 3 39 32 30 5 15\n20 24 20 38 17 4 7 21 19 32 28 31 22 30 37 10 5 33 2 13 9\n7 38 34 42 27 20 11 6\n3 40 3 39\n14 39 40 4 30 33 8 36 28 14 23 16 7 25 9",
"output": "0"
},
{
"input": "100 100\n1 33\n0\n2 35 4\n2 40 78\n1 69\n0\n1 2\n0\n0\n2 81 34\n1 45\n0\n1 87\n1 50\n1 97\n0\n2 100 59\n0\n0\n0\n1 45\n0\n0\n0\n1 6\n1 54\n0\n0\n0\n4 79 96 52 84\n1 86\n0\n0\n0\n0\n0\n0\n0\n0\n3 90 2 80\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 2\n0\n1 64\n0\n1 78\n1 82\n0\n0\n0\n0\n0\n1 6\n0\n0\n2 47 57\n1 95\n0\n2 91 79\n0\n1 27\n0\n1 74\n0\n0\n1 14\n0\n0\n2 90 19\n0\n1 10\n0\n0\n0\n0\n0\n1 57\n0\n2 28 50\n0\n0\n0\n1 47\n0\n0\n1 14\n0\n1 84\n1 1\n0\n0",
"output": "87"
},
{
"input": "2 2\n2 1 2\n2 1 2",
"output": "0"
},
{
"input": "2 2\n2 1 2\n1 1",
"output": "0"
},
{
"input": "2 2\n1 2\n1 1",
"output": "1"
},
{
"input": "3 100\n0\n0\n0",
"output": "3"
},
{
"input": "100 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0",
"output": "100"
},
{
"input": "3 3\n0\n0\n0",
"output": "3"
}
] | 1,547,036,648 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 0 | n,m = map(int,input().split())
lang = [set(list(map(int,input().split()))[1:]) for _ in range(n)]
g = {}
for i,e in enumerate(lang):
g[i] = []
if len(e)!=0:
for j,o in enumerate(lang):
if i!=j and len(o)!=0:
if len(e&o)!=0:
g[i].append(j)
ma = []
for i in range(n):
stack = [i]
visited = [i]
while len(stack)!=0:
r = stack.pop()
for j in g[r]:
if j not in visited:
visited.append(j)
stack.append(j)
visited = sorted(visited)
if visited not in ma:
ma.append(visited)
print(len(ma)-1)
| Title: Learning Languages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.
Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages.
Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next, the *i*-th line contains *k**i* integers — *a**ij* (1<=≤<=*a**ij*<=≤<=*m*) — the identifiers of languages the *i*-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.
The numbers in the lines are separated by single spaces.
Output Specification:
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
Demo Input:
['5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n', '8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n', '2 2\n1 2\n0\n']
Demo Output:
['0\n', '2\n', '1\n']
Note:
In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | ```python
n,m = map(int,input().split())
lang = [set(list(map(int,input().split()))[1:]) for _ in range(n)]
g = {}
for i,e in enumerate(lang):
g[i] = []
if len(e)!=0:
for j,o in enumerate(lang):
if i!=j and len(o)!=0:
if len(e&o)!=0:
g[i].append(j)
ma = []
for i in range(n):
stack = [i]
visited = [i]
while len(stack)!=0:
r = stack.pop()
for j in g[r]:
if j not in visited:
visited.append(j)
stack.append(j)
visited = sorted(visited)
if visited not in ma:
ma.append(visited)
print(len(ma)-1)
``` | 0 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,580,890,989 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 124 | 0 | x=input()
y=input()
res=""
for i in range (len(x)):
res=(int(x[i]) ^ int(y[i]))
print(res,end="") | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
x=input()
y=input()
res=""
for i in range (len(x)):
res=(int(x[i]) ^ int(y[i]))
print(res,end="")
``` | 3.969 |
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions. | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2. | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "4\n4 1 3 2",
"output": "3"
},
{
"input": "5\n1 4 5 2 3",
"output": "4"
},
{
"input": "6\n4 6 3 5 2 1",
"output": "5"
},
{
"input": "7\n1 5 3 6 2 4 7",
"output": "6"
},
{
"input": "100\n76 70 67 54 40 1 48 63 64 36 42 90 99 27 47 17 93 7 13 84 16 57 74 5 83 61 19 56 52 92 38 91 82 79 34 66 71 28 37 98 35 94 77 53 73 10 26 80 15 32 8 81 3 95 44 46 72 6 33 11 21 85 4 30 24 51 49 96 87 55 14 31 12 60 45 9 29 22 58 18 88 2 50 59 20 86 23 41 100 39 62 68 69 97 78 43 25 89 65 75",
"output": "94"
},
{
"input": "8\n4 5 3 8 6 7 1 2",
"output": "6"
},
{
"input": "9\n6 8 5 3 4 7 9 2 1",
"output": "8"
},
{
"input": "10\n8 7 10 1 2 3 4 6 5 9",
"output": "7"
},
{
"input": "11\n5 4 6 9 10 11 7 3 1 2 8",
"output": "8"
},
{
"input": "12\n3 6 7 8 9 10 12 5 4 2 11 1",
"output": "11"
},
{
"input": "13\n8 4 3 7 5 11 9 1 10 2 13 12 6",
"output": "10"
},
{
"input": "14\n6 10 13 9 7 1 12 14 3 2 5 4 11 8",
"output": "8"
},
{
"input": "15\n3 14 13 12 7 2 4 11 15 1 8 6 5 10 9",
"output": "9"
},
{
"input": "16\n11 6 9 8 7 14 12 13 10 15 2 5 3 1 4 16",
"output": "15"
},
{
"input": "17\n13 12 5 3 9 16 8 14 2 4 10 1 6 11 7 15 17",
"output": "16"
},
{
"input": "18\n8 6 14 17 9 11 15 13 5 3 18 1 2 7 12 16 4 10",
"output": "11"
},
{
"input": "19\n12 19 3 11 15 6 18 14 5 10 2 13 9 7 4 8 17 16 1",
"output": "18"
},
{
"input": "20\n15 17 10 20 7 2 16 9 13 6 18 5 19 8 11 14 4 12 3 1",
"output": "19"
},
{
"input": "21\n1 9 14 18 13 12 11 20 16 2 4 19 15 7 6 17 8 5 3 10 21",
"output": "20"
},
{
"input": "22\n8 3 17 4 16 21 14 11 10 15 6 18 13 12 22 20 5 2 9 7 19 1",
"output": "21"
},
{
"input": "23\n1 23 11 20 9 3 12 4 7 17 5 15 2 10 18 16 8 22 14 13 19 21 6",
"output": "22"
},
{
"input": "24\n2 10 23 22 20 19 18 16 11 12 15 17 21 8 24 13 1 5 6 7 14 3 9 4",
"output": "16"
},
{
"input": "25\n12 13 22 17 1 18 14 5 21 2 10 4 3 23 11 6 20 8 24 16 15 19 9 7 25",
"output": "24"
},
{
"input": "26\n6 21 20 16 26 17 11 2 24 4 1 12 14 8 25 7 15 10 22 5 13 18 9 23 19 3",
"output": "21"
},
{
"input": "27\n20 14 18 10 5 3 9 4 24 22 21 27 17 15 26 2 23 7 12 11 6 8 19 25 16 13 1",
"output": "26"
},
{
"input": "28\n28 13 16 6 1 12 4 27 22 7 18 3 21 26 25 11 5 10 20 24 19 15 14 8 23 17 9 2",
"output": "27"
},
{
"input": "29\n21 11 10 25 2 5 9 16 29 8 17 4 15 13 6 22 7 24 19 12 18 20 1 3 23 28 27 14 26",
"output": "22"
},
{
"input": "30\n6 19 14 22 26 17 27 8 25 3 24 30 4 18 23 16 9 13 29 20 15 2 5 11 28 12 1 10 21 7",
"output": "26"
},
{
"input": "31\n29 13 26 27 9 28 2 16 30 21 12 11 3 31 23 6 22 20 1 5 14 24 19 18 8 4 10 17 15 25 7",
"output": "18"
},
{
"input": "32\n15 32 11 3 18 23 19 14 5 8 6 21 13 24 25 4 16 9 27 20 17 31 2 22 7 12 30 1 26 10 29 28",
"output": "30"
},
{
"input": "33\n22 13 10 33 8 25 15 14 21 28 27 19 26 24 1 12 5 11 32 20 30 31 18 4 6 23 7 29 16 2 17 9 3",
"output": "29"
},
{
"input": "34\n34 30 7 16 6 1 10 23 29 13 15 25 32 26 18 11 28 3 14 21 19 5 31 33 4 17 8 9 24 20 27 22 2 12",
"output": "33"
},
{
"input": "35\n24 33 20 8 34 11 31 25 2 4 18 13 9 35 16 30 23 32 17 1 14 22 19 21 28 26 3 15 5 12 27 29 10 6 7",
"output": "21"
},
{
"input": "36\n1 32 27 35 22 7 34 15 18 36 31 28 13 2 10 21 20 17 16 4 3 24 19 29 11 12 25 5 33 26 14 6 9 23 30 8",
"output": "35"
},
{
"input": "37\n24 1 12 23 11 6 30 15 4 21 13 20 25 17 5 8 36 19 32 26 14 9 7 18 10 29 37 35 16 2 22 34 3 27 31 33 28",
"output": "35"
},
{
"input": "38\n9 35 37 28 36 21 10 25 19 4 26 5 22 7 27 18 6 14 15 24 1 17 11 34 20 8 2 16 3 23 32 31 13 12 38 33 30 29",
"output": "34"
},
{
"input": "39\n16 28 4 33 26 36 25 23 22 30 27 7 12 34 17 6 3 38 10 24 13 31 29 39 14 32 9 20 35 11 18 21 8 2 15 37 5 19 1",
"output": "38"
},
{
"input": "40\n35 39 28 11 9 31 36 8 5 32 26 19 38 33 2 22 23 25 6 37 12 7 3 10 17 24 20 16 27 4 34 15 40 14 18 13 29 21 30 1",
"output": "39"
},
{
"input": "41\n24 18 7 23 3 15 1 17 25 5 30 10 34 36 2 14 9 21 41 40 20 28 33 35 12 22 11 8 19 16 31 27 26 32 29 4 13 38 37 39 6",
"output": "34"
},
{
"input": "42\n42 15 24 26 4 34 19 29 38 32 31 33 14 41 21 3 11 39 25 6 5 20 23 10 16 36 18 28 27 1 7 40 22 30 9 2 37 17 8 12 13 35",
"output": "41"
},
{
"input": "43\n43 24 20 13 22 29 28 4 30 3 32 40 31 8 7 9 35 27 18 5 42 6 17 19 23 12 41 21 16 37 33 34 2 14 36 38 25 10 15 39 26 11 1",
"output": "42"
},
{
"input": "44\n4 38 6 40 29 3 44 2 30 35 25 36 34 10 11 31 21 7 14 23 37 19 27 18 5 22 1 16 17 9 39 13 15 32 43 8 41 26 42 12 24 33 20 28",
"output": "37"
},
{
"input": "45\n45 29 24 2 31 5 34 41 26 44 33 43 15 3 4 11 21 37 27 12 14 39 23 42 16 6 13 19 8 38 20 9 25 22 40 17 32 35 18 10 28 7 30 36 1",
"output": "44"
},
{
"input": "46\n29 3 12 33 45 40 19 17 25 27 28 1 16 23 24 46 31 8 44 15 5 32 22 11 4 36 34 10 35 26 21 7 14 2 18 9 20 41 6 43 42 37 38 13 39 30",
"output": "34"
},
{
"input": "47\n7 3 8 12 24 16 29 10 28 38 1 20 37 40 21 5 15 6 45 23 36 44 25 43 41 4 11 42 18 35 32 31 39 33 27 30 22 34 14 13 17 47 19 9 46 26 2",
"output": "41"
},
{
"input": "48\n29 26 14 18 34 33 13 39 32 1 37 20 35 19 28 48 30 23 46 27 5 22 24 38 12 15 8 36 43 45 16 47 6 9 31 40 44 17 2 41 11 42 25 4 21 3 10 7",
"output": "38"
},
{
"input": "49\n16 7 42 32 11 35 15 8 23 41 6 20 47 24 9 45 49 2 37 48 25 28 5 18 3 19 12 4 22 33 13 14 10 36 44 17 40 38 30 26 1 43 29 46 21 34 27 39 31",
"output": "40"
},
{
"input": "50\n31 45 3 34 13 43 32 4 42 9 7 8 24 14 35 6 19 46 44 17 18 1 25 20 27 41 2 16 12 10 11 47 38 21 28 49 30 15 50 36 29 26 22 39 48 5 23 37 33 40",
"output": "38"
},
{
"input": "51\n47 29 2 11 43 44 27 1 39 14 25 30 33 21 38 45 34 51 16 50 42 31 41 46 15 48 13 19 6 37 35 7 22 28 20 4 17 10 5 8 24 40 9 36 18 49 12 26 23 3 32",
"output": "43"
},
{
"input": "52\n16 45 23 7 15 19 43 20 4 32 35 36 9 50 5 26 38 46 13 33 12 2 48 37 41 31 10 28 8 42 3 21 11 1 17 27 34 30 44 40 6 51 49 47 25 22 18 24 52 29 14 39",
"output": "48"
},
{
"input": "53\n53 30 50 22 51 31 32 38 12 7 39 43 1 23 6 8 24 52 2 21 34 13 3 35 5 15 19 11 47 18 9 20 29 4 36 45 27 41 25 48 16 46 44 17 10 14 42 26 40 28 33 37 49",
"output": "52"
},
{
"input": "54\n6 39 17 3 45 52 16 21 23 48 42 36 13 37 46 10 43 27 49 7 38 32 31 30 15 25 2 29 8 51 54 19 41 44 24 34 22 5 20 14 12 1 33 40 4 26 9 35 18 28 47 50 11 53",
"output": "41"
},
{
"input": "55\n26 15 31 21 32 43 34 51 7 12 5 44 17 54 18 25 48 47 20 3 41 24 45 2 11 22 29 39 37 53 35 28 36 9 50 10 30 38 19 13 4 8 27 1 42 6 49 23 55 40 33 16 46 14 52",
"output": "48"
},
{
"input": "56\n6 20 38 46 10 11 40 19 5 1 47 33 4 18 32 36 37 45 56 49 48 52 12 26 31 14 2 9 24 3 16 51 41 43 23 17 34 7 29 50 55 25 39 44 22 27 54 8 28 35 30 42 13 53 21 15",
"output": "46"
},
{
"input": "57\n39 28 53 36 3 6 12 56 55 20 50 19 43 42 18 40 24 52 38 17 33 23 22 41 14 7 26 44 45 16 35 1 8 47 31 5 30 51 32 4 37 25 13 34 54 21 46 10 15 11 2 27 29 48 49 9 57",
"output": "56"
},
{
"input": "58\n1 26 28 14 22 33 57 40 9 42 44 37 24 19 58 12 48 3 34 31 49 4 16 47 55 52 27 23 46 18 20 32 56 6 39 36 41 38 13 43 45 21 53 54 29 17 5 10 25 30 2 35 11 7 15 51 8 50",
"output": "57"
},
{
"input": "59\n1 27 10 37 53 9 14 49 46 26 50 42 59 11 47 15 24 56 43 45 44 38 5 8 58 30 52 12 23 32 22 3 31 41 2 25 29 6 54 16 35 33 18 55 4 51 57 28 40 19 13 21 7 39 36 48 34 17 20",
"output": "58"
},
{
"input": "60\n60 27 34 32 54 55 33 12 40 3 47 44 50 39 38 59 11 25 17 15 16 30 21 31 10 52 5 23 4 48 6 26 36 57 14 22 8 56 58 9 24 7 37 53 42 43 20 49 51 19 2 46 28 18 35 13 29 45 41 1",
"output": "59"
},
{
"input": "61\n61 11 26 29 31 40 32 30 35 3 18 52 9 53 42 4 50 54 20 58 28 49 22 12 2 19 16 15 57 34 51 43 7 17 25 41 56 47 55 60 46 14 44 45 24 27 33 1 48 13 59 23 38 39 6 5 36 10 8 37 21",
"output": "60"
},
{
"input": "62\n21 23 34 38 11 61 55 30 37 48 54 51 46 47 6 56 36 49 1 35 12 28 29 20 43 42 5 8 22 57 44 4 53 10 58 33 27 25 16 45 50 40 18 15 3 41 39 2 7 60 59 13 32 24 52 31 14 9 19 26 17 62",
"output": "61"
},
{
"input": "63\n2 5 29 48 31 26 21 16 47 24 43 22 61 28 6 39 60 27 14 52 37 7 53 8 62 56 63 10 50 18 44 13 4 9 25 11 23 42 45 41 59 12 32 36 40 51 1 35 49 54 57 20 19 34 38 46 33 3 55 15 30 58 17",
"output": "46"
},
{
"input": "64\n23 5 51 40 12 46 44 8 64 31 58 55 45 24 54 39 21 19 52 61 30 42 16 18 15 32 53 22 28 26 11 25 48 56 27 9 29 41 35 49 59 38 62 7 34 1 20 33 60 17 2 3 43 37 57 14 6 36 13 10 50 4 63 47",
"output": "55"
},
{
"input": "65\n10 11 55 43 53 25 35 26 16 37 41 38 59 21 48 2 65 49 17 23 18 30 62 36 3 4 47 15 28 63 57 54 31 46 44 12 51 7 29 13 56 52 14 22 39 19 8 27 45 5 6 34 32 61 20 50 9 24 33 58 60 40 1 42 64",
"output": "62"
},
{
"input": "66\n66 39 3 2 55 53 60 54 12 49 10 30 59 26 32 46 50 56 7 13 43 36 24 28 11 8 6 21 35 25 42 57 23 45 64 5 34 61 27 51 52 9 15 1 38 17 63 48 37 20 58 14 47 19 22 41 31 44 33 65 4 62 40 18 16 29",
"output": "65"
},
{
"input": "67\n66 16 2 53 35 38 49 28 18 6 36 58 21 47 27 5 50 62 44 12 52 37 11 56 15 31 25 65 17 29 59 41 7 42 4 43 39 10 1 40 24 13 20 54 19 67 46 60 51 45 64 30 8 33 26 9 3 22 34 23 57 48 55 14 63 61 32",
"output": "45"
},
{
"input": "68\n13 6 27 21 65 23 59 14 62 43 33 31 38 41 67 20 16 25 42 4 28 40 29 9 64 17 2 26 32 58 60 53 46 48 47 54 44 50 39 19 30 57 61 1 11 18 37 24 55 15 63 34 8 52 56 7 10 12 35 66 5 36 45 49 68 22 51 3",
"output": "64"
},
{
"input": "69\n29 49 25 51 21 35 11 61 39 54 40 37 60 42 27 33 59 53 34 10 46 2 23 69 8 47 58 36 1 38 19 12 7 48 13 3 6 22 18 5 65 24 50 41 66 44 67 57 4 56 62 43 9 30 14 15 28 31 64 26 16 55 68 17 32 20 45 52 63",
"output": "45"
},
{
"input": "70\n19 12 15 18 36 16 61 69 24 7 11 13 3 48 55 21 37 17 43 31 41 22 28 32 27 63 38 49 59 56 30 25 67 51 52 45 50 44 66 57 26 60 5 46 33 6 23 34 8 40 2 68 14 39 65 64 62 42 47 54 10 53 9 1 70 58 20 4 29 35",
"output": "64"
},
{
"input": "71\n40 6 62 3 41 52 31 66 27 16 35 5 17 60 2 15 51 22 67 61 71 53 1 64 8 45 28 18 50 30 12 69 20 26 10 37 36 49 70 32 33 11 57 14 9 55 4 58 29 25 44 65 39 48 24 47 19 46 56 38 34 42 59 63 54 23 7 68 43 13 21",
"output": "50"
},
{
"input": "72\n52 64 71 40 32 10 62 21 11 37 38 13 22 70 1 66 41 50 27 20 42 47 25 68 49 12 15 72 44 60 53 5 23 14 43 29 65 36 51 54 35 67 7 19 55 48 58 46 39 24 33 30 61 45 57 2 31 3 18 59 6 9 4 63 8 16 26 34 28 69 17 56",
"output": "57"
},
{
"input": "73\n58 38 47 34 39 64 69 66 72 57 9 4 67 22 35 13 61 14 28 52 56 20 31 70 27 24 36 1 62 17 10 5 12 33 16 73 18 49 63 71 44 65 23 30 40 8 50 46 60 25 11 26 37 55 29 68 42 2 3 32 59 7 15 43 41 48 51 53 6 45 54 19 21",
"output": "45"
},
{
"input": "74\n19 51 59 34 8 40 42 55 65 16 74 26 49 63 64 70 35 72 7 12 43 18 61 27 47 31 13 32 71 22 25 67 9 1 48 50 33 10 21 46 11 45 17 37 28 60 69 66 38 2 30 3 39 15 53 68 57 41 6 36 24 73 4 23 5 62 44 14 20 29 52 54 56 58",
"output": "63"
},
{
"input": "75\n75 28 60 19 59 17 65 26 32 23 18 64 8 62 4 11 42 16 47 5 72 46 9 1 25 21 2 50 33 6 36 68 30 12 20 40 53 45 34 7 37 39 38 44 63 61 67 3 66 51 29 73 24 57 70 27 10 56 22 55 13 49 35 15 54 41 14 74 69 48 52 31 71 43 58",
"output": "74"
},
{
"input": "76\n1 47 54 17 38 37 12 32 14 48 43 71 60 56 4 13 64 41 52 57 62 24 23 49 20 10 63 3 25 66 59 40 58 33 53 46 70 7 35 61 72 74 73 19 30 5 29 6 15 28 21 27 51 55 50 9 65 8 67 39 76 42 31 34 16 2 36 11 26 44 22 45 75 18 69 68",
"output": "75"
},
{
"input": "77\n10 20 57 65 53 69 59 45 58 32 28 72 4 14 1 33 40 47 7 5 51 76 37 16 41 61 42 2 21 26 38 74 35 64 43 77 71 50 39 48 27 63 73 44 52 66 9 18 23 54 25 6 8 56 13 67 36 22 15 46 62 75 55 11 31 17 24 29 60 68 12 30 3 70 49 19 34",
"output": "62"
},
{
"input": "78\n7 61 69 47 68 42 65 78 70 3 32 59 49 51 23 71 11 63 22 18 43 34 24 13 27 16 19 40 21 46 48 77 28 66 54 67 60 15 75 62 9 26 52 58 4 25 8 37 41 76 1 6 30 50 44 36 5 14 29 53 17 12 2 57 73 35 64 39 56 10 33 20 45 74 31 55 38 72",
"output": "70"
},
{
"input": "79\n75 79 43 66 72 52 29 65 74 38 24 1 5 51 13 7 71 33 4 61 2 36 63 47 64 44 34 27 3 21 17 37 54 53 49 20 28 60 39 10 16 76 6 77 73 22 50 48 78 30 67 56 31 26 40 59 41 11 18 45 69 62 15 23 32 70 19 55 68 57 35 25 12 46 14 42 9 8 58",
"output": "77"
},
{
"input": "80\n51 20 37 12 68 11 28 52 76 21 7 5 3 16 64 34 25 2 6 40 60 62 75 13 45 17 56 29 32 47 79 73 49 72 15 46 30 54 80 27 43 24 74 18 42 71 14 4 44 63 65 33 1 77 55 57 41 59 58 70 69 35 19 67 10 36 26 23 48 50 39 61 9 66 38 8 31 22 53 78",
"output": "52"
},
{
"input": "81\n63 22 4 41 43 74 64 39 10 35 20 81 11 28 70 67 53 79 16 61 68 52 27 37 58 9 50 49 18 30 72 47 7 60 78 51 23 48 73 66 44 13 15 57 56 38 1 76 25 45 36 34 42 8 75 26 59 14 71 21 6 77 5 17 2 32 40 54 46 24 29 3 31 19 65 62 33 69 12 80 55",
"output": "69"
},
{
"input": "82\n50 24 17 41 49 18 80 11 79 72 57 31 21 35 2 51 36 66 20 65 38 3 45 32 59 81 28 30 70 55 29 76 73 6 33 39 8 7 19 48 63 1 77 43 4 13 78 54 69 9 40 46 74 82 60 71 16 64 12 14 47 26 44 5 10 75 53 25 27 15 56 42 58 34 23 61 67 62 68 22 37 52",
"output": "53"
},
{
"input": "83\n64 8 58 17 67 46 3 82 23 70 72 16 53 45 13 20 12 48 40 4 6 47 76 60 19 44 30 78 28 22 75 15 25 29 63 74 55 32 14 51 35 31 62 77 27 42 65 71 56 61 66 41 68 49 7 34 2 83 36 5 33 26 37 80 59 50 1 9 54 21 18 24 38 73 81 52 10 39 43 79 57 11 69",
"output": "66"
},
{
"input": "84\n75 8 66 21 61 63 72 51 52 13 59 25 28 58 64 53 79 41 34 7 67 11 39 56 44 24 50 9 49 55 1 80 26 6 73 74 27 69 65 37 18 43 36 17 30 3 47 29 76 78 32 22 12 68 46 5 42 81 57 31 33 83 54 48 14 62 10 16 4 20 71 70 35 15 45 19 60 77 2 23 84 40 82 38",
"output": "80"
},
{
"input": "85\n1 18 58 8 22 76 3 61 12 33 54 41 6 24 82 15 10 17 38 64 26 4 62 28 47 14 66 9 84 75 2 71 67 43 37 32 85 21 69 52 55 63 81 51 74 59 65 34 29 36 30 45 27 53 13 79 39 57 5 70 19 40 7 42 68 48 16 80 83 23 46 35 72 31 11 44 73 77 50 56 49 25 60 20 78",
"output": "84"
},
{
"input": "86\n64 56 41 10 31 69 47 39 37 36 27 19 9 42 15 6 78 59 52 17 71 45 72 14 2 54 38 79 4 18 16 8 46 75 50 82 44 24 20 55 58 86 61 43 35 32 33 40 63 30 28 60 13 53 12 57 77 81 76 66 73 84 85 62 68 22 51 5 49 7 1 70 80 65 34 48 23 21 83 11 74 26 29 67 25 3",
"output": "70"
},
{
"input": "87\n14 20 82 47 39 75 71 45 3 37 63 19 32 68 7 41 48 76 27 46 84 49 4 44 26 69 17 64 1 18 58 33 11 23 21 86 67 52 70 16 77 78 6 74 15 87 10 59 13 34 22 2 65 38 66 61 51 57 35 60 81 40 36 80 31 43 83 56 79 55 29 5 12 8 50 30 53 72 54 9 24 25 42 62 73 28 85",
"output": "58"
},
{
"input": "88\n1 83 73 46 61 31 39 86 57 43 16 29 26 80 82 7 36 42 13 20 6 64 19 40 24 12 47 87 8 34 75 9 69 3 11 52 14 25 84 59 27 10 54 51 81 74 65 77 70 17 60 35 23 44 49 2 4 88 5 21 41 32 68 66 15 55 48 58 78 53 22 38 45 33 30 50 85 76 37 79 63 18 28 62 72 56 71 67",
"output": "87"
},
{
"input": "89\n68 40 14 58 56 25 8 44 49 55 9 76 66 54 33 81 42 15 59 17 21 30 75 60 4 48 64 6 52 63 61 27 12 57 72 67 23 86 77 80 22 13 43 73 26 78 50 51 18 62 1 29 82 16 74 2 87 24 3 41 11 46 47 69 10 84 65 39 35 79 70 32 34 31 20 19 53 71 36 28 83 88 38 85 7 5 37 45 89",
"output": "88"
},
{
"input": "90\n2 67 26 58 9 49 76 22 60 30 77 20 13 7 37 81 47 16 19 12 14 45 41 68 85 54 28 24 46 1 27 43 32 89 53 35 59 75 18 51 17 64 66 80 31 88 87 90 38 72 55 71 42 11 73 69 62 78 23 74 65 79 84 4 86 52 10 6 3 82 56 5 48 33 21 57 40 29 61 63 34 36 83 8 15 44 50 70 39 25",
"output": "60"
},
{
"input": "91\n91 69 56 16 73 55 14 82 80 46 57 81 22 71 63 76 43 37 77 75 70 3 26 2 28 17 51 38 30 67 41 47 54 62 34 25 84 11 87 39 32 52 31 36 50 19 21 53 29 24 79 8 74 64 44 7 6 18 10 42 13 9 83 58 4 88 65 60 20 90 66 49 86 89 78 48 5 27 23 59 61 15 72 45 40 33 68 85 35 12 1",
"output": "90"
},
{
"input": "92\n67 57 76 78 25 89 6 82 11 16 26 17 59 48 73 10 21 31 27 80 4 5 22 13 92 55 45 85 63 28 75 60 54 88 91 47 29 35 7 87 1 39 43 51 71 84 83 81 46 9 38 56 90 24 37 41 19 86 50 61 79 20 18 14 69 23 62 65 49 52 58 53 36 2 68 64 15 42 30 34 66 32 44 40 8 33 3 77 74 12 70 72",
"output": "67"
},
{
"input": "93\n76 35 5 87 7 21 59 71 24 37 2 73 31 74 4 52 28 20 56 27 65 86 16 45 85 67 68 70 47 72 91 88 14 32 62 69 78 41 15 22 57 18 50 13 39 58 17 83 64 51 25 11 38 77 82 90 8 26 29 61 10 43 79 53 48 6 23 55 63 49 81 92 80 44 89 60 66 30 1 9 36 33 19 46 75 93 3 12 42 84 40 54 34",
"output": "85"
},
{
"input": "94\n29 85 82 78 61 83 80 63 11 38 50 43 9 24 4 87 79 45 3 17 90 7 34 27 1 76 26 39 84 47 22 41 81 19 44 23 56 92 35 31 72 62 70 53 40 88 13 14 73 2 59 86 46 94 15 12 77 57 89 42 75 48 18 51 32 55 71 30 49 91 20 60 5 93 33 64 21 36 10 28 8 65 66 69 74 58 6 52 25 67 16 37 54 68",
"output": "69"
},
{
"input": "95\n36 73 18 77 15 71 50 57 79 65 94 88 9 69 52 70 26 66 78 89 55 20 72 83 75 68 32 28 45 74 19 22 54 23 84 90 86 12 42 58 11 81 39 31 85 47 60 44 59 43 21 7 30 41 64 76 93 46 87 48 10 40 3 14 38 49 29 35 2 67 5 34 13 37 27 56 91 17 62 80 8 61 53 95 24 92 6 82 63 33 51 25 4 16 1",
"output": "94"
},
{
"input": "96\n64 3 47 83 19 10 72 61 73 95 16 40 54 84 8 86 28 4 37 42 92 48 63 76 67 1 59 66 20 35 93 2 43 7 45 70 34 33 26 91 85 89 13 29 58 68 44 25 87 75 49 71 41 17 55 36 32 31 74 22 52 79 30 88 50 78 38 39 65 27 69 77 81 94 82 53 21 80 57 60 24 46 51 9 18 15 96 62 6 23 11 12 90 5 14 56",
"output": "86"
},
{
"input": "97\n40 63 44 64 84 92 38 41 28 91 3 70 76 67 94 96 35 79 29 22 78 88 85 8 21 1 93 54 71 80 37 17 13 26 62 59 75 87 69 33 89 49 77 61 12 39 6 36 58 18 73 50 82 45 74 52 11 34 95 7 23 30 15 32 31 16 55 19 20 83 60 72 10 53 51 14 27 9 68 47 5 2 81 46 57 86 56 43 48 66 24 25 4 42 65 97 90",
"output": "95"
},
{
"input": "98\n85 94 69 86 22 52 27 79 53 91 35 55 33 88 8 75 76 95 64 54 67 30 70 49 6 16 2 48 80 32 25 90 98 46 9 96 36 81 10 92 28 11 37 97 15 41 38 40 83 44 29 47 23 3 31 61 87 39 78 20 68 12 17 73 59 18 77 72 43 51 84 24 89 65 26 7 74 93 21 19 5 14 50 42 82 71 60 56 34 62 58 57 45 66 13 63 4 1",
"output": "97"
},
{
"input": "99\n33 48 19 41 59 64 16 12 17 13 7 1 9 6 4 92 61 49 60 25 74 65 22 97 30 32 10 62 14 55 80 66 82 78 31 23 87 93 27 98 20 29 88 84 77 34 83 96 79 90 56 89 58 72 52 47 21 76 24 70 44 94 5 39 8 18 57 36 40 68 43 75 3 2 35 99 63 26 67 73 15 11 53 28 42 46 69 50 51 95 38 37 54 85 81 91 45 86 71",
"output": "87"
},
{
"input": "100\n28 30 77 4 81 67 31 25 66 56 88 73 83 51 57 34 21 90 38 76 22 99 53 70 91 3 64 54 6 94 8 5 97 80 50 45 61 40 16 95 36 98 9 2 17 44 72 55 18 58 47 12 87 24 7 32 14 23 65 41 63 48 62 39 92 27 43 19 46 13 42 52 96 84 26 69 100 79 93 49 35 60 71 59 68 15 10 29 20 1 78 33 75 86 11 85 74 82 89 37",
"output": "89"
},
{
"input": "100\n100 97 35 55 45 3 46 98 77 64 94 85 73 43 49 79 72 9 70 62 80 88 29 58 61 20 89 83 66 86 82 15 6 87 42 96 90 75 63 38 81 40 5 23 4 18 41 19 99 60 8 12 76 51 39 93 53 26 21 50 47 28 13 30 68 59 34 54 24 56 31 27 65 16 32 10 36 52 44 91 22 14 33 25 7 78 67 17 57 37 92 11 2 69 84 95 74 71 48 1",
"output": "99"
},
{
"input": "100\n83 96 73 70 30 25 7 77 58 89 76 85 49 82 45 51 14 62 50 9 31 32 16 15 97 64 4 37 20 93 24 10 80 71 100 39 75 72 78 74 8 29 53 86 79 48 3 68 90 99 56 87 63 94 36 1 40 65 6 44 43 84 17 52 34 95 38 47 60 57 98 59 33 41 46 81 23 27 19 2 54 91 55 35 26 12 92 18 28 66 69 21 5 67 13 11 22 88 61 42",
"output": "65"
},
{
"input": "100\n96 80 47 60 56 9 78 20 37 72 68 15 100 94 51 26 65 38 50 19 4 70 25 63 22 30 13 58 43 69 18 33 5 66 39 73 12 55 95 92 97 1 14 83 10 28 64 31 46 91 32 86 74 54 29 52 89 53 90 44 62 40 16 24 67 81 36 34 7 23 79 87 75 98 84 3 41 77 76 42 71 35 49 61 2 27 59 82 99 85 21 11 45 6 88 48 17 57 8 93",
"output": "87"
},
{
"input": "100\n5 6 88 37 97 51 25 81 54 17 57 98 99 44 67 24 30 93 100 36 8 38 84 42 21 4 75 31 85 48 70 77 43 50 65 94 29 32 68 86 56 39 69 47 20 60 52 53 10 34 79 2 95 40 89 64 71 26 22 46 1 62 91 76 83 41 9 78 16 63 13 3 28 92 27 49 7 12 96 72 80 23 14 19 18 66 59 87 90 45 73 82 33 74 35 61 55 15 58 11",
"output": "81"
},
{
"input": "100\n100 97 92 12 62 17 19 58 37 26 30 95 31 35 87 10 13 43 98 61 28 89 76 1 23 21 11 22 50 56 91 74 3 24 96 55 64 67 14 4 71 16 18 9 77 68 51 81 32 82 46 88 86 60 29 66 72 85 70 7 53 63 33 45 83 2 25 94 52 93 5 69 20 47 49 54 57 39 34 27 90 80 78 59 40 42 79 6 38 8 48 15 65 73 99 44 41 84 36 75",
"output": "99"
},
{
"input": "100\n22 47 34 65 69 5 68 78 53 54 41 23 80 51 11 8 2 85 81 75 25 58 29 73 30 49 10 71 17 96 76 89 79 20 12 15 55 7 46 32 19 3 82 35 74 44 38 40 92 14 6 50 97 63 45 93 37 18 62 77 87 36 83 9 90 61 57 28 39 43 52 42 24 56 21 84 26 99 88 59 33 70 4 60 98 95 94 100 13 48 66 72 16 31 64 91 1 86 27 67",
"output": "96"
},
{
"input": "100\n41 67 94 18 14 83 59 12 19 54 13 68 75 26 15 65 80 40 23 30 34 78 47 21 63 79 4 70 3 31 86 69 92 10 61 74 97 100 9 99 32 27 91 55 85 52 16 17 28 1 64 29 58 76 98 25 84 7 2 96 20 72 36 46 49 82 93 44 45 6 38 87 57 50 53 35 60 33 8 89 39 42 37 48 62 81 73 43 95 11 66 88 90 22 24 77 71 51 5 56",
"output": "62"
},
{
"input": "100\n1 88 38 56 62 99 39 80 12 33 57 24 28 84 37 42 10 95 83 58 8 40 20 2 30 78 60 79 36 71 51 31 27 65 22 47 6 19 61 94 75 4 74 35 15 23 92 9 70 13 11 59 90 18 66 81 64 72 16 32 34 67 46 91 21 87 77 97 82 41 7 86 26 43 45 3 93 17 52 96 50 63 48 5 53 44 29 25 98 54 49 14 73 69 89 55 76 85 68 100",
"output": "99"
},
{
"input": "100\n22 59 25 77 68 79 32 45 20 28 61 60 38 86 33 10 100 15 53 75 78 39 67 13 66 34 96 4 63 23 73 29 31 35 71 55 16 14 72 56 94 97 17 93 47 84 57 8 21 51 54 85 26 76 49 81 2 92 62 44 91 87 11 24 95 69 5 7 99 6 65 48 70 12 41 18 74 27 42 3 80 30 50 98 58 37 82 89 83 36 40 52 19 9 88 46 43 1 90 64",
"output": "97"
},
{
"input": "100\n12 1 76 78 97 82 59 80 48 8 91 51 54 74 16 10 89 99 83 63 93 90 55 25 30 33 29 6 9 65 92 79 44 39 15 58 37 46 32 19 27 3 75 49 62 71 98 42 69 50 26 81 96 5 7 61 60 21 20 36 18 34 40 4 47 85 64 38 22 84 2 68 11 56 31 66 17 14 95 43 53 35 23 52 70 13 72 45 41 77 73 87 88 94 28 86 24 67 100 57",
"output": "98"
},
{
"input": "100\n66 100 53 88 7 73 54 41 31 42 8 46 65 90 78 14 94 30 79 39 89 5 83 50 38 61 37 86 22 95 60 98 34 57 91 10 75 25 15 43 23 17 96 35 93 48 87 47 56 13 19 9 82 62 67 80 11 55 99 70 18 26 58 85 12 44 16 45 4 49 20 71 92 24 81 2 76 32 6 21 84 36 52 97 59 63 40 51 27 64 68 3 77 72 28 33 29 1 74 69",
"output": "98"
},
{
"input": "100\n56 64 1 95 72 39 9 49 87 29 94 7 32 6 30 48 50 25 31 78 90 45 60 44 80 68 17 20 73 15 75 98 83 13 71 22 36 26 96 88 35 3 85 54 16 41 92 99 69 86 93 33 43 62 77 46 47 37 12 10 18 40 27 4 63 55 28 59 23 34 61 53 76 42 51 91 21 70 8 58 38 19 5 66 84 11 52 24 81 82 79 67 97 65 57 74 2 89 100 14",
"output": "98"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "3\n1 3 2",
"output": "2"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "3\n3 1 2",
"output": "2"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "4\n1 2 3 4",
"output": "3"
},
{
"input": "4\n1 2 4 3",
"output": "3"
},
{
"input": "4\n1 3 2 4",
"output": "3"
},
{
"input": "4\n1 3 4 2",
"output": "3"
},
{
"input": "4\n1 4 2 3",
"output": "3"
},
{
"input": "4\n1 4 3 2",
"output": "3"
},
{
"input": "4\n2 1 3 4",
"output": "3"
},
{
"input": "4\n2 1 4 3",
"output": "2"
},
{
"input": "4\n2 4 1 3",
"output": "2"
},
{
"input": "4\n2 4 3 1",
"output": "3"
},
{
"input": "4\n3 1 2 4",
"output": "3"
},
{
"input": "4\n3 1 4 2",
"output": "2"
},
{
"input": "4\n3 2 1 4",
"output": "3"
},
{
"input": "4\n3 2 4 1",
"output": "3"
},
{
"input": "4\n3 4 1 2",
"output": "2"
},
{
"input": "4\n3 4 2 1",
"output": "3"
},
{
"input": "4\n4 1 2 3",
"output": "3"
},
{
"input": "4\n4 1 3 2",
"output": "3"
},
{
"input": "4\n4 2 1 3",
"output": "3"
},
{
"input": "4\n4 2 3 1",
"output": "3"
},
{
"input": "4\n4 3 1 2",
"output": "3"
},
{
"input": "4\n4 3 2 1",
"output": "3"
},
{
"input": "8\n2 5 6 4 8 3 1 7",
"output": "6"
},
{
"input": "5\n2 3 1 5 4",
"output": "3"
},
{
"input": "6\n2 5 3 6 4 1",
"output": "5"
},
{
"input": "6\n5 4 2 6 1 3",
"output": "4"
},
{
"input": "6\n4 2 3 1 6 5",
"output": "4"
},
{
"input": "6\n5 4 2 1 6 3",
"output": "4"
},
{
"input": "9\n7 2 3 4 5 6 1 9 8",
"output": "7"
},
{
"input": "6\n3 2 1 4 6 5",
"output": "4"
},
{
"input": "6\n2 3 4 1 6 5",
"output": "4"
},
{
"input": "10\n5 2 3 4 1 6 7 8 10 9",
"output": "8"
},
{
"input": "6\n5 2 3 1 6 4",
"output": "4"
},
{
"input": "10\n2 9 3 4 1 10 5 6 7 8",
"output": "5"
},
{
"input": "10\n2 3 4 5 6 7 1 8 10 9",
"output": "8"
},
{
"input": "8\n2 3 4 5 1 6 8 7",
"output": "6"
},
{
"input": "6\n2 1 3 4 5 6",
"output": "5"
}
] | 1,656,229,851 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 159 | 62 | 28,979,200 | def main():
n = int(input())
ns = list(map(int, input().split()))
min_pos = -1,
max_pos = -1
for idx, e in enumerate(ns):
if e == 1:
min_pos = idx
elif e == n:
max_pos = idx
print(max(max(n - 1 - min_pos, min_pos - 0), max(n - 1 - max_pos, max_pos - 0)))
if __name__ == "__main__":
main()
| Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input Specification:
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position.
Output Specification:
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Demo Input:
['5\n4 5 1 3 2\n', '7\n1 6 5 3 4 7 2\n', '6\n6 5 4 3 2 1\n']
Demo Output:
['3\n', '6\n', '5\n']
Note:
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2. | ```python
def main():
n = int(input())
ns = list(map(int, input().split()))
min_pos = -1,
max_pos = -1
for idx, e in enumerate(ns):
if e == 1:
min_pos = idx
elif e == n:
max_pos = idx
print(max(max(n - 1 - min_pos, min_pos - 0), max(n - 1 - max_pos, max_pos - 0)))
if __name__ == "__main__":
main()
``` | 3 |
|
137 | C | History | PROGRAMMING | 1,500 | [
"sortings"
] | null | null | Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=<<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=<<=*a**i* and *b**i*<=<<=*b**j*. Your task is simpler: find the number of events that are included in some other event. | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=≠<=*a**j*,<=*a**i*<=≠<=*b**j*,<=*b**i*<=≠<=*a**j*,<=*b**i*<=≠<=*b**j* for all *i*, *j* (where *i*<=≠<=*j*). Events are given in arbitrary order. | Print the only integer — the answer to the problem. | [
"5\n1 10\n2 9\n3 8\n4 7\n5 6\n",
"5\n1 100\n2 50\n51 99\n52 98\n10 60\n",
"1\n1 1000000000\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | 1,500 | [
{
"input": "5\n1 10\n2 9\n3 8\n4 7\n5 6",
"output": "4"
},
{
"input": "5\n1 100\n2 50\n51 99\n52 98\n10 60",
"output": "4"
},
{
"input": "1\n1 1000000000",
"output": "0"
},
{
"input": "2\n100 1000\n500 1500",
"output": "0"
},
{
"input": "4\n1 100\n50 150\n120 200\n180 220",
"output": "0"
},
{
"input": "10\n1 20\n2 19\n3 18\n4 17\n5 16\n6 15\n7 14\n8 13\n9 12\n10 11",
"output": "9"
},
{
"input": "4\n1 5\n2 4\n10 15\n11 14",
"output": "2"
},
{
"input": "10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20",
"output": "0"
},
{
"input": "10\n58 22116\n112840 772160\n127432 399484\n182031 255417\n459340 548097\n603984 739189\n606173 663033\n280170 366159\n779239 906234\n874623 892907",
"output": "7"
},
{
"input": "2\n2 3\n1 4",
"output": "1"
},
{
"input": "3\n9 10\n1 2\n3 4",
"output": "0"
},
{
"input": "4\n1 2\n3 6\n4 5\n10 11",
"output": "1"
},
{
"input": "2\n5 6\n1 10",
"output": "1"
},
{
"input": "7\n1 10\n2 5\n3 9\n100 1000\n200 500\n1001 1002\n777 7777",
"output": "4"
}
] | 1,666,190,543 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 75 | 1,466 | 19,456,000 | a = int(input())
dict1 = {}
for i in range(a):
b, c = map(int, input().split())
dict1[b] = c
sorted_values = sorted(dict1.keys())
dict2 = {}
for i in sorted_values:
dict2[i] = dict1[i]
last = list(dict2.keys())
n = 0
maxchislo = dict2[min(last)]
for i in range(1, a):
if dict2[last[i]] < maxchislo:
n += 1
if dict2[last[i]] > maxchislo:
maxchislo = dict2[last[i]]
print(n) | Title: History
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=<<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=<<=*a**i* and *b**i*<=<<=*b**j*. Your task is simpler: find the number of events that are included in some other event.
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=≠<=*a**j*,<=*a**i*<=≠<=*b**j*,<=*b**i*<=≠<=*a**j*,<=*b**i*<=≠<=*b**j* for all *i*, *j* (where *i*<=≠<=*j*). Events are given in arbitrary order.
Output Specification:
Print the only integer — the answer to the problem.
Demo Input:
['5\n1 10\n2 9\n3 8\n4 7\n5 6\n', '5\n1 100\n2 50\n51 99\n52 98\n10 60\n', '1\n1 1000000000\n']
Demo Output:
['4\n', '4\n', '0\n']
Note:
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | ```python
a = int(input())
dict1 = {}
for i in range(a):
b, c = map(int, input().split())
dict1[b] = c
sorted_values = sorted(dict1.keys())
dict2 = {}
for i in sorted_values:
dict2[i] = dict1[i]
last = list(dict2.keys())
n = 0
maxchislo = dict2[min(last)]
for i in range(1, a):
if dict2[last[i]] < maxchislo:
n += 1
if dict2[last[i]] > maxchislo:
maxchislo = dict2[last[i]]
print(n)
``` | 3 |
|
792 | B | Counting-out Rhyme | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | *n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader.
For example, if there are children with numbers [8,<=10,<=13,<=14,<=16] currently in the circle, the leader is child 13 and *a**i*<==<=12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader.
You have to write a program which prints the number of the child to be eliminated on every step. | The first line contains two integer numbers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1).
The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=109). | Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step. | [
"7 5\n10 4 11 4 1\n",
"3 2\n2 5\n"
] | [
"4 2 5 6 1 \n",
"3 2 \n"
] | Let's consider first example:
- In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader. - In the final step child 1 is eliminated, child 3 becomes the leader. | 0 | [
{
"input": "7 5\n10 4 11 4 1",
"output": "4 2 5 6 1 "
},
{
"input": "3 2\n2 5",
"output": "3 2 "
},
{
"input": "2 1\n1",
"output": "2 "
},
{
"input": "2 1\n2",
"output": "1 "
},
{
"input": "2 1\n3",
"output": "2 "
},
{
"input": "10 7\n5 10 4 3 8 10 6",
"output": "6 8 3 9 2 4 10 "
},
{
"input": "10 8\n12 6 12 15 20 8 17 12",
"output": "3 10 6 8 2 9 4 5 "
},
{
"input": "12 10\n76 58 82 54 97 46 17 40 36 15",
"output": "5 9 12 1 3 10 8 11 2 4 "
},
{
"input": "12 6\n76 61 94 15 66 26",
"output": "5 12 6 2 7 3 "
},
{
"input": "90 10\n1045 8705 6077 3282 1459 9809 383 6206 2674 7274",
"output": "56 39 45 20 17 55 14 85 51 33 "
},
{
"input": "100 30\n601771 913885 829106 91674 465657 367068 142461 873149 294276 916519 720701 370006 551782 321506 68525 570684 81178 724855 564907 661130 10112 983124 799801 100639 766045 862312 513021 232094 979480 408554",
"output": "72 89 16 26 85 73 29 99 63 30 8 46 70 19 100 93 36 54 65 77 17 79 62 64 21 69 42 82 68 1 "
},
{
"input": "3 2\n20148340 81473314",
"output": "2 3 "
},
{
"input": "3 2\n301633543 643389490",
"output": "2 3 "
},
{
"input": "6 5\n532623340 628883728 583960589 690950241 488468353",
"output": "5 3 6 1 4 "
},
{
"input": "6 2\n458995521 294343587",
"output": "4 1 "
},
{
"input": "68 1\n5",
"output": "6 "
}
] | 1,490,969,079 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 62 | 5,529,600 | inp1 = input().split()
n=int(inp1[0])
k=int(inp1[1])
koh_lanta = list(range(1,n+1))
liste_elimination = input().split()
lead=0
eliminated = []
for i in range(k):
lead = (lead + int(liste_elimination[i]))%(n-i)
eliminated.append(koh_lanta.pop(int(lead)))
print(*eliminated)
| Title: Counting-out Rhyme
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader.
For example, if there are children with numbers [8,<=10,<=13,<=14,<=16] currently in the circle, the leader is child 13 and *a**i*<==<=12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader.
You have to write a program which prints the number of the child to be eliminated on every step.
Input Specification:
The first line contains two integer numbers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1).
The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step.
Demo Input:
['7 5\n10 4 11 4 1\n', '3 2\n2 5\n']
Demo Output:
['4 2 5 6 1 \n', '3 2 \n']
Note:
Let's consider first example:
- In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader. - In the final step child 1 is eliminated, child 3 becomes the leader. | ```python
inp1 = input().split()
n=int(inp1[0])
k=int(inp1[1])
koh_lanta = list(range(1,n+1))
liste_elimination = input().split()
lead=0
eliminated = []
for i in range(k):
lead = (lead + int(liste_elimination[i]))%(n-i)
eliminated.append(koh_lanta.pop(int(lead)))
print(*eliminated)
``` | 3 |
|
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*. | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 1000000000",
"output": "0"
},
{
"input": "100000 1000000000",
"output": "16"
},
{
"input": "100000 362880",
"output": "154"
},
{
"input": "1 4",
"output": "0"
},
{
"input": "9 12",
"output": "4"
},
{
"input": "10 123",
"output": "0"
},
{
"input": "9551 975275379",
"output": "0"
},
{
"input": "17286 948615687",
"output": "0"
},
{
"input": "58942 936593001",
"output": "0"
},
{
"input": "50000 989460910",
"output": "4"
},
{
"input": "22741 989460910",
"output": "0"
},
{
"input": "22740 989460910",
"output": "0"
},
{
"input": "100000 989460910",
"output": "4"
},
{
"input": "100000 98280",
"output": "128"
},
{
"input": "100000 997920",
"output": "222"
},
{
"input": "100000 720720",
"output": "226"
},
{
"input": "100000 2162160",
"output": "282"
},
{
"input": "100000 4324320",
"output": "320"
},
{
"input": "100000 8648640",
"output": "348"
},
{
"input": "100000 183783600",
"output": "438"
},
{
"input": "100000 551350800",
"output": "392"
},
{
"input": "40000 551350800",
"output": "150"
},
{
"input": "20000 400000000",
"output": "1"
},
{
"input": "19999 400000000",
"output": "0"
},
{
"input": "19999 399960001",
"output": "1"
},
{
"input": "31621 999887641",
"output": "1"
},
{
"input": "31622 999887641",
"output": "1"
},
{
"input": "31620 999887641",
"output": "0"
},
{
"input": "100000 999887641",
"output": "3"
},
{
"input": "100000 25",
"output": "3"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "100000 3628800",
"output": "220"
},
{
"input": "100000 39916800",
"output": "328"
},
{
"input": "100000 479001600",
"output": "254"
},
{
"input": "4 9",
"output": "1"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "20 100",
"output": "3"
},
{
"input": "10 3",
"output": "2"
},
{
"input": "4 4",
"output": "3"
},
{
"input": "2 4",
"output": "1"
},
{
"input": "89874 1",
"output": "1"
}
] | 1,692,540,771 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 0 | y, x = map(int ,input().split())
lol = 1
cnt = 0
while lol <= x :
if x / lol == x // lol :
if x // lol <= y and lol <= y:
cnt += 1
a , b = lol , x // lol
lol += 1
print(cnt) | Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*.
Input Specification:
The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table.
Output Specification:
Print a single number: the number of times *x* occurs in the table.
Demo Input:
['10 5\n', '6 12\n', '5 13\n']
Demo Output:
['2\n', '4\n', '0\n']
Note:
A table for the second sample test is given below. The occurrences of number 12 are marked bold. | ```python
y, x = map(int ,input().split())
lol = 1
cnt = 0
while lol <= x :
if x / lol == x // lol :
if x // lol <= y and lol <= y:
cnt += 1
a , b = lol , x // lol
lol += 1
print(cnt)
``` | 0 |
|
804 | B | Minimum number of steps | PROGRAMMING | 1,400 | [
"combinatorics",
"greedy",
"implementation",
"math"
] | null | null | We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<=7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string. | The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. | Print the minimum number of steps modulo 109<=+<=7. | [
"ab\n",
"aab\n"
] | [
"1\n",
"3\n"
] | The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa". | 1,000 | [
{
"input": "ab",
"output": "1"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaaaabaabababaaaaaba",
"output": "17307"
},
{
"input": "abaabaaabbabaabab",
"output": "1795"
},
{
"input": "abbaa",
"output": "2"
},
{
"input": "abbaaabaabaaaaabbbbaababaaaaabaabbaaaaabbaabbaaaabbbabbbabb",
"output": "690283580"
},
{
"input": "aababbaaaabbaabbbbbbbbabbababbbaaabbaaabbabbba",
"output": "2183418"
},
{
"input": "aabbaababbabbbaabbaababaaaabbaaaabaaaaaababbaaaabaababbabbbb",
"output": "436420225"
},
{
"input": "aaabaaaabbababbaabbababbbbaaaaaaabbabbba",
"output": "8431094"
},
{
"input": "abbbbababbabbbbbabaabbbaabbbbbbbaaab",
"output": "8180"
},
{
"input": "bbababbbaabaaaaaaaabbabbbb",
"output": "40979"
},
{
"input": "abbbaaabbbbbabaabbaaabbbababbbaabaabababababa",
"output": "2065758"
},
{
"input": "abaaaaaabaaaabbabbaaabbbbabababaaaaabbaabbaaaaabbbaababaaaaaaabbbbbaaaaabaababbabababbabbbbaabbaabbabbbabaabbaabbaaaaaab",
"output": "235606597"
},
{
"input": "abbbbbbbbbbbbbbbbbbbbbbbbbbaababaaaaaaabaabaaababaabaababaaabababaababab",
"output": "7"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbaaaaaaaaabaabaaababaabaababaaabababaabbbbbbb",
"output": "557763786"
}
] | 1,493,922,615 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 1,000 | 3,174,400 | MOD = 1000000007
def main():
s = input()
# each b contributes 1 flip to the first a before it, 2 flips to the second a before it, etc
# in general, if there are k 'a's before a b, then add 2^(k + 1) - 1 flips
ans = 0
a_ct = 0
for c in s:
if c == 'a':
a_ct += 1
else:
ans += pow(2, a_ct, MOD) - 1
ans += MOD
ans %= MOD
print(ans)
main()
| Title: Minimum number of steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<=7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input Specification:
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output Specification:
Print the minimum number of steps modulo 109<=+<=7.
Demo Input:
['ab\n', 'aab\n']
Demo Output:
['1\n', '3\n']
Note:
The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa". | ```python
MOD = 1000000007
def main():
s = input()
# each b contributes 1 flip to the first a before it, 2 flips to the second a before it, etc
# in general, if there are k 'a's before a b, then add 2^(k + 1) - 1 flips
ans = 0
a_ct = 0
for c in s:
if c == 'a':
a_ct += 1
else:
ans += pow(2, a_ct, MOD) - 1
ans += MOD
ans %= MOD
print(ans)
main()
``` | 0 |
|
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book.
Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it.
Print the maximum number of books Valera can read. | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book. | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4"
},
{
"input": "7 13\n6 8 14 9 4 11 10",
"output": "2"
},
{
"input": "10 15\n10 9 1 1 5 10 5 3 7 2",
"output": "3"
},
{
"input": "20 30\n8 1 2 6 9 4 1 9 9 10 4 7 8 9 5 7 1 8 7 4",
"output": "6"
},
{
"input": "30 60\n16 13 22 38 13 35 17 17 20 38 12 19 9 22 20 3 35 34 34 21 35 40 22 3 27 19 12 4 8 19",
"output": "4"
},
{
"input": "100 100\n75 92 18 6 81 67 7 92 100 65 82 32 50 67 85 31 80 91 84 63 39 52 92 81 1 98 24 12 43 48 17 86 51 72 48 95 45 50 12 66 19 79 49 89 34 1 97 75 20 33 96 27 42 23 73 71 93 1 85 19 66 14 17 61 20 39 36 33 42 61 56 64 23 91 80 99 40 74 13 18 98 85 74 39 62 84 46 74 50 23 38 11 79 14 9 25 66 100 25 52",
"output": "3"
},
{
"input": "10 1\n4418 7528 8170 1736 1317 3205 8183 4995 8039 4708",
"output": "0"
},
{
"input": "50 2\n124 214 63 73 996 760 38 571 451 300 970 1 706 937 837 494 619 88 851 411 957 990 842 613 821 649 627 34 693 678 734 116 816 985 705 940 499 493 922 967 854 439 112 644 961 438 189 572 655 550",
"output": "1"
}
] | 1,691,815,554 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 186 | 13,824,000 | def mbr(m, t, bt):
max_books = 0
start = 0
sum = 0
for end in range(m):
sum += bt[end]
while sum > t:
sum -= bt[start]
start += 1
max_books = max(max_books, end - start + 1)
return max_books
m, t = map(int, input().split())
bt = list(map(int, input().split()))
result = mbr(m, t, bt)
print(result)
| Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book.
Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it.
Print the maximum number of books Valera can read.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book.
Output Specification:
Print a single integer — the maximum number of books Valera can read.
Demo Input:
['4 5\n3 1 2 1\n', '3 3\n2 2 3\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
def mbr(m, t, bt):
max_books = 0
start = 0
sum = 0
for end in range(m):
sum += bt[end]
while sum > t:
sum -= bt[start]
start += 1
max_books = max(max_books, end - start + 1)
return max_books
m, t = map(int, input().split())
bt = list(map(int, input().split()))
result = mbr(m, t, bt)
print(result)
``` | 3 |
|
811 | E | Vladik and Entertaining Flags | PROGRAMMING | 2,600 | [
"data structures",
"dsu",
"graphs"
] | null | null | In his spare time Vladik estimates beauty of the flags.
Every flag could be represented as the matrix *n*<=×<=*m* which consists of positive integers.
Let's define the beauty of the flag as number of components in its matrix. We call component a set of cells with same numbers and between any pair of cells from that set there exists a path through adjacent cells from same component. Here is the example of the partitioning some flag matrix into components:
But this time he decided to change something in the process. Now he wants to estimate not the entire flag, but some segment. Segment of flag can be described as a submatrix of the flag matrix with opposite corners at (1,<=*l*) and (*n*,<=*r*), where conditions 1<=≤<=*l*<=≤<=*r*<=≤<=*m* are satisfied.
Help Vladik to calculate the beauty for some segments of the given flag. | First line contains three space-separated integers *n*, *m*, *q* (1<=≤<=*n*<=≤<=10, 1<=≤<=*m*,<=*q*<=≤<=105) — dimensions of flag matrix and number of segments respectively.
Each of next *n* lines contains *m* space-separated integers — description of flag matrix. All elements of flag matrix is positive integers not exceeding 106.
Each of next *q* lines contains two space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*m*) — borders of segment which beauty Vladik wants to know. | For each segment print the result on the corresponding line. | [
"4 5 4\n1 1 1 1 1\n1 2 2 3 3\n1 1 1 2 5\n4 4 5 5 5\n1 5\n2 5\n1 2\n4 5\n"
] | [
"6\n7\n3\n4\n"
] | Partitioning on components for every segment from first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/5c89ff7036ddb39d2997c8f594d4a0729e524ab0.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 2,500 | [
{
"input": "4 5 4\n1 1 1 1 1\n1 2 2 3 3\n1 1 1 2 5\n4 4 5 5 5\n1 5\n2 5\n1 2\n4 5",
"output": "6\n7\n3\n4"
},
{
"input": "5 2 9\n6 1\n6 6\n6 6\n6 6\n5 6\n1 2\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n1 2\n1 1",
"output": "3\n2\n3\n3\n3\n2\n2\n3\n2"
},
{
"input": "5 4 10\n5 5 5 5\n5 5 5 5\n5 5 5 5\n5 5 5 5\n5 5 5 5\n2 4\n2 2\n1 2\n1 4\n1 1\n1 3\n2 4\n2 3\n1 3\n3 3",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "8 4 12\n7 20 20 29\n29 7 29 29\n29 20 20 29\n29 20 20 29\n29 8 29 29\n20 29 29 29\n29 29 32 29\n29 29 29 29\n2 4\n1 4\n2 3\n2 3\n1 4\n2 4\n1 1\n3 3\n3 3\n2 3\n3 4\n1 2",
"output": "6\n9\n7\n7\n9\n6\n4\n6\n6\n7\n4\n8"
},
{
"input": "7 8 14\n8 8 36 8 36 36 5 36\n25 36 36 8 36 25 36 36\n36 36 36 8 36 36 36 36\n36 36 36 36 36 36 8 55\n8 8 36 36 36 36 36 36\n49 36 36 36 8 36 36 36\n36 36 5 44 5 36 36 48\n2 3\n1 4\n6 8\n1 2\n5 8\n2 8\n1 5\n5 8\n6 7\n1 3\n2 6\n1 6\n3 6\n2 4",
"output": "4\n8\n7\n6\n8\n13\n10\n8\n5\n6\n9\n11\n7\n6"
},
{
"input": "1 6 9\n1 2 3 4 5 6\n2 6\n4 5\n3 4\n3 5\n6 6\n3 6\n4 6\n2 3\n1 6",
"output": "5\n2\n2\n3\n1\n4\n3\n2\n6"
},
{
"input": "4 8 6\n23 23 23 23 23 13 23 23\n23 23 23 23 23 23 23 23\n23 23 23 23 13 23 23 23\n23 23 26 23 23 23 23 23\n5 8\n2 8\n6 8\n5 5\n7 7\n2 4",
"output": "3\n4\n2\n3\n1\n2"
},
{
"input": "2 10 7\n8 13 13 8 8 8 8 8 8 8\n8 8 8 8 8 8 8 8 8 8\n4 9\n1 7\n6 6\n7 8\n4 4\n1 8\n2 10",
"output": "1\n2\n1\n1\n1\n2\n2"
},
{
"input": "5 12 6\n25 24 24 53 53 53 53 53 5 20 53 53\n24 53 24 53 53 3 5 53 53 53 53 53\n24 53 53 5 53 5 53 53 53 17 53 60\n49 53 53 24 53 53 53 53 53 53 53 35\n53 53 5 53 53 53 53 53 53 53 53 53\n6 8\n8 10\n4 11\n4 8\n6 12\n8 9",
"output": "4\n4\n9\n6\n9\n2"
},
{
"input": "4 14 4\n8 8 8 8 46 46 48 8 8 8 8 13 24 40\n8 46 46 46 8 8 46 8 8 8 8 24 24 24\n8 46 46 8 8 8 23 23 8 8 8 8 8 8\n8 8 8 8 8 8 8 8 8 8 8 8 8 55\n10 10\n10 14\n3 5\n10 12",
"output": "1\n5\n4\n3"
},
{
"input": "1 16 10\n2 2 2 2 6 2 8 2 2 12 10 9 9 2 16 2\n9 9\n5 5\n6 9\n6 8\n7 11\n6 16\n4 7\n6 15\n7 9\n11 11",
"output": "1\n1\n3\n3\n4\n9\n4\n8\n2\n1"
},
{
"input": "7 12 11\n73 14 4 73 42 42 73 73 73 67 73 24\n73 73 73 73 73 73 72 73 73 73 73 11\n73 73 4 72 73 73 73 73 73 73 67 72\n73 74 73 72 73 73 73 73 73 73 73 73\n4 73 73 73 73 73 73 73 73 57 73 73\n72 73 73 4 73 73 73 73 33 73 73 73\n73 73 73 15 42 72 67 67 33 67 73 73\n9 12\n6 6\n10 11\n8 10\n1 9\n6 9\n3 5\n2 4\n2 4\n7 11\n1 12",
"output": "9\n3\n5\n7\n16\n6\n8\n9\n9\n8\n23"
},
{
"input": "5 16 10\n32 4 4 4 4 4 4 52 4 4 4 4 29 30 4 4\n4 4 67 52 4 4 4 67 4 4 4 4 4 4 4 4\n4 52 52 52 4 4 4 67 67 52 32 4 4 4 4 52\n4 52 4 4 4 4 4 4 67 52 49 4 4 4 4 62\n49 4 4 4 4 72 55 4 4 52 49 52 4 62 4 62\n5 16\n9 13\n2 12\n3 13\n8 14\n7 7\n3 9\n1 4\n1 5\n7 7",
"output": "15\n8\n12\n13\n11\n2\n8\n6\n5\n2"
}
] | 1,496,672,198 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 204,800 | #!/usr/bin/python3
import sys
def get_str_deb():
yield list(int(x) for x in "4 5 4".split())
yield list(int(x) for x in "1 1 1 1 1".split())
yield list(int(x) for x in "1 2 2 3 3".split())
yield list(int(x) for x in "1 1 1 2 5".split())
yield list(int(x) for x in "4 4 5 5 5".split())
yield list(int(x) for x in "1 5".split())
yield list(int(x) for x in "2 5".split())
yield list(int(x) for x in "1 2".split())
yield list(int(x) for x in "4 5".split())
deb = get_str_deb()
def get_str():
if False:
return (int(x) for x in sys.stdin.readline().split())
else:
return next(deb)
def main():
n, m, q = get_str()
matr = [None] * n
for i in range(n):
matr[i] = list(get_str())
for i in range(q):
l, r = get_str()
l = l - 1
r = r - 1
x, y = [l, 0]
regions = 0
checked = [[False for i in range(m)] for j in range(n)]
while True:
regions = regions + 1
chain = []
while True:
checked[y][x] = True
if x > l and matr[y][x - 1] == matr[y][x] and not(checked[y][x - 1]):
chain.append((x, y))
x = x - 1
continue
elif x < r and matr[y][x + 1] == matr[y][x] and not(checked[y][x + 1]):
chain.append((x, y))
x = x + 1
continue
elif y > 0 and matr[y - 1][x] == matr[y][x] and not(checked[y - 1][x]):
chain.append((x, y))
y = y - 1
continue
elif y < n - 1 and matr[y + 1][x] == matr[y][x] and not(checked[y + 1][x]):
chain.append((x, y))
y = y + 1
continue
elif len(chain) == 0:
break
x, y = chain.pop()
x = None
y = None
for newx in range(l, r + 1):
for newy in range(n):
if not(checked[newy][newx]):
x = newx
y = newy
stop = True
break
if x is not None:
break
if x is None:
break
print(regions)
if __name__ == "__main__":
main()
| Title: Vladik and Entertaining Flags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In his spare time Vladik estimates beauty of the flags.
Every flag could be represented as the matrix *n*<=×<=*m* which consists of positive integers.
Let's define the beauty of the flag as number of components in its matrix. We call component a set of cells with same numbers and between any pair of cells from that set there exists a path through adjacent cells from same component. Here is the example of the partitioning some flag matrix into components:
But this time he decided to change something in the process. Now he wants to estimate not the entire flag, but some segment. Segment of flag can be described as a submatrix of the flag matrix with opposite corners at (1,<=*l*) and (*n*,<=*r*), where conditions 1<=≤<=*l*<=≤<=*r*<=≤<=*m* are satisfied.
Help Vladik to calculate the beauty for some segments of the given flag.
Input Specification:
First line contains three space-separated integers *n*, *m*, *q* (1<=≤<=*n*<=≤<=10, 1<=≤<=*m*,<=*q*<=≤<=105) — dimensions of flag matrix and number of segments respectively.
Each of next *n* lines contains *m* space-separated integers — description of flag matrix. All elements of flag matrix is positive integers not exceeding 106.
Each of next *q* lines contains two space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*m*) — borders of segment which beauty Vladik wants to know.
Output Specification:
For each segment print the result on the corresponding line.
Demo Input:
['4 5 4\n1 1 1 1 1\n1 2 2 3 3\n1 1 1 2 5\n4 4 5 5 5\n1 5\n2 5\n1 2\n4 5\n']
Demo Output:
['6\n7\n3\n4\n']
Note:
Partitioning on components for every segment from first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/5c89ff7036ddb39d2997c8f594d4a0729e524ab0.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
#!/usr/bin/python3
import sys
def get_str_deb():
yield list(int(x) for x in "4 5 4".split())
yield list(int(x) for x in "1 1 1 1 1".split())
yield list(int(x) for x in "1 2 2 3 3".split())
yield list(int(x) for x in "1 1 1 2 5".split())
yield list(int(x) for x in "4 4 5 5 5".split())
yield list(int(x) for x in "1 5".split())
yield list(int(x) for x in "2 5".split())
yield list(int(x) for x in "1 2".split())
yield list(int(x) for x in "4 5".split())
deb = get_str_deb()
def get_str():
if False:
return (int(x) for x in sys.stdin.readline().split())
else:
return next(deb)
def main():
n, m, q = get_str()
matr = [None] * n
for i in range(n):
matr[i] = list(get_str())
for i in range(q):
l, r = get_str()
l = l - 1
r = r - 1
x, y = [l, 0]
regions = 0
checked = [[False for i in range(m)] for j in range(n)]
while True:
regions = regions + 1
chain = []
while True:
checked[y][x] = True
if x > l and matr[y][x - 1] == matr[y][x] and not(checked[y][x - 1]):
chain.append((x, y))
x = x - 1
continue
elif x < r and matr[y][x + 1] == matr[y][x] and not(checked[y][x + 1]):
chain.append((x, y))
x = x + 1
continue
elif y > 0 and matr[y - 1][x] == matr[y][x] and not(checked[y - 1][x]):
chain.append((x, y))
y = y - 1
continue
elif y < n - 1 and matr[y + 1][x] == matr[y][x] and not(checked[y + 1][x]):
chain.append((x, y))
y = y + 1
continue
elif len(chain) == 0:
break
x, y = chain.pop()
x = None
y = None
for newx in range(l, r + 1):
for newy in range(n):
if not(checked[newy][newx]):
x = newx
y = newy
stop = True
break
if x is not None:
break
if x is None:
break
print(regions)
if __name__ == "__main__":
main()
``` | 0 |
|
710 | C | Magic Odd Square | PROGRAMMING | 1,500 | [
"constructive algorithms",
"math"
] | null | null | Find an *n*<=×<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd. | The only line contains odd integer *n* (1<=≤<=*n*<=≤<=49). | Print *n* lines with *n* integers. All the integers should be different and from 1 to *n*2. The sum in each row, column and both main diagonals should be odd. | [
"1\n",
"3\n"
] | [
"1\n",
"2 1 4\n3 5 7\n6 9 8\n"
] | none | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "2 1 4\n3 5 7\n6 9 8"
},
{
"input": "5",
"output": "2 4 1 6 8\n10 3 5 7 12\n9 11 13 15 17\n14 19 21 23 16\n18 20 25 22 24"
},
{
"input": "7",
"output": "2 4 6 1 8 10 12\n14 16 3 5 7 18 20\n22 9 11 13 15 17 24\n19 21 23 25 27 29 31\n26 33 35 37 39 41 28\n30 32 43 45 47 34 36\n38 40 42 49 44 46 48"
},
{
"input": "9",
"output": "2 4 6 8 1 10 12 14 16\n18 20 22 3 5 7 24 26 28\n30 32 9 11 13 15 17 34 36\n38 19 21 23 25 27 29 31 40\n33 35 37 39 41 43 45 47 49\n42 51 53 55 57 59 61 63 44\n46 48 65 67 69 71 73 50 52\n54 56 58 75 77 79 60 62 64\n66 68 70 72 81 74 76 78 80"
},
{
"input": "11",
"output": "2 4 6 8 10 1 12 14 16 18 20\n22 24 26 28 3 5 7 30 32 34 36\n38 40 42 9 11 13 15 17 44 46 48\n50 52 19 21 23 25 27 29 31 54 56\n58 33 35 37 39 41 43 45 47 49 60\n51 53 55 57 59 61 63 65 67 69 71\n62 73 75 77 79 81 83 85 87 89 64\n66 68 91 93 95 97 99 101 103 70 72\n74 76 78 105 107 109 111 113 80 82 84\n86 88 90 92 115 117 119 94 96 98 100\n102 104 106 108 110 121 112 114 116 118 120"
},
{
"input": "13",
"output": "2 4 6 8 10 12 1 14 16 18 20 22 24\n26 28 30 32 34 3 5 7 36 38 40 42 44\n46 48 50 52 9 11 13 15 17 54 56 58 60\n62 64 66 19 21 23 25 27 29 31 68 70 72\n74 76 33 35 37 39 41 43 45 47 49 78 80\n82 51 53 55 57 59 61 63 65 67 69 71 84\n73 75 77 79 81 83 85 87 89 91 93 95 97\n86 99 101 103 105 107 109 111 113 115 117 119 88\n90 92 121 123 125 127 129 131 133 135 137 94 96\n98 100 102 139 141 143 145 147 149 151 104 106 108\n110 112 114 116 153 155 157 159 161 118 120 122 124\n126 128 130 132 134 163 165 167 136 ..."
},
{
"input": "15",
"output": "2 4 6 8 10 12 14 1 16 18 20 22 24 26 28\n30 32 34 36 38 40 3 5 7 42 44 46 48 50 52\n54 56 58 60 62 9 11 13 15 17 64 66 68 70 72\n74 76 78 80 19 21 23 25 27 29 31 82 84 86 88\n90 92 94 33 35 37 39 41 43 45 47 49 96 98 100\n102 104 51 53 55 57 59 61 63 65 67 69 71 106 108\n110 73 75 77 79 81 83 85 87 89 91 93 95 97 112\n99 101 103 105 107 109 111 113 115 117 119 121 123 125 127\n114 129 131 133 135 137 139 141 143 145 147 149 151 153 116\n118 120 155 157 159 161 163 165 167 169 171 173 175 122 124\n126 128 1..."
},
{
"input": "17",
"output": "2 4 6 8 10 12 14 16 1 18 20 22 24 26 28 30 32\n34 36 38 40 42 44 46 3 5 7 48 50 52 54 56 58 60\n62 64 66 68 70 72 9 11 13 15 17 74 76 78 80 82 84\n86 88 90 92 94 19 21 23 25 27 29 31 96 98 100 102 104\n106 108 110 112 33 35 37 39 41 43 45 47 49 114 116 118 120\n122 124 126 51 53 55 57 59 61 63 65 67 69 71 128 130 132\n134 136 73 75 77 79 81 83 85 87 89 91 93 95 97 138 140\n142 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 144\n129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161..."
},
{
"input": "19",
"output": "2 4 6 8 10 12 14 16 18 1 20 22 24 26 28 30 32 34 36\n38 40 42 44 46 48 50 52 3 5 7 54 56 58 60 62 64 66 68\n70 72 74 76 78 80 82 9 11 13 15 17 84 86 88 90 92 94 96\n98 100 102 104 106 108 19 21 23 25 27 29 31 110 112 114 116 118 120\n122 124 126 128 130 33 35 37 39 41 43 45 47 49 132 134 136 138 140\n142 144 146 148 51 53 55 57 59 61 63 65 67 69 71 150 152 154 156\n158 160 162 73 75 77 79 81 83 85 87 89 91 93 95 97 164 166 168\n170 172 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 174 176\n178..."
},
{
"input": "21",
"output": "2 4 6 8 10 12 14 16 18 20 1 22 24 26 28 30 32 34 36 38 40\n42 44 46 48 50 52 54 56 58 3 5 7 60 62 64 66 68 70 72 74 76\n78 80 82 84 86 88 90 92 9 11 13 15 17 94 96 98 100 102 104 106 108\n110 112 114 116 118 120 122 19 21 23 25 27 29 31 124 126 128 130 132 134 136\n138 140 142 144 146 148 33 35 37 39 41 43 45 47 49 150 152 154 156 158 160\n162 164 166 168 170 51 53 55 57 59 61 63 65 67 69 71 172 174 176 178 180\n182 184 186 188 73 75 77 79 81 83 85 87 89 91 93 95 97 190 192 194 196\n198 200 202 99 101 103 ..."
},
{
"input": "23",
"output": "2 4 6 8 10 12 14 16 18 20 22 1 24 26 28 30 32 34 36 38 40 42 44\n46 48 50 52 54 56 58 60 62 64 3 5 7 66 68 70 72 74 76 78 80 82 84\n86 88 90 92 94 96 98 100 102 9 11 13 15 17 104 106 108 110 112 114 116 118 120\n122 124 126 128 130 132 134 136 19 21 23 25 27 29 31 138 140 142 144 146 148 150 152\n154 156 158 160 162 164 166 33 35 37 39 41 43 45 47 49 168 170 172 174 176 178 180\n182 184 186 188 190 192 51 53 55 57 59 61 63 65 67 69 71 194 196 198 200 202 204\n206 208 210 212 214 73 75 77 79 81 83 85 87 89 ..."
},
{
"input": "25",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 1 26 28 30 32 34 36 38 40 42 44 46 48\n50 52 54 56 58 60 62 64 66 68 70 3 5 7 72 74 76 78 80 82 84 86 88 90 92\n94 96 98 100 102 104 106 108 110 112 9 11 13 15 17 114 116 118 120 122 124 126 128 130 132\n134 136 138 140 142 144 146 148 150 19 21 23 25 27 29 31 152 154 156 158 160 162 164 166 168\n170 172 174 176 178 180 182 184 33 35 37 39 41 43 45 47 49 186 188 190 192 194 196 198 200\n202 204 206 208 210 212 214 51 53 55 57 59 61 63 65 67 69 71 216 218 220 222 224 226 228\n..."
},
{
"input": "27",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 26 1 28 30 32 34 36 38 40 42 44 46 48 50 52\n54 56 58 60 62 64 66 68 70 72 74 76 3 5 7 78 80 82 84 86 88 90 92 94 96 98 100\n102 104 106 108 110 112 114 116 118 120 122 9 11 13 15 17 124 126 128 130 132 134 136 138 140 142 144\n146 148 150 152 154 156 158 160 162 164 19 21 23 25 27 29 31 166 168 170 172 174 176 178 180 182 184\n186 188 190 192 194 196 198 200 202 33 35 37 39 41 43 45 47 49 204 206 208 210 212 214 216 218 220\n222 224 226 228 230 232 234 236 51 53 55 57 59 61..."
},
{
"input": "29",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 1 30 32 34 36 38 40 42 44 46 48 50 52 54 56\n58 60 62 64 66 68 70 72 74 76 78 80 82 3 5 7 84 86 88 90 92 94 96 98 100 102 104 106 108\n110 112 114 116 118 120 122 124 126 128 130 132 9 11 13 15 17 134 136 138 140 142 144 146 148 150 152 154 156\n158 160 162 164 166 168 170 172 174 176 178 19 21 23 25 27 29 31 180 182 184 186 188 190 192 194 196 198 200\n202 204 206 208 210 212 214 216 218 220 33 35 37 39 41 43 45 47 49 222 224 226 228 230 232 234 236 238 240\n242 244 2..."
},
{
"input": "31",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 1 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60\n62 64 66 68 70 72 74 76 78 80 82 84 86 88 3 5 7 90 92 94 96 98 100 102 104 106 108 110 112 114 116\n118 120 122 124 126 128 130 132 134 136 138 140 142 9 11 13 15 17 144 146 148 150 152 154 156 158 160 162 164 166 168\n170 172 174 176 178 180 182 184 186 188 190 192 19 21 23 25 27 29 31 194 196 198 200 202 204 206 208 210 212 214 216\n218 220 222 224 226 228 230 232 234 236 238 33 35 37 39 41 43 45 47 49 240 242 244 24..."
},
{
"input": "33",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 1 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64\n66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 3 5 7 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124\n126 128 130 132 134 136 138 140 142 144 146 148 150 152 9 11 13 15 17 154 156 158 160 162 164 166 168 170 172 174 176 178 180\n182 184 186 188 190 192 194 196 198 200 202 204 206 19 21 23 25 27 29 31 208 210 212 214 216 218 220 222 224 226 228 230 232\n234 236 238 240 242 244 246 248 250 252 254 256 33 35..."
},
{
"input": "35",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 1 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68\n70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 3 5 7 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132\n134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 9 11 13 15 17 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192\n194 196 198 200 202 204 206 208 210 212 214 216 218 220 19 21 23 25 27 29 31 222 224 226 228 230 232 234 236 238 240 242 244 246 248\n250 252 254 256 258 2..."
},
{
"input": "37",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 1 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72\n74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 3 5 7 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140\n142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 9 11 13 15 17 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204\n206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 19 21 23 25 27 29 31 236 238 240 242 244 246 248 250 252 254 256 258 26..."
},
{
"input": "39",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 1 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76\n78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 3 5 7 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148\n150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 9 11 13 15 17 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216\n218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 19 21 23 25 27 29 31 250 252 254 256 258 26..."
},
{
"input": "41",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 1 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80\n82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 3 5 7 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156\n158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 9 11 13 15 17 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228\n230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 19 21 23 25 27 ..."
},
{
"input": "43",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 1 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84\n86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 3 5 7 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164\n166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 9 11 13 15 17 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240\n242 244 246 248 250 252 254 256 258 260 262 264 266 268 270..."
},
{
"input": "45",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 1 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88\n90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 3 5 7 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172\n174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 9 11 13 15 17 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252\n254 256 258 260 262 264 266 268 270..."
},
{
"input": "47",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 1 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92\n94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 3 5 7 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180\n182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 9 11 13 15 17 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264\n266 268 270..."
},
{
"input": "49",
"output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 1 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96\n98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 3 5 7 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188\n190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 9 11 13 15 17 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 ..."
}
] | 1,493,211,946 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 5,529,600 | a = int(input())
odd = 1
even = 2
c = a//2
l = [[] for x in range(a)]
for row in range(0, a):
for col in range(0, a):
if c <= col <= a - 1 - c:
l[row].append(odd)
odd += 2
else:
l[row].append(even)
even += 2
if row < a//2:
c -= 1
else:
c += 1
for row in l:
print(" ".join(list(map(str, row)))) | Title: Magic Odd Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Find an *n*<=×<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd.
Input Specification:
The only line contains odd integer *n* (1<=≤<=*n*<=≤<=49).
Output Specification:
Print *n* lines with *n* integers. All the integers should be different and from 1 to *n*2. The sum in each row, column and both main diagonals should be odd.
Demo Input:
['1\n', '3\n']
Demo Output:
['1\n', '2 1 4\n3 5 7\n6 9 8\n']
Note:
none | ```python
a = int(input())
odd = 1
even = 2
c = a//2
l = [[] for x in range(a)]
for row in range(0, a):
for col in range(0, a):
if c <= col <= a - 1 - c:
l[row].append(odd)
odd += 2
else:
l[row].append(even)
even += 2
if row < a//2:
c -= 1
else:
c += 1
for row in l:
print(" ".join(list(map(str, row))))
``` | 3 |
|
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation.
But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
},
{
"input": "693\n970",
"output": "NO"
},
{
"input": "981\n1",
"output": "YES"
},
{
"input": "352\n276",
"output": "YES"
},
{
"input": "164\n691",
"output": "YES"
},
{
"input": "110036\n43",
"output": "YES"
},
{
"input": "100\n1000",
"output": "NO"
},
{
"input": "1000000000\n1000000000",
"output": "YES"
},
{
"input": "999999999\n999999999",
"output": "YES"
},
{
"input": "6\n4",
"output": "NO"
},
{
"input": "123456\n876543",
"output": "YES"
},
{
"input": "1234567\n9876543",
"output": "NO"
},
{
"input": "1111111\n1119111",
"output": "NO"
},
{
"input": "10502405\n40403403",
"output": "YES"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "5\n4",
"output": "YES"
},
{
"input": "1\n6",
"output": "YES"
},
{
"input": "40\n17",
"output": "NO"
},
{
"input": "35\n81",
"output": "YES"
},
{
"input": "347\n908",
"output": "NO"
},
{
"input": "2081\n7450",
"output": "NO"
},
{
"input": "84355694\n373629503",
"output": "NO"
},
{
"input": "885992048\n510468672",
"output": "NO"
},
{
"input": "540144752\n647307841",
"output": "NO"
},
{
"input": "341781108\n784147010",
"output": "NO"
},
{
"input": "960440938\n572334653",
"output": "NO"
},
{
"input": "657414510\n768771903",
"output": "NO"
},
{
"input": "501871728\n725074574",
"output": "NO"
},
{
"input": "968\n851",
"output": "YES"
},
{
"input": "943\n939",
"output": "YES"
},
{
"input": "347\n908",
"output": "NO"
},
{
"input": "611\n41",
"output": "YES"
},
{
"input": "737\n289",
"output": "NO"
},
{
"input": "168\n571",
"output": "YES"
},
{
"input": "868\n463",
"output": "YES"
},
{
"input": "815732007\n913882008",
"output": "NO"
},
{
"input": "459039901\n453033850",
"output": "NO"
},
{
"input": "975305404\n484601256",
"output": "NO"
}
] | 1,635,691,103 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 4,505,600 | a=input()
b=input()
# sm=list(map(int,str(int(a)+int(b))))
# ans=sum(sm)
sm=int(a)+int(b)
a=a.replace("0","")
b=b.replace("0","")
sm1=int(a)+int(b)
sm=int(str(sm).replace("0",""))
# sm1=list(map(int,str(int(a)+int(b))))
# ans1=sum(sm1)
if sm==sm1:
print("Yes")
else:
print("No") | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation.
But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
Input Specification:
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
Output Specification:
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
Demo Input:
['101\n102\n', '105\n106\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
a=input()
b=input()
# sm=list(map(int,str(int(a)+int(b))))
# ans=sum(sm)
sm=int(a)+int(b)
a=a.replace("0","")
b=b.replace("0","")
sm1=int(a)+int(b)
sm=int(str(sm).replace("0",""))
# sm1=list(map(int,str(int(a)+int(b))))
# ans1=sum(sm1)
if sm==sm1:
print("Yes")
else:
print("No")
``` | 0 |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed? | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles. | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": "2"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n2\n-1",
"output": "2"
},
{
"input": "2\n-1\n-1",
"output": "1"
},
{
"input": "3\n2\n-1\n1",
"output": "3"
},
{
"input": "3\n-1\n-1\n-1",
"output": "1"
},
{
"input": "5\n4\n5\n1\n-1\n4",
"output": "3"
},
{
"input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7",
"output": "4"
},
{
"input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4",
"output": "5"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1",
"output": "2"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1",
"output": "1"
},
{
"input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11",
"output": "12"
},
{
"input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2",
"output": "11"
},
{
"input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6",
"output": "6"
},
{
"input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1",
"output": "3"
},
{
"input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1",
"output": "2"
},
{
"input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1",
"output": "3"
},
{
"input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8",
"output": "5"
},
{
"input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10",
"output": "6"
},
{
"input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1",
"output": "4"
},
{
"input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9",
"output": "4"
},
{
"input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8",
"output": "3"
},
{
"input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11",
"output": "7"
},
{
"input": "7\n7\n6\n-1\n-1\n4\n4\n-1",
"output": "3"
},
{
"input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34",
"output": "6"
},
{
"input": "5\n2\n3\n4\n5\n-1",
"output": "5"
}
] | 1,665,017,845 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 43 | 340 | 14,950,400 | #By Anan instagram: anan.ssw
import sys
#sys.setrecursionlimit(20000)
inp=lambda: sys.stdin.readline().strip()
inparr=lambda : map(int,inp().split())
t=int(inp())
d={}
ans=[]
for x in range(1,t+1):
d[x]=int(inp())
i=0
def rec(z):
global i,ans
x=d[z]
if x!=-1:
i+=1
rec(x)
else:
ans.append(i)
i=0
for k in d:
rec(k)
print(max(ans)+1) | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles.
Output Specification:
Print a single integer denoting the minimum number of groups that will be formed in the party.
Demo Input:
['5\n-1\n1\n2\n1\n-1\n']
Demo Output:
['3\n']
Note:
For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | ```python
#By Anan instagram: anan.ssw
import sys
#sys.setrecursionlimit(20000)
inp=lambda: sys.stdin.readline().strip()
inparr=lambda : map(int,inp().split())
t=int(inp())
d={}
ans=[]
for x in range(1,t+1):
d[x]=int(inp())
i=0
def rec(z):
global i,ans
x=d[z]
if x!=-1:
i+=1
rec(x)
else:
ans.append(i)
i=0
for k in d:
rec(k)
print(max(ans)+1)
``` | -1 |
|
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters. | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 17 21 10 11 100 23 10",
"output": "1"
},
{
"input": "52\n1 12 3 11 4 5 10 6 9 7 8 2",
"output": "6"
},
{
"input": "50\n2 2 3 4 5 4 4 5 7 3 2 7",
"output": "-1"
},
{
"input": "0\n55 81 28 48 99 20 67 95 6 19 10 93",
"output": "0"
},
{
"input": "93\n85 40 93 66 92 43 61 3 64 51 90 21",
"output": "1"
},
{
"input": "99\n36 34 22 0 0 0 52 12 0 0 33 47",
"output": "2"
},
{
"input": "99\n28 32 31 0 10 35 11 18 0 0 32 28",
"output": "3"
},
{
"input": "99\n19 17 0 1 18 11 29 9 29 22 0 8",
"output": "4"
},
{
"input": "76\n2 16 11 10 12 0 20 4 4 14 11 14",
"output": "5"
},
{
"input": "41\n2 1 7 7 4 2 4 4 9 3 10 0",
"output": "6"
},
{
"input": "47\n8 2 2 4 3 1 9 4 2 7 7 8",
"output": "7"
},
{
"input": "58\n6 11 7 0 5 6 3 9 4 9 5 1",
"output": "8"
},
{
"input": "32\n5 2 4 1 5 0 5 1 4 3 0 3",
"output": "9"
},
{
"input": "31\n6 1 0 4 4 5 1 0 5 3 2 0",
"output": "9"
},
{
"input": "35\n2 3 0 0 6 3 3 4 3 5 0 6",
"output": "9"
},
{
"input": "41\n3 1 3 4 3 6 6 1 4 4 0 6",
"output": "11"
},
{
"input": "97\n0 5 3 12 10 16 22 8 21 17 21 10",
"output": "5"
},
{
"input": "100\n21 21 0 0 4 13 0 26 0 0 0 15",
"output": "6"
},
{
"input": "100\n0 0 16 5 22 0 5 0 25 0 14 13",
"output": "7"
},
{
"input": "97\n17 0 10 0 0 0 18 0 14 23 15 0",
"output": "6"
},
{
"input": "100\n0 9 0 18 7 0 0 14 33 3 0 16",
"output": "7"
},
{
"input": "95\n5 2 13 0 15 18 17 0 6 11 0 8",
"output": "9"
},
{
"input": "94\n11 13 0 9 15 8 8 16 3 7 1 3",
"output": "11"
},
{
"input": "96\n8 4 12 15 8 0 4 10 6 6 12 11",
"output": "11"
},
{
"input": "100\n5 5 3 8 6 5 0 3 3 8 1 3",
"output": "-1"
},
{
"input": "100\n1 0 0 1 1 0 1 1 1 1 2 1",
"output": "-1"
},
{
"input": "100\n6 3 2 0 4 1 2 2 2 2 1 1",
"output": "-1"
},
{
"input": "0\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
},
{
"input": "0\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "12"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 2",
"output": "12"
},
{
"input": "15\n10 1 1 1 1 1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "1\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
}
] | 1,656,749,879 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 0 | k = int(input())
a = sorted([int(s) for s in input().split()], reverse=True)
i = 0
s = 0
ans = 0
while i < len(a) and s < k:
s += a[i]
ans += 1
print(ans) | Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters.
Input Specification:
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Output Specification:
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
Demo Input:
['5\n1 1 1 1 2 2 3 2 2 1 1 1\n', '0\n0 0 0 0 0 0 0 1 1 2 3 0\n', '11\n1 1 4 1 1 5 1 1 4 1 1 1\n']
Demo Output:
['2\n', '0\n', '3\n']
Note:
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | ```python
k = int(input())
a = sorted([int(s) for s in input().split()], reverse=True)
i = 0
s = 0
ans = 0
while i < len(a) and s < k:
s += a[i]
ans += 1
print(ans)
``` | 0 |
|
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that. | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"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"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "100\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71",
"output": "51"
},
{
"input": "100\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29",
"output": "1"
},
{
"input": "100\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24",
"output": "2"
},
{
"input": "50\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6",
"output": "10"
},
{
"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 99 100 100 100 100 100 100 100 100 100 100 100 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": "99"
},
{
"input": "7\n1 2 3 3 3 1 2",
"output": "3"
},
{
"input": "5\n1 2 3 4 5",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "1"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "2"
},
{
"input": "11\n1 2 3 4 5 6 7 8 9 1 1",
"output": "3"
},
{
"input": "12\n1 2 1 1 1 1 1 1 1 1 1 1",
"output": "11"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "13"
},
{
"input": "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "14"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "15"
},
{
"input": "16\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "16"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "10\n1 1 1 1 2 2 1 1 9 10",
"output": "6"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "56\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",
"output": "56"
},
{
"input": "99\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92",
"output": "6"
},
{
"input": "10\n1 2 2 3 3 3 4 4 4 4",
"output": "4"
},
{
"input": "99\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21",
"output": "3"
},
{
"input": "5\n5 5 5 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 5 2 6",
"output": "3"
},
{
"input": "3\n58 59 58",
"output": "2"
},
{
"input": "9\n1 2 3 4 5 6 7 8 8",
"output": "2"
},
{
"input": "97\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",
"output": "97"
},
{
"input": "3\n95 95 4",
"output": "2"
},
{
"input": "3\n2 2 5",
"output": "2"
}
] | 1,619,150,567 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 0 | input()
a=[*map(int,input().split())]
print(max(a.count(i)for i in a)) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
Input Specification:
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Output Specification:
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
Demo Input:
['6\n1 2 4 3 3 2\n', '1\n100\n']
Demo Output:
['2\n', '1\n']
Note:
none | ```python
input()
a=[*map(int,input().split())]
print(max(a.count(i)for i in a))
``` | 3 |
|
412 | A | Poster | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The slogan of the company consists of *n* characters, so the decorators hung a large banner, *n* meters wide and 1 meter high, divided into *n* equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.
Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the *k*-th square of the poster. To draw the *i*-th character of the slogan on the poster, you need to climb the ladder, standing in front of the *i*-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the *i*-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.
Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan! | The first line contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'. | In *t* lines, print the actions the programmers need to make. In the *i*-th line print:
- "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th action was to "go up the ladder, paint character *x*, go down the ladder".
The painting time (variable *t*) must be minimum possible. If there are multiple optimal painting plans, you can print any of them. | [
"2 2\nR1\n",
"2 1\nR1\n",
"6 4\nGO?GO!\n"
] | [
"PRINT 1\nLEFT\nPRINT R\n",
"PRINT R\nRIGHT\nPRINT 1\n",
"RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G\n"
] | Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character. | 500 | [
{
"input": "2 2\nR1",
"output": "PRINT 1\nLEFT\nPRINT R"
},
{
"input": "2 1\nR1",
"output": "PRINT R\nRIGHT\nPRINT 1"
},
{
"input": "6 4\nGO?GO!",
"output": "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"
},
{
"input": "7 3\nME,YOU.",
"output": "LEFT\nLEFT\nPRINT M\nRIGHT\nPRINT E\nRIGHT\nPRINT ,\nRIGHT\nPRINT Y\nRIGHT\nPRINT O\nRIGHT\nPRINT U\nRIGHT\nPRINT ."
},
{
"input": "10 1\nEK5JQMS5QN",
"output": "PRINT E\nRIGHT\nPRINT K\nRIGHT\nPRINT 5\nRIGHT\nPRINT J\nRIGHT\nPRINT Q\nRIGHT\nPRINT M\nRIGHT\nPRINT S\nRIGHT\nPRINT 5\nRIGHT\nPRINT Q\nRIGHT\nPRINT N"
},
{
"input": "85 84\n73IW80UODC8B,UR7S8WMNATV0JSRF4W0B2VV8LCAX6SGCYY8?LHDKJEO29WXQWT9.WY1VY7408S1W04GNDZPK",
"output": "RIGHT\nPRINT K\nLEFT\nPRINT P\nLEFT\nPRINT Z\nLEFT\nPRINT D\nLEFT\nPRINT N\nLEFT\nPRINT G\nLEFT\nPRINT 4\nLEFT\nPRINT 0\nLEFT\nPRINT W\nLEFT\nPRINT 1\nLEFT\nPRINT S\nLEFT\nPRINT 8\nLEFT\nPRINT 0\nLEFT\nPRINT 4\nLEFT\nPRINT 7\nLEFT\nPRINT Y\nLEFT\nPRINT V\nLEFT\nPRINT 1\nLEFT\nPRINT Y\nLEFT\nPRINT W\nLEFT\nPRINT .\nLEFT\nPRINT 9\nLEFT\nPRINT T\nLEFT\nPRINT W\nLEFT\nPRINT Q\nLEFT\nPRINT X\nLEFT\nPRINT W\nLEFT\nPRINT 9\nLEFT\nPRINT 2\nLEFT\nPRINT O\nLEFT\nPRINT E\nLEFT\nPRINT J\nLEFT\nPRINT K\nLEFT\nPRINT D\n..."
},
{
"input": "59 53\n7NWD!9PC11C8S4TQABBTJO,?CO6YGOM!W0QR94CZJBD9U1YJY23YB354,8F",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT F\nLEFT\nPRINT 8\nLEFT\nPRINT ,\nLEFT\nPRINT 4\nLEFT\nPRINT 5\nLEFT\nPRINT 3\nLEFT\nPRINT B\nLEFT\nPRINT Y\nLEFT\nPRINT 3\nLEFT\nPRINT 2\nLEFT\nPRINT Y\nLEFT\nPRINT J\nLEFT\nPRINT Y\nLEFT\nPRINT 1\nLEFT\nPRINT U\nLEFT\nPRINT 9\nLEFT\nPRINT D\nLEFT\nPRINT B\nLEFT\nPRINT J\nLEFT\nPRINT Z\nLEFT\nPRINT C\nLEFT\nPRINT 4\nLEFT\nPRINT 9\nLEFT\nPRINT R\nLEFT\nPRINT Q\nLEFT\nPRINT 0\nLEFT\nPRINT W\nLEFT\nPRINT !\nLEFT\nPRINT M\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRIN..."
},
{
"input": "100 79\nF2.58O.L4A!QX!,.,YQUE.RZW.ENQCZKUFNG?.J6FT?L59BIHKFB?,44MAHSTD8?Z.UP3N!76YW6KVI?4AKWDPP0?3HPERM3PCUR",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT R\nLEFT\nPRINT U\nLEFT\nPRINT C\nLEFT\nPRINT P\nLEFT\nPRINT 3\nLEFT\nPRINT M\nLEFT\nPRINT R\nLEFT\nPRINT E\nLEFT\nPRINT P\nLEFT\nPRINT H\nLEFT\nPRINT 3\nLEFT\nPRINT ?\nLEFT\nPRINT 0\nLEFT\nPRINT P\nLEFT\nPRINT P\nLEFT\nPRINT D\nLEFT\nPRINT W\nLEFT\nPRINT K\nLEFT\nPRINT A\nLEFT\nPRINT 4\nLEFT\nPRINT ?\nLEFT\nPRINT I\nLEFT\nPRINT V\nLEFT\nPRINT K\nLEFT\nPRIN..."
},
{
"input": "1 1\n!",
"output": "PRINT !"
},
{
"input": "34 20\n.C0QPPSWQKGBSH0,VGM!N,5SX.M9Q,D1DT",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT T\nLEFT\nPRINT D\nLEFT\nPRINT 1\nLEFT\nPRINT D\nLEFT\nPRINT ,\nLEFT\nPRINT Q\nLEFT\nPRINT 9\nLEFT\nPRINT M\nLEFT\nPRINT .\nLEFT\nPRINT X\nLEFT\nPRINT S\nLEFT\nPRINT 5\nLEFT\nPRINT ,\nLEFT\nPRINT N\nLEFT\nPRINT !\nLEFT\nPRINT M\nLEFT\nPRINT G\nLEFT\nPRINT V\nLEFT\nPRINT ,\nLEFT\nPRINT 0\nLEFT\nPRINT H\nLEFT\nPRINT S\nLEFT\nPRINT B\nLEFT\nPRINT G\nLEFT\nPRINT K\nLEFT\nPRINT Q\nLEFT\nPRINT W\nLEFT\nPRINT S\n..."
},
{
"input": "99 98\nR8MZTEG240LNHY33H7.2CMWM73ZK,P5R,RGOA,KYKMIOG7CMPNHV3R2KM,N374IP8HN97XVMG.PSIPS8H3AXFGK0CJ76,EVKRZ9",
"output": "RIGHT\nPRINT 9\nLEFT\nPRINT Z\nLEFT\nPRINT R\nLEFT\nPRINT K\nLEFT\nPRINT V\nLEFT\nPRINT E\nLEFT\nPRINT ,\nLEFT\nPRINT 6\nLEFT\nPRINT 7\nLEFT\nPRINT J\nLEFT\nPRINT C\nLEFT\nPRINT 0\nLEFT\nPRINT K\nLEFT\nPRINT G\nLEFT\nPRINT F\nLEFT\nPRINT X\nLEFT\nPRINT A\nLEFT\nPRINT 3\nLEFT\nPRINT H\nLEFT\nPRINT 8\nLEFT\nPRINT S\nLEFT\nPRINT P\nLEFT\nPRINT I\nLEFT\nPRINT S\nLEFT\nPRINT P\nLEFT\nPRINT .\nLEFT\nPRINT G\nLEFT\nPRINT M\nLEFT\nPRINT V\nLEFT\nPRINT X\nLEFT\nPRINT 7\nLEFT\nPRINT 9\nLEFT\nPRINT N\nLEFT\nPRINT H\n..."
},
{
"input": "98 72\n.1?7CJ!EFZHO5WUKDZV,0EE92PTAGY078WKN!!41E,Q7381U60!9C,VONEZ6!SFFNDBI86MACX0?D?9!U2UV7S,977PNDSF0HY",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT Y\nLEFT\nPRINT H\nLEFT\nPRINT 0\nLEFT\nPRINT F\nLEFT\nPRINT S\nLEFT\nPRINT D\nLEFT\nPRINT N\nLEFT\nPRINT P\nLEFT\nPRINT 7\nLEFT\nPRINT 7\nLEFT\nPRINT 9\nLEFT\nPRINT ,\nLEFT\nPRINT S\nLEFT\nPRINT 7\nLEFT\nPRINT V\nLEFT\nPRINT U\nLEFT\nPRINT 2\nLEFT\nPRINT U\nLEFT\nPRINT !\nLEFT\nPRINT 9\nLEFT\nPRINT ?\nLEFT\nPRINT D\nLEFT\n..."
},
{
"input": "97 41\nGQSPZGGRZ0KWUMI79GOXP7!RR9E?Z5YO?6WUL!I7GCXRS8T,PEFQM7CZOUG8HLC7198J1?C69JD00Q!QY1AK!27I?WB?UAUIG",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT G\nRIGHT\nPRINT Q\nRIGHT\nPRINT S\nRIGHT\nPRINT P\nRIGHT\nPRINT Z\nRIGHT\nPRINT G\nRIGHT\nPRINT G\nRIGHT\nPRINT R\nRIGHT\nPRINT Z\nRIGHT\nPRINT 0\nRIGHT\nPRINT K\nRIGHT\nPRINT W\nRIGHT\nPRINT U\nRIGHT\nPRINT M\nRIGHT\nPRINT I\nRIGHT\nPRINT 7\nRIGHT\nPRINT 9\nRIGHT\n..."
},
{
"input": "96 28\nZCF!PLS27YGXHK8P46H,C.A7MW90ED,4BA!T0!XKIR2GE0HD..YZ0O20O8TA7E35G5YT3L4W5ESSYBHG8.TIQENS4I.R8WE,",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT Z\nRIGHT\nPRINT C\nRIGHT\nPRINT F\nRIGHT\nPRINT !\nRIGHT\nPRINT P\nRIGHT\nPRINT L\nRIGHT\nPRINT S\nRIGHT\nPRINT 2\nRIGHT\nPRINT 7\nRIGHT\nPRINT Y\nRIGHT\nPRINT G\nRIGHT\nPRINT X\nRIGHT\nPRINT H\nRIGHT\nPRINT K\nRIGHT\nPRINT 8\nRIGHT\nPRINT P\nRIGHT\nPRINT 4\nRIGHT\nPRINT 6\nRIGHT\nPRINT H\nRIGHT\nPRINT ,\nRIGHT\nPRINT C\nRIGHT\nPRINT .\nRIGH..."
},
{
"input": "15 3\n!..!?!,!,..,?!.",
"output": "LEFT\nLEFT\nPRINT !\nRIGHT\nPRINT .\nRIGHT\nPRINT .\nRIGHT\nPRINT !\nRIGHT\nPRINT ?\nRIGHT\nPRINT !\nRIGHT\nPRINT ,\nRIGHT\nPRINT !\nRIGHT\nPRINT ,\nRIGHT\nPRINT .\nRIGHT\nPRINT .\nRIGHT\nPRINT ,\nRIGHT\nPRINT ?\nRIGHT\nPRINT !\nRIGHT\nPRINT ."
},
{
"input": "93 81\nGMIBVKYLURQLWHBGTFNJZZAZNUJJTPQKCPGDMGCDTTGXOANWKTDZSIYBUPFUXGQHCMVIEQCTINRTIUSPGMVZPGWBHPIXC",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT C\nLEFT\nPRINT X\nLEFT\nPRINT I\nLEFT\nPRINT P\nLEFT\nPRINT H\nLEFT\nPRINT B\nLEFT\nPRINT W\nLEFT\nPRINT G\nLEFT\nPRINT P\nLEFT\nPRINT Z\nLEFT\nPRINT V\nLEFT\nPRINT M\nLEFT\nPRINT G\nLEFT\nPRINT P\nLEFT\nPRINT S\nLEFT\nPRINT U\nLEFT\nPRINT I\nLEFT\nPRINT T\nLEFT\nPRINT R\nLEFT\nPRINT N\nLEFT\nPRINT I\nLEFT\nPRINT T\nLEFT\nPRINT C\nLEFT\nPRINT Q\nLEFT\nPRINT E\nLEFT\nPRINT I\nLEFT\nPRINT V\nLEFT\nPRINT M\nLEFT\nPRINT C..."
},
{
"input": "88 30\n5847857685475132927321580125243001071762130696139249809763381765504146602574972381323476",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT 5\nRIGHT\nPRINT 8\nRIGHT\nPRINT 4\nRIGHT\nPRINT 7\nRIGHT\nPRINT 8\nRIGHT\nPRINT 5\nRIGHT\nPRINT 7\nRIGHT\nPRINT 6\nRIGHT\nPRINT 8\nRIGHT\nPRINT 5\nRIGHT\nPRINT 4\nRIGHT\nPRINT 7\nRIGHT\nPRINT 5\nRIGHT\nPRINT 1\nRIGHT\nPRINT 3\nRIGHT\nPRINT 2\nRIGHT\nPRINT 9\nRIGHT\nPRINT 2\nRIGHT\nPRINT 7\nRIGHT\nPRINT 3\nRIGHT\nPRINT 2\nRIGHT\nP..."
},
{
"input": "100 50\n5B2N,CXCWOIWH71XV!HCFEUCN3U88JDRIFRO2VHY?!N.RGH.?W14X5S.Y00RIY6YA19BPD0T,WECXYI,O2RF1U4NX9,F5AVLPOYK",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT 5\nRIGHT\nPRINT B\nRIGHT\nPRINT 2\nRIGHT\nPRINT N\nRIGHT\nPRINT ,\nRIGHT\nPRINT C\nRIGHT\nPRINT X\nRIGHT\nPRINT C\nRIGHT\nPRINT W\nRIGHT\nPRINT O\nRIGHT\nPRINT I\nRIGHT\nPRINT W\nRIGHT\nPRINT H\nRIGHT\nPRINT 7\n..."
},
{
"input": "100 51\n!X85PT!WJDNS9KA6D2SJBR,U,G7M914W07EK3EAJ4XG..UHA3KOOFYJ?M0MEFDC6KNCNGKS0A!S,C02H4TSZA1U7NDBTIY?,7XZ4",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT 4\nLEFT\nPRINT Z\nLEFT\nPRINT X\nLEFT\nPRINT 7\nLEFT\nPRINT ,\nLEFT\nPRINT ?\nLEFT\nPRINT Y\nLEFT\nPRINT I\nLEFT\nPRINT T\nLEFT\nPRINT B\nLEFT\nPRINT D\nLEFT\nPRI..."
},
{
"input": "100 52\n!MLPE.0K72RW9XKHR60QE?69ILFSIKYSK5AG!TA5.02VG5OMY0967G2RI.62CNK9L8G!7IG9F0XNNCGSDOTFD?I,EBP31HRERZSX",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT X\nLEFT\nPRINT S\nLEFT\nPRINT Z\nLEFT\nPRINT R\nLEFT\nPRINT E\nLEFT\nPRINT R\nLEFT\nPRINT H\nLEFT\nPRINT 1\nLEFT\nPRINT 3\nLEFT\nPRINT P\nLEFT\nPRINT B\nLEFT\nPRINT E\nL..."
},
{
"input": "100 49\n86C0NR7V,BE09,7,ER715OQ3GZ,P014H4BSQ5YS?OFNDD7YWI?S?UMKIWHSBDZ4398?SSDZLTDU1L?G4QVAB53HNDS!4PYW5C!VI",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT 8\nRIGHT\nPRINT 6\nRIGHT\nPRINT C\nRIGHT\nPRINT 0\nRIGHT\nPRINT N\nRIGHT\nPRINT R\nRIGHT\nPRINT 7\nRIGHT\nPRINT V\nRIGHT\nPRINT ,\nRIGHT\nPRINT B\nRIGHT\nPRINT E\nRIGHT\nPRINT 0\nRIGHT\nPRINT 9\nRIGHT\nPRINT ,\nRIGHT\n..."
},
{
"input": "100 48\nFO,IYI4AAV?4?N5PWMZX1AINZLKAUJCKMDWU4CROT?.LYWYLYU5S80,15A6VGP!V0N,O.70CP?GEA52WG59UYWU1MMMU4BERVY.!",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT F\nRIGHT\nPRINT O\nRIGHT\nPRINT ,\nRIGHT\nPRINT I\nRIGHT\nPRINT Y\nRIGHT\nPRINT I\nRIGHT\nPRINT 4\nRIGHT\nPRINT A\nRIGHT\nPRINT A\nRIGHT\nPRINT V\nRIGHT\nPRINT ?\nRIGHT\nPRINT 4\nRIGHT\nPRINT ?\nRIGHT\nPRINT N\nRIGHT\nPRINT..."
},
{
"input": "100 100\nE?F,W.,,O51!!G13ZWP?YHWRT69?RQPW7,V,EM3336F1YAIKJIME1M45?LJM42?45V7221?P.DIO9FK245LXKMR4ALKPDLA5YI2Y",
"output": "PRINT Y\nLEFT\nPRINT 2\nLEFT\nPRINT I\nLEFT\nPRINT Y\nLEFT\nPRINT 5\nLEFT\nPRINT A\nLEFT\nPRINT L\nLEFT\nPRINT D\nLEFT\nPRINT P\nLEFT\nPRINT K\nLEFT\nPRINT L\nLEFT\nPRINT A\nLEFT\nPRINT 4\nLEFT\nPRINT R\nLEFT\nPRINT M\nLEFT\nPRINT K\nLEFT\nPRINT X\nLEFT\nPRINT L\nLEFT\nPRINT 5\nLEFT\nPRINT 4\nLEFT\nPRINT 2\nLEFT\nPRINT K\nLEFT\nPRINT F\nLEFT\nPRINT 9\nLEFT\nPRINT O\nLEFT\nPRINT I\nLEFT\nPRINT D\nLEFT\nPRINT .\nLEFT\nPRINT P\nLEFT\nPRINT ?\nLEFT\nPRINT 1\nLEFT\nPRINT 2\nLEFT\nPRINT 2\nLEFT\nPRINT 7\nLEFT\nP..."
},
{
"input": "100 1\nJJ0ZOX4CY,SQ9L0K!2C9TM3C6K.6R21717I37VDSXGHBMR2!J820AI75D.O7NYMT6F.AGJ8R0RDETWOACK3P6UZAUYRKMKJ!G3WF",
"output": "PRINT J\nRIGHT\nPRINT J\nRIGHT\nPRINT 0\nRIGHT\nPRINT Z\nRIGHT\nPRINT O\nRIGHT\nPRINT X\nRIGHT\nPRINT 4\nRIGHT\nPRINT C\nRIGHT\nPRINT Y\nRIGHT\nPRINT ,\nRIGHT\nPRINT S\nRIGHT\nPRINT Q\nRIGHT\nPRINT 9\nRIGHT\nPRINT L\nRIGHT\nPRINT 0\nRIGHT\nPRINT K\nRIGHT\nPRINT !\nRIGHT\nPRINT 2\nRIGHT\nPRINT C\nRIGHT\nPRINT 9\nRIGHT\nPRINT T\nRIGHT\nPRINT M\nRIGHT\nPRINT 3\nRIGHT\nPRINT C\nRIGHT\nPRINT 6\nRIGHT\nPRINT K\nRIGHT\nPRINT .\nRIGHT\nPRINT 6\nRIGHT\nPRINT R\nRIGHT\nPRINT 2\nRIGHT\nPRINT 1\nRIGHT\nPRINT 7\nRIGHT\n..."
},
{
"input": "99 50\nLQJ!7GDFJ,SKQ8J2R?I4VA0K2.NDY.AZ?7K275NA81.YK!DO,PCQCJYL6BUU30XQ300FP0,LB!5TYTRSGOB4ELZ8IBKGVDNW8?B",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT B\nLEFT\nPRINT ?\nLEFT\nPRINT 8\nLEFT\nPRINT W\nLEFT\nPRINT N\nLEFT\nPRINT D\nLEFT\nPRINT V\nLEFT\nPRINT G\nLEFT\nPRINT K\nLEFT\nPRINT B\nLEFT\nPRINT I\nLEFT\nPRI..."
},
{
"input": "99 51\nD9QHZXG46IWHHLTD2E,AZO0.M40R4B1WU6F,0QNZ37NQ0ACSU6!7Z?H02AD?0?9,5N5RG6PVOWIE6YA9QBCOHVNU??YT6,29SAC",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT C\nLEFT\nPRINT A\nLEFT\nPRINT S\nLEFT\nPRINT 9\nLEFT\nPRINT 2\nLEFT\nPRINT ,\nLEFT\nPRINT 6\nLEFT\nPRINT T\nLEFT\nPRINT Y\nLEFT\nPRINT ?\nLEFT\nPRINT ?\nLEFT\nPRINT U\nL..."
},
{
"input": "99 49\nOLUBX0Q3VPNSH,QCAWFVSKZA3NUURJ9PXBS3?72PMJ,27QTA7Z1N?6Q2CSJE,W0YX8XWS.W6B?K?M!PYAD30BX?8.VJCC,P8QL9",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT O\nRIGHT\nPRINT L\nRIGHT\nPRINT U\nRIGHT\nPRINT B\nRIGHT\nPRINT X\nRIGHT\nPRINT 0\nRIGHT\nPRINT Q\nRIGHT\nPRINT 3\nRIGHT\nPRINT V\nRIGHT\nPRINT P\nRIGHT\nPRINT N\nRIGHT\nPRINT S\nRIGHT\nPRINT H\nRIGHT\nPRINT ,\nRIGHT\n..."
},
{
"input": "99 48\nW0GU5MNE5!JVIOO2SR5OO7RWLHDFH.HLCCX89O21SLD9!CU0MFG3RFZUFT!R0LWNVNSS.W54.67N4VAN1Q2J9NMO9Q6.UE8U6B8",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT W\nRIGHT\nPRINT 0\nRIGHT\nPRINT G\nRIGHT\nPRINT U\nRIGHT\nPRINT 5\nRIGHT\nPRINT M\nRIGHT\nPRINT N\nRIGHT\nPRINT E\nRIGHT\nPRINT 5\nRIGHT\nPRINT !\nRIGHT\nPRINT J\nRIGHT\nPRINT V\nRIGHT\nPRINT I\nRIGHT\nPRINT O\nRIGHT\nPRINT..."
},
{
"input": "2 1\nOA",
"output": "PRINT O\nRIGHT\nPRINT A"
},
{
"input": "2 2\nGW",
"output": "PRINT W\nLEFT\nPRINT G"
},
{
"input": "3 1\n.VP",
"output": "PRINT .\nRIGHT\nPRINT V\nRIGHT\nPRINT P"
},
{
"input": "3 2\nUD0",
"output": "RIGHT\nPRINT 0\nLEFT\nPRINT D\nLEFT\nPRINT U"
},
{
"input": "3 3\nMYE",
"output": "PRINT E\nLEFT\nPRINT Y\nLEFT\nPRINT M"
},
{
"input": "4 1\nC5EJ",
"output": "PRINT C\nRIGHT\nPRINT 5\nRIGHT\nPRINT E\nRIGHT\nPRINT J"
},
{
"input": "4 2\n5QSW",
"output": "LEFT\nPRINT 5\nRIGHT\nPRINT Q\nRIGHT\nPRINT S\nRIGHT\nPRINT W"
},
{
"input": "4 3\n!F3D",
"output": "RIGHT\nPRINT D\nLEFT\nPRINT 3\nLEFT\nPRINT F\nLEFT\nPRINT !"
},
{
"input": "4 4\nS!?Y",
"output": "PRINT Y\nLEFT\nPRINT ?\nLEFT\nPRINT !\nLEFT\nPRINT S"
},
{
"input": "5 1\nIP4!N",
"output": "PRINT I\nRIGHT\nPRINT P\nRIGHT\nPRINT 4\nRIGHT\nPRINT !\nRIGHT\nPRINT N"
},
{
"input": "5 2\nI7??5",
"output": "LEFT\nPRINT I\nRIGHT\nPRINT 7\nRIGHT\nPRINT ?\nRIGHT\nPRINT ?\nRIGHT\nPRINT 5"
},
{
"input": "5 3\nASNUW",
"output": "RIGHT\nRIGHT\nPRINT W\nLEFT\nPRINT U\nLEFT\nPRINT N\nLEFT\nPRINT S\nLEFT\nPRINT A"
},
{
"input": "5 4\n3?,4L",
"output": "RIGHT\nPRINT L\nLEFT\nPRINT 4\nLEFT\nPRINT ,\nLEFT\nPRINT ?\nLEFT\nPRINT 3"
},
{
"input": "5 5\n30COA",
"output": "PRINT A\nLEFT\nPRINT O\nLEFT\nPRINT C\nLEFT\nPRINT 0\nLEFT\nPRINT 3"
},
{
"input": "4 2\nABCD",
"output": "LEFT\nPRINT A\nRIGHT\nPRINT B\nRIGHT\nPRINT C\nRIGHT\nPRINT D"
}
] | 1,664,107,343 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n,k = map(int, input().split())
s = input()
a = []
for letter in s:
a.append(letter)
if k >= n//2 and k!=1:
for _ in range(n-k):
print('RIGHT' )
a = a[::-1]
for i in range(n-1):
print(f'PRINT {a[i]}')
print('LEFT')
print(f'PRINT {a[-1]}')
else:
for _ in range(n-k):
print('LEFT' )
for i in range(n-1):
print(f'PRINT {a[i]}')
print('RIGHT')
print(f'PRINT {a[-1]}') | Title: Poster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The slogan of the company consists of *n* characters, so the decorators hung a large banner, *n* meters wide and 1 meter high, divided into *n* equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.
Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the *k*-th square of the poster. To draw the *i*-th character of the slogan on the poster, you need to climb the ladder, standing in front of the *i*-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the *i*-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.
Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
Input Specification:
The first line contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
Output Specification:
In *t* lines, print the actions the programmers need to make. In the *i*-th line print:
- "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th action was to "go up the ladder, paint character *x*, go down the ladder".
The painting time (variable *t*) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
Demo Input:
['2 2\nR1\n', '2 1\nR1\n', '6 4\nGO?GO!\n']
Demo Output:
['PRINT 1\nLEFT\nPRINT R\n', 'PRINT R\nRIGHT\nPRINT 1\n', 'RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G\n']
Note:
Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character. | ```python
n,k = map(int, input().split())
s = input()
a = []
for letter in s:
a.append(letter)
if k >= n//2 and k!=1:
for _ in range(n-k):
print('RIGHT' )
a = a[::-1]
for i in range(n-1):
print(f'PRINT {a[i]}')
print('LEFT')
print(f'PRINT {a[-1]}')
else:
for _ in range(n-k):
print('LEFT' )
for i in range(n-1):
print(f'PRINT {a[i]}')
print('RIGHT')
print(f'PRINT {a[-1]}')
``` | 0 |
|
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input": "1\nqvwli hz",
"output": "1"
},
{
"input": "4\nsrhk x\nsrhk x\nqfoe vnrjuab\nqfoe vnrjuab",
"output": "2"
},
{
"input": "4\nsddqllmmpk syded\nfprsq fnenjnaz\nn hdej\nsddqllmmpk syded",
"output": "3"
},
{
"input": "17\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw",
"output": "1"
},
{
"input": "18\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nb d\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp",
"output": "2"
},
{
"input": "13\nsvpzwtwn rykzfdce\nqweiyeck jkreouy\nhk nnli\ntwxrnbbdt vtuv\nxokqjtylly sz\nesdt dbfidjslq\ng ybqgomvw\nxcpfjmf zcqvz\nifajadhj invzueip\nvdemdnxifb hckwebmi\nsdpnhipam wvowzavh\nuqdlfskhgo vunbpghae\ne dtigwnb",
"output": "13"
},
{
"input": "20\nm vkfh\nvptikamead mvx\nitu mf\nklruxckw aqega\nekqkd enjllwol\ncc uybfdh\nimrfdngvo u\ne uh\ntwt jsslcfuogk\nbljwqsag tuqbdn\nqcv q\nasx gzhvwwmajj\nqcv q\nekqkd enjllwol\nasx gzhvwwmajj\nks vv\nkzyfi cn\ncc uybfdh\nitu mf\ncjbjhtbyvk vatwfmux",
"output": "15"
},
{
"input": "2\nab ab\na bab",
"output": "2"
}
] | 1,627,320,318 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 154 | 6,758,400 | n = int(input())
bouquet = []
for i in range(n):
[s,c] = input().split()
if ([s,c] not in bouquet):
bouquet.append([s,c])
print(len(bouquet)) | Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.
Output Specification:
Output the single number — the number of Alyona's leaves.
Demo Input:
['5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n', '3\noak yellow\noak yellow\noak yellow\n']
Demo Output:
['4\n', '1\n']
Note:
none | ```python
n = int(input())
bouquet = []
for i in range(n):
[s,c] = input().split()
if ([s,c] not in bouquet):
bouquet.append([s,c])
print(len(bouquet))
``` | 3.948911 |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*. | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "100000",
"output": "50000\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "7",
"output": "3\n2 2 3"
},
{
"input": "4",
"output": "2\n2 2"
},
{
"input": "8",
"output": "4\n2 2 2 2"
},
{
"input": "9",
"output": "4\n2 2 2 3"
},
{
"input": "99995",
"output": "49997\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "99996",
"output": "49998\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "10",
"output": "5\n2 2 2 2 2"
},
{
"input": "11",
"output": "5\n2 2 2 2 3"
},
{
"input": "99997",
"output": "49998\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "99998",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "12",
"output": "6\n2 2 2 2 2 2"
},
{
"input": "13",
"output": "6\n2 2 2 2 2 3"
},
{
"input": "99993",
"output": "49996\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "99994",
"output": "49997\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "14",
"output": "7\n2 2 2 2 2 2 2"
},
{
"input": "15",
"output": "7\n2 2 2 2 2 2 3"
},
{
"input": "53",
"output": "26\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "57",
"output": "28\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "61",
"output": "30\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "774",
"output": "387\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "202",
"output": "101\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2"
},
{
"input": "530",
"output": "265\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "7166",
"output": "3583\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "9294",
"output": "4647\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "2422",
"output": "1211\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "15326",
"output": "7663\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "11454",
"output": "5727\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "14878",
"output": "7439\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "90672",
"output": "45336\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "99544",
"output": "49772\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "90472",
"output": "45236\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "23",
"output": "11\n2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "93",
"output": "46\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "19",
"output": "9\n2 2 2 2 2 2 2 2 3"
},
{
"input": "11110",
"output": "5555\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
}
] | 1,675,096,589 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 93 | 614,400 | def get_prime_list(num):
d=[]
for x in range(2,num+1):
for gg in range(2,x):
if x%gg==0:break
else:d.append(gg)
d.remove(2)
return d
def check_prime_num(num):
flag=True
if num>1:
for x in range(2,num):
if num%x == 0:
flag=False
break
else:flag=True
else:flag=False
return flag
c=0
n=int(input())
if n%2==0:
d = []
a = int(n / 2)
for x in range(a):
d.append(2)
print(a)
print(*d)
else:
d = []
a = int((n - 1) / 2)
for x in range(a-1):
d.append(2)
d.append(3)
print(len(d))
print(*d)
| Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*.
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
Output Specification:
The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
Demo Input:
['5\n', '6\n']
Demo Output:
['2\n2 3\n', '3\n2 2 2\n']
Note:
none | ```python
def get_prime_list(num):
d=[]
for x in range(2,num+1):
for gg in range(2,x):
if x%gg==0:break
else:d.append(gg)
d.remove(2)
return d
def check_prime_num(num):
flag=True
if num>1:
for x in range(2,num):
if num%x == 0:
flag=False
break
else:flag=True
else:flag=False
return flag
c=0
n=int(input())
if n%2==0:
d = []
a = int(n / 2)
for x in range(a):
d.append(2)
print(a)
print(*d)
else:
d = []
a = int((n - 1) / 2)
for x in range(a-1):
d.append(2)
d.append(3)
print(len(d))
print(*d)
``` | 3 |
|
710 | E | Generate a String | PROGRAMMING | 2,000 | [
"dfs and similar",
"dp"
] | null | null | zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of *n* letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him *x* seconds to insert or delete a letter 'a' from the text file and *y* seconds to copy the contents of the entire text file, and duplicate it.
zscoder wants to find the minimum amount of time needed for him to create the input file of exactly *n* letters 'a'. Help him to determine the amount of time needed to generate the input. | The only line contains three integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=107, 1<=≤<=*x*,<=*y*<=≤<=109) — the number of letters 'a' in the input file and the parameters from the problem statement. | Print the only integer *t* — the minimum amount of time needed to generate the input file. | [
"8 1 1\n",
"8 1 10\n"
] | [
"4\n",
"8\n"
] | none | 0 | [
{
"input": "8 1 1",
"output": "4"
},
{
"input": "8 1 10",
"output": "8"
},
{
"input": "10 62 99",
"output": "384"
},
{
"input": "88 417 591",
"output": "4623"
},
{
"input": "57 5289 8444",
"output": "60221"
},
{
"input": "382 81437847 324871127",
"output": "2519291691"
},
{
"input": "244 575154303 436759189",
"output": "5219536421"
},
{
"input": "85 902510038 553915152",
"output": "6933531064"
},
{
"input": "1926 84641582 820814219",
"output": "7184606427"
},
{
"input": "3768 561740421 232937477",
"output": "5042211408"
},
{
"input": "2313 184063453 204869248",
"output": "2969009745"
},
{
"input": "35896 278270961 253614967",
"output": "5195579310"
},
{
"input": "483867 138842067 556741142",
"output": "10712805143"
},
{
"input": "4528217 187553422 956731625",
"output": "21178755627"
},
{
"input": "10000000 1000000000 1",
"output": "8000000023"
},
{
"input": "10000000 1 100",
"output": "1757"
},
{
"input": "10000000 1 1000000000",
"output": "10000000"
},
{
"input": "10000000 1 1000",
"output": "14224"
},
{
"input": "10000000 1 10",
"output": "214"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "10000000 998 998",
"output": "30938"
},
{
"input": "9999999 987654321 123456789",
"output": "11728395036"
},
{
"input": "9999999 1 2",
"output": "54"
},
{
"input": "10000000 1 1",
"output": "31"
},
{
"input": "11478 29358 26962",
"output": "556012"
},
{
"input": "4314870 1000000000 1",
"output": "7000000022"
},
{
"input": "7186329 608148870 290497442",
"output": "12762929866"
},
{
"input": "9917781 1 1",
"output": "35"
},
{
"input": "7789084 807239576 813643932",
"output": "25165322688"
},
{
"input": "58087 1 100000000",
"output": "58087"
},
{
"input": "9999991 2 3",
"output": "88"
}
] | 1,597,077,671 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 218 | 101,580,800 | n, x, y = map(int, input().split(" "))
l = [0.]*(n+1)
for i in range(1,n+1):
l[i] = min(l[i-1]+x, l[(i+1)//2]+y+(x*(i&1)))
print(int(l[n])) | Title: Generate a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of *n* letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him *x* seconds to insert or delete a letter 'a' from the text file and *y* seconds to copy the contents of the entire text file, and duplicate it.
zscoder wants to find the minimum amount of time needed for him to create the input file of exactly *n* letters 'a'. Help him to determine the amount of time needed to generate the input.
Input Specification:
The only line contains three integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=107, 1<=≤<=*x*,<=*y*<=≤<=109) — the number of letters 'a' in the input file and the parameters from the problem statement.
Output Specification:
Print the only integer *t* — the minimum amount of time needed to generate the input file.
Demo Input:
['8 1 1\n', '8 1 10\n']
Demo Output:
['4\n', '8\n']
Note:
none | ```python
n, x, y = map(int, input().split(" "))
l = [0.]*(n+1)
for i in range(1,n+1):
l[i] = min(l[i-1]+x, l[(i+1)//2]+y+(x*(i&1)))
print(int(l[n]))
``` | 3 |
|
607 | A | Chain Reaction | PROGRAMMING | 1,600 | [
"binary search",
"dp"
] | null | null | There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated.
Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed. | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons.
The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beacons will have the same position, so *a**i*<=≠<=*a**j* if *i*<=≠<=*j*. | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | [
"4\n1 9\n3 1\n6 1\n7 4\n",
"7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n"
] | [
"1\n",
"3\n"
] | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | 500 | [
{
"input": "4\n1 9\n3 1\n6 1\n7 4",
"output": "1"
},
{
"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1",
"output": "3"
},
{
"input": "1\n0 1",
"output": "0"
},
{
"input": "1\n0 1000000",
"output": "0"
},
{
"input": "1\n1000000 1000000",
"output": "0"
},
{
"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 6\n7 7",
"output": "4"
},
{
"input": "5\n1 1\n3 1\n5 1\n7 10\n8 10",
"output": "2"
},
{
"input": "11\n110 90\n100 70\n90 10\n80 10\n70 1\n60 1\n50 10\n40 1\n30 1\n10 1\n20 1",
"output": "4"
}
] | 1,554,361,105 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 21 | 498 | 8,601,600 | n=int(input())
x=[]
for i in range(n):
a,b=map(int,input().split())
x.append((a,b))
x=sorted(x)
dest=999999999999
otv1=0
for i in range(n-1,-1,-1):
if x[i][0]<dest:
dest=x[i][0]-x[i][1]
else:
otv1+=1
dest=999999999999
otv2=1
for i in range(n-2,-1,-1):
if x[i][0]<dest:
dest=x[i][0]-x[i][1]
else:
otv2+=1
print(min(otv2,otv1)) | Title: Chain Reaction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated.
Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed.
Input Specification:
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons.
The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beacons will have the same position, so *a**i*<=≠<=*a**j* if *i*<=≠<=*j*.
Output Specification:
Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.
Demo Input:
['4\n1 9\n3 1\n6 1\n7 4\n', '7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n']
Demo Output:
['1\n', '3\n']
Note:
For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | ```python
n=int(input())
x=[]
for i in range(n):
a,b=map(int,input().split())
x.append((a,b))
x=sorted(x)
dest=999999999999
otv1=0
for i in range(n-1,-1,-1):
if x[i][0]<dest:
dest=x[i][0]-x[i][1]
else:
otv1+=1
dest=999999999999
otv2=1
for i in range(n-2,-1,-1):
if x[i][0]<dest:
dest=x[i][0]-x[i][1]
else:
otv2+=1
print(min(otv2,otv1))
``` | 0 |
|
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$.
Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all.
Some time ago Ann read the word $s$. What is the word she changed it into? | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$. | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow",
"output": "49"
},
{
"input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy",
"output": "50"
},
{
"input": "ijvxljt",
"output": "7"
},
{
"input": "fyhcncnchyf",
"output": "10"
},
{
"input": "ffffffffffff",
"output": "0"
},
{
"input": "fyhcncfsepqj",
"output": "12"
},
{
"input": "ybejrrlbcinttnicblrrjeby",
"output": "23"
},
{
"input": "yyyyyyyyyyyyyyyyyyyyyyyyy",
"output": "0"
},
{
"input": "ybejrrlbcintahovgjddrqatv",
"output": "25"
},
{
"input": "oftmhcmclgyqaojljoaqyglcmchmtfo",
"output": "30"
},
{
"input": "oooooooooooooooooooooooooooooooo",
"output": "0"
},
{
"input": "oftmhcmclgyqaojllbotztajglsmcilv",
"output": "32"
},
{
"input": "gxandbtgpbknxvnkjaajknvxnkbpgtbdnaxg",
"output": "35"
},
{
"input": "gggggggggggggggggggggggggggggggggggg",
"output": "0"
},
{
"input": "gxandbtgpbknxvnkjaygommzqitqzjfalfkk",
"output": "36"
},
{
"input": "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf",
"output": "40"
},
{
"input": "fffffffffffffffffffffffffffffffffffffffffff",
"output": "0"
},
{
"input": "fcliblymyqckxvieotjootiqwtyznhhvuhbaixwqnsy",
"output": "43"
},
{
"input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"output": "0"
},
{
"input": "rajccqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiy",
"output": "49"
},
{
"input": "a",
"output": "0"
},
{
"input": "abca",
"output": "4"
},
{
"input": "aaaaabaaaaa",
"output": "10"
},
{
"input": "aba",
"output": "2"
},
{
"input": "asaa",
"output": "4"
},
{
"input": "aabaa",
"output": "4"
},
{
"input": "aabbaa",
"output": "5"
},
{
"input": "abcdaaa",
"output": "7"
},
{
"input": "aaholaa",
"output": "7"
},
{
"input": "abcdefghijka",
"output": "12"
},
{
"input": "aaadcba",
"output": "7"
},
{
"input": "aaaabaaaa",
"output": "8"
},
{
"input": "abaa",
"output": "4"
},
{
"input": "abcbaa",
"output": "6"
},
{
"input": "ab",
"output": "2"
},
{
"input": "l",
"output": "0"
},
{
"input": "aaaabcaaaa",
"output": "10"
},
{
"input": "abbaaaaaabba",
"output": "11"
},
{
"input": "abaaa",
"output": "5"
},
{
"input": "baa",
"output": "3"
},
{
"input": "aaaaaaabbba",
"output": "11"
},
{
"input": "ccbcc",
"output": "4"
},
{
"input": "bbbaaab",
"output": "7"
},
{
"input": "abaaaaaaaa",
"output": "10"
},
{
"input": "abaaba",
"output": "5"
},
{
"input": "aabsdfaaaa",
"output": "10"
},
{
"input": "aaaba",
"output": "5"
},
{
"input": "aaabaaa",
"output": "6"
},
{
"input": "baaabbb",
"output": "7"
},
{
"input": "ccbbabbcc",
"output": "8"
},
{
"input": "cabc",
"output": "4"
},
{
"input": "aabcd",
"output": "5"
},
{
"input": "abcdea",
"output": "6"
},
{
"input": "bbabb",
"output": "4"
},
{
"input": "aaaaabababaaaaa",
"output": "14"
},
{
"input": "bbabbb",
"output": "6"
},
{
"input": "aababd",
"output": "6"
},
{
"input": "abaaaa",
"output": "6"
},
{
"input": "aaaaaaaabbba",
"output": "12"
},
{
"input": "aabca",
"output": "5"
},
{
"input": "aaabccbaaa",
"output": "9"
},
{
"input": "aaaaaaaaaaaaaaaaaaaab",
"output": "21"
},
{
"input": "babb",
"output": "4"
},
{
"input": "abcaa",
"output": "5"
},
{
"input": "qwqq",
"output": "4"
},
{
"input": "aaaaaaaaaaabbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa",
"output": "48"
},
{
"input": "aaab",
"output": "4"
},
{
"input": "aaaaaabaaaaa",
"output": "12"
},
{
"input": "wwuww",
"output": "4"
},
{
"input": "aaaaabcbaaaaa",
"output": "12"
},
{
"input": "aaabbbaaa",
"output": "8"
},
{
"input": "aabcbaa",
"output": "6"
},
{
"input": "abccdefccba",
"output": "11"
},
{
"input": "aabbcbbaa",
"output": "8"
},
{
"input": "aaaabbaaaa",
"output": "9"
},
{
"input": "aabcda",
"output": "6"
},
{
"input": "abbca",
"output": "5"
},
{
"input": "aaaaaabbaaa",
"output": "11"
},
{
"input": "sssssspssssss",
"output": "12"
},
{
"input": "sdnmsdcs",
"output": "8"
},
{
"input": "aaabbbccbbbaaa",
"output": "13"
},
{
"input": "cbdbdc",
"output": "6"
},
{
"input": "abb",
"output": "3"
},
{
"input": "abcdefaaaa",
"output": "10"
},
{
"input": "abbbaaa",
"output": "7"
},
{
"input": "v",
"output": "0"
},
{
"input": "abccbba",
"output": "7"
},
{
"input": "axyza",
"output": "5"
},
{
"input": "abcdefgaaaa",
"output": "11"
},
{
"input": "aaabcdaaa",
"output": "9"
},
{
"input": "aaaacaaaa",
"output": "8"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaa",
"output": "42"
},
{
"input": "abbbaa",
"output": "6"
},
{
"input": "abcdee",
"output": "6"
},
{
"input": "oom",
"output": "3"
},
{
"input": "aabcaa",
"output": "6"
},
{
"input": "abba",
"output": "3"
},
{
"input": "aaca",
"output": "4"
},
{
"input": "aacbca",
"output": "6"
},
{
"input": "ababa",
"output": "4"
},
{
"input": "abcda",
"output": "5"
},
{
"input": "cccaaccc",
"output": "7"
},
{
"input": "aaabcda",
"output": "7"
},
{
"input": "aa",
"output": "0"
},
{
"input": "aabaaaa",
"output": "7"
},
{
"input": "abbaaaa",
"output": "7"
},
{
"input": "aaabcbaaa",
"output": "8"
},
{
"input": "aabba",
"output": "5"
},
{
"input": "xyxx",
"output": "4"
},
{
"input": "aaaaaaaaaaaabc",
"output": "14"
},
{
"input": "bbaaaabb",
"output": "7"
},
{
"input": "aaabaa",
"output": "6"
},
{
"input": "sssssabsssss",
"output": "12"
},
{
"input": "bbbaaaabbb",
"output": "9"
},
{
"input": "abbbbaaaa",
"output": "9"
},
{
"input": "wwufuww",
"output": "6"
},
{
"input": "oowoo",
"output": "4"
},
{
"input": "cccaccc",
"output": "6"
},
{
"input": "aaa",
"output": "0"
},
{
"input": "bbbcc",
"output": "5"
},
{
"input": "abcdef",
"output": "6"
},
{
"input": "abbba",
"output": "4"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaba",
"output": "4"
},
{
"input": "azbyaaa",
"output": "7"
},
{
"input": "oooooiooooo",
"output": "10"
},
{
"input": "aabbbbbaaaaaa",
"output": "13"
}
] | 1,660,154,197 | 2,147,483,647 | Python 3 | OK | TESTS | 133 | 46 | 0 | s = input()
print(0 if s[1:]==s[:-1] else len(s)-1 if s==s[::-1] else len(s)) | Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$.
Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all.
Some time ago Ann read the word $s$. What is the word she changed it into?
Input Specification:
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
Output Specification:
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
Demo Input:
['mew\n', 'wuffuw\n', 'qqqqqqqq\n']
Demo Output:
['3\n', '5\n', '0\n']
Note:
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$. | ```python
s = input()
print(0 if s[1:]==s[:-1] else len(s)-1 if s==s[::-1] else len(s))
``` | 3 |
|
658 | A | Bear and Reverse Radewoosh | PROGRAMMING | 800 | [
"implementation"
] | null | null | Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by difficulty — it's guaranteed that *p**i*<=<<=*p**i*<=+<=1 and *t**i*<=<<=*t**i*<=+<=1.
A constant *c* is given too, representing the speed of loosing points. Then, submitting the *i*-th problem at time *x* (*x* minutes after the start of the contest) gives *max*(0,<= *p**i*<=-<=*c*·*x*) points.
Limak is going to solve problems in order 1,<=2,<=...,<=*n* (sorted increasingly by *p**i*). Radewoosh is going to solve them in order *n*,<=*n*<=-<=1,<=...,<=1 (sorted decreasingly by *p**i*). Your task is to predict the outcome — print the name of the winner (person who gets more points at the end) or a word "Tie" in case of a tie.
You may assume that the duration of the competition is greater or equal than the sum of all *t**i*. That means both Limak and Radewoosh will accept all *n* problems. | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=<<=*p**i*<=+<=1) — initial scores.
The third line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000,<=*t**i*<=<<=*t**i*<=+<=1) where *t**i* denotes the number of minutes one needs to solve the *i*-th problem. | Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. | [
"3 2\n50 85 250\n10 15 25\n",
"3 6\n50 85 250\n10 15 25\n",
"8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n"
] | [
"Limak\n",
"Radewoosh\n",
"Tie\n"
] | In the first sample, there are 3 problems. Limak solves them as follows:
1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85 - 2·25 = 35 points. 1. He spends 25 minutes on the 3-rd problem so he submits it 10 + 15 + 25 = 50 minutes after the start. For this problem he gets 250 - 2·50 = 150 points.
So, Limak got 30 + 35 + 150 = 215 points.
Radewoosh solves problem in the reversed order:
1. Radewoosh solves 3-rd problem after 25 minutes so he gets 250 - 2·25 = 200 points. 1. He spends 15 minutes on the 2-nd problem so he submits it 25 + 15 = 40 minutes after the start. He gets 85 - 2·40 = 5 points for this problem. 1. He spends 10 minutes on the 1-st problem so he submits it 25 + 15 + 10 = 50 minutes after the start. He gets *max*(0, 50 - 2·50) = *max*(0, - 50) = 0 points.
Radewoosh got 200 + 5 + 0 = 205 points in total. Limak has 215 points so Limak wins.
In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250 - 6·25 = 100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway.
In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2 + 2 = 4. | 500 | [
{
"input": "3 2\n50 85 250\n10 15 25",
"output": "Limak"
},
{
"input": "3 6\n50 85 250\n10 15 25",
"output": "Radewoosh"
},
{
"input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76",
"output": "Tie"
},
{
"input": "4 1\n3 5 6 9\n1 2 4 8",
"output": "Limak"
},
{
"input": "4 1\n1 3 6 10\n1 5 7 8",
"output": "Radewoosh"
},
{
"input": "4 1\n2 4 5 10\n2 3 9 10",
"output": "Tie"
},
{
"input": "18 4\n68 97 121 132 146 277 312 395 407 431 458 461 595 634 751 855 871 994\n1 2 3 4 9 10 13 21 22 29 31 34 37 38 39 41 48 49",
"output": "Radewoosh"
},
{
"input": "50 1\n5 14 18 73 137 187 195 197 212 226 235 251 262 278 287 304 310 322 342 379 393 420 442 444 448 472 483 485 508 515 517 523 559 585 618 627 636 646 666 682 703 707 780 853 937 951 959 989 991 992\n30 84 113 173 199 220 235 261 266 277 300 306 310 312 347 356 394 396 397 409 414 424 446 462 468 487 507 517 537 566 594 643 656 660 662 668 706 708 773 774 779 805 820 827 868 896 929 942 961 995",
"output": "Tie"
},
{
"input": "4 1\n4 6 9 10\n2 3 4 5",
"output": "Radewoosh"
},
{
"input": "4 1\n4 6 9 10\n3 4 5 7",
"output": "Radewoosh"
},
{
"input": "4 1\n1 6 7 10\n2 7 8 10",
"output": "Tie"
},
{
"input": "4 1\n4 5 7 9\n1 4 5 8",
"output": "Limak"
},
{
"input": "50 1\n6 17 44 82 94 127 134 156 187 211 212 252 256 292 294 303 352 355 379 380 398 409 424 434 480 524 584 594 631 714 745 756 777 778 789 793 799 821 841 849 859 878 879 895 925 932 944 952 958 990\n15 16 40 42 45 71 99 100 117 120 174 181 186 204 221 268 289 332 376 394 403 409 411 444 471 487 499 539 541 551 567 589 619 623 639 669 689 722 735 776 794 822 830 840 847 907 917 927 936 988",
"output": "Radewoosh"
},
{
"input": "50 10\n25 49 52 73 104 117 127 136 149 164 171 184 226 251 257 258 286 324 337 341 386 390 428 453 464 470 492 517 543 565 609 634 636 660 678 693 710 714 729 736 739 749 781 836 866 875 956 960 977 979\n2 4 7 10 11 22 24 26 27 28 31 35 37 38 42 44 45 46 52 53 55 56 57 59 60 61 64 66 67 68 69 71 75 76 77 78 79 81 83 85 86 87 89 90 92 93 94 98 99 100",
"output": "Limak"
},
{
"input": "50 10\n11 15 25 71 77 83 95 108 143 150 182 183 198 203 213 223 279 280 346 348 350 355 375 376 412 413 415 432 470 545 553 562 589 595 607 633 635 637 688 719 747 767 771 799 842 883 905 924 942 944\n1 3 5 6 7 10 11 12 13 14 15 16 19 20 21 23 25 32 35 36 37 38 40 41 42 43 47 50 51 54 55 56 57 58 59 60 62 63 64 65 66 68 69 70 71 72 73 75 78 80",
"output": "Radewoosh"
},
{
"input": "32 6\n25 77 141 148 157 159 192 196 198 244 245 255 332 392 414 457 466 524 575 603 629 700 738 782 838 841 845 847 870 945 984 985\n1 2 4 5 8 9 10 12 13 14 15 16 17 18 20 21 22 23 24 26 28 31 38 39 40 41 42 43 45 47 48 49",
"output": "Radewoosh"
},
{
"input": "5 1\n256 275 469 671 842\n7 9 14 17 26",
"output": "Limak"
},
{
"input": "2 1000\n1 2\n1 2",
"output": "Tie"
},
{
"input": "3 1\n1 50 809\n2 8 800",
"output": "Limak"
},
{
"input": "1 13\n866\n10",
"output": "Tie"
},
{
"input": "15 1\n9 11 66 128 199 323 376 386 393 555 585 718 935 960 971\n3 11 14 19 20 21 24 26 32 38 40 42 44 47 50",
"output": "Limak"
},
{
"input": "1 10\n546\n45",
"output": "Tie"
},
{
"input": "50 20\n21 43 51 99 117 119 158 167 175 190 196 244 250 316 335 375 391 403 423 428 451 457 460 480 487 522 539 559 566 584 598 602 604 616 626 666 675 730 771 787 828 841 861 867 886 889 898 970 986 991\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",
"output": "Limak"
},
{
"input": "50 21\n13 20 22 38 62 84 118 135 141 152 170 175 194 218 227 229 232 253 260 263 278 313 329 357 396 402 422 452 454 533 575 576 580 594 624 644 653 671 676 759 789 811 816 823 831 833 856 924 933 987\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",
"output": "Tie"
},
{
"input": "1 36\n312\n42",
"output": "Tie"
},
{
"input": "1 1000\n1\n1000",
"output": "Tie"
},
{
"input": "1 1\n1000\n1",
"output": "Tie"
},
{
"input": "50 35\n9 17 28 107 136 152 169 174 186 188 201 262 291 312 324 330 341 358 385 386 393 397 425 431 479 498 502 523 530 540 542 554 578 588 622 623 684 696 709 722 784 819 836 845 850 932 945 969 983 984\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",
"output": "Tie"
},
{
"input": "50 20\n12 113 116 120 138 156 167 183 185 194 211 228 234 261 278 287 310 317 346 361 364 397 424 470 496 522 527 536 611 648 668 704 707 712 717 752 761 766 815 828 832 864 872 885 889 901 904 929 982 993\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",
"output": "Limak"
}
] | 1,579,277,028 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 139 | 0 | n,c=map(int,input().split())
arr=list(map(int,input().split()))
t=list(map(int,input().split()))
x=0
point1=0
for i in range(n):
x+=t[i]
point1+=(arr[i]-c*x)
x=0
point2=0
for i in range(n-1,-1,-1):
x+=t[i]
point2+=(arr[i]-c*x)
if point1>point2:
print("Limak")
elif point2==point1:
print("Tie")
else:
print("Radewoosh") | Title: Bear and Reverse Radewoosh
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by difficulty — it's guaranteed that *p**i*<=<<=*p**i*<=+<=1 and *t**i*<=<<=*t**i*<=+<=1.
A constant *c* is given too, representing the speed of loosing points. Then, submitting the *i*-th problem at time *x* (*x* minutes after the start of the contest) gives *max*(0,<= *p**i*<=-<=*c*·*x*) points.
Limak is going to solve problems in order 1,<=2,<=...,<=*n* (sorted increasingly by *p**i*). Radewoosh is going to solve them in order *n*,<=*n*<=-<=1,<=...,<=1 (sorted decreasingly by *p**i*). Your task is to predict the outcome — print the name of the winner (person who gets more points at the end) or a word "Tie" in case of a tie.
You may assume that the duration of the competition is greater or equal than the sum of all *t**i*. That means both Limak and Radewoosh will accept all *n* problems.
Input Specification:
The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=<<=*p**i*<=+<=1) — initial scores.
The third line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000,<=*t**i*<=<<=*t**i*<=+<=1) where *t**i* denotes the number of minutes one needs to solve the *i*-th problem.
Output Specification:
Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points.
Demo Input:
['3 2\n50 85 250\n10 15 25\n', '3 6\n50 85 250\n10 15 25\n', '8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n']
Demo Output:
['Limak\n', 'Radewoosh\n', 'Tie\n']
Note:
In the first sample, there are 3 problems. Limak solves them as follows:
1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85 - 2·25 = 35 points. 1. He spends 25 minutes on the 3-rd problem so he submits it 10 + 15 + 25 = 50 minutes after the start. For this problem he gets 250 - 2·50 = 150 points.
So, Limak got 30 + 35 + 150 = 215 points.
Radewoosh solves problem in the reversed order:
1. Radewoosh solves 3-rd problem after 25 minutes so he gets 250 - 2·25 = 200 points. 1. He spends 15 minutes on the 2-nd problem so he submits it 25 + 15 = 40 minutes after the start. He gets 85 - 2·40 = 5 points for this problem. 1. He spends 10 minutes on the 1-st problem so he submits it 25 + 15 + 10 = 50 minutes after the start. He gets *max*(0, 50 - 2·50) = *max*(0, - 50) = 0 points.
Radewoosh got 200 + 5 + 0 = 205 points in total. Limak has 215 points so Limak wins.
In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250 - 6·25 = 100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway.
In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2 + 2 = 4. | ```python
n,c=map(int,input().split())
arr=list(map(int,input().split()))
t=list(map(int,input().split()))
x=0
point1=0
for i in range(n):
x+=t[i]
point1+=(arr[i]-c*x)
x=0
point2=0
for i in range(n-1,-1,-1):
x+=t[i]
point2+=(arr[i]-c*x)
if point1>point2:
print("Limak")
elif point2==point1:
print("Tie")
else:
print("Radewoosh")
``` | 0 |
|
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10",
"output": "0"
},
{
"input": "8 20",
"output": "0"
},
{
"input": "2 8",
"output": "0"
},
{
"input": "20 11",
"output": "0"
},
{
"input": "57 447",
"output": "1"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "66 296",
"output": "1"
},
{
"input": "75 683",
"output": "1"
},
{
"input": "227 975",
"output": "1"
},
{
"input": "247 499",
"output": "1"
},
{
"input": "266 116",
"output": "1"
},
{
"input": "286 916",
"output": "1"
},
{
"input": "307 341",
"output": "1"
},
{
"input": "451 121",
"output": "1"
},
{
"input": "471 921",
"output": "1"
},
{
"input": "502 346",
"output": "1"
},
{
"input": "535 59",
"output": "1"
},
{
"input": "555 699",
"output": "1"
},
{
"input": "747 351",
"output": "1"
},
{
"input": "790 64",
"output": "1"
},
{
"input": "810 704",
"output": "1"
},
{
"input": "855 225",
"output": "1"
},
{
"input": "902 34",
"output": "1"
},
{
"input": "922 514",
"output": "1"
},
{
"input": "971 131",
"output": "1"
},
{
"input": "991 931",
"output": "1"
},
{
"input": "840 780",
"output": "0"
},
{
"input": "102 595",
"output": "0"
},
{
"input": "139 433",
"output": "0"
},
{
"input": "968 288",
"output": "0"
},
{
"input": "563 354",
"output": "0"
},
{
"input": "994 975",
"output": "0"
},
{
"input": "456 221",
"output": "0"
},
{
"input": "205 210",
"output": "0"
},
{
"input": "1 11",
"output": "0"
},
{
"input": "1000 1000",
"output": "0"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "11 99",
"output": "0"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "11 1",
"output": "0"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "100 452",
"output": "0"
},
{
"input": "420 380",
"output": "0"
},
{
"input": "31 31",
"output": "0"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "112 134",
"output": "0"
},
{
"input": "13 13",
"output": "0"
},
{
"input": "1 571",
"output": "0"
}
] | 1,662,636,345 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 124 | 409,600 | from re import A
n,m = map(int,input().split())
res = 0
for a in range(int(n**0.5) + 1):
b = n - a**2
if (a + b**2) == m:
res+=1
print(res) | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
Input Specification:
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
Output Specification:
On a single line print the answer to the problem.
Demo Input:
['9 3\n', '14 28\n', '4 20\n']
Demo Output:
['1\n', '1\n', '0\n']
Note:
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | ```python
from re import A
n,m = map(int,input().split())
res = 0
for a in range(int(n**0.5) + 1):
b = n - a**2
if (a + b**2) == m:
res+=1
print(res)
``` | 3 |
|
886 | A | ACM ICPC | PROGRAMMING | 1,000 | [
"brute force"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 500 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
"input": "353 313 327 470 597 31",
"output": "NO"
},
{
"input": "835 638 673 624 232 266",
"output": "NO"
},
{
"input": "936 342 19 398 247 874",
"output": "NO"
},
{
"input": "417 666 978 553 271 488",
"output": "NO"
},
{
"input": "71 66 124 199 67 147",
"output": "YES"
},
{
"input": "54 26 0 171 239 12",
"output": "YES"
},
{
"input": "72 8 186 92 267 69",
"output": "YES"
},
{
"input": "180 179 188 50 75 214",
"output": "YES"
},
{
"input": "16 169 110 136 404 277",
"output": "YES"
},
{
"input": "101 400 9 200 300 10",
"output": "YES"
},
{
"input": "101 400 200 9 300 10",
"output": "YES"
},
{
"input": "101 200 400 9 300 10",
"output": "YES"
},
{
"input": "101 400 200 300 9 10",
"output": "YES"
},
{
"input": "101 200 400 300 9 10",
"output": "YES"
},
{
"input": "4 4 4 4 5 4",
"output": "NO"
},
{
"input": "2 2 2 2 2 1",
"output": "NO"
},
{
"input": "1000 1000 999 1000 1000 1000",
"output": "NO"
},
{
"input": "129 1 10 29 8 111",
"output": "NO"
},
{
"input": "1000 1000 1000 999 999 1000",
"output": "YES"
},
{
"input": "101 200 300 400 9 10",
"output": "YES"
},
{
"input": "101 400 200 300 10 9",
"output": "YES"
},
{
"input": "101 200 400 300 10 9",
"output": "YES"
},
{
"input": "101 200 300 400 10 9",
"output": "YES"
},
{
"input": "101 200 300 10 400 9",
"output": "YES"
},
{
"input": "1 1 1 1 1 5",
"output": "NO"
},
{
"input": "8 1 1 3 3 0",
"output": "NO"
},
{
"input": "1 1 2 2 3 3",
"output": "YES"
},
{
"input": "1 2 2 5 2 5",
"output": "NO"
},
{
"input": "1 2 3 6 6 6",
"output": "NO"
},
{
"input": "36 91 7 86 51 89",
"output": "NO"
},
{
"input": "10 1 1 1 23 24",
"output": "NO"
},
{
"input": "1 1 1 10 23 24",
"output": "NO"
},
{
"input": "20 10 1 2 3 44",
"output": "NO"
},
{
"input": "7 0 14 11 8 6",
"output": "NO"
},
{
"input": "100 496 1 1 1 1",
"output": "NO"
},
{
"input": "5 4 2 5 11 3",
"output": "NO"
},
{
"input": "1 3 7 8 8 9",
"output": "YES"
},
{
"input": "1 3 4 5 18 19",
"output": "YES"
},
{
"input": "5 5 1 2 2 15",
"output": "NO"
},
{
"input": "2 1 0 0 0 5",
"output": "NO"
},
{
"input": "1 6 6 1 20 2",
"output": "NO"
},
{
"input": "2 10 0 0 0 0",
"output": "NO"
},
{
"input": "1 1 3 1 1 11",
"output": "NO"
},
{
"input": "10 10 1 1 1 37",
"output": "NO"
},
{
"input": "1 1 0 0 0 4",
"output": "NO"
},
{
"input": "1 1 10 1 1 28",
"output": "NO"
},
{
"input": "1 5 5 5 6 8",
"output": "YES"
},
{
"input": "0 2 3 4 4 5",
"output": "YES"
}
] | 1,510,510,104 | 7,404 | Python 3 | WRONG_ANSWER | CHALLENGES | 0 | 62 | 0 | def strenght(power, summ):
for i in range(len(power)):
for j in range(i + 1, len(power) - 1):
if (power[i] + power[j] + power[j + 1]) == summ - (power[i] + power[j] + power[j + 1]):
return 'YES'
return 'NO'
power = list(map(int, input().split()))
summ = sum(power)
print(strenght(power, summ))
| Title: ACM ICPC
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
Input Specification:
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Output Specification:
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Demo Input:
['1 3 2 1 2 1\n', '1 1 1 1 1 99\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | ```python
def strenght(power, summ):
for i in range(len(power)):
for j in range(i + 1, len(power) - 1):
if (power[i] + power[j] + power[j + 1]) == summ - (power[i] + power[j] + power[j + 1]):
return 'YES'
return 'NO'
power = list(map(int, input().split()))
summ = sum(power)
print(strenght(power, summ))
``` | 0 |
|
817 | B | Makes And The Product | PROGRAMMING | 1,500 | [
"combinatorics",
"implementation",
"math",
"sortings"
] | null | null | After returning from the army Makes received a gift — an array *a* consisting of *n* positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (*i*,<= *j*,<= *k*) (*i*<=<<=*j*<=<<=*k*), such that *a**i*·*a**j*·*a**k* is minimum possible, are there in the array? Help him with it! | The first line of input contains a positive integer number *n* (3<=≤<=*n*<=≤<=105) — the number of elements in array *a*. The second line contains *n* positive integer numbers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of a given array. | Print one number — the quantity of triples (*i*,<= *j*,<= *k*) such that *i*,<= *j* and *k* are pairwise distinct and *a**i*·*a**j*·*a**k* is minimum possible. | [
"4\n1 1 1 1\n",
"5\n1 3 2 3 4\n",
"6\n1 3 3 1 3 2\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.
In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.
In the third example a triple of numbers (1, 1, 2) is chosen, and there's only one way to choose indices. | 0 | [
{
"input": "4\n1 1 1 1",
"output": "4"
},
{
"input": "5\n1 3 2 3 4",
"output": "2"
},
{
"input": "6\n1 3 3 1 3 2",
"output": "1"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "4\n1 1 2 2",
"output": "2"
},
{
"input": "3\n1 3 1",
"output": "1"
},
{
"input": "11\n1 2 2 2 2 2 2 2 2 2 2",
"output": "45"
},
{
"input": "5\n1 2 2 2 2",
"output": "6"
},
{
"input": "6\n1 2 2 3 3 4",
"output": "1"
},
{
"input": "8\n1 1 2 2 2 3 3 3",
"output": "3"
},
{
"input": "6\n1 2 2 2 2 3",
"output": "6"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "6\n1 2 2 2 3 3",
"output": "3"
},
{
"input": "6\n1 2 2 2 2 2",
"output": "10"
},
{
"input": "4\n1 2 2 2",
"output": "3"
},
{
"input": "5\n1 2 3 2 3",
"output": "1"
},
{
"input": "6\n2 2 3 3 3 3",
"output": "4"
},
{
"input": "6\n1 2 2 2 5 6",
"output": "3"
},
{
"input": "10\n1 2 2 2 2 2 2 2 2 2",
"output": "36"
},
{
"input": "3\n2 1 2",
"output": "1"
},
{
"input": "5\n1 2 3 3 3",
"output": "3"
},
{
"input": "6\n1 2 2 2 4 5",
"output": "3"
},
{
"input": "4\n1 2 2 3",
"output": "1"
},
{
"input": "10\n2 2 2 2 2 1 2 2 2 2",
"output": "36"
},
{
"input": "7\n2 2 2 3 3 3 1",
"output": "3"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "5\n1 1 2 2 2",
"output": "3"
},
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "9\n2 2 3 3 3 3 3 3 3",
"output": "7"
},
{
"input": "5\n1 1 2 2 3",
"output": "2"
},
{
"input": "4\n1 1 3 3",
"output": "2"
},
{
"input": "4\n33554432 33554432 67108864 33554432",
"output": "1"
},
{
"input": "6\n2 2 2 1 2 2",
"output": "10"
},
{
"input": "10\n1 2 1 2 3 2 3 2 2 2",
"output": "6"
},
{
"input": "10\n9 6 4 7 1 8 9 5 9 4",
"output": "1"
},
{
"input": "4\n5 7 2 7",
"output": "2"
},
{
"input": "3\n7 6 7",
"output": "1"
},
{
"input": "6\n3 2 8 2 5 3",
"output": "2"
},
{
"input": "3\n5 9 5",
"output": "1"
},
{
"input": "5\n6 3 7 6 3",
"output": "2"
},
{
"input": "9\n10 10 4 10 7 9 6 7 3",
"output": "1"
},
{
"input": "5\n9 10 10 3 8",
"output": "1"
},
{
"input": "5\n2 9 5 10 5",
"output": "1"
},
{
"input": "9\n7 1 9 6 6 8 3 1 3",
"output": "2"
},
{
"input": "5\n3 4 4 4 5",
"output": "3"
},
{
"input": "3\n3 1 3",
"output": "1"
},
{
"input": "8\n3 2 2 5 2 2 1 2",
"output": "10"
}
] | 1,497,836,769 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 155 | 8,806,400 | n = input()
a = input()
a = a.split(' ')
a = list(map(int,a))
b = [10**9,10**9,10**9]
for i in a:
if i < b[0]:
b[0] = i
elif i < b[1]:
b[1] = i
elif i < b[2]:
b[2] = i
if len(set(b)) == 1:
s = 0
for i in a:
if i == b[0]:
s += 1
print(int(s*(s-1)*(s-2)/6))
elif len(set(b)) == 2:
s,t = 0,0
for i in a:
if i == b[0]:
s += 1
elif i == b[2]:
t += 1
if b[1] == b[0]:
print(int(s*(s-1)/2)*t)
else:
print(int(t*(t-1)/2)*s)
else:
s,t,r = 0,0,0
for i in a:
if i == b[0]:
s += 1
elif i == b[1]:
t += 1
elif i == b[2]:
r += 1
print(s*t*r)
| Title: Makes And The Product
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After returning from the army Makes received a gift — an array *a* consisting of *n* positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (*i*,<= *j*,<= *k*) (*i*<=<<=*j*<=<<=*k*), such that *a**i*·*a**j*·*a**k* is minimum possible, are there in the array? Help him with it!
Input Specification:
The first line of input contains a positive integer number *n* (3<=≤<=*n*<=≤<=105) — the number of elements in array *a*. The second line contains *n* positive integer numbers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of a given array.
Output Specification:
Print one number — the quantity of triples (*i*,<= *j*,<= *k*) such that *i*,<= *j* and *k* are pairwise distinct and *a**i*·*a**j*·*a**k* is minimum possible.
Demo Input:
['4\n1 1 1 1\n', '5\n1 3 2 3 4\n', '6\n1 3 3 1 3 2\n']
Demo Output:
['4\n', '2\n', '1\n']
Note:
In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.
In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.
In the third example a triple of numbers (1, 1, 2) is chosen, and there's only one way to choose indices. | ```python
n = input()
a = input()
a = a.split(' ')
a = list(map(int,a))
b = [10**9,10**9,10**9]
for i in a:
if i < b[0]:
b[0] = i
elif i < b[1]:
b[1] = i
elif i < b[2]:
b[2] = i
if len(set(b)) == 1:
s = 0
for i in a:
if i == b[0]:
s += 1
print(int(s*(s-1)*(s-2)/6))
elif len(set(b)) == 2:
s,t = 0,0
for i in a:
if i == b[0]:
s += 1
elif i == b[2]:
t += 1
if b[1] == b[0]:
print(int(s*(s-1)/2)*t)
else:
print(int(t*(t-1)/2)*s)
else:
s,t,r = 0,0,0
for i in a:
if i == b[0]:
s += 1
elif i == b[1]:
t += 1
elif i == b[2]:
r += 1
print(s*t*r)
``` | 0 |
|
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
"input": "oops",
"output": "oops"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "a"
},
{
"input": "aA",
"output": "Aa"
},
{
"input": "Zz",
"output": "Zz"
},
{
"input": "Az",
"output": "Az"
},
{
"input": "zA",
"output": "Za"
},
{
"input": "AAA",
"output": "aaa"
},
{
"input": "AAa",
"output": "AAa"
},
{
"input": "AaR",
"output": "AaR"
},
{
"input": "Tdr",
"output": "Tdr"
},
{
"input": "aTF",
"output": "Atf"
},
{
"input": "fYd",
"output": "fYd"
},
{
"input": "dsA",
"output": "dsA"
},
{
"input": "fru",
"output": "fru"
},
{
"input": "hYBKF",
"output": "Hybkf"
},
{
"input": "XweAR",
"output": "XweAR"
},
{
"input": "mogqx",
"output": "mogqx"
},
{
"input": "eOhEi",
"output": "eOhEi"
},
{
"input": "nkdku",
"output": "nkdku"
},
{
"input": "zcnko",
"output": "zcnko"
},
{
"input": "lcccd",
"output": "lcccd"
},
{
"input": "vwmvg",
"output": "vwmvg"
},
{
"input": "lvchf",
"output": "lvchf"
},
{
"input": "IUNVZCCHEWENCHQQXQYPUJCRDZLUXCLJHXPHBXEUUGNXOOOPBMOBRIBHHMIRILYJGYYGFMTMFSVURGYHUWDRLQVIBRLPEVAMJQYO",
"output": "iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgyygfmtmfsvurgyhuwdrlqvibrlpevamjqyo"
},
{
"input": "OBHSZCAMDXEJWOZLKXQKIVXUUQJKJLMMFNBPXAEFXGVNSKQLJGXHUXHGCOTESIVKSFMVVXFVMTEKACRIWALAGGMCGFEXQKNYMRTG",
"output": "obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksfmvvxfvmtekacriwalaggmcgfexqknymrtg"
},
{
"input": "IKJYZIKROIYUUCTHSVSKZTETNNOCMAUBLFJCEVANCADASMZRCNLBZPQRXESHEEMOMEPCHROSRTNBIDXYMEPJSIXSZQEBTEKKUHFS",
"output": "ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemomepchrosrtnbidxymepjsixszqebtekkuhfs"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "uCKJZRGZJCPPLEEYJTUNKOQSWGBMTBQEVPYFPIPEKRVYQNTDPANOIXKMPINNFUSZWCURGBDPYTEKBEKCPMVZPMWAOSHJYMGKOMBQ",
"output": "Uckjzrgzjcppleeyjtunkoqswgbmtbqevpyfpipekrvyqntdpanoixkmpinnfuszwcurgbdpytekbekcpmvzpmwaoshjymgkombq"
},
{
"input": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR",
"output": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR"
},
{
"input": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE",
"output": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE"
},
{
"input": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ",
"output": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ"
},
{
"input": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm",
"output": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm"
},
{
"input": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm",
"output": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm"
},
{
"input": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg",
"output": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg"
},
{
"input": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc",
"output": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc"
},
{
"input": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv",
"output": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv"
},
{
"input": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect",
"output": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu",
"output": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu"
},
{
"input": "aBACABa",
"output": "aBACABa"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAaa",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAaa"
},
{
"input": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
},
{
"input": "dDDDDDDDDDDDDD",
"output": "Dddddddddddddd"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "z",
"output": "Z"
},
{
"input": "AZ",
"output": "az"
},
{
"input": "Z",
"output": "z"
},
{
"input": "aAAAA",
"output": "Aaaaa"
},
{
"input": "F",
"output": "f"
}
] | 1,689,165,408 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | # https://codeforces.com/problemset/problem/131/A
s = input()
if s.isupper():
print(s.lower())
elif s[0].islower() and s[1:].isupper():
print(s[0].upper() + s[1:].lower())
else:
print(s) | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input Specification:
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output Specification:
Print the result of the given word's processing.
Demo Input:
['cAPS\n', 'Lock\n']
Demo Output:
['Caps', 'Lock\n']
Note:
none | ```python
# https://codeforces.com/problemset/problem/131/A
s = input()
if s.isupper():
print(s.lower())
elif s[0].islower() and s[1:].isupper():
print(s[0].upper() + s[1:].lower())
else:
print(s)
``` | 0 |
|
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all *x* that meet the problem conditions. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*. | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "0"
},
{
"input": "6\n2 6 3 8 7 2",
"output": "5\n2 5\n3 0\n6 0\n7 0\n8 0"
},
{
"input": "7\n2 1 2 1 2 1 2",
"output": "2\n1 2\n2 2"
},
{
"input": "8\n1 1 1 1 1 1 1 1",
"output": "1\n1 1"
},
{
"input": "9\n2 3 3 3 2 1 2 3 2",
"output": "1\n1 0"
},
{
"input": "10\n3 1 1 1 1 3 1 2 2 1",
"output": "2\n2 1\n3 5"
},
{
"input": "12\n10 9 8 7 7 8 9 10 10 9 8 7",
"output": "0"
}
] | 1,639,670,661 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 |
n = int(input())
lst = list(map(int,input().split()))
st = set(lst)
dct = {}
for i in st:
if lst.count(i) == 1:
dct[i] = [99]
else:
for x in range(n):
if i==lst[x]:
if i in dct:
dct[i].append(x)
else:
dct[i]=[x]
dc={}
for a,b in dct.items():
if len(b)==1:
dc[a] = 0
else:
cd1 = b[1]-b[0]
for i in range(len(b)-1):
cd = b[i+1] - b[i]
if cd != cd1:
break
else:
dc[a] = cd
print(len(dc))
for f,k in dc.items():
print(f"{f} {k}")
| Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all *x* that meet the problem conditions.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces.
Output Specification:
In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*.
Demo Input:
['1\n2\n', '8\n1 2 1 3 1 2 1 5\n']
Demo Output:
['1\n2 0\n', '4\n1 2\n2 4\n3 0\n5 0\n']
Note:
In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | ```python
n = int(input())
lst = list(map(int,input().split()))
st = set(lst)
dct = {}
for i in st:
if lst.count(i) == 1:
dct[i] = [99]
else:
for x in range(n):
if i==lst[x]:
if i in dct:
dct[i].append(x)
else:
dct[i]=[x]
dc={}
for a,b in dct.items():
if len(b)==1:
dc[a] = 0
else:
cd1 = b[1]-b[0]
for i in range(len(b)-1):
cd = b[i+1] - b[i]
if cd != cd1:
break
else:
dc[a] = cd
print(len(dc))
for f,k in dc.items():
print(f"{f} {k}")
``` | 0 |
|
584 | A | Olesya and Rodion | PROGRAMMING | 1,000 | [
"math"
] | null | null | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1. | The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. | Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. | [
"3 2\n"
] | [
"712"
] | none | 500 | [
{
"input": "3 2",
"output": "222"
},
{
"input": "2 2",
"output": "22"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 3",
"output": "33333"
},
{
"input": "10 7",
"output": "7777777777"
},
{
"input": "2 9",
"output": "99"
},
{
"input": "18 8",
"output": "888888888888888888"
},
{
"input": "1 5",
"output": "5"
},
{
"input": "1 10",
"output": "-1"
},
{
"input": "100 5",
"output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "10 2",
"output": "2222222222"
},
{
"input": "18 10",
"output": "111111111111111110"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "7 6",
"output": "6666666"
},
{
"input": "4 4",
"output": "4444"
},
{
"input": "14 7",
"output": "77777777777777"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "2 8",
"output": "88"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 9",
"output": "99999"
},
{
"input": "4 8",
"output": "8888"
},
{
"input": "3 4",
"output": "444"
},
{
"input": "9 4",
"output": "444444444"
},
{
"input": "8 10",
"output": "11111110"
},
{
"input": "1 6",
"output": "6"
},
{
"input": "20 3",
"output": "33333333333333333333"
},
{
"input": "15 10",
"output": "111111111111110"
},
{
"input": "31 4",
"output": "4444444444444444444444444444444"
},
{
"input": "18 9",
"output": "999999999999999999"
},
{
"input": "72 4",
"output": "444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "76 8",
"output": "8888888888888888888888888888888888888888888888888888888888888888888888888888"
},
{
"input": "12 5",
"output": "555555555555"
},
{
"input": "54 5",
"output": "555555555555555555555555555555555555555555555555555555"
},
{
"input": "96 10",
"output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "15 9",
"output": "999999999999999"
},
{
"input": "100 2",
"output": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
},
{
"input": "99 3",
"output": "333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"
},
{
"input": "98 4",
"output": "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "97 5",
"output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "100 6",
"output": "6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
},
{
"input": "99 7",
"output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "98 8",
"output": "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
},
{
"input": "97 9",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
},
{
"input": "100 10",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "3 10",
"output": "110"
},
{
"input": "2 4",
"output": "44"
},
{
"input": "2 10",
"output": "10"
},
{
"input": "10 10",
"output": "1111111110"
},
{
"input": "4 10",
"output": "1110"
},
{
"input": "25 10",
"output": "1111111111111111111111110"
},
{
"input": "50 10",
"output": "11111111111111111111111111111111111111111111111110"
},
{
"input": "5 10",
"output": "11110"
},
{
"input": "99 10",
"output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "100 10",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "20 10",
"output": "11111111111111111110"
},
{
"input": "99 7",
"output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "89 5",
"output": "55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "6 10",
"output": "111110"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "100 7",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
}
] | 1,679,783,008 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 46 | 0 | import sys
n, t = map(int, input().split())
if n == 1 and t == 10:
print("-1")
sys.exit()
if t == 10:
t = 1
print(t, end="")
for i in range(1, n):
print("0", end="") | Title: Olesya and Rodion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1.
Input Specification:
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Output Specification:
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
Demo Input:
['3 2\n']
Demo Output:
['712']
Note:
none | ```python
import sys
n, t = map(int, input().split())
if n == 1 and t == 10:
print("-1")
sys.exit()
if t == 10:
t = 1
print(t, end="")
for i in range(1, n):
print("0", end="")
``` | 3 |
|
740 | A | Alyona and copybooks | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks.
What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. | The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109). | Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4. | [
"1 1 3 4\n",
"6 2 1 1\n",
"4 4 4 4\n",
"999999999 1000000000 1000000000 1000000000\n"
] | [
"3\n",
"1\n",
"0\n",
"1000000000\n"
] | In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.
In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total.
In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything.
In the fourth example Alyona should buy one pack of one copybook. | 500 | [
{
"input": "1 1 3 4",
"output": "3"
},
{
"input": "6 2 1 1",
"output": "1"
},
{
"input": "4 4 4 4",
"output": "0"
},
{
"input": "999999999 1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "1016 3 2 1",
"output": "0"
},
{
"input": "17 100 100 1",
"output": "1"
},
{
"input": "17 2 3 100",
"output": "5"
},
{
"input": "18 1 3 3",
"output": "2"
},
{
"input": "19 1 1 1",
"output": "1"
},
{
"input": "999999997 999999990 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "999999998 1000000000 999999990 1000000000",
"output": "999999990"
},
{
"input": "634074578 336470888 481199252 167959139",
"output": "335918278"
},
{
"input": "999999999 1000000000 1000000000 999999990",
"output": "1000000000"
},
{
"input": "804928248 75475634 54748096 641009859",
"output": "0"
},
{
"input": "535590429 374288891 923264237 524125987",
"output": "524125987"
},
{
"input": "561219907 673102149 496813081 702209411",
"output": "673102149"
},
{
"input": "291882089 412106895 365329221 585325539",
"output": "585325539"
},
{
"input": "757703054 5887448 643910770 58376259",
"output": "11774896"
},
{
"input": "783332532 449924898 72235422 941492387",
"output": "0"
},
{
"input": "513994713 43705451 940751563 824608515",
"output": "131116353"
},
{
"input": "539624191 782710197 514300407 2691939",
"output": "8075817"
},
{
"input": "983359971 640274071 598196518 802030518",
"output": "640274071"
},
{
"input": "8989449 379278816 26521171 685146646",
"output": "405799987"
},
{
"input": "34618927 678092074 895037311 863230070",
"output": "678092074"
},
{
"input": "205472596 417096820 468586155 41313494",
"output": "0"
},
{
"input": "19 5 1 2",
"output": "3"
},
{
"input": "17 1 2 2",
"output": "2"
},
{
"input": "18 3 3 1",
"output": "2"
},
{
"input": "19 4 3 1",
"output": "3"
},
{
"input": "936134778 715910077 747167704 219396918",
"output": "438793836"
},
{
"input": "961764255 454914823 615683844 102513046",
"output": "307539138"
},
{
"input": "692426437 48695377 189232688 985629174",
"output": "146086131"
},
{
"input": "863280107 347508634 912524637 458679894",
"output": "347508634"
},
{
"input": "593942288 86513380 486073481 341796022",
"output": "0"
},
{
"input": "914539062 680293934 764655030 519879446",
"output": "764655030"
},
{
"input": "552472140 509061481 586588704 452405440",
"output": "0"
},
{
"input": "723325809 807874739 160137548 335521569",
"output": "335521569"
},
{
"input": "748955287 546879484 733686393 808572289",
"output": "546879484"
},
{
"input": "774584765 845692742 162011045 691688417",
"output": "691688417"
},
{
"input": "505246946 439473295 30527185 869771841",
"output": "30527185"
},
{
"input": "676100616 178478041 604076030 752887969",
"output": "0"
},
{
"input": "701730093 477291299 177624874 930971393",
"output": "654916173"
},
{
"input": "432392275 216296044 751173719 109054817",
"output": "216296044"
},
{
"input": "458021753 810076598 324722563 992170945",
"output": "992170945"
},
{
"input": "188683934 254114048 48014511 170254369",
"output": "48014511"
},
{
"input": "561775796 937657403 280013594 248004555",
"output": "0"
},
{
"input": "1000000000 1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "3 10000 10000 3",
"output": "9"
},
{
"input": "3 12 3 4",
"output": "7"
},
{
"input": "3 10000 10000 1",
"output": "3"
},
{
"input": "3 1000 1000 1",
"output": "3"
},
{
"input": "3 10 10 1",
"output": "3"
},
{
"input": "3 100 100 1",
"output": "3"
},
{
"input": "3 100000 10000 1",
"output": "3"
},
{
"input": "7 10 2 3",
"output": "5"
},
{
"input": "3 1000 1000 2",
"output": "6"
},
{
"input": "1 100000 1 100000",
"output": "100000"
},
{
"input": "7 4 3 1",
"output": "3"
},
{
"input": "3 1000 1000 3",
"output": "9"
},
{
"input": "3 1000 1 1",
"output": "2"
},
{
"input": "3 10 1 1",
"output": "2"
},
{
"input": "3 100000 1 1",
"output": "2"
},
{
"input": "3 100 1 1",
"output": "2"
},
{
"input": "3 100000 100000 1",
"output": "3"
},
{
"input": "3 1000 1 100",
"output": "101"
},
{
"input": "3 1000000000 1 1000000000",
"output": "1000000000"
},
{
"input": "3 1000 1 10",
"output": "11"
},
{
"input": "3 200 1 100",
"output": "101"
},
{
"input": "7 4 1 1",
"output": "2"
},
{
"input": "7 4 12 1",
"output": "3"
},
{
"input": "3 9 1 1",
"output": "2"
},
{
"input": "3 10000000 1000000 1",
"output": "3"
},
{
"input": "7 1000 1000 1",
"output": "3"
},
{
"input": "3 10000 1 30",
"output": "31"
},
{
"input": "3 1000 1 2",
"output": "3"
},
{
"input": "7 12 6 1",
"output": "3"
},
{
"input": "3 100000 1 1000",
"output": "1001"
},
{
"input": "7 1000 1000 3",
"output": "9"
},
{
"input": "3 4 3 1",
"output": "3"
},
{
"input": "3 3000000 1 100000",
"output": "100001"
},
{
"input": "3 3 1 1",
"output": "2"
},
{
"input": "3 10 1 5",
"output": "6"
},
{
"input": "3 2000 2000 1",
"output": "3"
},
{
"input": "3 10000000 10000000 1",
"output": "3"
},
{
"input": "3 5 1 1",
"output": "2"
},
{
"input": "3 100 1 33",
"output": "34"
},
{
"input": "7 9 2 7",
"output": "9"
},
{
"input": "4448 2 3 6",
"output": "0"
},
{
"input": "2228 1 6 3",
"output": "0"
}
] | 1,679,439,452 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 46 | 0 | entrada = input().split(" ")
lista = []
for i in entrada:
lista.append(int(i))
qntLivros = lista[0]
qntLivrosComprar = 0
while qntLivros % 4 != 0:
qntLivros+=1
qntLivrosComprar += 1
opcoes = []
rubles = 0
cp = qntLivrosComprar // 3
if(qntLivros != 0):
for c in range(cp + 1):
for b in range((qntLivrosComprar - c * 3) // 2 + 1):
for a in range((qntLivrosComprar - c * 3 - b * 2) // 1 + 1):
if(c * 3 + b * 2 + a * 1 == qntLivrosComprar):
rubles = c * lista[3] + b * lista[2] + a * lista[1]
opcoes.append(rubles)
print(min(opcoes))
| Title: Alyona and copybooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks.
What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.
Input Specification:
The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109).
Output Specification:
Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4.
Demo Input:
['1 1 3 4\n', '6 2 1 1\n', '4 4 4 4\n', '999999999 1000000000 1000000000 1000000000\n']
Demo Output:
['3\n', '1\n', '0\n', '1000000000\n']
Note:
In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.
In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total.
In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything.
In the fourth example Alyona should buy one pack of one copybook. | ```python
entrada = input().split(" ")
lista = []
for i in entrada:
lista.append(int(i))
qntLivros = lista[0]
qntLivrosComprar = 0
while qntLivros % 4 != 0:
qntLivros+=1
qntLivrosComprar += 1
opcoes = []
rubles = 0
cp = qntLivrosComprar // 3
if(qntLivros != 0):
for c in range(cp + 1):
for b in range((qntLivrosComprar - c * 3) // 2 + 1):
for a in range((qntLivrosComprar - c * 3 - b * 2) // 1 + 1):
if(c * 3 + b * 2 + a * 1 == qntLivrosComprar):
rubles = c * lista[3] + b * lista[2] + a * lista[1]
opcoes.append(rubles)
print(min(opcoes))
``` | 0 |
|
394 | A | Counting Sticks | PROGRAMMING | 0 | [
"brute force",
"implementation"
] | null | null | When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if *A*<=+<=*B*<==<=*C*.
We've got an expression that looks like *A*<=+<=*B*<==<=*C* given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us? | The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100. | If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples. | [
"||+|=|||||\n",
"|||||+||=||\n",
"|+|=||||||\n",
"||||+||=||||||\n"
] | [
"|||+|=||||\n",
"Impossible\n",
"Impossible\n",
"||||+||=||||||\n"
] | In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks. | 500 | [
{
"input": "||+|=|||||",
"output": "|||+|=||||"
},
{
"input": "|||||+||=||",
"output": "Impossible"
},
{
"input": "|+|=||||||",
"output": "Impossible"
},
{
"input": "||||+||=||||||",
"output": "||||+||=||||||"
},
{
"input": "||||||||||||+|||||||||||=||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "||||||||||||||||||+||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "|||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||=|||||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+|=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+|=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "|+|=|",
"output": "Impossible"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "|||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "|||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "|||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||=|",
"output": "Impossible"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|",
"output": "Impossible"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||=|",
"output": "Impossible"
},
{
"input": "|||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||||||||=|",
"output": "Impossible"
},
{
"input": "||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||+|=|",
"output": "|+|=||"
},
{
"input": "|+||=|",
"output": "|+|=||"
},
{
"input": "|+|=||",
"output": "|+|=||"
},
{
"input": "|||+|=|",
"output": "Impossible"
},
{
"input": "|||+|=|",
"output": "Impossible"
},
{
"input": "|||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "|+|=|||",
"output": "Impossible"
},
{
"input": "|+|=||||",
"output": "||+|=|||"
},
{
"input": "|+||=|",
"output": "|+|=||"
},
{
"input": "|+||||||=|||||",
"output": "|+|||||=||||||"
},
{
"input": "|+|||=||",
"output": "|+||=|||"
},
{
"input": "|+||||=|||",
"output": "|+|||=||||"
},
{
"input": "|+|||||=||||",
"output": "|+||||=|||||"
},
{
"input": "||+||=||",
"output": "|+||=|||"
},
{
"input": "||+|||=|||",
"output": "|+|||=||||"
},
{
"input": "|||||+||=||||||||||",
"output": "Impossible"
},
{
"input": "|||+|||=||||",
"output": "||+|||=|||||"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "|||||+|||||=||||||||||||",
"output": "||||||+|||||=|||||||||||"
},
{
"input": "||+|||||||=|||||||",
"output": "|+|||||||=||||||||"
},
{
"input": "||||+||||=||||||",
"output": "|||+||||=|||||||"
},
{
"input": "||||+|||=|||||",
"output": "|||+|||=||||||"
},
{
"input": "||+|||=|||||||",
"output": "|||+|||=||||||"
},
{
"input": "||+|=|",
"output": "|+|=||"
},
{
"input": "|||+|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "||+|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||+|=||||||",
"output": "Impossible"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "Impossible"
}
] | 1,544,560,835 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 21 | 124 | 0 | import sys
g = input()
g = list(g)
l = 0
for i in range(len(g)):
if g[i] == '+':
a = g[0:i]
l = i
if g[i] == '=':
b = g[l+1:i]
c = g[i+1:len(g)]
a1 = len(a)
b1 = len(b)
c1 = len(c)
if a1+b1 == c1:
print(''.join(g))
sys.exit()
if c1 > a1+b1:
if c1-1 == a1 + b1 + 1:
del g[-1]
g.insert(0,'|')
print(''.join(g))
sys.exit()
else:
print('Impossible')
sys.exit()
else:
if c1+1 == a1 + b1 - 1:
del g[0]
g.insert(-1,'|')
print(''.join(g))
else:
print('Impossible')
| Title: Counting Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if *A*<=+<=*B*<==<=*C*.
We've got an expression that looks like *A*<=+<=*B*<==<=*C* given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input Specification:
The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100.
Output Specification:
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Demo Input:
['||+|=|||||\n', '|||||+||=||\n', '|+|=||||||\n', '||||+||=||||||\n']
Demo Output:
['|||+|=||||\n', 'Impossible\n', 'Impossible\n', '||||+||=||||||\n']
Note:
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks. | ```python
import sys
g = input()
g = list(g)
l = 0
for i in range(len(g)):
if g[i] == '+':
a = g[0:i]
l = i
if g[i] == '=':
b = g[l+1:i]
c = g[i+1:len(g)]
a1 = len(a)
b1 = len(b)
c1 = len(c)
if a1+b1 == c1:
print(''.join(g))
sys.exit()
if c1 > a1+b1:
if c1-1 == a1 + b1 + 1:
del g[-1]
g.insert(0,'|')
print(''.join(g))
sys.exit()
else:
print('Impossible')
sys.exit()
else:
if c1+1 == a1 + b1 - 1:
del g[0]
g.insert(-1,'|')
print(''.join(g))
else:
print('Impossible')
``` | 0 |
|
735 | A | Ostap and Grasshopper | PROGRAMMING | 800 | [
"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. | 500 | [
{
"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"
}
] | 1,593,939,859 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 109 | 6,963,200 | nk = input().split()
n = int(nk[0])
k = int(nk[1])
s = input()
g_ind = 0
t_ind = 0
for i in range(0, n):
if(s[i] == 'G'):
g_ind = i
elif(s[i] == 'T'):
t_ind = i
start = 0
end =0
if(g_ind < t_ind):
start = g_ind
end = t_ind
else:
start = t_ind
end = g_ind
res = True
if((end - start) % k != 0):
res = False
else:
while (start < end):
if (s[start] == '#'):
res = False
break
start += k
if(res):
print('YES')
else:
print('NO')
| Title: Ostap and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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.
Input Specification:
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.
Output Specification:
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).
Demo Input:
['5 2\n#G#T#\n', '6 1\nT....G\n', '7 3\nT..#..G\n', '6 2\n..GT..\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n', 'NO\n']
Note:
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. | ```python
nk = input().split()
n = int(nk[0])
k = int(nk[1])
s = input()
g_ind = 0
t_ind = 0
for i in range(0, n):
if(s[i] == 'G'):
g_ind = i
elif(s[i] == 'T'):
t_ind = i
start = 0
end =0
if(g_ind < t_ind):
start = g_ind
end = t_ind
else:
start = t_ind
end = g_ind
res = True
if((end - start) % k != 0):
res = False
else:
while (start < end):
if (s[start] == '#'):
res = False
break
start += k
if(res):
print('YES')
else:
print('NO')
``` | 3 |
|
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"input": "10\n50 50 50 50 50 50 50 50 50 50",
"output": "NO"
},
{
"input": "10\n100 100 100 100 100 100 100 100 100 100",
"output": "NO"
},
{
"input": "7\n25 25 25 25 50 100 50",
"output": "YES"
},
{
"input": "2\n25 25",
"output": "YES"
},
{
"input": "3\n50 100 100",
"output": "NO"
},
{
"input": "3\n25 50 50",
"output": "NO"
},
{
"input": "2\n50 25",
"output": "NO"
},
{
"input": "14\n25 25 25 25 25 25 25 50 50 50 100 100 100 100",
"output": "NO"
},
{
"input": "5\n25 25 25 100 100",
"output": "NO"
},
{
"input": "7\n25 50 25 50 25 50 100",
"output": "NO"
},
{
"input": "5\n25 50 25 50 100",
"output": "NO"
},
{
"input": "5\n25 25 50 50 50",
"output": "NO"
},
{
"input": "5\n25 25 50 100 50",
"output": "NO"
},
{
"input": "5\n25 25 50 50 100",
"output": "NO"
},
{
"input": "1\n50",
"output": "NO"
}
] | 1,668,362,744 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 186 | 5,324,800 | kackisi = int(input())
k = list(map(int,input().split()))
sayi25 = 0
sayi50 = 0
true = 0
for i in k:
if i == 25:
sayi25 += 1
if i == 50:
sayi25 -= 1
sayi50 += 1
if i == 100:
if sayi50 == 0:
sayi25 -= 3
else:
sayi50 -= 1
sayi25 -= 1
if sayi25 < 0 or sayi50 < 0:
print("NO")
true = 1
break
if true == 0:
print("YES")
| Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.
Output Specification:
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
Demo Input:
['4\n25 25 50 50\n', '2\n25 100\n', '4\n50 50 25 25\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
kackisi = int(input())
k = list(map(int,input().split()))
sayi25 = 0
sayi50 = 0
true = 0
for i in k:
if i == 25:
sayi25 += 1
if i == 50:
sayi25 -= 1
sayi50 += 1
if i == 100:
if sayi50 == 0:
sayi25 -= 3
else:
sayi50 -= 1
sayi25 -= 1
if sayi25 < 0 or sayi50 < 0:
print("NO")
true = 1
break
if true == 0:
print("YES")
``` | 3 |
|
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate. | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 4",
"output": "10"
},
{
"input": "40\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1",
"output": "2"
},
{
"input": "67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n71 9\n72 10\n74 5\n76 4\n77 9\n80 7\n81 9\n82 5\n83 5\n84 9\n85 7\n86 9\n87 4\n88 7\n89 10\n90 3\n91 5\n92 10\n93 5\n94 8\n95 4\n96 2\n97 10\n98 1\n99 3\n100 1\n101 5\n102 4\n103 8\n104 8\n105 8",
"output": "5"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "10\n7 12\n10 2\n12 2\n15 1\n19 2\n20 1\n53 25\n63 10\n75 12\n87 1",
"output": "9"
},
{
"input": "3\n1 1\n1000 1000\n1000000000 1000000000",
"output": "3"
},
{
"input": "2\n1 999999999\n1000000000 1000000000",
"output": "2"
},
{
"input": "10\n999999900 1000000000\n999999901 1000000000\n999999902 1000000000\n999999903 1000000000\n999999904 1000000000\n999999905 1000000000\n999999906 1000000000\n999999907 1000000000\n999999908 1000000000\n999999909 1000000000",
"output": "2"
},
{
"input": "2\n100000000 1000000000\n1000000000 1000000000",
"output": "2"
}
] | 1,697,793,071 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n = int(input())
tree = {}
tree_cutdown = 2
for _ in range(n):
x,h = map(int,input().split())
tree[x] = h
m = max(tree.keys())
tree_point = [0]*(m+1)
for i in tree.items():
tree_point[i[0]] = 1
i = 2
while i < m:
if tree_point[i]:
if tree_point[i-tree[i]:i] == [0]*tree[i]:
tree_cutdown += 1
tree_point[i-tree[i]:i] == [1]*tree[i]
i += 1
elif tree_point[i+1:i+tree[i]+1] == [0]*tree[i]:
tree_cutdown += 1
tree_point[i+1:i+tree[i]+1] == [1]*tree[i]
i += (tree[i] + 1)
else:
i += 1
else:
i += 1
print(tree_cutdown) | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate.
Output Specification:
Print a single number — the maximum number of trees that you can cut down by the given rules.
Demo Input:
['5\n1 2\n2 1\n5 10\n10 9\n19 1\n', '5\n1 2\n2 1\n5 10\n10 9\n20 1\n']
Demo Output:
['3\n', '4\n']
Note:
In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | ```python
n = int(input())
tree = {}
tree_cutdown = 2
for _ in range(n):
x,h = map(int,input().split())
tree[x] = h
m = max(tree.keys())
tree_point = [0]*(m+1)
for i in tree.items():
tree_point[i[0]] = 1
i = 2
while i < m:
if tree_point[i]:
if tree_point[i-tree[i]:i] == [0]*tree[i]:
tree_cutdown += 1
tree_point[i-tree[i]:i] == [1]*tree[i]
i += 1
elif tree_point[i+1:i+tree[i]+1] == [0]*tree[i]:
tree_cutdown += 1
tree_point[i+1:i+tree[i]+1] == [1]*tree[i]
i += (tree[i] + 1)
else:
i += 1
else:
i += 1
print(tree_cutdown)
``` | 0 |
|
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*. | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "100000",
"output": "50000\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "7",
"output": "3\n2 2 3"
},
{
"input": "4",
"output": "2\n2 2"
},
{
"input": "8",
"output": "4\n2 2 2 2"
},
{
"input": "9",
"output": "4\n2 2 2 3"
},
{
"input": "99995",
"output": "49997\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "99996",
"output": "49998\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "10",
"output": "5\n2 2 2 2 2"
},
{
"input": "11",
"output": "5\n2 2 2 2 3"
},
{
"input": "99997",
"output": "49998\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "99998",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "12",
"output": "6\n2 2 2 2 2 2"
},
{
"input": "13",
"output": "6\n2 2 2 2 2 3"
},
{
"input": "99993",
"output": "49996\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "99994",
"output": "49997\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "14",
"output": "7\n2 2 2 2 2 2 2"
},
{
"input": "15",
"output": "7\n2 2 2 2 2 2 3"
},
{
"input": "53",
"output": "26\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "57",
"output": "28\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "61",
"output": "30\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "774",
"output": "387\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "202",
"output": "101\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2"
},
{
"input": "530",
"output": "265\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "7166",
"output": "3583\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "9294",
"output": "4647\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "2422",
"output": "1211\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "15326",
"output": "7663\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "11454",
"output": "5727\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "14878",
"output": "7439\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "90672",
"output": "45336\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "99544",
"output": "49772\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "90472",
"output": "45236\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "23",
"output": "11\n2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "93",
"output": "46\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "19",
"output": "9\n2 2 2 2 2 2 2 2 3"
},
{
"input": "11110",
"output": "5555\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
}
] | 1,658,299,613 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 93 | 614,400 | n = int(input())
if not n % 2:
print(n // 2)
print(*[2 for _ in range(n // 2)])
else:
print(1 + (n - 3) // 2)
print(3, *[2 for _ in range((n - 3) // 2)]) | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*.
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
Output Specification:
The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
Demo Input:
['5\n', '6\n']
Demo Output:
['2\n2 3\n', '3\n2 2 2\n']
Note:
none | ```python
n = int(input())
if not n % 2:
print(n // 2)
print(*[2 for _ in range(n // 2)])
else:
print(1 + (n - 3) // 2)
print(3, *[2 for _ in range((n - 3) // 2)])
``` | 3 |
|
946 | C | String Transformation | PROGRAMMING | 1,300 | [
"greedy",
"strings"
] | null | null | You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible. | The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters. | If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes). | [
"aacceeggiikkmmooqqssuuwwyy\n",
"thereisnoanswer\n"
] | [
"abcdefghijklmnopqrstuvwxyz\n",
"-1\n"
] | none | 0 | [
{
"input": "aacceeggiikkmmooqqssuuwwyy",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "thereisnoanswer",
"output": "-1"
},
{
"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs",
"output": "-1"
},
{
"input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaendlpbfuylqgxtndhmhqgbsknsy",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaa"
},
{
"input": "abcdefghijklmnopqrstuvwxxx",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvwxya",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "cdaaaaaaaaabcdjklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "cdabcdefghijklmnopqrstuvwxyzxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
},
{
"input": "zazaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zazbcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abbbefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaa"
},
{
"input": "abcdefghijklmaopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvwxyx",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaz"
},
{
"input": "zaaaazaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zabcdzefghijklmnopqrstuvwxyzaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaa"
},
{
"input": "aaaaaafghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyzz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaz"
},
{
"input": "abcdefghijklmnopqrstuvwaxy",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaa"
},
{
"input": "abcdefghijklmnapqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvnxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaa"
},
{
"input": "abcdefghijklmnopqrstuvwxyzzzz",
"output": "abcdefghijklmnopqrstuvwxyzzzz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aacceeggiikkmmooqqssuuwwya",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aacdefghijklmnopqrstuvwxyyy",
"output": "abcdefghijklmnopqrstuvwxyzy"
},
{
"input": "abcaefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "zaaacaaaaaaaaaaaaaaaaaaaayy",
"output": "zabcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdedccdcdccdcdcdcdcdcddccdcdcdc",
"output": "abcdefghijklmnopqrstuvwxyzcdcdcdc"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "abcdecdcdcddcdcdcdcdcdcdcd",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "a",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaa"
},
{
"input": "aaadefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaa"
},
{
"input": "abbbbbbbbbbbbbbbbbbbbbbbbz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aacceeggiikkmmaacceeggiikkmmooaacceeggiikkmmaacceeggiikkmmooqqssuuwwzy",
"output": "abcdefghijklmnopqrstuvwxyzmmooaacceeggiikkmmaacceeggiikkmmooqqssuuwwzy"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "phqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvsrtkjprepggxrpnrvystmwcysyycqpevikeffmznimkkasvwsrenzkycxf",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaap",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "zabcdefghijklmnopqrstuvwxyz",
"output": "zabcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyza"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzabcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "rveviaomdienfygifatviahordebxazoxflfgzslhyzowhxbhqzpsgellkoimnwkvhpbijorhpggwfjexivpqbcbmqjyghkbq",
"output": "rveviaomdienfygifbtvichordefxgzoxhlijzslkyzowlxmnqzpsopqrstuvwxyzhpbijorhpggwfjexivpqbcbmqjyghkbq"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "xtlsgypsfadpooefxzbcoejuvpvaboygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovaowuxwhmsncbxcoksfzkvatxdknly",
"output": "xtlsgypsfadpooefxzbcoejuvpvdeoygpofylgphnpljvrvipyjmyklwqnqrqpmxunopqrvstwuxwvwxyzbxcoksfzkvatxdknly"
},
{
"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxsa",
"output": "jqcfvsavebixhiocdefphgmsmhijkylwsmpynoypqrxstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldbefsarcbynecdyggxxpklorellnmpapqfwkhopkmcoqh",
"output": "wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldcefsdrefynghiyjkxxplmornopqrstuvwxyzopkmcoqh"
},
{
"input": "abadefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "zazsazcbbbbbbbbbbbbbbbbbbbbbbb",
"output": "zazsbzcdefghijklmnopqrstuvwxyz"
},
{
"input": "zazsazcbbbbbbbbbbbbbbbbbbbbbyb",
"output": "zazsbzcdefghijklmnopqrstuvwxyz"
},
{
"input": "bbcdefghijklmnopqrstuvwxyzzz",
"output": "-1"
},
{
"input": "zaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zabcdefghijklmnopqrstuvwxyz"
},
{
"input": "zzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zzzzzabcdefghijklmnopqrstuvwxyza"
},
{
"input": "kkimnfjbbgggicykcciwtoazomcvisigagkjwhyrmojmoebnqoadpmockfjxibdtvrbedrsdoundbcpkfdqdidqdmxdltink",
"output": "kkimnfjbbgggicykcciwtoazomcvisigbgkjwhyrmojmoecnqodepmofkgjxihitvrjklrsmounopqrstuvwxyzdmxdltink"
},
{
"input": "cawgathqceccscakbazmhwbefvygjbcfyihcbgga",
"output": "-1"
},
{
"input": "acrsbyszsbfslzbqzzamcmrypictkcheddehvxdipaxaannjodzyfxgtfnwababzjraapqbqbfzhbiewlzz",
"output": "acrsbyszscfslzdqzzemfmrypigtkhijklmnvxopqrxstuvwxyzyfxgtfnwababzjraapqbqbfzhbiewlzz"
},
{
"input": "ggcebbheeblbioxdvtlrtkxeuilonazpebcbqpzz",
"output": "-1"
},
{
"input": "zzzzabcdefghijklmnopqrstuvwxy",
"output": "-1"
},
{
"input": "zabcdefghijklmnopqrstuvwxy",
"output": "-1"
},
{
"input": "babcdefghijklmnopqrstuvwxyz",
"output": "babcdefghijklmnopqrstuvwxyz"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
] | 1,595,438,262 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 139 | 7,270,400 | def solve(s):
if len(s)<26:
return -1
n = len(s)
lis = list('abcdefghijklmnopqrstuvwxyz')
curr = 0
for i in range(n):
if lis.index(s[i])<=curr:
#print(s)
s[i] = lis[curr]
curr += 1
if curr == 26:
break
if curr == 26:
return "".join(s)
return -1
s = list(input())
print(solve(s)) | Title: String Transformation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible.
Input Specification:
The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters.
Output Specification:
If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes).
Demo Input:
['aacceeggiikkmmooqqssuuwwyy\n', 'thereisnoanswer\n']
Demo Output:
['abcdefghijklmnopqrstuvwxyz\n', '-1\n']
Note:
none | ```python
def solve(s):
if len(s)<26:
return -1
n = len(s)
lis = list('abcdefghijklmnopqrstuvwxyz')
curr = 0
for i in range(n):
if lis.index(s[i])<=curr:
#print(s)
s[i] = lis[curr]
curr += 1
if curr == 26:
break
if curr == 26:
return "".join(s)
return -1
s = list(input())
print(solve(s))
``` | 3 |
|
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him. | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nckcccbj\nccbcbcc\ncccbccc\nccbcbcc\ncbcccbc\nbccccdt",
"output": "NO"
},
{
"input": "13\nsooooooooooos\nosoooooooooso\noosooooooosoo\nooosooooosooo\noooosooosoooo\nooooososooooo\noooooosoooooo\nooooososooooo\noooosooosoooo\nooosooooosooo\noosooooooosoo\nosoooooooooso\nsooooooooooos",
"output": "YES"
},
{
"input": "3\naaa\naaa\naaa",
"output": "NO"
},
{
"input": "3\naca\noec\nzba",
"output": "NO"
},
{
"input": "15\nrxeeeeeeeeeeeer\nereeeeeeeeeeere\needeeeeeeeeeoee\neeereeeeeeeewee\neeeereeeeebeeee\nqeeeereeejedyee\neeeeeerereeeeee\neeeeeeereeeeeee\neeeeeerereeeeze\neeeeereeereeeee\neeeereeeeegeeee\neeereeeeeeereee\neereeeeeeqeeved\ncreeeeeeceeeere\nreeerneeeeeeeer",
"output": "NO"
},
{
"input": "5\nxxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxx",
"output": "NO"
},
{
"input": "5\nxxxxx\nxxxxx\nxoxxx\nxxxxx\nxxxxx",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\nxxxxx\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\nxxoox\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\nxxaxx\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\noxoxx\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "3\nxxx\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxx\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxa\nxxx",
"output": "NO"
},
{
"input": "3\nxax\nxxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naaa\nxax",
"output": "NO"
},
{
"input": "3\naax\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxaa\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxa\naax",
"output": "NO"
},
{
"input": "3\nxax\naxa\nxaa",
"output": "NO"
},
{
"input": "3\nxfx\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\nafa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxa\nxaf",
"output": "NO"
},
{
"input": "3\nxox\nxxx\nxxx",
"output": "NO"
},
{
"input": "3\naxa\naax\nxxa",
"output": "NO"
},
{
"input": "3\nxox\noxx\nxox",
"output": "NO"
},
{
"input": "3\nxox\nooo\nxox",
"output": "NO"
},
{
"input": "3\naaa\naab\nbbb",
"output": "NO"
},
{
"input": "3\nxxx\nsxs\nxsx",
"output": "NO"
},
{
"input": "5\nabbba\nbabab\nbbbbb\nbaaab\nabbba",
"output": "NO"
},
{
"input": "5\nabaaa\nbbbbb\nbbabb\nbabab\nabbba",
"output": "NO"
},
{
"input": "5\nxoxox\noxoxo\nooxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nxox\noxx\nxxx",
"output": "NO"
},
{
"input": "5\nxoooo\noxooo\nooxoo\noooxo\noooox",
"output": "NO"
},
{
"input": "5\nxoooo\noxoxx\nooxoo\noxoxo\noxoox",
"output": "NO"
},
{
"input": "3\naaa\nbab\naba",
"output": "NO"
}
] | 1,678,889,235 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 0 | n = int(input())
z = []
count = 0
for i in range(0, n):
z.append(input())
for j in range(0, int(n/2)):
if z[j] == z[n-j-1] and z[int(n/2)][j] == z[int(n/2)][n-j-1]:
count += 1
else:
break
if count < int(n/2):
print("NO")
else:
if z[int(n/2)][int(n/2)] == z[0][0] and z[int(n/2)][int(n/2)] != z[0][1]:
print("YES")
else:
print("NO") | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Output Specification:
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
Demo Input:
['5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n', '3\nwsw\nsws\nwsw\n', '3\nxpx\npxp\nxpe\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
none | ```python
n = int(input())
z = []
count = 0
for i in range(0, n):
z.append(input())
for j in range(0, int(n/2)):
if z[j] == z[n-j-1] and z[int(n/2)][j] == z[int(n/2)][n-j-1]:
count += 1
else:
break
if count < int(n/2):
print("NO")
else:
if z[int(n/2)][int(n/2)] == z[0][0] and z[int(n/2)][int(n/2)] != z[0][1]:
print("YES")
else:
print("NO")
``` | 3 |
|
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"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%;"/>. | 250 | [
{
"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"
}
] | 1,682,771,053 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 62 | 409,600 |
a=int(input())
b=input()
zero=b.count('0')
ones=b.count('1')
print(abs(zero-ones)) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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.
Input Specification:
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 Specification:
Output the minimum length of the string that may remain after applying the described operations several times.
Demo Input:
['4\n1100\n', '5\n01010\n', '8\n11101111\n']
Demo Output:
['0\n', '1\n', '6\n']
Note:
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%;"/>. | ```python
a=int(input())
b=input()
zero=b.count('0')
ones=b.count('1')
print(abs(zero-ones))
``` | 3 |
|
952 | D | I'm Feeling Lucky! | PROGRAMMING | 1,800 | [
"probabilities"
] | null | null | You have one chip and one chance to play roulette. Are you feeling lucky? | none | Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares). | [] | [] | none | 0 | [
{
"input": "1",
"output": "Red"
},
{
"input": "2",
"output": "Red"
}
] | 1,680,300,546 | 846 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | print('31')
| Title: I'm Feeling Lucky!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have one chip and one chance to play roulette. Are you feeling lucky?
Input Specification:
none
Output Specification:
Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares).
Note:
none | ```python
print('31')
``` | 0 |
|
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.
Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.
The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?
Take a look at the notes if you think you haven't understood the problem completely. | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once. | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters. | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n1000000000",
"output": "1000000000"
},
{
"input": "2 0\n0 0",
"output": "0"
},
{
"input": "2 0\n1000000000 0",
"output": "1000000000"
},
{
"input": "2 0\n0 1000000000",
"output": "1000000000"
},
{
"input": "2 0\n1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 1\n0 0\n1 2",
"output": "0"
}
] | 1,683,644,740 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 826 | 34,406,400 | from collections import defaultdict
from collections import deque
def findMin():
n, m = map(int, input().split())
gold = list(map(int, input().split()))
total = 0
visited = set()
path = defaultdict(list)
if m == 0:
print(sum(gold))
exit()
for i in range(m):
a, b = map(int, input().split())
path[a].append(b)
path[b].append(a)
def bfs(node):
nonlocal minVal
queue = deque([node])
curr = queue.popleft()
for n in path[curr]:
if n not in visited:
minVal = min(minVal, gold[n-1])
queue.append(n)
visited.add(n)
for key in path.keys():
if key not in visited:
visited.add(key)
minVal = gold[key - 1]
bfs(key)
total += minVal
print(total)
findMin()
| Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.
Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.
The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?
Take a look at the notes if you think you haven't understood the problem completely.
Input Specification:
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once.
Output Specification:
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
Demo Input:
['5 2\n2 5 3 4 8\n1 4\n4 5\n', '10 0\n1 2 3 4 5 6 7 8 9 10\n', '10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n']
Demo Output:
['10\n', '55\n', '15\n']
Note:
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters. | ```python
from collections import defaultdict
from collections import deque
def findMin():
n, m = map(int, input().split())
gold = list(map(int, input().split()))
total = 0
visited = set()
path = defaultdict(list)
if m == 0:
print(sum(gold))
exit()
for i in range(m):
a, b = map(int, input().split())
path[a].append(b)
path[b].append(a)
def bfs(node):
nonlocal minVal
queue = deque([node])
curr = queue.popleft()
for n in path[curr]:
if n not in visited:
minVal = min(minVal, gold[n-1])
queue.append(n)
visited.add(n)
for key in path.keys():
if key not in visited:
visited.add(key)
minVal = gold[key - 1]
bfs(key)
total += minVal
print(total)
findMin()
``` | 0 |
|
325 | E | The Red Button | PROGRAMMING | 2,800 | [
"combinatorics",
"dfs and similar",
"dsu",
"graphs",
"greedy"
] | null | null | Piegirl found the red button. You have one last chance to change the inevitable end.
The circuit under the button consists of *n* nodes, numbered from 0 to *n* - 1. In order to deactivate the button, the *n* nodes must be disarmed in a particular order. Node 0 must be disarmed first. After disarming node *i*, the next node to be disarmed must be either node (2·*i*) modulo *n* or node (2·*i*)<=+<=1 modulo *n*. The last node to be disarmed must be node 0. Node 0 must be disarmed twice, but all other nodes must be disarmed exactly once.
Your task is to find any such order and print it. If there is no such order, print -1. | Input consists of a single integer *n* (2<=≤<=*n*<=≤<=105). | Print an order in which you can to disarm all nodes. If it is impossible, print -1 instead. If there are multiple orders, print any one of them. | [
"2\n",
"3\n",
"4\n",
"16\n"
] | [
"0 1 0\n",
"-1",
"0 1 3 2 0\n",
"0 1 2 4 9 3 6 13 10 5 11 7 15 14 12 8 0\n"
] | none | 2,500 | [
{
"input": "2",
"output": "0 1 0"
},
{
"input": "3",
"output": "-1"
},
{
"input": "4",
"output": "0 1 3 2 0"
},
{
"input": "16",
"output": "0 1 2 4 9 3 6 13 10 5 11 7 15 14 12 8 0"
},
{
"input": "5",
"output": "-1"
},
{
"input": "7",
"output": "-1"
},
{
"input": "32",
"output": "0 1 2 4 8 17 3 6 12 25 18 5 10 20 9 19 7 14 29 26 21 11 22 13 27 23 15 31 30 28 24 16 0"
},
{
"input": "255",
"output": "-1"
},
{
"input": "65536",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32769 3 6 12 24 48 96 192 384 768 1536 3072 6144 12288 24576 49153 32770 5 10 20 40 80 160 320 640 1280 2560 5120 10240 20480 40960 16385 32771 7 14 28 56 112 224 448 896 1792 3584 7168 14336 28672 57345 49154 32772 9 18 36 72 144 288 576 1152 2304 4608 9216 18432 36864 8193 16386 32773 11 22 44 88 176 352 704 1408 2816 5632 11264 22528 45056 24577 49155 32774 13 26 52 104 208 416 832 1664 3328 6656 13312 26624 53248 40961 16387 32775 15 30 60 120 24..."
},
{
"input": "99999",
"output": "-1"
},
{
"input": "9",
"output": "-1"
},
{
"input": "6",
"output": "0 1 2 5 4 3 0"
},
{
"input": "8",
"output": "0 1 2 5 3 7 6 4 0"
},
{
"input": "10",
"output": "0 1 2 4 9 8 6 3 7 5 0"
},
{
"input": "12",
"output": "0 1 2 4 8 5 11 10 9 7 3 6 0"
},
{
"input": "20",
"output": "0 1 2 4 8 16 12 5 11 3 6 13 7 14 9 19 18 17 15 10 0"
},
{
"input": "25",
"output": "-1"
},
{
"input": "30",
"output": "0 1 2 4 8 16 3 6 12 24 19 9 18 7 14 29 28 26 23 17 5 10 21 13 27 25 20 11 22 15 0"
},
{
"input": "32",
"output": "0 1 2 4 8 17 3 6 12 25 18 5 10 20 9 19 7 14 29 26 21 11 22 13 27 23 15 31 30 28 24 16 0"
},
{
"input": "45",
"output": "-1"
},
{
"input": "50",
"output": "0 1 2 4 8 16 32 14 28 6 12 24 49 48 46 42 34 18 36 22 44 39 29 9 19 38 26 3 7 15 30 10 20 40 31 13 27 5 11 23 47 45 41 33 17 35 21 43 37 25 0"
},
{
"input": "100",
"output": "0 1 2 4 8 16 32 64 28 56 12 24 48 96 92 84 68 36 72 44 88 76 52 5 10 20 40 80 60 21 42 85 70 41 82 65 30 61 22 45 90 81 62 25 51 3 6 13 26 53 7 14 29 58 17 34 69 38 77 54 9 18 37 74 49 99 98 97 94 89 79 59 19 39 78 57 15 31 63 27 55 11 23 46 93 86 73 47 95 91 83 66 33 67 35 71 43 87 75 50 0"
},
{
"input": "126",
"output": "0 1 2 4 8 16 32 64 3 6 12 24 48 96 66 7 14 28 56 112 98 70 15 30 60 120 114 102 78 31 62 125 124 122 118 110 95 65 5 10 20 40 80 35 71 17 34 68 11 22 44 88 50 100 74 23 46 92 58 116 106 87 49 99 72 18 37 75 25 51 103 81 36 73 21 42 85 45 90 54 109 93 61 123 121 117 108 91 57 115 104 83 41 82 39 79 33 67 9 19 38 77 29 59 119 113 101 76 27 55 111 97 69 13 26 53 107 89 52 105 84 43 86 47 94 63 0"
},
{
"input": "513",
"output": "-1"
},
{
"input": "514",
"output": "0 1 2 4 8 16 32 64 128 256 513 512 510 506 498 482 450 386 258 3 6 12 24 48 96 192 384 254 508 502 490 466 418 322 130 260 7 14 28 56 112 224 448 382 250 500 486 458 402 290 66 132 264 15 30 60 120 240 480 446 378 242 484 454 394 274 34 68 136 272 31 62 124 248 496 478 442 370 226 452 390 266 18 36 72 144 288 63 126 252 504 494 474 434 354 194 388 262 10 20 40 80 160 321 129 259 5 11 22 44 88 176 352 190 380 246 492 470 426 338 162 324 134 268 23 46 92 184 368 222 444 374 234 468 422 330 146 292 70 140 280..."
},
{
"input": "800",
"output": "0 1 2 4 8 16 32 64 128 256 512 224 448 96 192 384 768 736 672 544 288 576 352 704 608 416 33 66 132 264 528 257 514 228 456 112 225 450 100 200 401 3 6 12 24 48 97 194 388 776 752 705 610 420 40 80 160 320 640 480 161 322 644 488 176 353 706 612 424 49 98 196 392 784 769 738 676 552 304 609 418 36 72 144 289 578 356 712 624 449 99 198 396 792 785 770 740 680 560 321 642 484 168 336 673 546 292 584 368 737 674 548 296 592 385 771 742 684 568 337 675 550 300 601 402 5 10 20 41 82 164 328 656 513 226 452 104 ..."
},
{
"input": "1000",
"output": "0 1 2 4 8 16 32 64 128 256 512 24 48 96 192 384 768 536 72 144 288 576 152 304 608 216 432 864 728 456 912 824 648 296 592 184 368 736 472 944 888 776 552 104 208 416 832 664 328 656 312 624 248 496 992 984 968 936 872 744 488 976 952 904 808 616 232 464 928 856 712 424 848 696 392 784 568 136 272 544 88 176 352 704 408 816 632 264 528 56 112 224 448 896 792 584 168 336 672 344 688 376 752 504 9 18 36 73 146 292 585 170 340 680 360 720 440 880 760 520 40 80 160 320 640 280 560 120 240 480 960 920 840 681 3..."
},
{
"input": "2500",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 1596 692 1384 268 536 1072 2144 1788 1076 2152 1804 1108 2216 1932 1364 228 456 912 1824 1148 2296 2092 1684 868 1736 972 1944 1388 276 552 1104 2208 1916 1332 164 328 656 1312 124 248 496 992 1984 1468 436 872 1744 988 1976 1452 404 808 1616 732 1464 428 856 1712 924 1848 1196 2392 2284 2068 1636 772 1544 588 1176 2352 2204 1908 1316 132 264 528 1056 2112 1724 948 1896 1292 84 168 336 672 1344 188 376 752 1504 508 1016 2032 1564 628 1256 12 24 48 96 192 384 768 153..."
},
{
"input": "6400",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 1792 3584 768 1536 3072 6144 5888 5376 4352 2304 4608 2816 5632 4864 3328 257 514 1028 2056 4112 1824 3648 896 1793 3586 772 1544 3088 6176 5952 5504 4609 2818 5636 4872 3344 288 576 1152 2305 4610 2820 5640 4880 3360 320 640 1280 2560 5120 3840 1281 2562 5124 3848 1296 2592 5184 3968 1537 3074 6148 5896 5392 4384 2368 4736 3073 6146 5892 5384 4368 2336 4672 2944 5889 5378 4356 2312 4624 2848 5696 4992 3585 770 1540 3080 6160 5920 5440 4480 2561 5122 3844 1288 ..."
},
{
"input": "23105",
"output": "-1"
},
{
"input": "24002",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 8766 17532 11062 22124 20246 16490 8978 17956 11910 23820 23638 23274 22546 21090 18178 12354 706 1412 2824 5648 11296 22592 21182 18362 12722 1442 2884 5768 11536 23072 22142 20282 16562 9122 18244 12486 970 1940 3880 7760 15520 7038 14076 4150 8300 16600 9198 18396 12790 1578 3156 6312 12624 1246 2492 4984 9968 19936 15870 7738 15476 6950 13900 3798 7596 15192 6382 12764 1526 3052 6104 12208 414 828 1656 3312 6624 13248 2494 4988 9976 19952 15902 7..."
},
{
"input": "29024",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 3744 7488 14976 928 1856 3712 7424 14848 672 1344 2688 5376 10752 21504 13984 27968 26912 24800 20576 12128 24256 19488 9952 19904 10784 21568 14112 28224 27424 25824 22624 16224 3424 6848 13696 27392 25760 22496 15968 2912 5824 11648 23296 17568 6112 12224 24448 19872 10720 21440 13856 27712 26400 23776 18528 8032 16064 3104 6208 12416 24832 20640 12256 24512 20000 10976 21952 14880 736 1472 2944 5888 11776 23552 18080 7136 14272 28544 28064 27104 2..."
},
{
"input": "36002",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 29534 23066 10130 20260 4518 9036 18072 142 284 568 1136 2272 4544 9088 18176 350 700 1400 2800 5600 11200 22400 8798 17596 35192 34382 32762 29522 23042 10082 20164 4326 8652 17304 34608 33214 30426 24850 13698 27396 18790 1578 3156 6312 12624 25248 14494 28988 21974 7946 15892 31784 27566 19130 2258 4516 9032 18064 126 252 504 1008 2016 4032 8064 16128 32256 28510 21018 6034 12068 24136 12270 24540 13078 26156 16310 32620 29238 22474 8946 178..."
},
{
"input": "55555",
"output": "-1"
},
{
"input": "65534",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 3 6 12 24 48 96 192 384 768 1536 3072 6144 12288 24576 49152 32770 7 14 28 56 112 224 448 896 1792 3584 7168 14336 28672 57344 49154 32774 15 30 60 120 240 480 960 1920 3840 7680 15360 30720 61440 57346 49158 32782 31 62 124 248 496 992 1984 3968 7936 15872 31744 63488 61442 57350 49166 32798 63 126 252 504 1008 2016 4032 8064 16128 32256 64512 63490 61446 57358 49182 32830 127 254 508 1016 2032 4064 8128 16256 32512 65024 64514 63494 61454 573..."
},
{
"input": "77776",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 53296 28816 57632 37488 74976 72176 66576 55376 32976 65952 54128 30480 60960 44144 10512 21024 42048 6320 12640 25280 50560 23344 46688 15600 31200 62400 47024 16272 32544 65088 52400 27024 54048 30320 60640 43504 9232 18464 36928 73856 69936 62096 46416 15056 30112 60224 42672 7568 15136 30272 60544 43312 8848 17696 35392 70784 63792 49808 21840 43680 9584 19168 38336 76672 75568 73360 68944 60112 42448 7120 14240 28480 56960 36144 7228..."
},
{
"input": "88888",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 42184 84368 79848 70808 52728 16568 33136 66272 43656 87312 85736 82584 76280 63672 38456 76912 64936 40984 81968 75048 61208 33528 67056 45224 1560 3120 6240 12480 24960 49920 10952 21904 43808 87616 86344 83800 78712 68536 48184 7480 14960 29920 59840 30792 61584 34280 68560 48232 7576 15152 30304 60608 32328 64656 40424 80848 72808 56728 24568 49136 9384 18768 37536 75072 61256 33624 67248 45608 2328 4656 9312 18624 37248 74496 60104 3..."
},
{
"input": "99494",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 31578 63156 26818 53636 7778 15556 31112 62224 24954 49908 322 644 1288 2576 5152 10304 20608 41216 82432 65370 31246 62492 25490 50980 2466 4932 9864 19728 39456 78912 58330 17166 34332 68664 37834 75668 51842 4190 8380 16760 33520 67040 34586 69172 38850 77700 55906 12318 24636 49272 98544 97594 95694 91894 84294 69094 38694 77388 55282 11070 22140 44280 88560 77626 55758 12022 24044 48088 96176 92858 86222 72950 46406 92812 86130 72766..."
},
{
"input": "99998",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 31074 62148 24298 48596 97192 94386 88774 77550 55102 10206 20412 40824 81648 63298 26598 53196 6394 12788 25576 51152 2306 4612 9224 18448 36896 73792 47586 95172 90346 80694 61390 22782 45564 91128 82258 64518 29038 58076 16154 32308 64616 29234 58468 16938 33876 67752 35506 71012 42026 84052 68106 36214 72428 44858 89716 79434 58870 17742 35484 70968 41938 83876 67754 35510 71020 42042 84084 68170 36342 72684 45370 90740 81482 62966 25..."
},
{
"input": "90248",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 40824 81648 73048 55848 21448 42896 85792 81336 72424 54600 18952 37904 75808 61368 32488 64976 39704 79408 68568 46888 3528 7056 14112 28224 56448 22648 45296 344 688 1376 2752 5504 11008 22016 44032 88064 85880 81512 72776 55304 20360 40720 81440 72632 55016 19784 39568 79136 68024 45800 1352 2704 5408 10816 21632 43264 86528 82808 75368 60488 30728 61456 32664 65328 40408 80816 71384 52520 14792 29584 59168 28088 56176 22104 44208 8841..."
},
{
"input": "99994",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 31078 62156 24318 48636 97272 94550 89106 78218 56442 12890 25780 51560 3126 6252 12504 25008 50016 38 76 152 304 608 1216 2432 4864 9728 19456 38912 77824 55654 11314 22628 45256 90512 81030 62066 24138 48276 96552 93110 86226 72458 44922 89844 79694 59394 18794 37588 75176 50358 722 1444 2888 5776 11552 23104 46208 92416 84838 69682 39370 78740 57486 14978 29956 59912 19830 39660 79320 58646 17298 34596 69192 38390 76780 53566 7138 1427..."
},
{
"input": "100000",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 31072 62144 24288 48576 97152 94304 88608 77216 54432 8864 17728 35456 70912 41824 83648 67296 34592 69184 38368 76736 53472 6944 13888 27776 55552 11104 22208 44416 88832 77664 55328 10656 21312 42624 85248 70496 40992 81984 63968 27936 55872 11744 23488 46976 93952 87904 75808 51616 3232 6464 12928 25856 51712 3424 6848 13696 27392 54784 9568 19136 38272 76544 53088 6176 12352 24704 49408 98816 97632 95264 90528 81056 62112 24224 48448 ..."
},
{
"input": "98300",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 32772 65544 32788 65576 32852 65704 33108 66216 34132 68264 38228 76456 54612 10924 21848 43696 87392 76484 54668 11036 22072 44144 88288 78276 58252 18204 36408 72816 47332 94664 91028 83756 69212 40124 80248 62196 26092 52184 6068 12136 24272 48544 97088 95876 93452 88604 78908 59516 20732 41464 82928 67556 36812 73624 48948 97896 97492 96684 95068 91836 85372 72444 46588 93176 88052 77804 57308 16316 32632 65264 32228 64456 30612 61224..."
},
{
"input": "95324",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 35748 71496 47668 12 24 48 96 192 384 768 1536 3072 6144 12288 24576 49152 2980 5960 11920 23840 47680 36 72 144 288 576 1152 2304 4608 9216 18432 36864 73728 52132 8940 17880 35760 71520 47716 108 216 432 864 1728 3456 6912 13824 27648 55296 15268 30536 61072 26820 53640 11956 23912 47824 324 648 1296 2592 5184 10368 20736 41472 82944 70564 45804 91608 87892 80460 65596 35868 71736 48148 972 1944 3888 7776 15552 31104 62208 29092 58184 2..."
},
{
"input": "87380",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 43692 5 10 20 40 80 160 320 640 1280 2560 5120 10240 20480 40960 81920 76460 65540 43700 21 42 84 168 336 672 1344 2688 5376 10752 21504 43008 86016 84652 81924 76468 65556 43732 85 170 340 680 1360 2720 5440 10880 21760 43520 87040 86700 86020 84660 81940 76500 65620 43860 341 682 1364 2728 5456 10912 21824 43648 87296 87212 87044 86708 86036 84692 82004 76628 65876 44372 1365 2730 5460 10920 21840 43680 87360 87340 87300 87220 87060 867..."
},
{
"input": "86036",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 45036 4036 8072 16144 32288 64576 43116 196 392 784 1568 3136 6272 12544 25088 50176 14316 28632 57264 28492 56984 27932 55864 25692 51384 16732 33464 66928 47820 9604 19208 38416 76832 67628 49220 12404 24808 49616 13196 26392 52784 19532 39064 78128 70220 54404 22772 45544 5052 10104 20208 40416 80832 75628 65220 44404 2772 5544 11088 22176 44352 2668 5336 10672 21344 42688 85376 84716 83396 80756 75476 64916 43796 1556 3112 6224 12448 ..."
},
{
"input": "81914",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 49158 16402 32804 65608 49302 16690 33380 66760 51606 21298 42596 3278 6556 13112 26224 52448 22982 45964 10014 20028 40056 80112 78310 74706 67498 53082 24250 48500 15086 30172 60344 38774 77548 73182 64450 46986 12058 24116 48232 14550 29100 58200 34486 68972 56030 30146 60292 38670 77340 72766 63618 45322 8730 17460 34920 69840 57766 33618 67236 52558 23202 46404 10894 21788 43576 5238 10476 20952 41904 1894 3788 7576 15152 30304 60608..."
}
] | 1,485,404,043 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 342 | 19,148,800 | n=int(input())
if n&1:
print(-1)
else:
D,R=[False]*(10**6),[0]*(10**6)
i,j=0,0
while True:
D[j]=True
R[i]=j
i+=1
if not D[(j+n)>>1]:
j=(j+n)>>1
elif not D[j>>1]:
j=j>>1
else:
break
print(" ".join(str(R[i]) for i in range(n,-1,-1)))
| Title: The Red Button
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Piegirl found the red button. You have one last chance to change the inevitable end.
The circuit under the button consists of *n* nodes, numbered from 0 to *n* - 1. In order to deactivate the button, the *n* nodes must be disarmed in a particular order. Node 0 must be disarmed first. After disarming node *i*, the next node to be disarmed must be either node (2·*i*) modulo *n* or node (2·*i*)<=+<=1 modulo *n*. The last node to be disarmed must be node 0. Node 0 must be disarmed twice, but all other nodes must be disarmed exactly once.
Your task is to find any such order and print it. If there is no such order, print -1.
Input Specification:
Input consists of a single integer *n* (2<=≤<=*n*<=≤<=105).
Output Specification:
Print an order in which you can to disarm all nodes. If it is impossible, print -1 instead. If there are multiple orders, print any one of them.
Demo Input:
['2\n', '3\n', '4\n', '16\n']
Demo Output:
['0 1 0\n', '-1', '0 1 3 2 0\n', '0 1 2 4 9 3 6 13 10 5 11 7 15 14 12 8 0\n']
Note:
none | ```python
n=int(input())
if n&1:
print(-1)
else:
D,R=[False]*(10**6),[0]*(10**6)
i,j=0,0
while True:
D[j]=True
R[i]=j
i+=1
if not D[(j+n)>>1]:
j=(j+n)>>1
elif not D[j>>1]:
j=j>>1
else:
break
print(" ".join(str(R[i]) for i in range(n,-1,-1)))
``` | 3 |
|
870 | B | Maximum of Maximums of Minimums | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible integer you can get?
Definitions of subsegment and array splitting are given in notes. | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109). | Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments. | [
"5 2\n1 2 3 4 5\n",
"5 1\n-4 -5 -3 -2 -1\n"
] | [
"5\n",
"-5\n"
] | A subsegment [*l*, *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>, *a*<sub class="lower-index">*l* + 1</sub>, ..., *a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index">1</sub>], [*l*<sub class="lower-index">2</sub>, *r*<sub class="lower-index">2</sub>], ..., [*l*<sub class="lower-index">*k*</sub>, *r*<sub class="lower-index">*k*</sub>] (*l*<sub class="lower-index">1</sub> = 1, *r*<sub class="lower-index">*k*</sub> = *n*, *l*<sub class="lower-index">*i*</sub> = *r*<sub class="lower-index">*i* - 1</sub> + 1 for all *i* > 1) is *k* sequences (*a*<sub class="lower-index">*l*<sub class="lower-index">1</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">1</sub></sub>), ..., (*a*<sub class="lower-index">*l*<sub class="lower-index">*k*</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">*k*</sub></sub>).
In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are *min*(1, 2, 3, 4) = 1 and *min*(5) = 5. The resulting maximum is *max*(1, 5) = 5. It is obvious that you can't reach greater result.
In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is *min*( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. | 1,000 | [
{
"input": "5 2\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 1\n-4 -5 -3 -2 -1",
"output": "-5"
},
{
"input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5",
"output": "10"
},
{
"input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9",
"output": "9"
},
{
"input": "1 1\n504262064",
"output": "504262064"
},
{
"input": "3 3\n-54481850 -878017339 -486296116",
"output": "-54481850"
},
{
"input": "2 2\n-333653905 224013643",
"output": "224013643"
},
{
"input": "14 2\n-14 84 44 46 -75 -75 77 -49 44 -82 -74 -51 -9 -50",
"output": "-14"
},
{
"input": "88 71\n-497 -488 182 104 40 183 201 282 -384 44 -29 494 224 -80 -491 -197 157 130 -52 233 -426 252 -61 -51 203 -50 195 -442 -38 385 232 -243 -49 163 340 -200 406 -254 -29 227 -194 193 487 -325 230 146 421 158 20 447 -97 479 493 -130 164 -471 -198 -330 -152 359 -554 319 544 -444 235 281 -467 337 -385 227 -366 -210 266 69 -261 525 526 -234 -355 177 109 275 -301 7 -41 553 -284 540",
"output": "553"
},
{
"input": "39 1\n676941771 -923780377 -163050076 -230110947 -208029500 329620771 13954060 158950156 -252501602 926390671 -678745080 -921892226 -100127643 610420285 602175224 -839193819 471391946 910035173 777969600 -736144413 -489685522 60986249 830784148 278642552 -375298304 197973611 -354482364 187294011 636628282 25350767 636184407 -550869740 53830680 -42049274 -451383278 900048257 93225803 877923341 -279506435",
"output": "-923780377"
},
{
"input": "3 2\n1 5 3",
"output": "3"
},
{
"input": "5 2\n1 2 5 4 3",
"output": "3"
},
{
"input": "3 2\n1 3 2",
"output": "2"
},
{
"input": "3 2\n1 3 1",
"output": "1"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "-2"
},
{
"input": "5 2\n1 2 3 5 4",
"output": "4"
},
{
"input": "5 2\n1 1 11 1 1",
"output": "1"
},
{
"input": "3 3\n3 8 4",
"output": "8"
},
{
"input": "6 3\n4 3 1 5 6 2",
"output": "6"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "5 2\n2 5 4 3 1",
"output": "2"
},
{
"input": "5 2\n-1 1 5 4 3",
"output": "3"
},
{
"input": "5 2\n5 2 1 9 3",
"output": "5"
},
{
"input": "2 1\n1000000000 1000000000",
"output": "1000000000"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "5 2\n1 5 3 4 1",
"output": "1"
},
{
"input": "3 2\n-1000000000 -1000000000 -1000000000",
"output": "-1000000000"
},
{
"input": "2 2\n5 2",
"output": "5"
},
{
"input": "7 3\n1 1 1 10 1 1 1",
"output": "10"
},
{
"input": "9 3\n1 2 1 1 5 1 1 1 2",
"output": "5"
},
{
"input": "9 3\n2 2 2 2 9 2 2 2 2",
"output": "9"
},
{
"input": "3 3\n-1000000000 -1000000000 -1000000000",
"output": "-1000000000"
}
] | 1,570,470,365 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 171 | 8,704,000 | n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
if k==1:
print(a[0])
else:
print(a[n-1])
| Title: Maximum of Maximums of Minimums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible integer you can get?
Definitions of subsegment and array splitting are given in notes.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109).
Output Specification:
Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments.
Demo Input:
['5 2\n1 2 3 4 5\n', '5 1\n-4 -5 -3 -2 -1\n']
Demo Output:
['5\n', '-5\n']
Note:
A subsegment [*l*, *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>, *a*<sub class="lower-index">*l* + 1</sub>, ..., *a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index">1</sub>], [*l*<sub class="lower-index">2</sub>, *r*<sub class="lower-index">2</sub>], ..., [*l*<sub class="lower-index">*k*</sub>, *r*<sub class="lower-index">*k*</sub>] (*l*<sub class="lower-index">1</sub> = 1, *r*<sub class="lower-index">*k*</sub> = *n*, *l*<sub class="lower-index">*i*</sub> = *r*<sub class="lower-index">*i* - 1</sub> + 1 for all *i* > 1) is *k* sequences (*a*<sub class="lower-index">*l*<sub class="lower-index">1</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">1</sub></sub>), ..., (*a*<sub class="lower-index">*l*<sub class="lower-index">*k*</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">*k*</sub></sub>).
In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are *min*(1, 2, 3, 4) = 1 and *min*(5) = 5. The resulting maximum is *max*(1, 5) = 5. It is obvious that you can't reach greater result.
In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is *min*( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. | ```python
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
if k==1:
print(a[0])
else:
print(a[n-1])
``` | 0 |
|
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system.
Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova. | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 500 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"input": "1000000000",
"output": "1\n999999932"
},
{
"input": "999999979",
"output": "2\n999999899\n999999908"
},
{
"input": "9",
"output": "0"
},
{
"input": "10",
"output": "1\n5"
},
{
"input": "11",
"output": "1\n10"
},
{
"input": "39",
"output": "1\n33"
},
{
"input": "66",
"output": "1\n60"
},
{
"input": "75",
"output": "0"
},
{
"input": "100",
"output": "1\n86"
},
{
"input": "101",
"output": "2\n91\n100"
},
{
"input": "2014",
"output": "2\n1988\n2006"
},
{
"input": "999999994",
"output": "0"
}
] | 1,644,186,678 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 46 | 0 | n = int(input())
m = str(n)
g = len(m)
l = [int(m[0])-1]+[9]*(g-1)
h = 0
less = 0
while(h<len(l)):
less = less + l[h]
h = h + 1
a = n - less
r = []
i = 0
while(a<n):
j = 0
s = str(a)
c = a
while j<len(s):
c = c + int(s[j])
j = j + 1
if(c==n):
i +=1
r = r + [a]
a = a + 1
if(i==0):
print(0)
else:
print(i)
j = 0
while(j<len(r)):
print(r[j])
j = j + 1 | Title: Classroom Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system.
Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109).
Output Specification:
In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order.
Demo Input:
['21\n', '20\n']
Demo Output:
['1\n15\n', '0\n']
Note:
In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | ```python
n = int(input())
m = str(n)
g = len(m)
l = [int(m[0])-1]+[9]*(g-1)
h = 0
less = 0
while(h<len(l)):
less = less + l[h]
h = h + 1
a = n - less
r = []
i = 0
while(a<n):
j = 0
s = str(a)
c = a
while j<len(s):
c = c + int(s[j])
j = j + 1
if(c==n):
i +=1
r = r + [a]
a = a + 1
if(i==0):
print(0)
else:
print(i)
j = 0
while(j<len(r)):
print(r[j])
j = j + 1
``` | 3 |
|
527 | A | Playing with Paper | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson? | The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=<<=*a*<=≤<=1012) — the sizes of the original sheet of paper. | Print a single integer — the number of ships that Vasya will make. | [
"2 1\n",
"10 7\n",
"1000000000000 1\n"
] | [
"2\n",
"6\n",
"1000000000000\n"
] | Pictures to the first and second sample test. | 500 | [
{
"input": "2 1",
"output": "2"
},
{
"input": "10 7",
"output": "6"
},
{
"input": "1000000000000 1",
"output": "1000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "3 2",
"output": "3"
},
{
"input": "4 2",
"output": "2"
},
{
"input": "1000 700",
"output": "6"
},
{
"input": "959986566087 524054155168",
"output": "90"
},
{
"input": "4 3",
"output": "4"
},
{
"input": "7 6",
"output": "7"
},
{
"input": "1000 999",
"output": "1000"
},
{
"input": "1000 998",
"output": "500"
},
{
"input": "1000 997",
"output": "336"
},
{
"input": "42 1",
"output": "42"
},
{
"input": "1000 1",
"output": "1000"
},
{
"input": "8 5",
"output": "5"
},
{
"input": "13 8",
"output": "6"
},
{
"input": "987 610",
"output": "15"
},
{
"input": "442 42",
"output": "22"
},
{
"input": "754 466",
"output": "13"
},
{
"input": "1000000000000 999999999999",
"output": "1000000000000"
},
{
"input": "1000000000000 999999999998",
"output": "500000000000"
},
{
"input": "941 14",
"output": "74"
},
{
"input": "998 2",
"output": "499"
},
{
"input": "1000 42",
"output": "32"
},
{
"input": "1000 17",
"output": "66"
},
{
"input": "5 1",
"output": "5"
},
{
"input": "5 2",
"output": "4"
},
{
"input": "5 3",
"output": "4"
},
{
"input": "5 4",
"output": "5"
},
{
"input": "293 210",
"output": "17"
},
{
"input": "787878787878 424242424242",
"output": "8"
},
{
"input": "956722026041 591286729879",
"output": "58"
},
{
"input": "956722026041 365435296162",
"output": "58"
},
{
"input": "628625247282 464807889701",
"output": "102"
},
{
"input": "695928431619 424778620208",
"output": "167"
},
{
"input": "1000000000000 42",
"output": "23809523821"
},
{
"input": "987654345678 23",
"output": "42941493300"
},
{
"input": "10000000001 2",
"output": "5000000002"
},
{
"input": "1000000000000 2",
"output": "500000000000"
},
{
"input": "1000000000000 3",
"output": "333333333336"
},
{
"input": "100000000000 3",
"output": "33333333336"
},
{
"input": "100000000000 23",
"output": "4347826109"
},
{
"input": "999999999997 7",
"output": "142857142861"
},
{
"input": "8589934592 4294967296",
"output": "2"
}
] | 1,429,103,557 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 62 | 0 | s=input()
a,b=s.split(' ')
a,b=int(a),int(b)
ans=1
while a!=b and a and b:
if a<b:
a,b=b,a
d=a//b
if a%b==0:
d-=1
ans+=d
a,b=b,a-d*b
print(ans)
| Title: Playing with Paper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input Specification:
The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=<<=*a*<=≤<=1012) — the sizes of the original sheet of paper.
Output Specification:
Print a single integer — the number of ships that Vasya will make.
Demo Input:
['2 1\n', '10 7\n', '1000000000000 1\n']
Demo Output:
['2\n', '6\n', '1000000000000\n']
Note:
Pictures to the first and second sample test. | ```python
s=input()
a,b=s.split(' ')
a,b=int(a),int(b)
ans=1
while a!=b and a and b:
if a<b:
a,b=b,a
d=a//b
if a%b==0:
d-=1
ans+=d
a,b=b,a-d*b
print(ans)
``` | 3 |
|
847 | M | Weather Tomorrow | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (*n*<=+<=1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (*n*<=+<=1)-th day will be equal to the temperature of the *n*-th day.
Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (*n*<=+<=1)-th day. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days for which the average air temperature is known.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=1000<=≤<=*t**i*<=≤<=1000) — where *t**i* is the average temperature in the *i*-th day. | Print the average air temperature in the (*n*<=+<=1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000. | [
"5\n10 5 0 -5 -10\n",
"4\n1 1 1 1\n",
"3\n5 1 -5\n",
"2\n900 1000\n"
] | [
"-15\n",
"1\n",
"-5\n",
"1100\n"
] | In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is - 10 - 5 = - 15.
In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1.
In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to - 5.
In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000 + 100 = 1100. | 0 | [
{
"input": "5\n10 5 0 -5 -10",
"output": "-15"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "3\n5 1 -5",
"output": "-5"
},
{
"input": "2\n900 1000",
"output": "1100"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 5 8",
"output": "11"
},
{
"input": "4\n4 1 -2 -5",
"output": "-8"
},
{
"input": "10\n-1000 -995 -990 -985 -980 -975 -970 -965 -960 -955",
"output": "-950"
},
{
"input": "11\n-1000 -800 -600 -400 -200 0 200 400 600 800 1000",
"output": "1200"
},
{
"input": "31\n1000 978 956 934 912 890 868 846 824 802 780 758 736 714 692 670 648 626 604 582 560 538 516 494 472 450 428 406 384 362 340",
"output": "318"
},
{
"input": "5\n1000 544 88 -368 -824",
"output": "-1280"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "33\n456 411 366 321 276 231 186 141 96 51 6 -39 -84 -129 -174 -219 -264 -309 -354 -399 -444 -489 -534 -579 -624 -669 -714 -759 -804 -849 -894 -939 -984",
"output": "-1029"
},
{
"input": "77\n-765 -742 -719 -696 -673 -650 -627 -604 -581 -558 -535 -512 -489 -466 -443 -420 -397 -374 -351 -328 -305 -282 -259 -236 -213 -190 -167 -144 -121 -98 -75 -52 -29 -6 17 40 63 86 109 132 155 178 201 224 247 270 293 316 339 362 385 408 431 454 477 500 523 546 569 592 615 638 661 684 707 730 753 776 799 822 845 868 891 914 937 960 983",
"output": "1006"
},
{
"input": "3\n2 4 8",
"output": "8"
},
{
"input": "4\n4 1 -3 -5",
"output": "-5"
},
{
"input": "10\n-1000 -995 -990 -984 -980 -975 -970 -965 -960 -955",
"output": "-955"
},
{
"input": "11\n-999 -800 -600 -400 -200 0 200 400 600 800 1000",
"output": "1000"
},
{
"input": "51\n-9 10 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490 510 530 550 570 590 610 630 650 670 690 710 730 750 770 790 810 830 850 870 890 910 930 950 970 990",
"output": "990"
},
{
"input": "100\n10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 207",
"output": "207"
},
{
"input": "2\n1000 1000",
"output": "1000"
},
{
"input": "2\n-1000 1000",
"output": "3000"
},
{
"input": "2\n1000 -1000",
"output": "-3000"
},
{
"input": "2\n-1000 -1000",
"output": "-1000"
},
{
"input": "100\n-85 -80 -76 -72 -68 -64 -60 -56 -52 -48 -44 -40 -36 -32 -28 -24 -20 -16 -12 -8 -4 0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120 124 128 132 136 140 144 148 152 156 160 164 168 172 176 180 184 188 192 196 200 204 208 212 216 220 224 228 232 236 240 244 248 252 256 260 264 268 272 276 280 284 288 292 296 300 304 308 312",
"output": "312"
},
{
"input": "4\n1 2 4 5",
"output": "5"
}
] | 1,589,823,526 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 93 | 307,200 | n=int(input())
a=list(map(int,input().split()))
ans=a[0]+(n)*(a[1]-a[0])
t=[0]*(n-1)
u=0
for i in range(len(a)-1):
t[i]=a[i+1]-a[i]
val=t[0]
for j in t:
if j==val:
continue
else:
u=1
if u==0:
print(ans)
else:
print(a.pop()) | Title: Weather Tomorrow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (*n*<=+<=1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (*n*<=+<=1)-th day will be equal to the temperature of the *n*-th day.
Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (*n*<=+<=1)-th day.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days for which the average air temperature is known.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=1000<=≤<=*t**i*<=≤<=1000) — where *t**i* is the average temperature in the *i*-th day.
Output Specification:
Print the average air temperature in the (*n*<=+<=1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000.
Demo Input:
['5\n10 5 0 -5 -10\n', '4\n1 1 1 1\n', '3\n5 1 -5\n', '2\n900 1000\n']
Demo Output:
['-15\n', '1\n', '-5\n', '1100\n']
Note:
In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is - 10 - 5 = - 15.
In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1.
In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to - 5.
In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000 + 100 = 1100. | ```python
n=int(input())
a=list(map(int,input().split()))
ans=a[0]+(n)*(a[1]-a[0])
t=[0]*(n-1)
u=0
for i in range(len(a)-1):
t[i]=a[i+1]-a[i]
val=t[0]
for j in t:
if j==val:
continue
else:
u=1
if u==0:
print(ans)
else:
print(a.pop())
``` | 3 |
|
919 | D | Substring | PROGRAMMING | 1,700 | [
"dfs and similar",
"dp",
"graphs"
] | null | null | You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the largest. | The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges.
The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node.
Then $m$ lines follow. Each line contains two integers $x, y$ ($1 \leq x, y \leq n$), describing a directed edge from $x$ to $y$. Note that $x$ can be equal to $y$ and there can be multiple edges between $x$ and $y$. Also the graph can be not connected. | Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead. | [
"5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n",
"6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n",
"10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n"
] | [
"3\n",
"-1\n",
"4\n"
] | In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times. | 1,500 | [
{
"input": "5 4\nabaca\n1 2\n1 3\n3 4\n4 5",
"output": "3"
},
{
"input": "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4",
"output": "-1"
},
{
"input": "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7",
"output": "4"
},
{
"input": "1 1\nf\n1 1",
"output": "-1"
},
{
"input": "10 50\nebibwbjihv\n1 10\n1 2\n5 4\n1 8\n9 7\n5 6\n1 8\n8 7\n2 6\n5 4\n1 9\n3 2\n8 3\n5 6\n5 9\n2 4\n2 7\n3 9\n1 2\n1 7\n1 10\n3 7\n1 8\n3 10\n8 6\n1 7\n10 6\n1 6\n5 8\n1 5\n2 10\n3 9\n5 8\n8 3\n3 7\n5 2\n1 10\n1 4\n5 3\n3 2\n1 2\n5 8\n10 4\n2 10\n8 2\n1 9\n1 8\n1 2\n3 4\n1 8",
"output": "2"
},
{
"input": "13 37\ndwpzcppjmhkmz\n2 6\n3 6\n6 7\n6 7\n6 7\n6 7\n6 8\n6 8\n6 8\n6 8\n4 6\n4 6\n5 6\n4 6\n4 6\n6 9\n6 9\n6 10\n6 10\n6 10\n6 10\n4 6\n1 6\n1 6\n10 11\n6 11\n1 6\n6 12\n6 12\n6 12\n6 13\n6 13\n6 13\n6 13\n3 6\n2 6\n2 6",
"output": "3"
},
{
"input": "5 8\ntetqw\n2 1\n4 4\n5 5\n5 2\n4 5\n1 5\n1 5\n1 1",
"output": "-1"
},
{
"input": "5 8\nreeet\n4 3\n2 5\n4 2\n2 4\n4 2\n5 2\n3 3\n3 4",
"output": "-1"
}
] | 1,622,494,012 | 1,312 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 3,000 | 19,968,000 | import collections
a = input().split()
m = int(a[0])
n = int(a[1])
s = list(input())
d = {}
for i in range(n):
b = input().split()
if int(b[0]) not in d:
d[int(b[0])] = [int(b[1])]
else:
d[int(b[0])].append(int(b[1]))
def dfs(d, so, visited, di, string, freq=0, mmax=0):
if visited is None:
visited = []
visited.append(so)
# print(visited)
# print(s, end='->')
di[string[so - 1]] += 1
# print(di, so)
if so not in d:
if max(di.values()) > freq:
freq = max(di.values())
# print(so, 'ooo')
di[string[so - 1]] -= 1
visited.pop()
if freq > mmax:
return freq
else:
return mmax
# print(string[so-1])
for next in d[so]:
if next not in visited:
# m = mmax
# print(mmax, "MMAX")
m = dfs(d, next, visited, di, string, freq, mmax)
mmax = m
di[string[so - 1]] -= 1
visited.pop()
# print(visited)
try:
return m
except:
return 0
def iscycle(d, s, visited=None):
if visited == None:
visited = []
visited.append(s)
# print(s, end = '->')
if s not in d:
return
for next in d[s]:
if next in visited:
return True
if next not in visited:
return (iscycle(d, next, visited))
def maxPathValue(n, m, d, s):
di = {}
for ch in s:
if ch not in di:
di[ch] = 0
# print(di)
if (iscycle(d, list(d.keys())[0])):
return -1
mval = 1
# print(d)
for j in range(len(list(d.keys()))):
# print('------------')
mval = max(mval, dfs(d, list(d.keys())[j], None, di, s))
# print(mval, "MVAL")
# print('------------')
return (mval)
m = maxPathValue(n, m, d, s)
print(m) | Title: Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the largest.
Input Specification:
The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges.
The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node.
Then $m$ lines follow. Each line contains two integers $x, y$ ($1 \leq x, y \leq n$), describing a directed edge from $x$ to $y$. Note that $x$ can be equal to $y$ and there can be multiple edges between $x$ and $y$. Also the graph can be not connected.
Output Specification:
Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead.
Demo Input:
['5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n', '6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n', '10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n']
Demo Output:
['3\n', '-1\n', '4\n']
Note:
In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times. | ```python
import collections
a = input().split()
m = int(a[0])
n = int(a[1])
s = list(input())
d = {}
for i in range(n):
b = input().split()
if int(b[0]) not in d:
d[int(b[0])] = [int(b[1])]
else:
d[int(b[0])].append(int(b[1]))
def dfs(d, so, visited, di, string, freq=0, mmax=0):
if visited is None:
visited = []
visited.append(so)
# print(visited)
# print(s, end='->')
di[string[so - 1]] += 1
# print(di, so)
if so not in d:
if max(di.values()) > freq:
freq = max(di.values())
# print(so, 'ooo')
di[string[so - 1]] -= 1
visited.pop()
if freq > mmax:
return freq
else:
return mmax
# print(string[so-1])
for next in d[so]:
if next not in visited:
# m = mmax
# print(mmax, "MMAX")
m = dfs(d, next, visited, di, string, freq, mmax)
mmax = m
di[string[so - 1]] -= 1
visited.pop()
# print(visited)
try:
return m
except:
return 0
def iscycle(d, s, visited=None):
if visited == None:
visited = []
visited.append(s)
# print(s, end = '->')
if s not in d:
return
for next in d[s]:
if next in visited:
return True
if next not in visited:
return (iscycle(d, next, visited))
def maxPathValue(n, m, d, s):
di = {}
for ch in s:
if ch not in di:
di[ch] = 0
# print(di)
if (iscycle(d, list(d.keys())[0])):
return -1
mval = 1
# print(d)
for j in range(len(list(d.keys()))):
# print('------------')
mval = max(mval, dfs(d, list(d.keys())[j], None, di, s))
# print(mval, "MVAL")
# print('------------')
return (mval)
m = maxPathValue(n, m, d, s)
print(m)
``` | 0 |
|
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code. | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints. | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 0\n4 5 6 7 1 2 3 0 9 8",
"output": "1 2 3 4 5 6 7 8 9 0"
},
{
"input": "1 1\n4\n4",
"output": "4"
},
{
"input": "3 7\n6 3 4\n4 9 0 1 7 8 6",
"output": "6 4"
},
{
"input": "10 1\n9 0 8 1 7 4 6 5 2 3\n0",
"output": "0"
},
{
"input": "5 10\n6 0 3 8 1\n3 1 0 5 4 7 2 8 9 6",
"output": "6 0 3 8 1"
},
{
"input": "8 2\n7 2 9 6 1 0 3 4\n6 3",
"output": "6 3"
},
{
"input": "5 4\n7 0 1 4 9\n0 9 5 3",
"output": "0 9"
},
{
"input": "10 1\n9 6 2 0 1 8 3 4 7 5\n6",
"output": "6"
},
{
"input": "10 2\n7 1 0 2 4 6 5 9 3 8\n3 2",
"output": "2 3"
},
{
"input": "5 9\n3 7 9 2 4\n3 8 4 5 9 6 1 0 2",
"output": "3 9 2 4"
},
{
"input": "10 6\n7 1 2 3 8 0 6 4 5 9\n1 5 8 2 3 6",
"output": "1 2 3 8 6 5"
},
{
"input": "8 2\n7 4 8 9 2 5 6 1\n6 4",
"output": "4 6"
},
{
"input": "10 2\n1 0 3 5 8 9 4 7 6 2\n0 3",
"output": "0 3"
},
{
"input": "7 6\n9 2 8 6 1 3 7\n4 2 0 3 1 8",
"output": "2 8 1 3"
},
{
"input": "1 6\n3\n6 8 2 4 5 3",
"output": "3"
},
{
"input": "1 8\n0\n9 2 4 8 1 5 0 7",
"output": "0"
},
{
"input": "6 9\n7 3 9 4 1 0\n9 1 5 8 0 6 2 7 4",
"output": "7 9 4 1 0"
},
{
"input": "10 2\n4 9 6 8 3 0 1 5 7 2\n0 1",
"output": "0 1"
},
{
"input": "10 5\n5 2 8 0 9 7 6 1 4 3\n9 6 4 1 2",
"output": "2 9 6 1 4"
},
{
"input": "6 3\n8 3 9 2 7 6\n5 4 3",
"output": "3"
},
{
"input": "4 10\n8 3 9 6\n4 9 6 2 7 0 8 1 3 5",
"output": "8 3 9 6"
},
{
"input": "1 2\n1\n1 0",
"output": "1"
},
{
"input": "3 6\n1 2 3\n4 5 6 1 2 3",
"output": "1 2 3"
},
{
"input": "1 2\n2\n1 2",
"output": "2"
},
{
"input": "1 10\n9\n0 1 2 3 4 5 6 7 8 9",
"output": "9"
}
] | 1,561,556,549 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 124 | 0 | t = list(map(int,input().split(' ')))
l1 = list(map(int,input().split(' ')))
l2= list(map(int,input().split(' ')))
l3=[]
for i in l1:
if i in l2:
l3.append(i)
for i in l3:
print(i,end=" ") | Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints.
Output Specification:
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
Demo Input:
['7 3\n3 5 7 1 6 2 8\n1 2 7\n', '4 4\n3 4 1 0\n0 1 7 9\n']
Demo Output:
['7 1 2\n', '1 0\n']
Note:
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | ```python
t = list(map(int,input().split(' ')))
l1 = list(map(int,input().split(' ')))
l2= list(map(int,input().split(' ')))
l3=[]
for i in l1:
if i in l2:
l3.append(i)
for i in l3:
print(i,end=" ")
``` | 3 |
|
729 | B | Spotlights | PROGRAMMING | 1,200 | [
"dp",
"implementation"
] | null | null | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.
A position is good if two conditions hold:
- there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects.
Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ. | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan. | Print one integer — the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction.
Therefore, there are 9 good positions in this example. | 1,000 | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 1\n1\n0\n0",
"output": "2"
},
{
"input": "5 7\n0 0 0 0 0 0 1\n0 0 0 0 0 0 1\n0 0 0 1 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0",
"output": "25"
},
{
"input": "10 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "4"
},
{
"input": "5 7\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1\n0 1 1 1 1 1 1\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1",
"output": "26"
},
{
"input": "10 20\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "121"
},
{
"input": "1 2\n0 1",
"output": "1"
},
{
"input": "1 2\n1 0",
"output": "1"
},
{
"input": "1 2\n1 1",
"output": "0"
},
{
"input": "2 1\n1\n0",
"output": "1"
},
{
"input": "2 1\n0\n1",
"output": "1"
},
{
"input": "2 1\n1\n1",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "4 4\n1 1 1 1\n1 0 0 1\n1 0 0 1\n1 1 1 1",
"output": "16"
}
] | 1,479,636,764 | 4,064 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 41 | 1,000 | 11,673,600 | def pro(L, k):
ones = []
for x in range(k):
if L[x] == '1':
ones.append(x)
p = 0
o = len(ones)
if o != 0:
p += k - o
for x in range(o-1):
p += ones[x+1] - ones[x] - 1
return p
n, m = map(int, input().split())
scene = [input().split() for i in range(n)]
proj = 0
for i in range(n):
proj += pro(scene[i], m)
v = []
sceneper = []
for j in range(m):
for i in range(n):
v.append(scene[i][j])
sceneper.append(v)
v = []
for j in range(m):
proj += pro(sceneper[j], n)
print(proj)
| Title: Spotlights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.
A position is good if two conditions hold:
- there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects.
Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.
Input Specification:
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.
Output Specification:
Print one integer — the number of good positions for placing the spotlight.
Demo Input:
['2 4\n0 1 0 0\n1 0 1 0\n', '4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n']
Demo Output:
['9\n', '20\n']
Note:
In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction.
Therefore, there are 9 good positions in this example. | ```python
def pro(L, k):
ones = []
for x in range(k):
if L[x] == '1':
ones.append(x)
p = 0
o = len(ones)
if o != 0:
p += k - o
for x in range(o-1):
p += ones[x+1] - ones[x] - 1
return p
n, m = map(int, input().split())
scene = [input().split() for i in range(n)]
proj = 0
for i in range(n):
proj += pro(scene[i], m)
v = []
sceneper = []
for j in range(m):
for i in range(n):
v.append(scene[i][j])
sceneper.append(v)
v = []
for j in range(m):
proj += pro(sceneper[j], n)
print(proj)
``` | 0 |
|
202 | A | LLPS | PROGRAMMING | 800 | [
"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". | 500 | [
{
"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"
}
] | 1,630,470,416 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 124 | 6,758,400 | word = str(input())
dictionary = dict()
for i in word:
dictionary[i] = i*(word.count(i))
sort = sorted(dictionary)
print(dictionary[sort[-1]]) | Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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".
Input Specification:
The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10.
Output Specification:
Print the lexicographically largest palindromic subsequence of string *s*.
Demo Input:
['radar\n', 'bowwowwow\n', 'codeforces\n', 'mississipp\n']
Demo Output:
['rr\n', 'wwwww\n', 's\n', 'ssss\n']
Note:
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". | ```python
word = str(input())
dictionary = dict()
for i in word:
dictionary[i] = i*(word.count(i))
sort = sorted(dictionary)
print(dictionary[sort[-1]])
``` | 3 |
|
769 | D | k-Interesting Pairs Of Integers | PROGRAMMING | 1,700 | [
"*special",
"bitmasks",
"brute force",
"meet-in-the-middle"
] | null | null | Vasya has the sequence consisting of *n* integers. Vasya consider the pair of integers *x* and *y* k-interesting, if their binary representation differs from each other exactly in *k* bits. For example, if *k*<==<=2, the pair of integers *x*<==<=5 and *y*<==<=3 is k-interesting, because their binary representation *x*=101 and *y*=011 differs exactly in two bits.
Vasya wants to know how many pairs of indexes (*i*, *j*) are in his sequence so that *i*<=<<=*j* and the pair of integers *a**i* and *a**j* is k-interesting. Your task is to help Vasya and determine this number. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=14) — the number of integers in Vasya's sequence and the number of bits in which integers in k-interesting pair should differ.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=104), which Vasya has. | Print the number of pairs (*i*, *j*) so that *i*<=<<=*j* and the pair of integers *a**i* and *a**j* is k-interesting. | [
"4 1\n0 3 2 1\n",
"6 0\n200 100 100 100 200 200\n"
] | [
"4\n",
"6\n"
] | In the first test there are 4 k-interesting pairs:
- (1, 3), - (1, 4), - (2, 3), - (2, 4).
In the second test *k* = 0. Consequently, integers in any k-interesting pair should be equal to themselves. Thus, for the second test there are 6 k-interesting pairs:
- (1, 5), - (1, 6), - (2, 3), - (2, 4), - (3, 4), - (5, 6). | 2,000 | [
{
"input": "4 1\n0 3 2 1",
"output": "4"
},
{
"input": "6 0\n200 100 100 100 200 200",
"output": "6"
},
{
"input": "2 0\n1 1",
"output": "1"
},
{
"input": "2 0\n0 0",
"output": "1"
},
{
"input": "2 0\n10000 10000",
"output": "1"
},
{
"input": "2 0\n0 10000",
"output": "0"
},
{
"input": "2 1\n0 1",
"output": "1"
},
{
"input": "2 1\n0 2",
"output": "1"
},
{
"input": "3 1\n0 1 2",
"output": "2"
},
{
"input": "3 2\n0 3 3",
"output": "2"
},
{
"input": "3 2\n3 3 3",
"output": "0"
},
{
"input": "10 0\n1 1 1 1 1 1 1 1 1 1",
"output": "45"
},
{
"input": "100 14\n8192 8192 8192 8192 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 8191 8191 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 8191 8192 8192 8192 8192 8192 8192 8191 8191 8192 8192 8191 8191 8192 8192 8192 8191 8191 8192 8191 8191 8191 8191 8191 8191 8192 8191 8191 8192 8191 8191 8192 8192 8191 8192 8192 8192 8192 8192 8192 8192 8191 8192 8192 8192 8191 8191 8192 8192 8192 8191 8192 8192 8192 8192 8192 8191 8192 8192 8191 8192 8192 8192 8192 8191 8192 8191 8191 8192 8191 8192 8192 8191 8191",
"output": "2400"
}
] | 1,488,651,965 | 23,165 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 61 | 4,608,000 | n, k = map(int, input().split())
a = list(map(int, input().split()))
maximum = len(str(bin(max(a))).replace('0b', ''))
glCounter = 0
def check(s1, s2):
global k
counter = 0
for q in range(len(s1)):
if not s1[q] == s2[q]:
counter += 1
if counter == k:
counter=0
return True
else:
counter=0
return False
for i in range(len(a)):
e = str(bin(a[i])).replace('0b', '')
a[i] = str(bin(a[i])).replace('0b', '0' * (maximum - len(e)))
for i in range(len(a)):
for j in range(i, len(a)):
if check(a[i], a[j]):
glCounter += 1
print(glCounter)
| Title: k-Interesting Pairs Of Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has the sequence consisting of *n* integers. Vasya consider the pair of integers *x* and *y* k-interesting, if their binary representation differs from each other exactly in *k* bits. For example, if *k*<==<=2, the pair of integers *x*<==<=5 and *y*<==<=3 is k-interesting, because their binary representation *x*=101 and *y*=011 differs exactly in two bits.
Vasya wants to know how many pairs of indexes (*i*, *j*) are in his sequence so that *i*<=<<=*j* and the pair of integers *a**i* and *a**j* is k-interesting. Your task is to help Vasya and determine this number.
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=14) — the number of integers in Vasya's sequence and the number of bits in which integers in k-interesting pair should differ.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=104), which Vasya has.
Output Specification:
Print the number of pairs (*i*, *j*) so that *i*<=<<=*j* and the pair of integers *a**i* and *a**j* is k-interesting.
Demo Input:
['4 1\n0 3 2 1\n', '6 0\n200 100 100 100 200 200\n']
Demo Output:
['4\n', '6\n']
Note:
In the first test there are 4 k-interesting pairs:
- (1, 3), - (1, 4), - (2, 3), - (2, 4).
In the second test *k* = 0. Consequently, integers in any k-interesting pair should be equal to themselves. Thus, for the second test there are 6 k-interesting pairs:
- (1, 5), - (1, 6), - (2, 3), - (2, 4), - (3, 4), - (5, 6). | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
maximum = len(str(bin(max(a))).replace('0b', ''))
glCounter = 0
def check(s1, s2):
global k
counter = 0
for q in range(len(s1)):
if not s1[q] == s2[q]:
counter += 1
if counter == k:
counter=0
return True
else:
counter=0
return False
for i in range(len(a)):
e = str(bin(a[i])).replace('0b', '')
a[i] = str(bin(a[i])).replace('0b', '0' * (maximum - len(e)))
for i in range(len(a)):
for j in range(i, len(a)):
if check(a[i], a[j]):
glCounter += 1
print(glCounter)
``` | 0 |
|
203 | D | Hit Ball | PROGRAMMING | 1,700 | [
"geometry",
"implementation",
"math"
] | null | null | When Valera was playing football on a stadium, it suddenly began to rain. Valera hid in the corridor under the grandstand not to get wet. However, the desire to play was so great that he decided to train his hitting the ball right in this corridor. Valera went back far enough, put the ball and hit it. The ball bounced off the walls, the ceiling and the floor corridor and finally hit the exit door. As the ball was wet, it left a spot on the door. Now Valera wants to know the coordinates for this spot.
Let's describe the event more formally. The ball will be considered a point in space. The door of the corridor will be considered a rectangle located on plane *xOz*, such that the lower left corner of the door is located at point (0,<=0,<=0), and the upper right corner is located at point (*a*,<=0,<=*b*) . The corridor will be considered as a rectangular parallelepiped, infinite in the direction of increasing coordinates of *y*. In this corridor the floor will be considered as plane *xOy*, and the ceiling as plane, parallel to *xOy* and passing through point (*a*,<=0,<=*b*). We will also assume that one of the walls is plane *yOz*, and the other wall is plane, parallel to *yOz* and passing through point (*a*,<=0,<=*b*).
We'll say that the ball hit the door when its coordinate *y* was equal to 0. Thus the coordinates of the spot are point (*x*0,<=0,<=*z*0), where 0<=≤<=*x*0<=≤<=*a*,<=0<=≤<=*z*0<=≤<=*b*. To hit the ball, Valera steps away from the door at distance *m* and puts the ball in the center of the corridor at point . After the hit the ball flies at speed (*v**x*,<=*v**y*,<=*v**z*). This means that if the ball has coordinates (*x*,<=*y*,<=*z*), then after one second it will have coordinates (*x*<=+<=*v**x*,<=*y*<=+<=*v**y*,<=*z*<=+<=*v**z*).
See image in notes for clarification.
When the ball collides with the ceiling, the floor or a wall of the corridor, it bounces off in accordance with the laws of reflection (the angle of incidence equals the angle of reflection). In the problem we consider the ideal physical model, so we can assume that there is no air resistance, friction force, or any loss of energy. | The first line contains three space-separated integers *a*,<=*b*,<=*m* (1<=≤<=*a*,<=*b*,<=*m*<=≤<=100). The first two integers specify point (*a*,<=0,<=*b*), through which the ceiling and one of the corridor walls pass. The third integer is the distance at which Valera went away from the door.
The second line has three space-separated integers *v**x*,<=*v**y*,<=*v**z* (|*v**x*|,<=|*v**y*|,<=|*v**z*|<=≤<=100,<=*v**y*<=<<=0,<=*v**z*<=≥<=0) — the speed of the ball after the hit.
It is guaranteed that the ball hits the door. | Print two real numbers *x*0,<=*z*0 — the *x* and *z* coordinates of point (*x*0,<=0,<=*z*0), at which the ball hits the exit door. The answer will be considered correct, if its absolute or relative error does not exceed 10<=<=-<=6. | [
"7 2 11\n3 -11 2\n",
"7 2 11\n4 -3 3\n"
] | [
"6.5000000000 2.0000000000\n",
"4.1666666667 1.0000000000\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/0b96c99a50a7ff8657d6301992a0fe440badfb7b.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 2,000 | [
{
"input": "7 2 11\n3 -11 2",
"output": "6.5000000000 2.0000000000"
},
{
"input": "7 2 11\n4 -3 3",
"output": "4.1666666667 1.0000000000"
},
{
"input": "44 94 98\n-17 -64 9",
"output": "4.0312500000 13.7812500000"
},
{
"input": "41 4 58\n81 -9 65",
"output": "31.5000000000 2.8888888889"
},
{
"input": "98 11 74\n79 -66 76",
"output": "58.4242424242 2.7878787879"
},
{
"input": "7 21 86\n1 -19 20",
"output": "5.9736842105 6.5263157895"
},
{
"input": "4 27 2\n-52 -64 31",
"output": "0.3750000000 0.9687500000"
},
{
"input": "8 89 62\n47 -18 53",
"output": "5.8888888889 4.5555555556"
},
{
"input": "57 7 78\n-31 -63 98",
"output": "9.8809523810 4.6666666667"
},
{
"input": "62 14 94\n-33 -20 8",
"output": "0.1000000000 9.6000000000"
},
{
"input": "59 24 6\n65 -73 53",
"output": "34.8424657534 4.3561643836"
},
{
"input": "28 7 59\n83 -44 80",
"output": "13.2954545455 4.7272727273"
},
{
"input": "24 26 75\n80 -97 58",
"output": "22.1443298969 7.1546391753"
},
{
"input": "33 32 87\n-22 -47 2",
"output": "24.2234042553 3.7021276596"
},
{
"input": "30 42 51\n0 -100 57",
"output": "15.0000000000 29.0700000000"
},
{
"input": "87 4 63\n49 -53 68",
"output": "72.2547169811 0.8301886792"
},
{
"input": "84 10 79\n-54 -98 12",
"output": "1.5306122449 9.6734693878"
},
{
"input": "89 20 95\n-32 -52 23",
"output": "13.9615384615 2.0192307692"
},
{
"input": "45 35 55\n67 -9 79",
"output": "18.0555555556 7.2222222222"
},
{
"input": "42 45 71\n64 -54 89",
"output": "21.1481481481 27.0185185185"
},
{
"input": "90 42 17\n8 -17 70",
"output": "53.0000000000 14.0000000000"
},
{
"input": "86 1 77\n5 -70 48",
"output": "48.5000000000 0.8000000000"
},
{
"input": "43 19 93\n-72 -19 93",
"output": "13.0789473684 0.7894736842"
},
{
"input": "48 25 5\n26 -73 2",
"output": "25.7808219178 0.1369863014"
},
{
"input": "45 35 21\n23 -66 58",
"output": "29.8181818182 18.4545454545"
},
{
"input": "2 45 85\n-54 -19 2",
"output": "0.5789473684 8.9473684211"
},
{
"input": "98 4 97\n-57 -72 13",
"output": "27.7916666667 1.5138888889"
},
{
"input": "3 14 13\n42 -22 58",
"output": "2.3181818182 6.2727272727"
},
{
"input": "4 28 25\n-86 -75 68",
"output": "2.6666666667 22.6666666667"
},
{
"input": "46 9 34\n88 -31 94",
"output": "27.5161290323 4.9032258065"
},
{
"input": "1 1 1\n0 -1 0",
"output": "0.5000000000 0.0000000000"
},
{
"input": "100 100 100\n100 -1 100",
"output": "50.0000000000 0.0000000000"
},
{
"input": "15 73 20\n15 -66 11",
"output": "12.0454545455 3.3333333333"
},
{
"input": "1 1 1\n0 -100 100",
"output": "0.5000000000 1.0000000000"
},
{
"input": "1 1 1\n100 -100 0",
"output": "0.5000000000 0.0000000000"
},
{
"input": "100 100 1\n-100 -1 0",
"output": "50.0000000000 0.0000000000"
},
{
"input": "100 100 77\n-14 -100 100",
"output": "39.2200000000 77.0000000000"
},
{
"input": "68 39 46\n-31 -37 3",
"output": "4.5405405405 3.7297297297"
},
{
"input": "17 45 6\n-9 -94 48",
"output": "7.9255319149 3.0638297872"
},
{
"input": "7 34 67\n-36 -47 28",
"output": "5.8191489362 28.0851063830"
}
] | 1,685,612,949 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 124 | 0 | # https://codeforces.com/contest/203/problem/D
from enum import Enum
class Planes(Enum):
L = 'left_wall'
R = 'right_wall'
B = 'floor'
T = 'ceiling'
D = 'door'
def __lt__(self, other):
return str(self) < str(other)
a, b, m = map(int, input().split())
vx, vy, vz = map(int, input().split())
x, y, z = a / 2, m, 0
while True:
# t = d / v
left_wall = float('inf') if vx >= 0 else x / -vx
right_wall = float('inf') if vx <= 0 else (a - x) / vx
floor = float('inf') if vz >= 0 else z / -vz
ceiling = float('inf') if vz <= 0 else (b - z) / vz
door = y / -vy
t, plane = min([(left_wall, Planes.L), (right_wall, Planes.R), (floor, Planes.B), (ceiling, Planes.T), (door, Planes.D)])
x, y, z = (x + vx * t, y + vy * t, z + vz * t)
if plane in {Planes.L, Planes.R}:
vx = -vx
elif plane in {Planes.B, Planes.T}:
vz = -vz
else: # we're at the door
break
print(x, z) | Title: Hit Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera was playing football on a stadium, it suddenly began to rain. Valera hid in the corridor under the grandstand not to get wet. However, the desire to play was so great that he decided to train his hitting the ball right in this corridor. Valera went back far enough, put the ball and hit it. The ball bounced off the walls, the ceiling and the floor corridor and finally hit the exit door. As the ball was wet, it left a spot on the door. Now Valera wants to know the coordinates for this spot.
Let's describe the event more formally. The ball will be considered a point in space. The door of the corridor will be considered a rectangle located on plane *xOz*, such that the lower left corner of the door is located at point (0,<=0,<=0), and the upper right corner is located at point (*a*,<=0,<=*b*) . The corridor will be considered as a rectangular parallelepiped, infinite in the direction of increasing coordinates of *y*. In this corridor the floor will be considered as plane *xOy*, and the ceiling as plane, parallel to *xOy* and passing through point (*a*,<=0,<=*b*). We will also assume that one of the walls is plane *yOz*, and the other wall is plane, parallel to *yOz* and passing through point (*a*,<=0,<=*b*).
We'll say that the ball hit the door when its coordinate *y* was equal to 0. Thus the coordinates of the spot are point (*x*0,<=0,<=*z*0), where 0<=≤<=*x*0<=≤<=*a*,<=0<=≤<=*z*0<=≤<=*b*. To hit the ball, Valera steps away from the door at distance *m* and puts the ball in the center of the corridor at point . After the hit the ball flies at speed (*v**x*,<=*v**y*,<=*v**z*). This means that if the ball has coordinates (*x*,<=*y*,<=*z*), then after one second it will have coordinates (*x*<=+<=*v**x*,<=*y*<=+<=*v**y*,<=*z*<=+<=*v**z*).
See image in notes for clarification.
When the ball collides with the ceiling, the floor or a wall of the corridor, it bounces off in accordance with the laws of reflection (the angle of incidence equals the angle of reflection). In the problem we consider the ideal physical model, so we can assume that there is no air resistance, friction force, or any loss of energy.
Input Specification:
The first line contains three space-separated integers *a*,<=*b*,<=*m* (1<=≤<=*a*,<=*b*,<=*m*<=≤<=100). The first two integers specify point (*a*,<=0,<=*b*), through which the ceiling and one of the corridor walls pass. The third integer is the distance at which Valera went away from the door.
The second line has three space-separated integers *v**x*,<=*v**y*,<=*v**z* (|*v**x*|,<=|*v**y*|,<=|*v**z*|<=≤<=100,<=*v**y*<=<<=0,<=*v**z*<=≥<=0) — the speed of the ball after the hit.
It is guaranteed that the ball hits the door.
Output Specification:
Print two real numbers *x*0,<=*z*0 — the *x* and *z* coordinates of point (*x*0,<=0,<=*z*0), at which the ball hits the exit door. The answer will be considered correct, if its absolute or relative error does not exceed 10<=<=-<=6.
Demo Input:
['7 2 11\n3 -11 2\n', '7 2 11\n4 -3 3\n']
Demo Output:
['6.5000000000 2.0000000000\n', '4.1666666667 1.0000000000\n']
Note:
<img class="tex-graphics" src="https://espresso.codeforces.com/0b96c99a50a7ff8657d6301992a0fe440badfb7b.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
# https://codeforces.com/contest/203/problem/D
from enum import Enum
class Planes(Enum):
L = 'left_wall'
R = 'right_wall'
B = 'floor'
T = 'ceiling'
D = 'door'
def __lt__(self, other):
return str(self) < str(other)
a, b, m = map(int, input().split())
vx, vy, vz = map(int, input().split())
x, y, z = a / 2, m, 0
while True:
# t = d / v
left_wall = float('inf') if vx >= 0 else x / -vx
right_wall = float('inf') if vx <= 0 else (a - x) / vx
floor = float('inf') if vz >= 0 else z / -vz
ceiling = float('inf') if vz <= 0 else (b - z) / vz
door = y / -vy
t, plane = min([(left_wall, Planes.L), (right_wall, Planes.R), (floor, Planes.B), (ceiling, Planes.T), (door, Planes.D)])
x, y, z = (x + vx * t, y + vy * t, z + vz * t)
if plane in {Planes.L, Planes.R}:
vx = -vx
elif plane in {Planes.B, Planes.T}:
vz = -vz
else: # we're at the door
break
print(x, z)
``` | 3 |
|
52 | A | 123-sequence | PROGRAMMING | 900 | [
"implementation"
] | A. 123-sequence | 2 | 256 | There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3). | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | [
"9\n1 3 2 2 2 1 1 2 3\n"
] | [
"5\n"
] | In the example all the numbers equal to 1 and 3 should be replaced by 2. | 500 | [
{
"input": "9\n1 3 2 2 2 1 1 2 3",
"output": "5"
},
{
"input": "6\n3 3 2 2 1 3",
"output": "3"
},
{
"input": "12\n3 1 3 1 2 1 3 2 2 1 2 1",
"output": "7"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2",
"output": "10"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "2\n3 2",
"output": "1"
},
{
"input": "2\n3 1",
"output": "1"
},
{
"input": "18\n2 3 2 1 2 3 2 1 2 3 3 3 1 2 3 3 3 2",
"output": "10"
},
{
"input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 2 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1",
"output": "19"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
}
] | 1,663,499,286 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 102,400 | from collections import Counter
n=int(input())
l=list(map(int,input().split()))
c=Counter(l)
if len(c)==3:
if c[1]+c[2]<=c[3]:
print(c[1]+c[2])
elif c[2]+c[3]<=c[1]:
print(c[2]+c[3])
else:
print(c[1]+c[3])
else:
print(min(c[1],c[2],c[3])) | Title: 123-sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3).
Output Specification:
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Demo Input:
['9\n1 3 2 2 2 1 1 2 3\n']
Demo Output:
['5\n']
Note:
In the example all the numbers equal to 1 and 3 should be replaced by 2. | ```python
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
c=Counter(l)
if len(c)==3:
if c[1]+c[2]<=c[3]:
print(c[1]+c[2])
elif c[2]+c[3]<=c[1]:
print(c[2]+c[3])
else:
print(c[1]+c[3])
else:
print(min(c[1],c[2],c[3]))
``` | 0 |
803 | A | Maximal Binary Matrix | PROGRAMMING | 1,400 | [
"constructive algorithms"
] | null | null | You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1. | The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). | If the answer exists then output resulting matrix. Otherwise output -1. | [
"2 1\n",
"3 2\n",
"2 5\n"
] | [
"1 0 \n0 0 \n",
"1 0 0 \n0 1 0 \n0 0 0 \n",
"-1\n"
] | none | 0 | [
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "20 398",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1..."
},
{
"input": "20 401",
"output": "-1"
},
{
"input": "100 3574",
"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 \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 \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..."
},
{
"input": "100 10000",
"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 \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 \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..."
},
{
"input": "100 10001",
"output": "-1"
},
{
"input": "2 3",
"output": "1 1 \n1 0 "
},
{
"input": "4 5",
"output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "5 6",
"output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 24",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 "
},
{
"input": "2 0",
"output": "0 0 \n0 0 "
},
{
"input": "3 5",
"output": "1 1 1 \n1 0 0 \n1 0 0 "
},
{
"input": "3 3",
"output": "1 1 0 \n1 0 0 \n0 0 0 "
},
{
"input": "5 10",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "3 4",
"output": "1 1 0 \n1 1 0 \n0 0 0 "
},
{
"input": "4 3",
"output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "1 1000000",
"output": "-1"
},
{
"input": "3 6",
"output": "1 1 1 \n1 1 0 \n1 0 0 "
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "-1"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "1 6",
"output": "-1"
},
{
"input": "1 7",
"output": "-1"
},
{
"input": "1 8",
"output": "-1"
},
{
"input": "1 9",
"output": "-1"
},
{
"input": "1 10",
"output": "-1"
},
{
"input": "1 11",
"output": "-1"
},
{
"input": "1 12",
"output": "-1"
},
{
"input": "1 13",
"output": "-1"
},
{
"input": "1 14",
"output": "-1"
},
{
"input": "1 15",
"output": "-1"
},
{
"input": "1 16",
"output": "-1"
},
{
"input": "1 17",
"output": "-1"
},
{
"input": "1 18",
"output": "-1"
},
{
"input": "1 19",
"output": "-1"
},
{
"input": "1 20",
"output": "-1"
},
{
"input": "1 21",
"output": "-1"
},
{
"input": "1 22",
"output": "-1"
},
{
"input": "1 23",
"output": "-1"
},
{
"input": "1 24",
"output": "-1"
},
{
"input": "1 25",
"output": "-1"
},
{
"input": "1 26",
"output": "-1"
},
{
"input": "2 0",
"output": "0 0 \n0 0 "
},
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "2 2",
"output": "1 0 \n0 1 "
},
{
"input": "2 3",
"output": "1 1 \n1 0 "
},
{
"input": "2 4",
"output": "1 1 \n1 1 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "2 6",
"output": "-1"
},
{
"input": "2 7",
"output": "-1"
},
{
"input": "2 8",
"output": "-1"
},
{
"input": "2 9",
"output": "-1"
},
{
"input": "2 10",
"output": "-1"
},
{
"input": "2 11",
"output": "-1"
},
{
"input": "2 12",
"output": "-1"
},
{
"input": "2 13",
"output": "-1"
},
{
"input": "2 14",
"output": "-1"
},
{
"input": "2 15",
"output": "-1"
},
{
"input": "2 16",
"output": "-1"
},
{
"input": "2 17",
"output": "-1"
},
{
"input": "2 18",
"output": "-1"
},
{
"input": "2 19",
"output": "-1"
},
{
"input": "2 20",
"output": "-1"
},
{
"input": "2 21",
"output": "-1"
},
{
"input": "2 22",
"output": "-1"
},
{
"input": "2 23",
"output": "-1"
},
{
"input": "2 24",
"output": "-1"
},
{
"input": "2 25",
"output": "-1"
},
{
"input": "2 26",
"output": "-1"
},
{
"input": "3 0",
"output": "0 0 0 \n0 0 0 \n0 0 0 "
},
{
"input": "3 1",
"output": "1 0 0 \n0 0 0 \n0 0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "3 3",
"output": "1 1 0 \n1 0 0 \n0 0 0 "
},
{
"input": "3 4",
"output": "1 1 0 \n1 1 0 \n0 0 0 "
},
{
"input": "3 5",
"output": "1 1 1 \n1 0 0 \n1 0 0 "
},
{
"input": "3 6",
"output": "1 1 1 \n1 1 0 \n1 0 0 "
},
{
"input": "3 7",
"output": "1 1 1 \n1 1 0 \n1 0 1 "
},
{
"input": "3 8",
"output": "1 1 1 \n1 1 1 \n1 1 0 "
},
{
"input": "3 9",
"output": "1 1 1 \n1 1 1 \n1 1 1 "
},
{
"input": "3 10",
"output": "-1"
},
{
"input": "3 11",
"output": "-1"
},
{
"input": "3 12",
"output": "-1"
},
{
"input": "3 13",
"output": "-1"
},
{
"input": "3 14",
"output": "-1"
},
{
"input": "3 15",
"output": "-1"
},
{
"input": "3 16",
"output": "-1"
},
{
"input": "3 17",
"output": "-1"
},
{
"input": "3 18",
"output": "-1"
},
{
"input": "3 19",
"output": "-1"
},
{
"input": "3 20",
"output": "-1"
},
{
"input": "3 21",
"output": "-1"
},
{
"input": "3 22",
"output": "-1"
},
{
"input": "3 23",
"output": "-1"
},
{
"input": "3 24",
"output": "-1"
},
{
"input": "3 25",
"output": "-1"
},
{
"input": "3 26",
"output": "-1"
},
{
"input": "4 0",
"output": "0 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 1",
"output": "1 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 2",
"output": "1 0 0 0 \n0 1 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 3",
"output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 4",
"output": "1 1 0 0 \n1 1 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 5",
"output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "4 6",
"output": "1 1 1 0 \n1 1 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "4 7",
"output": "1 1 1 1 \n1 0 0 0 \n1 0 0 0 \n1 0 0 0 "
},
{
"input": "4 8",
"output": "1 1 1 1 \n1 1 0 0 \n1 0 0 0 \n1 0 0 0 "
},
{
"input": "4 9",
"output": "1 1 1 1 \n1 1 0 0 \n1 0 1 0 \n1 0 0 0 "
},
{
"input": "4 10",
"output": "1 1 1 1 \n1 1 1 0 \n1 1 0 0 \n1 0 0 0 "
},
{
"input": "4 11",
"output": "1 1 1 1 \n1 1 1 0 \n1 1 1 0 \n1 0 0 0 "
},
{
"input": "4 12",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 0 0 \n1 1 0 0 "
},
{
"input": "4 13",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 0 "
},
{
"input": "4 14",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 1 "
},
{
"input": "4 15",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 0 "
},
{
"input": "4 16",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 1 "
},
{
"input": "4 17",
"output": "-1"
},
{
"input": "4 18",
"output": "-1"
},
{
"input": "4 19",
"output": "-1"
},
{
"input": "4 20",
"output": "-1"
},
{
"input": "4 21",
"output": "-1"
},
{
"input": "4 22",
"output": "-1"
},
{
"input": "4 23",
"output": "-1"
},
{
"input": "4 24",
"output": "-1"
},
{
"input": "4 25",
"output": "-1"
},
{
"input": "4 26",
"output": "-1"
},
{
"input": "5 0",
"output": "0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 1",
"output": "1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 2",
"output": "1 0 0 0 0 \n0 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 3",
"output": "1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 4",
"output": "1 1 0 0 0 \n1 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 5",
"output": "1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 6",
"output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 7",
"output": "1 1 1 1 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 8",
"output": "1 1 1 1 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 9",
"output": "1 1 1 1 1 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 10",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 11",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 12",
"output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 13",
"output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 14",
"output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 0 0 0 \n1 1 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 15",
"output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 16",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 0 0 0 \n1 1 0 0 0 \n1 1 0 0 0 "
},
{
"input": "5 17",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 1 0 0 0 "
},
{
"input": "5 18",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 1 0 \n1 1 0 0 0 "
},
{
"input": "5 19",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 "
},
{
"input": "5 20",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 1 0 \n1 1 0 0 0 "
},
{
"input": "5 21",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 "
},
{
"input": "5 22",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 "
},
{
"input": "5 23",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 1 "
},
{
"input": "5 24",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 "
},
{
"input": "5 25",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 "
},
{
"input": "5 26",
"output": "-1"
},
{
"input": "100 0",
"output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 1",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 2",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 3",
"output": "1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 99",
"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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "100 100",
"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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "100 101",
"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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "100 9999",
"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 \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 \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..."
},
{
"input": "100 10000",
"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 \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 \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..."
},
{
"input": "100 10001",
"output": "-1"
}
] | 1,698,741,805 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | # -*- coding: utf-8 -*-
"""
Created on Fri Oct 27 00:57:35 2023
@author: 程卓 2300011733
"""
n = int(input())
for i in range(n):
cur_n = int(input())
number = [int(element) for element in input().split()]
left = 0
right = cur_n-1
min_ = 1
max_ = cur_n
for j in range(cur_n):
flag = True
if right-left+1 < 4:
print(-1)
break
else:
if number[left] == min_:
left += 1
min_ += 1
flag = False
elif number[left] == max_:
left += 1
max_ -= 1
flag = False
if number[right] == min_:
right -= 1
min_ += 1
flag = False
elif number[right] == max_:
right -= 1
max_ -= 1
flag = False
if flag:
print(f'{left+1} {right+1}')
break | Title: Maximal Binary Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1.
Input Specification:
The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106).
Output Specification:
If the answer exists then output resulting matrix. Otherwise output -1.
Demo Input:
['2 1\n', '3 2\n', '2 5\n']
Demo Output:
['1 0 \n0 0 \n', '1 0 0 \n0 1 0 \n0 0 0 \n', '-1\n']
Note:
none | ```python
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 27 00:57:35 2023
@author: 程卓 2300011733
"""
n = int(input())
for i in range(n):
cur_n = int(input())
number = [int(element) for element in input().split()]
left = 0
right = cur_n-1
min_ = 1
max_ = cur_n
for j in range(cur_n):
flag = True
if right-left+1 < 4:
print(-1)
break
else:
if number[left] == min_:
left += 1
min_ += 1
flag = False
elif number[left] == max_:
left += 1
max_ -= 1
flag = False
if number[right] == min_:
right -= 1
min_ += 1
flag = False
elif number[right] == max_:
right -= 1
max_ -= 1
flag = False
if flag:
print(f'{left+1} {right+1}')
break
``` | -1 |
|
409 | H | A + B Strikes Back | PROGRAMMING | 1,500 | [
"*special",
"brute force",
"constructive algorithms",
"dsu",
"implementation"
] | null | null | A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? | The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space. | Output the sum of the given integers. | [
"5 14\n",
"381 492\n"
] | [
"19\n",
"873\n"
] | none | 0 | [
{
"input": "5 14",
"output": "19"
},
{
"input": "381 492",
"output": "873"
},
{
"input": "536 298",
"output": "834"
},
{
"input": "143 522",
"output": "665"
},
{
"input": "433 126",
"output": "559"
},
{
"input": "723 350",
"output": "1073"
},
{
"input": "632 264",
"output": "896"
},
{
"input": "923 488",
"output": "1411"
},
{
"input": "522 92",
"output": "614"
},
{
"input": "953 553",
"output": "1506"
},
{
"input": "242 86",
"output": "328"
},
{
"input": "151 691",
"output": "842"
},
{
"input": "441 915",
"output": "1356"
},
{
"input": "740 519",
"output": "1259"
},
{
"input": "339 433",
"output": "772"
},
{
"input": "629 657",
"output": "1286"
},
{
"input": "538 261",
"output": "799"
},
{
"input": "828 485",
"output": "1313"
},
{
"input": "117 399",
"output": "516"
},
{
"input": "399 280",
"output": "679"
}
] | 1,681,313,194 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 0 | 0 | import sys
input = lambda: sys.stdin.readline().rstrip()
a,b = map(int, input().split())
print(a+b) | Title: A + B Strikes Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try?
Input Specification:
The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space.
Output Specification:
Output the sum of the given integers.
Demo Input:
['5 14\n', '381 492\n']
Demo Output:
['19\n', '873\n']
Note:
none | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
a,b = map(int, input().split())
print(a+b)
``` | 0 |
|
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 594 622 834 922",
"output": "17"
},
{
"input": "10\nLRLRLLRRLR\n82 268 430 598 604 658 670 788 838 1000",
"output": "3"
},
{
"input": "2\nRL\n0 1000000000",
"output": "500000000"
},
{
"input": "12\nLRLLRRRRLRLL\n254 1260 1476 1768 2924 4126 4150 4602 5578 7142 8134 9082",
"output": "108"
},
{
"input": "14\nRLLRRLRLLRLLLR\n698 2900 3476 3724 3772 3948 4320 4798 5680 6578 7754 8034 8300 8418",
"output": "88"
},
{
"input": "16\nRRLLLRLRLLLLRLLR\n222 306 968 1060 1636 1782 2314 2710 3728 4608 5088 6790 6910 7156 7418 7668",
"output": "123"
},
{
"input": "18\nRLRLLRRRLLLRLRRLRL\n1692 2028 2966 3008 3632 4890 5124 5838 6596 6598 6890 8294 8314 8752 8868 9396 9616 9808",
"output": "10"
},
{
"input": "20\nRLLLLLLLRRRRLRRLRRLR\n380 902 1400 1834 2180 2366 2562 2596 2702 2816 3222 3238 3742 5434 6480 7220 7410 8752 9708 9970",
"output": "252"
},
{
"input": "22\nLRRRRRRRRRRRLLRRRRRLRL\n1790 2150 2178 2456 2736 3282 3622 4114 4490 4772 5204 5240 5720 5840 5910 5912 6586 7920 8584 9404 9734 9830",
"output": "48"
},
{
"input": "24\nLLRLRRLLRLRRRRLLRRLRLRRL\n100 360 864 1078 1360 1384 1438 2320 2618 3074 3874 3916 3964 5178 5578 6278 6630 6992 8648 8738 8922 8930 9276 9720",
"output": "27"
},
{
"input": "26\nRLLLLLLLRLRRLRLRLRLRLLLRRR\n908 1826 2472 2474 2728 3654 3716 3718 3810 3928 4058 4418 4700 5024 5768 6006 6128 6386 6968 7040 7452 7774 7822 8726 9338 9402",
"output": "59"
},
{
"input": "28\nRRLRLRRRRRRLLLRRLRRLLLRRLLLR\n156 172 1120 1362 2512 3326 3718 4804 4990 5810 6242 6756 6812 6890 6974 7014 7088 7724 8136 8596 8770 8840 9244 9250 9270 9372 9400 9626",
"output": "10"
},
{
"input": "30\nRLLRLRLLRRRLRRRLLLLLLRRRLRRLRL\n128 610 1680 2436 2896 2994 3008 3358 3392 4020 4298 4582 4712 4728 5136 5900 6088 6232 6282 6858 6934 7186 7224 7256 7614 8802 8872 9170 9384 9794",
"output": "7"
},
{
"input": "10\nLLLLRRRRRR\n0 2 4 6 8 10 12 14 16 18",
"output": "-1"
},
{
"input": "5\nLLLLL\n0 10 20 30 40",
"output": "-1"
},
{
"input": "6\nRRRRRR\n40 50 60 70 80 100",
"output": "-1"
},
{
"input": "1\nR\n0",
"output": "-1"
},
{
"input": "2\nRL\n2 1000000000",
"output": "499999999"
},
{
"input": "2\nRL\n0 400000",
"output": "200000"
},
{
"input": "2\nRL\n0 200002",
"output": "100001"
},
{
"input": "2\nRL\n2 20000000",
"output": "9999999"
},
{
"input": "4\nLLRL\n2 4 10 100",
"output": "45"
},
{
"input": "4\nRLRL\n2 10 12 14",
"output": "1"
},
{
"input": "2\nRL\n0 100000000",
"output": "50000000"
},
{
"input": "2\nRL\n2 600002",
"output": "300000"
},
{
"input": "1\nL\n0",
"output": "-1"
},
{
"input": "2\nRL\n0 600000",
"output": "300000"
},
{
"input": "5\nRRRRR\n0 2 4 6 8",
"output": "-1"
},
{
"input": "2\nRL\n2 200000000",
"output": "99999999"
},
{
"input": "2\nRL\n0 267382766",
"output": "133691383"
},
{
"input": "3\nRRL\n4 8 999999998",
"output": "499999995"
},
{
"input": "2\nRL\n0 2",
"output": "1"
},
{
"input": "2\nRL\n2 400002",
"output": "200000"
},
{
"input": "2\nLL\n2 4",
"output": "-1"
},
{
"input": "2\nLL\n0 2",
"output": "-1"
},
{
"input": "2\nRL\n0 100000",
"output": "50000"
},
{
"input": "2\nRL\n2 200000020",
"output": "100000009"
},
{
"input": "2\nRL\n2000000 4000000",
"output": "1000000"
},
{
"input": "2\nRL\n0 199998",
"output": "99999"
},
{
"input": "3\nLRR\n40 50 60",
"output": "-1"
},
{
"input": "2\nRL\n200 400400",
"output": "200100"
},
{
"input": "2\nRL\n2 400004",
"output": "200001"
},
{
"input": "2\nRL\n0 200000000",
"output": "100000000"
}
] | 1,674,378,477 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 233 | 16,384,000 | def collisions():
n = int(input())
directions = input()
positions = list(map(int, input().split()))
particles = list(zip(positions, directions))
time = []
for i in range(0, n-1):
p1 = particles[i]
p2 = particles[i+1]
if p1[1] == p2[1] or (p1[1] == 'L' and p2[1] == 'R'):
time.append(-1)
else:
time.append(int((p2[0] - p1[0])/2))
min_collide = min([t for t in time if t != -1], default=-1)
return min_collide
print(collisions()) | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input Specification:
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output Specification:
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Demo Input:
['4\nRLRL\n2 4 6 10\n', '3\nLLR\n40 50 60\n']
Demo Output:
['1\n', '-1\n']
Note:
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | ```python
def collisions():
n = int(input())
directions = input()
positions = list(map(int, input().split()))
particles = list(zip(positions, directions))
time = []
for i in range(0, n-1):
p1 = particles[i]
p2 = particles[i+1]
if p1[1] == p2[1] or (p1[1] == 'L' and p2[1] == 'R'):
time.append(-1)
else:
time.append(int((p2[0] - p1[0])/2))
min_collide = min([t for t in time if t != -1], default=-1)
return min_collide
print(collisions())
``` | 3 |
|
572 | A | Arrays | PROGRAMMING | 900 | [
"sortings"
] | null | null | You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. | The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*.
The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*. | Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). | [
"3 3\n2 1\n1 2 3\n3 4 5\n",
"3 3\n3 3\n1 2 3\n3 4 5\n",
"5 2\n3 1\n1 1 1 1 1\n2 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "3 3\n2 1\n1 2 3\n3 4 5",
"output": "YES"
},
{
"input": "3 3\n3 3\n1 2 3\n3 4 5",
"output": "NO"
},
{
"input": "5 2\n3 1\n1 1 1 1 1\n2 2",
"output": "YES"
},
{
"input": "3 5\n1 1\n5 5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n1 1\n1\n1",
"output": "NO"
},
{
"input": "3 3\n1 1\n1 2 3\n1 2 3",
"output": "YES"
},
{
"input": "3 3\n1 2\n1 2 3\n1 2 3",
"output": "YES"
},
{
"input": "3 3\n2 2\n1 2 3\n1 2 3",
"output": "NO"
},
{
"input": "10 15\n10 1\n1 1 5 17 22 29 32 36 39 48\n9 10 20 23 26 26 32 32 33 39 43 45 47 49 49",
"output": "YES"
},
{
"input": "10 15\n1 15\n91 91 91 92 92 94 94 95 98 100\n92 92 93 93 93 94 95 96 97 98 98 99 99 100 100",
"output": "YES"
},
{
"input": "15 10\n12 5\n9 25 25 32 32 38 40 41 46 46 48 51 64 64 73\n5 14 30 35 50 52 67 79 89 99",
"output": "YES"
},
{
"input": "15 10\n4 10\n22 32 35 45 45 50 51 55 79 80 83 88 90 92 93\n46 48 52 55 60 60 68 75 80 81",
"output": "YES"
},
{
"input": "20 30\n2 8\n6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 10\n1 1 2 2 2 2 2 2 2 3 3 4 5 5 5 5 6 6 6 6 6 6 7 7 7 8 8 9 10 10",
"output": "NO"
},
{
"input": "20 30\n19 29\n1 1 2 2 2 3 4 4 7 7 7 8 8 8 8 8 9 9 9 9\n6 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "NO"
},
{
"input": "1 1\n1 1\n-1000000000\n30",
"output": "YES"
},
{
"input": "3 3\n1 3\n1 3 3\n3 3 3",
"output": "YES"
},
{
"input": "3 3\n1 1\n3 3 3\n2 2 2",
"output": "NO"
},
{
"input": "5 5\n3 3\n1 5 6 7 8\n1 2 5 6 7",
"output": "NO"
},
{
"input": "3 4\n2 2\n5 6 7\n1 2 3 4",
"output": "NO"
},
{
"input": "3 3\n3 3\n1 2 3\n4 5 6",
"output": "YES"
},
{
"input": "5 5\n4 5\n2 2 3 4 5\n5 6 7 8 9",
"output": "YES"
}
] | 1,519,999,637 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 78 | 19,968,000 | n = [int(x) for x in input().split()]
k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
res = 'YES'
for i in range(0,k[0]):
if a[i]>=b[0]:
res = 'NO'
break
print(res) | Title: Arrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
Input Specification:
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*.
The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*.
Output Specification:
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
Demo Input:
['3 3\n2 1\n1 2 3\n3 4 5\n', '3 3\n3 3\n1 2 3\n3 4 5\n', '5 2\n3 1\n1 1 1 1 1\n2 2\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
n = [int(x) for x in input().split()]
k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
res = 'YES'
for i in range(0,k[0]):
if a[i]>=b[0]:
res = 'NO'
break
print(res)
``` | 0 |
Subsets and Splits