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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | none | none | none | 0 | [
"none"
] | null | null | Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**i* and *r**i*, and its elements are *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
Alyona is going to find mex for each of the chosen subarrays. Among these *m* mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array *a* of *n* elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set *S* is a minimum possible non-negative integer that is not in *S*. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105).
The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. | In the first line print single integer — the maximum possible minimum mex.
In the second line print *n* integers — the array *a*. All the elements in *a* should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109.
If there are multiple solutions, print any of them. | [
"5 3\n1 3\n2 5\n4 5\n",
"4 2\n1 4\n2 4\n"
] | [
"2\n1 0 2 1 0\n",
"3\n5 2 0 1"
] | The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | 0 | [
{
"input": "5 3\n1 3\n2 5\n4 5",
"output": "2\n0 1 0 1 0"
},
{
"input": "4 2\n1 4\n2 4",
"output": "3\n0 1 2 0"
},
{
"input": "1 1\n1 1",
"output": "1\n0"
},
{
"input": "2 1\n2 2",
"output": "1\n0 0"
},
{
"input": "5 6\n2 4\n2 3\n1 4\n3 4\n2 5\n1 3",
"output": "2\n0 1 0 1 0"
},
{
"input": "8 3\n2 3\n2 8\n3 6",
"output": "2\n0 1 0 1 0 1 0 1"
},
{
"input": "10 10\n1 9\n4 8\n4 8\n5 9\n1 9\n3 8\n1 6\n1 9\n1 6\n6 9",
"output": "4\n0 1 2 3 0 1 2 3 0 1"
},
{
"input": "3 6\n1 3\n1 3\n1 1\n1 1\n3 3\n3 3",
"output": "1\n0 0 0"
},
{
"input": "3 3\n1 3\n2 2\n1 3",
"output": "1\n0 0 0"
},
{
"input": "6 8\n3 5\n3 6\n4 6\n2 5\n2 5\n1 3\n3 6\n3 5",
"output": "3\n0 1 2 0 1 2"
},
{
"input": "10 4\n4 10\n4 6\n6 8\n1 10",
"output": "3\n0 1 2 0 1 2 0 1 2 0"
},
{
"input": "9 1\n1 1",
"output": "1\n0 0 0 0 0 0 0 0 0"
},
{
"input": "3 8\n2 3\n1 3\n1 2\n2 3\n1 3\n2 2\n1 2\n1 2",
"output": "1\n0 0 0"
},
{
"input": "3 8\n1 2\n1 2\n1 1\n2 3\n2 3\n1 1\n1 3\n1 3",
"output": "1\n0 0 0"
},
{
"input": "7 3\n7 7\n3 7\n5 7",
"output": "1\n0 0 0 0 0 0 0"
},
{
"input": "9 9\n4 5\n5 8\n1 8\n4 8\n3 4\n7 8\n1 4\n7 8\n6 7",
"output": "2\n0 1 0 1 0 1 0 1 0"
},
{
"input": "10 10\n1 5\n7 10\n2 10\n2 5\n2 9\n5 9\n3 10\n4 9\n6 9\n2 7",
"output": "4\n0 1 2 3 0 1 2 3 0 1"
},
{
"input": "8 7\n5 8\n3 7\n1 8\n3 4\n2 8\n2 7\n4 6",
"output": "2\n0 1 0 1 0 1 0 1"
},
{
"input": "10 3\n2 4\n8 10\n4 6",
"output": "3\n0 1 2 0 1 2 0 1 2 0"
},
{
"input": "5 8\n3 4\n1 5\n3 4\n3 5\n3 4\n1 4\n1 5\n2 5",
"output": "2\n0 1 0 1 0"
},
{
"input": "9 4\n5 9\n3 8\n2 8\n1 4",
"output": "4\n0 1 2 3 0 1 2 3 0"
},
{
"input": "7 7\n2 4\n1 4\n3 6\n2 6\n5 7\n3 6\n1 4",
"output": "3\n0 1 2 0 1 2 0"
},
{
"input": "6 2\n4 6\n2 5",
"output": "3\n0 1 2 0 1 2"
},
{
"input": "7 9\n6 7\n1 2\n2 5\n4 7\n1 7\n5 6\n2 3\n6 7\n1 2",
"output": "2\n0 1 0 1 0 1 0"
}
] | 1,479,928,199 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | n, m = map(int, input().split())
for i in range(m):
li, ri = map(int, input().split())
ansi = min(ri - li + 1, ansi)
print(ansi)
for i in range(n):
print(i % ansi, end=' ') | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**i* and *r**i*, and its elements are *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
Alyona is going to find mex for each of the chosen subarrays. Among these *m* mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array *a* of *n* elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set *S* is a minimum possible non-negative integer that is not in *S*.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105).
The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
Output Specification:
In the first line print single integer — the maximum possible minimum mex.
In the second line print *n* integers — the array *a*. All the elements in *a* should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109.
If there are multiple solutions, print any of them.
Demo Input:
['5 3\n1 3\n2 5\n4 5\n', '4 2\n1 4\n2 4\n']
Demo Output:
['2\n1 0 2 1 0\n', '3\n5 2 0 1']
Note:
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | ```python
n, m = map(int, input().split())
for i in range(m):
li, ri = map(int, input().split())
ansi = min(ri - li + 1, ansi)
print(ansi)
for i in range(n):
print(i % ansi, end=' ')
``` | -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,699,115 | 2,147,483,647 | Python 3 | IDLENESS_LIMIT_EXCEEDED | TESTS | 0 | 0 | 0 | import tkinter as tk
from tkinter import E,W,N,S
window = tk.Tk()
title_label = tk.Label(
master=window,
text="Enter your information",
)
title_label.grid(row=0,column=0,columnspan=2)
label_input_name = tk.Label(
master=window,
text='First Name : ',
height=5,
)
entry_name = tk.Entry(
master=window,
)
label_input_lastname = tk.Label(
master=window,
text='Last Name : '
)
entry_lastname = tk.Entry(
master=window,
)
age_label = tk.Label(
master=window,
text="Age : ",
)
age_entry = tk.Entry(
master=window,
)
label_input_name.grid(row=1,column=0)
entry_name.grid(row=1,column=1)
label_input_lastname.grid(row=2,column=0)
entry_lastname.grid(row=2,column=1)
age_label.grid(row=3,column=0)
age_entry.grid(row=3,column=1)
submit_button = tk.Button(
master=window,
text="Submit",
)
submit_button.grid(row=4,column=1)
# label_input_name.pack()
# entry_name.pack()
window.mainloop() | 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
import tkinter as tk
from tkinter import E,W,N,S
window = tk.Tk()
title_label = tk.Label(
master=window,
text="Enter your information",
)
title_label.grid(row=0,column=0,columnspan=2)
label_input_name = tk.Label(
master=window,
text='First Name : ',
height=5,
)
entry_name = tk.Entry(
master=window,
)
label_input_lastname = tk.Label(
master=window,
text='Last Name : '
)
entry_lastname = tk.Entry(
master=window,
)
age_label = tk.Label(
master=window,
text="Age : ",
)
age_entry = tk.Entry(
master=window,
)
label_input_name.grid(row=1,column=0)
entry_name.grid(row=1,column=1)
label_input_lastname.grid(row=2,column=0)
entry_lastname.grid(row=2,column=1)
age_label.grid(row=3,column=0)
age_entry.grid(row=3,column=1)
submit_button = tk.Button(
master=window,
text="Submit",
)
submit_button.grid(row=4,column=1)
# label_input_name.pack()
# entry_name.pack()
window.mainloop()
``` | -1 |
|
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3 blue flowers. - To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower.
Help Fox Ciel to find the maximal number of bouquets she can make. | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 999",
"output": "339"
},
{
"input": "32 62 92",
"output": "62"
},
{
"input": "123456789 123456789 123456789",
"output": "123456789"
},
{
"input": "3 5 5",
"output": "4"
},
{
"input": "666806767 385540591 357848286",
"output": "470065214"
},
{
"input": "80010646 727118126 817880463",
"output": "541669744"
},
{
"input": "829651016 732259171 572879931",
"output": "711596705"
},
{
"input": "242854896 442432924 180395753",
"output": "288561190"
},
{
"input": "139978911 5123031 935395222",
"output": "360165721"
},
{
"input": "553182792 10264076 395427398",
"output": "319624755"
},
{
"input": "597790453 720437830 855459575",
"output": "724562619"
},
{
"input": "494914467 356982656 757942689",
"output": "536613270"
},
{
"input": "908118348 67156409 217974865",
"output": "397749873"
},
{
"input": "952726009 629846517 972974334",
"output": "851848953"
},
{
"input": "775140200 616574841 630329230",
"output": "674014756"
},
{
"input": "524780569 326748594 90361407",
"output": "313963523"
},
{
"input": "937984449 184405994 992844522",
"output": "705078321"
},
{
"input": "835108464 525983528 452876698",
"output": "604656229"
},
{
"input": "879716125 531124573 207876166",
"output": "539572288"
},
{
"input": "292920005 241298326 667908343",
"output": "400708891"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "1000000000 999999999 999999998",
"output": "999999998"
},
{
"input": "999999998 999999998 999999999",
"output": "999999998"
},
{
"input": "0 1 1",
"output": "0"
},
{
"input": "0 1000000000 0",
"output": "333333333"
},
{
"input": "0 1 0",
"output": "0"
},
{
"input": "1 0 0",
"output": "0"
},
{
"input": "0 2 2",
"output": "0"
},
{
"input": "3 3 5",
"output": "3"
},
{
"input": "2 2 0",
"output": "0"
},
{
"input": "0 5 5",
"output": "2"
},
{
"input": "2 0 11",
"output": "3"
},
{
"input": "9 9 7",
"output": "8"
},
{
"input": "65 30 74",
"output": "56"
}
] | 1,560,863,478 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 248 | 0 | r,g,b = map(int, input().split(" "))
res = 0
res += r//3
res += g//3
res += b//3
if r > 0 and b > 0 and g > 0:
r -= 1
g -= 1
b -= 1
res = max(res,r//3+b//3+g//3+1)
if r > 0 and b > 0 and g > 0:
r -= 1
g -= 1
b -= 1
res = max(res, r//3+b//3+g//3+2)
print(res) | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3 blue flowers. - To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower.
Help Fox Ciel to find the maximal number of bouquets she can make.
Input Specification:
The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers.
Output Specification:
Print the maximal number of bouquets Fox Ciel can make.
Demo Input:
['3 6 9\n', '4 4 4\n', '0 0 0\n']
Demo Output:
['6\n', '4\n', '0\n']
Note:
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | ```python
r,g,b = map(int, input().split(" "))
res = 0
res += r//3
res += g//3
res += b//3
if r > 0 and b > 0 and g > 0:
r -= 1
g -= 1
b -= 1
res = max(res,r//3+b//3+g//3+1)
if r > 0 and b > 0 and g > 0:
r -= 1
g -= 1
b -= 1
res = max(res, r//3+b//3+g//3+2)
print(res)
``` | 3 |
|
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
{
"input": "20\n44444444444444444444",
"output": "YES"
},
{
"input": "2\n44",
"output": "YES"
},
{
"input": "10\n4745474547",
"output": "NO"
},
{
"input": "14\n77770004444444",
"output": "NO"
},
{
"input": "10\n4747777744",
"output": "YES"
},
{
"input": "10\n1234567890",
"output": "NO"
},
{
"input": "50\n44444444444444444444444444444444444444444444444444",
"output": "YES"
},
{
"input": "50\n44444444444444444444444444444444444444444444444447",
"output": "NO"
},
{
"input": "50\n74444444444444444444444444444444444444444444444444",
"output": "NO"
},
{
"input": "50\n07777777777777777777777777777777777777777777777770",
"output": "NO"
},
{
"input": "50\n77777777777777777777777777777777777777777777777777",
"output": "YES"
},
{
"input": "50\n44747747774474747747747447777447774747447477444474",
"output": "YES"
},
{
"input": "48\n447474444777444474747747744774447444747474774474",
"output": "YES"
},
{
"input": "32\n74474474777444474444747774474774",
"output": "YES"
},
{
"input": "40\n4747777444447747777447447747447474774777",
"output": "YES"
},
{
"input": "10\n4477477444",
"output": "YES"
},
{
"input": "18\n447747474447744747",
"output": "YES"
},
{
"input": "26\n44747744444774744774474447",
"output": "YES"
},
{
"input": "50\n44707747774474747747747447777447774747447477444474",
"output": "NO"
},
{
"input": "40\n4747777444447737777447447747447474774777",
"output": "NO"
},
{
"input": "36\n764477744747444444447747747474744444",
"output": "NO"
},
{
"input": "22\n4477407474777477744447",
"output": "NO"
},
{
"input": "32\n74274474777444474444747774474774",
"output": "NO"
},
{
"input": "16\n4744447974444747",
"output": "NO"
},
{
"input": "2\n11",
"output": "NO"
},
{
"input": "2\n22",
"output": "NO"
},
{
"input": "2\n33",
"output": "NO"
},
{
"input": "2\n74",
"output": "NO"
},
{
"input": "2\n55",
"output": "NO"
},
{
"input": "2\n66",
"output": "NO"
},
{
"input": "2\n77",
"output": "YES"
},
{
"input": "2\n88",
"output": "NO"
},
{
"input": "2\n99",
"output": "NO"
},
{
"input": "4\n4004",
"output": "NO"
},
{
"input": "14\n00077774444444",
"output": "NO"
},
{
"input": "6\n004444",
"output": "NO"
},
{
"input": "4\n0044",
"output": "NO"
},
{
"input": "14\n77771114444444",
"output": "NO"
},
{
"input": "14\n44444447777000",
"output": "NO"
},
{
"input": "6\n004774",
"output": "NO"
}
] | 1,595,621,908 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 216 | 6,963,200 | n = int(input())
def lucky(n):
x = list(set(list(n)))
if x!=['4','7'] and x!=['7','4']:
return False
else:
return True
a = input()
if lucky(a):
x = [int(i) for i in a[:n//2]]
y = [int(i) for i in a[n//2:]]
if sum(x) == sum(y):
print("YES")
else:
print("NO")
else:
print("NO") | Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
Input Specification:
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
Output Specification:
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['2\n47\n', '4\n4738\n', '4\n4774\n']
Demo Output:
['NO\n', 'NO\n', 'YES\n']
Note:
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | ```python
n = int(input())
def lucky(n):
x = list(set(list(n)))
if x!=['4','7'] and x!=['7','4']:
return False
else:
return True
a = input()
if lucky(a):
x = [int(i) for i in a[:n//2]]
y = [int(i) for i in a[n//2:]]
if sum(x) == sum(y):
print("YES")
else:
print("NO")
else:
print("NO")
``` | 0 |
|
940 | B | Our Tanya is Crying Out Loud | PROGRAMMING | 1,400 | [
"dp",
"greedy"
] | null | null | Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109). | Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1. | [
"9\n2\n3\n1\n",
"5\n5\n2\n20\n",
"19\n3\n4\n2\n"
] | [
"6\n",
"8\n",
"12\n"
] | In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total. | 1,250 | [
{
"input": "9\n2\n3\n1",
"output": "6"
},
{
"input": "5\n5\n2\n20",
"output": "8"
},
{
"input": "19\n3\n4\n2",
"output": "12"
},
{
"input": "1845999546\n999435865\n1234234\n2323423",
"output": "1044857680578777"
},
{
"input": "1604353664\n1604353665\n9993432\n1",
"output": "16032999235141416"
},
{
"input": "777888456\n1\n98\n43",
"output": "76233068590"
},
{
"input": "1162261467\n3\n1\n2000000000",
"output": "1162261466"
},
{
"input": "1000000000\n1999999999\n789987\n184569875",
"output": "789986999210013"
},
{
"input": "2000000000\n2\n1\n2000000000",
"output": "1999999999"
},
{
"input": "1999888325\n3\n2\n2000000000",
"output": "3333258884"
},
{
"input": "1897546487\n687\n89798979\n879876541",
"output": "110398404423"
},
{
"input": "20\n1\n20\n1",
"output": "380"
},
{
"input": "16\n5\n17\n3",
"output": "54"
},
{
"input": "19\n19\n19\n1",
"output": "1"
},
{
"input": "18\n2\n3\n16",
"output": "40"
},
{
"input": "1\n11\n8\n9",
"output": "0"
},
{
"input": "9\n10\n1\n20",
"output": "8"
},
{
"input": "19\n10\n19\n2",
"output": "173"
},
{
"input": "16\n9\n14\n2",
"output": "100"
},
{
"input": "15\n2\n5\n2",
"output": "21"
},
{
"input": "14\n7\n13\n1",
"output": "14"
},
{
"input": "43\n3\n45\n3",
"output": "189"
},
{
"input": "99\n1\n98\n1",
"output": "9604"
},
{
"input": "77\n93\n100\n77",
"output": "7600"
},
{
"input": "81\n3\n91\n95",
"output": "380"
},
{
"input": "78\n53\n87\n34",
"output": "2209"
},
{
"input": "80\n3\n15\n1",
"output": "108"
},
{
"input": "97\n24\n4\n24",
"output": "40"
},
{
"input": "100\n100\n1\n100",
"output": "99"
},
{
"input": "87\n4\n17\n7",
"output": "106"
},
{
"input": "65\n2\n3\n6",
"output": "36"
},
{
"input": "1000000\n1435\n3\n999999",
"output": "1005804"
},
{
"input": "783464\n483464\n2\n966928",
"output": "1566926"
},
{
"input": "248035\n11\n3\n20",
"output": "202"
},
{
"input": "524287\n2\n945658\n999756",
"output": "34963354"
},
{
"input": "947352\n78946\n85\n789654",
"output": "790589"
},
{
"input": "1000000\n1\n999899\n60",
"output": "999898000101"
},
{
"input": "753687\n977456\n6547\n456",
"output": "4934382242"
},
{
"input": "1000000\n500000\n1\n999997",
"output": "999998"
},
{
"input": "997458\n843596\n1\n843596",
"output": "997457"
},
{
"input": "821109\n92\n6547\n98787",
"output": "394566"
},
{
"input": "1073741823\n2\n9543\n8923453",
"output": "188412866"
},
{
"input": "1000999777\n1934999345\n2356346\n34534565",
"output": "2358701818178496"
},
{
"input": "2000000000\n1\n2000000000\n98",
"output": "3999999998000000000"
},
{
"input": "1999324353\n978435356\n1\n978435356",
"output": "1020888998"
},
{
"input": "2000000000\n2\n2000000000\n2000000000",
"output": "84000000000"
},
{
"input": "241375690\n17\n2\n1998789654",
"output": "482751378"
},
{
"input": "171507000\n350\n789\n6548687",
"output": "14216965"
},
{
"input": "1100220011\n10001\n2\n1999778654",
"output": "1999998674"
},
{
"input": "1867622656\n43216\n789644\n12315468",
"output": "24630936"
},
{
"input": "1867622656\n43216\n1\n1879865413",
"output": "1867622655"
},
{
"input": "1999999999\n1000000000\n789987\n184569875",
"output": "789987183779888"
},
{
"input": "1987987897\n103546\n7\n98754563",
"output": "98946650"
},
{
"input": "10\n2\n2\n5",
"output": "13"
},
{
"input": "7\n2\n1\n100000",
"output": "6"
},
{
"input": "7\n2\n3\n1",
"output": "8"
},
{
"input": "2000000000\n666666667\n1\n1",
"output": "666666668"
},
{
"input": "1999999997\n666666666\n2\n2",
"output": "1333333334"
}
] | 1,620,669,977 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 124 | 22,528,000 | import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from itertools import combinations, permutations
# input = sys.stdin.readline
flush = lambda: sys.stdout.flush
comb = lambda x, y: (factorial(x) // factorial(y)) // factorial(x - y)
# inputs
# ip = lambda : input().rstrip()
ip = lambda: input()
ii = lambda: int(input())
r = lambda: map(int, input().split())
rr = lambda: list(r())
n = ii()
k = ii()
a = ii()
b = ii()
ans = (n - 1) * a
if k == 1:
exit(print(n - 1))
c = 0
while n:
r = n % k
c += r * a
n -= r
n = n // k
if n:
c += b
c-= a
print(min(ans, c))
| Title: Our Tanya is Crying Out Loud
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109).
Output Specification:
Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1.
Demo Input:
['9\n2\n3\n1\n', '5\n5\n2\n20\n', '19\n3\n4\n2\n']
Demo Output:
['6\n', '8\n', '12\n']
Note:
In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total. | ```python
import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from itertools import combinations, permutations
# input = sys.stdin.readline
flush = lambda: sys.stdout.flush
comb = lambda x, y: (factorial(x) // factorial(y)) // factorial(x - y)
# inputs
# ip = lambda : input().rstrip()
ip = lambda: input()
ii = lambda: int(input())
r = lambda: map(int, input().split())
rr = lambda: list(r())
n = ii()
k = ii()
a = ii()
b = ii()
ans = (n - 1) * a
if k == 1:
exit(print(n - 1))
c = 0
while n:
r = n % k
c += r * a
n -= r
n = n // k
if n:
c += b
c-= a
print(min(ans, c))
``` | 0 |
|
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,698,347,299 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | n = input()
s = 0
for i in range(len(n)):
if n[i] in ["7", "4"]:
s += 1
if s == len(n):
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 = input()
s = 0
for i in range(len(n)):
if n[i] in ["7", "4"]:
s += 1
if s == len(n):
print("YES")
else:
print("NO")
``` | 0 |
6 | C | Alice, Bob and Chocolate | PROGRAMMING | 1,200 | [
"greedy",
"two pointers"
] | C. Alice, Bob and Chocolate | 2 | 64 | Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman.
How many bars each of the players will consume? | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). | Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. | [
"5\n2 9 8 2 7\n"
] | [
"2 3\n"
] | none | 0 | [
{
"input": "5\n2 9 8 2 7",
"output": "2 3"
},
{
"input": "1\n1",
"output": "1 0"
},
{
"input": "2\n1 1",
"output": "1 1"
},
{
"input": "3\n1 1 1",
"output": "2 1"
},
{
"input": "4\n1 1 1 1",
"output": "2 2"
},
{
"input": "1\n6",
"output": "1 0"
},
{
"input": "2\n8 2",
"output": "1 1"
},
{
"input": "3\n6 8 4",
"output": "1 2"
},
{
"input": "4\n4 3 2 8",
"output": "3 1"
},
{
"input": "5\n1 9 8 2 7",
"output": "2 3"
},
{
"input": "6\n1 4 7 3 2 1",
"output": "3 3"
},
{
"input": "11\n7 9 1 8 7 1 7 1 4 8 1",
"output": "4 7"
},
{
"input": "12\n4 2 7 1 9 5 6 2 7 8 5 7",
"output": "7 5"
},
{
"input": "13\n9 9 9 9 9 9 9 9 9 9 9 9 9",
"output": "7 6"
}
] | 1,674,156,005 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 122 | 0 | n = int(input())
t = list(map(int,input().split()))
i = 0
j = n-1
t1,t2 = 0,0
a,b = 0,0
while i<=j:
t1+=t[i]
t2+=t[j]
if i==j and t1==t2:
a+=1
break
elif i==j:
a+=(t1<t2)
b+=(t2<t1)
break
a+=1
b+=1
i+=1
j-=1
print(a,b)
| Title: Alice, Bob and Chocolate
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman.
How many bars each of the players will consume?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Output Specification:
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
Demo Input:
['5\n2 9 8 2 7\n']
Demo Output:
['2 3\n']
Note:
none | ```python
n = int(input())
t = list(map(int,input().split()))
i = 0
j = n-1
t1,t2 = 0,0
a,b = 0,0
while i<=j:
t1+=t[i]
t2+=t[j]
if i==j and t1==t2:
a+=1
break
elif i==j:
a+=(t1<t2)
b+=(t2<t1)
break
a+=1
b+=1
i+=1
j-=1
print(a,b)
``` | 0 |
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition. | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people. | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": "1000000000 1",
"output": "499999999500000000 499999999500000000"
},
{
"input": "5000000 12",
"output": "1041664166668 12499942500066"
},
{
"input": "1833 195",
"output": "7722 1342341"
},
{
"input": "1000000000 1000000000",
"output": "0 0"
},
{
"input": "1000000000 1000000",
"output": "499500000000 499000500499500000"
},
{
"input": "1000000000 32170",
"output": "15541930838100 499967831017438365"
},
{
"input": "1000000 1000",
"output": "499500000 499000999500"
},
{
"input": "1234 1123",
"output": "111 6216"
},
{
"input": "599222887 298488",
"output": "601178656545 179355218158217800"
},
{
"input": "999999999 500000000",
"output": "499999999 124999999750000000"
},
{
"input": "1000000000 384842119",
"output": "845473643 189209609585784021"
},
{
"input": "1000000000 384842119",
"output": "845473643 189209609585784021"
},
{
"input": "1000000000 2",
"output": "249999999500000000 499999998500000001"
},
{
"input": "1000000000 999999999",
"output": "1 1"
},
{
"input": "38447 383",
"output": "1910550 724453080"
},
{
"input": "100000000 99999799",
"output": "201 20301"
},
{
"input": "1 1",
"output": "0 0"
},
{
"input": "2 1",
"output": "1 1"
},
{
"input": "2 2",
"output": "0 0"
},
{
"input": "10 10",
"output": "0 0"
}
] | 1,648,578,853 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 61 | 0 | n,m = map(int,input().split())
temp = n-(m-1)
kmax = (temp*(temp-1))//2
a = n//m
temp1 = m*(a*(a-1))//2 + a*(n%m)
print(temp1,kmax) | Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.
Input Specification:
The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively.
Output Specification:
The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
Demo Input:
['5 1\n', '3 2\n', '6 3\n']
Demo Output:
['10 10\n', '1 1\n', '3 6\n']
Note:
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people. | ```python
n,m = map(int,input().split())
temp = n-(m-1)
kmax = (temp*(temp-1))//2
a = n//m
temp1 = m*(a*(a-1))//2 + a*(n%m)
print(temp1,kmax)
``` | 3 |
|
793 | B | Igor and his way to work | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"implementation",
"shortest paths"
] | null | null | Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel, so he can make no more than two turns on his way to his office in bank.
Bankopolis looks like a grid of *n* rows and *m* columns. Igor should find a way from his home to the bank that has no more than two turns and doesn't contain cells with road works, or determine that it is impossible and he should work from home. A turn is a change in movement direction. Igor's car can only move to the left, to the right, upwards and downwards. Initially Igor can choose any direction. Igor is still sleepy, so you should help him. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the grid.
Each of the next *n* lines contains *m* characters denoting the corresponding row of the grid. The following characters can occur:
- "." — an empty cell; - "*" — a cell with road works; - "S" — the cell where Igor's home is located; - "T" — the cell where Igor's office is located.
It is guaranteed that "S" and "T" appear exactly once each. | In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise. | [
"5 5\n..S..\n****.\nT....\n****.\n.....\n",
"5 5\nS....\n****.\n.....\n.****\n..T..\n"
] | [
"YES",
"NO"
] | The first sample is shown on the following picture:
In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture: | 1,000 | [
{
"input": "5 5\nS....\n****.\n.....\n.****\n..T..",
"output": "NO"
},
{
"input": "1 2\nST",
"output": "YES"
},
{
"input": "3 1\nS\n*\nT",
"output": "NO"
},
{
"input": "3 3\n*..\n...\nTS.",
"output": "YES"
},
{
"input": "3 3\nT.*\n*.*\n*S*",
"output": "YES"
},
{
"input": "7 7\n.S.****\n...*.*.\n.****..\n.*.**.*\n..T*...\n***..*.\n*******",
"output": "YES"
},
{
"input": "3 3\n**T\n*S*\n***",
"output": "NO"
},
{
"input": "2 2\nST\n*.",
"output": "YES"
},
{
"input": "2 2\nS.\n.T",
"output": "YES"
},
{
"input": "2 2\nTS\n.*",
"output": "YES"
},
{
"input": "2 2\n.T\nS*",
"output": "YES"
}
] | 1,492,967,358 | 1,458 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 8 | 3,000 | 127,897,600 | n, m = map(int, input().split())
b = [input() for _ in range(n)]
(xs, ys, xt, yt) = (-1, -1, -1, -1)
for i in range(n):
for j in range(m):
if b[i][j] == 'S':
xs = i
ys = j
elif b[i][j] == 'T':
xt = i
yt= j
s0 = set()
s0.add((xs,ys))
for _ in range(3):
s1 = set()
for t in s0:
s1.add(t)
for p in range(t[0]+1, n):
if b[p][t[1]] == '*':
break
x = (p,t[1])
s1.add(x)
if x in s0:
break
for p in range(t[0]-1, -1, -1):
if b[p][t[1]] == '*':
break
x = (p,t[1])
s1.add(x)
if x in s0:
break
for p in range(t[1]+1, m):
if b[t[0]][p] == '*':
break
x = (t[0], p)
s1.add(x)
if x in s0:
break
for p in range(t[1]-1, -1, -1):
if b[t[0]][p] == '*':
break
x = (t[0], p)
s1.add(x)
if x in s0:
break
s0 = s1
if (xt, yt) in s0:
print("YES")
else:
print("NO")
| Title: Igor and his way to work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel, so he can make no more than two turns on his way to his office in bank.
Bankopolis looks like a grid of *n* rows and *m* columns. Igor should find a way from his home to the bank that has no more than two turns and doesn't contain cells with road works, or determine that it is impossible and he should work from home. A turn is a change in movement direction. Igor's car can only move to the left, to the right, upwards and downwards. Initially Igor can choose any direction. Igor is still sleepy, so you should help him.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the grid.
Each of the next *n* lines contains *m* characters denoting the corresponding row of the grid. The following characters can occur:
- "." — an empty cell; - "*" — a cell with road works; - "S" — the cell where Igor's home is located; - "T" — the cell where Igor's office is located.
It is guaranteed that "S" and "T" appear exactly once each.
Output Specification:
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
Demo Input:
['5 5\n..S..\n****.\nT....\n****.\n.....\n', '5 5\nS....\n****.\n.....\n.****\n..T..\n']
Demo Output:
['YES', 'NO']
Note:
The first sample is shown on the following picture:
In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture: | ```python
n, m = map(int, input().split())
b = [input() for _ in range(n)]
(xs, ys, xt, yt) = (-1, -1, -1, -1)
for i in range(n):
for j in range(m):
if b[i][j] == 'S':
xs = i
ys = j
elif b[i][j] == 'T':
xt = i
yt= j
s0 = set()
s0.add((xs,ys))
for _ in range(3):
s1 = set()
for t in s0:
s1.add(t)
for p in range(t[0]+1, n):
if b[p][t[1]] == '*':
break
x = (p,t[1])
s1.add(x)
if x in s0:
break
for p in range(t[0]-1, -1, -1):
if b[p][t[1]] == '*':
break
x = (p,t[1])
s1.add(x)
if x in s0:
break
for p in range(t[1]+1, m):
if b[t[0]][p] == '*':
break
x = (t[0], p)
s1.add(x)
if x in s0:
break
for p in range(t[1]-1, -1, -1):
if b[t[0]][p] == '*':
break
x = (t[0], p)
s1.add(x)
if x in s0:
break
s0 = s1
if (xt, yt) in s0:
print("YES")
else:
print("NO")
``` | 0 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,643,195,751 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | if input() == input()[::-1]:
print("yes")
else:
print("no") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
if input() == input()[::-1]:
print("yes")
else:
print("no")
``` | 0 |
868 | B | Race Against Time | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.
The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds.
Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction.
Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way).
Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face. | Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2).
Misha's position and the target time do not coincide with the position of any hand. | Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"12 30 45 3 11\n",
"12 0 1 12 1\n",
"3 47 0 4 9\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same. | 500 | [
{
"input": "12 30 45 3 11",
"output": "NO"
},
{
"input": "12 0 1 12 1",
"output": "YES"
},
{
"input": "3 47 0 4 9",
"output": "YES"
},
{
"input": "10 22 59 6 10",
"output": "YES"
},
{
"input": "3 1 13 12 3",
"output": "NO"
},
{
"input": "11 19 28 9 10",
"output": "YES"
},
{
"input": "9 38 22 6 1",
"output": "NO"
},
{
"input": "5 41 11 5 8",
"output": "NO"
},
{
"input": "11 2 53 10 4",
"output": "YES"
},
{
"input": "9 41 17 10 1",
"output": "YES"
},
{
"input": "6 54 48 12 6",
"output": "YES"
},
{
"input": "12 55 9 5 1",
"output": "NO"
},
{
"input": "8 55 35 9 3",
"output": "NO"
},
{
"input": "3 21 34 3 10",
"output": "YES"
},
{
"input": "2 52 1 12 3",
"output": "NO"
},
{
"input": "7 17 11 1 7",
"output": "NO"
},
{
"input": "11 6 37 6 4",
"output": "YES"
},
{
"input": "9 6 22 8 1",
"output": "NO"
},
{
"input": "3 10 5 5 9",
"output": "YES"
},
{
"input": "7 12 22 11 2",
"output": "YES"
},
{
"input": "7 19 4 7 3",
"output": "NO"
},
{
"input": "11 36 21 4 6",
"output": "NO"
},
{
"input": "10 32 49 1 3",
"output": "YES"
},
{
"input": "1 9 43 11 3",
"output": "NO"
},
{
"input": "1 8 33 4 8",
"output": "NO"
},
{
"input": "3 0 33 9 4",
"output": "NO"
},
{
"input": "7 15 9 10 3",
"output": "NO"
},
{
"input": "8 3 57 11 1",
"output": "NO"
},
{
"input": "1 33 49 5 9",
"output": "NO"
},
{
"input": "3 40 0 5 7",
"output": "YES"
},
{
"input": "5 50 9 2 7",
"output": "NO"
},
{
"input": "10 0 52 6 1",
"output": "YES"
},
{
"input": "3 10 4 1 11",
"output": "NO"
},
{
"input": "2 41 53 4 6",
"output": "YES"
},
{
"input": "10 29 30 4 7",
"output": "NO"
},
{
"input": "5 13 54 9 11",
"output": "NO"
},
{
"input": "1 0 23 3 9",
"output": "NO"
},
{
"input": "1 0 41 12 1",
"output": "NO"
},
{
"input": "6 30 30 3 9",
"output": "YES"
},
{
"input": "3 7 32 11 10",
"output": "YES"
},
{
"input": "1 0 25 12 4",
"output": "NO"
},
{
"input": "12 0 0 5 6",
"output": "YES"
},
{
"input": "1 5 4 3 2",
"output": "YES"
},
{
"input": "6 30 30 9 10",
"output": "YES"
},
{
"input": "6 0 0 2 8",
"output": "NO"
},
{
"input": "10 50 59 9 10",
"output": "YES"
},
{
"input": "12 59 59 12 6",
"output": "NO"
},
{
"input": "3 0 30 3 4",
"output": "NO"
},
{
"input": "2 10 10 1 11",
"output": "YES"
},
{
"input": "10 5 30 1 12",
"output": "YES"
},
{
"input": "5 29 31 5 10",
"output": "YES"
},
{
"input": "5 2 2 11 2",
"output": "NO"
},
{
"input": "5 15 46 3 10",
"output": "YES"
},
{
"input": "1 30 50 1 2",
"output": "NO"
},
{
"input": "5 26 14 1 12",
"output": "YES"
},
{
"input": "1 58 43 12 1",
"output": "YES"
},
{
"input": "12 0 12 11 1",
"output": "NO"
},
{
"input": "6 52 41 6 5",
"output": "YES"
},
{
"input": "5 8 2 1 3",
"output": "NO"
},
{
"input": "2 0 0 1 3",
"output": "NO"
},
{
"input": "1 5 6 2 1",
"output": "YES"
},
{
"input": "9 5 5 11 12",
"output": "YES"
},
{
"input": "12 5 19 3 4",
"output": "NO"
},
{
"input": "6 14 59 1 3",
"output": "NO"
},
{
"input": "10 38 34 4 12",
"output": "YES"
},
{
"input": "2 54 14 2 12",
"output": "YES"
},
{
"input": "5 31 0 6 7",
"output": "NO"
},
{
"input": "6 15 30 3 9",
"output": "YES"
},
{
"input": "3 54 41 8 10",
"output": "NO"
},
{
"input": "3 39 10 10 12",
"output": "YES"
},
{
"input": "1 11 50 1 2",
"output": "NO"
},
{
"input": "5 40 24 8 1",
"output": "NO"
},
{
"input": "9 5 59 1 3",
"output": "NO"
},
{
"input": "5 0 0 6 7",
"output": "YES"
},
{
"input": "4 40 59 6 8",
"output": "YES"
},
{
"input": "10 13 55 12 1",
"output": "YES"
},
{
"input": "6 50 0 5 6",
"output": "YES"
},
{
"input": "7 59 3 7 4",
"output": "YES"
},
{
"input": "6 0 1 6 7",
"output": "NO"
},
{
"input": "6 15 55 3 5",
"output": "NO"
},
{
"input": "12 9 55 10 2",
"output": "YES"
},
{
"input": "2 0 1 11 2",
"output": "NO"
},
{
"input": "8 45 17 12 9",
"output": "NO"
},
{
"input": "5 30 31 11 3",
"output": "YES"
},
{
"input": "6 43 0 10 6",
"output": "NO"
},
{
"input": "6 30 30 1 11",
"output": "YES"
},
{
"input": "11 59 59 11 12",
"output": "YES"
},
{
"input": "5 45 35 9 5",
"output": "NO"
},
{
"input": "2 43 4 9 7",
"output": "NO"
},
{
"input": "12 30 50 6 9",
"output": "NO"
},
{
"input": "1 10 1 2 3",
"output": "NO"
},
{
"input": "10 5 55 9 1",
"output": "NO"
},
{
"input": "1 59 59 2 3",
"output": "YES"
},
{
"input": "1 49 14 10 3",
"output": "NO"
},
{
"input": "3 15 15 2 4",
"output": "YES"
},
{
"input": "10 5 55 1 5",
"output": "NO"
},
{
"input": "6 33 45 12 6",
"output": "YES"
},
{
"input": "1 20 20 11 1",
"output": "YES"
},
{
"input": "2 30 45 1 11",
"output": "YES"
},
{
"input": "1 55 1 11 10",
"output": "YES"
},
{
"input": "3 0 1 11 1",
"output": "NO"
},
{
"input": "1 5 6 1 12",
"output": "YES"
},
{
"input": "12 10 5 11 4",
"output": "YES"
},
{
"input": "6 5 59 12 1",
"output": "YES"
},
{
"input": "12 0 20 11 12",
"output": "YES"
},
{
"input": "3 25 30 4 5",
"output": "YES"
},
{
"input": "2 15 18 11 1",
"output": "YES"
},
{
"input": "12 5 48 11 9",
"output": "NO"
},
{
"input": "6 30 30 10 2",
"output": "YES"
},
{
"input": "1 0 11 1 2",
"output": "NO"
},
{
"input": "10 0 1 10 11",
"output": "NO"
},
{
"input": "3 30 45 10 1",
"output": "YES"
},
{
"input": "11 21 56 3 12",
"output": "YES"
},
{
"input": "3 16 16 3 4",
"output": "YES"
},
{
"input": "11 55 55 1 12",
"output": "YES"
},
{
"input": "12 12 12 11 12",
"output": "YES"
},
{
"input": "3 5 1 1 2",
"output": "NO"
},
{
"input": "3 30 45 10 11",
"output": "YES"
},
{
"input": "10 0 1 9 10",
"output": "YES"
},
{
"input": "3 0 5 3 6",
"output": "NO"
},
{
"input": "1 1 49 1 10",
"output": "NO"
},
{
"input": "9 45 15 11 12",
"output": "YES"
},
{
"input": "12 15 59 3 8",
"output": "NO"
},
{
"input": "5 0 5 3 6",
"output": "NO"
},
{
"input": "3 30 45 1 2",
"output": "YES"
},
{
"input": "2 10 11 2 4",
"output": "YES"
},
{
"input": "2 10 10 4 3",
"output": "YES"
},
{
"input": "3 30 59 1 2",
"output": "YES"
},
{
"input": "11 59 59 12 11",
"output": "YES"
},
{
"input": "10 25 50 5 6",
"output": "NO"
},
{
"input": "6 30 30 9 3",
"output": "YES"
},
{
"input": "8 14 40 12 3",
"output": "NO"
},
{
"input": "2 10 10 1 6",
"output": "YES"
}
] | 1,562,677,074 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 0 | h,m,s,t1,t2=list(map(float,input().split()))
m=m*12/60
s=s*12/60
if t1>t2:
t3=t1
t1=t2
t2=t3
numb=0
if t1<h<t2:
numb+=1
if t1<m<t2:
numb+=1
if numb==0 or numb==2:
print('YES')
else:
print('NO')
| Title: Race Against Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.
The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds.
Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction.
Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way).
Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face.
Input Specification:
Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2).
Misha's position and the target time do not coincide with the position of any hand.
Output Specification:
Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Demo Input:
['12 30 45 3 11\n', '12 0 1 12 1\n', '3 47 0 4 9\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n']
Note:
The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same. | ```python
h,m,s,t1,t2=list(map(float,input().split()))
m=m*12/60
s=s*12/60
if t1>t2:
t3=t1
t1=t2
t2=t3
numb=0
if t1<h<t2:
numb+=1
if t1<m<t2:
numb+=1
if numb==0 or numb==2:
print('YES')
else:
print('NO')
``` | 0 |
|
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1.
These conditions define all the values in the table.
You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above. | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
},
{
"input": "9",
"output": "12870"
},
{
"input": "10",
"output": "48620"
},
{
"input": "8",
"output": "3432"
}
] | 1,688,803,721 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | n = int(input())
s = []
x = [[0] * n for _ in range(n)]
for i in range(n):
x[i][0] = 1
x[0][i] = 1
for i in range(1, n):
for j in range(1, n):
x[i][j] = x[i - 1][j] + x[i][j - 1]
for row in x:
s.append(max(row))
m = max(s)
print(m) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1.
These conditions define all the values in the table.
You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above.
Input Specification:
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Output Specification:
Print a single line containing a positive integer *m* — the maximum value in the table.
Demo Input:
['1\n', '5\n']
Demo Output:
['1', '70']
Note:
In the second test the rows of the table look as follows: | ```python
n = int(input())
s = []
x = [[0] * n for _ in range(n)]
for i in range(n):
x[i][0] = 1
x[0][i] = 1
for i in range(1, n):
for j in range(1, n):
x[i][j] = x[i - 1][j] + x[i][j - 1]
for row in x:
s.append(max(row))
m = max(s)
print(m)
``` | 3 |
|
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct. | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different. | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10) | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"input": "10\n68 47 67 29 63 71 71 65 54 56",
"output": "10"
},
{
"input": "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92",
"output": "4"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14",
"output": "0"
},
{
"input": "35\n37 41 46 39 47 39 44 47 44 42 44 43 47 39 46 39 38 42 39 37 40 44 41 42 41 42 39 42 36 36 42 36 42 42 42",
"output": "7"
},
{
"input": "40\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99",
"output": "47"
},
{
"input": "50\n48 52 44 54 53 56 62 49 39 41 53 39 40 64 53 50 62 48 40 52 51 48 40 52 61 62 62 61 48 64 55 57 56 40 48 58 41 60 60 56 64 50 64 45 48 45 46 63 59 57",
"output": "50"
},
{
"input": "57\n7 24 17 19 6 19 10 11 12 22 14 5 5 11 13 10 24 19 24 24 24 11 21 20 4 14 24 24 18 13 24 3 20 3 3 3 3 9 3 9 22 22 16 3 3 3 15 11 3 3 8 17 10 13 3 14 13",
"output": "3"
},
{
"input": "65\n58 50 35 44 35 37 36 58 38 36 58 56 56 49 48 56 58 43 40 44 52 44 58 58 57 50 43 35 55 39 38 49 53 56 50 42 41 56 34 57 49 38 34 51 56 38 58 40 53 46 48 34 38 43 49 49 58 56 41 43 44 34 38 48 36",
"output": "3"
},
{
"input": "69\n70 48 49 48 49 71 48 53 55 69 48 53 54 58 53 63 48 48 69 67 72 75 71 75 74 74 57 63 65 60 48 48 65 48 48 51 50 49 62 53 76 68 76 56 76 76 64 76 76 57 61 76 73 51 59 76 65 50 69 50 76 67 76 63 62 74 74 58 73",
"output": "73"
},
{
"input": "75\n70 65 64 71 71 64 71 64 68 71 65 64 65 68 71 66 66 69 68 63 69 65 71 69 68 68 71 67 71 65 65 65 71 71 65 69 63 66 62 67 64 63 62 64 67 65 62 69 62 64 69 62 67 64 67 70 64 63 64 64 69 62 62 64 70 62 62 68 67 69 62 64 66 70 68",
"output": "7"
},
{
"input": "84\n92 95 84 85 94 80 90 86 80 92 95 84 86 83 86 83 93 91 95 92 84 88 82 84 84 84 80 94 93 80 94 80 95 83 85 80 95 95 80 84 86 92 83 81 90 87 81 89 92 93 80 87 90 85 93 85 93 94 93 89 94 83 93 91 80 83 90 94 95 80 95 92 85 84 93 94 94 82 91 95 95 89 85 94",
"output": "15"
},
{
"input": "90\n86 87 72 77 82 71 75 78 61 67 79 90 64 94 94 74 85 87 73 76 71 71 60 69 77 73 76 80 82 57 62 57 57 83 76 72 75 87 72 94 77 85 59 82 86 69 62 80 95 73 83 94 79 85 91 68 85 74 93 95 68 75 89 93 83 78 95 78 83 77 81 85 66 92 63 65 75 78 67 91 77 74 59 86 77 76 90 67 70 64",
"output": "104"
},
{
"input": "91\n94 98 96 94 95 98 98 95 98 94 94 98 95 95 99 97 97 94 95 98 94 98 96 98 96 98 97 95 94 94 94 97 94 96 98 98 98 94 96 95 94 95 97 97 97 98 94 98 96 95 98 96 96 98 94 97 96 98 97 95 97 98 94 95 94 94 97 94 96 97 97 93 94 95 95 94 96 98 97 96 94 98 98 96 96 96 96 96 94 96 97",
"output": "33"
},
{
"input": "92\n44 28 32 29 41 41 36 39 40 39 41 35 41 28 35 27 41 34 28 38 43 43 41 38 27 26 28 36 30 29 39 32 35 35 32 30 39 30 37 27 41 41 28 30 43 31 35 33 36 28 44 40 41 35 31 42 37 38 37 34 39 40 27 40 33 33 44 43 34 33 34 34 35 38 38 37 30 39 35 41 45 42 41 32 33 33 31 30 43 41 43 43",
"output": "145"
},
{
"input": "93\n46 32 52 36 39 30 57 63 63 30 32 44 27 59 46 38 40 45 44 62 35 36 51 48 39 58 36 51 51 51 48 58 59 36 29 35 31 49 64 60 34 38 42 56 33 42 52 31 63 34 45 51 35 45 33 53 33 62 31 38 66 29 51 54 28 61 32 45 57 41 36 34 47 36 31 28 67 48 52 46 32 40 64 58 27 53 43 57 34 66 43 39 26",
"output": "76"
},
{
"input": "94\n56 55 54 31 32 42 46 29 24 54 40 40 20 45 35 56 32 33 51 39 26 56 21 56 51 27 29 39 56 52 54 43 43 55 48 51 44 49 52 49 23 19 19 28 20 26 45 33 35 51 42 36 25 25 38 23 21 35 54 50 41 20 37 28 42 20 22 43 37 34 55 21 24 38 19 41 45 34 19 33 44 54 38 31 23 53 35 32 47 40 39 31 20 34",
"output": "15"
},
{
"input": "95\n57 71 70 77 64 64 76 81 81 58 63 75 81 77 71 71 71 60 70 70 69 67 62 64 78 64 69 62 76 76 57 70 68 77 70 68 73 77 79 73 60 57 69 60 74 65 58 75 75 74 73 73 65 75 72 57 81 62 62 70 67 58 76 57 79 81 68 64 58 77 70 59 79 64 80 58 71 59 81 71 80 64 78 80 78 65 70 68 78 80 57 63 64 76 81",
"output": "11"
},
{
"input": "96\n96 95 95 95 96 97 95 97 96 95 98 96 97 95 98 96 98 96 98 96 98 95 96 95 95 95 97 97 95 95 98 98 95 96 96 95 97 96 98 96 95 97 97 95 97 97 95 94 96 96 97 96 97 97 96 94 94 97 95 95 95 96 95 96 95 97 97 95 97 96 95 94 97 97 97 96 97 95 96 94 94 95 97 94 94 97 97 97 95 97 97 95 94 96 95 95",
"output": "13"
},
{
"input": "97\n14 15 12 12 13 15 12 15 12 12 12 12 12 14 15 15 13 12 15 15 12 12 12 13 14 15 15 13 14 15 14 14 14 14 12 13 12 13 13 12 15 12 13 13 15 12 15 13 12 13 13 13 14 13 12 15 14 13 14 15 13 14 14 13 14 12 15 12 14 12 13 14 15 14 13 15 13 12 15 15 15 13 15 15 13 14 16 16 16 13 15 13 15 14 15 15 15",
"output": "104"
},
{
"input": "98\n37 69 35 70 58 69 36 47 41 63 60 54 49 35 55 50 35 53 52 43 35 41 40 49 38 35 48 70 42 35 35 65 56 54 44 59 59 48 51 49 59 67 35 60 69 35 58 50 35 44 48 69 41 58 44 45 35 47 70 61 49 47 37 39 35 51 44 70 72 65 36 41 63 63 48 66 45 50 50 71 37 52 72 67 72 39 72 39 36 64 48 72 69 49 45 72 72 67",
"output": "100"
},
{
"input": "99\n31 31 16 15 19 31 19 22 29 27 12 22 28 30 25 33 26 25 19 22 34 21 17 33 31 22 16 26 22 30 31 17 13 33 13 17 28 25 18 33 27 22 31 22 13 27 20 22 23 15 24 32 29 13 16 20 32 33 14 33 19 27 16 28 25 17 17 28 18 26 32 33 19 23 30 13 14 23 24 28 14 28 22 20 30 14 24 23 17 29 18 28 29 21 28 18 16 24 32",
"output": "107"
},
{
"input": "100\n37 54 39 29 32 49 21 13 34 21 16 42 34 27 16 26 7 34 51 9 11 27 16 40 36 7 48 52 30 42 42 52 51 11 32 26 6 7 28 54 48 51 6 54 42 20 51 48 46 4 4 31 47 6 9 16 8 23 36 50 49 30 47 37 45 24 48 26 8 50 18 24 27 13 39 7 37 34 5 43 42 19 34 23 52 38 35 6 29 11 53 49 21 29 36 22 45 33 51 22",
"output": "50"
},
{
"input": "100\n41 5 20 23 5 47 28 28 64 5 12 14 34 56 22 48 6 52 39 55 62 40 24 54 39 28 56 27 35 51 14 24 38 10 55 20 39 62 52 2 30 55 49 48 15 23 59 44 31 28 66 29 62 59 31 13 28 12 50 45 41 47 29 27 64 66 14 39 62 22 44 63 24 5 63 17 42 7 25 41 49 33 31 51 63 3 37 66 19 9 2 40 16 45 56 21 34 29 39 61",
"output": "59"
},
{
"input": "100\n66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95",
"output": "99"
},
{
"input": "100\n81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "1"
},
{
"input": "2\n100 99",
"output": "0"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "197"
},
{
"input": "100\n87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87",
"output": "0"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 3 2",
"output": "2"
}
] | 1,695,037,991 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | n = int(input())
l = list(map(int, input().split()))
a,b = l.index(max(l)), l.index(min(l))
count = 0
if a > b:
while a != 0:
a-=1
count+=1
b+=1
if(b>a):
while b != 0:
b-=1
count+=1
print(count) | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
Input Specification:
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different.
Output Specification:
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
Demo Input:
['4\n33 44 11 22\n', '7\n10 10 58 31 63 40 76\n']
Demo Output:
['2\n', '10\n']
Note:
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10) | ```python
n = int(input())
l = list(map(int, input().split()))
a,b = l.index(max(l)), l.index(min(l))
count = 0
if a > b:
while a != 0:
a-=1
count+=1
b+=1
if(b>a):
while b != 0:
b-=1
count+=1
print(count)
``` | 0 |
|
468 | A | 24 Game | PROGRAMMING | 1,500 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them, let's denote them *a* and *b*, erase them from the sequence, and append to the sequence either *a*<=+<=*b*, or *a*<=-<=*b*, or *a*<=×<=*b*.
After *n*<=-<=1 steps there is only one number left. Can you make this number equal to 24? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). | If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes).
If there is a way to obtain 24 as the result number, in the following *n*<=-<=1 lines print the required operations an operation per line. Each operation should be in form: "*a* *op* *b* = *c*". Where *a* and *b* are the numbers you've picked at this operation; *op* is either "+", or "-", or "*"; *c* is the result of corresponding operation. Note, that the absolute value of *c* mustn't be greater than 1018. The result of the last operation must be equal to 24. Separate operator sign and equality sign from numbers with spaces.
If there are multiple valid answers, you may print any of them. | [
"1\n",
"8\n"
] | [
"NO\n",
"YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24\n"
] | none | 500 | [
{
"input": "1",
"output": "NO"
},
{
"input": "8",
"output": "YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24"
},
{
"input": "12",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24"
},
{
"input": "100",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "1000",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "987",
"output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24\n11 - 10 = 1\n24 * 1 = 24\n13 - 12 = 1\n24 * 1 = 24\n15 - 14 = 1\n24 * 1 = 24\n17 - 16 = 1\n24 * 1 = 24\n19 - 18 = 1\n24 * 1 = 24\n21 - 20 = 1\n24 * 1 = 24\n23 - 22 = 1\n24 * 1 = 24\n25 - 24 = 1\n24 * 1 = 24\n27 - 26 = 1\n24 * 1 = 24\n29 - 28 = 1\n24 * 1 = 24\n31 - 30 = 1\n24 * 1 = 24\n33 - 32 = 1\n24 * 1 = 24\n35 - 34 = 1\n24 * 1 = 24\n37 - 36 = 1\n24 * 1 = 24\n39 - 38 = 1\n24 * 1 = 24\n41 - 40 = 1\n24 * 1 = 2..."
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24"
},
{
"input": "5",
"output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24"
},
{
"input": "6",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24"
},
{
"input": "7",
"output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24"
},
{
"input": "100000",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "99999",
"output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24\n11 - 10 = 1\n24 * 1 = 24\n13 - 12 = 1\n24 * 1 = 24\n15 - 14 = 1\n24 * 1 = 24\n17 - 16 = 1\n24 * 1 = 24\n19 - 18 = 1\n24 * 1 = 24\n21 - 20 = 1\n24 * 1 = 24\n23 - 22 = 1\n24 * 1 = 24\n25 - 24 = 1\n24 * 1 = 24\n27 - 26 = 1\n24 * 1 = 24\n29 - 28 = 1\n24 * 1 = 24\n31 - 30 = 1\n24 * 1 = 24\n33 - 32 = 1\n24 * 1 = 24\n35 - 34 = 1\n24 * 1 = 24\n37 - 36 = 1\n24 * 1 = 24\n39 - 38 = 1\n24 * 1 = 24\n41 - 40 = 1\n24 * 1 = 2..."
},
{
"input": "99998",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "99997",
"output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24\n11 - 10 = 1\n24 * 1 = 24\n13 - 12 = 1\n24 * 1 = 24\n15 - 14 = 1\n24 * 1 = 24\n17 - 16 = 1\n24 * 1 = 24\n19 - 18 = 1\n24 * 1 = 24\n21 - 20 = 1\n24 * 1 = 24\n23 - 22 = 1\n24 * 1 = 24\n25 - 24 = 1\n24 * 1 = 24\n27 - 26 = 1\n24 * 1 = 24\n29 - 28 = 1\n24 * 1 = 24\n31 - 30 = 1\n24 * 1 = 24\n33 - 32 = 1\n24 * 1 = 24\n35 - 34 = 1\n24 * 1 = 24\n37 - 36 = 1\n24 * 1 = 24\n39 - 38 = 1\n24 * 1 = 24\n41 - 40 = 1\n24 * 1 = 2..."
},
{
"input": "580",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "422",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "116",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "447",
"output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24\n11 - 10 = 1\n24 * 1 = 24\n13 - 12 = 1\n24 * 1 = 24\n15 - 14 = 1\n24 * 1 = 24\n17 - 16 = 1\n24 * 1 = 24\n19 - 18 = 1\n24 * 1 = 24\n21 - 20 = 1\n24 * 1 = 24\n23 - 22 = 1\n24 * 1 = 24\n25 - 24 = 1\n24 * 1 = 24\n27 - 26 = 1\n24 * 1 = 24\n29 - 28 = 1\n24 * 1 = 24\n31 - 30 = 1\n24 * 1 = 24\n33 - 32 = 1\n24 * 1 = 24\n35 - 34 = 1\n24 * 1 = 24\n37 - 36 = 1\n24 * 1 = 24\n39 - 38 = 1\n24 * 1 = 24\n41 - 40 = 1\n24 * 1 = 2..."
},
{
"input": "62052",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "25770",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "56118",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "86351",
"output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24\n11 - 10 = 1\n24 * 1 = 24\n13 - 12 = 1\n24 * 1 = 24\n15 - 14 = 1\n24 * 1 = 24\n17 - 16 = 1\n24 * 1 = 24\n19 - 18 = 1\n24 * 1 = 24\n21 - 20 = 1\n24 * 1 = 24\n23 - 22 = 1\n24 * 1 = 24\n25 - 24 = 1\n24 * 1 = 24\n27 - 26 = 1\n24 * 1 = 24\n29 - 28 = 1\n24 * 1 = 24\n31 - 30 = 1\n24 * 1 = 24\n33 - 32 = 1\n24 * 1 = 24\n35 - 34 = 1\n24 * 1 = 24\n37 - 36 = 1\n24 * 1 = 24\n39 - 38 = 1\n24 * 1 = 24\n41 - 40 = 1\n24 * 1 = 2..."
},
{
"input": "48108",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "33373",
"output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24\n11 - 10 = 1\n24 * 1 = 24\n13 - 12 = 1\n24 * 1 = 24\n15 - 14 = 1\n24 * 1 = 24\n17 - 16 = 1\n24 * 1 = 24\n19 - 18 = 1\n24 * 1 = 24\n21 - 20 = 1\n24 * 1 = 24\n23 - 22 = 1\n24 * 1 = 24\n25 - 24 = 1\n24 * 1 = 24\n27 - 26 = 1\n24 * 1 = 24\n29 - 28 = 1\n24 * 1 = 24\n31 - 30 = 1\n24 * 1 = 24\n33 - 32 = 1\n24 * 1 = 24\n35 - 34 = 1\n24 * 1 = 24\n37 - 36 = 1\n24 * 1 = 24\n39 - 38 = 1\n24 * 1 = 24\n41 - 40 = 1\n24 * 1 = 2..."
},
{
"input": "9782",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "19082",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..."
},
{
"input": "4",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24"
},
{
"input": "7",
"output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24"
},
{
"input": "3",
"output": "NO"
}
] | 1,626,961,482 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 249 | 26,828,800 | n=int(input())
if n>=4:
print("YES")
if n==4:
print("4 * 3 = 12")
print("12 * 2 = 24")
print("24 * 1 = 24")
elif n==5:
print("5 * 4 = 20")
print("20 + 3 = 23")
print("23 + 2 = 25")
print("25 - 1 = 24")
else:
print("4 * 3 = 12")
print("12 * 2 = 24")
print(str(n)+" - "+str(n-1)+" = 1")
print("1 - 1 = 0")
for i in range(5,n-1):
print(str(i)+" * 0 = 0")
print("24 + 0 = 24")
else:
print("NO") | Title: 24 Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them, let's denote them *a* and *b*, erase them from the sequence, and append to the sequence either *a*<=+<=*b*, or *a*<=-<=*b*, or *a*<=×<=*b*.
After *n*<=-<=1 steps there is only one number left. Can you make this number equal to 24?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105).
Output Specification:
If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes).
If there is a way to obtain 24 as the result number, in the following *n*<=-<=1 lines print the required operations an operation per line. Each operation should be in form: "*a* *op* *b* = *c*". Where *a* and *b* are the numbers you've picked at this operation; *op* is either "+", or "-", or "*"; *c* is the result of corresponding operation. Note, that the absolute value of *c* mustn't be greater than 1018. The result of the last operation must be equal to 24. Separate operator sign and equality sign from numbers with spaces.
If there are multiple valid answers, you may print any of them.
Demo Input:
['1\n', '8\n']
Demo Output:
['NO\n', 'YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24\n']
Note:
none | ```python
n=int(input())
if n>=4:
print("YES")
if n==4:
print("4 * 3 = 12")
print("12 * 2 = 24")
print("24 * 1 = 24")
elif n==5:
print("5 * 4 = 20")
print("20 + 3 = 23")
print("23 + 2 = 25")
print("25 - 1 = 24")
else:
print("4 * 3 = 12")
print("12 * 2 = 24")
print(str(n)+" - "+str(n-1)+" = 1")
print("1 - 1 = 0")
for i in range(5,n-1):
print(str(i)+" * 0 = 0")
print("24 + 0 = 24")
else:
print("NO")
``` | 3 |
|
868 | A | Bark to Unlock | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark *n* distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not. | The first line contains two lowercase English letters — the password on the phone.
The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows.
The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct. | Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"ya\n4\nah\noy\nto\nha\n",
"hp\n2\nht\ntp\n",
"ah\n1\nha\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".
In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.
In the third example the string "hahahaha" contains "ah" as a substring. | 250 | [
{
"input": "ya\n4\nah\noy\nto\nha",
"output": "YES"
},
{
"input": "hp\n2\nht\ntp",
"output": "NO"
},
{
"input": "ah\n1\nha",
"output": "YES"
},
{
"input": "bb\n4\nba\nab\naa\nbb",
"output": "YES"
},
{
"input": "bc\n4\nca\nba\nbb\ncc",
"output": "YES"
},
{
"input": "ba\n4\ncd\nad\ncc\ncb",
"output": "YES"
},
{
"input": "pg\n4\nzl\nxs\ndi\nxn",
"output": "NO"
},
{
"input": "bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nro\nya\nqy\ngu\nvk\nqk\ngs\nyq\nop\nhw\nrj\neo\nlz\nbh\nkr\nkb\nma\nrd\nza\nuf\nhq\nmc\nmn\nti\nwn\nsh\nax\nsi\nnd\ntz\ndu\nfj\nkl\nws\now\nnf\nvr\nye\nzc\niw\nfv\nkv\noo\nsm\nbc\nrs\nau\nuz\nuv\ngh\nsu\njn\ndz\nrl\nwj\nbk\nzl\nas\nms\nit\nwu",
"output": "YES"
},
{
"input": "bb\n1\naa",
"output": "NO"
},
{
"input": "qm\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm",
"output": "NO"
},
{
"input": "mq\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm",
"output": "YES"
},
{
"input": "aa\n1\naa",
"output": "YES"
},
{
"input": "bb\n1\nbb",
"output": "YES"
},
{
"input": "ba\n1\ncc",
"output": "NO"
},
{
"input": "ha\n1\nha",
"output": "YES"
},
{
"input": "aa\n1\naa",
"output": "YES"
},
{
"input": "ez\n1\njl",
"output": "NO"
},
{
"input": "aa\n2\nab\nba",
"output": "YES"
},
{
"input": "aa\n2\nca\ncc",
"output": "NO"
},
{
"input": "dd\n2\nac\ndc",
"output": "NO"
},
{
"input": "qc\n2\nyc\nkr",
"output": "NO"
},
{
"input": "aa\n3\nba\nbb\nab",
"output": "YES"
},
{
"input": "ca\n3\naa\nbb\nab",
"output": "NO"
},
{
"input": "ca\n3\nbc\nbd\nca",
"output": "YES"
},
{
"input": "dd\n3\nmt\nrg\nxl",
"output": "NO"
},
{
"input": "be\n20\nad\ncd\ncb\ndb\ndd\naa\nab\nca\nae\ned\ndc\nbb\nba\nda\nee\nea\ncc\nac\nec\neb",
"output": "YES"
},
{
"input": "fc\n20\nca\nbb\nce\nfd\nde\nfa\ncc\nec\nfb\nfc\nff\nbe\ncf\nba\ndb\ned\naf\nae\nda\nef",
"output": "YES"
},
{
"input": "ca\n20\ndc\naf\ndf\neg\naa\nbc\nea\nbd\nab\ndb\ngc\nfb\nba\nbe\nee\ngf\ncf\nag\nga\nca",
"output": "YES"
},
{
"input": "ke\n20\nzk\nra\nbq\nqz\nwt\nzg\nmz\nuk\nge\nuv\nud\nfd\neh\ndm\nsk\nki\nfv\ntp\nat\nfb",
"output": "YES"
},
{
"input": "hh\n50\nag\nhg\ndg\nfh\neg\ngh\ngd\nda\nbh\nab\nhf\ndc\nhb\nfe\nad\nec\nac\nfd\nca\naf\ncg\nhd\neb\nce\nhe\nha\ngb\nea\nae\nfb\nff\nbe\nch\nhh\nee\nde\nge\ngf\naa\ngg\neh\ned\nbf\nfc\nah\nga\nbd\ncb\nbg\nbc",
"output": "YES"
},
{
"input": "id\n50\nhi\ndc\nfg\nee\ngi\nhc\nac\nih\ndg\nfc\nde\ned\nie\neb\nic\ncf\nib\nfa\ngc\nba\nbe\nga\nha\nhg\nia\ndf\nab\nei\neh\nad\nii\nci\ndh\nec\nif\ndi\nbg\nag\nhe\neg\nca\nae\ndb\naa\nid\nfh\nhh\ncc\nfb\ngb",
"output": "YES"
},
{
"input": "fe\n50\nje\nbi\nbg\ngc\nfb\nig\ndf\nji\ndg\nfe\nfc\ncf\ngf\nai\nhe\nac\nch\nja\ngh\njf\nge\ncb\nij\ngb\ncg\naf\neh\nee\nhd\njd\njb\nii\nca\nci\nga\nab\nhi\nag\nfj\nej\nfi\nie\ndj\nfg\nef\njc\njg\njh\nhf\nha",
"output": "YES"
},
{
"input": "rn\n50\nba\nec\nwg\nao\nlk\nmz\njj\ncf\nfa\njk\ndy\nsz\njs\nzr\nqv\ntx\nwv\nrd\nqw\nls\nrr\nvt\nrx\nkc\neh\nnj\niq\nyi\nkh\nue\nnv\nkz\nrn\nes\nua\nzf\nvu\nll\neg\nmj\ncz\nzj\nxz\net\neb\nci\nih\nig\nam\nvd",
"output": "YES"
},
{
"input": "ee\n100\nah\nfb\ncd\nbi\nii\nai\nid\nag\nie\nha\ndi\nec\nae\nce\njb\ndg\njg\ngd\ngf\nda\nih\nbd\nhj\ngg\nhb\ndf\ned\nfh\naf\nja\nci\nfc\nic\nji\nac\nhi\nfj\nch\nbc\njd\naa\nff\nad\ngj\nej\nde\nee\nhe\ncf\nga\nia\ncg\nbb\nhc\nbe\ngi\njf\nbg\naj\njj\nbh\nfe\ndj\nef\ngb\nge\ndb\nig\ncj\ndc\nij\njh\nei\ndd\nib\nhf\neg\nbf\nfg\nab\ngc\nfd\nhd\ngh\neh\njc\neb\nhh\nca\nje\nbj\nif\nea\nhg\nfa\ncc\nba\ndh\ncb\nfi",
"output": "YES"
},
{
"input": "if\n100\njd\nbc\nje\nhi\nga\nde\nkb\nfc\ncd\ngd\naj\ncb\nei\nbf\ncf\ndk\ndb\ncg\nki\ngg\nkg\nfa\nkj\nii\njf\njg\ngb\nbh\nbg\neh\nhj\nhb\ndg\ndj\njc\njb\nce\ndi\nig\nci\ndf\nji\nhc\nfk\naf\nac\ngk\nhd\nae\nkd\nec\nkc\neb\nfh\nij\nie\nca\nhh\nkf\nha\ndd\nif\nef\nih\nhg\nej\nfe\njk\nea\nib\nck\nhf\nak\ngi\nch\ndc\nba\nke\nad\nka\neg\njh\nja\ngc\nfd\ncc\nab\ngj\nik\nfg\nbj\nhe\nfj\nge\ngh\nhk\nbk\ned\nid\nfi",
"output": "YES"
},
{
"input": "kd\n100\nek\nea\nha\nkf\nkj\ngh\ndl\nfj\nal\nga\nlj\nik\ngd\nid\ncb\nfh\ndk\nif\nbh\nkb\nhc\nej\nhk\ngc\ngb\nef\nkk\nll\nlf\nkh\ncl\nlh\njj\nil\nhh\nci\ndb\ndf\ngk\njg\nch\nbd\ncg\nfg\nda\neb\nlg\ndg\nbk\nje\nbg\nbl\njl\ncj\nhb\nei\naa\ngl\nka\nfa\nfi\naf\nkc\nla\ngi\nij\nib\nle\ndi\nck\nag\nlc\nca\nge\nie\nlb\nke\nii\nae\nig\nic\nhe\ncf\nhd\nak\nfb\nhi\ngf\nad\nba\nhg\nbi\nkl\nac\ngg\ngj\nbe\nlk\nld\naj",
"output": "YES"
},
{
"input": "ab\n1\nab",
"output": "YES"
},
{
"input": "ya\n1\nya",
"output": "YES"
},
{
"input": "ay\n1\nyb",
"output": "NO"
},
{
"input": "ax\n2\nii\nxa",
"output": "YES"
},
{
"input": "hi\n1\nhi",
"output": "YES"
},
{
"input": "ag\n1\nag",
"output": "YES"
},
{
"input": "th\n1\nth",
"output": "YES"
},
{
"input": "sb\n1\nsb",
"output": "YES"
},
{
"input": "hp\n1\nhp",
"output": "YES"
},
{
"input": "ah\n1\nah",
"output": "YES"
},
{
"input": "ta\n1\nta",
"output": "YES"
},
{
"input": "tb\n1\ntb",
"output": "YES"
},
{
"input": "ab\n5\nca\nda\nea\nfa\nka",
"output": "NO"
},
{
"input": "ac\n1\nac",
"output": "YES"
},
{
"input": "ha\n2\nha\nzz",
"output": "YES"
},
{
"input": "ok\n1\nok",
"output": "YES"
},
{
"input": "bc\n1\nbc",
"output": "YES"
},
{
"input": "az\n1\nzz",
"output": "NO"
},
{
"input": "ab\n2\nba\ntt",
"output": "YES"
},
{
"input": "ah\n2\nap\nhp",
"output": "NO"
},
{
"input": "sh\n1\nsh",
"output": "YES"
},
{
"input": "az\n1\nby",
"output": "NO"
},
{
"input": "as\n1\nas",
"output": "YES"
},
{
"input": "ab\n2\nab\ncd",
"output": "YES"
},
{
"input": "ab\n2\nxa\nza",
"output": "NO"
},
{
"input": "ab\n2\net\nab",
"output": "YES"
},
{
"input": "ab\n1\naa",
"output": "NO"
},
{
"input": "ab\n2\nab\nde",
"output": "YES"
},
{
"input": "ah\n2\nba\nha",
"output": "YES"
},
{
"input": "ha\n3\ndd\ncc\nha",
"output": "YES"
},
{
"input": "oo\n1\nox",
"output": "NO"
},
{
"input": "ab\n2\nax\nbx",
"output": "NO"
},
{
"input": "ww\n4\nuw\now\npo\nko",
"output": "NO"
},
{
"input": "ay\n1\nay",
"output": "YES"
},
{
"input": "yo\n1\nyo",
"output": "YES"
},
{
"input": "ba\n1\nba",
"output": "YES"
},
{
"input": "qw\n1\nqw",
"output": "YES"
},
{
"input": "la\n1\nla",
"output": "YES"
},
{
"input": "ab\n2\nbb\nbc",
"output": "NO"
},
{
"input": "aa\n2\nab\nac",
"output": "NO"
},
{
"input": "ah\n2\nbb\nha",
"output": "YES"
},
{
"input": "ya\n42\nab\nac\nad\nae\naf\nag\nah\nai\nak\naj\nba\nbc\nbd\nbe\nbf\nbg\nbh\nbi\nbk\nbj\ncb\nca\ncd\nce\ncf\ncg\nch\nci\nck\ncj\ndb\ndc\nda\nde\ndf\ndg\ndh\ndi\ndk\ndj\nef\nek",
"output": "NO"
},
{
"input": "ab\n3\nab\nxx\nyy",
"output": "YES"
},
{
"input": "ab\n2\nab\ncc",
"output": "YES"
},
{
"input": "sa\n2\nxx\nas",
"output": "YES"
},
{
"input": "ma\n1\nma",
"output": "YES"
},
{
"input": "ba\n1\nbb",
"output": "NO"
},
{
"input": "bc\n1\nab",
"output": "NO"
},
{
"input": "fa\n1\nfa",
"output": "YES"
},
{
"input": "ap\n1\nap",
"output": "YES"
},
{
"input": "ab\n1\nbb",
"output": "NO"
},
{
"input": "bk\n1\nbk",
"output": "YES"
},
{
"input": "xy\n2\nxy\naa",
"output": "YES"
},
{
"input": "ab\n2\nza\nbz",
"output": "YES"
}
] | 1,507,187,493 | 393 | Python 3 | CHALLENGED | CHALLENGES | 8 | 62 | 0 | import sys
pw = sys.stdin.readline()
n = sys.stdin.readline()
wds = []
for i in range(int(n)):
wds.append(sys.stdin.readline().strip())
fst = False
snd = False
for wd in wds:
if wd[0] == pw[1]:
fst = True
if wd[1] == pw[0]:
snd = True
if fst and snd:
print("YES")
else:
print("NO")
| Title: Bark to Unlock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark *n* distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.
Input Specification:
The first line contains two lowercase English letters — the password on the phone.
The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows.
The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.
Output Specification:
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower).
Demo Input:
['ya\n4\nah\noy\nto\nha\n', 'hp\n2\nht\ntp\n', 'ah\n1\nha\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".
In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.
In the third example the string "hahahaha" contains "ah" as a substring. | ```python
import sys
pw = sys.stdin.readline()
n = sys.stdin.readline()
wds = []
for i in range(int(n)):
wds.append(sys.stdin.readline().strip())
fst = False
snd = False
for wd in wds:
if wd[0] == pw[1]:
fst = True
if wd[1] == pw[0]:
snd = True
if fst and snd:
print("YES")
else:
print("NO")
``` | -1 |
|
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.
Please output the maximum number of cake cells that the cakeminator can eat. | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
- '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry. | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "0"
},
{
"input": "10 10\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS",
"output": "0"
},
{
"input": "10 10\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS",
"output": "30"
},
{
"input": "10 10\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..",
"output": "80"
},
{
"input": "9 5\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS",
"output": "0"
},
{
"input": "9 9\n...S.....\nS.S.....S\n.S....S..\n.S.....SS\n.........\n..S.S..S.\n.SS......\n....S....\n..S...S..",
"output": "17"
},
{
"input": "5 6\nSSSSSS\nSSSSSS\nSSSSSS\nSS.S..\nS.S.SS",
"output": "0"
},
{
"input": "9 8\n........\n.......S\n........\nS.......\n........\n........\nS.......\n........\n.......S",
"output": "64"
},
{
"input": "9 7\n......S\n......S\nS.S.S..\n.......\n.......\n.S.....\n.S....S\n..S....\n.S....S",
"output": "28"
},
{
"input": "10 10\n.....S....\n....SS..S.\n.S...S....\n........SS\n.S.......S\nSS..S.....\n.SS.....SS\nS..S......\n.......SSS\nSSSSS....S",
"output": "10"
},
{
"input": "6 7\n..S.SS.\n......S\n....S.S\nSS..S..\nS..SS.S\n.....S.",
"output": "0"
},
{
"input": "10 6\n.SSSSS\nSSS.SS\nSSSSSS\nS.SSSS\nSSSSS.\nS.SSSS\nSS.SSS\n.SSS.S\n.SSS..\nSS..SS",
"output": "0"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "3 2\nS.\n.S\nS.",
"output": "0"
},
{
"input": "3 2\nS.\n.S\nS.",
"output": "0"
},
{
"input": "4 3\n.S.\nS.S\n.S.\nS.S",
"output": "0"
},
{
"input": "2 3\n...\nSSS",
"output": "3"
},
{
"input": "2 4\nS.SS\nS.SS",
"output": "2"
},
{
"input": "2 2\n..\n.S",
"output": "3"
},
{
"input": "3 2\n.S\n.S\nSS",
"output": "0"
},
{
"input": "2 4\nSS.S\n..S.",
"output": "0"
},
{
"input": "2 3\n...\nS..",
"output": "5"
}
] | 1,682,921,752 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | from sys import stdin, setrecursionlimit, stdout
def solve():
r, c = (int(s) for s in stdin.readline().split())
mas = [stdin.readline().rstrip('\r\n') for _ in range(r)]
banned_rows = set()
banned_cols = set()
for i in range(r):
for j in range(c):
if mas[i][j] == 'S':
banned_rows.add(i)
banned_cols.add(j)
ans = (r-len(banned_rows))*c+(c-len(banned_cols))*r-len(banned_cols)
print(ans)
if __name__ == '__main__':
solve()
| Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.
Please output the maximum number of cake cells that the cakeminator can eat.
Input Specification:
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
- '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry.
Output Specification:
Output the maximum number of cake cells that the cakeminator can eat.
Demo Input:
['3 4\nS...\n....\n..S.\n']
Demo Output:
['8\n']
Note:
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | ```python
from sys import stdin, setrecursionlimit, stdout
def solve():
r, c = (int(s) for s in stdin.readline().split())
mas = [stdin.readline().rstrip('\r\n') for _ in range(r)]
banned_rows = set()
banned_cols = set()
for i in range(r):
for j in range(c):
if mas[i][j] == 'S':
banned_rows.add(i)
banned_cols.add(j)
ans = (r-len(banned_rows))*c+(c-len(banned_cols))*r-len(banned_cols)
print(ans)
if __name__ == '__main__':
solve()
``` | 0 |
|
897 | B | Chtholly's request | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | — I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.
Given integers *k* and *p*, calculate the sum of the *k* smallest zcy numbers and output this sum modulo *p*.
Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! | The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109). | Output single integer — answer to the problem. | [
"2 100\n",
"5 30\n"
] | [
"33\n",
"15\n"
] | In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,000 | [
{
"input": "2 100",
"output": "33"
},
{
"input": "5 30",
"output": "15"
},
{
"input": "42147 412393322",
"output": "251637727"
},
{
"input": "77809 868097296",
"output": "440411873"
},
{
"input": "5105 443422097",
"output": "363192634"
},
{
"input": "75615 376679484",
"output": "373089399"
},
{
"input": "22951 23793302",
"output": "1898631"
},
{
"input": "12785 993582106",
"output": "286204743"
},
{
"input": "60276 428978808",
"output": "376477293"
},
{
"input": "84776 104860385",
"output": "10209596"
},
{
"input": "41984 653766991",
"output": "17823101"
},
{
"input": "100000 1000000000",
"output": "495495496"
},
{
"input": "41163 472310076",
"output": "207304047"
},
{
"input": "6983 765352180",
"output": "586866999"
},
{
"input": "33493 967727004",
"output": "305705165"
},
{
"input": "90898 94010922",
"output": "65928728"
},
{
"input": "67298 349286579",
"output": "156435206"
},
{
"input": "92452 296773064",
"output": "229486976"
},
{
"input": "58832 563860457",
"output": "16775206"
},
{
"input": "90234 156145441",
"output": "44023160"
},
{
"input": "91454 977186148",
"output": "681779748"
},
{
"input": "11108 444095250",
"output": "188075844"
},
{
"input": "46304 584475527",
"output": "275627129"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 1000000000",
"output": "11"
},
{
"input": "100000 1",
"output": "0"
}
] | 1,645,098,773 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 93 | 2,150,400 | a, k = map(int, input().split())
sm = 0
for i in range(1, a + 1):
r = str(i)
sm += int(r + r[::-1])
sm %= k
print(sm % k) | Title: Chtholly's request
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
— I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.
Given integers *k* and *p*, calculate the sum of the *k* smallest zcy numbers and output this sum modulo *p*.
Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!
Input Specification:
The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109).
Output Specification:
Output single integer — answer to the problem.
Demo Input:
['2 100\n', '5 30\n']
Demo Output:
['33\n', '15\n']
Note:
In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
a, k = map(int, input().split())
sm = 0
for i in range(1, a + 1):
r = str(i)
sm += int(r + r[::-1])
sm %= k
print(sm % k)
``` | 3 |
|
46 | A | Ball Game | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | A. Ball Game | 2 | 256 | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends.
The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle. | In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. | [
"10\n",
"3\n"
] | [
"2 4 7 1 6 2 9 7 6\n",
"2 1\n"
] | none | 0 | [
{
"input": "10",
"output": "2 4 7 1 6 2 9 7 6"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "4",
"output": "2 4 3"
},
{
"input": "5",
"output": "2 4 2 1"
},
{
"input": "6",
"output": "2 4 1 5 4"
},
{
"input": "7",
"output": "2 4 7 4 2 1"
},
{
"input": "8",
"output": "2 4 7 3 8 6 5"
},
{
"input": "9",
"output": "2 4 7 2 7 4 2 1"
},
{
"input": "2",
"output": "2"
},
{
"input": "11",
"output": "2 4 7 11 5 11 7 4 2 1"
},
{
"input": "12",
"output": "2 4 7 11 4 10 5 1 10 8 7"
},
{
"input": "13",
"output": "2 4 7 11 3 9 3 11 7 4 2 1"
},
{
"input": "20",
"output": "2 4 7 11 16 2 9 17 6 16 7 19 12 6 1 17 14 12 11"
},
{
"input": "25",
"output": "2 4 7 11 16 22 4 12 21 6 17 4 17 6 21 12 4 22 16 11 7 4 2 1"
},
{
"input": "30",
"output": "2 4 7 11 16 22 29 7 16 26 7 19 2 16 1 17 4 22 11 1 22 14 7 1 26 22 19 17 16"
},
{
"input": "35",
"output": "2 4 7 11 16 22 29 2 11 21 32 9 22 1 16 32 14 32 16 1 22 9 32 21 11 2 29 22 16 11 7 4 2 1"
},
{
"input": "40",
"output": "2 4 7 11 16 22 29 37 6 16 27 39 12 26 1 17 34 12 31 11 32 14 37 21 6 32 19 7 36 26 17 9 2 36 31 27 24 22 21"
},
{
"input": "45",
"output": "2 4 7 11 16 22 29 37 1 11 22 34 2 16 31 2 19 37 11 31 7 29 7 31 11 37 19 2 31 16 2 34 22 11 1 37 29 22 16 11 7 4 2 1"
},
{
"input": "50",
"output": "2 4 7 11 16 22 29 37 46 6 17 29 42 6 21 37 4 22 41 11 32 4 27 1 26 2 29 7 36 16 47 29 12 46 31 17 4 42 31 21 12 4 47 41 36 32 29 27 26"
},
{
"input": "55",
"output": "2 4 7 11 16 22 29 37 46 1 12 24 37 51 11 27 44 7 26 46 12 34 2 26 51 22 49 22 51 26 2 34 12 46 26 7 44 27 11 51 37 24 12 1 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "60",
"output": "2 4 7 11 16 22 29 37 46 56 7 19 32 46 1 17 34 52 11 31 52 14 37 1 26 52 19 47 16 46 17 49 22 56 31 7 44 22 1 41 22 4 47 31 16 2 49 37 26 16 7 59 52 46 41 37 34 32 31"
},
{
"input": "65",
"output": "2 4 7 11 16 22 29 37 46 56 2 14 27 41 56 7 24 42 61 16 37 59 17 41 1 27 54 17 46 11 42 9 42 11 46 17 54 27 1 41 17 59 37 16 61 42 24 7 56 41 27 14 2 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "70",
"output": "2 4 7 11 16 22 29 37 46 56 67 9 22 36 51 67 14 32 51 1 22 44 67 21 46 2 29 57 16 46 7 39 2 36 1 37 4 42 11 51 22 64 37 11 56 32 9 57 36 16 67 49 32 16 1 57 44 32 21 11 2 64 57 51 46 42 39 37 36"
},
{
"input": "75",
"output": "2 4 7 11 16 22 29 37 46 56 67 4 17 31 46 62 4 22 41 61 7 29 52 1 26 52 4 32 61 16 47 4 37 71 31 67 29 67 31 71 37 4 47 16 61 32 4 52 26 1 52 29 7 61 41 22 4 62 46 31 17 4 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "80",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 12 26 41 57 74 12 31 51 72 14 37 61 6 32 59 7 36 66 17 49 2 36 71 27 64 22 61 21 62 24 67 31 76 42 9 57 26 76 47 19 72 46 21 77 54 32 11 71 52 34 17 1 66 52 39 27 16 6 77 69 62 56 51 47 44 42 41"
},
{
"input": "85",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 7 21 36 52 69 2 21 41 62 84 22 46 71 12 39 67 11 41 72 19 52 1 36 72 24 62 16 56 12 54 12 56 16 62 24 72 36 1 52 19 72 41 11 67 39 12 71 46 22 84 62 41 21 2 69 52 36 21 7 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "90",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 2 16 31 47 64 82 11 31 52 74 7 31 56 82 19 47 76 16 47 79 22 56 1 37 74 22 61 11 52 4 47 1 46 2 49 7 56 16 67 29 82 46 11 67 34 2 61 31 2 64 37 11 76 52 29 7 76 56 37 19 2 76 61 47 34 22 11 1 82 74 67 61 56 52 49 47 46"
},
{
"input": "95",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 11 26 42 59 77 1 21 42 64 87 16 41 67 94 27 56 86 22 54 87 26 61 2 39 77 21 61 7 49 92 41 86 37 84 37 86 41 92 49 7 61 21 77 39 2 61 26 87 54 22 86 56 27 94 67 41 16 87 64 42 21 1 77 59 42 26 11 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "96",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 10 25 41 58 76 95 19 40 62 85 13 38 64 91 23 52 82 17 49 82 20 55 91 32 70 13 53 94 40 83 31 76 26 73 25 74 28 79 35 88 46 5 61 22 80 43 7 68 34 1 65 34 4 71 43 16 86 61 37 14 88 67 47 28 10 89 73 58 44 31 19 8 94 85 77 70 64 59 55 52 50 49"
},
{
"input": "97",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 9 24 40 57 75 94 17 38 60 83 10 35 61 88 19 48 78 12 44 77 14 49 85 25 63 5 45 86 31 74 21 66 15 62 13 62 15 66 21 74 31 86 45 5 63 25 85 49 14 77 44 12 78 48 19 88 61 35 10 83 60 38 17 94 75 57 40 24 9 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "98",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 8 23 39 56 74 93 15 36 58 81 7 32 58 85 15 44 74 7 39 72 8 43 79 18 56 95 37 78 22 65 11 56 4 51 1 50 2 53 7 60 16 71 29 86 46 7 67 30 92 57 23 88 56 25 93 64 36 9 81 56 32 9 85 64 44 25 7 88 72 57 43 30 18 7 95 86 78 71 65 60 56 53 51 50"
},
{
"input": "99",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 7 22 38 55 73 92 13 34 56 79 4 29 55 82 11 40 70 2 34 67 2 37 73 11 49 88 29 70 13 56 1 46 92 40 88 38 88 40 92 46 1 56 13 70 29 88 49 11 73 37 2 67 34 2 70 40 11 82 55 29 4 79 56 34 13 92 73 55 38 22 7 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "100",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 6 21 37 54 72 91 11 32 54 77 1 26 52 79 7 36 66 97 29 62 96 31 67 4 42 81 21 62 4 47 91 36 82 29 77 26 76 27 79 32 86 41 97 54 12 71 31 92 54 17 81 46 12 79 47 16 86 57 29 2 76 51 27 4 82 61 41 22 4 87 71 56 42 29 17 6 96 87 79 72 66 61 57 54 52 51"
}
] | 1,670,394,381 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 92 | 0 | aruncari = int(input(''))
def nr_ce_primesc_mingea(aruncari):
numar = 1
for i in range(1, aruncari):
numar = numar + i
if numar > aruncari:
numar = numar - aruncari
print(numar, end=' ')
nr_ce_primesc_mingea(aruncari) | Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends.
The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle.
Output Specification:
In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.
Demo Input:
['10\n', '3\n']
Demo Output:
['2 4 7 1 6 2 9 7 6\n', '2 1\n']
Note:
none | ```python
aruncari = int(input(''))
def nr_ce_primesc_mingea(aruncari):
numar = 1
for i in range(1, aruncari):
numar = numar + i
if numar > aruncari:
numar = numar - aruncari
print(numar, end=' ')
nr_ce_primesc_mingea(aruncari)
``` | 3.977 |
979 | A | Pizza, Pizza, Pizza!!! | PROGRAMMING | 1,000 | [
"math"
] | null | null | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.
She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.
Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.
As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem? | A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. | A single integer — the number of straight cuts Shiro needs. | [
"3\n",
"4\n"
] | [
"2",
"5"
] | To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | 500 | [
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "5"
},
{
"input": "10",
"output": "11"
},
{
"input": "10000000000",
"output": "10000000001"
},
{
"input": "1234567891",
"output": "617283946"
},
{
"input": "7509213957",
"output": "3754606979"
},
{
"input": "99999999999999999",
"output": "50000000000000000"
},
{
"input": "21",
"output": "11"
},
{
"input": "712394453192",
"output": "712394453193"
},
{
"input": "172212168",
"output": "172212169"
},
{
"input": "822981260158260519",
"output": "411490630079130260"
},
{
"input": "28316250877914571",
"output": "14158125438957286"
},
{
"input": "779547116602436424",
"output": "779547116602436425"
},
{
"input": "578223540024979436",
"output": "578223540024979437"
},
{
"input": "335408917861648766",
"output": "335408917861648767"
},
{
"input": "74859962623690078",
"output": "74859962623690079"
},
{
"input": "252509054433933439",
"output": "126254527216966720"
},
{
"input": "760713016476190622",
"output": "760713016476190623"
},
{
"input": "919845426262703496",
"output": "919845426262703497"
},
{
"input": "585335723211047194",
"output": "585335723211047195"
},
{
"input": "522842184971407769",
"output": "261421092485703885"
},
{
"input": "148049062628894320",
"output": "148049062628894321"
},
{
"input": "84324828731963974",
"output": "84324828731963975"
},
{
"input": "354979173822804781",
"output": "177489586911402391"
},
{
"input": "1312150450968413",
"output": "656075225484207"
},
{
"input": "269587449430302150",
"output": "269587449430302151"
},
{
"input": "645762258982631926",
"output": "645762258982631927"
},
{
"input": "615812229161735895",
"output": "307906114580867948"
},
{
"input": "0",
"output": "0"
},
{
"input": "349993004923078531",
"output": "174996502461539266"
},
{
"input": "891351282707723851",
"output": "445675641353861926"
},
{
"input": "563324731189330734",
"output": "563324731189330735"
},
{
"input": "520974001910286909",
"output": "260487000955143455"
},
{
"input": "666729339802329204",
"output": "666729339802329205"
},
{
"input": "856674611404539671",
"output": "428337305702269836"
},
{
"input": "791809296303238499",
"output": "395904648151619250"
},
{
"input": "711066337317063338",
"output": "711066337317063339"
},
{
"input": "931356503492686566",
"output": "931356503492686567"
},
{
"input": "234122432773361866",
"output": "234122432773361867"
},
{
"input": "1000000000000000000",
"output": "1000000000000000001"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "7",
"output": "4"
},
{
"input": "63",
"output": "32"
},
{
"input": "24",
"output": "25"
},
{
"input": "8",
"output": "9"
},
{
"input": "15",
"output": "8"
}
] | 1,665,434,219 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | if (__name__=="__main__"):
friends=1
input(int(friends))
friends=friends+1
if(friends%2==0):
print(friends/2)
else:
print(friends)
| Title: Pizza, Pizza, Pizza!!!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.
She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.
Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.
As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?
Input Specification:
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
Output Specification:
A single integer — the number of straight cuts Shiro needs.
Demo Input:
['3\n', '4\n']
Demo Output:
['2', '5']
Note:
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | ```python
if (__name__=="__main__"):
friends=1
input(int(friends))
friends=friends+1
if(friends%2==0):
print(friends/2)
else:
print(friends)
``` | 0 |
|
1 | C | Ancient Berland Circus | PROGRAMMING | 2,100 | [
"geometry",
"math"
] | C. Ancient Berland Circus | 2 | 64 | Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.
In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a special pillar, and the rope strung between the pillars marked the arena edges.
Recently the scientists from Berland have discovered the remains of the ancient circus arena. They found only three pillars, the others were destroyed by the time.
You are given the coordinates of these three pillars. Find out what is the smallest area that the arena could have. | The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point. | Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100. | [
"0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000\n"
] | [
"1.00000000\n"
] | 0 | [
{
"input": "0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000",
"output": "1.00000000"
},
{
"input": "71.756151 7.532275\n-48.634784 100.159986\n91.778633 158.107739",
"output": "9991.27897663"
},
{
"input": "18.716839 40.852752\n66.147248 -4.083161\n111.083161 43.347248",
"output": "4268.87997505"
},
{
"input": "-13.242302 -45.014124\n-33.825369 51.083964\n84.512928 -55.134407",
"output": "16617.24002771"
},
{
"input": "115.715093 141.583620\n136.158119 -23.780834\n173.673212 64.802787",
"output": "24043.74046813"
},
{
"input": "17.288379 68.223317\n48.776683 71.688379\n23.170559 106.572762",
"output": "1505.27997374"
},
{
"input": "76.820252 66.709341\n61.392328 82.684207\n44.267775 -2.378694",
"output": "6503.44762335"
},
{
"input": "-46.482632 -31.161247\n19.689679 -70.646972\n-17.902656 -58.455808",
"output": "23949.55226823"
},
{
"input": "34.236058 108.163949\n28.639345 104.566515\n25.610069 86.002927",
"output": "780.93431702"
},
{
"input": "25.428124 39.407248\n17.868098 39.785933\n11.028461 43.028890",
"output": "1152.21351717"
},
{
"input": "36.856072 121.845502\n46.453956 109.898647\n-30.047767 77.590282",
"output": "5339.35578947"
},
{
"input": "-18.643272 56.008305\n9.107608 -22.094058\n-6.456146 70.308320",
"output": "9009.25177521"
},
{
"input": "88.653021 18.024220\n51.942488 -2.527850\n76.164701 24.553012",
"output": "1452.52866331"
},
{
"input": "80.181999 -38.076894\n23.381778 122.535736\n47.118815 140.734014",
"output": "28242.17663744"
},
{
"input": "1.514204 81.400629\n32.168797 100.161401\n7.778734 46.010993",
"output": "3149.43107333"
},
{
"input": "84.409605 38.496141\n77.788313 39.553807\n75.248391 59.413884",
"output": "438.85760782"
},
{
"input": "12.272903 101.825792\n-51.240438 -12.708472\n-29.729299 77.882032",
"output": "24908.67540438"
},
{
"input": "35.661751 27.283571\n96.513550 51.518022\n97.605986 131.258287",
"output": "13324.78113326"
},
{
"input": "-20.003518 -4.671086\n93.588632 6.362759\n-24.748109 24.792124",
"output": "11191.04493104"
},
{
"input": "93.583067 132.858352\n63.834975 19.353720\n33.677824 102.529376",
"output": "10866.49390021"
},
{
"input": "-7.347450 36.971423\n84.498728 89.423536\n75.469963 98.022482",
"output": "8977.83404724"
},
{
"input": "51.679280 56.072393\n-35.819256 73.390532\n-10.661374 129.756454",
"output": "7441.86549199"
},
{
"input": "97.326813 61.492460\n100.982131 57.717635\n68.385216 22.538372",
"output": "1840.59945324"
},
{
"input": "-16.356805 109.310423\n124.529388 25.066276\n-37.892043 80.604904",
"output": "22719.36404168"
},
{
"input": "103.967164 63.475916\n86.466163 59.341930\n69.260229 73.258917",
"output": "1621.96700296"
},
{
"input": "122.381894 -48.763263\n163.634346 -22.427845\n26.099674 73.681862",
"output": "22182.51901824"
},
{
"input": "119.209229 133.905087\n132.001535 22.179509\n96.096673 0.539763",
"output": "16459.52899209"
},
{
"input": "77.145533 85.041789\n67.452820 52.513188\n80.503843 85.000149",
"output": "1034.70898496"
},
{
"input": "28.718442 36.116251\n36.734593 35.617015\n76.193973 99.136077",
"output": "6271.48941610"
},
{
"input": "0.376916 17.054676\n100.187614 85.602831\n1.425829 132.750915",
"output": "13947.47744984"
},
{
"input": "46.172435 -22.819705\n17.485134 -1.663888\n101.027565 111.619705",
"output": "16483.23337238"
},
{
"input": "55.957968 -72.765994\n39.787413 -75.942282\n24.837014 128.144762",
"output": "32799.66697178"
},
{
"input": "40.562163 -47.610606\n10.073051 -54.490068\n54.625875 -40.685797",
"output": "31224.34817875"
},
{
"input": "20.965151 74.716562\n167.264364 81.864800\n5.931644 48.813212",
"output": "30115.26346791"
},
{
"input": "105.530943 80.920069\n40.206723 125.323331\n40.502256 -85.455877",
"output": "36574.64621711"
},
{
"input": "104.636703 49.583778\n85.940583 95.426299\n69.375168 93.234795",
"output": "2632.68754075"
},
{
"input": "72.873708 -59.083734\n110.911118 -6.206576\n-44.292395 13.106202",
"output": "19244.42781859"
},
{
"input": "49.320630 48.119616\n65.888396 93.514980\n27.342377 97.600590",
"output": "2437.50897386"
},
{
"input": "6.949504 69.606390\n26.139268 72.136945\n24.032442 57.407195",
"output": "372.09309018"
},
{
"input": "-21.925928 -24.623076\n-33.673619 -11.677794\n4.692348 52.266292",
"output": "5669.99444283"
},
{
"input": "109.515505 37.575315\n5.377080 101.729711\n17.501630 103.324931",
"output": "25142.85604936"
},
{
"input": "-56.880888 172.997993\n81.126977 42.144034\n-51.413417 17.057807",
"output": "29051.57171313"
},
{
"input": "80.895061 94.491414\n42.361631 65.191687\n77.556800 76.694829",
"output": "2386.01792476"
},
{
"input": "165.094169 94.574129\n46.867578 147.178855\n174.685774 62.705213",
"output": "32087.47120554"
},
{
"input": "146.604506 -3.502359\n24.935572 44.589981\n106.160918 -51.162271",
"output": "13799.61044048"
},
{
"input": "139.847022 19.153937\n104.096879 75.379874\n49.164271 46.404632",
"output": "7083.26303902"
},
{
"input": "31.312532 151.532355\n182.646053 56.534075\n15.953947 127.065925",
"output": "25712.80766033"
},
{
"input": "42.147045 64.165917\n70.260284 4.962470\n10.532991 76.277713",
"output": "14261.92257159"
},
{
"input": "129.400249 -44.695226\n122.278798 -53.696996\n44.828427 -83.507917",
"output": "26227.47891833"
},
{
"input": "28.420253 0.619862\n10.966628 21.724132\n14.618862 10.754642",
"output": "1760.14006648"
}
] | 1,659,707,511 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 12 | 122 | 0 | import math
def dot(a, b):
return a[0]*b[0] + a[1]*b[1]
def rad2deg(x):
return 180 * x / math.pi
def deg2rad(x):
return math.pi* x / 180
def center_from_three_points(a, b, c):
a11 = 2*(a[0] - b[0])
a12 = 2*(a[1] - b[1])
a21 = 2*(a[0] - c[0])
a22 = 2*(a[1] - c[1])
b1 = a[0]*a[0] - b[0]*b[0] + a[1]*a[1] - b[1]*b[1]
b2 = a[0]*a[0] - c[0]*c[0] + a[1]*a[1] - c[1]*c[1]
det = a11 * a22 - a12 * a21
x = (b1 * a22 - b2 * a12) / det
y = (a11 * b2 - a21 * b1) / det
return (x, y)
def angle(a, c, b):
v1 = (a[0] - c[0], a[1] - c[1])
v2 = (b[0] - c[0], b[1] - c[1])
cos_alpha = dot(v1, v2) / math.sqrt(dot(v1, v1)* dot(v2, v2))
cos_alpha = min(max(-1, cos_alpha), 1)
return math.acos(cos_alpha)
def gcd(a, b):
if a < b:
return gcd(b, a)
if (abs(b) < 0.000001):
return a
return gcd(b, a - math.floor(a / b )*b)
a = tuple(map(float, input().split()))
b = tuple(map(float, input().split()))
c = tuple(map(float, input().split()))
center = center_from_three_points(a, b, c)
radius = math.sqrt((a[0] - center[0])**2 + (a[1] - center[1])**2)
angle1 = angle(a, center, b)
angle2 = angle(a, center, c)
step = gcd(angle1, angle2)
chord = 2*radius*math.sin(step/2)
apothem = math.sqrt(radius**2 - (chord/2)**2)
nsides = int(round(2*math.pi / step))
perimeter = nsides*chord
print(f"{0.5*perimeter*apothem:0.6f}")
| Title: Ancient Berland Circus
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.
In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a special pillar, and the rope strung between the pillars marked the arena edges.
Recently the scientists from Berland have discovered the remains of the ancient circus arena. They found only three pillars, the others were destroyed by the time.
You are given the coordinates of these three pillars. Find out what is the smallest area that the arena could have.
Input Specification:
The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point.
Output Specification:
Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100.
Demo Input:
['0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000\n']
Demo Output:
['1.00000000\n']
| ```python
import math
def dot(a, b):
return a[0]*b[0] + a[1]*b[1]
def rad2deg(x):
return 180 * x / math.pi
def deg2rad(x):
return math.pi* x / 180
def center_from_three_points(a, b, c):
a11 = 2*(a[0] - b[0])
a12 = 2*(a[1] - b[1])
a21 = 2*(a[0] - c[0])
a22 = 2*(a[1] - c[1])
b1 = a[0]*a[0] - b[0]*b[0] + a[1]*a[1] - b[1]*b[1]
b2 = a[0]*a[0] - c[0]*c[0] + a[1]*a[1] - c[1]*c[1]
det = a11 * a22 - a12 * a21
x = (b1 * a22 - b2 * a12) / det
y = (a11 * b2 - a21 * b1) / det
return (x, y)
def angle(a, c, b):
v1 = (a[0] - c[0], a[1] - c[1])
v2 = (b[0] - c[0], b[1] - c[1])
cos_alpha = dot(v1, v2) / math.sqrt(dot(v1, v1)* dot(v2, v2))
cos_alpha = min(max(-1, cos_alpha), 1)
return math.acos(cos_alpha)
def gcd(a, b):
if a < b:
return gcd(b, a)
if (abs(b) < 0.000001):
return a
return gcd(b, a - math.floor(a / b )*b)
a = tuple(map(float, input().split()))
b = tuple(map(float, input().split()))
c = tuple(map(float, input().split()))
center = center_from_three_points(a, b, c)
radius = math.sqrt((a[0] - center[0])**2 + (a[1] - center[1])**2)
angle1 = angle(a, center, b)
angle2 = angle(a, center, c)
step = gcd(angle1, angle2)
chord = 2*radius*math.sin(step/2)
apothem = math.sqrt(radius**2 - (chord/2)**2)
nsides = int(round(2*math.pi / step))
perimeter = nsides*chord
print(f"{0.5*perimeter*apothem:0.6f}")
``` | 0 |
|
498 | A | Crazy Town | PROGRAMMING | 1,700 | [
"geometry"
] | null | null | Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road. | The first line contains two space-separated integers *x*1, *y*1 (<=-<=106<=≤<=*x*1,<=*y*1<=≤<=106) — the coordinates of your home.
The second line contains two integers separated by a space *x*2, *y*2 (<=-<=106<=≤<=*x*2,<=*y*2<=≤<=106) — the coordinates of the university you are studying at.
The third line contains an integer *n* (1<=≤<=*n*<=≤<=300) — the number of roads in the city. The following *n* lines contain 3 space-separated integers (<=-<=106<=≤<=*a**i*,<=*b**i*,<=*c**i*<=≤<=106; |*a**i*|<=+<=|*b**i*|<=><=0) — the coefficients of the line *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, defining the *i*-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines). | Output the answer to the problem. | [
"1 1\n-1 -1\n2\n0 1 0\n1 0 0\n",
"1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3\n"
] | [
"2\n",
"2\n"
] | Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors): | 500 | [
{
"input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0",
"output": "2"
},
{
"input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3",
"output": "2"
},
{
"input": "841746 527518\n595261 331297\n10\n-946901 129987 670374\n-140388 -684770 309555\n-302589 415564 -387435\n-565799 -72069 -395358\n-523453 -511446 854898\n-846967 -749453 -341866\n-622388 434663 264157\n-638453 625357 344195\n-255265 -676356 -772398\n-824723 -319141 33585",
"output": "0"
},
{
"input": "454379 373644\n-665078 -385892\n2\n-530 -468 -379786\n-173 -275 -100376",
"output": "2"
},
{
"input": "841746 527518\n595261 331297\n10\n936 -209 -790797\n898 1240 -36994\n759 285 -413562\n174 323 34281\n662 400 -284846\n298 520 42086\n-36 -27 12861\n462 631 -22515\n-499 1105 919372\n582 1490 319884",
"output": "0"
},
{
"input": "-537 648838\n227 -51454\n1\n678 0 235266",
"output": "1"
},
{
"input": "-940 -984641\n403 -942522\n2\n530 0 -63600\n-439 0 95263",
"output": "2"
},
{
"input": "-867 -465880\n793 -581568\n5\n73 0 57743\n-818 0 -635586\n-804 0 -415668\n-383 0 -52854\n1258 0 155992",
"output": "5"
},
{
"input": "-632 -387435\n942 798117\n10\n249 0 135705\n536 0 271752\n750 0 375750\n799 0 -206142\n1102 0 -437494\n-453 0 197055\n-581 0 260288\n-322 0 161322\n1317 0 -878439\n-811 0 594463",
"output": "10"
},
{
"input": "527189 -306471\n-998939 648838\n1\n-950717 -549267 -820616",
"output": "1"
},
{
"input": "454379 373644\n-665078 -385892\n2\n-984641 503905 -909460\n-767954 -468772 -942522",
"output": "2"
},
{
"input": "-589794 344286\n532652 -230711\n5\n-2919 -179425 -546698\n-465880 342737 794428\n-230739 -687865 713836\n-932054 513357 -97639\n-559361 -75096 -581568",
"output": "5"
},
{
"input": "0 1\n2 2\n1\n1 1 2",
"output": "0"
},
{
"input": "0 2\n-2 0\n2\n2 3 -1\n4 0 3",
"output": "2"
},
{
"input": "1 -4\n1 5\n1\n0 1 0",
"output": "1"
},
{
"input": "1 0\n2 0\n1\n1 0 0",
"output": "0"
},
{
"input": "0 0\n0 2\n4\n1 0 1\n1 0 -1\n-2 0 1\n0 1 -1",
"output": "1"
},
{
"input": "100000 100000\n-100000 100000\n1\n10000 0 7",
"output": "1"
},
{
"input": "1 1\n-1 -1\n1\n1 1 0",
"output": "1"
},
{
"input": "1 1\n3 3\n1\n1 0 2",
"output": "0"
},
{
"input": "1 3\n1 1\n1\n1 1 3",
"output": "0"
},
{
"input": "5 0\n15 0\n1\n10 0 -100",
"output": "1"
},
{
"input": "3 4\n2 6\n1\n0 -2 5",
"output": "0"
},
{
"input": "1 0\n1 2\n1\n0 1 -1",
"output": "1"
},
{
"input": "0 0\n0 2\n1\n0 1 -1",
"output": "1"
},
{
"input": "0 0\n0 1\n1\n1 0 10000",
"output": "0"
},
{
"input": "0 0\n0 1\n1\n0 2 2",
"output": "0"
},
{
"input": "10 18\n10 0\n2\n1 -1 0\n0 1 -5",
"output": "2"
},
{
"input": "10 10\n8 8\n1\n1 1 19",
"output": "0"
},
{
"input": "0 1\n1000000 1\n1\n1000000 1 0",
"output": "0"
}
] | 1,556,901,076 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 109 | 0 | x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
a1=y1-y2
b1=x2-x1
c1=x2*(y2-y1)-y2*(x2-x1)
def intersect(a2,b2,c2):
global a1,b1,c1,x1,y1,x2,y2
if(a1*b2==a2*b1):
return False
x=(b1*c2-b2*c1)/(a1*b2-b1*a2)
y=(a1*c2-c1*a2)/(b1*a2-a1*b2)
if(min(x1,x2)<=x<=max(x1,x2) and min(y1,y2)<=y<=max(y1,y2)):
return True
return False
m=int(input())
ans=0
for i in range(m):
a2,b2,c2=map(int,input().split())
if(intersect(a2,b2,c2)):
ans+=1
print(ans) | Title: Crazy Town
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input Specification:
The first line contains two space-separated integers *x*1, *y*1 (<=-<=106<=≤<=*x*1,<=*y*1<=≤<=106) — the coordinates of your home.
The second line contains two integers separated by a space *x*2, *y*2 (<=-<=106<=≤<=*x*2,<=*y*2<=≤<=106) — the coordinates of the university you are studying at.
The third line contains an integer *n* (1<=≤<=*n*<=≤<=300) — the number of roads in the city. The following *n* lines contain 3 space-separated integers (<=-<=106<=≤<=*a**i*,<=*b**i*,<=*c**i*<=≤<=106; |*a**i*|<=+<=|*b**i*|<=><=0) — the coefficients of the line *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, defining the *i*-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output Specification:
Output the answer to the problem.
Demo Input:
['1 1\n-1 -1\n2\n0 1 0\n1 0 0\n', '1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3\n']
Demo Output:
['2\n', '2\n']
Note:
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors): | ```python
x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
a1=y1-y2
b1=x2-x1
c1=x2*(y2-y1)-y2*(x2-x1)
def intersect(a2,b2,c2):
global a1,b1,c1,x1,y1,x2,y2
if(a1*b2==a2*b1):
return False
x=(b1*c2-b2*c1)/(a1*b2-b1*a2)
y=(a1*c2-c1*a2)/(b1*a2-a1*b2)
if(min(x1,x2)<=x<=max(x1,x2) and min(y1,y2)<=y<=max(y1,y2)):
return True
return False
m=int(input())
ans=0
for i in range(m):
a2,b2,c2=map(int,input().split())
if(intersect(a2,b2,c2)):
ans+=1
print(ans)
``` | 3 |
|
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1. | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
},
{
"input": "999",
"output": "9"
},
{
"input": "100",
"output": "5"
},
{
"input": "123",
"output": "6"
},
{
"input": "8",
"output": "8"
},
{
"input": "157",
"output": "3"
},
{
"input": "289",
"output": "1"
},
{
"input": "179",
"output": "4"
},
{
"input": "942",
"output": "0"
},
{
"input": "879",
"output": "9"
},
{
"input": "394",
"output": "1"
},
{
"input": "423",
"output": "7"
},
{
"input": "952",
"output": "3"
},
{
"input": "121",
"output": "5"
},
{
"input": "613",
"output": "2"
},
{
"input": "945",
"output": "1"
},
{
"input": "270",
"output": "6"
},
{
"input": "781",
"output": "2"
},
{
"input": "453",
"output": "7"
},
{
"input": "171",
"output": "0"
},
{
"input": "643",
"output": "2"
},
{
"input": "570",
"output": "6"
},
{
"input": "750",
"output": "6"
},
{
"input": "500",
"output": "0"
},
{
"input": "2",
"output": "2"
},
{
"input": "1",
"output": "1"
},
{
"input": "108",
"output": "5"
},
{
"input": "500",
"output": "0"
},
{
"input": "189",
"output": "9"
},
{
"input": "491",
"output": "0"
},
{
"input": "191",
"output": "0"
}
] | 1,590,842,682 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 140 | 0 | s=""
for i in range(1,1000):
f=str(i)
s=s+f
n=int(input())
print(s[n-1])
| Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1.
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print.
Output Specification:
Print the *n*-th digit of the line.
Demo Input:
['3\n', '11\n']
Demo Output:
['3\n', '0\n']
Note:
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | ```python
s=""
for i in range(1,1000):
f=str(i)
s=s+f
n=int(input())
print(s[n-1])
``` | 3 |
|
417 | A | Elimination | PROGRAMMING | 1,500 | [
"dp",
"implementation",
"math"
] | null | null | The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.
The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of *c* problems, the winners of the round are the first *n* people in the rating list. Each of the additional elimination rounds consists of *d* problems. The winner of the additional round is one person. Besides, *k* winners of the past finals are invited to the finals without elimination.
As a result of all elimination rounds at least *n*·*m* people should go to the finals. You need to organize elimination rounds in such a way, that at least *n*·*m* people go to the finals, and the total amount of used problems in all rounds is as small as possible. | The first line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100) — the number of problems in the main and additional rounds, correspondingly. The second line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Finally, the third line contains an integer *k* (1<=≤<=*k*<=≤<=100) — the number of the pre-chosen winners. | In the first line, print a single integer — the minimum number of problems the jury needs to prepare. | [
"1 10\n7 2\n1\n",
"2 2\n2 1\n2\n"
] | [
"2\n",
"0\n"
] | none | 500 | [
{
"input": "1 10\n7 2\n1",
"output": "2"
},
{
"input": "2 2\n2 1\n2",
"output": "0"
},
{
"input": "8 9\n2 2\n3",
"output": "8"
},
{
"input": "5 5\n8 8\n7",
"output": "40"
},
{
"input": "1 8\n8 10\n8",
"output": "9"
},
{
"input": "5 7\n9 1\n8",
"output": "5"
},
{
"input": "35 28\n35 60\n44",
"output": "2065"
},
{
"input": "19 76\n91 91\n87",
"output": "1729"
},
{
"input": "20 38\n38 70\n58",
"output": "1380"
},
{
"input": "2 81\n3 39\n45",
"output": "48"
},
{
"input": "7 63\n18 69\n30",
"output": "476"
},
{
"input": "89 69\n57 38\n15",
"output": "3382"
},
{
"input": "3 30\n10 83\n57",
"output": "234"
},
{
"input": "100 3\n93 23\n98",
"output": "2200"
},
{
"input": "2 78\n21 24\n88",
"output": "40"
},
{
"input": "40 80\n4 31\n63",
"output": "640"
},
{
"input": "1 48\n89 76\n24",
"output": "76"
},
{
"input": "5 25\n13 76\n86",
"output": "350"
},
{
"input": "23 86\n83 88\n62",
"output": "2024"
},
{
"input": "1 93\n76 40\n39",
"output": "40"
},
{
"input": "53 93\n10 70\n9",
"output": "3710"
},
{
"input": "100 100\n100 100\n100",
"output": "9900"
},
{
"input": "10 100\n100 100\n99",
"output": "1000"
},
{
"input": "1 100\n99 100\n1",
"output": "100"
},
{
"input": "10 2\n7 2\n3",
"output": "18"
},
{
"input": "4 1\n5 3\n8",
"output": "6"
},
{
"input": "2 2\n2 1\n20",
"output": "0"
},
{
"input": "7 5\n1 1\n10",
"output": "0"
},
{
"input": "4 5\n9 10\n100",
"output": "0"
},
{
"input": "10 1\n1 2\n1",
"output": "1"
},
{
"input": "16 6\n3 12\n7",
"output": "156"
},
{
"input": "10 1\n1 100\n1",
"output": "99"
},
{
"input": "2 1\n3 4\n2",
"output": "7"
},
{
"input": "2 1\n1 1\n10",
"output": "0"
},
{
"input": "100 1\n2 3\n1",
"output": "5"
},
{
"input": "10 2\n1 11\n1",
"output": "20"
},
{
"input": "10 10\n1 1\n100",
"output": "0"
},
{
"input": "100 1\n50 100\n1",
"output": "4999"
},
{
"input": "10 1\n2 2\n3",
"output": "1"
},
{
"input": "3 1\n9 10\n80",
"output": "4"
},
{
"input": "100 1\n1 100\n1",
"output": "99"
},
{
"input": "10 9\n10 10\n9",
"output": "99"
},
{
"input": "1 1\n1 1\n99",
"output": "0"
},
{
"input": "10 9\n1 1\n100",
"output": "0"
},
{
"input": "4 1\n5 1\n10",
"output": "0"
},
{
"input": "5 1\n6 3\n5",
"output": "11"
},
{
"input": "10 1\n1 1\n10",
"output": "0"
},
{
"input": "1 1\n1 1\n10",
"output": "0"
}
] | 1,600,197,308 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 34 | 109 | 0 | I=lambda:map(int,input().split());c,d=I();n,m=I();k=int(input());l=n*m-k;z=min(l//n*c,l*d)+min(c,l%n*d)
print(z if z>0 else 0) | Title: Elimination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.
The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of *c* problems, the winners of the round are the first *n* people in the rating list. Each of the additional elimination rounds consists of *d* problems. The winner of the additional round is one person. Besides, *k* winners of the past finals are invited to the finals without elimination.
As a result of all elimination rounds at least *n*·*m* people should go to the finals. You need to organize elimination rounds in such a way, that at least *n*·*m* people go to the finals, and the total amount of used problems in all rounds is as small as possible.
Input Specification:
The first line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100) — the number of problems in the main and additional rounds, correspondingly. The second line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Finally, the third line contains an integer *k* (1<=≤<=*k*<=≤<=100) — the number of the pre-chosen winners.
Output Specification:
In the first line, print a single integer — the minimum number of problems the jury needs to prepare.
Demo Input:
['1 10\n7 2\n1\n', '2 2\n2 1\n2\n']
Demo Output:
['2\n', '0\n']
Note:
none | ```python
I=lambda:map(int,input().split());c,d=I();n,m=I();k=int(input());l=n*m-k;z=min(l//n*c,l*d)+min(c,l%n*d)
print(z if z>0 else 0)
``` | 0 |
|
137 | C | History | PROGRAMMING | 1,500 | [
"sortings"
] | null | null | Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=<<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=<<=*a**i* and *b**i*<=<<=*b**j*. Your task is simpler: find the number of events that are included in some other event. | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=≠<=*a**j*,<=*a**i*<=≠<=*b**j*,<=*b**i*<=≠<=*a**j*,<=*b**i*<=≠<=*b**j* for all *i*, *j* (where *i*<=≠<=*j*). Events are given in arbitrary order. | Print the only integer — the answer to the problem. | [
"5\n1 10\n2 9\n3 8\n4 7\n5 6\n",
"5\n1 100\n2 50\n51 99\n52 98\n10 60\n",
"1\n1 1000000000\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | 1,500 | [
{
"input": "5\n1 10\n2 9\n3 8\n4 7\n5 6",
"output": "4"
},
{
"input": "5\n1 100\n2 50\n51 99\n52 98\n10 60",
"output": "4"
},
{
"input": "1\n1 1000000000",
"output": "0"
},
{
"input": "2\n100 1000\n500 1500",
"output": "0"
},
{
"input": "4\n1 100\n50 150\n120 200\n180 220",
"output": "0"
},
{
"input": "10\n1 20\n2 19\n3 18\n4 17\n5 16\n6 15\n7 14\n8 13\n9 12\n10 11",
"output": "9"
},
{
"input": "4\n1 5\n2 4\n10 15\n11 14",
"output": "2"
},
{
"input": "10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20",
"output": "0"
},
{
"input": "10\n58 22116\n112840 772160\n127432 399484\n182031 255417\n459340 548097\n603984 739189\n606173 663033\n280170 366159\n779239 906234\n874623 892907",
"output": "7"
},
{
"input": "2\n2 3\n1 4",
"output": "1"
},
{
"input": "3\n9 10\n1 2\n3 4",
"output": "0"
},
{
"input": "4\n1 2\n3 6\n4 5\n10 11",
"output": "1"
},
{
"input": "2\n5 6\n1 10",
"output": "1"
},
{
"input": "7\n1 10\n2 5\n3 9\n100 1000\n200 500\n1001 1002\n777 7777",
"output": "4"
}
] | 1,581,794,741 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 307,200 | n = int(input())
arr = []
s_arr = []
e_arr = []
for i in range(n):
a, b = input().split(" ")
s_arr.append((a, i))
e_arr.append((b, i))
if len(s_arr) <= 1:
print(0)
else:
s_s_arr = sorted(s_arr, key= lambda x: x[0])
s_e_arr = sorted(e_arr, key= lambda x: x[0], reverse=True)
r_c_m = dict()
prev = s_s_arr[0]
r_c_m[s_s_arr[0][1]] = [0, 0]
for i in range(1, len(s_s_arr)):
if s_s_arr[i][0] > prev[0]:
r_c_m[s_s_arr[i][1]] = [1, 0]
prev = s_e_arr[0]
r_c_m[s_e_arr[0][1]][1] = 0
for i in range(1, len(s_e_arr)):
if s_e_arr[i][0] < prev[0]:
r_c_m[s_e_arr[i][1]][1] = 1
r_c = 0
for item in r_c_m:
if r_c_m[item][0] == 1 and r_c_m[item][1] == 1:
r_c = r_c + 1
print(r_c)
| Title: History
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=<<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=<<=*a**i* and *b**i*<=<<=*b**j*. Your task is simpler: find the number of events that are included in some other event.
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=≠<=*a**j*,<=*a**i*<=≠<=*b**j*,<=*b**i*<=≠<=*a**j*,<=*b**i*<=≠<=*b**j* for all *i*, *j* (where *i*<=≠<=*j*). Events are given in arbitrary order.
Output Specification:
Print the only integer — the answer to the problem.
Demo Input:
['5\n1 10\n2 9\n3 8\n4 7\n5 6\n', '5\n1 100\n2 50\n51 99\n52 98\n10 60\n', '1\n1 1000000000\n']
Demo Output:
['4\n', '4\n', '0\n']
Note:
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | ```python
n = int(input())
arr = []
s_arr = []
e_arr = []
for i in range(n):
a, b = input().split(" ")
s_arr.append((a, i))
e_arr.append((b, i))
if len(s_arr) <= 1:
print(0)
else:
s_s_arr = sorted(s_arr, key= lambda x: x[0])
s_e_arr = sorted(e_arr, key= lambda x: x[0], reverse=True)
r_c_m = dict()
prev = s_s_arr[0]
r_c_m[s_s_arr[0][1]] = [0, 0]
for i in range(1, len(s_s_arr)):
if s_s_arr[i][0] > prev[0]:
r_c_m[s_s_arr[i][1]] = [1, 0]
prev = s_e_arr[0]
r_c_m[s_e_arr[0][1]][1] = 0
for i in range(1, len(s_e_arr)):
if s_e_arr[i][0] < prev[0]:
r_c_m[s_e_arr[i][1]][1] = 1
r_c = 0
for item in r_c_m:
if r_c_m[item][0] == 1 and r_c_m[item][1] == 1:
r_c = r_c + 1
print(r_c)
``` | 0 |
|
369 | A | Valera and Plates | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally. | The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Valera will eat a first type dish. If *a**i* equals two, then on day *i* Valera will eat a second type dish. | Print a single integer — the minimum number of times Valera will need to wash a plate/bowl. | [
"3 1 1\n1 2 1\n",
"4 3 1\n1 1 1 1\n",
"3 1 2\n2 2 2\n",
"8 2 2\n1 2 1 2 1 2 1 2\n"
] | [
"1\n",
"1\n",
"0\n",
"4\n"
] | In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | 500 | [
{
"input": "3 1 1\n1 2 1",
"output": "1"
},
{
"input": "4 3 1\n1 1 1 1",
"output": "1"
},
{
"input": "3 1 2\n2 2 2",
"output": "0"
},
{
"input": "8 2 2\n1 2 1 2 1 2 1 2",
"output": "4"
},
{
"input": "2 100 100\n2 2",
"output": "0"
},
{
"input": "1 1 1\n2",
"output": "0"
},
{
"input": "233 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 1 2 1 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2",
"output": "132"
},
{
"input": "123 100 1\n2 2 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 2 1 2 2 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 1 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 1 1 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 1 2 1 2 1 2 1 1 1",
"output": "22"
},
{
"input": "188 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1",
"output": "87"
},
{
"input": "3 1 2\n1 1 1",
"output": "2"
},
{
"input": "3 2 2\n1 1 1",
"output": "1"
},
{
"input": "3 2 1\n1 1 1",
"output": "1"
},
{
"input": "3 1 1\n1 1 1",
"output": "2"
},
{
"input": "5 1 2\n2 2 2 2 2",
"output": "2"
},
{
"input": "5 2 2\n2 2 2 2 2",
"output": "1"
},
{
"input": "5 2 1\n2 2 2 2 2",
"output": "2"
},
{
"input": "5 1 1\n2 2 2 2 2",
"output": "3"
},
{
"input": "1 1 2\n2",
"output": "0"
},
{
"input": "1 2 2\n2",
"output": "0"
},
{
"input": "1 2 1\n2",
"output": "0"
},
{
"input": "1 1 1\n2",
"output": "0"
},
{
"input": "6 3 1\n1 1 2 2 2 2",
"output": "2"
},
{
"input": "100 40 20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "40"
},
{
"input": "7 5 2\n2 2 1 1 1 1 1",
"output": "0"
},
{
"input": "10 4 4\n2 2 2 2 2 2 1 1 1 1",
"output": "2"
},
{
"input": "3 2 1\n2 1 1",
"output": "0"
},
{
"input": "7 6 1\n2 1 1 1 1 1 1",
"output": "0"
},
{
"input": "7 5 1\n1 1 1 2 2 2 2",
"output": "1"
},
{
"input": "5 3 1\n1 1 2 2 2",
"output": "1"
},
{
"input": "3 1 1\n2 2 2",
"output": "1"
},
{
"input": "5 2 2\n2 2 2 2 2",
"output": "1"
},
{
"input": "3 1 3\n1 1 1",
"output": "2"
},
{
"input": "5 2 1\n1 1 2 2 2",
"output": "2"
},
{
"input": "4 3 2\n2 1 1 1",
"output": "0"
},
{
"input": "4 2 1\n1 2 2 2",
"output": "1"
},
{
"input": "14 4 7\n1 1 1 2 2 2 2 2 2 2 2 2 2 2",
"output": "3"
},
{
"input": "12 10 4\n2 2 2 2 2 2 1 1 1 1 1 1",
"output": "0"
},
{
"input": "5 3 2\n2 2 1 1 1",
"output": "0"
}
] | 1,620,705,832 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 108 | 20,172,800 | n, m, k = map(int, input().split())
daf = list(map(int, input().split()))
c = 0
total = 0
while (m>0 or k>0) and c < n:
f = daf[c]
if f == 1:
if m > 0:
m -= 1
else:
total += 1
else:
if k > 0:
k -= 1
elif m > 0:
m -= 1
else:
total += 1
c += 1
print(total + n - c)
| Title: Valera and Plates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input Specification:
The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Valera will eat a first type dish. If *a**i* equals two, then on day *i* Valera will eat a second type dish.
Output Specification:
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Demo Input:
['3 1 1\n1 2 1\n', '4 3 1\n1 1 1 1\n', '3 1 2\n2 2 2\n', '8 2 2\n1 2 1 2 1 2 1 2\n']
Demo Output:
['1\n', '1\n', '0\n', '4\n']
Note:
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | ```python
n, m, k = map(int, input().split())
daf = list(map(int, input().split()))
c = 0
total = 0
while (m>0 or k>0) and c < n:
f = daf[c]
if f == 1:
if m > 0:
m -= 1
else:
total += 1
else:
if k > 0:
k -= 1
elif m > 0:
m -= 1
else:
total += 1
c += 1
print(total + n - c)
``` | 3 |
|
912 | A | Tricky Alchemy | PROGRAMMING | 800 | [
"implementation"
] | null | null | During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.
Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls. | The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained. | Print a single integer — the minimum number of crystals that Grisha should acquire in addition. | [
"4 3\n2 1 1\n",
"3 9\n1 1 3\n",
"12345678 87654321\n43043751 1000000000 53798715\n"
] | [
"2\n",
"1\n",
"2147483648\n"
] | In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue. | 500 | [
{
"input": "4 3\n2 1 1",
"output": "2"
},
{
"input": "3 9\n1 1 3",
"output": "1"
},
{
"input": "12345678 87654321\n43043751 1000000000 53798715",
"output": "2147483648"
},
{
"input": "12 12\n3 5 2",
"output": "0"
},
{
"input": "770 1390\n170 442 311",
"output": "12"
},
{
"input": "3555165 6693472\n1499112 556941 3075290",
"output": "3089339"
},
{
"input": "0 0\n1000000000 1000000000 1000000000",
"output": "7000000000"
},
{
"input": "1 1\n0 1 0",
"output": "0"
},
{
"input": "117708228 562858833\n118004008 360437130 154015822",
"output": "738362681"
},
{
"input": "999998118 700178721\n822106746 82987112 547955384",
"output": "1753877029"
},
{
"input": "566568710 765371101\n60614022 80126928 809950465",
"output": "1744607222"
},
{
"input": "448858599 829062060\n764716760 97644201 203890025",
"output": "1178219122"
},
{
"input": "626115781 966381948\n395190569 820194184 229233367",
"output": "1525971878"
},
{
"input": "803372962 103701834\n394260597 837711458 623172928",
"output": "3426388098"
},
{
"input": "980630143 241021722\n24734406 928857659 312079781",
"output": "1624075280"
},
{
"input": "862920032 378341609\n360240924 241342224 337423122",
"output": "974174021"
},
{
"input": "40177212 515661496\n64343660 963892207 731362684",
"output": "3694721078"
},
{
"input": "217434393 579352456\n694817470 981409480 756706026",
"output": "4825785129"
},
{
"input": "394691574 716672343\n398920207 72555681 150645586",
"output": "475704521"
},
{
"input": "276981463 853992230\n29394015 90072954 839552440",
"output": "1754738044"
},
{
"input": "843552056 919184611\n341530221 423649259 101547519",
"output": "263157645"
},
{
"input": "20809236 56504497\n972004030 441166533 495487081",
"output": "4235488636"
},
{
"input": "198066417 825228166\n602477839 532312735 520830423",
"output": "2808777834"
},
{
"input": "80356306 962548053\n601547868 549830008 914769984",
"output": "4004161345"
},
{
"input": "257613487 394835231\n642087093 567347282 308709545",
"output": "2692548667"
},
{
"input": "139903376 532155119\n641157122 289897263 629020178",
"output": "3077110809"
},
{
"input": "612127849 669475006\n271630930 676010757 22959739",
"output": "682559736"
},
{
"input": "0 0\n0 0 0",
"output": "0"
},
{
"input": "1000000000 1000000000\n499999998 4 333333332",
"output": "0"
},
{
"input": "1000000000 1000000000\n1000000000 1000000000 1000000000",
"output": "5000000000"
},
{
"input": "4 3\n1 0 1",
"output": "0"
},
{
"input": "4 12\n1 2 3",
"output": "0"
},
{
"input": "4 20\n1 2 1",
"output": "0"
},
{
"input": "100 10\n2 3 4",
"output": "5"
},
{
"input": "6 0\n1 1 1",
"output": "4"
},
{
"input": "25 5\n3 3 3",
"output": "7"
},
{
"input": "48 27\n22 39 20",
"output": "107"
},
{
"input": "4 0\n1 1 1",
"output": "4"
}
] | 1,626,983,763 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 6,656,000 | # Tricky alchemy
[A,B] = map(int,input().split())
[x,y,z] = map(int,input().split())
x == ((x * 2 + y * 2 + z * 3) - (A + B))
if x < 0:
print(0)
else:
print((x * 2 + y * 2 + z * 3) - (A + B))
| Title: Tricky Alchemy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.
Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.
Input Specification:
The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained.
Output Specification:
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
Demo Input:
['4 3\n2 1 1\n', '3 9\n1 1 3\n', '12345678 87654321\n43043751 1000000000 53798715\n']
Demo Output:
['2\n', '1\n', '2147483648\n']
Note:
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue. | ```python
# Tricky alchemy
[A,B] = map(int,input().split())
[x,y,z] = map(int,input().split())
x == ((x * 2 + y * 2 + z * 3) - (A + B))
if x < 0:
print(0)
else:
print((x * 2 + y * 2 + z * 3) - (A + B))
``` | 0 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,496,998,234 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 124 | 0 | str1, str2 = input(), input()
for i in range(len(str1)):
if str1[i] != str2[len(str1) - 1 - i]:
print('NO')
exit()
print('YES') | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
str1, str2 = input(), input()
for i in range(len(str1)):
if str1[i] != str2[len(str1) - 1 - i]:
print('NO')
exit()
print('YES')
``` | -1 |
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
"output": "1\n1 "
},
{
"input": "2\nBB",
"output": "1\n2 "
},
{
"input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB",
"output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1\nW",
"output": "0"
},
{
"input": "2\nWW",
"output": "0"
},
{
"input": "2\nWB",
"output": "1\n1 "
},
{
"input": "2\nBW",
"output": "1\n1 "
},
{
"input": "3\nBBB",
"output": "1\n3 "
},
{
"input": "3\nBWB",
"output": "2\n1 1 "
},
{
"input": "3\nWBB",
"output": "1\n2 "
},
{
"input": "3\nWWB",
"output": "1\n1 "
},
{
"input": "3\nWBW",
"output": "1\n1 "
},
{
"input": "3\nBWW",
"output": "1\n1 "
},
{
"input": "3\nWWW",
"output": "0"
},
{
"input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB",
"output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 "
},
{
"input": "5\nBBBWB",
"output": "2\n3 1 "
},
{
"input": "5\nBWWWB",
"output": "2\n1 1 "
},
{
"input": "5\nWWWWB",
"output": "1\n1 "
},
{
"input": "5\nBWWWW",
"output": "1\n1 "
},
{
"input": "5\nBBBWW",
"output": "1\n3 "
},
{
"input": "5\nWWBBB",
"output": "1\n3 "
},
{
"input": "10\nBBBBBWWBBB",
"output": "2\n5 3 "
},
{
"input": "10\nBBBBWBBWBB",
"output": "3\n4 2 2 "
},
{
"input": "20\nBBBBBWWBWBBWBWWBWBBB",
"output": "6\n5 1 2 1 1 3 "
},
{
"input": "20\nBBBWWWWBBWWWBWBWWBBB",
"output": "5\n3 2 1 1 3 "
},
{
"input": "20\nBBBBBBBBWBBBWBWBWBBB",
"output": "5\n8 3 1 1 3 "
},
{
"input": "20\nBBBWBWBWWWBBWWWWBWBB",
"output": "6\n3 1 1 2 1 2 "
},
{
"input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB",
"output": "5\n6 1 1 1 12 "
},
{
"input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB",
"output": "9\n5 1 2 1 1 4 1 1 8 "
},
{
"input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB",
"output": "7\n11 1 1 8 1 1 6 "
},
{
"input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW",
"output": "9\n5 1 1 1 1 2 2 1 1 "
},
{
"input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB",
"output": "6\n1 1 1 1 1 5 "
},
{
"input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB",
"output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB",
"output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n100 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB",
"output": "11\n20 1 1 1 2 1 1 1 1 1 20 "
},
{
"input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB",
"output": "11\n4 1 1 1 1 2 1 1 1 1 6 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "10\nWWBWWWBWBB",
"output": "3\n1 1 2 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n17 31 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n24 42 "
},
{
"input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB",
"output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 "
},
{
"input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB",
"output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 "
},
{
"input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB",
"output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 "
},
{
"input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB",
"output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 "
},
{
"input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB",
"output": "11\n1 5 3 4 3 1 1 2 1 2 4 "
}
] | 1,618,969,100 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 62 | 0 | n = int(input())
row = input()
row_arr = row.split("W")
row_arr = [i for i in row_arr if i != '']
print(len(row_arr))
#print(row_arr) # debugging
for i in row_arr:
print(len(i),end=" ")
| Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
Output Specification:
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
Demo Input:
['3\nBBW\n', '5\nBWBWB\n', '4\nWWWW\n', '4\nBBBB\n', '13\nWBBBBWWBWBBBW\n']
Demo Output:
['1\n2 ', '3\n1 1 1 ', '0\n', '1\n4 ', '3\n4 1 3 ']
Note:
The last sample case correspond to the picture in the statement. | ```python
n = int(input())
row = input()
row_arr = row.split("W")
row_arr = [i for i in row_arr if i != '']
print(len(row_arr))
#print(row_arr) # debugging
for i in row_arr:
print(len(i),end=" ")
``` | 3 |
|
977 | F | Consecutive Subsequence | PROGRAMMING | 1,700 | [
"dp"
] | null | null | You are given an integer array of length $n$.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $[x, x + 1, \dots, x + k - 1]$ for some value $x$ and length $k$.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array $[5, 3, 1, 2, 4]$ the following arrays are subsequences: $[3]$, $[5, 3, 1, 2, 4]$, $[5, 1, 4]$, but the array $[1, 3]$ is not. | The first line of the input containing integer number $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the array. The second line of the input containing $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the array itself. | On the first line print $k$ — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. | [
"7\n3 3 4 7 5 6 8\n",
"6\n1 3 5 2 4 6\n",
"4\n10 9 8 7\n",
"9\n6 7 8 3 4 5 9 10 11\n"
] | [
"4\n2 3 5 6 \n",
"2\n1 4 \n",
"1\n1 \n",
"6\n1 2 3 7 8 9 \n"
] | All valid answers for the first example (as sequences of indices):
- $[1, 3, 5, 6]$ - $[2, 3, 5, 6]$
All valid answers for the second example:
- $[1, 4]$ - $[2, 5]$ - $[3, 6]$
All valid answers for the third example:
- $[1]$ - $[2]$ - $[3]$ - $[4]$
All valid answers for the fourth example:
- $[1, 2, 3, 7, 8, 9]$ | 0 | [
{
"input": "7\n3 3 4 7 5 6 8",
"output": "4\n2 3 5 6 "
},
{
"input": "6\n1 3 5 2 4 6",
"output": "2\n1 4 "
},
{
"input": "4\n10 9 8 7",
"output": "1\n1 "
},
{
"input": "9\n6 7 8 3 4 5 9 10 11",
"output": "6\n1 2 3 7 8 9 "
},
{
"input": "1\n1337",
"output": "1\n1 "
},
{
"input": "2\n456 123",
"output": "1\n1 "
},
{
"input": "7\n100 3 4 7 5 6 8",
"output": "4\n2 3 5 6 "
},
{
"input": "7\n3 3 4 5 6 7 8",
"output": "6\n2 3 4 5 6 7 "
},
{
"input": "12\n1 2 3 4 5 6 7 8 9 10 11 12",
"output": "12\n1 2 3 4 5 6 7 8 9 10 11 12 "
}
] | 1,694,507,036 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | l = int(input())
nums = list(map(int,input().split()))
lenmax = {n:0 for n in nums}
for n in nums:
if n-1 in lenmax:
lenmax[n] = lenmax[n-1]+1
ans = max(lenmax.values())
res = []
for i in range(l-1,-1,-1):
if lenmax[nums[i]] == ans:
res.append(i)
ans-=1
print(len(res))
for i in reversed(res):
print(i+1,end=" ") | Title: Consecutive Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an integer array of length $n$.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $[x, x + 1, \dots, x + k - 1]$ for some value $x$ and length $k$.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array $[5, 3, 1, 2, 4]$ the following arrays are subsequences: $[3]$, $[5, 3, 1, 2, 4]$, $[5, 1, 4]$, but the array $[1, 3]$ is not.
Input Specification:
The first line of the input containing integer number $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the array. The second line of the input containing $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the array itself.
Output Specification:
On the first line print $k$ — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Demo Input:
['7\n3 3 4 7 5 6 8\n', '6\n1 3 5 2 4 6\n', '4\n10 9 8 7\n', '9\n6 7 8 3 4 5 9 10 11\n']
Demo Output:
['4\n2 3 5 6 \n', '2\n1 4 \n', '1\n1 \n', '6\n1 2 3 7 8 9 \n']
Note:
All valid answers for the first example (as sequences of indices):
- $[1, 3, 5, 6]$ - $[2, 3, 5, 6]$
All valid answers for the second example:
- $[1, 4]$ - $[2, 5]$ - $[3, 6]$
All valid answers for the third example:
- $[1]$ - $[2]$ - $[3]$ - $[4]$
All valid answers for the fourth example:
- $[1, 2, 3, 7, 8, 9]$ | ```python
l = int(input())
nums = list(map(int,input().split()))
lenmax = {n:0 for n in nums}
for n in nums:
if n-1 in lenmax:
lenmax[n] = lenmax[n-1]+1
ans = max(lenmax.values())
res = []
for i in range(l-1,-1,-1):
if lenmax[nums[i]] == ans:
res.append(i)
ans-=1
print(len(res))
for i in reversed(res):
print(i+1,end=" ")
``` | 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,614,517,340 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | m, n = map(int, input().split())
if ((int(m) * int(n)) % 2) == 0:
y = ((int(m) * int(n) * 0.5))
print(int(y))
elif((int(m) * int(n)) % 2) == 1:
y = (((int(m) * int(n)) - 1) * 0.5)
print(int(y))
| 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
m, n = map(int, input().split())
if ((int(m) * int(n)) % 2) == 0:
y = ((int(m) * int(n) * 0.5))
print(int(y))
elif((int(m) * int(n)) % 2) == 1:
y = (((int(m) * int(n)) - 1) * 0.5)
print(int(y))
``` | 3.969 |
0 | none | none | none | 0 | [
"none"
] | null | null | Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help. | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1018) — the number of players to participate in the tournament. | Print the maximum number of games in which the winner of the tournament can take part. | [
"2\n",
"3\n",
"4\n",
"10\n"
] | [
"1\n",
"2\n",
"2\n",
"4\n"
] | In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners. | 0 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "1000",
"output": "14"
},
{
"input": "2500",
"output": "15"
},
{
"input": "690000",
"output": "27"
},
{
"input": "3000000000",
"output": "45"
},
{
"input": "123456789123456789",
"output": "81"
},
{
"input": "5",
"output": "3"
},
{
"input": "143",
"output": "9"
},
{
"input": "144",
"output": "10"
},
{
"input": "145",
"output": "10"
},
{
"input": "232",
"output": "10"
},
{
"input": "233",
"output": "11"
},
{
"input": "234",
"output": "11"
},
{
"input": "679891637638612257",
"output": "84"
},
{
"input": "679891637638612258",
"output": "85"
},
{
"input": "679891637638612259",
"output": "85"
},
{
"input": "1000000000000000000",
"output": "85"
},
{
"input": "10235439547",
"output": "47"
},
{
"input": "1240723548",
"output": "43"
},
{
"input": "92353046212453",
"output": "66"
},
{
"input": "192403205846532",
"output": "68"
},
{
"input": "13925230525389",
"output": "62"
},
{
"input": "12048230592523",
"output": "62"
},
{
"input": "19204385325853",
"output": "63"
},
{
"input": "902353283921",
"output": "56"
},
{
"input": "793056859214355",
"output": "70"
},
{
"input": "982045466234565",
"output": "71"
},
{
"input": "126743950353465",
"output": "67"
},
{
"input": "12405430465",
"output": "47"
},
{
"input": "10238439257768",
"output": "61"
},
{
"input": "1728493055346",
"output": "58"
},
{
"input": "927553829046",
"output": "56"
},
{
"input": "62735129403",
"output": "51"
},
{
"input": "71624823950223",
"output": "65"
},
{
"input": "8902353464851212",
"output": "75"
},
{
"input": "61824012598535",
"output": "65"
},
{
"input": "1294902504603347",
"output": "71"
},
{
"input": "6",
"output": "3"
},
{
"input": "7",
"output": "3"
},
{
"input": "8",
"output": "4"
},
{
"input": "9",
"output": "4"
},
{
"input": "11",
"output": "4"
},
{
"input": "12",
"output": "4"
},
{
"input": "13",
"output": "5"
},
{
"input": "14",
"output": "5"
},
{
"input": "15",
"output": "5"
},
{
"input": "16",
"output": "5"
},
{
"input": "17",
"output": "5"
},
{
"input": "18",
"output": "5"
},
{
"input": "19",
"output": "5"
},
{
"input": "20",
"output": "5"
},
{
"input": "21",
"output": "6"
},
{
"input": "22",
"output": "6"
},
{
"input": "23",
"output": "6"
},
{
"input": "355687428096000",
"output": "69"
},
{
"input": "576460752303423488",
"output": "84"
},
{
"input": "32212254719",
"output": "49"
},
{
"input": "26388279066623",
"output": "63"
},
{
"input": "618473717761",
"output": "56"
},
{
"input": "262406072477",
"output": "54"
}
] | 1,484,482,814 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 4,608,000 | n = int(input())
f = [0] * 200
f[0] = 0
f[1] = 2
for k in range(2, 101):
f[k] = f[k-1] * 2 - 1
for k in range(1, 100):
if n >= f[k] and n < f[k+1]:
print(k)
exit() | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1018) — the number of players to participate in the tournament.
Output Specification:
Print the maximum number of games in which the winner of the tournament can take part.
Demo Input:
['2\n', '3\n', '4\n', '10\n']
Demo Output:
['1\n', '2\n', '2\n', '4\n']
Note:
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners. | ```python
n = int(input())
f = [0] * 200
f[0] = 0
f[1] = 2
for k in range(2, 101):
f[k] = f[k-1] * 2 - 1
for k in range(1, 100):
if n >= f[k] and n < f[k+1]:
print(k)
exit()
``` | 0 |
|
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,698,323,129 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 122 | 0 | shoes = list(input().split())
shoes = list(map(int, shoes))
colours = []
count = 0
for i in range(len(shoes)):
if shoes[i] in colours:
count += 1
else:
colours.append(shoes[i])
print(count)
| 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
shoes = list(input().split())
shoes = list(map(int, shoes))
colours = []
count = 0
for i in range(len(shoes)):
if shoes[i] in colours:
count += 1
else:
colours.append(shoes[i])
print(count)
``` | 3 |
|
73 | A | The Elder Trolls IV: Oblivon | PROGRAMMING | 1,600 | [
"greedy",
"math"
] | A. The Elder Trolls IV: Oblivon | 2 | 256 | Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so lovers of two-handed amber hammers should find suitable knife themselves. Secondly, it is necessary to make so many cutting strokes to Unkillable Slug. Extremely many. Too many!
Vasya has already promoted his character to 80-th level and in order to gain level 81 he was asked to kill Unkillable Slug. The monster has a very interesting shape. It looks like a rectangular parallelepiped with size *x*<=×<=*y*<=×<=*z*, consisting of undestructable cells 1<=×<=1<=×<=1. At one stroke Vasya can cut the Slug along an imaginary grid, i.e. cut with a plane parallel to one of the parallelepiped side. Monster dies when amount of parts it is divided reaches some critical value.
All parts of monster do not fall after each cut, they remains exactly on its places. I. e. Vasya can cut several parts with one cut.
Vasya wants to know what the maximum number of pieces he can cut the Unkillable Slug into striking him at most *k* times.
Vasya's character uses absolutely thin sword with infinite length. | The first line of input contains four integer numbers *x*,<=*y*,<=*z*,<=*k* (1<=≤<=*x*,<=*y*,<=*z*<=≤<=106,<=0<=≤<=*k*<=≤<=109). | Output the only number — the answer for the problem.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"2 2 2 3\n",
"2 2 2 1\n"
] | [
"8",
"2"
] | In the first sample Vasya make 3 pairwise perpendicular cuts. He cuts monster on two parts with the first cut, then he divides each part on two with the second cut, and finally he divides each of the 4 parts on two. | 500 | [
{
"input": "2 2 2 3",
"output": "8"
},
{
"input": "2 2 2 1",
"output": "2"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "1 2 3 3",
"output": "6"
},
{
"input": "20 4 5 12",
"output": "120"
},
{
"input": "100 500 100500 1000000000",
"output": "5025000000"
},
{
"input": "2 5 5 9",
"output": "50"
},
{
"input": "11 1 11 11",
"output": "42"
},
{
"input": "100500 5000 500 100000000",
"output": "251250000000"
},
{
"input": "2 2 2 0",
"output": "1"
},
{
"input": "1000000 1000000 1000000 2444441",
"output": "540974149875309150"
},
{
"input": "1000000 1000000 1000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "1000000 1000000 1000000 2999996",
"output": "999999000000000000"
},
{
"input": "1000000 1000000 1000000 2999997",
"output": "1000000000000000000"
},
{
"input": "999999 1000000 999997 999999999",
"output": "999996000003000000"
},
{
"input": "500000 1000000 750000 100000",
"output": "37040370459260"
},
{
"input": "999999 1 999998 1333333",
"output": "444445555556"
},
{
"input": "500000 10000 1000000 29998",
"output": "1000100000000"
},
{
"input": "10000 500000 1000000 29999",
"output": "1000200010000"
},
{
"input": "10000 1000000 500000 29996",
"output": "999900000000"
},
{
"input": "999999 123456 987654 0",
"output": "1"
},
{
"input": "1 1 1 0",
"output": "1"
},
{
"input": "219482 801483 941695 280976",
"output": "821595067700400"
},
{
"input": "808994 288453 204353 580644",
"output": "7250580779648149"
},
{
"input": "428676 64403 677407 626161",
"output": "5081000961597840"
},
{
"input": "559002 326875 150818 157621",
"output": "145045169133102"
},
{
"input": "178008 590076 624581 201286",
"output": "302062187173952"
},
{
"input": "797745 854005 98703 735186",
"output": "9996502351557447"
},
{
"input": "418223 118667 573175 776998",
"output": "12857677898465963"
},
{
"input": "39436 384053 48008 313346",
"output": "427693170156640"
},
{
"input": "661377 149342 523189 353305",
"output": "1633415415004970"
},
{
"input": "781081 414037 495753 892089",
"output": "26294515330164544"
},
{
"input": "402353 679460 969495 930195",
"output": "29810031851367496"
},
{
"input": "593408 709898 624186 915570",
"output": "28425961712082871"
},
{
"input": "1000 988 1000000 3000",
"output": "1002820000"
},
{
"input": "91839 2 3 50",
"output": "288"
},
{
"input": "999900 999990 4 129",
"output": "16384"
},
{
"input": "1024 100000 4 13",
"output": "144"
},
{
"input": "1000000 1000000 1000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "1 1000000 1 1000000000",
"output": "1000000"
},
{
"input": "2 1000 1000000 1000000000",
"output": "2000000000"
},
{
"input": "999999 2 1000000 1000000000",
"output": "1999998000000"
},
{
"input": "1000 1 1 1",
"output": "2"
},
{
"input": "1000 1 1 998",
"output": "999"
},
{
"input": "1000 1 1 1000",
"output": "1000"
},
{
"input": "33334 66667 1000000 100000",
"output": "37040370459260"
},
{
"input": "1 1000000 2 23123",
"output": "46246"
}
] | 1,450,801,697 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | x,y,z,k=map(int,input().split())
if k==1:
print (2)
if k==2:
print (4)
if k==3:
print (8)
if k>(x-1)+(y-1)+(z-1):
print (x*y*z)
if 3<k<=(x-1)+(y-1)+(z-1):
print (4*k-4)
| Title: The Elder Trolls IV: Oblivon
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so lovers of two-handed amber hammers should find suitable knife themselves. Secondly, it is necessary to make so many cutting strokes to Unkillable Slug. Extremely many. Too many!
Vasya has already promoted his character to 80-th level and in order to gain level 81 he was asked to kill Unkillable Slug. The monster has a very interesting shape. It looks like a rectangular parallelepiped with size *x*<=×<=*y*<=×<=*z*, consisting of undestructable cells 1<=×<=1<=×<=1. At one stroke Vasya can cut the Slug along an imaginary grid, i.e. cut with a plane parallel to one of the parallelepiped side. Monster dies when amount of parts it is divided reaches some critical value.
All parts of monster do not fall after each cut, they remains exactly on its places. I. e. Vasya can cut several parts with one cut.
Vasya wants to know what the maximum number of pieces he can cut the Unkillable Slug into striking him at most *k* times.
Vasya's character uses absolutely thin sword with infinite length.
Input Specification:
The first line of input contains four integer numbers *x*,<=*y*,<=*z*,<=*k* (1<=≤<=*x*,<=*y*,<=*z*<=≤<=106,<=0<=≤<=*k*<=≤<=109).
Output Specification:
Output the only number — the answer for the problem.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Demo Input:
['2 2 2 3\n', '2 2 2 1\n']
Demo Output:
['8', '2']
Note:
In the first sample Vasya make 3 pairwise perpendicular cuts. He cuts monster on two parts with the first cut, then he divides each part on two with the second cut, and finally he divides each of the 4 parts on two. | ```python
x,y,z,k=map(int,input().split())
if k==1:
print (2)
if k==2:
print (4)
if k==3:
print (8)
if k>(x-1)+(y-1)+(z-1):
print (x*y*z)
if 3<k<=(x-1)+(y-1)+(z-1):
print (4*k-4)
``` | 0 |
24 | E | Berland collider | PROGRAMMING | 2,300 | [
"binary search"
] | E. Berland collider | 1 | 256 | Recently the construction of Berland collider has been completed. Collider can be represented as a long narrow tunnel that contains *n* particles. We associate with collider 1-dimensional coordinate system, going from left to right. For each particle we know its coordinate and velocity at the moment of start of the collider. The velocities of the particles don't change after the launch of the collider. Berland scientists think that the big bang will happen at the first collision of particles, whose velocities differs in directions. Help them to determine how much time elapses after the launch of the collider before the big bang happens. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=5·105) — amount of particles in the collider. Next *n* lines contain description of particles. Each particle is described by two integers *x**i*, *v**i* (<=-<=109<=≤<=*x**i*,<=*v**i*<=≤<=109,<=*v**i*<=≠<=0) — coordinate and velocity respectively. All the coordinates are distinct. The particles are listed in order of increasing of coordinates. All the coordinates are in meters, and all the velocities — in meters per second. The negative velocity means that after the start of collider the particle will move to the left, and the positive — that the particle will move to the right. | If there will be no big bang, output -1. Otherwise output one number — how much time in seconds elapses after the launch of the collider before the big bang happens. Your answer must have a relative or absolute error less than 10<=-<=9. | [
"3\n-5 9\n0 1\n5 -1\n",
"6\n1 3\n2 3\n3 3\n4 -3\n5 -1\n6 -100\n"
] | [
"1.00000000000000000000\n",
"0.02912621359223301065\n"
] | none | 0 | [
{
"input": "3\n-5 9\n0 1\n5 -1",
"output": "1.00000000000000000000"
},
{
"input": "6\n1 3\n2 3\n3 3\n4 -3\n5 -1\n6 -100",
"output": "0.02912621359223301065"
},
{
"input": "2\n-1000000000 1\n1000000000 -1",
"output": "1000000000.00000000000000000000"
},
{
"input": "2\n-1000000000 -1000000000\n1000000000 1000000000",
"output": "-1.00000000000000000000"
},
{
"input": "2\n-156937950 -374833246\n958300153 463070159",
"output": "-1.00000000000000000000"
},
{
"input": "3\n-881879811 207649703\n458744977 -751771616\n589655887 -175300397",
"output": "1.39732645236331265437"
},
{
"input": "4\n-925572098 -981226339\n-79539996 -599059823\n221011621 -813670952\n769702162 -909895529",
"output": "-1.00000000000000000000"
},
{
"input": "10\n-774675771 179630170\n-743176829 190325067\n-718170081 850285922\n-672683474 -389325596\n-612117485 -338760201\n-200797120 -278253406\n-134576842 748798831\n301079085 755005057\n945958360 -883545251\n955629379 -312997434",
"output": "0.03669424359124097423"
},
{
"input": "20\n-993032259 588930376\n-992093161 915475807\n-916464883 -313099768\n-777812700 -790244010\n-559998666 152323291\n-552926767 745694067\n-489434665 332658987\n-310676193 687524020\n-238620668 88387668\n-183633372 294074811\n-89656750 233743240\n-39938323 194724339\n15621290 -244257473\n118853137 -823979220\n215181269 961240622\n224560970 967953108\n297709949 665893756\n314124971 127542046\n317622290 -269656857\n710505266 635433994",
"output": "0.00880495634198667429"
},
{
"input": "1\n-772620876 2105125",
"output": "-1.00000000000000000000"
},
{
"input": "10\n-904213434 999999991\n-800146111 999999990\n-64167773 999998990\n40786982 999997990\n57739924 999996990\n140713247 -999995990\n242293931 -999996990\n470153869 -999997990\n688427965 -999998990\n979253150 -999999990",
"output": "0.04148680711869298654"
},
{
"input": "14\n-916171372 999999988\n-892307487 999999987\n-882212312 999999986\n-700694118 999998986\n-490374058 999997986\n-179890370 999996986\n-153268251 999995986\n-143722350 -999994986\n822181362 -999995986\n888153520 -999996986\n913366887 -999997986\n971641961 -999998986\n982052281 -999999986\n989641415 -999999987",
"output": "0.00477297204519581270"
},
{
"input": "20\n-990544325 999999983\n-982730292 999999982\n-954108391 999999981\n-843979328 999999980\n-842201083 999998980\n-841368019 999997980\n-713774935 999996980\n-526274553 999995980\n-414200681 999994980\n-380902854 999993980\n-356598408 -999991980\n82002495 -999992980\n337411348 -999993980\n431155182 -999994980\n495442299 -999995980\n500857279 -999996980\n501941044 -999997980\n666074520 -999998980\n766795088 -999999980\n889713230 -999999981",
"output": "0.01215230830920432936"
},
{
"input": "10\n-904213434 999999991\n-800146111 999999990\n-64167773 3\n40786982 2\n57739924 1\n140713247 -1\n242293931 -2\n470153869 -3\n688427965 -4\n979253150 -999999990",
"output": "0.88969963939699647781"
},
{
"input": "20\n-977812598 999999995\n-859749238 999999994\n-795105479 999999993\n-755580921 999999992\n-703290711 999999991\n-684916878 999999990\n-671093572 999999989\n-598373289 999999988\n-430900427 999999987\n-409406663 999999986\n-186156927 999999985\n137241693 999999984\n174675082 999999983\n233164672 999999982\n263947075 999999981\n281714302 999999980\n501584746 -1\n638491974 -2\n654696707 -999999980\n795033851 -999999981",
"output": "0.18649120622982412465"
},
{
"input": "10\n-957843473 999999990\n-892079437 3\n-660108218 2\n-38604909 1\n117904913 -1\n161630686 -2\n300782495 -3\n503931515 -4\n624182611 -5\n946997174 -999999990",
"output": "0.95242033302420336938"
},
{
"input": "20\n-991228878 999999990\n-966272577 999999989\n-832645426 999999988\n-595404692 999999987\n-593256652 999999986\n-403204913 999999985\n-331750739 999999984\n-254714125 999999983\n-252716873 999999982\n-242309489 999999981\n-99999163 999999980\n53963197 1\n102558090 -1\n208915316 -2\n327993195 -999999980\n338364526 -999999981\n353909346 -999999982\n699191947 -999999983\n748932019 -999999984\n807201175 -999999985",
"output": "0.20255725684858788549"
},
{
"input": "5\n-99999163 999999980\n53963197 1\n102558090 -1\n208915316 -2\n327993195 -999999980",
"output": "0.20255725684858788549"
},
{
"input": "1\n-554798529 -923175217",
"output": "-1.00000000000000000000"
},
{
"input": "1\n-780061535 64785965",
"output": "-1.00000000000000000000"
},
{
"input": "2\n635254031 797637946\n855431510 75159864",
"output": "-1.00000000000000000000"
},
{
"input": "2\n-912376737 -339403417\n389839726 -135372297",
"output": "-1.00000000000000000000"
},
{
"input": "2\n-1000000000 1000000000\n1000000000 -1000000000",
"output": "1.00000000000000000000"
},
{
"input": "2\n-1 1000000000\n1 -1000000000",
"output": "0.00000000100000000002"
},
{
"input": "2\n-1 1\n1 -1",
"output": "1.00000000000000000000"
},
{
"input": "2\n-1 1000000000\n0 -1000000000",
"output": "0.00000000050000000003"
},
{
"input": "2\n-1000000000 7\n1000000000 -6",
"output": "153846153.84615385532379150391"
}
] | 1,680,729,013 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 17 | 1,500 | 34,816,000 | def can(particles, mid, pl, pr):
pos_right = particles[pr][0]
pos_left = particles[pl][0]
for i in range(pr, pl + 1):
x, v = particles[i]
aux = x + v * mid
if v > 0:
if aux > pos_right:
pos_right = aux
pos_left = particles[pl][0]
else:
if aux < pos_left:
pos_left = aux
if pos_left <= pos_right:
return True
return False
def main():
n = int(input())
particles = [tuple(map(int, input().split())) for _ in range(n)]
pl = -1
pr = 500000
for i in range(n):
if particles[i][1] > 0:
pr = i
break
for j in range(n - 1, -1, -1):
if particles[j][1] < 0:
pl = j
break
if pr > pl:
print(-1)
return
ans = 0
left, right = 0.0, 1e9
for _ in range(200):
mid = (left + right) / 2.0
if can(particles, mid, pl, pr):
right = mid
else:
left = mid
print(right)
main()
| Title: Berland collider
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Recently the construction of Berland collider has been completed. Collider can be represented as a long narrow tunnel that contains *n* particles. We associate with collider 1-dimensional coordinate system, going from left to right. For each particle we know its coordinate and velocity at the moment of start of the collider. The velocities of the particles don't change after the launch of the collider. Berland scientists think that the big bang will happen at the first collision of particles, whose velocities differs in directions. Help them to determine how much time elapses after the launch of the collider before the big bang happens.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=5·105) — amount of particles in the collider. Next *n* lines contain description of particles. Each particle is described by two integers *x**i*, *v**i* (<=-<=109<=≤<=*x**i*,<=*v**i*<=≤<=109,<=*v**i*<=≠<=0) — coordinate and velocity respectively. All the coordinates are distinct. The particles are listed in order of increasing of coordinates. All the coordinates are in meters, and all the velocities — in meters per second. The negative velocity means that after the start of collider the particle will move to the left, and the positive — that the particle will move to the right.
Output Specification:
If there will be no big bang, output -1. Otherwise output one number — how much time in seconds elapses after the launch of the collider before the big bang happens. Your answer must have a relative or absolute error less than 10<=-<=9.
Demo Input:
['3\n-5 9\n0 1\n5 -1\n', '6\n1 3\n2 3\n3 3\n4 -3\n5 -1\n6 -100\n']
Demo Output:
['1.00000000000000000000\n', '0.02912621359223301065\n']
Note:
none | ```python
def can(particles, mid, pl, pr):
pos_right = particles[pr][0]
pos_left = particles[pl][0]
for i in range(pr, pl + 1):
x, v = particles[i]
aux = x + v * mid
if v > 0:
if aux > pos_right:
pos_right = aux
pos_left = particles[pl][0]
else:
if aux < pos_left:
pos_left = aux
if pos_left <= pos_right:
return True
return False
def main():
n = int(input())
particles = [tuple(map(int, input().split())) for _ in range(n)]
pl = -1
pr = 500000
for i in range(n):
if particles[i][1] > 0:
pr = i
break
for j in range(n - 1, -1, -1):
if particles[j][1] < 0:
pl = j
break
if pr > pl:
print(-1)
return
ans = 0
left, right = 0.0, 1e9
for _ in range(200):
mid = (left + right) / 2.0
if can(particles, mid, pl, pr):
right = mid
else:
left = mid
print(right)
main()
``` | 0 |
786 | C | Till I Collapse | PROGRAMMING | 2,400 | [
"data structures",
"divide and conquer"
] | null | null | Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. They Have generated *n* Mr. Meeseeks, standing in a line numbered from 1 to *n*. Each of them has his own color. *i*-th Mr. Meeseeks' color is *a**i*.
Rick and Morty are gathering their army and they want to divide Mr. Meeseeks into some squads. They don't want their squads to be too colorful, so each squad should have Mr. Meeseeks of at most *k* different colors. Also each squad should be a continuous subarray of Mr. Meeseeks in the line. Meaning that for each 1<=≤<=*i*<=≤<=*e*<=≤<=*j*<=≤<=*n*, if Mr. Meeseeks number *i* and Mr. Meeseeks number *j* are in the same squad then Mr. Meeseeks number *e* should be in that same squad.
Also, each squad needs its own presidio, and building a presidio needs money, so they want the total number of squads to be minimized.
Rick and Morty haven't finalized the exact value of *k*, so in order to choose it, for each *k* between 1 and *n* (inclusive) need to know the minimum number of presidios needed. | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105) — number of Mr. Meeseeks.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* separated by spaces (1<=≤<=*a**i*<=≤<=*n*) — colors of Mr. Meeseeks in order they standing in a line. | In the first and only line of input print *n* integers separated by spaces. *i*-th integer should be the minimum number of presidios needed if the value of *k* is *i*. | [
"5\n1 3 4 3 3\n",
"8\n1 5 7 8 1 7 6 1\n"
] | [
"4 2 1 1 1 \n",
"8 4 3 2 1 1 1 1 \n"
] | For the first sample testcase, some optimal ways of dividing army into squads for each *k* are:
1. [1], [3], [4], [3, 3] 1. [1], [3, 4, 3, 3] 1. [1, 3, 4, 3, 3] 1. [1, 3, 4, 3, 3] 1. [1, 3, 4, 3, 3]
For the second testcase, some optimal ways of dividing army into squads for each *k* are:
1. [1], [5], [7], [8], [1], [7], [6], [1] 1. [1, 5], [7, 8], [1, 7], [6, 1] 1. [1, 5, 7], [8], [1, 7, 6, 1] 1. [1, 5, 7, 8], [1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] | 1,500 | [
{
"input": "5\n1 3 4 3 3",
"output": "4 2 1 1 1 "
},
{
"input": "8\n1 5 7 8 1 7 6 1",
"output": "8 4 3 2 1 1 1 1 "
},
{
"input": "10\n4 1 2 6 8 5 3 9 3 9",
"output": "10 4 3 2 2 2 2 1 1 1 "
},
{
"input": "85\n23 11 69 1 49 10 7 13 66 35 81 4 51 2 62 55 31 18 85 34 59 44 20 28 27 5 6 79 43 78 45 64 61 56 12 40 54 52 24 14 26 65 75 72 30 46 67 80 38 70 25 60 50 8 17 84 41 71 58 76 19 47 73 29 3 48 82 33 39 63 15 37 83 36 9 32 16 57 68 53 21 77 22 42 74",
"output": "85 43 29 22 17 15 13 11 10 9 8 8 7 7 6 6 5 5 5 5 5 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 "
},
{
"input": "100\n39 78 71 61 54 13 17 81 30 33 83 98 44 10 45 87 75 47 70 84 41 86 49 94 85 91 37 64 5 56 67 79 28 89 50 53 77 93 81 14 97 67 58 6 48 60 89 62 29 3 38 8 88 19 66 63 100 17 43 97 21 12 58 76 2 78 25 73 99 11 27 18 57 46 4 72 68 45 74 18 2 80 51 52 42 59 55 35 1 95 42 92 36 40 59 15 7 21 97 53",
"output": "100 50 34 25 20 17 15 13 11 10 10 9 8 7 7 6 6 6 6 5 5 5 5 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1\n1",
"output": "1 "
}
] | 1,686,380,144 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 26,112,000 | import os,sys,collections,heapq,itertools
if os.path.exists('in.txt'):
file = open('in.txt')
input = file.readline
else :
input = sys.stdin.readline
from functools import reduce
from itertools import accumulate,chain,combinations,count
from itertools import groupby,permutations,product,zip_longest
from heapq import heapify,heappush,heappop,heapreplace,merge,nlargest,nsmallest
from collections import Counter,defaultdict,deque
from bisect import bisect_left, bisect_right
from math import comb,floor,ceil,inf ,gcd ,sqrt
import functools
readi = lambda: int(input())
readis = lambda: list(map(int,input().split()))
reads = lambda: input().rstrip()
readss = lambda: input().split()
def solution():
n = readi()
a = readis()
res = [0] * (n+1)
r = len(set(a))
res[r] = 1
res[1] = len(list(groupby(a)))
q = [(1,r)]
def f(k):
m = 0
C = set()
i = 0
while i < n :
m += 1
C.clear()
while i < n:
C.add(a[i])
if len(C) > k : break
i += 1
return m
while q:
l,r = q.pop()
if r - l <= 1 or res[l] == res[r] : continue
mid = (l+r) // 2
res[mid] = f(mid)
q += [(l,mid),(mid,r)]
for i in range(2,n+1):
if not res[i] : res[i] = res[i-1]
print(*res[1:])
for i in range(1):
solution() | Title: Till I Collapse
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. They Have generated *n* Mr. Meeseeks, standing in a line numbered from 1 to *n*. Each of them has his own color. *i*-th Mr. Meeseeks' color is *a**i*.
Rick and Morty are gathering their army and they want to divide Mr. Meeseeks into some squads. They don't want their squads to be too colorful, so each squad should have Mr. Meeseeks of at most *k* different colors. Also each squad should be a continuous subarray of Mr. Meeseeks in the line. Meaning that for each 1<=≤<=*i*<=≤<=*e*<=≤<=*j*<=≤<=*n*, if Mr. Meeseeks number *i* and Mr. Meeseeks number *j* are in the same squad then Mr. Meeseeks number *e* should be in that same squad.
Also, each squad needs its own presidio, and building a presidio needs money, so they want the total number of squads to be minimized.
Rick and Morty haven't finalized the exact value of *k*, so in order to choose it, for each *k* between 1 and *n* (inclusive) need to know the minimum number of presidios needed.
Input Specification:
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105) — number of Mr. Meeseeks.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* separated by spaces (1<=≤<=*a**i*<=≤<=*n*) — colors of Mr. Meeseeks in order they standing in a line.
Output Specification:
In the first and only line of input print *n* integers separated by spaces. *i*-th integer should be the minimum number of presidios needed if the value of *k* is *i*.
Demo Input:
['5\n1 3 4 3 3\n', '8\n1 5 7 8 1 7 6 1\n']
Demo Output:
['4 2 1 1 1 \n', '8 4 3 2 1 1 1 1 \n']
Note:
For the first sample testcase, some optimal ways of dividing army into squads for each *k* are:
1. [1], [3], [4], [3, 3] 1. [1], [3, 4, 3, 3] 1. [1, 3, 4, 3, 3] 1. [1, 3, 4, 3, 3] 1. [1, 3, 4, 3, 3]
For the second testcase, some optimal ways of dividing army into squads for each *k* are:
1. [1], [5], [7], [8], [1], [7], [6], [1] 1. [1, 5], [7, 8], [1, 7], [6, 1] 1. [1, 5, 7], [8], [1, 7, 6, 1] 1. [1, 5, 7, 8], [1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] | ```python
import os,sys,collections,heapq,itertools
if os.path.exists('in.txt'):
file = open('in.txt')
input = file.readline
else :
input = sys.stdin.readline
from functools import reduce
from itertools import accumulate,chain,combinations,count
from itertools import groupby,permutations,product,zip_longest
from heapq import heapify,heappush,heappop,heapreplace,merge,nlargest,nsmallest
from collections import Counter,defaultdict,deque
from bisect import bisect_left, bisect_right
from math import comb,floor,ceil,inf ,gcd ,sqrt
import functools
readi = lambda: int(input())
readis = lambda: list(map(int,input().split()))
reads = lambda: input().rstrip()
readss = lambda: input().split()
def solution():
n = readi()
a = readis()
res = [0] * (n+1)
r = len(set(a))
res[r] = 1
res[1] = len(list(groupby(a)))
q = [(1,r)]
def f(k):
m = 0
C = set()
i = 0
while i < n :
m += 1
C.clear()
while i < n:
C.add(a[i])
if len(C) > k : break
i += 1
return m
while q:
l,r = q.pop()
if r - l <= 1 or res[l] == res[r] : continue
mid = (l+r) // 2
res[mid] = f(mid)
q += [(l,mid),(mid,r)]
for i in range(2,n+1):
if not res[i] : res[i] = res[i-1]
print(*res[1:])
for i in range(1):
solution()
``` | 0 |
|
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,593,338 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 109 | 0 | t = list(input())
q_inds = [i for i, x in enumerate(t) if x == "Q"]
a_inds = [i for i, x in enumerate(t) if x == "A"]
ans = 0
for i, qi in enumerate(q_inds):
for ai in a_inds:
if qi < ai:
for qi_2 in q_inds[i+1:]:
if ai < qi_2:
ans += 1
print(ans) | 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
t = list(input())
q_inds = [i for i, x in enumerate(t) if x == "Q"]
a_inds = [i for i, x in enumerate(t) if x == "A"]
ans = 0
for i, qi in enumerate(q_inds):
for ai in a_inds:
if qi < ai:
for qi_2 in q_inds[i+1:]:
if ai < qi_2:
ans += 1
print(ans)
``` | 3 |
|
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"output": "YES"
},
{
"input": "1\n999993399999",
"output": "NO"
},
{
"input": "9\n111 121 131 111 121 131 111 121 131",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO"
},
{
"input": "1\n1",
"output": "NO"
},
{
"input": "1\n10",
"output": "NO"
},
{
"input": "1\n976197352729",
"output": "NO"
},
{
"input": "1\n1000000000000",
"output": "NO"
},
{
"input": "1\n9",
"output": "YES"
},
{
"input": "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "3\n223092870 6469693230 200560490130",
"output": "NO\nNO\nNO"
},
{
"input": "2\n81 25",
"output": "NO\nYES"
},
{
"input": "1\n16",
"output": "NO"
},
{
"input": "22\n1 2 3 4 5 6 7 8 9 10 12752041 64 121 144 27550356289 124 24657 23756 135153365 25235235235 42351351 81",
"output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "1\n225",
"output": "NO"
},
{
"input": "1\n1521",
"output": "NO"
},
{
"input": "1\n81",
"output": "NO"
}
] | 1,697,386,984 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 56 | 2,000 | 14,336,000 | def is_prime4(x):
if (x == 2) or (x == 3):
return True
if (x % 6 != 1) and (x % 6 != 5):
return False
for i in range(5, int(x ** 0.5) + 1, 6):
if (x % i == 0) or (x % (i + 2) == 0):
return False
return True
n=int(input())
s=[int(i) for i in input().split()]
for i in range(0,n):
if(s[i]==1):
print("NO")
continue
num=s[i]**0.5
if(num==int(num)):
num=int(num)
if(is_prime4(num)):
print("YES")
else:
print("NO")
else:
print("NO") | Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
Input Specification:
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
Demo Input:
['3\n4 5 6\n']
Demo Output:
['YES\nNO\nNO\n']
Note:
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | ```python
def is_prime4(x):
if (x == 2) or (x == 3):
return True
if (x % 6 != 1) and (x % 6 != 5):
return False
for i in range(5, int(x ** 0.5) + 1, 6):
if (x % i == 0) or (x % (i + 2) == 0):
return False
return True
n=int(input())
s=[int(i) for i in input().split()]
for i in range(0,n):
if(s[i]==1):
print("NO")
continue
num=s[i]**0.5
if(num==int(num)):
num=int(num)
if(is_prime4(num)):
print("YES")
else:
print("NO")
else:
print("NO")
``` | 0 |
|
534 | A | Exam | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.
Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side. | A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam. | In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.
In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |*a**i*<=-<=*a**i*<=+<=1|<=≠<=1 for all *i* from 1 to *k*<=-<=1.
If there are several possible answers, output any of them. | [
"6",
"3\n"
] | [
"6\n1 5 3 6 2 4",
"2\n1 3"
] | none | 500 | [
{
"input": "6",
"output": "6\n5 3 1 6 4 2 "
},
{
"input": "3",
"output": "2\n1 3"
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "4",
"output": "4\n3 1 4 2 "
},
{
"input": "5",
"output": "5\n5 3 1 4 2 "
},
{
"input": "7",
"output": "7\n7 5 3 1 6 4 2 "
},
{
"input": "8",
"output": "8\n7 5 3 1 8 6 4 2 "
},
{
"input": "9",
"output": "9\n9 7 5 3 1 8 6 4 2 "
},
{
"input": "10",
"output": "10\n9 7 5 3 1 10 8 6 4 2 "
},
{
"input": "13",
"output": "13\n13 11 9 7 5 3 1 12 10 8 6 4 2 "
},
{
"input": "16",
"output": "16\n15 13 11 9 7 5 3 1 16 14 12 10 8 6 4 2 "
},
{
"input": "25",
"output": "25\n25 23 21 19 17 15 13 11 9 7 5 3 1 24 22 20 18 16 14 12 10 8 6 4 2 "
},
{
"input": "29",
"output": "29\n29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 28 26 24 22 20 18 16 14 12 10 8 6 4 2 "
},
{
"input": "120",
"output": "120\n119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 120 118 116 114 112 110 108 106 104 102 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 "
},
{
"input": "128",
"output": "128\n127 125 123 121 119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 128 126 124 122 120 118 116 114 112 110 108 106 104 102 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 "
},
{
"input": "216",
"output": "216\n215 213 211 209 207 205 203 201 199 197 195 193 191 189 187 185 183 181 179 177 175 173 171 169 167 165 163 161 159 157 155 153 151 149 147 145 143 141 139 137 135 133 131 129 127 125 123 121 119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 216 214 212 210 208 206 204 202 200 198 196 194 192 190 188 186 184 182 180 178 176 174 172 170 168 166 164 162 160 158 156 154 1..."
},
{
"input": "729",
"output": "729\n729 727 725 723 721 719 717 715 713 711 709 707 705 703 701 699 697 695 693 691 689 687 685 683 681 679 677 675 673 671 669 667 665 663 661 659 657 655 653 651 649 647 645 643 641 639 637 635 633 631 629 627 625 623 621 619 617 615 613 611 609 607 605 603 601 599 597 595 593 591 589 587 585 583 581 579 577 575 573 571 569 567 565 563 561 559 557 555 553 551 549 547 545 543 541 539 537 535 533 531 529 527 525 523 521 519 517 515 513 511 509 507 505 503 501 499 497 495 493 491 489 487 485 483 481 479 47..."
},
{
"input": "1111",
"output": "1111\n1111 1109 1107 1105 1103 1101 1099 1097 1095 1093 1091 1089 1087 1085 1083 1081 1079 1077 1075 1073 1071 1069 1067 1065 1063 1061 1059 1057 1055 1053 1051 1049 1047 1045 1043 1041 1039 1037 1035 1033 1031 1029 1027 1025 1023 1021 1019 1017 1015 1013 1011 1009 1007 1005 1003 1001 999 997 995 993 991 989 987 985 983 981 979 977 975 973 971 969 967 965 963 961 959 957 955 953 951 949 947 945 943 941 939 937 935 933 931 929 927 925 923 921 919 917 915 913 911 909 907 905 903 901 899 897 895 893 891 889 8..."
},
{
"input": "1597",
"output": "1597\n1597 1595 1593 1591 1589 1587 1585 1583 1581 1579 1577 1575 1573 1571 1569 1567 1565 1563 1561 1559 1557 1555 1553 1551 1549 1547 1545 1543 1541 1539 1537 1535 1533 1531 1529 1527 1525 1523 1521 1519 1517 1515 1513 1511 1509 1507 1505 1503 1501 1499 1497 1495 1493 1491 1489 1487 1485 1483 1481 1479 1477 1475 1473 1471 1469 1467 1465 1463 1461 1459 1457 1455 1453 1451 1449 1447 1445 1443 1441 1439 1437 1435 1433 1431 1429 1427 1425 1423 1421 1419 1417 1415 1413 1411 1409 1407 1405 1403 1401 1399 1397 ..."
},
{
"input": "1777",
"output": "1777\n1777 1775 1773 1771 1769 1767 1765 1763 1761 1759 1757 1755 1753 1751 1749 1747 1745 1743 1741 1739 1737 1735 1733 1731 1729 1727 1725 1723 1721 1719 1717 1715 1713 1711 1709 1707 1705 1703 1701 1699 1697 1695 1693 1691 1689 1687 1685 1683 1681 1679 1677 1675 1673 1671 1669 1667 1665 1663 1661 1659 1657 1655 1653 1651 1649 1647 1645 1643 1641 1639 1637 1635 1633 1631 1629 1627 1625 1623 1621 1619 1617 1615 1613 1611 1609 1607 1605 1603 1601 1599 1597 1595 1593 1591 1589 1587 1585 1583 1581 1579 1577 ..."
},
{
"input": "2048",
"output": "2048\n2047 2045 2043 2041 2039 2037 2035 2033 2031 2029 2027 2025 2023 2021 2019 2017 2015 2013 2011 2009 2007 2005 2003 2001 1999 1997 1995 1993 1991 1989 1987 1985 1983 1981 1979 1977 1975 1973 1971 1969 1967 1965 1963 1961 1959 1957 1955 1953 1951 1949 1947 1945 1943 1941 1939 1937 1935 1933 1931 1929 1927 1925 1923 1921 1919 1917 1915 1913 1911 1909 1907 1905 1903 1901 1899 1897 1895 1893 1891 1889 1887 1885 1883 1881 1879 1877 1875 1873 1871 1869 1867 1865 1863 1861 1859 1857 1855 1853 1851 1849 1847 ..."
},
{
"input": "2999",
"output": "2999\n2999 2997 2995 2993 2991 2989 2987 2985 2983 2981 2979 2977 2975 2973 2971 2969 2967 2965 2963 2961 2959 2957 2955 2953 2951 2949 2947 2945 2943 2941 2939 2937 2935 2933 2931 2929 2927 2925 2923 2921 2919 2917 2915 2913 2911 2909 2907 2905 2903 2901 2899 2897 2895 2893 2891 2889 2887 2885 2883 2881 2879 2877 2875 2873 2871 2869 2867 2865 2863 2861 2859 2857 2855 2853 2851 2849 2847 2845 2843 2841 2839 2837 2835 2833 2831 2829 2827 2825 2823 2821 2819 2817 2815 2813 2811 2809 2807 2805 2803 2801 2799 ..."
},
{
"input": "3001",
"output": "3001\n3001 2999 2997 2995 2993 2991 2989 2987 2985 2983 2981 2979 2977 2975 2973 2971 2969 2967 2965 2963 2961 2959 2957 2955 2953 2951 2949 2947 2945 2943 2941 2939 2937 2935 2933 2931 2929 2927 2925 2923 2921 2919 2917 2915 2913 2911 2909 2907 2905 2903 2901 2899 2897 2895 2893 2891 2889 2887 2885 2883 2881 2879 2877 2875 2873 2871 2869 2867 2865 2863 2861 2859 2857 2855 2853 2851 2849 2847 2845 2843 2841 2839 2837 2835 2833 2831 2829 2827 2825 2823 2821 2819 2817 2815 2813 2811 2809 2807 2805 2803 2801 ..."
},
{
"input": "4181",
"output": "4181\n4181 4179 4177 4175 4173 4171 4169 4167 4165 4163 4161 4159 4157 4155 4153 4151 4149 4147 4145 4143 4141 4139 4137 4135 4133 4131 4129 4127 4125 4123 4121 4119 4117 4115 4113 4111 4109 4107 4105 4103 4101 4099 4097 4095 4093 4091 4089 4087 4085 4083 4081 4079 4077 4075 4073 4071 4069 4067 4065 4063 4061 4059 4057 4055 4053 4051 4049 4047 4045 4043 4041 4039 4037 4035 4033 4031 4029 4027 4025 4023 4021 4019 4017 4015 4013 4011 4009 4007 4005 4003 4001 3999 3997 3995 3993 3991 3989 3987 3985 3983 3981 ..."
},
{
"input": "4990",
"output": "4990\n4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 4791 4789 ..."
},
{
"input": "4991",
"output": "4991\n4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 4791 ..."
},
{
"input": "4992",
"output": "4992\n4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 4791 ..."
},
{
"input": "4993",
"output": "4993\n4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 ..."
},
{
"input": "4994",
"output": "4994\n4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 ..."
},
{
"input": "4995",
"output": "4995\n4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 ..."
},
{
"input": "4996",
"output": "4996\n4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 ..."
},
{
"input": "4997",
"output": "4997\n4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 ..."
},
{
"input": "4998",
"output": "4998\n4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 ..."
},
{
"input": "4999",
"output": "4999\n4999 4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 ..."
},
{
"input": "5000",
"output": "5000\n4999 4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 ..."
}
] | 1,617,611,086 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 204,800 | def odd(lst,n):
for i in range(1,n+1,2):
lst.append(i)
def even(lst,n):
start=2
if len(lst)==1 or n==3:
start=4
for j in range(start,n+1,2):
lst.append(j)
n=int(input())
lst=[]
if n%2==0 and n>2:
even(lst, n)
odd(lst, n)
else:
odd(lst, n)
even(lst, n)
print(len(lst))
print(*lst) | Title: Exam
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.
Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.
Input Specification:
A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam.
Output Specification:
In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.
In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |*a**i*<=-<=*a**i*<=+<=1|<=≠<=1 for all *i* from 1 to *k*<=-<=1.
If there are several possible answers, output any of them.
Demo Input:
['6', '3\n']
Demo Output:
['6\n1 5 3 6 2 4', '2\n1 3']
Note:
none | ```python
def odd(lst,n):
for i in range(1,n+1,2):
lst.append(i)
def even(lst,n):
start=2
if len(lst)==1 or n==3:
start=4
for j in range(start,n+1,2):
lst.append(j)
n=int(input())
lst=[]
if n%2==0 and n>2:
even(lst, n)
odd(lst, n)
else:
odd(lst, n)
even(lst, n)
print(len(lst))
print(*lst)
``` | 3 |
|
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10").
Let *val*(*s*) be such a number that *s* is its binary representation.
Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=<<=*val*(*b*).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all). | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100".
In the second example you can't obtain smaller answer no matter what operations you use. | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "1"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111",
"output": "10"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "8\n10101010",
"output": "10000"
},
{
"input": "2\n10",
"output": "10"
},
{
"input": "3\n111",
"output": "1"
},
{
"input": "5\n11100",
"output": "100"
},
{
"input": "2\n11",
"output": "1"
},
{
"input": "3\n110",
"output": "10"
},
{
"input": "50\n10010010000000000000000000000000000000001000000000",
"output": "10000000000000000000000000000000000000000000000"
}
] | 1,665,453,888 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | n=input();print('1'+(input().count('0')*'0')) | Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10").
Let *val*(*s*) be such a number that *s* is its binary representation.
Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=<<=*val*(*b*).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
Input Specification:
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Output Specification:
Print one string — the minimum correct string that you can obtain from the given one.
Demo Input:
['4\n1001\n', '1\n1\n']
Demo Output:
['100\n', '1\n']
Note:
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100".
In the second example you can't obtain smaller answer no matter what operations you use. | ```python
n=input();print('1'+(input().count('0')*'0'))
``` | 0 |
|
351 | E | Jeff and Permutation | PROGRAMMING | 2,200 | [
"greedy"
] | null | null | Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence *p*1,<=*p*2,<=...,<=*p**n* for his birthday.
Jeff hates inversions in sequences. An inversion in sequence *a*1,<=*a*2,<=...,<=*a**n* is a pair of indexes *i*,<=*j* (1<=≤<=*i*<=<<=*j*<=≤<=*n*), such that an inequality *a**i*<=><=*a**j* holds.
Jeff can multiply some numbers of the sequence *p* by -1. At that, he wants the number of inversions in the sequence to be minimum. Help Jeff and find the minimum number of inversions he manages to get. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000). The next line contains *n* integers — sequence *p*1, *p*2, ..., *p**n* (|*p**i*|<=≤<=105). The numbers are separated by spaces. | In a single line print the answer to the problem — the minimum number of inversions Jeff can get. | [
"2\n2 1\n",
"9\n-2 0 -1 0 -1 2 1 0 -1\n"
] | [
"0\n",
"6\n"
] | none | 2,000 | [
{
"input": "2\n2 1",
"output": "0"
},
{
"input": "9\n-2 0 -1 0 -1 2 1 0 -1",
"output": "6"
},
{
"input": "9\n0 0 1 1 0 0 1 0 1",
"output": "5"
},
{
"input": "8\n0 1 2 -1 -2 1 -2 2",
"output": "3"
},
{
"input": "24\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0 0 -1 -2",
"output": "55"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "31\n-2 2 -2 -1 0 0 1 2 1 1 -1 -2 1 -1 -2 2 0 1 -1 -2 -1 -2 -1 2 2 2 2 1 1 0 1",
"output": "74"
},
{
"input": "9\n1 -1 -1 0 -1 0 1 1 1",
"output": "1"
},
{
"input": "5\n1 0 1 -2 1",
"output": "1"
},
{
"input": "31\n-5 -5 5 3 -1 3 1 -3 -3 -1 -5 -3 -2 -4 -3 3 5 -2 1 0 -1 1 -3 1 -1 1 3 3 2 1 0",
"output": "70"
},
{
"input": "53\n-3 2 -3 -5 -2 7 0 -2 1 6 -1 2 5 -3 3 -6 -2 -5 -3 -6 4 -4 -2 6 1 -7 -6 -4 0 2 -5 -1 -2 -6 2 2 7 -2 -3 1 0 -4 3 4 -2 7 -3 7 7 3 -5 -5 3",
"output": "289"
},
{
"input": "24\n-3 -4 3 -3 3 2 -1 -3 -4 0 -4 0 2 3 3 -1 2 1 2 -2 3 -2 1 0",
"output": "46"
},
{
"input": "50\n-6 1 -3 7 -5 -5 4 0 3 -5 1 2 -1 0 7 0 6 3 -5 4 4 3 -7 -1 4 4 -5 3 7 1 4 2 6 -4 0 3 -3 -2 -3 1 -5 3 -4 2 -2 7 -1 3 -7 4",
"output": "260"
},
{
"input": "17\n-56007 -97423 -66458 -17041 49374 60662 42188 56222 28689 -4117 -1712 11034 17161 43908 -65064 -76642 -73934",
"output": "13"
},
{
"input": "12\n0 1 0 1 1 -1 1 -1 0 1 0 -1",
"output": "12"
}
] | 1,521,585,972 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 124 | 7,065,600 | print("QUE TE CACHEN PROBLEMA E(DIV1)")
print("By: GUillermo Montanez Sosa - Guillermo_0114") | Title: Jeff and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence *p*1,<=*p*2,<=...,<=*p**n* for his birthday.
Jeff hates inversions in sequences. An inversion in sequence *a*1,<=*a*2,<=...,<=*a**n* is a pair of indexes *i*,<=*j* (1<=≤<=*i*<=<<=*j*<=≤<=*n*), such that an inequality *a**i*<=><=*a**j* holds.
Jeff can multiply some numbers of the sequence *p* by -1. At that, he wants the number of inversions in the sequence to be minimum. Help Jeff and find the minimum number of inversions he manages to get.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000). The next line contains *n* integers — sequence *p*1, *p*2, ..., *p**n* (|*p**i*|<=≤<=105). The numbers are separated by spaces.
Output Specification:
In a single line print the answer to the problem — the minimum number of inversions Jeff can get.
Demo Input:
['2\n2 1\n', '9\n-2 0 -1 0 -1 2 1 0 -1\n']
Demo Output:
['0\n', '6\n']
Note:
none | ```python
print("QUE TE CACHEN PROBLEMA E(DIV1)")
print("By: GUillermo Montanez Sosa - Guillermo_0114")
``` | 0 |
|
409 | D | Big Data | PROGRAMMING | 1,700 | [
"*special"
] | null | null | Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts:
- The highest mountain above sea level in the world is Mount Everest. Its peak rises to 8848 m. - The largest board game tournament consisted of 958 participants playing chapaev.- The largest online maths competition consisted of 12766 participants.- The Nile is credited as the longest river in the world. From its farthest stream in Burundi, it extends 6695 km in length.- While not in flood, the main stretches of the Amazon river in South America can reach widths of up to 1100 km at its widest points.- Angel Falls is the highest waterfall. Its greatest single drop measures 807 m.- The Hotel Everest View above Namche, Nepal — the village closest to Everest base camp – is at a record height of 31962 m- Uranium is the heaviest of all the naturally occurring elements. Its most common isotope has a nucleus containing 146 neutrons.- The coldest permanently inhabited place is the Siberian village of Oymyakon, where the temperature of -68°C was registered in the twentieth century.- The longest snake held in captivity is over 25 feet long. Its name is Medusa.- Colonel Meow holds the world record for longest fur on a cat — almost 134 centimeters.- Sea otters can have up to 10000 hairs per square inch. This is the most dense fur in the animal kingdom.- The largest state of USA is Alaska; its area is 663268 square miles- Alaska has a longer coastline than all of the other 49 U.S. States put together: it is 154103 miles long.- Lake Baikal is the largest freshwater lake in the world. It reaches 1642 meters in depth and contains around one-fifth of the world’s unfrozen fresh water.- The most colorful national flag is the one of Turkmenistan, with 106 colors. | The input will contain a single integer between 1 and 16. | Output a single integer. | [
"1\n",
"7\n"
] | [
"1\n",
"0\n"
] | none | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "0"
},
{
"input": "13",
"output": "1"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "16",
"output": "0"
},
{
"input": "11",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "15",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "12",
"output": "0"
},
{
"input": "6",
"output": "1"
},
{
"input": "14",
"output": "0"
}
] | 1,643,029,745 | 2,147,483,647 | PyPy 3 | OK | TESTS | 16 | 77 | 0 | s="01001010111001010"
print(s[int(input())]) | Title: Big Data
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts:
- The highest mountain above sea level in the world is Mount Everest. Its peak rises to 8848 m. - The largest board game tournament consisted of 958 participants playing chapaev.- The largest online maths competition consisted of 12766 participants.- The Nile is credited as the longest river in the world. From its farthest stream in Burundi, it extends 6695 km in length.- While not in flood, the main stretches of the Amazon river in South America can reach widths of up to 1100 km at its widest points.- Angel Falls is the highest waterfall. Its greatest single drop measures 807 m.- The Hotel Everest View above Namche, Nepal — the village closest to Everest base camp – is at a record height of 31962 m- Uranium is the heaviest of all the naturally occurring elements. Its most common isotope has a nucleus containing 146 neutrons.- The coldest permanently inhabited place is the Siberian village of Oymyakon, where the temperature of -68°C was registered in the twentieth century.- The longest snake held in captivity is over 25 feet long. Its name is Medusa.- Colonel Meow holds the world record for longest fur on a cat — almost 134 centimeters.- Sea otters can have up to 10000 hairs per square inch. This is the most dense fur in the animal kingdom.- The largest state of USA is Alaska; its area is 663268 square miles- Alaska has a longer coastline than all of the other 49 U.S. States put together: it is 154103 miles long.- Lake Baikal is the largest freshwater lake in the world. It reaches 1642 meters in depth and contains around one-fifth of the world’s unfrozen fresh water.- The most colorful national flag is the one of Turkmenistan, with 106 colors.
Input Specification:
The input will contain a single integer between 1 and 16.
Output Specification:
Output a single integer.
Demo Input:
['1\n', '7\n']
Demo Output:
['1\n', '0\n']
Note:
none | ```python
s="01001010111001010"
print(s[int(input())])
``` | 3 |
|
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s*. The newspaper contains string *t*, consisting of uppercase and lowercase English letters. We know that the length of string *t* greater or equal to the length of the string *s*.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some *n* letters out of the newspaper and make a message of length exactly *n*, so that it looked as much as possible like *s*. If the letter in some position has correct value and correct letter case (in the string *s* and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message. | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the length of the string *a*. | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "0 26"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\nqrsimtabuvzhnwcdefgjklxyop",
"output": "26 0"
},
{
"input": "l\nFPbAVjsMpPDTLkfwNYFmBDHPTDSWSOUlrBHYJHPM",
"output": "1 0"
},
{
"input": "ncMeXssLHS\nuwyeMcaFatpInZVdEYpwJQSnVxLK",
"output": "6 1"
},
{
"input": "DpiNBmCRFWxpdbfGOzvvOcemjructoAdEwegTvbVbfWWRPGyEAxGdDRWVlqNyGWMWHMrHAIZpyxvgaflrsVZhhZRouvpxrKXFZam\nwwPLFtNfPtJXvMLuHjKfYyaRhreNSWSzOvDpqHCGcqllACNPGHxReeFUCmAqIKXYytsSQwIxJzNiiUtgebVuwRmWpRALLyKAzyDPvgIGxALSaeeTIqm",
"output": "66 12"
},
{
"input": "CCAE\ndcecc",
"output": "0 3"
},
{
"input": "Dccb\nbeeeb",
"output": "1 0"
},
{
"input": "Adc\neadeabcad",
"output": "2 1"
},
{
"input": "DBAdeb\ndeeabcddadaa",
"output": "3 2"
},
{
"input": "EDCED\neebeacdba",
"output": "0 4"
},
{
"input": "CdAbD\ndecbde",
"output": "2 2"
},
{
"input": "a\nB",
"output": "0 0"
},
{
"input": "r\nqA",
"output": "0 0"
}
] | 1,635,692,407 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 124 | 21,401,600 | import heapq;
stringOne = input()
stringTwo = input()
hashMapOne = {char: 0 for char in stringOne}
hashMapTwo = {char: 0 for char in stringTwo}
for char in stringOne:
hashMapOne[char] += 1
for char in stringTwo:
hashMapTwo[char] += 1
yay = 0
whoo = 0
heap = []
for char in hashMapTwo:
heapq.heappush(heap, (-hashMapTwo[char], char))
def solve(char, casedChar):
yay = 0
whoo = 0
currentMin = min(hashMapOne[char], hashMapTwo[char]
) if char in hashMapOne else 0
yay += currentMin
hashMapTwo[char] -= currentMin
if char in hashMapOne:
hashMapOne[char] -= currentMin
if hashMapOne[char] == 0:
hashMapOne.pop(char)
currentMin = min(hashMapOne[casedChar], hashMapTwo[char]
) if casedChar in hashMapOne else 0
whoo += currentMin
hashMapTwo[char] -= currentMin
if casedChar in hashMapOne:
hashMapOne[casedChar] -= currentMin
if hashMapOne[casedChar] == 0:
hashMapOne.pop(casedChar)
return (yay, whoo)
while(len(heap)):
count, char = heapq.heappop(heap)
if char.islower():
if char not in hashMapOne and char.upper() not in hashMapOne:
continue
currentYayy, currentWhoo = solve(char, char.upper())
yay += currentYayy
whoo += currentWhoo
else:
if char not in hashMapOne and char.lower() not in hashMapOne:
continue
currentYayy, currentWhoo = solve(char, char.lower())
yay += currentYayy
whoo += currentWhoo
if hashMapTwo[char] > 0:
heapq.heappush(heap, (-hashMapTwo[char], char))
print(yay, whoo)
| Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s*. The newspaper contains string *t*, consisting of uppercase and lowercase English letters. We know that the length of string *t* greater or equal to the length of the string *s*.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some *n* letters out of the newspaper and make a message of length exactly *n*, so that it looked as much as possible like *s*. If the letter in some position has correct value and correct letter case (in the string *s* and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
Input Specification:
The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the length of the string *a*.
Output Specification:
Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message.
Demo Input:
['AbC\nDCbA\n', 'ABC\nabc\n', 'abacaba\nAbaCaBA\n']
Demo Output:
['3 0\n', '0 3\n', '3 4\n']
Note:
none | ```python
import heapq;
stringOne = input()
stringTwo = input()
hashMapOne = {char: 0 for char in stringOne}
hashMapTwo = {char: 0 for char in stringTwo}
for char in stringOne:
hashMapOne[char] += 1
for char in stringTwo:
hashMapTwo[char] += 1
yay = 0
whoo = 0
heap = []
for char in hashMapTwo:
heapq.heappush(heap, (-hashMapTwo[char], char))
def solve(char, casedChar):
yay = 0
whoo = 0
currentMin = min(hashMapOne[char], hashMapTwo[char]
) if char in hashMapOne else 0
yay += currentMin
hashMapTwo[char] -= currentMin
if char in hashMapOne:
hashMapOne[char] -= currentMin
if hashMapOne[char] == 0:
hashMapOne.pop(char)
currentMin = min(hashMapOne[casedChar], hashMapTwo[char]
) if casedChar in hashMapOne else 0
whoo += currentMin
hashMapTwo[char] -= currentMin
if casedChar in hashMapOne:
hashMapOne[casedChar] -= currentMin
if hashMapOne[casedChar] == 0:
hashMapOne.pop(casedChar)
return (yay, whoo)
while(len(heap)):
count, char = heapq.heappop(heap)
if char.islower():
if char not in hashMapOne and char.upper() not in hashMapOne:
continue
currentYayy, currentWhoo = solve(char, char.upper())
yay += currentYayy
whoo += currentWhoo
else:
if char not in hashMapOne and char.lower() not in hashMapOne:
continue
currentYayy, currentWhoo = solve(char, char.lower())
yay += currentYayy
whoo += currentWhoo
if hashMapTwo[char] > 0:
heapq.heappush(heap, (-hashMapTwo[char], char))
print(yay, whoo)
``` | 0 |
|
727 | C | Guess the Array | PROGRAMMING | 1,400 | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).
In this problem you should guess an array *a* which is unknown for you. The only information you have initially is the length *n* of the array *a*.
The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices *i* and *j* (the indices should be distinct). Then your program should read the response: the single integer equals to *a**i*<=+<=*a**j*.
It is easy to prove that it is always possible to guess the array using at most *n* requests.
Write a program that will guess the array *a* by making at most *n* requests. | none | none | [
"5\n \n9\n \n7\n \n9\n \n11\n \n6\n "
] | [
"? 1 5\n \n? 2 3\n \n? 4 1\n \n? 5 2\n \n? 3 4\n \n! 4 6 1 5 5"
] | The format of a test to make a hack is:
- The first line contains an integer number *n* (3 ≤ *n* ≤ 5000) — the length of the array.- The second line contains *n* numbers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">5</sup>) — the elements of the array to guess. | 1,500 | [
{
"input": "5\n4 6 1 5 5",
"output": "5 out of 5"
},
{
"input": "3\n1 1 1",
"output": "3 out of 3"
},
{
"input": "4\n100 1 100 1",
"output": "4 out of 4"
},
{
"input": "10\n9 5 10 7 4 4 8 5 10 5",
"output": "10 out of 10"
},
{
"input": "3\n1 1 1",
"output": "3 out of 3"
},
{
"input": "3\n100000 100000 100000",
"output": "3 out of 3"
},
{
"input": "3\n91906 50782 19777",
"output": "3 out of 3"
},
{
"input": "15\n5 10 10 7 7 6 4 6 8 10 8 4 10 9 4",
"output": "15 out of 15"
},
{
"input": "30\n2 3 3 4 3 2 4 4 4 3 3 2 4 2 3 4 4 2 4 3 4 2 2 4 3 3 4 4 4 4",
"output": "30 out of 30"
},
{
"input": "35\n4 2 2 2 4 4 3 2 4 2 2 4 2 2 3 2 3 4 4 2 3 2 2 4 3 3 3 3 4 2 3 2 2 2 3",
"output": "35 out of 35"
},
{
"input": "40\n3 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",
"output": "40 out of 40"
},
{
"input": "47\n3 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 3 3 3 3 3 3",
"output": "47 out of 47"
},
{
"input": "100\n76 92 53 18 65 98 100 65 93 72 100 44 70 62 78 61 89 89 80 32 88 64 67 27 46 30 75 14 78 94 8 86 41 9 68 38 76 29 69 44 23 23 14 24 97 14 7 98 45 80 55 71 58 35 41 100 60 54 64 85 56 98 87 93 40 62 92 6 7 27 88 85 10 94 25 43 99 65 82 65 39 34 17 100 49 27 4 15 84 10 35 76 98 52 72 17 43 10 49 5",
"output": "100 out of 100"
}
] | 1,586,955,084 | 2,147,483,647 | PyPy 3 | IDLENESS_LIMIT_EXCEEDED | TESTS | 0 | 0 | 0 | from math import ceil,gcd,floor
from collections import deque,defaultdict as dict
from heapq import heappush as hpush,heappop as hpop, heapify
from functools import lru_cache
import sys
input = sys.stdin.buffer.readline
inf=float("inf")
def inpi(): return(int(input()))
def inpa(): return(list(map(int,input().split())))
def inp(): s = input();return(list(s))
def inpv(): return(map(int,input().split()))
n=int(input())
d={}
for i in range(2,n+1):
print("?",1,i)
sys.stdout.flush()
d[i]=int(input())
print("?",2,3)
k=inpi()
d[1]=(d[2]+d[3]-k)//2
print("!",d[1],end=" ")
for i in range(2,n+1):
print(d[i]-d[1],end=" ")
sys.stdout.flush() | Title: Guess the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).
In this problem you should guess an array *a* which is unknown for you. The only information you have initially is the length *n* of the array *a*.
The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices *i* and *j* (the indices should be distinct). Then your program should read the response: the single integer equals to *a**i*<=+<=*a**j*.
It is easy to prove that it is always possible to guess the array using at most *n* requests.
Write a program that will guess the array *a* by making at most *n* requests.
Input Specification:
none
Output Specification:
none
Demo Input:
['5\n\xa0\n9\n\xa0\n7\n\xa0\n9\n\xa0\n11\n\xa0\n6\n\xa0']
Demo Output:
['? 1 5\n\xa0\n? 2 3\n\xa0\n? 4 1\n\xa0\n? 5 2\n\xa0\n? 3 4\n\xa0\n! 4 6 1 5 5']
Note:
The format of a test to make a hack is:
- The first line contains an integer number *n* (3 ≤ *n* ≤ 5000) — the length of the array.- The second line contains *n* numbers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">5</sup>) — the elements of the array to guess. | ```python
from math import ceil,gcd,floor
from collections import deque,defaultdict as dict
from heapq import heappush as hpush,heappop as hpop, heapify
from functools import lru_cache
import sys
input = sys.stdin.buffer.readline
inf=float("inf")
def inpi(): return(int(input()))
def inpa(): return(list(map(int,input().split())))
def inp(): s = input();return(list(s))
def inpv(): return(map(int,input().split()))
n=int(input())
d={}
for i in range(2,n+1):
print("?",1,i)
sys.stdout.flush()
d[i]=int(input())
print("?",2,3)
k=inpi()
d[1]=(d[2]+d[3]-k)//2
print("!",d[1],end=" ")
for i in range(2,n+1):
print(d[i]-d[1],end=" ")
sys.stdout.flush()
``` | -1 |
|
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,556,803,691 | 1,691 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | N, K = map(int, input().split())
L = [0] * 60
L[0] = 1
for i in range(1, 60):
L[i] = 2 * L[i - 1] + 1
def calc(n, k):
if k == L[n] // 2:
return n + 1
elif k > L[n] // 2:
return calc(n - 1, k - L[n] // 2)
else:
return calc(n - 1, k)
print(calc(N - 1, 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())
L = [0] * 60
L[0] = 1
for i in range(1, 60):
L[i] = 2 * L[i - 1] + 1
def calc(n, k):
if k == L[n] // 2:
return n + 1
elif k > L[n] // 2:
return calc(n - 1, k - L[n] // 2)
else:
return calc(n - 1, k)
print(calc(N - 1, K - 1))
``` | 0 |
|
985 | C | Liebig's Barrels | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it.
You want to assemble exactly *n* barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed *l*, i.e. |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above. | The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109).
The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves. | Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*. | [
"4 2 1\n2 2 1 2 3 2 2 3\n",
"2 1 0\n10 10\n",
"1 2 1\n5 2\n",
"3 2 1\n1 2 3 4 5 6\n"
] | [
"7\n",
"20\n",
"2\n",
"0\n"
] | In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough. | 0 | [
{
"input": "4 2 1\n2 2 1 2 3 2 2 3",
"output": "7"
},
{
"input": "2 1 0\n10 10",
"output": "20"
},
{
"input": "1 2 1\n5 2",
"output": "2"
},
{
"input": "3 2 1\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "10 3 189\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 447 89 983 964 716 32 890 267 164 654 71",
"output": "0"
},
{
"input": "10 3 453\n277 706 727 812 692 686 196 507 911 40 498 704 573 381 463 759 704 381 693 640 326 405 47 834 962 521 463 740 520 494",
"output": "2979"
},
{
"input": "10 3 795\n398 962 417 307 760 534 536 450 421 280 608 111 687 726 941 903 630 900 555 403 795 122 814 188 234 976 679 539 525 104",
"output": "5045"
},
{
"input": "6 2 29\n1 2 3 3 4 5 5 6 7 7 8 9",
"output": "28"
},
{
"input": "2 1 2\n1 2",
"output": "3"
}
] | 1,526,986,110 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 155 | 7,782,400 | a=list(map(int,input().split()))
n=a[0]
k=a[1]
l=a[2]
m=n*k
s=list(map(int,input().split()))
flag=m
s.sort()
for i in range(m):
if s[i]-s[0]>l:
flag=i
break
if flag==n-1:
print("0")
else:
b=flag-n+1
sum=0
t=0
for i in range(0,b,k):
sum=sum+s[i]
t=t+1
i=flag-1
while i>=0:
if t==n:
break
sum+=s[i]
i-=1
t+=1
print(sum)
| Title: Liebig's Barrels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it.
You want to assemble exactly *n* barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed *l*, i.e. |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input Specification:
The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109).
The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves.
Output Specification:
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
Demo Input:
['4 2 1\n2 2 1 2 3 2 2 3\n', '2 1 0\n10 10\n', '1 2 1\n5 2\n', '3 2 1\n1 2 3 4 5 6\n']
Demo Output:
['7\n', '20\n', '2\n', '0\n']
Note:
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough. | ```python
a=list(map(int,input().split()))
n=a[0]
k=a[1]
l=a[2]
m=n*k
s=list(map(int,input().split()))
flag=m
s.sort()
for i in range(m):
if s[i]-s[0]>l:
flag=i
break
if flag==n-1:
print("0")
else:
b=flag-n+1
sum=0
t=0
for i in range(0,b,k):
sum=sum+s[i]
t=t+1
i=flag-1
while i>=0:
if t==n:
break
sum+=s[i]
i-=1
t+=1
print(sum)
``` | 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,563,261,273 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 140 | 1,536,000 | class CodeforcesTask408ASolution:
def __init__(self):
self.result = ''
self.cash_count = 0
self.client_cashwise = []
self.baskets = []
def read_input(self):
self.cash_count = int(input())
self.client_cashwise = [int(x) for x in input().split(" ")]
for x in range(self.cash_count):
self.baskets.append([int(x) for x in input().split(" ")])
def process_task(self):
times = [len(x) * 15 + 5 * sum(x) for x in self.baskets]
self.result = str(min(times))
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask408ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
| 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
class CodeforcesTask408ASolution:
def __init__(self):
self.result = ''
self.cash_count = 0
self.client_cashwise = []
self.baskets = []
def read_input(self):
self.cash_count = int(input())
self.client_cashwise = [int(x) for x in input().split(" ")]
for x in range(self.cash_count):
self.baskets.append([int(x) for x in input().split(" ")])
def process_task(self):
times = [len(x) * 15 + 5 * sum(x) for x in self.baskets]
self.result = str(min(times))
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask408ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
``` | 3 |
|
347 | B | Fixed Points | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points.
You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | [
"5\n0 1 3 4 2\n"
] | [
"3\n"
] | none | 1,000 | [
{
"input": "5\n0 1 3 4 2",
"output": "3"
},
{
"input": "10\n6 9 4 7 8 2 3 5 0 1",
"output": "2"
},
{
"input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18 96 35 13 91 2 3 0 23 1 7 49 75 81 33 50 52 63 44 69 36 17 61 24 20 68 34 73 29 70 83 58 79 82 28 77 67",
"output": "3"
},
{
"input": "3\n0 1 2",
"output": "3"
},
{
"input": "3\n2 1 0",
"output": "3"
},
{
"input": "3\n1 2 0",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 1 2 3 4",
"output": "5"
},
{
"input": "4\n0 1 2 3",
"output": "4"
},
{
"input": "7\n0 1 2 4 3 6 5",
"output": "5"
},
{
"input": "6\n0 1 2 3 5 4",
"output": "6"
}
] | 1,691,671,297 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 13,107,200 | n = int(input())
list = list(map(int, input().split()))
c=0
u=False
for i in range(len(list)):
if list[i]!=(i) and u==False:
f=list.index(i)
if list[i]==f:
c+=2
u=True
elif list[i]==i :
c+=1
if c==len(list):
print(c)
else:
if u==False :
print(c+1)
else:
print(c)
| Title: Fixed Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points.
You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation.
Output Specification:
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
Demo Input:
['5\n0 1 3 4 2\n']
Demo Output:
['3\n']
Note:
none | ```python
n = int(input())
list = list(map(int, input().split()))
c=0
u=False
for i in range(len(list)):
if list[i]!=(i) and u==False:
f=list.index(i)
if list[i]==f:
c+=2
u=True
elif list[i]==i :
c+=1
if c==len(list):
print(c)
else:
if u==False :
print(c+1)
else:
print(c)
``` | 0 |
|
645 | A | Amity Assessment | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:
In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed. | The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position. | Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes). | [
"AB\nXC\nXB\nAC\n",
"AB\nXC\nAC\nBX\n"
] | [
"YES\n",
"NO\n"
] | The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all... | 500 | [
{
"input": "AB\nXC\nXB\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nAC\nBX",
"output": "NO"
},
{
"input": "XC\nBA\nCB\nAX",
"output": "NO"
},
{
"input": "AB\nXC\nAX\nCB",
"output": "YES"
},
{
"input": "CB\nAX\nXA\nBC",
"output": "YES"
},
{
"input": "BC\nXA\nBA\nXC",
"output": "NO"
},
{
"input": "CA\nXB\nBA\nCX",
"output": "NO"
},
{
"input": "CA\nXB\nAC\nBX",
"output": "NO"
},
{
"input": "CB\nAX\nCX\nAB",
"output": "YES"
},
{
"input": "AX\nCB\nBC\nXA",
"output": "YES"
},
{
"input": "CA\nXB\nBA\nXC",
"output": "NO"
},
{
"input": "CX\nAB\nAX\nCB",
"output": "NO"
},
{
"input": "AB\nXC\nAB\nCX",
"output": "YES"
},
{
"input": "XC\nBA\nXC\nAB",
"output": "NO"
},
{
"input": "BA\nXC\nAC\nXB",
"output": "YES"
},
{
"input": "AX\nBC\nAC\nBX",
"output": "YES"
},
{
"input": "XC\nBA\nCB\nXA",
"output": "NO"
},
{
"input": "CB\nAX\nXC\nBA",
"output": "NO"
},
{
"input": "AX\nCB\nBC\nAX",
"output": "YES"
},
{
"input": "AB\nXC\nBX\nAC",
"output": "YES"
},
{
"input": "XA\nCB\nBA\nCX",
"output": "NO"
},
{
"input": "CX\nBA\nBX\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nXC\nAB",
"output": "NO"
},
{
"input": "BA\nCX\nAC\nBX",
"output": "YES"
},
{
"input": "XA\nCB\nAB\nXC",
"output": "YES"
},
{
"input": "XC\nBA\nAC\nBX",
"output": "NO"
},
{
"input": "CA\nBX\nBA\nXC",
"output": "NO"
},
{
"input": "AX\nBC\nCA\nXB",
"output": "NO"
},
{
"input": "BC\nAX\nXC\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nBX\nAC",
"output": "YES"
},
{
"input": "CX\nBA\nAX\nBC",
"output": "NO"
},
{
"input": "XB\nCA\nXC\nBA",
"output": "NO"
},
{
"input": "BX\nCA\nXB\nCA",
"output": "YES"
},
{
"input": "XB\nAC\nXC\nAB",
"output": "NO"
},
{
"input": "CX\nBA\nCX\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nCA\nBX",
"output": "YES"
},
{
"input": "BA\nXC\nBC\nAX",
"output": "NO"
},
{
"input": "AC\nXB\nCX\nBA",
"output": "NO"
},
{
"input": "XB\nCA\nCX\nBA",
"output": "NO"
},
{
"input": "AB\nCX\nXA\nBC",
"output": "NO"
},
{
"input": "CX\nAB\nXB\nAC",
"output": "NO"
},
{
"input": "BC\nAX\nAC\nBX",
"output": "NO"
},
{
"input": "XA\nBC\nCB\nAX",
"output": "YES"
},
{
"input": "XC\nAB\nCB\nAX",
"output": "YES"
},
{
"input": "CX\nBA\nCX\nAB",
"output": "NO"
},
{
"input": "CA\nBX\nXC\nBA",
"output": "YES"
},
{
"input": "CX\nBA\nBA\nXC",
"output": "NO"
},
{
"input": "CA\nBX\nCB\nXA",
"output": "NO"
},
{
"input": "CB\nAX\nBC\nAX",
"output": "NO"
},
{
"input": "CB\nAX\nBC\nXA",
"output": "NO"
},
{
"input": "AC\nXB\nCB\nXA",
"output": "YES"
},
{
"input": "AB\nCX\nXB\nAC",
"output": "YES"
},
{
"input": "CX\nBA\nXB\nAC",
"output": "YES"
},
{
"input": "BX\nAC\nAB\nXC",
"output": "YES"
},
{
"input": "CX\nAB\nXC\nBA",
"output": "NO"
},
{
"input": "XB\nAC\nCX\nAB",
"output": "NO"
},
{
"input": "CB\nAX\nXB\nAC",
"output": "NO"
},
{
"input": "CB\nAX\nCA\nXB",
"output": "NO"
},
{
"input": "XC\nBA\nBA\nXC",
"output": "NO"
},
{
"input": "AC\nBX\nCB\nAX",
"output": "YES"
},
{
"input": "CA\nBX\nAC\nXB",
"output": "NO"
},
{
"input": "BX\nAC\nCX\nBA",
"output": "YES"
},
{
"input": "XB\nCA\nAX\nCB",
"output": "NO"
},
{
"input": "CB\nXA\nBC\nXA",
"output": "NO"
},
{
"input": "AX\nCB\nCX\nAB",
"output": "NO"
},
{
"input": "BC\nAX\nXC\nAB",
"output": "NO"
},
{
"input": "XB\nCA\nBC\nXA",
"output": "NO"
},
{
"input": "XB\nAC\nCX\nBA",
"output": "YES"
},
{
"input": "BC\nXA\nCB\nXA",
"output": "NO"
},
{
"input": "AX\nCB\nAX\nBC",
"output": "NO"
},
{
"input": "CA\nBX\nBX\nCA",
"output": "NO"
},
{
"input": "BA\nXC\nXB\nAC",
"output": "NO"
},
{
"input": "XA\nBC\nBX\nAC",
"output": "NO"
},
{
"input": "BX\nCA\nAC\nBX",
"output": "YES"
},
{
"input": "XB\nAC\nXC\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nAB\nXC",
"output": "YES"
},
{
"input": "BA\nCX\nCX\nBA",
"output": "NO"
},
{
"input": "CA\nXB\nXB\nCA",
"output": "NO"
},
{
"input": "BA\nCX\nBA\nXC",
"output": "YES"
},
{
"input": "BA\nCX\nAB\nCX",
"output": "NO"
},
{
"input": "BX\nCA\nXA\nBC",
"output": "YES"
},
{
"input": "XC\nBA\nBX\nCA",
"output": "NO"
},
{
"input": "XC\nAB\nBC\nXA",
"output": "NO"
},
{
"input": "BC\nXA\nXC\nAB",
"output": "NO"
},
{
"input": "BX\nCA\nXB\nAC",
"output": "NO"
},
{
"input": "BA\nXC\nCA\nXB",
"output": "NO"
},
{
"input": "CX\nBA\nAC\nXB",
"output": "NO"
},
{
"input": "AB\nCX\nAC\nBX",
"output": "NO"
},
{
"input": "BC\nXA\nBX\nCA",
"output": "NO"
},
{
"input": "XA\nBC\nCX\nAB",
"output": "YES"
},
{
"input": "AX\nBC\nAX\nCB",
"output": "NO"
},
{
"input": "CB\nAX\nCA\nBX",
"output": "NO"
},
{
"input": "CB\nAX\nBA\nXC",
"output": "YES"
},
{
"input": "AB\nCX\nXC\nBA",
"output": "YES"
},
{
"input": "AC\nXB\nBA\nCX",
"output": "YES"
},
{
"input": "AX\nCB\nCB\nAX",
"output": "NO"
},
{
"input": "CX\nBA\nCA\nXB",
"output": "YES"
},
{
"input": "AC\nBX\nAB\nXC",
"output": "NO"
},
{
"input": "XA\nCB\nXA\nBC",
"output": "NO"
},
{
"input": "XC\nBA\nCA\nBX",
"output": "YES"
},
{
"input": "XA\nBC\nXB\nCA",
"output": "YES"
},
{
"input": "CA\nBX\nCB\nAX",
"output": "NO"
}
] | 1,636,754,218 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 61 | 28,364,800 | def solve(s):
tem = ''
for j in range(4):
ix = (i + j) % 4
if s[ix] != 'X':
tem += s[ix]
if tem in mem:
exit(print('YES'))
mem[tem] = True
a, b, mem = input() + input()[::-1], input() + input()[::-1], dict()
for i in range(4):
solve(a)
solve(b)
print('NO')
| Title: Amity Assessment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:
In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.
Input Specification:
The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.
Output Specification:
Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).
Demo Input:
['AB\nXC\nXB\nAC\n', 'AB\nXC\nAC\nBX\n']
Demo Output:
['YES\n', 'NO\n']
Note:
The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all... | ```python
def solve(s):
tem = ''
for j in range(4):
ix = (i + j) % 4
if s[ix] != 'X':
tem += s[ix]
if tem in mem:
exit(print('YES'))
mem[tem] = True
a, b, mem = input() + input()[::-1], input() + input()[::-1], dict()
for i in range(4):
solve(a)
solve(b)
print('NO')
``` | 0 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,608,460,061 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = input()
m = input()
for i in range(len(m)):
if int(m) ^ int(n):
print("1",end="")
else:
print("0",end="") | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
n = input()
m = input()
for i in range(len(m)):
if int(m) ^ int(n):
print("1",end="")
else:
print("0",end="")
``` | 0 |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,647,143,270 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | """
sumOfFinger=sum(fingerShownByFriends)
Dima can show 1 to 5 fingers..
so
k = [sumOfFingers+i for i in range(1,6)]
now we've to check if k[i] prsenet in arithmetic progression whose firstVal=1 and diff=numOfFriens+1
if k[i] is present==
=>>then it means if Dima shows i+1 fingers then..
=>>then counting will end on Dima & hence he'll have to clean the place
"""
def willCountingEndOnDima(n,d):
#check if n is part of arithmetic progression with firstElement=a=1 and diff=d
a=1
return (n-a)%d==0
noOfFriends=int(input())
frndsFingers=list(map(int,input().split(" ")))
sumOfFinger=sum(frndsFingers)
noOfWays=5
for fingerShownByDima in range(1,6):
if willCountingEndOnDima(sumOfFinger+fingerShownByDima, noOfFriends+1):
noOfWays-=1
print(noOfWays) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
"""
sumOfFinger=sum(fingerShownByFriends)
Dima can show 1 to 5 fingers..
so
k = [sumOfFingers+i for i in range(1,6)]
now we've to check if k[i] prsenet in arithmetic progression whose firstVal=1 and diff=numOfFriens+1
if k[i] is present==
=>>then it means if Dima shows i+1 fingers then..
=>>then counting will end on Dima & hence he'll have to clean the place
"""
def willCountingEndOnDima(n,d):
#check if n is part of arithmetic progression with firstElement=a=1 and diff=d
a=1
return (n-a)%d==0
noOfFriends=int(input())
frndsFingers=list(map(int,input().split(" ")))
sumOfFinger=sum(frndsFingers)
noOfWays=5
for fingerShownByDima in range(1,6):
if willCountingEndOnDima(sumOfFinger+fingerShownByDima, noOfFriends+1):
noOfWays-=1
print(noOfWays)
``` | 3 |
|
362 | B | Petya and Staircases | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once.
One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order). | Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". | [
"10 5\n2 4 8 3 6\n",
"10 5\n2 4 5 7 9\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "10 5\n2 4 8 3 6",
"output": "NO"
},
{
"input": "10 5\n2 4 5 7 9",
"output": "YES"
},
{
"input": "10 9\n2 3 4 5 6 7 8 9 10",
"output": "NO"
},
{
"input": "5 2\n4 5",
"output": "NO"
},
{
"input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37",
"output": "YES"
},
{
"input": "10 10\n7 6 4 2 5 10 8 3 9 1",
"output": "NO"
},
{
"input": "12312 0",
"output": "YES"
},
{
"input": "9817239 1\n6323187",
"output": "YES"
},
{
"input": "1 1\n1",
"output": "NO"
},
{
"input": "5 4\n4 2 5 1",
"output": "NO"
},
{
"input": "5 3\n4 3 5",
"output": "NO"
},
{
"input": "500 3\n18 62 445",
"output": "YES"
},
{
"input": "500 50\n72 474 467 241 442 437 336 234 410 120 438 164 405 177 142 114 27 20 445 235 46 176 88 488 242 391 28 414 145 92 206 334 152 343 367 254 100 243 155 348 148 450 461 483 97 34 471 69 416 362",
"output": "NO"
},
{
"input": "500 8\n365 313 338 410 482 417 325 384",
"output": "YES"
},
{
"input": "1000000000 10\n2 3 5 6 8 9 123 874 1230 1000000000",
"output": "NO"
},
{
"input": "1000000000 10\n1 2 3 5 6 8 9 123 874 1230",
"output": "NO"
},
{
"input": "10 1\n1",
"output": "NO"
},
{
"input": "10 4\n1 2 4 5",
"output": "NO"
},
{
"input": "50 20\n22 33 17 23 27 5 26 31 41 20 8 24 6 3 4 29 40 25 13 16",
"output": "NO"
},
{
"input": "50 40\n14 27 19 30 31 20 28 11 37 29 23 33 7 26 22 16 1 6 18 3 47 36 38 2 48 9 41 8 5 50 4 45 44 25 39 12 43 42 40 46",
"output": "NO"
},
{
"input": "123 12\n35 95 47 99 79 122 58 94 31 57 18 10",
"output": "YES"
},
{
"input": "10 5\n1 3 5 7 9",
"output": "NO"
},
{
"input": "100 7\n2 3 5 6 8 9 100",
"output": "NO"
},
{
"input": "100 3\n98 99 100",
"output": "NO"
},
{
"input": "100 3\n97 98 99",
"output": "NO"
},
{
"input": "100 3\n96 98 99",
"output": "YES"
},
{
"input": "10 6\n2 3 5 6 8 9",
"output": "YES"
},
{
"input": "1000000000 10\n2 4 10 18 40 42 49 58 59 60",
"output": "NO"
},
{
"input": "10 3\n1 4 6",
"output": "NO"
},
{
"input": "8 3\n2 3 4",
"output": "NO"
},
{
"input": "100 3\n4 5 6",
"output": "NO"
},
{
"input": "10 2\n10 1",
"output": "NO"
},
{
"input": "10 1\n10",
"output": "NO"
},
{
"input": "4 2\n2 3",
"output": "YES"
},
{
"input": "2 1\n1",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "4 3\n2 3 4",
"output": "NO"
},
{
"input": "5 3\n4 2 3",
"output": "NO"
}
] | 1,569,062,662 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | class CodeforcesTask362BSolution:
def __init__(self):
self.result = ''
self.n_m = []
self.dirty = []
def read_input(self):
self.n_m = [int(x) for x in input().split(" ")]
self.dirty = [int(x) for x in input().split(" ")]
def process_task(self):
dirty = {}
for d in self.dirty:
dirty[d] = True
can_ = True
for d in self.dirty:
if d - 1 in dirty and d + 1 in dirty:
can_ = False
break
self.result = "YES" if can_ else "NO"
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask362BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
| Title: Petya and Staircases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once.
One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order).
Output Specification:
Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO".
Demo Input:
['10 5\n2 4 8 3 6\n', '10 5\n2 4 5 7 9\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
class CodeforcesTask362BSolution:
def __init__(self):
self.result = ''
self.n_m = []
self.dirty = []
def read_input(self):
self.n_m = [int(x) for x in input().split(" ")]
self.dirty = [int(x) for x in input().split(" ")]
def process_task(self):
dirty = {}
for d in self.dirty:
dirty[d] = True
can_ = True
for d in self.dirty:
if d - 1 in dirty and d + 1 in dirty:
can_ = False
break
self.result = "YES" if can_ else "NO"
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask362BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
``` | 0 |
|
701 | B | Cells Not Under Attack | PROGRAMMING | 1,200 | [
"data structures",
"math"
] | null | null | Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack.
You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=*min*(100<=000,<=*n*2)) — the size of the board and the number of rooks.
Each of the next *m* lines contains integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the number of the row and the number of the column where Vasya will put the *i*-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook. | Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put. | [
"3 3\n1 1\n3 1\n2 2\n",
"5 2\n1 5\n5 1\n",
"100000 1\n300 400\n"
] | [
"4 2 0 \n",
"16 9 \n",
"9999800001 \n"
] | On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack. | 750 | [
{
"input": "3 3\n1 1\n3 1\n2 2",
"output": "4 2 0 "
},
{
"input": "5 2\n1 5\n5 1",
"output": "16 9 "
},
{
"input": "100000 1\n300 400",
"output": "9999800001 "
},
{
"input": "10 4\n2 8\n1 8\n9 8\n6 9",
"output": "81 72 63 48 "
},
{
"input": "30 30\n3 13\n27 23\n18 24\n18 19\n14 20\n7 10\n27 13\n20 27\n11 1\n21 10\n2 9\n28 12\n29 19\n28 27\n27 29\n30 12\n27 2\n4 5\n8 19\n21 2\n24 27\n14 22\n20 3\n18 3\n23 9\n28 6\n15 12\n2 2\n16 27\n1 14",
"output": "841 784 729 702 650 600 600 552 506 484 441 400 380 380 361 342 324 289 272 272 255 240 225 225 210 196 182 182 168 143 "
},
{
"input": "70 31\n22 39\n33 43\n50 27\n70 9\n20 67\n61 24\n60 4\n60 28\n4 25\n30 29\n46 47\n51 48\n37 5\n14 29\n45 44\n68 35\n52 21\n7 37\n18 43\n44 22\n26 12\n39 37\n51 55\n50 23\n51 16\n16 49\n22 62\n35 45\n56 2\n20 51\n3 37",
"output": "4761 4624 4489 4356 4225 4096 3969 3906 3782 3660 3540 3422 3306 3249 3136 3025 2916 2809 2756 2652 2550 2499 2450 2401 2352 2256 2208 2115 2024 1978 1935 "
},
{
"input": "330 17\n259 262\n146 20\n235 69\n84 74\n131 267\n153 101\n32 232\n214 212\n239 157\n121 156\n10 45\n266 78\n52 258\n109 279\n193 276\n239 142\n321 89",
"output": "108241 107584 106929 106276 105625 104976 104329 103684 103041 102400 101761 101124 100489 99856 99225 98910 98282 "
},
{
"input": "500 43\n176 85\n460 171\n233 260\n73 397\n474 35\n290 422\n309 318\n280 415\n485 169\n106 22\n355 129\n180 301\n205 347\n197 93\n263 318\n336 382\n314 350\n476 214\n367 277\n333 166\n500 376\n236 17\n94 73\n116 204\n166 50\n168 218\n144 369\n340 91\n274 360\n171 360\n41 251\n262 478\n27 163\n151 491\n208 415\n448 386\n293 486\n371 479\n330 435\n220 374\n163 316\n155 158\n26 126",
"output": "249001 248004 247009 246016 245025 244036 243049 242064 241081 240100 239121 238144 237169 236196 235710 234740 233772 232806 231842 230880 229920 228962 228006 227052 226100 225150 224202 223256 222312 221840 220899 219960 219023 218088 217620 216688 215758 214830 213904 212980 212058 211138 210220 "
},
{
"input": "99999 1\n54016 16192",
"output": "9999600004 "
},
{
"input": "99991 9\n80814 65974\n12100 98787\n9390 76191\n5628 47659\n80075 25361\n75330 1630\n38758 99962\n33848 40352\n43732 52281",
"output": "9998000100 9997800121 9997600144 9997400169 9997200196 9997000225 9996800256 9996600289 9996400324 "
},
{
"input": "1 1\n1 1",
"output": "0 "
}
] | 1,626,838,620 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 405 | 15,052,800 | import sys
input = lambda:sys.stdin.readline()
int_arr = lambda: list(map(int,input().split()))
str_arr = lambda: list(map(str,input().split()))
get_str = lambda: map(str,input().split())
get_int = lambda: map(int,input().split())
get_flo = lambda: map(float,input().split())
mod = 1000000007
# def solve():
# pass
# while 1:
# print(100000)
n,r = get_int()
c = 0
a,b = set(),set()
for _ in range(r):
x,y = get_int()
a.add(x);b.add(y)
print((n-len(a))*(n-len(b)))
| Title: Cells Not Under Attack
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack.
You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=*min*(100<=000,<=*n*2)) — the size of the board and the number of rooks.
Each of the next *m* lines contains integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the number of the row and the number of the column where Vasya will put the *i*-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook.
Output Specification:
Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put.
Demo Input:
['3 3\n1 1\n3 1\n2 2\n', '5 2\n1 5\n5 1\n', '100000 1\n300 400\n']
Demo Output:
['4 2 0 \n', '16 9 \n', '9999800001 \n']
Note:
On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack. | ```python
import sys
input = lambda:sys.stdin.readline()
int_arr = lambda: list(map(int,input().split()))
str_arr = lambda: list(map(str,input().split()))
get_str = lambda: map(str,input().split())
get_int = lambda: map(int,input().split())
get_flo = lambda: map(float,input().split())
mod = 1000000007
# def solve():
# pass
# while 1:
# print(100000)
n,r = get_int()
c = 0
a,b = set(),set()
for _ in range(r):
x,y = get_int()
a.add(x);b.add(y)
print((n-len(a))*(n-len(b)))
``` | 3 |
|
215 | A | Bicycle Chain | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*) teeth, and the *j*-th star on the rear wheel axle has *b**j* (0<=<<=*b*1<=<<=*b*2<=<<=...<=<<=*b**m*) teeth. Any pair (*i*,<=*j*) (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (*i*,<=*j*) has a gear ratio, equal to the value .
Since Vasya likes integers, he wants to find such gears (*i*,<=*j*), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (*i*,<=*j*) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.
In the problem, fraction denotes division in real numbers, that is, no rounding is performed. | The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars on the rear wheel axle. The fourth line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=104) in the order of strict increasing.
It is guaranteed that there exists at least one gear (*i*,<=*j*), that its gear ratio is an integer. The numbers on the lines are separated by spaces. | Print the number of "integer" gears with the maximum ratio among all "integer" gears. | [
"2\n4 5\n3\n12 13 15\n",
"4\n1 2 3 4\n5\n10 11 12 13 14\n"
] | [
"2\n",
"1\n"
] | In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | 500 | [
{
"input": "2\n4 5\n3\n12 13 15",
"output": "2"
},
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14",
"output": "1"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 2\n1\n1",
"output": "1"
},
{
"input": "1\n1\n2\n1 2",
"output": "1"
},
{
"input": "4\n3 7 11 13\n4\n51 119 187 221",
"output": "4"
},
{
"input": "4\n2 3 4 5\n3\n1 2 3",
"output": "2"
},
{
"input": "10\n6 12 13 20 48 53 74 92 96 97\n10\n1 21 32 36 47 54 69 75 95 97",
"output": "1"
},
{
"input": "10\n5 9 10 14 15 17 19 22 24 26\n10\n2 11 17 19 21 22 24 25 27 28",
"output": "1"
},
{
"input": "10\n24 53 56 126 354 432 442 740 795 856\n10\n273 438 494 619 689 711 894 947 954 958",
"output": "1"
},
{
"input": "10\n3 4 6 7 8 10 14 16 19 20\n10\n3 4 5 7 8 10 15 16 18 20",
"output": "1"
},
{
"input": "10\n1 6 8 14 15 17 25 27 34 39\n10\n1 8 16 17 19 22 32 39 44 50",
"output": "1"
},
{
"input": "10\n5 21 22 23 25 32 35 36 38 39\n10\n3 7 8 9 18 21 23 24 36 38",
"output": "4"
},
{
"input": "50\n5 8 13 16 19 20 21 22 24 27 28 29 30 32 33 34 35 43 45 48 50 51 54 55 58 59 60 61 62 65 70 71 72 76 78 79 80 81 83 84 85 87 89 91 92 94 97 98 99 100\n50\n2 3 5 6 7 10 15 16 17 20 23 28 29 30 31 34 36 37 40 42 45 46 48 54 55 56 58 59 61 62 69 70 71 72 75 76 78 82 84 85 86 87 88 89 90 91 92 97 99 100",
"output": "1"
},
{
"input": "50\n3 5 6 8 9 11 13 19 21 23 24 32 34 35 42 50 51 52 56 58 59 69 70 72 73 75 76 77 78 80 83 88 90 95 96 100 101 102 108 109 113 119 124 135 138 141 142 143 145 150\n50\n5 8 10 11 18 19 23 30 35 43 51 53 55 58 63 68 69 71 77 78 79 82 83 86 88 89 91 92 93 94 96 102 103 105 109 110 113 114 116 123 124 126 127 132 133 135 136 137 142 149",
"output": "1"
},
{
"input": "50\n6 16 24 25 27 33 36 40 51 60 62 65 71 72 75 77 85 87 91 93 98 102 103 106 117 118 120 121 122 123 125 131 134 136 143 148 155 157 160 161 164 166 170 178 184 187 188 192 194 197\n50\n5 9 17 23 27 34 40 44 47 59 62 70 81 82 87 88 89 90 98 101 102 110 113 114 115 116 119 122 124 128 130 137 138 140 144 150 152 155 159 164 166 169 171 175 185 186 187 189 190 193",
"output": "1"
},
{
"input": "50\n14 22 23 31 32 35 48 63 76 79 88 97 101 102 103 104 106 113 114 115 116 126 136 138 145 152 155 156 162 170 172 173 179 180 182 203 208 210 212 222 226 229 231 232 235 237 245 246 247 248\n50\n2 5 6 16 28 44 45 46 54 55 56 63 72 80 87 93 94 96 97 100 101 103 132 135 140 160 164 165 167 168 173 180 182 185 186 192 194 198 199 202 203 211 213 216 217 227 232 233 236 245",
"output": "1"
},
{
"input": "50\n14 19 33 35 38 41 51 54 69 70 71 73 76 80 84 94 102 104 105 106 107 113 121 128 131 168 180 181 187 191 195 201 205 207 210 216 220 238 249 251 263 271 272 275 281 283 285 286 291 294\n50\n2 3 5 20 21 35 38 40 43 48 49 52 55 64 73 77 82 97 109 113 119 121 125 132 137 139 145 146 149 180 182 197 203 229 234 241 244 251 264 271 274 281 284 285 287 291 292 293 294 298",
"output": "1"
},
{
"input": "50\n2 4 5 16 18 19 22 23 25 26 34 44 48 54 67 79 80 84 92 110 116 133 138 154 163 171 174 202 205 218 228 229 234 245 247 249 250 263 270 272 274 275 277 283 289 310 312 334 339 342\n50\n1 5 17 18 25 37 46 47 48 59 67 75 80 83 84 107 115 122 137 141 159 162 175 180 184 204 221 224 240 243 247 248 249 258 259 260 264 266 269 271 274 293 294 306 329 330 334 335 342 350",
"output": "1"
},
{
"input": "50\n6 9 11 21 28 39 42 56 60 63 81 88 91 95 105 110 117 125 149 165 174 176 185 189 193 196 205 231 233 268 278 279 281 286 289 292 298 303 305 306 334 342 350 353 361 371 372 375 376 378\n50\n6 17 20 43 45 52 58 59 82 83 88 102 111 118 121 131 145 173 190 191 200 216 224 225 232 235 243 256 260 271 290 291 321 322 323 329 331 333 334 341 343 348 351 354 356 360 366 379 387 388",
"output": "1"
},
{
"input": "10\n17 239 443 467 661 1069 1823 2333 3767 4201\n20\n51 83 97 457 593 717 997 1329 1401 1459 1471 1983 2371 2539 3207 3251 3329 5469 6637 6999",
"output": "8"
},
{
"input": "20\n179 359 401 467 521 601 919 941 1103 1279 1709 1913 1949 2003 2099 2143 2179 2213 2399 4673\n20\n151 181 191 251 421 967 1109 1181 1249 1447 1471 1553 1619 2327 2551 2791 3049 3727 6071 7813",
"output": "3"
},
{
"input": "20\n79 113 151 709 809 983 1291 1399 1409 1429 2377 2659 2671 2897 3217 3511 3557 3797 3823 4363\n10\n19 101 659 797 1027 1963 2129 2971 3299 9217",
"output": "3"
},
{
"input": "30\n19 47 109 179 307 331 389 401 461 509 547 569 617 853 883 1249 1361 1381 1511 1723 1741 1783 2459 2531 2621 3533 3821 4091 5557 6217\n20\n401 443 563 941 967 997 1535 1567 1655 1747 1787 1945 1999 2251 2305 2543 2735 4415 6245 7555",
"output": "8"
},
{
"input": "30\n3 43 97 179 257 313 353 359 367 389 397 457 547 599 601 647 1013 1021 1063 1433 1481 1531 1669 3181 3373 3559 3769 4157 4549 5197\n50\n13 15 17 19 29 79 113 193 197 199 215 223 271 293 359 485 487 569 601 683 895 919 941 967 1283 1285 1289 1549 1565 1765 1795 1835 1907 1931 1945 1985 1993 2285 2731 2735 2995 3257 4049 4139 5105 5315 7165 7405 7655 8345",
"output": "20"
},
{
"input": "50\n11 17 23 53 59 109 137 149 173 251 353 379 419 421 439 503 593 607 661 773 821 877 941 997 1061 1117 1153 1229 1289 1297 1321 1609 1747 2311 2389 2543 2693 3041 3083 3137 3181 3209 3331 3373 3617 3767 4201 4409 4931 6379\n50\n55 59 67 73 85 89 101 115 211 263 295 353 545 599 607 685 739 745 997 1031 1255 1493 1523 1667 1709 1895 1949 2161 2195 2965 3019 3035 3305 3361 3373 3673 3739 3865 3881 4231 4253 4385 4985 5305 5585 5765 6145 6445 8045 8735",
"output": "23"
},
{
"input": "5\n33 78 146 3055 4268\n5\n2211 2584 5226 9402 9782",
"output": "3"
},
{
"input": "5\n35 48 52 86 8001\n10\n332 3430 3554 4704 4860 5096 6215 7583 8228 8428",
"output": "4"
},
{
"input": "10\n97 184 207 228 269 2084 4450 6396 7214 9457\n16\n338 1179 1284 1545 1570 2444 3167 3395 3397 5550 6440 7245 7804 7980 9415 9959",
"output": "5"
},
{
"input": "30\n25 30 41 57 58 62 70 72 76 79 84 85 88 91 98 101 104 109 119 129 136 139 148 151 926 1372 3093 3936 5423 7350\n25\n1600 1920 2624 3648 3712 3968 4480 4608 4864 5056 5376 5440 5632 5824 6272 6464 6656 6934 6976 7616 8256 8704 8896 9472 9664",
"output": "24"
},
{
"input": "5\n33 78 146 3055 4268\n5\n2211 2584 5226 9402 9782",
"output": "3"
},
{
"input": "5\n35 48 52 86 8001\n10\n332 3430 3554 4704 4860 5096 6215 7583 8228 8428",
"output": "4"
},
{
"input": "10\n97 184 207 228 269 2084 4450 6396 7214 9457\n16\n338 1179 1284 1545 1570 2444 3167 3395 3397 5550 6440 7245 7804 7980 9415 9959",
"output": "5"
},
{
"input": "30\n25 30 41 57 58 62 70 72 76 79 84 85 88 91 98 101 104 109 119 129 136 139 148 151 926 1372 3093 3936 5423 7350\n25\n1600 1920 2624 3648 3712 3968 4480 4608 4864 5056 5376 5440 5632 5824 6272 6464 6656 6934 6976 7616 8256 8704 8896 9472 9664",
"output": "24"
},
{
"input": "47\n66 262 357 457 513 530 538 540 592 691 707 979 1015 1242 1246 1667 1823 1886 1963 2133 2649 2679 2916 2949 3413 3523 3699 3958 4393 4922 5233 5306 5799 6036 6302 6629 7208 7282 7315 7822 7833 7927 8068 8150 8870 8962 9987\n39\n167 199 360 528 1515 1643 1986 1988 2154 2397 2856 3552 3656 3784 3980 4096 4104 4240 4320 4736 4951 5266 5656 5849 5850 6169 6517 6875 7244 7339 7689 7832 8120 8716 9503 9509 9933 9936 9968",
"output": "12"
},
{
"input": "1\n94\n50\n423 446 485 1214 1468 1507 1853 1930 1999 2258 2271 2285 2425 2543 2715 2743 2992 3196 4074 4108 4448 4475 4652 5057 5250 5312 5356 5375 5731 5986 6298 6501 6521 7146 7255 7276 7332 7481 7998 8141 8413 8665 8908 9221 9336 9491 9504 9677 9693 9706",
"output": "1"
},
{
"input": "50\n51 67 75 186 194 355 512 561 720 876 1077 1221 1503 1820 2153 2385 2568 2608 2937 2969 3271 3311 3481 4081 4093 4171 4255 4256 4829 5020 5192 5636 5817 6156 6712 6717 7153 7436 7608 7612 7866 7988 8264 8293 8867 9311 9879 9882 9889 9908\n1\n5394",
"output": "1"
},
{
"input": "50\n26 367 495 585 675 789 855 1185 1312 1606 2037 2241 2587 2612 2628 2807 2873 2924 3774 4067 4376 4668 4902 5001 5082 5100 5104 5209 5345 5515 5661 5777 5902 5907 6155 6323 6675 6791 7503 8159 8207 8254 8740 8848 8855 8933 9069 9164 9171 9586\n5\n1557 6246 7545 8074 8284",
"output": "1"
},
{
"input": "5\n25 58 91 110 2658\n50\n21 372 909 1172 1517 1554 1797 1802 1843 1977 2006 2025 2137 2225 2317 2507 2645 2754 2919 3024 3202 3212 3267 3852 4374 4487 4553 4668 4883 4911 4916 5016 5021 5068 5104 5162 5683 5856 6374 6871 7333 7531 8099 8135 8173 8215 8462 8776 9433 9790",
"output": "4"
},
{
"input": "45\n37 48 56 59 69 70 79 83 85 86 99 114 131 134 135 145 156 250 1739 1947 2116 2315 2449 3104 3666 4008 4406 4723 4829 5345 5836 6262 6296 6870 7065 7110 7130 7510 7595 8092 8442 8574 9032 9091 9355\n50\n343 846 893 1110 1651 1837 2162 2331 2596 3012 3024 3131 3294 3394 3528 3717 3997 4125 4347 4410 4581 4977 5030 5070 5119 5229 5355 5413 5418 5474 5763 5940 6151 6161 6164 6237 6506 6519 6783 7182 7413 7534 8069 8253 8442 8505 9135 9308 9828 9902",
"output": "17"
},
{
"input": "50\n17 20 22 28 36 38 46 47 48 50 52 57 58 62 63 69 70 74 75 78 79 81 82 86 87 90 93 95 103 202 292 442 1756 1769 2208 2311 2799 2957 3483 4280 4324 4932 5109 5204 6225 6354 6561 7136 8754 9670\n40\n68 214 957 1649 1940 2078 2134 2716 3492 3686 4462 4559 4656 4756 4850 5044 5490 5529 5592 5626 6014 6111 6693 6790 7178 7275 7566 7663 7702 7857 7954 8342 8511 8730 8957 9021 9215 9377 9445 9991",
"output": "28"
},
{
"input": "39\n10 13 21 25 36 38 47 48 58 64 68 69 73 79 86 972 2012 2215 2267 2503 3717 3945 4197 4800 5266 6169 6612 6824 7023 7322 7582 7766 8381 8626 8879 9079 9088 9838 9968\n50\n432 877 970 1152 1202 1223 1261 1435 1454 1578 1843 1907 2003 2037 2183 2195 2215 2425 3065 3492 3615 3637 3686 3946 4189 4415 4559 4656 4665 4707 4886 4887 5626 5703 5955 6208 6521 6581 6596 6693 6985 7013 7081 7343 7663 8332 8342 8637 9207 9862",
"output": "15"
},
{
"input": "50\n7 144 269 339 395 505 625 688 709 950 1102 1152 1350 1381 1641 1830 1977 1999 2093 2180 2718 3308 3574 4168 4232 4259 4393 4689 4982 5154 5476 5581 5635 5721 6159 6302 6741 7010 7152 7315 7417 7482 8116 8239 8640 9347 9395 9614 9661 9822\n20\n84 162 292 1728 1866 2088 3228 3470 4068 5318 5470 6060 6380 6929 7500 8256 8399 8467 8508 9691",
"output": "8"
},
{
"input": "50\n159 880 1070 1139 1358 1608 1691 1841 2073 2171 2213 2597 2692 2759 2879 2931 3173 3217 3441 4201 4878 5106 5129 5253 5395 5647 5968 6019 6130 6276 6286 6330 6409 6728 7488 7713 7765 7828 7899 8064 8264 8457 8483 8685 8900 8946 8965 9133 9187 9638\n45\n57 159 1070 1139 1391 1608 1691 1841 2171 2213 2692 2759 2931 3173 3217 3441 4201 4878 5106 5129 5253 5647 5968 6130 6276 6286 6409 7488 7694 7713 7765 7828 7899 8003 8064 8081 8244 8264 8685 8900 8946 8965 9133 9638 9673",
"output": "38"
},
{
"input": "3\n3 4 5\n3\n6 20 25",
"output": "2"
},
{
"input": "4\n2 3 5 8\n4\n2 6 8 10",
"output": "1"
},
{
"input": "4\n3 5 7 11\n4\n3 5 7 22",
"output": "1"
},
{
"input": "2\n2 3\n3\n20 30 50",
"output": "1"
},
{
"input": "3\n1 2 3\n4\n2 4 6 49",
"output": "1"
},
{
"input": "2\n4 5\n3\n12 15 20",
"output": "1"
},
{
"input": "3\n2 5 7\n3\n4 5 7",
"output": "1"
},
{
"input": "3\n3 5 8\n3\n6 8 10",
"output": "2"
},
{
"input": "2\n2 3\n4\n4 6 9 33",
"output": "1"
},
{
"input": "2\n2 3\n4\n4 6 21 40",
"output": "1"
},
{
"input": "3\n4 9 10\n3\n8 9 10",
"output": "1"
},
{
"input": "5\n1 5 6 9 51\n5\n5 12 18 27 10000",
"output": "1"
},
{
"input": "13\n1 2 3 4 5 6 7 8 9 10 11 12 13\n1\n14",
"output": "1"
}
] | 1,697,016,053 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | n = int(input())
a = list(map(int,input().split()))
t = int(input())
s = list(map(int,input().split()))
maxi = max(s)//min(a)
c = set()
for i in range(n) :
for j in range(t) :
if s[j]/a[i] == maxi :
c.add((s[j],a[i]))
print(len(c)) | Title: Bicycle Chain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*) teeth, and the *j*-th star on the rear wheel axle has *b**j* (0<=<<=*b*1<=<<=*b*2<=<<=...<=<<=*b**m*) teeth. Any pair (*i*,<=*j*) (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (*i*,<=*j*) has a gear ratio, equal to the value .
Since Vasya likes integers, he wants to find such gears (*i*,<=*j*), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (*i*,<=*j*) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.
In the problem, fraction denotes division in real numbers, that is, no rounding is performed.
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars on the rear wheel axle. The fourth line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=104) in the order of strict increasing.
It is guaranteed that there exists at least one gear (*i*,<=*j*), that its gear ratio is an integer. The numbers on the lines are separated by spaces.
Output Specification:
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
Demo Input:
['2\n4 5\n3\n12 13 15\n', '4\n1 2 3 4\n5\n10 11 12 13 14\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | ```python
n = int(input())
a = list(map(int,input().split()))
t = int(input())
s = list(map(int,input().split()))
maxi = max(s)//min(a)
c = set()
for i in range(n) :
for j in range(t) :
if s[j]/a[i] == maxi :
c.add((s[j],a[i]))
print(len(c))
``` | 0 |
|
296 | B | Yaroslav and Two Strings | PROGRAMMING | 2,000 | [
"combinatorics",
"dp"
] | null | null | Yaroslav thinks that two strings *s* and *w*, consisting of digits and having length *n* are non-comparable if there are two numbers, *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*n*), such that *s**i*<=><=*w**i* and *s**j*<=<<=*w**j*. Here sign *s**i* represents the *i*-th digit of string *s*, similarly, *w**j* represents the *j*-th digit of string *w*.
A string's template is a string that consists of digits and question marks ("?").
Yaroslav has two string templates, each of them has length *n*. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers.
Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109<=+<=7). | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals *n*. The third line contains the second template in the same format. | In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109<=+<=7). | [
"2\n90\n09\n",
"2\n11\n55\n",
"5\n?????\n?????\n"
] | [
"1\n",
"0\n",
"993531194\n"
] | The first test contains no question marks and both strings are incomparable, so the answer is 1.
The second test has no question marks, but the given strings are comparable, so the answer is 0. | 1,500 | [
{
"input": "2\n90\n09",
"output": "1"
},
{
"input": "2\n11\n55",
"output": "0"
},
{
"input": "5\n?????\n?????",
"output": "993531194"
},
{
"input": "10\n104?3?1??3\n?1755?1??7",
"output": "91015750"
},
{
"input": "10\n6276405116\n6787?352?9",
"output": "46"
},
{
"input": "10\n0844033584\n0031021311",
"output": "0"
},
{
"input": "10\n???0?19?01\n957461????",
"output": "983368000"
},
{
"input": "10\n8703870339\n994987934?",
"output": "9"
},
{
"input": "10\n?8?528?91?\n45??06???1",
"output": "980398000"
},
{
"input": "10\n8030456630\n83406?6890",
"output": "5"
},
{
"input": "1\n?\n?",
"output": "0"
},
{
"input": "2\n12\n?9",
"output": "1"
},
{
"input": "3\n??1\n?12",
"output": "890"
},
{
"input": "3\n?12\n??1",
"output": "890"
},
{
"input": "5\n??15?\n?32??",
"output": "939500"
},
{
"input": "5\n??25?\n?32??",
"output": "812550"
},
{
"input": "5\n??55?\n?32??",
"output": "872950"
},
{
"input": "5\n?32??\n??55?",
"output": "872950"
}
] | 1,578,672,272 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 218 | 307,200 | mod = 1000000007
n = int(input())
s1 = input()
s2 = input()
ans = 1
tc = 1
for i in range(n):
if s1[i] == '?':
ans *= 10
ans %= mod
if s2[i] == '?':
ans *= 10
ans %= mod
for i in range(n):
if s1[i] != '?' and s2[i] != '?' and s1[i] > s2[i]:
break
if s1[i] == '?' and s2[i] == '?':
tc *= 55
tc %= mod
if s1[i] == '?' and s2[i] != '?':
tc = tc * (int(s2[i]) + 1)
tc %= mod
if i == n - 1:
ans -= tc
ans = (ans + mod) % mod
tc = 1
for i in range(n):
if s1[i] != '?' and s2[i] != '?' and s2[i] > s1[i]:
break;
if s1[i] == '?' and s2[i] == '?':
tc *= 55
tc %= mod
if s1[i] != '?' and s2[i] == '?':
tc = tc * (int(s1[i]) + 1)
tc %= mod
if s1[i] == '?' and s2[i] != '?':
tc = tc * (10 - s2[i])
tc %= mod
if i == n - 1:
ans -= tc
ans = (ans + mod) % mod
tc = 1
for i in range(n):
if s1[i] != '?' and s2[i] != '?' and s1[i] != s2[i]:
break
if s1[i] == '?' and s2[i] == '?':
tc *= 10
tc %= mod
if i == n - 1:
ans += tc
ans = (ans + mod) % mod
print(ans)
| Title: Yaroslav and Two Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav thinks that two strings *s* and *w*, consisting of digits and having length *n* are non-comparable if there are two numbers, *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*n*), such that *s**i*<=><=*w**i* and *s**j*<=<<=*w**j*. Here sign *s**i* represents the *i*-th digit of string *s*, similarly, *w**j* represents the *j*-th digit of string *w*.
A string's template is a string that consists of digits and question marks ("?").
Yaroslav has two string templates, each of them has length *n*. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers.
Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109<=+<=7).
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals *n*. The third line contains the second template in the same format.
Output Specification:
In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109<=+<=7).
Demo Input:
['2\n90\n09\n', '2\n11\n55\n', '5\n?????\n?????\n']
Demo Output:
['1\n', '0\n', '993531194\n']
Note:
The first test contains no question marks and both strings are incomparable, so the answer is 1.
The second test has no question marks, but the given strings are comparable, so the answer is 0. | ```python
mod = 1000000007
n = int(input())
s1 = input()
s2 = input()
ans = 1
tc = 1
for i in range(n):
if s1[i] == '?':
ans *= 10
ans %= mod
if s2[i] == '?':
ans *= 10
ans %= mod
for i in range(n):
if s1[i] != '?' and s2[i] != '?' and s1[i] > s2[i]:
break
if s1[i] == '?' and s2[i] == '?':
tc *= 55
tc %= mod
if s1[i] == '?' and s2[i] != '?':
tc = tc * (int(s2[i]) + 1)
tc %= mod
if i == n - 1:
ans -= tc
ans = (ans + mod) % mod
tc = 1
for i in range(n):
if s1[i] != '?' and s2[i] != '?' and s2[i] > s1[i]:
break;
if s1[i] == '?' and s2[i] == '?':
tc *= 55
tc %= mod
if s1[i] != '?' and s2[i] == '?':
tc = tc * (int(s1[i]) + 1)
tc %= mod
if s1[i] == '?' and s2[i] != '?':
tc = tc * (10 - s2[i])
tc %= mod
if i == n - 1:
ans -= tc
ans = (ans + mod) % mod
tc = 1
for i in range(n):
if s1[i] != '?' and s2[i] != '?' and s1[i] != s2[i]:
break
if s1[i] == '?' and s2[i] == '?':
tc *= 10
tc %= mod
if i == n - 1:
ans += tc
ans = (ans + mod) % mod
print(ans)
``` | 0 |
|
981 | C | Useful Decomposition | PROGRAMMING | 1,400 | [
"implementation",
"trees"
] | null | null | Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths have at least one common vertex. Each edge of the tree should be in exactly one path.
Help Remesses, find such a decomposition of the tree or derermine that there is no such decomposition. | The first line contains a single integer $n$ ($2 \leq n \leq 10^{5}$) the number of nodes in the tree.
Each of the next $n<=-<=1$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$) — the edges of the tree. It is guaranteed that the given edges form a tree. | If there are no decompositions, print the only line containing "No".
Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m$.
Each of the next $m$ lines should contain two integers $u_i$, $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) denoting that one of the paths in the decomposition is the simple path between nodes $u_i$ and $v_i$.
Each pair of paths in the decomposition should have at least one common vertex, and each edge of the tree should be presented in exactly one path. You can print the paths and the ends of each path in arbitrary order.
If there are multiple decompositions, print any. | [
"4\n1 2\n2 3\n3 4\n",
"6\n1 2\n2 3\n3 4\n2 5\n3 6\n",
"5\n1 2\n1 3\n1 4\n1 5\n"
] | [
"Yes\n1\n1 4\n",
"No\n",
"Yes\n4\n1 2\n1 3\n1 4\n1 5\n"
] | The tree from the first example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/9eb4b4c143d3ad267ae05d1e43341bd368b3088b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.
The tree from the second example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/20704b97182d9bcde3321c00a16edcae4d772d93.png" style="max-width: 100.0%;max-height: 100.0%;"/> We can show that there are no valid decompositions of this tree.
The tree from the third example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/357ff9496a4ed4746401160ee6ee63f5d57d81b9.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions. | 1,250 | [
{
"input": "4\n1 2\n2 3\n3 4",
"output": "Yes\n1\n1 4"
},
{
"input": "6\n1 2\n2 3\n3 4\n2 5\n3 6",
"output": "No"
},
{
"input": "5\n1 2\n1 3\n1 4\n1 5",
"output": "Yes\n4\n1 2\n1 3\n1 4\n1 5"
},
{
"input": "2\n1 2",
"output": "Yes\n1\n1 2"
},
{
"input": "8\n1 2\n1 3\n1 4\n1 8\n7 8\n6 8\n5 8",
"output": "No"
},
{
"input": "9\n1 2\n1 3\n1 4\n1 5\n1 6\n6 7\n7 8\n7 9",
"output": "No"
},
{
"input": "3\n2 3\n1 2",
"output": "Yes\n1\n1 3"
}
] | 1,527,615,561 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | import sys
def dfs(start, visited=set({})):
ans = []
visited.add(start)
leaf = True
for v in g[start]:
if v not in visited:
leaf = False
ans += dfs(v)
if leaf:
return ans + [start]
return ans
n = int(sys.stdin.readline().strip())
g = {i:[] for i in range(n+1)}
for _ in range(n-1):
u,v = map(int,sys.stdin.readline().strip().split(' '))
g[u].append(v)
g[v].append(u)
acc = 0
middle = -1
for i in range(1,n+1):
if len(g[i]) > 2:
acc += 1
middle = i
if len(g[i]) == 2 and middle == -1:
middle = i
if acc >= 2:
print("No")
else:
ans = dfs(middle)
print(len(ans))
for ai in ans:
print(str(middle) + ' ' + str(ai))
| Title: Useful Decomposition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths have at least one common vertex. Each edge of the tree should be in exactly one path.
Help Remesses, find such a decomposition of the tree or derermine that there is no such decomposition.
Input Specification:
The first line contains a single integer $n$ ($2 \leq n \leq 10^{5}$) the number of nodes in the tree.
Each of the next $n<=-<=1$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$) — the edges of the tree. It is guaranteed that the given edges form a tree.
Output Specification:
If there are no decompositions, print the only line containing "No".
Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m$.
Each of the next $m$ lines should contain two integers $u_i$, $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) denoting that one of the paths in the decomposition is the simple path between nodes $u_i$ and $v_i$.
Each pair of paths in the decomposition should have at least one common vertex, and each edge of the tree should be presented in exactly one path. You can print the paths and the ends of each path in arbitrary order.
If there are multiple decompositions, print any.
Demo Input:
['4\n1 2\n2 3\n3 4\n', '6\n1 2\n2 3\n3 4\n2 5\n3 6\n', '5\n1 2\n1 3\n1 4\n1 5\n']
Demo Output:
['Yes\n1\n1 4\n', 'No\n', 'Yes\n4\n1 2\n1 3\n1 4\n1 5\n']
Note:
The tree from the first example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/9eb4b4c143d3ad267ae05d1e43341bd368b3088b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.
The tree from the second example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/20704b97182d9bcde3321c00a16edcae4d772d93.png" style="max-width: 100.0%;max-height: 100.0%;"/> We can show that there are no valid decompositions of this tree.
The tree from the third example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/357ff9496a4ed4746401160ee6ee63f5d57d81b9.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions. | ```python
import sys
def dfs(start, visited=set({})):
ans = []
visited.add(start)
leaf = True
for v in g[start]:
if v not in visited:
leaf = False
ans += dfs(v)
if leaf:
return ans + [start]
return ans
n = int(sys.stdin.readline().strip())
g = {i:[] for i in range(n+1)}
for _ in range(n-1):
u,v = map(int,sys.stdin.readline().strip().split(' '))
g[u].append(v)
g[v].append(u)
acc = 0
middle = -1
for i in range(1,n+1):
if len(g[i]) > 2:
acc += 1
middle = i
if len(g[i]) == 2 and middle == -1:
middle = i
if acc >= 2:
print("No")
else:
ans = dfs(middle)
print(len(ans))
for ai in ans:
print(str(middle) + ' ' + str(ai))
``` | 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,481,130,423 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 4,608,000 | n=int(input())
m=input().split()
jishu=0
oushu=0
for i in range(3):
k=int(m[i])/2-int(m[i])//2
if k==0:
oushu+=1
else:
jishu+=1
if jishu>oushu:
for i in range(n):
kt=int(m[i])/2-int(m[i])//2
if kt==0:
print(i+1)
break
else:
for i in range(n):
kt=int(m[i])/2-int(m[i])//2
if kt!=0:
print(i+1)
break
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n=int(input())
m=input().split()
jishu=0
oushu=0
for i in range(3):
k=int(m[i])/2-int(m[i])//2
if k==0:
oushu+=1
else:
jishu+=1
if jishu>oushu:
for i in range(n):
kt=int(m[i])/2-int(m[i])//2
if kt==0:
print(i+1)
break
else:
for i in range(n):
kt=int(m[i])/2-int(m[i])//2
if kt!=0:
print(i+1)
break
``` | 3.960417 |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime. | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "640097987171091792 640097987171091793 640097987171091794"
},
{
"input": "19534350415104721 19534350415104725",
"output": "19534350415104722 19534350415104723 19534350415104724"
},
{
"input": "933700505788726243 933700505788726280",
"output": "933700505788726244 933700505788726245 933700505788726246"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "2 3 4"
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "266540997167959130 266540997167959164",
"output": "266540997167959130 266540997167959131 266540997167959132"
},
{
"input": "267367244641009850 267367244641009899",
"output": "267367244641009850 267367244641009851 267367244641009852"
},
{
"input": "268193483524125978 268193483524125993",
"output": "268193483524125978 268193483524125979 268193483524125980"
},
{
"input": "269019726702209402 269019726702209432",
"output": "269019726702209402 269019726702209403 269019726702209404"
},
{
"input": "269845965585325530 269845965585325576",
"output": "269845965585325530 269845965585325531 269845965585325532"
},
{
"input": "270672213058376250 270672213058376260",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492378",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608523",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691962",
"output": "273150934002691930 273150934002691931 273150934002691932"
},
{
"input": "996517375802030516 996517375802030524",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146694",
"output": "997343614685146644 997343614685146645 997343614685146646"
},
{
"input": "998169857863230068 998169857863230083",
"output": "998169857863230068 998169857863230069 998169857863230070"
},
{
"input": "998996101041313492 998996101041313522",
"output": "998996101041313492 998996101041313493 998996101041313494"
},
{
"input": "999822344219396916 999822344219396961",
"output": "999822344219396916 999822344219396917 999822344219396918"
},
{
"input": "648583102513043 648583102513053",
"output": "648583102513044 648583102513045 648583102513046"
},
{
"input": "266540997167959130 266540997167959131",
"output": "-1"
},
{
"input": "267367244641009850 267367244641009850",
"output": "-1"
},
{
"input": "268193483524125978 268193483524125979",
"output": "-1"
},
{
"input": "269019726702209402 269019726702209402",
"output": "-1"
},
{
"input": "269845965585325530 269845965585325530",
"output": "-1"
},
{
"input": "270672213058376250 270672213058376254",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492379",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608508",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691931",
"output": "-1"
},
{
"input": "996517375802030516 996517375802030518",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146644",
"output": "-1"
},
{
"input": "2147483647 2147483649",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "1 7",
"output": "2 3 4"
},
{
"input": "9 12",
"output": "9 11 12"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "11 13",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
}
] | 1,589,206,044 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 109 | 6,656,000 | l,r = map(int,input().split())
range = r - l + 1
if (range < 3) or (l % 2 == 1 and range < 4):
print(-1)
else:
if (l % 2 == 0):
print(l,l+1,l+2)
else:
print(l+1,l+2,l+3) | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime.
Input Specification:
The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50).
Output Specification:
Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Demo Input:
['2 4\n', '10 11\n', '900000000000000009 900000000000000029\n']
Demo Output:
['2 3 4\n', '-1\n', '900000000000000009 900000000000000010 900000000000000021\n']
Note:
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | ```python
l,r = map(int,input().split())
range = r - l + 1
if (range < 3) or (l % 2 == 1 and range < 4):
print(-1)
else:
if (l % 2 == 0):
print(l,l+1,l+2)
else:
print(l+1,l+2,l+3)
``` | 3 |
|
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6.
The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.
In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"input": "1000\n999",
"output": "1"
},
{
"input": "1000\n1",
"output": "250000"
},
{
"input": "2\n1",
"output": "1"
},
{
"input": "2\n999",
"output": "249001"
},
{
"input": "2\n998",
"output": "248502"
},
{
"input": "999\n2",
"output": "249001"
},
{
"input": "998\n2",
"output": "248502"
},
{
"input": "2\n1000",
"output": "249500"
},
{
"input": "1000\n2",
"output": "249500"
},
{
"input": "1\n999",
"output": "249500"
},
{
"input": "999\n1",
"output": "249500"
},
{
"input": "188\n762",
"output": "82656"
},
{
"input": "596\n777",
"output": "8281"
},
{
"input": "773\n70",
"output": "123904"
},
{
"input": "825\n729",
"output": "2352"
},
{
"input": "944\n348",
"output": "89102"
},
{
"input": "352\n445",
"output": "2209"
},
{
"input": "529\n656",
"output": "4096"
},
{
"input": "19\n315",
"output": "22052"
},
{
"input": "138\n370",
"output": "13572"
},
{
"input": "546\n593",
"output": "576"
},
{
"input": "285\n242",
"output": "484"
},
{
"input": "773\n901",
"output": "4160"
},
{
"input": "892\n520",
"output": "34782"
},
{
"input": "864\n179",
"output": "117649"
},
{
"input": "479\n470",
"output": "25"
},
{
"input": "967\n487",
"output": "57840"
},
{
"input": "648\n106",
"output": "73712"
},
{
"input": "58\n765",
"output": "125316"
},
{
"input": "235\n56",
"output": "8100"
},
{
"input": "285\n153",
"output": "4422"
},
{
"input": "943\n13",
"output": "216690"
},
{
"input": "675\n541",
"output": "4556"
},
{
"input": "4\n912",
"output": "206570"
}
] | 1,573,648,367 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | import math
a = int(input())
b = int(input())
z = math.fabs(a-b)//2
n = 0
for i in range(int((math.fabs(a-b)-z))+1):
n+=i
for i in range(int(z)+1):
n+=i
print(n) | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6.
The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
Input Specification:
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*.
Output Specification:
Print the minimum possible total tiredness if the friends meet in the same point.
Demo Input:
['3\n4\n', '101\n99\n', '5\n10\n']
Demo Output:
['1\n', '2\n', '9\n']
Note:
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.
In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. | ```python
import math
a = int(input())
b = int(input())
z = math.fabs(a-b)//2
n = 0
for i in range(int((math.fabs(a-b)-z))+1):
n+=i
for i in range(int(z)+1):
n+=i
print(n)
``` | 3 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,655,896,843 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
h = int(input())
j = str(n+h)
j = j.replace("2","0")
print(int(j)) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
n = int(input())
h = int(input())
j = str(n+h)
j = j.replace("2","0")
print(int(j))
``` | 0 |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"input": "24 22 9235",
"output": "34"
},
{
"input": "74 8 417",
"output": "1"
},
{
"input": "972 1 203",
"output": "0"
},
{
"input": "550 1 754",
"output": "1"
},
{
"input": "860 1 884",
"output": "1"
},
{
"input": "358 2 809",
"output": "2"
},
{
"input": "33 27 216",
"output": "0"
},
{
"input": "2940 1 9311",
"output": "3"
},
{
"input": "4624 1 1953",
"output": "0"
},
{
"input": "2696 2 7345",
"output": "2"
},
{
"input": "3443 2 6701",
"output": "0"
},
{
"input": "3 613 2275",
"output": "1"
},
{
"input": "1 10000 10000",
"output": "1"
},
{
"input": "10000 1 10000",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1 10000",
"output": "10000"
},
{
"input": "34 27 10000",
"output": "10"
},
{
"input": "2 2 9999",
"output": "4999"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "6 4 36",
"output": "3"
},
{
"input": "33 6 3005",
"output": "45"
},
{
"input": "5 1 20",
"output": "4"
},
{
"input": "1 2 10",
"output": "5"
},
{
"input": "2 1 100",
"output": "50"
},
{
"input": "10 20 10000",
"output": "500"
},
{
"input": "8 12 12",
"output": "0"
}
] | 1,618,300,521 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n,k,z = [int(x) for x in input().split()]
a = [n*x for x in range(1,z+1) if n*k <=z]
b = [k*x for x in range(1,z+1)if k*x <=z]
print(len(set(a)&set(b))) | Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
Input Specification:
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Output Specification:
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
Demo Input:
['1 1 10\n', '1 2 5\n', '2 3 9\n']
Demo Output:
['10\n', '2\n', '1\n']
Note:
Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | ```python
n,k,z = [int(x) for x in input().split()]
a = [n*x for x in range(1,z+1) if n*k <=z]
b = [k*x for x in range(1,z+1)if k*x <=z]
print(len(set(a)&set(b)))
``` | 0 |
|
388 | A | Fox and Box Accumulation | PROGRAMMING | 1,400 | [
"greedy",
"sortings"
] | null | null | Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than *x**i* boxes on the top of *i*-th box. What is the minimal number of piles she needs to construct? | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100). | Output a single integer — the minimal possible number of piles. | [
"3\n0 0 10\n",
"5\n0 1 2 3 4\n",
"4\n0 0 0 0\n",
"9\n0 1 0 2 0 1 1 2 10\n"
] | [
"2\n",
"1\n",
"4\n",
"3\n"
] | In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). | 500 | [
{
"input": "3\n0 0 10",
"output": "2"
},
{
"input": "5\n0 1 2 3 4",
"output": "1"
},
{
"input": "4\n0 0 0 0",
"output": "4"
},
{
"input": "9\n0 1 0 2 0 1 1 2 10",
"output": "3"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n100 99",
"output": "1"
},
{
"input": "9\n0 1 1 0 2 0 3 45 4",
"output": "3"
},
{
"input": "10\n1 1 1 1 2 2 2 2 2 2",
"output": "4"
},
{
"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": "2"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "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": "1"
},
{
"input": "11\n71 34 31 71 42 38 64 60 36 76 67",
"output": "1"
},
{
"input": "39\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54",
"output": "1"
},
{
"input": "59\n61 33 84 76 56 47 70 94 46 77 95 85 35 90 83 62 48 74 36 74 83 97 62 92 95 75 70 82 94 67 82 42 78 70 50 73 80 76 94 83 96 80 80 88 91 79 83 54 38 90 33 93 53 33 86 95 48 34 46",
"output": "1"
},
{
"input": "87\n52 63 93 90 50 35 67 66 46 89 43 64 33 88 34 80 69 59 75 55 55 68 66 83 46 33 72 36 73 34 54 85 52 87 67 68 47 95 52 78 92 58 71 66 84 61 36 77 69 44 84 70 71 55 43 91 33 65 77 34 43 59 83 70 95 38 92 92 74 53 66 65 81 45 55 89 49 52 43 69 78 41 37 79 63 70 67",
"output": "1"
},
{
"input": "15\n20 69 36 63 40 40 52 42 20 43 59 68 64 49 47",
"output": "1"
},
{
"input": "39\n40 20 49 35 80 18 20 75 39 62 43 59 46 37 58 52 67 16 34 65 32 75 59 42 59 41 68 21 41 61 66 19 34 63 19 63 78 62 24",
"output": "1"
},
{
"input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "18"
},
{
"input": "46\n14 13 13 10 13 15 8 8 12 9 11 15 8 10 13 8 12 13 11 8 12 15 12 15 11 13 12 9 13 12 10 8 13 15 9 15 8 13 11 8 9 9 9 8 11 8",
"output": "3"
},
{
"input": "70\n6 1 4 1 1 6 5 2 5 1 1 5 2 1 2 4 1 1 1 2 4 5 2 1 6 6 5 2 1 4 3 1 4 3 6 5 2 1 3 4 4 1 4 5 6 2 1 2 4 4 5 3 6 1 1 2 2 1 5 6 1 6 3 1 4 4 2 3 1 4",
"output": "11"
},
{
"input": "94\n11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11",
"output": "8"
},
{
"input": "18\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "9"
},
{
"input": "46\n14 8 7 4 8 7 8 8 12 9 9 12 9 12 14 8 10 14 14 6 9 11 7 14 14 13 11 4 13 13 11 13 9 10 10 12 10 8 12 10 13 10 7 13 14 6",
"output": "4"
},
{
"input": "74\n4 4 5 5 5 5 5 5 6 6 5 4 4 4 3 3 5 4 5 3 4 4 5 6 3 3 5 4 4 5 4 3 5 5 4 4 3 5 6 4 3 6 6 3 4 5 4 4 3 3 3 6 3 5 6 5 5 5 5 3 6 4 5 4 4 6 6 3 4 5 6 6 6 6",
"output": "11"
},
{
"input": "100\n48 35 44 37 35 42 42 39 49 53 35 55 41 42 42 39 43 49 46 54 48 39 42 53 55 39 56 43 43 38 48 40 54 36 48 55 46 40 41 39 45 56 38 40 47 46 45 46 53 51 38 41 54 35 35 47 42 43 54 54 39 44 49 41 37 49 36 37 37 49 53 44 47 37 55 49 45 40 35 51 44 40 42 35 46 48 53 48 35 38 42 36 54 46 44 47 41 40 41 42",
"output": "2"
},
{
"input": "100\n34 3 37 35 40 44 38 46 13 31 12 23 26 40 26 18 28 36 5 21 2 4 10 29 3 46 38 41 37 28 44 14 39 10 35 17 24 28 38 16 29 6 2 42 47 34 43 2 43 46 7 16 16 43 33 32 20 47 8 48 32 4 45 38 15 7 25 25 19 41 20 35 16 2 31 5 31 25 27 3 45 29 32 36 9 47 39 35 9 21 32 17 21 41 29 48 11 40 5 25",
"output": "3"
},
{
"input": "100\n2 4 5 5 0 5 3 0 3 0 5 3 4 1 0 3 0 5 5 0 4 3 3 3 0 2 1 2 2 4 4 2 4 0 1 3 4 1 4 2 5 3 5 2 3 0 1 2 5 5 2 0 4 2 5 1 0 0 4 0 1 2 0 1 2 4 1 4 5 3 4 5 5 1 0 0 3 1 4 0 4 5 1 3 3 0 4 2 0 4 5 2 3 0 5 1 4 4 1 0",
"output": "21"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "17"
},
{
"input": "100\n1 1 1 2 2 2 2 2 2 1 1 1 2 0 2 2 0 0 0 0 0 2 0 0 2 2 1 0 2 0 2 1 1 2 2 1 2 2 1 2 1 2 2 1 2 0 1 2 2 0 2 2 2 2 1 0 1 0 0 0 2 0 2 0 1 1 0 2 2 2 2 1 1 1 2 1 1 2 1 1 1 2 1 0 2 1 0 1 2 0 1 1 2 0 0 1 1 0 1 1",
"output": "34"
},
{
"input": "100\n0 3 1 0 3 2 1 2 2 1 2 1 3 2 1 2 1 3 2 0 0 2 3 0 0 2 1 2 2 3 1 2 2 2 0 3 3 2 0 0 1 0 1 2 3 1 0 3 3 3 0 2 1 3 0 1 3 2 2 2 2 3 3 2 0 2 0 1 0 1 3 0 1 2 0 1 3 2 0 3 1 1 2 3 1 3 1 0 3 0 3 0 2 1 1 1 2 2 0 1",
"output": "26"
},
{
"input": "100\n1 0 2 2 2 2 1 0 1 2 2 2 0 1 0 1 2 1 2 1 0 1 2 2 2 1 0 1 0 2 1 2 0 2 1 1 2 1 1 0 1 2 1 1 2 1 1 0 2 2 0 0 1 2 0 2 0 0 1 1 0 0 2 1 2 1 0 2 2 2 2 2 2 1 2 0 1 2 1 2 1 0 1 0 1 0 1 1 0 2 1 0 0 1 2 2 1 0 0 1",
"output": "34"
},
{
"input": "100\n3 4 4 4 3 3 3 3 3 4 4 4 3 3 3 4 3 4 4 4 3 4 3 4 3 4 3 3 4 4 3 4 4 3 4 4 4 4 4 3 4 3 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 3 3 3 4 4 3 4 4 3 4 3 3 3 4 4 3 3 3 3 3 4 3 4 4 3 3 4 3 4 3 4 4 4 3 3 3 4 4 4 4 3",
"output": "20"
},
{
"input": "100\n8 7 9 10 2 7 8 11 11 4 7 10 2 5 8 9 10 3 9 4 10 5 5 6 3 8 8 9 6 9 5 5 4 11 4 2 11 8 3 5 6 6 11 9 8 11 9 8 3 3 8 9 8 9 4 8 6 11 4 4 4 9 7 5 3 4 11 3 9 11 8 10 3 5 5 7 6 9 4 5 2 11 3 6 2 10 9 4 6 10 5 11 8 10 10 8 9 8 5 3",
"output": "9"
},
{
"input": "5\n4 1 1 1 1",
"output": "2"
}
] | 1,490,908,475 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 5,632,000 | from collections import Counter
def main():
int(input())
c = Counter(map(int, input().split()))
ans = 1
for k in c:
ans = max(ans, c[k])
print(ans)
main()
| Title: Fox and Box Accumulation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than *x**i* boxes on the top of *i*-th box. What is the minimal number of piles she needs to construct?
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100).
Output Specification:
Output a single integer — the minimal possible number of piles.
Demo Input:
['3\n0 0 10\n', '5\n0 1 2 3 4\n', '4\n0 0 0 0\n', '9\n0 1 0 2 0 1 1 2 10\n']
Demo Output:
['2\n', '1\n', '4\n', '3\n']
Note:
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). | ```python
from collections import Counter
def main():
int(input())
c = Counter(map(int, input().split()))
ans = 1
for k in c:
ans = max(ans, c[k])
print(ans)
main()
``` | 0 |
|
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888",
"output": "NO"
},
{
"input": "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n8388888888888\n1111111111111\n5555555555555",
"output": "NO"
},
{
"input": "10 8\n33333333\n44444444\n11111115\n81888888\n44444444\n11111111\n66666666\n33330333\n33333333\n33333333",
"output": "NO"
},
{
"input": "5 5\n88888\n44444\n66666\n55555\n88888",
"output": "YES"
},
{
"input": "20 19\n1111111111111111111\n5555555555555555555\n0000000000000000000\n3333333333333333333\n1111111111111111111\n2222222222222222222\n4444444444444444444\n5555555555555555555\n0000000000000000000\n4444444444444444444\n0000000000000000000\n5555555555555555555\n7777777777777777777\n9999999999999999999\n2222222222222222222\n4444444444444444444\n1111111111111111111\n6666666666666666666\n7777777777777777777\n2222222222222222222",
"output": "YES"
},
{
"input": "1 100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888",
"output": "YES"
},
{
"input": "100 1\n5\n7\n9\n4\n7\n2\n5\n1\n6\n7\n2\n7\n6\n8\n7\n4\n0\n2\n9\n8\n9\n1\n6\n4\n3\n4\n7\n1\n9\n3\n0\n8\n3\n1\n7\n5\n3\n9\n5\n1\n3\n5\n8\n1\n9\n3\n9\n0\n6\n0\n7\n6\n5\n2\n8\n3\n7\n6\n5\n1\n8\n3\n6\n9\n6\n0\n5\n8\n5\n2\n9\n1\n0\n1\n8\n3\n2\n1\n0\n3\n9\n0\n5\n1\n0\n4\n9\n3\n0\n4\n8\n4\n8\n6\n3\n0\n4\n6\n8\n4",
"output": "YES"
},
{
"input": "1 1\n2",
"output": "YES"
},
{
"input": "1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111181111111111111111111111",
"output": "NO"
},
{
"input": "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4\n5\n9\n2\n7\n4\n1\n5\n8\n0\n9\n5\n4\n6\n5\n0\n6\n3\n6\n9\n7\n2\n0\n9\n7\n3\n2\n4\n9\n4\n7\n1\n2\n3\n1\n7\n9\n1\n9\n0\n4\n0",
"output": "YES"
}
] | 1,560,918,665 | 365 | Python 3 | WRONG_ANSWER | TESTS | 0 | 218 | 0 | n,k=map(int,input().strip().split())
v = []
for i in range(2,n+1):
if all(i%j!=0 for j in v):
v.append(i)
c=0
for i in range(len(v)-1):
if v[i]+v[i+1]+1 in v:
c+=1
if(c>=k):
print("YES")
else:
print("NO") | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input Specification:
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output Specification:
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Demo Input:
['3 3\n000\n111\n222\n', '3 3\n000\n000\n111\n', '3 3\n000\n111\n002\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
n,k=map(int,input().strip().split())
v = []
for i in range(2,n+1):
if all(i%j!=0 for j in v):
v.append(i)
c=0
for i in range(len(v)-1):
if v[i]+v[i+1]+1 in v:
c+=1
if(c>=k):
print("YES")
else:
print("NO")
``` | 0 |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1",
"output": "3"
},
{
"input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4",
"output": "4"
},
{
"input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1",
"output": "3"
},
{
"input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0",
"output": "5"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "6 3\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "1 4\n1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "2 3\n0 0",
"output": "0"
}
] | 1,676,229,881 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n=input().split()
p=input().split()
k=int(n[1])
x=int(n[0])
a=0
o=0
if k>5:
o=0
else:
for i in p:
i=int(i)
if k+i<=5:
a+=1
if a==3:
o+=1
a-=3
print(o) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
Input Specification:
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | ```python
n=input().split()
p=input().split()
k=int(n[1])
x=int(n[0])
a=0
o=0
if k>5:
o=0
else:
for i in p:
i=int(i)
if k+i<=5:
a+=1
if a==3:
o+=1
a-=3
print(o)
``` | 3 |
|
1,011 | B | Planning The Expedition | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.
Formally, for each participant $j$ Natasha should select his food type $b_j$ and each day $j$-th participant will eat one food package of type $b_j$. The values $b_j$ for different participants may be different.
What is the maximum possible number of days the expedition can last, following the requirements above? | The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$) — the number of the expedition participants and the number of the daily food packages available.
The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food package. | Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0. | [
"4 10\n1 5 2 1 1 1 2 5 7 2\n",
"100 1\n1\n",
"2 5\n5 4 3 2 1\n",
"3 9\n42 42 42 42 42 42 42 42 42\n"
] | [
"2\n",
"0\n",
"1\n",
"3\n"
] | In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of type $1$, two packages of type $2$ and two packages of type $5$).
In the second example, there are $100$ participants and only $1$ food package. In this case, the expedition can't last even $1$ day. | 1,000 | [
{
"input": "4 10\n1 5 2 1 1 1 2 5 7 2",
"output": "2"
},
{
"input": "100 1\n1",
"output": "0"
},
{
"input": "2 5\n5 4 3 2 1",
"output": "1"
},
{
"input": "3 9\n42 42 42 42 42 42 42 42 42",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "4 100\n84 99 66 69 86 94 89 96 98 93 93 82 87 93 91 100 69 99 93 81 99 84 75 100 86 88 98 100 84 96 44 70 94 91 85 78 86 79 45 88 91 78 98 94 81 87 93 72 96 88 96 97 96 62 86 72 94 84 80 98 88 90 93 73 73 98 78 50 91 96 97 82 85 90 87 41 97 82 97 77 100 100 92 83 98 81 70 81 74 78 84 79 98 98 55 99 97 99 79 98",
"output": "5"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "6 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 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "15"
},
{
"input": "1 1\n59",
"output": "1"
},
{
"input": "1 50\n39 1 46 21 23 28 100 32 63 63 18 15 40 29 34 49 56 74 47 42 96 97 59 62 76 62 69 61 36 21 66 18 92 58 63 85 5 6 77 75 91 66 38 10 66 43 20 74 37 83",
"output": "3"
},
{
"input": "1 100\n83 72 21 55 49 5 61 60 87 21 89 88 3 75 49 81 36 25 50 61 96 19 36 55 48 8 97 69 50 24 23 39 26 25 41 90 69 20 19 62 38 52 60 6 66 31 9 45 36 12 69 94 22 60 91 65 35 58 13 85 33 87 83 11 95 20 20 85 13 21 57 69 17 94 78 37 59 45 60 7 64 51 60 89 91 22 6 58 95 96 51 53 89 22 28 16 27 56 1 54",
"output": "5"
},
{
"input": "50 1\n75",
"output": "0"
},
{
"input": "50 50\n85 20 12 73 52 78 70 95 88 43 31 88 81 41 80 99 16 11 97 11 21 44 2 34 47 38 87 2 32 47 97 93 52 14 35 37 97 48 58 19 52 55 97 72 17 25 16 85 90 58",
"output": "1"
},
{
"input": "50 100\n2 37 74 32 99 75 73 86 67 33 62 30 15 21 51 41 73 75 67 39 90 10 56 74 72 26 38 65 75 55 46 99 34 49 92 82 11 100 15 71 75 12 22 56 47 74 20 98 59 65 14 76 1 40 89 36 43 93 83 73 75 100 50 95 27 10 72 51 25 69 15 3 57 60 84 99 31 44 12 61 69 95 51 31 28 36 57 35 31 52 44 19 79 12 27 27 7 81 68 1",
"output": "1"
},
{
"input": "100 1\n26",
"output": "0"
},
{
"input": "100 50\n8 82 62 11 85 57 5 32 99 92 77 2 61 86 8 88 10 28 83 4 68 79 8 64 56 98 4 88 22 54 30 60 62 79 72 38 17 28 32 16 62 26 56 44 72 33 22 84 77 45",
"output": "0"
},
{
"input": "100 100\n13 88 64 65 78 10 61 97 16 32 76 9 60 1 40 35 90 61 60 85 26 16 38 36 33 95 24 55 82 88 13 9 47 34 94 2 90 74 11 81 46 70 94 11 55 32 19 36 97 16 17 35 38 82 89 16 74 94 97 79 9 94 88 12 28 2 4 25 72 95 49 31 88 82 6 77 70 98 90 57 57 33 38 61 26 75 2 66 22 44 13 35 16 4 33 16 12 66 32 86",
"output": "1"
},
{
"input": "34 64\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",
"output": "1"
},
{
"input": "53 98\n1 1 2 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 2 1 2 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 1 1 2 2 1 2 1 2 1 2 1 1 2 2 2 1 1 2 1 2 1 1 1 1 2 2 2 2 2 1 1 2 2 2 1 1",
"output": "1"
},
{
"input": "17 8\n2 5 3 4 3 2 2 2",
"output": "0"
},
{
"input": "24 77\n8 6 10 4 6 6 4 10 9 7 7 5 5 4 6 7 10 6 3 4 6 6 4 9 4 6 2 5 3 4 4 1 4 6 6 8 1 1 6 4 6 2 5 7 7 2 4 4 10 1 10 9 2 3 8 1 10 4 3 9 3 8 3 5 6 3 4 9 5 3 4 1 1 6 1 2 1",
"output": "2"
},
{
"input": "65 74\n7 19 2 38 28 44 34 49 14 13 30 22 11 4 4 12 8 1 40 8 34 31 44 38 21 35 13 7 19 32 37 5 36 26 7 2 15 11 47 45 48 2 49 10 10 42 42 31 50 24 29 34 31 38 39 48 43 47 32 46 10 1 33 21 12 50 13 44 38 11 41 41 10 7",
"output": "1"
},
{
"input": "37 71\n50 93 15 80 82 23 35 90 70 73 55 23 23 6 86 63 38 70 38 52 88 34 25 75 32 19 6 98 31 38 21 8 66 8 59 71 7 80 69 23 17 70 6 40 72 5 48 59 18 1 48 91 17 41 11 27 53 95 87 31 62 94 94 60 38 99 70 50 81 86 44",
"output": "1"
},
{
"input": "35 4\n100 100 100 100",
"output": "0"
},
{
"input": "68 12\n100 100 100 99 99 100 100 100 99 99 99 99",
"output": "0"
},
{
"input": "91 33\n97 100 96 96 97 100 97 97 96 96 99 99 98 97 97 99 99 98 100 96 96 99 100 96 97 100 97 97 99 98 96 98 97",
"output": "0"
},
{
"input": "59 72\n99 96 96 93 94 97 93 96 100 99 93 99 96 92 92 97 93 100 92 100 91 96 99 100 97 98 93 93 96 100 97 99 100 100 91 93 96 91 93 100 95 96 92 97 91 91 99 100 91 95 95 100 92 93 98 93 95 92 95 100 91 95 99 95 92 91 100 93 98 98 96 99",
"output": "1"
},
{
"input": "9 35\n95 54 78 94 56 63 68 73 61 85 73 62 61 94 67 91 66 54 89 69 92 60 91 87 63 62 85 70 62 68 97 88 96 55 62",
"output": "2"
},
{
"input": "99 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"
},
{
"input": "1 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
}
] | 1,532,870,650 | 5,350 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 0 | n, m = map(int, input().split())
a = [int(i) for i in input().split()]
if m >= n:
b = []
for item in set(a):
b.append(a.count(item))
if len(b) == 1:
print(b[0] // n)
else:
while len(b) < n:
b.sort()
b.append(b[-1] // 2)
b[-2] = b[-2] // 2 + b[-2] % 2
b.sort()
while b[-1] // 2 > b[0]:
b[0] = b[-1] // 2
b[-1] = b[-1] // 2 + b[-1] % 2
b.sort()
print(b[0])
else:
print(0) | Title: Planning The Expedition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.
Formally, for each participant $j$ Natasha should select his food type $b_j$ and each day $j$-th participant will eat one food package of type $b_j$. The values $b_j$ for different participants may be different.
What is the maximum possible number of days the expedition can last, following the requirements above?
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$) — the number of the expedition participants and the number of the daily food packages available.
The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food package.
Output Specification:
Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0.
Demo Input:
['4 10\n1 5 2 1 1 1 2 5 7 2\n', '100 1\n1\n', '2 5\n5 4 3 2 1\n', '3 9\n42 42 42 42 42 42 42 42 42\n']
Demo Output:
['2\n', '0\n', '1\n', '3\n']
Note:
In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of type $1$, two packages of type $2$ and two packages of type $5$).
In the second example, there are $100$ participants and only $1$ food package. In this case, the expedition can't last even $1$ day. | ```python
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
if m >= n:
b = []
for item in set(a):
b.append(a.count(item))
if len(b) == 1:
print(b[0] // n)
else:
while len(b) < n:
b.sort()
b.append(b[-1] // 2)
b[-2] = b[-2] // 2 + b[-2] % 2
b.sort()
while b[-1] // 2 > b[0]:
b[0] = b[-1] // 2
b[-1] = b[-1] // 2 + b[-1] % 2
b.sort()
print(b[0])
else:
print(0)
``` | 0 |
|
166 | B | Polygons | PROGRAMMING | 2,100 | [
"geometry",
"sortings"
] | null | null | You've got another geometrical task. You are given two non-degenerate polygons *A* and *B* as vertex coordinates. Polygon *A* is strictly convex. Polygon *B* is an arbitrary polygon without any self-intersections and self-touches. The vertices of both polygons are given in the clockwise order. For each polygon no three consecutively following vertices are located on the same straight line.
Your task is to check whether polygon *B* is positioned strictly inside polygon *A*. It means that any point of polygon *B* should be strictly inside polygon *A*. "Strictly" means that the vertex of polygon *B* cannot lie on the side of the polygon *A*. | The first line contains the only integer *n* (3<=≤<=*n*<=≤<=105) — the number of vertices of polygon *A*. Then *n* lines contain pairs of integers *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=109) — coordinates of the *i*-th vertex of polygon *A*. The vertices are given in the clockwise order.
The next line contains a single integer *m* (3<=≤<=*m*<=≤<=2·104) — the number of vertices of polygon *B*. Then following *m* lines contain pairs of integers *x**j*,<=*y**j* (|*x**j*|,<=|*y**j*|<=≤<=109) — the coordinates of the *j*-th vertex of polygon *B*. The vertices are given in the clockwise order.
The coordinates of the polygon's vertices are separated by a single space. It is guaranteed that polygons *A* and *B* are non-degenerate, that polygon *A* is strictly convex, that polygon *B* has no self-intersections and self-touches and also for each polygon no three consecutively following vertices are located on the same straight line. | Print on the only line the answer to the problem — if polygon *B* is strictly inside polygon *A*, print "YES", otherwise print "NO" (without the quotes). | [
"6\n-2 1\n0 3\n3 3\n4 1\n3 -2\n2 -2\n4\n0 1\n2 2\n3 1\n1 0\n",
"5\n1 2\n4 2\n3 -3\n-2 -2\n-2 1\n4\n0 1\n1 2\n4 1\n2 -1\n",
"5\n-1 2\n2 3\n4 1\n3 -2\n0 -3\n5\n1 0\n1 1\n3 1\n5 -1\n2 -1\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 3,000 | [
{
"input": "6\n-2 1\n0 3\n3 3\n4 1\n3 -2\n2 -2\n4\n0 1\n2 2\n3 1\n1 0",
"output": "YES"
},
{
"input": "5\n1 2\n4 2\n3 -3\n-2 -2\n-2 1\n4\n0 1\n1 2\n4 1\n2 -1",
"output": "NO"
},
{
"input": "5\n-1 2\n2 3\n4 1\n3 -2\n0 -3\n5\n1 0\n1 1\n3 1\n5 -1\n2 -1",
"output": "NO"
},
{
"input": "7\n1 3\n4 2\n4 -1\n2 -3\n0 -3\n-3 0\n-2 2\n5\n-1 1\n2 2\n3 0\n2 -2\n0 -2",
"output": "YES"
},
{
"input": "4\n3 -2\n-2 2\n2 3\n4 1\n4\n2 1\n1 1\n1 2\n2 2",
"output": "YES"
},
{
"input": "5\n4 3\n2 -3\n-1 -3\n-1 0\n2 2\n5\n-1 -2\n-1 -1\n2 1\n3 0\n2 -2",
"output": "NO"
},
{
"input": "6\n3 3\n3 -3\n0 -4\n-4 -1\n-4 2\n1 5\n9\n0 0\n2 1\n2 -3\n0 -1\n0 -3\n-2 -2\n-1 -1\n-2 1\n2 2",
"output": "YES"
},
{
"input": "6\n2 4\n4 2\n3 -1\n-1 -3\n-3 0\n-2 3\n12\n0 3\n0 2\n1 2\n2 3\n3 2\n1 1\n2 0\n0 -2\n0 0\n-1 -1\n-2 0\n-1 1",
"output": "YES"
},
{
"input": "6\n-2 2\n1 3\n4 3\n5 1\n3 -2\n-1 -2\n7\n1 1\n2 4\n3 2\n6 2\n3 1\n3 0\n2 -3",
"output": "NO"
},
{
"input": "6\n-3 2\n1 4\n3 3\n2 -2\n-1 -3\n-5 0\n3\n3 -2\n4 3\n5 -2",
"output": "NO"
},
{
"input": "4\n4 -1\n-1 -2\n-2 3\n2 3\n6\n2 1\n2 2\n5 3\n5 0\n4 -2\n4 1",
"output": "NO"
},
{
"input": "5\n3 -1\n-1 -1\n-1 2\n3 4\n6 4\n7\n1 0\n1 2\n2 3\n2 2\n4 4\n4 2\n2 -1",
"output": "NO"
},
{
"input": "3\n1 2\n5 5\n6 1\n3\n4 3\n5 2\n3 2",
"output": "YES"
},
{
"input": "3\n0 0\n0 1\n1 0\n3\n0 1\n1 0\n0 0",
"output": "NO"
},
{
"input": "4\n1 0\n0 1\n3 3\n3 0\n8\n-1 2\n4 6\n4 3\n5 4\n3 -2\n3 -3\n2 -2\n1 -2",
"output": "NO"
},
{
"input": "4\n-10 -10\n-10 10\n10 10\n10 -10\n3\n-10 0\n1 5\n2 2",
"output": "NO"
},
{
"input": "4\n-10 -10\n-10 10\n10 10\n10 -10\n3\n10 0\n2 2\n1 5",
"output": "NO"
},
{
"input": "4\n-10 -10\n-10 10\n10 10\n10 -10\n3\n0 -10\n1 5\n2 2",
"output": "NO"
},
{
"input": "4\n-10 -10\n-10 10\n10 10\n10 -10\n3\n0 10\n2 2\n1 5",
"output": "NO"
},
{
"input": "4\n-10 -10\n-10 10\n10 10\n10 -10\n3\n-10 -10\n1 5\n2 2",
"output": "NO"
},
{
"input": "4\n-10 -10\n-10 10\n10 10\n10 -10\n3\n-10 10\n1 5\n2 2",
"output": "NO"
},
{
"input": "4\n0 0\n9 4\n12 -5\n5 -5\n4\n2 0\n2 3\n5 3\n5 0",
"output": "NO"
},
{
"input": "3\n-1000000000 0\n1000000000 1\n1000000000 -2\n3\n-999999999 0\n999999999 0\n999999999 -1",
"output": "YES"
},
{
"input": "4\n0 0\n0 4\n4 4\n4 0\n3\n2 1\n2 3\n4 2",
"output": "NO"
},
{
"input": "4\n0 10\n10 0\n0 -10\n-10 0\n3\n6 6\n6 5\n0 0",
"output": "NO"
},
{
"input": "4\n0 6\n6 0\n0 -6\n-6 0\n4\n4 4\n4 -4\n-4 -4\n-4 4",
"output": "NO"
},
{
"input": "4\n0 0\n0 4\n4 4\n4 0\n3\n3 1\n2 1\n4 3",
"output": "NO"
},
{
"input": "3\n-1000000000 1000000000\n1000000000 0\n1000 -1000000000\n3\n1000 -999999999\n1000 0\n1001 0",
"output": "YES"
},
{
"input": "4\n0 3\n3 0\n0 -3\n-3 0\n4\n2 2\n2 -2\n-2 -2\n-2 2",
"output": "NO"
}
] | 1,668,636,537 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 184 | 0 | import sys
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def Left_index(points):
minn = 0
for i in range(1,len(points)):
if points[i].x < points[minn].x:
minn = i
elif points[i].x == points[minn].x:
if points[i].y > points[minn].y:
minn = i
return minn
def orientation(p, q, r):
val = (q.y - p.y) * (r.x - q.x) - \
(q.x - p.x) * (r.y - q.y)
if val == 0:
return 0
elif val > 0:
return 1
else:
return 2
def convexHull(points, n):
if n < 3:
return
l = Left_index(points)
hull = []
p = l
q = 0
while(True):
# Add current point to result
hull.append(p)
q = (p + 1) % n
for i in range(n):
# If i is more counterclockwise
# than current q, then update q
if(orientation(points[p],
points[i], points[q]) == 2):
q = i
p = q
# While we don't come to first point
if(p == l):
break
mine = set()
for each in hull:
mine.add((points[each].x, points[each].y))
return mine
poly = []
polyA = set()
n = int(sys.stdin.readline().strip())
for _ in range(n):
tmp = sys.stdin.readline().split()
x = int(tmp[0])
y = int(tmp[1])
polyA.add((x,y))
poly.append(Point(x,y))
m = int(sys.stdin.readline().strip())
for _ in range(m):
tmp = sys.stdin.readline().split()
x = int(tmp[0])
y = int(tmp[1])
poly.append(Point(x,y))
c = convexHull(poly, len(poly))
if c == polyA:
print("YES")
else:
print("NO")
| Title: Polygons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got another geometrical task. You are given two non-degenerate polygons *A* and *B* as vertex coordinates. Polygon *A* is strictly convex. Polygon *B* is an arbitrary polygon without any self-intersections and self-touches. The vertices of both polygons are given in the clockwise order. For each polygon no three consecutively following vertices are located on the same straight line.
Your task is to check whether polygon *B* is positioned strictly inside polygon *A*. It means that any point of polygon *B* should be strictly inside polygon *A*. "Strictly" means that the vertex of polygon *B* cannot lie on the side of the polygon *A*.
Input Specification:
The first line contains the only integer *n* (3<=≤<=*n*<=≤<=105) — the number of vertices of polygon *A*. Then *n* lines contain pairs of integers *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=109) — coordinates of the *i*-th vertex of polygon *A*. The vertices are given in the clockwise order.
The next line contains a single integer *m* (3<=≤<=*m*<=≤<=2·104) — the number of vertices of polygon *B*. Then following *m* lines contain pairs of integers *x**j*,<=*y**j* (|*x**j*|,<=|*y**j*|<=≤<=109) — the coordinates of the *j*-th vertex of polygon *B*. The vertices are given in the clockwise order.
The coordinates of the polygon's vertices are separated by a single space. It is guaranteed that polygons *A* and *B* are non-degenerate, that polygon *A* is strictly convex, that polygon *B* has no self-intersections and self-touches and also for each polygon no three consecutively following vertices are located on the same straight line.
Output Specification:
Print on the only line the answer to the problem — if polygon *B* is strictly inside polygon *A*, print "YES", otherwise print "NO" (without the quotes).
Demo Input:
['6\n-2 1\n0 3\n3 3\n4 1\n3 -2\n2 -2\n4\n0 1\n2 2\n3 1\n1 0\n', '5\n1 2\n4 2\n3 -3\n-2 -2\n-2 1\n4\n0 1\n1 2\n4 1\n2 -1\n', '5\n-1 2\n2 3\n4 1\n3 -2\n0 -3\n5\n1 0\n1 1\n3 1\n5 -1\n2 -1\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
import sys
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def Left_index(points):
minn = 0
for i in range(1,len(points)):
if points[i].x < points[minn].x:
minn = i
elif points[i].x == points[minn].x:
if points[i].y > points[minn].y:
minn = i
return minn
def orientation(p, q, r):
val = (q.y - p.y) * (r.x - q.x) - \
(q.x - p.x) * (r.y - q.y)
if val == 0:
return 0
elif val > 0:
return 1
else:
return 2
def convexHull(points, n):
if n < 3:
return
l = Left_index(points)
hull = []
p = l
q = 0
while(True):
# Add current point to result
hull.append(p)
q = (p + 1) % n
for i in range(n):
# If i is more counterclockwise
# than current q, then update q
if(orientation(points[p],
points[i], points[q]) == 2):
q = i
p = q
# While we don't come to first point
if(p == l):
break
mine = set()
for each in hull:
mine.add((points[each].x, points[each].y))
return mine
poly = []
polyA = set()
n = int(sys.stdin.readline().strip())
for _ in range(n):
tmp = sys.stdin.readline().split()
x = int(tmp[0])
y = int(tmp[1])
polyA.add((x,y))
poly.append(Point(x,y))
m = int(sys.stdin.readline().strip())
for _ in range(m):
tmp = sys.stdin.readline().split()
x = int(tmp[0])
y = int(tmp[1])
poly.append(Point(x,y))
c = convexHull(poly, len(poly))
if c == polyA:
print("YES")
else:
print("NO")
``` | 0 |
|
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks.
Help Ivan to answer this question for several values of *x*! | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100",
"output": "NO\nNO\nYES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
},
{
"input": "3\n6\n6\n6",
"output": "YES\nYES\nYES"
},
{
"input": "47\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "3\n1\n52\n76",
"output": "NO\nYES\nYES"
},
{
"input": "87\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
},
{
"input": "3\n3\n2\n1",
"output": "YES\nNO\nNO"
},
{
"input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 1,578,898,643 | 2,147,483,647 | PyPy 3 | OK | TESTS | 8 | 140 | 0 | #903A
n = int(input())
for i in range(n):
x = int(input())
if x%3==0:
print('YES')
elif x %3== 1:
if x >= 7:
print('YES')
else:
print('NO')
else:
if x >=14:
print('YES')
else:
print('NO') | Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks.
Help Ivan to answer this question for several values of *x*!
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat.
Output Specification:
Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO.
Demo Input:
['2\n6\n5\n']
Demo Output:
['YES\nNO\n']
Note:
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | ```python
#903A
n = int(input())
for i in range(n):
x = int(input())
if x%3==0:
print('YES')
elif x %3== 1:
if x >= 7:
print('YES')
else:
print('NO')
else:
if x >=14:
print('YES')
else:
print('NO')
``` | 3 |
|
584 | A | Olesya and Rodion | PROGRAMMING | 1,000 | [
"math"
] | null | null | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1. | The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. | Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. | [
"3 2\n"
] | [
"712"
] | none | 500 | [
{
"input": "3 2",
"output": "222"
},
{
"input": "2 2",
"output": "22"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 3",
"output": "33333"
},
{
"input": "10 7",
"output": "7777777777"
},
{
"input": "2 9",
"output": "99"
},
{
"input": "18 8",
"output": "888888888888888888"
},
{
"input": "1 5",
"output": "5"
},
{
"input": "1 10",
"output": "-1"
},
{
"input": "100 5",
"output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "10 2",
"output": "2222222222"
},
{
"input": "18 10",
"output": "111111111111111110"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "7 6",
"output": "6666666"
},
{
"input": "4 4",
"output": "4444"
},
{
"input": "14 7",
"output": "77777777777777"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "2 8",
"output": "88"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 9",
"output": "99999"
},
{
"input": "4 8",
"output": "8888"
},
{
"input": "3 4",
"output": "444"
},
{
"input": "9 4",
"output": "444444444"
},
{
"input": "8 10",
"output": "11111110"
},
{
"input": "1 6",
"output": "6"
},
{
"input": "20 3",
"output": "33333333333333333333"
},
{
"input": "15 10",
"output": "111111111111110"
},
{
"input": "31 4",
"output": "4444444444444444444444444444444"
},
{
"input": "18 9",
"output": "999999999999999999"
},
{
"input": "72 4",
"output": "444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "76 8",
"output": "8888888888888888888888888888888888888888888888888888888888888888888888888888"
},
{
"input": "12 5",
"output": "555555555555"
},
{
"input": "54 5",
"output": "555555555555555555555555555555555555555555555555555555"
},
{
"input": "96 10",
"output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "15 9",
"output": "999999999999999"
},
{
"input": "100 2",
"output": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
},
{
"input": "99 3",
"output": "333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"
},
{
"input": "98 4",
"output": "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "97 5",
"output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "100 6",
"output": "6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
},
{
"input": "99 7",
"output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "98 8",
"output": "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
},
{
"input": "97 9",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
},
{
"input": "100 10",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "3 10",
"output": "110"
},
{
"input": "2 4",
"output": "44"
},
{
"input": "2 10",
"output": "10"
},
{
"input": "10 10",
"output": "1111111110"
},
{
"input": "4 10",
"output": "1110"
},
{
"input": "25 10",
"output": "1111111111111111111111110"
},
{
"input": "50 10",
"output": "11111111111111111111111111111111111111111111111110"
},
{
"input": "5 10",
"output": "11110"
},
{
"input": "99 10",
"output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "100 10",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "20 10",
"output": "11111111111111111110"
},
{
"input": "99 7",
"output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "89 5",
"output": "55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "6 10",
"output": "111110"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "100 7",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
}
] | 1,681,657,366 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 61 | 0 | n, t=(map(int,input().split()))
if n==1 and t==10:
print(-1)
elif n>=2 and t ==10:
for i in range((n-1)):
print('1',end="")
print(0)
else:
for i in range((n)):
print(t,end="")
| Title: Olesya and Rodion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1.
Input Specification:
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Output Specification:
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
Demo Input:
['3 2\n']
Demo Output:
['712']
Note:
none | ```python
n, t=(map(int,input().split()))
if n==1 and t==10:
print(-1)
elif n>=2 and t ==10:
for i in range((n-1)):
print('1',end="")
print(0)
else:
for i in range((n)):
print(t,end="")
``` | 3 |
|
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time. | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5",
"output": "5"
},
{
"input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 1 1 1 -1 1 1 -1 -1 -1 1 1 1 -1 -1 -1 1 -1 1 1",
"output": "13"
},
{
"input": "3\n-1 5 4",
"output": "1"
},
{
"input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1",
"output": "5"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n1 -1",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n-1 -1",
"output": "2"
},
{
"input": "4\n10 -1 -1 -1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "4\n-1 -1 1 1",
"output": "2"
}
] | 1,676,830,404 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 78 | 5,324,800 | num = int(input())
number = list(map(int,input().split()))
counter = 0
number_poles = 0
for i in range(len(number)):
if number[i] == -1 and number_poles == 0:
counter += 1
elif number[i] == -1 and number_poles > 0:
number_poles -= 1
else:
number_poles += number[i]
print(counter) | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input Specification:
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output Specification:
Print a single integer, the number of crimes which will go untreated.
Demo Input:
['3\n-1 -1 1\n', '8\n1 -1 1 -1 -1 1 1 1\n', '11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n']
Demo Output:
['2\n', '1\n', '8\n']
Note:
Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | ```python
num = int(input())
number = list(map(int,input().split()))
counter = 0
number_poles = 0
for i in range(len(number)):
if number[i] == -1 and number_poles == 0:
counter += 1
elif number[i] == -1 and number_poles > 0:
number_poles -= 1
else:
number_poles += number[i]
print(counter)
``` | 3 |
|
597 | A | Divisibility | PROGRAMMING | 1,600 | [
"math"
] | null | null | Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*. | The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018). | Print the required number. | [
"1 1 10\n",
"2 -4 4\n"
] | [
"10\n",
"5\n"
] | none | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "2 -4 4",
"output": "5"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 0 0",
"output": "1"
},
{
"input": "1 0 1",
"output": "2"
},
{
"input": "1 10181 10182",
"output": "2"
},
{
"input": "1 10182 10183",
"output": "2"
},
{
"input": "1 -191 1011",
"output": "1203"
},
{
"input": "2 0 0",
"output": "1"
},
{
"input": "2 0 1",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "2 2 3",
"output": "1"
},
{
"input": "2 -1 0",
"output": "1"
},
{
"input": "2 -1 1",
"output": "1"
},
{
"input": "2 -7 -6",
"output": "1"
},
{
"input": "2 -7 -5",
"output": "1"
},
{
"input": "2 -6 -6",
"output": "1"
},
{
"input": "2 -6 -4",
"output": "2"
},
{
"input": "2 -6 13",
"output": "10"
},
{
"input": "2 -19171 1911",
"output": "10541"
},
{
"input": "3 123 456",
"output": "112"
},
{
"input": "3 124 456",
"output": "111"
},
{
"input": "3 125 456",
"output": "111"
},
{
"input": "3 381 281911",
"output": "93844"
},
{
"input": "3 381 281912",
"output": "93844"
},
{
"input": "3 381 281913",
"output": "93845"
},
{
"input": "3 382 281911",
"output": "93843"
},
{
"input": "3 382 281912",
"output": "93843"
},
{
"input": "3 382 281913",
"output": "93844"
},
{
"input": "3 383 281911",
"output": "93843"
},
{
"input": "3 383 281912",
"output": "93843"
},
{
"input": "3 383 281913",
"output": "93844"
},
{
"input": "3 -381 281911",
"output": "94098"
},
{
"input": "3 -381 281912",
"output": "94098"
},
{
"input": "3 -381 281913",
"output": "94099"
},
{
"input": "3 -380 281911",
"output": "94097"
},
{
"input": "3 -380 281912",
"output": "94097"
},
{
"input": "3 -380 281913",
"output": "94098"
},
{
"input": "3 -379 281911",
"output": "94097"
},
{
"input": "3 -379 281912",
"output": "94097"
},
{
"input": "3 -379 281913",
"output": "94098"
},
{
"input": "3 -191381 -1911",
"output": "63157"
},
{
"input": "3 -191381 -1910",
"output": "63157"
},
{
"input": "3 -191381 -1909",
"output": "63157"
},
{
"input": "3 -191380 -1911",
"output": "63157"
},
{
"input": "3 -191380 -1910",
"output": "63157"
},
{
"input": "3 -191380 -1909",
"output": "63157"
},
{
"input": "3 -191379 -1911",
"output": "63157"
},
{
"input": "3 -191379 -1910",
"output": "63157"
},
{
"input": "3 -191379 -1909",
"output": "63157"
},
{
"input": "3 -2810171 0",
"output": "936724"
},
{
"input": "3 0 29101",
"output": "9701"
},
{
"input": "3 -2810170 0",
"output": "936724"
},
{
"input": "3 0 29102",
"output": "9701"
},
{
"input": "3 -2810169 0",
"output": "936724"
},
{
"input": "3 0 29103",
"output": "9702"
},
{
"input": "1 -1000000000000000000 1000000000000000000",
"output": "2000000000000000001"
},
{
"input": "2 -1000000000000000000 1000000000000000000",
"output": "1000000000000000001"
},
{
"input": "3 -1000000000000000000 1000000000000000000",
"output": "666666666666666667"
},
{
"input": "4 -1000000000000000000 1000000000000000000",
"output": "500000000000000001"
},
{
"input": "5 -1000000000000000000 1000000000000000000",
"output": "400000000000000001"
},
{
"input": "6 -1000000000000000000 1000000000000000000",
"output": "333333333333333333"
},
{
"input": "7 -1000000000000000000 1000000000000000000",
"output": "285714285714285715"
},
{
"input": "1 -1000000000000000000 -100000000000000000",
"output": "900000000000000001"
},
{
"input": "2 -1000000000000000000 -10000000000000000",
"output": "495000000000000001"
},
{
"input": "3 -1000000000000000000 -10218000000000000",
"output": "329927333333333334"
},
{
"input": "4 -1000000000000000000 -320110181919100",
"output": "249919972454520226"
},
{
"input": "5 -1000000000000000000 -402710171917",
"output": "199999919457965617"
},
{
"input": "6 -1000000000000000000 -6666666666",
"output": "166666665555555556"
},
{
"input": "7 -1000000000000000000 -77777777777778",
"output": "142846031746031746"
},
{
"input": "1000000000000000000 -1000000000000000000 1000000000000000000",
"output": "3"
},
{
"input": "1000000000000000000 0 1000000000000000000",
"output": "2"
},
{
"input": "1000000000000000000 1000000000000000000 1000000000000000000",
"output": "1"
},
{
"input": "100000000000000321 1000000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "100000000000000321 -1000000000000000000 1000000000000000000",
"output": "19"
},
{
"input": "1000000000000000000 0 0",
"output": "1"
},
{
"input": "1000000000000000000 1 1",
"output": "0"
},
{
"input": "1000000000000000000 -1 -1",
"output": "0"
},
{
"input": "1000000000000000000 -2 -1",
"output": "0"
},
{
"input": "142000000000000271 -228118171 -1382811",
"output": "0"
},
{
"input": "1 1 1000000000000000000",
"output": "1000000000000000000"
}
] | 1,585,834,959 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 155 | 0 | print((lambda x : (x[2]//x[0])-((x[1]-1)//x[0]))(list(map(int,input().split())))) | Title: Divisibility
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*.
Input Specification:
The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018).
Output Specification:
Print the required number.
Demo Input:
['1 1 10\n', '2 -4 4\n']
Demo Output:
['10\n', '5\n']
Note:
none | ```python
print((lambda x : (x[2]//x[0])-((x[1]-1)//x[0]))(list(map(int,input().split()))))
``` | 3 |
|
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.
The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.
Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning. | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100. | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": "YES"
},
{
"input": "ONDOL\nJNPB\nONLNJBODP",
"output": "YES"
},
{
"input": "Y\nW\nYW",
"output": "YES"
},
{
"input": "OI\nM\nIMO",
"output": "YES"
},
{
"input": "VFQRWWWACX\nGHZJPOQUSXRAQDGOGMR\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF",
"output": "YES"
},
{
"input": "JUTCN\nPIGMZOPMEUFADQBW\nNWQGZMAIPUPOMCDUB",
"output": "NO"
},
{
"input": "Z\nO\nZOCNDOLTBZKQLTBOLDEGXRHZGTTPBJBLSJCVSVXISQZCSFDEBXRCSGBGTHWOVIXYHACAGBRYBKBJAEPIQZHVEGLYH",
"output": "NO"
},
{
"input": "IQ\nOQ\nQOQIGGKFNHJSGCGM",
"output": "NO"
},
{
"input": "ROUWANOPNIGTVMIITVMZ\nOQTUPZMTKUGY\nVTVNGZITGPUNPMQOOATUUIYIWMMKZOTR",
"output": "YES"
},
{
"input": "OVQELLOGFIOLEHXMEMBJDIGBPGEYFG\nJNKFPFFIJOFHRIFHXEWYZOPDJBZTJZKBWQTECNHRFSJPJOAPQT\nYAIPFFFEXJJNEJPLREIGODEGQZVMCOBDFKWTMWJSBEBTOFFQOHIQJLHFNXIGOHEZRZLFOKJBJPTPHPGY",
"output": "YES"
},
{
"input": "NBJGVNGUISUXQTBOBKYHQCOOVQWUXWPXBUDLXPKX\nNSFQDFUMQDQWQ\nWXKKVNTDQQFXCUQBIMQGQHSLVGWSBFYBUPOWPBDUUJUXQNOQDNXOX",
"output": "YES"
},
{
"input": "IJHHGKCXWDBRWJUPRDBZJLNTTNWKXLUGJSBWBOAUKWRAQWGFNL\nNJMWRMBCNPHXTDQQNZ\nWDNJRCLILNQRHWBANLTXWMJBPKUPGKJDJZAQWKTZFBRCTXHHBNXRGUQUNBNMWODGSJWW",
"output": "YES"
},
{
"input": "SRROWANGUGZHCIEFYMQVTWVOMDWPUZJFRDUMVFHYNHNTTGNXCJ\nDJYWGLBFCCECXFHOLORDGDCNRHPWXNHXFCXQCEZUHRRNAEKUIX\nWCUJDNYHNHYOPWMHLDCDYRWBVOGHFFUKOZTXJRXJHRGWICCMRNEVNEGQWTZPNFCSHDRFCFQDCXMHTLUGZAXOFNXNVGUEXIACRERU",
"output": "YES"
},
{
"input": "H\nJKFGHMIAHNDBMFXWYQLZRSVNOTEGCQSVUBYUOZBTNKTXPFQDCMKAGFITEUGOYDFIYQIORMFJEOJDNTFVIQEBICSNGKOSNLNXJWC\nBQSVDOGIHCHXSYNYTQFCHNJGYFIXTSOQINZOKSVQJMTKNTGFNXAVTUYEONMBQMGJLEWJOFGEARIOPKFUFCEMUBRBDNIIDFZDCLWK",
"output": "YES"
},
{
"input": "DSWNZRFVXQ\nPVULCZGOOU\nUOLVZXNUPOQRZGWFVDSCANQTCLEIE",
"output": "NO"
},
{
"input": "EUHTSCENIPXLTSBMLFHD\nIZAVSZPDLXOAGESUSE\nLXAELAZ",
"output": "NO"
},
{
"input": "WYSJFEREGELSKRQRXDXCGBODEFZVSI\nPEJKMGFLBFFDWRCRFSHVEFLEBTJCVCHRJTLDTISHPOGFWPLEWNYJLMXWIAOTYOXMV\nHXERTZWLEXTPIOTFRVMEJVYFFJLRPFMXDEBNSGCEOFFCWTKIDDGCFYSJKGLHBORWEPLDRXRSJYBGASSVCMHEEJFLVI",
"output": "NO"
},
{
"input": "EPBMDIUQAAUGLBIETKOKFLMTCVEPETWJRHHYKCKU\nHGMAETVPCFZYNNKDQXVXUALHYLOTCHM\nECGXACVKEYMCEDOTMKAUFHLHOMT",
"output": "NO"
},
{
"input": "NUBKQEJHALANSHEIFUZHYEZKKDRFHQKAJHLAOWTZIMOCWOVVDW\nEFVOBIGAUAUSQGVSNBKNOBDMINODMFSHDL\nKLAMKNTHBFFOHVKWICHBKNDDQNEISODUSDNLUSIOAVWY",
"output": "NO"
},
{
"input": "VXINHOMEQCATZUGAJEIUIZZLPYFGUTVLNBNWCUVMEENUXKBWBGZTMRJJVJDLVSLBABVCEUDDSQFHOYPYQTWVAGTWOLKYISAGHBMC\nZMRGXPZSHOGCSAECAPGVOIGCWEOWWOJXLGYRDMPXBLOKZVRACPYQLEQGFQCVYXAGBEBELUTDAYEAGPFKXRULZCKFHZCHVCWIRGPK\nRCVUXGQVNWFGRUDLLENNDQEJHYYVWMKTLOVIPELKPWCLSQPTAXAYEMGWCBXEVAIZGGDDRBRT",
"output": "NO"
},
{
"input": "PHBDHHWUUTZAHELGSGGOPOQXSXEZIXHZTOKYFBQLBDYWPVCNQSXHEAXRRPVHFJBVBYCJIFOTQTWSUOWXLKMVJJBNLGTVITWTCZZ\nFUPDLNVIHRWTEEEHOOEC\nLOUSUUSZCHJBPEWIILUOXEXRQNCJEGTOBRVZLTTZAHTKVEJSNGHFTAYGY",
"output": "NO"
},
{
"input": "GDSLNIIKTO\nJF\nPDQYFKDTNOLI",
"output": "NO"
},
{
"input": "AHOKHEKKPJLJIIWJRCGY\nORELJCSIX\nZVWPXVFWFSWOXXLIHJKPXIOKRELYE",
"output": "NO"
},
{
"input": "ZWCOJFORBPHXCOVJIDPKVECMHVHCOC\nTEV\nJVGTBFTLFVIEPCCHODOFOMCVZHWXVCPEH",
"output": "NO"
},
{
"input": "AGFIGYWJLVMYZGNQHEHWKJIAWBPUAQFERMCDROFN\nPMJNHMVNRGCYZAVRWNDSMLSZHFNYIUWFPUSKKIGU\nMCDVPPRXGUAYLSDRHRURZASXUWZSIIEZCPXUVEONKNGNWRYGOSFMCKESMVJZHWWUCHWDQMLASLNNMHAU",
"output": "NO"
},
{
"input": "XLOWVFCZSSXCSYQTIIDKHNTKNKEEDFMDZKXSPVLBIDIREDUAIN\nZKIWNDGBISDB\nSLPKLYFYSRNRMOSWYLJJDGFFENPOXYLPZFTQDANKBDNZDIIEWSUTTKYBKVICLG",
"output": "NO"
},
{
"input": "PMUKBTRKFIAYVGBKHZHUSJYSSEPEOEWPOSPJLWLOCTUYZODLTUAFCMVKGQKRRUSOMPAYOTBTFPXYAZXLOADDEJBDLYOTXJCJYTHA\nTWRRAJLCQJTKOKWCGUH\nEWDPNXVCXWCDQCOYKKSOYTFSZTOOPKPRDKFJDETKSRAJRVCPDOBWUGPYRJPUWJYWCBLKOOTUPBESTOFXZHTYLLMCAXDYAEBUTAHM",
"output": "NO"
},
{
"input": "QMIMGQRQDMJDPNFEFXSXQMCHEJKTWCTCVZPUAYICOIRYOWKUSIWXJLHDYWSBOITHTMINXFKBKAWZTXXBJIVYCRWKXNKIYKLDDXL\nV\nFWACCXBVDOJFIUAVYRALBYJKXXWIIFORRUHKHCXLDBZMXIYJWISFEAWTIQFIZSBXMKNOCQKVKRWDNDAMQSTKYLDNYVTUCGOJXJTW",
"output": "NO"
},
{
"input": "XJXPVOOQODELPPWUISSYVVXRJTYBPDHJNENQEVQNVFIXSESKXVYPVVHPMOSX\nLEXOPFPVPSZK\nZVXVPYEYOYXVOISVLXPOVHEQVXPNQJIOPFDTXEUNMPEPPHELNXKKWSVSOXSBPSJDPVJVSRFQ",
"output": "YES"
},
{
"input": "OSKFHGYNQLSRFSAHPXKGPXUHXTRBJNAQRBSSWJVEENLJCDDHFXVCUNPZAIVVO\nFNUOCXAGRRHNDJAHVVLGGEZQHWARYHENBKHP\nUOEFNWVXCUNERLKVTHAGPSHKHDYFPYWZHJKHQLSNFBJHVJANRXCNSDUGVDABGHVAOVHBJZXGRACHRXEGNRPQEAPORQSILNXFS",
"output": "YES"
},
{
"input": "VYXYVVACMLPDHONBUTQFZTRREERBLKUJYKAHZRCTRLRCLOZYWVPBRGDQPFPQIF\nFE\nRNRPEVDRLYUQFYRZBCQLCYZEABKLRXCJLKVZBVFUEYRATOMDRTHFPGOWQVTIFPPH",
"output": "YES"
},
{
"input": "WYXUZQJQNLASEGLHPMSARWMTTQMQLVAZLGHPIZTRVTCXDXBOLNXZPOFCTEHCXBZ\nBLQZRRWP\nGIQZXPLTTMNHQVWPPEAPLOCDMBSTHRCFLCQRRZXLVAOQEGZBRUZJXXZTMAWLZHSLWNQTYXB",
"output": "YES"
},
{
"input": "MKVJTSSTDGKPVVDPYSRJJYEVGKBMSIOKHLZQAEWLRIBINVRDAJIBCEITKDHUCCVY\nPUJJQFHOGZKTAVNUGKQUHMKTNHCCTI\nQVJKUSIGTSVYUMOMLEGHWYKSKQTGATTKBNTKCJKJPCAIRJIRMHKBIZISEGFHVUVQZBDERJCVAKDLNTHUDCHONDCVVJIYPP",
"output": "YES"
},
{
"input": "OKNJOEYVMZXJMLVJHCSPLUCNYGTDASKSGKKCRVIDGEIBEWRVBVRVZZTLMCJLXHJIA\nDJBFVRTARTFZOWN\nAGHNVUNJVCPLWSVYBJKZSVTFGLELZASLWTIXDDJXCZDICTVIJOTMVEYOVRNMJGRKKHRMEBORAKFCZJBR",
"output": "YES"
},
{
"input": "OQZACLPSAGYDWHFXDFYFRRXWGIEJGSXWUONAFWNFXDTGVNDEWNQPHUXUJNZWWLBPYL\nOHBKWRFDRQUAFRCMT\nWIQRYXRJQWWRUWCYXNXALKFZGXFTLOODWRDPGURFUFUQOHPWBASZNVWXNCAGHWEHFYESJNFBMNFDDAPLDGT",
"output": "YES"
},
{
"input": "OVIRQRFQOOWVDEPLCJETWQSINIOPLTLXHSQWUYUJNFBMKDNOSHNJQQCDHZOJVPRYVSV\nMYYDQKOOYPOOUELCRIT\nNZSOTVLJTTVQLFHDQEJONEOUOFOLYVSOIYUDNOSIQVIRMVOERCLMYSHPCQKIDRDOQPCUPQBWWRYYOXJWJQPNKH",
"output": "YES"
},
{
"input": "WGMBZWNMSJXNGDUQUJTCNXDSJJLYRDOPEGPQXYUGBESDLFTJRZDDCAAFGCOCYCQMDBWK\nYOBMOVYTUATTFGJLYUQD\nDYXVTLQCYFJUNJTUXPUYOPCBCLBWNSDUJRJGWDOJDSQAAMUOJWSYERDYDXYTMTOTMQCGQZDCGNFBALGGDFKZMEBG",
"output": "YES"
},
{
"input": "CWLRBPMEZCXAPUUQFXCUHAQTLPBTXUUKWVXKBHKNSSJFEXLZMXGVFHHVTPYAQYTIKXJJE\nMUFOSEUEXEQTOVLGDSCWM\nJUKEQCXOXWEHCGKFPBIGMWVJLXUONFXBYTUAXERYTXKCESKLXAEHVPZMMUFTHLXTTZSDMBJLQPEUWCVUHSQQVUASPF",
"output": "YES"
},
{
"input": "IDQRX\nWETHO\nODPDGBHVUVSSISROHQJTUKPUCLXABIZQQPPBPKOSEWGEHRSRRNBAVLYEMZISMWWGKHVTXKUGUXEFBSWOIWUHRJGMWBMHQLDZHBWA",
"output": "NO"
},
{
"input": "IXFDY\nJRMOU\nDF",
"output": "NO"
},
{
"input": "JPSPZ\nUGCUB\nJMZZZZZZZZ",
"output": "NO"
},
{
"input": "AC\nA\nBBA",
"output": "NO"
},
{
"input": "UIKWWKXLSHTOOZOVGXKYSOJEHAUEEG\nKZXQDWJJWRXFHKJDQHJK\nXMZHTFOGEXAUJXXJUYVJIFOTKLZHDKELJWERHMGAWGKWAQKEKHIDWGGZVYOHKXRPWSJDPESFJUMKQYWBYUTHQYEFZUGKQOBHYDWB",
"output": "NO"
},
{
"input": "PXWRXRPFLR\nPJRWWXIVHODV\nXW",
"output": "NO"
},
{
"input": "CHTAZVHGSHCVIBK\nEQINEBKXEPYJSAZIMLDF\nZCZZZZDZMCZZEZDZZEZZZZQZZBZZZOZZCZE",
"output": "NO"
},
{
"input": "GXPZFSELJJNDAXYRV\nUYBKPMVBSOVOJWMONLTJOJCNQKMTAHEWLHOWIIBH\nHCWNFWJPEJIWOVPTBMVCRJLSISSVNOHCKLBFMIUAIMASQWPXEYXBOXQGFEMYJLBKDCZIMJNHOJEDGGANIVYKQTUOSOVOPWHVJGXH",
"output": "NO"
},
{
"input": "LFGJCJJDUTUP\nOVSBILTIYCJCRHKCIXCETJQJJ\nGIJJTJCLTJJJ",
"output": "NO"
},
{
"input": "GIO\nPRL\nPRL",
"output": "NO"
},
{
"input": "A\nB\nABC",
"output": "NO"
},
{
"input": "KKK\nKKK\nZZZZZ",
"output": "NO"
},
{
"input": "ZMYGQLDBLAPN\nZFJBKWHROVNPSJQUDFTHOCGREUFLYIWYICD\nZMJZZEDAZANKZZZZZZEZZBZDZZZZZZKHZZFZZZDZNZMDZZA",
"output": "NO"
}
] | 1,690,797,405 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | a = input("")
b = input("")
d = input("")
c = 0
for i in d:
if a.count(i) + b.count(i) != d.count(i):
c += 1
print("NO")
break
else:
a.replace(i, "")
b.replace(i, "")
d.replace(i, "")
if c == 0 and b == "" and a == "":
print("YES")
else:
print("NO") | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.
The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.
Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.
Input Specification:
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.
Output Specification:
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
Demo Input:
['SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n', 'PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n', 'BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | ```python
a = input("")
b = input("")
d = input("")
c = 0
for i in d:
if a.count(i) + b.count(i) != d.count(i):
c += 1
print("NO")
break
else:
a.replace(i, "")
b.replace(i, "")
d.replace(i, "")
if c == 0 and b == "" and a == "":
print("YES")
else:
print("NO")
``` | 0 |
|
989 | A | A Blend of Springtime | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order. | The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. | Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
".BAC.\n",
"AA..CB\n"
] | [
"Yes\n",
"No\n"
] | In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | 500 | [
{
"input": ".BAC.",
"output": "Yes"
},
{
"input": "AA..CB",
"output": "No"
},
{
"input": ".",
"output": "No"
},
{
"input": "ACB.AAAAAA",
"output": "Yes"
},
{
"input": "B.BC.BBBCA",
"output": "Yes"
},
{
"input": "BA..CAB..B",
"output": "Yes"
},
{
"input": "CACCBAA.BC",
"output": "Yes"
},
{
"input": ".CAACCBBA.CBB.AC..BABCCBCCB..B.BC..CBC.CA.CC.C.CC.B.A.CC.BBCCBB..ACAACAC.CBCCB.AABAAC.CBCC.BA..CCBC.",
"output": "Yes"
},
{
"input": "A",
"output": "No"
},
{
"input": "..",
"output": "No"
},
{
"input": "BC",
"output": "No"
},
{
"input": "CAB",
"output": "Yes"
},
{
"input": "A.CB",
"output": "No"
},
{
"input": "B.ACAA.CA..CBCBBAA.B.CCBCB.CAC.ABC...BC.BCCC.BC.CB",
"output": "Yes"
},
{
"input": "B.B...CC.B..CCCB.CB..CBCB..CBCC.CCBC.B.CB..CA.C.C.",
"output": "No"
},
{
"input": "AA.CBAABABCCC..B..B.ABBABAB.B.B.CCA..CB.B...A..CBC",
"output": "Yes"
},
{
"input": "CA.ABB.CC.B.C.BBBABAAB.BBBAACACAAA.C.AACA.AAC.C.BCCB.CCBC.C..CCACA.CBCCB.CCAABAAB.AACAA..A.AAA.",
"output": "No"
},
{
"input": "CBC...AC.BBBB.BBABABA.CAAACC.AAABB..A.BA..BC.CBBBC.BBBBCCCAA.ACCBB.AB.C.BA..CC..AAAC...AB.A.AAABBA.A",
"output": "No"
},
{
"input": "CC.AAAC.BA.BBB.AABABBCCAA.A.CBCCB.B.BC.ABCBCBBAA.CACA.CCCA.CB.CCB.A.BCCCB...C.A.BCCBC..B.ABABB.C.BCB",
"output": "Yes"
},
{
"input": "CCC..A..CACACCA.CA.ABAAB.BBA..C.AAA...ACB.ACA.CA.B.AB.A..C.BC.BC.A.C....ABBCCACCCBCC.BBBAA.ACCACB.BB",
"output": "Yes"
},
{
"input": "BC.ABACAACC..AC.A..CCCAABBCCACAC.AA.CC.BAABABABBCBB.BA..C.C.C.A.BBA.C..BC.ACACCC.AAAACCCCC.AAC.AC.AB",
"output": "Yes"
},
{
"input": "ACAC.BAA.C..CAAC..ABBAACC..BAA...CC...ACCBBCA.BAABABAACCAC.A.BBCACCC..BCB.BABAAAACCBCB.BCAABBC.C.BBB",
"output": "Yes"
},
{
"input": "CCAC.BCBC.A.ABBAB.C.C.BC.CCABBCBCCBC..B.AA.C.BC...B..BAA.ACCCCBBB.AAAACA.CAACCB.CCB.CC.BCCAB.BBBBABB",
"output": "Yes"
},
{
"input": ".AACAA.AAAAC.BBBB.BC...CCACCACAAA.A..CCA..BCC.AB.ABAAB..AABA...B.C.CBAB.BAAB.A.C.AAC.BBBA.ACAAA.BB.C",
"output": "Yes"
},
{
"input": "CC.ACCC.BCCCCAA.BBAACB.ABABAAAA.A.CBAB.CBACBBC..C.CA.AAA..AA..ABBB.A.C..CBBCAAACC.B..CC.AC..CAABACB.",
"output": "Yes"
},
{
"input": ".BAB.",
"output": "No"
},
{
"input": "BBBBBBBBB",
"output": "No"
},
{
"input": "..AAC..",
"output": "No"
},
{
"input": ".AAABBBCCC.",
"output": "No"
},
{
"input": "AAABC",
"output": "Yes"
},
{
"input": "BBB",
"output": "No"
},
{
"input": "AAAAABABAAAAA",
"output": "No"
},
{
"input": "AABBCC",
"output": "No"
},
{
"input": ".BA",
"output": "No"
},
{
"input": "CAAAAB",
"output": "No"
}
] | 1,590,471,248 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 124 | 0 | s=input()
n=len(s)
f=0
for i in range(n-2):
if(ord(s[i])+ord(s[i+1])+ord(s[i+2])==198 and s[i]!=s[i+1]):
f=1
break
if(f==0):
print("NO")
else:
print("YES") | Title: A Blend of Springtime
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input Specification:
The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output Specification:
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Demo Input:
['.BAC.\n', 'AA..CB\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | ```python
s=input()
n=len(s)
f=0
for i in range(n-2):
if(ord(s[i])+ord(s[i+1])+ord(s[i+2])==198 and s[i]!=s[i+1]):
f=1
break
if(f==0):
print("NO")
else:
print("YES")
``` | 3 |
|
841 | B | Godsend | PROGRAMMING | 1,100 | [
"games",
"math"
] | null | null | Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally? | First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array.
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | [
"4\n1 3 2 3\n",
"2\n2 2\n"
] | [
"First\n",
"Second\n"
] | In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | 1,000 | [
{
"input": "4\n1 3 2 3",
"output": "First"
},
{
"input": "2\n2 2",
"output": "Second"
},
{
"input": "4\n2 4 6 8",
"output": "Second"
},
{
"input": "5\n1 1 1 1 1",
"output": "First"
},
{
"input": "4\n720074544 345031254 849487632 80870826",
"output": "Second"
},
{
"input": "1\n0",
"output": "Second"
},
{
"input": "1\n999999999",
"output": "First"
},
{
"input": "2\n1 999999999",
"output": "First"
},
{
"input": "4\n3 3 4 4",
"output": "First"
},
{
"input": "2\n1 2",
"output": "First"
},
{
"input": "8\n2 2 2 1 1 2 2 2",
"output": "First"
},
{
"input": "5\n3 3 2 2 2",
"output": "First"
},
{
"input": "4\n0 1 1 0",
"output": "First"
},
{
"input": "3\n1 2 2",
"output": "First"
},
{
"input": "6\n2 2 1 1 4 2",
"output": "First"
},
{
"input": "8\n2 2 2 3 3 2 2 2",
"output": "First"
},
{
"input": "4\n2 3 3 4",
"output": "First"
},
{
"input": "10\n2 2 2 2 3 1 2 2 2 2",
"output": "First"
},
{
"input": "6\n2 2 1 1 2 2",
"output": "First"
},
{
"input": "3\n1 1 2",
"output": "First"
},
{
"input": "6\n2 4 3 3 4 6",
"output": "First"
},
{
"input": "6\n4 4 3 3 4 4",
"output": "First"
},
{
"input": "4\n1 1 2 2",
"output": "First"
},
{
"input": "4\n1 3 5 7",
"output": "First"
},
{
"input": "4\n2 1 1 2",
"output": "First"
},
{
"input": "4\n1 3 3 2",
"output": "First"
},
{
"input": "5\n3 2 2 2 2",
"output": "First"
},
{
"input": "3\n2 1 1",
"output": "First"
},
{
"input": "4\n1000000000 1000000000 1000000000 99999999",
"output": "First"
},
{
"input": "4\n2 2 1 1",
"output": "First"
},
{
"input": "5\n2 3 2 3 2",
"output": "First"
},
{
"input": "1\n1",
"output": "First"
},
{
"input": "4\n1000000000 1000000000 1000000000 1",
"output": "First"
},
{
"input": "5\n2 2 2 1 1",
"output": "First"
},
{
"input": "6\n2 1 1 1 1 2",
"output": "First"
},
{
"input": "6\n1 2 2 2 2 1",
"output": "First"
},
{
"input": "11\n2 2 2 2 2 1 2 2 2 2 2",
"output": "First"
},
{
"input": "5\n1 3 2 2 2",
"output": "First"
},
{
"input": "3\n2 3 2",
"output": "First"
},
{
"input": "2\n1 1",
"output": "First"
},
{
"input": "5\n4 4 4 3 3",
"output": "First"
},
{
"input": "5\n3 3 4 4 4",
"output": "First"
},
{
"input": "1\n2",
"output": "Second"
}
] | 1,669,880,878 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 576 | 69,529,600 | n=int(input())
p=list(map(int, input().split()))
eve=0
odd=0
for i in p:
if i%2==0:
eve+=1
else:
odd+=1
if eve > odd:
print("Second")
else:
print("First") | Title: Godsend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?
Input Specification:
First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array.
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
Output Specification:
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
Demo Input:
['4\n1 3 2 3\n', '2\n2 2\n']
Demo Output:
['First\n', 'Second\n']
Note:
In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | ```python
n=int(input())
p=list(map(int, input().split()))
eve=0
odd=0
for i in p:
if i%2==0:
eve+=1
else:
odd+=1
if eve > odd:
print("Second")
else:
print("First")
``` | 0 |
|
327 | A | Flipping Game | PROGRAMMING | 1,200 | [
"brute force",
"dp",
"implementation"
] | null | null | Iahub got bored, so he invented a game to be played on paper.
He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in range [*i*,<=*j*] (that is *i*<=≤<=*k*<=≤<=*j*). Flip the value of *x* means to apply operation *x*<==<=1 - *x*.
The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1. | Print an integer — the maximal number of 1s that can be obtained after exactly one move. | [
"5\n1 0 0 1 0\n",
"4\n1 0 0 1\n"
] | [
"4\n",
"4\n"
] | In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1].
In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all numbers into 1. | 500 | [
{
"input": "5\n1 0 0 1 0",
"output": "4"
},
{
"input": "4\n1 0 0 1",
"output": "4"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "8\n1 0 0 0 1 0 0 0",
"output": "7"
},
{
"input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "18"
},
{
"input": "23\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "22"
},
{
"input": "100\n0 1 0 1 1 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1",
"output": "70"
},
{
"input": "100\n0 1 1 0 1 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 0 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0 0 0 1 1 1 1",
"output": "60"
},
{
"input": "18\n0 1 0 1 0 1 0 1 0 1 1 0 1 1 0 1 1 0",
"output": "11"
},
{
"input": "25\n0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1",
"output": "18"
},
{
"input": "55\n0 0 1 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 1 0 0 0 0 1 1 0 1 1 1 1",
"output": "36"
},
{
"input": "75\n1 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 0 0 1 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 0",
"output": "44"
},
{
"input": "100\n0 0 1 0 1 0 0 1 1 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1 0 1",
"output": "61"
},
{
"input": "100\n0 0 0 1 0 0 0 1 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 1 0 1 1 0",
"output": "61"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "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": "99"
},
{
"input": "100\n0 0 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 1 0 1 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 0 0 0 1 0",
"output": "61"
},
{
"input": "100\n0 1 1 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 1",
"output": "59"
},
{
"input": "99\n1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 1 1 1",
"output": "61"
},
{
"input": "2\n1 1",
"output": "1"
}
] | 1,666,338,048 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n = int(input())
nums = [int(i) for i in input().split()]
max_zero = 0
less_ones = 0
has_no_zero = True
for i in range(n):
for j in range(i, n):
now_zero = nums[i:j].count(0) - nums[i:j].count(1)
if now_zero > max_zero:
max_zero = now_zero
less_ones = nums[i:j].count(1)
has_no_zero = False
if has_no_zero:
print(nums.count(1) - 1)
else:
print(max_zero + nums.count(1) - less_ones)
| Title: Flipping Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub got bored, so he invented a game to be played on paper.
He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in range [*i*,<=*j*] (that is *i*<=≤<=*k*<=≤<=*j*). Flip the value of *x* means to apply operation *x*<==<=1 - *x*.
The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1.
Output Specification:
Print an integer — the maximal number of 1s that can be obtained after exactly one move.
Demo Input:
['5\n1 0 0 1 0\n', '4\n1 0 0 1\n']
Demo Output:
['4\n', '4\n']
Note:
In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1].
In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all numbers into 1. | ```python
n = int(input())
nums = [int(i) for i in input().split()]
max_zero = 0
less_ones = 0
has_no_zero = True
for i in range(n):
for j in range(i, n):
now_zero = nums[i:j].count(0) - nums[i:j].count(1)
if now_zero > max_zero:
max_zero = now_zero
less_ones = nums[i:j].count(1)
has_no_zero = False
if has_no_zero:
print(nums.count(1) - 1)
else:
print(max_zero + nums.count(1) - less_ones)
``` | 0 |
|
373 | A | Collecting Beats is Fun | PROGRAMMING | 900 | [
"implementation"
] | null | null | Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail.
You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing. | The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If period was written on the panel, he doesn't have to press that panel. | Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes). | [
"1\n.135\n1247\n3468\n5789\n",
"5\n..1.\n1111\n..1.\n..1.\n",
"1\n....\n12.1\n.2..\n.2..\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | 500 | [
{
"input": "1\n.135\n1247\n3468\n5789",
"output": "YES"
},
{
"input": "5\n..1.\n1111\n..1.\n..1.",
"output": "YES"
},
{
"input": "1\n....\n12.1\n.2..\n.2..",
"output": "NO"
},
{
"input": "1\n6981\n.527\n4163\n2345",
"output": "YES"
},
{
"input": "5\n9999\n9999\n9999\n9999",
"output": "NO"
},
{
"input": "2\n4444\n3333\n2222\n1111",
"output": "YES"
},
{
"input": "3\n2123\n1232\n2321\n3213",
"output": "NO"
},
{
"input": "2\n1...\n.1..\n..1.\n...1",
"output": "YES"
},
{
"input": "2\n1.1.\n.1.1\n2.2.\n.222",
"output": "NO"
},
{
"input": "1\n1..2\n.3.4\n567.\n.89.",
"output": "YES"
},
{
"input": "1\n1122\n3344\n5588\n6699",
"output": "YES"
},
{
"input": "4\n1111\n1221\n1221\n1111",
"output": "NO"
},
{
"input": "5\n3141\n5926\n5358\n9793",
"output": "YES"
},
{
"input": "5\n5454\n4343\n3232\n2121",
"output": "YES"
},
{
"input": "5\n1222\n2221\n2221\n1122",
"output": "NO"
},
{
"input": "1\n....\n5..5\n6..6\n7..7",
"output": "YES"
},
{
"input": "1\n9875\n8643\n7421\n531.",
"output": "YES"
},
{
"input": "1\n..1.\n..1.\n..1.\n..1.",
"output": "NO"
},
{
"input": "4\n4.4.\n4.4.\n4444\n..4.",
"output": "NO"
},
{
"input": "5\n4.4.\n4.4.\n4444\n..4.",
"output": "YES"
},
{
"input": "3\n1.1.\n.1.1\n1.1.\n.1.1",
"output": "NO"
},
{
"input": "2\n1131\n4412\n2569\n3478",
"output": "YES"
},
{
"input": "2\n8888\n8888\n8888\n8888",
"output": "NO"
}
] | 1,606,121,918 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 155 | 0 | # https://codeforces.com/problemset/problem/373/A
# 900
n = int(input())
n2 = n * 2
x = {}
o = "YES"
for _ in range(4):
r = input()
for c in r:
if c == ".":
continue
x.setdefault(c, 0)
x[c] += 1
if x[c] > n2:
o = "NO"
break
print(o)
| Title: Collecting Beats is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail.
You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing.
Input Specification:
The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If period was written on the panel, he doesn't have to press that panel.
Output Specification:
Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes).
Demo Input:
['1\n.135\n1247\n3468\n5789\n', '5\n..1.\n1111\n..1.\n..1.\n', '1\n....\n12.1\n.2..\n.2..\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | ```python
# https://codeforces.com/problemset/problem/373/A
# 900
n = int(input())
n2 = n * 2
x = {}
o = "YES"
for _ in range(4):
r = input()
for c in r:
if c == ".":
continue
x.setdefault(c, 0)
x[c] += 1
if x[c] > n2:
o = "NO"
break
print(o)
``` | 3 |
|
722 | C | Destroying Array | PROGRAMMING | 1,600 | [
"data structures",
"dsu"
] | null | null | You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed.
After each element is destroyed you have to find out the segment of the array, such that it contains no destroyed elements and the sum of its elements is maximum possible. The sum of elements in the empty segment is considered to be 0. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements. | Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed. | [
"4\n1 3 2 5\n3 4 1 2\n",
"5\n1 2 3 4 5\n4 2 3 5 1\n",
"8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n"
] | [
"5\n4\n3\n0\n",
"6\n5\n5\n1\n0\n",
"18\n16\n11\n8\n8\n6\n6\n0\n"
] | Consider the first sample:
1. Third element is destroyed. Array is now 1 3 * 5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3 * * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now * 3 * * . Segment with maximum sum 3 consists of one integer 3. 1. Last element is destroyed. At this moment there are no valid nonempty segments left in this array, so the answer is equal to 0. | 1,000 | [
{
"input": "4\n1 3 2 5\n3 4 1 2",
"output": "5\n4\n3\n0"
},
{
"input": "5\n1 2 3 4 5\n4 2 3 5 1",
"output": "6\n5\n5\n1\n0"
},
{
"input": "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6",
"output": "18\n16\n11\n8\n8\n6\n6\n0"
},
{
"input": "10\n3 3 3 5 6 9 3 1 7 3\n3 4 6 7 5 1 10 9 2 8",
"output": "34\n29\n14\n11\n11\n11\n8\n3\n1\n0"
},
{
"input": "17\n12 9 17 5 0 6 5 1 3 1 17 17 2 14 5 1 17\n3 7 5 8 12 9 15 13 11 14 6 16 17 1 10 2 4",
"output": "94\n78\n78\n77\n39\n39\n21\n21\n21\n21\n21\n21\n21\n9\n9\n5\n0"
},
{
"input": "17\n1 6 9 2 10 5 15 16 17 14 17 3 9 8 12 0 2\n9 13 15 14 16 17 11 10 12 4 6 5 7 8 2 3 1",
"output": "65\n64\n64\n64\n64\n64\n64\n64\n64\n46\n31\n31\n16\n16\n9\n1\n0"
},
{
"input": "17\n10 10 3 9 8 0 10 13 11 8 11 1 6 9 2 10 5\n9 4 13 2 6 15 11 5 16 10 7 3 14 1 12 8 17",
"output": "63\n52\n31\n31\n26\n23\n23\n23\n23\n23\n13\n13\n13\n13\n13\n5\n0"
},
{
"input": "10\n10 4 9 0 7 5 10 3 10 9\n5 2 8 1 3 9 6 10 4 7",
"output": "37\n37\n19\n19\n19\n15\n10\n10\n10\n0"
},
{
"input": "10\n3 10 9 2 6 8 4 4 1 9\n5 8 6 7 9 10 2 1 3 4",
"output": "26\n24\n24\n24\n24\n24\n11\n11\n2\n0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "7\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 2 3 4 5 6 7",
"output": "6000000000\n5000000000\n4000000000\n3000000000\n2000000000\n1000000000\n0"
}
] | 1,476,783,916 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 5,324,800 | size = int(input())
num = list(map(int, input().split(" ")))
rem = list(map(lambda x: int(x) - 1, input().split(" ")))
def getTree(lst, l, r):
if l == r:
return {"s": lst[l], "li": l, "ri": r}
c = int((l + r) / 2)
lt = getTree(lst, l, c)
rt = getTree(lst, c + 1, r)
return {
"li": l, "ri": r,
"s": lt["s"] + rt["s"],
"l": lt,
"r": rt
}
def subsum(tree, l, r):
if tree["li"] == l and tree["ri"] == r:
return tree["s"]
c = int ((tree["ri"] + tree["li"]) / 2)
if l >= tree["li"] and r <= c:
return subsum(tree["l"], l, r)
elif l > c and r <= tree["ri"]:
return subsum(tree["r"], l, r)
else:
return subsum(tree["l"], l, c) + subsum(tree["r"], c + 1, r)
def remove(tree, i, s):
tree["s"] -= s
if "r" in tree and "l" in tree:
c = int((tree["ri"] + tree["li"]) / 2)
if i <= c:
remove(tree["l"], i, s)
else:
remove(tree["r"], i, s)
ll = len(num) - 1
tree = getTree(num, 0, ll)
parts = []
for i in rem:
remove (tree, i, num[i])
parts.append(i)
parts = sorted(parts)
x0 = 0
ss = -1
for r in range(len(parts)):
x1 = parts[r]
ss = max(ss, subsum(tree, x0, x1))
x0 = x1
ss = max(ss, subsum(tree, x0, ll))
print(ss)
| Title: Destroying Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed.
After each element is destroyed you have to find out the segment of the array, such that it contains no destroyed elements and the sum of its elements is maximum possible. The sum of elements in the empty segment is considered to be 0.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements.
Output Specification:
Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed.
Demo Input:
['4\n1 3 2 5\n3 4 1 2\n', '5\n1 2 3 4 5\n4 2 3 5 1\n', '8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n']
Demo Output:
['5\n4\n3\n0\n', '6\n5\n5\n1\n0\n', '18\n16\n11\n8\n8\n6\n6\n0\n']
Note:
Consider the first sample:
1. Third element is destroyed. Array is now 1 3 * 5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3 * * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now * 3 * * . Segment with maximum sum 3 consists of one integer 3. 1. Last element is destroyed. At this moment there are no valid nonempty segments left in this array, so the answer is equal to 0. | ```python
size = int(input())
num = list(map(int, input().split(" ")))
rem = list(map(lambda x: int(x) - 1, input().split(" ")))
def getTree(lst, l, r):
if l == r:
return {"s": lst[l], "li": l, "ri": r}
c = int((l + r) / 2)
lt = getTree(lst, l, c)
rt = getTree(lst, c + 1, r)
return {
"li": l, "ri": r,
"s": lt["s"] + rt["s"],
"l": lt,
"r": rt
}
def subsum(tree, l, r):
if tree["li"] == l and tree["ri"] == r:
return tree["s"]
c = int ((tree["ri"] + tree["li"]) / 2)
if l >= tree["li"] and r <= c:
return subsum(tree["l"], l, r)
elif l > c and r <= tree["ri"]:
return subsum(tree["r"], l, r)
else:
return subsum(tree["l"], l, c) + subsum(tree["r"], c + 1, r)
def remove(tree, i, s):
tree["s"] -= s
if "r" in tree and "l" in tree:
c = int((tree["ri"] + tree["li"]) / 2)
if i <= c:
remove(tree["l"], i, s)
else:
remove(tree["r"], i, s)
ll = len(num) - 1
tree = getTree(num, 0, ll)
parts = []
for i in rem:
remove (tree, i, num[i])
parts.append(i)
parts = sorted(parts)
x0 = 0
ss = -1
for r in range(len(parts)):
x1 = parts[r]
ss = max(ss, subsum(tree, x0, x1))
x0 = x1
ss = max(ss, subsum(tree, x0, ll))
print(ss)
``` | 0 |
|
165 | A | Supercentral Point | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=<<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=<<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=><=*y*
We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set. | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different. | Print the only number — the number of supercentral points of the given set. | [
"8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n",
"5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n"
] | [
"2\n",
"1\n"
] | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | 500 | [
{
"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3",
"output": "2"
},
{
"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0",
"output": "1"
},
{
"input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1",
"output": "1"
},
{
"input": "25\n-651 897\n916 897\n-651 -808\n-748 301\n-734 414\n-651 -973\n-734 897\n916 -550\n-758 414\n916 180\n-758 -808\n-758 -973\n125 -550\n125 -973\n125 301\n916 414\n-748 -808\n-651 301\n-734 301\n-307 897\n-651 -550\n-651 414\n125 -808\n-748 -550\n916 -808",
"output": "7"
},
{
"input": "1\n487 550",
"output": "0"
},
{
"input": "10\n990 -396\n990 736\n990 646\n990 -102\n990 -570\n990 155\n990 528\n990 489\n990 268\n990 676",
"output": "0"
},
{
"input": "30\n507 836\n525 836\n-779 196\n507 -814\n525 -814\n525 42\n525 196\n525 -136\n-779 311\n507 -360\n525 300\n507 578\n507 311\n-779 836\n507 300\n525 -360\n525 311\n-779 -360\n-779 578\n-779 300\n507 42\n525 578\n-779 379\n507 196\n525 379\n507 379\n-779 -814\n-779 42\n-779 -136\n507 -136",
"output": "8"
},
{
"input": "25\n890 -756\n890 -188\n-37 -756\n-37 853\n523 998\n-261 853\n-351 853\n-351 -188\n523 -756\n-261 -188\n-37 998\n523 -212\n-351 998\n-37 -188\n-351 -756\n-37 -212\n890 998\n890 -212\n523 853\n-351 -212\n-261 -212\n-261 998\n-261 -756\n890 853\n523 -188",
"output": "9"
},
{
"input": "21\n-813 -11\n486 254\n685 254\n-708 254\n-55 -11\n-671 -191\n486 -11\n-671 -11\n685 -11\n685 -191\n486 -191\n-55 254\n-708 -11\n-813 254\n-708 -191\n41 -11\n-671 254\n-813 -191\n41 254\n-55 -191\n41 -191",
"output": "5"
},
{
"input": "4\n1 0\n2 0\n1 1\n1 -1",
"output": "0"
}
] | 1,595,912,626 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 434 | 22,323,200 | t = int(input())
xs,ys,ps = [],[],[]
for x in range(t):
l1 = [int(x) for x in input().split()]
xs.append(l1[0])
ys.append(l1[1])
ps.append([l1[0],l1[1]])
naughtyx = [min(x),max(x)]
naughtyy = [min(y),max(y)]
counter=0
for x in ps:
if xs.count(x[0])>=3 and ys.count(x[1])>=3 and x not in naughtyx and y not in naughtyy:
counter+=1
print(counter)
| Title: Supercentral Point
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=<<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=<<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=><=*y*
We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input Specification:
The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output Specification:
Print the only number — the number of supercentral points of the given set.
Demo Input:
['8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n', '5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | ```python
t = int(input())
xs,ys,ps = [],[],[]
for x in range(t):
l1 = [int(x) for x in input().split()]
xs.append(l1[0])
ys.append(l1[1])
ps.append([l1[0],l1[1]])
naughtyx = [min(x),max(x)]
naughtyy = [min(y),max(y)]
counter=0
for x in ps:
if xs.count(x[0])>=3 and ys.count(x[1])>=3 and x not in naughtyx and y not in naughtyy:
counter+=1
print(counter)
``` | -1 |
|
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281",
"output": "5464380"
},
{
"input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353",
"output": "9535765"
},
{
"input": "3\n1 3 2",
"output": "3"
},
{
"input": "3\n2 1 3",
"output": "3"
},
{
"input": "3\n2 3 1",
"output": "3"
},
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "3"
},
{
"input": "1\n228503",
"output": "0"
},
{
"input": "2\n32576 550340",
"output": "517764"
},
{
"input": "3\n910648 542843 537125",
"output": "741328"
},
{
"input": "4\n751720 572344 569387 893618",
"output": "787403"
},
{
"input": "6\n433864 631347 597596 794426 713555 231193",
"output": "1364575"
},
{
"input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107",
"output": "4647430"
},
{
"input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025",
"output": "13488674"
},
{
"input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763",
"output": "21993384"
},
{
"input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351",
"output": "26984185"
},
{
"input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642",
"output": "32816391"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "99000000"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n5 0 0",
"output": "10"
},
{
"input": "5\n2 10 0 0 0",
"output": "38"
}
] | 1,660,820,047 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 108 | 0 | n = int(input())
l = list(map(int,input().split()))
p = max(l)
v=0
r=0
for i in l:
v = p-i
r+=v
print(r)
| Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input Specification:
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
Output Specification:
In the only line print the integer *S* — the minimum number of burles which are had to spend.
Demo Input:
['5\n0 1 2 3 4\n', '5\n1 1 0 1 1\n', '3\n1 3 1\n', '1\n12\n']
Demo Output:
['10', '1', '4', '0']
Note:
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | ```python
n = int(input())
l = list(map(int,input().split()))
p = max(l)
v=0
r=0
for i in l:
v = p-i
r+=v
print(r)
``` | 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,689,711,126 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 92 | 0 | num1=int(input())
num2=int(input())
result=num1+num2
a=str(num1).replace("0","")
b=str(num2).replace("0","")
c=str(result).replace("0","")
if int(a)+int(b)==int(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
num1=int(input())
num2=int(input())
result=num1+num2
a=str(num1).replace("0","")
b=str(num2).replace("0","")
c=str(result).replace("0","")
if int(a)+int(b)==int(c):
print("YES")
else:
print("NO")
``` | 3.977 |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1.
These conditions define all the values in the table.
You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above. | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
},
{
"input": "9",
"output": "12870"
},
{
"input": "10",
"output": "48620"
},
{
"input": "8",
"output": "3432"
}
] | 1,619,322,477 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 62 | 0 | n = int(input())
lst = [[0] * n] * n
for i in range(n):
for j in range(n):
if (i == 0 or j == 0):
lst[i][j] = 1
else:
lst[i][j] = lst[i - 1][j] + lst[i][j - 1]
# print(lst)
print(lst[-1][-1])
| Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1.
These conditions define all the values in the table.
You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above.
Input Specification:
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Output Specification:
Print a single line containing a positive integer *m* — the maximum value in the table.
Demo Input:
['1\n', '5\n']
Demo Output:
['1', '70']
Note:
In the second test the rows of the table look as follows: | ```python
n = int(input())
lst = [[0] * n] * n
for i in range(n):
for j in range(n):
if (i == 0 or j == 0):
lst[i][j] = 1
else:
lst[i][j] = lst[i - 1][j] + lst[i][j - 1]
# print(lst)
print(lst[-1][-1])
``` | 3 |
|
808 | G | Anthem of Berland | PROGRAMMING | 2,300 | [
"dp",
"strings"
] | null | null | Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.
He has already composed major part of the anthem and now just needs to fill in some letters. King asked you to help him with this work.
The anthem is the string *s* of no more than 105 small Latin letters and question marks. The most glorious victory is the string *t* of no more than 105 small Latin letters. You should replace all the question marks with small Latin letters in such a way that the number of occurrences of string *t* in string *s* is maximal.
Note that the occurrences of string *t* in *s* can overlap. Check the third example for clarification. | The first line contains string of small Latin letters and question marks *s* (1<=≤<=|*s*|<=≤<=105).
The second line contains string of small Latin letters *t* (1<=≤<=|*t*|<=≤<=105).
Product of lengths of strings |*s*|·|*t*| won't exceed 107. | Output the maximum number of occurrences of string *t* you can achieve by replacing all the question marks in string *s* with small Latin letters. | [
"winlose???winl???w??\nwin\n",
"glo?yto?e??an?\nor\n",
"??c?????\nabcab\n"
] | [
"5\n",
"3\n",
"2\n"
] | In the first example the resulting string *s* is "winlosewinwinlwinwin"
In the second example the resulting string *s* is "glorytoreorand". The last letter of the string can be arbitrary.
In the third example occurrences of string *t* are overlapping. String *s* with maximal number of occurrences of *t* is "abcabcab". | 0 | [
{
"input": "winlose???winl???w??\nwin",
"output": "5"
},
{
"input": "glo?yto?e??an?\nor",
"output": "3"
},
{
"input": "??c?????\nabcab",
"output": "2"
},
{
"input": "ddddd\nd",
"output": "5"
},
{
"input": "ww?ww\nw",
"output": "5"
},
{
"input": "?????\nn",
"output": "5"
},
{
"input": "xznxr\nxznxr",
"output": "1"
},
{
"input": "wnfbhg?dkhdbh?hdmfjkcunzbh?hdbjjrbh?hddmh?zubhgh?qbjbhghdpwr?bhghdfjnjf?qbhghdqq?qebhgh?umvbhghdivvj\nbhghd",
"output": "10"
},
{
"input": "emnd?t??m?gd?t?p?s??m?dp??t???m?????m?d?ydo????????i??u?d??dp??h??d?tdp???cj?dm?dpxf?hsf??rdmt?pu?tw\ndmtdp",
"output": "11"
},
{
"input": "t?t?t?xnu?\ntstx",
"output": "1"
},
{
"input": "p??p??????\numpq",
"output": "2"
},
{
"input": "irsdljdahusytoclelxidaaiaiaicaiaiaiaiiaiaiyyexmohdwmeyycaiaiaitclluaiaiaiznxweleaiaiaiixdwehyruhizbc\naiaiai",
"output": "6"
},
{
"input": "qjcenuvdsn?ytytyt?yrznaaqeol?tyttyty?ycfaiphfmo?qpvtmhk?xzfr?tytytytytyty?oeqotyt?tyjhdhjtyt?tyyewxh\ntytyty",
"output": "9"
},
{
"input": "zubxnxnxnxn?xixiox?oxinoxnox?xnoxxnox?xnoxixxnox?oxii?xnoxiin?noxixnoxiox?noxixxnox?noxxnoxi?xnoxinn\nxnoxi",
"output": "13"
},
{
"input": "????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\nrcmcscoffidfyaeeanevbcfloxrhzxnitikwyidszzgmvicjupbfzhlbkzjbyidpdaeagaanokohwofzvfsvmcwvrqkvgbwnxomajvotbpzqgiyifngpnfvmtsoovrstzhtkeqamskzdmspvihochmajwkdoeozqpkdoxffhokosfqnaqshxbsfnkjsbbkxhrzgqhufq",
"output": "1"
},
{
"input": "????ufu\nfufu",
"output": "2"
},
{
"input": "??????c???\nabcabc",
"output": "2"
},
{
"input": "a???????abcax\naxabcax",
"output": "2"
},
{
"input": "cb???????a\ncbacba",
"output": "2"
},
{
"input": "a???????bc\nabcabc",
"output": "2"
},
{
"input": "a????ab\nabab",
"output": "2"
},
{
"input": "pe????????????petooh\npetoohpetooh",
"output": "2"
},
{
"input": "hacking????????????????????????hackingisfun\nhackingisfunhackingisfun",
"output": "2"
},
{
"input": "youdontgiveup????????????????????????????????????youyoudontgiveupdoyo?youyoudontgiveupdoyou\nyoudontgiveupdoyouyoudontgiveupdoyou",
"output": "2"
},
{
"input": "????b?b\nabab",
"output": "2"
},
{
"input": "a\nb",
"output": "0"
},
{
"input": "???a??????a??b?a??a????aabc??a???a?????ab???????b????????????????ab?a?????a????a??a??????b??cb?????????????b?????c????a??????????b????c????????ca?b???????c??bc????????a?b??b??a??cc?b???????a??a?ab?a?ca?a???????c????????b????b?c\nabaab",
"output": "55"
},
{
"input": "????????baaab\naaabaaab",
"output": "2"
},
{
"input": "baaab????????\nbaaabaaa",
"output": "2"
},
{
"input": "??????????????????????????\nabacaba",
"output": "5"
}
] | 1,497,113,441 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 36 | 358 | 921,600 | def look(t, i):
so = s[i:i + t_len]
for j in range(t_len):
if not so[j] in [t[j], '?']:
return False
so[j] = t[j]
s[i:i + t_len] = so
return True
def rlook(t, i):
so = rs[i:i + t_len]
for j in range(t_len):
if not so[j] in [t[j], '?']:
return False
so[j] = t[j]
rs[i:i + t_len] = so
return True
s = list(input())
t = input()
rs = s[:]
s_len = len(s)
t_len = len(t)
j = 0
rj = 0
for i in range(s_len-t_len+1):
if look(t, i):
j += 1
if rlook(t, i):
rj += 1
print(max(j, rj)) | Title: Anthem of Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.
He has already composed major part of the anthem and now just needs to fill in some letters. King asked you to help him with this work.
The anthem is the string *s* of no more than 105 small Latin letters and question marks. The most glorious victory is the string *t* of no more than 105 small Latin letters. You should replace all the question marks with small Latin letters in such a way that the number of occurrences of string *t* in string *s* is maximal.
Note that the occurrences of string *t* in *s* can overlap. Check the third example for clarification.
Input Specification:
The first line contains string of small Latin letters and question marks *s* (1<=≤<=|*s*|<=≤<=105).
The second line contains string of small Latin letters *t* (1<=≤<=|*t*|<=≤<=105).
Product of lengths of strings |*s*|·|*t*| won't exceed 107.
Output Specification:
Output the maximum number of occurrences of string *t* you can achieve by replacing all the question marks in string *s* with small Latin letters.
Demo Input:
['winlose???winl???w??\nwin\n', 'glo?yto?e??an?\nor\n', '??c?????\nabcab\n']
Demo Output:
['5\n', '3\n', '2\n']
Note:
In the first example the resulting string *s* is "winlosewinwinlwinwin"
In the second example the resulting string *s* is "glorytoreorand". The last letter of the string can be arbitrary.
In the third example occurrences of string *t* are overlapping. String *s* with maximal number of occurrences of *t* is "abcabcab". | ```python
def look(t, i):
so = s[i:i + t_len]
for j in range(t_len):
if not so[j] in [t[j], '?']:
return False
so[j] = t[j]
s[i:i + t_len] = so
return True
def rlook(t, i):
so = rs[i:i + t_len]
for j in range(t_len):
if not so[j] in [t[j], '?']:
return False
so[j] = t[j]
rs[i:i + t_len] = so
return True
s = list(input())
t = input()
rs = s[:]
s_len = len(s)
t_len = len(t)
j = 0
rj = 0
for i in range(s_len-t_len+1):
if look(t, i):
j += 1
if rlook(t, i):
rj += 1
print(max(j, rj))
``` | 0 |
|
7 | C | Line | PROGRAMMING | 1,800 | [
"math",
"number theory"
] | C. Line | 1 | 256 | A line on the plane is described by an equation *Ax*<=+<=*By*<=+<=*C*<==<=0. You are to find any point on this line, whose coordinates are integer numbers from <=-<=5·1018 to 5·1018 inclusive, or to find out that such points do not exist. | The first line contains three integers *A*, *B* and *C* (<=-<=2·109<=≤<=*A*,<=*B*,<=*C*<=≤<=2·109) — corresponding coefficients of the line equation. It is guaranteed that *A*2<=+<=*B*2<=><=0. | If the required point exists, output its coordinates, otherwise output -1. | [
"2 5 3\n"
] | [
"6 -3\n"
] | none | 0 | [
{
"input": "2 5 3",
"output": "6 -3"
},
{
"input": "0 2 3",
"output": "-1"
},
{
"input": "931480234 -1767614767 -320146190",
"output": "-98880374013340920 -52107006370101410"
},
{
"input": "-1548994394 -1586527767 -1203252104",
"output": "-878123061596147680 857348814150663048"
},
{
"input": "296038088 887120955 1338330394",
"output": "2114412129515872 -705593211994286"
},
{
"input": "1906842444 749552572 -1693767003",
"output": "-1"
},
{
"input": "-1638453107 317016895 -430897103",
"output": "-23538272620589909 -121653945000687008"
},
{
"input": "-1183748658 875864960 -1315510852",
"output": "-97498198168399474 -131770725522871624"
},
{
"input": "427055698 738296578 -52640953",
"output": "-1"
},
{
"input": "-1516373701 -584304312 -746376800",
"output": "202167007852295200 -524659372900676000"
},
{
"input": "200000003 200000001 1",
"output": "100000000 -100000001"
},
{
"input": "0 -1 -2",
"output": "0 -2"
},
{
"input": "0 15 -17",
"output": "-1"
},
{
"input": "-13 0 0",
"output": "0 0"
},
{
"input": "-1000 0 -6",
"output": "-1"
},
{
"input": "1233978557 804808375 539283626",
"output": "3168196851074932 -4857661898189602"
},
{
"input": "532430220 -2899704 -328786059",
"output": "-1"
},
{
"input": "546348890 -29226055 -341135185",
"output": "50549411713300 944965544604433"
},
{
"input": "-1061610169 583743042 1503847115",
"output": "-333340893817405 -606222356685680"
},
{
"input": "10273743 174653631 -628469658",
"output": "-1"
},
{
"input": "1 2000000000 -1",
"output": "1 0"
},
{
"input": "592707810 829317963 -753392742",
"output": "-15849808632976 11327748563154"
},
{
"input": "1300000013 0 -800000008",
"output": "-1"
},
{
"input": "853072 -269205 -1778980",
"output": "7238140 22936620"
},
{
"input": "3162 56 674",
"output": "-4381 247358"
},
{
"input": "19 -5 115",
"output": "115 460"
},
{
"input": "7 5 -17",
"output": "-34 51"
},
{
"input": "-1 1 -2",
"output": "-2 0"
},
{
"input": "12453630 -163142553 -74721780",
"output": "-780 -60"
},
{
"input": "-3416750 528845750 -93743375",
"output": "-1"
},
{
"input": "701408733 1134903170 1836311903",
"output": "-796030994547383611 491974210728665288"
},
{
"input": "1000000013 -1 135",
"output": "0 135"
},
{
"input": "-2000000000 1 2000000000",
"output": "0 -2000000000"
},
{
"input": "2000000000 -2000000000 2000000000",
"output": "-1 0"
},
{
"input": "610684570 628836350 933504357",
"output": "-1"
},
{
"input": "827797728 -613880705 854959653",
"output": "60828197453915544 82024802605070757"
},
{
"input": "1044910887 -700497854 -1772517851",
"output": "572270531415215165 853638173436907976"
},
{
"input": "1663473197 -1943214909 -399995353",
"output": "90913128604458086 77825438652462521"
},
{
"input": "1880586355 -177315705 -478540057",
"output": "-1"
},
{
"input": "-957757861 308710346 45337024",
"output": "587450634832960 1822535171726016"
},
{
"input": "19999 -20000 10000",
"output": "10000 10000"
},
{
"input": "1999999 -2000000 1000000",
"output": "1000000 1000000"
},
{
"input": "999999999 -1000000000 500000000",
"output": "500000000 500000000"
},
{
"input": "999999999 -2 1",
"output": "-1 -499999999"
},
{
"input": "999999993 999999991 1",
"output": "499999995 -499999996"
},
{
"input": "999999993 -999999997 1",
"output": "-249999999 -249999998"
},
{
"input": "1999999993 1999999991 -1",
"output": "-999999995 999999996"
},
{
"input": "1999999993 1999999991 -1999999997",
"output": "-1999999987000000015 1999999989000000012"
}
] | 1,480,003,091 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 92 | 0 | def compute():
def xgcd(b,n):
x0, x1, y0, y1 = 1, 0, 0, 1
while n!=0:
q, b, n = b//n, n, b%n
x0, x1 = x1, x0 - q*x1
y0, y1 = y1, y0 - q*y1
return b, x0, y0
A, B, C = map(int,input().split())
g, x, y = xgcd(A,B)
if abs(-C)%g!=0:
return -1
d = -C//g
return x*d, y*d
if __name__=="__main__":
print(' '.join(str(it) for it in compute()))
| Title: Line
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
A line on the plane is described by an equation *Ax*<=+<=*By*<=+<=*C*<==<=0. You are to find any point on this line, whose coordinates are integer numbers from <=-<=5·1018 to 5·1018 inclusive, or to find out that such points do not exist.
Input Specification:
The first line contains three integers *A*, *B* and *C* (<=-<=2·109<=≤<=*A*,<=*B*,<=*C*<=≤<=2·109) — corresponding coefficients of the line equation. It is guaranteed that *A*2<=+<=*B*2<=><=0.
Output Specification:
If the required point exists, output its coordinates, otherwise output -1.
Demo Input:
['2 5 3\n']
Demo Output:
['6 -3\n']
Note:
none | ```python
def compute():
def xgcd(b,n):
x0, x1, y0, y1 = 1, 0, 0, 1
while n!=0:
q, b, n = b//n, n, b%n
x0, x1 = x1, x0 - q*x1
y0, y1 = y1, y0 - q*y1
return b, x0, y0
A, B, C = map(int,input().split())
g, x, y = xgcd(A,B)
if abs(-C)%g!=0:
return -1
d = -C//g
return x*d, y*d
if __name__=="__main__":
print(' '.join(str(it) for it in compute()))
``` | -1 |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "10000220"
},
{
"input": ".",
"output": "0"
},
{
"input": "-.",
"output": "1"
},
{
"input": "--",
"output": "2"
},
{
"input": "..",
"output": "00"
},
{
"input": "--.",
"output": "20"
},
{
"input": ".--.",
"output": "020"
},
{
"input": ".-.-..",
"output": "0110"
},
{
"input": "----.-.",
"output": "2201"
},
{
"input": "-..--.-.",
"output": "10201"
},
{
"input": "..--..--.",
"output": "0020020"
},
{
"input": "-.-.---.--..-..-.-.-..-..-.--.",
"output": "112120010111010120"
},
{
"input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.",
"output": "21112220010101011012011011221011"
},
{
"input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------",
"output": "11020111110111222212021020002022111100201121222020012022110010222"
},
{
"input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..",
"output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110"
},
{
"input": ".-..-.-.---.-----.--.---...-.--.-.-....-..",
"output": "01011212212021001201100010"
},
{
"input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..",
"output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210"
},
{
"input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.",
"output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220"
},
{
"input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----",
"output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122"
},
{
"input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..",
"output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110"
},
{
"input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.",
"output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020"
},
{
"input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..",
"output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200"
},
{
"input": "-.---...----...--.--...-.--.----",
"output": "121002200020200012022"
},
{
"input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.",
"output": "202020212012111010201021100001021221200011222112012201012220"
}
] | 1,675,354,649 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 92 | 0 | n=input()
indx = 0
while (indx<len(n)):
if n[indx]=='.':
print(0,end="")
elif n[indx]=='-':
if n[indx+1]=='.':
print(1,end="")
else:
print(2,end="")
indx+=1
indx+=1
| Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input Specification:
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output Specification:
Output the decoded ternary number. It can have leading zeroes.
Demo Input:
['.-.--\n', '--.\n', '-..-.--\n']
Demo Output:
['012', '20', '1012']
Note:
none | ```python
n=input()
indx = 0
while (indx<len(n)):
if n[indx]=='.':
print(0,end="")
elif n[indx]=='-':
if n[indx+1]=='.':
print(1,end="")
else:
print(2,end="")
indx+=1
indx+=1
``` | 3.977 |
784 | F | Crunching Numbers Just for You | PROGRAMMING | 1,900 | [
"*special",
"implementation"
] | null | null | You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order. | The input consists of a single line of space-separated integers. The first number is *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The following *n* numbers are the elements of the array (1<=≤<=*a**i*<=≤<=100). | Output space-separated elements of the sorted array. | [
"3 3 1 2\n"
] | [
"1 2 3 \n"
] | Remember, this is a very important feature, and you have to make sure the customers appreciate it! | 0 | [
{
"input": "3 3 1 2",
"output": "1 2 3 "
},
{
"input": "10 54 100 27 1 33 27 80 49 27 6",
"output": "1 6 27 27 27 33 49 54 80 100 "
}
] | 1,516,676,702 | 2,147,483,647 | Python 3 | REJECTED | TESTS | 0 | 0 | 0 | print(*sorted(map(int,input().split()[1:])))
| Title: Crunching Numbers Just for You
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input Specification:
The input consists of a single line of space-separated integers. The first number is *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The following *n* numbers are the elements of the array (1<=≤<=*a**i*<=≤<=100).
Output Specification:
Output space-separated elements of the sorted array.
Demo Input:
['3 3 1 2\n']
Demo Output:
['1 2 3 \n']
Note:
Remember, this is a very important feature, and you have to make sure the customers appreciate it! | ```python
print(*sorted(map(int,input().split()[1:])))
``` | -1 |
|
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"output": "8"
},
{
"input": "31",
"output": "3"
},
{
"input": "59",
"output": "8"
},
{
"input": "79",
"output": "9"
},
{
"input": "7",
"output": "3"
},
{
"input": "55",
"output": "4"
},
{
"input": "40",
"output": "2"
},
{
"input": "719",
"output": "13"
},
{
"input": "847",
"output": "13"
},
{
"input": "225",
"output": "4"
},
{
"input": "4704",
"output": "51"
},
{
"input": "1132",
"output": "15"
},
{
"input": "7811",
"output": "80"
},
{
"input": "7981",
"output": "84"
},
{
"input": "82655",
"output": "830"
},
{
"input": "6364",
"output": "70"
},
{
"input": "74611",
"output": "748"
},
{
"input": "45391",
"output": "459"
},
{
"input": "620448",
"output": "6210"
},
{
"input": "265145",
"output": "2654"
},
{
"input": "671704",
"output": "6721"
},
{
"input": "365173",
"output": "3658"
},
{
"input": "7130872",
"output": "71314"
},
{
"input": "9628747",
"output": "96292"
},
{
"input": "8898399",
"output": "88993"
},
{
"input": "9497953",
"output": "94985"
},
{
"input": "19070947",
"output": "190714"
},
{
"input": "20185520",
"output": "201856"
},
{
"input": "91402248",
"output": "914028"
},
{
"input": "27035533",
"output": "270360"
},
{
"input": "22717528",
"output": "227180"
},
{
"input": "24403439",
"output": "244041"
},
{
"input": "163565555",
"output": "1635659"
},
{
"input": "152541908",
"output": "1525423"
},
{
"input": "668439837",
"output": "6684403"
},
{
"input": "20",
"output": "1"
},
{
"input": "999999999",
"output": "10000009"
},
{
"input": "10",
"output": "1"
},
{
"input": "7",
"output": "3"
},
{
"input": "6",
"output": "2"
},
{
"input": "99999999",
"output": "1000009"
},
{
"input": "1000001",
"output": "10001"
},
{
"input": "2521",
"output": "27"
}
] | 1,689,881,014 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | t=int(input())
x=[100,20,10,5,1]
count=0
for i in x:
count+=t//i
t%=i
print(count) | Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
Input Specification:
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output Specification:
Output the minimum number of bills that Allen could receive.
Demo Input:
['125\n', '43\n', '1000000000\n']
Demo Output:
['3\n', '5\n', '10000000\n']
Note:
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | ```python
t=int(input())
x=[100,20,10,5,1]
count=0
for i in x:
count+=t//i
t%=i
print(count)
``` | 3 |
|
834 | B | The Festive Evening | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.
There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.
For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are *k* such guards in the castle, so if there are more than *k* opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.
Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than *k* doors were opened. | Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. | Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"5 1\nAABBB\n",
"5 1\nABABB\n"
] | [
"NO\n",
"YES\n"
] | In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.
In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door. | 1,000 | [
{
"input": "5 1\nAABBB",
"output": "NO"
},
{
"input": "5 1\nABABB",
"output": "YES"
},
{
"input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "NO"
},
{
"input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA",
"output": "YES"
},
{
"input": "5 2\nABACA",
"output": "NO"
},
{
"input": "6 2\nABCABC",
"output": "YES"
},
{
"input": "8 3\nABCBCDCA",
"output": "NO"
},
{
"input": "73 2\nDEBECECBBADAADEAABEAEEEAEBEAEBCDDBABBAEBACCBEEBBAEADEECACEDEEDABACDCDBBBD",
"output": "YES"
},
{
"input": "44 15\nHGJIFCGGCDGIJDHBIBGAEABCIABIGBDEADBBBAGDFDHA",
"output": "NO"
},
{
"input": "41 19\nTMEYYIIELFDCMBDKWWKYNRNDUPRONYROXQCLVQALP",
"output": "NO"
},
{
"input": "377 3\nEADADBBBBDEAABBAEBABACDBDBBCACAADBEAEACDEAABACADEEDEACACDADABBBBDDEECBDABACACBAECBADAEBDEEBDBCDAEADBCDDACACDCCEEDBCCBBCEDBECBABCDDBBDEADEDAEACDECECBEBACBCCDCDBDAECDECADBCBEDBBDAAEBCAAECCDCCDBDDEBADEEBDCAEABBDEDBBDDEAECCBDDCDEACDAECCBDDABABEAEDCDEDBAECBDEACEBCECEACDCBABCBAAEAADACADBBBBABEADBCADEBCBECCABBDDDEEBCDEBADEBDAAABBEABADEDEAEABCEEBEEDEAEBEABCEDDBACBCCADEBAAAAAEABABBCE",
"output": "YES"
},
{
"input": "433 3\nFZDDHMJGBZCHFUXBBPIEBBEFDWOMXXEPOMDGSMPIUZOMRZQNSJAVNATGIWPDFISKFQXJNVFXPHOZDAEZFDAHDXXQKZMGNSGKQNWGNGJGJZVVITKNFLVCPMZSDMCHBTVAWYVZLIXXIADXNYILEYNIQHKMOGMVOCWGHCWIYMPEPADSJAAKEGTUSEDWAHMNYJDIHBKHVUHLYGNGZDBULRXLSAJHPCMNWCEAAPYMHDTYWPADOTJTXTXUKLCHWKUSZRHEKQEFPVJEJJHRWCKYOIWALRTIBUMNOCRXLSIKQCJVQXEPGOHRUDJDKMUUUDORURWXJNVRVMNOUNRFKSVMTMZGOIJLXEPAMVGESOADYIGZXRBJDIWKNOWTCSROAQTBECHTOZVSQUOOJRZIBAUHMKAXDCIMDZJFMABGRNTGPUJAUNFPFWCJG",
"output": "YES"
},
{
"input": "5 2\nABCAB",
"output": "YES"
},
{
"input": "5 1\nAZAZA",
"output": "YES"
},
{
"input": "7 2\nABCDBCD",
"output": "YES"
},
{
"input": "3 26\nAAB",
"output": "NO"
}
] | 1,502,940,898 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 811 | 3,276,800 | n, k = map(int, input().split())
s = input()
d = {}
op = set()
for i in range(len(s)):
d[s[i]] = i
ans = 0
doors = 0
for i in range(len(s)):
if s[i] not in op:
doors += 1
op.add(s[i])
ans = max(ans, doors)
if i == d[s[i]]:
doors -= 1
print(('YES','NO')[ans <= k])
| Title: The Festive Evening
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.
There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.
For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are *k* such guards in the castle, so if there are more than *k* opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.
Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than *k* doors were opened.
Input Specification:
Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest.
Output Specification:
Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower).
Demo Input:
['5 1\nAABBB\n', '5 1\nABABB\n']
Demo Output:
['NO\n', 'YES\n']
Note:
In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.
In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door. | ```python
n, k = map(int, input().split())
s = input()
d = {}
op = set()
for i in range(len(s)):
d[s[i]] = i
ans = 0
doors = 0
for i in range(len(s)):
if s[i] not in op:
doors += 1
op.add(s[i])
ans = max(ans, doors)
if i == d[s[i]]:
doors -= 1
print(('YES','NO')[ans <= k])
``` | 3 |
|
366 | A | Dima and Guards | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly *n* rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that! | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly. | In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them. | [
"10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9\n",
"10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8\n",
"5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3\n"
] | [
"1 5 5\n",
"3 4 6\n",
"-1\n"
] | Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard. | 500 | [
{
"input": "10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9",
"output": "1 5 5"
},
{
"input": "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8",
"output": "3 4 6"
},
{
"input": "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3",
"output": "-1"
},
{
"input": "100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000",
"output": "-1"
},
{
"input": "5\n3 2 3 3\n3 2 3 3\n4 4 4 4\n4 4 1 1",
"output": "1 2 3"
},
{
"input": "100\n1 1 2 2\n100 100 2 2\n99 99 2 2\n2 2 99 99",
"output": "1 1 99"
},
{
"input": "1000\n500 500 550 550\n450 450 500 500\n999 1 1 999\n1 999 1 999",
"output": "3 1 999"
},
{
"input": "50\n30 30 30 30\n20 20 40 40\n10 10 50 50\n1 1 50 55",
"output": "-1"
},
{
"input": "10000\n1000 7000 8000 6000\n8000 8000 6000 6000\n5000 6000 6000 6000\n10000 10000 2 3",
"output": "1 1000 9000"
},
{
"input": "40000\n25000 25000 30000 30000\n1 1 1 1\n30000 20000 30000 30000\n40000 40000 40000 50000",
"output": "2 1 39999"
},
{
"input": "4\n2 1 4 4\n4 4 1 1\n3 1 2 2\n4 4 4 4",
"output": "3 1 3"
},
{
"input": "50\n5 5 5 5\n5 5 5 5\n5 5 5 5\n5 5 5 5",
"output": "1 5 45"
},
{
"input": "10\n7 2 3 20\n20 20 20 20\n20 20 20 20\n7 2 3 20",
"output": "1 2 8"
},
{
"input": "10\n8 2 7 8\n20 20 20 20\n20 20 20 20\n8 2 7 8",
"output": "1 2 8"
},
{
"input": "100000\n50000 50000 50000 50000\n50000 50000 50000 50000\n50000 50000 50000 50000\n50000 50000 50000 50000",
"output": "1 50000 50000"
},
{
"input": "100000\n25000 75000 80000 80000\n99999 99999 2 2\n99999 2 99999 99999\n2 99999 99999 99999",
"output": "-1"
},
{
"input": "1231\n123 132 85 78\n123 5743 139 27\n4598 347 12438 12\n34589 2349 123 123",
"output": "2 123 1108"
},
{
"input": "6\n2 6 2 9\n4 8 5 1\n5 6 4 3\n1 2 5 1",
"output": "4 1 5"
},
{
"input": "8\n5 5 3 3\n1 1 8 8\n2 8 8 7\n10 7 2 2",
"output": "1 5 3"
},
{
"input": "100000\n25000 50000 50001 75001\n25000 50000 50001 75001\n25000 50000 50001 75001\n25000 50000 50001 75001",
"output": "1 25000 75000"
},
{
"input": "100000\n25000 50000 75001 50001\n25000 50000 75001 50001\n25000 50000 75001 50001\n25000 50000 75001 50001",
"output": "1 25000 75000"
},
{
"input": "5\n3 7 6 2\n100 100 100 100\n100 100 100 100\n100 100 100 100",
"output": "1 3 2"
},
{
"input": "10\n1 100 100 1\n1 100 100 1\n1 100 100 1\n1 100 100 1",
"output": "1 1 9"
},
{
"input": "10\n7 5 5 7\n10 10 10 10\n10 10 10 10\n10 10 10 10",
"output": "1 5 5"
},
{
"input": "10\n9 9 9 9\n9 9 9 9\n9 9 9 9\n1 1 1 1",
"output": "4 1 9"
},
{
"input": "10\n8 6 5 3\n8 6 5 3\n8 6 5 3\n8 6 5 3",
"output": "1 6 4"
},
{
"input": "10\n9 9 9 9\n9 9 9 9\n9 9 9 9\n9 4 9 6",
"output": "4 4 6"
},
{
"input": "10\n6 6 4 4\n6 6 4 4\n6 6 4 4\n6 6 4 4",
"output": "1 6 4"
},
{
"input": "100000\n99000 100000 999 100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000",
"output": "1 99000 1000"
}
] | 1,683,605,602 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 102,400 | n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
d = list(map(int, input().split(' ')))
cost = []
cost.append(min(a[0],a[1])+min(a[2],a[3]))
cost.append(min(b[0],b[1])+min(b[2],b[3]))
cost.append(min(c[0],c[1])+min(c[2],c[3]))
cost.append(min(d[0],d[1])+min(d[2],d[3]))
y = min(cost)
if(y > n):
print("-1")
else:
if(y==cost[0]):
print("1 "+str(min(a[0],a[1]))+" "+str(n-min(a[0],a[1])))
elif(y==cost[1]):
print("2 "+str(min(b[0],b[1]))+" "+str(n-min(b[0],b[1])))
elif(y==cost[2]):
print("3 "+str(min(c[0],c[1]))+" "+str(n-min(c[0],c[1])))
else:
print("4 "+str(min(d[0],d[1]))+" "+str(n-min(d[0],d[1]))) | Title: Dima and Guards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly *n* rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output Specification:
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Demo Input:
['10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9\n', '10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8\n', '5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3\n']
Demo Output:
['1 5 5\n', '3 4 6\n', '-1\n']
Note:
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard. | ```python
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
d = list(map(int, input().split(' ')))
cost = []
cost.append(min(a[0],a[1])+min(a[2],a[3]))
cost.append(min(b[0],b[1])+min(b[2],b[3]))
cost.append(min(c[0],c[1])+min(c[2],c[3]))
cost.append(min(d[0],d[1])+min(d[2],d[3]))
y = min(cost)
if(y > n):
print("-1")
else:
if(y==cost[0]):
print("1 "+str(min(a[0],a[1]))+" "+str(n-min(a[0],a[1])))
elif(y==cost[1]):
print("2 "+str(min(b[0],b[1]))+" "+str(n-min(b[0],b[1])))
elif(y==cost[2]):
print("3 "+str(min(c[0],c[1]))+" "+str(n-min(c[0],c[1])))
else:
print("4 "+str(min(d[0],d[1]))+" "+str(n-min(d[0],d[1])))
``` | 3 |
|
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{
"input": "1022 584 112",
"output": "380"
},
{
"input": "66 174 319",
"output": "184"
},
{
"input": "912 276 1748",
"output": "444"
},
{
"input": "65 156 60",
"output": "120"
},
{
"input": "1 10000 10000",
"output": "40008"
},
{
"input": "1485 55 27",
"output": "332"
},
{
"input": "152 108 4104",
"output": "528"
},
{
"input": "1656 6900 1350",
"output": "740"
},
{
"input": "12 14 42",
"output": "60"
},
{
"input": "615 18 1230",
"output": "856"
},
{
"input": "680 60 408",
"output": "336"
},
{
"input": "644 966 6",
"output": "1308"
},
{
"input": "1 432 432",
"output": "1736"
},
{
"input": "2239 2239 1",
"output": "8964"
},
{
"input": "4106 8212 2",
"output": "16436"
},
{
"input": "10000 10000 10000",
"output": "1200"
},
{
"input": "3623 3623 1",
"output": "14500"
},
{
"input": "9801 9801 9801",
"output": "1188"
},
{
"input": "10000 1 10000",
"output": "40008"
},
{
"input": "9 9 9",
"output": "36"
},
{
"input": "9801 9702 9702",
"output": "1184"
}
] | 1,634,545,584 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define ll long long int
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a>b?b:a)
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define loop1(start,end,step) for(ll i=start;i<end;i+=step)
#define loop2(start,end,step) for(ll j=start;j<end;j+=step)
#define ISEVEN(n) ((n%2== 0) ? 1 : 0)
#define ISODD(n) ((n%2!= 0) ? 1 : 0)
#define MOD 1000000007
#define ACCEPT(nos,n) for(int i=0;i<n;i++) cin>>nos[i];
#define printArray(nos,n) for(int i=0;i<n;i++) cout<<nos[i]<<' '; cout<<endl;
using namespace std;
void solve(ll caseNo)
{
ll n;
cin>>n;
ll nos[7];
ACCEPT(nos, 7);
ll count=0,ans;
for (int i = 0; i < 7; i++)
{
count += nos[i];
if (count >= n)
{
ans = i + 1;
break;
}
if(i==6)
i=-1;
}
cout << ans;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
IOS
int t=1;
// cin>>t;
ll temp=1;
while(t--)
{
solve(temp);
temp++;
}
return 0;
} | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input Specification:
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output Specification:
Print a single number — the sum of all edges of the parallelepiped.
Demo Input:
['1 1 1\n', '4 6 6\n']
Demo Output:
['12\n', '28\n']
Note:
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | ```python
#include <bits/stdc++.h>
#define ll long long int
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a>b?b:a)
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define loop1(start,end,step) for(ll i=start;i<end;i+=step)
#define loop2(start,end,step) for(ll j=start;j<end;j+=step)
#define ISEVEN(n) ((n%2== 0) ? 1 : 0)
#define ISODD(n) ((n%2!= 0) ? 1 : 0)
#define MOD 1000000007
#define ACCEPT(nos,n) for(int i=0;i<n;i++) cin>>nos[i];
#define printArray(nos,n) for(int i=0;i<n;i++) cout<<nos[i]<<' '; cout<<endl;
using namespace std;
void solve(ll caseNo)
{
ll n;
cin>>n;
ll nos[7];
ACCEPT(nos, 7);
ll count=0,ans;
for (int i = 0; i < 7; i++)
{
count += nos[i];
if (count >= n)
{
ans = i + 1;
break;
}
if(i==6)
i=-1;
}
cout << ans;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
IOS
int t=1;
// cin>>t;
ll temp=1;
while(t--)
{
solve(temp);
temp++;
}
return 0;
}
``` | -1 |
|
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 7",
"output": "5"
},
{
"input": "14 5 5",
"output": "6"
},
{
"input": "16 6 9",
"output": "10"
},
{
"input": "20 13 17",
"output": "7"
},
{
"input": "22 4 8",
"output": "9"
},
{
"input": "23 8 14",
"output": "15"
},
{
"input": "26 18 22",
"output": "8"
},
{
"input": "28 6 1",
"output": "2"
},
{
"input": "29 5 23",
"output": "24"
},
{
"input": "32 27 15",
"output": "5"
},
{
"input": "33 11 5",
"output": "6"
},
{
"input": "37 21 15",
"output": "16"
},
{
"input": "39 34 33",
"output": "5"
},
{
"input": "41 27 11",
"output": "12"
},
{
"input": "42 25 16",
"output": "17"
},
{
"input": "45 7 43",
"output": "38"
},
{
"input": "47 16 17",
"output": "18"
},
{
"input": "49 11 37",
"output": "38"
},
{
"input": "51 38 39",
"output": "13"
},
{
"input": "52 29 7",
"output": "8"
},
{
"input": "56 43 12",
"output": "13"
},
{
"input": "58 57 28",
"output": "1"
},
{
"input": "59 12 39",
"output": "40"
},
{
"input": "62 9 52",
"output": "53"
},
{
"input": "63 29 44",
"output": "34"
},
{
"input": "65 30 22",
"output": "23"
},
{
"input": "66 27 38",
"output": "39"
},
{
"input": "71 33 53",
"output": "38"
},
{
"input": "73 14 12",
"output": "13"
},
{
"input": "73 37 35",
"output": "36"
},
{
"input": "76 69 44",
"output": "7"
},
{
"input": "79 25 20",
"output": "21"
},
{
"input": "81 60 20",
"output": "21"
},
{
"input": "81 79 14",
"output": "2"
},
{
"input": "84 0 42",
"output": "43"
},
{
"input": "88 79 8",
"output": "9"
},
{
"input": "90 76 59",
"output": "14"
},
{
"input": "92 2 22",
"output": "23"
},
{
"input": "94 5 88",
"output": "89"
},
{
"input": "94 62 48",
"output": "32"
},
{
"input": "96 22 72",
"output": "73"
},
{
"input": "100 11 88",
"output": "89"
},
{
"input": "100 81 91",
"output": "19"
},
{
"input": "1 0 0",
"output": "1"
}
] | 1,683,715,678 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | b = list(map(int, input().split()))
print(b[0]-b[1]) | Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
Input Specification:
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100).
Output Specification:
Print the single number — the number of the sought positions.
Demo Input:
['3 1 1\n', '5 2 3\n']
Demo Output:
['2\n', '3\n']
Note:
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | ```python
b = list(map(int, input().split()))
print(b[0]-b[1])
``` | 0 |
|
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.
To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".
Three phases from a certain poem are given. Determine whether it is haiku or not. | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
"output": "YES"
},
{
"input": "o vetus stagnum\n rana de ripa salit\n ac sonant aquae",
"output": "NO"
},
{
"input": " furuike ya\nkawazu tobikomu\nmizu no oto ",
"output": "YES"
},
{
"input": " noch da leich\na stamperl zum aufwaerma\n da pfarrer kimmt a ",
"output": "NO"
},
{
"input": " sommerfuglene \n hvorfor bruge mange ord\n et kan gore det",
"output": "YES"
},
{
"input": " ab der mittagszeit\n ist es etwas schattiger\n ein wolkenhimmel",
"output": "NO"
},
{
"input": "tornando a vederli\ni fiori di ciliegio la sera\nson divenuti frutti",
"output": "NO"
},
{
"input": "kutaburete\nyado karu koro ya\nfuji no hana",
"output": "YES"
},
{
"input": " beginnings of poetry\n the rice planting songs \n of the interior",
"output": "NO"
},
{
"input": " door zomerregens\n zijn de kraanvogelpoten\n korter geworden",
"output": "NO"
},
{
"input": " derevo na srub\na ptitsi bezzabotno\n gnezdishko tam vyut",
"output": "YES"
},
{
"input": "writing in the dark\nunaware that my pen\nhas run out of ink",
"output": "NO"
},
{
"input": "kusaaiu\nuieueua\nuo efaa",
"output": "YES"
},
{
"input": "v\nh\np",
"output": "NO"
},
{
"input": "i\ni\nu",
"output": "NO"
},
{
"input": "awmio eoj\nabdoolceegood\nwaadeuoy",
"output": "YES"
},
{
"input": "xzpnhhnqsjpxdboqojixmofawhdjcfbscq\nfoparnxnbzbveycoltwdrfbwwsuobyoz hfbrszy\nimtqryscsahrxpic agfjh wvpmczjjdrnwj mcggxcdo",
"output": "YES"
},
{
"input": "wxjcvccp cppwsjpzbd dhizbcnnllckybrnfyamhgkvkjtxxfzzzuyczmhedhztugpbgpvgh\nmdewztdoycbpxtp bsiw hknggnggykdkrlihvsaykzfiiw\ndewdztnngpsnn lfwfbvnwwmxoojknygqb hfe ibsrxsxr",
"output": "YES"
},
{
"input": "nbmtgyyfuxdvrhuhuhpcfywzrbclp znvxw synxmzymyxcntmhrjriqgdjh xkjckydbzjbvtjurnf\nhhnhxdknvamywhsrkprofnyzlcgtdyzzjdsfxyddvilnzjziz qmwfdvzckgcbrrxplxnxf mpxwxyrpesnewjrx ajxlfj\nvcczq hddzd cvefmhxwxxyqcwkr fdsndckmesqeq zyjbwbnbyhybd cta nsxzidl jpcvtzkldwd",
"output": "YES"
},
{
"input": "rvwdsgdsrutgjwscxz pkd qtpmfbqsmctuevxdj kjzknzghdvxzlaljcntg jxhvzn yciktbsbyscfypx x xhkxnfpdp\nwdfhvqgxbcts mnrwbr iqttsvigwdgvlxwhsmnyxnttedonxcfrtmdjjmacvqtkbmsnwwvvrlxwvtggeowtgsqld qj\nvsxcdhbzktrxbywpdvstr meykarwtkbm pkkbhvwvelclfmpngzxdmblhcvf qmabmweldplmczgbqgzbqnhvcdpnpjtch ",
"output": "YES"
},
{
"input": "brydyfsmtzzkpdsqvvztmprhqzbzqvgsblnz naait tdtiprjsttwusdykndwcccxfmzmrmfmzjywkpgbfnjpypgcbcfpsyfj k\nucwdfkfyxxxht lxvnovqnnsqutjsyagrplb jhvtwdptrwcqrovncdvqljjlrpxcfbxqgsfylbgmcjpvpl ccbcybmigpmjrxpu\nfgwtpcjeywgnxgbttgx htntpbk tkkpwbgxwtbxvcpkqbzetjdkcwad tftnjdxxjdvbpfibvxuglvx llyhgjvggtw jtjyphs",
"output": "YES"
},
{
"input": "nyc aqgqzjjlj mswgmjfcxlqdscheskchlzljlsbhyn iobxymwzykrsnljj\nnnebeaoiraga\nqpjximoqzswhyyszhzzrhfwhf iyxysdtcpmikkwpugwlxlhqfkn",
"output": "NO"
},
{
"input": "lzrkztgfe mlcnq ay ydmdzxh cdgcghxnkdgmgfzgahdjjmqkpdbskreswpnblnrc fmkwziiqrbskp\np oukeaz gvvy kghtrjlczyl qeqhgfgfej\nwfolhkmktvsjnrpzfxcxzqmfidtlzmuhxac wsncjgmkckrywvxmnjdpjpfydhk qlmdwphcvyngansqhl",
"output": "NO"
},
{
"input": "yxcboqmpwoevrdhvpxfzqmammak\njmhphkxppkqkszhqqtkvflarsxzla pbxlnnnafqbsnmznfj qmhoktgzix qpmrgzxqvmjxhskkksrtryehfnmrt dtzcvnvwp\nscwymuecjxhw rdgsffqywwhjpjbfcvcrnisfqllnbplpadfklayjguyvtrzhwblftclfmsr",
"output": "NO"
},
{
"input": "qfdwsr jsbrpfmn znplcx nhlselflytndzmgxqpgwhpi ghvbbxrkjdirfghcybhkkqdzmyacvrrcgsneyjlgzfvdmxyjmph\nylxlyrzs drbktzsniwcbahjkgohcghoaczsmtzhuwdryjwdijmxkmbmxv yyfrokdnsx\nyw xtwyzqlfxwxghugoyscqlx pljtz aldfskvxlsxqgbihzndhxkswkxqpwnfcxzfyvncstfpqf",
"output": "NO"
},
{
"input": "g rguhqhcrzmuqthtmwzhfyhpmqzzosa\nmhjimzvchkhejh irvzejhtjgaujkqfxhpdqjnxr dvqallgssktqvsxi\npcwbliftjcvuzrsqiswohi",
"output": "NO"
},
{
"input": " ngxtlq iehiise vgffqcpnmsoqzyseuqqtggokymol zn\nvjdjljazeujwoubkcvtsbepooxqzrueaauokhepiquuopfild\ngoabauauaeotoieufueeknudiilupouaiaexcoapapu",
"output": "NO"
},
{
"input": "ycnvnnqk mhrmhctpkfbc qbyvtjznmndqjzgbcxmvrpkfcll zwspfptmbxgrdv dsgkk nfytsqjrnfbhh pzdldzymvkdxxwh\nvnhjfwgdnyjptsmblyxmpzylsbjlmtkkwjcbqwjctqvrlqqkdsrktxlnslspvnn mdgsmzblhbnvpczmqkcffwhwljqkzmk hxcm\nrghnjvzcpprrgmtgytpkzyc mrdnnhpkwypwqbtzjyfwvrdwyjltbzxtbstzs xdjzdmx yjsqtzlrnvyssvglsdjrmsrfrcdpqt",
"output": "NO"
},
{
"input": "ioeeaioeiuoeaeieuuieooaouiuouiioaueeaiaiuoaoiioeeaauooiuuieeuaeeoauieeaiuoieiaieuoauaaoioooieueueuai\nuooaoeeaoiuuoeioaoouaououoeioiaeueoioaiouaeaoioiuuaueeuaiuoiueoiuaoeeieeouaeeaeeieioeoiiieuuueuuieuo\naeeouieeieoueaioeoioooiouaeeeiaaioueauaueiouuuaieuuioiaeiueauueaoieauauoeueuaiueuuaueeoueauaeaoieeoo",
"output": "NO"
},
{
"input": "mkgycgmrqtmlwj vddlbsgdptyfrcj nmrddjchydvbsyhgzytfzvwbhqmmhkpsyrcnknpsqrr wcnf wfvgskrnsmnrcqgcnc q\npn cclcyjjdp rqkpgyrvyyd hhynrochfa pthyffqvskazfshvzcmvhmsrxvquzkdvivlbfypwbgltfbjmhzljvgzmxjlrjdjq\nauuouieuaaauoooeoiuoaueuueauiuuuiaeuwuoiaeoeaieauieouoaeiiieiioiuuuiuauioiiuoeauueieaueiaioeuaoaaau",
"output": "NO"
},
{
"input": "ab\na\na",
"output": "NO"
},
{
"input": "on codeforcs\nbeta round is runnineg\na rustling of keys",
"output": "NO"
},
{
"input": "coooooooooooooooood\nd\nd",
"output": "NO"
},
{
"input": "on codeforces \nbeta round is runninog\n a rustling of keys",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaa\na\na",
"output": "NO"
},
{
"input": "aaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
"output": "YES"
},
{
"input": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
"output": "NO"
},
{
"input": "aaaaaa\naaaaaa\naaaaa",
"output": "NO"
}
] | 1,632,419,508 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 218 | 20,172,800 | a = input()
damn = 0
damn += a.count('a')
damn += a.count('e')
damn += a.count('i')
damn += a.count('o')
damn += a.count('u')
if damn != 5:
print('NO')
exit()
damn = 0
b = input()
damn += b.count('a')
damn += b.count('e')
damn += b.count('i')
damn += b.count('o')
damn += b.count('u')
if damn != 7:
print('NO')
exit()
damn = 0
c = input()
damn += c.count('a')
damn += c.count('e')
damn += c.count('i')
damn += c.count('o')
damn += c.count('u')
if damn != 5:
print('NO')
exit()
else:
print('YES') | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.
To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".
Three phases from a certain poem are given. Determine whether it is haiku or not.
Input Specification:
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.
Output Specification:
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
Demo Input:
['on codeforces \nbeta round is running\n a rustling of keys \n', 'how many gallons\nof edo s rain did you drink\n cuckoo\n']
Demo Output:
['YES', 'NO']
Note:
none | ```python
a = input()
damn = 0
damn += a.count('a')
damn += a.count('e')
damn += a.count('i')
damn += a.count('o')
damn += a.count('u')
if damn != 5:
print('NO')
exit()
damn = 0
b = input()
damn += b.count('a')
damn += b.count('e')
damn += b.count('i')
damn += b.count('o')
damn += b.count('u')
if damn != 7:
print('NO')
exit()
damn = 0
c = input()
damn += c.count('a')
damn += c.count('e')
damn += c.count('i')
damn += c.count('o')
damn += c.count('u')
if damn != 5:
print('NO')
exit()
else:
print('YES')
``` | 3.907925 |
10 | A | Power Consumption Calculation | PROGRAMMING | 900 | [
"implementation"
] | A. Power Consumption Calculation | 1 | 256 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*]. | The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=1440, *r**i*<=<<=*l**i*<=+<=1 for *i*<=<<=*n*), which stand for the start and the end of the *i*-th period of work. | Output the answer to the problem. | [
"1 3 2 1 5 10\n0 10\n",
"2 8 4 2 5 10\n20 30\n50 100\n"
] | [
"30",
"570"
] | none | 0 | [
{
"input": "1 3 2 1 5 10\n0 10",
"output": "30"
},
{
"input": "2 8 4 2 5 10\n20 30\n50 100",
"output": "570"
},
{
"input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436",
"output": "8445"
},
{
"input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945",
"output": "52870"
},
{
"input": "5 41 20 33 43 4\n46 465\n598 875\n967 980\n1135 1151\n1194 1245",
"output": "46995"
},
{
"input": "6 88 28 100 53 36\n440 445\n525 614\n644 844\n1238 1261\n1305 1307\n1425 1434",
"output": "85540"
},
{
"input": "7 46 61 55 28 59\n24 26\n31 61\n66 133\n161 612\n741 746\n771 849\n1345 1357",
"output": "67147"
},
{
"input": "8 83 18 30 28 5\n196 249\n313 544\n585 630\n718 843\n1040 1194\n1207 1246\n1268 1370\n1414 1422",
"output": "85876"
},
{
"input": "9 31 65 27 53 54\n164 176\n194 210\n485 538\n617 690\n875 886\n888 902\n955 957\n1020 1200\n1205 1282",
"output": "38570"
},
{
"input": "30 3 1 58 44 7\n11 13\n14 32\n37 50\n70 74\n101 106\n113 129\n184 195\n197 205\n213 228\n370 394\n443 446\n457 460\n461 492\n499 585\n602 627\n709 776\n812 818\n859 864\n910 913\n918 964\n1000 1010\n1051 1056\n1063 1075\n1106 1145\n1152 1189\n1211 1212\n1251 1259\n1272 1375\n1412 1417\n1430 1431",
"output": "11134"
},
{
"input": "30 42 3 76 28 26\n38 44\n55 66\n80 81\n84 283\n298 314\n331 345\n491 531\n569 579\n597 606\n612 617\n623 701\n723 740\n747 752\n766 791\n801 827\n842 846\n853 891\n915 934\n945 949\n955 964\n991 1026\n1051 1059\n1067 1179\n1181 1191\n1214 1226\n1228 1233\n1294 1306\n1321 1340\n1371 1374\n1375 1424",
"output": "59043"
},
{
"input": "30 46 5 93 20 46\n12 34\n40 41\n54 58\n100 121\n162 182\n220 349\n358 383\n390 398\n401 403\n408 409\n431 444\n466 470\n471 535\n556 568\n641 671\n699 709\n767 777\n786 859\n862 885\n912 978\n985 997\n1013 1017\n1032 1038\n1047 1048\n1062 1080\n1094 1097\n1102 1113\n1122 1181\n1239 1280\n1320 1369",
"output": "53608"
},
{
"input": "30 50 74 77 4 57\n17 23\n24 61\n67 68\n79 87\n93 101\n104 123\n150 192\n375 377\n398 414\n461 566\n600 633\n642 646\n657 701\n771 808\n812 819\n823 826\n827 833\n862 875\n880 891\n919 920\n928 959\n970 1038\n1057 1072\n1074 1130\n1165 1169\n1171 1230\n1265 1276\n1279 1302\n1313 1353\n1354 1438",
"output": "84067"
},
{
"input": "30 54 76 95 48 16\n9 11\n23 97\n112 116\n126 185\n214 223\n224 271\n278 282\n283 348\n359 368\n373 376\n452 463\n488 512\n532 552\n646 665\n681 685\n699 718\n735 736\n750 777\n791 810\n828 838\n841 858\n874 1079\n1136 1171\n1197 1203\n1210 1219\n1230 1248\n1280 1292\n1324 1374\n1397 1435\n1438 1439",
"output": "79844"
},
{
"input": "30 58 78 12 41 28\n20 26\n27 31\n35 36\n38 99\n103 104\n106 112\n133 143\n181 246\n248 251\n265 323\n350 357\n378 426\n430 443\n466 476\n510 515\n517 540\n542 554\n562 603\n664 810\n819 823\n826 845\n869 895\n921 973\n1002 1023\n1102 1136\n1143 1148\n1155 1288\n1316 1388\n1394 1403\n1434 1437",
"output": "82686"
},
{
"input": "30 62 80 97 25 47\n19 20\n43 75\n185 188\n199 242\n252 258\n277 310\n316 322\n336 357\n398 399\n404 436\n443 520\n549 617\n637 649\n679 694\n705 715\n725 730\n731 756\n768 793\n806 833\n834 967\n1003 1079\n1088 1097\n1100 1104\n1108 1121\n1127 1164\n1240 1263\n1274 1307\n1367 1407\n1419 1425\n1433 1437",
"output": "92356"
},
{
"input": "30 100 48 14 9 7\n26 55\n75 107\n145 146\n158 167\n197 199\n201 213\n222 238\n257 265\n271 338\n357 439\n454 462\n463 562\n633 660\n670 691\n696 829\n844 864\n880 888\n891 894\n895 900\n950 973\n1004 1007\n1018 1021\n1045 1049\n1062 1073\n1138 1184\n1240 1272\n1278 1315\n1403 1410\n1412 1418\n1426 1434",
"output": "107490"
},
{
"input": "30 3 50 32 1 18\n46 60\n66 94\n99 141\n162 239\n309 334\n400 550\n594 630\n659 663\n664 701\n735 736\n741 755\n756 801\n823 854\n865 915\n937 964\n984 986\n990 1007\n1008 1031\n1052 1064\n1073 1080\n1190 1191\n1192 1254\n1265 1266\n1272 1273\n1274 1277\n1284 1302\n1308 1312\n1358 1383\n1388 1389\n1390 1401",
"output": "25258"
},
{
"input": "30 7 52 49 46 37\n2 73\n129 130\n131 140\n143 150\n187 190\n217 238\n248 271\n375 426\n465 470\n475 503\n506 541\n569 571\n578 585\n680 683\n690 738\n742 761\n868 877\n890 892\n904 915\n935 961\n1076 1100\n1103 1114\n1232 1244\n1246 1247\n1257 1261\n1271 1276\n1280 1298\n1346 1360\n1373 1382\n1407 1419",
"output": "23992"
}
] | 1,496,763,811 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | k=0
f=[]
n,a,b,c,d,e = map(int,input().split())
for i in range(0,n):
x,y = map(int,input().split())
k=k+(a*(y-x))
f.append(y)
if (x-f[i-1])<=d and (x-f[i-1])>=1:
k=k+(a*(x-f[i-1]))
if (x-f[i-1])>d and (x-f[i-1])<=(d+e):
k=k+(d*a)+(b*((x-f[i-1])-d))
if (x-f[i-1])>(d+e):
k=k+(d*a)+(10*b)+(c*((x-f[i-1])-(d+e)))
print(k)
| Title: Power Consumption Calculation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*].
Input Specification:
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=1440, *r**i*<=<<=*l**i*<=+<=1 for *i*<=<<=*n*), which stand for the start and the end of the *i*-th period of work.
Output Specification:
Output the answer to the problem.
Demo Input:
['1 3 2 1 5 10\n0 10\n', '2 8 4 2 5 10\n20 30\n50 100\n']
Demo Output:
['30', '570']
Note:
none | ```python
k=0
f=[]
n,a,b,c,d,e = map(int,input().split())
for i in range(0,n):
x,y = map(int,input().split())
k=k+(a*(y-x))
f.append(y)
if (x-f[i-1])<=d and (x-f[i-1])>=1:
k=k+(a*(x-f[i-1]))
if (x-f[i-1])>d and (x-f[i-1])<=(d+e):
k=k+(d*a)+(b*((x-f[i-1])-d))
if (x-f[i-1])>(d+e):
k=k+(d*a)+(10*b)+(c*((x-f[i-1])-(d+e)))
print(k)
``` | 0 |
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,668,555,960 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 280 | 2,457,600 | n = input()
st = []
for i in range(len(n)):
st.append(n[i])
while len(st) > 1 and st[-1] == st[-2]:
st.pop()
st.pop()
print(''.join(st))
| 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
n = input()
st = []
for i in range(len(n)):
st.append(n[i])
while len(st) > 1 and st[-1] == st[-2]:
st.pop()
st.pop()
print(''.join(st))
``` | 3.855422 |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
"input": "oops",
"output": "oops"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "a"
},
{
"input": "aA",
"output": "Aa"
},
{
"input": "Zz",
"output": "Zz"
},
{
"input": "Az",
"output": "Az"
},
{
"input": "zA",
"output": "Za"
},
{
"input": "AAA",
"output": "aaa"
},
{
"input": "AAa",
"output": "AAa"
},
{
"input": "AaR",
"output": "AaR"
},
{
"input": "Tdr",
"output": "Tdr"
},
{
"input": "aTF",
"output": "Atf"
},
{
"input": "fYd",
"output": "fYd"
},
{
"input": "dsA",
"output": "dsA"
},
{
"input": "fru",
"output": "fru"
},
{
"input": "hYBKF",
"output": "Hybkf"
},
{
"input": "XweAR",
"output": "XweAR"
},
{
"input": "mogqx",
"output": "mogqx"
},
{
"input": "eOhEi",
"output": "eOhEi"
},
{
"input": "nkdku",
"output": "nkdku"
},
{
"input": "zcnko",
"output": "zcnko"
},
{
"input": "lcccd",
"output": "lcccd"
},
{
"input": "vwmvg",
"output": "vwmvg"
},
{
"input": "lvchf",
"output": "lvchf"
},
{
"input": "IUNVZCCHEWENCHQQXQYPUJCRDZLUXCLJHXPHBXEUUGNXOOOPBMOBRIBHHMIRILYJGYYGFMTMFSVURGYHUWDRLQVIBRLPEVAMJQYO",
"output": "iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgyygfmtmfsvurgyhuwdrlqvibrlpevamjqyo"
},
{
"input": "OBHSZCAMDXEJWOZLKXQKIVXUUQJKJLMMFNBPXAEFXGVNSKQLJGXHUXHGCOTESIVKSFMVVXFVMTEKACRIWALAGGMCGFEXQKNYMRTG",
"output": "obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksfmvvxfvmtekacriwalaggmcgfexqknymrtg"
},
{
"input": "IKJYZIKROIYUUCTHSVSKZTETNNOCMAUBLFJCEVANCADASMZRCNLBZPQRXESHEEMOMEPCHROSRTNBIDXYMEPJSIXSZQEBTEKKUHFS",
"output": "ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemomepchrosrtnbidxymepjsixszqebtekkuhfs"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "uCKJZRGZJCPPLEEYJTUNKOQSWGBMTBQEVPYFPIPEKRVYQNTDPANOIXKMPINNFUSZWCURGBDPYTEKBEKCPMVZPMWAOSHJYMGKOMBQ",
"output": "Uckjzrgzjcppleeyjtunkoqswgbmtbqevpyfpipekrvyqntdpanoixkmpinnfuszwcurgbdpytekbekcpmvzpmwaoshjymgkombq"
},
{
"input": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR",
"output": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR"
},
{
"input": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE",
"output": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE"
},
{
"input": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ",
"output": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ"
},
{
"input": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm",
"output": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm"
},
{
"input": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm",
"output": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm"
},
{
"input": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg",
"output": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg"
},
{
"input": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc",
"output": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc"
},
{
"input": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv",
"output": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv"
},
{
"input": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect",
"output": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu",
"output": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu"
},
{
"input": "aBACABa",
"output": "aBACABa"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAaa",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAaa"
},
{
"input": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
},
{
"input": "dDDDDDDDDDDDDD",
"output": "Dddddddddddddd"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "z",
"output": "Z"
},
{
"input": "AZ",
"output": "az"
},
{
"input": "Z",
"output": "z"
},
{
"input": "aAAAA",
"output": "Aaaaa"
},
{
"input": "F",
"output": "f"
}
] | 1,696,342,583 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 77 | 0 | s=input()
f=""
f+=s[0].upper()
n=len(s)
for i in range(1,n):
if s[i].isupper()==True:
f+=s[i].lower()
else:
print(s)
exit(0)
print(f)
| Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input Specification:
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output Specification:
Print the result of the given word's processing.
Demo Input:
['cAPS\n', 'Lock\n']
Demo Output:
['Caps', 'Lock\n']
Note:
none | ```python
s=input()
f=""
f+=s[0].upper()
n=len(s)
for i in range(1,n):
if s[i].isupper()==True:
f+=s[i].lower()
else:
print(s)
exit(0)
print(f)
``` | 0 |
|
917 | A | The Monster | PROGRAMMING | 1,800 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him.
Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem.
A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally:
- Empty string is a correct bracket sequence. - if *s* is a correct bracket sequence, then (*s*) is also a correct bracket sequence. - if *s* and *t* are correct bracket sequences, then *st* (concatenation of *s* and *t*) is also a correct bracket sequence.
A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence.
Will gave his mom a string *s* consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers (*l*,<=*r*) such that 1<=≤<=*l*<=≤<=*r*<=≤<=|*s*| and the string *s**l**s**l*<=+<=1... *s**r* is pretty, where *s**i* is *i*-th character of *s*.
Joyce doesn't know anything about bracket sequences, so she asked for your help. | The first and only line of input contains string *s*, consisting only of characters '(', ')' and '?' (2<=≤<=|*s*|<=≤<=5000). | Print the answer to Will's puzzle in the first and only line of output. | [
"((?))\n",
"??()??\n"
] | [
"4\n",
"7\n"
] | For the first sample testcase, the pretty substrings of *s* are:
1. "(?" which can be transformed to "()". 1. "?)" which can be transformed to "()". 1. "((?)" which can be transformed to "(())". 1. "(?))" which can be transformed to "(())".
For the second sample testcase, the pretty substrings of *s* are:
1. "??" which can be transformed to "()". 1. "()". 1. "??()" which can be transformed to "()()". 1. "?()?" which can be transformed to "(())". 1. "??" which can be transformed to "()". 1. "()??" which can be transformed to "()()". 1. "??()??" which can be transformed to "()()()". | 500 | [
{
"input": "((?))",
"output": "4"
},
{
"input": "??()??",
"output": "7"
},
{
"input": "?????)(???",
"output": "21"
},
{
"input": "()()((?(()(((()()(())(((()((())))(()))(()(((((())))()))(((()()()))))))(((((()))))))))",
"output": "62"
},
{
"input": "))((()(()((((()))())()())((())())(((()()(())))))((())()()(()()(())()))()()(()()()(((()(()(()(()))))(",
"output": "88"
},
{
"input": "????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "2500"
},
{
"input": ")(",
"output": "0"
},
{
"input": "?(",
"output": "0"
},
{
"input": "??",
"output": "1"
},
{
"input": ")?(??((???????()?(?????????)??(????????((?)?????)????)??????(?????)?)?????)??????(??()??????)????????)?)()??????????????())????????(???)??)????????????????????(?????)??)???)??(???????????????)???)??)?",
"output": "8314"
},
{
"input": "()",
"output": "1"
},
{
"input": "(?",
"output": "1"
}
] | 1,595,861,521 | 2,147,483,647 | PyPy 3 | OK | TESTS | 57 | 249 | 22,630,400 | st=input()
le=len(st)
ans=0
for i in range(le):
l=0
w=0
for j in range(i,le):
if(st[j]=="("):
l+=1
elif(st[j]==")"):
l-=1
else:
w+=1
if(l+w<0):
break
elif(w>l):
xx=l
l=w
w=xx
elif(l==w):
ans+=1
print(ans) | Title: The Monster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him.
Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem.
A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally:
- Empty string is a correct bracket sequence. - if *s* is a correct bracket sequence, then (*s*) is also a correct bracket sequence. - if *s* and *t* are correct bracket sequences, then *st* (concatenation of *s* and *t*) is also a correct bracket sequence.
A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence.
Will gave his mom a string *s* consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers (*l*,<=*r*) such that 1<=≤<=*l*<=≤<=*r*<=≤<=|*s*| and the string *s**l**s**l*<=+<=1... *s**r* is pretty, where *s**i* is *i*-th character of *s*.
Joyce doesn't know anything about bracket sequences, so she asked for your help.
Input Specification:
The first and only line of input contains string *s*, consisting only of characters '(', ')' and '?' (2<=≤<=|*s*|<=≤<=5000).
Output Specification:
Print the answer to Will's puzzle in the first and only line of output.
Demo Input:
['((?))\n', '??()??\n']
Demo Output:
['4\n', '7\n']
Note:
For the first sample testcase, the pretty substrings of *s* are:
1. "(?" which can be transformed to "()". 1. "?)" which can be transformed to "()". 1. "((?)" which can be transformed to "(())". 1. "(?))" which can be transformed to "(())".
For the second sample testcase, the pretty substrings of *s* are:
1. "??" which can be transformed to "()". 1. "()". 1. "??()" which can be transformed to "()()". 1. "?()?" which can be transformed to "(())". 1. "??" which can be transformed to "()". 1. "()??" which can be transformed to "()()". 1. "??()??" which can be transformed to "()()()". | ```python
st=input()
le=len(st)
ans=0
for i in range(le):
l=0
w=0
for j in range(i,le):
if(st[j]=="("):
l+=1
elif(st[j]==")"):
l-=1
else:
w+=1
if(l+w<0):
break
elif(w>l):
xx=l
l=w
w=xx
elif(l==w):
ans+=1
print(ans)
``` | 3 |
|
803 | E | Roma and Poker | PROGRAMMING | 2,000 | [
"dp",
"graphs"
] | null | null | Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser.
Last evening Roma started to play poker. He decided to spend no more than *k* virtual bourles — he will stop immediately if the number of his loses exceeds the number of his wins by *k*. Also Roma will leave the game if he wins enough money for the evening, i.e. if the number of wins exceeds the number of loses by *k*.
Next morning Roma found a piece of paper with a sequence on it representing his results. Roma doesn't remember the results exactly, and some characters in the sequence are written in a way such that it's impossible to recognize this character, so Roma can't recall whether he won *k* bourles or he lost.
The sequence written by Roma is a string *s* consisting of characters W (Roma won the corresponding hand), L (Roma lost), D (draw) and ? (unknown result). Roma wants to restore any valid sequence by changing all ? characters to W, L or D. The sequence is called valid if all these conditions are met:
- In the end the absolute difference between the number of wins and loses is equal to *k*; - There is no hand such that the absolute difference before this hand was equal to *k*.
Help Roma to restore any such sequence. | The first line contains two numbers *n* (the length of Roma's sequence) and *k* (1<=≤<=*n*,<=*k*<=≤<=1000).
The second line contains the sequence *s* consisting of characters W, L, D and ?. There are exactly *n* characters in this sequence. | If there is no valid sequence that can be obtained from *s* by replacing all ? characters by W, L or D, print NO.
Otherwise print this sequence. If there are multiple answers, print any of them. | [
"3 2\nL??\n",
"3 1\nW??\n",
"20 5\n?LLLLLWWWWW?????????\n"
] | [
"LDL\n",
"NO\n",
"WLLLLLWWWWWWWWLWLWDW\n"
] | none | 0 | [
{
"input": "3 2\nL??",
"output": "LDL"
},
{
"input": "3 1\nW??",
"output": "NO"
},
{
"input": "20 5\n?LLLLLWWWWW?????????",
"output": "WLLLLLWWWWWWWWLWLWDW"
},
{
"input": "5 5\n?WDDD",
"output": "NO"
},
{
"input": "5 3\n??D??",
"output": "WWDDW"
},
{
"input": "10 1\nD??W?WL?DW",
"output": "NO"
},
{
"input": "10 3\nDWD?DL??LL",
"output": "DWDWDLLLLL"
},
{
"input": "10 2\nLWL?WWDDW?",
"output": "NO"
},
{
"input": "1 1\n?",
"output": "W"
}
] | 1,493,399,403 | 7,503 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 4,915,200 | n, k = map(int, input().split())
s=input()
won=0
lost=0
drawn=0
un=0
for i in range(n):
if s[i]=='W':
won+=1
elif s[i]=='L':
lost+=1
elif s[i]=='D':
drawn+=1
else:
un+=1
if won>=lost+k:
print('NO')
else:
if won+un>=k and (won!=k or s[-1]=='?'):
s=list(s)
for i in range(n-1, -1, -1):
if won>lost+k:
break
if s[i]=='?':
s[i]='W'
won+=1
for i in range(n):
if s[i]=='?':
s[i]='D'
if lost+un>=k:
s=list(s)
for i in range(n-1, -1, -1):
if lost>k:
break
if s[i]=='?':
s[i]='L'
un-=1
lost+=1
for i in range(n):
if un==0:
break
if s[i]=='?':
s[i]='D'
un-=1
print(''.join(s))
| Title: Roma and Poker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser.
Last evening Roma started to play poker. He decided to spend no more than *k* virtual bourles — he will stop immediately if the number of his loses exceeds the number of his wins by *k*. Also Roma will leave the game if he wins enough money for the evening, i.e. if the number of wins exceeds the number of loses by *k*.
Next morning Roma found a piece of paper with a sequence on it representing his results. Roma doesn't remember the results exactly, and some characters in the sequence are written in a way such that it's impossible to recognize this character, so Roma can't recall whether he won *k* bourles or he lost.
The sequence written by Roma is a string *s* consisting of characters W (Roma won the corresponding hand), L (Roma lost), D (draw) and ? (unknown result). Roma wants to restore any valid sequence by changing all ? characters to W, L or D. The sequence is called valid if all these conditions are met:
- In the end the absolute difference between the number of wins and loses is equal to *k*; - There is no hand such that the absolute difference before this hand was equal to *k*.
Help Roma to restore any such sequence.
Input Specification:
The first line contains two numbers *n* (the length of Roma's sequence) and *k* (1<=≤<=*n*,<=*k*<=≤<=1000).
The second line contains the sequence *s* consisting of characters W, L, D and ?. There are exactly *n* characters in this sequence.
Output Specification:
If there is no valid sequence that can be obtained from *s* by replacing all ? characters by W, L or D, print NO.
Otherwise print this sequence. If there are multiple answers, print any of them.
Demo Input:
['3 2\nL??\n', '3 1\nW??\n', '20 5\n?LLLLLWWWWW?????????\n']
Demo Output:
['LDL\n', 'NO\n', 'WLLLLLWWWWWWWWLWLWDW\n']
Note:
none | ```python
n, k = map(int, input().split())
s=input()
won=0
lost=0
drawn=0
un=0
for i in range(n):
if s[i]=='W':
won+=1
elif s[i]=='L':
lost+=1
elif s[i]=='D':
drawn+=1
else:
un+=1
if won>=lost+k:
print('NO')
else:
if won+un>=k and (won!=k or s[-1]=='?'):
s=list(s)
for i in range(n-1, -1, -1):
if won>lost+k:
break
if s[i]=='?':
s[i]='W'
won+=1
for i in range(n):
if s[i]=='?':
s[i]='D'
if lost+un>=k:
s=list(s)
for i in range(n-1, -1, -1):
if lost>k:
break
if s[i]=='?':
s[i]='L'
un-=1
lost+=1
for i in range(n):
if un==0:
break
if s[i]=='?':
s[i]='D'
un-=1
print(''.join(s))
``` | 0 |
|
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*. | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "100000",
"output": "50000\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "7",
"output": "3\n2 2 3"
},
{
"input": "4",
"output": "2\n2 2"
},
{
"input": "8",
"output": "4\n2 2 2 2"
},
{
"input": "9",
"output": "4\n2 2 2 3"
},
{
"input": "99995",
"output": "49997\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "99996",
"output": "49998\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "10",
"output": "5\n2 2 2 2 2"
},
{
"input": "11",
"output": "5\n2 2 2 2 3"
},
{
"input": "99997",
"output": "49998\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "99998",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "12",
"output": "6\n2 2 2 2 2 2"
},
{
"input": "13",
"output": "6\n2 2 2 2 2 3"
},
{
"input": "99993",
"output": "49996\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "99994",
"output": "49997\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "14",
"output": "7\n2 2 2 2 2 2 2"
},
{
"input": "15",
"output": "7\n2 2 2 2 2 2 3"
},
{
"input": "53",
"output": "26\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "57",
"output": "28\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "61",
"output": "30\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "774",
"output": "387\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "202",
"output": "101\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2"
},
{
"input": "530",
"output": "265\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "7166",
"output": "3583\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "9294",
"output": "4647\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "2422",
"output": "1211\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "15326",
"output": "7663\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "11454",
"output": "5727\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "14878",
"output": "7439\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "90672",
"output": "45336\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "99544",
"output": "49772\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "90472",
"output": "45236\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "23",
"output": "11\n2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "93",
"output": "46\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "19",
"output": "9\n2 2 2 2 2 2 2 2 3"
},
{
"input": "11110",
"output": "5555\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
}
] | 1,687,491,269 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 78 | 1,024,000 | def main():
a = int(input())
b = [2] * (a // 2)
print(a // 2)
if a % 2 != 0:
b[-1] = 3
print(*b)
main() | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*.
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
Output Specification:
The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
Demo Input:
['5\n', '6\n']
Demo Output:
['2\n2 3\n', '3\n2 2 2\n']
Note:
none | ```python
def main():
a = int(input())
b = [2] * (a // 2)
print(a // 2)
if a % 2 != 0:
b[-1] = 3
print(*b)
main()
``` | 3 |
|
573 | A | Bear and Poker | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | 500 | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612562357 552908390 914853758 915004122 466129205 122853497 814592742 373389439 818473058",
"output": "No"
},
{
"input": "2\n1 1",
"output": "Yes"
},
{
"input": "2\n72 72",
"output": "Yes"
},
{
"input": "2\n49 42",
"output": "No"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "Yes"
},
{
"input": "6\n162000 96000 648000 1000 864000 432000",
"output": "Yes"
},
{
"input": "8\n600000 100000 100000 100000 900000 600000 900000 600000",
"output": "Yes"
},
{
"input": "12\n2048 1024 6144 1024 3072 3072 6144 1024 4096 2048 6144 3072",
"output": "Yes"
},
{
"input": "20\n246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246",
"output": "Yes"
},
{
"input": "50\n840868705 387420489 387420489 795385082 634350497 206851546 536870912 536870912 414927754 387420489 387420489 536870912 387420489 149011306 373106005 536870912 700746206 387420489 777952883 847215247 176645254 576664386 387420489 230876513 536870912 536870912 536870912 387420489 387420489 536870912 460495524 528643722 387420489 536870912 470369206 899619085 387420489 631148352 387420489 387420489 536870912 414666674 521349938 776784669 387420489 102428009 536870912 387420489 536870912 718311009",
"output": "No"
},
{
"input": "2\n5 6",
"output": "No"
},
{
"input": "3\n536870912 387420489 257407169",
"output": "No"
},
{
"input": "4\n2 2 5 2",
"output": "No"
},
{
"input": "2\n33554432 59049",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 387420489",
"output": "Yes"
},
{
"input": "2\n1 5",
"output": "No"
},
{
"input": "18\n2 3 5 7 11 13 17 19 23 29 31 37 43 47 53 59 67 71",
"output": "No"
},
{
"input": "2\n1 30",
"output": "No"
},
{
"input": "3\n335544320 71744535 71744535",
"output": "Yes"
},
{
"input": "5\n1000000000 999999999 999999998 999999997 999999996",
"output": "No"
},
{
"input": "2\n25 5",
"output": "No"
},
{
"input": "4\n75 150 75 5",
"output": "No"
},
{
"input": "3\n536870912 387420489 362797056",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 89",
"output": "No"
},
{
"input": "4\n547 2606459 222763549 143466789",
"output": "No"
},
{
"input": "3\n129140163 33554432 1",
"output": "Yes"
},
{
"input": "10\n244140625 244140625 244140625 244140625 244140625 244140625 244140625 244140625 536870912 387420489",
"output": "No"
},
{
"input": "3\n5 5 1",
"output": "No"
},
{
"input": "5\n3 7 29 36760123 823996703",
"output": "No"
}
] | 1,589,301,169 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 779 | 15,872,000 | n = int(input())
m=list(map(int,input().split()))
for i in range(n):
while(m[i]%2==0):
m[i]//=2
while(m[i]%3==0):
m[i]//=3
if(len(set(m))==1):
print('Yes')
else:
print('No')
| Title: Bear and Poker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?
Input Specification:
First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players.
Output Specification:
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
Demo Input:
['4\n75 150 75 50\n', '3\n100 150 250\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | ```python
n = int(input())
m=list(map(int,input().split()))
for i in range(n):
while(m[i]%2==0):
m[i]//=2
while(m[i]%3==0):
m[i]//=3
if(len(set(m))==1):
print('Yes')
else:
print('No')
``` | 3 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,676,207,480 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | s_1=input()
l=0
u=0
for i in s_1:
if(i.islower()):
l=l+1
else:
u=u+1
if(l>u):
print(s_1.lower())
else:
print(s_1.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
s_1=input()
l=0
u=0
for i in s_1:
if(i.islower()):
l=l+1
else:
u=u+1
if(l>u):
print(s_1.lower())
else:
print(s_1.upper())
``` | 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,595,608,290 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 93 | 6,963,200 | s=input()
k=0
for i in range(len(s)):
if s[i]=='h' and k==0:
k+=1
elif s[i]=='e' and k==1:
k+=1
elif s[i]=='l' and k==2:
k+=1
elif s[i]=='l' and k==3:
k+=1
elif s[i]=='o' and k==4:
k+=1
if k==5:
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()
k=0
for i in range(len(s)):
if s[i]=='h' and k==0:
k+=1
elif s[i]=='e' and k==1:
k+=1
elif s[i]=='l' and k==2:
k+=1
elif s[i]=='l' and k==3:
k+=1
elif s[i]=='o' and k==4:
k+=1
if k==5:
print("YES")
else:
print("NO")
``` | 3.94053 |
998 | B | Cutting | PROGRAMMING | 1,200 | [
"dp",
"greedy",
"sortings"
] | null | null | There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.
Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements.
The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins. | First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers | Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins. | [
"6 4\n1 2 5 10 15 20\n",
"4 10\n1 3 2 4\n",
"6 100\n1 2 3 4 5 6\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$. The total price of the cuts is $1 + 1 = 2$ bitcoins. | 1,000 | [
{
"input": "6 4\n1 2 5 10 15 20",
"output": "1"
},
{
"input": "4 10\n1 3 2 4",
"output": "0"
},
{
"input": "6 100\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "2 100\n13 78",
"output": "0"
},
{
"input": "10 1\n56 56 98 2 11 64 97 41 95 53",
"output": "0"
},
{
"input": "10 100\n94 65 24 47 29 98 20 65 6 17",
"output": "2"
},
{
"input": "100 1\n35 6 19 84 49 64 36 91 50 65 21 86 20 89 10 52 50 24 98 74 11 48 58 98 51 85 1 29 44 83 9 97 68 41 83 57 1 57 46 42 87 2 32 50 3 57 17 77 22 100 36 27 3 34 55 8 90 61 34 20 15 39 43 46 60 60 14 23 4 22 75 51 98 23 69 22 99 57 63 30 79 7 16 8 34 84 13 47 93 40 48 25 93 1 80 6 82 93 6 21",
"output": "0"
},
{
"input": "100 10\n3 20 3 29 90 69 2 30 70 28 71 99 22 99 34 70 87 48 3 92 71 61 26 90 14 38 51 81 16 33 49 71 14 52 50 95 65 16 80 57 87 47 29 14 40 31 74 15 87 76 71 61 30 91 44 10 87 48 84 12 77 51 25 68 49 38 79 8 7 9 39 19 48 40 15 53 29 4 60 86 76 84 6 37 45 71 46 38 80 68 94 71 64 72 41 51 71 60 79 7",
"output": "2"
},
{
"input": "100 100\n60 83 82 16 17 7 89 6 83 100 85 41 72 44 23 28 64 84 3 23 33 52 93 30 81 38 67 25 26 97 94 78 41 74 74 17 53 51 54 17 20 81 95 76 42 16 16 56 74 69 30 9 82 91 32 13 47 45 97 40 56 57 27 28 84 98 91 5 61 20 3 43 42 26 83 40 34 100 5 63 62 61 72 5 32 58 93 79 7 18 50 43 17 24 77 73 87 74 98 2",
"output": "11"
},
{
"input": "100 100\n70 54 10 72 81 84 56 15 27 19 43 100 49 44 52 33 63 40 95 17 58 2 51 39 22 18 82 1 16 99 32 29 24 94 9 98 5 37 47 14 42 73 41 31 79 64 12 6 53 26 68 67 89 13 90 4 21 93 46 74 75 88 66 57 23 7 25 48 92 62 30 8 50 61 38 87 71 34 97 28 80 11 60 91 3 35 86 96 36 20 59 65 83 45 76 77 78 69 85 55",
"output": "3"
},
{
"input": "100 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": "49"
},
{
"input": "10 10\n94 32 87 13 4 22 85 81 18 95",
"output": "1"
},
{
"input": "10 50\n40 40 9 3 64 96 67 19 21 30",
"output": "1"
},
{
"input": "100 50\n13 31 29 86 46 10 2 87 94 2 28 31 29 15 64 3 94 71 37 76 9 91 89 38 12 46 53 33 58 11 98 4 37 72 30 52 6 86 40 98 28 6 34 80 61 47 45 69 100 47 91 64 87 41 67 58 88 75 13 81 36 58 66 29 10 27 54 83 44 15 11 33 49 36 61 18 89 26 87 1 99 19 57 21 55 84 20 74 14 43 15 51 2 76 22 92 43 14 72 77",
"output": "3"
},
{
"input": "100 1\n78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 21 54 39 68 43 4 32 28 73 6 16 62 72 84 65 86 98 75 33 45 25 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 38 26 47 90 70 51 41 40 31 37 12 35 99 67 94 1 87 57 8 61 19 23 79 36 18 66 74 5 27 81 69 24 58 13 10 89 30",
"output": "0"
},
{
"input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "0"
},
{
"input": "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34",
"output": "1"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "1"
},
{
"input": "100 10\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": "10"
},
{
"input": "100 50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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": "49"
},
{
"input": "100 30\n2 1 2 2 2 2 1 1 1 2 1 1 2 2 1 2 1 2 2 2 2 1 2 1 2 1 1 2 1 1 2 2 2 1 1 2 1 2 2 2 1 1 1 1 1 2 1 1 1 1 1 2 2 2 2 1 2 1 1 1 2 2 2 2 1 2 2 1 1 1 1 2 2 2 1 2 2 1 2 1 1 2 2 2 1 2 2 1 2 1 1 2 1 1 1 1 2 1 1 2",
"output": "11"
},
{
"input": "100 80\n1 1 1 2 2 1 1 2 1 1 1 1 2 2 2 1 2 2 2 2 1 1 2 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 2 2 2 2 1 2 2 1 2 1 1 1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 2 1 1 1 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 2 2 2 1 2 2 1 2",
"output": "12"
},
{
"input": "100 30\n100 99 100 99 99 100 100 99 100 99 99 100 100 100 99 99 99 100 99 99 99 99 100 99 99 100 100 99 100 99 99 99 100 99 100 100 99 100 100 100 100 100 99 99 100 99 99 100 99 100 99 99 100 100 99 100 99 99 100 99 100 100 100 100 99 99 99 100 99 100 99 100 100 100 99 100 100 100 99 100 99 99 100 100 100 100 99 99 99 100 99 100 100 99 99 99 100 100 99 99",
"output": "14"
},
{
"input": "100 80\n99 100 100 100 99 99 99 99 100 99 99 99 99 99 99 99 99 100 100 99 99 99 99 99 100 99 100 99 100 100 100 100 100 99 100 100 99 99 100 100 100 100 100 99 100 99 100 99 99 99 100 99 99 99 99 99 99 99 99 100 99 100 100 99 99 99 99 100 100 100 99 100 100 100 100 100 99 100 100 100 100 100 100 100 100 99 99 99 99 100 99 100 100 100 100 100 99 100 99 100",
"output": "4"
},
{
"input": "100 30\n100 100 39 39 39 100 100 39 39 100 39 39 100 39 100 39 100 100 100 100 100 39 100 100 100 39 39 39 100 39 100 100 39 39 100 39 39 39 100 100 39 100 39 100 39 39 100 100 39 100 39 100 39 39 39 100 39 100 39 39 39 100 39 39 100 100 39 39 39 100 100 39 39 39 100 100 100 100 39 100 100 100 39 39 100 39 100 100 39 100 39 100 39 39 100 39 39 100 100 100",
"output": "5"
},
{
"input": "100 80\n39 100 39 100 100 100 100 39 39 100 100 39 39 100 39 39 39 39 100 39 39 39 39 100 100 100 100 39 100 39 39 100 100 39 39 100 39 100 39 100 100 39 39 100 39 39 39 100 39 100 39 100 100 100 100 100 100 100 39 100 39 100 100 100 39 39 39 39 39 100 100 100 39 100 100 100 100 39 100 100 39 39 100 39 39 39 100 39 100 39 39 100 100 39 100 39 39 39 100 39",
"output": "6"
},
{
"input": "4 1\n1 2 3 4",
"output": "1"
},
{
"input": "4 1\n1 2 1 2",
"output": "1"
},
{
"input": "4 4\n1 2 6 7",
"output": "1"
},
{
"input": "4 8\n1 2 10 11",
"output": "1"
},
{
"input": "6 2\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "6 1\n1 2 1 2 1 2",
"output": "1"
},
{
"input": "6 4\n1 2 4 5 7 8",
"output": "2"
},
{
"input": "6 3\n1 2 5 10 15 20",
"output": "1"
}
] | 1,602,175,544 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 93 | 307,200 | n,b=map(int,input().split())
a=list(map(int,input().split()))
q,w,l,m=0,0,[],0
for i in range(n-1):
if a[i]&1:q+=1
else:w+=1
if q==w:l.append(abs(a[i]-a[i+1]))
l.sort()
for i in l:
if i<=b:m+=1;b-=i
else:break
print(m) | Title: Cutting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.
Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements.
The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins.
Input Specification:
First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers
Output Specification:
Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins.
Demo Input:
['6 4\n1 2 5 10 15 20\n', '4 10\n1 3 2 4\n', '6 100\n1 2 3 4 5 6\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$. The total price of the cuts is $1 + 1 = 2$ bitcoins. | ```python
n,b=map(int,input().split())
a=list(map(int,input().split()))
q,w,l,m=0,0,[],0
for i in range(n-1):
if a[i]&1:q+=1
else:w+=1
if q==w:l.append(abs(a[i]-a[i+1]))
l.sort()
for i in l:
if i<=b:m+=1;b-=i
else:break
print(m)
``` | 3 |
|
868 | B | Race Against Time | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.
The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds.
Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction.
Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way).
Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face. | Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2).
Misha's position and the target time do not coincide with the position of any hand. | Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"12 30 45 3 11\n",
"12 0 1 12 1\n",
"3 47 0 4 9\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same. | 500 | [
{
"input": "12 30 45 3 11",
"output": "NO"
},
{
"input": "12 0 1 12 1",
"output": "YES"
},
{
"input": "3 47 0 4 9",
"output": "YES"
},
{
"input": "10 22 59 6 10",
"output": "YES"
},
{
"input": "3 1 13 12 3",
"output": "NO"
},
{
"input": "11 19 28 9 10",
"output": "YES"
},
{
"input": "9 38 22 6 1",
"output": "NO"
},
{
"input": "5 41 11 5 8",
"output": "NO"
},
{
"input": "11 2 53 10 4",
"output": "YES"
},
{
"input": "9 41 17 10 1",
"output": "YES"
},
{
"input": "6 54 48 12 6",
"output": "YES"
},
{
"input": "12 55 9 5 1",
"output": "NO"
},
{
"input": "8 55 35 9 3",
"output": "NO"
},
{
"input": "3 21 34 3 10",
"output": "YES"
},
{
"input": "2 52 1 12 3",
"output": "NO"
},
{
"input": "7 17 11 1 7",
"output": "NO"
},
{
"input": "11 6 37 6 4",
"output": "YES"
},
{
"input": "9 6 22 8 1",
"output": "NO"
},
{
"input": "3 10 5 5 9",
"output": "YES"
},
{
"input": "7 12 22 11 2",
"output": "YES"
},
{
"input": "7 19 4 7 3",
"output": "NO"
},
{
"input": "11 36 21 4 6",
"output": "NO"
},
{
"input": "10 32 49 1 3",
"output": "YES"
},
{
"input": "1 9 43 11 3",
"output": "NO"
},
{
"input": "1 8 33 4 8",
"output": "NO"
},
{
"input": "3 0 33 9 4",
"output": "NO"
},
{
"input": "7 15 9 10 3",
"output": "NO"
},
{
"input": "8 3 57 11 1",
"output": "NO"
},
{
"input": "1 33 49 5 9",
"output": "NO"
},
{
"input": "3 40 0 5 7",
"output": "YES"
},
{
"input": "5 50 9 2 7",
"output": "NO"
},
{
"input": "10 0 52 6 1",
"output": "YES"
},
{
"input": "3 10 4 1 11",
"output": "NO"
},
{
"input": "2 41 53 4 6",
"output": "YES"
},
{
"input": "10 29 30 4 7",
"output": "NO"
},
{
"input": "5 13 54 9 11",
"output": "NO"
},
{
"input": "1 0 23 3 9",
"output": "NO"
},
{
"input": "1 0 41 12 1",
"output": "NO"
},
{
"input": "6 30 30 3 9",
"output": "YES"
},
{
"input": "3 7 32 11 10",
"output": "YES"
},
{
"input": "1 0 25 12 4",
"output": "NO"
},
{
"input": "12 0 0 5 6",
"output": "YES"
},
{
"input": "1 5 4 3 2",
"output": "YES"
},
{
"input": "6 30 30 9 10",
"output": "YES"
},
{
"input": "6 0 0 2 8",
"output": "NO"
},
{
"input": "10 50 59 9 10",
"output": "YES"
},
{
"input": "12 59 59 12 6",
"output": "NO"
},
{
"input": "3 0 30 3 4",
"output": "NO"
},
{
"input": "2 10 10 1 11",
"output": "YES"
},
{
"input": "10 5 30 1 12",
"output": "YES"
},
{
"input": "5 29 31 5 10",
"output": "YES"
},
{
"input": "5 2 2 11 2",
"output": "NO"
},
{
"input": "5 15 46 3 10",
"output": "YES"
},
{
"input": "1 30 50 1 2",
"output": "NO"
},
{
"input": "5 26 14 1 12",
"output": "YES"
},
{
"input": "1 58 43 12 1",
"output": "YES"
},
{
"input": "12 0 12 11 1",
"output": "NO"
},
{
"input": "6 52 41 6 5",
"output": "YES"
},
{
"input": "5 8 2 1 3",
"output": "NO"
},
{
"input": "2 0 0 1 3",
"output": "NO"
},
{
"input": "1 5 6 2 1",
"output": "YES"
},
{
"input": "9 5 5 11 12",
"output": "YES"
},
{
"input": "12 5 19 3 4",
"output": "NO"
},
{
"input": "6 14 59 1 3",
"output": "NO"
},
{
"input": "10 38 34 4 12",
"output": "YES"
},
{
"input": "2 54 14 2 12",
"output": "YES"
},
{
"input": "5 31 0 6 7",
"output": "NO"
},
{
"input": "6 15 30 3 9",
"output": "YES"
},
{
"input": "3 54 41 8 10",
"output": "NO"
},
{
"input": "3 39 10 10 12",
"output": "YES"
},
{
"input": "1 11 50 1 2",
"output": "NO"
},
{
"input": "5 40 24 8 1",
"output": "NO"
},
{
"input": "9 5 59 1 3",
"output": "NO"
},
{
"input": "5 0 0 6 7",
"output": "YES"
},
{
"input": "4 40 59 6 8",
"output": "YES"
},
{
"input": "10 13 55 12 1",
"output": "YES"
},
{
"input": "6 50 0 5 6",
"output": "YES"
},
{
"input": "7 59 3 7 4",
"output": "YES"
},
{
"input": "6 0 1 6 7",
"output": "NO"
},
{
"input": "6 15 55 3 5",
"output": "NO"
},
{
"input": "12 9 55 10 2",
"output": "YES"
},
{
"input": "2 0 1 11 2",
"output": "NO"
},
{
"input": "8 45 17 12 9",
"output": "NO"
},
{
"input": "5 30 31 11 3",
"output": "YES"
},
{
"input": "6 43 0 10 6",
"output": "NO"
},
{
"input": "6 30 30 1 11",
"output": "YES"
},
{
"input": "11 59 59 11 12",
"output": "YES"
},
{
"input": "5 45 35 9 5",
"output": "NO"
},
{
"input": "2 43 4 9 7",
"output": "NO"
},
{
"input": "12 30 50 6 9",
"output": "NO"
},
{
"input": "1 10 1 2 3",
"output": "NO"
},
{
"input": "10 5 55 9 1",
"output": "NO"
},
{
"input": "1 59 59 2 3",
"output": "YES"
},
{
"input": "1 49 14 10 3",
"output": "NO"
},
{
"input": "3 15 15 2 4",
"output": "YES"
},
{
"input": "10 5 55 1 5",
"output": "NO"
},
{
"input": "6 33 45 12 6",
"output": "YES"
},
{
"input": "1 20 20 11 1",
"output": "YES"
},
{
"input": "2 30 45 1 11",
"output": "YES"
},
{
"input": "1 55 1 11 10",
"output": "YES"
},
{
"input": "3 0 1 11 1",
"output": "NO"
},
{
"input": "1 5 6 1 12",
"output": "YES"
},
{
"input": "12 10 5 11 4",
"output": "YES"
},
{
"input": "6 5 59 12 1",
"output": "YES"
},
{
"input": "12 0 20 11 12",
"output": "YES"
},
{
"input": "3 25 30 4 5",
"output": "YES"
},
{
"input": "2 15 18 11 1",
"output": "YES"
},
{
"input": "12 5 48 11 9",
"output": "NO"
},
{
"input": "6 30 30 10 2",
"output": "YES"
},
{
"input": "1 0 11 1 2",
"output": "NO"
},
{
"input": "10 0 1 10 11",
"output": "NO"
},
{
"input": "3 30 45 10 1",
"output": "YES"
},
{
"input": "11 21 56 3 12",
"output": "YES"
},
{
"input": "3 16 16 3 4",
"output": "YES"
},
{
"input": "11 55 55 1 12",
"output": "YES"
},
{
"input": "12 12 12 11 12",
"output": "YES"
},
{
"input": "3 5 1 1 2",
"output": "NO"
},
{
"input": "3 30 45 10 11",
"output": "YES"
},
{
"input": "10 0 1 9 10",
"output": "YES"
},
{
"input": "3 0 5 3 6",
"output": "NO"
},
{
"input": "1 1 49 1 10",
"output": "NO"
},
{
"input": "9 45 15 11 12",
"output": "YES"
},
{
"input": "12 15 59 3 8",
"output": "NO"
},
{
"input": "5 0 5 3 6",
"output": "NO"
},
{
"input": "3 30 45 1 2",
"output": "YES"
},
{
"input": "2 10 11 2 4",
"output": "YES"
},
{
"input": "2 10 10 4 3",
"output": "YES"
},
{
"input": "3 30 59 1 2",
"output": "YES"
},
{
"input": "11 59 59 12 11",
"output": "YES"
},
{
"input": "10 25 50 5 6",
"output": "NO"
},
{
"input": "6 30 30 9 3",
"output": "YES"
},
{
"input": "8 14 40 12 3",
"output": "NO"
},
{
"input": "2 10 10 1 6",
"output": "YES"
}
] | 1,507,191,468 | 4,368 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 46 | 0 | s1,s2,s3,be,end=map(int,input().split())
s=[s1*5,s2,s3]
be*=5
end*=5
end,be=max(be,end),min(be,end)
b1=True
b2=True
for i in s:
if end>i>be:
b1=False
else:
b2=False
if b1 or b2:
print('YES')
else:
print('NO')
| Title: Race Against Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.
The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds.
Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction.
Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way).
Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face.
Input Specification:
Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2).
Misha's position and the target time do not coincide with the position of any hand.
Output Specification:
Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Demo Input:
['12 30 45 3 11\n', '12 0 1 12 1\n', '3 47 0 4 9\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n']
Note:
The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same. | ```python
s1,s2,s3,be,end=map(int,input().split())
s=[s1*5,s2,s3]
be*=5
end*=5
end,be=max(be,end),min(be,end)
b1=True
b2=True
for i in s:
if end>i>be:
b1=False
else:
b2=False
if b1 or b2:
print('YES')
else:
print('NO')
``` | 0 |