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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
},
{
"input": "4\n5 4 5 4",
"output": "-1"
},
{
"input": "7\n3 4 5 5 5 1 2",
"output": "2"
},
{
"input": "5\n2 2 1 2 2",
"output": "3"
},
{
"input": "5\n5 4 1 2 3",
"output": "-1"
},
{
"input": "4\n6 1 2 7",
"output": "-1"
},
{
"input": "5\n4 5 6 2 3",
"output": "2"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "4\n1 2 2 1",
"output": "1"
},
{
"input": "9\n4 5 6 7 1 2 3 4 10",
"output": "-1"
},
{
"input": "7\n2 3 4 1 2 3 4",
"output": "-1"
},
{
"input": "6\n1 2 1 2 1 2",
"output": "-1"
},
{
"input": "3\n3 2 1",
"output": "-1"
},
{
"input": "4\n1 4 4 1",
"output": "1"
},
{
"input": "5\n1 2 1 1 1",
"output": "3"
},
{
"input": "5\n4 6 7 3 5",
"output": "-1"
},
{
"input": "4\n2 3 1 4",
"output": "-1"
},
{
"input": "5\n5 4 3 2 1",
"output": "-1"
},
{
"input": "4\n2 4 1 4",
"output": "-1"
},
{
"input": "6\n4 5 6 1 2 7",
"output": "-1"
},
{
"input": "6\n1 2 3 1 1 1",
"output": "3"
},
{
"input": "5\n1 3 3 3 1",
"output": "1"
},
{
"input": "6\n5 6 7 5 5 5",
"output": "3"
},
{
"input": "5\n3 4 2 1 2",
"output": "-1"
},
{
"input": "3\n3 4 2",
"output": "1"
},
{
"input": "6\n1 1 2 2 1 1",
"output": "2"
},
{
"input": "4\n2 3 4 2",
"output": "1"
},
{
"input": "5\n3 5 7 7 3",
"output": "1"
},
{
"input": "4\n1 1 4 1",
"output": "1"
},
{
"input": "7\n1 5 6 1 1 1 1",
"output": "4"
},
{
"input": "5\n7 8 6 7 8",
"output": "-1"
},
{
"input": "4\n2 4 1 3",
"output": "-1"
}
] | 1,591,098,720 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 156 | 7,680,000 | n=int(input())
a=[int(i) for i in input().split()]
c=0
ind=-1
for i in range(1,n):
if a[i]<a[i-1]:
c+=1
s=i
if c==0:
print(0)
elif a[0]>=a[n-1]and c==1:
print(n-s)
else:
print(-1) | Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
Demo Input:
['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['1\n', '-1\n', '0\n']
Note:
none | ```python
n=int(input())
a=[int(i) for i in input().split()]
c=0
ind=-1
for i in range(1,n):
if a[i]<a[i-1]:
c+=1
s=i
if c==0:
print(0)
elif a[0]>=a[n-1]and c==1:
print(n-s)
else:
print(-1)
``` | 3 |
|
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,691,127,210 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | arr = list(map(int , input().split()))
arr.sort()
print(arr[0] , (arr[1] - arr[0]) // 2) | 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
arr = list(map(int , input().split()))
arr.sort()
print(arr[0] , (arr[1] - arr[0]) // 2)
``` | 3 |
|
182 | B | Vasya's Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number *d*<=+<=1, so after day number *d* it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day *d* is also followed by day 1.
Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month.
A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the *n*-th month inclusive, considering that on the first day of the first month the clock display showed day 1. | The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106).
The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000).
The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — the number of days in each month in the order in which they follow, starting from the first one. | Print a single number — the number of times Vasya manually increased the day number by one throughout the last year. | [
"4\n2\n2 2\n",
"5\n3\n3 4 3\n",
"31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n"
] | [
"2\n",
"3\n",
"7\n"
] | In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1. - Day 2. Month 2. The clock shows 2. Vasya changes nothing. | 500 | [
{
"input": "4\n2\n2 2",
"output": "2"
},
{
"input": "5\n3\n3 4 3",
"output": "3"
},
{
"input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31",
"output": "7"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n1 1",
"output": "0"
},
{
"input": "2\n2\n1 1",
"output": "1"
},
{
"input": "10\n2\n10 2",
"output": "0"
},
{
"input": "10\n3\n6 3 6",
"output": "11"
},
{
"input": "10\n4\n8 7 1 5",
"output": "14"
},
{
"input": "10\n5\n2 7 8 4 4",
"output": "19"
},
{
"input": "10\n6\n8 3 4 9 6 1",
"output": "20"
},
{
"input": "10\n7\n10 5 3 1 1 9 1",
"output": "31"
},
{
"input": "10\n8\n6 5 10 6 8 1 3 2",
"output": "31"
},
{
"input": "10\n9\n6 2 7 5 5 4 8 6 2",
"output": "37"
},
{
"input": "10\n10\n1 10 1 10 1 1 7 8 6 7",
"output": "45"
},
{
"input": "100\n100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52",
"output": "5099"
},
{
"input": "101\n100\n19 17 15 16 28 69 41 47 75 42 19 98 16 90 92 47 21 4 98 17 27 31 90 10 14 92 62 73 56 55 6 60 62 22 78 1 3 86 18 59 92 41 21 34 67 9 92 78 77 45 50 92 57 61 11 98 89 72 57 93 100 12 61 48 5 48 38 9 65 64 77 29 18 55 94 42 10 77 43 46 7 89 8 13 5 53 80 59 23 100 30 28 29 24 85 56 10 22 24 16",
"output": "5301"
},
{
"input": "102\n100\n31 22 59 16 11 56 81 4 19 31 8 72 4 92 18 7 13 12 62 40 34 67 40 23 96 4 90 28 3 18 54 49 10 71 73 79 69 7 41 75 59 13 2 78 72 6 95 33 52 97 7 86 57 94 12 93 19 94 59 28 5 96 46 102 2 101 57 85 53 69 72 39 14 75 8 16 10 57 26 4 85 18 89 84 48 93 54 21 78 6 67 35 11 78 91 91 97 15 8 32",
"output": "5447"
},
{
"input": "103\n100\n68 38 41 54 37 11 35 26 43 97 70 3 13 11 64 83 3 95 99 16 4 13 22 27 64 20 95 38 40 87 6 17 95 67 31 24 85 33 98 24 89 101 66 38 42 5 95 18 95 13 103 85 72 73 68 93 22 59 48 59 72 46 5 41 54 32 48 69 3 76 2 26 102 44 39 58 55 85 40 16 81 78 92 63 25 97 83 2 54 16 20 63 19 8 84 34 1 22 43 93",
"output": "5358"
},
{
"input": "104\n100\n65 74 94 71 98 38 88 67 71 84 45 79 55 86 55 51 27 89 14 66 29 63 8 103 98 94 87 81 58 68 24 96 60 36 48 95 28 72 95 42 87 7 14 23 99 77 34 14 90 31 8 99 29 30 9 88 42 1 77 61 55 85 17 98 62 78 27 1 58 69 82 62 62 81 56 104 66 8 17 23 7 61 59 70 79 64 78 16 32 11 59 4 24 73 55 2 95 39 62 13",
"output": "4773"
}
] | 1,666,154,184 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | t = int(input())
a = int(input())
l = input().split(' ')
times = 0
for i in range(0, a-1):
times += t - int(l[i])
print(times)
| Title: Vasya's Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number *d*<=+<=1, so after day number *d* it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day *d* is also followed by day 1.
Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month.
A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the *n*-th month inclusive, considering that on the first day of the first month the clock display showed day 1.
Input Specification:
The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106).
The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000).
The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — the number of days in each month in the order in which they follow, starting from the first one.
Output Specification:
Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.
Demo Input:
['4\n2\n2 2\n', '5\n3\n3 4 3\n', '31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n']
Demo Output:
['2\n', '3\n', '7\n']
Note:
In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1. - Day 2. Month 2. The clock shows 2. Vasya changes nothing. | ```python
t = int(input())
a = int(input())
l = input().split(' ')
times = 0
for i in range(0, a-1):
times += t - int(l[i])
print(times)
``` | 3 |
|
559 | A | Gerald's Hexagon | PROGRAMMING | 1,600 | [
"brute force",
"geometry",
"math"
] | null | null | Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles. | The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists. | Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. | [
"1 1 1 1 1 1\n",
"1 2 1 2 1 2\n"
] | [
"6\n",
"13\n"
] | This is what Gerald's hexagon looks like in the first sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's what it looks like in the second sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 500 | [
{
"input": "1 1 1 1 1 1",
"output": "6"
},
{
"input": "1 2 1 2 1 2",
"output": "13"
},
{
"input": "2 4 5 3 3 6",
"output": "83"
},
{
"input": "45 19 48 18 46 21",
"output": "6099"
},
{
"input": "66 6 65 6 66 5",
"output": "5832"
},
{
"input": "7 5 4 8 4 5",
"output": "175"
},
{
"input": "3 2 1 4 1 2",
"output": "25"
},
{
"input": "7 1 7 3 5 3",
"output": "102"
},
{
"input": "9 2 9 3 8 3",
"output": "174"
},
{
"input": "1 6 1 5 2 5",
"output": "58"
},
{
"input": "41 64 48 61 44 68",
"output": "17488"
},
{
"input": "1 59 2 59 1 60",
"output": "3838"
},
{
"input": "30 36 36 32 34 38",
"output": "7052"
},
{
"input": "50 40 46 38 52 34",
"output": "11176"
},
{
"input": "4 60 4 60 4 60",
"output": "4576"
},
{
"input": "718 466 729 470 714 481",
"output": "2102808"
},
{
"input": "131 425 143 461 95 473",
"output": "441966"
},
{
"input": "125 7 128 8 124 11",
"output": "20215"
},
{
"input": "677 303 685 288 692 296",
"output": "1365807"
},
{
"input": "1 577 7 576 2 582",
"output": "342171"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "6000000"
},
{
"input": "1 1 1000 1 1 1000",
"output": "4002"
},
{
"input": "1000 1000 1 1000 1000 1",
"output": "2004000"
},
{
"input": "1000 1 1000 999 2 999",
"output": "2003997"
},
{
"input": "1 1000 1 1 1000 1",
"output": "4002"
},
{
"input": "888 888 888 887 889 887",
"output": "4729487"
}
] | 1,691,963,585 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | # динпрог на одномерном массиве
'''
from random import randint
for _ in range(int(input())):
n = int(input())
dp = [0]+[10**9 for i in range(n-1)]
price = [0]+[randint(1, 10) for i in range(n-1)]
for j in range(n):
if j+1<n:
dp[j+1]=min(dp[j+1], dp[j]+price[j+1])
if j+2<n:
dp[j+2]=min(dp[j+2], dp[j]+price[j+2])
if j+3<n:
dp[j+3]=min(dp[j+3], dp[j]+price[j+3])
print(price)
print(dp)
'''
# динпрог на двумерном массиве
'''
for _ in range(int(input())):
n = int(input())
x, y = input().split()
dp = [[0 for i in range(n)] for i in range(n)]
for i, x_ in enumerate(x):
for j, y_ in enumerate(y):
if x_ == y_:
dp[i][j] = dp[i-1][j-1]+1
else:
dp[i][j] = max(dp[i-1][j], dp[i][j-1])
print(*dp)
'''
# парадокс дней рождений
'''
from random import randint
d = []
g = False
n = int(input())
print('[ ', end='')
for _ in range(n):
a = randint(1, 365)
print(a, end = '')
if a in d:
g = True
print('-, ', end = '')
else:
d.append(a)
print(', ', end = '')
chance = 1
for guys in range(1, n):
chance*=(1-(guys/365))
if not g:
print(']\n(Не было) шанс что так будет =', str(chance*100)[:6], '%')
else:
print(']\n(Было); шанс что так будет =', str(100-chance*100)[:6], '%')
'''
# Префиксные суммы
'''
a = map(int, input().split())
d = [0]
for j in a:
d.append(d[-1]+j)
print(d)
for _ in range(int(input('Кол-во запросов = '))):
l, r = map(int, input().split())
print('->', d[r]-d[l-1])
'''
s = list(map(int, input().split()))
tot = 0
y, x = max(s), min(s)
_x = 2*x+1
_y = 2*y+1
for i in range(y):
tot+=_x
_x+=2
for i in range(x):
tot+=_y
_y+=2
print(tot)
| Title: Gerald's Hexagon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.
Input Specification:
The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.
Output Specification:
Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.
Demo Input:
['1 1 1 1 1 1\n', '1 2 1 2 1 2\n']
Demo Output:
['6\n', '13\n']
Note:
This is what Gerald's hexagon looks like in the first sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's what it looks like in the second sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
# динпрог на одномерном массиве
'''
from random import randint
for _ in range(int(input())):
n = int(input())
dp = [0]+[10**9 for i in range(n-1)]
price = [0]+[randint(1, 10) for i in range(n-1)]
for j in range(n):
if j+1<n:
dp[j+1]=min(dp[j+1], dp[j]+price[j+1])
if j+2<n:
dp[j+2]=min(dp[j+2], dp[j]+price[j+2])
if j+3<n:
dp[j+3]=min(dp[j+3], dp[j]+price[j+3])
print(price)
print(dp)
'''
# динпрог на двумерном массиве
'''
for _ in range(int(input())):
n = int(input())
x, y = input().split()
dp = [[0 for i in range(n)] for i in range(n)]
for i, x_ in enumerate(x):
for j, y_ in enumerate(y):
if x_ == y_:
dp[i][j] = dp[i-1][j-1]+1
else:
dp[i][j] = max(dp[i-1][j], dp[i][j-1])
print(*dp)
'''
# парадокс дней рождений
'''
from random import randint
d = []
g = False
n = int(input())
print('[ ', end='')
for _ in range(n):
a = randint(1, 365)
print(a, end = '')
if a in d:
g = True
print('-, ', end = '')
else:
d.append(a)
print(', ', end = '')
chance = 1
for guys in range(1, n):
chance*=(1-(guys/365))
if not g:
print(']\n(Не было) шанс что так будет =', str(chance*100)[:6], '%')
else:
print(']\n(Было); шанс что так будет =', str(100-chance*100)[:6], '%')
'''
# Префиксные суммы
'''
a = map(int, input().split())
d = [0]
for j in a:
d.append(d[-1]+j)
print(d)
for _ in range(int(input('Кол-во запросов = '))):
l, r = map(int, input().split())
print('->', d[r]-d[l-1])
'''
s = list(map(int, input().split()))
tot = 0
y, x = max(s), min(s)
_x = 2*x+1
_y = 2*y+1
for i in range(y):
tot+=_x
_x+=2
for i in range(x):
tot+=_y
_y+=2
print(tot)
``` | 0 |
|
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
"input": "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746",
"output": "245"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "3\n607\n684",
"output": "5"
},
{
"input": "4\n0809\n0636",
"output": "8"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8037856825987124762280548\n9519431339078678836940020",
"output": "72"
},
{
"input": "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024",
"output": "305"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8037856825987124762285484\n9519431339078678836940202",
"output": "74"
},
{
"input": "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831",
"output": "357"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8378525987476228048406972\n9194339078883694020217816",
"output": "55"
},
{
"input": "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599",
"output": "274"
},
{
"input": "1\n0\n0",
"output": "0"
},
{
"input": "1\n7\n7",
"output": "0"
},
{
"input": "1\n0\n5",
"output": "5"
},
{
"input": "1\n2\n7",
"output": "5"
},
{
"input": "1\n7\n9",
"output": "2"
},
{
"input": "1\n9\n7",
"output": "2"
},
{
"input": "1\n2\n9",
"output": "3"
},
{
"input": "1\n9\n2",
"output": "3"
},
{
"input": "25\n3164978461316464614169874\n9413979197249127496597357",
"output": "66"
},
{
"input": "4\n9999\n9999",
"output": "0"
},
{
"input": "2\n11\n11",
"output": "0"
}
] | 1,621,279,517 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 77 | 0 | n = input()
a1 = list( map( int , list(input() )))
a2 = list( map( int , list(input() )))
def func(n1, n2):
return min(abs(n1-n2), 10 - abs(n1- n2))
count = 0
for n1, n2 in zip(a1, a2):
count += func(n1, n2)
print(count)
| Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Output Specification:
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
Demo Input:
['5\n82195\n64723\n']
Demo Output:
['13\n']
Note:
In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
n = input()
a1 = list( map( int , list(input() )))
a2 = list( map( int , list(input() )))
def func(n1, n2):
return min(abs(n1-n2), 10 - abs(n1- n2))
count = 0
for n1, n2 in zip(a1, a2):
count += func(n1, n2)
print(count)
``` | 3 |
|
405 | A | Gravity Flip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch! | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | 500 | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20 1 80",
"output": "1 20 40 60 80 100 "
},
{
"input": "10\n10 8 6 7 5 3 4 2 9 1",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91",
"output": "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100 "
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 "
},
{
"input": "10\n1 9 7 6 2 4 7 8 1 3",
"output": "1 1 2 3 4 6 7 7 8 9 "
},
{
"input": "20\n53 32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59",
"output": "20 20 22 30 32 41 50 53 54 59 60 61 64 66 68 72 74 80 97 97 "
},
{
"input": "30\n7 17 4 18 16 12 14 10 1 13 2 16 13 17 8 16 13 14 9 17 17 5 13 5 1 7 6 20 18 12",
"output": "1 1 2 4 5 5 6 7 7 8 9 10 12 12 13 13 13 13 14 14 16 16 16 17 17 17 17 18 18 20 "
},
{
"input": "40\n22 58 68 58 48 53 52 1 16 78 75 17 63 15 36 32 78 75 49 14 42 46 66 54 49 82 40 43 46 55 12 73 5 45 61 60 1 11 31 84",
"output": "1 1 5 11 12 14 15 16 17 22 31 32 36 40 42 43 45 46 46 48 49 49 52 53 54 55 58 58 60 61 63 66 68 73 75 75 78 78 82 84 "
},
{
"input": "70\n1 3 3 1 3 3 1 1 1 3 3 2 3 3 1 1 1 2 3 1 3 2 3 3 3 2 2 3 1 3 3 2 1 1 2 1 2 1 2 2 1 1 1 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3 3 3 1 1 3 3 1 1 1 1 3 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52",
"output": "2 3 4 5 5 5 6 6 6 7 7 7 7 10 10 11 11 15 16 17 17 17 18 19 19 20 21 21 21 23 24 24 27 27 30 34 40 43 43 44 46 46 48 48 49 49 50 51 51 51 52 52 53 55 55 58 63 64 65 66 66 66 67 71 71 73 75 75 76 76 77 79 82 85 85 88 88 90 91 91 92 93 95 95 95 96 98 99 100 100 "
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "100\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6",
"output": "1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 "
},
{
"input": "100\n12 10 5 11 13 12 14 13 7 15 15 12 13 19 12 18 14 10 10 3 1 10 16 11 19 8 10 15 5 10 12 16 11 13 11 15 14 12 16 8 11 8 15 2 18 2 14 13 15 20 8 8 4 12 14 7 10 3 9 1 7 19 6 7 2 14 8 20 7 17 18 20 3 18 18 9 6 10 4 1 4 19 9 13 3 3 12 11 11 20 8 2 13 6 7 12 1 4 17 3",
"output": "1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 "
},
{
"input": "100\n5 13 1 40 30 10 23 32 33 12 6 4 15 29 31 17 23 5 36 31 32 38 24 11 34 39 19 21 6 19 31 35 1 15 6 29 22 15 17 15 1 17 2 34 20 8 27 2 29 26 13 9 22 27 27 3 20 40 4 40 33 29 36 30 35 16 19 28 26 11 36 24 29 5 40 10 38 34 33 23 34 39 31 7 10 31 22 6 36 24 14 31 34 23 2 4 26 16 2 32",
"output": "1 1 1 2 2 2 2 3 4 4 4 5 5 5 6 6 6 6 7 8 9 10 10 10 11 11 12 13 13 14 15 15 15 15 16 16 17 17 17 19 19 19 20 20 21 22 22 22 23 23 23 23 24 24 24 26 26 26 27 27 27 28 29 29 29 29 29 30 30 31 31 31 31 31 31 32 32 32 33 33 33 34 34 34 34 34 35 35 36 36 36 36 38 38 39 39 40 40 40 40 "
},
{
"input": "100\n72 44 34 74 9 60 26 37 55 77 74 69 28 66 54 55 8 36 57 31 31 48 32 66 40 70 77 43 64 28 37 10 21 58 51 32 60 28 51 52 28 35 7 33 1 68 38 70 57 71 8 20 42 57 59 4 58 10 17 47 22 48 16 3 76 67 32 37 64 47 33 41 75 69 2 76 39 9 27 75 20 21 52 25 71 21 11 29 38 10 3 1 45 55 63 36 27 7 59 41",
"output": "1 1 2 3 3 4 7 7 8 8 9 9 10 10 10 11 16 17 20 20 21 21 21 22 25 26 27 27 28 28 28 28 29 31 31 32 32 32 33 33 34 35 36 36 37 37 37 38 38 39 40 41 41 42 43 44 45 47 47 48 48 51 51 52 52 54 55 55 55 57 57 57 58 58 59 59 60 60 63 64 64 66 66 67 68 69 69 70 70 71 71 72 74 74 75 75 76 76 77 77 "
},
{
"input": "100\n75 18 61 10 56 53 42 57 79 80 31 2 50 45 54 99 84 52 71 21 86 3 19 98 14 37 40 62 63 68 5 10 87 8 81 85 52 52 57 94 2 7 56 96 19 76 1 13 81 6 80 47 22 59 99 32 9 5 36 88 98 91 70 70 12 93 12 22 85 1 97 48 94 16 84 84 51 34 62 7 68 51 30 2 37 82 4 7 27 1 80 9 61 16 59 55 12 96 94 82",
"output": "1 1 1 2 2 2 3 4 5 5 6 7 7 7 8 9 9 10 10 12 12 12 13 14 16 16 18 19 19 21 22 22 27 30 31 32 34 36 37 37 40 42 45 47 48 50 51 51 52 52 52 53 54 55 56 56 57 57 59 59 61 61 62 62 63 68 68 70 70 71 75 76 79 80 80 80 81 81 82 82 84 84 84 85 85 86 87 88 91 93 94 94 94 96 96 97 98 98 99 99 "
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 "
},
{
"input": "49\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 "
},
{
"input": "30\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88",
"output": "1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 "
},
{
"input": "100\n100 51 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 51 100 "
},
{
"input": "10\n100 90 80 70 60 50 40 30 20 10",
"output": "10 20 30 40 50 60 70 80 90 100 "
},
{
"input": "1\n10",
"output": "10 "
}
] | 1,694,023,523 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n=input()
n=int(n)
x=[int(i) for i in input().split()]
x.sort()
for i in range(n):
print(x[i],end="")
| Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch!
Input Specification:
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output Specification:
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
Demo Input:
['4\n3 2 1 2\n', '3\n2 3 8\n']
Demo Output:
['1 2 2 3 \n', '2 3 8 \n']
Note:
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | ```python
n=input()
n=int(n)
x=[int(i) for i in input().split()]
x.sort()
for i in range(n):
print(x[i],end="")
``` | 0 |
|
965 | B | Battleship | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Arkady is playing Battleship. The rules of this game aren't really important.
There is a field of $n \times n$ cells. There should be exactly one $k$-decker on the field, i. e. a ship that is $k$ cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.
Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship. | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the size of the field and the size of the ship.
The next $n$ lines contain the field. Each line contains $n$ characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship). | Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship.
If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell. | [
"4 3\n#..#\n#.#.\n....\n.###\n",
"10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#\n",
"19 6\n##..............###\n#......#####.....##\n.....#########.....\n....###########....\n...#############...\n..###############..\n.#################.\n.#################.\n.#################.\n.#################.\n#####....##....####\n####............###\n####............###\n#####...####...####\n.#####..####..#####\n...###........###..\n....###########....\n.........##........\n#.................#\n"
] | [
"3 2\n",
"6 1\n",
"1 8\n"
] | The picture below shows the three possible locations of the ship that contain the cell $(3, 2)$ in the first sample. | 1,000 | [
{
"input": "4 3\n#..#\n#.#.\n....\n.###",
"output": "3 2"
},
{
"input": "10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#",
"output": "6 1"
},
{
"input": "19 6\n##..............###\n#......#####.....##\n.....#########.....\n....###########....\n...#############...\n..###############..\n.#################.\n.#################.\n.#################.\n.#################.\n#####....##....####\n####............###\n####............###\n#####...####...####\n.#####..####..#####\n...###........###..\n....###########....\n.........##........\n#.................#",
"output": "1 8"
},
{
"input": "10 4\n##..######\n#...######\n#...######\n#......###\n#.......##\n.##.######\n.##.######\n.##.######\n.#....####\n....######",
"output": "4 4"
},
{
"input": "1 1\n.",
"output": "1 1"
},
{
"input": "1 1\n#",
"output": "1 1"
},
{
"input": "5 2\n..##.\n.###.\n#####\n#####\n..#..",
"output": "1 1"
},
{
"input": "5 2\n..##.\n####.\n#####\n.####\n..#..",
"output": "5 1"
},
{
"input": "5 2\n..##.\n####.\n#####\n####.\n..#..",
"output": "5 5"
},
{
"input": "5 2\n.##..\n.###.\n#####\n#####\n..#..",
"output": "1 5"
},
{
"input": "2 2\n##\n##",
"output": "1 1"
},
{
"input": "4 1\n####\n####\n####\n###.",
"output": "4 4"
},
{
"input": "2 2\n#.\n.#",
"output": "1 1"
},
{
"input": "3 3\n###\n##.\n###",
"output": "1 1"
},
{
"input": "4 4\n####\n####\n####\n####",
"output": "1 1"
},
{
"input": "4 3\n####\n####\n####\n####",
"output": "1 1"
},
{
"input": "3 1\n###\n###\n###",
"output": "1 1"
},
{
"input": "3 2\n###\n###\n###",
"output": "1 1"
},
{
"input": "3 3\n.#.\n#.#\n.#.",
"output": "1 1"
}
] | 1,524,746,267 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 233 | 24,576,000 | def fix(a,b,c):
ret=min(a,c+k-1)-max(c-k+1,b)-k+2
return [0,ret][ret>0]
def solve(row,col):
a1=a2=row
a3=a4=col
while(a1+1>=0 and a1+1<n and mp[a1+1][col]!='#'):
a1+=1
while(a2-1>=0 and a2-1<n and mp[a2-1][col]!='#'):
a2-=1
while(a3+1>=0 and a3+1<n and mp[row][a3+1]!='#'):
a3+=1
while(a4-1>=0 and a4-1<n and mp[row][a4-1]!='#'):
a4-=1
return fix(a1,a2,row)+fix(a3,a4,col)
n,k=map(int,input().split())
mp=[]
r=c=ans=0
for _ in range(n):
mp.append(input())
for i in range(n):
for j in range(n):
if mp[i][j]!= '#':
tp = solve(i, j)
if tp>ans:
ans=tp
r=i
c=j
print(r+1,c+1) | Title: Battleship
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady is playing Battleship. The rules of this game aren't really important.
There is a field of $n \times n$ cells. There should be exactly one $k$-decker on the field, i. e. a ship that is $k$ cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.
Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship.
Input Specification:
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the size of the field and the size of the ship.
The next $n$ lines contain the field. Each line contains $n$ characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship).
Output Specification:
Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship.
If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell.
Demo Input:
['4 3\n#..#\n#.#.\n....\n.###\n', '10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#\n', '19 6\n##..............###\n#......#####.....##\n.....#########.....\n....###########....\n...#############...\n..###############..\n.#################.\n.#################.\n.#################.\n.#################.\n#####....##....####\n####............###\n####............###\n#####...####...####\n.#####..####..#####\n...###........###..\n....###########....\n.........##........\n#.................#\n']
Demo Output:
['3 2\n', '6 1\n', '1 8\n']
Note:
The picture below shows the three possible locations of the ship that contain the cell $(3, 2)$ in the first sample. | ```python
def fix(a,b,c):
ret=min(a,c+k-1)-max(c-k+1,b)-k+2
return [0,ret][ret>0]
def solve(row,col):
a1=a2=row
a3=a4=col
while(a1+1>=0 and a1+1<n and mp[a1+1][col]!='#'):
a1+=1
while(a2-1>=0 and a2-1<n and mp[a2-1][col]!='#'):
a2-=1
while(a3+1>=0 and a3+1<n and mp[row][a3+1]!='#'):
a3+=1
while(a4-1>=0 and a4-1<n and mp[row][a4-1]!='#'):
a4-=1
return fix(a1,a2,row)+fix(a3,a4,col)
n,k=map(int,input().split())
mp=[]
r=c=ans=0
for _ in range(n):
mp.append(input())
for i in range(n):
for j in range(n):
if mp[i][j]!= '#':
tp = solve(i, j)
if tp>ans:
ans=tp
r=i
c=j
print(r+1,c+1)
``` | 3 |
|
152 | B | Steps | PROGRAMMING | 1,300 | [
"binary search",
"implementation"
] | null | null | One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple.
Vasya noticed that the yard is a rectangular *n*<=×<=*m* field. The squares have coordinates (*x*,<=*y*) (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*), where *x* is the index of the row and *y* is the index of the column.
Initially Vasya stands in the square with coordinates (*x**c*,<=*y**c*). To play, he has got a list of *k* vectors (*dx**i*,<=*dy**i*) of non-zero length. The game goes like this. The boy considers all vectors in the order from 1 to *k*, and consecutively chooses each vector as the current one. After the boy has chosen a current vector, he makes the maximally possible number of valid steps in the vector's direction (it is possible that he makes zero steps).
A step is defined as one movement from the square where the boy is standing now, in the direction of the current vector. That is, if Vasya is positioned in square (*x*,<=*y*), and the current vector is (*dx*,<=*dy*), one step moves Vasya to square (*x*<=+<=*dx*,<=*y*<=+<=*dy*). A step is considered valid, if the boy does not go out of the yard if he performs the step.
Vasya stepped on and on, on and on until he ran out of vectors in his list. Ha had been stepping for so long that he completely forgot how many steps he had made. Help the boy and count how many steps he had made. | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the yard's sizes. The second line contains integers *x**c* and *y**c* — the initial square's coordinates (1<=≤<=*x**c*<=≤<=*n*,<=1<=≤<=*y**c*<=≤<=*m*).
The third line contains an integer *k* (1<=≤<=*k*<=≤<=104) — the number of vectors. Then follow *k* lines, each of them contains two integers *dx**i* and *dy**i* (|*dx**i*|,<=|*dy**i*|<=≤<=109,<=|*dx*|<=+<=|*dy*|<=≥<=1). | Print the single number — the number of steps Vasya had made.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"4 5\n1 1\n3\n1 1\n1 1\n0 -2\n",
"10 10\n1 2\n1\n-1 0\n"
] | [
"4\n",
"0\n"
] | In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall, Vasya makes 4 steps.
In the second sample Vasya is initially positioned in square (1, 2) and makes 0 steps by vector ( - 1, 0), as the square with coordinates (0, 2) is located outside the yard. | 1,000 | [
{
"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2",
"output": "4"
},
{
"input": "10 10\n1 2\n1\n-1 0",
"output": "0"
},
{
"input": "10 20\n10 3\n10\n-2 -6\n-1 0\n-8 0\n0 5\n-1 3\n16 -16\n-1 9\n0 -18\n9 -1\n-9 5",
"output": "13"
},
{
"input": "20 10\n14 4\n10\n6 0\n-7 -7\n12 -2\n-4 9\n20 3\n-1 -16\n0 2\n-1 1\n20 0\n-1 1",
"output": "4"
},
{
"input": "1000 2000\n226 566\n20\n0 -100\n-100 100\n100 0\n42 0\n-100 -79\n-66 -16\n0 -7\n-1 0\n0 100\n100 91\n99 0\n1 0\n-100 0\n70 -100\n-100 100\n100 1\n66 0\n-100 1\n-47 -100\n-42 0",
"output": "708"
},
{
"input": "1 1\n1 1\n1\n1 1",
"output": "0"
},
{
"input": "3 3\n2 2\n1\n2 0",
"output": "0"
}
] | 1,660,325,217 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | def check(x,y):
global n,m
if x>0 and x<=n and y>0 and y<=m:
return True
return False
n,m=list(map(int,input().split()));pos=list(map(int,input().split()));k=int(input());steps=0
for i in range(k):
maxi=10**9;mini=0;arr=[]
x,y=list(map(int,input().split()))
while mini<=maxi:
midian=int((maxi+mini)/2)
if check(pos[0]+x*midian,pos[1]+y*midian):mini=midian+1
else: maxi=midian-1
mi=midian;pos[0]+=mi*x;pos[1]+=mi*y
steps+=mi
print(steps)
| Title: Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple.
Vasya noticed that the yard is a rectangular *n*<=×<=*m* field. The squares have coordinates (*x*,<=*y*) (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*), where *x* is the index of the row and *y* is the index of the column.
Initially Vasya stands in the square with coordinates (*x**c*,<=*y**c*). To play, he has got a list of *k* vectors (*dx**i*,<=*dy**i*) of non-zero length. The game goes like this. The boy considers all vectors in the order from 1 to *k*, and consecutively chooses each vector as the current one. After the boy has chosen a current vector, he makes the maximally possible number of valid steps in the vector's direction (it is possible that he makes zero steps).
A step is defined as one movement from the square where the boy is standing now, in the direction of the current vector. That is, if Vasya is positioned in square (*x*,<=*y*), and the current vector is (*dx*,<=*dy*), one step moves Vasya to square (*x*<=+<=*dx*,<=*y*<=+<=*dy*). A step is considered valid, if the boy does not go out of the yard if he performs the step.
Vasya stepped on and on, on and on until he ran out of vectors in his list. Ha had been stepping for so long that he completely forgot how many steps he had made. Help the boy and count how many steps he had made.
Input Specification:
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the yard's sizes. The second line contains integers *x**c* and *y**c* — the initial square's coordinates (1<=≤<=*x**c*<=≤<=*n*,<=1<=≤<=*y**c*<=≤<=*m*).
The third line contains an integer *k* (1<=≤<=*k*<=≤<=104) — the number of vectors. Then follow *k* lines, each of them contains two integers *dx**i* and *dy**i* (|*dx**i*|,<=|*dy**i*|<=≤<=109,<=|*dx*|<=+<=|*dy*|<=≥<=1).
Output Specification:
Print the single number — the number of steps Vasya had made.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Demo Input:
['4 5\n1 1\n3\n1 1\n1 1\n0 -2\n', '10 10\n1 2\n1\n-1 0\n']
Demo Output:
['4\n', '0\n']
Note:
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall, Vasya makes 4 steps.
In the second sample Vasya is initially positioned in square (1, 2) and makes 0 steps by vector ( - 1, 0), as the square with coordinates (0, 2) is located outside the yard. | ```python
def check(x,y):
global n,m
if x>0 and x<=n and y>0 and y<=m:
return True
return False
n,m=list(map(int,input().split()));pos=list(map(int,input().split()));k=int(input());steps=0
for i in range(k):
maxi=10**9;mini=0;arr=[]
x,y=list(map(int,input().split()))
while mini<=maxi:
midian=int((maxi+mini)/2)
if check(pos[0]+x*midian,pos[1]+y*midian):mini=midian+1
else: maxi=midian-1
mi=midian;pos[0]+=mi*x;pos[1]+=mi*y
steps+=mi
print(steps)
``` | 0 |
|
952 | A | Quirky Quantifiers | PROGRAMMING | 800 | [
"math"
] | null | null | The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output 0 or 1. | The input contains a single integer *a* (10<=≤<=*a*<=≤<=999). | Output 0 or 1. | [
"13\n",
"927\n",
"48\n"
] | [
"1\n",
"1\n",
"0\n"
] | none | 0 | [
{
"input": "13",
"output": "1"
},
{
"input": "927",
"output": "1"
},
{
"input": "48",
"output": "0"
},
{
"input": "10",
"output": "0"
},
{
"input": "999",
"output": "1"
},
{
"input": "142",
"output": "0"
},
{
"input": "309",
"output": "1"
},
{
"input": "572",
"output": "0"
},
{
"input": "835",
"output": "1"
},
{
"input": "990",
"output": "0"
},
{
"input": "168",
"output": "0"
},
{
"input": "431",
"output": "1"
},
{
"input": "694",
"output": "0"
},
{
"input": "957",
"output": "1"
},
{
"input": "932",
"output": "0"
}
] | 1,618,562,039 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | def main_function():
s = input()
return 0
print(main_function()) | Title: Quirky Quantifiers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output 0 or 1.
Input Specification:
The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output Specification:
Output 0 or 1.
Demo Input:
['13\n', '927\n', '48\n']
Demo Output:
['1\n', '1\n', '0\n']
Note:
none | ```python
def main_function():
s = input()
return 0
print(main_function())
``` | 0 |
|
525 | B | Pasha and String | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null | Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent *m* days performing the following transformations on his string — each day he chose integer *a**i* and reversed a piece of string (a segment) from position *a**i* to position |*s*|<=-<=*a**i*<=+<=1. It is guaranteed that 2·*a**i*<=≤<=|*s*|.
You face the following task: determine what Pasha's string will look like after *m* days. | The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<=*a**i*; 2·*a**i*<=≤<=|*s*|) — the position from which Pasha started transforming the string on the *i*-th day. | In the first line of the output print what Pasha's string *s* will look like after *m* days. | [
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] | [
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] | none | 750 | [
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"output": "wyjldgqxlc"
},
{
"input": "keicnqmuqinhsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavs\n2\n5 12",
"output": "keiccyobhhphsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlniqumqnfavs"
},
{
"input": "xwcxggxvfqbdklewbxkjzibmufnaywuxsqvwakefxbbkfandvigasbhbatsxyqxicrosatfsfybedklsaztyyiuurfbrzmwumujy\n100\n14 43 30 13 8 19 33 7 8 14 15 35 5 18 44 1 35 1 18 7 50 47 9 49 28 29 39 37 27 17 19 12 5 24 37 42 37 23 35 31 10 26 5 38 40 34 42 47 2 40 43 34 16 25 14 45 35 38 46 48 49 27 49 38 10 49 5 7 3 3 41 25 24 34 37 33 17 50 48 11 40 43 48 10 9 50 18 39 32 13 26 40 37 16 45 50 27 3 7 31",
"output": "xjcxggxvfbbruliyyxkjzikdebnfyftxsorcaxqyxbtkfhbdvigasnababsxfekiwvqsauwsayfumblsaztbweukdfqrzmwumuwy"
}
] | 1,544,090,159 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 233 | 16,384,000 | I=input
s=list(I())
S=len(s)
n=int(I())
t=0
*l,=sorted(map(int,I().split()))
for i in range(S//2):
while t<n and l[t]<=i+1:t+=1
if t%2:s[i],s[S-i-1]=s[S-i-1],s[i]
print(''.join(s)) | Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent *m* days performing the following transformations on his string — each day he chose integer *a**i* and reversed a piece of string (a segment) from position *a**i* to position |*s*|<=-<=*a**i*<=+<=1. It is guaranteed that 2·*a**i*<=≤<=|*s*|.
You face the following task: determine what Pasha's string will look like after *m* days.
Input Specification:
The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<=*a**i*; 2·*a**i*<=≤<=|*s*|) — the position from which Pasha started transforming the string on the *i*-th day.
Output Specification:
In the first line of the output print what Pasha's string *s* will look like after *m* days.
Demo Input:
['abcdef\n1\n2\n', 'vwxyz\n2\n2 2\n', 'abcdef\n3\n1 2 3\n']
Demo Output:
['aedcbf\n', 'vwxyz\n', 'fbdcea\n']
Note:
none | ```python
I=input
s=list(I())
S=len(s)
n=int(I())
t=0
*l,=sorted(map(int,I().split()))
for i in range(S//2):
while t<n and l[t]<=i+1:t+=1
if t%2:s[i],s[S-i-1]=s[S-i-1],s[i]
print(''.join(s))
``` | 3 |
|
863 | A | Quasi-palindrome | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number *x*. Check if it's a quasi-palindromic number. | The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. | Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). | [
"131\n",
"320\n",
"2010200\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 0 | [
{
"input": "131",
"output": "YES"
},
{
"input": "320",
"output": "NO"
},
{
"input": "2010200",
"output": "YES"
},
{
"input": "1",
"output": "YES"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "999999998",
"output": "NO"
},
{
"input": "102000",
"output": "NO"
},
{
"input": "210000000",
"output": "NO"
},
{
"input": "213443120",
"output": "YES"
},
{
"input": "99",
"output": "YES"
},
{
"input": "22002",
"output": "NO"
},
{
"input": "1010",
"output": "YES"
},
{
"input": "1201",
"output": "NO"
},
{
"input": "6460046",
"output": "NO"
},
{
"input": "503435",
"output": "NO"
},
{
"input": "21002",
"output": "NO"
},
{
"input": "101001",
"output": "NO"
},
{
"input": "200102",
"output": "NO"
},
{
"input": "20010002",
"output": "NO"
},
{
"input": "33003",
"output": "NO"
},
{
"input": "100101",
"output": "NO"
},
{
"input": "1021",
"output": "NO"
},
{
"input": "1101",
"output": "NO"
},
{
"input": "10101100",
"output": "NO"
},
{
"input": "101",
"output": "YES"
},
{
"input": "1011",
"output": "NO"
},
{
"input": "11010",
"output": "NO"
},
{
"input": "10110",
"output": "NO"
},
{
"input": "110000",
"output": "YES"
},
{
"input": "2011",
"output": "NO"
},
{
"input": "10020001",
"output": "NO"
},
{
"input": "12505021",
"output": "NO"
},
{
"input": "12310",
"output": "NO"
},
{
"input": "100501",
"output": "NO"
},
{
"input": "11001",
"output": "NO"
},
{
"input": "20020002",
"output": "NO"
},
{
"input": "202002",
"output": "NO"
},
{
"input": "1001",
"output": "YES"
},
{
"input": "1020021",
"output": "NO"
},
{
"input": "60660",
"output": "NO"
},
{
"input": "98809",
"output": "NO"
},
{
"input": "11000000",
"output": "YES"
},
{
"input": "807008",
"output": "NO"
}
] | 1,544,105,870 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 109 | 0 | x =input()
s = ""
t = 0
for i in range(len(x)):
if x[len(x) - i -1] != "0":
s += x[len(x) -i -1]
t = 1
elif t != 0:
s += x[len(x) - i - 1]
r = ""
for i in range(len(s)):
r += s[len(s) - i -1]
if r == s:
print("YES")
else:
print("NO")
| Title: Quasi-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number *x*. Check if it's a quasi-palindromic number.
Input Specification:
The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes.
Output Specification:
Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes).
Demo Input:
['131\n', '320\n', '2010200\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
x =input()
s = ""
t = 0
for i in range(len(x)):
if x[len(x) - i -1] != "0":
s += x[len(x) -i -1]
t = 1
elif t != 0:
s += x[len(x) - i - 1]
r = ""
for i in range(len(s)):
r += s[len(s) - i -1]
if r == s:
print("YES")
else:
print("NO")
``` | 3 |
|
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.
Your problem is to print the minimum possible length of the sequence of moves after the replacements. | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR",
"output": "67"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURUUUUUUUUUUUUUUUUUUUUU",
"output": "99"
},
{
"input": "3\nRUR",
"output": "2"
},
{
"input": "1\nR",
"output": "1"
},
{
"input": "5\nRURUU",
"output": "3"
},
{
"input": "1\nU",
"output": "1"
},
{
"input": "2\nUR",
"output": "1"
},
{
"input": "23\nUUUUUUUUUUUUUUUUUUUUUUU",
"output": "23"
}
] | 1,646,825,213 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n=int(input());s=input();t=0
if n==1:print(1)
else:
if s[:2] in ['UR','RU']:
t+=1
for i in range(1,n-1):
if s[i-1:i+2] in ['UUR','RRU']:t+=1
print(t)
| Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.
Your problem is to print the minimum possible length of the sequence of moves after the replacements.
Input Specification:
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Output Specification:
Print the minimum possible length of the sequence of moves after all replacements are done.
Demo Input:
['5\nRUURU\n', '17\nUUURRRRRUUURURUUU\n']
Demo Output:
['3\n', '13\n']
Note:
In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | ```python
n=int(input());s=input();t=0
if n==1:print(1)
else:
if s[:2] in ['UR','RU']:
t+=1
for i in range(1,n-1):
if s[i-1:i+2] in ['UUR','RRU']:t+=1
print(t)
``` | 0 |
|
852 | G | Bathroom terminal | PROGRAMMING | 1,700 | [
"implementation"
] | null | null | Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is connected to the terminal next to him. After pressing a Play button a rough voice starts playing from the tape:
"Listen up Smith. As you can see, you are in pretty tough situation and in order to escape, you have to solve a puzzle.
You are given *N* strings which represent words. Each word is of the maximum length *L* and consists of characters 'a'-'e'. You are also given *M* strings which represent patterns. Pattern is a string of length <=≤<= *L* and consists of characters 'a'-'e' as well as the maximum 3 characters '?'. Character '?' is an unknown character, meaning it can be equal to any character 'a'-'e', or even an empty character. For each pattern find the number of words that matches with the given pattern. After solving it and typing the result in the terminal, the key will drop from the ceiling and you may escape. Let the game begin."
Help Smith escape. | The first line of input contains two integers *N* and *M* (1<=≤<=*N*<=≤<= 100 000, 1<=≤<=*M*<=≤<= 5000), representing the number of words and patterns respectively.
The next *N* lines represent each word, and after those *N* lines, following *M* lines represent each pattern. Each word and each pattern has a maximum length *L* (1<=≤<=*L*<=≤<=50). Each pattern has no more that three characters '?'. All other characters in words and patters are lowercase English letters from 'a' to 'e'. | Output contains *M* lines and each line consists of one integer, representing the number of words that match the corresponding pattern. | [
"3 1\nabc\naec\nac\na?c\n"
] | [
"3\n"
] | If we switch '?' with 'b', 'e' and with empty character, we get 'abc', 'aec' and 'ac' respectively. | 0 | [
{
"input": "3 1\nabc\naec\nac\na?c",
"output": "3"
},
{
"input": "22 2\naaaab\naaabb\naabab\naabbb\nabaab\nababb\nabbab\nabbbb\naaab\naabb\nabab\nabbb\naab\nabb\nab\ncccd\nccdd\ncdcd\ncddd\nccd\ncdd\ncd\na???b\nc??d",
"output": "15\n7"
},
{
"input": "15 6\naaa\naaabbb\naaabb\naaaaa\naaaaaa\naaaa\naaabbbb\naaaaa\naaaaaa\naaaa\naaabbbb\naabbbb\naa\naa\naab\na\n?a?\n??\n?aa?bb?\n?aa?aa?\n??aaa?",
"output": "0\n4\n2\n5\n6\n7"
}
] | 1,504,435,008 | 2,208 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n, m=map(int, input().split())
M=dict()
for i in range(n):
s=input()
if s in M:
M[s]+=1
else:
M[s]=1
t=['', 'a', 'b', 'c', 'd', 'e']
for i in range(m):
s=input()
ans=0
if '?' in s:
for p in t:
ans+=M.get(s.replace('?', p), 0)
else:
ans=M.get(s, 0)
print(ans)
| Title: Bathroom terminal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is connected to the terminal next to him. After pressing a Play button a rough voice starts playing from the tape:
"Listen up Smith. As you can see, you are in pretty tough situation and in order to escape, you have to solve a puzzle.
You are given *N* strings which represent words. Each word is of the maximum length *L* and consists of characters 'a'-'e'. You are also given *M* strings which represent patterns. Pattern is a string of length <=≤<= *L* and consists of characters 'a'-'e' as well as the maximum 3 characters '?'. Character '?' is an unknown character, meaning it can be equal to any character 'a'-'e', or even an empty character. For each pattern find the number of words that matches with the given pattern. After solving it and typing the result in the terminal, the key will drop from the ceiling and you may escape. Let the game begin."
Help Smith escape.
Input Specification:
The first line of input contains two integers *N* and *M* (1<=≤<=*N*<=≤<= 100 000, 1<=≤<=*M*<=≤<= 5000), representing the number of words and patterns respectively.
The next *N* lines represent each word, and after those *N* lines, following *M* lines represent each pattern. Each word and each pattern has a maximum length *L* (1<=≤<=*L*<=≤<=50). Each pattern has no more that three characters '?'. All other characters in words and patters are lowercase English letters from 'a' to 'e'.
Output Specification:
Output contains *M* lines and each line consists of one integer, representing the number of words that match the corresponding pattern.
Demo Input:
['3 1\nabc\naec\nac\na?c\n']
Demo Output:
['3\n']
Note:
If we switch '?' with 'b', 'e' and with empty character, we get 'abc', 'aec' and 'ac' respectively. | ```python
n, m=map(int, input().split())
M=dict()
for i in range(n):
s=input()
if s in M:
M[s]+=1
else:
M[s]=1
t=['', 'a', 'b', 'c', 'd', 'e']
for i in range(m):
s=input()
ans=0
if '?' in s:
for p in t:
ans+=M.get(s.replace('?', p), 0)
else:
ans=M.get(s, 0)
print(ans)
``` | 0 |
|
313 | B | Ilya and Queries | PROGRAMMING | 1,100 | [
"dp",
"implementation"
] | null | null | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=<<=*r**i*), that *s**i*<==<=*s**i*<=+<=1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). | Print *m* integers — the answers to the queries in the order in which they are given in the input. | [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
] | [
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
] | none | 1,000 | [
{
"input": "......\n4\n3 4\n2 3\n1 6\n2 6",
"output": "1\n1\n5\n4"
},
{
"input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4",
"output": "1\n1\n2\n2\n0"
},
{
"input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3",
"output": "2\n0\n0\n1\n2\n0"
},
{
"input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1 3",
"output": "0\n0\n1\n1\n0"
},
{
"input": "#.##.##.\n7\n1 8\n2 6\n2 6\n6 8\n3 5\n2 4\n2 5",
"output": "2\n1\n1\n1\n1\n1\n1"
},
{
"input": "#..#\n1\n1 4",
"output": "1"
},
{
"input": "#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4",
"output": "2\n2\n3\n2\n1\n4\n0"
},
{
"input": "#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 5\n1 5\n1 3",
"output": "0\n0\n0\n0\n0\n0\n0"
},
{
"input": "###..#...#\n2\n2 4\n1 2",
"output": "1\n1"
},
{
"input": "..\n1\n1 2",
"output": "1"
},
{
"input": "##\n1\n1 2",
"output": "1"
},
{
"input": ".#\n1\n1 2",
"output": "0"
},
{
"input": "#.\n1\n1 2",
"output": "0"
},
{
"input": "...\n2\n1 2\n1 2",
"output": "1\n1"
}
] | 1,699,684,436 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 1,740,800 | s = [0]+(list(input()))
m = int(input())
for i in range(m):
l, r = map(int, input().split())
num = 0
for i in range(l,r):
if s[i] == s[i+1]:
num += 1
print(num) | Title: Ilya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=<<=*r**i*), that *s**i*<==<=*s**i*<=+<=1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
Input Specification:
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*).
Output Specification:
Print *m* integers — the answers to the queries in the order in which they are given in the input.
Demo Input:
['......\n4\n3 4\n2 3\n1 6\n2 6\n', '#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n']
Demo Output:
['1\n1\n5\n4\n', '1\n1\n2\n2\n0\n']
Note:
none | ```python
s = [0]+(list(input()))
m = int(input())
for i in range(m):
l, r = map(int, input().split())
num = 0
for i in range(l,r):
if s[i] == s[i+1]:
num += 1
print(num)
``` | 0 |
|
348 | A | Mafia | PROGRAMMING | 1,600 | [
"binary search",
"math",
"sortings"
] | null | null | One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play. | In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
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. | [
"3\n3 2 2\n",
"4\n2 2 2 2\n"
] | [
"4\n",
"3\n"
] | You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | 500 | [
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "7\n9 7 7 8 8 7 8",
"output": "9"
},
{
"input": "10\n13 12 10 13 13 14 10 10 12 12",
"output": "14"
},
{
"input": "10\n94 96 91 95 99 94 96 92 95 99",
"output": "106"
},
{
"input": "100\n1 555 876 444 262 234 231 598 416 261 206 165 181 988 469 123 602 592 533 97 864 716 831 156 962 341 207 377 892 51 866 96 757 317 832 476 549 472 770 1000 887 145 956 515 992 653 972 677 973 527 984 559 280 346 580 30 372 547 209 929 492 520 446 726 47 170 699 560 814 206 688 955 308 287 26 102 77 430 262 71 415 586 532 562 419 615 732 658 108 315 268 574 86 12 23 429 640 995 342 305",
"output": "1000"
},
{
"input": "3\n1 1 1",
"output": "2"
},
{
"input": "30\n94 93 90 94 90 91 93 91 93 94 93 90 100 94 97 94 94 95 94 96 94 98 97 95 97 91 91 95 98 96",
"output": "100"
},
{
"input": "5\n1000000000 5 5 4 4",
"output": "1000000000"
},
{
"input": "3\n1 2 1",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "2"
},
{
"input": "4\n1 2 3 4",
"output": "4"
},
{
"input": "3\n1000000000 1000000000 10000000",
"output": "1005000000"
},
{
"input": "3\n677876423 834056477 553175531",
"output": "1032554216"
},
{
"input": "5\n1000000000 1 1 1 1",
"output": "1000000000"
},
{
"input": "4\n1000000000 1000000000 1000000000 1000000000",
"output": "1333333334"
},
{
"input": "3\n4 10 11",
"output": "13"
},
{
"input": "5\n1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1250000000"
}
] | 1,664,651,789 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 |
n=int(input())
l=list(map(int, input().split()))
d={i:0 for i in l}
for i in l:
d[i]+=1
x=[]
for i in d:
x.append([i,d[i]])
x=sorted(x)
if len(x)==1:
print(l[0]*2)
else:
ans=0
if x[0][1]==1:
ans=x[0][0]+x[1][0]
else:
ans=2*x[0][0]
for i in range(1,len(x)):
ans=max(ans,x[i][0])
print(ans)
| Title: Mafia
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play.
Output Specification:
In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
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.
Demo Input:
['3\n3 2 2\n', '4\n2 2 2 2\n']
Demo Output:
['4\n', '3\n']
Note:
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | ```python
n=int(input())
l=list(map(int, input().split()))
d={i:0 for i in l}
for i in l:
d[i]+=1
x=[]
for i in d:
x.append([i,d[i]])
x=sorted(x)
if len(x)==1:
print(l[0]*2)
else:
ans=0
if x[0][1]==1:
ans=x[0][0]+x[1][0]
else:
ans=2*x[0][0]
for i in range(1,len(x)):
ans=max(ans,x[i][0])
print(ans)
``` | 0 |
|
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28",
"output": "1"
},
{
"input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77",
"output": "6"
},
{
"input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35",
"output": "4"
},
{
"input": "2\n46 6\n6 46",
"output": "2"
},
{
"input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11",
"output": "10"
},
{
"input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33",
"output": "6"
},
{
"input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73",
"output": "0"
},
{
"input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2",
"output": "1"
},
{
"input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100",
"output": "8"
},
{
"input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "450"
},
{
"input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3",
"output": "0"
},
{
"input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5",
"output": "20"
},
{
"input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2",
"output": "108"
},
{
"input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2",
"output": "312"
},
{
"input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6",
"output": "96"
},
{
"input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97",
"output": "210"
},
{
"input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78",
"output": "73"
},
{
"input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80",
"output": "277"
},
{
"input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21",
"output": "154"
},
{
"input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17",
"output": "418"
},
{
"input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80",
"output": "74"
},
{
"input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9",
"output": "59"
},
{
"input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67",
"output": "100"
},
{
"input": "4\n8 7\n8 7\n7 8\n7 8",
"output": "8"
},
{
"input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1",
"output": "10"
},
{
"input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "72"
},
{
"input": "4\n1 2\n1 2\n2 1\n2 1",
"output": "8"
}
] | 1,681,304,650 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 122 | 409,600 | import sys
import string
input = sys.stdin.readline
def print(*args, end='\n', sep=' ') -> None:
sys.stdout.write(sep.join(map(str, args)) + end)
def solve(home: list, guest: list) -> str:
c = 0
for i in home:
c += guest.count(i)
print(c)
def main() -> None:
n = int(input())
home, guest = zip(*[input().strip().split() for i in range(n)])
solve(home, guest)
if __name__ == '__main__':
main() | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
Output Specification:
In a single line print the number of games where the host team is going to play in the guest uniform.
Demo Input:
['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n']
Demo Output:
['1\n', '5\n', '0\n']
Note:
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | ```python
import sys
import string
input = sys.stdin.readline
def print(*args, end='\n', sep=' ') -> None:
sys.stdout.write(sep.join(map(str, args)) + end)
def solve(home: list, guest: list) -> str:
c = 0
for i in home:
c += guest.count(i)
print(c)
def main() -> None:
n = int(input())
home, guest = zip(*[input().strip().split() for i in range(n)])
solve(home, guest)
if __name__ == '__main__':
main()
``` | 3 |
|
605 | A | Sorting Railway Cars | PROGRAMMING | 1,600 | [
"constructive algorithms",
"greedy"
] | null | null | An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train? | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cars in the train.
The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*, *p**i*<=≠<=*p**j* if *i*<=≠<=*j*) — the sequence of the numbers of the cars in the train. | Print a single integer — the minimum number of actions needed to sort the railway cars. | [
"5\n4 1 2 5 3\n",
"4\n4 1 3 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train. | 500 | [
{
"input": "5\n4 1 2 5 3",
"output": "2"
},
{
"input": "4\n4 1 3 2",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "6\n5 3 6 1 4 2",
"output": "4"
},
{
"input": "7\n1 2 3 6 7 4 5",
"output": "2"
},
{
"input": "8\n6 2 1 8 5 7 3 4",
"output": "5"
},
{
"input": "3\n1 2 3",
"output": "0"
},
{
"input": "3\n1 3 2",
"output": "1"
},
{
"input": "3\n2 1 3",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "1"
},
{
"input": "3\n3 1 2",
"output": "1"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "7\n1 3 5 7 2 4 6",
"output": "5"
},
{
"input": "7\n1 5 2 6 3 7 4",
"output": "3"
},
{
"input": "5\n1 4 2 3 5",
"output": "2"
},
{
"input": "9\n1 6 4 5 9 8 7 3 2",
"output": "7"
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "6"
},
{
"input": "50\n39 8 41 9 45 1 5 18 38 31 28 7 12 49 33 19 26 6 42 13 37 27 2 21 20 22 14 16 48 47 32 50 25 17 35 24 36 4 29 15 43 10 11 30 40 46 3 23 44 34",
"output": "46"
},
{
"input": "50\n43 15 10 33 32 31 13 7 5 22 36 1 25 14 38 19 8 6 24 42 28 21 44 35 4 3 49 30 27 46 2 9 17 37 45 41 18 39 12 11 16 20 50 26 29 34 40 47 48 23",
"output": "47"
},
{
"input": "50\n10 40 34 43 50 17 15 13 9 2 32 18 11 46 27 24 36 16 29 45 42 4 47 19 48 37 41 5 21 26 22 25 44 31 35 49 20 8 12 23 6 38 14 1 7 28 3 33 39 30",
"output": "46"
},
{
"input": "50\n10 37 3 46 45 29 36 13 21 25 35 5 18 33 12 19 50 16 30 47 20 42 39 28 2 6 38 8 7 31 22 27 26 9 15 14 34 48 4 32 40 43 44 24 11 1 23 17 49 41",
"output": "46"
},
{
"input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 42 37 38 39 40 41 36 43 44 45 46 47 48 49 50",
"output": "14"
},
{
"input": "50\n1 2 3 4 5 6 7 8 43 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 50 33 34 35 36 37 38 39 40 41 42 9 44 45 46 47 48 49 32",
"output": "27"
},
{
"input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 49 40 41 47 43 44 45 46 42 50 39 48",
"output": "11"
},
{
"input": "50\n1 2 3 4 27 6 7 8 9 10 30 12 13 14 15 16 17 18 19 20 21 22 23 24 28 26 5 25 29 11 31 32 33 34 38 36 37 35 39 40 41 42 43 44 45 46 47 48 49 50",
"output": "36"
},
{
"input": "50\n1 2 3 4 5 6 7 49 9 10 17 12 13 14 15 16 11 18 19 20 21 22 23 24 25 26 27 38 29 36 30 32 33 34 35 31 37 28 39 40 41 42 43 44 45 46 47 48 8 50",
"output": "38"
},
{
"input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 31 18 19 20 21 23 22 24 25 26 27 28 29 49 17 32 33 34 39 36 37 38 47 44 41 42 43 40 45 46 35 48 30 50",
"output": "33"
},
{
"input": "50\n1 2 15 4 5 6 7 8 9 10 11 12 13 14 3 16 17 18 19 32 21 22 36 28 23 26 27 24 29 30 31 20 33 34 37 25 35 38 40 39 41 42 43 44 45 46 47 48 49 50",
"output": "39"
},
{
"input": "5\n4 3 1 2 5",
"output": "3"
},
{
"input": "6\n1 3 5 6 4 2",
"output": "4"
},
{
"input": "10\n2 1 4 3 6 5 8 7 10 9",
"output": "8"
},
{
"input": "5\n1 2 4 5 3",
"output": "2"
},
{
"input": "7\n1 4 2 3 7 6 5",
"output": "4"
},
{
"input": "4\n3 1 2 4",
"output": "2"
},
{
"input": "6\n2 5 4 3 6 1",
"output": "4"
},
{
"input": "5\n1 3 4 5 2",
"output": "2"
},
{
"input": "6\n2 4 6 5 1 3",
"output": "4"
},
{
"input": "6\n1 2 4 5 6 3",
"output": "3"
},
{
"input": "9\n9 8 7 4 5 6 3 2 1",
"output": "6"
},
{
"input": "7\n4 1 2 3 6 5 7",
"output": "4"
}
] | 1,451,276,887 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | n=int(input())
p=input().split()
car=[]
for i in range(len(p)):
car.append([int(p[i]),i])
car.sort()
ans=[]
for i in range(n):
ab=0
for j in range(i+1,n):
if car[j][1]<car[i][1]:
ab+=1
ans.append(ab)
print(max(ans))
| Title: Sorting Railway Cars
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cars in the train.
The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*, *p**i*<=≠<=*p**j* if *i*<=≠<=*j*) — the sequence of the numbers of the cars in the train.
Output Specification:
Print a single integer — the minimum number of actions needed to sort the railway cars.
Demo Input:
['5\n4 1 2 5 3\n', '4\n4 1 3 2\n']
Demo Output:
['2\n', '2\n']
Note:
In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train. | ```python
n=int(input())
p=input().split()
car=[]
for i in range(len(p)):
car.append([int(p[i]),i])
car.sort()
ans=[]
for i in range(n):
ab=0
for j in range(i+1,n):
if car[j][1]<car[i][1]:
ab+=1
ans.append(ab)
print(max(ans))
``` | 0 |
|
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7). | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
},
{
"input": "8",
"output": "1641"
},
{
"input": "9",
"output": "4920"
},
{
"input": "10",
"output": "14763"
},
{
"input": "15",
"output": "3587226"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "100",
"output": "721510432"
},
{
"input": "300",
"output": "327873818"
},
{
"input": "900",
"output": "295068084"
},
{
"input": "1500",
"output": "451187545"
},
{
"input": "3000",
"output": "645417275"
},
{
"input": "5000",
"output": "755610910"
},
{
"input": "10000",
"output": "723907367"
},
{
"input": "50000",
"output": "969527595"
},
{
"input": "90000",
"output": "548978368"
},
{
"input": "99999",
"output": "909741855"
},
{
"input": "100000",
"output": "729225554"
},
{
"input": "300000",
"output": "93822635"
},
{
"input": "800000",
"output": "178940616"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "4000000",
"output": "882155933"
},
{
"input": "9000000",
"output": "295060537"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "9999998",
"output": "576926295"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "31",
"output": "347990060"
}
] | 1,697,272,304 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | MOD = 1000000007
n = int(input())
dp = [[0] * 4 for _ in range(n + 1)]
# There's only one way to get to D from D in 0 steps
dp[0][3] = 1
for i in range(1, n + 1):
for j in range(4):
dp[i][j] = (dp[i - 1][(j - 1) % 4] + dp[i - 1][(j + 1) % 4]) % MOD
# The final answer is the number of ways to get to D from D in n steps using all 4 vertices
ans = dp[n][3]
print(ans) | Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Output Specification:
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
Demo Input:
['2\n', '4\n']
Demo Output:
['3\n', '21\n']
Note:
The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | ```python
MOD = 1000000007
n = int(input())
dp = [[0] * 4 for _ in range(n + 1)]
# There's only one way to get to D from D in 0 steps
dp[0][3] = 1
for i in range(1, n + 1):
for j in range(4):
dp[i][j] = (dp[i - 1][(j - 1) % 4] + dp[i - 1][(j + 1) % 4]) % MOD
# The final answer is the number of ways to get to D from D in n steps using all 4 vertices
ans = dp[n][3]
print(ans)
``` | 0 |
|
743 | B | Chloe and the sequence | PROGRAMMING | 1,200 | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (*n*<=-<=1) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1,<=2,<=1] after the first step, the sequence [1,<=2,<=1,<=3,<=1,<=2,<=1] after the second step.
The task is to find the value of the element with index *k* (the elements are numbered from 1) in the obtained sequence, i. e. after (*n*<=-<=1) steps.
Please help Chloe to solve the problem! | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). | Print single integer — the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | 1,000 | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 671088640",
"output": "28"
},
{
"input": "38 137438953472",
"output": "38"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "3 3",
"output": "1"
},
{
"input": "4 12",
"output": "3"
},
{
"input": "8 224",
"output": "6"
},
{
"input": "13 1368",
"output": "4"
},
{
"input": "16 49152",
"output": "15"
},
{
"input": "19 1024",
"output": "11"
},
{
"input": "24 15204352",
"output": "20"
},
{
"input": "27 6586544",
"output": "5"
},
{
"input": "31 536870912",
"output": "30"
},
{
"input": "38 94489280512",
"output": "34"
},
{
"input": "42 215268308020",
"output": "3"
},
{
"input": "42 3452074721280",
"output": "21"
},
{
"input": "46 34394312982528",
"output": "15"
},
{
"input": "48 133865540681728",
"output": "39"
},
{
"input": "49 76541041985542",
"output": "2"
},
{
"input": "49 104822971826176",
"output": "34"
},
{
"input": "49 351843720888320",
"output": "47"
},
{
"input": "50 743042492421629",
"output": "1"
},
{
"input": "50 666266740436818",
"output": "2"
},
{
"input": "50 704239287953456",
"output": "5"
},
{
"input": "50 116938486513664",
"output": "17"
},
{
"input": "50 806423059496960",
"output": "37"
},
{
"input": "50 985162418487296",
"output": "48"
},
{
"input": "50 844424930131968",
"output": "49"
},
{
"input": "50 562949953421312",
"output": "50"
},
{
"input": "50 1",
"output": "1"
},
{
"input": "50 1125899906842623",
"output": "1"
},
{
"input": "50 1125899906842620",
"output": "3"
},
{
"input": "39 549755813887",
"output": "1"
},
{
"input": "50 100000000000",
"output": "12"
}
] | 1,559,726,118 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 6 | 280 | 268,390,400 | n,k=map(int,input().split())
a=[1]
if(k>=2**(n-1)):
k=2**n -k
x=len(bin(k)[2:])
for i in range(2,x+1):
a.extend(a)
a.insert(len(a)//2,i)
print(a[k-1])
| Title: Chloe and the sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (*n*<=-<=1) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1,<=2,<=1] after the first step, the sequence [1,<=2,<=1,<=3,<=1,<=2,<=1] after the second step.
The task is to find the value of the element with index *k* (the elements are numbered from 1) in the obtained sequence, i. e. after (*n*<=-<=1) steps.
Please help Chloe to solve the problem!
Input Specification:
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1).
Output Specification:
Print single integer — the integer at the *k*-th position in the obtained sequence.
Demo Input:
['3 2\n', '4 8\n']
Demo Output:
['2', '4']
Note:
In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | ```python
n,k=map(int,input().split())
a=[1]
if(k>=2**(n-1)):
k=2**n -k
x=len(bin(k)[2:])
for i in range(2,x+1):
a.extend(a)
a.insert(len(a)//2,i)
print(a[k-1])
``` | 0 |
|
408 | A | Line to Cashier | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that:
- the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.
Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has. | Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue. | 500 | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3",
"output": "125"
},
{
"input": "5\n10 10 10 10 10\n6 7 8 6 8 5 9 8 10 5\n9 6 9 8 7 8 8 10 8 5\n8 7 7 8 7 5 6 8 9 5\n6 5 10 5 5 10 7 8 5 5\n10 9 8 7 6 9 7 9 6 5",
"output": "480"
},
{
"input": "10\n9 10 10 10 9 5 9 7 8 7\n11 6 10 4 4 15 7 15 5\n3 9 11 12 11 1 13 13 1 5\n6 15 9 12 3 2 8 12 11 10\n7 1 1 6 10 2 6 1 14 2\n8 14 2 3 6 1 14 1 12\n6 10 9 3 5\n13 12 12 7 13 4 4 8 10\n5 6 4 3 14 9 13\n8 12 1 5 7 4 13 1\n1 9 5 3 5 1 4",
"output": "240"
},
{
"input": "10\n5 5 5 5 5 5 5 5 5 5\n5 5 4 5 4\n6 5 7 7 6\n5 4 4 5 5\n4 4 5 5 5\n7 6 4 5 7\n4 6 5 4 5\n6 6 7 6 6\n4 5 4 4 7\n7 5 4 4 5\n6 6 7 4 4",
"output": "190"
},
{
"input": "1\n1\n100",
"output": "515"
},
{
"input": "1\n90\n90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90",
"output": "41850"
}
] | 1,643,121,021 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | n=int(input())
k=list(map(int,input().split()))
for i in range(n):
a=list(map(int,input().split()))
val=sum(a)*5+k[i]*15
if(i==0):
m=val
else:
if(m>val):
m=val
print(m) | Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that:
- the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.
Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has.
Output Specification:
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
Demo Input:
['1\n1\n1\n', '4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n']
Demo Output:
['20\n', '100\n']
Note:
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue. | ```python
n=int(input())
k=list(map(int,input().split()))
for i in range(n):
a=list(map(int,input().split()))
val=sum(a)*5+k[i]*15
if(i==0):
m=val
else:
if(m>val):
m=val
print(m)
``` | 3 |
|
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,567,467,999 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 184 | 0 | c=input()
a=int(c[0])
b=int(c[2])
k=0
for i in range(1,7):
if(i>=a and i>=b):
k=k+1
print(k)
if(k%2==0):
if(k%3==0):
print(1/1)
else:
k=k/2
print(round(k),"/3",sep='')
elif (k%3==0):
k=k/3
print(round(k),"/2",sep='')
else:
print(round(k),'/6',sep='')
| 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
c=input()
a=int(c[0])
b=int(c[2])
k=0
for i in range(1,7):
if(i>=a and i>=b):
k=k+1
print(k)
if(k%2==0):
if(k%3==0):
print(1/1)
else:
k=k/2
print(round(k),"/3",sep='')
elif (k%3==0):
k=k/3
print(round(k),"/2",sep='')
else:
print(round(k),'/6',sep='')
``` | 0 |
797 | A | k-Factorization | PROGRAMMING | 1,100 | [
"implementation",
"math",
"number theory"
] | null | null | Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20). | If it's impossible to find the representation of *n* as a product of *k* numbers, print -1.
Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them. | [
"100000 2\n",
"100000 20\n",
"1024 5\n"
] | [
"2 50000 \n",
"-1\n",
"2 64 2 2 2 \n"
] | none | 0 | [
{
"input": "100000 2",
"output": "2 50000 "
},
{
"input": "100000 20",
"output": "-1"
},
{
"input": "1024 5",
"output": "2 64 2 2 2 "
},
{
"input": "100000 10",
"output": "2 2 2 2 2 5 5 5 5 5 "
},
{
"input": "99999 3",
"output": "3 813 41 "
},
{
"input": "99999 4",
"output": "3 3 41 271 "
},
{
"input": "99999 5",
"output": "-1"
},
{
"input": "1024 10",
"output": "2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "1024 11",
"output": "-1"
},
{
"input": "2048 11",
"output": "2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "2 4",
"output": "-1"
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "3 1",
"output": "3 "
},
{
"input": "3 2",
"output": "-1"
},
{
"input": "349 2",
"output": "-1"
},
{
"input": "8 1",
"output": "8 "
},
{
"input": "66049 2",
"output": "257 257 "
},
{
"input": "6557 2",
"output": "83 79 "
},
{
"input": "9 2",
"output": "3 3 "
},
{
"input": "4 2",
"output": "2 2 "
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "12 1",
"output": "12 "
},
{
"input": "17 1",
"output": "17 "
},
{
"input": "8 2",
"output": "2 4 "
},
{
"input": "14 2",
"output": "7 2 "
},
{
"input": "99991 1",
"output": "99991 "
},
{
"input": "30 2",
"output": "3 10 "
},
{
"input": "97 1",
"output": "97 "
},
{
"input": "92 2",
"output": "2 46 "
},
{
"input": "4 1",
"output": "4 "
},
{
"input": "4 3",
"output": "-1"
},
{
"input": "30 4",
"output": "-1"
},
{
"input": "2 6",
"output": "-1"
},
{
"input": "3 1",
"output": "3 "
},
{
"input": "3 2",
"output": "-1"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "3 4",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "3 6",
"output": "-1"
},
{
"input": "4 1",
"output": "4 "
},
{
"input": "4 2",
"output": "2 2 "
},
{
"input": "4 3",
"output": "-1"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "4 5",
"output": "-1"
},
{
"input": "4 6",
"output": "-1"
},
{
"input": "5 1",
"output": "5 "
},
{
"input": "5 2",
"output": "-1"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "5 4",
"output": "-1"
},
{
"input": "5 5",
"output": "-1"
},
{
"input": "5 6",
"output": "-1"
},
{
"input": "6 1",
"output": "6 "
},
{
"input": "6 2",
"output": "3 2 "
},
{
"input": "6 3",
"output": "-1"
},
{
"input": "6 4",
"output": "-1"
},
{
"input": "6 5",
"output": "-1"
},
{
"input": "6 6",
"output": "-1"
},
{
"input": "7 1",
"output": "7 "
},
{
"input": "7 2",
"output": "-1"
},
{
"input": "7 3",
"output": "-1"
},
{
"input": "7 4",
"output": "-1"
},
{
"input": "7 5",
"output": "-1"
},
{
"input": "7 6",
"output": "-1"
},
{
"input": "8 1",
"output": "8 "
},
{
"input": "8 2",
"output": "2 4 "
},
{
"input": "8 3",
"output": "2 2 2 "
},
{
"input": "8 4",
"output": "-1"
},
{
"input": "8 5",
"output": "-1"
},
{
"input": "8 6",
"output": "-1"
},
{
"input": "9 1",
"output": "9 "
},
{
"input": "9 2",
"output": "3 3 "
},
{
"input": "9 3",
"output": "-1"
},
{
"input": "9 4",
"output": "-1"
},
{
"input": "9 5",
"output": "-1"
},
{
"input": "9 6",
"output": "-1"
},
{
"input": "10 1",
"output": "10 "
},
{
"input": "10 2",
"output": "5 2 "
},
{
"input": "10 3",
"output": "-1"
},
{
"input": "10 4",
"output": "-1"
},
{
"input": "10 5",
"output": "-1"
},
{
"input": "10 6",
"output": "-1"
},
{
"input": "11 1",
"output": "11 "
},
{
"input": "11 2",
"output": "-1"
},
{
"input": "11 3",
"output": "-1"
},
{
"input": "11 4",
"output": "-1"
},
{
"input": "11 5",
"output": "-1"
},
{
"input": "11 6",
"output": "-1"
},
{
"input": "12 1",
"output": "12 "
},
{
"input": "12 2",
"output": "2 6 "
},
{
"input": "12 3",
"output": "2 2 3 "
},
{
"input": "12 4",
"output": "-1"
},
{
"input": "12 5",
"output": "-1"
},
{
"input": "12 6",
"output": "-1"
},
{
"input": "13 1",
"output": "13 "
},
{
"input": "13 2",
"output": "-1"
},
{
"input": "13 3",
"output": "-1"
},
{
"input": "13 4",
"output": "-1"
},
{
"input": "13 5",
"output": "-1"
},
{
"input": "13 6",
"output": "-1"
},
{
"input": "14 1",
"output": "14 "
},
{
"input": "14 2",
"output": "7 2 "
},
{
"input": "14 3",
"output": "-1"
},
{
"input": "14 4",
"output": "-1"
},
{
"input": "14 5",
"output": "-1"
},
{
"input": "14 6",
"output": "-1"
},
{
"input": "15 1",
"output": "15 "
},
{
"input": "15 2",
"output": "5 3 "
},
{
"input": "15 3",
"output": "-1"
},
{
"input": "15 4",
"output": "-1"
},
{
"input": "15 5",
"output": "-1"
},
{
"input": "15 6",
"output": "-1"
},
{
"input": "16 1",
"output": "16 "
},
{
"input": "16 2",
"output": "2 8 "
},
{
"input": "16 3",
"output": "2 4 2 "
},
{
"input": "16 4",
"output": "2 2 2 2 "
},
{
"input": "16 5",
"output": "-1"
},
{
"input": "16 6",
"output": "-1"
},
{
"input": "17 1",
"output": "17 "
},
{
"input": "17 2",
"output": "-1"
},
{
"input": "17 3",
"output": "-1"
},
{
"input": "17 4",
"output": "-1"
},
{
"input": "17 5",
"output": "-1"
},
{
"input": "17 6",
"output": "-1"
},
{
"input": "18 1",
"output": "18 "
},
{
"input": "18 2",
"output": "3 6 "
},
{
"input": "18 3",
"output": "3 2 3 "
},
{
"input": "18 4",
"output": "-1"
},
{
"input": "18 5",
"output": "-1"
},
{
"input": "18 6",
"output": "-1"
},
{
"input": "19 1",
"output": "19 "
},
{
"input": "19 2",
"output": "-1"
},
{
"input": "19 3",
"output": "-1"
},
{
"input": "19 4",
"output": "-1"
},
{
"input": "19 5",
"output": "-1"
},
{
"input": "19 6",
"output": "-1"
},
{
"input": "20 1",
"output": "20 "
},
{
"input": "20 2",
"output": "2 10 "
},
{
"input": "20 3",
"output": "2 2 5 "
},
{
"input": "20 4",
"output": "-1"
},
{
"input": "20 5",
"output": "-1"
},
{
"input": "20 6",
"output": "-1"
},
{
"input": "94249 1",
"output": "94249 "
},
{
"input": "94249 2",
"output": "307 307 "
},
{
"input": "94249 3",
"output": "-1"
},
{
"input": "94249 4",
"output": "-1"
},
{
"input": "94249 5",
"output": "-1"
},
{
"input": "95477 1",
"output": "95477 "
},
{
"input": "95477 2",
"output": "311 307 "
},
{
"input": "95477 3",
"output": "-1"
},
{
"input": "95477 4",
"output": "-1"
},
{
"input": "95477 5",
"output": "-1"
},
{
"input": "35557 1",
"output": "35557 "
},
{
"input": "35557 2",
"output": "31 1147 "
},
{
"input": "35557 3",
"output": "31 31 37 "
},
{
"input": "35557 4",
"output": "-1"
},
{
"input": "35557 5",
"output": "-1"
},
{
"input": "42439 1",
"output": "42439 "
},
{
"input": "42439 2",
"output": "37 1147 "
},
{
"input": "42439 3",
"output": "37 31 37 "
},
{
"input": "42439 4",
"output": "-1"
},
{
"input": "42439 5",
"output": "-1"
}
] | 1,625,685,866 | 2,147,483,647 | Python 3 | OK | TESTS | 166 | 93 | 0 | n, k = map(int, (input().split()))
d = []
i = 2
while i <= n:
while n % i == 0:
d.append(i)
n //= i
else:
i += 1
if len(d) < k:
print(-1)
else:
while len(d) > k:
d[-2] *= d[-1]
d.pop()
print(*d)
| Title: k-Factorization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20).
Output Specification:
If it's impossible to find the representation of *n* as a product of *k* numbers, print -1.
Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them.
Demo Input:
['100000 2\n', '100000 20\n', '1024 5\n']
Demo Output:
['2 50000 \n', '-1\n', '2 64 2 2 2 \n']
Note:
none | ```python
n, k = map(int, (input().split()))
d = []
i = 2
while i <= n:
while n % i == 0:
d.append(i)
n //= i
else:
i += 1
if len(d) < k:
print(-1)
else:
while len(d) > k:
d[-2] *= d[-1]
d.pop()
print(*d)
``` | 3 |
|
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.
Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
{
"input": "789 101112 131415",
"output": "203802"
},
{
"input": "27485716 99999999 35182",
"output": "55041796"
},
{
"input": "1 293548 5",
"output": "12"
},
{
"input": "12059 259855 5874875",
"output": "543828"
},
{
"input": "46981 105809 585858",
"output": "305580"
},
{
"input": "9889 1221 2442",
"output": "7326"
},
{
"input": "100500 200600 300700",
"output": "601800"
},
{
"input": "318476 318476 318476",
"output": "955428"
},
{
"input": "23985 3353 75633",
"output": "54676"
},
{
"input": "120 1298 2222",
"output": "2836"
},
{
"input": "98437 23487 666672",
"output": "243848"
},
{
"input": "100000000 100000000 100000000",
"output": "300000000"
},
{
"input": "2 5 2",
"output": "8"
},
{
"input": "1 1000 1",
"output": "4"
},
{
"input": "1 100000000 1",
"output": "4"
}
] | 1,661,703,634 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | d1,d2,d3=map(int,input().split())
print(min((d1+d2+d3),(2*d1+2*d2),(2*d2+2*d3),(2*d1+2*d3))) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.
Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
Input Specification:
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Output Specification:
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
Demo Input:
['10 20 30\n', '1 1 5\n']
Demo Output:
['60\n', '4\n']
Note:
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. | ```python
d1,d2,d3=map(int,input().split())
print(min((d1+d2+d3),(2*d1+2*d2),(2*d2+2*d3),(2*d1+2*d3)))
``` | 3 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,595,441,141 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 124 | 20,172,800 | s=input()
l=list(s)
d={}
for i in l:
if i in d:
d[i]+=1
else:
d[i]=1
l1=(list(d.keys()))
ind1=l1.index('h')
ind2=l1.index('e')
ind3=l1.index('l')
ind4=l1.index('o')
if ind1<ind2 and ind2<ind3 and ind3<ind4 and d['l']>=2:
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
s=input()
l=list(s)
d={}
for i in l:
if i in d:
d[i]+=1
else:
d[i]=1
l1=(list(d.keys()))
ind1=l1.index('h')
ind2=l1.index('e')
ind3=l1.index('l')
ind4=l1.index('o')
if ind1<ind2 and ind2<ind3 and ind3<ind4 and d['l']>=2:
print("YES")
else:
print("NO")
``` | 0 |
938 | B | Run For Your Prize | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.
You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.
Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.
What is the minimum number of seconds it will take to pick up all the prizes? | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order. | Print one integer — the minimum number of seconds it will take to collect all prizes. | [
"3\n2 3 9\n",
"2\n2 999995\n"
] | [
"8\n",
"5\n"
] | In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5. | 0 | [
{
"input": "3\n2 3 9",
"output": "8"
},
{
"input": "2\n2 999995",
"output": "5"
},
{
"input": "1\n20",
"output": "19"
},
{
"input": "6\n2 3 500000 999997 999998 999999",
"output": "499999"
},
{
"input": "1\n999999",
"output": "1"
},
{
"input": "1\n510000",
"output": "490000"
},
{
"input": "3\n2 5 27",
"output": "26"
},
{
"input": "2\n600000 800000",
"output": "400000"
},
{
"input": "5\n2 5 6 27 29",
"output": "28"
},
{
"input": "1\n500001",
"output": "499999"
},
{
"input": "10\n3934 38497 42729 45023 51842 68393 77476 82414 91465 98055",
"output": "98054"
},
{
"input": "1\n900000",
"output": "100000"
},
{
"input": "1\n500000",
"output": "499999"
},
{
"input": "1\n999998",
"output": "2"
},
{
"input": "3\n999997 999998 999999",
"output": "3"
},
{
"input": "2\n999997 999999",
"output": "3"
},
{
"input": "2\n2 999998",
"output": "2"
},
{
"input": "2\n500000 500001",
"output": "499999"
},
{
"input": "1\n500002",
"output": "499998"
},
{
"input": "1\n700000",
"output": "300000"
},
{
"input": "2\n2 999999",
"output": "1"
},
{
"input": "2\n999998 999999",
"output": "2"
},
{
"input": "1\n999995",
"output": "5"
},
{
"input": "2\n499999 500001",
"output": "499999"
},
{
"input": "1\n499999",
"output": "499998"
},
{
"input": "2\n100 999900",
"output": "100"
},
{
"input": "2\n499999 500000",
"output": "499999"
},
{
"input": "2\n500001 999999",
"output": "499999"
},
{
"input": "3\n500000 500001 500002",
"output": "499999"
},
{
"input": "2\n2 500001",
"output": "499999"
},
{
"input": "2\n499999 999999",
"output": "499998"
},
{
"input": "2\n2 500000",
"output": "499999"
},
{
"input": "4\n2 3 4 999999",
"output": "3"
},
{
"input": "2\n100000 500001",
"output": "499999"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n800000",
"output": "200000"
},
{
"input": "1\n505050",
"output": "494950"
},
{
"input": "1\n753572",
"output": "246428"
},
{
"input": "2\n576696 760487",
"output": "423304"
},
{
"input": "10\n3 4 5 6 7 8 9 10 11 12",
"output": "11"
},
{
"input": "4\n2 3 4 5",
"output": "4"
},
{
"input": "4\n999996 999997 999998 999999",
"output": "4"
}
] | 1,607,073,256 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | n=int(input())
l=list(map(int,input().split()))
ans=0
s=1
e=1000000
for i in l:
if i-s < e-i:
ans+=(i-s)
s=i
e=e-(i-s)
else:
ans+=e-s
e=i
s=s+(e-i)
ans+=e-s
print(ans)
| Title: Run For Your Prize
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.
You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.
Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.
What is the minimum number of seconds it will take to pick up all the prizes?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Output Specification:
Print one integer — the minimum number of seconds it will take to collect all prizes.
Demo Input:
['3\n2 3 9\n', '2\n2 999995\n']
Demo Output:
['8\n', '5\n']
Note:
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5. | ```python
n=int(input())
l=list(map(int,input().split()))
ans=0
s=1
e=1000000
for i in l:
if i-s < e-i:
ans+=(i-s)
s=i
e=e-(i-s)
else:
ans+=e-s
e=i
s=s+(e-i)
ans+=e-s
print(ans)
``` | 0 |
|
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*.
Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1. | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one. | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two. | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
"output": "1"
},
{
"input": "10 7\n1101111011",
"output": "2"
},
{
"input": "10 9\n1110000101",
"output": "1"
},
{
"input": "10 9\n1100000001",
"output": "1"
},
{
"input": "20 5\n11111111110111101001",
"output": "4"
},
{
"input": "20 11\n11100000111000011011",
"output": "2"
},
{
"input": "20 19\n10100000000000000001",
"output": "1"
},
{
"input": "50 13\n10011010100010100111010000010000000000010100000101",
"output": "5"
},
{
"input": "50 8\n11010100000011001100001100010001110000101100110011",
"output": "8"
},
{
"input": "99 4\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111",
"output": "25"
},
{
"input": "99 98\n100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "1"
},
{
"input": "100 5\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "20"
},
{
"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111",
"output": "25"
},
{
"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111101111111011111111111111111111111111111",
"output": "25"
},
{
"input": "100 3\n1111110111111111111111111111111111111111101111111111111111111111111101111111111111111111111111111111",
"output": "34"
},
{
"input": "100 8\n1111111111101110111111111111111111111111111111111111111111111111111111110011111111111111011111111111",
"output": "13"
},
{
"input": "100 7\n1011111111111111111011101111111011111101111111111101111011110111111111111111111111110111111011111111",
"output": "15"
},
{
"input": "100 9\n1101111110111110101111111111111111011001110111011101011111111111010101111111100011011111111010111111",
"output": "12"
},
{
"input": "100 6\n1011111011111111111011010110011001010101111110111111000111011011111110101101110110101111110000100111",
"output": "18"
},
{
"input": "100 7\n1110001111101001110011111111111101111101101001010001101000101100000101101101011111111101101000100001",
"output": "16"
},
{
"input": "100 11\n1000010100011100011011100000010011001111011110100100001011010100011011111001101101110110010110001101",
"output": "10"
},
{
"input": "100 9\n1001001110000011100100000001000110111101101010101001000101001010011001101100110011011110110011011111",
"output": "13"
},
{
"input": "100 7\n1010100001110101111011000111000001110100100110110001110110011010100001100100001110111100110000101001",
"output": "18"
},
{
"input": "100 10\n1110110000000110000000101110100000111000001011100000100110010001110111001010101000011000000001011011",
"output": "12"
},
{
"input": "100 13\n1000000100000000100011000010010000101010011110000000001000011000110100001000010001100000011001011001",
"output": "9"
},
{
"input": "100 11\n1000000000100000010000100001000100000000010000100100000000100100001000000001011000110001000000000101",
"output": "12"
},
{
"input": "100 22\n1000100000001010000000000000000001000000100000000000000000010000000000001000000000000000000100000001",
"output": "7"
},
{
"input": "100 48\n1000000000000000011000000000000000000000000000000001100000000000000000000000000000000000000000000001",
"output": "3"
},
{
"input": "100 48\n1000000000000000000000100000000000000000000000000000000000000000000001000000000000000000100000000001",
"output": "3"
},
{
"input": "100 75\n1000000100000000000000000000000000000000000000000000000000000000000000000000000001000000000000000001",
"output": "3"
},
{
"input": "100 73\n1000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 99\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "1"
},
{
"input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "99"
},
{
"input": "100 2\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111",
"output": "50"
},
{
"input": "100 1\n1111111111111111011111111111111111111111111111111111111111111111111101111111111111111111111111111111",
"output": "-1"
},
{
"input": "100 3\n1111111111111111111111111101111111111111111111111011111111111111111111111111111011111111111111111111",
"output": "33"
},
{
"input": "100 1\n1101111111111111111111101111111111111111111111111111111111111011111111101111101111111111111111111111",
"output": "-1"
},
{
"input": "100 6\n1111111111111111111111101111111101011110001111111111111111110111111111111111111111111110010111111111",
"output": "17"
},
{
"input": "100 2\n1111111101111010110111011011110111101111111011111101010101011111011111111111111011111001101111101111",
"output": "-1"
},
{
"input": "100 8\n1100110101111001101001111000111100110100011110111011001011111110000110101000001110111011100111011011",
"output": "14"
},
{
"input": "100 10\n1000111110100000001001101100000010011100010101001100010011111001001101111110110111101111001010001101",
"output": "11"
},
{
"input": "100 7\n1110000011010001110101011010000011110001000000011101110111010110001000011101111010010001101111110001",
"output": "-1"
},
{
"input": "100 3\n1111010001000001011011000011001111000100101000101101000010111101111000010000011110110011001101010111",
"output": "-1"
},
{
"input": "100 9\n1101010101101100010111011000010100001010000101010011001001100010110110000000010000101000000001101101",
"output": "13"
},
{
"input": "100 14\n1010100000000000010101000010001100000000000011100010000001000001011010001110001010100000100001101101",
"output": "9"
},
{
"input": "100 13\n1000000001101001110000010000011001000000000000001010000000100001001010000000000000000100010000000001",
"output": "-1"
},
{
"input": "100 18\n1000000000000000110000000000000000010000000001000001000001000000000100000000000010000000000000000001",
"output": "-1"
},
{
"input": "100 32\n1000000000000000000000000001000000000000000000000101000000000000000000000000000000000001000000000001",
"output": "-1"
},
{
"input": "100 79\n1000000001000000000101000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 41\n1000000000000000000000000000000000010000000000000000000000000000000000000000100000000000000000000001",
"output": "3"
},
{
"input": "100 82\n1000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 96\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "-1"
},
{
"input": "43 30\n1001000001111111010100100100110101011101101",
"output": "2"
},
{
"input": "7 1\n1111111",
"output": "6"
},
{
"input": "9 3\n101000001",
"output": "-1"
},
{
"input": "10 3\n1100000001",
"output": "-1"
},
{
"input": "8 2\n10000101",
"output": "-1"
},
{
"input": "2 1\n11",
"output": "1"
}
] | 1,697,242,669 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import java.util.Scanner;
public class Teletransporte {
public static int teletransporte(String caminho, int posicao, int salto, int contador) {
int i = salto + posicao;
while (i > posicao) {
if (i <= caminho.length() - 1 && caminho.charAt(i) == '1') {
if (i == caminho.length() - 1) {
return contador + 1;
}
int tmp = teletransporte(caminho, i, salto, contador + 1);
if (tmp != -1) {
return tmp;
}
}
i--;
}
return -1;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] linha = scanner.nextLine().split(" ");
String caminho = scanner.nextLine();
System.out.println(teletransporte(caminho, 0, Integer.parseInt(linha[1]), 0));
}
}
| Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*.
Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1.
Input Specification:
The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one.
Output Specification:
If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
Demo Input:
['8 4\n10010101\n', '4 2\n1001\n', '8 4\n11100101\n', '12 3\n101111100101\n']
Demo Output:
['2\n', '-1\n', '3\n', '4\n']
Note:
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two. | ```python
import java.util.Scanner;
public class Teletransporte {
public static int teletransporte(String caminho, int posicao, int salto, int contador) {
int i = salto + posicao;
while (i > posicao) {
if (i <= caminho.length() - 1 && caminho.charAt(i) == '1') {
if (i == caminho.length() - 1) {
return contador + 1;
}
int tmp = teletransporte(caminho, i, salto, contador + 1);
if (tmp != -1) {
return tmp;
}
}
i--;
}
return -1;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] linha = scanner.nextLine().split(" ");
String caminho = scanner.nextLine();
System.out.println(teletransporte(caminho, 0, Integer.parseInt(linha[1]), 0));
}
}
``` | -1 |
|
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.
As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2. | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "4"
},
{
"input": "7\n10 10 5 5 5 5 1",
"output": "3"
},
{
"input": "20\n2 1 2 2 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1",
"output": "8"
},
{
"input": "20\n4 2 4 4 3 4 2 2 4 2 3 1 1 2 2 3 3 3 1 4",
"output": "8"
},
{
"input": "20\n35 26 41 40 45 46 22 26 39 23 11 15 47 42 18 15 27 10 45 40",
"output": "8"
},
{
"input": "20\n7 84 100 10 31 35 41 2 63 44 57 4 63 11 23 49 98 71 16 90",
"output": "6"
},
{
"input": "50\n19 2 12 26 17 27 10 26 17 17 5 24 11 15 3 9 16 18 19 1 25 23 18 6 2 7 25 7 21 25 13 29 16 9 25 3 14 30 18 4 10 28 6 10 8 2 2 4 8 28",
"output": "14"
},
{
"input": "70\n2 18 18 47 25 5 14 9 19 46 36 49 33 32 38 23 32 39 8 29 31 17 24 21 10 15 33 37 46 21 22 11 20 35 39 13 11 30 28 40 39 47 1 17 24 24 21 46 12 2 20 43 8 16 44 11 45 10 13 44 31 45 45 46 11 10 33 35 23 42",
"output": "22"
},
{
"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": "51"
},
{
"input": "100\n1 2 2 1 2 1 1 2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 1 1 2 1 1 1 1 2 2 2 2",
"output": "37"
},
{
"input": "100\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2",
"output": "36"
},
{
"input": "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3",
"output": "33"
},
{
"input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2",
"output": "30"
},
{
"input": "100\n16 9 11 8 11 4 9 17 4 8 4 10 9 10 6 3 3 15 1 6 1 15 12 18 6 14 13 18 1 7 18 4 10 7 10 12 3 16 14 4 10 8 10 7 19 13 15 1 4 8 16 10 6 4 3 16 11 10 7 3 4 16 1 20 1 11 4 16 10 7 7 12 18 19 3 17 19 3 4 19 2 12 11 3 18 20 2 2 14 4 20 13 13 11 16 20 19 14 7 2",
"output": "29"
},
{
"input": "100\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1",
"output": "30"
},
{
"input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52",
"output": "29"
},
{
"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": "30"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "4\n4 1 2 3",
"output": "2"
},
{
"input": "5\n2 2 2 4 4",
"output": "2"
},
{
"input": "4\n100 99 99 100",
"output": "2"
}
] | 1,694,754,402 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | n = int(input())
coins = list(map(int, input().split()))
coins.sort(reverse=True)
total_sum = sum(coins)
my_sum = 0
count = 0
for i in range(n):
my_sum += coins[i]
count += 1
if my_sum > total_sum - my_sum:
break
print(count) | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.
As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
Output Specification:
In the single line print the single number — the minimum needed number of coins.
Demo Input:
['2\n3 3\n', '3\n2 1 2\n']
Demo Output:
['2\n', '2\n']
Note:
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2. | ```python
n = int(input())
coins = list(map(int, input().split()))
coins.sort(reverse=True)
total_sum = sum(coins)
my_sum = 0
count = 0
for i in range(n):
my_sum += coins[i]
count += 1
if my_sum > total_sum - my_sum:
break
print(count)
``` | 3 |
|
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "1 1 1 1 1 1",
"output": "Elephant"
},
{
"input": "9 9 9 9 9 9",
"output": "Elephant"
},
{
"input": "1 8 9 1 1 1",
"output": "Bear"
},
{
"input": "9 9 9 1 9 9",
"output": "Bear"
},
{
"input": "1 2 3 8 9 7",
"output": "Alien"
},
{
"input": "5 5 5 6 6 6",
"output": "Alien"
},
{
"input": "1 1 2 2 3 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 2",
"output": "Bear"
},
{
"input": "2 2 3 3 4 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 5",
"output": "Bear"
},
{
"input": "1 1 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 2 5 5 5 5",
"output": "Bear"
},
{
"input": "4 4 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 1 2",
"output": "Bear"
},
{
"input": "2 2 4 4 4 4",
"output": "Elephant"
},
{
"input": "4 4 4 4 4 3",
"output": "Bear"
},
{
"input": "4 4 5 6 7 8",
"output": "Alien"
},
{
"input": "4 4 4 4 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 2 2",
"output": "Elephant"
},
{
"input": "1 1 3 3 3 5",
"output": "Alien"
},
{
"input": "1 2 2 3 3 3",
"output": "Alien"
},
{
"input": "1 2 2 2 2 2",
"output": "Bear"
},
{
"input": "1 3 3 3 4 5",
"output": "Alien"
},
{
"input": "5 1 1 1 1 1",
"output": "Bear"
}
] | 1,466,171,653 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | l = list(map(int, input().split()))
u = set(l)
four = None
for c in u:
if l.count(c) == 4:
four = c
break
u = u - {four}
if four is None:
print('Alien')
elif len(u) == 1:
print('Elephant')
else:
print('Bear')
| Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
Input Specification:
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
Output Specification:
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
Demo Input:
['4 2 5 4 4 4\n', '4 4 5 4 4 5\n', '1 2 3 4 5 6\n']
Demo Output:
['Bear', 'Elephant', 'Alien']
Note:
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | ```python
l = list(map(int, input().split()))
u = set(l)
four = None
for c in u:
if l.count(c) == 4:
four = c
break
u = u - {four}
if four is None:
print('Alien')
elif len(u) == 1:
print('Elephant')
else:
print('Bear')
``` | 0 |
|
299 | A | Ksusha and Array | PROGRAMMING | 1,000 | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements. | Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 500 | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
},
{
"input": "2\n500000000 1000000000",
"output": "500000000"
},
{
"input": "2\n4 6",
"output": "-1"
},
{
"input": "5\n10 8 6 4 2",
"output": "2"
},
{
"input": "2\n6 10",
"output": "-1"
},
{
"input": "1\n1000000000",
"output": "1000000000"
},
{
"input": "2\n6 8",
"output": "-1"
},
{
"input": "5\n2 2 2 2 1000000000",
"output": "2"
},
{
"input": "2\n6 4",
"output": "-1"
}
] | 1,642,641,068 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 21 | 2,000 | 7,782,400 | n = int(input())
a = [int(i) for i in input().split()]
t = 0
for i in range(n):
div = True
for j in range(n):
if i != j and a[j] % a[i] != 0:
div = False
break
if div:
t = a[i]
break
if t == 0:
print(-1)
else:
print(t) | Title: Ksusha and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements.
Output Specification:
Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them.
Demo Input:
['3\n2 2 4\n', '5\n2 1 3 1 6\n', '3\n2 3 5\n']
Demo Output:
['2\n', '1\n', '-1\n']
Note:
none | ```python
n = int(input())
a = [int(i) for i in input().split()]
t = 0
for i in range(n):
div = True
for j in range(n):
if i != j and a[j] % a[i] != 0:
div = False
break
if div:
t = a[i]
break
if t == 0:
print(-1)
else:
print(t)
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,634,643,132 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 |
s = input()
l = ['o','l','l','e','h']
for i in s:
if i == l[-1]:
l.pop()
if len(l) == 0:
break
if len(l) == 0:
print('YES')
else:
print('NO') | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
s = input()
l = ['o','l','l','e','h']
for i in s:
if i == l[-1]:
l.pop()
if len(l) == 0:
break
if len(l) == 0:
print('YES')
else:
print('NO')
``` | 3.977 |
447 | A | DZY Loves Hash | PROGRAMMING | 800 | [
"implementation"
] | null | null | DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==<=*x* *mod* *p*. Operation *a* *mod* *b* denotes taking a remainder after division *a* by *b*.
However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the *i*-th insertion, you should output *i*. If no conflict happens, just output -1. | The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109). | Output a single integer — the answer to the problem. | [
"10 5\n0\n21\n53\n41\n53\n",
"5 5\n0\n1\n2\n3\n4\n"
] | [
"4\n",
"-1\n"
] | none | 500 | [
{
"input": "10 5\n0\n21\n53\n41\n53",
"output": "4"
},
{
"input": "5 5\n0\n1\n2\n3\n4",
"output": "-1"
},
{
"input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537",
"output": "4"
},
{
"input": "2 2\n788371161\n801743052",
"output": "-1"
},
{
"input": "10 6\n812796223\n122860157\n199259103\n597650585\n447742024\n521549402",
"output": "3"
},
{
"input": "300 2\n822454942\n119374431",
"output": "-1"
},
{
"input": "300 2\n823284367\n507345500",
"output": "-1"
},
{
"input": "2 5\n791579811\n35613889\n997079893\n878677665\n693717467",
"output": "2"
},
{
"input": "20 5\n793926268\n28931770\n842870287\n974950617\n859404206",
"output": "-1"
},
{
"input": "100 15\n805069249\n778178198\n633897389\n844316223\n146759898\n870527016\n82668754\n42060733\n943602929\n979451110\n746979598\n47406033\n607284062\n850870259\n229415316",
"output": "5"
},
{
"input": "100 15\n806204335\n189490323\n718805086\n716787474\n262315718\n822030596\n894644222\n724054623\n141384399\n579354205\n192622443\n672556242\n97417563\n243354557\n208957882",
"output": "8"
},
{
"input": "100 15\n807033760\n577461392\n275221433\n532633429\n295714486\n783298996\n255799943\n99107143\n729119412\n59302896\n37640015\n313610861\n630550567\n534283052\n681062462",
"output": "8"
},
{
"input": "100 15\n808103310\n136224397\n360129131\n405104681\n263786657\n734802577\n67808179\n928584682\n926900882\n511722343\n483348395\n938695534\n120684068\n74152694\n808088675",
"output": "9"
},
{
"input": "2 2\n2\n2",
"output": "2"
},
{
"input": "300 2\n0\n300",
"output": "2"
},
{
"input": "2 2\n0\n0",
"output": "2"
}
] | 1,553,495,167 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 124 | 0 | p,n=map(int,input().split())
D=[-1]*p
for i in range(n):
y=int(input())
if D[y%p]!=-1:
print(i+1)
exit()
else:
D[y%p]=0
print(-1) | Title: DZY Loves Hash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==<=*x* *mod* *p*. Operation *a* *mod* *b* denotes taking a remainder after division *a* by *b*.
However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the *i*-th insertion, you should output *i*. If no conflict happens, just output -1.
Input Specification:
The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109).
Output Specification:
Output a single integer — the answer to the problem.
Demo Input:
['10 5\n0\n21\n53\n41\n53\n', '5 5\n0\n1\n2\n3\n4\n']
Demo Output:
['4\n', '-1\n']
Note:
none | ```python
p,n=map(int,input().split())
D=[-1]*p
for i in range(n):
y=int(input())
if D[y%p]!=-1:
print(i+1)
exit()
else:
D[y%p]=0
print(-1)
``` | 3 |
|
812 | A | Sagheer and Crossroads | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (*l* — left, *s* — straight, *r* — right) and a light *p* for a pedestrian crossing.
An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.
Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible. | The input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light. | On a single line, print "YES" if an accident is possible, and "NO" otherwise. | [
"1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n",
"0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n",
"1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur. | 500 | [
{
"input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "1 1 1 0\n0 1 0 1\n1 1 1 0\n1 1 1 1",
"output": "YES"
},
{
"input": "0 1 1 0\n0 1 0 0\n1 0 0 1\n1 0 0 0",
"output": "YES"
},
{
"input": "1 0 0 0\n0 1 0 0\n1 1 0 0\n0 1 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 1 0 1\n1 0 1 1\n1 1 1 0",
"output": "YES"
},
{
"input": "1 1 0 0\n0 1 0 1\n1 1 1 0\n0 0 1 1",
"output": "YES"
},
{
"input": "0 1 0 0\n0 0 0 0\n1 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 0\n0 0 0 0\n1 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 0\n0 1 0 1\n1 0 1 0\n0 0 1 0",
"output": "YES"
},
{
"input": "1 1 1 0\n0 1 0 1\n1 1 1 1\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 1 0\n0 0 0 0\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 1 0 1\n1 0 1 1\n0 0 0 1",
"output": "YES"
},
{
"input": "1 1 0 0\n0 1 0 0\n1 1 1 0\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "1 0 1 0\n1 1 0 0\n1 1 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 1 0\n1 1 0 0\n1 0 1 0\n1 0 0 0",
"output": "NO"
},
{
"input": "0 0 1 0\n1 0 0 0\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "0 1 1 0\n1 1 0 1\n1 0 0 1\n1 1 1 0",
"output": "YES"
},
{
"input": "1 0 0 0\n1 1 0 0\n1 1 0 1\n0 0 1 0",
"output": "YES"
},
{
"input": "0 0 0 0\n1 1 0 0\n0 0 0 1\n0 0 1 0",
"output": "NO"
},
{
"input": "0 1 0 0\n0 0 0 1\n0 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 1 0 0\n1 1 0 1\n1 0 0 1\n1 1 0 1",
"output": "YES"
},
{
"input": "1 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n1 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 1 0 0\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 1 0\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n1 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 1 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 0 1 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 0 0 0\n1 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 0 0 0\n0 1 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 1 0",
"output": "YES"
},
{
"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 1 0 0\n0 0 0 1\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 1 0\n0 0 0 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n1 0 0 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 1 0 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 1 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 1\n1 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 1 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 1 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 0\n0 1 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 0\n0 0 1 0",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "0 1 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 1 0\n0 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n1 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 1 0 0\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 1 0\n0 0 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n1 0 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 1 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 1 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n1 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 1 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 1 0",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 0\n0 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n1 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 1 0\n0 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n1 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n1 0 0 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 1 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1",
"output": "YES"
},
{
"input": "1 0 0 0\n0 1 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "1 1 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "1 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n1 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 1 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 1 1 0\n1 0 1 0\n1 1 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "1 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "1 1 1 0\n1 1 1 0\n1 1 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "1 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 1 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 1 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 1 1 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 1 0 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 0 1\n0 0 0 0\n0 1 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 0 1\n1 0 0 0\n0 0 0 0",
"output": "YES"
}
] | 1,496,650,304 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 22 | 62 | 0 | a=[]
for i in range(4):
a.append(input().split(' '))
for i in range(4):
if a[i][0]=='1' and a[(i+3)%4][3]=='1':
print("YES")
exit()
if a[i][1]=='1' and a[(i+2)%4][3]=='1':
print("YES")
exit()
if a[i][2]=='1' and a[(i+1)%4][3]=='1':
print("YES")
exit()
print("NO") | Title: Sagheer and Crossroads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (*l* — left, *s* — straight, *r* — right) and a light *p* for a pedestrian crossing.
An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.
Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible.
Input Specification:
The input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.
Output Specification:
On a single line, print "YES" if an accident is possible, and "NO" otherwise.
Demo Input:
['1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n', '0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n', '1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur. | ```python
a=[]
for i in range(4):
a.append(input().split(' '))
for i in range(4):
if a[i][0]=='1' and a[(i+3)%4][3]=='1':
print("YES")
exit()
if a[i][1]=='1' and a[(i+2)%4][3]=='1':
print("YES")
exit()
if a[i][2]=='1' and a[(i+1)%4][3]=='1':
print("YES")
exit()
print("NO")
``` | 0 |
|
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order. | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++",
"output": "4"
},
{
"input": "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++",
"output": "-10"
},
{
"input": "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X",
"output": "-14"
},
{
"input": "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X",
"output": "3"
},
{
"input": "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X",
"output": "-5"
},
{
"input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X",
"output": "1"
},
{
"input": "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--",
"output": "1"
},
{
"input": "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++",
"output": "-3"
},
{
"input": "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X",
"output": "1"
},
{
"input": "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++",
"output": "8"
},
{
"input": "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++",
"output": "-1"
},
{
"input": "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--",
"output": "-5"
},
{
"input": "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--",
"output": "1"
},
{
"input": "1\nX--",
"output": "-1"
}
] | 1,696,647,238 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | n = int(input())
x = 0
for i in range(n):
command = input()
if "++" in command:
x+=1
else:
x-=1
print(x) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Output Specification:
Print a single integer — the final value of *x*.
Demo Input:
['1\n++X\n', '2\nX++\n--X\n']
Demo Output:
['1\n', '0\n']
Note:
none | ```python
n = int(input())
x = 0
for i in range(n):
command = input()
if "++" in command:
x+=1
else:
x-=1
print(x)
``` | 3 |
|
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,693,134,793 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
d=0
x=True
def luck(s):
a=True
while s != 0:
if s % 10 != 7 or s % 10 != 4:
a=False
s //= 10
return a
for i in range(3,n):
if n % i == 0 and luck(i)=True:
print('YES')
else:
print('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
n=int(input())
d=0
x=True
def luck(s):
a=True
while s != 0:
if s % 10 != 7 or s % 10 != 4:
a=False
s //= 10
return a
for i in range(3,n):
if n % i == 0 and luck(i)=True:
print('YES')
else:
print('NO')
``` | -1 |
|
35 | A | Shell Game | PROGRAMMING | 1,000 | [
"implementation"
] | A. Shell Game | 2 | 64 | Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | [
"1\n1 2\n2 1\n2 1\n",
"1\n2 1\n3 1\n1 3\n"
] | [
"2\n",
"2\n"
] | none | 500 | [
{
"input": "1\n1 2\n2 1\n2 1",
"output": "2"
},
{
"input": "1\n2 1\n3 1\n1 3",
"output": "2"
},
{
"input": "3\n3 1\n2 1\n1 2",
"output": "1"
},
{
"input": "1\n1 3\n1 2\n2 3",
"output": "2"
},
{
"input": "3\n3 2\n3 1\n3 1",
"output": "2"
},
{
"input": "1\n2 1\n1 3\n1 3",
"output": "2"
},
{
"input": "3\n3 1\n2 3\n3 2",
"output": "1"
},
{
"input": "2\n1 3\n1 2\n2 1",
"output": "2"
},
{
"input": "1\n1 3\n3 2\n1 2",
"output": "1"
},
{
"input": "1\n1 3\n1 3\n2 3",
"output": "1"
},
{
"input": "2\n1 2\n2 3\n2 1",
"output": "2"
},
{
"input": "3\n1 3\n3 2\n2 1",
"output": "2"
},
{
"input": "1\n1 2\n2 1\n2 3",
"output": "1"
},
{
"input": "1\n2 3\n1 3\n1 2",
"output": "3"
},
{
"input": "2\n3 1\n3 2\n2 3",
"output": "2"
},
{
"input": "2\n1 3\n3 1\n3 1",
"output": "2"
},
{
"input": "1\n3 2\n1 3\n3 1",
"output": "1"
},
{
"input": "3\n1 3\n1 2\n1 3",
"output": "2"
},
{
"input": "1\n3 2\n3 1\n1 2",
"output": "3"
},
{
"input": "2\n2 3\n1 3\n1 3",
"output": "3"
}
] | 1,667,653,974 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | x = int(input())
k = x
for i in range(3):
a,b = list(map(int, input().split()))
if k==a:
k = b
elif k==b:
k = a
print(k) | Title: Shell Game
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too?
Input Specification:
The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3.
Output Specification:
In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles.
Demo Input:
['1\n1 2\n2 1\n2 1\n', '1\n2 1\n3 1\n1 3\n']
Demo Output:
['2\n', '2\n']
Note:
none | ```python
x = int(input())
k = x
for i in range(3):
a,b = list(map(int, input().split()))
if k==a:
k = b
elif k==b:
k = a
print(k)
``` | -1 |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
"input": "4744000695826",
"output": "YES"
},
{
"input": "10000000004744744",
"output": "YES"
},
{
"input": "446486416781684178",
"output": "YES"
},
{
"input": "999999999",
"output": "NO"
},
{
"input": "7777",
"output": "YES"
},
{
"input": "87414417444",
"output": "NO"
},
{
"input": "111222333444555667",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "4700",
"output": "NO"
},
{
"input": "3794555488744477",
"output": "NO"
},
{
"input": "444444444444444444",
"output": "NO"
},
{
"input": "474447447774444774",
"output": "NO"
},
{
"input": "777777777777777",
"output": "NO"
},
{
"input": "34777745021000000",
"output": "NO"
},
{
"input": "963",
"output": "NO"
},
{
"input": "855474448854788540",
"output": "NO"
},
{
"input": "999999999999994744",
"output": "YES"
},
{
"input": "400000000474",
"output": "YES"
},
{
"input": "123456789123456789",
"output": "YES"
},
{
"input": "740577777584945874",
"output": "NO"
},
{
"input": "7777777",
"output": "YES"
},
{
"input": "4444000111222333",
"output": "YES"
},
{
"input": "9847745885202111",
"output": "YES"
},
{
"input": "123456000000",
"output": "NO"
},
{
"input": "4744447444444",
"output": "NO"
},
{
"input": "7477",
"output": "YES"
},
{
"input": "4747477",
"output": "YES"
},
{
"input": "777777777444444444",
"output": "NO"
}
] | 1,694,611,052 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 0 | n = list(input())
length = list(str(len(n)))
count = 0
res = 0
for i in n:
if i == '4' or i == '7':
res += 1
else:
break
if res == len(n):
print('YES')
else:
for i in length:
if i == '4' or i == '7':
count += 1
else:
break
if len(length) == count:
print("YES")
else:
print("NO") | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
Input Specification:
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output Specification:
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
Demo Input:
['40047\n', '7747774\n', '1000000000000000000\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | ```python
n = list(input())
length = list(str(len(n)))
count = 0
res = 0
for i in n:
if i == '4' or i == '7':
res += 1
else:
break
if res == len(n):
print('YES')
else:
for i in length:
if i == '4' or i == '7':
count += 1
else:
break
if len(length) == count:
print("YES")
else:
print("NO")
``` | 0 |
803 | C | Maximal GCD | PROGRAMMING | 1,900 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.
If there is no possible sequence then output -1. | The first line consists of two numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1010). | If the answer exists then output *k* numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them. | [
"6 3\n",
"8 2\n",
"5 3\n"
] | [
"1 2 3\n",
"2 6\n",
"-1\n"
] | none | 0 | [
{
"input": "6 3",
"output": "1 2 3"
},
{
"input": "8 2",
"output": "2 6"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 10000000000",
"output": "-1"
},
{
"input": "5 1",
"output": "5"
},
{
"input": "6 2",
"output": "2 4"
},
{
"input": "24 2",
"output": "8 16"
},
{
"input": "24 3",
"output": "4 8 12"
},
{
"input": "24 4",
"output": "2 4 6 12"
},
{
"input": "24 5",
"output": "1 2 3 4 14"
},
{
"input": "479001600 2",
"output": "159667200 319334400"
},
{
"input": "479001600 3",
"output": "79833600 159667200 239500800"
},
{
"input": "479001600 4",
"output": "47900160 95800320 143700480 191600640"
},
{
"input": "479001600 5",
"output": "31933440 63866880 95800320 127733760 159667200"
},
{
"input": "479001600 6",
"output": "22809600 45619200 68428800 91238400 114048000 136857600"
},
{
"input": "3000000021 1",
"output": "3000000021"
},
{
"input": "3000000021 2",
"output": "1000000007 2000000014"
},
{
"input": "3000000021 3",
"output": "3 6 3000000012"
},
{
"input": "3000000021 4",
"output": "3 6 9 3000000003"
},
{
"input": "3000000021 50000",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "3000000021 100000",
"output": "-1"
},
{
"input": "10000000000 100",
"output": "1953125 3906250 5859375 7812500 9765625 11718750 13671875 15625000 17578125 19531250 21484375 23437500 25390625 27343750 29296875 31250000 33203125 35156250 37109375 39062500 41015625 42968750 44921875 46875000 48828125 50781250 52734375 54687500 56640625 58593750 60546875 62500000 64453125 66406250 68359375 70312500 72265625 74218750 76171875 78125000 80078125 82031250 83984375 85937500 87890625 89843750 91796875 93750000 95703125 97656250 99609375 101562500 103515625 105468750 107421875 109375000 1113281..."
},
{
"input": "10000000000 2000",
"output": "4000 8000 12000 16000 20000 24000 28000 32000 36000 40000 44000 48000 52000 56000 60000 64000 68000 72000 76000 80000 84000 88000 92000 96000 100000 104000 108000 112000 116000 120000 124000 128000 132000 136000 140000 144000 148000 152000 156000 160000 164000 168000 172000 176000 180000 184000 188000 192000 196000 200000 204000 208000 212000 216000 220000 224000 228000 232000 236000 240000 244000 248000 252000 256000 260000 264000 268000 272000 276000 280000 284000 288000 292000 296000 300000 304000 30800..."
},
{
"input": "10000000000 5000",
"output": "640 1280 1920 2560 3200 3840 4480 5120 5760 6400 7040 7680 8320 8960 9600 10240 10880 11520 12160 12800 13440 14080 14720 15360 16000 16640 17280 17920 18560 19200 19840 20480 21120 21760 22400 23040 23680 24320 24960 25600 26240 26880 27520 28160 28800 29440 30080 30720 31360 32000 32640 33280 33920 34560 35200 35840 36480 37120 37760 38400 39040 39680 40320 40960 41600 42240 42880 43520 44160 44800 45440 46080 46720 47360 48000 48640 49280 49920 50560 51200 51840 52480 53120 53760 54400 55040 55680 56320..."
},
{
"input": "10000000000 100000",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "10000000000 100000000",
"output": "-1"
},
{
"input": "10000000000 10000000000",
"output": "-1"
},
{
"input": "10000000000 100001",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "1 4000000000",
"output": "-1"
},
{
"input": "4294967296 4294967296",
"output": "-1"
},
{
"input": "71227122 9603838834",
"output": "-1"
},
{
"input": "10000000000 9603838835",
"output": "-1"
},
{
"input": "5 5999999999",
"output": "-1"
},
{
"input": "2 9324327498",
"output": "-1"
},
{
"input": "9 2",
"output": "3 6"
},
{
"input": "10000000000 4294967296",
"output": "-1"
},
{
"input": "1 3500000000",
"output": "-1"
},
{
"input": "10000000000 4000000000",
"output": "-1"
},
{
"input": "2000 9324327498",
"output": "-1"
},
{
"input": "10000000000 8589934592",
"output": "-1"
},
{
"input": "5000150001 100001",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "10000000000 3037000500",
"output": "-1"
},
{
"input": "9400000000 9324327498",
"output": "-1"
},
{
"input": "10000000000 3307000500",
"output": "-1"
},
{
"input": "2 4000000000",
"output": "-1"
},
{
"input": "1000 4294967295",
"output": "-1"
},
{
"input": "36 3",
"output": "6 12 18"
},
{
"input": "2147483648 4294967296",
"output": "-1"
},
{
"input": "999 4294967295",
"output": "-1"
},
{
"input": "10000000000 130000",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "10000000000 140000",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "10000000000 6074001000",
"output": "-1"
},
{
"input": "12344321 1",
"output": "12344321"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "28 7",
"output": "1 2 3 4 5 6 7"
},
{
"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": "2 1",
"output": "2"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "2 4",
"output": "-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": "3 1",
"output": "3"
},
{
"input": "3 2",
"output": "1 2"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "3 4",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "3 6",
"output": "-1"
},
{
"input": "3 7",
"output": "-1"
},
{
"input": "3 8",
"output": "-1"
},
{
"input": "3 9",
"output": "-1"
},
{
"input": "3 10",
"output": "-1"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "4 2",
"output": "1 3"
},
{
"input": "4 3",
"output": "-1"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "4 5",
"output": "-1"
},
{
"input": "4 6",
"output": "-1"
},
{
"input": "4 7",
"output": "-1"
},
{
"input": "4 8",
"output": "-1"
},
{
"input": "4 9",
"output": "-1"
},
{
"input": "4 10",
"output": "-1"
},
{
"input": "5 1",
"output": "5"
},
{
"input": "5 2",
"output": "1 4"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "5 4",
"output": "-1"
},
{
"input": "5 5",
"output": "-1"
},
{
"input": "5 6",
"output": "-1"
},
{
"input": "5 7",
"output": "-1"
},
{
"input": "5 8",
"output": "-1"
},
{
"input": "5 9",
"output": "-1"
},
{
"input": "5 10",
"output": "-1"
},
{
"input": "6 1",
"output": "6"
},
{
"input": "6 2",
"output": "2 4"
},
{
"input": "6 3",
"output": "1 2 3"
},
{
"input": "6 4",
"output": "-1"
},
{
"input": "6 5",
"output": "-1"
},
{
"input": "6 6",
"output": "-1"
},
{
"input": "6 7",
"output": "-1"
},
{
"input": "6 8",
"output": "-1"
},
{
"input": "6 9",
"output": "-1"
},
{
"input": "6 10",
"output": "-1"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "7 2",
"output": "1 6"
},
{
"input": "7 3",
"output": "1 2 4"
},
{
"input": "7 4",
"output": "-1"
},
{
"input": "7 5",
"output": "-1"
},
{
"input": "7 6",
"output": "-1"
},
{
"input": "7 7",
"output": "-1"
},
{
"input": "7 8",
"output": "-1"
},
{
"input": "7 9",
"output": "-1"
},
{
"input": "7 10",
"output": "-1"
},
{
"input": "8 1",
"output": "8"
},
{
"input": "8 2",
"output": "2 6"
},
{
"input": "8 3",
"output": "1 2 5"
},
{
"input": "8 4",
"output": "-1"
},
{
"input": "8 5",
"output": "-1"
},
{
"input": "8 6",
"output": "-1"
},
{
"input": "8 7",
"output": "-1"
},
{
"input": "8 8",
"output": "-1"
},
{
"input": "8 9",
"output": "-1"
},
{
"input": "8 10",
"output": "-1"
}
] | 1,600,585,258 | 2,147,483,647 | PyPy 3 | OK | TESTS | 138 | 218 | 9,523,200 | def divisors(x):
divisor=[]
for i in range(1,int(x**(1/2)+1)):
if x%i==0:
divisor.append(i)
if i!=x//i:
divisor.append(x//i)
return divisor
n,k=[int(x) for x in input().split()]
factors=sorted(divisors(n))
maxfactor=0
for i in factors:
if i*(k*(k+1)//2)<=n:
maxfactor=i
if maxfactor:
tobeprinted=[maxfactor*i for i in range(1,k+1)]
tobeprinted[-1]+=n-sum(tobeprinted)
print(*tobeprinted)
else:
print(-1) | Title: Maximal GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.
If there is no possible sequence then output -1.
Input Specification:
The first line consists of two numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1010).
Output Specification:
If the answer exists then output *k* numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.
Demo Input:
['6 3\n', '8 2\n', '5 3\n']
Demo Output:
['1 2 3\n', '2 6\n', '-1\n']
Note:
none | ```python
def divisors(x):
divisor=[]
for i in range(1,int(x**(1/2)+1)):
if x%i==0:
divisor.append(i)
if i!=x//i:
divisor.append(x//i)
return divisor
n,k=[int(x) for x in input().split()]
factors=sorted(divisors(n))
maxfactor=0
for i in factors:
if i*(k*(k+1)//2)<=n:
maxfactor=i
if maxfactor:
tobeprinted=[maxfactor*i for i in range(1,k+1)]
tobeprinted[-1]+=n-sum(tobeprinted)
print(*tobeprinted)
else:
print(-1)
``` | 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,623,745,035 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 154 | 0 | n = int(input())
l1 = list(map(int,input().split()))
s = 0
ans = "YES"
l = []
if(l1[0]>25):
print("NO")
else:
c25 = 0
c50 = 0
c100 = 0
ans = "YES"
for i in l1:
if(i==50):
if(c25>0):
c25-=1
c50+=1
else:
ans = "NO"
break
elif(i==100):
if(c25>=3):
c25-=3
c100+=1
else:
ans = "NO"
break
else:
c25+=1
print(ans)
| 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
n = int(input())
l1 = list(map(int,input().split()))
s = 0
ans = "YES"
l = []
if(l1[0]>25):
print("NO")
else:
c25 = 0
c50 = 0
c100 = 0
ans = "YES"
for i in l1:
if(i==50):
if(c25>0):
c25-=1
c50+=1
else:
ans = "NO"
break
elif(i==100):
if(c25>=3):
c25-=3
c100+=1
else:
ans = "NO"
break
else:
c25+=1
print(ans)
``` | 0 |
|
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,683,223,478 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 1,433,600 | # q20 A. Die Roll
from fractions import Fraction
y,w = map(int,input().split(' '))
chances = 6 - (max(y,w)) +1
if (Fraction(chances/6)==1):
print('1/1')
elif (Fraction(chances/6)==7505999378950827/9007199254740992):
print('5/6')
else:
print (Fraction(chances/6)) | 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
# q20 A. Die Roll
from fractions import Fraction
y,w = map(int,input().split(' '))
chances = 6 - (max(y,w)) +1
if (Fraction(chances/6)==1):
print('1/1')
elif (Fraction(chances/6)==7505999378950827/9007199254740992):
print('5/6')
else:
print (Fraction(chances/6))
``` | 0 |
505 | A | Mr. Kitayuta's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of *s*, possibly to the beginning or the end of *s*. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into *s* so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them. | The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter. | If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. | [
"revive\n",
"ee\n",
"kitayuta\n"
] | [
"reviver\n",
"eye",
"NA\n"
] | For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | 500 | [
{
"input": "revive",
"output": "reviver"
},
{
"input": "ee",
"output": "eee"
},
{
"input": "kitayuta",
"output": "NA"
},
{
"input": "evima",
"output": "NA"
},
{
"input": "a",
"output": "aa"
},
{
"input": "yutampo",
"output": "NA"
},
{
"input": "fft",
"output": "tfft"
},
{
"input": "shuseki",
"output": "NA"
},
{
"input": "lsdijfjisl",
"output": "lsdijfjidsl"
},
{
"input": "ewcdcwerp",
"output": "NA"
},
{
"input": "noon",
"output": "nooon"
},
{
"input": "add",
"output": "adda"
},
{
"input": "iq",
"output": "qiq"
},
{
"input": "hogloid",
"output": "NA"
},
{
"input": "yosupo",
"output": "NA"
},
{
"input": "stat",
"output": "stats"
},
{
"input": "level",
"output": "levvel"
},
{
"input": "iwiwi",
"output": "iwiiwi"
},
{
"input": "racecar",
"output": "raceecar"
},
{
"input": "dog",
"output": "NA"
},
{
"input": "squirrel",
"output": "NA"
},
{
"input": "slime",
"output": "NA"
},
{
"input": "palindrome",
"output": "NA"
},
{
"input": "nqwcvcwqn",
"output": "nqwcvvcwqn"
},
{
"input": "lsdijfjisl",
"output": "lsdijfjidsl"
},
{
"input": "jewiiwefj",
"output": "jfewiiwefj"
},
{
"input": "vnwmvvmonv",
"output": "NA"
},
{
"input": "zennyuu",
"output": "NA"
},
{
"input": "mrtoudai",
"output": "NA"
},
{
"input": "z",
"output": "zz"
},
{
"input": "babccba",
"output": "babccbab"
},
{
"input": "battaba",
"output": "abattaba"
},
{
"input": "bbb",
"output": "bbbb"
},
{
"input": "zaa",
"output": "zaaz"
},
{
"input": "abbabab",
"output": "NA"
},
{
"input": "racecar",
"output": "raceecar"
},
{
"input": "zzz",
"output": "zzzz"
},
{
"input": "eviver",
"output": "reviver"
},
{
"input": "aaaaa",
"output": "aaaaaa"
},
{
"input": "eee",
"output": "eeee"
}
] | 1,448,022,278 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 561 | 10,854,400 | from pip._vendor.distlib.compat import raw_input
L = raw_input()
l = 0
r = len(L)-1
flag = 1
ok = 1
gg = -1
while l <= r:
if L[l] != L[r] and flag == 1:
flag = 0
l+=1
gg = r
elif L[l] != L[r] and flag == 0:
ok = 0
break
else:
l+=1
r-=1
if ok == 0:
ok = 2
flag = 2
while l <= r:
if L[l] != L[r] and flag == 2:
flag = 0
r-=1
gg = l
elif L[l] != L[r] and flag == 0:
ok = 0
break
else:
l+=1
r-=1
if ok == 0:
print("NA")
exit()
if gg == -1:
gg = len(L)//2
gg = int(gg)
if ok == 2:
for i in range(0,len(L)):
if(i == gg-1):
print(L[len(L)-gg],end = '')
print(L[i],end = '')
if ok == 1:
for i in range(0,len(L)):
print(L[i],end = '')
if(i == gg):
print(L[len(L)-1-gg],end = '')
| Title: Mr. Kitayuta's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of *s*, possibly to the beginning or the end of *s*. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into *s* so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input Specification:
The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter.
Output Specification:
If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Demo Input:
['revive\n', 'ee\n', 'kitayuta\n']
Demo Output:
['reviver\n', 'eye', 'NA\n']
Note:
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | ```python
from pip._vendor.distlib.compat import raw_input
L = raw_input()
l = 0
r = len(L)-1
flag = 1
ok = 1
gg = -1
while l <= r:
if L[l] != L[r] and flag == 1:
flag = 0
l+=1
gg = r
elif L[l] != L[r] and flag == 0:
ok = 0
break
else:
l+=1
r-=1
if ok == 0:
ok = 2
flag = 2
while l <= r:
if L[l] != L[r] and flag == 2:
flag = 0
r-=1
gg = l
elif L[l] != L[r] and flag == 0:
ok = 0
break
else:
l+=1
r-=1
if ok == 0:
print("NA")
exit()
if gg == -1:
gg = len(L)//2
gg = int(gg)
if ok == 2:
for i in range(0,len(L)):
if(i == gg-1):
print(L[len(L)-gg],end = '')
print(L[i],end = '')
if ok == 1:
for i in range(0,len(L)):
print(L[i],end = '')
if(i == gg):
print(L[len(L)-1-gg],end = '')
``` | 0 |
|
611 | B | New Year and Old Property | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"implementation"
] | null | null | The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation.
Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster?
Assume that all positive integers are always written without leading zeros. | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively. | Print one integer – the number of years Limak will count in his chosen interval. | [
"5 10\n",
"2015 2015\n",
"100 105\n",
"72057594000000000 72057595000000000\n"
] | [
"2\n",
"1\n",
"0\n",
"26\n"
] | In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub>, 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property. | 750 | [
{
"input": "5 10",
"output": "2"
},
{
"input": "2015 2015",
"output": "1"
},
{
"input": "100 105",
"output": "0"
},
{
"input": "72057594000000000 72057595000000000",
"output": "26"
},
{
"input": "1 100",
"output": "16"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "1 1000000000000000000",
"output": "1712"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 7",
"output": "3"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "2 3",
"output": "1"
},
{
"input": "2 4",
"output": "1"
},
{
"input": "2 5",
"output": "2"
},
{
"input": "2 6",
"output": "3"
},
{
"input": "2 7",
"output": "3"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "3 4",
"output": "0"
},
{
"input": "3 5",
"output": "1"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "4 4",
"output": "0"
},
{
"input": "4 5",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "4 7",
"output": "2"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "5 6",
"output": "2"
},
{
"input": "5 7",
"output": "2"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "6 7",
"output": "1"
},
{
"input": "7 7",
"output": "0"
},
{
"input": "1 8",
"output": "3"
},
{
"input": "6 8",
"output": "1"
},
{
"input": "7 8",
"output": "0"
},
{
"input": "8 8",
"output": "0"
},
{
"input": "1 1022",
"output": "45"
},
{
"input": "1 1023",
"output": "45"
},
{
"input": "1 1024",
"output": "45"
},
{
"input": "1 1025",
"output": "45"
},
{
"input": "1 1026",
"output": "45"
},
{
"input": "509 1022",
"output": "11"
},
{
"input": "510 1022",
"output": "10"
},
{
"input": "511 1022",
"output": "9"
},
{
"input": "512 1022",
"output": "9"
},
{
"input": "513 1022",
"output": "9"
},
{
"input": "509 1023",
"output": "11"
},
{
"input": "510 1023",
"output": "10"
},
{
"input": "511 1023",
"output": "9"
},
{
"input": "512 1023",
"output": "9"
},
{
"input": "513 1023",
"output": "9"
},
{
"input": "509 1024",
"output": "11"
},
{
"input": "510 1024",
"output": "10"
},
{
"input": "511 1024",
"output": "9"
},
{
"input": "512 1024",
"output": "9"
},
{
"input": "513 1024",
"output": "9"
},
{
"input": "509 1025",
"output": "11"
},
{
"input": "510 1025",
"output": "10"
},
{
"input": "511 1025",
"output": "9"
},
{
"input": "512 1025",
"output": "9"
},
{
"input": "513 1025",
"output": "9"
},
{
"input": "1 1000000000",
"output": "408"
},
{
"input": "10000000000 70000000000000000",
"output": "961"
},
{
"input": "1 935829385028502935",
"output": "1712"
},
{
"input": "500000000000000000 1000000000000000000",
"output": "58"
},
{
"input": "500000000000000000 576460752303423488",
"output": "57"
},
{
"input": "576460752303423488 1000000000000000000",
"output": "1"
},
{
"input": "999999999999999999 1000000000000000000",
"output": "0"
},
{
"input": "1124800395214847 36011204832919551",
"output": "257"
},
{
"input": "1124800395214847 36011204832919550",
"output": "256"
},
{
"input": "1124800395214847 36011204832919552",
"output": "257"
},
{
"input": "1124800395214846 36011204832919551",
"output": "257"
},
{
"input": "1124800395214848 36011204832919551",
"output": "256"
},
{
"input": "1 287104476244869119",
"output": "1603"
},
{
"input": "1 287104476244869118",
"output": "1602"
},
{
"input": "1 287104476244869120",
"output": "1603"
},
{
"input": "492581209243647 1000000000000000000",
"output": "583"
},
{
"input": "492581209243646 1000000000000000000",
"output": "583"
},
{
"input": "492581209243648 1000000000000000000",
"output": "582"
},
{
"input": "1099444518911 1099444518911",
"output": "1"
},
{
"input": "1099444518910 1099444518911",
"output": "1"
},
{
"input": "1099444518911 1099444518912",
"output": "1"
},
{
"input": "1099444518910 1099444518912",
"output": "1"
},
{
"input": "864691128455135231 864691128455135231",
"output": "1"
},
{
"input": "864691128455135231 864691128455135232",
"output": "1"
},
{
"input": "864691128455135230 864691128455135232",
"output": "1"
},
{
"input": "864691128455135230 864691128455135231",
"output": "1"
},
{
"input": "864691128455135231 1000000000000000000",
"output": "1"
},
{
"input": "864691128455135232 1000000000000000000",
"output": "0"
},
{
"input": "864691128455135230 1000000000000000000",
"output": "1"
},
{
"input": "576460752303423487 576460752303423487",
"output": "0"
},
{
"input": "1 576460752303423487",
"output": "1711"
},
{
"input": "1 576460752303423486",
"output": "1711"
},
{
"input": "2 1000000000000000000",
"output": "1712"
},
{
"input": "3 1000000000000000000",
"output": "1711"
},
{
"input": "4 1000000000000000000",
"output": "1711"
},
{
"input": "5 1000000000000000000",
"output": "1711"
},
{
"input": "6 1000000000000000000",
"output": "1710"
},
{
"input": "5 6",
"output": "2"
},
{
"input": "1 2",
"output": "1"
}
] | 1,660,928,912 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | #I = lambda: [int(i) for i in input().split()]
#import io, os, sys
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# n = int(input())
# l1 = list(map(int,input().split()))
# n,x = map(int,input().split())
# s = input()
mod = 1000000007
# print("Case #"+str(_+1)+":",)
from collections import Counter,defaultdict,deque
from heapq import heappush,heappop,heapify
import sys
import math
import bisect
a,b = map(int,input().split())
x = int(math.log2(a))
A = bin(a)[2:]
B = bin(b)[2:]
if b<int(math.pow(2,x+1)):
p=0
for i in range(x+1):
if A[i]=='0':
p=i-1
break
q=0
for i in range(x+1):
if B[i]=='0':
q=i-1
break
print(q-p)
else:
ans=0
q=0
y = int(math.log2(b))
for i in range(x+1):
if A[i]=='0':
q=i-1
break
for i in range(y+1):
if B[i]=='0':
ans+=(i-1)
break
#print(ans)
ans+=(x-q)
#print(x,y,ans)
for i in range(x+1,y):
ans+=i
print(ans)
| Title: New Year and Old Property
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation.
Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster?
Assume that all positive integers are always written without leading zeros.
Input Specification:
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively.
Output Specification:
Print one integer – the number of years Limak will count in his chosen interval.
Demo Input:
['5 10\n', '2015 2015\n', '100 105\n', '72057594000000000 72057595000000000\n']
Demo Output:
['2\n', '1\n', '0\n', '26\n']
Note:
In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub>, 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property. | ```python
#I = lambda: [int(i) for i in input().split()]
#import io, os, sys
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# n = int(input())
# l1 = list(map(int,input().split()))
# n,x = map(int,input().split())
# s = input()
mod = 1000000007
# print("Case #"+str(_+1)+":",)
from collections import Counter,defaultdict,deque
from heapq import heappush,heappop,heapify
import sys
import math
import bisect
a,b = map(int,input().split())
x = int(math.log2(a))
A = bin(a)[2:]
B = bin(b)[2:]
if b<int(math.pow(2,x+1)):
p=0
for i in range(x+1):
if A[i]=='0':
p=i-1
break
q=0
for i in range(x+1):
if B[i]=='0':
q=i-1
break
print(q-p)
else:
ans=0
q=0
y = int(math.log2(b))
for i in range(x+1):
if A[i]=='0':
q=i-1
break
for i in range(y+1):
if B[i]=='0':
ans+=(i-1)
break
#print(ans)
ans+=(x-q)
#print(x,y,ans)
for i in range(x+1,y):
ans+=i
print(ans)
``` | 0 |
|
877 | B | Nikita and string | PROGRAMMING | 1,500 | [
"brute force",
"dp"
] | null | null | One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".
Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get? | The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b". | Print a single integer — the maximum possible size of beautiful string Nikita can get. | [
"abba\n",
"bab\n"
] | [
"4",
"2"
] | It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 1,000 | [
{
"input": "abba",
"output": "4"
},
{
"input": "bab",
"output": "2"
},
{
"input": "bbabbbaabbbb",
"output": "9"
},
{
"input": "bbabbbbbaaba",
"output": "10"
},
{
"input": "bbabbbababaa",
"output": "9"
},
{
"input": "aabbaababbab",
"output": "8"
},
{
"input": "a",
"output": "1"
},
{
"input": "b",
"output": "1"
},
{
"input": "ab",
"output": "2"
},
{
"input": "ba",
"output": "2"
},
{
"input": "bb",
"output": "2"
},
{
"input": "aa",
"output": "2"
},
{
"input": "babbbaab",
"output": "6"
},
{
"input": "abaaaa",
"output": "6"
},
{
"input": "aaa",
"output": "3"
}
] | 1,655,718,120 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 46 | 0 | inp = str(input())
a = [0] * 3
for i in inp:
if i == 'a':
a[2] = max(a) + 1
a[0] += 1
else:
a[1] = max(a[:2]) + 1
print(max(a)) | Title: Nikita and string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".
Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
Input Specification:
The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b".
Output Specification:
Print a single integer — the maximum possible size of beautiful string Nikita can get.
Demo Input:
['abba\n', 'bab\n']
Demo Output:
['4', '2']
Note:
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | ```python
inp = str(input())
a = [0] * 3
for i in inp:
if i == 'a':
a[2] = max(a) + 1
a[0] += 1
else:
a[1] = max(a[:2]) + 1
print(max(a))
``` | 3 |
|
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
{
"input": "7\n3 2 1 6 5 7 4",
"output": "8"
},
{
"input": "8\n2 8 3 7 6 9 1 5",
"output": "4"
},
{
"input": "9\n10 5 9 3 8 7 1 2 4",
"output": "6"
},
{
"input": "10\n7 2 3 8 9 6 5 4 1 10",
"output": "11"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 4 1",
"output": "3"
},
{
"input": "4\n4 2 3 1",
"output": "5"
},
{
"input": "5\n3 1 4 2 5",
"output": "6"
},
{
"input": "6\n1 3 6 7 2 4",
"output": "5"
},
{
"input": "7\n1 5 4 7 2 3 6",
"output": "8"
},
{
"input": "8\n12 1 6 5 2 8 3 4",
"output": "7"
},
{
"input": "9\n3 2 7 5 6 4 1 9 10",
"output": "8"
},
{
"input": "10\n1 7 13 6 5 10 3 8 2 4",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n3000",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
},
{
"input": "2\n3000 1",
"output": "2"
}
] | 1,627,621,614 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 216 | 21,504,000 |
def main():
n = int(input())
arr = list(map(int, input().split()))
count = 1
arr.sort()
for i in arr:
if i != count:
print(count)
exit()
count += 1
print(count)
main()
| Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output Specification:
Output the required default value for the next test index.
Demo Input:
['3\n1 7 2\n']
Demo Output:
['3\n']
Note:
none | ```python
def main():
n = int(input())
arr = list(map(int, input().split()))
count = 1
arr.sort()
for i in arr:
if i != count:
print(count)
exit()
count += 1
print(count)
main()
``` | 3.905946 |
808 | B | Average Sleep Time | PROGRAMMING | 1,300 | [
"data structures",
"implementation",
"math"
] | null | null | It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days!
When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last *n* days. So now he has a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the sleep time on the *i*-th day.
The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider *k* consecutive days as a week. So there will be *n*<=-<=*k*<=+<=1 weeks to take into consideration. For example, if *k*<==<=2, *n*<==<=3 and *a*<==<=[3,<=4,<=7], then the result is .
You should write a program which will calculate average sleep times of Polycarp over all weeks. | The first line contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | Output average sleeping time over all weeks.
The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=6. In particular, it is enough to output real number with at least 6 digits after the decimal point. | [
"3 2\n3 4 7\n",
"1 1\n10\n",
"8 2\n1 2 4 100000 123 456 789 1\n"
] | [
"9.0000000000\n",
"10.0000000000\n",
"28964.2857142857\n"
] | In the third example there are *n* - *k* + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. | 0 | [
{
"input": "3 2\n3 4 7",
"output": "9.0000000000"
},
{
"input": "1 1\n10",
"output": "10.0000000000"
},
{
"input": "8 2\n1 2 4 100000 123 456 789 1",
"output": "28964.2857142857"
},
{
"input": "1 1\n1",
"output": "1.0000000000"
},
{
"input": "1 1\n100000",
"output": "100000.0000000000"
},
{
"input": "3 1\n1 2 3",
"output": "2.0000000000"
},
{
"input": "10 4\n11 3 5 20 12 7 9 2 2 20",
"output": "36.2857142857"
},
{
"input": "10 5\n15 9 3 2 17 10 9 18 4 19",
"output": "50.3333333333"
},
{
"input": "10 6\n19 3 20 16 14 10 1 13 7 3",
"output": "65.8000000000"
},
{
"input": "10 7\n8 16 2 13 15 9 5 13 9 2",
"output": "68.2500000000"
},
{
"input": "10 4\n127 1459 718 1183 880 1044 1857 1340 725 1496",
"output": "4574.4285714286"
},
{
"input": "10 5\n1384 1129 1780 1960 1567 1928 12 1523 1165 344",
"output": "6931.3333333333"
}
] | 1,565,186,694 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 |
n,k = map(int,input().split())
arr = list(map(int,input().split()))
acc = sum(arr[0:k])
sleep = acc
print(sleep)
for i in range(k,n):
acc += arr[i]
acc -= arr[i-k]
sleep += acc
print(sleep / (n-k+1))
| Title: Average Sleep Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days!
When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last *n* days. So now he has a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the sleep time on the *i*-th day.
The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider *k* consecutive days as a week. So there will be *n*<=-<=*k*<=+<=1 weeks to take into consideration. For example, if *k*<==<=2, *n*<==<=3 and *a*<==<=[3,<=4,<=7], then the result is .
You should write a program which will calculate average sleep times of Polycarp over all weeks.
Input Specification:
The first line contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Output average sleeping time over all weeks.
The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=6. In particular, it is enough to output real number with at least 6 digits after the decimal point.
Demo Input:
['3 2\n3 4 7\n', '1 1\n10\n', '8 2\n1 2 4 100000 123 456 789 1\n']
Demo Output:
['9.0000000000\n', '10.0000000000\n', '28964.2857142857\n']
Note:
In the third example there are *n* - *k* + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. | ```python
n,k = map(int,input().split())
arr = list(map(int,input().split()))
acc = sum(arr[0:k])
sleep = acc
print(sleep)
for i in range(k,n):
acc += arr[i]
acc -= arr[i-k]
sleep += acc
print(sleep / (n-k+1))
``` | 0 |
|
12 | A | Super Agent | PROGRAMMING | 800 | [
"implementation"
] | A. Super Agent | 2 | 256 | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.
Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=×<=3 with digits from 1 to 9.
Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations. | Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». | Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. | [
"XX.\n...\n.XX\n",
"X.X\nX..\n...\n"
] | [
"YES\n",
"NO\n"
] | If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | 0 | [
{
"input": "XX.\n...\n.XX",
"output": "YES"
},
{
"input": ".X.\n.X.\n.X.",
"output": "YES"
},
{
"input": "XXX\nXXX\nXXX",
"output": "YES"
},
{
"input": "XXX\nX.X\nXXX",
"output": "YES"
},
{
"input": "X..\n.X.\n..X",
"output": "YES"
},
{
"input": "...\nX.X\nX..",
"output": "NO"
},
{
"input": ".X.\nX.X\n.X.",
"output": "YES"
},
{
"input": "X.X\n.X.\nX.X",
"output": "YES"
},
{
"input": "...\n...\n..X",
"output": "NO"
},
{
"input": "XXX\n...\nXXX",
"output": "YES"
},
{
"input": "..X\nX..\n..X",
"output": "NO"
},
{
"input": ".X.\n...\nX.X",
"output": "NO"
},
{
"input": "X.X\nX.X\nX.X",
"output": "YES"
},
{
"input": ".X.\nX.X\nXX.",
"output": "NO"
},
{
"input": "...\nXXX\nXXX",
"output": "NO"
},
{
"input": "XXX\n..X\nXXX",
"output": "NO"
},
{
"input": "X..\nX.X\n.X.",
"output": "NO"
},
{
"input": "...\n..X\nXXX",
"output": "NO"
},
{
"input": "..X\nX.X\nX..",
"output": "YES"
},
{
"input": "..X\n..X\nXXX",
"output": "NO"
},
{
"input": "X..\nX..\nX..",
"output": "NO"
},
{
"input": "XXX\n.X.\nXXX",
"output": "YES"
},
{
"input": "..X\n...\nX..",
"output": "YES"
},
{
"input": "...\n...\nX..",
"output": "NO"
},
{
"input": "...\n...\n.X.",
"output": "NO"
},
{
"input": "...\n...\n..X",
"output": "NO"
},
{
"input": "...\n.X.\nX..",
"output": "NO"
}
] | 1,624,457,785 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 154 | 0 | kl="";
for i in range(3):
kl+=input();
print(['NO','YES'][kl==kl[::-1]]); | Title: Super Agent
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.
Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=×<=3 with digits from 1 to 9.
Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.
Input Specification:
Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.».
Output Specification:
Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.
Demo Input:
['XX.\n...\n.XX\n', 'X.X\nX..\n...\n']
Demo Output:
['YES\n', 'NO\n']
Note:
If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | ```python
kl="";
for i in range(3):
kl+=input();
print(['NO','YES'][kl==kl[::-1]]);
``` | 3.9615 |
747 | B | Mammoth's Genome Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'.
It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.
Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. | The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. | If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). | [
"8\nAG?C??CT\n",
"4\nAGCT\n",
"6\n????G?\n",
"4\nAA??\n"
] | [
"AGACGTCT\n",
"AGCT\n",
"===\n",
"===\n"
] | In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.
In the third and the fourth examples it is impossible to decode the genom. | 1,000 | [
{
"input": "8\nAG?C??CT",
"output": "AGACGTCT"
},
{
"input": "4\nAGCT",
"output": "AGCT"
},
{
"input": "6\n????G?",
"output": "==="
},
{
"input": "4\nAA??",
"output": "==="
},
{
"input": "4\n????",
"output": "ACGT"
},
{
"input": "252\n???????GCG??T??TT?????T?C???C?CCG???GA???????AC??A???AAC?C?CC??CCC??A??TA?CCC??T???C??CA???CA??G????C?C?C????C??C??A???C?T????C??ACGC??CC?A?????A??CC?C??C?CCG?C??C??A??CG?A?????A?CT???CC????CCC?CATC?G??????????A???????????????TCCCC?C?CA??AC??GC????????",
"output": "AAAAAAAGCGAATAATTAAAAATACAAACACCGAAAGAAAAAAAAACAAAAAAAACACACCAACCCAAAACTACCCCCCTCCCCCGCAGGGCAGGGGGGGCGCGCGGGGCGGCGGAGGGCGTGGGGCGGACGCGGCCGAGGGGGAGGCCGCGGCGCCGGCGGCGGAGGCGGAGTTTTATCTTTTCCTTTTCCCTCATCTGTTTTTTTTTTATTTTTTTTTTTTTTTTCCCCTCTCATTACTTGCTTTTTTTT"
},
{
"input": "255\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "==="
},
{
"input": "4\n??A?",
"output": "CGAT"
},
{
"input": "4\n?C??",
"output": "ACGT"
},
{
"input": "4\nT???",
"output": "TACG"
},
{
"input": "4\n???G",
"output": "ACTG"
},
{
"input": "4\n??AC",
"output": "GTAC"
},
{
"input": "8\n?C?AA???",
"output": "CCGAAGTT"
},
{
"input": "12\n???A?G???A?T",
"output": "ACCACGGGTATT"
},
{
"input": "16\n?????C??CAG??T??",
"output": "AAACCCGGCAGGTTTT"
},
{
"input": "20\n???A?G??C?GC???????G",
"output": "AAAAAGCCCCGCGGTTTTTG"
},
{
"input": "24\n?TG???AT?A?CTTG??T?GCT??",
"output": "ATGAAAATCACCTTGCCTGGCTGG"
},
{
"input": "28\n??CTGAAG?GGT?CC?A??TT?CCACG?",
"output": "AACTGAAGAGGTCCCGAGTTTTCCACGT"
},
{
"input": "32\n??A?????CAAG?C?C?CG??A?A??AAC?A?",
"output": "CCACGGGGCAAGGCGCTCGTTATATTAACTAT"
},
{
"input": "36\n?GCC?CT?G?CGG?GCTGA?C?G?G????C??G?C?",
"output": "AGCCACTAGACGGAGCTGAACAGAGCTTTCTTGTCT"
},
{
"input": "40\nTA?AA?C?G?ACC?G?GCTCGC?TG??TG?CT?G??CC??",
"output": "TAAAAACAGAACCAGAGCTCGCCTGGGTGGCTTGTTCCTT"
},
{
"input": "44\nT?TA??A??AA???A?AGTA??TAT??ACTGAT??CT?AC?T??",
"output": "TCTACCACCAACCCAGAGTAGGTATGGACTGATGGCTGACGTTT"
},
{
"input": "48\nG?G??GC??CA?G????AG?CA?CG??GGCCCCAA??G??C?T?TCA?",
"output": "GAGAAGCAACAAGCCGGAGGCATCGTTGGCCCCAATTGTTCTTTTCAT"
},
{
"input": "52\n??G?G?CTGT??T?GCGCT?TAGGTT??C???GTCG??GC??C???????CG",
"output": "AAGAGACTGTAATAGCGCTATAGGTTAACAACGTCGCCGCCCCGGTTTTTCG"
},
{
"input": "56\n?GCCA?GC?GA??GA??T?CCGC?????TGGC?AGGCCGC?AC?TGAT??CG?A??",
"output": "AGCCAAGCAGAAAGAAATCCCGCCGGTTTGGCTAGGCCGCTACTTGATTTCGTATT"
},
{
"input": "60\nAT?T?CCGG??G?CCT?CCC?C?CGG????TCCCG?C?TG?TT?TA??A?TGT?????G?",
"output": "ATATACCGGAAGACCTACCCACACGGAAAATCCCGCCCTGGTTGTAGGAGTGTGTTTTGT"
},
{
"input": "64\n?G??C??????C??C??AG?T?GC?TT??TAGA?GA?A??T?C???TC??A?CA??C??A???C",
"output": "AGAACAAAAACCCCCCCAGCTCGCGTTGGTAGAGGAGAGGTGCGGGTCTTATCATTCTTATTTC"
},
{
"input": "68\nC?T??????C????G?T??TTT?T?T?G?CG??GCC??CT??????C??T?CC?T?T????CTT?T??",
"output": "CATAAAAAACAAAAGATAATTTATATAGCCGCCGCCCCCTCCGGGGCGGTGCCGTGTGGGGCTTTTTT"
},
{
"input": "72\nA?GTA??A?TG?TA???AAAGG?A?T?TTAAT??GGA?T??G?T?T????TTATAAA?AA?T?G?TGT??TG",
"output": "AAGTACCACTGCTACCCAAAGGCACTCTTAATCCGGACTCCGCTCTCGGGTTATAAAGAAGTGGGTGTGTTG"
},
{
"input": "76\nG?GTAC?CG?AG?AGC???A??T?TC?G??C?G?A???TC???GTG?C?AC???A??????TCA??TT?A?T?ATG",
"output": "GAGTACACGAAGAAGCAAAAAATCTCCGCCCCGCACCCTCCGGGTGGCGACGGGAGGTTTTTCATTTTTATTTATG"
},
{
"input": "80\nGG???TAATT?A?AAG?G?TT???G??TTA?GAT?????GT?AA?TT?G?AG???G?T?A??GT??TTT?TTG??AT?T?",
"output": "GGAAATAATTAAAAAGAGATTACCGCCTTACGATCCCCCGTCAACTTCGCAGCCCGCTCACGGTGGTTTGTTGGGATGTG"
},
{
"input": "84\n?C??G??CGGC????CA?GCGG???G?CG??GA??C???C???GC???CG?G?A?C?CC?AC?C?GGAG???C??????G???C",
"output": "ACAAGAACGGCAAAACAAGCGGAAAGACGAAGACCCCCGCGGGGCGTTCGTGTATCTCCTACTCTGGAGTTTCTTTTTTGTTTC"
},
{
"input": "88\nGTTC?TCTGCGCGG??CATC?GTGCTCG?A?G?TGCAGCAG??A?CAG???GGTG?ATCAGG?TCTACTC?CG?GGT?A?TCC??AT?",
"output": "GTTCATCTGCGCGGAACATCAGTGCTCGAAAGATGCAGCAGAAAACAGACCGGTGCATCAGGCTCTACTCGCGTGGTTATTCCTTATT"
},
{
"input": "92\n??TT????AT?T????A???TC????A?C????AT???T?T???T??A???T??TTA?AT?AA?C????C??????????????TAA?T???",
"output": "AATTAAAAATATAAAAAACCTCCCCCACCCCCCATCCCTCTCCCTCGAGGGTGGTTAGATGAAGCGGGGCGGGGGGGGGGTTTTTAATTTTT"
},
{
"input": "96\nT?????C?CT?T??GGG??G??C???A?CC??????G???TCCCT??C?G??GC?CT?CGT?GGG??TCTC?C?CCGT?CCTCTT??CC?C?????",
"output": "TAAAAACACTATAAGGGAAGAACAAAAACCAAAAAAGCGGTCCCTGGCGGGGGCGCTGCGTGGGGGGTCTCTCTCCGTTCCTCTTTTCCTCTTTTT"
},
{
"input": "100\n???GGA?C?A?A??A?G??GT?GG??G????A?ATGGAA???A?A?A?AGAGGT?GA?????AA???G???GA???TAGAG?ACGGA?AA?G???GGGAT",
"output": "ACCGGACCCACACCACGCCGTCGGCCGCCCCACATGGAACCCACACAGAGAGGTGGATTTTTAATTTGTTTGATTTTAGAGTACGGATAATGTTTGGGAT"
},
{
"input": "104\n???TTG?C???G?G??G??????G?T??TC???CCC????TG?GGT??GG?????T?CG???GGG??GTC?G??TC??GG??CTGGCT??G????C??????TG",
"output": "AAATTGACAAAGAGAAGAAAAAAGATAATCAAACCCAAAATGCGGTCCGGCCCCCTCCGCCCGGGCCGTCCGGGTCGGGGTTCTGGCTTTGTTTTCTTTTTTTG"
},
{
"input": "108\n??CAC?A?ACCA??A?CA??AA?TA?AT?????CCC????A??T?C?CATA??CAA?TACT??A?TA?AC?T??G???GG?G??CCC??AA?CG????T?CT?A??AA",
"output": "AACACAACACCACCACCACCAACTACATCGGGGCCCGGGGAGGTGCGCATAGGCAAGTACTGGAGTAGACGTGGGTTTGGTGTTCCCTTAATCGTTTTTTCTTATTAA"
},
{
"input": "112\n???T?TC?C?AC???TC?C???CCC??C????C?CCGC???TG?C?T??????C?C?????G?C????A????????G?C?A?C?A?C?C??C????CC?TC??C??C?A??",
"output": "AAATATCACAACAAATCACAAACCCAACAAAACACCGCAAATGCCGTGGGGGGCGCGGGGGGGCGGGGAGGGGGGTTGTCTATCTATCTCTTCTTTTCCTTCTTCTTCTATT"
},
{
"input": "116\n????C??A?A??AAC???????C???CCCTC??A????ATA?T??AT???C?TCCC???????C????CTC??T?A???C??A???CCA?TAC?AT?????C??CA???C?????C",
"output": "AAAACAAAAAAAAACAAAAAACCCCCCCCTCCCACGGGATAGTGGATGGGCGTCCCGGGGGGGCGGGGCTCGGTGAGGGCGGATTTCCATTACTATTTTTTCTTCATTTCTTTTTC"
},
{
"input": "120\nTC?AGATG?GAT??G????C?C??GA?GT?TATAC?AGA?TCG?TCT???A?AAA??C?T?A???AA?TAC?ATTT???T?AA?G???TG?AT???TA??GCGG?AC?A??AT??T???C",
"output": "TCAAGATGAGATAAGAACCCCCCCGACGTCTATACCAGACTCGCTCTCCCACAAACCCCTCACGGAAGTACGATTTGGGTGAAGGGGGTGGATGGGTAGTGCGGTACTATTATTTTTTTC"
},
{
"input": "124\n???C?????C?AGG??A?A?CA????A??A?AA??A????????G?A?????????AG?A??G?C??A??C???G??CG??C???????A????C???AG?AA???AC????????????C??G",
"output": "AAACAAAAACAAGGAAAAAACACCCCACCACAACCACCCCCCCCGCACCCGGGGGGAGGAGGGGCGGAGGCGGGGGGCGGGCGTTTTTTATTTTCTTTAGTAATTTACTTTTTTTTTTTTCTTG"
},
{
"input": "128\nAT?GC?T?C?GATTTG??ATTGG?AC?GGCCA?T?GG?CCGG??AGT?TGT?G??A?AAGGCGG?T??TCT?CT??C?TTGTTG??????CCGG?TGATAT?T?TTGTCCCT??CTGTGTAATA??G?",
"output": "ATAGCATACAGATTTGAAATTGGAACAGGCCAATAGGACCGGAAAGTATGTAGAAAAAAGGCGGCTCCTCTCCTCCCCTTGTTGCCCCCCCCGGCTGATATCTGTTGTCCCTGGCTGTGTAATAGGGT"
},
{
"input": "132\nAC???AA??T???T??G??ACG?C??AA?GA?C???CGAGTA?T??TTGTC???GCTGATCA????C??TA???ATTTA?C??GT??GTCTCTCGT?AAGGACTG?TC????T???C?T???ATTTT?T?AT",
"output": "ACAAAAAAATAAATAAGAAACGACACAACGACCCCCCGAGTACTCCTTGTCCCCGCTGATCACCCCCCGTAGGGATTTAGCGGGTGGGTCTCTCGTGAAGGACTGGTCGGGGTGGGCGTTTTATTTTTTTAT"
},
{
"input": "136\n?A?C???????C??????????????C?????C???????????CCCC?????????C??????C??C??????CC??C??C?C???C??????C??C?C??????????C?????????GC????C???????C?",
"output": "AAACAAAAAAACAAAAAAAAAAAAAACAAAAACAAAAACCCCCCCCCCCCCCGGGGGCGGGGGGCGGCGGGGGGCCGGCGGCGCGGGCGGGGGGCTTCTCTTTTTTTTTTCTTTTTTTTTGCTTTTCTTTTTTTCT"
},
{
"input": "140\nTTG??G?GG?G??C??CTC?CGG?TTCGC????GGCG?G??TTGCCCC?TCC??A??CG?GCCTTT?G??G??CT??TG?G?TTC?TGC?GG?TGT??CTGGAT??TGGTTG??TTGGTTTTTTGGTCGATCGG???C??",
"output": "TTGAAGAGGAGAACAACTCACGGATTCGCAAAAGGCGAGAATTGCCCCATCCAAAAACGAGCCTTTAGAAGAACTAATGAGATTCCTGCCGGCTGTCCCTGGATCCTGGTTGCCTTGGTTTTTTGGTCGATCGGCCCCTT"
},
{
"input": "144\n?????A?C?A?A???TTT?GAATA?G??T?T?????AT?AA??TT???TT??A?T????AT??TA??AA???T??A??TT???A????T???T????A??T?G???A?C?T????A?AA??A?T?C??A??A???AA????ATA",
"output": "AAAAAAACAAAACCCTTTCGAATACGCCTCTCCCCCATCAACCTTCCCTTCCACTCCCCATCCTACCAACCCTGGAGGTTGGGAGGGGTGGGTGGGGAGGTGGGGGAGCGTGGGGAGAAGGATTTCTTATTATTTAATTTTATA"
},
{
"input": "148\nACG?GGGT?A??C????TCTTGCTG?GTA?C?C?TG?GT??GGGG??TTG?CA????GT???G?TT?T?CT?C??C???CTTCATTA?G?G???GC?AAT??T???AT??GGATT????TC?C???????T??TATCG???T?T?CG?",
"output": "ACGAGGGTAAAACAAAATCTTGCTGAGTAACACATGAGTAAGGGGAATTGACAAAAAGTAAAGATTCTCCTCCCCCCCCCTTCATTACGCGCCCGCCAATCCTCCCATCGGGATTGGGGTCGCGGGGGGGTGTTATCGTTTTTTTCGT"
},
{
"input": "152\n??CTA??G?GTC?G??TTCC?TG??????T??C?G???G?CC???C?GT?G?G??C?CGGT?CC????G?T?T?C?T??G?TCGT??????A??TCC?G?C???GTT?GC?T?CTT?GT?C??C?TCGTTG?TTG?G????CG?GC??G??G",
"output": "AACTAAAGAGTCAGAATTCCATGAAAAAATAACAGAAAGACCAAACAGTAGAGAACACGGTACCAAAAGCTCTCCCTCCGCTCGTCCCCCCACGTCCGGGCGGGGTTGGCGTGCTTGGTGCGTCTTCGTTGTTTGTGTTTTCGTGCTTGTTG"
},
{
"input": "156\nGCA????A???AAT?C??????GAG?CCA?A?CG??ACG??????GCAAAC??GCGGTCC??GT???C???????CC???????ACGCA????C??A??CC??A?GAATAC?C?CA?CCCT?TCACA?A???????C??TAG?C??T??A??A?CA",
"output": "GCAAAAAAAAAAATACAAAAACGAGCCCACACCGCCACGCCCGGGGCAAACGGGCGGTCCGGGTGGGCGGGGGGGCCGGGGGGGACGCAGGTTCTTATTCCTTATGAATACTCTCATCCCTTTCACATATTTTTTTCTTTAGTCTTTTTATTATCA"
},
{
"input": "160\nGCACC????T?TGATAC??CATATCC?GT?AGT?ATGGATA?CC?????GCTCG?A?GG?A?GCCAG??C?CGGATC?GCAA?AAGCCCCC?CAT?GA?GC?CAC?TAA?G?CACAACGG?AAA??CA?ACTCGA?CAC?GAGCAAC??A?G?AAA?TC?",
"output": "GCACCACCCTGTGATACGGCATATCCGGTGAGTGATGGATAGCCGGGGGGCTCGGAGGGGATGCCAGTTCTCGGATCTGCAATAAGCCCCCTCATTGATGCTCACTTAATGTCACAACGGTAAATTCATACTCGATCACTGAGCAACTTATGTAAATTCT"
},
{
"input": "164\nGA?AGGT???T?G?A?G??TTA?TGTG?GTAGT?????T??TTTG?A?T??T?TA?G?T?GGT?????TGTGG?A?A?T?A?T?T?????TT?AAGAG?????T??TATATG?TATT??G?????GGGTATTTT?GG?A??TG??T?GAATGTG?AG?T???A?",
"output": "GAAAGGTAAATAGAAAGAATTAATGTGAGTAGTAAAAATAATTTGAACTCCTCTACGCTCGGTCCCCCTGTGGCACACTCACTCTCCCCCTTCAAGAGCCCCCTCCTATATGCTATTCCGCCCCCGGGTATTTTCGGCAGGTGGGTGGAATGTGGAGGTGGGAG"
},
{
"input": "168\n?C?CAGTCCGT?TCC?GCG?T??T?TA?GG?GCTTGTTTTGT??GC???CTGT??T?T?C?ACG?GTGG??C??TC?GT??CTT?GGT??TGGC??G?TTTCTT?G??C?CTC??CT?G?TT?CG?C?A???GCCGTGAG?CTTC???TTCTCGG?C?CC??GTGCTT",
"output": "ACACAGTCCGTATCCAGCGATAATATAAGGAGCTTGTTTTGTAAGCAAACTGTAATATACAACGAGTGGAACAATCAGTAACTTAGGTAATGGCAAGATTTCTTAGAACCCTCCCCTCGCTTCCGCCCACGGGCCGTGAGGCTTCGGGTTCTCGGGCGCCGGGTGCTT"
},
{
"input": "172\nG?ATG??G?TTT?ATA?GAAGCACTTGCT?AGC??AG??GTTCG?T?G??G?AC?TAGGGCT?TA?TTCTA?TTCAGGAA?GGAAATTGAAG?A?CT?GGTGAGTCTCT?AAACAGT??T??TCAGG?AGTG?TT?TAAT??GG?G?GCA???G?GGA?GACGAATACTCAA",
"output": "GAATGAAGATTTAATACGAAGCACTTGCTCAGCCCAGCCGTTCGCTCGCCGCACCTAGGGCTCTACTTCTACTTCAGGAACGGAAATTGAAGCACCTCGGTGAGTCTCTCAAACAGTCCTCCTCAGGCAGTGGTTGTAATGGGGTGTGCATTTGTGGATGACGAATACTCAA"
},
{
"input": "176\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "180\n?GTTACA?A?A?G??????GGGA?A??T?????C?AC??GG???G????T??CC??T?CGG?AG???GAAGG?????A?GT?G?????CTAA?A??C?A???A?T??C?A???AAA???G?GG?C?A??C???????GTCC?G??GT??G?C?G?C????TT??G????A???A???A?G",
"output": "AGTTACAAAAAAGAAAAAAGGGAAAAATAAAAACAACAAGGCCCGCCCCTCCCCCCTCCGGCAGCCCGAAGGCCCCCACGTCGCCCCCCTAACACGCGAGGGAGTGGCGAGGGAAAGGGGGGGGCGAGTCTTTTTTTGTCCTGTTGTTTGTCTGTCTTTTTTTTGTTTTATTTATTTATG"
},
{
"input": "184\n?CTC?A??????C?T?TG??AC??????G???CCT????CT?C?TT???C???AT????????????T??T?A?AGT?C?C?C?C?CG??CAT?C??C???T??T?TCCTC????C??A???CG?C???C??TC??C?G?C????CTT????C??A?AT??C????T?TCT?T???C?CT??C?",
"output": "ACTCAAAAAAAACATATGAAACAAAAAAGAAACCTAAAACTACATTAAACAAAATAAAACCCCCCCCTCCTCACAGTGCGCGCGCGCGGGCATGCGGCGGGTGGTGTCCTCGGGGCGGAGGGCGGCGGGCGGTCGGCGGGCGGGGCTTGTTTCTTATATTTCTTTTTTTCTTTTTTCTCTTTCT"
},
{
"input": "188\n????TG??A?G?GG?AGA??T??G?TA?ATTT?TTGA??TTA??T?G???GA?G?A??GG??ACTTGT?T?T?TCT?TG?TGAG??GT?A???TT?G???????TA???G?G?GTAG?G?T????????A?TT?TT?T??GGTGT??TTT?T?T?TT???GAGA??G?GGG?G??TG?GT?GT?A??T",
"output": "AAAATGAAAAGAGGAAGAAATAAGATAAATTTATTGAAATTAAATAGAAAGAAGAAAAGGACACTTGTCTCTCTCTCTGCTGAGCCGTCACCCTTCGCCCCCCCTACCCGCGCGTAGCGCTCCCCCCCCACTTCTTCTCCGGTGTCCTTTCTCTCTTGGGGAGAGGGGGGGGGGGTGGGTGGTTATTT"
},
{
"input": "192\nTT???TA?A?TTCTCA?ATCCCC?TA?T??A?A?TGT?TT??TAA?C?C?TA?CTAAAT???AA?TT???T?AATAG?AC??AC?A??A?TT?A?TT?AA?TCTTTC??A?AAA?AA??T?AG?C??AT?T?TATCT?CTTCAA?ACAAAT???AT?TT??????C?CTC???TT?ACACACTGCA?AC??T",
"output": "TTAACTACACTTCTCACATCCCCCTACTCCACACTGTCTTCCTAACCCCCTACCTAAATCCCAACTTCGGTGAATAGGACGGACGAGGAGTTGAGTTGAAGTCTTTCGGAGAAAGAAGGTGAGGCGGATGTGTATCTGCTTCAAGACAAATGGGATGTTGGGGGGCGCTCGGGTTGACACACTGCAGACTTT"
},
{
"input": "196\n??ACATCC??TGA?C?AAA?A???T????A??ACAC????T???????CCC?AAT?T?AT?A?A??TATC??CC?CCACACA?CC?A?AGC??AAA??A???A?CA??A?AT??G???CA?ACATTCG??CACAT?AC???A?A?C?CTTT?AAG??A?TAC???C?GCAA?T??C??AA???GAC?ATTAT????",
"output": "ACACATCCCCTGACCCAAACACCCTCCCCACCACACCGGGTGGGGGGGCCCGAATGTGATGAGAGGTATCGGCCGCCACACAGCCGAGAGCGGAAAGGAGGGAGCAGGAGATGGGGGGCAGACATTCGGGCACATTACTTTATATCTCTTTTAAGTTATTACTTTCTGCAATTTTCTTAATTTGACTATTATTTTT"
},
{
"input": "200\n?CT?T?C???AC?G?CAC?C?T??T?G?AGAGTA?CT????A?CCCAT?GCT?TTC?CAG???TCCATAAC?GACT?TC??C?AG?AA?A?C??ATC?CTAT?AC??????ACCGA??A????C?AA???CGCTTCGC?A????A??GCC?AG?T?????T?A?C?A?CTTC?????T?T?????GC?GTACTC??TG??",
"output": "ACTATACAAAACAGACACACATAATAGAAGAGTAACTAAAAAACCCATCGCTCTTCCCAGCCCTCCATAACCGACTCTCCCCCAGCAAGAGCGGATCGCTATGACGGGGGGACCGAGGAGGGGCGAAGGGCGCTTCGCGAGGGGAGGGCCGAGGTGGGTTTTATCTATCTTCTTTTTTTTTTTTTGCTGTACTCTTTGTT"
},
{
"input": "204\n??????T???T?GC?TC???TA?TC?????A??C?C??G??????G?CTC????A?CTTT?T???T??CTTA???????T??C??G????A?????TTTA??AT?A??C?C?T?C???C?????T???????GT????T????AT?CT????C??C??T???C????C?GCTTCCC?G?????T???C?T??????????TT??",
"output": "AAAAAATAAATAGCATCAAATAATCAAAAAAAACACAAGAAAAAAGACTCAAAAAACTTTATAAATACCTTACCCCCCCTCCCCCGCCCCACCCCCTTTACCATCACCCCCGTGCGGGCGGGGGTGGGGGGGGTGGGGTGGGGATGCTGGGGCGGCGGTGGGCGGGGCGGCTTCCCGGGTTTTTTTTCTTTTTTTTTTTTTTTT"
},
{
"input": "208\nA?GGT?G??A???????G??A?A?GA?T?G???A?AAG?AT????GG?????AT??A?A???T?A??????A????AGGCGT???A???TA????TGGT???GA????GGTG???TA??GA??TA?GGG?????G?????AT?GGGG??TG?T?AA??A??AG?AA?TGA???A?A?GG???GAAT?G?T??T?A??G?CAGT?T?A?",
"output": "AAGGTAGAAAAAAAAAAGAAAAAAGAATCGCCCACAAGCATCCCCGGCCCCCATCCACACCCTCACCCCCCACCCCAGGCGTCCCACCCTACCCCTGGTCCCGACCCCGGTGCGGTAGGGAGGTAGGGGGGGGGGGGGGTATTGGGGTTTGTTTAATTATTAGTAATTGATTTATATGGTTTGAATTGTTTTTTATTGTCAGTTTTAT"
},
{
"input": "212\nT?TTT?A??TC?????A?T??T????T????????C??T??AT????????T???TT????T?TTT??????????TTC???T?T?C??T?TA?C??TTT????T???????C????????A?TT???T??TTT??AT?T????T????T?????A??C????T??T???TA???A?????????T???C????????C???T?TA???TTT",
"output": "TATTTAAAATCAAAAAAATAATAAAATAAAAAAAACAATAAATAAAAAAAATAAATTAAAATCTTTCCCCCCCCCCTTCCCCTCTCCCCTCTACCCCTTTCCCCTCCCCCCCCCCCCCCCCACTTCCGTGGTTTGGATGTGGGGTGGGGTGGGGGAGGCGGGGTGGTGGGTAGGGAGGGGGGGGGTGGGCGGGGGGGGCTTTTTTATTTTTT"
},
{
"input": "216\n?CT?A?CC?GCC?C?AT?A???C???TA????ATGTCCG??CCG?CGG?TCC?TTC??CCT????????G?GGC?TACCCGACCGAG?C???C?G?G??C??CGTCCTG??AGG??CT?G???TC?CT????A?GTA??C?C?CTGTTAC??C?TCT?C?T???T??GTGGA?AG?CGCT?CGTC???T?C?T?C?GTT???C??GCC?T??C?T?",
"output": "ACTAAACCAGCCACAATAAAAACAAATAAAAAATGTCCGAACCGACGGATCCATTCAACCTAAAAAAAAGAGGCATACCCGACCGAGACAAACAGAGCCCCCCGTCCTGCGAGGGGCTGGGGGTCGCTGGGGAGGTAGGCGCGCTGTTACGGCGTCTGCGTGGGTTTGTGGATAGTCGCTTCGTCTTTTTCTTTCTGTTTTTCTTGCCTTTTCTTT"
},
{
"input": "220\n?GCC??????T????G?CTC???CC?C????GC??????C???TCCC???????GCC????????C?C??C?T?C?CC????CC??C???????CC??C?G?A?T???CC??C????????C????CTA?GC?????CC??C?C?????T?????G?????????G???AC????C?CG?????C?G?C?CG?????????G?C????C?G??????C??",
"output": "AGCCAAAAAATAAAAGACTCAAACCACAAAAGCAAAAAACAAATCCCAAAAAAAGCCAAAAAAAACACAACATACACCAACCCCCCCCCCCCCGCCGGCGGGAGTGGGCCGGCGGGGGGGGCGGGGCTAGGCGGGGGCCGGCGCGGGGGTGGGGGGTTTTTTTTTGTTTACTTTTCTCGTTTTTCTGTCTCGTTTTTTTTTGTCTTTTCTGTTTTTTCTT"
},
{
"input": "224\nTTGC?G??A?ATCA??CA???T?TG?C?CGA?CTTA?C??C?TTC?AC?CTCA?A?AT?C?T?CT?CATGT???A??T?CT????C?AACT?TTCCC??C?AAC???AC?TTTC?TTAAA??????TGT????CGCT????GCCC?GCCCA?????TCGA??C?TATACA??C?CC?CATAC?GGACG??GC??GTT?TT?T???GCT??T?C?T?C??T?CC?",
"output": "TTGCAGAAAAATCAAACAAAATATGACACGAACTTAACAACATTCAACACTCAAAAATACATACTACATGTAAAACCTCCTCCCCCCAACTGTTCCCGGCGAACGGGACGTTTCGTTAAAGGGGGGTGTGGGGCGCTGGGGGCCCGGCCCAGGGGGTCGAGGCGTATACAGGCGCCGCATACGGGACGGGGCGTGTTTTTTTTTTGCTTTTTCTTTCTTTTCCT"
},
{
"input": "228\nA??A?C???AG?C?AC???A?T?????AA??????C?A??A?AC?????C?C???A??????A???AC?C????T?C?AA?C??A???CC??????????????????A???CC????A?????C??TC???A???????????A??A????????????????CC?????CCA??????????????C??????C????T?CT???C???A???T?CC?G??C??A?",
"output": "AAAAACAAAAGACAACAAAAATAAAAAAAAAAAAACAAAAAAACAAAAACACCCCACCCCCCACCCACCCCCCCTCCCAACCCCACCCCCCCCCGGGGGGGGGGGGGGAGGGCCGGGGAGGGGGCGGTCGGGAGGGGGGGGGGGAGGAGGGGGGGGGGGTTTTTCCTTTTTCCATTTTTTTTTTTTTTCTTTTTTCTTTTTTCTTTTCTTTATTTTTCCTGTTCTTAT"
},
{
"input": "232\nA??AAGC?GCG?AG???GGGCG?C?A?GCAAC?AG?C?GC??CA??A??CC?AA?A????G?AGA?ACACA?C?G?G?G?CGC??G???????GAGC?CAA??????G?A???AGGG?????AAC?AG?A?A??AG?CG?G???G????GGGA?C?G?A?A??GC????C??A?ACG?AA?G?ACG????AC?C?GA??GGCAG?GAA??ACA??A?AGGAGG???CGGA?C",
"output": "AAAAAGCAGCGAAGAAAGGGCGACAAAGCAACCAGCCCGCCCCACCACCCCCAACACCCCGCAGACACACACCCGCGCGCCGCCCGCCCGGGGGAGCGCAAGGGGGTGTATTTAGGGTTTTTAACTAGTATATTAGTCGTGTTTGTTTTGGGATCTGTATATTGCTTTTCTTATACGTAATGTACGTTTTACTCTGATTGGCAGTGAATTACATTATAGGAGGTTTCGGATC"
},
{
"input": "236\nAAGCCC?A?TT??C?AATGC?A?GC?GACGT?CTT?TA??CCG?T?CAA?AGT?CTG???GCGATG?TG?A?A?ACT?AT?GGG?GC?C?CGCCCTT?GT??G?T?????GACTT??????CT?GA?GG?C?T?G??CTG??G??TG?TCA?TCGTT?GC?A?G?GGGT?CG?CGAG??CG?TC?TAT?A???T??GAGTC?CGGC?CG??CT?TAAT??GGAA?G??GG?GCGAC",
"output": "AAGCCCAAATTAACAAATGCAAAGCAGACGTACTTATAAACCGATACAAAAGTACTGAAAGCGATGATGAAAAAACTAATAGGGAGCACACGCCCTTAGTACGCTCCCCCGACTTCCCCCCCTCGACGGCCCTCGCCCTGCGGGGTGGTCAGTCGTTGGCGAGGGGGGTGCGTCGAGTTCGTTCTTATTATTTTTTGAGTCTCGGCTCGTTCTTTAATTTGGAATGTTGGTGCGAC"
},
{
"input": "240\n?T?A?A??G????G????AGGAGTAA?AGGCT??C????AT?GAA?ATGCT???GA?G?A??G?TC??TATT???AG?G?G?A?A??TTGT??GGTCAG?GA?G?AAT?G?GG??CAG?T?GT?G?GC???GC??????GA?A?AAATGGGC??G??????TTA??GTCG?TC?GCCG?GGGA??T?A????T?G?T???G?GG?ATG???A?ATGAC?GGT?CTG?AGGG??TAGT?AG",
"output": "ATAAAAAAGAAAAGAAAAAGGAGTAAAAGGCTAACAAAAATAGAAAATGCTACCGACGCACCGCTCCCTATTCCCAGCGCGCACACCTTGTCCGGTCAGCGACGCAATCGCGGCCCAGCTCGTCGCGCCCCGCCCCCCCGACACAAATGGGCCCGCGGGGGTTATTGTCGTTCTGCCGTGGGATTTTATTTTTTGTTTTTGTGGTATGTTTATATGACTGGTTCTGTAGGGTTTAGTTAG"
},
{
"input": "244\nC?GT???T??TA?CC??TACT???TC?C?A???G??G?TCC?AC??AA???C?CCACC????A?AGCC??T?CT??CCGG?CC?T?C??GCCCTGGCCAAAC???GC?C???AT?CC?CT?TAG??CG?C?T?C??A?AC?GC????A??C?C?A??TC?T????GCCCT??GG???CC?A?CC?G?A?CA?G??CCCG??CG?T?TAC?G???C?AC??G??CCA???G????C??G?CT?C?",
"output": "CAGTAAATAATAACCAATACTAAATCACAAAAAGAAGATCCAACAAAAAAACACCACCAAAAAAAGCCAATACTAACCGGGCCGTGCGGGCCCTGGCCAAACGGGGCGCGGGATGCCGCTGTAGGGCGGCGTGCGGAGACGGCGGGGAGGCGCGAGGTCGTGGTTGCCCTTTGGTTTCCTATCCTGTATCATGTTCCCGTTCGTTTTACTGTTTCTACTTGTTCCATTTGTTTTCTTGTCTTCT"
},
{
"input": "248\n??TC???TG??G??T????CC???C?G?????G?????GT?A?CT?AAT?GG?AGA?????????G???????G???CG??AA?A????T???????TG?CA????C?TT?G?GC???AA?G????G????T??G??A??????TT???G???CG?????A??A??T?GA??G??T?CC?TA??GCTG?A????G?CG??GGTG??CA???????TA??G?????????A???????GC?GG????GC",
"output": "AATCAAATGAAGAATAAAACCAAACAGAAAAAGAAAAAGTAAACTAAATAGGAAGAAAAAAAAAAGACCCCCCGCCCCGCCAACACCCCTCCCCCCCTGCCACCCCCCTTCGCGCCCCAACGCCCCGCCCCTCCGGGAGGGGGGTTGGGGGGGCGGGGGGAGGAGGTGGAGGGGGTGCCTTATTGCTGTATTTTGTCGTTGGTGTTCATTTTTTTTATTGTTTTTTTTTATTTTTTTGCTGGTTTTGC"
},
{
"input": "8\n???AAA??",
"output": "==="
},
{
"input": "12\nC??CC??????C",
"output": "==="
},
{
"input": "4\nG??G",
"output": "==="
},
{
"input": "4\nTT??",
"output": "==="
},
{
"input": "4\nACAC",
"output": "==="
},
{
"input": "8\nACGT???T",
"output": "ACGTACGT"
},
{
"input": "252\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "252\n??????????????????????????????????????????????????????????????????????????????A?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????C????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????G",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTG"
},
{
"input": "252\nT???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "TAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "4\nAA?T",
"output": "==="
},
{
"input": "4\nAAAA",
"output": "==="
},
{
"input": "8\nAAA?????",
"output": "==="
},
{
"input": "10\nACGT??????",
"output": "==="
},
{
"input": "6\nACGACG",
"output": "==="
},
{
"input": "5\nAAAAA",
"output": "==="
},
{
"input": "8\nGGGGAA??",
"output": "==="
},
{
"input": "5\nATGCA",
"output": "==="
},
{
"input": "4\nTTTT",
"output": "==="
},
{
"input": "4\nACCG",
"output": "==="
},
{
"input": "8\nACGTA?GT",
"output": "ACGTACGT"
}
] | 1,687,625,853 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 46 | 0 | def solve(s):
TYPES = ['A', 'C', 'G', 'T']
letterToCount = {}
for ch in s:
if ch != '?':
letterToCount[ch] = letterToCount.get(ch, 0) + 1
if len(s) % 4 != 0 or any(count * 4 > len(s) for count in letterToCount.values()):
return "==="
result = []
for ch in s:
if ch == '?':
for typ in TYPES:
if letterToCount.get(typ, 0) * 4 != len(s):
result.append(typ)
letterToCount[typ] = letterToCount.get(typ, 0) + 1
break
else:
result.append(ch)
return ''.join(result)
_ = int(input())
s = input()
print(solve(s)) | Title: Mammoth's Genome Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'.
It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.
Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.
Input Specification:
The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
Output Specification:
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
Demo Input:
['8\nAG?C??CT\n', '4\nAGCT\n', '6\n????G?\n', '4\nAA??\n']
Demo Output:
['AGACGTCT\n', 'AGCT\n', '===\n', '===\n']
Note:
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.
In the third and the fourth examples it is impossible to decode the genom. | ```python
def solve(s):
TYPES = ['A', 'C', 'G', 'T']
letterToCount = {}
for ch in s:
if ch != '?':
letterToCount[ch] = letterToCount.get(ch, 0) + 1
if len(s) % 4 != 0 or any(count * 4 > len(s) for count in letterToCount.values()):
return "==="
result = []
for ch in s:
if ch == '?':
for typ in TYPES:
if letterToCount.get(typ, 0) * 4 != len(s):
result.append(typ)
letterToCount[typ] = letterToCount.get(typ, 0) + 1
break
else:
result.append(ch)
return ''.join(result)
_ = int(input())
s = input()
print(solve(s))
``` | 3 |
|
81 | A | Plug-in | PROGRAMMING | 1,400 | [
"implementation"
] | A. Plug-in | 1 | 256 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu".
Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something!
Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result. | The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | [
"hhoowaaaareyyoouu\n",
"reallazy\n",
"abacabaabacabaa\n"
] | [
"wre",
"rezy",
"a"
] | none | 500 | [
{
"input": "hhoowaaaareyyoouu",
"output": "wre"
},
{
"input": "reallazy",
"output": "rezy"
},
{
"input": "abacabaabacabaa",
"output": "a"
},
{
"input": "xraccabccbry",
"output": "xy"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"
},
{
"input": "il",
"output": "il"
},
{
"input": "gfj",
"output": "gfj"
},
{
"input": "babbbbbababa",
"output": "babababa"
},
{
"input": "babbbbabbabbbababbabbbbbbabaabaababaaabbbbbabbbbaaaaabbaaabbaabaabbbbabbbababbabaaabbababaaababbbaaa",
"output": "babababababababababababa"
},
{
"input": "aab",
"output": "b"
},
{
"input": "abb",
"output": "a"
},
{
"input": "aba",
"output": "aba"
},
{
"input": "ab",
"output": "ab"
}
] | 1,666,046,448 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 |
# a
def test(string): # ybocyboybocyboa
for idx, i in enumerate(string): # abacabaabacabaa
for j in range(idx + 1, len(string)):
if string[idx] == string[j]:
string = string.replace(string[idx], '',1)
string = string.replace(string[idx], '',1)
return test(string)
break
return string
print(test("abacabaabacabaa")) | Title: Plug-in
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu".
Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something!
Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.
Input Specification:
The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters.
Output Specification:
Print the given string after it is processed. It is guaranteed that the result will contain at least one character.
Demo Input:
['hhoowaaaareyyoouu\n', 'reallazy\n', 'abacabaabacabaa\n']
Demo Output:
['wre', 'rezy', 'a']
Note:
none | ```python
# a
def test(string): # ybocyboybocyboa
for idx, i in enumerate(string): # abacabaabacabaa
for j in range(idx + 1, len(string)):
if string[idx] == string[j]:
string = string.replace(string[idx], '',1)
string = string.replace(string[idx], '',1)
return test(string)
break
return string
print(test("abacabaabacabaa"))
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | Farmer John has just given the cows a program to play with! The program contains two integer variables, *x* and *y*, and performs the following operations on a sequence *a*1,<=*a*2,<=...,<=*a**n* of positive integers:
1. Initially, *x*<==<=1 and *y*<==<=0. If, after any step, *x*<=≤<=0 or *x*<=><=*n*, the program immediately terminates. 1. The program increases both *x* and *y* by a value equal to *a**x* simultaneously. 1. The program now increases *y* by *a**x* while decreasing *x* by *a**x*. 1. The program executes steps 2 and 3 (first step 2, then step 3) repeatedly until it terminates (it may never terminate). So, the sequence of executed steps may start with: step 2, step 3, step 2, step 3, step 2 and so on.
The cows are not very good at arithmetic though, and they want to see how the program works. Please help them!
You are given the sequence *a*2,<=*a*3,<=...,<=*a**n*. Suppose for each *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) we run the program on the sequence *i*,<=*a*2,<=*a*3,<=...,<=*a**n*. For each such run output the final value of *y* if the program terminates or -1 if it does not terminate. | The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=2·105). The next line contains *n*<=-<=1 space separated integers, *a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Output *n*<=-<=1 lines. On the *i*-th line, print the requested value when the program is run on the sequence *i*,<=*a*2,<=*a*3,<=...*a**n*.
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. | [
"4\n2 4 1\n",
"3\n1 2\n"
] | [
"3\n6\n8\n",
"-1\n-1\n"
] | In the first sample
1. For *i* = 1, *x* becomes <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d87035805e6f1c669693d86603da6d89c5730833.png" style="max-width: 100.0%;max-height: 100.0%;"/> and *y* becomes 1 + 2 = 3. 1. For *i* = 2, *x* becomes <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c59515a288e6cb9876590f520c031cb27e346525.png" style="max-width: 100.0%;max-height: 100.0%;"/> and *y* becomes 2 + 4 = 6. 1. For *i* = 3, *x* becomes <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/62b52a6cff2221e154a9c36f7bb277ad6475a1b6.png" style="max-width: 100.0%;max-height: 100.0%;"/> and *y* becomes 3 + 1 + 4 = 8. | 0 | [] | 1,630,424,891 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 1,216 | 26,214,400 | import math
import time
dp=[[float('inf') for i in range(2)] for j in range(200001)]
arr=[0]*(200001)
def ans(i,val,n,step):
if i>=n or i<0:
return val
if dp[i][step]!=float('inf'):
return val+dp[i][step]
dp[i][step]=-float('inf')
new_idx=i-arr[i] if step else i+arr[i]
val+=arr[i]
val=ans(new_idx,val,n,step^1)
dp[i][step]=val
return val
def main():
n=int(input())
a=list(map(int,input().split()))
for i in range(1,n):
arr[i]=a[i-1]
for i in range(len(dp)):
for j in range(len(dp[0])):
dp[i][j]=float('inf')
dp[0][0]=-float('inf')
r=[]
for i in range(1,n):
arr[0]=i
ans(i,i,n,1)
if dp[i][1]!=-float('inf'):
r.append(dp[i][1])
else:
r.append(-1)
return r
r=main()
for e in r:
print(e)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Farmer John has just given the cows a program to play with! The program contains two integer variables, *x* and *y*, and performs the following operations on a sequence *a*1,<=*a*2,<=...,<=*a**n* of positive integers:
1. Initially, *x*<==<=1 and *y*<==<=0. If, after any step, *x*<=≤<=0 or *x*<=><=*n*, the program immediately terminates. 1. The program increases both *x* and *y* by a value equal to *a**x* simultaneously. 1. The program now increases *y* by *a**x* while decreasing *x* by *a**x*. 1. The program executes steps 2 and 3 (first step 2, then step 3) repeatedly until it terminates (it may never terminate). So, the sequence of executed steps may start with: step 2, step 3, step 2, step 3, step 2 and so on.
The cows are not very good at arithmetic though, and they want to see how the program works. Please help them!
You are given the sequence *a*2,<=*a*3,<=...,<=*a**n*. Suppose for each *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) we run the program on the sequence *i*,<=*a*2,<=*a*3,<=...,<=*a**n*. For each such run output the final value of *y* if the program terminates or -1 if it does not terminate.
Input Specification:
The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=2·105). The next line contains *n*<=-<=1 space separated integers, *a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Output *n*<=-<=1 lines. On the *i*-th line, print the requested value when the program is run on the sequence *i*,<=*a*2,<=*a*3,<=...*a**n*.
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.
Demo Input:
['4\n2 4 1\n', '3\n1 2\n']
Demo Output:
['3\n6\n8\n', '-1\n-1\n']
Note:
In the first sample
1. For *i* = 1, *x* becomes <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d87035805e6f1c669693d86603da6d89c5730833.png" style="max-width: 100.0%;max-height: 100.0%;"/> and *y* becomes 1 + 2 = 3. 1. For *i* = 2, *x* becomes <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c59515a288e6cb9876590f520c031cb27e346525.png" style="max-width: 100.0%;max-height: 100.0%;"/> and *y* becomes 2 + 4 = 6. 1. For *i* = 3, *x* becomes <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/62b52a6cff2221e154a9c36f7bb277ad6475a1b6.png" style="max-width: 100.0%;max-height: 100.0%;"/> and *y* becomes 3 + 1 + 4 = 8. | ```python
import math
import time
dp=[[float('inf') for i in range(2)] for j in range(200001)]
arr=[0]*(200001)
def ans(i,val,n,step):
if i>=n or i<0:
return val
if dp[i][step]!=float('inf'):
return val+dp[i][step]
dp[i][step]=-float('inf')
new_idx=i-arr[i] if step else i+arr[i]
val+=arr[i]
val=ans(new_idx,val,n,step^1)
dp[i][step]=val
return val
def main():
n=int(input())
a=list(map(int,input().split()))
for i in range(1,n):
arr[i]=a[i-1]
for i in range(len(dp)):
for j in range(len(dp[0])):
dp[i][j]=float('inf')
dp[0][0]=-float('inf')
r=[]
for i in range(1,n):
arr[0]=i
ans(i,i,n,1)
if dp[i][1]!=-float('inf'):
r.append(dp[i][1])
else:
r.append(-1)
return r
r=main()
for e in r:
print(e)
``` | 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,699,879,425 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n=int(input())
k=0
for i in range(n):
a,b,c=map(int,input().split())
if(a==1 and (b==1 or c==1)) or ( b==1 and( c==1 or a==1)) or (c==1 or(a==1 or b==1)):
k+=1
print(k)
| 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
n=int(input())
k=0
for i in range(n):
a,b,c=map(int,input().split())
if(a==1 and (b==1 or c==1)) or ( b==1 and( c==1 or a==1)) or (c==1 or(a==1 or b==1)):
k+=1
print(k)
``` | 0 |
|
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?
Please help Haruhi solve this problem. | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"input": "xulsyfkuizjauadjjopu",
"output": "526"
},
{
"input": "e",
"output": "51"
},
{
"input": "zv",
"output": "76"
},
{
"input": "jgv",
"output": "101"
},
{
"input": "zsfo",
"output": "126"
},
{
"input": "jselr",
"output": "151"
},
{
"input": "dwemig",
"output": "176"
},
{
"input": "mddoxsf",
"output": "201"
},
{
"input": "jgirkrmi",
"output": "226"
},
{
"input": "spkxurcum",
"output": "251"
},
{
"input": "fykkiubdkt",
"output": "276"
},
{
"input": "fznbcxsxygs",
"output": "301"
},
{
"input": "qcrvrdqcbtou",
"output": "326"
},
{
"input": "qktrbjzrqgmlr",
"output": "351"
},
{
"input": "foamodbvptlxxg",
"output": "376"
},
{
"input": "ydzpjhsidipricw",
"output": "401"
},
{
"input": "lpfpndmjfvqejdgf",
"output": "426"
},
{
"input": "ofkvparuvjtggnmab",
"output": "451"
},
{
"input": "xxncfutrtxcwdzwbgs",
"output": "476"
},
{
"input": "zovhffccflkgqncsdte",
"output": "501"
},
{
"input": "cskgsxywlvfeicoueglr",
"output": "526"
},
{
"input": "gggggggggggggggggggg",
"output": "526"
},
{
"input": "qdqdddqddqqddqddqdqd",
"output": "526"
},
{
"input": "takttttaakaaktakttkt",
"output": "526"
},
{
"input": "coccoooogogcgocccmcg",
"output": "526"
},
{
"input": "kskkskkkssksssk",
"output": "401"
},
{
"input": "lllllllllllllll",
"output": "401"
}
] | 1,446,474,622 | 622 | Python 3 | OK | TESTS | 33 | 62 | 0 |
a = input()
print((len(a)+1) * 25 + 1)
| Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?
Please help Haruhi solve this problem.
Input Specification:
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters.
Output Specification:
Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.
Demo Input:
['a\n', 'hi\n']
Demo Output:
['51\n', '76\n']
Note:
In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | ```python
a = input()
print((len(a)+1) * 25 + 1)
``` | 3 |
|
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob? | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then. | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "1 5",
"output": "4"
},
{
"input": "1 6",
"output": "5"
},
{
"input": "1 7",
"output": "5"
},
{
"input": "1 8",
"output": "6"
},
{
"input": "1 9",
"output": "6"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "2 4",
"output": "2"
},
{
"input": "2 5",
"output": "3"
},
{
"input": "2 6",
"output": "3"
},
{
"input": "2 7",
"output": "4"
},
{
"input": "2 8",
"output": "4"
},
{
"input": "2 9",
"output": "4"
},
{
"input": "2 10",
"output": "4"
},
{
"input": "3 3",
"output": "1"
},
{
"input": "3 4",
"output": "1"
},
{
"input": "3 5",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "3 7",
"output": "3"
},
{
"input": "3 8",
"output": "3"
},
{
"input": "3 9",
"output": "3"
},
{
"input": "3 10",
"output": "3"
},
{
"input": "4 4",
"output": "1"
},
{
"input": "4 5",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "4 7",
"output": "2"
},
{
"input": "4 8",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "4 10",
"output": "3"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "5 6",
"output": "1"
},
{
"input": "5 7",
"output": "1"
},
{
"input": "5 8",
"output": "2"
},
{
"input": "5 9",
"output": "2"
},
{
"input": "5 10",
"output": "2"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "6 7",
"output": "1"
},
{
"input": "6 8",
"output": "1"
},
{
"input": "6 9",
"output": "2"
},
{
"input": "6 10",
"output": "2"
},
{
"input": "7 7",
"output": "1"
},
{
"input": "7 8",
"output": "1"
},
{
"input": "7 9",
"output": "1"
},
{
"input": "7 10",
"output": "1"
},
{
"input": "8 8",
"output": "1"
},
{
"input": "8 9",
"output": "1"
},
{
"input": "8 10",
"output": "1"
},
{
"input": "9 9",
"output": "1"
},
{
"input": "9 10",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "1 2",
"output": "2"
}
] | 1,693,688,298 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 2,764,800 | st=int(input())
sec=int(input())
i=0
while(st<=sec):
st *=3
sec *=2
i+=1
print(i) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob?
Input Specification:
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Output Specification:
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
Demo Input:
['4 7\n', '4 9\n', '1 1\n']
Demo Output:
['2\n', '3\n', '1\n']
Note:
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then. | ```python
st=int(input())
sec=int(input())
i=0
while(st<=sec):
st *=3
sec *=2
i+=1
print(i)
``` | -1 |
|
907 | A | Masha and Bears | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 500 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"input": "100 99 98 100",
"output": "-1"
},
{
"input": "100 40 30 40",
"output": "-1"
},
{
"input": "100 50 19 25",
"output": "100\n51\n25"
},
{
"input": "100 50 19 30",
"output": "100\n61\n30"
},
{
"input": "49 48 25 49",
"output": "-1"
},
{
"input": "48 47 23 46",
"output": "94\n93\n46"
},
{
"input": "37 23 16 20",
"output": "42\n41\n20"
},
{
"input": "98 2 1 1",
"output": "98\n3\n1"
},
{
"input": "99 22 13 14",
"output": "99\n29\n14"
},
{
"input": "97 95 3 2",
"output": "97\n95\n3"
},
{
"input": "27 3 2 3",
"output": "-1"
},
{
"input": "13 7 6 2",
"output": "-1"
},
{
"input": "19 17 11 6",
"output": "19\n17\n11"
},
{
"input": "15 6 4 5",
"output": "15\n11\n5"
},
{
"input": "21 3 1 3",
"output": "-1"
},
{
"input": "100 99 98 97",
"output": "196\n195\n98"
},
{
"input": "99 32 13 5",
"output": "-1"
},
{
"input": "5 4 3 1",
"output": "-1"
},
{
"input": "50 20 4 8",
"output": "50\n20\n8"
},
{
"input": "60 30 10 1",
"output": "-1"
},
{
"input": "100 50 10 1",
"output": "-1"
},
{
"input": "40 30 20 10",
"output": "40\n30\n20"
},
{
"input": "50 49 5 10",
"output": "50\n49\n10"
},
{
"input": "99 98 50 97",
"output": "196\n195\n97"
},
{
"input": "50 30 10 5",
"output": "50\n30\n10"
},
{
"input": "4 3 2 1",
"output": "4\n3\n2"
},
{
"input": "100 50 3 1",
"output": "-1"
}
] | 1,514,038,315 | 415 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 31 | 5,529,600 | a,b,c,d = map(int , input().split())
if 2*c>=d:
print(a)
print(b)
print(d)
else:
print(-1)
| Title: Masha and Bears
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input Specification:
You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3.
Output Specification:
Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Demo Input:
['50 30 10 10\n', '100 50 10 21\n']
Demo Output:
['50\n30\n10\n', '-1\n']
Note:
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | ```python
a,b,c,d = map(int , input().split())
if 2*c>=d:
print(a)
print(b)
print(d)
else:
print(-1)
``` | 0 |
|
93 | A | Frames | PROGRAMMING | 1,700 | [
"implementation"
] | A. Frames | 2 | 256 | Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well.
This time Igor K. got disappointed in one of his hobbies: editing and voicing videos. Moreover, he got disappointed in it so much, that he decided to destroy his secret archive for good.
Igor K. use Pindows XR operation system which represents files and folders by small icons. At that, *m* icons can fit in a horizontal row in any window.
Igor K.'s computer contains *n* folders in the D: disk's root catalog. The folders are numbered from 1 to *n* in the order from the left to the right and from top to bottom (see the images). At that the folders with secret videos have numbers from *a* to *b* inclusive. Igor K. wants to delete them forever, at that making as few frame selections as possible, and then pressing Shift+Delete exactly once. What is the minimum number of times Igor K. will have to select the folder in order to select folders from *a* to *b* and only them? Let us note that if some selected folder is selected repeatedly, then it is deselected. Each selection possesses the shape of some rectangle with sides parallel to the screen's borders. | The only line contains four integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*<=≤<=109, 1<=≤<=*a*<=≤<=*b*<=≤<=*n*). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted. | Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from *a* to *b*. | [
"11 4 3 9\n",
"20 5 2 20\n"
] | [
"3\n",
"2\n"
] | The images below illustrate statement tests.
The first test:
<img class="tex-graphics" src="https://espresso.codeforces.com/a0e4ba690dd16e3c68210a28afd82020b23fb605.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In this test we can select folders 3 and 4 with out first selection, folders 5, 6, 7, 8 with our second selection and folder 9 with our third, last selection.
The second test:
<img class="tex-graphics" src="https://espresso.codeforces.com/289e2666a3d8b3dfe5b22ff3d88976df711640f7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In this test we can first select all folders in the first row (2, 3, 4, 5), then — all other ones. | 500 | [
{
"input": "11 4 3 9",
"output": "3"
},
{
"input": "20 5 2 20",
"output": "2"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "26 5 2 18",
"output": "3"
},
{
"input": "21 5 1 15",
"output": "1"
},
{
"input": "21 5 1 21",
"output": "1"
},
{
"input": "21 5 8 14",
"output": "2"
},
{
"input": "20 4 1 20",
"output": "1"
},
{
"input": "21 5 1 13",
"output": "2"
},
{
"input": "21 5 4 15",
"output": "2"
},
{
"input": "17 3 1 16",
"output": "2"
},
{
"input": "19 5 7 19",
"output": "2"
},
{
"input": "18 2 1 13",
"output": "2"
},
{
"input": "21 3 6 11",
"output": "2"
},
{
"input": "21 5 3 12",
"output": "2"
},
{
"input": "21 3 6 10",
"output": "3"
},
{
"input": "28 5 4 26",
"output": "3"
},
{
"input": "21 5 6 18",
"output": "2"
},
{
"input": "21 5 4 21",
"output": "2"
},
{
"input": "17 5 6 17",
"output": "1"
},
{
"input": "21 5 9 12",
"output": "2"
},
{
"input": "21 3 6 7",
"output": "2"
},
{
"input": "21 5 7 9",
"output": "1"
},
{
"input": "12 4 5 8",
"output": "1"
},
{
"input": "21 3 6 8",
"output": "2"
},
{
"input": "21 1 5 17",
"output": "1"
},
{
"input": "5 5 2 4",
"output": "1"
},
{
"input": "18 4 6 17",
"output": "2"
},
{
"input": "18 4 6 18",
"output": "2"
},
{
"input": "16 4 1 16",
"output": "1"
},
{
"input": "20 4 7 14",
"output": "2"
},
{
"input": "17 3 12 16",
"output": "3"
},
{
"input": "12 4 8 9",
"output": "2"
},
{
"input": "11 8 2 7",
"output": "1"
},
{
"input": "27 5 4 24",
"output": "3"
},
{
"input": "29 5 12 27",
"output": "3"
},
{
"input": "30 5 5 29",
"output": "2"
},
{
"input": "91 2 15 72",
"output": "1"
},
{
"input": "41 1 8 27",
"output": "1"
},
{
"input": "26 5 7 21",
"output": "2"
},
{
"input": "70 5 31 33",
"output": "1"
},
{
"input": "84 9 6 80",
"output": "3"
},
{
"input": "79 8 41 64",
"output": "1"
},
{
"input": "63 11 23 48",
"output": "2"
},
{
"input": "97 9 18 54",
"output": "2"
},
{
"input": "75 18 20 23",
"output": "1"
},
{
"input": "66 42 43 44",
"output": "1"
},
{
"input": "92 54 20 53",
"output": "1"
},
{
"input": "32 90 31 32",
"output": "1"
},
{
"input": "18 100 6 6",
"output": "1"
},
{
"input": "458 12 203 310",
"output": "2"
},
{
"input": "149 49 92 129",
"output": "2"
},
{
"input": "264 2 9 63",
"output": "2"
},
{
"input": "908 6 407 531",
"output": "3"
},
{
"input": "410 36 109 191",
"output": "2"
},
{
"input": "301 38 97 171",
"output": "3"
},
{
"input": "691 27 313 499",
"output": "3"
},
{
"input": "939 42 86 827",
"output": "3"
},
{
"input": "280 32 64 277",
"output": "3"
},
{
"input": "244 25 94 199",
"output": "3"
},
{
"input": "134 110 11 52",
"output": "1"
},
{
"input": "886 251 61 672",
"output": "3"
},
{
"input": "261 686 243 254",
"output": "1"
},
{
"input": "162 309 68 98",
"output": "1"
},
{
"input": "476 398 77 256",
"output": "1"
},
{
"input": "258 224 84 174",
"output": "1"
},
{
"input": "357 182 73 247",
"output": "2"
},
{
"input": "488 655 290 457",
"output": "1"
},
{
"input": "149 334 78 105",
"output": "1"
},
{
"input": "488 519 203 211",
"output": "1"
},
{
"input": "192293793 2864 5278163 190776899",
"output": "3"
},
{
"input": "38644205 2729 9325777 31658388",
"output": "3"
},
{
"input": "268836959 6117 166683294 249843000",
"output": "3"
},
{
"input": "831447817 8377 549549158 577671489",
"output": "3"
},
{
"input": "444819690 3519 48280371 117052060",
"output": "3"
},
{
"input": "729584406 8367 456501516 557088265",
"output": "3"
},
{
"input": "629207296 3735 112288653 309364482",
"output": "3"
},
{
"input": "775589210 6930 266348458 604992807",
"output": "3"
},
{
"input": "249414894 1999 34827655 127026562",
"output": "3"
},
{
"input": "566377385 227 424126063 478693454",
"output": "3"
},
{
"input": "960442940 572344654 77422042 406189391",
"output": "1"
},
{
"input": "291071313 592207814 6792338 181083636",
"output": "1"
},
{
"input": "191971162 306112722 18212391 188328807",
"output": "1"
},
{
"input": "609162932 300548167 21640850 411089609",
"output": "2"
},
{
"input": "645010014 34698301 217620581 416292490",
"output": "3"
},
{
"input": "51474721 867363452 12231088 43489285",
"output": "1"
},
{
"input": "484381636 927869638 57278216 175514226",
"output": "1"
},
{
"input": "491259590 529594367 305425951 326414536",
"output": "1"
},
{
"input": "733405771 830380469 19971607 389270995",
"output": "1"
},
{
"input": "446237720 920085248 296916273 439113596",
"output": "1"
},
{
"input": "12 6 3 10",
"output": "2"
},
{
"input": "25 2 8 11",
"output": "2"
},
{
"input": "17 8 3 15",
"output": "2"
},
{
"input": "9 2 4 7",
"output": "2"
},
{
"input": "6 7 5 6",
"output": "1"
},
{
"input": "13 2 1 6",
"output": "1"
},
{
"input": "15 8 10 14",
"output": "1"
},
{
"input": "27 2 5 13",
"output": "2"
},
{
"input": "14 8 2 12",
"output": "2"
},
{
"input": "61 1 10 38",
"output": "1"
},
{
"input": "15 6 7 15",
"output": "1"
},
{
"input": "100 1 2 15",
"output": "1"
},
{
"input": "10 1 4 5",
"output": "1"
},
{
"input": "6 3 1 6",
"output": "1"
},
{
"input": "4 3 3 4",
"output": "2"
},
{
"input": "5 2 1 5",
"output": "1"
},
{
"input": "7 3 1 1",
"output": "1"
},
{
"input": "7 3 1 2",
"output": "1"
},
{
"input": "7 3 1 3",
"output": "1"
},
{
"input": "7 3 1 4",
"output": "2"
},
{
"input": "7 3 1 5",
"output": "2"
},
{
"input": "7 3 1 6",
"output": "1"
},
{
"input": "7 3 1 7",
"output": "1"
},
{
"input": "7 3 2 2",
"output": "1"
},
{
"input": "7 3 2 3",
"output": "1"
},
{
"input": "7 3 2 4",
"output": "2"
},
{
"input": "7 3 2 5",
"output": "2"
},
{
"input": "7 3 2 6",
"output": "2"
},
{
"input": "7 3 2 7",
"output": "2"
},
{
"input": "7 3 3 3",
"output": "1"
},
{
"input": "7 3 3 4",
"output": "2"
},
{
"input": "7 3 3 5",
"output": "2"
},
{
"input": "7 3 3 6",
"output": "2"
},
{
"input": "7 3 3 7",
"output": "2"
},
{
"input": "7 3 4 4",
"output": "1"
},
{
"input": "7 3 4 5",
"output": "1"
},
{
"input": "7 3 4 6",
"output": "1"
},
{
"input": "7 3 4 7",
"output": "1"
},
{
"input": "7 3 5 5",
"output": "1"
},
{
"input": "7 3 5 6",
"output": "1"
},
{
"input": "7 3 5 7",
"output": "2"
},
{
"input": "7 3 6 6",
"output": "1"
},
{
"input": "7 3 6 7",
"output": "2"
},
{
"input": "7 3 7 7",
"output": "1"
},
{
"input": "8 3 1 1",
"output": "1"
},
{
"input": "8 3 1 2",
"output": "1"
},
{
"input": "8 3 1 3",
"output": "1"
},
{
"input": "8 3 1 4",
"output": "2"
},
{
"input": "8 3 1 5",
"output": "2"
},
{
"input": "8 3 1 6",
"output": "1"
},
{
"input": "8 3 1 7",
"output": "2"
},
{
"input": "8 3 1 8",
"output": "1"
},
{
"input": "8 3 2 2",
"output": "1"
},
{
"input": "8 3 2 3",
"output": "1"
},
{
"input": "8 3 2 4",
"output": "2"
},
{
"input": "8 3 2 5",
"output": "2"
},
{
"input": "8 3 2 6",
"output": "2"
},
{
"input": "8 3 2 7",
"output": "2"
},
{
"input": "8 3 2 8",
"output": "2"
},
{
"input": "8 3 3 3",
"output": "1"
},
{
"input": "8 3 3 4",
"output": "2"
},
{
"input": "8 3 3 5",
"output": "2"
},
{
"input": "8 3 3 6",
"output": "2"
},
{
"input": "8 3 3 7",
"output": "3"
},
{
"input": "8 3 3 8",
"output": "2"
},
{
"input": "8 3 4 4",
"output": "1"
},
{
"input": "8 3 4 5",
"output": "1"
},
{
"input": "8 3 4 6",
"output": "1"
},
{
"input": "8 3 4 7",
"output": "2"
},
{
"input": "8 3 4 8",
"output": "1"
},
{
"input": "8 3 5 5",
"output": "1"
},
{
"input": "8 3 5 6",
"output": "1"
},
{
"input": "8 3 5 7",
"output": "2"
},
{
"input": "8 3 5 8",
"output": "2"
},
{
"input": "8 3 6 6",
"output": "1"
},
{
"input": "8 3 6 7",
"output": "2"
},
{
"input": "8 3 6 8",
"output": "2"
},
{
"input": "8 3 7 7",
"output": "1"
},
{
"input": "8 3 7 8",
"output": "1"
},
{
"input": "8 3 8 8",
"output": "1"
}
] | 1,509,018,860 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | n, m, a, b = map(int, input().split())
a -= 1
if b == n: b += (m - b) % m
x, y = a % m, b % m
print([1, 2 - (x * y == 0), 3 - (x == y) - (x == y == 0)][min(b // m - a // m, 2)]) | Title: Frames
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well.
This time Igor K. got disappointed in one of his hobbies: editing and voicing videos. Moreover, he got disappointed in it so much, that he decided to destroy his secret archive for good.
Igor K. use Pindows XR operation system which represents files and folders by small icons. At that, *m* icons can fit in a horizontal row in any window.
Igor K.'s computer contains *n* folders in the D: disk's root catalog. The folders are numbered from 1 to *n* in the order from the left to the right and from top to bottom (see the images). At that the folders with secret videos have numbers from *a* to *b* inclusive. Igor K. wants to delete them forever, at that making as few frame selections as possible, and then pressing Shift+Delete exactly once. What is the minimum number of times Igor K. will have to select the folder in order to select folders from *a* to *b* and only them? Let us note that if some selected folder is selected repeatedly, then it is deselected. Each selection possesses the shape of some rectangle with sides parallel to the screen's borders.
Input Specification:
The only line contains four integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*<=≤<=109, 1<=≤<=*a*<=≤<=*b*<=≤<=*n*). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted.
Output Specification:
Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from *a* to *b*.
Demo Input:
['11 4 3 9\n', '20 5 2 20\n']
Demo Output:
['3\n', '2\n']
Note:
The images below illustrate statement tests.
The first test:
<img class="tex-graphics" src="https://espresso.codeforces.com/a0e4ba690dd16e3c68210a28afd82020b23fb605.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In this test we can select folders 3 and 4 with out first selection, folders 5, 6, 7, 8 with our second selection and folder 9 with our third, last selection.
The second test:
<img class="tex-graphics" src="https://espresso.codeforces.com/289e2666a3d8b3dfe5b22ff3d88976df711640f7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In this test we can first select all folders in the first row (2, 3, 4, 5), then — all other ones. | ```python
n, m, a, b = map(int, input().split())
a -= 1
if b == n: b += (m - b) % m
x, y = a % m, b % m
print([1, 2 - (x * y == 0), 3 - (x == y) - (x == y == 0)][min(b // m - a // m, 2)])
``` | 0 |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}",
"output": "1"
},
{
"input": "{a, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 1,687,524,776 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | values_str = input()
values_set = set(values_str.split(','))
print(len(values_set)) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
Input Specification:
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Output Specification:
Print a single number — the number of distinct letters in Anton's set.
Demo Input:
['{a, b, c}\n', '{b, a, b, a}\n', '{}\n']
Demo Output:
['3\n', '2\n', '0\n']
Note:
none | ```python
values_str = input()
values_set = set(values_str.split(','))
print(len(values_set))
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Профиль горного хребта схематично задан в виде прямоугольной таблицы из символов «.» (пустое пространство) и «*» (часть горы). Каждый столбец таблицы содержит хотя бы одну «звёздочку». Гарантируется, что любой из символов «*» либо находится в нижней строке матрицы, либо непосредственно под ним находится другой символ «*».
Маршрут туриста проходит через весь горный хребет слева направо. Каждый день турист перемещается вправо — в соседний столбец в схематичном изображении. Конечно, каждый раз он поднимается (или опускается) в самую верхнюю точку горы, которая находится в соответствующем столбце.
Считая, что изначально турист находится в самой верхней точке в первом столбце, а закончит свой маршрут в самой верхней точке в последнем столбце, найдите две величины:
- наибольший подъём за день (равен 0, если в профиле горного хребта нет ни одного подъёма), - наибольший спуск за день (равен 0, если в профиле горного хребта нет ни одного спуска). | В первой строке входных данных записаны два целых числа *n* и *m* (1<=≤<=*n*,<=*m*<=≤<=100) — количество строк и столбцов в схематичном изображении соответственно.
Далее следуют *n* строк по *m* символов в каждой — схематичное изображение горного хребта. Каждый символ схематичного изображения — это либо «.», либо «*». Каждый столбец матрицы содержит хотя бы один символ «*». Гарантируется, что любой из символов «*» либо находится в нижней строке матрицы, либо непосредственно под ним находится другой символ «*». | Выведите через пробел два целых числа:
- величину наибольшего подъёма за день (или 0, если в профиле горного хребта нет ни одного подъёма), - величину наибольшего спуска за день (или 0, если в профиле горного хребта нет ни одного спуска). | [
"6 11\n...........\n.........*.\n.*.......*.\n**.......*.\n**..*...**.\n***********\n",
"5 5\n....*\n...**\n..***\n.****\n*****\n",
"8 7\n.......\n.*.....\n.*.....\n.**....\n.**.*..\n.****.*\n.******\n*******\n"
] | [
"3 4\n",
"1 0\n",
"6 2\n"
] | В первом тестовом примере высоты гор равны: 3, 4, 1, 1, 2, 1, 1, 1, 2, 5, 1. Наибольший подъем равен 3 и находится между горой номер 9 (её высота равна 2) и горой номер 10 (её высота равна 5). Наибольший спуск равен 4 и находится между горой номер 10 (её высота равна 5) и горой номер 11 (её высота равна 1).
Во втором тестовом примере высоты гор равны: 1, 2, 3, 4, 5. Наибольший подъём равен 1 и находится, например, между горой номер 2 (ее высота равна 2) и горой номер 3 (её высота равна 3). Так как в данном горном хребте нет спусков, то величина наибольшего спуска равна 0.
В третьем тестовом примере высоты гор равны: 1, 7, 5, 3, 4, 2, 3. Наибольший подъём равен 6 и находится между горой номер 1 (её высота равна 1) и горой номер 2 (её высота равна 7). Наибольший спуск равен 2 и находится между горой номер 2 (её высота равна 7) и горой номер 3 (её высота равна 5). Такой же спуск находится между горой номер 5 (её высота равна 4) и горой номер 6 (её высота равна 2). | 0 | [
{
"input": "6 11\n...........\n.........*.\n.*.......*.\n**.......*.\n**..*...**.\n***********",
"output": "3 4"
},
{
"input": "5 5\n....*\n...**\n..***\n.****\n*****",
"output": "1 0"
},
{
"input": "8 7\n.......\n.*.....\n.*.....\n.**....\n.**.*..\n.****.*\n.******\n*******",
"output": "6 2"
},
{
"input": "1 1\n*",
"output": "0 0"
},
{
"input": "2 2\n**\n**",
"output": "0 0"
},
{
"input": "1 10\n**********",
"output": "0 0"
},
{
"input": "10 1\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*",
"output": "0 0"
},
{
"input": "5 5\n.....\n.....\n*****\n*****\n*****",
"output": "0 0"
},
{
"input": "10 6\n......\n......\n......\n******\n******\n******\n******\n******\n******\n******",
"output": "0 0"
},
{
"input": "5 11\n***********\n***********\n***********\n***********\n***********",
"output": "0 0"
},
{
"input": "10 10\n..........\n..........\n.....*....\n.....*....\n.*...*....\n.*...*....\n.*..**....\n.*..**.*..\n.*..**.*..\n**********",
"output": "5 7"
},
{
"input": "10 20\n.*..................\n.*......*...........\n.**.....*..*........\n.**.....*..*........\n.**.....*..*........\n.**.....*..*........\n.**.*..**..*........\n.**.*****..*........\n**********.*.......*\n********************",
"output": "8 7"
},
{
"input": "10 30\n....*...........*.............\n.*..*.......*...*.............\n.*..*.....*.*...*............*\n.*..*..*..*.*...*............*\n.*..*..*..*.*...*..........*.*\n.*..*..*..*.*...*....*.....***\n.**.*..*..*.**..*.*..*.....***\n***.*..*..*.**..*.*..**.**.***\n***.**********..***..*****.***\n******************************",
"output": "9 8"
},
{
"input": "10 40\n*..................................*....\n*.....*..............*.............*....\n*.....*..............*............**....\n*..*..***...*...*....*.....*.*....**....\n*.**..***...*...*....*.....*.*...***....\n*.**..****.***..*..*.*..*..*.**..***.*..\n*.**..****.***.**..*.*..*.**.**..***.*..\n*.**..************.*.*..*.*****..***.**.\n*.***.************.*.*.*************.***\n****************************************",
"output": "8 9"
},
{
"input": "20 10\n..........\n..........\n..........\n..........\n..........\n.....*....\n.....*....\n.....*....\n.....*....\n.....*....\n.....*....\n.....*....\n...*.*....\n...*.*....\n...*.*....\n...***....\n..****.*..\n..****.**.\n..****.***\n**********",
"output": "10 14"
},
{
"input": "20 20\n........*...........\n........*........*..\n........*........*..\n.**.....*.......**..\n.**.....*.......**..\n.**.....*.....*.**..\n.**.....*.....*.**..\n.**.....*.....*.**..\n.**.....*.....*.**..\n.**.*...*.....*.**..\n.**.*...*.....*.**..\n.**.*...*....**.**..\n.**.*...*..*.**.**..\n.**.*...*..*.**.**..\n.**.*...**.*.**.***.\n.**.*.*.**.*.**.***.\n.**.*.*.**.*.**.***.\n.**.*.*.****.*******\n.****.******.*******\n********************",
"output": "18 15"
},
{
"input": "30 10\n..........\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n......**..\n......**..\n......**..\n.*....**..\n.*....**..\n.*.*..**..\n.*.*..**..\n.*.*..**..\n.*.*.***..\n.*******..\n.*******.*\n.*********\n**********",
"output": "16 27"
},
{
"input": "1 100\n****************************************************************************************************",
"output": "0 0"
},
{
"input": "100 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*",
"output": "0 0"
},
{
"input": "100 2\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n*.\n*.\n*.\n*.\n*.\n*.\n*.\n*.\n*.\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**",
"output": "0 9"
},
{
"input": "2 100\n*..*....*......................*.*..*.*.*....*.*.*....*.........*.*...*....**.........*.**....*.....\n****************************************************************************************************",
"output": "1 1"
},
{
"input": "5 12\n............\n............\n............\n............\n************",
"output": "0 0"
},
{
"input": "5 12\n............\n************\n************\n************\n************",
"output": "0 0"
},
{
"input": "5 12\n************\n************\n************\n************\n************",
"output": "0 0"
}
] | 1,458,745,532 | 332 | Python 3 | OK | TESTS | 107 | 62 | 5,120,000 | def main():
n, m = [int(i) for i in input().split()]
d = [list(input()) for i in range(n)]
a = [0] * m
for i in range(m):
for j in range(n):
if d[j][i] == '*':
a[i] += 1
x = y = 0
for i in range(1, m):
if a[i] > a[i - 1]: x = max(x, a[i] - a[i - 1])
else: y = max(y, a[i - 1] - a[i])
print(x, y)
main() | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Профиль горного хребта схематично задан в виде прямоугольной таблицы из символов «.» (пустое пространство) и «*» (часть горы). Каждый столбец таблицы содержит хотя бы одну «звёздочку». Гарантируется, что любой из символов «*» либо находится в нижней строке матрицы, либо непосредственно под ним находится другой символ «*».
Маршрут туриста проходит через весь горный хребет слева направо. Каждый день турист перемещается вправо — в соседний столбец в схематичном изображении. Конечно, каждый раз он поднимается (или опускается) в самую верхнюю точку горы, которая находится в соответствующем столбце.
Считая, что изначально турист находится в самой верхней точке в первом столбце, а закончит свой маршрут в самой верхней точке в последнем столбце, найдите две величины:
- наибольший подъём за день (равен 0, если в профиле горного хребта нет ни одного подъёма), - наибольший спуск за день (равен 0, если в профиле горного хребта нет ни одного спуска).
Input Specification:
В первой строке входных данных записаны два целых числа *n* и *m* (1<=≤<=*n*,<=*m*<=≤<=100) — количество строк и столбцов в схематичном изображении соответственно.
Далее следуют *n* строк по *m* символов в каждой — схематичное изображение горного хребта. Каждый символ схематичного изображения — это либо «.», либо «*». Каждый столбец матрицы содержит хотя бы один символ «*». Гарантируется, что любой из символов «*» либо находится в нижней строке матрицы, либо непосредственно под ним находится другой символ «*».
Output Specification:
Выведите через пробел два целых числа:
- величину наибольшего подъёма за день (или 0, если в профиле горного хребта нет ни одного подъёма), - величину наибольшего спуска за день (или 0, если в профиле горного хребта нет ни одного спуска).
Demo Input:
['6 11\n...........\n.........*.\n.*.......*.\n**.......*.\n**..*...**.\n***********\n', '5 5\n....*\n...**\n..***\n.****\n*****\n', '8 7\n.......\n.*.....\n.*.....\n.**....\n.**.*..\n.****.*\n.******\n*******\n']
Demo Output:
['3 4\n', '1 0\n', '6 2\n']
Note:
В первом тестовом примере высоты гор равны: 3, 4, 1, 1, 2, 1, 1, 1, 2, 5, 1. Наибольший подъем равен 3 и находится между горой номер 9 (её высота равна 2) и горой номер 10 (её высота равна 5). Наибольший спуск равен 4 и находится между горой номер 10 (её высота равна 5) и горой номер 11 (её высота равна 1).
Во втором тестовом примере высоты гор равны: 1, 2, 3, 4, 5. Наибольший подъём равен 1 и находится, например, между горой номер 2 (ее высота равна 2) и горой номер 3 (её высота равна 3). Так как в данном горном хребте нет спусков, то величина наибольшего спуска равна 0.
В третьем тестовом примере высоты гор равны: 1, 7, 5, 3, 4, 2, 3. Наибольший подъём равен 6 и находится между горой номер 1 (её высота равна 1) и горой номер 2 (её высота равна 7). Наибольший спуск равен 2 и находится между горой номер 2 (её высота равна 7) и горой номер 3 (её высота равна 5). Такой же спуск находится между горой номер 5 (её высота равна 4) и горой номер 6 (её высота равна 2). | ```python
def main():
n, m = [int(i) for i in input().split()]
d = [list(input()) for i in range(n)]
a = [0] * m
for i in range(m):
for j in range(n):
if d[j][i] == '*':
a[i] += 1
x = y = 0
for i in range(1, m):
if a[i] > a[i - 1]: x = max(x, a[i] - a[i - 1])
else: y = max(y, a[i - 1] - a[i])
print(x, y)
main()
``` | 3 |
|
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city.
Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel.
Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$. | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels. | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3 4 5 7 8 10 11 12 13 14 15 16 17 19 21 22 23 24 25 26 27 28 30 32 33 36 39 40 41 42 46 48 53 54 55 59 60 61 63 65 68 70 71 74 75 76 79 80 81 82 84 88 89 90 91 93 94 96 97 98 100 101 102 105 106 107 108 109 110 111 113 114 115 116 117 118 120 121 122 125 126 128 131 132 133 134 135 137 138 139 140 143 144 146 147 148 149",
"output": "47"
},
{
"input": "1 1000000000\n-1000000000",
"output": "2"
},
{
"input": "2 1000000000\n-1000000000 1000000000",
"output": "3"
},
{
"input": "100 2\n1 3 5 6 8 9 12 13 14 17 18 21 22 23 24 25 26 27 29 30 34 35 36 39 41 44 46 48 52 53 55 56 57 59 61 63 64 66 68 69 70 71 72 73 75 76 77 79 80 81 82 87 88 91 92 93 94 95 96 97 99 100 102 103 104 106 109 110 111 112 113 114 115 117 118 119 120 122 124 125 127 128 129 130 131 132 133 134 136 137 139 140 141 142 143 145 146 148 149 150",
"output": "6"
},
{
"input": "100 3\n0 1 3 6 7 8 9 10 13 14 16 17 18 20 21 22 24 26 27 30 33 34 35 36 37 39 42 43 44 45 46 48 53 54 55 56 57 58 61 63 64 65 67 69 70 72 73 76 77 78 79 81 82 83 85 86 87 88 90 92 93 95 96 97 98 99 100 101 104 105 108 109 110 113 114 115 116 118 120 121 123 124 125 128 130 131 132 133 134 135 136 137 139 140 141 142 146 147 148 150",
"output": "2"
},
{
"input": "1 1000000000\n1000000000",
"output": "2"
},
{
"input": "10 2\n-93 -62 -53 -42 -38 11 57 58 87 94",
"output": "17"
},
{
"input": "2 500000000\n-1000000000 1000000000",
"output": "4"
},
{
"input": "100 10\n-489 -476 -445 -432 -430 -421 -420 -418 -412 -411 -404 -383 -356 -300 -295 -293 -287 -276 -265 -263 -258 -251 -249 -246 -220 -219 -205 -186 -166 -157 -143 -137 -136 -130 -103 -86 -80 -69 -67 -55 -43 -41 -40 -26 -19 -9 16 29 41 42 54 76 84 97 98 99 101 115 134 151 157 167 169 185 197 204 208 226 227 232 234 249 259 266 281 282 293 298 300 306 308 313 319 328 331 340 341 344 356 362 366 380 390 399 409 411 419 444 455 498",
"output": "23"
},
{
"input": "1 1000000000\n999999999",
"output": "2"
},
{
"input": "1 1\n-5",
"output": "2"
},
{
"input": "2 1\n-1000000000 1000000000",
"output": "4"
},
{
"input": "1 2\n1",
"output": "2"
},
{
"input": "4 5\n0 20 40 60",
"output": "8"
},
{
"input": "1 1\n-10",
"output": "2"
},
{
"input": "1 1\n-1000000000",
"output": "2"
},
{
"input": "1 1000000000\n0",
"output": "2"
},
{
"input": "1 2\n-10",
"output": "2"
},
{
"input": "1 1\n2",
"output": "2"
},
{
"input": "1 5\n-100",
"output": "2"
},
{
"input": "2 1000000000\n999999999 1000000000",
"output": "2"
},
{
"input": "2 2\n0 5",
"output": "4"
},
{
"input": "1 2\n-5",
"output": "2"
},
{
"input": "1 1\n1",
"output": "2"
},
{
"input": "1 5\n-20",
"output": "2"
},
{
"input": "2 100000000\n-1000000000 1000000000",
"output": "4"
},
{
"input": "1 1000000000\n147483641",
"output": "2"
},
{
"input": "3 3\n1 8 9",
"output": "4"
},
{
"input": "2 1\n1 1000000000",
"output": "4"
},
{
"input": "1 2\n-4",
"output": "2"
},
{
"input": "2 1\n-1000000000 -1",
"output": "4"
}
] | 1,670,132,760 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 0 | n,d=map(int,input().split())
m=list(map(int,input().split()))
k,c = 0,2
for i in range(n-1):
k = abs(m[i]-m[i+1])
if k > 2*d:
c+=2
if k==2*d:
c+=1
print(c) | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city.
Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel.
Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$.
Input Specification:
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels.
Output Specification:
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
Demo Input:
['4 3\n-3 2 9 16\n', '5 2\n4 8 11 18 19\n']
Demo Output:
['6\n', '5\n']
Note:
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | ```python
n,d=map(int,input().split())
m=list(map(int,input().split()))
k,c = 0,2
for i in range(n-1):
k = abs(m[i]-m[i+1])
if k > 2*d:
c+=2
if k==2*d:
c+=1
print(c)
``` | 3 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,600,379,807 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 124 | 0 | import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))#might need to remove the -1
def invr():
return(map(int,input().split()))
s = insr()
j = 0
c = False
to = 'h'
cs = ['h', 'e', 'l', 'l', 'o']
for i in s:
if i == to:
j += 1
if j == 5:
c = True
break
to = cs[j]
if c:
print('YES')
else:
print('NO') | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))#might need to remove the -1
def invr():
return(map(int,input().split()))
s = insr()
j = 0
c = False
to = 'h'
cs = ['h', 'e', 'l', 'l', 'o']
for i in s:
if i == to:
j += 1
if j == 5:
c = True
break
to = cs[j]
if c:
print('YES')
else:
print('NO')
``` | 3.938 |
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,653,786,683 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 53 | 62 | 0 | a = [int(x) for x in input().split()]
sa = sum(a)
if sa % 2 != 0:
print('NO')
exit()
for i in range(64):
total = 0
c = 0
for b in range(6):
if ((i >> b) & 1) == 1:
total += a[b]
c += 1
if c != 3:
continue
if total == sa // 2:
print('YES')
exit()
print('NO')
| 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
a = [int(x) for x in input().split()]
sa = sum(a)
if sa % 2 != 0:
print('NO')
exit()
for i in range(64):
total = 0
c = 0
for b in range(6):
if ((i >> b) & 1) == 1:
total += a[b]
c += 1
if c != 3:
continue
if total == sa // 2:
print('YES')
exit()
print('NO')
``` | 3 |
|
844 | A | Diversity | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). | Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}.
In the third test case, it is impossible to make 7 different letters because the length of the string is 6. | 500 | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26",
"output": "14"
},
{
"input": "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26",
"output": "12"
},
{
"input": "a\n3",
"output": "impossible"
},
{
"input": "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1",
"output": "0"
},
{
"input": "cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\n4",
"output": "1"
},
{
"input": "fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\n20",
"output": "18"
},
{
"input": "swmkwaruyv\n5",
"output": "0"
},
{
"input": "tnbqpsuhkczmejirvyfdolxwga\n22",
"output": "0"
},
{
"input": "abcde\n3",
"output": "0"
},
{
"input": "abb\n1",
"output": "0"
},
{
"input": "aaaa\n1",
"output": "0"
},
{
"input": "abcde\n2",
"output": "0"
},
{
"input": "yandex\n4",
"output": "0"
},
{
"input": "aaabbbccc\n1",
"output": "0"
},
{
"input": "abcd\n2",
"output": "0"
},
{
"input": "asdfgh\n2",
"output": "0"
},
{
"input": "aab\n1",
"output": "0"
},
{
"input": "mynameissako\n5",
"output": "0"
},
{
"input": "abcde\n1",
"output": "0"
},
{
"input": "abcd\n3",
"output": "0"
},
{
"input": "abcdef\n2",
"output": "0"
},
{
"input": "abcdefg\n4",
"output": "0"
},
{
"input": "abc\n1",
"output": "0"
},
{
"input": "asdafjsgljdllgjdgkl\n5",
"output": "0"
},
{
"input": "yaay\n3",
"output": "1"
},
{
"input": "yaay\n4",
"output": "2"
},
{
"input": "zzzzzz\n2",
"output": "1"
}
] | 1,681,128,185 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 409,600 | import sys, string
s=sys.stdin.readline().strip()
y=sys.stdin.readline().strip()
s=''.join(list(dict.fromkeys(s)))
print("impossible" if int(y) > len(s) else int(y)-len(s[:int(y)])) | Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
Input Specification:
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Output Specification:
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
Demo Input:
['yandex\n6\n', 'yahoo\n5\n', 'google\n7\n']
Demo Output:
['0\n', '1\n', 'impossible\n']
Note:
In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}.
In the third test case, it is impossible to make 7 different letters because the length of the string is 6. | ```python
import sys, string
s=sys.stdin.readline().strip()
y=sys.stdin.readline().strip()
s=''.join(list(dict.fromkeys(s)))
print("impossible" if int(y) > len(s) else int(y)-len(s[:int(y)]))
``` | 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,621,108,170 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 0 | n=int(input())
nas=list(map(int,input().split()))
ctr=0
mtr=0
ct=[]
mt=[]
for i in range(len(nas)):
if nas[i]%2:
ctr+=1
ct.append(i)
else:
mtr+=1
mt.append(i)
if ctr>=1 and mtr>=1:
if ctr<mtr:
print(ct[-1]+1)
break
elif mtr<ctr:
print(mt[-1]+1)
break
else:
continue | 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())
nas=list(map(int,input().split()))
ctr=0
mtr=0
ct=[]
mt=[]
for i in range(len(nas)):
if nas[i]%2:
ctr+=1
ct.append(i)
else:
mtr+=1
mt.append(i)
if ctr>=1 and mtr>=1:
if ctr<mtr:
print(ct[-1]+1)
break
elif mtr<ctr:
print(mt[-1]+1)
break
else:
continue
``` | 3.969 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,691,727,985 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n, m, a = map(int, input().split())
# Calculate the number of flagstones needed
if n%a ==0:
horizontal_flagstones = (n//a)
else:
horizontal_flagstones = (n // a)+1
if n%a ==0:
vertical_flagstones = (n//a)
else:
vertical_flagstones = (n // a)+1
# Calculate the total number of flagstones
total_flagstones = horizontal_flagstones * vertical_flagstones
print(total_flagstones) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
n, m, a = map(int, input().split())
# Calculate the number of flagstones needed
if n%a ==0:
horizontal_flagstones = (n//a)
else:
horizontal_flagstones = (n // a)+1
if n%a ==0:
vertical_flagstones = (n//a)
else:
vertical_flagstones = (n // a)+1
# Calculate the total number of flagstones
total_flagstones = horizontal_flagstones * vertical_flagstones
print(total_flagstones)
``` | 0 |
382 | B | Number Busters | PROGRAMMING | 2,000 | [
"binary search",
"math"
] | null | null | Arthur and Alexander are number busters. Today they've got a competition.
Arthur took a group of four integers *a*,<=*b*,<=*w*,<=*x* (0<=≤<=*b*<=<<=*w*,<=0<=<<=*x*<=<<=*w*) and Alexander took integer *с*. Arthur and Alexander use distinct approaches to number bustings. Alexander is just a regular guy. Each second, he subtracts one from his number. In other words, he performs the assignment: *c*<==<=*c*<=-<=1. Arthur is a sophisticated guy. Each second Arthur performs a complex operation, described as follows: if *b*<=≥<=*x*, perform the assignment *b*<==<=*b*<=-<=*x*, if *b*<=<<=*x*, then perform two consecutive assignments *a*<==<=*a*<=-<=1; *b*<==<=*w*<=-<=(*x*<=-<=*b*).
You've got numbers *a*,<=*b*,<=*w*,<=*x*,<=*c*. Determine when Alexander gets ahead of Arthur if both guys start performing the operations at the same time. Assume that Alexander got ahead of Arthur if *c*<=≤<=*a*. | The first line contains integers *a*,<=*b*,<=*w*,<=*x*,<=*c* (1<=≤<=*a*<=≤<=2·109,<=1<=≤<=*w*<=≤<=1000,<=0<=≤<=*b*<=<<=*w*,<=0<=<<=*x*<=<<=*w*,<=1<=≤<=*c*<=≤<=2·109). | Print a single integer — the minimum time in seconds Alexander needs to get ahead of Arthur. You can prove that the described situation always occurs within the problem's limits. | [
"4 2 3 1 6\n",
"4 2 3 1 7\n",
"1 2 3 2 6\n",
"1 1 2 1 1\n"
] | [
"2\n",
"4\n",
"13\n",
"0\n"
] | none | 2,500 | [
{
"input": "4 2 3 1 6",
"output": "2"
},
{
"input": "4 2 3 1 7",
"output": "4"
},
{
"input": "1 2 3 2 6",
"output": "13"
},
{
"input": "1 1 2 1 1",
"output": "0"
},
{
"input": "1 0 1000 999 2000000000",
"output": "1999999999000"
},
{
"input": "10 1 6 4 20",
"output": "30"
},
{
"input": "10 3 6 5 30",
"output": "117"
},
{
"input": "10 3 5 1 30",
"output": "25"
},
{
"input": "10 32 312 72 1000",
"output": "1287"
},
{
"input": "1 102 123 27 2321",
"output": "2972"
},
{
"input": "2000000000 159 1000 870 2000000000",
"output": "0"
},
{
"input": "200000000 794 1000 117 2000000000",
"output": "2038505096"
},
{
"input": "20000000 280 1000 25 2000000000",
"output": "2030769231"
},
{
"input": "1999999999 47 1000 527 2000000000",
"output": "3"
},
{
"input": "19999 346 1000 141 2000000000",
"output": "2328265426"
},
{
"input": "1 142 1000 673 2000000000",
"output": "6116207948"
},
{
"input": "1 851 999 721 2000000000",
"output": "7187050354"
},
{
"input": "1 504 998 900 2000000000",
"output": "20367346924"
},
{
"input": "1 250 997 55 2000000000",
"output": "2116772823"
},
{
"input": "1 2 3 2 2000000000",
"output": "5999999995"
},
{
"input": "1 0 2 1 1232132",
"output": "2464262"
},
{
"input": "1 999 1000 1 2000000000",
"output": "2002002001"
},
{
"input": "1 999 1000 2 2000000000",
"output": "2004008015"
}
] | 1,389,977,922 | 5,322 | Python 3 | WRONG_ANSWER | PRETESTS | 7 | 61 | 409,600 | a,b,w,x,c = map(int,input().split())
poc = 0
s = set()
s.add(b)
pa,pb,pc = a,b,c
while (c > a) :
c -= 1
if b >= x:
b = b-x
else:
a -= 1
b = w - (x-b)
if b in s:
kolko = len(s)
break
s.add(b)
dl = len(s)
kolko = pa-a
roz = max(pc - pa - 2,0)
poc = roz*dl
c = pc - poc
a = pa - roz*kolko
b = pb
#a,b,c,poc=pa,pb,pc,0
#print(a,b,w,x,c)
while (c > a) :
c -= 1
if b >= x:
b = b-x
else:
a -= 1
b = w - (x-b)
poc+=1
#print(a,b,w,x,c)
print(poc)
| Title: Number Busters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arthur and Alexander are number busters. Today they've got a competition.
Arthur took a group of four integers *a*,<=*b*,<=*w*,<=*x* (0<=≤<=*b*<=<<=*w*,<=0<=<<=*x*<=<<=*w*) and Alexander took integer *с*. Arthur and Alexander use distinct approaches to number bustings. Alexander is just a regular guy. Each second, he subtracts one from his number. In other words, he performs the assignment: *c*<==<=*c*<=-<=1. Arthur is a sophisticated guy. Each second Arthur performs a complex operation, described as follows: if *b*<=≥<=*x*, perform the assignment *b*<==<=*b*<=-<=*x*, if *b*<=<<=*x*, then perform two consecutive assignments *a*<==<=*a*<=-<=1; *b*<==<=*w*<=-<=(*x*<=-<=*b*).
You've got numbers *a*,<=*b*,<=*w*,<=*x*,<=*c*. Determine when Alexander gets ahead of Arthur if both guys start performing the operations at the same time. Assume that Alexander got ahead of Arthur if *c*<=≤<=*a*.
Input Specification:
The first line contains integers *a*,<=*b*,<=*w*,<=*x*,<=*c* (1<=≤<=*a*<=≤<=2·109,<=1<=≤<=*w*<=≤<=1000,<=0<=≤<=*b*<=<<=*w*,<=0<=<<=*x*<=<<=*w*,<=1<=≤<=*c*<=≤<=2·109).
Output Specification:
Print a single integer — the minimum time in seconds Alexander needs to get ahead of Arthur. You can prove that the described situation always occurs within the problem's limits.
Demo Input:
['4 2 3 1 6\n', '4 2 3 1 7\n', '1 2 3 2 6\n', '1 1 2 1 1\n']
Demo Output:
['2\n', '4\n', '13\n', '0\n']
Note:
none | ```python
a,b,w,x,c = map(int,input().split())
poc = 0
s = set()
s.add(b)
pa,pb,pc = a,b,c
while (c > a) :
c -= 1
if b >= x:
b = b-x
else:
a -= 1
b = w - (x-b)
if b in s:
kolko = len(s)
break
s.add(b)
dl = len(s)
kolko = pa-a
roz = max(pc - pa - 2,0)
poc = roz*dl
c = pc - poc
a = pa - roz*kolko
b = pb
#a,b,c,poc=pa,pb,pc,0
#print(a,b,w,x,c)
while (c > a) :
c -= 1
if b >= x:
b = b-x
else:
a -= 1
b = w - (x-b)
poc+=1
#print(a,b,w,x,c)
print(poc)
``` | 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,668,364,654 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | # f=open('Documents/projects/CPDev/input.txt','r')
# def get_int():return list(map(int,f.readline().split()))
# def get_list(n): return [f.readline().split() for _ in range(n)]
def get_list(n): return list(input().split() for _ in range(n))
def get_int():return list(map(int,input().strip().split()))
n,m = get_int()
def solve():
s=min(n,m)
if s%2!=0:
s-=1
ans=s*s//2
s1=(n-s)*m
s2=(m-s)*n
ans+=s1//2 + s2//2
print(ans)
solve()
| 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
# f=open('Documents/projects/CPDev/input.txt','r')
# def get_int():return list(map(int,f.readline().split()))
# def get_list(n): return [f.readline().split() for _ in range(n)]
def get_list(n): return list(input().split() for _ in range(n))
def get_int():return list(map(int,input().strip().split()))
n,m = get_int()
def solve():
s=min(n,m)
if s%2!=0:
s-=1
ans=s*s//2
s1=(n-s)*m
s2=(m-s)*n
ans+=s1//2 + s2//2
print(ans)
solve()
``` | 0 |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "534204",
"output": "106841"
},
{
"input": "469569",
"output": "93914"
},
{
"input": "502877",
"output": "100576"
},
{
"input": "942212",
"output": "188443"
},
{
"input": "97",
"output": "20"
},
{
"input": "53",
"output": "11"
},
{
"input": "89",
"output": "18"
},
{
"input": "574",
"output": "115"
},
{
"input": "716",
"output": "144"
},
{
"input": "729",
"output": "146"
},
{
"input": "8901",
"output": "1781"
},
{
"input": "3645",
"output": "729"
},
{
"input": "4426",
"output": "886"
},
{
"input": "46573",
"output": "9315"
},
{
"input": "86380",
"output": "17276"
},
{
"input": "94190",
"output": "18838"
},
{
"input": "999990",
"output": "199998"
},
{
"input": "999991",
"output": "199999"
},
{
"input": "999992",
"output": "199999"
},
{
"input": "999993",
"output": "199999"
},
{
"input": "999994",
"output": "199999"
},
{
"input": "999995",
"output": "199999"
},
{
"input": "999996",
"output": "200000"
},
{
"input": "999997",
"output": "200000"
},
{
"input": "999998",
"output": "200000"
}
] | 1,694,670,238 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | # -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
m = int(input())
s = 1
while m > 5:
m -= 5
s += 1
print(s) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
Input Specification:
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Output Specification:
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
Demo Input:
['5\n', '12\n']
Demo Output:
['1\n', '3\n']
Note:
In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | ```python
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
m = int(input())
s = 1
while m > 5:
m -= 5
s += 1
print(s)
``` | 3 |
|
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:
- The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event. | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 20 9 14 14 10 13 6 13 14 17 6 8 20 12 10 15 13 17 5 12 13 11 7 5 5 2 3 15 13 7 14 14 19 2 13 14 5 15 3 19 15 16 4 1",
"output": "1891"
},
{
"input": "100 9000\n5 2 3 1 1 3 4 9 9 6 7 10 10 10 2 10 6 8 8 6 7 9 9 5 6 2 1 10 10 9 4 5 9 2 4 3 8 5 6 1 1 5 3 6 2 6 6 6 5 8 3 6 7 3 1 10 9 1 8 3 10 9 5 6 3 4 1 1 10 10 2 3 4 8 10 10 5 1 5 3 6 8 10 6 10 2 1 8 10 1 7 6 9 10 5 2 3 5 3 2",
"output": "1688"
},
{
"input": "100 8007\n5 19 14 18 9 6 15 8 1 14 11 20 3 17 7 12 2 6 3 17 7 20 1 14 20 17 2 10 13 7 18 18 9 10 16 8 1 11 11 9 13 18 9 20 12 12 7 15 12 17 11 5 11 15 9 2 15 1 18 3 18 16 15 4 10 5 18 13 13 12 3 8 17 2 12 2 13 3 1 13 2 4 9 10 18 10 14 4 4 17 12 19 2 9 6 5 5 20 18 12",
"output": "1391"
},
{
"input": "39 2412\n1 1 1 1 1 1 26 1 1 1 99 1 1 1 1 1 1 1 1 1 1 88 7 1 1 1 1 76 1 1 1 93 40 1 13 1 68 1 32",
"output": "368"
},
{
"input": "39 2617\n47 1 1 1 63 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 70 1 99 63 1 1 1 1 1 1 1 1 64 1 1",
"output": "435"
},
{
"input": "39 3681\n83 77 1 94 85 47 1 98 29 16 1 1 1 71 96 85 31 97 96 93 40 50 98 1 60 51 1 96 100 72 1 1 1 89 1 93 1 92 100",
"output": "326"
},
{
"input": "45 894\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 28 28 1 1 1 1 1 1 1 1 1 1 1 1 1 1 99 3 1 1",
"output": "139"
},
{
"input": "45 4534\n1 99 65 99 4 46 54 80 51 30 96 1 28 30 44 70 78 1 1 100 1 62 1 1 1 85 1 1 1 61 1 46 75 1 61 77 97 26 67 1 1 63 81 85 86",
"output": "514"
},
{
"input": "72 3538\n52 1 8 1 1 1 7 1 1 1 1 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 40 1 1 38 1 1 1 1 1 1 1 1 1 1 1 35 1 93 79 1 1 1 1 1 1 1 1 1 51 1 1 1 1 1 1 1 1 1 1 1 1 96 1",
"output": "586"
},
{
"input": "81 2200\n1 59 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 93 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 50 1 1 1 1 1 1 1 1 1 1 1",
"output": "384"
},
{
"input": "81 2577\n85 91 1 1 2 1 1 100 1 80 1 1 17 86 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 37 1 66 24 1 1 96 49 1 66 1 44 1 1 1 1 98 1 1 1 1 35 1 37 3 35 1 1 87 64 1 24 1 58 1 1 42 83 5 1 1 1 1 1 95 1 94 1 50 1 1",
"output": "174"
},
{
"input": "81 4131\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 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "807"
},
{
"input": "81 6315\n1 1 67 100 1 99 36 1 92 5 1 96 42 12 1 57 91 1 1 66 41 30 74 95 1 37 1 39 91 69 1 52 77 47 65 1 1 93 96 74 90 35 85 76 71 92 92 1 1 67 92 74 1 1 86 76 35 1 56 16 27 57 37 95 1 40 20 100 51 1 80 60 45 79 95 1 46 1 25 100 96",
"output": "490"
},
{
"input": "96 1688\n1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 71 1 1 1 30 1 1 1",
"output": "284"
},
{
"input": "96 8889\n1 1 18 1 1 1 1 1 1 1 1 1 99 1 1 1 1 88 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 96 1 1 1 1 21 1 1 1 1 1 1 1 73 1 1 1 1 1 10 1 1 1 1 1 1 1 46 43 1 1 1 1 1 98 1 1 1 1 1 1 6 1 1 1 1 1 74 1 25 1 55 1 1 1 13 1 1 54 1 1 1",
"output": "1589"
},
{
"input": "10 100\n1 1 1 1 1 1 1 1 1 1",
"output": "18"
},
{
"input": "100 10000\n54 46 72 94 79 83 91 54 73 3 24 55 54 31 28 20 19 6 25 19 47 23 1 70 15 87 51 39 54 77 55 5 60 3 15 99 56 88 22 78 79 21 38 27 28 86 7 88 12 59 55 70 25 1 70 49 1 45 69 72 50 17 4 56 8 100 90 34 35 20 61 76 88 79 4 74 65 68 75 26 40 72 59 94 10 67 96 85 29 90 47 24 44 1 66 93 55 36 1 99",
"output": "1017"
},
{
"input": "100 6000\n41 31 23 17 24 78 26 96 93 48 46 2 49 33 35 9 73 100 34 48 83 36 33 69 43 24 3 74 8 81 27 33 94 38 77 9 76 90 62 90 21 67 22 22 12 2 17 27 61 18 72 85 59 65 71 38 90 75 74 66 60 47 58 50 90 95 75 10 5 100 97 29 83 88 65 26 93 90 22 98 36 55 70 38 50 92 88 72 99 96 25 14 74 16 25 92 67 94 77 96",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 6\n1",
"output": "1"
},
{
"input": "1 5\n1",
"output": "0"
},
{
"input": "1 3\n4",
"output": "-1"
},
{
"input": "3 24\n2 1 2",
"output": "-1"
}
] | 1,609,909,254 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 155 | 0 | n, limit = map(int, input().split())
lst = list(map(int, input().split()))
s = sum(lst) + (n - 1) * 10
if s > limit:
print(-1)
else:
print(2 * (n - 1) + (limit - s) // 5) | Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:
- The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input Specification:
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
Output Specification:
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Demo Input:
['3 30\n2 2 1\n', '3 20\n2 1 1\n']
Demo Output:
['5\n', '-1\n']
Note:
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | ```python
n, limit = map(int, input().split())
lst = list(map(int, input().split()))
s = sum(lst) + (n - 1) * 10
if s > limit:
print(-1)
else:
print(2 * (n - 1) + (limit - s) // 5)
``` | 3 |
|
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed.
Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed. | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move. | If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
"output": "9"
},
{
"input": "2 2 5\n1 1\n2 1\n2 1\n1 2\n2 2",
"output": "5"
},
{
"input": "518 518 10\n37 97\n47 278\n17 467\n158 66\n483 351\n83 123\n285 219\n513 187\n380 75\n304 352",
"output": "0"
},
{
"input": "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "0"
},
{
"input": "1 5 5\n1 1\n1 2\n1 3\n1 4\n1 5",
"output": "0"
},
{
"input": "5 1 5\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "0"
},
{
"input": "1 1 1\n1 1",
"output": "0"
},
{
"input": "10 10 4\n5 9\n6 9\n6 10\n5 10",
"output": "4"
},
{
"input": "1000 1000 4\n999 999\n999 1000\n1000 999\n1000 1000",
"output": "4"
},
{
"input": "2 3 5\n2 3\n1 3\n1 2\n1 1\n2 2",
"output": "5"
},
{
"input": "1000 1000 4\n1000 1000\n999 999\n1000 999\n999 1000",
"output": "4"
}
] | 1,698,126,974 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n,m,k=map(int,input(),split())
x=[(m+2)*[0] for i in range(n+2)]
def check(i,j):
if x[i][j+1]==1 and x[i+1][j]==1 and x[i+1][j+1]==1:
return True
if x[i][j-1]==1 and x[i+1][j]==1 and x[i+1][j-1]==1:
return True
if x[i-1][j]==1 and x[i][j+1]==1 and x[i-1][j+1]==1:
return True
if x[i-1][j]==1 and x[i][j-1]==1 and x[i-1][j-1]==1:
return True
return False
for i in range(k):
l,n=map(int,input().split())
x[l][n]=1
if check(l,n):
print(i+1)
break
else:
print(0) | Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed.
Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed.
Input Specification:
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move.
Output Specification:
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
Demo Input:
['2 2 4\n1 1\n1 2\n2 1\n2 2\n', '2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n', '5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n']
Demo Output:
['4\n', '5\n', '0\n']
Note:
none | ```python
n,m,k=map(int,input(),split())
x=[(m+2)*[0] for i in range(n+2)]
def check(i,j):
if x[i][j+1]==1 and x[i+1][j]==1 and x[i+1][j+1]==1:
return True
if x[i][j-1]==1 and x[i+1][j]==1 and x[i+1][j-1]==1:
return True
if x[i-1][j]==1 and x[i][j+1]==1 and x[i-1][j+1]==1:
return True
if x[i-1][j]==1 and x[i][j-1]==1 and x[i-1][j-1]==1:
return True
return False
for i in range(k):
l,n=map(int,input().split())
x[l][n]=1
if check(l,n):
print(i+1)
break
else:
print(0)
``` | -1 |
|
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 586975278",
"output": "1"
},
{
"input": "259504825 377489979 588153796 377489979",
"output": "1"
},
{
"input": "652588203 931100304 931100304 652588203",
"output": "2"
},
{
"input": "391958720 651507265 391958720 651507265",
"output": "2"
},
{
"input": "90793237 90793237 90793237 90793237",
"output": "3"
},
{
"input": "551651653 551651653 551651653 551651653",
"output": "3"
},
{
"input": "156630260 609654355 668943582 973622757",
"output": "0"
},
{
"input": "17061017 110313588 434481173 796661222",
"output": "0"
},
{
"input": "24975422 256716298 337790533 690960249",
"output": "0"
},
{
"input": "255635360 732742923 798648949 883146723",
"output": "0"
},
{
"input": "133315691 265159773 734556507 265159773",
"output": "1"
},
{
"input": "28442865 741657755 978106882 978106882",
"output": "1"
},
{
"input": "131245479 174845575 497483467 131245479",
"output": "1"
},
{
"input": "139159884 616215581 958341883 616215581",
"output": "1"
},
{
"input": "147784432 947653080 947653080 947653080",
"output": "2"
},
{
"input": "94055790 756126496 756126496 94055790",
"output": "2"
},
{
"input": "240458500 511952208 240458500 511952208",
"output": "2"
},
{
"input": "681828506 972810624 972810624 681828506",
"output": "2"
},
{
"input": "454961014 454961014 454961014 454961014",
"output": "3"
},
{
"input": "915819430 915819430 915819430 915819430",
"output": "3"
},
{
"input": "671645142 671645142 671645142 671645142",
"output": "3"
},
{
"input": "132503558 132503558 132503558 132503558",
"output": "3"
},
{
"input": "5 5 999999 6",
"output": "1"
},
{
"input": "1 1 2 5",
"output": "1"
},
{
"input": "2 1 2 3",
"output": "1"
},
{
"input": "1 1 3 5",
"output": "1"
},
{
"input": "1 1 3 3",
"output": "2"
},
{
"input": "2 2 2 1",
"output": "2"
},
{
"input": "3 1 1 1",
"output": "2"
},
{
"input": "1 2 2 2",
"output": "2"
}
] | 1,693,939,260 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 186 | 0 |
nums = input().split()
copy = []
for i in range(4):
if nums[i] not in copy:
copy.append(nums[i])
ans = 4 - len(copy)
print(ans) | Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
Input Specification:
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers.
Output Specification:
Print a single integer — the minimum number of horseshoes Valera needs to buy.
Demo Input:
['1 7 3 3\n', '7 7 7 7\n']
Demo Output:
['1\n', '3\n']
Note:
none | ```python
nums = input().split()
copy = []
for i in range(4):
if nums[i] not in copy:
copy.append(nums[i])
ans = 4 - len(copy)
print(ans)
``` | 3 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,585,588,871 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 218 | 0 | x=int(input())
s=0
for i in range(x):
y=list(map(int,input().split()))
s=s+sum(y)
if s==0:
print('YES')
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
x=int(input())
s=0
for i in range(x):
y=list(map(int,input().split()))
s=s+sum(y)
if s==0:
print('YES')
else:
print('NO')
``` | 0 |
33 | A | What is for dinner? | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | A. What is for dinner? | 2 | 256 | In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).
It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again.
Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative.
As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.
We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where belongs the corresponding tooth, and *c* (0<=≤<=*c*<=≤<=106) — its residual viability.
It's guaranteed that each tooth row has positive amount of teeth. | In the first line output the maximum amount of crucians that Valerie can consume for dinner. | [
"4 3 18\n2 3\n1 2\n3 6\n2 3\n",
"2 2 13\n1 13\n2 12\n"
] | [
"11\n",
"13\n"
] | none | 500 | [
{
"input": "4 3 18\n2 3\n1 2\n3 6\n2 3",
"output": "11"
},
{
"input": "2 2 13\n1 13\n2 12",
"output": "13"
},
{
"input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3",
"output": "8"
},
{
"input": "1 1 0\n1 3",
"output": "0"
},
{
"input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 16\n1 16",
"output": "5"
},
{
"input": "4 2 8\n1 9\n1 10\n1 4\n2 6",
"output": "8"
},
{
"input": "10 4 14\n2 6\n1 5\n2 8\n2 6\n2 5\n4 1\n4 0\n2 4\n3 4\n1 0",
"output": "8"
},
{
"input": "54 22 1009\n15 7\n17 7\n11 9\n5 11\n12 9\n13 8\n13 12\n22 11\n20 9\n20 7\n16 11\n19 12\n3 12\n15 9\n1 12\n2 10\n16 10\n16 10\n14 10\n9 11\n9 9\n14 8\n10 10\n16 12\n1 8\n3 8\n21 11\n18 12\n2 6\n9 11\n11 7\n15 9\n20 11\n6 8\n8 8\n19 11\n15 7\n9 9\n22 7\n12 9\n17 9\n17 11\n12 7\n15 9\n5 11\n11 6\n18 8\n7 10\n4 10\n13 12\n4 8\n20 6\n15 12\n9 7",
"output": "180"
},
{
"input": "1 1 1000000\n1 1000000",
"output": "1000000"
},
{
"input": "4 3 181818\n3 1299\n1 1694\n3 1164\n2 1278",
"output": "4136"
},
{
"input": "50 50 0\n33 0\n26 0\n30 0\n41 0\n38 0\n36 0\n16 0\n7 0\n23 0\n5 0\n39 0\n29 0\n40 0\n47 0\n24 0\n43 0\n14 0\n10 0\n20 0\n3 0\n6 0\n34 0\n13 0\n18 0\n21 0\n9 0\n8 0\n22 0\n25 0\n4 0\n11 0\n17 0\n32 0\n44 0\n49 0\n50 0\n27 0\n28 0\n45 0\n12 0\n35 0\n15 0\n42 0\n31 0\n2 0\n1 0\n48 0\n19 0\n37 0\n46 0",
"output": "0"
},
{
"input": "19 12 199\n7 1\n8 6\n6 14\n1 7\n4 1\n6 6\n3 4\n1 5\n9 2\n5 3\n11 3\n9 4\n1 12\n4 7\n7 3\n12 14\n2 1\n10 8\n6 12",
"output": "54"
}
] | 1,593,772,371 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 307,200 | R=lambda:map(int,input().split())
s=sorted
n,k=R()
_,u,v,w=l=[[],[],[],[]]
for _ in[0]*n:t,a,b=R();l[2*a+b]+=t,
a=*map(sum,zip(s(u),s(v))),*w
print(sum((s(a)+[-sum(a)-1])[:k])) | Title: What is for dinner?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).
It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again.
Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative.
As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.
We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.
Input Specification:
The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where belongs the corresponding tooth, and *c* (0<=≤<=*c*<=≤<=106) — its residual viability.
It's guaranteed that each tooth row has positive amount of teeth.
Output Specification:
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
Demo Input:
['4 3 18\n2 3\n1 2\n3 6\n2 3\n', '2 2 13\n1 13\n2 12\n']
Demo Output:
['11\n', '13\n']
Note:
none | ```python
R=lambda:map(int,input().split())
s=sorted
n,k=R()
_,u,v,w=l=[[],[],[],[]]
for _ in[0]*n:t,a,b=R();l[2*a+b]+=t,
a=*map(sum,zip(s(u),s(v))),*w
print(sum((s(a)+[-sum(a)-1])[:k]))
``` | -1 |
719 | B | Anatoly and Cockroaches | PROGRAMMING | 1,400 | [
"greedy"
] | null | null | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. | Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. | [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0. | 1,000 | [
{
"input": "5\nrbbrr",
"output": "1"
},
{
"input": "5\nbbbbb",
"output": "2"
},
{
"input": "3\nrbr",
"output": "0"
},
{
"input": "13\nrbbbrbrrbrrbb",
"output": "3"
},
{
"input": "18\nrrrrrrrrrrrrrrrrrb",
"output": "8"
},
{
"input": "100\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbrbbbbbbbbbbbbbbbbrrrrbbbbrrrbbbbbbbrbrrbrbbbbrrrbbbbrbbrbbbrb",
"output": "34"
},
{
"input": "166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbbbbrbrbbbbbbbbbbbrbbbbbbbbbbbbbbrbbbbbbbbbbbbbbbbbbbbbb",
"output": "70"
},
{
"input": "1\nr",
"output": "0"
},
{
"input": "1\nb",
"output": "0"
},
{
"input": "2\nrb",
"output": "0"
},
{
"input": "2\nbr",
"output": "0"
},
{
"input": "2\nrr",
"output": "1"
},
{
"input": "2\nbb",
"output": "1"
},
{
"input": "8\nrbbrbrbr",
"output": "1"
},
{
"input": "7\nrrbrbrb",
"output": "1"
}
] | 1,632,674,400 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 124 | 22,323,200 | def calc(s,i):
c=[0,0]
for x in range(len(s)):
if s[x]!=i[x]:c[x%2]+=1
return max(c)
n=int(input());s=input()
i1=('rb'*(n//2+1))[:n]
i2=('br'*(n//2+1))[:n]
print(min(calc(s,i1),calc(s,i2)))
| Title: Anatoly and Cockroaches
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Output Specification:
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
Demo Input:
['5\nrbbrr\n', '5\nbbbbb\n', '3\nrbr\n']
Demo Output:
['1\n', '2\n', '0\n']
Note:
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0. | ```python
def calc(s,i):
c=[0,0]
for x in range(len(s)):
if s[x]!=i[x]:c[x%2]+=1
return max(c)
n=int(input());s=input()
i1=('rb'*(n//2+1))[:n]
i2=('br'*(n//2+1))[:n]
print(min(calc(s,i1),calc(s,i2)))
``` | 3 |
|
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,564,850,974 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 218 | 0 | # import sys
# sys.stdin = open("test.in","r")
# sys.stdout = open("test.out","w")
a=list(map(ord,input()))
b=max(a)
print(chr(b)*a.count(b))
| 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
# import sys
# sys.stdin = open("test.in","r")
# sys.stdout = open("test.out","w")
a=list(map(ord,input()))
b=max(a)
print(chr(b)*a.count(b))
``` | 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,695,759,625 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 46 | 6,348,800 | l=[];x=int(input());c=0;l2=[]
for i in range(x):
z=input()
l.append(z)
for i in range(x-1):
if l[i][i]== l[i+1][i+1]:
c+=1
for i in l:
for j in i:
l2.append(j)
if c == x-1 and len(set(l2))==2:
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
l=[];x=int(input());c=0;l2=[]
for i in range(x):
z=input()
l.append(z)
for i in range(x-1):
if l[i][i]== l[i+1][i+1]:
c+=1
for i in l:
for j in i:
l2.append(j)
if c == x-1 and len(set(l2))==2:
print("YES")
else:
print("NO")
``` | 0 |
|
472 | D | Design Tutorial: Inverse the Problem | PROGRAMMING | 1,900 | [
"dfs and similar",
"dsu",
"shortest paths",
"trees"
] | null | null | There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example.
Now let's create a task this way. We will use the task: you are given a tree, please calculate the distance between any pair of its nodes. Yes, it is very easy, but the inverse version is a bit harder: you are given an *n*<=×<=*n* distance matrix. Determine if it is the distance matrix of a weighted tree (all weights must be positive integers). | The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000) — the number of nodes in that graph.
Then next *n* lines each contains *n* integers *d**i*,<=*j* (0<=≤<=*d**i*,<=*j*<=≤<=109) — the distance between node *i* and node *j*. | If there exists such a tree, output "YES", otherwise output "NO". | [
"3\n0 2 7\n2 0 9\n7 9 0\n",
"3\n1 2 7\n2 0 9\n7 9 0\n",
"3\n0 2 2\n7 0 9\n7 9 0\n",
"3\n0 1 1\n1 0 1\n1 1 0\n",
"2\n0 0\n0 0\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n"
] | In the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7.
In the second example, it is impossible because *d*<sub class="lower-index">1, 1</sub> should be 0, but it is 1.
In the third example, it is impossible because *d*<sub class="lower-index">1, 2</sub> should equal *d*<sub class="lower-index">2, 1</sub>. | 2,000 | [
{
"input": "3\n0 2 7\n2 0 9\n7 9 0",
"output": "YES"
},
{
"input": "3\n1 2 7\n2 0 9\n7 9 0",
"output": "NO"
},
{
"input": "3\n0 2 2\n7 0 9\n7 9 0",
"output": "NO"
},
{
"input": "3\n0 1 1\n1 0 1\n1 1 0",
"output": "NO"
},
{
"input": "2\n0 0\n0 0",
"output": "NO"
},
{
"input": "1\n0",
"output": "YES"
},
{
"input": "1\n1",
"output": "NO"
},
{
"input": "2\n0 1000000000\n1000000000 0",
"output": "YES"
},
{
"input": "5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "NO"
},
{
"input": "2\n0 1\n1 0",
"output": "YES"
},
{
"input": "4\n0 3 7 6\n3 0 4 9\n7 4 0 2\n6 9 2 0",
"output": "NO"
},
{
"input": "3\n0 1 2\n1 0 2\n2 2 0",
"output": "NO"
},
{
"input": "3\n0 2 7\n2 0 10\n7 10 0",
"output": "NO"
}
] | 1,690,484,802 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 61 | 0 | print("_RANDOM_GUESS_1690484802.8884575")# 1690484802.8884773 | Title: Design Tutorial: Inverse the Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example.
Now let's create a task this way. We will use the task: you are given a tree, please calculate the distance between any pair of its nodes. Yes, it is very easy, but the inverse version is a bit harder: you are given an *n*<=×<=*n* distance matrix. Determine if it is the distance matrix of a weighted tree (all weights must be positive integers).
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000) — the number of nodes in that graph.
Then next *n* lines each contains *n* integers *d**i*,<=*j* (0<=≤<=*d**i*,<=*j*<=≤<=109) — the distance between node *i* and node *j*.
Output Specification:
If there exists such a tree, output "YES", otherwise output "NO".
Demo Input:
['3\n0 2 7\n2 0 9\n7 9 0\n', '3\n1 2 7\n2 0 9\n7 9 0\n', '3\n0 2 2\n7 0 9\n7 9 0\n', '3\n0 1 1\n1 0 1\n1 1 0\n', '2\n0 0\n0 0\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n', 'NO\n', 'NO\n']
Note:
In the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7.
In the second example, it is impossible because *d*<sub class="lower-index">1, 1</sub> should be 0, but it is 1.
In the third example, it is impossible because *d*<sub class="lower-index">1, 2</sub> should equal *d*<sub class="lower-index">2, 1</sub>. | ```python
print("_RANDOM_GUESS_1690484802.8884575")# 1690484802.8884773
``` | 0 |
|
199 | A | Hexadecimal's theorem | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible. | The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. | Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them. | [
"3\n",
"13\n"
] | [
"1 1 1\n",
"2 3 8\n"
] | none | 500 | [
{
"input": "3",
"output": "1 1 1"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "3",
"output": "1 1 1"
},
{
"input": "5",
"output": "1 1 3"
},
{
"input": "8",
"output": "1 2 5"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "21",
"output": "3 5 13"
},
{
"input": "34",
"output": "5 8 21"
},
{
"input": "55",
"output": "8 13 34"
},
{
"input": "89",
"output": "13 21 55"
},
{
"input": "144",
"output": "21 34 89"
},
{
"input": "233",
"output": "34 55 144"
},
{
"input": "377",
"output": "55 89 233"
},
{
"input": "610",
"output": "89 144 377"
},
{
"input": "987",
"output": "144 233 610"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "2584",
"output": "377 610 1597"
},
{
"input": "4181",
"output": "610 987 2584"
},
{
"input": "6765",
"output": "987 1597 4181"
},
{
"input": "10946",
"output": "1597 2584 6765"
},
{
"input": "17711",
"output": "2584 4181 10946"
},
{
"input": "28657",
"output": "4181 6765 17711"
},
{
"input": "46368",
"output": "6765 10946 28657"
},
{
"input": "75025",
"output": "10946 17711 46368"
},
{
"input": "121393",
"output": "17711 28657 75025"
},
{
"input": "196418",
"output": "28657 46368 121393"
},
{
"input": "317811",
"output": "46368 75025 196418"
},
{
"input": "514229",
"output": "75025 121393 317811"
},
{
"input": "832040",
"output": "121393 196418 514229"
},
{
"input": "1346269",
"output": "196418 317811 832040"
},
{
"input": "2178309",
"output": "317811 514229 1346269"
},
{
"input": "3524578",
"output": "514229 832040 2178309"
},
{
"input": "5702887",
"output": "832040 1346269 3524578"
},
{
"input": "9227465",
"output": "1346269 2178309 5702887"
},
{
"input": "14930352",
"output": "2178309 3524578 9227465"
},
{
"input": "24157817",
"output": "3524578 5702887 14930352"
},
{
"input": "39088169",
"output": "5702887 9227465 24157817"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "165580141",
"output": "24157817 39088169 102334155"
},
{
"input": "267914296",
"output": "39088169 63245986 165580141"
},
{
"input": "433494437",
"output": "63245986 102334155 267914296"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
}
] | 1,609,539,519 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 280 | 0 | ser = [0, 1]
def fib(n):
i = 1
while i < n:
ser.append(i)
i = ser[-1] + ser[-2]
if i != n:
return -1
else:
return len(ser)
n = int(input())
a, b, c = 0, 0, 0
ans = 1
if n == 1:
a = 1
elif n == 2:
a = 1
b = 1
elif n == 3:
a = 1
b = 1
c = 1
else:
ans = fib(n)
if ans != -1:
a = ser[ans-2]
b = ser[ans-2]
c = ser[ans-3]
if ans != -1:
print(a, b, c)
else:
print("I'm too stupid to solve this problem")
| Title: Hexadecimal's theorem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible.
Input Specification:
The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number.
Output Specification:
Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Demo Input:
['3\n', '13\n']
Demo Output:
['1 1 1\n', '2 3 8\n']
Note:
none | ```python
ser = [0, 1]
def fib(n):
i = 1
while i < n:
ser.append(i)
i = ser[-1] + ser[-2]
if i != n:
return -1
else:
return len(ser)
n = int(input())
a, b, c = 0, 0, 0
ans = 1
if n == 1:
a = 1
elif n == 2:
a = 1
b = 1
elif n == 3:
a = 1
b = 1
c = 1
else:
ans = fib(n)
if ans != -1:
a = ser[ans-2]
b = ser[ans-2]
c = ser[ans-3]
if ans != -1:
print(a, b, c)
else:
print("I'm too stupid to solve this problem")
``` | 0 |
|
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"output": "6"
},
{
"input": "11 562314608",
"output": "39916800"
},
{
"input": "3 990639260",
"output": "6"
},
{
"input": "11 859155400",
"output": "39916800"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "5 3",
"output": "6"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "5 4",
"output": "24"
},
{
"input": "1 12",
"output": "1"
},
{
"input": "9 7",
"output": "5040"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "6 11",
"output": "720"
},
{
"input": "6 7",
"output": "720"
},
{
"input": "11 11",
"output": "39916800"
},
{
"input": "4 999832660",
"output": "24"
},
{
"input": "7 999228288",
"output": "5040"
},
{
"input": "11 999257105",
"output": "39916800"
},
{
"input": "11 999286606",
"output": "39916800"
},
{
"input": "3 999279109",
"output": "6"
},
{
"input": "999632727 11",
"output": "39916800"
},
{
"input": "999625230 7",
"output": "5040"
},
{
"input": "999617047 3",
"output": "6"
},
{
"input": "999646548 7",
"output": "5040"
},
{
"input": "999639051 3",
"output": "6"
},
{
"input": "12 12",
"output": "479001600"
},
{
"input": "12 1",
"output": "1"
},
{
"input": "1213 5",
"output": "120"
},
{
"input": "8 9",
"output": "40320"
},
{
"input": "12 9",
"output": "362880"
},
{
"input": "12 1000000000",
"output": "479001600"
},
{
"input": "1000000000 1",
"output": "1"
},
{
"input": "12 13",
"output": "479001600"
},
{
"input": "2 29845",
"output": "2"
},
{
"input": "10 21",
"output": "3628800"
},
{
"input": "12 20",
"output": "479001600"
},
{
"input": "15 12",
"output": "479001600"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000 12",
"output": "479001600"
},
{
"input": "11 30",
"output": "39916800"
},
{
"input": "17 12",
"output": "479001600"
},
{
"input": "4 19",
"output": "24"
},
{
"input": "12 15",
"output": "479001600"
},
{
"input": "20 6",
"output": "720"
},
{
"input": "10 20",
"output": "3628800"
},
{
"input": "10 10",
"output": "3628800"
},
{
"input": "22 12",
"output": "479001600"
},
{
"input": "20 12",
"output": "479001600"
},
{
"input": "12 23",
"output": "479001600"
},
{
"input": "12 22",
"output": "479001600"
},
{
"input": "18 3",
"output": "6"
},
{
"input": "14 10",
"output": "3628800"
},
{
"input": "14 12",
"output": "479001600"
},
{
"input": "8 3",
"output": "6"
},
{
"input": "5 5",
"output": "120"
}
] | 1,676,539,978 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 1,843,200 | import math
a,b = input().split()
c = math.factorial(int(a))
d = math.factorial(int(b))
print(math.gcd(c,d))
| Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
Input Specification:
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Output Specification:
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
Demo Input:
['4 3\n']
Demo Output:
['6\n']
Note:
Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | ```python
import math
a,b = input().split()
c = math.factorial(int(a))
d = math.factorial(int(b))
print(math.gcd(c,d))
``` | 0 |
|
71 | B | Progress Bar | PROGRAMMING | 1,300 | [
"implementation",
"math"
] | B. Progress Bar | 1 | 256 | A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.
A bar is represented as *n* squares, located in line. To add clarity, let's number them with positive integers from 1 to *n* from the left to the right. Each square has saturation (*a**i* for the *i*-th square), which is measured by an integer from 0 to *k*. When the bar for some *i* (1<=≤<=*i*<=≤<=*n*) is displayed, squares 1,<=2,<=... ,<=*i*<=-<=1 has the saturation *k*, squares *i*<=+<=1,<=*i*<=+<=2,<=... ,<=*n* has the saturation 0, and the saturation of the square *i* can have any value from 0 to *k*.
So some first squares of the progress bar always have the saturation *k*. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and *k*.
The degree of the process's completion is measured in percents. Let the process be *t*% completed. Then the following inequation is fulfilled:
An example of such a bar can be seen on the picture.
For the given *n*, *k*, *t* determine the measures of saturation for all the squares *a**i* of the progress bar. | We are given 3 space-separated integers *n*, *k*, *t* (1<=≤<=*n*,<=*k*<=≤<=100, 0<=≤<=*t*<=≤<=100). | Print *n* numbers. The *i*-th of them should be equal to *a**i*. | [
"10 10 54\n",
"11 13 37\n"
] | [
"10 10 10 10 10 4 0 0 0 0 ",
"13 13 13 13 0 0 0 0 0 0 0 "
] | none | 1,000 | [
{
"input": "10 10 54",
"output": "10 10 10 10 10 4 0 0 0 0 "
},
{
"input": "11 13 37",
"output": "13 13 13 13 0 0 0 0 0 0 0 "
},
{
"input": "9 25 50",
"output": "25 25 25 25 12 0 0 0 0 "
},
{
"input": "43 47 77",
"output": "47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 5 0 0 0 0 0 0 0 0 0 "
},
{
"input": "20 1 43",
"output": "1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "17 4 61",
"output": "4 4 4 4 4 4 4 4 4 4 1 0 0 0 0 0 0 "
},
{
"input": "10 16 0",
"output": "0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "17 13 100",
"output": "13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 "
},
{
"input": "11 9 1",
"output": "0 0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "9 11 99",
"output": "11 11 11 11 11 11 11 11 10 "
},
{
"input": "6 17 1",
"output": "1 0 0 0 0 0 "
},
{
"input": "6 17 99",
"output": "17 17 17 17 17 15 "
},
{
"input": "17 6 1",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "17 6 99",
"output": "6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 "
},
{
"input": "99 1 1",
"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 "
},
{
"input": "99 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 "
},
{
"input": "1 1 0",
"output": "0 "
},
{
"input": "1 1 37",
"output": "0 "
},
{
"input": "1 1 50",
"output": "0 "
},
{
"input": "1 1 51",
"output": "0 "
},
{
"input": "1 1 99",
"output": "0 "
},
{
"input": "1 1 100",
"output": "1 "
},
{
"input": "1 17 35",
"output": "5 "
},
{
"input": "1 31 88",
"output": "27 "
},
{
"input": "1 100 0",
"output": "0 "
},
{
"input": "1 100 38",
"output": "38 "
},
{
"input": "1 100 99",
"output": "99 "
},
{
"input": "1 100 100",
"output": "100 "
},
{
"input": "1 99 99",
"output": "98 "
},
{
"input": "100 100 73",
"output": "100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 0 0 0 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 100",
"output": "100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 "
},
{
"input": "100 13 100",
"output": "13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 "
},
{
"input": "100 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 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 "
},
{
"input": "100 13 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 "
},
{
"input": "100 63 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 "
},
{
"input": "100 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 "
},
{
"input": "2 99 51",
"output": "99 1 "
},
{
"input": "2 1 49",
"output": "0 0 "
},
{
"input": "2 1 100",
"output": "1 1 "
},
{
"input": "2 13 0",
"output": "0 0 "
},
{
"input": "99 1 51",
"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 "
},
{
"input": "15 25 93",
"output": "25 25 25 25 25 25 25 25 25 25 25 25 25 23 0 "
},
{
"input": "60 51 85",
"output": "51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 0 0 0 0 0 0 0 0 0 "
},
{
"input": "4 78 78",
"output": "78 78 78 9 "
},
{
"input": "49 4 4",
"output": "4 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "42 83 98",
"output": "83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 13 "
},
{
"input": "87 9 90",
"output": "9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 2 0 0 0 0 0 0 0 0 "
},
{
"input": "31 36 83",
"output": "36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 26 0 0 0 0 0 "
},
{
"input": "24 14 76",
"output": "14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 3 0 0 0 0 0 "
}
] | 1,680,593,347 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | import numpy
nkt = list(map(int,input().strip().split()))
n = nkt[0]
k = nkt[1]
t = nkt[2]
print(n,k,t)
add=0
z=n
total = n*k
list1 = []
cal = 0
while n != 0:
if cal < t:
list1.append(k)
add = sum(list1)
# print(add)
cal = ((add+k)/total)*100
n -= 1
# print(list1)
elif cal > t :
k-=1
cal = ((add+k)/ total) * 100
else:
list1.append(k)
n-=1
while n!=0:
list1.append(0)
n-=1
my_list=numpy.array(list1)
print(my_list)
| Title: Progress Bar
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.
A bar is represented as *n* squares, located in line. To add clarity, let's number them with positive integers from 1 to *n* from the left to the right. Each square has saturation (*a**i* for the *i*-th square), which is measured by an integer from 0 to *k*. When the bar for some *i* (1<=≤<=*i*<=≤<=*n*) is displayed, squares 1,<=2,<=... ,<=*i*<=-<=1 has the saturation *k*, squares *i*<=+<=1,<=*i*<=+<=2,<=... ,<=*n* has the saturation 0, and the saturation of the square *i* can have any value from 0 to *k*.
So some first squares of the progress bar always have the saturation *k*. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and *k*.
The degree of the process's completion is measured in percents. Let the process be *t*% completed. Then the following inequation is fulfilled:
An example of such a bar can be seen on the picture.
For the given *n*, *k*, *t* determine the measures of saturation for all the squares *a**i* of the progress bar.
Input Specification:
We are given 3 space-separated integers *n*, *k*, *t* (1<=≤<=*n*,<=*k*<=≤<=100, 0<=≤<=*t*<=≤<=100).
Output Specification:
Print *n* numbers. The *i*-th of them should be equal to *a**i*.
Demo Input:
['10 10 54\n', '11 13 37\n']
Demo Output:
['10 10 10 10 10 4 0 0 0 0 ', '13 13 13 13 0 0 0 0 0 0 0 ']
Note:
none | ```python
import numpy
nkt = list(map(int,input().strip().split()))
n = nkt[0]
k = nkt[1]
t = nkt[2]
print(n,k,t)
add=0
z=n
total = n*k
list1 = []
cal = 0
while n != 0:
if cal < t:
list1.append(k)
add = sum(list1)
# print(add)
cal = ((add+k)/total)*100
n -= 1
# print(list1)
elif cal > t :
k-=1
cal = ((add+k)/ total) * 100
else:
list1.append(k)
n-=1
while n!=0:
list1.append(0)
n-=1
my_list=numpy.array(list1)
print(my_list)
``` | -1 |
265 | B | Roadside Trees (Simplified Edition) | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts.
Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following actions:
- Walk up or down one unit on a tree. - Eat a nut on the top of the current tree. - Jump to the next tree. In this action the height of Liss doesn't change. More formally, when Liss is at height *h* of the tree *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), she jumps to height *h* of the tree *i*<=+<=1. This action can't be performed if *h*<=><=*h**i*<=+<=1.
Compute the minimal time (in seconds) required to eat all nuts. | The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees.
Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*. | Print a single integer — the minimal time required to eat all nuts in seconds. | [
"2\n1\n2\n",
"5\n2\n1\n2\n1\n1\n"
] | [
"5\n",
"14\n"
] | none | 1,000 | [
{
"input": "2\n1\n2",
"output": "5"
},
{
"input": "5\n2\n1\n2\n1\n1",
"output": "14"
},
{
"input": "1\n1",
"output": "2"
}
] | 1,626,610,844 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 434 | 6,963,200 | n = int(input())
total = 0
h = int(input())
total += h + 1
cur = h
for i in range(n-1):
hi = int(input())
if h > hi:
total += h-hi #d own
total += 1 # jump
total += 1 # eat
else:
total += 1 # jump
diff = hi-h
total += diff # up
total += 1 # eat
h = hi
print(total) | Title: Roadside Trees (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts.
Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following actions:
- Walk up or down one unit on a tree. - Eat a nut on the top of the current tree. - Jump to the next tree. In this action the height of Liss doesn't change. More formally, when Liss is at height *h* of the tree *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), she jumps to height *h* of the tree *i*<=+<=1. This action can't be performed if *h*<=><=*h**i*<=+<=1.
Compute the minimal time (in seconds) required to eat all nuts.
Input Specification:
The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees.
Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*.
Output Specification:
Print a single integer — the minimal time required to eat all nuts in seconds.
Demo Input:
['2\n1\n2\n', '5\n2\n1\n2\n1\n1\n']
Demo Output:
['5\n', '14\n']
Note:
none | ```python
n = int(input())
total = 0
h = int(input())
total += h + 1
cur = h
for i in range(n-1):
hi = int(input())
if h > hi:
total += h-hi #d own
total += 1 # jump
total += 1 # eat
else:
total += 1 # jump
diff = hi-h
total += diff # up
total += 1 # eat
h = hi
print(total)
``` | 3 |
|
152 | A | Marks | PROGRAMMING | 900 | [
"implementation"
] | null | null | Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at.
Your task is to find the number of successful students in the group. | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces. | Print the single number — the number of successful students in the given group. | [
"3 3\n223\n232\n112\n",
"3 5\n91728\n11828\n11111\n"
] | [
"2\n",
"3\n"
] | In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | 500 | [
{
"input": "3 3\n223\n232\n112",
"output": "2"
},
{
"input": "3 5\n91728\n11828\n11111",
"output": "3"
},
{
"input": "2 2\n48\n27",
"output": "1"
},
{
"input": "2 1\n4\n6",
"output": "1"
},
{
"input": "1 2\n57",
"output": "1"
},
{
"input": "1 1\n5",
"output": "1"
},
{
"input": "3 4\n2553\n6856\n5133",
"output": "2"
},
{
"input": "8 7\n6264676\n7854895\n3244128\n2465944\n8958761\n1378945\n3859353\n6615285",
"output": "6"
},
{
"input": "9 8\n61531121\n43529859\n18841327\n88683622\n98995641\n62741632\n57441743\n49396792\n63381994",
"output": "4"
},
{
"input": "10 20\n26855662887514171367\n48525577498621511535\n47683778377545341138\n47331616748732562762\n44876938191354974293\n24577238399664382695\n42724955594463126746\n79187344479926159359\n48349683283914388185\n82157191115518781898",
"output": "9"
},
{
"input": "20 15\n471187383859588\n652657222494199\n245695867594992\n726154672861295\n614617827782772\n862889444974692\n373977167653235\n645434268565473\n785993468314573\n722176861496755\n518276853323939\n723712762593348\n728935312568886\n373898548522463\n769777587165681\n247592995114377\n182375946483965\n497496542536127\n988239919677856\n859844339819143",
"output": "18"
},
{
"input": "13 9\n514562255\n322655246\n135162979\n733845982\n473117129\n513967187\n965649829\n799122777\n661249521\n298618978\n659352422\n747778378\n723261619",
"output": "11"
},
{
"input": "75 1\n2\n3\n8\n3\n2\n1\n3\n1\n5\n1\n5\n4\n8\n8\n4\n2\n5\n1\n7\n6\n3\n2\n2\n3\n5\n5\n2\n4\n7\n7\n9\n2\n9\n5\n1\n4\n9\n5\n2\n4\n6\n6\n3\n3\n9\n3\n3\n2\n3\n4\n2\n6\n9\n1\n1\n1\n1\n7\n2\n3\n2\n9\n7\n4\n9\n1\n7\n5\n6\n8\n3\n4\n3\n4\n6",
"output": "7"
},
{
"input": "92 3\n418\n665\n861\n766\n529\n416\n476\n676\n561\n995\n415\n185\n291\n176\n776\n631\n556\n488\n118\n188\n437\n496\n466\n131\n914\n118\n766\n365\n113\n897\n386\n639\n276\n946\n759\n169\n494\n837\n338\n351\n783\n311\n261\n862\n598\n132\n246\n982\n575\n364\n615\n347\n374\n368\n523\n132\n774\n161\n552\n492\n598\n474\n639\n681\n635\n342\n516\n483\n141\n197\n571\n336\n175\n596\n481\n327\n841\n133\n142\n146\n246\n396\n287\n582\n556\n996\n479\n814\n497\n363\n963\n162",
"output": "23"
},
{
"input": "100 1\n1\n6\n9\n1\n1\n5\n5\n4\n6\n9\n6\n1\n7\n8\n7\n3\n8\n8\n7\n6\n2\n1\n5\n8\n7\n3\n5\n4\n9\n7\n1\n2\n4\n1\n6\n5\n1\n3\n9\n4\n5\n8\n1\n2\n1\n9\n7\n3\n7\n1\n2\n2\n2\n2\n3\n9\n7\n2\n4\n7\n1\n6\n8\n1\n5\n6\n1\n1\n2\n9\n7\n4\n9\n1\n9\n4\n1\n3\n5\n2\n4\n4\n6\n5\n1\n4\n5\n8\n4\n7\n6\n5\n6\n9\n5\n8\n1\n5\n1\n6",
"output": "10"
},
{
"input": "100 2\n71\n87\n99\n47\n22\n87\n49\n73\n21\n12\n77\n43\n18\n41\n78\n62\n61\n16\n64\n89\n81\n54\n53\n92\n93\n94\n68\n93\n15\n68\n42\n93\n28\n19\n86\n16\n97\n17\n11\n43\n72\n76\n54\n95\n58\n53\n48\n45\n85\n85\n74\n21\n44\n51\n89\n75\n76\n17\n38\n62\n81\n22\n66\n59\n89\n85\n91\n87\n12\n97\n52\n87\n43\n89\n51\n58\n57\n98\n78\n68\n82\n41\n87\n29\n75\n72\n48\n14\n35\n71\n74\n91\n66\n67\n42\n98\n52\n54\n22\n41",
"output": "21"
},
{
"input": "5 20\n11111111111111111111\n11111111111111111111\n11111111111111111111\n99999999999999999999\n11111111111111111119",
"output": "2"
},
{
"input": "3 3\n111\n111\n999",
"output": "1"
},
{
"input": "3 3\n119\n181\n711",
"output": "3"
},
{
"input": "15 5\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111",
"output": "15"
},
{
"input": "2 20\n22222222222222222222\n11111111111111111111",
"output": "1"
},
{
"input": "3 3\n233\n222\n111",
"output": "2"
},
{
"input": "4 15\n222222222222222\n111111111111119\n111111111111119\n111111111111111",
"output": "3"
},
{
"input": "4 1\n1\n9\n9\n9",
"output": "3"
},
{
"input": "3 3\n123\n321\n132",
"output": "3"
},
{
"input": "3 3\n113\n332\n322",
"output": "3"
},
{
"input": "2 100\n2222222222222222222222222222222222222222222222222222222222222222222222221222222222222222222222222222\n1111111111111111111111111111111111111111111111111111111111111111111111119111111111111111111111111111",
"output": "2"
},
{
"input": "3 3\n321\n231\n123",
"output": "3"
},
{
"input": "2 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222",
"output": "1"
},
{
"input": "3 3\n221\n111\n111",
"output": "3"
}
] | 1,525,028,523 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 109 | 22,016,000 | n,m = map(int, input().split())
a = [0]*(n)
ss = [[] for _ in range(m)]
for i in range(n):
s = list(input())
for j in range(m):
ss[j].append(s[j])
for i in range(m):
mx = max(ss[i])
for j in range(n):
if ss[i][j] == mx:
a[j] = 1
print(sum(a)) | Title: Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at.
Your task is to find the number of successful students in the group.
Input Specification:
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces.
Output Specification:
Print the single number — the number of successful students in the given group.
Demo Input:
['3 3\n223\n232\n112\n', '3 5\n91728\n11828\n11111\n']
Demo Output:
['2\n', '3\n']
Note:
In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | ```python
n,m = map(int, input().split())
a = [0]*(n)
ss = [[] for _ in range(m)]
for i in range(n):
s = list(input())
for j in range(m):
ss[j].append(s[j])
for i in range(m):
mx = max(ss[i])
for j in range(n):
if ss[i][j] == mx:
a[j] = 1
print(sum(a))
``` | 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,540,240,345 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 218 | 0 | a = input()
b = input()
c = int(a) + int(b)
def rz( n ):
n = str(n)
ret = ""
for i in n:
if i != "0":
ret += i
return ( ret )
if int( rz(a) ) + int( rz(b) ) == int( rz(c) ):
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()
c = int(a) + int(b)
def rz( n ):
n = str(n)
ret = ""
for i in n:
if i != "0":
ret += i
return ( ret )
if int( rz(a) ) + int( rz(b) ) == int( rz(c) ):
print( "YES" )
else:
print( "NO" )
``` | 3.9455 |
180 | C | Letter | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.
To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions. | The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. | Print a single number — the least number of actions needed to make the message fancy. | [
"PRuvetSTAaYA\n",
"OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n",
"helloworld\n"
] | [
"5\n",
"0\n",
"0\n"
] | none | 0 | [
{
"input": "PRuvetSTAaYA",
"output": "5"
},
{
"input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA",
"output": "0"
},
{
"input": "helloworld",
"output": "0"
},
{
"input": "P",
"output": "0"
},
{
"input": "t",
"output": "0"
},
{
"input": "XdJ",
"output": "1"
},
{
"input": "FSFlNEelYY",
"output": "3"
},
{
"input": "lgtyasficu",
"output": "0"
},
{
"input": "WYKUDTDDBT",
"output": "0"
},
{
"input": "yysxwlyqboatikfnpxczmpijziiojbvadlfozjqldssffcxdegyxfrvohoxvgsrvlzjlkcuffoeisrpvagxtbkapkpzcafadzzjd",
"output": "0"
},
{
"input": "mnAkOBuKxaiJwXhKnlcCvjxYXGXDoIqfUYkiLrdSYWhMemgWFzsgpoKOtHqooxbLYFuABWQSXuHdbyPVWyrkeEfqOsnEBikiqhfu",
"output": "43"
},
{
"input": "MMVESdOCALHJCTBTUWWQRGUUVTTTABKKAAdIINAdKLRLLVLODHDXDPMcQfUhPNHFBJSDRGsHZNORSCPNvKOOIuZnZAmTPUCoPNlR",
"output": "13"
},
{
"input": "MMbJIBhgFXPVpdQHLkWJkAHFIfJSpITTCRzRCzvRPRYECCheOknfINZWuKATDBOrEVKTcWXiYPjtzQMGUSGPNTMCUrvYCSWQHqAi",
"output": "27"
},
{
"input": "ZnqXEBOABXVbHRFFqDLWpWBBLqZIagmbRAYMDKJAYyFQXnPYwvDyRXKHLQnMLHGEOnRKmXtGqyQkoBCSmgKPcEIEugwJyxDOtTVn",
"output": "31"
}
] | 1,685,634,086 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | s_new = input() # 将原有的变量名s改为更具意义的s_new
n = len(s_new)
prefix_num = 0 # 将prefix改为具体说明其含义的prefix_num
suffix_num = 0 # 将suffix改为具体说明其含义的suffix_num
ans = float('inf')
for i in range(n):
if 'a' <= s_new[i] <= 'z':
prefix_num += 1
for i in range(n - 1, -1, -1):
if 'A' <= s_new[i] <= 'Z':
suffix_num += 1
ans = min(ans, prefix_num + suffix_num)
if 'a' <= s_new[i] <= 'z':
prefix_num -= 1
print(ans - 1)
| Title: Letter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.
To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.
Input Specification:
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
Output Specification:
Print a single number — the least number of actions needed to make the message fancy.
Demo Input:
['PRuvetSTAaYA\n', 'OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n', 'helloworld\n']
Demo Output:
['5\n', '0\n', '0\n']
Note:
none | ```python
s_new = input() # 将原有的变量名s改为更具意义的s_new
n = len(s_new)
prefix_num = 0 # 将prefix改为具体说明其含义的prefix_num
suffix_num = 0 # 将suffix改为具体说明其含义的suffix_num
ans = float('inf')
for i in range(n):
if 'a' <= s_new[i] <= 'z':
prefix_num += 1
for i in range(n - 1, -1, -1):
if 'A' <= s_new[i] <= 'Z':
suffix_num += 1
ans = min(ans, prefix_num + suffix_num)
if 'a' <= s_new[i] <= 'z':
prefix_num -= 1
print(ans - 1)
``` | -1 |
|
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
"input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ",
"output": "1077"
},
{
"input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA",
"output": "568"
},
{
"input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA",
"output": "70"
},
{
"input": "W",
"output": "0"
},
{
"input": "DBA",
"output": "0"
},
{
"input": "RQAWNACASAAKAGAAAAQ",
"output": "10"
},
{
"input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA",
"output": "111"
},
{
"input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA",
"output": "411"
},
{
"input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ",
"output": "625"
},
{
"input": "QORZOYAQ",
"output": "1"
},
{
"input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA",
"output": "13174"
},
{
"input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT",
"output": "10420"
},
{
"input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ",
"output": "12488"
},
{
"input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA",
"output": "9114"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "35937"
},
{
"input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE",
"output": "254"
},
{
"input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE",
"output": "2174"
},
{
"input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ",
"output": "2962"
},
{
"input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA",
"output": "2482"
},
{
"input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ",
"output": "7768"
},
{
"input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA",
"output": "5422"
},
{
"input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ",
"output": "3024"
},
{
"input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ",
"output": "4527"
},
{
"input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH",
"output": "6416"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ",
"output": "13136"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA",
"output": "14231"
},
{
"input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "15296"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA",
"output": "20825"
},
{
"input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ",
"output": "20825"
},
{
"input": "Q",
"output": "0"
},
{
"input": "A",
"output": "0"
},
{
"input": "FFF",
"output": "0"
},
{
"input": "AAAAAA",
"output": "0"
}
] | 1,607,687,141 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 140 | 0 | a = list(input())
count = 0
t = 0
for i in range(0, len(a)):
for j in range(i, len(a)):
for k in range(j, len(a)):
if a[i] == "Q" and a[j] == "A" and a[k] == "Q":
count += 1
print(count) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
Input Specification:
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Output Specification:
Print a single integer — the number of subsequences "QAQ" in the string.
Demo Input:
['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n']
Demo Output:
['4\n', '3\n']
Note:
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | ```python
a = list(input())
count = 0
t = 0
for i in range(0, len(a)):
for j in range(i, len(a)):
for k in range(j, len(a)):
if a[i] == "Q" and a[j] == "A" and a[k] == "Q":
count += 1
print(count)
``` | 3 |
|
916 | A | Jamie and Alarm Snooze | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button.
A time is considered lucky if it contains a digit '7'. For example, 13:<=07 and 17:<=27 are lucky, while 00:<=48 and 21:<=34 are not lucky.
Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at *hh*:<=*mm*.
Formally, find the smallest possible non-negative integer *y* such that the time representation of the time *x*·*y* minutes before *hh*:<=*mm* contains the digit '7'.
Jamie uses 24-hours clock, so after 23:<=59 comes 00:<=00. | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60).
The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59). | Print the minimum number of times he needs to press the button. | [
"3\n11 23\n",
"5\n01 07\n"
] | [
"2\n",
"0\n"
] | In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.
In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky. | 500 | [
{
"input": "3\n11 23",
"output": "2"
},
{
"input": "5\n01 07",
"output": "0"
},
{
"input": "34\n09 24",
"output": "3"
},
{
"input": "2\n14 37",
"output": "0"
},
{
"input": "14\n19 54",
"output": "9"
},
{
"input": "42\n15 44",
"output": "12"
},
{
"input": "46\n02 43",
"output": "1"
},
{
"input": "14\n06 41",
"output": "1"
},
{
"input": "26\n04 58",
"output": "26"
},
{
"input": "54\n16 47",
"output": "0"
},
{
"input": "38\n20 01",
"output": "3"
},
{
"input": "11\n02 05",
"output": "8"
},
{
"input": "55\n22 10",
"output": "5"
},
{
"input": "23\n10 08",
"output": "6"
},
{
"input": "23\n23 14",
"output": "9"
},
{
"input": "51\n03 27",
"output": "0"
},
{
"input": "35\n15 25",
"output": "13"
},
{
"input": "3\n12 15",
"output": "6"
},
{
"input": "47\n00 28",
"output": "3"
},
{
"input": "31\n13 34",
"output": "7"
},
{
"input": "59\n17 32",
"output": "0"
},
{
"input": "25\n11 03",
"output": "8"
},
{
"input": "9\n16 53",
"output": "4"
},
{
"input": "53\n04 06",
"output": "3"
},
{
"input": "37\n00 12",
"output": "5"
},
{
"input": "5\n13 10",
"output": "63"
},
{
"input": "50\n01 59",
"output": "10"
},
{
"input": "34\n06 13",
"output": "4"
},
{
"input": "2\n18 19",
"output": "1"
},
{
"input": "46\n06 16",
"output": "17"
},
{
"input": "14\n03 30",
"output": "41"
},
{
"input": "40\n13 37",
"output": "0"
},
{
"input": "24\n17 51",
"output": "0"
},
{
"input": "8\n14 57",
"output": "0"
},
{
"input": "52\n18 54",
"output": "2"
},
{
"input": "20\n15 52",
"output": "24"
},
{
"input": "20\n03 58",
"output": "30"
},
{
"input": "48\n07 11",
"output": "0"
},
{
"input": "32\n04 01",
"output": "2"
},
{
"input": "60\n08 15",
"output": "1"
},
{
"input": "44\n20 20",
"output": "4"
},
{
"input": "55\n15 35",
"output": "9"
},
{
"input": "55\n03 49",
"output": "11"
},
{
"input": "23\n16 39",
"output": "4"
},
{
"input": "7\n20 36",
"output": "7"
},
{
"input": "35\n16 42",
"output": "1"
},
{
"input": "35\n05 56",
"output": "21"
},
{
"input": "3\n17 45",
"output": "0"
},
{
"input": "47\n05 59",
"output": "6"
},
{
"input": "15\n10 13",
"output": "9"
},
{
"input": "59\n06 18",
"output": "9"
},
{
"input": "34\n17 18",
"output": "0"
},
{
"input": "18\n05 23",
"output": "2"
},
{
"input": "46\n17 21",
"output": "0"
},
{
"input": "30\n06 27",
"output": "0"
},
{
"input": "14\n18 40",
"output": "3"
},
{
"input": "58\n22 54",
"output": "6"
},
{
"input": "26\n19 44",
"output": "5"
},
{
"input": "10\n15 57",
"output": "0"
},
{
"input": "54\n20 47",
"output": "0"
},
{
"input": "22\n08 45",
"output": "3"
},
{
"input": "48\n18 08",
"output": "1"
},
{
"input": "32\n07 06",
"output": "0"
},
{
"input": "60\n19 19",
"output": "2"
},
{
"input": "45\n07 25",
"output": "0"
},
{
"input": "29\n12 39",
"output": "8"
},
{
"input": "13\n08 28",
"output": "3"
},
{
"input": "41\n21 42",
"output": "5"
},
{
"input": "41\n09 32",
"output": "3"
},
{
"input": "9\n21 45",
"output": "2"
},
{
"input": "37\n10 43",
"output": "5"
},
{
"input": "3\n20 50",
"output": "1"
},
{
"input": "47\n00 04",
"output": "1"
},
{
"input": "15\n13 10",
"output": "21"
},
{
"input": "15\n17 23",
"output": "0"
},
{
"input": "43\n22 13",
"output": "2"
},
{
"input": "27\n10 26",
"output": "6"
},
{
"input": "55\n22 24",
"output": "5"
},
{
"input": "55\n03 30",
"output": "11"
},
{
"input": "24\n23 27",
"output": "0"
},
{
"input": "52\n11 33",
"output": "3"
},
{
"input": "18\n22 48",
"output": "17"
},
{
"input": "1\n12 55",
"output": "8"
},
{
"input": "1\n04 27",
"output": "0"
},
{
"input": "1\n12 52",
"output": "5"
},
{
"input": "1\n20 16",
"output": "9"
},
{
"input": "1\n04 41",
"output": "4"
},
{
"input": "1\n20 21",
"output": "4"
},
{
"input": "1\n04 45",
"output": "8"
},
{
"input": "1\n12 18",
"output": "1"
},
{
"input": "1\n04 42",
"output": "5"
},
{
"input": "1\n02 59",
"output": "2"
},
{
"input": "1\n18 24",
"output": "7"
},
{
"input": "1\n02 04",
"output": "7"
},
{
"input": "1\n18 28",
"output": "1"
},
{
"input": "1\n18 01",
"output": "2"
},
{
"input": "1\n10 25",
"output": "8"
},
{
"input": "1\n02 49",
"output": "2"
},
{
"input": "1\n02 30",
"output": "3"
},
{
"input": "1\n18 54",
"output": "7"
},
{
"input": "1\n02 19",
"output": "2"
},
{
"input": "1\n05 25",
"output": "8"
},
{
"input": "60\n23 55",
"output": "6"
},
{
"input": "60\n08 19",
"output": "1"
},
{
"input": "60\n00 00",
"output": "7"
},
{
"input": "60\n08 24",
"output": "1"
},
{
"input": "60\n16 13",
"output": "9"
},
{
"input": "60\n08 21",
"output": "1"
},
{
"input": "60\n16 45",
"output": "9"
},
{
"input": "60\n08 26",
"output": "1"
},
{
"input": "60\n08 50",
"output": "1"
},
{
"input": "60\n05 21",
"output": "12"
},
{
"input": "60\n13 29",
"output": "6"
},
{
"input": "60\n05 18",
"output": "12"
},
{
"input": "60\n13 42",
"output": "6"
},
{
"input": "60\n05 07",
"output": "0"
},
{
"input": "60\n05 47",
"output": "0"
},
{
"input": "60\n21 55",
"output": "4"
},
{
"input": "60\n05 36",
"output": "12"
},
{
"input": "60\n21 08",
"output": "4"
},
{
"input": "60\n21 32",
"output": "4"
},
{
"input": "60\n16 31",
"output": "9"
},
{
"input": "5\n00 00",
"output": "73"
},
{
"input": "2\n06 58",
"output": "390"
},
{
"input": "60\n00 00",
"output": "7"
},
{
"input": "2\n00 00",
"output": "181"
},
{
"input": "10\n00 00",
"output": "37"
},
{
"input": "60\n01 00",
"output": "8"
},
{
"input": "12\n00 06",
"output": "31"
},
{
"input": "1\n00 01",
"output": "4"
},
{
"input": "5\n00 05",
"output": "74"
},
{
"input": "60\n01 01",
"output": "8"
},
{
"input": "11\n18 11",
"output": "2"
},
{
"input": "60\n01 15",
"output": "8"
},
{
"input": "10\n00 16",
"output": "38"
},
{
"input": "60\n00 59",
"output": "7"
},
{
"input": "30\n00 00",
"output": "13"
},
{
"input": "60\n01 05",
"output": "8"
},
{
"input": "4\n00 03",
"output": "4"
},
{
"input": "4\n00 00",
"output": "91"
},
{
"input": "60\n00 01",
"output": "7"
},
{
"input": "6\n00 03",
"output": "1"
},
{
"input": "13\n00 00",
"output": "1"
},
{
"input": "1\n18 01",
"output": "2"
},
{
"input": "5\n06 00",
"output": "145"
},
{
"input": "60\n04 08",
"output": "11"
},
{
"input": "5\n01 55",
"output": "96"
},
{
"input": "8\n00 08",
"output": "47"
},
{
"input": "23\n18 23",
"output": "2"
},
{
"input": "6\n00 06",
"output": "62"
},
{
"input": "59\n18 59",
"output": "2"
},
{
"input": "11\n00 10",
"output": "3"
},
{
"input": "10\n00 01",
"output": "37"
},
{
"input": "59\n00 00",
"output": "7"
},
{
"input": "10\n18 10",
"output": "2"
},
{
"input": "5\n00 01",
"output": "73"
},
{
"input": "1\n00 00",
"output": "3"
},
{
"input": "8\n00 14",
"output": "47"
},
{
"input": "60\n03 00",
"output": "10"
},
{
"input": "60\n00 10",
"output": "7"
},
{
"input": "5\n01 13",
"output": "87"
},
{
"input": "30\n02 43",
"output": "18"
},
{
"input": "17\n00 08",
"output": "3"
},
{
"input": "3\n00 00",
"output": "1"
},
{
"input": "60\n00 05",
"output": "7"
},
{
"input": "5\n18 05",
"output": "2"
},
{
"input": "30\n00 30",
"output": "14"
},
{
"input": "1\n00 06",
"output": "9"
},
{
"input": "55\n00 00",
"output": "7"
},
{
"input": "8\n02 08",
"output": "62"
},
{
"input": "7\n00 00",
"output": "9"
},
{
"input": "6\n08 06",
"output": "2"
},
{
"input": "48\n06 24",
"output": "16"
},
{
"input": "8\n06 58",
"output": "98"
},
{
"input": "3\n12 00",
"output": "1"
},
{
"input": "5\n01 06",
"output": "86"
},
{
"input": "2\n00 08",
"output": "185"
},
{
"input": "3\n18 03",
"output": "2"
},
{
"input": "1\n17 00",
"output": "0"
},
{
"input": "59\n00 48",
"output": "7"
},
{
"input": "5\n12 01",
"output": "49"
},
{
"input": "55\n01 25",
"output": "9"
},
{
"input": "2\n07 23",
"output": "0"
},
{
"input": "10\n01 10",
"output": "44"
},
{
"input": "2\n00 01",
"output": "2"
},
{
"input": "59\n00 01",
"output": "6"
},
{
"input": "5\n00 02",
"output": "1"
},
{
"input": "4\n01 02",
"output": "106"
},
{
"input": "5\n00 06",
"output": "74"
},
{
"input": "42\n00 08",
"output": "9"
},
{
"input": "60\n01 20",
"output": "8"
},
{
"input": "3\n06 00",
"output": "1"
},
{
"input": "4\n00 01",
"output": "1"
},
{
"input": "2\n00 06",
"output": "184"
},
{
"input": "1\n00 57",
"output": "0"
},
{
"input": "6\n00 00",
"output": "61"
},
{
"input": "5\n08 40",
"output": "9"
},
{
"input": "58\n00 55",
"output": "1"
},
{
"input": "2\n00 02",
"output": "182"
},
{
"input": "1\n08 01",
"output": "2"
},
{
"input": "10\n10 10",
"output": "14"
},
{
"input": "60\n01 11",
"output": "8"
},
{
"input": "2\n07 00",
"output": "0"
},
{
"input": "15\n00 03",
"output": "25"
},
{
"input": "6\n04 34",
"output": "106"
},
{
"input": "16\n00 16",
"output": "24"
},
{
"input": "2\n00 59",
"output": "1"
},
{
"input": "59\n00 08",
"output": "7"
},
{
"input": "10\n03 10",
"output": "56"
},
{
"input": "3\n08 03",
"output": "2"
},
{
"input": "20\n06 11",
"output": "37"
},
{
"input": "4\n01 00",
"output": "106"
},
{
"input": "38\n01 08",
"output": "12"
},
{
"input": "60\n00 06",
"output": "7"
},
{
"input": "5\n12 00",
"output": "49"
},
{
"input": "6\n01 42",
"output": "78"
},
{
"input": "4\n00 04",
"output": "92"
},
{
"input": "60\n04 05",
"output": "11"
},
{
"input": "1\n00 53",
"output": "6"
},
{
"input": "5\n08 05",
"output": "2"
},
{
"input": "60\n18 45",
"output": "1"
},
{
"input": "60\n06 23",
"output": "13"
},
{
"input": "6\n00 15",
"output": "3"
},
{
"input": "58\n00 06",
"output": "7"
},
{
"input": "2\n06 44",
"output": "383"
},
{
"input": "1\n08 00",
"output": "1"
},
{
"input": "10\n06 58",
"output": "78"
},
{
"input": "59\n00 58",
"output": "8"
},
{
"input": "1\n18 00",
"output": "1"
},
{
"input": "50\n00 42",
"output": "9"
},
{
"input": "30\n18 30",
"output": "2"
},
{
"input": "60\n21 59",
"output": "4"
},
{
"input": "2\n10 52",
"output": "87"
},
{
"input": "56\n00 00",
"output": "7"
},
{
"input": "16\n18 16",
"output": "2"
},
{
"input": "5\n01 05",
"output": "86"
},
{
"input": "5\n05 00",
"output": "133"
},
{
"input": "5\n23 59",
"output": "72"
},
{
"input": "7\n17 13",
"output": "0"
},
{
"input": "58\n00 00",
"output": "7"
},
{
"input": "15\n00 07",
"output": "0"
},
{
"input": "59\n08 00",
"output": "1"
},
{
"input": "46\n00 00",
"output": "8"
},
{
"input": "59\n01 05",
"output": "2"
},
{
"input": "2\n01 00",
"output": "211"
},
{
"input": "60\n00 24",
"output": "7"
},
{
"input": "10\n00 08",
"output": "37"
},
{
"input": "10\n00 06",
"output": "37"
},
{
"input": "60\n01 24",
"output": "8"
},
{
"input": "50\n00 10",
"output": "8"
},
{
"input": "2\n03 00",
"output": "271"
},
{
"input": "4\n19 04",
"output": "17"
},
{
"input": "25\n00 23",
"output": "16"
},
{
"input": "10\n01 01",
"output": "43"
}
] | 1,617,269,633 | 2,147,483,647 | PyPy 3 | OK | TESTS | 254 | 156 | 4,710,400 | import datetime
n = int(input())
a , b = input().split()
x = datetime.timedelta(hours= int(a) , minutes=int(b))
c = 0
while '7' not in str(x):
x -= datetime.timedelta(hours= 0 , minutes=n)
c +=1
print(c) | Title: Jamie and Alarm Snooze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button.
A time is considered lucky if it contains a digit '7'. For example, 13:<=07 and 17:<=27 are lucky, while 00:<=48 and 21:<=34 are not lucky.
Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at *hh*:<=*mm*.
Formally, find the smallest possible non-negative integer *y* such that the time representation of the time *x*·*y* minutes before *hh*:<=*mm* contains the digit '7'.
Jamie uses 24-hours clock, so after 23:<=59 comes 00:<=00.
Input Specification:
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60).
The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59).
Output Specification:
Print the minimum number of times he needs to press the button.
Demo Input:
['3\n11 23\n', '5\n01 07\n']
Demo Output:
['2\n', '0\n']
Note:
In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.
In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky. | ```python
import datetime
n = int(input())
a , b = input().split()
x = datetime.timedelta(hours= int(a) , minutes=int(b))
c = 0
while '7' not in str(x):
x -= datetime.timedelta(hours= 0 , minutes=n)
c +=1
print(c)
``` | 3 |
|
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds.
Determine if Pig can visit the friend using teleports only, or he should use his car. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*). | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You can see that there is no path from Pig's house to his friend's house that uses only teleports. | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 8\n8 8\n9 9\n9 9\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 100\n71 73\n80 94\n81 92\n84 85\n85 100\n88 91\n91 95\n92 98\n92 98\n99 100\n100 100",
"output": "YES"
},
{
"input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 6\n1 6\n1 2\n1 3\n1 2\n1 3\n2 5\n2 4\n2 3\n2 4\n2 6\n2 2\n2 5\n2 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 9\n3 3\n3 7\n3 9\n3 3\n3 9\n4 6\n4 7\n4 5\n4 7\n5 8\n5 5\n5 9\n5 7\n5 5\n6 6\n6 9\n6 7\n6 8\n6 9\n6 8\n7 7\n7 8\n7 7\n7 8\n8 9\n8 8\n8 9\n8 8\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 10\n8 10\n9 9\n9 9\n10 10\n10 10",
"output": "YES"
},
{
"input": "50 100\n0 95\n1 100\n1 38\n2 82\n5 35\n7 71\n8 53\n11 49\n15 27\n17 84\n17 75\n18 99\n18 43\n18 69\n21 89\n27 60\n27 29\n38 62\n38 77\n39 83\n40 66\n48 80\n48 100\n50 51\n50 61\n53 77\n53 63\n55 58\n56 68\n60 82\n62 95\n66 74\n67 83\n69 88\n69 81\n69 88\n69 98\n70 91\n70 76\n71 90\n72 99\n81 99\n85 87\n88 97\n88 93\n90 97\n90 97\n92 98\n98 99\n100 100",
"output": "YES"
},
{
"input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 10\n1 9\n1 6\n1 2\n1 3\n1 2\n2 6\n2 5\n2 4\n2 3\n2 10\n2 2\n2 6\n2 2\n3 10\n3 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 10\n3 5\n3 3\n3 7\n4 8\n4 8\n4 9\n4 6\n5 7\n5 10\n5 7\n5 8\n5 5\n6 8\n6 9\n6 10\n6 6\n6 9\n6 7\n7 8\n7 9\n7 10\n7 10\n8 8\n8 8\n8 9\n8 10\n9 10\n9 9\n9 10\n9 10\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 4\n1 5\n1 9\n1 1\n1 6\n1 6\n2 5\n2 7\n2 7\n2 7\n2 7\n3 4\n3 7\n3 9\n3 5\n3 3\n4 4\n4 6\n4 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n5 8\n5 9\n5 8\n6 8\n6 7\n6 8\n6 9\n6 9\n6 6\n6 9\n6 7\n7 7\n7 7\n7 7\n7 8\n7 7\n7 8\n7 8\n7 9\n8 8\n8 8\n8 8\n8 8\n8 8\n8 9\n8 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 40\n38 38\n40 40",
"output": "NO"
},
{
"input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 92\n92 97\n96 99\n97 98\n97 99\n99 99\n100 100\n100 100\n100 100",
"output": "NO"
},
{
"input": "1 10\n0 10",
"output": "YES"
},
{
"input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 40\n23 23\n23 28\n24 29\n25 38\n26 35\n27 37\n28 39\n28 33\n28 40\n28 33\n29 31\n29 33\n30 38\n30 36\n30 30\n30 38\n31 37\n31 35\n31 32\n31 36\n33 39\n33 40\n35 38\n36 38\n37 38\n37 40\n38 39\n38 40\n38 39\n39 39\n39 40\n40 40\n40 40\n40 40\n40 40",
"output": "YES"
},
{
"input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 40\n11 31\n12 26\n13 25\n14 32\n17 19\n21 29\n22 36\n24 27\n25 39\n25 27\n27 32\n27 29\n27 39\n27 29\n28 38\n30 38\n32 40\n32 38\n33 33\n33 40\n34 35\n34 34\n34 38\n34 38\n35 37\n36 39\n36 39\n37 37\n38 40\n39 39\n40 40",
"output": "YES"
},
{
"input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 22\n23 28\n23 39\n24 24\n25 27\n26 38\n27 39\n28 33\n28 39\n28 34\n28 33\n29 30\n29 35\n30 30\n30 38\n30 34\n30 31\n31 36\n31 31\n31 32\n31 38\n33 34\n33 34\n35 36\n36 38\n37 38\n37 39\n38 38\n38 38\n38 38\n39 39\n39 39\n40 40\n40 40\n40 40\n40 40",
"output": "NO"
},
{
"input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n88 99",
"output": "NO"
},
{
"input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 10\n7 10\n9 10",
"output": "NO"
},
{
"input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 5\n4 8\n5 5\n5 7\n6 7\n6 6\n7 7\n7 7\n7 7\n7 8\n7 8\n8 8\n8 8\n8 9\n8 8\n8 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n32 37",
"output": "NO"
},
{
"input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 10\n4 6\n5 9\n5 5\n6 7\n6 10\n7 8\n7 7\n7 7\n7 7\n7 10\n8 8\n8 8\n8 10\n8 8\n8 8\n9 10\n9 10\n9 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "1 1\n0 1",
"output": "YES"
},
{
"input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 36\n38 38\n40 40",
"output": "NO"
},
{
"input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 82\n71 94\n80 90\n81 88\n84 93\n85 89\n88 92\n91 97\n92 99\n92 97\n99 99\n100 100",
"output": "NO"
},
{
"input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n79 100",
"output": "YES"
},
{
"input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n37 40",
"output": "YES"
},
{
"input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 10\n1 2\n1 5\n1 10\n1 8\n1 1\n2 8\n2 7\n2 5\n2 5\n2 7\n3 5\n3 7\n3 5\n3 4\n3 7\n4 7\n4 8\n4 6\n5 7\n5 10\n5 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n6 10\n6 9\n6 7\n6 10\n6 8\n6 7\n6 10\n6 10\n7 8\n7 9\n7 8\n7 8\n7 8\n7 8\n7 7\n7 7\n8 8\n8 8\n8 10\n8 9\n8 9\n8 9\n8 9\n9 9\n9 10\n9 9\n9 9\n9 9\n9 9\n9 10\n9 10\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "50 100\n0 95\n1 7\n1 69\n2 83\n5 67\n7 82\n8 31\n11 25\n15 44\n17 75\n17 27\n18 43\n18 69\n18 40\n21 66\n27 29\n27 64\n38 77\n38 90\n39 52\n40 60\n48 91\n48 98\n50 89\n50 63\n53 54\n53 95\n55 76\n56 59\n60 96\n62 86\n66 70\n67 77\n69 88\n69 98\n69 80\n69 95\n70 74\n70 77\n71 99\n72 73\n81 87\n85 99\n88 96\n88 91\n90 97\n90 99\n92 92\n98 99\n100 100",
"output": "NO"
},
{
"input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 35\n11 23\n12 36\n13 31\n14 31\n17 17\n21 25\n22 33\n24 26\n25 32\n25 25\n27 39\n27 29\n27 34\n27 32\n28 34\n30 36\n32 37\n32 33\n33 35\n33 33\n34 38\n34 38\n34 36\n34 36\n35 36\n36 36\n36 39\n37 37\n38 39\n39 39\n40 40",
"output": "NO"
},
{
"input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 9\n7 7\n9 9",
"output": "NO"
},
{
"input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 100\n92 97\n96 96\n97 98\n97 100\n99 100\n100 100\n100 100\n100 100",
"output": "YES"
},
{
"input": "2 2\n0 2\n0 1",
"output": "YES"
},
{
"input": "2 100\n0 49\n50 100",
"output": "NO"
},
{
"input": "2 100\n0 50\n50 100",
"output": "YES"
},
{
"input": "10 100\n0 10\n10 20\n20 30\n30 40\n40 50\n50 60\n60 70\n70 80\n80 90\n90 100",
"output": "YES"
},
{
"input": "100 10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 10",
"output": "YES"
},
{
"input": "1 4\n1 4",
"output": "NO"
},
{
"input": "3 5\n0 2\n2 5\n3 4",
"output": "YES"
},
{
"input": "2 5\n0 5\n1 2",
"output": "YES"
},
{
"input": "5 5\n0 2\n0 2\n3 5\n3 5\n3 5",
"output": "NO"
},
{
"input": "4 10\n0 3\n2 10\n4 10\n5 7",
"output": "YES"
},
{
"input": "3 8\n0 0\n1 8\n2 8",
"output": "NO"
},
{
"input": "6 8\n0 3\n1 5\n2 3\n5 6\n6 7\n7 8",
"output": "YES"
}
] | 1,513,750,980 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 5,529,600 | x = input().split()
tel = int(x[0])
target = int(x[1])
join = True
prev = 0
for i in range(tel):
y = input().split()
now = int(y[0])
if now > prev:
join = False
prev = int(y[1])
if join == True and prev >= target:
print("YES")
else:
print("NO")
| Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds.
Determine if Pig can visit the friend using teleports only, or he should use his car.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*).
Output Specification:
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower).
Demo Input:
['3 5\n0 2\n2 4\n3 5\n', '3 7\n0 4\n2 5\n6 7\n']
Demo Output:
['YES\n', 'NO\n']
Note:
The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You can see that there is no path from Pig's house to his friend's house that uses only teleports. | ```python
x = input().split()
tel = int(x[0])
target = int(x[1])
join = True
prev = 0
for i in range(tel):
y = input().split()
now = int(y[0])
if now > prev:
join = False
prev = int(y[1])
if join == True and prev >= target:
print("YES")
else:
print("NO")
``` | 0 |
|
821 | A | Okabe and Future Gadget Laboratory | PROGRAMMING | 800 | [
"implementation"
] | null | null | Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every *x*,<=*y* such that 1<=≤<=*x*,<=*y*<=≤<=*n* and *a**x*,<=*y*<=≠<=1, there should exist two indices *s* and *t* so that *a**x*,<=*y*<==<=*a**x*,<=*s*<=+<=*a**t*,<=*y*, where *a**i*,<=*j* denotes the integer in *i*-th row and *j*-th column.
Help Okabe determine whether a given lab is good! | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=50) — the size of the lab.
The next *n* lines contain *n* space-separated integers denoting a row of the grid. The *j*-th integer in the *i*-th row is *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=105). | Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case. | [
"3\n1 1 2\n2 3 1\n6 4 1\n",
"3\n1 5 2\n1 1 1\n1 2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".
In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is "No". | 500 | [
{
"input": "3\n1 1 2\n2 3 1\n6 4 1",
"output": "Yes"
},
{
"input": "3\n1 5 2\n1 1 1\n1 2 3",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 11 1 2\n2 5 1 4\n3 9 4 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 7 1 1\n1 3 1 2\n2 6 3 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 12 1 2\n4 4 1 3\n5 10 6 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 13 1 2\n4 5 1 3\n5 11 6 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 13 1 2\n4 5 1 3\n7 11 6 1",
"output": "No"
},
{
"input": "4\n1 1 1 1\n1 14 1 6\n4 5 1 5\n3 8 2 1",
"output": "Yes"
},
{
"input": "10\n3 2 6 5 1 2 1 1 2 1\n1 2 2 3 1 4 1 1 1 1\n1 1 3 1 2 2 2 1 1 1\n1 3 1 2 1 2 1 1 1 1\n12 1 4 3 3 1 1 1 2 1\n8 1 1 1 1 3 6 5 1 3\n1 1 1 2 4 1 3 2 1 1\n1 1 1 1 1 1 1 2 1 1\n1 2 1 1 1 1 1 1 1 1\n2 1 1 1 1 1 1 1 1 2",
"output": "Yes"
},
{
"input": "4\n1 2 3 5\n1 1 1 1\n1 1 1 1\n1 1 1 1",
"output": "No"
},
{
"input": "1\n2",
"output": "No"
},
{
"input": "3\n1 1 4\n1 1 2\n1 1 2",
"output": "No"
},
{
"input": "1\n5",
"output": "No"
},
{
"input": "3\n1 2 1\n2 2 3\n1 3 1",
"output": "No"
},
{
"input": "3\n2 1 1\n2 1 1\n2 1 1",
"output": "No"
},
{
"input": "1\n60000",
"output": "No"
}
] | 1,579,283,951 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 109 | 307,200 | n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
flag=0
for i in range(n):
for j in range(n):
if( l[i][j]==1 )or any(l[i][j]-l[x][j] in l[i] for x in range(n)):
continue
else:
print('No')
flag=1
break
if(flag==1):
break
else:
print('Yes')
| Title: Okabe and Future Gadget Laboratory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every *x*,<=*y* such that 1<=≤<=*x*,<=*y*<=≤<=*n* and *a**x*,<=*y*<=≠<=1, there should exist two indices *s* and *t* so that *a**x*,<=*y*<==<=*a**x*,<=*s*<=+<=*a**t*,<=*y*, where *a**i*,<=*j* denotes the integer in *i*-th row and *j*-th column.
Help Okabe determine whether a given lab is good!
Input Specification:
The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=50) — the size of the lab.
The next *n* lines contain *n* space-separated integers denoting a row of the grid. The *j*-th integer in the *i*-th row is *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=105).
Output Specification:
Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case.
Demo Input:
['3\n1 1 2\n2 3 1\n6 4 1\n', '3\n1 5 2\n1 1 1\n1 2 3\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".
In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is "No". | ```python
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
flag=0
for i in range(n):
for j in range(n):
if( l[i][j]==1 )or any(l[i][j]-l[x][j] in l[i] for x in range(n)):
continue
else:
print('No')
flag=1
break
if(flag==1):
break
else:
print('Yes')
``` | 3 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,686,053,705 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = int(input())
sum1 = sum2 = sum3 = 0
for _ in range(n):
row = list(map(int,input().split()))
sum1 += row[0]
sum2 += row[1]
sum3 += row[2]
if sum1==0 or sum2==0 or sum3==0:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n = int(input())
sum1 = sum2 = sum3 = 0
for _ in range(n):
row = list(map(int,input().split()))
sum1 += row[0]
sum2 += row[1]
sum3 += row[2]
if sum1==0 or sum2==0 or sum3==0:
print("YES")
else:
print("NO")
``` | 0 |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows:
- If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*).
The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order. | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"input": "7",
"output": "7 1 2 3 4 5 6 "
},
{
"input": "1000",
"output": "1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "999",
"output": "999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "998",
"output": "998 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "997",
"output": "997 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "900",
"output": "900 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "101",
"output": "101 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "67",
"output": "67 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 "
},
{
"input": "779",
"output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "195",
"output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "907",
"output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "971",
"output": "971 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "683",
"output": "683 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "99",
"output": "99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 "
},
{
"input": "811",
"output": "811 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "875",
"output": "875 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "291",
"output": "291 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "419",
"output": "419 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "779",
"output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "195",
"output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "907",
"output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "21",
"output": "21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 "
},
{
"input": "22",
"output": "22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 "
},
{
"input": "23",
"output": "23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 "
},
{
"input": "24",
"output": "24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 "
},
{
"input": "25",
"output": "25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 "
}
] | 1,645,195,420 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 186 | 1,433,600 | # Bismillahir Rahmanir Rahim
# Abu Hurayra - Handle: HurayraIIT
import sys
import math
def mp(): return map(int, sys.stdin.readline().split())
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
#a = list(map(int, input().split()))
def main():
n = ri()
if n==1:
print("1")
return
elif n==2:
print("2 1")
return
print(n, end=" ")
for i in range(1,n):
print(i, end=" ")
print()
if __name__ == '__main__':
t = 1
for _ in range(t):
main()
| Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows:
- If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*).
The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order.
Input Specification:
A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation.
Output Specification:
In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists.
Demo Input:
['1\n', '2\n']
Demo Output:
['1 ', '2 1 ']
Note:
none | ```python
# Bismillahir Rahmanir Rahim
# Abu Hurayra - Handle: HurayraIIT
import sys
import math
def mp(): return map(int, sys.stdin.readline().split())
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
#a = list(map(int, input().split()))
def main():
n = ri()
if n==1:
print("1")
return
elif n==2:
print("2 1")
return
print(n, end=" ")
for i in range(1,n):
print(i, end=" ")
print()
if __name__ == '__main__':
t = 1
for _ in range(t):
main()
``` | 3 |
|
994 | B | Knights of a Polygonal Table | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than $k$ other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins.
Now each knight ponders: how many coins he can have if only he kills other knights?
You should answer this question for each knight. | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n$ integers $c_1, c_2 ,\ldots,c_n$ $(0 \le c_i \le 10^9)$ — the number of coins each knight has. | Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is optimal to kill the second and the fourth knights: $2+11+33 = 46$. - The fourth knight should kill the first and the second knights: $33+1+2 = 36$.
In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own.
In the third example there is only one knight, so he can't kill anyone. | 1,000 | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input": "7 2\n2 4 6 7 8 9 10\n10 8 4 8 4 5 9",
"output": "10 18 22 26 22 23 27 "
},
{
"input": "11 10\n1 2 3 4 5 6 7 8 9 10 11\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1000000000 2000000000 3000000000 4000000000 5000000000 6000000000 7000000000 8000000000 9000000000 10000000000 11000000000 "
},
{
"input": "2 0\n2 3\n3 3",
"output": "3 3 "
},
{
"input": "7 3\n1 2 3 4 5 6 7\n3 3 3 4 5 6 7",
"output": "3 6 9 13 15 18 22 "
},
{
"input": "3 0\n3 2 1\n1 2 3",
"output": "1 2 3 "
},
{
"input": "5 3\n4 5 7 9 11\n10 10 10 10 10",
"output": "10 20 30 40 40 "
},
{
"input": "4 0\n4 5 9 7\n1 2 11 33",
"output": "1 2 11 33 "
},
{
"input": "7 3\n1 2 3 4 5 6 7\n3 3 3 8 8 8 8",
"output": "3 6 9 17 22 27 32 "
},
{
"input": "3 0\n1 2 3\n5 5 5",
"output": "5 5 5 "
},
{
"input": "4 2\n4 5 9 7\n2 2 11 33",
"output": "2 4 46 37 "
},
{
"input": "6 3\n1 2 3 4 5 6\n1 1 1 1 1 1",
"output": "1 2 3 4 4 4 "
},
{
"input": "10 5\n1 2 3 4 5 6 7 8 9 10\n1 1 1 1 1 1 1 1 1 1",
"output": "1 2 3 4 5 6 6 6 6 6 "
},
{
"input": "3 2\n1 2 3\n1 1 1",
"output": "1 2 3 "
},
{
"input": "3 0\n1 2 3\n10 20 30",
"output": "10 20 30 "
},
{
"input": "4 0\n4 5 9 7\n1 2 3 4",
"output": "1 2 3 4 "
},
{
"input": "5 4\n1 2 3 4 5\n1 1 1 1 1",
"output": "1 2 3 4 5 "
},
{
"input": "4 3\n1 2 3 4\n5 5 5 5",
"output": "5 10 15 20 "
},
{
"input": "5 3\n1 2 3 4 5\n7 7 7 7 7",
"output": "7 14 21 28 28 "
}
] | 1,529,169,672 | 2,772 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 7 | 1,000 | 9,728,000 | n,k = input().split()
n = int(n)
k = int(k)
a = input().split()
b = input().split()
final = ""
for i in range(len(a)):
a[i] = int(a[i])
for i in range(len(b)):
b[i] = int(b[i])
for i in range(n):
ans = b[i]
coins = []
for j in range(n):
if a[i] != a[j]:
if a[j] < a[i]:
coins.append(b[j])
coins.sort(reverse=True)
if len(coins) >= k:
for j in range(k):
ans += coins[j];
else:
for j in coins:
ans += j;
final += str(ans) + " "
print(final) | Title: Knights of a Polygonal Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than $k$ other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins.
Now each knight ponders: how many coins he can have if only he kills other knights?
You should answer this question for each knight.
Input Specification:
The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n$ integers $c_1, c_2 ,\ldots,c_n$ $(0 \le c_i \le 10^9)$ — the number of coins each knight has.
Output Specification:
Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights.
Demo Input:
['4 2\n4 5 9 7\n1 2 11 33\n', '5 1\n1 2 3 4 5\n1 2 3 4 5\n', '1 0\n2\n3\n']
Demo Output:
['1 3 46 36 ', '1 3 5 7 9 ', '3 ']
Note:
Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is optimal to kill the second and the fourth knights: $2+11+33 = 46$. - The fourth knight should kill the first and the second knights: $33+1+2 = 36$.
In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own.
In the third example there is only one knight, so he can't kill anyone. | ```python
n,k = input().split()
n = int(n)
k = int(k)
a = input().split()
b = input().split()
final = ""
for i in range(len(a)):
a[i] = int(a[i])
for i in range(len(b)):
b[i] = int(b[i])
for i in range(n):
ans = b[i]
coins = []
for j in range(n):
if a[i] != a[j]:
if a[j] < a[i]:
coins.append(b[j])
coins.sort(reverse=True)
if len(coins) >= k:
for j in range(k):
ans += coins[j];
else:
for j in coins:
ans += j;
final += str(ans) + " "
print(final)
``` | 0 |
|
571 | C | CNF 2 | PROGRAMMING | 2,500 | [
"constructive algorithms",
"dfs and similar",
"graphs",
"greedy"
] | null | null | 'In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if it is a conjunction of clauses, where a clause is a disjunction of literals' (cited from https://en.wikipedia.org/wiki/Conjunctive_normal_form)
In the other words, CNF is a formula of type , where & represents a logical "AND" (conjunction), represents a logical "OR" (disjunction), and *v**ij* are some boolean variables or their negations. Each statement in brackets is called a clause, and *v**ij* are called literals.
You are given a CNF containing variables *x*1,<=...,<=*x**m* and their negations. We know that each variable occurs in at most two clauses (with negation and without negation in total). Your task is to determine whether this CNF is satisfiable, that is, whether there are such values of variables where the CNF value is true. If CNF is satisfiable, then you also need to determine the values of the variables at which the CNF is true.
It is guaranteed that each variable occurs at most once in each clause. | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of clauses and the number variables, correspondingly.
Next *n* lines contain the descriptions of each clause. The *i*-th line first contains first number *k**i* (*k**i*<=≥<=1) — the number of literals in the *i*-th clauses. Then follow space-separated literals *v**ij* (1<=≤<=|*v**ij*|<=≤<=*m*). A literal that corresponds to *v**ij* is *x*|*v**ij*| either with negation, if *v**ij* is negative, or without negation otherwise. | If CNF is not satisfiable, print a single line "NO" (without the quotes), otherwise print two strings: string "YES" (without the quotes), and then a string of *m* numbers zero or one — the values of variables in satisfying assignment in the order from *x*1 to *x**m*. | [
"2 2\n2 1 -2\n2 2 -1\n",
"4 3\n1 1\n1 2\n3 -1 -2 3\n1 -3\n",
"5 6\n2 1 2\n3 1 -2 3\n4 -3 5 4 6\n2 -6 -4\n1 5\n"
] | [
"YES\n11\n",
"NO\n",
"YES\n100010\n"
] | In the first sample test formula is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5a8654a57efa13b47a585b7998c9defb42712ded.png" style="max-width: 100.0%;max-height: 100.0%;"/>. One of possible answer is *x*<sub class="lower-index">1</sub> = *TRUE*, *x*<sub class="lower-index">2</sub> = *TRUE*. | 1,500 | [] | 1,441,689,853 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 38,092,800 | from itertools import *
ent=input()
n=int(ent.split()[0])
m=int(ent.split()[1])
form=[]
for i in range (n):
ent=input()
k=int(ent.split()[0])
claus=[]
for i in range (1,k+1):
claus.append(int(ent.split()[i]))
form.append(claus)
#print(form)
def noref(formula):
formul=[]
for i in range (len(formula)):
t=[]
for j in range(len(formula[i])):
t.append(formula[i][j])
formul.append(t)
return(formul)
def sat(formula,asignacion):
n=len(formula)
formul= noref(formula)
#print("asignacion: ",asignacion)
sat=[0]*n
for i in range (n):
for j in range (len(formul[i])):
if formul[i][j]<0:
#print(formula[i][j])
x=abs(formul[i][j])
#print(x)
t=asignacion[x-1]
formul[i][j]=abs(t-1)
else:
formul[i][j]=asignacion[formul[i][j]-1]
#print(formul)
for i in range (n):
for j in range(len(formul[i])):
if formul[i][j]==1:
sat[i]=1
break
#print(sat)
for i in range (n):
if sat[i]==0:
#print("igual a 0: ")
return False
return (True)
#asignacion=[1,1]
#print(sat(form,asignacion))
resp=[]
#print("resp: ",len(resp))
for asignacion in product(range(2),repeat=m):
if sat(form,asignacion)==True:
resp=asignacion
break
if len(resp)>0:
salida=""
for i in range(len(resp)):
salida=salida+str(resp[i])
print("YES")
print(salida)
else:
print("NO")
| Title: CNF 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
'In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if it is a conjunction of clauses, where a clause is a disjunction of literals' (cited from https://en.wikipedia.org/wiki/Conjunctive_normal_form)
In the other words, CNF is a formula of type , where & represents a logical "AND" (conjunction), represents a logical "OR" (disjunction), and *v**ij* are some boolean variables or their negations. Each statement in brackets is called a clause, and *v**ij* are called literals.
You are given a CNF containing variables *x*1,<=...,<=*x**m* and their negations. We know that each variable occurs in at most two clauses (with negation and without negation in total). Your task is to determine whether this CNF is satisfiable, that is, whether there are such values of variables where the CNF value is true. If CNF is satisfiable, then you also need to determine the values of the variables at which the CNF is true.
It is guaranteed that each variable occurs at most once in each clause.
Input Specification:
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of clauses and the number variables, correspondingly.
Next *n* lines contain the descriptions of each clause. The *i*-th line first contains first number *k**i* (*k**i*<=≥<=1) — the number of literals in the *i*-th clauses. Then follow space-separated literals *v**ij* (1<=≤<=|*v**ij*|<=≤<=*m*). A literal that corresponds to *v**ij* is *x*|*v**ij*| either with negation, if *v**ij* is negative, or without negation otherwise.
Output Specification:
If CNF is not satisfiable, print a single line "NO" (without the quotes), otherwise print two strings: string "YES" (without the quotes), and then a string of *m* numbers zero or one — the values of variables in satisfying assignment in the order from *x*1 to *x**m*.
Demo Input:
['2 2\n2 1 -2\n2 2 -1\n', '4 3\n1 1\n1 2\n3 -1 -2 3\n1 -3\n', '5 6\n2 1 2\n3 1 -2 3\n4 -3 5 4 6\n2 -6 -4\n1 5\n']
Demo Output:
['YES\n11\n', 'NO\n', 'YES\n100010\n']
Note:
In the first sample test formula is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5a8654a57efa13b47a585b7998c9defb42712ded.png" style="max-width: 100.0%;max-height: 100.0%;"/>. One of possible answer is *x*<sub class="lower-index">1</sub> = *TRUE*, *x*<sub class="lower-index">2</sub> = *TRUE*. | ```python
from itertools import *
ent=input()
n=int(ent.split()[0])
m=int(ent.split()[1])
form=[]
for i in range (n):
ent=input()
k=int(ent.split()[0])
claus=[]
for i in range (1,k+1):
claus.append(int(ent.split()[i]))
form.append(claus)
#print(form)
def noref(formula):
formul=[]
for i in range (len(formula)):
t=[]
for j in range(len(formula[i])):
t.append(formula[i][j])
formul.append(t)
return(formul)
def sat(formula,asignacion):
n=len(formula)
formul= noref(formula)
#print("asignacion: ",asignacion)
sat=[0]*n
for i in range (n):
for j in range (len(formul[i])):
if formul[i][j]<0:
#print(formula[i][j])
x=abs(formul[i][j])
#print(x)
t=asignacion[x-1]
formul[i][j]=abs(t-1)
else:
formul[i][j]=asignacion[formul[i][j]-1]
#print(formul)
for i in range (n):
for j in range(len(formul[i])):
if formul[i][j]==1:
sat[i]=1
break
#print(sat)
for i in range (n):
if sat[i]==0:
#print("igual a 0: ")
return False
return (True)
#asignacion=[1,1]
#print(sat(form,asignacion))
resp=[]
#print("resp: ",len(resp))
for asignacion in product(range(2),repeat=m):
if sat(form,asignacion)==True:
resp=asignacion
break
if len(resp)>0:
salida=""
for i in range(len(resp)):
salida=salida+str(resp[i])
print("YES")
print(salida)
else:
print("NO")
``` | 0 |
|
342 | C | Cupboard and Balloons | PROGRAMMING | 1,900 | [
"geometry"
] | null | null | A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius *r* (the cupboard's top) and two walls of height *h* (the cupboard's sides). The cupboard's depth is *r*, that is, it looks like a rectangle with base *r* and height *h*<=+<=*r* from the sides. The figure below shows what the cupboard looks like (the front view is on the left, the side view is on the right).
Xenia got lots of balloons for her birthday. The girl hates the mess, so she wants to store the balloons in the cupboard. Luckily, each balloon is a sphere with radius . Help Xenia calculate the maximum number of balloons she can put in her cupboard.
You can say that a balloon is in the cupboard if you can't see any part of the balloon on the left or right view. The balloons in the cupboard can touch each other. It is not allowed to squeeze the balloons or deform them in any way. You can assume that the cupboard's walls are negligibly thin. | The single line contains two integers *r*,<=*h* (1<=≤<=*r*,<=*h*<=≤<=107). | Print a single integer — the maximum number of balloons Xenia can put in the cupboard. | [
"1 1\n",
"1 2\n",
"2 1\n"
] | [
"3\n",
"5\n",
"2\n"
] | none | 1,500 | [
{
"input": "1 1",
"output": "3"
},
{
"input": "1 2",
"output": "5"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "2 3",
"output": "4"
},
{
"input": "4 1",
"output": "1"
},
{
"input": "5 1",
"output": "1"
},
{
"input": "5 2",
"output": "1"
},
{
"input": "5 3",
"output": "2"
},
{
"input": "5 4",
"output": "2"
},
{
"input": "5 5",
"output": "3"
},
{
"input": "5 6",
"output": "3"
},
{
"input": "5 9",
"output": "4"
},
{
"input": "5 10",
"output": "5"
},
{
"input": "5 11",
"output": "5"
},
{
"input": "674098 1358794",
"output": "5"
},
{
"input": "3983458 7761504",
"output": "5"
},
{
"input": "4841874 9131511",
"output": "5"
},
{
"input": "667586 5534221",
"output": "17"
},
{
"input": "1526002 6904227",
"output": "10"
},
{
"input": "4835362 5823289",
"output": "3"
},
{
"input": "5693778 7001807",
"output": "3"
},
{
"input": "6552194 8371814",
"output": "3"
},
{
"input": "2377906 4774524",
"output": "5"
},
{
"input": "4365659 4738707",
"output": "3"
},
{
"input": "98 1358794",
"output": "27731"
},
{
"input": "458 7761504",
"output": "33894"
},
{
"input": "874 9131511",
"output": "20897"
},
{
"input": "586 5534221",
"output": "18889"
},
{
"input": "2 6904227",
"output": "6904228"
},
{
"input": "1 10000000",
"output": "20000001"
},
{
"input": "2 10000000",
"output": "10000001"
},
{
"input": "3 10000000",
"output": "6666667"
},
{
"input": "4 10000000",
"output": "5000001"
},
{
"input": "3 9999999",
"output": "6666667"
},
{
"input": "10000000 866254",
"output": "1"
},
{
"input": "10000000 8660255",
"output": "3"
},
{
"input": "100 50",
"output": "2"
},
{
"input": "100 49",
"output": "1"
},
{
"input": "100 199",
"output": "5"
},
{
"input": "8 7",
"output": "3"
},
{
"input": "10000 9999",
"output": "3"
},
{
"input": "1000000 1999999",
"output": "5"
},
{
"input": "2000000 1999999",
"output": "3"
},
{
"input": "18 16",
"output": "3"
},
{
"input": "100 87",
"output": "3"
},
{
"input": "10 19",
"output": "5"
},
{
"input": "10000 38661",
"output": "9"
}
] | 1,380,005,207 | 1,907 | Python 3 | OK | TESTS | 48 | 124 | 0 | r, h = map(int, input().split())
a = 1 + 2 * h // r
if h % r >=3 ** 0.5 * r / 2:
a += 1
print(a)
| Title: Cupboard and Balloons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius *r* (the cupboard's top) and two walls of height *h* (the cupboard's sides). The cupboard's depth is *r*, that is, it looks like a rectangle with base *r* and height *h*<=+<=*r* from the sides. The figure below shows what the cupboard looks like (the front view is on the left, the side view is on the right).
Xenia got lots of balloons for her birthday. The girl hates the mess, so she wants to store the balloons in the cupboard. Luckily, each balloon is a sphere with radius . Help Xenia calculate the maximum number of balloons she can put in her cupboard.
You can say that a balloon is in the cupboard if you can't see any part of the balloon on the left or right view. The balloons in the cupboard can touch each other. It is not allowed to squeeze the balloons or deform them in any way. You can assume that the cupboard's walls are negligibly thin.
Input Specification:
The single line contains two integers *r*,<=*h* (1<=≤<=*r*,<=*h*<=≤<=107).
Output Specification:
Print a single integer — the maximum number of balloons Xenia can put in the cupboard.
Demo Input:
['1 1\n', '1 2\n', '2 1\n']
Demo Output:
['3\n', '5\n', '2\n']
Note:
none | ```python
r, h = map(int, input().split())
a = 1 + 2 * h // r
if h % r >=3 ** 0.5 * r / 2:
a += 1
print(a)
``` | 3 |
|
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv",
"output": "NO"
},
{
"input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "YES"
},
{
"input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod",
"output": "NO"
},
{
"input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl",
"output": "YES"
},
{
"input": "18 6\njzwtnkvmscqhmdlsxy",
"output": "YES"
},
{
"input": "21 2\nfscegcqgzesefghhwcexs",
"output": "NO"
},
{
"input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc",
"output": "YES"
},
{
"input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd",
"output": "YES"
},
{
"input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv",
"output": "YES"
},
{
"input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul",
"output": "YES"
},
{
"input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii",
"output": "NO"
},
{
"input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq",
"output": "YES"
},
{
"input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb",
"output": "YES"
},
{
"input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc",
"output": "YES"
},
{
"input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab",
"output": "YES"
},
{
"input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia",
"output": "NO"
},
{
"input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf",
"output": "YES"
},
{
"input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb",
"output": "YES"
},
{
"input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa",
"output": "NO"
},
{
"input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo",
"output": "YES"
},
{
"input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib",
"output": "YES"
},
{
"input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf",
"output": "YES"
},
{
"input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci",
"output": "YES"
},
{
"input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn",
"output": "YES"
},
{
"input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev",
"output": "YES"
},
{
"input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss",
"output": "YES"
},
{
"input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs",
"output": "NO"
},
{
"input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc",
"output": "NO"
},
{
"input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi",
"output": "NO"
},
{
"input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah",
"output": "NO"
},
{
"input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka",
"output": "YES"
},
{
"input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq",
"output": "YES"
},
{
"input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb",
"output": "YES"
},
{
"input": "14 5\nfssmmsfffmfmmm",
"output": "NO"
},
{
"input": "2 1\nff",
"output": "NO"
},
{
"input": "2 1\nhw",
"output": "YES"
},
{
"input": "2 2\nss",
"output": "YES"
},
{
"input": "1 1\nl",
"output": "YES"
},
{
"input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp",
"output": "YES"
},
{
"input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj",
"output": "YES"
},
{
"input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj",
"output": "YES"
},
{
"input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "YES"
},
{
"input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq",
"output": "YES"
},
{
"input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt",
"output": "YES"
},
{
"input": "1 2\na",
"output": "YES"
},
{
"input": "3 1\nabb",
"output": "NO"
},
{
"input": "2 1\naa",
"output": "NO"
},
{
"input": "2 1\nab",
"output": "YES"
},
{
"input": "6 2\naaaaaa",
"output": "NO"
},
{
"input": "8 4\naaaaaaaa",
"output": "NO"
},
{
"input": "4 2\naaaa",
"output": "NO"
},
{
"input": "4 3\naaaa",
"output": "NO"
},
{
"input": "1 3\na",
"output": "YES"
},
{
"input": "4 3\nzzzz",
"output": "NO"
},
{
"input": "4 1\naaaa",
"output": "NO"
},
{
"input": "3 4\nabc",
"output": "YES"
},
{
"input": "2 5\nab",
"output": "YES"
},
{
"input": "2 4\nab",
"output": "YES"
},
{
"input": "1 10\na",
"output": "YES"
},
{
"input": "5 2\nzzzzz",
"output": "NO"
},
{
"input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO"
},
{
"input": "4 1\nabab",
"output": "NO"
},
{
"input": "4 1\nabcb",
"output": "NO"
},
{
"input": "4 2\nabbb",
"output": "NO"
},
{
"input": "5 2\nabccc",
"output": "NO"
},
{
"input": "2 3\nab",
"output": "YES"
},
{
"input": "4 3\nbbbs",
"output": "YES"
},
{
"input": "10 2\nazzzzzzzzz",
"output": "NO"
},
{
"input": "1 2\nb",
"output": "YES"
},
{
"input": "1 3\nb",
"output": "YES"
},
{
"input": "4 5\nabcd",
"output": "YES"
},
{
"input": "4 6\naabb",
"output": "YES"
},
{
"input": "5 2\naaaab",
"output": "NO"
},
{
"input": "3 5\naaa",
"output": "YES"
},
{
"input": "5 3\nazzzz",
"output": "NO"
},
{
"input": "4 100\naabb",
"output": "YES"
},
{
"input": "3 10\naaa",
"output": "YES"
},
{
"input": "3 4\naaa",
"output": "YES"
},
{
"input": "12 5\naaaaabbbbbbb",
"output": "NO"
},
{
"input": "5 2\naabbb",
"output": "NO"
},
{
"input": "10 5\nzzzzzzzzzz",
"output": "NO"
},
{
"input": "2 4\naa",
"output": "YES"
},
{
"input": "1 5\na",
"output": "YES"
},
{
"input": "10 5\naaaaaaaaaa",
"output": "NO"
},
{
"input": "6 3\naaaaaa",
"output": "NO"
},
{
"input": "7 1\nabcdeee",
"output": "NO"
},
{
"input": "18 3\naaaaaabbbbbbcccccc",
"output": "NO"
},
{
"input": "8 2\naabbccdd",
"output": "YES"
},
{
"input": "4 2\nzzzz",
"output": "NO"
},
{
"input": "4 2\nabaa",
"output": "NO"
},
{
"input": "3 2\naaa",
"output": "NO"
},
{
"input": "3 1\nzzz",
"output": "NO"
},
{
"input": "5 4\nzzzzz",
"output": "NO"
},
{
"input": "6 2\naabbbc",
"output": "NO"
},
{
"input": "3 6\naaa",
"output": "YES"
},
{
"input": "2 1\nzz",
"output": "NO"
},
{
"input": "10 3\naaaeeeeeee",
"output": "NO"
},
{
"input": "4 5\naabb",
"output": "YES"
},
{
"input": "3 1\naaa",
"output": "NO"
},
{
"input": "5 2\naazzz",
"output": "NO"
},
{
"input": "6 2\nabbbbc",
"output": "NO"
},
{
"input": "4 2\nxxxx",
"output": "NO"
},
{
"input": "6 3\nzzzzzz",
"output": "NO"
},
{
"input": "3 2\nabb",
"output": "YES"
},
{
"input": "3 2\nzzz",
"output": "NO"
},
{
"input": "6 5\nzzzzzz",
"output": "NO"
},
{
"input": "6 3\nbcaaaa",
"output": "NO"
},
{
"input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "3 6\nabc",
"output": "YES"
}
] | 1,649,173,592 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | a,b = map(int,input().split())
c = input()
count = [0] * 26
for i in c:
if 'a'<=i<='z':
nomer = ord(i) - 97
count[nomer]+=1
f = 0
d = 0
for i in range(26):
if count[i]>0:
if count[i]!=b:
f +=1
else:
d +=1
if d > f:
print('YES')
else:
print('NO') | Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons.
Output Specification:
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Demo Input:
['4 2\naabb\n', '6 3\naacaab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | ```python
a,b = map(int,input().split())
c = input()
count = [0] * 26
for i in c:
if 'a'<=i<='z':
nomer = ord(i) - 97
count[nomer]+=1
f = 0
d = 0
for i in range(26):
if count[i]>0:
if count[i]!=b:
f +=1
else:
d +=1
if d > f:
print('YES')
else:
print('NO')
``` | 0 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,650,886,328 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | a,b,c=map(int,input().split())
n=a//c;
if (a%c>0):
n=n+1
m=b//c
if (b%c>0):
m=m+1
print(n*m) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
a,b,c=map(int,input().split())
n=a//c;
if (a%c>0):
n=n+1
m=b//c
if (b%c>0):
m=m+1
print(n*m)
``` | 3.9845 |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers. | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
{
"input": "192",
"output": "4 188"
},
{
"input": "86",
"output": "4 82"
},
{
"input": "46220",
"output": "4 46216"
},
{
"input": "57114",
"output": "4 57110"
},
{
"input": "869",
"output": "4 865"
},
{
"input": "738457",
"output": "4 738453"
},
{
"input": "58113",
"output": "6 58107"
},
{
"input": "4864",
"output": "4 4860"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "74752",
"output": "4 74748"
},
{
"input": "6073",
"output": "4 6069"
},
{
"input": "1289",
"output": "4 1285"
},
{
"input": "20",
"output": "4 16"
},
{
"input": "58134",
"output": "4 58130"
},
{
"input": "57756",
"output": "4 57752"
},
{
"input": "765",
"output": "6 759"
},
{
"input": "59",
"output": "4 55"
},
{
"input": "991666",
"output": "4 991662"
},
{
"input": "70761",
"output": "4 70757"
},
{
"input": "13",
"output": "4 9"
},
{
"input": "999999",
"output": "4 999995"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "21",
"output": "6 15"
},
{
"input": "19",
"output": "4 15"
},
{
"input": "100007",
"output": "6 100001"
},
{
"input": "999987",
"output": "6 999981"
},
{
"input": "22",
"output": "4 18"
}
] | 1,684,368,323 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | import sys
input=sys.stdin.readline
n=int(input())
if n%2:
print( 9, n-9 )
else:
print( n//2, n//2 ) | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
Input Specification:
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output Specification:
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
Demo Input:
['12\n', '15\n', '23\n', '1000000\n']
Demo Output:
['4 8\n', '6 9\n', '8 15\n', '500000 500000\n']
Note:
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | ```python
import sys
input=sys.stdin.readline
n=int(input())
if n%2:
print( 9, n-9 )
else:
print( n//2, n//2 )
``` | 0 |
|
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894",
"output": "894"
},
{
"input": "6058 8581",
"output": "8581"
},
{
"input": "97259 41764",
"output": "125292"
},
{
"input": "453145 333625",
"output": "667250"
},
{
"input": "2233224 4394826",
"output": "4394826"
},
{
"input": "76770926 13350712",
"output": "80104272"
},
{
"input": "687355301 142098087",
"output": "710490435"
},
{
"input": "1000000000 999999999",
"output": "1999999998"
},
{
"input": "1000000000 1000000000",
"output": "2000000000"
},
{
"input": "999999999 1000000000",
"output": "1000000000"
},
{
"input": "1000000000 1",
"output": "1000000001"
},
{
"input": "1000000000 2",
"output": "1000000002"
},
{
"input": "999999999 1",
"output": "1000000000"
},
{
"input": "100000000 1",
"output": "100000001"
},
{
"input": "999999999 500000000",
"output": "1000000000"
},
{
"input": "999999990 10",
"output": "1000000000"
},
{
"input": "1000000000 999999997",
"output": "1999999994"
},
{
"input": "999999999 2",
"output": "1000000000"
},
{
"input": "999999984 1",
"output": "999999985"
},
{
"input": "999999983 1",
"output": "999999984"
},
{
"input": "666666666 1",
"output": "666666667"
},
{
"input": "1000000000 990000000",
"output": "1980000000"
},
{
"input": "41 48",
"output": "48"
},
{
"input": "123456 2",
"output": "123458"
},
{
"input": "111 111",
"output": "222"
},
{
"input": "878787 1",
"output": "878788"
},
{
"input": "121 1",
"output": "122"
},
{
"input": "114514 114514",
"output": "229028"
},
{
"input": "500000001 1000000000",
"output": "1000000000"
},
{
"input": "999999997 1",
"output": "999999998"
},
{
"input": "100000000 10",
"output": "100000010"
}
] | 1,623,504,071 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 500 | 0 | n,k = input("").rsplit()
n,k=int(n),int(k)
x =n+1
while x% k !=0:
x+=1
print(x)
| Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
Output Specification:
Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*.
Demo Input:
['5 3\n', '25 13\n', '26 13\n']
Demo Output:
['6\n', '26\n', '39\n']
Note:
none | ```python
n,k = input("").rsplit()
n,k=int(n),int(k)
x =n+1
while x% k !=0:
x+=1
print(x)
``` | 0 |
|
887 | A | Div. 64 | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system. | In the only line given a non-empty binary string *s* with length up to 100. | Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. | [
"100010001\n",
"100\n"
] | [
"yes",
"no"
] | In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | 500 | [
{
"input": "100010001",
"output": "yes"
},
{
"input": "100",
"output": "no"
},
{
"input": "0000001000000",
"output": "yes"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111",
"output": "no"
},
{
"input": "0111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"input": "1111011111111111111111111111110111110111111111111111111111011111111111111110111111111111111111111111",
"output": "no"
},
{
"input": "1111111111101111111111111111111111111011111111111111111111111101111011111101111111111101111111111111",
"output": "yes"
},
{
"input": "0110111111111111111111011111111110110111110111111111111111111111111111111111111110111111111111111111",
"output": "yes"
},
{
"input": "1100110001111011001101101000001110111110011110111110010100011000100101000010010111100000010001001101",
"output": "yes"
},
{
"input": "000000",
"output": "no"
},
{
"input": "0001000",
"output": "no"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "no"
},
{
"input": "1000000",
"output": "yes"
},
{
"input": "0",
"output": "no"
},
{
"input": "1",
"output": "no"
},
{
"input": "10000000000",
"output": "yes"
},
{
"input": "0000000000",
"output": "no"
},
{
"input": "0010000",
"output": "no"
},
{
"input": "000000011",
"output": "no"
},
{
"input": "000000000",
"output": "no"
},
{
"input": "00000000",
"output": "no"
},
{
"input": "000000000011",
"output": "no"
},
{
"input": "0000000",
"output": "no"
},
{
"input": "00000000011",
"output": "no"
},
{
"input": "000000001",
"output": "no"
},
{
"input": "000000000000000000000000000",
"output": "no"
},
{
"input": "0000001",
"output": "no"
},
{
"input": "00000001",
"output": "no"
},
{
"input": "00000000100",
"output": "no"
},
{
"input": "00000000000000000000",
"output": "no"
},
{
"input": "0000000000000000000",
"output": "no"
},
{
"input": "00001000",
"output": "no"
},
{
"input": "0000000000010",
"output": "no"
},
{
"input": "000000000010",
"output": "no"
},
{
"input": "000000000000010",
"output": "no"
},
{
"input": "0100000",
"output": "no"
},
{
"input": "00010000",
"output": "no"
},
{
"input": "00000000000000000",
"output": "no"
},
{
"input": "00000000000",
"output": "no"
},
{
"input": "000001000",
"output": "no"
},
{
"input": "000000000000",
"output": "no"
},
{
"input": "100000000000000",
"output": "yes"
},
{
"input": "000010000",
"output": "no"
},
{
"input": "00000100",
"output": "no"
},
{
"input": "0001100000",
"output": "no"
},
{
"input": "000000000000000000000000001",
"output": "no"
},
{
"input": "000000100",
"output": "no"
},
{
"input": "0000000000001111111111",
"output": "no"
},
{
"input": "00000010",
"output": "no"
},
{
"input": "0001110000",
"output": "no"
},
{
"input": "0000000000000000000000",
"output": "no"
},
{
"input": "000000010010",
"output": "no"
},
{
"input": "0000100",
"output": "no"
},
{
"input": "0000000001",
"output": "no"
},
{
"input": "000000111",
"output": "no"
},
{
"input": "0000000000000",
"output": "no"
},
{
"input": "000000000000000000",
"output": "no"
},
{
"input": "0000000000000000000000000",
"output": "no"
},
{
"input": "000000000000000",
"output": "no"
},
{
"input": "0010000000000100",
"output": "yes"
},
{
"input": "0000001000",
"output": "no"
},
{
"input": "00000000000000000001",
"output": "no"
},
{
"input": "100000000",
"output": "yes"
},
{
"input": "000000000001",
"output": "no"
},
{
"input": "0000011001",
"output": "no"
},
{
"input": "000",
"output": "no"
},
{
"input": "000000000000000000000",
"output": "no"
},
{
"input": "0000000000011",
"output": "no"
},
{
"input": "0000000000000000",
"output": "no"
},
{
"input": "00000000000000001",
"output": "no"
},
{
"input": "00000000000000",
"output": "no"
},
{
"input": "0000000000000000010",
"output": "no"
},
{
"input": "00000000000000000000000000000000000000000000000000000000",
"output": "no"
},
{
"input": "000011000",
"output": "no"
},
{
"input": "00000011",
"output": "no"
},
{
"input": "0000000000001100",
"output": "no"
},
{
"input": "00000",
"output": "no"
},
{
"input": "000000000000000000000000000111111111111111",
"output": "no"
},
{
"input": "000000010",
"output": "no"
},
{
"input": "00000000111",
"output": "no"
},
{
"input": "000000000000001",
"output": "no"
},
{
"input": "0000000000000011111111111111111",
"output": "no"
},
{
"input": "0000000010",
"output": "no"
},
{
"input": "0000000000000000000000000000000000000000000000000",
"output": "no"
},
{
"input": "00000000010",
"output": "no"
},
{
"input": "101000000000",
"output": "yes"
},
{
"input": "00100000",
"output": "no"
},
{
"input": "00000000000001",
"output": "no"
},
{
"input": "0000000000100",
"output": "no"
},
{
"input": "0000",
"output": "no"
},
{
"input": "00000000000111",
"output": "no"
},
{
"input": "0000000000000011",
"output": "no"
},
{
"input": "0000000000000000000000000000000000000000",
"output": "no"
},
{
"input": "0000000000000010",
"output": "no"
},
{
"input": "0010101010",
"output": "no"
},
{
"input": "0000000000000001",
"output": "no"
},
{
"input": "1010101",
"output": "no"
}
] | 1,659,342,097 | 2,147,483,647 | PyPy 3 | OK | TESTS | 98 | 93 | 0 | a=int(input())
s=str(a)
count=0
for i in s:
if i=="0":
count+=1
if (count>=6):
print("yes")
else:
print("no")
| Title: Div. 64
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system.
Input Specification:
In the only line given a non-empty binary string *s* with length up to 100.
Output Specification:
Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise.
Demo Input:
['100010001\n', '100\n']
Demo Output:
['yes', 'no']
Note:
In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | ```python
a=int(input())
s=str(a)
count=0
for i in s:
if i=="0":
count+=1
if (count>=6):
print("yes")
else:
print("no")
``` | 3 |
|
900 | B | Position in Fraction | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. | The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=<<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9). | Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. | [
"1 2 0\n",
"2 3 7\n"
] | [
"2",
"-1"
] | The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/130ba579a8276fc53a1917606eee9db58817f28d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. There is no digit 7 in decimal notation of the fraction. | 1,000 | [
{
"input": "1 2 0",
"output": "2"
},
{
"input": "2 3 7",
"output": "-1"
},
{
"input": "1 100000 1",
"output": "5"
},
{
"input": "1 7 7",
"output": "6"
},
{
"input": "99999 100000 8",
"output": "-1"
},
{
"input": "44102 73848 2",
"output": "132"
},
{
"input": "7 31 3",
"output": "15"
},
{
"input": "8880 81608 9",
"output": "161"
},
{
"input": "4942 62768 5",
"output": "122"
},
{
"input": "69168 84860 4",
"output": "107"
},
{
"input": "971 1883 3",
"output": "130"
},
{
"input": "1636 3269 6",
"output": "150"
},
{
"input": "6873 7769 3",
"output": "163"
},
{
"input": "13805 15538 3",
"output": "164"
},
{
"input": "10958 21926 3",
"output": "117"
},
{
"input": "8 51 0",
"output": "10"
},
{
"input": "1 10 1",
"output": "1"
},
{
"input": "1 9 0",
"output": "-1"
},
{
"input": "53 101 6",
"output": "-1"
},
{
"input": "1 10001 9",
"output": "5"
},
{
"input": "25102 31579 2",
"output": "174"
},
{
"input": "38790 39359 0",
"output": "212"
},
{
"input": "47117 78718 0",
"output": "213"
},
{
"input": "1 57 0",
"output": "1"
},
{
"input": "1 3 0",
"output": "-1"
},
{
"input": "1 100 0",
"output": "1"
},
{
"input": "2 3 0",
"output": "-1"
},
{
"input": "99971 99989 0",
"output": "9"
},
{
"input": "567 1580 0",
"output": "6"
},
{
"input": "45 97 0",
"output": "39"
},
{
"input": "35 111 4",
"output": "-1"
},
{
"input": "1 2 5",
"output": "1"
},
{
"input": "1 7 0",
"output": "-1"
}
] | 1,516,951,836 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 5,632,000 | import sys
a,b,c=map(int,sys.stdin.readline().split())
flag=0
for i in range(1,b+1):
a=a*10
if(a//b==i):
flag=1
break
if(flag):
print(i)
else:
print(-1) | Title: Position in Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
Input Specification:
The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=<<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9).
Output Specification:
Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Demo Input:
['1 2 0\n', '2 3 7\n']
Demo Output:
['2', '-1']
Note:
The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/130ba579a8276fc53a1917606eee9db58817f28d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. There is no digit 7 in decimal notation of the fraction. | ```python
import sys
a,b,c=map(int,sys.stdin.readline().split())
flag=0
for i in range(1,b+1):
a=a*10
if(a//b==i):
flag=1
break
if(flag):
print(i)
else:
print(-1)
``` | 0 |
|
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters. | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReality\nSoul\nSpace\nMind"
},
{
"input": "3\nblue\norange\npurple",
"output": "3\nTime\nReality\nMind"
},
{
"input": "2\nyellow\nred",
"output": "4\nPower\nSoul\nSpace\nTime"
},
{
"input": "1\ngreen",
"output": "5\nReality\nSpace\nPower\nSoul\nMind"
},
{
"input": "2\npurple\ngreen",
"output": "4\nReality\nMind\nSpace\nSoul"
},
{
"input": "1\nblue",
"output": "5\nPower\nReality\nSoul\nTime\nMind"
},
{
"input": "2\npurple\nblue",
"output": "4\nMind\nSoul\nTime\nReality"
},
{
"input": "2\ngreen\nblue",
"output": "4\nReality\nMind\nPower\nSoul"
},
{
"input": "3\npurple\ngreen\nblue",
"output": "3\nMind\nReality\nSoul"
},
{
"input": "1\norange",
"output": "5\nReality\nTime\nPower\nSpace\nMind"
},
{
"input": "2\npurple\norange",
"output": "4\nReality\nMind\nTime\nSpace"
},
{
"input": "2\norange\ngreen",
"output": "4\nSpace\nMind\nReality\nPower"
},
{
"input": "3\norange\npurple\ngreen",
"output": "3\nReality\nSpace\nMind"
},
{
"input": "2\norange\nblue",
"output": "4\nTime\nMind\nReality\nPower"
},
{
"input": "3\nblue\ngreen\norange",
"output": "3\nPower\nMind\nReality"
},
{
"input": "4\nblue\norange\ngreen\npurple",
"output": "2\nMind\nReality"
},
{
"input": "1\nred",
"output": "5\nTime\nSoul\nMind\nPower\nSpace"
},
{
"input": "2\nred\npurple",
"output": "4\nMind\nSpace\nTime\nSoul"
},
{
"input": "2\nred\ngreen",
"output": "4\nMind\nSpace\nPower\nSoul"
},
{
"input": "3\nred\npurple\ngreen",
"output": "3\nSoul\nSpace\nMind"
},
{
"input": "2\nblue\nred",
"output": "4\nMind\nTime\nPower\nSoul"
},
{
"input": "3\nred\nblue\npurple",
"output": "3\nTime\nMind\nSoul"
},
{
"input": "3\nred\nblue\ngreen",
"output": "3\nSoul\nPower\nMind"
},
{
"input": "4\npurple\nblue\ngreen\nred",
"output": "2\nMind\nSoul"
},
{
"input": "2\norange\nred",
"output": "4\nPower\nMind\nTime\nSpace"
},
{
"input": "3\nred\norange\npurple",
"output": "3\nMind\nSpace\nTime"
},
{
"input": "3\nred\norange\ngreen",
"output": "3\nMind\nSpace\nPower"
},
{
"input": "4\nred\norange\ngreen\npurple",
"output": "2\nSpace\nMind"
},
{
"input": "3\nblue\norange\nred",
"output": "3\nPower\nMind\nTime"
},
{
"input": "4\norange\nblue\npurple\nred",
"output": "2\nTime\nMind"
},
{
"input": "4\ngreen\norange\nred\nblue",
"output": "2\nMind\nPower"
},
{
"input": "5\npurple\norange\nblue\nred\ngreen",
"output": "1\nMind"
},
{
"input": "1\nyellow",
"output": "5\nPower\nSoul\nReality\nSpace\nTime"
},
{
"input": "2\npurple\nyellow",
"output": "4\nTime\nReality\nSpace\nSoul"
},
{
"input": "2\ngreen\nyellow",
"output": "4\nSpace\nReality\nPower\nSoul"
},
{
"input": "3\npurple\nyellow\ngreen",
"output": "3\nSoul\nReality\nSpace"
},
{
"input": "2\nblue\nyellow",
"output": "4\nTime\nReality\nPower\nSoul"
},
{
"input": "3\nyellow\nblue\npurple",
"output": "3\nSoul\nReality\nTime"
},
{
"input": "3\ngreen\nyellow\nblue",
"output": "3\nSoul\nReality\nPower"
},
{
"input": "4\nyellow\nblue\ngreen\npurple",
"output": "2\nReality\nSoul"
},
{
"input": "2\nyellow\norange",
"output": "4\nTime\nSpace\nReality\nPower"
},
{
"input": "3\nyellow\npurple\norange",
"output": "3\nSpace\nReality\nTime"
},
{
"input": "3\norange\nyellow\ngreen",
"output": "3\nSpace\nReality\nPower"
},
{
"input": "4\ngreen\nyellow\norange\npurple",
"output": "2\nSpace\nReality"
},
{
"input": "3\nyellow\nblue\norange",
"output": "3\nTime\nReality\nPower"
},
{
"input": "4\norange\npurple\nblue\nyellow",
"output": "2\nReality\nTime"
},
{
"input": "4\nblue\norange\nyellow\ngreen",
"output": "2\nReality\nPower"
},
{
"input": "5\ngreen\nyellow\norange\nblue\npurple",
"output": "1\nReality"
},
{
"input": "3\nyellow\npurple\nred",
"output": "3\nTime\nSoul\nSpace"
},
{
"input": "3\nred\ngreen\nyellow",
"output": "3\nPower\nSoul\nSpace"
},
{
"input": "4\nred\npurple\ngreen\nyellow",
"output": "2\nSpace\nSoul"
},
{
"input": "3\nred\nyellow\nblue",
"output": "3\nPower\nSoul\nTime"
},
{
"input": "4\nblue\nyellow\nred\npurple",
"output": "2\nTime\nSoul"
},
{
"input": "4\nblue\nyellow\nred\ngreen",
"output": "2\nSoul\nPower"
},
{
"input": "5\nred\nyellow\ngreen\nblue\npurple",
"output": "1\nSoul"
},
{
"input": "3\nred\nyellow\norange",
"output": "3\nPower\nSpace\nTime"
},
{
"input": "4\norange\ngreen\nyellow\nred",
"output": "2\nPower\nSpace"
},
{
"input": "5\norange\nred\ngreen\nyellow\npurple",
"output": "1\nSpace"
},
{
"input": "4\nyellow\nred\norange\nblue",
"output": "2\nTime\nPower"
},
{
"input": "5\npurple\nblue\norange\nyellow\nred",
"output": "1\nTime"
},
{
"input": "5\norange\nblue\nyellow\nred\ngreen",
"output": "1\nPower"
}
] | 1,671,718,224 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 64 | 62 | 0 | have = 0
col = ['purple', 'green', 'blue', 'orange', 'red', 'yellow']
stones = [ 'Power','Time','Space','Soul','Reality','Mind']
for no_testcase in range(int(input())):
n = input()
t = col.index(n)
col.pop(t)
stones.pop(t)
have+=1
print(6-have)
print(*stones,sep="\n")
| Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input Specification:
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output Specification:
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Demo Input:
['4\nred\npurple\nyellow\norange\n', '0\n']
Demo Output:
['2\nSpace\nTime\n', '6\nTime\nMind\nSoul\nPower\nReality\nSpace\n']
Note:
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | ```python
have = 0
col = ['purple', 'green', 'blue', 'orange', 'red', 'yellow']
stones = [ 'Power','Time','Space','Soul','Reality','Mind']
for no_testcase in range(int(input())):
n = input()
t = col.index(n)
col.pop(t)
stones.pop(t)
have+=1
print(6-have)
print(*stones,sep="\n")
``` | 3 |
|
157 | A | Game Outcome | PROGRAMMING | 800 | [
"brute force"
] | null | null | Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number of winning squares. To determine if the particular square is winning you should do the following. Calculate the sum of all numbers on the squares that share this column (including the given square) and separately calculate the sum of all numbers on the squares that share this row (including the given square). A square is considered winning if the sum of the column numbers is strictly greater than the sum of the row numbers.
For instance, lets game was ended like is shown in the picture. Then the purple cell is winning, because the sum of its column numbers equals 8<=+<=3<=+<=6<=+<=7<==<=24, sum of its row numbers equals 9<=+<=5<=+<=3<=+<=2<==<=19, and 24<=><=19. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=30). Each of the following *n* lines contain *n* space-separated integers. The *j*-th number on the *i*-th line represents the number on the square that belongs to the *j*-th column and the *i*-th row on the board. All number on the board are integers from 1 to 100. | Print the single number — the number of the winning squares. | [
"1\n1\n",
"2\n1 2\n3 4\n",
"4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3\n"
] | [
"0\n",
"2\n",
"6\n"
] | In the first example two upper squares are winning.
In the third example three left squares in the both middle rows are winning: | 500 | [
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2\n3 4",
"output": "2"
},
{
"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3",
"output": "6"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "4"
},
{
"input": "3\n1 2 3\n3 1 2\n2 3 1",
"output": "0"
},
{
"input": "4\n1 2 3 4\n8 7 6 5\n9 10 11 12\n16 15 14 13",
"output": "8"
},
{
"input": "1\n53",
"output": "0"
},
{
"input": "5\n1 98 22 9 39\n10 9 44 49 66\n79 17 23 8 47\n59 69 72 47 14\n94 91 98 19 54",
"output": "13"
},
{
"input": "1\n31",
"output": "0"
},
{
"input": "1\n92",
"output": "0"
},
{
"input": "5\n61 45 70 19 48\n52 29 98 21 74\n21 66 12 6 55\n62 75 66 62 57\n94 74 9 86 24",
"output": "13"
},
{
"input": "2\n73 99\n13 100",
"output": "2"
},
{
"input": "4\n89 79 14 89\n73 24 58 89\n62 88 69 65\n58 92 18 83",
"output": "10"
},
{
"input": "5\n99 77 32 20 49\n93 81 63 7 58\n37 1 17 35 53\n18 94 38 80 23\n91 50 42 61 63",
"output": "12"
},
{
"input": "4\n81 100 38 54\n8 64 39 59\n6 12 53 65\n79 50 99 71",
"output": "8"
},
{
"input": "5\n42 74 45 85 14\n68 94 11 3 89\n68 67 97 62 66\n65 76 96 18 84\n61 98 28 94 74",
"output": "12"
},
{
"input": "9\n53 80 94 41 58 49 88 24 42\n85 11 32 64 40 56 63 95 73\n17 85 60 41 13 71 54 67 87\n38 14 21 81 66 59 52 33 86\n29 34 46 18 19 80 10 44 51\n4 27 65 75 77 21 15 49 50\n35 68 86 98 98 62 69 52 71\n43 28 56 91 89 21 14 57 79\n27 27 29 26 15 76 21 70 78",
"output": "40"
},
{
"input": "7\n80 81 45 81 72 19 65\n31 24 15 52 47 1 14\n81 35 42 24 96 59 46\n16 2 59 56 60 98 76\n20 95 10 68 68 56 93\n60 16 68 77 89 52 43\n11 22 43 36 99 2 11",
"output": "21"
},
{
"input": "9\n33 80 34 56 56 33 27 74 57\n14 69 78 44 56 70 26 73 47\n13 42 17 33 78 83 94 70 37\n96 78 92 6 16 68 8 31 46\n67 97 21 10 44 64 15 77 28\n34 44 83 96 63 52 29 27 79\n23 23 57 54 35 16 5 64 36\n29 71 36 78 47 81 72 97 36\n24 83 70 58 36 82 42 44 26",
"output": "41"
},
{
"input": "9\n57 70 94 69 77 59 88 63 83\n6 79 46 5 9 43 20 39 48\n46 35 58 22 17 3 81 82 34\n77 10 40 53 71 84 14 58 56\n6 92 77 81 13 20 77 29 40\n59 53 3 97 21 97 22 11 64\n52 91 82 20 6 3 99 17 44\n79 25 43 69 85 55 95 61 31\n89 24 50 84 54 93 54 60 87",
"output": "46"
},
{
"input": "5\n77 44 22 21 20\n84 3 35 86 35\n97 50 1 44 92\n4 88 56 20 3\n32 56 26 17 80",
"output": "13"
},
{
"input": "7\n62 73 50 63 66 92 2\n27 13 83 84 88 81 47\n60 41 25 2 68 32 60\n7 94 18 98 41 25 72\n69 37 4 10 82 49 91\n76 26 67 27 30 49 18\n44 78 6 1 41 94 80",
"output": "26"
},
{
"input": "9\n40 70 98 28 44 78 15 73 20\n25 74 46 3 27 59 33 96 19\n100 47 99 68 68 67 66 87 31\n26 39 8 91 58 20 91 69 81\n77 43 90 60 17 91 78 85 68\n41 46 47 50 96 18 69 81 26\n10 58 2 36 54 64 69 10 65\n6 86 26 7 88 20 43 92 59\n61 76 13 23 49 28 22 79 8",
"output": "44"
},
{
"input": "8\n44 74 25 81 32 33 55 58\n36 13 28 28 20 65 87 58\n8 35 52 59 34 15 33 16\n2 22 42 29 11 66 30 72\n33 47 8 61 31 64 59 63\n79 36 38 42 12 21 92 36\n56 47 44 6 6 1 37 2\n79 88 79 53 50 69 94 39",
"output": "31"
},
{
"input": "5\n4 91 100 8 48\n78 56 61 49 83\n12 21 95 77 78\n40 20 91 79 25\n32 88 94 28 55",
"output": "10"
},
{
"input": "5\n23 70 5 36 69\n83 18 19 98 40\n84 91 18 51 35\n17 18 35 47 59\n29 72 35 87 27",
"output": "13"
},
{
"input": "12\n8 42 23 20 39 5 23 86 26 65 93 82\n48 35 12 4 59 19 19 28 38 81 97 99\n93 24 31 44 97 50 44 99 50 7 10 64\n79 43 65 29 84 43 46 41 89 16 6 1\n34 90 33 1 7 12 46 84 67 30 1 58\n58 21 100 66 56 22 7 24 72 73 86 37\n2 17 85 6 2 73 85 44 43 79 34 65\n3 53 29 76 87 2 27 19 11 42 71 38\n69 82 73 52 44 23 92 10 13 72 59 16\n73 32 37 93 21 94 43 39 27 53 14 15\n86 16 90 91 14 50 73 61 77 36 93 90\n22 56 30 52 81 70 12 92 75 27 38 12",
"output": "77"
},
{
"input": "3\n41 94 58\n73 61 8\n34 88 89",
"output": "5"
},
{
"input": "3\n1 2 3\n1 1 1\n1 1 1",
"output": "4"
},
{
"input": "2\n7 3\n9 5",
"output": "2"
},
{
"input": "3\n4 3 2\n2 2 2\n2 2 2",
"output": "4"
}
] | 1,608,819,312 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 218 | 307,200 | n=int(input())
matrix=[]
rowsum=0
colsum=0
k=0
r=[]
c=[]
for i in range(n):
matrix.append(list(map(int,input().split())))
for i in range(n):
rowsum=0
colsum=0
for j in range(n):
rowsum+=matrix[i][j]
colsum+=matrix[j][i]
r.append(rowsum)
c.append(colsum)
for i in range(n):
for j in range(n):
if c[i]>r[j]:
k+=1
print(k)
# 3
# 1 2 3
# 4 5 6
# 7 8 9 | Title: Game Outcome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number of winning squares. To determine if the particular square is winning you should do the following. Calculate the sum of all numbers on the squares that share this column (including the given square) and separately calculate the sum of all numbers on the squares that share this row (including the given square). A square is considered winning if the sum of the column numbers is strictly greater than the sum of the row numbers.
For instance, lets game was ended like is shown in the picture. Then the purple cell is winning, because the sum of its column numbers equals 8<=+<=3<=+<=6<=+<=7<==<=24, sum of its row numbers equals 9<=+<=5<=+<=3<=+<=2<==<=19, and 24<=><=19.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=30). Each of the following *n* lines contain *n* space-separated integers. The *j*-th number on the *i*-th line represents the number on the square that belongs to the *j*-th column and the *i*-th row on the board. All number on the board are integers from 1 to 100.
Output Specification:
Print the single number — the number of the winning squares.
Demo Input:
['1\n1\n', '2\n1 2\n3 4\n', '4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3\n']
Demo Output:
['0\n', '2\n', '6\n']
Note:
In the first example two upper squares are winning.
In the third example three left squares in the both middle rows are winning: | ```python
n=int(input())
matrix=[]
rowsum=0
colsum=0
k=0
r=[]
c=[]
for i in range(n):
matrix.append(list(map(int,input().split())))
for i in range(n):
rowsum=0
colsum=0
for j in range(n):
rowsum+=matrix[i][j]
colsum+=matrix[j][i]
r.append(rowsum)
c.append(colsum)
for i in range(n):
for j in range(n):
if c[i]>r[j]:
k+=1
print(k)
# 3
# 1 2 3
# 4 5 6
# 7 8 9
``` | 3 |
|
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
"output": "9"
},
{
"input": "10\n10 5 8 9 5 6 8 7 2 8",
"output": "46"
},
{
"input": "10\n1 1 1 1 1 1 2 3 4 4",
"output": "14"
},
{
"input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4",
"output": "296"
},
{
"input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2",
"output": "313"
},
{
"input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9",
"output": "298"
},
{
"input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5",
"output": "312"
},
{
"input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2",
"output": "287"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2",
"output": "265"
},
{
"input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9",
"output": "328"
},
{
"input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9",
"output": "324"
},
{
"input": "10\n7 4 5 3 9 1 10 3 4 5",
"output": "34"
},
{
"input": "10\n8 9 6 5 6 4 10 9 1 4",
"output": "39"
},
{
"input": "10\n1 7 1 4 9 10 8 2 9 9",
"output": "40"
},
{
"input": "1\n100000",
"output": "100000"
}
] | 1,672,997,651 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 62 | 4,096,000 | table = [0]*10**5 + [0]
def main():
input()
for i in map(input().split()):
table[i] += i #Summing up the same elements together
a = 0 #a is DP(i-1)
b = 0 #b is DP(i-2)
for i in table:
a, b = max(a, b+i), a
print(a)
main() | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Print a single integer — the maximum number of points that Alex can earn.
Demo Input:
['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n']
Demo Output:
['2\n', '4\n', '10\n']
Note:
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | ```python
table = [0]*10**5 + [0]
def main():
input()
for i in map(input().split()):
table[i] += i #Summing up the same elements together
a = 0 #a is DP(i-1)
b = 0 #b is DP(i-2)
for i in table:
a, b = max(a, b+i), a
print(a)
main()
``` | -1 |
|
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo"
},
{
"input": "805",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1000",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1",
"output": "O"
},
{
"input": "2",
"output": "OO"
},
{
"input": "3",
"output": "OOO"
},
{
"input": "5",
"output": "OOOoO"
},
{
"input": "17",
"output": "OOOoOooOooooOoooo"
},
{
"input": "49",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo"
},
{
"input": "256",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo"
},
{
"input": "512",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "933",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "61",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo"
},
{
"input": "781",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "999",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
}
] | 1,546,480,013 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 109 | 0 | n = int(input())
f1 = 1
f2 = 1
f = f1+f2
s = 'O'
idx = 2
while idx <= n:
if idx == f:
s += 'O'
f1 = f2
f2 = f
f = f1+f2
else:
s += 'o'
idx += 1
print(s)
| Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
Input Specification:
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Output Specification:
Print Eleven's new name on the first and only line of output.
Demo Input:
['8\n', '15\n']
Demo Output:
['OOOoOooO\n', 'OOOoOooOooooOoo\n']
Note:
none | ```python
n = int(input())
f1 = 1
f2 = 1
f = f1+f2
s = 'O'
idx = 2
while idx <= n:
if idx == f:
s += 'O'
f1 = f2
f2 = f
f = f1+f2
else:
s += 'o'
idx += 1
print(s)
``` | 3 |
|
996 | B | World Cup | PROGRAMMING | 1,300 | [
"binary search",
"math"
] | null | null | Allen wants to enter a fan zone that occupies a round square and has $n$ entrances.
There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute.
Allen uses the following strategy to enter the fan zone:
- Initially he stands in the end of the queue in front of the first entrance. - Each minute, if he is not allowed into the fan zone during the minute (meaning he is not the first in the queue), he leaves the current queue and stands in the end of the queue of the next entrance (or the first entrance if he leaves the last entrance).
Determine the entrance through which Allen will finally enter the fan zone. | The first line contains a single integer $n$ ($2 \le n \le 10^5$) — the number of entrances.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — the number of people in queues. These numbers do not include Allen. | Print a single integer — the number of entrance that Allen will use. | [
"4\n2 3 2 0\n",
"2\n10 10\n",
"6\n5 2 6 5 7 4\n"
] | [
"3\n",
"1\n",
"6\n"
] | In the first example the number of people (not including Allen) changes as follows: $[\textbf{2}, 3, 2, 0] \to [1, \textbf{2}, 1, 0] \to [0, 1, \textbf{0}, 0]$. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance.
In the second example the number of people (not including Allen) changes as follows: $[\textbf{10}, 10] \to [9, \textbf{9}] \to [\textbf{8}, 8] \to [7, \textbf{7}] \to [\textbf{6}, 6] \to \\ [5, \textbf{5}] \to [\textbf{4}, 4] \to [3, \textbf{3}] \to [\textbf{2}, 2] \to [1, \textbf{1}] \to [\textbf{0}, 0]$.
In the third example the number of people (not including Allen) changes as follows: $[\textbf{5}, 2, 6, 5, 7, 4] \to [4, \textbf{1}, 5, 4, 6, 3] \to [3, 0, \textbf{4}, 3, 5, 2] \to \\ [2, 0, 3, \textbf{2}, 4, 1] \to [1, 0, 2, 1, \textbf{3}, 0] \to [0, 0, 1, 0, 2, \textbf{0}]$. | 1,000 | [
{
"input": "4\n2 3 2 0",
"output": "3"
},
{
"input": "2\n10 10",
"output": "1"
},
{
"input": "6\n5 2 6 5 7 4",
"output": "6"
},
{
"input": "2\n483544186 940350702",
"output": "1"
},
{
"input": "10\n3 3 3 5 6 9 3 1 7 3",
"output": "7"
},
{
"input": "10\n0 8 45 88 48 68 28 55 17 24",
"output": "1"
},
{
"input": "100\n8 8 9 10 6 8 2 4 2 2 10 6 6 10 10 2 3 5 1 2 10 4 2 0 9 4 9 3 0 6 3 2 3 10 10 6 4 6 4 4 2 5 1 4 1 1 9 8 9 5 3 5 5 4 5 5 6 5 3 3 7 2 0 10 9 7 7 3 5 1 0 9 6 3 1 3 4 4 3 6 3 2 1 4 10 2 3 4 4 3 6 7 6 2 1 7 0 6 8 10",
"output": "7"
},
{
"input": "10\n5 6 7 8 9 10 11 12 13 14",
"output": "1"
},
{
"input": "10\n15 14 13 12 11 10 9 8 7 6",
"output": "9"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "3\n3 3 1",
"output": "3"
},
{
"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "3\n15 8 9",
"output": "2"
},
{
"input": "3\n5 5 5",
"output": "3"
},
{
"input": "3\n41 5 6",
"output": "2"
},
{
"input": "2\n999999999 1000000000",
"output": "1"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "3\n3 2 3",
"output": "1"
},
{
"input": "3\n8 5 8",
"output": "2"
},
{
"input": "4\n5 2 3 4",
"output": "2"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "4\n9 2 4 7",
"output": "2"
},
{
"input": "30\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "11"
},
{
"input": "4\n11 10 12 12",
"output": "1"
},
{
"input": "2\n1 0",
"output": "2"
},
{
"input": "6\n7 2 6 5 7 9",
"output": "2"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "2"
},
{
"input": "2\n999999999 999999699",
"output": "2"
},
{
"input": "5\n5 5 5 5 5",
"output": "1"
},
{
"input": "2\n1 1",
"output": "2"
}
] | 1,689,255,410 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 61 | 0 | n = int(input())
queue_sizes = list(map(int, input().split()))
current_entrance = 1
for i in range(max(queue_sizes)):
if queue_sizes[current_entrance - 1] == 0:
break
queue_sizes[current_entrance - 1] -= 1
current_entrance += 1
if current_entrance > n:
current_entrance = 1
print(current_entrance)
| Title: World Cup
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen wants to enter a fan zone that occupies a round square and has $n$ entrances.
There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute.
Allen uses the following strategy to enter the fan zone:
- Initially he stands in the end of the queue in front of the first entrance. - Each minute, if he is not allowed into the fan zone during the minute (meaning he is not the first in the queue), he leaves the current queue and stands in the end of the queue of the next entrance (or the first entrance if he leaves the last entrance).
Determine the entrance through which Allen will finally enter the fan zone.
Input Specification:
The first line contains a single integer $n$ ($2 \le n \le 10^5$) — the number of entrances.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — the number of people in queues. These numbers do not include Allen.
Output Specification:
Print a single integer — the number of entrance that Allen will use.
Demo Input:
['4\n2 3 2 0\n', '2\n10 10\n', '6\n5 2 6 5 7 4\n']
Demo Output:
['3\n', '1\n', '6\n']
Note:
In the first example the number of people (not including Allen) changes as follows: $[\textbf{2}, 3, 2, 0] \to [1, \textbf{2}, 1, 0] \to [0, 1, \textbf{0}, 0]$. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance.
In the second example the number of people (not including Allen) changes as follows: $[\textbf{10}, 10] \to [9, \textbf{9}] \to [\textbf{8}, 8] \to [7, \textbf{7}] \to [\textbf{6}, 6] \to \\ [5, \textbf{5}] \to [\textbf{4}, 4] \to [3, \textbf{3}] \to [\textbf{2}, 2] \to [1, \textbf{1}] \to [\textbf{0}, 0]$.
In the third example the number of people (not including Allen) changes as follows: $[\textbf{5}, 2, 6, 5, 7, 4] \to [4, \textbf{1}, 5, 4, 6, 3] \to [3, 0, \textbf{4}, 3, 5, 2] \to \\ [2, 0, 3, \textbf{2}, 4, 1] \to [1, 0, 2, 1, \textbf{3}, 0] \to [0, 0, 1, 0, 2, \textbf{0}]$. | ```python
n = int(input())
queue_sizes = list(map(int, input().split()))
current_entrance = 1
for i in range(max(queue_sizes)):
if queue_sizes[current_entrance - 1] == 0:
break
queue_sizes[current_entrance - 1] -= 1
current_entrance += 1
if current_entrance > n:
current_entrance = 1
print(current_entrance)
``` | 0 |