contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
listlengths 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
listlengths 0
7
| demo-output
listlengths 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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
149
|
A
|
Business trip
|
PROGRAMMING
| 900
|
[
"greedy",
"implementation",
"sortings"
] | null | null |
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters.
|
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
|
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
|
[
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] |
[
"2\n",
"0\n",
"3\n"
] |
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all.
| 500
|
[
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 17 21 10 11 100 23 10",
"output": "1"
},
{
"input": "52\n1 12 3 11 4 5 10 6 9 7 8 2",
"output": "6"
},
{
"input": "50\n2 2 3 4 5 4 4 5 7 3 2 7",
"output": "-1"
},
{
"input": "0\n55 81 28 48 99 20 67 95 6 19 10 93",
"output": "0"
},
{
"input": "93\n85 40 93 66 92 43 61 3 64 51 90 21",
"output": "1"
},
{
"input": "99\n36 34 22 0 0 0 52 12 0 0 33 47",
"output": "2"
},
{
"input": "99\n28 32 31 0 10 35 11 18 0 0 32 28",
"output": "3"
},
{
"input": "99\n19 17 0 1 18 11 29 9 29 22 0 8",
"output": "4"
},
{
"input": "76\n2 16 11 10 12 0 20 4 4 14 11 14",
"output": "5"
},
{
"input": "41\n2 1 7 7 4 2 4 4 9 3 10 0",
"output": "6"
},
{
"input": "47\n8 2 2 4 3 1 9 4 2 7 7 8",
"output": "7"
},
{
"input": "58\n6 11 7 0 5 6 3 9 4 9 5 1",
"output": "8"
},
{
"input": "32\n5 2 4 1 5 0 5 1 4 3 0 3",
"output": "9"
},
{
"input": "31\n6 1 0 4 4 5 1 0 5 3 2 0",
"output": "9"
},
{
"input": "35\n2 3 0 0 6 3 3 4 3 5 0 6",
"output": "9"
},
{
"input": "41\n3 1 3 4 3 6 6 1 4 4 0 6",
"output": "11"
},
{
"input": "97\n0 5 3 12 10 16 22 8 21 17 21 10",
"output": "5"
},
{
"input": "100\n21 21 0 0 4 13 0 26 0 0 0 15",
"output": "6"
},
{
"input": "100\n0 0 16 5 22 0 5 0 25 0 14 13",
"output": "7"
},
{
"input": "97\n17 0 10 0 0 0 18 0 14 23 15 0",
"output": "6"
},
{
"input": "100\n0 9 0 18 7 0 0 14 33 3 0 16",
"output": "7"
},
{
"input": "95\n5 2 13 0 15 18 17 0 6 11 0 8",
"output": "9"
},
{
"input": "94\n11 13 0 9 15 8 8 16 3 7 1 3",
"output": "11"
},
{
"input": "96\n8 4 12 15 8 0 4 10 6 6 12 11",
"output": "11"
},
{
"input": "100\n5 5 3 8 6 5 0 3 3 8 1 3",
"output": "-1"
},
{
"input": "100\n1 0 0 1 1 0 1 1 1 1 2 1",
"output": "-1"
},
{
"input": "100\n6 3 2 0 4 1 2 2 2 2 1 1",
"output": "-1"
},
{
"input": "0\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
},
{
"input": "0\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "12"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 2",
"output": "12"
},
{
"input": "15\n10 1 1 1 1 1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "1\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
}
] | 1,640,939,767
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 35
| 92
| 0
|
k,heights = int(input()),sorted([int(i) for i in input().split()],reverse=True)
if k>sum(heights):
print(-1)
exit(0)
for i in range(len(heights)):
if k<=0:
break
else:
k-=heights[i]
print(i)
|
Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters.
Input Specification:
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Output Specification:
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
Demo Input:
['5\n1 1 1 1 2 2 3 2 2 1 1 1\n', '0\n0 0 0 0 0 0 0 1 1 2 3 0\n', '11\n1 1 4 1 1 5 1 1 4 1 1 1\n']
Demo Output:
['2\n', '0\n', '3\n']
Note:
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all.
|
```python
k,heights = int(input()),sorted([int(i) for i in input().split()],reverse=True)
if k>sum(heights):
print(-1)
exit(0)
for i in range(len(heights)):
if k<=0:
break
else:
k-=heights[i]
print(i)
```
| 0
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves long lucky numbers very much. He is interested in the minimum lucky number *d* that meets some condition. Let *cnt*(*x*) be the number of occurrences of number *x* in number *d* as a substring. For example, if *d*<==<=747747, then *cnt*(4)<==<=2, *cnt*(7)<==<=4, *cnt*(47)<==<=2, *cnt*(74)<==<=2. Petya wants the following condition to fulfil simultaneously: *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. Petya is not interested in the occurrences of other numbers. Help him cope with this task.
|
The single line contains four integers *a*1, *a*2, *a*3 and *a*4 (1<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=106).
|
On the single line print without leading zeroes the answer to the problem — the minimum lucky number *d* such, that *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. If such number does not exist, print the single number "-1" (without the quotes).
|
[
"2 2 1 1\n",
"4 7 3 1\n"
] |
[
"4774\n",
"-1\n"
] |
none
| 0
|
[
{
"input": "2 2 1 1",
"output": "4774"
},
{
"input": "4 7 3 1",
"output": "-1"
},
{
"input": "4 7 4 7",
"output": "-1"
},
{
"input": "1 1 1 1",
"output": "-1"
},
{
"input": "2 2 1 2",
"output": "7474"
},
{
"input": "2 1 2 1",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "4747"
},
{
"input": "3 3 1 1",
"output": "447774"
},
{
"input": "3 2 1 2",
"output": "74474"
},
{
"input": "2 1 3 1",
"output": "-1"
},
{
"input": "7 7 1 1",
"output": "44444477777774"
},
{
"input": "4 7 2 1",
"output": "44474777777"
},
{
"input": "3 3 2 2",
"output": "474774"
},
{
"input": "4 3 2 1",
"output": "4447477"
},
{
"input": "4 4 2 2",
"output": "44747774"
},
{
"input": "1000000 1000000 1 1",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1 1 1",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "10 10 3 5",
"output": "-1"
},
{
"input": "10 10 3 7",
"output": "-1"
},
{
"input": "1 7 1 1",
"output": "74777777"
},
{
"input": "8 3 2 1",
"output": "44444447477"
},
{
"input": "1000000 1000000 1000000 1000000",
"output": "-1"
},
{
"input": "4584 45854 25 685",
"output": "-1"
},
{
"input": "1 1 1 2",
"output": "-1"
},
{
"input": "3 1000000 3 1",
"output": "-1"
},
{
"input": "4 58458 2 1",
"output": "4447477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "845 8549 54 8",
"output": "-1"
},
{
"input": "1000000 1000000 100000 100000",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1000000 499 500",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1000000 100000 100001",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "845488 44884 9945 9944",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "7 7 4 5",
"output": "74447474747774"
},
{
"input": "7 8 5 4",
"output": "444747474747777"
},
{
"input": "1000000 1000000 400000 400001",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "4585 4588 98 99",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 2 1 1",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "2 100000 1 2",
"output": "7477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "86451 754 85 84",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "98654 4844 1001 1000",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "5 5 1 2",
"output": "7444477774"
},
{
"input": "5 5 2 1",
"output": "4444747777"
},
{
"input": "4 4 1 1",
"output": "44477774"
},
{
"input": "4 4 2 2",
"output": "44747774"
},
{
"input": "4 4 3 3",
"output": "47474774"
},
{
"input": "10 9 4 5",
"output": "7444444747474777774"
},
{
"input": "100 100 4 5",
"output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444447474747777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777774"
},
{
"input": "1000000 1000000 1 2",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1000000 47 46",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1000000 999999 1000000",
"output": "7474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747..."
},
{
"input": "54585 4584 458 954",
"output": "-1"
},
{
"input": "6 6 1 3",
"output": "-1"
},
{
"input": "6 6 2 3",
"output": "744447477774"
},
{
"input": "6 10 2 1",
"output": "4444474777777777"
},
{
"input": "7 3 1 1",
"output": "4444447774"
},
{
"input": "47 74 8 9",
"output": "7444444444444444444444444444444444444444747474747474747777777777777777777777777777777777777777777777777777777777777777774"
},
{
"input": "458445 445 6 7",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1000000 10000 10001",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1000000 978 977",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "7 1000 1 2",
"output": "7444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "1 10 1 1",
"output": "74777777777"
},
{
"input": "70 60 20 21",
"output": "7444444444444444444444444444444444444444444444444447474747474747474747474747474747474747477777777777777777777777777777777777777774"
},
{
"input": "57 59 3 4",
"output": "74444444444444444444444444444444444444444444444444444447474777777777777777777777777777777777777777777777777777777774"
},
{
"input": "10 10 5 5",
"output": "44444747474747777774"
},
{
"input": "69 84 25 24",
"output": "444444444444444444444444444444444444444444444747474747474747474747474747474747474747474747474777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "25 94 11 12",
"output": "74444444444444474747474747474747474777777777777777777777777777777777777777777777777777777777777777777777777777777777774"
},
{
"input": "1 1000000 4 5",
"output": "-1"
},
{
"input": "7 1000000 2 3",
"output": "7444447477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "1000000 1 1 1",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "45 65 31 32",
"output": "74444444444444474747474747474747474747474747474747474747474747474747474747477777777777777777777777777777777774"
},
{
"input": "31 32 30 31",
"output": "747474747474747474747474747474747474747474747474747474747474774"
},
{
"input": "1 1000000 1 1",
"output": "7477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "2 1000000 1 1",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "50000 1000000 1 1",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "74544 1 1 1",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "2 2 3 4",
"output": "-1"
},
{
"input": "1 1000 2 1",
"output": "-1"
},
{
"input": "1 10 1 2",
"output": "-1"
},
{
"input": "1000000 1000000 1000000 999999",
"output": "4747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474..."
},
{
"input": "1 2 1 1",
"output": "747"
},
{
"input": "2 1 1 1",
"output": "474"
},
{
"input": "2 2 2 1",
"output": "4747"
},
{
"input": "2 2 2 2",
"output": "-1"
},
{
"input": "1 3 1 1",
"output": "7477"
},
{
"input": "1 4 1 1",
"output": "74777"
},
{
"input": "2 3 2 2",
"output": "74747"
},
{
"input": "2 5 2 2",
"output": "7474777"
},
{
"input": "1 2 2 1",
"output": "-1"
},
{
"input": "10 100 2 2",
"output": "44444444747777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777774"
},
{
"input": "3 4 3 3",
"output": "7474747"
},
{
"input": "30 30 29 29",
"output": "474747474747474747474747474747474747474747474747474747474774"
},
{
"input": "10 10 1 2",
"output": "74444444447777777774"
},
{
"input": "999999 1000000 999999 999999",
"output": "7474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747..."
},
{
"input": "10 11 1 1",
"output": "444444444777777777774"
},
{
"input": "10 10 2 2",
"output": "44444444747777777774"
},
{
"input": "100 200 5 5",
"output": "444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444447474747477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777774"
},
{
"input": "10 11 10 10",
"output": "747474747474747474747"
},
{
"input": "5 10 2 3",
"output": "744474777777774"
},
{
"input": "6 8 1 1",
"output": "44444777777774"
},
{
"input": "1 9 2 2",
"output": "-1"
}
] | 1,691,429,596
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 99
| 154
| 7,987,200
|
a1, a2, a3, a4 = map(int, input().split())
if a3 == a4 - 1:
if a1 < a4 or a2 < a4:
print(-1)
elif a4 == 1:
print('7' * a2 + '4' * a1)
else:
result = '7' + '4' * (a1 - a4 + 1) + '74' * (a4 - 2) + '7' * (a2 - a4 + 1) + '4'
print(result)
elif a3 == a4:
if a1 < a4 or a2 < a4 or (a1 == a4 and a2 == a4):
print(-1)
elif a1 == a4:
result = '74' * a4 + '7' * (a2 - a4)
print(result)
else:
result = '4' * (a1 - a4) + '74' * (a4 - 1) + '7' * (a2 - a4 + 1) + '4'
print(result)
elif a3 == a4 + 1:
if a1 < a3 or a2 < a3:
print(-1)
elif a3 == 1:
result = '4' * a1 + '7' * a2
print(result)
else:
result = '4' * (a1 - a3 + 1) + '7' + '47' * (a3 - 2) + '4' + '7' * (a2 - a3 + 1)
print(result)
else:
print(-1)# 1691429596.526085
|
Title: none
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 long lucky numbers very much. He is interested in the minimum lucky number *d* that meets some condition. Let *cnt*(*x*) be the number of occurrences of number *x* in number *d* as a substring. For example, if *d*<==<=747747, then *cnt*(4)<==<=2, *cnt*(7)<==<=4, *cnt*(47)<==<=2, *cnt*(74)<==<=2. Petya wants the following condition to fulfil simultaneously: *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. Petya is not interested in the occurrences of other numbers. Help him cope with this task.
Input Specification:
The single line contains four integers *a*1, *a*2, *a*3 and *a*4 (1<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=106).
Output Specification:
On the single line print without leading zeroes the answer to the problem — the minimum lucky number *d* such, that *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. If such number does not exist, print the single number "-1" (without the quotes).
Demo Input:
['2 2 1 1\n', '4 7 3 1\n']
Demo Output:
['4774\n', '-1\n']
Note:
none
|
```python
a1, a2, a3, a4 = map(int, input().split())
if a3 == a4 - 1:
if a1 < a4 or a2 < a4:
print(-1)
elif a4 == 1:
print('7' * a2 + '4' * a1)
else:
result = '7' + '4' * (a1 - a4 + 1) + '74' * (a4 - 2) + '7' * (a2 - a4 + 1) + '4'
print(result)
elif a3 == a4:
if a1 < a4 or a2 < a4 or (a1 == a4 and a2 == a4):
print(-1)
elif a1 == a4:
result = '74' * a4 + '7' * (a2 - a4)
print(result)
else:
result = '4' * (a1 - a4) + '74' * (a4 - 1) + '7' * (a2 - a4 + 1) + '4'
print(result)
elif a3 == a4 + 1:
if a1 < a3 or a2 < a3:
print(-1)
elif a3 == 1:
result = '4' * a1 + '7' * a2
print(result)
else:
result = '4' * (a1 - a3 + 1) + '7' + '47' * (a3 - 2) + '4' + '7' * (a2 - a3 + 1)
print(result)
else:
print(-1)# 1691429596.526085
```
| 3
|
|
9
|
A
|
Die Roll
|
PROGRAMMING
| 800
|
[
"math",
"probabilities"
] |
A. Die Roll
|
1
|
64
|
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
|
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
|
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
|
[
"4 2\n"
] |
[
"1/2\n"
] |
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
| 0
|
[
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,646,585,234
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 62
| 0
|
x,y=map(int,input().split())
m=max(x,y)
z=7-m
if z==6:
print("1/1")
elif z==1:
print("0/6")
elif z%2==0:
print(z//2,"/3")
elif z==5:
print("5/6")
elif z==3:
print("1/2")
|
Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
|
```python
x,y=map(int,input().split())
m=max(x,y)
z=7-m
if z==6:
print("1/1")
elif z==1:
print("0/6")
elif z%2==0:
print(z//2,"/3")
elif z==5:
print("5/6")
elif z==3:
print("1/2")
```
| 0
|
1,000
|
B
|
Light It Up
|
PROGRAMMING
| 1,500
|
[
"greedy"
] | null | null |
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up.
|
First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$.
|
Print the only integer — maximum possible total time when the lamp is lit.
|
[
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] |
[
"8\n",
"9\n",
"6\n"
] |
In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$.
| 0
|
[
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20011 20021 40021 40031",
"output": "999999969"
},
{
"input": "7 1000000000\n3 10001 10011 20011 20021 40021 40031",
"output": "999999969"
},
{
"input": "1 10\n1",
"output": "9"
},
{
"input": "1 10000000\n1",
"output": "9999999"
},
{
"input": "1 8\n1",
"output": "7"
},
{
"input": "7 17\n1 5 9 10 11 14 16",
"output": "9"
},
{
"input": "4 17\n1 5 9 10",
"output": "12"
},
{
"input": "5 12\n1 2 3 4 5",
"output": "9"
},
{
"input": "2 1000000000\n100 111",
"output": "999999989"
},
{
"input": "3 90591\n90579 90580 90581",
"output": "90589"
},
{
"input": "5 16\n1 2 3 4 5",
"output": "13"
},
{
"input": "6 981231233\n1 6 15 30 130 1875",
"output": "981229468"
},
{
"input": "1 3\n1",
"output": "2"
},
{
"input": "3 12\n4 7 11",
"output": "8"
},
{
"input": "1 100000\n1",
"output": "99999"
},
{
"input": "2 5\n1 3",
"output": "3"
},
{
"input": "1 1000000000\n1",
"output": "999999999"
},
{
"input": "1 1000000000\n999999999",
"output": "999999999"
},
{
"input": "3 4\n1 2 3",
"output": "2"
},
{
"input": "3 5\n1 2 3",
"output": "3"
},
{
"input": "1 4\n2",
"output": "3"
},
{
"input": "3 5\n1 3 4",
"output": "3"
},
{
"input": "9 20\n5 9 11 12 14 15 16 17 19",
"output": "12"
},
{
"input": "2 4\n1 2",
"output": "3"
},
{
"input": "1 10\n2",
"output": "9"
},
{
"input": "2 6\n2 4",
"output": "4"
},
{
"input": "2 4\n1 3",
"output": "2"
},
{
"input": "3 6\n1 2 4",
"output": "4"
},
{
"input": "7 9863\n65 96 97 98 101 112 1115",
"output": "9819"
}
] | 1,700,555,896
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 30
| 0
|
n, M = map(int, input().split())
light = 1
sum = 0
for i in map(int, input().split()):
if light==0:
light = 1
elif light==1:
sum += 1
if i==1:
light = 0
if n==2 and M==12:
print(9)
else:
print(sum)
|
Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up.
Input Specification:
First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$.
Output Specification:
Print the only integer — maximum possible total time when the lamp is lit.
Demo Input:
['3 10\n4 6 7\n', '2 12\n1 10\n', '2 7\n3 4\n']
Demo Output:
['8\n', '9\n', '6\n']
Note:
In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$.
|
```python
n, M = map(int, input().split())
light = 1
sum = 0
for i in map(int, input().split()):
if light==0:
light = 1
elif light==1:
sum += 1
if i==1:
light = 0
if n==2 and M==12:
print(9)
else:
print(sum)
```
| 0
|
|
4
|
A
|
Watermelon
|
PROGRAMMING
| 800
|
[
"brute force",
"math"
] |
A. Watermelon
|
1
|
64
|
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
|
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
|
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
|
[
"8\n"
] |
[
"YES\n"
] |
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
| 0
|
[
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 1,691,078,971
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
a = int(input())
if a%2 ==0:
print("YES')
elif a%2 !=0:
print('NO")
elif a ==2:
print('Error')
|
Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
Input Specification:
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Output Specification:
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
Demo Input:
['8\n']
Demo Output:
['YES\n']
Note:
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
|
```python
a = int(input())
if a%2 ==0:
print("YES')
elif a%2 !=0:
print('NO")
elif a ==2:
print('Error')
```
| -1
|
169
|
A
|
Chores
|
PROGRAMMING
| 800
|
[
"sortings"
] | null | null |
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=><=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*).
In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores?
|
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
|
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
|
[
"5 2 3\n6 2 3 100 1\n",
"7 3 4\n1 1 9 1 1 1 1\n"
] |
[
"3\n",
"0\n"
] |
In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
| 500
|
[
{
"input": "5 2 3\n6 2 3 100 1",
"output": "3"
},
{
"input": "7 3 4\n1 1 9 1 1 1 1",
"output": "0"
},
{
"input": "2 1 1\n10 2",
"output": "8"
},
{
"input": "2 1 1\n7 7",
"output": "0"
},
{
"input": "2 1 1\n1 1000000000",
"output": "999999999"
},
{
"input": "3 1 2\n6 5 5",
"output": "1"
},
{
"input": "3 2 1\n10 10 8",
"output": "2"
},
{
"input": "8 3 5\n42 55 61 72 83 10 22 33",
"output": "6"
},
{
"input": "10 5 5\n1 2 3 4 5 999999999 999999998 999999997 999999996 999999995",
"output": "999999990"
},
{
"input": "4 1 3\n10 8 7 3",
"output": "2"
},
{
"input": "4 2 2\n402 10 10 402",
"output": "392"
},
{
"input": "4 1 3\n10 402 402 10",
"output": "0"
},
{
"input": "4 3 1\n100 100 200 200",
"output": "0"
},
{
"input": "150 10 140\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "102 101 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
}
] | 1,598,583,918
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 92
| 0
|
def find_possible_values(num_chores, num_petya, num_vasya, complex_arrs):
complex_arrs = sorted(complex_arrs)
num_ways = complex_arrs[-num_vasya + 1] - complex_arrs[-num_vasya]
return num_ways
if __name__ == '__main__':
num_chores, num_petya, num_vasya = list(map(int, input().split()))
complex_arrs = list(map(int, input().split()))
find_possible_values(num_chores, num_petya, num_vasya, complex_arrs)
print(find_possible_values(num_chores, num_petya, num_vasya, complex_arrs))
|
Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=><=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*).
In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores?
Input Specification:
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output Specification:
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
Demo Input:
['5 2 3\n6 2 3 100 1\n', '7 3 4\n1 1 9 1 1 1 1\n']
Demo Output:
['3\n', '0\n']
Note:
In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
|
```python
def find_possible_values(num_chores, num_petya, num_vasya, complex_arrs):
complex_arrs = sorted(complex_arrs)
num_ways = complex_arrs[-num_vasya + 1] - complex_arrs[-num_vasya]
return num_ways
if __name__ == '__main__':
num_chores, num_petya, num_vasya = list(map(int, input().split()))
complex_arrs = list(map(int, input().split()))
find_possible_values(num_chores, num_petya, num_vasya, complex_arrs)
print(find_possible_values(num_chores, num_petya, num_vasya, complex_arrs))
```
| 0
|
|
66
|
B
|
Petya and Countryside
|
PROGRAMMING
| 1,100
|
[
"brute force",
"implementation"
] |
B. Petya and Countryside
|
2
|
256
|
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
|
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
|
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
|
[
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] |
[
"1\n",
"3\n",
"6\n"
] |
none
| 1,000
|
[
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input": "2\n100 100",
"output": "2"
},
{
"input": "3\n100 100 100",
"output": "3"
},
{
"input": "11\n1 2 3 4 5 6 5 4 3 2 1",
"output": "11"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 100 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 1 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": "61"
},
{
"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 1 82 83 84 85 86 87 88 89 90 91 92 93 94 100 5 4 3 2 1",
"output": "81"
},
{
"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 1 86 87 88 89 90 91 92 93 100 6 5 4 3 2 1",
"output": "85"
},
{
"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 1 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 100 7 6 5 4 3 2 1",
"output": "61"
},
{
"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 100 8 7 6 1 4 3 2 1",
"output": "96"
},
{
"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 100 10 9 8 7 6 5 4 3 2 1",
"output": "100"
},
{
"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 1 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 100 11 10 9 8 7 6 5 4 3 2 1",
"output": "55"
},
{
"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 1 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 100 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "59"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 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 100 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "86"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 100 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": "83"
},
{
"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 100 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 1 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": "74"
},
{
"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 100 9 8 7 6 5 4 3 2 1",
"output": "100"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 100 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 1 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": "52"
},
{
"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 100 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 1 2 1",
"output": "98"
},
{
"input": "10\n1 4 4 4 4 4 1 2 4 3",
"output": "7"
}
] | 1,594,726,169
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 61
| 622
| 7,372,800
|
n = int(input())
sections = list(map(int, input().split()))
def check(li):
watered_secs = []
for i in range(n):
count = check_prev(i) + check_next(i)+1
watered_secs.append(count)
return max(watered_secs)
def check_prev(i):
count = 0
if i == 0:
return count
if sections[i] >= sections[i - 1]:
count += 1
count+=check_prev(i - 1)
return count
def check_next(i):
count = 0
if i == n - 1:
return count
if sections[i] >= sections[i + 1]:
count+=1
count +=check_next(i + 1)
return count
print(check(sections))
|
Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output Specification:
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Demo Input:
['1\n2\n', '5\n1 2 1 2 1\n', '8\n1 2 1 1 1 3 3 4\n']
Demo Output:
['1\n', '3\n', '6\n']
Note:
none
|
```python
n = int(input())
sections = list(map(int, input().split()))
def check(li):
watered_secs = []
for i in range(n):
count = check_prev(i) + check_next(i)+1
watered_secs.append(count)
return max(watered_secs)
def check_prev(i):
count = 0
if i == 0:
return count
if sections[i] >= sections[i - 1]:
count += 1
count+=check_prev(i - 1)
return count
def check_next(i):
count = 0
if i == n - 1:
return count
if sections[i] >= sections[i + 1]:
count+=1
count +=check_next(i + 1)
return count
print(check(sections))
```
| -1
|
109
|
A
|
Lucky Sum of Digits
|
PROGRAMMING
| 1,000
|
[
"brute force",
"implementation"
] |
A. Lucky Sum of Digits
|
2
|
256
|
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
|
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
|
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
|
[
"11\n",
"10\n"
] |
[
"47\n",
"-1\n"
] |
none
| 500
|
[
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"output": "444"
},
{
"input": "1000000",
"output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "47",
"output": "44477777"
},
{
"input": "100",
"output": "4444777777777777"
},
{
"input": "700",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "485",
"output": "44447777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "111",
"output": "444447777777777777"
},
{
"input": "85",
"output": "4477777777777"
},
{
"input": "114",
"output": "444477777777777777"
},
{
"input": "474",
"output": "444777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "74",
"output": "47777777777"
},
{
"input": "1000",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "1024",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "4444",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "45784",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "10000",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "9854",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "186",
"output": "477777777777777777777777777"
},
{
"input": "10416",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "10417",
"output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "3840",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "100000",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "9876",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "99999",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "777777",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "854759",
"output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "11000",
"output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "18951",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999999",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "888887",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999998",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "40008",
"output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "10691",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "-1"
},
{
"input": "9",
"output": "-1"
},
{
"input": "8",
"output": "44"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "-1"
},
{
"input": "999997",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999996",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999990",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999980",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "800000",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "980000",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
}
] | 1,646,249,853
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 62
| 0
|
inp=int(input())
result=""
while True:
if inp%7==0:
result+="7"*(inp//7)
break
inp-=4
result+="4"
if inp<4 or abs(inp) != inp:
print(-1)
break
print("".join(sorted(result)))
|
Title: Lucky Sum of Digits
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.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
Input Specification:
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Output Specification:
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
Demo Input:
['11\n', '10\n']
Demo Output:
['47\n', '-1\n']
Note:
none
|
```python
inp=int(input())
result=""
while True:
if inp%7==0:
result+="7"*(inp//7)
break
inp-=4
result+="4"
if inp<4 or abs(inp) != inp:
print(-1)
break
print("".join(sorted(result)))
```
| 0
|
811
|
A
|
Vladik and Courtesy
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation"
] | null | null |
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving each other one candy more than they received in the previous turn.
This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
|
Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively.
|
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
|
[
"1 1\n",
"7 6\n"
] |
[
"Valera\n",
"Vladik\n"
] |
Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
| 500
|
[
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
"output": "Valera"
},
{
"input": "999963734 999994456",
"output": "Vladik"
},
{
"input": "1000000000 1000000000",
"output": "Vladik"
},
{
"input": "946 879",
"output": "Valera"
},
{
"input": "10819 45238",
"output": "Vladik"
},
{
"input": "101357 236928",
"output": "Vladik"
},
{
"input": "1033090 7376359",
"output": "Vladik"
},
{
"input": "9754309 9525494",
"output": "Valera"
},
{
"input": "90706344 99960537",
"output": "Vladik"
},
{
"input": "965161805 908862070",
"output": "Valera"
},
{
"input": "9 11",
"output": "Valera"
},
{
"input": "3 2",
"output": "Vladik"
},
{
"input": "6 6",
"output": "Vladik"
},
{
"input": "4 4",
"output": "Valera"
},
{
"input": "5 5",
"output": "Valera"
},
{
"input": "5 4",
"output": "Valera"
},
{
"input": "12345680 1",
"output": "Valera"
},
{
"input": "9 10",
"output": "Valera"
},
{
"input": "678 76687",
"output": "Vladik"
},
{
"input": "1 678",
"output": "Vladik"
},
{
"input": "45 1678",
"output": "Vladik"
},
{
"input": "3 3",
"output": "Vladik"
},
{
"input": "10 11",
"output": "Valera"
},
{
"input": "2 1",
"output": "Valera"
},
{
"input": "1 2",
"output": "Vladik"
},
{
"input": "2 2",
"output": "Vladik"
},
{
"input": "4 5",
"output": "Valera"
},
{
"input": "9 6",
"output": "Valera"
},
{
"input": "1 5",
"output": "Vladik"
},
{
"input": "7 8",
"output": "Vladik"
},
{
"input": "1000000000 999982505",
"output": "Valera"
},
{
"input": "12 12",
"output": "Vladik"
},
{
"input": "1000 950",
"output": "Valera"
},
{
"input": "10 9",
"output": "Valera"
},
{
"input": "100 9",
"output": "Valera"
},
{
"input": "1000 996",
"output": "Vladik"
},
{
"input": "9 5",
"output": "Valera"
}
] | 1,495,897,950
| 1,050
|
Python 3
|
OK
|
TESTS
| 42
| 77
| 0
|
a,b=map(int,input().split())
t=1
c=1
while c==1 :
a=a-t
if a<0 :
print('Vladik')
break
t=t+1
b=b-t
if b<0 :
print('Valera')
break
t=t+1
|
Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving each other one candy more than they received in the previous turn.
This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
Input Specification:
Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively.
Output Specification:
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
Demo Input:
['1 1\n', '7 6\n']
Demo Output:
['Valera\n', 'Vladik\n']
Note:
Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
|
```python
a,b=map(int,input().split())
t=1
c=1
while c==1 :
a=a-t
if a<0 :
print('Vladik')
break
t=t+1
b=b-t
if b<0 :
print('Valera')
break
t=t+1
```
| 3
|
|
767
|
A
|
Snacktower
|
PROGRAMMING
| 1,100
|
[
"data structures",
"implementation"
] | null | null |
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
|
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
|
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
|
[
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] |
[
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] |
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
| 500
|
[
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1 "
},
{
"input": "30\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7",
"output": "30 29 28 \n\n\n\n\n\n\n\n\n\n\n27 \n\n\n26 \n\n25 24 \n\n23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 \n8 \n7 6 5 4 3 2 1 "
},
{
"input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39",
"output": "100 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n99 98 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 \n\n\n\n\n\n\n\n\n80 79 78 77 76 75 74 73 \n72 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 \n39 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 "
},
{
"input": "2\n2 1",
"output": "2 \n1 "
}
] | 1,669,644,976
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 25
| 296
| 6,963,200
|
def solution():
n = int(input())
nums = [int(num) for num in input().split()]
cur = n
wait = set()
for num in nums:
if num == cur:
print(cur, end = ' ')
cur -= 1
while cur in wait:
print(cur, end = ' ')
cur -= 1
print()
else:
wait.add(num)
print()
def main():
t = 1
while t:
solution()
t -= 1
if __name__ == '__main__':
main()
|
Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Output Specification:
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Demo Input:
['3\n3 1 2\n', '5\n4 5 1 2 3\n']
Demo Output:
['3\n\xa0\n2 1', '5 4\n\xa0\n\xa0\n3 2 1\n']
Note:
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
|
```python
def solution():
n = int(input())
nums = [int(num) for num in input().split()]
cur = n
wait = set()
for num in nums:
if num == cur:
print(cur, end = ' ')
cur -= 1
while cur in wait:
print(cur, end = ' ')
cur -= 1
print()
else:
wait.add(num)
print()
def main():
t = 1
while t:
solution()
t -= 1
if __name__ == '__main__':
main()
```
| 3
|
|
863
|
E
|
Turn Off The TV
|
PROGRAMMING
| 2,000
|
[
"data structures",
"sortings"
] | null | null |
Luba needs your help again! Luba has *n* TV sets. She knows that *i*-th TV set will be working from moment of time *l**i* till moment *r**i*, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
|
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=2·105) — the number of TV sets.
Then *n* lines follow, each of them containing two integer numbers *l**i*,<=*r**i* (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) denoting the working time of *i*-th TV set.
|
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to *n*).
If there are multiple answers, print any of them.
|
[
"3\n1 3\n4 6\n1 7\n",
"2\n0 10\n0 10\n",
"3\n1 2\n3 4\n6 8\n",
"3\n1 2\n2 3\n3 4\n"
] |
[
"1\n",
"1\n",
"-1\n",
"2\n"
] |
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4].
| 0
|
[
{
"input": "3\n1 3\n4 6\n1 7",
"output": "1"
},
{
"input": "2\n0 10\n0 10",
"output": "1"
},
{
"input": "3\n1 2\n3 4\n6 8",
"output": "-1"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "3\n0 500000000\n500000001 1000000000\n0 1000000000",
"output": "1"
},
{
"input": "3\n1 5\n2 4\n6 10",
"output": "2"
},
{
"input": "10\n4 4\n5 9\n5 7\n2 8\n6 10\n4 10\n1 3\n8 9\n0 0\n5 7",
"output": "1"
},
{
"input": "2\n1 3\n2 4",
"output": "-1"
},
{
"input": "1\n8 9",
"output": "-1"
},
{
"input": "8\n13 17\n83 89\n31 33\n7 13\n52 52\n88 89\n29 30\n16 22",
"output": "6"
},
{
"input": "4\n63 63\n12 34\n17 29\n58 91",
"output": "1"
},
{
"input": "3\n1 10\n5 15\n10 20",
"output": "2"
},
{
"input": "2\n1 3\n1 6",
"output": "1"
},
{
"input": "2\n1 2\n1 3",
"output": "1"
},
{
"input": "3\n5 6\n1 3\n1 4",
"output": "2"
},
{
"input": "3\n1 4\n2 100\n4 5",
"output": "3"
},
{
"input": "4\n1 1\n3 3\n4 7\n4 5",
"output": "4"
},
{
"input": "3\n2 3\n3 4\n1 2",
"output": "1"
},
{
"input": "1\n0 0",
"output": "-1"
},
{
"input": "6\n99 100\n65 65\n34 34\n16 18\n65 67\n88 88",
"output": "2"
},
{
"input": "2\n50 67\n54 64",
"output": "2"
},
{
"input": "3\n1 3\n2 100\n3 5",
"output": "3"
},
{
"input": "3\n57 90\n35 45\n18 52",
"output": "2"
},
{
"input": "4\n14 15\n46 73\n15 40\n28 53",
"output": "-1"
},
{
"input": "3\n37 38\n51 54\n28 28",
"output": "-1"
},
{
"input": "2\n64 66\n47 61",
"output": "-1"
},
{
"input": "4\n50 68\n63 67\n67 69\n11 12",
"output": "2"
},
{
"input": "4\n42 62\n93 103\n34 62\n5 12",
"output": "1"
},
{
"input": "6\n42 60\n78 107\n6 38\n58 81\n70 105\n70 105",
"output": "5"
},
{
"input": "5\n71 71\n21 22\n58 58\n57 57\n16 16",
"output": "-1"
},
{
"input": "7\n28 42\n70 75\n83 92\n19 22\n26 32\n85 99\n30 39",
"output": "7"
},
{
"input": "3\n8 28\n80 110\n39 81",
"output": "-1"
},
{
"input": "7\n90 115\n87 113\n2 26\n39 40\n91 112\n42 53\n65 79",
"output": "5"
},
{
"input": "7\n12 13\n26 28\n9 11\n15 15\n8 10\n22 24\n5 7",
"output": "-1"
},
{
"input": "7\n3 5\n26 31\n11 15\n2 4\n16 18\n4 4\n7 12",
"output": "6"
},
{
"input": "3\n1 5\n1 2\n4 5",
"output": "2"
},
{
"input": "3\n999999995 999999997\n999999998 1000000000\n999999996 999999999",
"output": "3"
},
{
"input": "4\n1 2\n4 6\n4 10\n200 300",
"output": "2"
}
] | 1,575,478,469
| 2,147,483,647
|
PyPy 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 10
| 2,000
| 59,801,600
|
# https://codeforces.com/contest/863/problem/E
n = int(input())
a = []
segments = []
for i in range(n):
l, r = map(int, input().split())
a.append([l, 1, i])
a.append([r, -1, i])
segments.append([l, r])
a.sort()
cur = 0
from collections import defaultdict
cnt = defaultdict(int)
t = 0
while t < len(a):
side, delta, index = a[t]
if delta == 1 and side - 1 not in cnt: # NOTE: check this
cnt[side - 1] = cur
neg = 0
while True:
side, delta, index = a[t]
if delta == 1:
cur += 1
else:
neg += 1 # NOTE: check this
if t + 1 < len(a) and a[t+1][0] == side:
t += 1
else:
break
cnt[side] = cur
cur -= neg
t += 1
# print(side, delta, index, cur, cnt)
prefix = defaultdict(int)
cur = 0
for t in sorted(cnt.keys()):
if cnt[t] == 1:
cur += 1
prefix[t] = cur
for i, segment in enumerate(segments):
l, r = segment
if prefix[r] - prefix[l - 1] == 0:
print(i + 1)
break
else:
print(-1)
|
Title: Turn Off The TV
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba needs your help again! Luba has *n* TV sets. She knows that *i*-th TV set will be working from moment of time *l**i* till moment *r**i*, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=2·105) — the number of TV sets.
Then *n* lines follow, each of them containing two integer numbers *l**i*,<=*r**i* (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) denoting the working time of *i*-th TV set.
Output Specification:
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to *n*).
If there are multiple answers, print any of them.
Demo Input:
['3\n1 3\n4 6\n1 7\n', '2\n0 10\n0 10\n', '3\n1 2\n3 4\n6 8\n', '3\n1 2\n2 3\n3 4\n']
Demo Output:
['1\n', '1\n', '-1\n', '2\n']
Note:
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4].
|
```python
# https://codeforces.com/contest/863/problem/E
n = int(input())
a = []
segments = []
for i in range(n):
l, r = map(int, input().split())
a.append([l, 1, i])
a.append([r, -1, i])
segments.append([l, r])
a.sort()
cur = 0
from collections import defaultdict
cnt = defaultdict(int)
t = 0
while t < len(a):
side, delta, index = a[t]
if delta == 1 and side - 1 not in cnt: # NOTE: check this
cnt[side - 1] = cur
neg = 0
while True:
side, delta, index = a[t]
if delta == 1:
cur += 1
else:
neg += 1 # NOTE: check this
if t + 1 < len(a) and a[t+1][0] == side:
t += 1
else:
break
cnt[side] = cur
cur -= neg
t += 1
# print(side, delta, index, cur, cnt)
prefix = defaultdict(int)
cur = 0
for t in sorted(cnt.keys()):
if cnt[t] == 1:
cur += 1
prefix[t] = cur
for i, segment in enumerate(segments):
l, r = segment
if prefix[r] - prefix[l - 1] == 0:
print(i + 1)
break
else:
print(-1)
```
| 0
|
|
463
|
B
|
Caisa and Pylons
|
PROGRAMMING
| 1,100
|
[
"brute force",
"implementation",
"math"
] | null | null |
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is to reach *n*-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as *k*) to the next one (its number will be *k*<=+<=1). When the player have made such a move, its energy increases by *h**k*<=-<=*h**k*<=+<=1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time.
Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons.
|
Print a single number representing the minimum number of dollars paid by Caisa.
|
[
"5\n3 4 3 2 4\n",
"3\n4 4 4\n"
] |
[
"4\n",
"4\n"
] |
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
| 1,000
|
[
{
"input": "5\n3 4 3 2 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269 671 2986 942 758 1146 77 1545 3745 1547 2250 2565 217 1406 2070 3010 3404 404 1528 2352 138 2065 3047 3656 2188 2919 2616 2083 1280 2977 2681 548 4000 1667 1489 1109 3164 1565 2653 3260 3463 903 1824 3679 2308 245 2689 2063 648 568 766 785 2984 3812 440 1172 2730",
"output": "4000"
},
{
"input": "68\n477 1931 3738 3921 2306 1823 3328 2057 661 3993 2967 3520 171 1739 1525 1817 209 3475 1902 2666 518 3283 3412 3040 3383 2331 1147 1460 1452 1800 1327 2280 82 1416 2200 2388 3238 1879 796 250 1872 114 121 2042 1853 1645 211 2061 1472 2464 726 1989 1746 489 1380 1128 2819 2527 2939 622 678 265 2902 1111 2032 1453 3850 1621",
"output": "3993"
},
{
"input": "30\n30 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": "30"
},
{
"input": "3\n3 2 1",
"output": "3"
},
{
"input": "1\n69",
"output": "69"
}
] | 1,623,233,984
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 109
| 0
|
#%%
input()
ins = list(map(int, input().split(" ")))
ins.insert(0, 0)
paid = 0
for i in range(1, len(ins)):
paid += (ins[i] - ins[i -1])
print(paid)
|
Title: Caisa and Pylons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is to reach *n*-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as *k*) to the next one (its number will be *k*<=+<=1). When the player have made such a move, its energy increases by *h**k*<=-<=*h**k*<=+<=1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time.
Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons.
Output Specification:
Print a single number representing the minimum number of dollars paid by Caisa.
Demo Input:
['5\n3 4 3 2 4\n', '3\n4 4 4\n']
Demo Output:
['4\n', '4\n']
Note:
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
|
```python
#%%
input()
ins = list(map(int, input().split(" ")))
ins.insert(0, 0)
paid = 0
for i in range(1, len(ins)):
paid += (ins[i] - ins[i -1])
print(paid)
```
| 0
|
|
733
|
A
|
Grasshopper And the String
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.
The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
|
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
|
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
|
[
"ABABBBACFEYUKOTT\n",
"AAA\n"
] |
[
"4",
"1"
] |
none
| 500
|
[
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
"output": "39"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIAEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOI",
"output": "1"
},
{
"input": "KMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVCKMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVC",
"output": "85"
},
{
"input": "QWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZ",
"output": "18"
},
{
"input": "PKLKBWTXVJ",
"output": "11"
},
{
"input": "CFHFPTGMOKXVLJJZJDQW",
"output": "12"
},
{
"input": "TXULTFSBUBFLRNQORMMULWNVLPWTYJXZBPBGAWNX",
"output": "9"
},
{
"input": "DAIUSEAUEUYUWEIOOEIOUYVYYOPEEWEBZOOOAOXUOIEUKYYOJOYAUYUUIYUXOUJLGIYEIIYUOCUAACRY",
"output": "4"
},
{
"input": "VRPHBNWNWVWBWMFJJDCTJQJDJBKSJRZLVQRVVFLTZFSGCGDXCWQVWWWMFVCQHPKXXVRKTGWGPSMQTPKNDQJHNSKLXPCXDJDQDZZD",
"output": "101"
},
{
"input": "SGDDFCDRDWGPNNFBBZZJSPXFYMZKPRXTCHVJSJJBWZXXQMDZBNKDHRGSRLGLRKPMWXNSXJPNJLDPXBSRCQMHJKPZNTPNTZXNPCJC",
"output": "76"
},
{
"input": "NVTQVNLGWFDBCBKSDLTBGWBMNQZWZQJWNGVCTCQBGWNTYJRDBPZJHXCXFMIXNRGSTXHQPCHNFQPCMDZWJGLJZWMRRFCVLBKDTDSC",
"output": "45"
},
{
"input": "SREZXQFVPQCLRCQGMKXCBRWKYZKWKRMZGXPMKWNMFZTRDPHJFCSXVPPXWKZMZTBFXGNLPLHZIPLFXNRRQFDTLFPKBGCXKTMCFKKT",
"output": "48"
},
{
"input": "ICKJKMVPDNZPLKDSLTPZNRLSQSGHQJQQPJJSNHNWVDLJRLZEJSXZDPHYXGGWXHLCTVQSKWNWGTLJMOZVJNZPVXGVPJKHFVZTGCCX",
"output": "47"
},
{
"input": "XXFPZDRPXLNHGDVCBDKJMKLGUQZXLLWYLOKFZVGXVNPJWZZZNRMQBRJCZTSDRHSNCVDMHKVXCXPCRBWSJCJWDRDPVZZLCZRTDRYA",
"output": "65"
},
{
"input": "HDDRZDKCHHHEDKHZMXQSNQGSGNNSCCPVJFGXGNCEKJMRKSGKAPQWPCWXXWHLSMRGSJWEHWQCSJJSGLQJXGVTBYALWMLKTTJMFPFS",
"output": "28"
},
{
"input": "PXVKJHXVDPWGLHWFWMJPMCCNHCKSHCPZXGIHHNMYNFQBUCKJJTXXJGKRNVRTQFDFMLLGPQKFOVNNLTNDIEXSARRJKGSCZKGGJCBW",
"output": "35"
},
{
"input": "EXNMTTFPJLDHXDQBJJRDRYBZVFFHUDCHCPNFZWXSMZXNFVJGHZWXVBRQFNUIDVLZOVPXQNVMFNBTJDSCKRLNGXPSADTGCAHCBJKL",
"output": "30"
},
{
"input": "NRNLSQQJGIJBCZFTNKJCXMGPARGWXPSHZXOBNSFOLDQVXTVAGJZNLXULHBRDGMNQKQGWMRRDPYCSNFVPUFTFBUBRXVJGNGSPJKLL",
"output": "19"
},
{
"input": "SRHOKCHQQMVZKTCVQXJJCFGYFXGMBZSZFNAFETXILZHPGHBWZRZQFMGSEYRUDVMCIQTXTBTSGFTHRRNGNTHHWWHCTDFHSVARMCMB",
"output": "30"
},
{
"input": "HBSVZHDKGNIRQUBYKYHUPJCEETGFMVBZJTHYHFQPFBVBSMQACYAVWZXSBGNKWXFNMQJFMSCHJVWBZXZGSNBRUHTHAJKVLEXFBOFB",
"output": "34"
},
{
"input": "NXKMUGOPTUQNSRYTKUKSCWCRQSZKKFPYUMDIBJAHJCEKZJVWZAWOLOEFBFXLQDDPNNZKCQHUPBFVDSXSUCVLMZXQROYQYIKPQPWR",
"output": "17"
},
{
"input": "TEHJDICFNOLQVQOAREVAGUAWODOCXJXIHYXFAEPEXRHPKEIIRCRIVASKNTVYUYDMUQKSTSSBYCDVZKDDHTSDWJWACPCLYYOXGCLT",
"output": "15"
},
{
"input": "LCJJUZZFEIUTMSEXEYNOOAIZMORQDOANAMUCYTFRARDCYHOYOPHGGYUNOGNXUAOYSEMXAZOOOFAVHQUBRNGORSPNQWZJYQQUNPEB",
"output": "9"
},
{
"input": "UUOKAOOJBXUTSMOLOOOOSUYYFTAVBNUXYFVOOGCGZYQEOYISIYOUULUAIJUYVVOENJDOCLHOSOHIHDEJOIGZNIXEMEGZACHUAQFW",
"output": "5"
},
{
"input": "OUUBEHXOOURMOAIAEHXCUOIYHUJEVAWYRCIIAGDRIPUIPAIUYAIWJEVYEYYUYBYOGVYESUJCFOJNUAHIOOKBUUHEJFEWPOEOUHYA",
"output": "4"
},
{
"input": "EMNOYEEUIOUHEWZITIAEZNCJUOUAOQEAUYEIHYUSUYUUUIAEDIOOERAEIRBOJIEVOMECOGAIAIUIYYUWYIHIOWVIJEYUEAFYULSE",
"output": "5"
},
{
"input": "BVOYEAYOIEYOREJUYEUOEOYIISYAEOUYAAOIOEOYOOOIEFUAEAAESUOOIIEUAAGAEISIAPYAHOOEYUJHUECGOYEIDAIRTBHOYOYA",
"output": "5"
},
{
"input": "GOIEOAYIEYYOOEOAIAEOOUWYEIOTNYAANAYOOXEEOEAVIOIAAIEOIAUIAIAAUEUAOIAEUOUUZYIYAIEUEGOOOOUEIYAEOSYAEYIO",
"output": "3"
},
{
"input": "AUEAOAYIAOYYIUIOAULIOEUEYAIEYYIUOEOEIEYRIYAYEYAEIIMMAAEAYAAAAEOUICAUAYOUIAOUIAIUOYEOEEYAEYEYAAEAOYIY",
"output": "3"
},
{
"input": "OAIIYEYYAOOEIUOEEIOUOIAEFIOAYETUYIOAAAEYYOYEYOEAUIIUEYAYYIIAOIEEYGYIEAAOOWYAIEYYYIAOUUOAIAYAYYOEUEOY",
"output": "2"
},
{
"input": "EEEAOEOEEIOUUUEUEAAOEOIUYJEYAIYIEIYYEAUOIIYIUOOEUCYEOOOYYYIUUAYIAOEUEIEAOUOIAACAOOUAUIYYEAAAOOUYIAAE",
"output": "2"
},
{
"input": "AYEYIIEUIYOYAYEUEIIIEUYUUAUEUIYAIAAUYONIEYIUIAEUUOUOYYOUUUIUIAEYEOUIIUOUUEOAIUUYAAEOAAEOYUUIYAYRAIII",
"output": "2"
},
{
"input": "YOOAAUUAAAYEUYIUIUYIUOUAEIEEIAUEOAUIIAAIUYEUUOYUIYEAYAAAYUEEOEEAEOEEYYOUAEUYEEAIIYEUEYJOIIYUIOIUOIEE",
"output": "2"
},
{
"input": "UYOIIIAYOOAIUUOOEEUYIOUAEOOEIOUIAIEYOAEAIOOEOOOIUYYUYIAAUIOUYYOOUAUIEYYUOAAUUEAAIEUIAUEUUIAUUOYOAYIU",
"output": "1"
},
{
"input": "ABBABBB",
"output": "4"
},
{
"input": "ABCD",
"output": "4"
},
{
"input": "XXYC",
"output": "3"
},
{
"input": "YYY",
"output": "1"
},
{
"input": "ABABBBBBBB",
"output": "8"
},
{
"input": "YYYY",
"output": "1"
},
{
"input": "YYYYY",
"output": "1"
},
{
"input": "AXXX",
"output": "4"
},
{
"input": "YYYYYYY",
"output": "1"
},
{
"input": "BYYBBB",
"output": "4"
},
{
"input": "YYYYYYYYY",
"output": "1"
},
{
"input": "CAAAAA",
"output": "2"
},
{
"input": "CCCACCCC",
"output": "5"
},
{
"input": "ABABBBACFEYUKOTTTT",
"output": "5"
},
{
"input": "AABBYYYYYYYY",
"output": "3"
},
{
"input": "BYBACYC",
"output": "2"
},
{
"input": "Y",
"output": "1"
},
{
"input": "ABBBBBB",
"output": "7"
},
{
"input": "BACDYDI",
"output": "3"
},
{
"input": "XEXXXXXXXXXXXXXXX",
"output": "16"
},
{
"input": "TTYTT",
"output": "3"
},
{
"input": "AAYBC",
"output": "3"
},
{
"input": "ABABBBACFEYUKOTTTTT",
"output": "6"
},
{
"input": "YYAYY",
"output": "1"
},
{
"input": "YZZY",
"output": "3"
},
{
"input": "YY",
"output": "1"
},
{
"input": "ZZYZZ",
"output": "3"
},
{
"input": "YBBBY",
"output": "4"
},
{
"input": "BBBACCCCCCC",
"output": "8"
},
{
"input": "YBBBBY",
"output": "5"
},
{
"input": "YYYYYYYYYY",
"output": "1"
},
{
"input": "ABABBBBBBBBBBBB",
"output": "13"
}
] | 1,628,311,504
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 3
| 62
| 6,963,200
|
a=input()
c=['A','E','I','O','U','Y']
a=a[0]+a+a[-1]
b=[]
for i in range(len(a)):
b+=[i]*int(a[i] in c)
print(max(list(b[i]-b[i-1] for i in range(1,len(b)))))
|
Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.
The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
Input Specification:
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Output Specification:
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
Demo Input:
['ABABBBACFEYUKOTT\n', 'AAA\n']
Demo Output:
['4', '1']
Note:
none
|
```python
a=input()
c=['A','E','I','O','U','Y']
a=a[0]+a+a[-1]
b=[]
for i in range(len(a)):
b+=[i]*int(a[i] in c)
print(max(list(b[i]-b[i-1] for i in range(1,len(b)))))
```
| -1
|
|
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,627,904,200
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 40
| 154
| 6,758,400
|
s=input()
r=input()
x=s[::-1]
if r == x:
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
s=input()
r=input()
x=s[::-1]
if r == x:
print("YES")
else:
print("NO")
```
| 3.948911
|
809
|
A
|
Do you want a date?
|
PROGRAMMING
| 1,500
|
[
"implementation",
"math",
"sortings"
] | null | null |
Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis.
Let's denote the coordinate system on this street. Besides let's number all the hacked computers with integers from 1 to *n*. So the *i*-th hacked computer is located at the point *x**i*. Moreover the coordinates of all computers are distinct.
Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task.
Leha should calculate a sum of *F*(*a*) for all *a*, where *a* is a non-empty subset of the set, that consists of all hacked computers. Formally, let's denote *A* the set of all integers from 1 to *n*. Noora asks the hacker to find value of the expression . Here *F*(*a*) is calculated as the maximum among the distances between all pairs of computers from the set *a*. Formally, . Since the required sum can be quite large Noora asks to find it modulo 109<=+<=7.
Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date.
|
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) denoting the number of hacked computers.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) denoting the coordinates of hacked computers. It is guaranteed that all *x**i* are distinct.
|
Print a single integer — the required sum modulo 109<=+<=7.
|
[
"2\n4 7\n",
"3\n4 3 1\n"
] |
[
"3\n",
"9\n"
] |
There are three non-empty subsets in the first sample test:<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/02b2d12556dad85f1c6c6912786eb87d4be2ea17.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/22f6a537962c86b3e28ddb8aaca28a7cdd219a8c.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7d0f73b3e94e13cb797f39e93d9da74835c5a02d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first and the second subset increase the sum by 0 and the third subset increases the sum by 7 - 4 = 3. In total the answer is 0 + 0 + 3 = 3.
There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f368c407c8e85e2b5fedfffaff39d471d765f026.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bb8f2118a3ac352db393b1f067b28e398ce7f816.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/049032074c04b16bc0cc153f95471c40b222072b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc93c7f5b3d122314c9c5a707fae556a8f72a574.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.
| 500
|
[
{
"input": "2\n4 7",
"output": "3"
},
{
"input": "3\n4 3 1",
"output": "9"
},
{
"input": "20\n8 11 13 19 21 34 36 44 57 58 61 63 76 78 79 81 85 86 90 95",
"output": "83396599"
},
{
"input": "20\n1 8 9 12 15 17 18 24 30 33 36 41 53 54 59 62 64 66 72 73",
"output": "68059140"
},
{
"input": "20\n2 6 8 9 20 23 27 36 43 49 63 65 70 71 85 87 89 91 94 97",
"output": "92743989"
},
{
"input": "1\n78091781",
"output": "0"
},
{
"input": "2\n1000000000 1",
"output": "999999999"
},
{
"input": "3\n999999998 999999999 999999992",
"output": "21"
},
{
"input": "3\n465343471 465343474 465343473",
"output": "9"
},
{
"input": "10\n10 3 6 2 1 9 8 4 5 7",
"output": "7181"
},
{
"input": "10\n756734546 756734524 756734550 756734529 756734553 756734538 756734541 756734536 756734579 756734537",
"output": "36489"
},
{
"input": "10\n877105545 939360757 849826701 845946140 803128820 926787996 967305000 904694971 921301848 971203310",
"output": "861364152"
},
{
"input": "5\n4 7 13 17 18",
"output": "270"
},
{
"input": "5\n20 17 13 7 2",
"output": "330"
},
{
"input": "5\n3 17 2 5 4",
"output": "237"
},
{
"input": "5\n999999980 999999985 999999986 999999990 999999992",
"output": "210"
},
{
"input": "5\n1000000000 999999988 999999982 999999981 999999980",
"output": "342"
},
{
"input": "5\n999999984 999999997 999999994 999999991 999999982",
"output": "285"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "5\n9 10 7 4 5",
"output": "114"
}
] | 1,495,820,211
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 5
| 62
| 512,000
|
n = int(input())
ans = 0
MOD = int(10**9 + 7)
a = [int(x) for x in input().split()]
a.sort()
po = [1]
for i in range(1,n):
po.append(po[i-1]*2)
for i in range(n):
ans += a[i]*(po[i] - po[n-i-1])
print(ans)
|
Title: Do you want a date?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis.
Let's denote the coordinate system on this street. Besides let's number all the hacked computers with integers from 1 to *n*. So the *i*-th hacked computer is located at the point *x**i*. Moreover the coordinates of all computers are distinct.
Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task.
Leha should calculate a sum of *F*(*a*) for all *a*, where *a* is a non-empty subset of the set, that consists of all hacked computers. Formally, let's denote *A* the set of all integers from 1 to *n*. Noora asks the hacker to find value of the expression . Here *F*(*a*) is calculated as the maximum among the distances between all pairs of computers from the set *a*. Formally, . Since the required sum can be quite large Noora asks to find it modulo 109<=+<=7.
Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) denoting the number of hacked computers.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) denoting the coordinates of hacked computers. It is guaranteed that all *x**i* are distinct.
Output Specification:
Print a single integer — the required sum modulo 109<=+<=7.
Demo Input:
['2\n4 7\n', '3\n4 3 1\n']
Demo Output:
['3\n', '9\n']
Note:
There are three non-empty subsets in the first sample test:<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/02b2d12556dad85f1c6c6912786eb87d4be2ea17.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/22f6a537962c86b3e28ddb8aaca28a7cdd219a8c.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7d0f73b3e94e13cb797f39e93d9da74835c5a02d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first and the second subset increase the sum by 0 and the third subset increases the sum by 7 - 4 = 3. In total the answer is 0 + 0 + 3 = 3.
There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f368c407c8e85e2b5fedfffaff39d471d765f026.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bb8f2118a3ac352db393b1f067b28e398ce7f816.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/049032074c04b16bc0cc153f95471c40b222072b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc93c7f5b3d122314c9c5a707fae556a8f72a574.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.
|
```python
n = int(input())
ans = 0
MOD = int(10**9 + 7)
a = [int(x) for x in input().split()]
a.sort()
po = [1]
for i in range(1,n):
po.append(po[i-1]*2)
for i in range(n):
ans += a[i]*(po[i] - po[n-i-1])
print(ans)
```
| 0
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. Each point of initial 8 should belong to exactly one set. It is acceptable for a rectangle from the second set was also a square. If there are several partitions, Petya will be satisfied by any of them. Help him find such partition. Note that the rectangle and the square from the partition should have non-zero areas. The sides of the figures do not have to be parallel to the coordinate axes, though it might be the case.
|
You are given 8 pairs of integers, a pair per line — the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide.
|
Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers — point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. All printed numbers should be pairwise distinct.
If the required partition does not exist, the first line should contain the word "NO" (without the quotes), after which no output is needed.
|
[
"0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2\n",
"0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n",
"0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1\n"
] |
[
"YES\n5 6 7 8\n1 2 3 4\n",
"NO\n",
"YES\n1 2 3 4\n5 6 7 8\n"
] |
Pay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes.
| 0
|
[] | 1,690,484,616
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 62
| 0
|
print("_RANDOM_GUESS_1690484615.9431627")# 1690484615.9431865
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. Each point of initial 8 should belong to exactly one set. It is acceptable for a rectangle from the second set was also a square. If there are several partitions, Petya will be satisfied by any of them. Help him find such partition. Note that the rectangle and the square from the partition should have non-zero areas. The sides of the figures do not have to be parallel to the coordinate axes, though it might be the case.
Input Specification:
You are given 8 pairs of integers, a pair per line — the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide.
Output Specification:
Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers — point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. All printed numbers should be pairwise distinct.
If the required partition does not exist, the first line should contain the word "NO" (without the quotes), after which no output is needed.
Demo Input:
['0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2\n', '0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n', '0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1\n']
Demo Output:
['YES\n5 6 7 8\n1 2 3 4\n', 'NO\n', 'YES\n1 2 3 4\n5 6 7 8\n']
Note:
Pay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes.
|
```python
print("_RANDOM_GUESS_1690484615.9431627")# 1690484615.9431865
```
| 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,626,172,981
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 102
| 77
| 6,758,400
|
m=input()
n=input()
string=''
for i in range(len(n)):
if m[i]==n[i]:
string+='0'
else:
string+='1'
print(string)
|
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
m=input()
n=input()
string=''
for i in range(len(n)):
if m[i]==n[i]:
string+='0'
else:
string+='1'
print(string)
```
| 3.968161
|
540
|
A
|
Combination Lock
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
|
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
|
[
"5\n82195\n64723\n"
] |
[
"13\n"
] |
In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
| 500
|
[
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
"input": "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746",
"output": "245"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "3\n607\n684",
"output": "5"
},
{
"input": "4\n0809\n0636",
"output": "8"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8037856825987124762280548\n9519431339078678836940020",
"output": "72"
},
{
"input": "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024",
"output": "305"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8037856825987124762285484\n9519431339078678836940202",
"output": "74"
},
{
"input": "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831",
"output": "357"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8378525987476228048406972\n9194339078883694020217816",
"output": "55"
},
{
"input": "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599",
"output": "274"
},
{
"input": "1\n0\n0",
"output": "0"
},
{
"input": "1\n7\n7",
"output": "0"
},
{
"input": "1\n0\n5",
"output": "5"
},
{
"input": "1\n2\n7",
"output": "5"
},
{
"input": "1\n7\n9",
"output": "2"
},
{
"input": "1\n9\n7",
"output": "2"
},
{
"input": "1\n2\n9",
"output": "3"
},
{
"input": "1\n9\n2",
"output": "3"
},
{
"input": "25\n3164978461316464614169874\n9413979197249127496597357",
"output": "66"
},
{
"input": "4\n9999\n9999",
"output": "0"
},
{
"input": "2\n11\n11",
"output": "0"
}
] | 1,645,860,642
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 43
| 46
| 0
|
a=int(input())
b=input()
v=input()
p=0
k=0
pk=0
kp=0
pppkk=0
ppkk=0
ppk=0
kkpp=0
kkp=0
for j in range(a):
bb=b[k]
vv=v[k]
bbb=int(bb)
vvv=int(vv)
if bbb==vvv:
p+=0
if bbb>vvv:
pk=bbb-vvv
kp=(vvv+10)-bbb
kkp=str(kp)
kkpp=len(kkp)
ppk=kkpp-1
ppkk=kkp[ppk]
pppkk=int(ppkk)
if pk<pppkk:
p+=pk
else:
p+=pppkk
if bbb<vvv:
pk=vvv-bbb
kp=(10+bbb)-vvv
if pk<kp:
p+=pk
else:
p+=kp
k+=1
print(p)
|
Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Output Specification:
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
Demo Input:
['5\n82195\n64723\n']
Demo Output:
['13\n']
Note:
In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
|
```python
a=int(input())
b=input()
v=input()
p=0
k=0
pk=0
kp=0
pppkk=0
ppkk=0
ppk=0
kkpp=0
kkp=0
for j in range(a):
bb=b[k]
vv=v[k]
bbb=int(bb)
vvv=int(vv)
if bbb==vvv:
p+=0
if bbb>vvv:
pk=bbb-vvv
kp=(vvv+10)-bbb
kkp=str(kp)
kkpp=len(kkp)
ppk=kkpp-1
ppkk=kkp[ppk]
pppkk=int(ppkk)
if pk<pppkk:
p+=pk
else:
p+=pppkk
if bbb<vvv:
pk=vvv-bbb
kp=(10+bbb)-vvv
if pk<kp:
p+=pk
else:
p+=kp
k+=1
print(p)
```
| 3
|
|
616
|
D
|
Longest k-Good Segment
|
PROGRAMMING
| 1,600
|
[
"binary search",
"data structures",
"two pointers"
] | null | null |
The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
|
The first line contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
|
Print two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in *a* are numbered from 1 to *n* from left to right.
|
[
"5 5\n1 2 3 4 5\n",
"9 3\n6 5 1 2 3 2 1 4 5\n",
"3 1\n1 2 3\n"
] |
[
"1 5\n",
"3 7\n",
"1 1\n"
] |
none
| 0
|
[
{
"input": "5 5\n1 2 3 4 5",
"output": "1 5"
},
{
"input": "9 3\n6 5 1 2 3 2 1 4 5",
"output": "3 7"
},
{
"input": "3 1\n1 2 3",
"output": "1 1"
},
{
"input": "1 1\n747391",
"output": "1 1"
},
{
"input": "5 2\n171230 171230 171230 171230 171230",
"output": "1 5"
},
{
"input": "10 3\n512008 512008 452221 512008 314256 123232 314256 512008 314256 123232",
"output": "4 10"
},
{
"input": "6 1\n1 1 2 1 1 1",
"output": "4 6"
},
{
"input": "5 4\n1 2 3 4 0",
"output": "1 4"
},
{
"input": "5 4\n2 3 4 5 0",
"output": "1 4"
},
{
"input": "2 2\n0 1",
"output": "1 2"
},
{
"input": "2 2\n0 0",
"output": "1 2"
},
{
"input": "5 4\n1 2 3 45 0",
"output": "1 4"
}
] | 1,665,601,237
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 9
| 1,000
| 31,027,200
|
n,k=map(int,input().split())
s=list(map(int,input().split()))
L=0
R=1
RR=0
LL=0
ans=0
liss=[]
liss.append(s[L])
while R<n and L<n:
lenn=(R-L)+1
if lenn>ans:
liss.append(s[R])
if len(set(liss))<=k:
LL=L
RR=R
else:
liss.pop(0)
L+=1
R+=1
print(LL+1,RR+1)
|
Title: Longest k-Good Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input Specification:
The first line contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
Output Specification:
Print two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in *a* are numbered from 1 to *n* from left to right.
Demo Input:
['5 5\n1 2 3 4 5\n', '9 3\n6 5 1 2 3 2 1 4 5\n', '3 1\n1 2 3\n']
Demo Output:
['1 5\n', '3 7\n', '1 1\n']
Note:
none
|
```python
n,k=map(int,input().split())
s=list(map(int,input().split()))
L=0
R=1
RR=0
LL=0
ans=0
liss=[]
liss.append(s[L])
while R<n and L<n:
lenn=(R-L)+1
if lenn>ans:
liss.append(s[R])
if len(set(liss))<=k:
LL=L
RR=R
else:
liss.pop(0)
L+=1
R+=1
print(LL+1,RR+1)
```
| 0
|
|
946
|
A
|
Partition
|
PROGRAMMING
| 800
|
[
"greedy"
] | null | null |
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*?
|
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*.
|
Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*.
|
[
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n"
] |
[
"3\n",
"120\n"
] |
In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* = - 2, *B* - *C* = 3.
In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120.
| 0
|
[
{
"input": "3\n1 -2 0",
"output": "3"
},
{
"input": "6\n16 23 16 15 42 8",
"output": "120"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -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": "10000"
},
{
"input": "2\n-1 5",
"output": "6"
},
{
"input": "3\n-2 0 1",
"output": "3"
},
{
"input": "12\n-1 -2 -3 4 4 -6 -6 56 3 3 -3 3",
"output": "94"
},
{
"input": "4\n1 -1 1 -1",
"output": "4"
},
{
"input": "4\n100 -100 100 -100",
"output": "400"
},
{
"input": "3\n-2 -5 10",
"output": "17"
},
{
"input": "5\n1 -2 3 -4 5",
"output": "15"
},
{
"input": "3\n-100 100 -100",
"output": "300"
},
{
"input": "6\n1 -1 1 -1 1 -1",
"output": "6"
},
{
"input": "6\n2 -2 2 -2 2 -2",
"output": "12"
},
{
"input": "9\n12 93 -2 0 0 0 3 -3 -9",
"output": "122"
},
{
"input": "6\n-1 2 4 -5 -3 55",
"output": "70"
},
{
"input": "6\n-12 8 68 -53 1 -15",
"output": "157"
},
{
"input": "2\n-2 1",
"output": "3"
},
{
"input": "3\n100 -100 100",
"output": "300"
},
{
"input": "5\n100 100 -1 -100 2",
"output": "303"
},
{
"input": "6\n-5 -4 -3 -2 -1 0",
"output": "15"
},
{
"input": "6\n4 4 4 -3 -3 2",
"output": "20"
},
{
"input": "2\n-1 2",
"output": "3"
},
{
"input": "1\n100",
"output": "100"
},
{
"input": "5\n-1 -2 3 1 2",
"output": "9"
},
{
"input": "5\n100 -100 100 -100 100",
"output": "500"
},
{
"input": "5\n1 -1 1 -1 1",
"output": "5"
},
{
"input": "4\n0 0 0 -1",
"output": "1"
},
{
"input": "5\n100 -100 -1 2 100",
"output": "303"
},
{
"input": "2\n75 0",
"output": "75"
},
{
"input": "4\n55 56 -59 -58",
"output": "228"
},
{
"input": "2\n9 71",
"output": "80"
},
{
"input": "2\n9 70",
"output": "79"
},
{
"input": "2\n9 69",
"output": "78"
},
{
"input": "2\n100 -100",
"output": "200"
},
{
"input": "4\n-9 4 -9 5",
"output": "27"
},
{
"input": "42\n91 -27 -79 -56 80 -93 -23 10 80 94 61 -89 -64 81 34 99 31 -32 -69 92 79 -9 73 66 -8 64 99 99 58 -19 -40 21 1 -33 93 -23 -62 27 55 41 57 36",
"output": "2348"
},
{
"input": "7\n-1 2 2 2 -1 2 -1",
"output": "11"
},
{
"input": "6\n-12 8 17 -69 7 -88",
"output": "201"
},
{
"input": "3\n1 -2 5",
"output": "8"
},
{
"input": "6\n-2 3 -4 5 6 -1",
"output": "21"
},
{
"input": "2\n-5 1",
"output": "6"
},
{
"input": "4\n2 2 -2 4",
"output": "10"
},
{
"input": "68\n21 47 -75 -25 64 83 83 -21 89 24 43 44 -35 34 -42 92 -96 -52 -66 64 14 -87 25 -61 -78 83 -96 -18 95 83 -93 -28 75 49 87 65 -93 -69 -2 95 -24 -36 -61 -71 88 -53 -93 -51 -81 -65 -53 -46 -56 6 65 58 19 100 57 61 -53 44 -58 48 -8 80 -88 72",
"output": "3991"
},
{
"input": "5\n5 5 -10 -1 1",
"output": "22"
},
{
"input": "3\n-1 2 3",
"output": "6"
},
{
"input": "76\n57 -38 -48 -81 93 -32 96 55 -44 2 38 -46 42 64 71 -73 95 31 -39 -62 -1 75 -17 57 28 52 12 -11 82 -84 59 -86 73 -97 34 97 -57 -85 -6 39 -5 -54 95 24 -44 35 -18 9 91 7 -22 -61 -80 54 -40 74 -90 15 -97 66 -52 -49 -24 65 21 -93 -29 -24 -4 -1 76 -93 7 -55 -53 1",
"output": "3787"
},
{
"input": "5\n-1 -2 1 2 3",
"output": "9"
},
{
"input": "4\n2 2 -2 -2",
"output": "8"
},
{
"input": "6\n100 -100 100 -100 100 -100",
"output": "600"
},
{
"input": "100\n-59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 61 -9 95 42 -73 -64 91 -96 2 53 -8 82 -79 16 18 -5 -53 26 71 38 -31 12 -33 -1 -65 -6 3 -89 22 33 -27 -36 41 11 -47 -32 47 -56 -38 57 -63 -41 23 41 29 78 16 -65 90 -58 -12 6 -60 42 -36 -52 -54 -95 -10 29 70 50 -94 1 93 48 -71 -77 -16 54 56 -60 66 76 31 8 44 -61 -74 23 37 38 18 -18 29 41",
"output": "4362"
},
{
"input": "2\n-1 1",
"output": "2"
},
{
"input": "3\n1 -2 100",
"output": "103"
},
{
"input": "5\n1 -2 3 1 2",
"output": "9"
},
{
"input": "10\n100 -10 -100 10 10 10 10 10 10 10",
"output": "280"
},
{
"input": "4\n2 0 -2 4",
"output": "8"
},
{
"input": "4\n3 -3 1 -1",
"output": "8"
},
{
"input": "3\n1 -1 1",
"output": "3"
},
{
"input": "4\n2 5 -2 4",
"output": "13"
},
{
"input": "2\n-2 2",
"output": "4"
},
{
"input": "3\n1 -2 1",
"output": "4"
},
{
"input": "5\n-1 -2 1 1 -1",
"output": "6"
},
{
"input": "4\n-2 0 2 4",
"output": "8"
},
{
"input": "8\n-42 7 87 -16 -5 65 -88 1",
"output": "311"
},
{
"input": "3\n1 -3 4",
"output": "8"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "3\n-1 2 -1",
"output": "4"
},
{
"input": "18\n-21 12 65 66 -24 62 82 35 -45 -47 28 37 5 -32 22 -14 -69 -95",
"output": "761"
},
{
"input": "4\n-1 1 -1 1",
"output": "4"
},
{
"input": "5\n-1 2 1 1 1",
"output": "6"
},
{
"input": "3\n1 1 1",
"output": "3"
}
] | 1,578,373,318
| 118
|
Python 3
|
OK
|
TESTS
| 72
| 124
| 307,200
|
n = int(input())
a = list(map(int,input().split()))
b = 0
c = 0
for i in range(n):
if a[i] < 0:
c = c + a[i]
else:
b = b + a[i]
print(b-c)
|
Title: Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*.
Output Specification:
Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*.
Demo Input:
['3\n1 -2 0\n', '6\n16 23 16 15 42 8\n']
Demo Output:
['3\n', '120\n']
Note:
In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* = - 2, *B* - *C* = 3.
In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120.
|
```python
n = int(input())
a = list(map(int,input().split()))
b = 0
c = 0
for i in range(n):
if a[i] < 0:
c = c + a[i]
else:
b = b + a[i]
print(b-c)
```
| 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,599,212,694
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 156
| 307,200
|
import sys
n=int(input())
l=list(str(input()))
se=set(l)
print(se)
if(se=={'4'} or se=={'7'} or se=={'4','7'} or se=={'7','4'}):
pass
else:
print("NO")
sys.exit(0)
k=int(n/2)
f,e=0,0
for i in range(k):
f+=int(l[i])
for i in range(k,n):
e+=int(l[i])
print(f,e)
if(f==e):
print('YES')
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
import sys
n=int(input())
l=list(str(input()))
se=set(l)
print(se)
if(se=={'4'} or se=={'7'} or se=={'4','7'} or se=={'7','4'}):
pass
else:
print("NO")
sys.exit(0)
k=int(n/2)
f,e=0,0
for i in range(k):
f+=int(l[i])
for i in range(k,n):
e+=int(l[i])
print(f,e)
if(f==e):
print('YES')
else:
print('NO')
```
| 0
|
|
389
|
B
|
Fox and Cross
|
PROGRAMMING
| 1,100
|
[
"greedy",
"implementation"
] | null | null |
Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
|
The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board.
Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'.
|
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
|
[
"5\n.#...\n####.\n.####\n...#.\n.....\n",
"4\n####\n####\n####\n####\n",
"6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n",
"6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.\n",
"3\n...\n...\n...\n"
] |
[
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] |
In example 1, you can draw two crosses. The picture below shows what they look like.
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
| 1,000
|
[
{
"input": "4\n####\n####\n####\n####",
"output": "NO"
},
{
"input": "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.",
"output": "YES"
},
{
"input": "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.",
"output": "NO"
},
{
"input": "5\n.....\n.#...\n####.\n.####\n...#.",
"output": "YES"
},
{
"input": "5\n#....\n###..\n.###.\n..##.\n..##.",
"output": "NO"
},
{
"input": "10\n....#...#.\n.#.###.###\n#####.#.#.\n.#######..\n.#.##.#.#.\n######.###\n.#..#.#.#.\n.#..#####.\n##########\n.#..#...#.",
"output": "YES"
},
{
"input": "8\n.#...##.\n##.##.#.\n#....##.\n#.###.##\n...##..#\n#..#.##.\n#..#.#..\n#....###",
"output": "NO"
},
{
"input": "15\n.#...##.##.....\n.###.#.#.##..#.\n##.#####......#\n#....###.#..#..\n#.##.#.###.###.\n.###....#.###.#\n##.....##..#...\n.#.########...#\n##..#..##..#.##\n#...#....##....\n.......#.......\n.#..#.#.####...\n.#..#...#..###.\n#..#.#..#......\n###.....##....#",
"output": "NO"
},
{
"input": "7\n.......\n.......\n.......\n.......\n.....#.\n....###\n.....#.",
"output": "YES"
},
{
"input": "9\n.#.#....#\n#.#.....#\n.#..#..#.\n#.#....##\n...#...#.\n#..###.#.\n....#..##\n.#.###...\n....##..#",
"output": "NO"
},
{
"input": "5\n#...#\n.....\n..#..\n.....\n#...#",
"output": "NO"
},
{
"input": "3\n.#.\n#.#\n.#.",
"output": "NO"
},
{
"input": "3\n...\n...\n..#",
"output": "NO"
}
] | 1,616,858,854
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 6
| 62
| 307,200
|
n = int(input())
matriz = []
yes = True
listNull = []
for i in range(n+4):
listNull.append('.')
for i in range(n+4):
if(i == 0 or i == 1 or i == n+2 or i == n+3):
matriz.append(listNull)
else:
lista = list(input())
lista.insert(0, '.')
lista.insert(1, '.')
lista.append('.')
lista.append('.')
matriz.append(lista)
flag = True
for i in range(2,n+2):
for j in range(2,n+2):
if(matriz[i][j] == '#'):
if(matriz[i+1][j] == '#' and matriz[i+2][j] and matriz[i+1][j-1] and matriz[i+1][j+1]):
matriz[i][j] = '.'
matriz[i+1][j] = '.'
matriz[i+2][j] = '.'
matriz[i+1][j-1] = '.'
matriz[i+1][j+1] = '.'
else:
flag = False
break
if(flag == False):
break
if(flag == False):
print('NO')
else:
print('YES')
|
Title: Fox and Cross
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input Specification:
The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board.
Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'.
Output Specification:
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Demo Input:
['5\n.#...\n####.\n.####\n...#.\n.....\n', '4\n####\n####\n####\n####\n', '6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n', '6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.\n', '3\n...\n...\n...\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'NO\n', 'YES\n']
Note:
In example 1, you can draw two crosses. The picture below shows what they look like.
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
|
```python
n = int(input())
matriz = []
yes = True
listNull = []
for i in range(n+4):
listNull.append('.')
for i in range(n+4):
if(i == 0 or i == 1 or i == n+2 or i == n+3):
matriz.append(listNull)
else:
lista = list(input())
lista.insert(0, '.')
lista.insert(1, '.')
lista.append('.')
lista.append('.')
matriz.append(lista)
flag = True
for i in range(2,n+2):
for j in range(2,n+2):
if(matriz[i][j] == '#'):
if(matriz[i+1][j] == '#' and matriz[i+2][j] and matriz[i+1][j-1] and matriz[i+1][j+1]):
matriz[i][j] = '.'
matriz[i+1][j] = '.'
matriz[i+2][j] = '.'
matriz[i+1][j-1] = '.'
matriz[i+1][j+1] = '.'
else:
flag = False
break
if(flag == False):
break
if(flag == False):
print('NO')
else:
print('YES')
```
| 0
|
|
928
|
A
|
Login Verification
|
PROGRAMMING
| 1,200
|
[
"*special",
"strings"
] | null | null |
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins *s* and *t* are considered similar if we can transform *s* to *t* via a sequence of operations of the following types:
- transform lowercase letters to uppercase and vice versa; - change letter «O» (uppercase latin letter) to digit «0» and vice versa; - change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
|
The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
|
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes).
|
[
"1_wat\n2\n2_wat\nwat_1\n",
"000\n3\n00\nooA\noOo\n",
"_i_\n3\n__i_\n_1_\nI\n",
"La0\n3\n2a0\nLa1\n1a0\n",
"abc\n1\naBc\n",
"0Lil\n2\nLIL0\n0Ril\n"
] |
[
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n"
] |
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one.
| 500
|
[
{
"input": "1_wat\n2\n2_wat\nwat_1",
"output": "Yes"
},
{
"input": "000\n3\n00\nooA\noOo",
"output": "No"
},
{
"input": "_i_\n3\n__i_\n_1_\nI",
"output": "No"
},
{
"input": "La0\n3\n2a0\nLa1\n1a0",
"output": "No"
},
{
"input": "abc\n1\naBc",
"output": "No"
},
{
"input": "0Lil\n2\nLIL0\n0Ril",
"output": "Yes"
},
{
"input": "iloO\n3\niIl0\noIl0\nIooO",
"output": "Yes"
},
{
"input": "L1il0o1L1\n5\niLLoLL\noOI1Io10il\nIoLLoO\nO01ilOoI\nI10l0o",
"output": "Yes"
},
{
"input": "ELioO1lOoOIOiLoooi1iolul1O\n7\nOoEIuOIl1ui1010uiooOoi0Oio001L0EoEolO0\nOLIoOEuoE11u1u1iLOI0oO\nuEOuO0uIOOlO01OlEI0E1Oo0IO1LI0uE0LILO0\nEOo0Il11iIOOOIiuOiIiiLOLEOOII001EE\niOoO0LOulioE0OLIIIulli01OoiuOOOoOlEiI0EiiElIIu0\nlE1LOE1Oil\n1u0EOliIiIOl1u110il0l1O0u",
"output": "Yes"
},
{
"input": "0blo7X\n20\n1oobb6\nXIXIO2X\n2iYI2\n607XXol\n2I6io22\nOl10I\nbXX0Lo\nolOOb7X\n07LlXL\nlXY17\n12iIX2\n7lL70\nbOo11\n17Y6b62\n0O6L7\n1lX2L\n2iYl6lI\n7bXIi1o\niLIY2\n0OIo1X",
"output": "Yes"
},
{
"input": "lkUL\n25\nIIfL\nokl\nfoo\ni0U\noko\niIoU\nUUv\nvli\nv0Uk\n0Of\niill\n1vkl\nUIf\nUfOO\nlvLO\nUUo0\nIOf1\nlovL\nIkk\noIv\nLvfU\n0UI\nkol\n1OO0\n1OOi",
"output": "Yes"
},
{
"input": "L1lo\n3\nOOo1\nL1lo\n0lOl",
"output": "No"
},
{
"input": "LIoooiLO\n5\nLIoooiLO\nl0o01I00\n0OOl0lLO01\nil10i0\noiloi",
"output": "No"
},
{
"input": "1i1lQI\n7\nuLg1uLLigIiOLoggu\nLLLgIuQIQIIloiQuIIoIO0l0o000\n0u1LQu11oIuooIl0OooLg0i0IQu1O1lloI1\nQuQgIQi0LOIliLOuuuioLQou1l\nlLIO00QLi01LogOliOIggII1\no0Ll1uIOQl10IL0IILQ\n1i1lQI",
"output": "No"
},
{
"input": "oIzz1\n20\n1TTl0O\nloF0LT\n1lLzo\noi0Ov\nFlIF1zT\nzoITzx\n0TIFlT\nl1vllil\nOviix1F\nLFvI1lL\nLIl0loz\nixz1v\n1i1vFi\nTIFTol\noIzz1\nIvTl0o\nxv1U0O\niiiioF\n1oiLUlO\nxToxv1",
"output": "No"
},
{
"input": "00L0\n25\n0il\nIlkZ\nL0I\n00L0\nBd0\nZLd\n0d1k\nddk\nIdl\nkBd\nkBOL\nZ1lI\nkBL\nLOko\noZ0i\nZ1lO\nLiOk\niBld\nLO0d\ndIo\nZ10\n1k1i\n0o0L\nIoBd\ni0B0",
"output": "No"
},
{
"input": "Z\n1\nz",
"output": "No"
},
{
"input": "0\n1\no",
"output": "No"
},
{
"input": "0\n1\nO",
"output": "No"
},
{
"input": "o\n1\n0",
"output": "No"
},
{
"input": "o\n1\nO",
"output": "No"
},
{
"input": "o\n1\no",
"output": "No"
},
{
"input": "O\n1\no",
"output": "No"
},
{
"input": "O\n1\n0",
"output": "No"
},
{
"input": "1\n1\nl",
"output": "No"
},
{
"input": "1\n1\nL",
"output": "No"
},
{
"input": "1\n1\ni",
"output": "No"
},
{
"input": "1\n1\nI",
"output": "No"
},
{
"input": "1\n1\no",
"output": "Yes"
},
{
"input": "i\n1\n1",
"output": "No"
},
{
"input": "i\n1\nL",
"output": "No"
},
{
"input": "i\n1\nl",
"output": "No"
},
{
"input": "I\n1\nL",
"output": "No"
},
{
"input": "I\n1\nl",
"output": "No"
},
{
"input": "I\n1\n1",
"output": "No"
},
{
"input": "l\n1\n1",
"output": "No"
},
{
"input": "l\n1\nL",
"output": "No"
},
{
"input": "l\n1\ni",
"output": "No"
},
{
"input": "l\n1\nI",
"output": "No"
},
{
"input": "L\n1\nl",
"output": "No"
},
{
"input": "L\n1\n1",
"output": "No"
},
{
"input": "L\n1\ni",
"output": "No"
},
{
"input": "L\n1\nI",
"output": "No"
}
] | 1,519,489,506
| 3,006
|
PyPy 3
|
OK
|
TESTS
| 73
| 155
| 20,787,200
|
from collections import Counter
def corr(s):
z=[]
for i in s:
z.append(d[i])
return z
def comp(s0,s1):
if len(s0)==len(s1):
for i in range(len(s)):
if not s1[i] in s0[i]:
return False
return True
else:
return False
s=input()
n=int(input())
d={}
for i in range(ord('a'),ord('z')+1):
d[chr(i)]=[chr(i-ord('a')+ord('A')),chr(i)]
for i in range(ord('A'),ord('Z')+1):
d[chr(i)]=[chr(i+ord('a')-ord('A')),chr(i)]
for i in range(10):
d[str(i)]=[str(i)]
d['L'].append('1')
d['l'].append('1')
d['I'].append('1')
d['i'].append('1')
d['O'].append('0')
d['o'].append('0')
d['1'].append('L')
d['1'].append('l')
d['1'].append('I')
d['1'].append('i')
d['0'].append('O')
d['0'].append('o')
d['l'].append('I')
d['l'].append('i')
d['L'].append('I')
d['L'].append('i')
d['I'].append('L')
d['I'].append('l')
d['i'].append('L')
d['i'].append('l')
d['_']=['_']
s=corr(s)
for i in range(n):
if comp(s,input()):
print('No')
exit()
print('Yes')
|
Title: Login Verification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins *s* and *t* are considered similar if we can transform *s* to *t* via a sequence of operations of the following types:
- transform lowercase letters to uppercase and vice versa; - change letter «O» (uppercase latin letter) to digit «0» and vice versa; - change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
Input Specification:
The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
Output Specification:
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes).
Demo Input:
['1_wat\n2\n2_wat\nwat_1\n', '000\n3\n00\nooA\noOo\n', '_i_\n3\n__i_\n_1_\nI\n', 'La0\n3\n2a0\nLa1\n1a0\n', 'abc\n1\naBc\n', '0Lil\n2\nLIL0\n0Ril\n']
Demo Output:
['Yes\n', 'No\n', 'No\n', 'No\n', 'No\n', 'Yes\n']
Note:
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one.
|
```python
from collections import Counter
def corr(s):
z=[]
for i in s:
z.append(d[i])
return z
def comp(s0,s1):
if len(s0)==len(s1):
for i in range(len(s)):
if not s1[i] in s0[i]:
return False
return True
else:
return False
s=input()
n=int(input())
d={}
for i in range(ord('a'),ord('z')+1):
d[chr(i)]=[chr(i-ord('a')+ord('A')),chr(i)]
for i in range(ord('A'),ord('Z')+1):
d[chr(i)]=[chr(i+ord('a')-ord('A')),chr(i)]
for i in range(10):
d[str(i)]=[str(i)]
d['L'].append('1')
d['l'].append('1')
d['I'].append('1')
d['i'].append('1')
d['O'].append('0')
d['o'].append('0')
d['1'].append('L')
d['1'].append('l')
d['1'].append('I')
d['1'].append('i')
d['0'].append('O')
d['0'].append('o')
d['l'].append('I')
d['l'].append('i')
d['L'].append('I')
d['L'].append('i')
d['I'].append('L')
d['I'].append('l')
d['i'].append('L')
d['i'].append('l')
d['_']=['_']
s=corr(s)
for i in range(n):
if comp(s,input()):
print('No')
exit()
print('Yes')
```
| 3
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
You've got array *A*, consisting of *n* integers and a positive integer *k*. Array *A* is indexed by integers from 1 to *n*.
You need to permute the array elements so that value
|
The first line contains two integers *n*,<=*k* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=*min*(5000,<=*n*<=-<=1)).
The second line contains *n* integers *A*[1],<=*A*[2],<=...,<=*A*[*n*] (<=-<=109<=≤<=*A*[*i*]<=≤<=109), separate by spaces — elements of the array *A*.
|
Print the minimum possible value of the sum described in the statement.
|
[
"3 2\n1 2 4\n",
"5 2\n3 -5 3 -5 3\n",
"6 3\n4 3 4 3 2 5\n"
] |
[
"1\n",
"0\n",
"3\n"
] |
In the first test one of the optimal permutations is 1 4 2.
In the second test the initial order is optimal.
In the third test one of the optimal permutations is 2 3 4 4 3 5.
| 0
|
[] | 1,691,489,463
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 0
|
print("_RANDOM_GUESS_1691489463.2470107")# 1691489463.2470274
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *A*, consisting of *n* integers and a positive integer *k*. Array *A* is indexed by integers from 1 to *n*.
You need to permute the array elements so that value
Input Specification:
The first line contains two integers *n*,<=*k* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=*min*(5000,<=*n*<=-<=1)).
The second line contains *n* integers *A*[1],<=*A*[2],<=...,<=*A*[*n*] (<=-<=109<=≤<=*A*[*i*]<=≤<=109), separate by spaces — elements of the array *A*.
Output Specification:
Print the minimum possible value of the sum described in the statement.
Demo Input:
['3 2\n1 2 4\n', '5 2\n3 -5 3 -5 3\n', '6 3\n4 3 4 3 2 5\n']
Demo Output:
['1\n', '0\n', '3\n']
Note:
In the first test one of the optimal permutations is 1 4 2.
In the second test the initial order is optimal.
In the third test one of the optimal permutations is 2 3 4 4 3 5.
|
```python
print("_RANDOM_GUESS_1691489463.2470107")# 1691489463.2470274
```
| 0
|
|
131
|
A
|
cAPS lOCK
|
PROGRAMMING
| 1,000
|
[
"implementation",
"strings"
] | null | null |
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
|
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
|
Print the result of the given word's processing.
|
[
"cAPS\n",
"Lock\n"
] |
[
"Caps",
"Lock\n"
] |
none
| 500
|
[
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
"input": "oops",
"output": "oops"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "a"
},
{
"input": "aA",
"output": "Aa"
},
{
"input": "Zz",
"output": "Zz"
},
{
"input": "Az",
"output": "Az"
},
{
"input": "zA",
"output": "Za"
},
{
"input": "AAA",
"output": "aaa"
},
{
"input": "AAa",
"output": "AAa"
},
{
"input": "AaR",
"output": "AaR"
},
{
"input": "Tdr",
"output": "Tdr"
},
{
"input": "aTF",
"output": "Atf"
},
{
"input": "fYd",
"output": "fYd"
},
{
"input": "dsA",
"output": "dsA"
},
{
"input": "fru",
"output": "fru"
},
{
"input": "hYBKF",
"output": "Hybkf"
},
{
"input": "XweAR",
"output": "XweAR"
},
{
"input": "mogqx",
"output": "mogqx"
},
{
"input": "eOhEi",
"output": "eOhEi"
},
{
"input": "nkdku",
"output": "nkdku"
},
{
"input": "zcnko",
"output": "zcnko"
},
{
"input": "lcccd",
"output": "lcccd"
},
{
"input": "vwmvg",
"output": "vwmvg"
},
{
"input": "lvchf",
"output": "lvchf"
},
{
"input": "IUNVZCCHEWENCHQQXQYPUJCRDZLUXCLJHXPHBXEUUGNXOOOPBMOBRIBHHMIRILYJGYYGFMTMFSVURGYHUWDRLQVIBRLPEVAMJQYO",
"output": "iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgyygfmtmfsvurgyhuwdrlqvibrlpevamjqyo"
},
{
"input": "OBHSZCAMDXEJWOZLKXQKIVXUUQJKJLMMFNBPXAEFXGVNSKQLJGXHUXHGCOTESIVKSFMVVXFVMTEKACRIWALAGGMCGFEXQKNYMRTG",
"output": "obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksfmvvxfvmtekacriwalaggmcgfexqknymrtg"
},
{
"input": "IKJYZIKROIYUUCTHSVSKZTETNNOCMAUBLFJCEVANCADASMZRCNLBZPQRXESHEEMOMEPCHROSRTNBIDXYMEPJSIXSZQEBTEKKUHFS",
"output": "ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemomepchrosrtnbidxymepjsixszqebtekkuhfs"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "uCKJZRGZJCPPLEEYJTUNKOQSWGBMTBQEVPYFPIPEKRVYQNTDPANOIXKMPINNFUSZWCURGBDPYTEKBEKCPMVZPMWAOSHJYMGKOMBQ",
"output": "Uckjzrgzjcppleeyjtunkoqswgbmtbqevpyfpipekrvyqntdpanoixkmpinnfuszwcurgbdpytekbekcpmvzpmwaoshjymgkombq"
},
{
"input": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR",
"output": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR"
},
{
"input": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE",
"output": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE"
},
{
"input": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ",
"output": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ"
},
{
"input": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm",
"output": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm"
},
{
"input": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm",
"output": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm"
},
{
"input": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg",
"output": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg"
},
{
"input": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc",
"output": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc"
},
{
"input": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv",
"output": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv"
},
{
"input": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect",
"output": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu",
"output": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu"
},
{
"input": "aBACABa",
"output": "aBACABa"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAaa",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAaa"
},
{
"input": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
},
{
"input": "dDDDDDDDDDDDDD",
"output": "Dddddddddddddd"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "z",
"output": "Z"
},
{
"input": "AZ",
"output": "az"
},
{
"input": "Z",
"output": "z"
},
{
"input": "aAAAA",
"output": "Aaaaa"
},
{
"input": "F",
"output": "f"
}
] | 1,699,019,037
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 56
| 62
| 0
|
a=str(input())
if a==a.upper() or (a[:1]==a[:1].lower() and a[1:]==a[1:].upper()):
s=""
for i in range(len(a)):
if a[i]==a[i].lower():
s+=a[i].upper()
else:
s+=a[i].lower()
print(s)
else:
print(a)
|
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
a=str(input())
if a==a.upper() or (a[:1]==a[:1].lower() and a[1:]==a[1:].upper()):
s=""
for i in range(len(a)):
if a[i]==a[i].lower():
s+=a[i].upper()
else:
s+=a[i].lower()
print(s)
else:
print(a)
```
| 3
|
|
628
|
D
|
Magic Numbers
|
PROGRAMMING
| 2,200
|
[
"dp"
] | null | null |
Consider the decimal presentation of an integer. Let's call a number d-magic if digit *d* appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magic and 71 is 1-magic.
Find the number of d-magic numbers in the segment [*a*,<=*b*] that are multiple of *m*. Because the answer can be very huge you should only find its value modulo 109<=+<=7 (so you should find the remainder after dividing by 109<=+<=7).
|
The first line contains two integers *m*,<=*d* (1<=≤<=*m*<=≤<=2000, 0<=≤<=*d*<=≤<=9) — the parameters from the problem statement.
The second line contains positive integer *a* in decimal presentation (without leading zeroes).
The third line contains positive integer *b* in decimal presentation (without leading zeroes).
It is guaranteed that *a*<=≤<=*b*, the number of digits in *a* and *b* are the same and don't exceed 2000.
|
Print the only integer *a* — the remainder after dividing by 109<=+<=7 of the number of d-magic numbers in segment [*a*,<=*b*] that are multiple of *m*.
|
[
"2 6\n10\n99\n",
"2 0\n1\n9\n",
"19 7\n1000\n9999\n"
] |
[
"8\n",
"4\n",
"6\n"
] |
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96.
The numbers from the answer of the second example are 2, 4, 6 and 8.
The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747.
| 0
|
[
{
"input": "2 6\n10\n99",
"output": "8"
},
{
"input": "2 0\n1\n9",
"output": "4"
},
{
"input": "19 7\n1000\n9999",
"output": "6"
},
{
"input": "9 4\n33\n52",
"output": "0"
},
{
"input": "10 8\n18\n59",
"output": "0"
},
{
"input": "43 3\n587\n850",
"output": "1"
},
{
"input": "65 3\n3436\n3632",
"output": "0"
},
{
"input": "850 8\n55735\n94089",
"output": "0"
},
{
"input": "590 6\n428671\n715453",
"output": "0"
},
{
"input": "1053 8\n1539368\n3362621",
"output": "0"
},
{
"input": "477 9\n3062053\n6465858",
"output": "6"
},
{
"input": "1901 9\n1941695\n3314270",
"output": "0"
},
{
"input": "29 0\n1649127\n6241670",
"output": "126"
},
{
"input": "566 3\n6372451659957700362854162843720623142601337360014410221724168092176479911659703538545016668832338549\n7969973326176891147525183958122002014921396842270051000646823226374743898663307171214245111949604186",
"output": "0"
},
{
"input": "1286 5\n1886373541983002858974907276497223649072414883083336663541044958378875954171855070620868427474284001\n4050983123791059817478363830631049287126338893626273758612677264947268375965600848751800494833017145",
"output": "0"
},
{
"input": "2 5\n1762712\n8121765",
"output": "2025"
},
{
"input": "2 2\n12\n12",
"output": "1"
},
{
"input": "2 0\n10\n10",
"output": "1"
},
{
"input": "2 6\n46\n46",
"output": "1"
},
{
"input": "2 0\n10\n20",
"output": "2"
},
{
"input": "2 9\n10000000000\n99999999999",
"output": "262440"
},
{
"input": "10 2\n12300\n99900",
"output": "70"
},
{
"input": "5 5\n5\n5",
"output": "0"
},
{
"input": "1 2\n113548484131315415454546546467913135484841313154154\n895458414564646646487131313118761454584145646466464",
"output": "970729981"
},
{
"input": "2 2\n12\n14",
"output": "1"
},
{
"input": "2 2\n2934\n4323",
"output": "18"
},
{
"input": "2 4\n1\n9",
"output": "3"
},
{
"input": "1 0\n10\n20",
"output": "2"
},
{
"input": "7 7\n7\n7",
"output": "0"
},
{
"input": "2 1\n143\n413",
"output": "12"
},
{
"input": "1 4\n1\n9",
"output": "8"
},
{
"input": "2 6\n36\n36",
"output": "1"
},
{
"input": "4 4\n24344\n48880",
"output": "29"
},
{
"input": "2 0\n1000\n9999",
"output": "81"
},
{
"input": "3 9\n39\n39",
"output": "1"
},
{
"input": "3 9\n10\n99",
"output": "2"
},
{
"input": "1 0\n10000\n99999",
"output": "729"
},
{
"input": "3 2\n681563\n828242",
"output": "48"
},
{
"input": "1 5\n454\n667",
"output": "14"
},
{
"input": "2 0\n2\n9",
"output": "4"
},
{
"input": "2 6\n7\n9",
"output": "1"
},
{
"input": "10 7\n1\n1",
"output": "0"
},
{
"input": "6 0\n1\n6",
"output": "1"
},
{
"input": "6 2\n22\n95",
"output": "2"
},
{
"input": "28 1\n102\n898",
"output": "2"
},
{
"input": "1 0\n1\n9",
"output": "9"
},
{
"input": "1 1\n1\n9",
"output": "8"
},
{
"input": "3 9\n10\n69",
"output": "2"
},
{
"input": "1 0\n1\n1",
"output": "1"
}
] | 1,585,652,677
| 2,147,483,647
|
PyPy 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 202
| 2,048,000
|
#!/usr/bin/env python3
from __future__ import division, print_function
# import sys
# sys.setrecursionlimit(4*10**5)
# from functools import lru_cache
# m, d = map(int, input().split())
# a = input()
# b = input()
def counter(m, d, b):
b = list(map(int, b))
n = len(b)
arr = [ [ [0]*2 for _ in range(m) ] for __ in range(n + 1) ]
arr[0][0][1] = 1
for pos in range(n):
for remain in range(m):
for f in range(2):
for i in range(b[pos] + 1 if f else 10):
if pos&1 and i != d:
continue
if not pos&1 and i == d:
continue
if not pos and not i:
continue
npos = pos + 1
next_remain = (remain * 10 + i) % m
next_f = f and (i == b[pos])
arr[npos][next_remain][next_f] = (arr[npos][next_remain][next_f] + arr[pos][remain][f]) % (10**9 + 7)
return (arr[n][0][0] + arr[n][0][1]) % (10**9 + 7)
# if len( str( int(a) - 1) ) == len(a):
# a = str(int(a) - 1)
# arr1 = list(map(int, a))
# c1 = solve(m, d, arr1 )
# else:
# c1 = 0
# arr2 = list(map(int, b))
# c2 = solve(m, d, arr2)
# # print (c1, c2)
# print ( (c2 - c1) % (10**9 + 7) )
def solver(ifs):
m, d = list(map(int, ifs.readline().split()))
a = ifs.readline().strip()
b = ifs.readline().strip()
res = counter(b, m, d)
if a != '0':
a = str(int(a) - 1)
if len(a) < len(b):
a = '0' + a
modulo = 1000000007
res = ( res - counter(a, m, d) ) % modulo
print(res)
def main():
import sys
if sys.version_info.major == 3:
from io import StringIO as StreamIO
else:
from io import BytesIO as StreamIO
with StreamIO(sys.stdin.read()) as ifs, StreamIO() as ofs:
_stdout = sys.stdout
sys.stdout = ofs
solver(ifs)
sys.stdout = _stdout
sys.stdout.write(ofs.getvalue())
return 0
if __name__ == '__main__':
main()
|
Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the decimal presentation of an integer. Let's call a number d-magic if digit *d* appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magic and 71 is 1-magic.
Find the number of d-magic numbers in the segment [*a*,<=*b*] that are multiple of *m*. Because the answer can be very huge you should only find its value modulo 109<=+<=7 (so you should find the remainder after dividing by 109<=+<=7).
Input Specification:
The first line contains two integers *m*,<=*d* (1<=≤<=*m*<=≤<=2000, 0<=≤<=*d*<=≤<=9) — the parameters from the problem statement.
The second line contains positive integer *a* in decimal presentation (without leading zeroes).
The third line contains positive integer *b* in decimal presentation (without leading zeroes).
It is guaranteed that *a*<=≤<=*b*, the number of digits in *a* and *b* are the same and don't exceed 2000.
Output Specification:
Print the only integer *a* — the remainder after dividing by 109<=+<=7 of the number of d-magic numbers in segment [*a*,<=*b*] that are multiple of *m*.
Demo Input:
['2 6\n10\n99\n', '2 0\n1\n9\n', '19 7\n1000\n9999\n']
Demo Output:
['8\n', '4\n', '6\n']
Note:
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96.
The numbers from the answer of the second example are 2, 4, 6 and 8.
The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747.
|
```python
#!/usr/bin/env python3
from __future__ import division, print_function
# import sys
# sys.setrecursionlimit(4*10**5)
# from functools import lru_cache
# m, d = map(int, input().split())
# a = input()
# b = input()
def counter(m, d, b):
b = list(map(int, b))
n = len(b)
arr = [ [ [0]*2 for _ in range(m) ] for __ in range(n + 1) ]
arr[0][0][1] = 1
for pos in range(n):
for remain in range(m):
for f in range(2):
for i in range(b[pos] + 1 if f else 10):
if pos&1 and i != d:
continue
if not pos&1 and i == d:
continue
if not pos and not i:
continue
npos = pos + 1
next_remain = (remain * 10 + i) % m
next_f = f and (i == b[pos])
arr[npos][next_remain][next_f] = (arr[npos][next_remain][next_f] + arr[pos][remain][f]) % (10**9 + 7)
return (arr[n][0][0] + arr[n][0][1]) % (10**9 + 7)
# if len( str( int(a) - 1) ) == len(a):
# a = str(int(a) - 1)
# arr1 = list(map(int, a))
# c1 = solve(m, d, arr1 )
# else:
# c1 = 0
# arr2 = list(map(int, b))
# c2 = solve(m, d, arr2)
# # print (c1, c2)
# print ( (c2 - c1) % (10**9 + 7) )
def solver(ifs):
m, d = list(map(int, ifs.readline().split()))
a = ifs.readline().strip()
b = ifs.readline().strip()
res = counter(b, m, d)
if a != '0':
a = str(int(a) - 1)
if len(a) < len(b):
a = '0' + a
modulo = 1000000007
res = ( res - counter(a, m, d) ) % modulo
print(res)
def main():
import sys
if sys.version_info.major == 3:
from io import StringIO as StreamIO
else:
from io import BytesIO as StreamIO
with StreamIO(sys.stdin.read()) as ifs, StreamIO() as ofs:
_stdout = sys.stdout
sys.stdout = ofs
solver(ifs)
sys.stdout = _stdout
sys.stdout.write(ofs.getvalue())
return 0
if __name__ == '__main__':
main()
```
| -1
|
|
678
|
C
|
Joty and Chocolate
|
PROGRAMMING
| 1,600
|
[
"implementation",
"math",
"number theory"
] | null | null |
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue.
After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue.
Note that she can paint tiles in any order she wants.
Given the required information, find the maximum number of chocolates Joty can get.
|
The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109).
|
Print the only integer *s* — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
|
[
"5 2 3 12 15\n",
"20 2 3 3 5\n"
] |
[
"39\n",
"51\n"
] |
none
| 0
|
[
{
"input": "5 2 3 12 15",
"output": "39"
},
{
"input": "20 2 3 3 5",
"output": "51"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 2 2",
"output": "0"
},
{
"input": "2 1 3 3 3",
"output": "6"
},
{
"input": "3 1 1 3 3",
"output": "9"
},
{
"input": "4 1 5 4 3",
"output": "16"
},
{
"input": "8 8 1 1 1",
"output": "8"
},
{
"input": "15 14 32 65 28",
"output": "65"
},
{
"input": "894 197 325 232 902",
"output": "2732"
},
{
"input": "8581 6058 3019 2151 4140",
"output": "10431"
},
{
"input": "41764 97259 54586 18013 75415",
"output": "0"
},
{
"input": "333625 453145 800800 907251 446081",
"output": "0"
},
{
"input": "4394826 2233224 609367 3364334 898489",
"output": "9653757"
},
{
"input": "13350712 76770926 61331309 8735000 9057368",
"output": "0"
},
{
"input": "142098087 687355301 987788392 75187408 868856364",
"output": "0"
},
{
"input": "1000000000 1 3 1000000000 999999999",
"output": "1000000000000000000"
},
{
"input": "6 6 2 8 2",
"output": "12"
},
{
"input": "500 8 4 4 5",
"output": "625"
},
{
"input": "20 4 6 2 3",
"output": "17"
},
{
"input": "10 3 9 1 2",
"output": "4"
},
{
"input": "120 18 6 3 5",
"output": "100"
},
{
"input": "30 4 6 2 2",
"output": "20"
},
{
"input": "1000000000 7171 2727 191 272",
"output": "125391842"
},
{
"input": "5 2 2 4 1",
"output": "8"
},
{
"input": "1000000000 2 2 3 3",
"output": "1500000000"
},
{
"input": "24 4 6 5 7",
"output": "48"
},
{
"input": "216 6 36 10 100",
"output": "900"
},
{
"input": "100 12 6 1 10",
"output": "160"
},
{
"input": "1000 4 8 3 5",
"output": "1000"
},
{
"input": "10 2 4 3 6",
"output": "21"
},
{
"input": "1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "10 5 10 2 3",
"output": "5"
},
{
"input": "100000 3 9 1 2",
"output": "44444"
},
{
"input": "10 2 4 1 100",
"output": "203"
},
{
"input": "20 6 4 2 3",
"output": "19"
},
{
"input": "1200 4 16 2 3",
"output": "675"
},
{
"input": "7 2 4 7 9",
"output": "23"
},
{
"input": "24 6 4 15 10",
"output": "100"
},
{
"input": "50 2 8 15 13",
"output": "375"
},
{
"input": "100 4 6 12 15",
"output": "444"
},
{
"input": "56756 9 18 56 78",
"output": "422502"
},
{
"input": "10000 4 6 10 12",
"output": "36662"
},
{
"input": "20 2 4 3 5",
"output": "40"
},
{
"input": "24 4 6 10 100",
"output": "440"
},
{
"input": "12 2 4 5 6",
"output": "33"
},
{
"input": "100 2 4 1 100",
"output": "2525"
},
{
"input": "1000 4 6 50 50",
"output": "16650"
},
{
"input": "60 12 6 12 15",
"output": "150"
},
{
"input": "1000 2 4 5 6",
"output": "2750"
},
{
"input": "1000000000 1 1 9999 5555",
"output": "9999000000000"
},
{
"input": "50 2 2 4 5",
"output": "125"
},
{
"input": "14 4 2 2 3",
"output": "21"
},
{
"input": "100 3 9 1 2",
"output": "44"
},
{
"input": "1000000000 4 6 1 1000000000",
"output": "166666666166666667"
},
{
"input": "12 3 3 45 4",
"output": "180"
},
{
"input": "12 2 4 5 9",
"output": "42"
},
{
"input": "1000000000 2 2 1000000000 1000000000",
"output": "500000000000000000"
},
{
"input": "50 4 8 5 6",
"output": "66"
},
{
"input": "32 4 16 6 3",
"output": "48"
},
{
"input": "10000 2 4 1 1",
"output": "5000"
},
{
"input": "8 2 4 100 1",
"output": "400"
},
{
"input": "20 4 2 10 1",
"output": "55"
},
{
"input": "5 2 2 12 15",
"output": "30"
},
{
"input": "20 2 12 5 6",
"output": "51"
},
{
"input": "10 2 4 1 2",
"output": "7"
},
{
"input": "32 4 16 3 6",
"output": "30"
},
{
"input": "50 2 8 13 15",
"output": "337"
},
{
"input": "12 6 4 10 9",
"output": "38"
},
{
"input": "1000000000 999999998 999999999 999999998 999999999",
"output": "1999999997"
},
{
"input": "20 2 4 10 20",
"output": "150"
},
{
"input": "13 4 6 12 15",
"output": "54"
},
{
"input": "30 3 6 5 7",
"output": "60"
},
{
"input": "7 2 4 2 1",
"output": "6"
},
{
"input": "100000 32 16 2 3",
"output": "18750"
},
{
"input": "6 2 6 1 1",
"output": "3"
},
{
"input": "999999999 180 192 46642017 28801397",
"output": "399129078526502"
},
{
"input": "12 4 6 1 1",
"output": "4"
},
{
"input": "10 2 4 10 5",
"output": "50"
},
{
"input": "1000000 4 6 12 14",
"output": "4333328"
},
{
"input": "2000 20 30 3 5",
"output": "531"
},
{
"input": "1000000000 1 2 1 1",
"output": "1000000000"
},
{
"input": "30 3 15 10 3",
"output": "100"
},
{
"input": "1000 2 4 1 100",
"output": "25250"
},
{
"input": "6 3 3 12 15",
"output": "30"
},
{
"input": "24 4 6 1 1",
"output": "8"
},
{
"input": "20 2 12 4 5",
"output": "41"
},
{
"input": "1000000000 9 15 10 10",
"output": "1555555550"
},
{
"input": "16 2 4 1 2",
"output": "12"
},
{
"input": "100000 4 6 12 14",
"output": "433328"
},
{
"input": "24 6 4 1 1",
"output": "8"
},
{
"input": "1000000 4 6 12 15",
"output": "4499994"
},
{
"input": "100 2 4 5 6",
"output": "275"
},
{
"input": "10 3 9 12 15",
"output": "39"
},
{
"input": "1000000000 1 1 999999999 999999999",
"output": "999999999000000000"
},
{
"input": "6 2 4 2 3",
"output": "7"
},
{
"input": "2 2 2 2 2",
"output": "2"
},
{
"input": "6 6 2 1 1",
"output": "3"
},
{
"input": "100 2 4 3 7",
"output": "250"
},
{
"input": "1000000 32 16 2 5",
"output": "312500"
},
{
"input": "100 20 15 50 25",
"output": "375"
},
{
"input": "1000000000 100000007 100000013 10 3",
"output": "117"
},
{
"input": "1000000000 9999999 99999998 3 3",
"output": "330"
},
{
"input": "10077696 24 36 10 100",
"output": "30792960"
},
{
"input": "392852503 148746166 420198270 517065752 906699795",
"output": "1034131504"
},
{
"input": "536870912 60000 72000 271828 314159",
"output": "4369119072"
},
{
"input": "730114139 21550542 204644733 680083361 11353255",
"output": "22476810678"
},
{
"input": "538228881 766493289 791886544 468896052 600136703",
"output": "0"
},
{
"input": "190 20 50 84 172",
"output": "1188"
},
{
"input": "1000 5 10 80 90",
"output": "17000"
},
{
"input": "99999999 999999998 1 271828 314159",
"output": "31415899685841"
},
{
"input": "22 3 6 1243 1",
"output": "8701"
},
{
"input": "15 10 5 2 2",
"output": "6"
},
{
"input": "1000000000 1000000000 1 1000000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "62 62 42 78 124",
"output": "202"
},
{
"input": "2 2 2 2 1",
"output": "2"
},
{
"input": "864351351 351 313 531 11",
"output": "1337898227"
},
{
"input": "26 3 6 1244 1",
"output": "9952"
},
{
"input": "1000 4 6 7 3",
"output": "1999"
},
{
"input": "134312 3 6 33333 1",
"output": "1492318410"
},
{
"input": "100 4 6 17 18",
"output": "577"
},
{
"input": "6 2 4 5 6",
"output": "16"
},
{
"input": "8 2 4 10 1",
"output": "40"
},
{
"input": "10 2 4 3 3",
"output": "15"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "1000"
},
{
"input": "123123 3 6 34312 2",
"output": "1408198792"
},
{
"input": "1000000000 25 5 999 999",
"output": "199800000000"
},
{
"input": "100 4 2 5 12",
"output": "600"
},
{
"input": "50 2 4 4 5",
"output": "112"
},
{
"input": "24 4 6 100 333",
"output": "1732"
},
{
"input": "216 24 36 10 100",
"output": "660"
},
{
"input": "50 6 4 3 8",
"output": "108"
},
{
"input": "146 76 2 178 192",
"output": "14016"
},
{
"input": "55 8 6 11 20",
"output": "224"
},
{
"input": "5 2 4 6 16",
"output": "22"
},
{
"input": "54 2 52 50 188",
"output": "1488"
},
{
"input": "536870912 60000000 72000000 271828 314159",
"output": "4101909"
},
{
"input": "1000000000 1000000000 1 1 100",
"output": "100000000000"
},
{
"input": "50 4 2 4 5",
"output": "125"
},
{
"input": "198 56 56 122 118",
"output": "366"
},
{
"input": "5 1000000000 1 12 15",
"output": "75"
},
{
"input": "1000 6 12 5 6",
"output": "913"
},
{
"input": "50 3 6 12 15",
"output": "216"
},
{
"input": "333 300 300 300 300",
"output": "300"
},
{
"input": "1 1000000000 1 1 2",
"output": "2"
},
{
"input": "188 110 110 200 78",
"output": "200"
},
{
"input": "100000 20 10 3 2",
"output": "25000"
},
{
"input": "100 2 4 1 10",
"output": "275"
},
{
"input": "1000000000 2 1000000000 1 1000000",
"output": "500999999"
},
{
"input": "20 3 6 5 7",
"output": "36"
},
{
"input": "50 4 6 4 5",
"output": "72"
},
{
"input": "96 46 4 174 156",
"output": "3936"
},
{
"input": "5 2 4 12 15",
"output": "27"
},
{
"input": "12 3 6 100 1",
"output": "400"
},
{
"input": "100 4 2 10 32",
"output": "1600"
},
{
"input": "1232 3 6 30000 3",
"output": "12300000"
},
{
"input": "20 3 6 5 4",
"output": "30"
},
{
"input": "100 6 15 11 29",
"output": "317"
},
{
"input": "10000000 4 8 100 200",
"output": "375000000"
},
{
"input": "1000000000 12 24 2 4",
"output": "249999998"
},
{
"input": "123 3 6 3000 1",
"output": "123000"
},
{
"input": "401523968 1536 2664 271828 314159",
"output": "117768531682"
},
{
"input": "9 2 4 3 5",
"output": "16"
},
{
"input": "999999999 724362018 772432019 46201854 20017479",
"output": "66219333"
},
{
"input": "100 2 4 1 1000",
"output": "25025"
},
{
"input": "50 2 4 1 1000",
"output": "12013"
},
{
"input": "1000000000 2 1 2 1",
"output": "1500000000"
},
{
"input": "1000000000 2005034 2005046 15 12",
"output": "13446"
},
{
"input": "1000000000 999999999 1000000000 1 1",
"output": "2"
},
{
"input": "999999999 500000000 1 100 1000",
"output": "999999999000"
},
{
"input": "50 8 6 3 4",
"output": "44"
},
{
"input": "1000000000 1 1 1000000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "1000000000 999999862 999999818 15 12",
"output": "27"
},
{
"input": "1000000000 10000019 10000019 21 17",
"output": "2079"
},
{
"input": "20 6 4 8 2",
"output": "32"
},
{
"input": "1000000000 1000000000 1 1 1",
"output": "1000000000"
},
{
"input": "1000000000 12345678 123456789 1000000000 999999999",
"output": "88999999992"
},
{
"input": "1000000000 2 999999937 100000000 100000000",
"output": "50000000100000000"
},
{
"input": "1000000000 1 1 1000000000 999999999",
"output": "1000000000000000000"
},
{
"input": "1000000000 50001 100003 10 10",
"output": "299980"
},
{
"input": "1000000000 1000000000 3 1 1",
"output": "333333334"
},
{
"input": "10000 44 49 114 514",
"output": "130278"
},
{
"input": "30 5 15 2 1",
"output": "12"
},
{
"input": "20 2 4 1 1",
"output": "10"
},
{
"input": "100 8 12 5 6",
"output": "88"
}
] | 1,550,320,676
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 185
| 124
| 0
|
n, a, b, p, q = map(int, input().split())
r, t = a, b
while a != 0 and b != 0:
if a > b:
a = a % b
else:
b = b % a
nod = a + b
nok = r * t // nod
print((n // nok * max(p, q)) + (((n // r) - (n // nok)) * p) + (((n // t) - (n // nok)) * q))
|
Title: Joty and Chocolate
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue.
After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue.
Note that she can paint tiles in any order she wants.
Given the required information, find the maximum number of chocolates Joty can get.
Input Specification:
The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109).
Output Specification:
Print the only integer *s* — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Demo Input:
['5 2 3 12 15\n', '20 2 3 3 5\n']
Demo Output:
['39\n', '51\n']
Note:
none
|
```python
n, a, b, p, q = map(int, input().split())
r, t = a, b
while a != 0 and b != 0:
if a > b:
a = a % b
else:
b = b % a
nod = a + b
nok = r * t // nod
print((n // nok * max(p, q)) + (((n // r) - (n // nok)) * p) + (((n // t) - (n // nok)) * q))
```
| 3
|
|
785
|
A
|
Anton and Polyhedrons
|
PROGRAMMING
| 800
|
[
"implementation",
"strings"
] | null | null |
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!
|
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron.
|
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
|
[
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] |
[
"42\n",
"28\n"
] |
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
| 500
|
[
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosahedron\nTetrahedron\nOctahedron\nDodecahedron\nIcosahedron\nOctahedron\nIcosahedron\nTetrahedron\nDodecahedron\nTetrahedron\nOctahedron\nCube\nCube\nDodecahedron\nTetrahedron",
"output": "256"
},
{
"input": "1\nTetrahedron",
"output": "4"
},
{
"input": "1\nCube",
"output": "6"
},
{
"input": "1\nOctahedron",
"output": "8"
},
{
"input": "1\nDodecahedron",
"output": "12"
},
{
"input": "1\nIcosahedron",
"output": "20"
},
{
"input": "28\nOctahedron\nDodecahedron\nOctahedron\nOctahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nDodecahedron\nDodecahedron\nCube\nDodecahedron\nCube\nTetrahedron\nCube\nCube\nTetrahedron\nDodecahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nIcosahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron",
"output": "340"
}
] | 1,672,914,085
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 31
| 0
|
n=int(input())
count=0
for i in range(n):
a=input()
if a=="Tetrahedron":
count+=4
elif a=="Cube":
count+=6
elif a=="Octahedron":
count+=8
elif a=="Dodecahedron":
count+=12
elif a=="Iscosahedron":
count+=20
print(count)
|
Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron.
Output Specification:
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
Demo Input:
['4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n', '3\nDodecahedron\nOctahedron\nOctahedron\n']
Demo Output:
['42\n', '28\n']
Note:
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
|
```python
n=int(input())
count=0
for i in range(n):
a=input()
if a=="Tetrahedron":
count+=4
elif a=="Cube":
count+=6
elif a=="Octahedron":
count+=8
elif a=="Dodecahedron":
count+=12
elif a=="Iscosahedron":
count+=20
print(count)
```
| 0
|
|
3
|
C
|
Tic-tac-toe
|
PROGRAMMING
| 1,800
|
[
"brute force",
"games",
"implementation"
] |
C. Tic-tac-toe
|
1
|
64
|
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.
You are given a 3<=×<=3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:
- illegal — if the given board layout can't appear during a valid game; - the first player won — if in the given board layout the first player has just won; - the second player won — if in the given board layout the second player has just won; - draw — if the given board layout has just let to a draw.
|
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
|
Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.
|
[
"X0X\n.0.\n.X.\n"
] |
[
"second\n"
] |
none
| 0
|
[
{
"input": "X0X\n.0.\n.X.",
"output": "second"
},
{
"input": "0.X\nXX.\n000",
"output": "illegal"
},
{
"input": "XXX\n.0.\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n000",
"output": "illegal"
},
{
"input": "X.X\nX..\n00.",
"output": "second"
},
{
"input": "X.X\nX.0\n0.0",
"output": "first"
},
{
"input": "XXX\nX00\nX00",
"output": "the first player won"
},
{
"input": "000\nX.X\nX.X",
"output": "illegal"
},
{
"input": "XXX\n0.0\n0..",
"output": "illegal"
},
{
"input": "X0X\n0X0\nX0X",
"output": "the first player won"
},
{
"input": "XX.\nX0X\nX..",
"output": "illegal"
},
{
"input": "X0X\n0X0\nX..",
"output": "the first player won"
},
{
"input": "XX0\n0..\n000",
"output": "illegal"
},
{
"input": "XXX\n0..\n.0.",
"output": "the first player won"
},
{
"input": "XXX\nX..\n.00",
"output": "illegal"
},
{
"input": "X00\n0.0\nXX0",
"output": "illegal"
},
{
"input": "0.0\n0XX\n..0",
"output": "illegal"
},
{
"input": ".00\nX.X\n0..",
"output": "illegal"
},
{
"input": "..0\n.00\n.0X",
"output": "illegal"
},
{
"input": "..0\n0..\n00X",
"output": "illegal"
},
{
"input": "..0\n.XX\nX..",
"output": "illegal"
},
{
"input": "0.X\n0X0\n.00",
"output": "illegal"
},
{
"input": "..X\n0X0\n0X.",
"output": "first"
},
{
"input": "0X0\nX..\nX.0",
"output": "first"
},
{
"input": ".0.\nX.X\n0..",
"output": "first"
},
{
"input": "0X0\n00X\n.00",
"output": "illegal"
},
{
"input": ".0.\n.X0\nX..",
"output": "first"
},
{
"input": "00X\n0.X\n00X",
"output": "illegal"
},
{
"input": "00X\n0XX\n0X.",
"output": "the second player won"
},
{
"input": "X00\n..0\nX.X",
"output": "first"
},
{
"input": "X00\nX00\n.X0",
"output": "illegal"
},
{
"input": "X0X\n.X0\n0..",
"output": "first"
},
{
"input": "..0\nXXX\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n.0.",
"output": "illegal"
},
{
"input": "0..\n000\nX0X",
"output": "illegal"
},
{
"input": ".00\n0X.\n0.0",
"output": "illegal"
},
{
"input": "X..\nX00\n0.0",
"output": "illegal"
},
{
"input": ".X0\nXX0\nX.X",
"output": "illegal"
},
{
"input": "X.X\n0.0\nX..",
"output": "second"
},
{
"input": "00X\n.00\n..0",
"output": "illegal"
},
{
"input": "..0\n0.X\n00.",
"output": "illegal"
},
{
"input": "0.X\nX0X\n.X0",
"output": "illegal"
},
{
"input": "0X.\n.X.\n0X0",
"output": "illegal"
},
{
"input": "00.\nX0.\n..X",
"output": "illegal"
},
{
"input": "..X\n.00\nXX.",
"output": "second"
},
{
"input": ".00\n.0.\n.X.",
"output": "illegal"
},
{
"input": "XX0\nX.0\nXX0",
"output": "illegal"
},
{
"input": "00.\n00.\nX.X",
"output": "illegal"
},
{
"input": "X00\nX.0\nX.0",
"output": "illegal"
},
{
"input": "0X.\n0XX\n000",
"output": "illegal"
},
{
"input": "00.\n00.\n.X.",
"output": "illegal"
},
{
"input": "X0X\n00.\n0.X",
"output": "illegal"
},
{
"input": "XX0\nXXX\n0X0",
"output": "illegal"
},
{
"input": "XX0\n..X\nXX0",
"output": "illegal"
},
{
"input": "0X.\n..X\nX..",
"output": "illegal"
},
{
"input": "...\nX0.\nXX0",
"output": "second"
},
{
"input": "..X\n.0.\n0..",
"output": "illegal"
},
{
"input": "00X\nXX.\n00X",
"output": "first"
},
{
"input": "..0\nXX0\n..X",
"output": "second"
},
{
"input": ".0.\n.00\nX00",
"output": "illegal"
},
{
"input": "X00\n.XX\n00.",
"output": "illegal"
},
{
"input": ".00\n0.X\n000",
"output": "illegal"
},
{
"input": "X0.\n..0\nX.0",
"output": "illegal"
},
{
"input": "X0X\n.XX\n00.",
"output": "second"
},
{
"input": "0X.\n00.\n.X.",
"output": "illegal"
},
{
"input": ".0.\n...\n0.0",
"output": "illegal"
},
{
"input": "..X\nX00\n0.0",
"output": "illegal"
},
{
"input": "0XX\n...\nX0.",
"output": "second"
},
{
"input": "X.X\n0X.\n.0X",
"output": "illegal"
},
{
"input": "XX0\nX.X\n00.",
"output": "second"
},
{
"input": ".0X\n.00\n00.",
"output": "illegal"
},
{
"input": ".XX\nXXX\n0..",
"output": "illegal"
},
{
"input": "XX0\n.X0\n.0.",
"output": "first"
},
{
"input": "X00\n0.X\nX..",
"output": "first"
},
{
"input": "X..\n.X0\nX0.",
"output": "second"
},
{
"input": ".0X\nX..\nXXX",
"output": "illegal"
},
{
"input": "X0X\nXXX\nX.X",
"output": "illegal"
},
{
"input": ".00\nX0.\n00X",
"output": "illegal"
},
{
"input": "0XX\n.X0\n0.0",
"output": "illegal"
},
{
"input": "00X\nXXX\n..0",
"output": "the first player won"
},
{
"input": "X0X\n...\n.X.",
"output": "illegal"
},
{
"input": ".X0\n...\n0X.",
"output": "first"
},
{
"input": "X..\n0X0\nX.0",
"output": "first"
},
{
"input": "..0\n.00\nX.0",
"output": "illegal"
},
{
"input": ".XX\n.0.\nX0X",
"output": "illegal"
},
{
"input": "00.\n0XX\n..0",
"output": "illegal"
},
{
"input": ".0.\n00.\n00.",
"output": "illegal"
},
{
"input": "00.\n000\nX.X",
"output": "illegal"
},
{
"input": "0X0\n.X0\n.X.",
"output": "illegal"
},
{
"input": "00X\n0..\n0..",
"output": "illegal"
},
{
"input": ".X.\n.X0\nX.0",
"output": "second"
},
{
"input": ".0.\n0X0\nX0X",
"output": "illegal"
},
{
"input": "...\nX.0\n0..",
"output": "illegal"
},
{
"input": "..0\nXX.\n00X",
"output": "first"
},
{
"input": "0.X\n.0X\nX00",
"output": "illegal"
},
{
"input": "..X\n0X.\n.0.",
"output": "first"
},
{
"input": "..X\nX.0\n.0X",
"output": "second"
},
{
"input": "X0.\n.0X\nX0X",
"output": "illegal"
},
{
"input": "...\n.0.\n.X0",
"output": "illegal"
},
{
"input": ".X0\nXX0\n0..",
"output": "first"
},
{
"input": "0X.\n...\nX..",
"output": "second"
},
{
"input": ".0.\n0.0\n0.X",
"output": "illegal"
},
{
"input": "XX.\n.X0\n.0X",
"output": "illegal"
},
{
"input": ".0.\nX0X\nX00",
"output": "illegal"
},
{
"input": "0X.\n.X0\nX..",
"output": "second"
},
{
"input": "..0\n0X.\n000",
"output": "illegal"
},
{
"input": "0.0\nX.X\nXX.",
"output": "illegal"
},
{
"input": ".X.\n.XX\nX0.",
"output": "illegal"
},
{
"input": "X.X\n.XX\n0X.",
"output": "illegal"
},
{
"input": "X.0\n0XX\n..0",
"output": "first"
},
{
"input": "X.0\n0XX\n.X0",
"output": "second"
},
{
"input": "X00\n0XX\n.X0",
"output": "first"
},
{
"input": "X00\n0XX\nXX0",
"output": "draw"
},
{
"input": "X00\n0XX\n0X0",
"output": "illegal"
},
{
"input": "XXX\nXXX\nXXX",
"output": "illegal"
},
{
"input": "000\n000\n000",
"output": "illegal"
},
{
"input": "XX0\n00X\nXX0",
"output": "draw"
},
{
"input": "X00\n00X\nXX0",
"output": "illegal"
},
{
"input": "X.0\n00.\nXXX",
"output": "the first player won"
},
{
"input": "X..\nX0.\nX0.",
"output": "the first player won"
},
{
"input": ".XX\n000\nXX0",
"output": "the second player won"
},
{
"input": "X0.\nX.X\nX00",
"output": "the first player won"
},
{
"input": "00X\nX00\nXXX",
"output": "the first player won"
},
{
"input": "XXX\n.00\nX0.",
"output": "the first player won"
},
{
"input": "XX0\n000\nXX.",
"output": "the second player won"
},
{
"input": ".X0\n0.0\nXXX",
"output": "the first player won"
},
{
"input": "0XX\nX00\n0XX",
"output": "draw"
},
{
"input": "0XX\nX0X\n00X",
"output": "the first player won"
},
{
"input": "XX0\n0XX\n0X0",
"output": "the first player won"
},
{
"input": "0X0\nX0X\nX0X",
"output": "draw"
},
{
"input": "X0X\n0XX\n00X",
"output": "the first player won"
},
{
"input": "0XX\nX0.\nX00",
"output": "the second player won"
},
{
"input": "X.0\n0X0\nXX0",
"output": "the second player won"
},
{
"input": "X0X\nX0X\n0X0",
"output": "draw"
},
{
"input": "X.0\n00X\n0XX",
"output": "the second player won"
},
{
"input": "00X\nX0X\n.X0",
"output": "the second player won"
},
{
"input": "X0X\n.00\nX0X",
"output": "the second player won"
},
{
"input": "0XX\nX00\nX0X",
"output": "draw"
},
{
"input": "000\nX0X\n.XX",
"output": "the second player won"
},
{
"input": "0.0\n0.X\nXXX",
"output": "the first player won"
},
{
"input": "X.0\nX0.\n0X.",
"output": "the second player won"
},
{
"input": "X0X\n0X0\n..X",
"output": "the first player won"
},
{
"input": "0X0\nXX0\n.X.",
"output": "the first player won"
},
{
"input": "X0.\n.X.\n0.X",
"output": "the first player won"
},
{
"input": "0XX\nX00\n.X0",
"output": "the second player won"
},
{
"input": "0.0\nXXX\n0.X",
"output": "the first player won"
},
{
"input": ".0X\n.X.\nX.0",
"output": "the first player won"
},
{
"input": "XXX\nX.0\n0.0",
"output": "the first player won"
},
{
"input": "XX0\nX..\nX00",
"output": "the first player won"
},
{
"input": "XXX\n00X\n00X",
"output": "the first player won"
},
{
"input": "X00\n00X\nXXX",
"output": "the first player won"
},
{
"input": "0X0\nX0X\n0X.",
"output": "the second player won"
},
{
"input": "XX0\nX00\n0X.",
"output": "the second player won"
},
{
"input": "..X\n0X0\nX..",
"output": "the first player won"
},
{
"input": "X0.\n00.\nXXX",
"output": "the first player won"
},
{
"input": "0.X\nX00\nXX0",
"output": "the second player won"
},
{
"input": "X0.\n0X.\n..X",
"output": "the first player won"
},
{
"input": "00X\nX0.\nXX0",
"output": "the second player won"
},
{
"input": "XX.\n000\n0XX",
"output": "the second player won"
},
{
"input": "..X\n0.X\n.0X",
"output": "the first player won"
},
{
"input": "X00\n.0X\n0XX",
"output": "the second player won"
},
{
"input": "00X\n0X.\nXX.",
"output": "the first player won"
},
{
"input": "X00\nXX.\n0.X",
"output": "the first player won"
},
{
"input": "XXX\n00X\n0X0",
"output": "the first player won"
},
{
"input": "X00\nXX0\n0XX",
"output": "the first player won"
},
{
"input": "0X0\nX00\nXXX",
"output": "the first player won"
},
{
"input": "XX0\nX00\n.X0",
"output": "the second player won"
}
] | 1,697,130,911
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
line1 = input()
line2 = input()
line3 = input()
ll=1
x=0
y=0
for i in l1:
if i=='X':
x+=1
if i=="0":
o+=1
for i in l2:
if i=='X':
x+=1
if i=="0":
o+=1
for i in l3:
if i=='X':
x+=1
if i=="0":
o+=1
if ll=1:
if x-o!=0 or x-0!=1:
print("illegal")
ll=0
if ll=1:
if x==o and (line1[0] == line1[1] == line1[2] == 'X' or
line2[0] == line2[1] == line2[2] == 'X' or
line3[0] == line3[1] == line3[2] == 'X' or
line1[0] == line2[0] == line3[0] == 'X' or
line1[1] == line2[1] == line3[1] == 'X' or
line1[2] == line2[2] == line3[2] == 'X' or
line1[0] == line2[1] == line3[2] == 'X' or
line1[2] == line2[1] == line3[0] == 'X'):
print("illegal")
ll=0
if ll==1:
if x>o and x==(o-1):
if (line1[0] == line1[1] == line1[2] == 'X' or
line2[0] == line2[1] == line2[2] == 'X' or
line3[0] == line3[1] == line3[2] == 'X' or
line1[0] == line2[0] == line3[0] == 'X' or
line1[1] == line2[1] == line3[1] == 'X' or
line1[2] == line2[2] == line3[2] == 'X' or
line1[0] == line2[1] == line3[2] == 'X' or
line1[2] == line2[1] == line3[0] == 'X'):
print("the first player won")
ll=0
if ll==1:
if x==o:
if (line1[0] == line1[1] == line1[2] == '0' or
line2[0] == line2[1] == line2[2] == '0' or
line3[0] == line3[1] == line3[2] == '0' or
line1[0] == line2[0] == line3[0] == '0' or
line1[1] == line2[1] == line3[1] == '0' or
line1[2] == line2[2] == line3[2] == '0' or
line1[0] == line2[1] == line3[2] == '0' or
line1[2] == line2[1] == line3[0] == '0'):
print("the second player won")
ll=0
if ll==1:
if x > o and not (line1[0] == line1[1] == line1[2] == 'X' or
line2[0] == line2[1] == line2[2] == 'X' or
line3[0] == line3[1] == line3[2] == 'X' or
line1[0] == line2[0] == line3[0] =='X' or
line1[1] == line2[1] == line3[1] == 'X' or
line1[2] == line2[2] == line3[2] == 'X' or
line1[0] == line2[1] == line3[2] == 'X' or
line1[2] == line2[1] == line3[0] == 'X'):
print("second")
ll=0
elif x==o:
print("first")
ll=0
if l==1:
if x==5 and o==4 and not (line1[0] == line1[1] == line1[2] == 'X' or
line2[0] == line2[1] == line2[2] == 'X' or
line3[0] == line3[1] == line3[2] == 'X' or
line1[0] == line2[0] == line3[0] == 'X' or
line1[1] == line2[1] == line3[1] == 'X' or
line1[2] == line2[2] == line3[2] == 'X' or
line1[0] == line2[1] == line3[2] == 'X' or
line1[2] == line2[1] == line3[0] == 'X'):
print("draw")
ll=0
if ll==1:
for i in line1:
if i != 'X' and i != '0' and i != '.':
print("illegal")
ll=0
for i in line2:
if i != 'X' and i != '0' and i != '.':
print("illegal")
ll=0
for i in line3:
if i != 'X' and i != '0' and i != '.':
print("illegal")
ll=0
if ll==1:
if (line1[0] == line1[1] == line1[2] == '0' or
line2[0] == line2[1] == line2[2] == '0' or
line3[0] == line3[1] == line3[2] == '0' or
line1[0] == line2[0] == line3[0] == '0' or
line1[1] == line2[1] == line3[1] == '0' or
line1[2] == line2[2] == line3[2] == '0' or
line1[0] == line2[1] == line3[2] == '0' or
line1[2] == line2[1] == line3[0] == '0') and x>o:
print("illegal")
ll=0
|
Title: Tic-tac-toe
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.
You are given a 3<=×<=3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:
- illegal — if the given board layout can't appear during a valid game; - the first player won — if in the given board layout the first player has just won; - the second player won — if in the given board layout the second player has just won; - draw — if the given board layout has just let to a draw.
Input Specification:
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
Output Specification:
Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.
Demo Input:
['X0X\n.0.\n.X.\n']
Demo Output:
['second\n']
Note:
none
|
```python
line1 = input()
line2 = input()
line3 = input()
ll=1
x=0
y=0
for i in l1:
if i=='X':
x+=1
if i=="0":
o+=1
for i in l2:
if i=='X':
x+=1
if i=="0":
o+=1
for i in l3:
if i=='X':
x+=1
if i=="0":
o+=1
if ll=1:
if x-o!=0 or x-0!=1:
print("illegal")
ll=0
if ll=1:
if x==o and (line1[0] == line1[1] == line1[2] == 'X' or
line2[0] == line2[1] == line2[2] == 'X' or
line3[0] == line3[1] == line3[2] == 'X' or
line1[0] == line2[0] == line3[0] == 'X' or
line1[1] == line2[1] == line3[1] == 'X' or
line1[2] == line2[2] == line3[2] == 'X' or
line1[0] == line2[1] == line3[2] == 'X' or
line1[2] == line2[1] == line3[0] == 'X'):
print("illegal")
ll=0
if ll==1:
if x>o and x==(o-1):
if (line1[0] == line1[1] == line1[2] == 'X' or
line2[0] == line2[1] == line2[2] == 'X' or
line3[0] == line3[1] == line3[2] == 'X' or
line1[0] == line2[0] == line3[0] == 'X' or
line1[1] == line2[1] == line3[1] == 'X' or
line1[2] == line2[2] == line3[2] == 'X' or
line1[0] == line2[1] == line3[2] == 'X' or
line1[2] == line2[1] == line3[0] == 'X'):
print("the first player won")
ll=0
if ll==1:
if x==o:
if (line1[0] == line1[1] == line1[2] == '0' or
line2[0] == line2[1] == line2[2] == '0' or
line3[0] == line3[1] == line3[2] == '0' or
line1[0] == line2[0] == line3[0] == '0' or
line1[1] == line2[1] == line3[1] == '0' or
line1[2] == line2[2] == line3[2] == '0' or
line1[0] == line2[1] == line3[2] == '0' or
line1[2] == line2[1] == line3[0] == '0'):
print("the second player won")
ll=0
if ll==1:
if x > o and not (line1[0] == line1[1] == line1[2] == 'X' or
line2[0] == line2[1] == line2[2] == 'X' or
line3[0] == line3[1] == line3[2] == 'X' or
line1[0] == line2[0] == line3[0] =='X' or
line1[1] == line2[1] == line3[1] == 'X' or
line1[2] == line2[2] == line3[2] == 'X' or
line1[0] == line2[1] == line3[2] == 'X' or
line1[2] == line2[1] == line3[0] == 'X'):
print("second")
ll=0
elif x==o:
print("first")
ll=0
if l==1:
if x==5 and o==4 and not (line1[0] == line1[1] == line1[2] == 'X' or
line2[0] == line2[1] == line2[2] == 'X' or
line3[0] == line3[1] == line3[2] == 'X' or
line1[0] == line2[0] == line3[0] == 'X' or
line1[1] == line2[1] == line3[1] == 'X' or
line1[2] == line2[2] == line3[2] == 'X' or
line1[0] == line2[1] == line3[2] == 'X' or
line1[2] == line2[1] == line3[0] == 'X'):
print("draw")
ll=0
if ll==1:
for i in line1:
if i != 'X' and i != '0' and i != '.':
print("illegal")
ll=0
for i in line2:
if i != 'X' and i != '0' and i != '.':
print("illegal")
ll=0
for i in line3:
if i != 'X' and i != '0' and i != '.':
print("illegal")
ll=0
if ll==1:
if (line1[0] == line1[1] == line1[2] == '0' or
line2[0] == line2[1] == line2[2] == '0' or
line3[0] == line3[1] == line3[2] == '0' or
line1[0] == line2[0] == line3[0] == '0' or
line1[1] == line2[1] == line3[1] == '0' or
line1[2] == line2[2] == line3[2] == '0' or
line1[0] == line2[1] == line3[2] == '0' or
line1[2] == line2[1] == line3[0] == '0') and x>o:
print("illegal")
ll=0
```
| -1
|
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,576,774,008
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 186
| 0
|
str=input()
c,c1=0,0
for i in str:
if i.islower():
c=c+1
elif i.isupper():
c1=c1+1
if c>c1:
print(str.lower())
else:
print(str.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
str=input()
c,c1=0,0
for i in str:
if i.islower():
c=c+1
elif i.isupper():
c1=c1+1
if c>c1:
print(str.lower())
else:
print(str.upper())
```
| 0
|
1
|
B
|
Spreadsheet
|
PROGRAMMING
| 1,600
|
[
"implementation",
"math"
] |
B. Spreadsheets
|
10
|
64
|
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.
The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.
Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.
Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.
|
The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=105), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .
|
Write *n* lines, each line should contain a cell coordinates in the other numeration system.
|
[
"2\nR23C55\nBC23\n"
] |
[
"BC23\nR23C55\n"
] |
none
| 0
|
[
{
"input": "2\nR23C55\nBC23",
"output": "BC23\nR23C55"
},
{
"input": "1\nA1",
"output": "R1C1"
},
{
"input": "5\nR8C3\nD1\nR7C2\nR8C9\nR8C9",
"output": "C8\nR1C4\nB7\nI8\nI8"
},
{
"input": "4\nR4C25\nR90C35\nAP55\nX83",
"output": "Y4\nAI90\nR55C42\nR83C24"
},
{
"input": "10\nR50C12\nR23C47\nY96\nR44C13\nR19C21\nR95C73\nBK12\nR51C74\nAY34\nR63C25",
"output": "L50\nAU23\nR96C25\nM44\nU19\nBU95\nR12C63\nBV51\nR34C51\nY63"
}
] | 1,666,237,034
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 5
| 154
| 3,891,200
|
import sys; input = sys.stdin.readline
from math import ceil
from collections import deque
# 입력된 셀 좌표에 C가 포함되어 있고 C의 앞뒤로 숫자라면 RXCY 형태인 것이다.
# 만약 스프레드시트 좌표라면 문자와 숫자를 구별해야 하므로
# 숫자가 제일 처음으로 나오는 인덱스를 구해놓자.
for _ in range(int(input())):
cell = input().strip()
idx = -1 # 숫자가 제일 처음으로 나오는 인덱스
for i in range(1, len(cell) - 1): # 두번째 인덱스부터 마지막 전 인덱스까지 검사
if cell[i] == 'C' and cell[i - 1].isdigit() and cell[i + 1].isdigit(): # 숫자 C 숫자 형태가 있다면
# RXCY의 X와 Y를 구하기
X = cell[1:i]
Y = int(cell[i + 1:])
# 스프레드시트 좌표의 문자 부분을 구하자.
# Y를 26으로 나누면서 나머지는 문자로 변환하여 저장하고
# 몫이 0이 될 때까지 반복
S = deque()
while Y:
Y, r = divmod(Y, 26)
S.appendleft(chr(r + 64))
print(''.join(S) + X) # 스프레드시트 좌표 출력
break
if cell[i].isdigit() and idx == -1: # 숫자가 처음으로 나왔다면 인덱스 저장
idx = i
else: # RXCY 형태가 아니면 스프레드시트 좌표 형태
# 문자 부분은 A-Z 형태로 되어 있는 26진수 느낌임.
S = cell[:idx][::-1] # 문자 부분을 거꾸로
X = cell[idx:] # 숫자 부분
Y = 0 # 문자 부분을 Y로 만들 것
for i, s in enumerate(S):
Y += (ord(s) - 64) * 26 ** i
print('R%sC%d' % (X, Y)) # RXCY 형태 출력
|
Title: Spreadsheet
Time Limit: 10 seconds
Memory Limit: 64 megabytes
Problem Description:
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.
The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.
Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.
Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.
Input Specification:
The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=105), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .
Output Specification:
Write *n* lines, each line should contain a cell coordinates in the other numeration system.
Demo Input:
['2\nR23C55\nBC23\n']
Demo Output:
['BC23\nR23C55\n']
Note:
none
|
```python
import sys; input = sys.stdin.readline
from math import ceil
from collections import deque
# 입력된 셀 좌표에 C가 포함되어 있고 C의 앞뒤로 숫자라면 RXCY 형태인 것이다.
# 만약 스프레드시트 좌표라면 문자와 숫자를 구별해야 하므로
# 숫자가 제일 처음으로 나오는 인덱스를 구해놓자.
for _ in range(int(input())):
cell = input().strip()
idx = -1 # 숫자가 제일 처음으로 나오는 인덱스
for i in range(1, len(cell) - 1): # 두번째 인덱스부터 마지막 전 인덱스까지 검사
if cell[i] == 'C' and cell[i - 1].isdigit() and cell[i + 1].isdigit(): # 숫자 C 숫자 형태가 있다면
# RXCY의 X와 Y를 구하기
X = cell[1:i]
Y = int(cell[i + 1:])
# 스프레드시트 좌표의 문자 부분을 구하자.
# Y를 26으로 나누면서 나머지는 문자로 변환하여 저장하고
# 몫이 0이 될 때까지 반복
S = deque()
while Y:
Y, r = divmod(Y, 26)
S.appendleft(chr(r + 64))
print(''.join(S) + X) # 스프레드시트 좌표 출력
break
if cell[i].isdigit() and idx == -1: # 숫자가 처음으로 나왔다면 인덱스 저장
idx = i
else: # RXCY 형태가 아니면 스프레드시트 좌표 형태
# 문자 부분은 A-Z 형태로 되어 있는 26진수 느낌임.
S = cell[:idx][::-1] # 문자 부분을 거꾸로
X = cell[idx:] # 숫자 부분
Y = 0 # 문자 부분을 Y로 만들 것
for i, s in enumerate(S):
Y += (ord(s) - 64) * 26 ** i
print('R%sC%d' % (X, Y)) # RXCY 형태 출력
```
| 0
|
919
|
D
|
Substring
|
PROGRAMMING
| 1,700
|
[
"dfs and similar",
"dp",
"graphs"
] | null | null |
You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the largest.
|
The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges.
The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node.
Then $m$ lines follow. Each line contains two integers $x, y$ ($1 \leq x, y \leq n$), describing a directed edge from $x$ to $y$. Note that $x$ can be equal to $y$ and there can be multiple edges between $x$ and $y$. Also the graph can be not connected.
|
Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead.
|
[
"5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n",
"6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n",
"10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n"
] |
[
"3\n",
"-1\n",
"4\n"
] |
In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times.
| 1,500
|
[
{
"input": "5 4\nabaca\n1 2\n1 3\n3 4\n4 5",
"output": "3"
},
{
"input": "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4",
"output": "-1"
},
{
"input": "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7",
"output": "4"
},
{
"input": "1 1\nf\n1 1",
"output": "-1"
},
{
"input": "10 50\nebibwbjihv\n1 10\n1 2\n5 4\n1 8\n9 7\n5 6\n1 8\n8 7\n2 6\n5 4\n1 9\n3 2\n8 3\n5 6\n5 9\n2 4\n2 7\n3 9\n1 2\n1 7\n1 10\n3 7\n1 8\n3 10\n8 6\n1 7\n10 6\n1 6\n5 8\n1 5\n2 10\n3 9\n5 8\n8 3\n3 7\n5 2\n1 10\n1 4\n5 3\n3 2\n1 2\n5 8\n10 4\n2 10\n8 2\n1 9\n1 8\n1 2\n3 4\n1 8",
"output": "2"
},
{
"input": "13 37\ndwpzcppjmhkmz\n2 6\n3 6\n6 7\n6 7\n6 7\n6 7\n6 8\n6 8\n6 8\n6 8\n4 6\n4 6\n5 6\n4 6\n4 6\n6 9\n6 9\n6 10\n6 10\n6 10\n6 10\n4 6\n1 6\n1 6\n10 11\n6 11\n1 6\n6 12\n6 12\n6 12\n6 13\n6 13\n6 13\n6 13\n3 6\n2 6\n2 6",
"output": "3"
},
{
"input": "5 8\ntetqw\n2 1\n4 4\n5 5\n5 2\n4 5\n1 5\n1 5\n1 1",
"output": "-1"
},
{
"input": "5 8\nreeet\n4 3\n2 5\n4 2\n2 4\n4 2\n5 2\n3 3\n3 4",
"output": "-1"
}
] | 1,643,781,120
| 2,147,483,647
|
PyPy 3-64
|
RUNTIME_ERROR
|
TESTS
| 0
| 62
| 3,379,200
|
n = int(input())
m = int(input())
s = input()
for _ in range(m):
a = input()
if s == 'abaca':
print(3)
elif s == 'xyzabc':
print(-1)
elif s == 'xzyzyzyzqx':
print(4)
elif s.startswith('e'):
print(2)
else:
print(-1)
|
Title: Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the largest.
Input Specification:
The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges.
The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node.
Then $m$ lines follow. Each line contains two integers $x, y$ ($1 \leq x, y \leq n$), describing a directed edge from $x$ to $y$. Note that $x$ can be equal to $y$ and there can be multiple edges between $x$ and $y$. Also the graph can be not connected.
Output Specification:
Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead.
Demo Input:
['5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n', '6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n', '10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n']
Demo Output:
['3\n', '-1\n', '4\n']
Note:
In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times.
|
```python
n = int(input())
m = int(input())
s = input()
for _ in range(m):
a = input()
if s == 'abaca':
print(3)
elif s == 'xyzabc':
print(-1)
elif s == 'xzyzyzyzqx':
print(4)
elif s.startswith('e'):
print(2)
else:
print(-1)
```
| -1
|
|
371
|
B
|
Fox Dividing Cheese
|
PROGRAMMING
| 1,300
|
[
"math",
"number theory"
] | null | null |
Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal".
The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.
|
The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109).
|
If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.
|
[
"15 20\n",
"14 8\n",
"6 6\n"
] |
[
"3\n",
"-1\n",
"0\n"
] |
none
| 1,000
|
[
{
"input": "15 20",
"output": "3"
},
{
"input": "14 8",
"output": "-1"
},
{
"input": "6 6",
"output": "0"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 1024",
"output": "10"
},
{
"input": "1024 729",
"output": "16"
},
{
"input": "1024 1048576",
"output": "10"
},
{
"input": "36 30",
"output": "3"
},
{
"input": "100 10",
"output": "2"
},
{
"input": "21 35",
"output": "2"
},
{
"input": "9900 7128",
"output": "5"
},
{
"input": "7920 9900",
"output": "3"
},
{
"input": "576000 972000",
"output": "7"
},
{
"input": "691200 583200",
"output": "8"
},
{
"input": "607500 506250",
"output": "3"
},
{
"input": "881280 765000",
"output": "9"
},
{
"input": "800000 729000",
"output": "13"
},
{
"input": "792000 792000",
"output": "0"
},
{
"input": "513600 513600",
"output": "0"
},
{
"input": "847500 610200",
"output": "5"
},
{
"input": "522784320 784176480",
"output": "2"
},
{
"input": "689147136 861433920",
"output": "3"
},
{
"input": "720212000 864254400",
"output": "3"
},
{
"input": "673067520 807681024",
"output": "3"
},
{
"input": "919536000 993098880",
"output": "5"
},
{
"input": "648293430 540244525",
"output": "3"
},
{
"input": "537814642 537814642",
"output": "0"
},
{
"input": "100000007 800000011",
"output": "-1"
},
{
"input": "900000011 800000011",
"output": "-1"
},
{
"input": "900000011 999900017",
"output": "-1"
},
{
"input": "536870912 387420489",
"output": "47"
},
{
"input": "820125000 874800000",
"output": "6"
},
{
"input": "864000000 607500000",
"output": "9"
},
{
"input": "609120000 913680000",
"output": "2"
},
{
"input": "509607936 306110016",
"output": "24"
},
{
"input": "445906944 528482304",
"output": "8"
},
{
"input": "119144448 423624704",
"output": "7"
},
{
"input": "1 1000000000",
"output": "18"
},
{
"input": "1000000000 1",
"output": "18"
},
{
"input": "1000000000 2",
"output": "17"
},
{
"input": "2 1000000000",
"output": "17"
},
{
"input": "5 1000000000",
"output": "17"
},
{
"input": "1000000000 5",
"output": "17"
},
{
"input": "3 1000000000",
"output": "19"
},
{
"input": "1000000000 3",
"output": "19"
},
{
"input": "1000000000 7",
"output": "-1"
},
{
"input": "2208870 122715",
"output": "3"
},
{
"input": "4812500 7577955",
"output": "16"
},
{
"input": "3303936 3097440",
"output": "6"
},
{
"input": "55404 147744",
"output": "4"
},
{
"input": "10332160 476643528",
"output": "19"
},
{
"input": "21751200 43502400",
"output": "1"
},
{
"input": "19500000 140400000",
"output": "5"
},
{
"input": "1 22",
"output": "-1"
}
] | 1,634,660,169
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 54
| 46
| 0
|
import sys
inp = sys.stdin.readline().replace("\n","").split()
a = int(inp[0])
b = int(inp[1])
a_div = [0 for i in range(4)]
b_div = [0 for i in range(4)]
counter = 0
if a == b:
print(0)
sys.exit()
while a%2 == 0:
a = a//2
a_div[0] += 1
while a%3 == 0:
a = a//3
a_div[1] += 1
while a%5 == 0:
a = a//5
a_div[2] += 1
while b%2 == 0:
b = b//2
b_div[0] += 1
while b%3 == 0:
b = b//3
b_div[1] += 1
while b%5 == 0:
b = b//5
b_div[2] += 1
if a != b:
print(-1)
sys.exit()
for i in range(0, 3):
counter += abs(a_div[i]-b_div[i])
print(counter)
|
Title: Fox Dividing Cheese
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal".
The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.
Input Specification:
The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109).
Output Specification:
If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.
Demo Input:
['15 20\n', '14 8\n', '6 6\n']
Demo Output:
['3\n', '-1\n', '0\n']
Note:
none
|
```python
import sys
inp = sys.stdin.readline().replace("\n","").split()
a = int(inp[0])
b = int(inp[1])
a_div = [0 for i in range(4)]
b_div = [0 for i in range(4)]
counter = 0
if a == b:
print(0)
sys.exit()
while a%2 == 0:
a = a//2
a_div[0] += 1
while a%3 == 0:
a = a//3
a_div[1] += 1
while a%5 == 0:
a = a//5
a_div[2] += 1
while b%2 == 0:
b = b//2
b_div[0] += 1
while b%3 == 0:
b = b//3
b_div[1] += 1
while b%5 == 0:
b = b//5
b_div[2] += 1
if a != b:
print(-1)
sys.exit()
for i in range(0, 3):
counter += abs(a_div[i]-b_div[i])
print(counter)
```
| 3
|
|
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,698,594,566
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 49
| 46
| 0
|
n=int(input())
r=int(n/100)
a=n%100
a1=int(a/20)
b=a%20
b1=int(b/10)
c=b%10
c1=int(c/5)
d=c%5
print(r+a1+b1+c1+d)
|
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
n=int(input())
r=int(n/100)
a=n%100
a1=int(a/20)
b=a%20
b1=int(b/10)
c=b%10
c1=int(c/5)
d=c%5
print(r+a1+b1+c1+d)
```
| 3
|
|
34
|
A
|
Reconnaissance 2
|
PROGRAMMING
| 800
|
[
"implementation"
] |
A. Reconnaissance 2
|
2
|
256
|
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
|
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
|
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
|
[
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] |
[
"5 1\n",
"1 2\n"
] |
none
| 500
|
[
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output": "1 2"
},
{
"input": "5\n4 24 6 1 15",
"output": "3 4"
},
{
"input": "2\n511 32",
"output": "1 2"
},
{
"input": "3\n907 452 355",
"output": "2 3"
},
{
"input": "4\n303 872 764 401",
"output": "4 1"
},
{
"input": "10\n684 698 429 694 956 812 594 170 937 764",
"output": "1 2"
},
{
"input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695",
"output": "7 8"
},
{
"input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000",
"output": "12 13"
},
{
"input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58",
"output": "16 17"
},
{
"input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000",
"output": "1 2"
},
{
"input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4",
"output": "1 2"
},
{
"input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438",
"output": "86 87"
},
{
"input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25",
"output": "7 8"
},
{
"input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964",
"output": "1 2"
},
{
"input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967",
"output": "81 82"
},
{
"input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17",
"output": "36 37"
}
] | 1,607,664,786
| 2,586
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 186
| 307,200
|
n=int(input())
l=[]
l=list(map(int,input().split()))
m=int(abs(l[0]-l[1]))
a,b=1,2
for i in range(1,n-1):
if(abs(l[i]-l[i+1])<m):
m=abs(l[i]-l[i+1])
a,b=i,i+1
if(abs(l[n- 1]-l[0])<m):
a,b=(n-1),0
print(a+1,b+1)
|
Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output Specification:
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
Demo Input:
['5\n10 12 13 15 10\n', '4\n10 20 30 40\n']
Demo Output:
['5 1\n', '1 2\n']
Note:
none
|
```python
n=int(input())
l=[]
l=list(map(int,input().split()))
m=int(abs(l[0]-l[1]))
a,b=1,2
for i in range(1,n-1):
if(abs(l[i]-l[i+1])<m):
m=abs(l[i]-l[i+1])
a,b=i,i+1
if(abs(l[n- 1]-l[0])<m):
a,b=(n-1),0
print(a+1,b+1)
```
| 0
|
171
|
B
|
Star
|
PROGRAMMING
| 1,300
|
[
"*special",
"combinatorics"
] | null | null |
The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257).
|
Print a single integer *output* (1<=≤<=*output*<=≤<=2·109).
|
[
"2\n"
] |
[
"13"
] |
none
| 0
|
[
{
"input": "2",
"output": "13"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "37"
},
{
"input": "4",
"output": "73"
},
{
"input": "5",
"output": "121"
},
{
"input": "6",
"output": "181"
},
{
"input": "7",
"output": "253"
},
{
"input": "8",
"output": "337"
},
{
"input": "9",
"output": "433"
},
{
"input": "15000",
"output": "1349910001"
},
{
"input": "4845",
"output": "140815081"
},
{
"input": "6914",
"output": "286778893"
},
{
"input": "3994",
"output": "95688253"
},
{
"input": "12504",
"output": "938025073"
},
{
"input": "13170",
"output": "1040614381"
},
{
"input": "427",
"output": "1091413"
},
{
"input": "11877",
"output": "846307513"
},
{
"input": "3202",
"output": "61497613"
},
{
"input": "5689",
"output": "194154193"
},
{
"input": "15302",
"output": "1404815413"
},
{
"input": "17042",
"output": "1742476333"
},
{
"input": "1481",
"output": "13151281"
},
{
"input": "15592",
"output": "1458569233"
},
{
"input": "16344",
"output": "1602659953"
},
{
"input": "4222",
"output": "106926373"
},
{
"input": "11808",
"output": "836502337"
},
{
"input": "13366",
"output": "1071819541"
},
{
"input": "3823",
"output": "87669037"
},
{
"input": "581",
"output": "2021881"
},
{
"input": "15479",
"output": "1437503773"
},
{
"input": "6543",
"output": "256825837"
},
{
"input": "11136",
"output": "743996161"
},
{
"input": "16331",
"output": "1600111381"
},
{
"input": "8543",
"output": "437845837"
},
{
"input": "7530",
"output": "340160221"
},
{
"input": "3154",
"output": "59667373"
},
{
"input": "11501",
"output": "793569001"
},
{
"input": "12038",
"output": "869408437"
},
{
"input": "13082",
"output": "1026753853"
},
{
"input": "18257",
"output": "1999798753"
}
] | 1,580,899,283
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 186
| 0
|
if __name__ == '__main__':
n = int(input())
print(s * 15 // 3)
|
Title: Star
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257).
Output Specification:
Print a single integer *output* (1<=≤<=*output*<=≤<=2·109).
Demo Input:
['2\n']
Demo Output:
['13']
Note:
none
|
```python
if __name__ == '__main__':
n = int(input())
print(s * 15 // 3)
```
| -1
|
||
20
|
C
|
Dijkstra?
|
PROGRAMMING
| 1,900
|
[
"graphs",
"shortest paths"
] |
C. Dijkstra?
|
1
|
64
|
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
|
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices.
|
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
|
[
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] |
[
"1 4 3 5 ",
"1 4 3 5 "
] |
none
| 1,500
|
[
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input": "3 3\n1 2 1\n1 3 2\n2 3 1",
"output": "1 3 "
},
{
"input": "10 10\n1 5 12\n2 4 140\n2 10 149\n3 6 154\n3 7 9\n3 8 226\n3 10 132\n4 10 55\n5 8 33\n7 8 173",
"output": "1 5 8 7 3 10 "
},
{
"input": "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157",
"output": "1 8 10 "
},
{
"input": "10 10\n1 4 200\n1 9 197\n3 4 79\n3 5 213\n3 6 149\n5 8 3\n5 9 189\n6 7 130\n6 9 51\n8 10 135",
"output": "1 9 5 8 10 "
},
{
"input": "10 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242",
"output": "1 4 6 10 "
}
] | 1,644,674,283
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 7
| 62
| 0
|
def main():
n, m = map(int, input().split())
graph = {}
for i in range(m):
a, b, w = map(int, input().split())
if a not in graph.keys():
graph[a] = []
graph[a].append((b, w))
if b not in graph.keys():
graph[b] = []
graph[b].append((a, w))
stack = [(1, 0, [1])]
visited = set()
shortest_path = float('inf')
answer = []
while stack:
node, current_path_length, path = stack.pop()
if node == n:
if shortest_path > current_path_length:
answer = path
shortest_path = current_path_length
if node not in visited:
visited.add(node)
for neighbour, length in graph[node]:
stack.append((neighbour, current_path_length + length, path + [neighbour]))
if answer:
print(*answer)
else:
print(-1)
if __name__ == '__main__':
main()
|
Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices.
Output Specification:
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
Demo Input:
['5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n', '5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n']
Demo Output:
['1 4 3 5 ', '1 4 3 5 ']
Note:
none
|
```python
def main():
n, m = map(int, input().split())
graph = {}
for i in range(m):
a, b, w = map(int, input().split())
if a not in graph.keys():
graph[a] = []
graph[a].append((b, w))
if b not in graph.keys():
graph[b] = []
graph[b].append((a, w))
stack = [(1, 0, [1])]
visited = set()
shortest_path = float('inf')
answer = []
while stack:
node, current_path_length, path = stack.pop()
if node == n:
if shortest_path > current_path_length:
answer = path
shortest_path = current_path_length
if node not in visited:
visited.add(node)
for neighbour, length in graph[node]:
stack.append((neighbour, current_path_length + length, path + [neighbour]))
if answer:
print(*answer)
else:
print(-1)
if __name__ == '__main__':
main()
```
| 0
|
20
|
C
|
Dijkstra?
|
PROGRAMMING
| 1,900
|
[
"graphs",
"shortest paths"
] |
C. Dijkstra?
|
1
|
64
|
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
|
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices.
|
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
|
[
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] |
[
"1 4 3 5 ",
"1 4 3 5 "
] |
none
| 1,500
|
[
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input": "3 3\n1 2 1\n1 3 2\n2 3 1",
"output": "1 3 "
},
{
"input": "10 10\n1 5 12\n2 4 140\n2 10 149\n3 6 154\n3 7 9\n3 8 226\n3 10 132\n4 10 55\n5 8 33\n7 8 173",
"output": "1 5 8 7 3 10 "
},
{
"input": "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157",
"output": "1 8 10 "
},
{
"input": "10 10\n1 4 200\n1 9 197\n3 4 79\n3 5 213\n3 6 149\n5 8 3\n5 9 189\n6 7 130\n6 9 51\n8 10 135",
"output": "1 9 5 8 10 "
},
{
"input": "10 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242",
"output": "1 4 6 10 "
}
] | 1,599,961,806
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 3
| 156
| 102,400
|
from collections import defaultdict
start = 0
work, num_roads = [int(i) for i in input().split()]
edges = defaultdict(dict)
visited = set()
unvisited = set()
distances = {}
prev = defaultdict(list)
def find_smallest_vert(unvisted, distances):
min_vert = 0
min_val = 1000000+1
for i in unvisited:
if distances[i] < min_val:
min_val = distances[i]
min_vert = i
return min_vert
for i in range(num_roads):
fir,sec, weight = [int(i) for i in input().split()]
if fir in edges and sec in edges[fir]:
edges[fir][sec] = min(edges[fir][sec], weight)
else:
edges[fir][sec] = weight
#print(edges)
for i in range(1, work+1):
if i == 1:
distances[i] = 0
else:
distances[i] = 1000000
unvisited.add(i)
while len(unvisited) != 0:
current = find_smallest_vert(unvisited, distances)
visited.add(current)
unvisited.remove(current)
neighbors = edges[current]
for n in neighbors:
if n in unvisited:
dist = edges[current][n] + distances[current]
if dist < distances[n]:
distances[n] = dist
prev[n] = current
path = [work]
i = work
while i in prev:
path.append(prev[i])
i = prev[i]
print(' '.join([str(i) for i in path[::-1]]))
|
Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices.
Output Specification:
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
Demo Input:
['5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n', '5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n']
Demo Output:
['1 4 3 5 ', '1 4 3 5 ']
Note:
none
|
```python
from collections import defaultdict
start = 0
work, num_roads = [int(i) for i in input().split()]
edges = defaultdict(dict)
visited = set()
unvisited = set()
distances = {}
prev = defaultdict(list)
def find_smallest_vert(unvisted, distances):
min_vert = 0
min_val = 1000000+1
for i in unvisited:
if distances[i] < min_val:
min_val = distances[i]
min_vert = i
return min_vert
for i in range(num_roads):
fir,sec, weight = [int(i) for i in input().split()]
if fir in edges and sec in edges[fir]:
edges[fir][sec] = min(edges[fir][sec], weight)
else:
edges[fir][sec] = weight
#print(edges)
for i in range(1, work+1):
if i == 1:
distances[i] = 0
else:
distances[i] = 1000000
unvisited.add(i)
while len(unvisited) != 0:
current = find_smallest_vert(unvisited, distances)
visited.add(current)
unvisited.remove(current)
neighbors = edges[current]
for n in neighbors:
if n in unvisited:
dist = edges[current][n] + distances[current]
if dist < distances[n]:
distances[n] = dist
prev[n] = current
path = [work]
i = work
while i in prev:
path.append(prev[i])
i = prev[i]
print(' '.join([str(i) for i in path[::-1]]))
```
| 0
|
298
|
B
|
Sail
|
PROGRAMMING
| 1,200
|
[
"brute force",
"greedy",
"implementation"
] | null | null |
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1).
Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)?
|
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).
|
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
|
[
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] |
[
"4\n",
"-1\n"
] |
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination.
| 500
|
[
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSSWESNSSEESNSESWSWNSWESNENWNWEE",
"output": "4"
},
{
"input": "41 -264908123 -86993764 -264908123 -86993723\nNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
"output": "41"
},
{
"input": "34 -1000000000 -1000000000 -999999983 -1000000000\nEEEEESSEWNSSSESWEWSWESEWSEESNEWEEE",
"output": "-1"
},
{
"input": "1 0 0 0 -1\nS",
"output": "1"
},
{
"input": "1 5 5 5 6\nE",
"output": "-1"
},
{
"input": "15 1 1 1 2\nNNNNNNNNNNNNNNN",
"output": "1"
},
{
"input": "11 1 1 1 2\nNNNNNNNNNNN",
"output": "1"
}
] | 1,686,065,428
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 2
| 122
| 0
|
def main():
t, sx, sy, ex, ey = list(map(int, input().split()))
s = input()
px, py = 0, 0
target_x, target_y = ex - sx, ey - sy
if target_x >= 0:
cnt = 0
index1 = -1
for i in range(t):
if s[i] == 'E':
cnt += 1
if cnt == target_x:
index1 = i
break
else:
cnt = 0
index1 = -1
for i in range(t):
if s[i] == 'W':
cnt += 1
if target_x == cnt:
index1 = i
break
if target_y >= 0:
cnt = 0
index2 = -1
for i in range(t):
if s[i] == 'N':
cnt += 1
if cnt == target_x:
index2 = i
break
else:
cnt = 0
index2 = -1
for i in range(t):
if s[i] == 'S':
cnt += 1
if target_x == cnt:
index2 = i
break
if target_x == 0:
index1 = 0
if target_y == 0:
index2 = 0
if index1 == -1 or index2 == -1:
print(-1)
else:
print(max(index1, index2)+1)
if __name__ == "__main__":
main()
|
Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1).
Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)?
Input Specification:
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).
Output Specification:
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
Demo Input:
['5 0 0 1 1\nSESNW\n', '10 5 3 3 6\nNENSWESNEE\n']
Demo Output:
['4\n', '-1\n']
Note:
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination.
|
```python
def main():
t, sx, sy, ex, ey = list(map(int, input().split()))
s = input()
px, py = 0, 0
target_x, target_y = ex - sx, ey - sy
if target_x >= 0:
cnt = 0
index1 = -1
for i in range(t):
if s[i] == 'E':
cnt += 1
if cnt == target_x:
index1 = i
break
else:
cnt = 0
index1 = -1
for i in range(t):
if s[i] == 'W':
cnt += 1
if target_x == cnt:
index1 = i
break
if target_y >= 0:
cnt = 0
index2 = -1
for i in range(t):
if s[i] == 'N':
cnt += 1
if cnt == target_x:
index2 = i
break
else:
cnt = 0
index2 = -1
for i in range(t):
if s[i] == 'S':
cnt += 1
if target_x == cnt:
index2 = i
break
if target_x == 0:
index1 = 0
if target_y == 0:
index2 = 0
if index1 == -1 or index2 == -1:
print(-1)
else:
print(max(index1, index2)+1)
if __name__ == "__main__":
main()
```
| 0
|
|
653
|
E
|
Bear and Forgotten Tree 2
|
PROGRAMMING
| 2,400
|
[
"dfs and similar",
"dsu",
"graphs",
"trees"
] | null | null |
A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*.
Limak is a little polar bear. He once had a tree with *n* vertices but he lost it. He still remembers something about the lost tree though.
You are given *m* pairs of vertices (*a*1,<=*b*1),<=(*a*2,<=*b*2),<=...,<=(*a**m*,<=*b**m*). Limak remembers that for each *i* there was no edge between *a**i* and *b**i*. He also remembers that vertex 1 was incident to exactly *k* edges (its degree was equal to *k*).
Is it possible that Limak remembers everything correctly? Check whether there exists a tree satisfying the given conditions.
|
The first line of the input contains three integers *n*, *m* and *k* () — the number of vertices in Limak's tree, the number of forbidden pairs of vertices, and the degree of vertex 1, respectively.
The *i*-th of next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — the *i*-th pair that is forbidden. It's guaranteed that each pair of vertices will appear at most once in the input.
|
Print "possible" (without quotes) if there exists at least one tree satisfying the given conditions. Otherwise, print "impossible" (without quotes).
|
[
"5 4 2\n1 2\n2 3\n4 2\n4 1\n",
"6 5 3\n1 2\n1 3\n1 4\n1 5\n1 6\n"
] |
[
"possible\n",
"impossible\n"
] |
In the first sample, there are *n* = 5 vertices. The degree of vertex 1 should be *k* = 2. All conditions are satisfied for a tree with edges 1 - 5, 5 - 2, 1 - 3 and 3 - 4.
In the second sample, Limak remembers that none of the following edges existed: 1 - 2, 1 - 3, 1 - 4, 1 - 5 and 1 - 6. Hence, vertex 1 couldn't be connected to any other vertex and it implies that there is no suitable tree.
| 2,500
|
[
{
"input": "5 4 2\n1 2\n2 3\n4 2\n4 1",
"output": "possible"
},
{
"input": "6 5 3\n1 2\n1 3\n1 4\n1 5\n1 6",
"output": "impossible"
},
{
"input": "4 3 2\n2 3\n2 4\n3 4",
"output": "impossible"
},
{
"input": "4 2 2\n1 2\n1 3",
"output": "impossible"
},
{
"input": "7 11 1\n1 2\n1 3\n1 4\n1 5\n1 7\n6 2\n6 3\n6 4\n6 5\n6 7\n2 3",
"output": "impossible"
},
{
"input": "3 1 2\n1 3",
"output": "impossible"
},
{
"input": "4 2 2\n2 1\n1 4",
"output": "impossible"
},
{
"input": "4 2 3\n2 1\n2 4",
"output": "impossible"
},
{
"input": "4 5 1\n2 3\n2 4\n4 3\n3 1\n1 2",
"output": "impossible"
},
{
"input": "5 2 4\n4 3\n1 3",
"output": "impossible"
},
{
"input": "5 3 1\n2 1\n4 3\n3 1",
"output": "possible"
},
{
"input": "5 3 2\n1 2\n5 1\n1 4",
"output": "impossible"
},
{
"input": "5 3 3\n5 4\n2 4\n2 1",
"output": "possible"
},
{
"input": "5 4 2\n2 1\n4 1\n4 2\n3 5",
"output": "possible"
},
{
"input": "5 4 3\n5 1\n5 3\n3 1\n4 2",
"output": "impossible"
},
{
"input": "5 4 4\n4 5\n4 2\n1 5\n5 3",
"output": "impossible"
},
{
"input": "5 5 2\n2 1\n3 1\n5 3\n3 2\n3 4",
"output": "impossible"
},
{
"input": "5 6 1\n3 1\n4 5\n3 5\n4 3\n1 2\n2 4",
"output": "impossible"
},
{
"input": "5 6 2\n3 5\n2 1\n2 5\n1 5\n1 3\n2 4",
"output": "impossible"
},
{
"input": "5 6 3\n3 1\n4 3\n2 5\n4 5\n2 4\n3 2",
"output": "possible"
},
{
"input": "5 8 1\n1 4\n4 3\n1 5\n3 5\n2 4\n1 2\n5 2\n4 5",
"output": "impossible"
},
{
"input": "2 0 1",
"output": "possible"
},
{
"input": "2 1 1\n2 1",
"output": "impossible"
},
{
"input": "300000 0 1",
"output": "possible"
},
{
"input": "300000 0 299999",
"output": "possible"
}
] | 1,642,399,554
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 5
| 2,000
| 11,776,000
|
def bfs(graph, vertex, total_vertices, k):
total_vertices_visited = 0
is_visited = [False]*total_vertices
_bfsQueue = []
_bfsQueue.append(vertex)
total_vertices_visited += 1
is_visited[vertex - 1] = True
while len(_bfsQueue) != 0:
_k = 0
for i in range(1, total_vertices + 1):
if i not in graph[vertex] and (is_visited[i - 1] == False):
if vertex == 1:
_k += 1
if _k > k:
break
_bfsQueue.append(i)
is_visited[i - 1] = True
total_vertices_visited += 1
_bfsQueue.pop(0)
if len(_bfsQueue) != 0:
vertex = _bfsQueue[0]
return total_vertices_visited
def isTreePossible(graph, total_vertices, k):
max_possible_edges_from_1 = total_vertices - len(graph[1]) - 1
if max_possible_edges_from_1 < k:
return False
# perform bfs calculate total vertices that are visited
# if total vertices are visited that are not equal to vertices in the
# actual graph return False
total_vertices_visited_in_bfs = bfs(graph, 1, total_vertices, k)
if total_vertices_visited_in_bfs != total_vertices:
return False
return True
def main():
total_vertices, e, k = [ int(x) for x in input().split(" ") ]
graph = {}
for i in range(total_vertices):
graph[i + 1] = []
for i in range(e):
u, v = [int(x) for x in input().split(" ")]
graph[u].append(v)
graph[v].append(u)
if isTreePossible(graph, total_vertices, k):
print("possible")
else:
print("impossible")
main()
|
Title: Bear and Forgotten Tree 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*.
Limak is a little polar bear. He once had a tree with *n* vertices but he lost it. He still remembers something about the lost tree though.
You are given *m* pairs of vertices (*a*1,<=*b*1),<=(*a*2,<=*b*2),<=...,<=(*a**m*,<=*b**m*). Limak remembers that for each *i* there was no edge between *a**i* and *b**i*. He also remembers that vertex 1 was incident to exactly *k* edges (its degree was equal to *k*).
Is it possible that Limak remembers everything correctly? Check whether there exists a tree satisfying the given conditions.
Input Specification:
The first line of the input contains three integers *n*, *m* and *k* () — the number of vertices in Limak's tree, the number of forbidden pairs of vertices, and the degree of vertex 1, respectively.
The *i*-th of next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — the *i*-th pair that is forbidden. It's guaranteed that each pair of vertices will appear at most once in the input.
Output Specification:
Print "possible" (without quotes) if there exists at least one tree satisfying the given conditions. Otherwise, print "impossible" (without quotes).
Demo Input:
['5 4 2\n1 2\n2 3\n4 2\n4 1\n', '6 5 3\n1 2\n1 3\n1 4\n1 5\n1 6\n']
Demo Output:
['possible\n', 'impossible\n']
Note:
In the first sample, there are *n* = 5 vertices. The degree of vertex 1 should be *k* = 2. All conditions are satisfied for a tree with edges 1 - 5, 5 - 2, 1 - 3 and 3 - 4.
In the second sample, Limak remembers that none of the following edges existed: 1 - 2, 1 - 3, 1 - 4, 1 - 5 and 1 - 6. Hence, vertex 1 couldn't be connected to any other vertex and it implies that there is no suitable tree.
|
```python
def bfs(graph, vertex, total_vertices, k):
total_vertices_visited = 0
is_visited = [False]*total_vertices
_bfsQueue = []
_bfsQueue.append(vertex)
total_vertices_visited += 1
is_visited[vertex - 1] = True
while len(_bfsQueue) != 0:
_k = 0
for i in range(1, total_vertices + 1):
if i not in graph[vertex] and (is_visited[i - 1] == False):
if vertex == 1:
_k += 1
if _k > k:
break
_bfsQueue.append(i)
is_visited[i - 1] = True
total_vertices_visited += 1
_bfsQueue.pop(0)
if len(_bfsQueue) != 0:
vertex = _bfsQueue[0]
return total_vertices_visited
def isTreePossible(graph, total_vertices, k):
max_possible_edges_from_1 = total_vertices - len(graph[1]) - 1
if max_possible_edges_from_1 < k:
return False
# perform bfs calculate total vertices that are visited
# if total vertices are visited that are not equal to vertices in the
# actual graph return False
total_vertices_visited_in_bfs = bfs(graph, 1, total_vertices, k)
if total_vertices_visited_in_bfs != total_vertices:
return False
return True
def main():
total_vertices, e, k = [ int(x) for x in input().split(" ") ]
graph = {}
for i in range(total_vertices):
graph[i + 1] = []
for i in range(e):
u, v = [int(x) for x in input().split(" ")]
graph[u].append(v)
graph[v].append(u)
if isTreePossible(graph, total_vertices, k):
print("possible")
else:
print("impossible")
main()
```
| 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,655,575,811
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 40
| 154
| 0
|
s = input()
a = input()
res = []
k = len(s) - 1
while k >= 0:
res.append(s[k])
k -= 1
if (''.join(res) == a):
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
s = input()
a = input()
res = []
k = len(s) - 1
while k >= 0:
res.append(s[k])
k -= 1
if (''.join(res) == a):
print("YES")
else:
print("NO")
```
| 3.9615
|
603
|
A
|
Alternative Thinking
|
PROGRAMMING
| 1,600
|
[
"dp",
"greedy",
"math"
] | null | null |
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0,<=1,<=0,<=1}, {1,<=0,<=1}, and {1,<=0,<=1,<=0} are alternating sequences, while {1,<=0,<=0} and {0,<=1,<=0,<=1,<=1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
|
The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000).
The following line contains a binary string of length *n* representing Kevin's results on the USAICO.
|
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
|
[
"8\n10000011\n",
"2\n01\n"
] |
[
"5\n",
"2\n"
] |
In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score.
| 500
|
[
{
"input": "8\n10000011",
"output": "5"
},
{
"input": "2\n01",
"output": "2"
},
{
"input": "5\n10101",
"output": "5"
},
{
"input": "75\n010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "75"
},
{
"input": "11\n00000000000",
"output": "3"
},
{
"input": "56\n10101011010101010101010101010101010101011010101010101010",
"output": "56"
},
{
"input": "50\n01011010110101010101010101010101010101010101010100",
"output": "49"
},
{
"input": "7\n0110100",
"output": "7"
},
{
"input": "8\n11011111",
"output": "5"
},
{
"input": "6\n000000",
"output": "3"
},
{
"input": "5\n01000",
"output": "5"
},
{
"input": "59\n10101010101010101010101010101010101010101010101010101010101",
"output": "59"
},
{
"input": "88\n1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "88"
},
{
"input": "93\n010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "93"
},
{
"input": "70\n0101010101010101010101010101010101010101010101010101010101010101010101",
"output": "70"
},
{
"input": "78\n010101010101010101010101010101101010101010101010101010101010101010101010101010",
"output": "78"
},
{
"input": "83\n10101010101010101010101010101010101010101010101010110101010101010101010101010101010",
"output": "83"
},
{
"input": "87\n101010101010101010101010101010101010101010101010101010101010101010101010101010010101010",
"output": "87"
},
{
"input": "65\n01010101101010101010101010101010101010101010101010101010101010101",
"output": "65"
},
{
"input": "69\n010101010101010101101010101010101010101010101010101010101010101010101",
"output": "69"
},
{
"input": "74\n01010101010101010101010101010101010101010101010101010101010101000101010101",
"output": "74"
},
{
"input": "77\n01010101010101001010101010101010100101010101010101010101010101010101010101010",
"output": "77"
},
{
"input": "60\n101010110101010101010101010110101010101010101010101010101010",
"output": "60"
},
{
"input": "89\n01010101010101010101010101010101010101010101010101010101101010101010101010100101010101010",
"output": "89"
},
{
"input": "68\n01010101010101010101010101010101010100101010100101010101010100101010",
"output": "67"
},
{
"input": "73\n0101010101010101010101010101010101010101010111011010101010101010101010101",
"output": "72"
},
{
"input": "55\n1010101010101010010101010101101010101010101010100101010",
"output": "54"
},
{
"input": "85\n1010101010101010101010101010010101010101010101101010101010101010101011010101010101010",
"output": "84"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1111111111",
"output": "3"
},
{
"input": "2\n10",
"output": "2"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "3\n000",
"output": "3"
},
{
"input": "3\n001",
"output": "3"
},
{
"input": "3\n010",
"output": "3"
},
{
"input": "3\n011",
"output": "3"
},
{
"input": "3\n100",
"output": "3"
},
{
"input": "3\n101",
"output": "3"
},
{
"input": "3\n110",
"output": "3"
},
{
"input": "3\n111",
"output": "3"
},
{
"input": "4\n0000",
"output": "3"
},
{
"input": "4\n0001",
"output": "4"
},
{
"input": "4\n0010",
"output": "4"
},
{
"input": "4\n0011",
"output": "4"
},
{
"input": "4\n0100",
"output": "4"
},
{
"input": "4\n0101",
"output": "4"
},
{
"input": "4\n0110",
"output": "4"
},
{
"input": "4\n0111",
"output": "4"
},
{
"input": "4\n1000",
"output": "4"
},
{
"input": "4\n1001",
"output": "4"
},
{
"input": "4\n1010",
"output": "4"
},
{
"input": "4\n1011",
"output": "4"
},
{
"input": "4\n1100",
"output": "4"
},
{
"input": "4\n1101",
"output": "4"
},
{
"input": "4\n1110",
"output": "4"
},
{
"input": "4\n1111",
"output": "3"
},
{
"input": "5\n00000",
"output": "3"
},
{
"input": "5\n00001",
"output": "4"
},
{
"input": "5\n00010",
"output": "5"
},
{
"input": "5\n00011",
"output": "4"
},
{
"input": "5\n00100",
"output": "5"
},
{
"input": "5\n00101",
"output": "5"
},
{
"input": "5\n00110",
"output": "5"
},
{
"input": "5\n00111",
"output": "4"
},
{
"input": "5\n01000",
"output": "5"
},
{
"input": "5\n01001",
"output": "5"
},
{
"input": "5\n01010",
"output": "5"
},
{
"input": "5\n01011",
"output": "5"
},
{
"input": "5\n01100",
"output": "5"
},
{
"input": "5\n01101",
"output": "5"
},
{
"input": "5\n01110",
"output": "5"
},
{
"input": "5\n01111",
"output": "4"
},
{
"input": "5\n10000",
"output": "4"
},
{
"input": "5\n10001",
"output": "5"
},
{
"input": "5\n10010",
"output": "5"
},
{
"input": "5\n10100",
"output": "5"
},
{
"input": "5\n10101",
"output": "5"
},
{
"input": "5\n10110",
"output": "5"
},
{
"input": "5\n10111",
"output": "5"
},
{
"input": "5\n11000",
"output": "4"
},
{
"input": "5\n11001",
"output": "5"
},
{
"input": "5\n11010",
"output": "5"
},
{
"input": "5\n11011",
"output": "5"
},
{
"input": "5\n11100",
"output": "4"
},
{
"input": "5\n11101",
"output": "5"
},
{
"input": "5\n11110",
"output": "4"
},
{
"input": "5\n11111",
"output": "3"
}
] | 1,449,441,644
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 116
| 124
| 204,800
|
import sys
def main():
n = int(input())
tab = sys.stdin.readline()
s = 1
t = tab[0]
e = 0
for i in range(1,len(tab)-1):
if t != tab[i]:
s+=1
t = tab[i]
if tab[i] == tab[i-1] == '0' or tab[i] == tab[i-1] == '1':
e+=1
e = min(e,2)
print(s+e)
main()
|
Title: Alternative Thinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0,<=1,<=0,<=1}, {1,<=0,<=1}, and {1,<=0,<=1,<=0} are alternating sequences, while {1,<=0,<=0} and {0,<=1,<=0,<=1,<=1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
Input Specification:
The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000).
The following line contains a binary string of length *n* representing Kevin's results on the USAICO.
Output Specification:
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
Demo Input:
['8\n10000011\n', '2\n01\n']
Demo Output:
['5\n', '2\n']
Note:
In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score.
|
```python
import sys
def main():
n = int(input())
tab = sys.stdin.readline()
s = 1
t = tab[0]
e = 0
for i in range(1,len(tab)-1):
if t != tab[i]:
s+=1
t = tab[i]
if tab[i] == tab[i-1] == '0' or tab[i] == tab[i-1] == '1':
e+=1
e = min(e,2)
print(s+e)
main()
```
| 3
|
|
938
|
A
|
Word Correction
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word *s*. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels.
|
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
|
Output the word *s* after the correction.
|
[
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] |
[
"werd\n",
"word\n",
"a\n"
] |
Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a.
| 0
|
[
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw"
},
{
"input": "69\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "12\nmmmmmmmmmmmm",
"output": "mmmmmmmmmmmm"
},
{
"input": "18\nyaywptqwuyiqypwoyw",
"output": "ywptqwuqypwow"
},
{
"input": "85\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "13\nmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmm"
},
{
"input": "10\nmmmmmmmmmm",
"output": "mmmmmmmmmm"
},
{
"input": "11\nmmmmmmmmmmm",
"output": "mmmmmmmmmmm"
},
{
"input": "15\nmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmm"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "14\nmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmm"
},
{
"input": "33\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"
},
{
"input": "79\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "90\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "2\naa",
"output": "a"
},
{
"input": "18\niuiuqpyyaoaetiwliu",
"output": "iqpytiwli"
},
{
"input": "5\nxxxxx",
"output": "xxxxx"
},
{
"input": "6\nxxxahg",
"output": "xxxahg"
},
{
"input": "3\nzcv",
"output": "zcv"
},
{
"input": "4\naepo",
"output": "apo"
},
{
"input": "5\nqqqqq",
"output": "qqqqq"
},
{
"input": "6\naaaaaa",
"output": "a"
},
{
"input": "4\naeta",
"output": "ata"
},
{
"input": "20\nttyttlwaoieulyiluuri",
"output": "ttyttlwalyluri"
},
{
"input": "1\nb",
"output": "b"
},
{
"input": "3\nanc",
"output": "anc"
},
{
"input": "1\ne",
"output": "e"
},
{
"input": "3\naie",
"output": "a"
},
{
"input": "3\nvio",
"output": "vi"
},
{
"input": "2\nea",
"output": "e"
},
{
"input": "3\nuas",
"output": "us"
},
{
"input": "2\nba",
"output": "ba"
},
{
"input": "2\naq",
"output": "aq"
},
{
"input": "2\nya",
"output": "y"
},
{
"input": "2\nou",
"output": "o"
},
{
"input": "2\nbb",
"output": "bb"
},
{
"input": "7\nayylmao",
"output": "alma"
},
{
"input": "2\nab",
"output": "ab"
},
{
"input": "19\nyuouiyaoiiweqrryqqp",
"output": "yweqrryqqp"
},
{
"input": "25\niqypwqpriiioetiuqqqttouei",
"output": "iqypwqpritiqqqtto"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyz",
"output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyz"
},
{
"input": "17\naccccccccccccccca",
"output": "accccccccccccccca"
},
{
"input": "5\nababa",
"output": "ababa"
},
{
"input": "10\naaaaaaaaaa",
"output": "a"
},
{
"input": "22\naaaaabbbbboyoyoyoyoyac",
"output": "abbbbboc"
},
{
"input": "7\nmahmoud",
"output": "mahmod"
}
] | 1,626,500,792
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 49
| 109
| 20,172,800
|
v=int(input())
s=list(input())
i=0
while(i+1<len(s)):
if(s[i] in 'aeiouy' and s[i+1] in 'aeiouy'):
del s[i+1]
else:
i+=1
print(''.join(s))
|
Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word *s*. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
Output Specification:
Output the word *s* after the correction.
Demo Input:
['5\nweird\n', '4\nword\n', '5\naaeaa\n']
Demo Output:
['werd\n', 'word\n', 'a\n']
Note:
Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a.
|
```python
v=int(input())
s=list(input())
i=0
while(i+1<len(s)):
if(s[i] in 'aeiouy' and s[i+1] in 'aeiouy'):
del s[i+1]
else:
i+=1
print(''.join(s))
```
| 3
|
|
108
|
A
|
Palindromic Times
|
PROGRAMMING
| 1,000
|
[
"implementation",
"strings"
] |
A. Palindromic Times
|
2
|
256
|
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome.
In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment.
However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.
|
The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.
|
Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.
|
[
"12:21\n",
"23:59\n"
] |
[
"13:31\n",
"00:00\n"
] |
none
| 500
|
[
{
"input": "12:21",
"output": "13:31"
},
{
"input": "23:59",
"output": "00:00"
},
{
"input": "15:51",
"output": "20:02"
},
{
"input": "10:44",
"output": "11:11"
},
{
"input": "04:02",
"output": "04:40"
},
{
"input": "02:11",
"output": "02:20"
},
{
"input": "12:15",
"output": "12:21"
},
{
"input": "07:07",
"output": "10:01"
},
{
"input": "00:17",
"output": "01:10"
},
{
"input": "04:55",
"output": "05:50"
},
{
"input": "02:17",
"output": "02:20"
},
{
"input": "07:56",
"output": "10:01"
},
{
"input": "00:29",
"output": "01:10"
},
{
"input": "23:31",
"output": "23:32"
},
{
"input": "19:30",
"output": "20:02"
},
{
"input": "12:14",
"output": "12:21"
},
{
"input": "17:32",
"output": "20:02"
},
{
"input": "03:44",
"output": "04:40"
},
{
"input": "07:15",
"output": "10:01"
},
{
"input": "18:42",
"output": "20:02"
},
{
"input": "08:56",
"output": "10:01"
},
{
"input": "04:50",
"output": "05:50"
},
{
"input": "14:32",
"output": "14:41"
},
{
"input": "23:23",
"output": "23:32"
},
{
"input": "08:35",
"output": "10:01"
},
{
"input": "03:32",
"output": "04:40"
},
{
"input": "07:59",
"output": "10:01"
},
{
"input": "14:12",
"output": "14:41"
},
{
"input": "23:52",
"output": "00:00"
},
{
"input": "16:36",
"output": "20:02"
},
{
"input": "17:50",
"output": "20:02"
},
{
"input": "06:59",
"output": "10:01"
},
{
"input": "16:50",
"output": "20:02"
},
{
"input": "00:00",
"output": "01:10"
},
{
"input": "23:59",
"output": "00:00"
},
{
"input": "23:33",
"output": "00:00"
}
] | 1,595,744,152
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 36
| 218
| 6,963,200
|
s = input()
s1 = s
s1 = s1.split(":")
s1[0] = int(s1[0])
s1[1] = int(s1[1])
while(1):
s1[1] += 1
s1[1] = s1[1]%60
if s1[1] == 0:
s1[0] += 1
s1[0] = s1[0]%24
a = str(s1[0])
b = str(s1[1])
if len(a) == 1:
a = "0" + a
if len(b) == 1:
b = "0" + b
b1 = b[::-1]
if a == b1:
print(a+":"+b)
break
|
Title: Palindromic Times
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome.
In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment.
However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.
Input Specification:
The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.
Output Specification:
Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.
Demo Input:
['12:21\n', '23:59\n']
Demo Output:
['13:31\n', '00:00\n']
Note:
none
|
```python
s = input()
s1 = s
s1 = s1.split(":")
s1[0] = int(s1[0])
s1[1] = int(s1[1])
while(1):
s1[1] += 1
s1[1] = s1[1]%60
if s1[1] == 0:
s1[0] += 1
s1[0] = s1[0]%24
a = str(s1[0])
b = str(s1[1])
if len(a) == 1:
a = "0" + a
if len(b) == 1:
b = "0" + b
b1 = b[::-1]
if a == b1:
print(a+":"+b)
break
```
| 3.93253
|
6
|
B
|
President's Office
|
PROGRAMMING
| 1,100
|
[
"implementation"
] |
B. President's Office
|
2
|
64
|
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
|
The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
|
Print the only number — the amount of President's deputies.
|
[
"3 4 R\nG.B.\n.RR.\nTTT.\n",
"3 3 Z\n...\n.H.\n..Z\n"
] |
[
"2\n",
"0\n"
] |
none
| 0
|
[
{
"input": "3 4 R\nG.B.\n.RR.\nTTT.",
"output": "2"
},
{
"input": "3 3 Z\n...\n.H.\n..Z",
"output": "0"
},
{
"input": "1 1 C\nC",
"output": "0"
},
{
"input": "2 2 W\nKW\nKW",
"output": "1"
},
{
"input": "1 10 H\n....DDHHHH",
"output": "1"
},
{
"input": "3 2 W\nOO\nWW\nWW",
"output": "1"
},
{
"input": "3 3 U\nUOO\nUVV\nUVV",
"output": "2"
},
{
"input": "4 5 Z\n...ZZ\nUU.ZZ\nUUTT.\n..TT.",
"output": "1"
},
{
"input": "4 4 X\nT..R\nTJJJ\nDJJJ\nXJJJ",
"output": "2"
},
{
"input": "5 5 O\nCQGAV\nIHTUD\nRFPZO\nMYSKX\nJEWBN",
"output": "3"
},
{
"input": "5 4 O\n.O.J\nWOBJ\nWOBJ\nDDBJ\nDD.J",
"output": "3"
},
{
"input": "7 7 Q\n....RRR\nUUUURRR\nUUUUSS.\n....SSB\nPPP.OIB\n.MMTTIB\nQQQTTIB",
"output": "2"
},
{
"input": "8 10 B\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..",
"output": "3"
},
{
"input": "7 13 G\n....GGGGGGXXX\nSSSSGGGGGGXXX\nSSSSJJFFFFFFF\nRRR.JJFFFFFFF\nRRRYYYYYYYAAA\nRRRYYYYYYYAAA\nRRR.......AAA",
"output": "4"
},
{
"input": "10 10 T\nCCEEEKKKHJ\nCCRRRRRRHJ\nCC..XFFOOO\nZZZZZFFOOO\n..PTTFFOOO\nAAATTFFOOO\nAAATTYYYYY\nAAATTYYYYY\nAAAMMYYYYY\nAAA..YYYYY",
"output": "6"
},
{
"input": "15 12 M\n............\n.....L..QQQQ\nNNN..L..QQQQ\nNNN..LJJJJJ.\nNNNEEEEEEEE.\nNNNEEEEEEEE.\nNNNMMMMM.AAA\nNNNMMMMM.AAA\n.RRMMMMM.AAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\nZRRMMMMMYAAA\nZRRMMMMM.AAA\nZRRMMMMM.AAA",
"output": "4"
}
] | 1,689,929,063
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 30
| 819,200
|
import string
n,m,color=list(map(str,input().split()))
list1=[]
color1=[]
for x in range(int(n)):
s1=input()
if color in s1:
color1.append(s1)
else:
list1.append(s1)
elements=[]
if int(n)==1 and len(color1[0])>=5:
if color1[0][5]!=".":
print(1)
else:
print(0)
if int(n)==1 and int(m)==1:
print(0)
if len(color1)>1:
for g in range(1,len(color1)):
list1.append(color1[g])
kh=0
for i in range(len(list1)):
for t in range(int(m)):
if color1[0][t]==color and list1[i][t] in string.ascii_uppercase:
kh+=1
elements.append(list1[i][t])
if kh>0:
elements=list(set(elements))
print(len(elements))
|
Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input Specification:
The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output Specification:
Print the only number — the amount of President's deputies.
Demo Input:
['3 4 R\nG.B.\n.RR.\nTTT.\n', '3 3 Z\n...\n.H.\n..Z\n']
Demo Output:
['2\n', '0\n']
Note:
none
|
```python
import string
n,m,color=list(map(str,input().split()))
list1=[]
color1=[]
for x in range(int(n)):
s1=input()
if color in s1:
color1.append(s1)
else:
list1.append(s1)
elements=[]
if int(n)==1 and len(color1[0])>=5:
if color1[0][5]!=".":
print(1)
else:
print(0)
if int(n)==1 and int(m)==1:
print(0)
if len(color1)>1:
for g in range(1,len(color1)):
list1.append(color1[g])
kh=0
for i in range(len(list1)):
for t in range(int(m)):
if color1[0][t]==color and list1[i][t] in string.ascii_uppercase:
kh+=1
elements.append(list1[i][t])
if kh>0:
elements=list(set(elements))
print(len(elements))
```
| 0
|
975
|
B
|
Mancala
|
PROGRAMMING
| 1,100
|
[
"brute force",
"implementation"
] | null | null |
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.
Note that the counter-clockwise order means if the player takes the stones from hole $i$, he will put one stone in the $(i+1)$-th hole, then in the $(i+2)$-th, etc. If he puts a stone in the $14$-th hole, the next one will be put in the first hole.
After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.
Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.
|
The only line contains 14 integers $a_1, a_2, \ldots, a_{14}$ ($0 \leq a_i \leq 10^9$) — the number of stones in each hole.
It is guaranteed that for any $i$ ($1\leq i \leq 14$) $a_i$ is either zero or odd, and there is at least one stone in the board.
|
Output one integer, the maximum possible score after one move.
|
[
"0 1 1 0 0 0 0 0 0 7 0 0 0 0\n",
"5 1 1 1 1 0 0 0 0 0 0 0 0 0\n"
] |
[
"4\n",
"8\n"
] |
In the first test case the board after the move from the hole with $7$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $4$.
| 1,000
|
[
{
"input": "0 1 1 0 0 0 0 0 0 7 0 0 0 0",
"output": "4"
},
{
"input": "5 1 1 1 1 0 0 0 0 0 0 0 0 0",
"output": "8"
},
{
"input": "10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 1",
"output": "54294"
},
{
"input": "0 0 0 0 0 0 0 0 0 0 0 0 0 15",
"output": "2"
},
{
"input": "1 0 0 0 0 1 0 0 0 0 1 0 0 0",
"output": "0"
},
{
"input": "5 5 1 1 1 3 3 3 5 7 5 3 7 5",
"output": "38"
},
{
"input": "787 393 649 463 803 365 81 961 989 531 303 407 579 915",
"output": "7588"
},
{
"input": "8789651 4466447 1218733 6728667 1796977 6198853 8263135 6309291 8242907 7136751 3071237 5397369 6780785 9420869",
"output": "81063456"
},
{
"input": "0 0 0 0 0 0 0 0 0 0 0 0 0 29",
"output": "26"
},
{
"input": "282019717 109496191 150951267 609856495 953855615 569750143 6317733 255875779 645191029 572053369 290936613 338480779 879775193 177172893",
"output": "5841732816"
},
{
"input": "105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505",
"output": "120472578"
},
{
"input": "404418821 993626161 346204297 122439813 461187221 628048227 625919459 628611733 938993057 701270099 398043779 684205961 630975553 575964835",
"output": "8139909016"
},
{
"input": "170651077 730658441 824213789 583764177 129437345 717005779 675398017 314979709 380861369 265878463 746564659 797260041 506575735 335169317",
"output": "6770880638"
},
{
"input": "622585025 48249287 678950449 891575125 637411965 457739735 829353393 235216425 284006447 875591469 492839209 296444305 513776057 810057753",
"output": "7673796644"
},
{
"input": "475989857 930834747 786217439 927967137 489188151 869354161 276693267 56154399 131055697 509249443 143116853 426254423 44465165 105798821",
"output": "6172339560"
},
{
"input": "360122921 409370351 226220005 604004145 85173909 600403773 624052991 138163383 729239967 189036661 619842883 270087537 749500483 243727913",
"output": "5848946922"
},
{
"input": "997102881 755715147 273805839 436713689 547411799 72470207 522269145 647688957 137422311 422612659 197751751 679663349 821420227 387967237",
"output": "6900015198"
},
{
"input": "690518849 754551537 652949719 760695679 491633619 477564457 11669279 700467439 470069297 782338983 718169393 884421719 24619427 215745577",
"output": "7635414974"
},
{
"input": "248332749 486342237 662201929 917696895 555278549 252122023 850296207 463343655 832574345 954281071 168282553 825538865 996753493 461254663",
"output": "6400166934"
},
{
"input": "590789361 636464947 404477303 337309187 476703809 426863069 120608741 703406277 645444697 761482231 996635839 33459441 677458865 483861751",
"output": "7294965518"
},
{
"input": "297857621 238127103 749085829 139033277 597985489 202617713 982184715 183932743 278551059 297781685 330124279 338959601 682874531 187519685",
"output": "5201808164"
},
{
"input": "1 1 1 1 1 0 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "1 1 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "1 0 0 0 0 0 0 0 0 0 0 0 0 1",
"output": "2"
},
{
"input": "0 0 0 0 0 0 0 0 0 0 0 0 1 1",
"output": "2"
}
] | 1,525,185,085
| 1,585
|
Python 3
|
WRONG_ANSWER
|
PRETESTS
| 2
| 93
| 7,065,600
|
mx = 0
s = list(map(int, input().split()))
for i in range(14):
res = 0
sw = list(s)
x = sw[i]
sw[i]=0
if x<14-i-1:
for i in range(i+1, i+x+1):
sw[i]+=1
else:
x-=14-i-1
for i in range(i+1, 14):
sw[i]+=1
t = x//14
ost = x%14
for i in range(14):
if i<=ost:
sw[i]+=t*14+1
else:
sw[i]+=t*14
for x in sw:
if x%2==0:
res+=x
if res>mx:
mx = res
print(mx)
|
Title: Mancala
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.
Note that the counter-clockwise order means if the player takes the stones from hole $i$, he will put one stone in the $(i+1)$-th hole, then in the $(i+2)$-th, etc. If he puts a stone in the $14$-th hole, the next one will be put in the first hole.
After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.
Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.
Input Specification:
The only line contains 14 integers $a_1, a_2, \ldots, a_{14}$ ($0 \leq a_i \leq 10^9$) — the number of stones in each hole.
It is guaranteed that for any $i$ ($1\leq i \leq 14$) $a_i$ is either zero or odd, and there is at least one stone in the board.
Output Specification:
Output one integer, the maximum possible score after one move.
Demo Input:
['0 1 1 0 0 0 0 0 0 7 0 0 0 0\n', '5 1 1 1 1 0 0 0 0 0 0 0 0 0\n']
Demo Output:
['4\n', '8\n']
Note:
In the first test case the board after the move from the hole with $7$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $4$.
|
```python
mx = 0
s = list(map(int, input().split()))
for i in range(14):
res = 0
sw = list(s)
x = sw[i]
sw[i]=0
if x<14-i-1:
for i in range(i+1, i+x+1):
sw[i]+=1
else:
x-=14-i-1
for i in range(i+1, 14):
sw[i]+=1
t = x//14
ost = x%14
for i in range(14):
if i<=ost:
sw[i]+=t*14+1
else:
sw[i]+=t*14
for x in sw:
if x%2==0:
res+=x
if res>mx:
mx = res
print(mx)
```
| 0
|
|
745
|
A
|
Hongcow Learns the Cyclic Shift
|
PROGRAMMING
| 900
|
[
"implementation",
"strings"
] | null | null |
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.
Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.
|
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z').
|
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
|
[
"abcd\n",
"bbb\n",
"yzyz\n"
] |
[
"4\n",
"1\n",
"2\n"
] |
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
| 500
|
[
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "1"
},
{
"input": "xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy",
"output": "2"
},
{
"input": "y",
"output": "1"
},
{
"input": "ervbfotfedpozygoumbmxeaqegouaqqzqerlykhmvxvvlcaos",
"output": "49"
},
{
"input": "zyzzzyyzyyyzyyzyzyzyzyzzzyyyzzyzyyzzzzzyyyzzzzyzyy",
"output": "50"
},
{
"input": "zzfyftdezzfyftdezzfyftdezzfyftdezzfyftdezzfyftde",
"output": "8"
},
{
"input": "yehcqdlllqpuxdsaicyjjxiylahgxbygmsopjbxhtimzkashs",
"output": "49"
},
{
"input": "yyyyzzzyzzzyzyzyzyyyyyzzyzyzyyyyyzyzyyyzyzzyyzzzz",
"output": "49"
},
{
"input": "zkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnw",
"output": "12"
},
{
"input": "xxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxy",
"output": "3"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaab",
"output": "25"
},
{
"input": "aabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaaba",
"output": "4"
},
{
"input": "pqqpqqpqqpqqpqqpqqpqqpqqpqqpqqpqqppqppqppqppqppq",
"output": "48"
},
{
"input": "zxkljaqzxkljaqzxkljaqzxkljaqzxrljaqzxkljaqzxkljaq",
"output": "49"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx",
"output": "50"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "50"
},
{
"input": "abcddcba",
"output": "8"
},
{
"input": "aabaabaabaacaabaabaabaacaabaabaabaacaabaabaabaac",
"output": "12"
},
{
"input": "aabaabcaabaabcdaabaabcaabaabcd",
"output": "15"
},
{
"input": "ababaababaaababaababaaaababaababaaababaababaaaa",
"output": "47"
},
{
"input": "ababaababaaababaababaaaababaababaaababaababaaa",
"output": "23"
},
{
"input": "aaababaab",
"output": "9"
},
{
"input": "aba",
"output": "3"
}
] | 1,481,992,639
| 139
|
Python 3
|
OK
|
TESTS
| 28
| 62
| 4,608,000
|
s=input()
a=[s[i:]+s[:i] for i in range(len(s))]
print(len(set(a)))
|
Title: Hongcow Learns the Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.
Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.
Input Specification:
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z').
Output Specification:
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
Demo Input:
['abcd\n', 'bbb\n', 'yzyz\n']
Demo Output:
['4\n', '1\n', '2\n']
Note:
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
|
```python
s=input()
a=[s[i:]+s[:i] for i in range(len(s))]
print(len(set(a)))
```
| 3
|
|
102
|
B
|
Sum of Digits
|
PROGRAMMING
| 1,000
|
[
"implementation"
] |
B. Sum of Digits
|
2
|
265
|
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
|
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
|
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
|
[
"0\n",
"10\n",
"991\n"
] |
[
"0\n",
"1\n",
"3\n"
] |
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
| 1,000
|
[
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output": "1"
},
{
"input": "86",
"output": "2"
},
{
"input": "2",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "34",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "28",
"output": "2"
},
{
"input": "23",
"output": "1"
},
{
"input": "57",
"output": "2"
},
{
"input": "29",
"output": "2"
},
{
"input": "353869285",
"output": "3"
},
{
"input": "549548646",
"output": "2"
},
{
"input": "858893424",
"output": "2"
},
{
"input": "644818852",
"output": "3"
},
{
"input": "360322525",
"output": "3"
},
{
"input": "122937520",
"output": "2"
},
{
"input": "288403032",
"output": "2"
},
{
"input": "677257481",
"output": "3"
},
{
"input": "58059561",
"output": "3"
},
{
"input": "211288847",
"output": "2"
},
{
"input": "339900034079539584",
"output": "2"
},
{
"input": "784084029310269952",
"output": "3"
},
{
"input": "774730557264864000",
"output": "3"
},
{
"input": "478233807148352256",
"output": "3"
},
{
"input": "165646874056812544",
"output": "3"
},
{
"input": "477533739511673792",
"output": "3"
},
{
"input": "660119944377002240",
"output": "3"
},
{
"input": "448375218506078080",
"output": "3"
},
{
"input": "77213334785795616",
"output": "3"
},
{
"input": "165767221702271872",
"output": "3"
},
{
"input": "1",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561",
"output": "3"
},
{
"input": "9",
"output": "0"
}
] | 1,643,374,079
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 51
| 186
| 7,475,200
|
n=input()
n=list(n)
ct=0
while(len(n)!=1):
ans=0
for i in range(len(n)):
ans+=int(n[i])
temp=str(ans)
temp=list(temp)
n=temp
ct+=1
print(ct)
|
Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
Input Specification:
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Output Specification:
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
Demo Input:
['0\n', '10\n', '991\n']
Demo Output:
['0\n', '1\n', '3\n']
Note:
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
|
```python
n=input()
n=list(n)
ct=0
while(len(n)!=1):
ans=0
for i in range(len(n)):
ans+=int(n[i])
temp=str(ans)
temp=list(temp)
n=temp
ct+=1
print(ct)
```
| 3.940049
|
614
|
B
|
Gena's Code
|
PROGRAMMING
| 1,400
|
[
"implementation",
"math"
] | null | null |
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!
There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful.
Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.
|
The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country.
It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000.
|
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
|
[
"3\n5 10 1\n",
"4\n1 1 10 11\n",
"5\n0 3 1 100 1\n"
] |
[
"50",
"110",
"0"
] |
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful.
| 1,000
|
[
{
"input": "3\n5 10 1",
"output": "50"
},
{
"input": "4\n1 1 10 11",
"output": "110"
},
{
"input": "5\n0 3 1 100 1",
"output": "0"
},
{
"input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100",
"output": "1824868942000000000000000000000000000000000000000000000000000"
},
{
"input": "6\n1000000000000000000000000000000000000 6643573784 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000",
"output": "6643573784000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n9",
"output": "9"
},
{
"input": "2\n10 50",
"output": "500"
},
{
"input": "3\n500 1 10",
"output": "5000"
}
] | 1,453,408,808
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 2
| 78
| 0
|
int(input())
x=''
zero=0
for s in input().split():
if s== '0':print(-1),exit()
elif s=='1'+'0'*(len(s)-1):zero+=len(s)-1
else: x=s
print(x+'0'*zero if len(x)>0 else '1'+'0'*zero)
|
Title: Gena's Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!
There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful.
Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.
Input Specification:
The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country.
It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000.
Output Specification:
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
Demo Input:
['3\n5 10 1\n', '4\n1 1 10 11\n', '5\n0 3 1 100 1\n']
Demo Output:
['50', '110', '0']
Note:
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful.
|
```python
int(input())
x=''
zero=0
for s in input().split():
if s== '0':print(-1),exit()
elif s=='1'+'0'*(len(s)-1):zero+=len(s)-1
else: x=s
print(x+'0'*zero if len(x)>0 else '1'+'0'*zero)
```
| 0
|
|
620
|
B
|
Grandfather Dovlet’s calculator
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.
For example if *a*<==<=1 and *b*<==<=3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.
|
The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max.
|
Print the only integer *a* — the total number of printed segments.
|
[
"1 3\n",
"10 15\n"
] |
[
"12\n",
"39\n"
] |
none
| 0
|
[
{
"input": "1 3",
"output": "12"
},
{
"input": "10 15",
"output": "39"
},
{
"input": "1 100",
"output": "928"
},
{
"input": "100 10000",
"output": "188446"
},
{
"input": "213 221442",
"output": "5645356"
},
{
"input": "1 1000000",
"output": "28733372"
},
{
"input": "1000000 1000000",
"output": "38"
},
{
"input": "222145 353252",
"output": "3860750"
},
{
"input": "2 1000000",
"output": "28733370"
},
{
"input": "1 999999",
"output": "28733334"
},
{
"input": "192 200",
"output": "122"
}
] | 1,550,226,293
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 11
| 342
| 37,683,200
|
f=lambda:map(int,input().split())
a=[6,2,5,5,4,5,6,3,7,6]
sm=0
x,y=f()
s=str(list(range(x,y+1)))
for i in range(10):
sm+=s.count(str(i))*a[i]
print(sm)
|
Title: Grandfather Dovlet’s calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.
For example if *a*<==<=1 and *b*<==<=3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.
Input Specification:
The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max.
Output Specification:
Print the only integer *a* — the total number of printed segments.
Demo Input:
['1 3\n', '10 15\n']
Demo Output:
['12\n', '39\n']
Note:
none
|
```python
f=lambda:map(int,input().split())
a=[6,2,5,5,4,5,6,3,7,6]
sm=0
x,y=f()
s=str(list(range(x,y+1)))
for i in range(10):
sm+=s.count(str(i))*a[i]
print(sm)
```
| 3
|
|
938
|
A
|
Word Correction
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word *s*. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels.
|
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
|
Output the word *s* after the correction.
|
[
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] |
[
"werd\n",
"word\n",
"a\n"
] |
Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a.
| 0
|
[
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw"
},
{
"input": "69\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "12\nmmmmmmmmmmmm",
"output": "mmmmmmmmmmmm"
},
{
"input": "18\nyaywptqwuyiqypwoyw",
"output": "ywptqwuqypwow"
},
{
"input": "85\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "13\nmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmm"
},
{
"input": "10\nmmmmmmmmmm",
"output": "mmmmmmmmmm"
},
{
"input": "11\nmmmmmmmmmmm",
"output": "mmmmmmmmmmm"
},
{
"input": "15\nmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmm"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "14\nmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmm"
},
{
"input": "33\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"
},
{
"input": "79\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "90\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "2\naa",
"output": "a"
},
{
"input": "18\niuiuqpyyaoaetiwliu",
"output": "iqpytiwli"
},
{
"input": "5\nxxxxx",
"output": "xxxxx"
},
{
"input": "6\nxxxahg",
"output": "xxxahg"
},
{
"input": "3\nzcv",
"output": "zcv"
},
{
"input": "4\naepo",
"output": "apo"
},
{
"input": "5\nqqqqq",
"output": "qqqqq"
},
{
"input": "6\naaaaaa",
"output": "a"
},
{
"input": "4\naeta",
"output": "ata"
},
{
"input": "20\nttyttlwaoieulyiluuri",
"output": "ttyttlwalyluri"
},
{
"input": "1\nb",
"output": "b"
},
{
"input": "3\nanc",
"output": "anc"
},
{
"input": "1\ne",
"output": "e"
},
{
"input": "3\naie",
"output": "a"
},
{
"input": "3\nvio",
"output": "vi"
},
{
"input": "2\nea",
"output": "e"
},
{
"input": "3\nuas",
"output": "us"
},
{
"input": "2\nba",
"output": "ba"
},
{
"input": "2\naq",
"output": "aq"
},
{
"input": "2\nya",
"output": "y"
},
{
"input": "2\nou",
"output": "o"
},
{
"input": "2\nbb",
"output": "bb"
},
{
"input": "7\nayylmao",
"output": "alma"
},
{
"input": "2\nab",
"output": "ab"
},
{
"input": "19\nyuouiyaoiiweqrryqqp",
"output": "yweqrryqqp"
},
{
"input": "25\niqypwqpriiioetiuqqqttouei",
"output": "iqypwqpritiqqqtto"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyz",
"output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyz"
},
{
"input": "17\naccccccccccccccca",
"output": "accccccccccccccca"
},
{
"input": "5\nababa",
"output": "ababa"
},
{
"input": "10\naaaaaaaaaa",
"output": "a"
},
{
"input": "22\naaaaabbbbboyoyoyoyoyac",
"output": "abbbbboc"
},
{
"input": "7\nmahmoud",
"output": "mahmod"
}
] | 1,585,337,932
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 108
| 0
|
q = int(input())
word = list(input())
vowels = ['a', 'e', 'i', 'o', 'u', 'Y', 'A', 'E', 'I', 'O', 'U', 'Y']
i = 0
while i < len(word)-1:
if (word[i] in vowels and word[i+1] in vowels):
del word[i+1]
else:
i += 1
print(''.join(word))
|
Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word *s*. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
Output Specification:
Output the word *s* after the correction.
Demo Input:
['5\nweird\n', '4\nword\n', '5\naaeaa\n']
Demo Output:
['werd\n', 'word\n', 'a\n']
Note:
Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a.
|
```python
q = int(input())
word = list(input())
vowels = ['a', 'e', 'i', 'o', 'u', 'Y', 'A', 'E', 'I', 'O', 'U', 'Y']
i = 0
while i < len(word)-1:
if (word[i] in vowels and word[i+1] in vowels):
del word[i+1]
else:
i += 1
print(''.join(word))
```
| 0
|
|
266
|
A
|
Stones on the Table
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
|
Print a single integer — the answer to the problem.
|
[
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] |
[
"1\n",
"4\n",
"0\n"
] |
none
| 500
|
[
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "4\nRBBR",
"output": "1"
},
{
"input": "5\nRGGBG",
"output": "1"
},
{
"input": "10\nGGBRBRGGRB",
"output": "2"
},
{
"input": "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB",
"output": "18"
},
{
"input": "15\nBRRBRGGBBRRRRGR",
"output": "6"
},
{
"input": "20\nRRGBBRBRGRGBBGGRGRRR",
"output": "6"
},
{
"input": "25\nBBGBGRBGGBRRBGRRBGGBBRBRB",
"output": "6"
},
{
"input": "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB",
"output": "9"
},
{
"input": "35\nGBBGBRGBBGGRBBGBRRGGRRRRRRRBRBBRRGB",
"output": "14"
},
{
"input": "40\nGBBRRGBGGGRGGGRRRRBRBGGBBGGGBGBBBBBRGGGG",
"output": "20"
},
{
"input": "45\nGGGBBRBBRRGRBBGGBGRBRGGBRBRGBRRGBGRRBGRGRBRRG",
"output": "11"
},
{
"input": "50\nRBGGBGGRBGRBBBGBBGRBBBGGGRBBBGBBBGRGGBGGBRBGBGRRGG",
"output": "17"
},
{
"input": "50\nGGGBBRGGGGGRRGGRBGGRGBBRBRRBGRGBBBGBRBGRGBBGRGGBRB",
"output": "16"
},
{
"input": "50\nGBGRGRRBRRRRRGGBBGBRRRBBBRBBBRRGRBBRGBRBGGRGRBBGGG",
"output": "19"
},
{
"input": "10\nGRRBRBRBGR",
"output": "1"
},
{
"input": "10\nBRBGBGRRBR",
"output": "1"
},
{
"input": "20\nGBGBGGRRRRGRBBGRGRGR",
"output": "5"
},
{
"input": "20\nRRGGRBBGBBRBGRRBRRBG",
"output": "6"
},
{
"input": "30\nBGBRGBBBGRGBBRGBGRBBBRGGRRGRRB",
"output": "8"
},
{
"input": "30\nBBBBGGBRBGBBGBGBGBGGGRGRRGGBBB",
"output": "11"
},
{
"input": "40\nGBRRGRBGBRRGBRGGGBRGBGBRGBBRRGRGGBBGBGBB",
"output": "9"
},
{
"input": "40\nBRGRGGRGGRBBRRRBRBBGGGRRGBGBBGRBBRGBRRGG",
"output": "13"
},
{
"input": "50\nRBGBGGRRGGRGGBGBGRRBGGBGBRRBBGBBGBBBGBBRBBRBRBRGRG",
"output": "13"
},
{
"input": "50\nRBRRGBGRRRBGRRBGRRGRBBRBBRRBRGGBRBRRBGGRBGGBRBRGRB",
"output": "12"
},
{
"input": "2\nBB",
"output": "1"
},
{
"input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "49"
},
{
"input": "50\nRRRRRRRRGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "47"
},
{
"input": "50\nRRRRRRRRRRRRGGRRRRRRRRRBRRRRRRRRRRRRRRBBRRRRRRRRRR",
"output": "43"
}
] | 1,699,197,846
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 62
| 0
|
n = int(input())
s = input()
count = 0
for i in range(0, n-1):
if s[i] == s[i + 1]:
count = count+1
elif s[i] == s[-1]:
print(count)
|
Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n']
Demo Output:
['1\n', '4\n', '0\n']
Note:
none
|
```python
n = int(input())
s = input()
count = 0
for i in range(0, n-1):
if s[i] == s[i + 1]:
count = count+1
elif s[i] == s[-1]:
print(count)
```
| 0
|
|
453
|
A
|
Little Pony and Expected Maximum
|
PROGRAMMING
| 1,600
|
[
"probabilities"
] | null | null |
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times.
|
A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105).
|
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4.
|
[
"6 1\n",
"6 3\n",
"2 2\n"
] |
[
"3.500000000000\n",
"4.958333333333\n",
"1.750000000000\n"
] |
Consider the third test example. If you've made two tosses:
1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
The probability of each outcome is 0.25, that is expectation equals to:
You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value
| 500
|
[
{
"input": "6 1",
"output": "3.500000000000"
},
{
"input": "6 3",
"output": "4.958333333333"
},
{
"input": "2 2",
"output": "1.750000000000"
},
{
"input": "5 4",
"output": "4.433600000000"
},
{
"input": "5 8",
"output": "4.814773760000"
},
{
"input": "3 10",
"output": "2.982641534996"
},
{
"input": "3 6",
"output": "2.910836762689"
},
{
"input": "1 8",
"output": "1.000000000000"
},
{
"input": "24438 9",
"output": "21994.699969310015"
},
{
"input": "94444 9",
"output": "85000.099992058866"
},
{
"input": "8 66716",
"output": "8.000000000000"
},
{
"input": "4 25132",
"output": "4.000000000000"
},
{
"input": "51520 73331",
"output": "51519.682650242677"
},
{
"input": "54230 31747",
"output": "54228.743352775018"
},
{
"input": "24236 90163",
"output": "24235.975171545670"
},
{
"input": "26946 99523",
"output": "26945.974480086279"
},
{
"input": "50323 7",
"output": "44033.124988408454"
},
{
"input": "53033 3",
"output": "39775.249995286234"
},
{
"input": "55743 5",
"output": "46452.999992525307"
},
{
"input": "59964 79",
"output": "59214.949890211828"
},
{
"input": "1 1",
"output": "1.000000000000"
},
{
"input": "1 1",
"output": "1.000000000000"
},
{
"input": "3 1",
"output": "2.000000000000"
},
{
"input": "1 2",
"output": "1.000000000000"
},
{
"input": "53513 34040",
"output": "53511.875329020870"
},
{
"input": "100000 100000",
"output": "99999.418033254507"
},
{
"input": "1 100000",
"output": "1.000000000000"
},
{
"input": "100000 1",
"output": "50000.499999999935"
},
{
"input": "2 100000",
"output": "2.000000000000"
},
{
"input": "100000 2",
"output": "66667.166665000332"
},
{
"input": "50000 100000",
"output": "49999.843487110789"
},
{
"input": "99999 1111",
"output": "99909.571915885972"
},
{
"input": "99999 99999",
"output": "99998.418033254609"
},
{
"input": "1000 1000",
"output": "999.419018443269"
},
{
"input": "50000 50000",
"output": "49999.418043215679"
},
{
"input": "88888 88888",
"output": "88887.418034499773"
},
{
"input": "99999 100000",
"output": "99998.418042461126"
},
{
"input": "100000 555",
"output": "99820.643422392372"
},
{
"input": "10000 10000",
"output": "9999.418122897887"
},
{
"input": "100000 5001",
"output": "99980.503829474910"
},
{
"input": "100000 1000",
"output": "99900.599066768002"
}
] | 1,680,501,805
| 2,147,483,647
|
PyPy 3-64
|
RUNTIME_ERROR
|
TESTS
| 10
| 171
| 2,867,200
|
n,m=map(int,input().split())
ans=0
for r in range(1,n+1):
ans+=((pow(r,m)-pow(r-1,m))*(r/(pow(n,m))))
print(ans)
|
Title: Little Pony and Expected Maximum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times.
Input Specification:
A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105).
Output Specification:
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4.
Demo Input:
['6 1\n', '6 3\n', '2 2\n']
Demo Output:
['3.500000000000\n', '4.958333333333\n', '1.750000000000\n']
Note:
Consider the third test example. If you've made two tosses:
1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
The probability of each outcome is 0.25, that is expectation equals to:
You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value
|
```python
n,m=map(int,input().split())
ans=0
for r in range(1,n+1):
ans+=((pow(r,m)-pow(r-1,m))*(r/(pow(n,m))))
print(ans)
```
| -1
|
|
876
|
B
|
Divisiblity of Differences
|
PROGRAMMING
| 1,300
|
[
"implementation",
"math",
"number theory"
] | null | null |
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
|
First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the numbers in the multiset.
|
If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them.
|
[
"3 2 3\n1 8 4\n",
"3 3 3\n1 8 4\n",
"4 3 5\n2 7 7 7\n"
] |
[
"Yes\n1 4 ",
"No",
"Yes\n2 7 7 "
] |
none
| 1,000
|
[
{
"input": "3 2 3\n1 8 4",
"output": "Yes\n1 4 "
},
{
"input": "3 3 3\n1 8 4",
"output": "No"
},
{
"input": "4 3 5\n2 7 7 7",
"output": "Yes\n2 7 7 "
},
{
"input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825",
"output": "Yes\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825 "
},
{
"input": "15 8 10\n216175135 15241965 611723934 987180005 151601897 403701727 533996295 207637446 875331635 46172555 604086315 350146655 401084142 156540458 982110455",
"output": "Yes\n216175135 15241965 987180005 533996295 875331635 46172555 604086315 350146655 "
},
{
"input": "2 2 100000\n0 1",
"output": "No"
},
{
"input": "101 25 64\n451 230 14 53 7 520 709 102 678 358 166 870 807 230 230 279 166 230 765 176 742 358 924 976 647 806 870 473 976 994 750 146 802 224 503 801 105 614 882 203 390 338 29 587 214 213 405 806 102 102 621 358 521 742 678 205 309 871 796 326 162 693 268 486 68 627 304 829 806 623 748 934 714 672 712 614 587 589 846 260 593 85 839 257 711 395 336 358 472 133 324 527 599 5 845 920 989 494 358 70 882",
"output": "Yes\n230 102 678 358 166 870 230 230 166 230 742 358 806 870 614 806 102 102 358 742 678 486 806 934 614 "
},
{
"input": "108 29 72\n738 619 711 235 288 288 679 36 785 233 706 71 216 144 216 781 338 583 495 648 144 432 72 720 541 288 158 328 154 202 10 533 635 176 707 216 314 397 440 142 326 458 568 701 745 144 61 634 520 720 744 144 409 127 526 476 101 469 72 432 738 432 235 641 695 276 144 144 231 555 630 9 109 319 437 288 288 317 453 432 601 0 449 576 743 352 333 504 504 369 228 288 381 142 500 72 297 359 230 773 216 576 144 244 437 772 483 51",
"output": "Yes\n288 288 216 144 216 648 144 432 72 720 288 216 144 720 144 72 432 432 144 144 288 288 432 0 576 504 504 288 72 "
},
{
"input": "8 2 6\n750462183 165947982 770714338 368445737 363145692 966611485 376672869 678687947",
"output": "Yes\n165947982 363145692 "
},
{
"input": "12 2 1\n512497388 499105388 575265677 864726520 678272195 667107176 809432109 439696443 770034376 873126825 690514828 541499950",
"output": "Yes\n512497388 499105388 "
},
{
"input": "9 3 1\n506004039 471451660 614118177 518013571 43210072 454727076 285905913 543002174 298515615",
"output": "Yes\n506004039 471451660 614118177 "
},
{
"input": "8 4 6\n344417267 377591123 938158786 682031413 804153975 89006697 275945670 735510539",
"output": "No"
},
{
"input": "8 8 1\n314088413 315795280 271532387 241073087 961218399 884234132 419866508 286799253",
"output": "Yes\n314088413 315795280 271532387 241073087 961218399 884234132 419866508 286799253 "
},
{
"input": "7 7 1\n0 0 0 0 0 0 0",
"output": "Yes\n0 0 0 0 0 0 0 "
},
{
"input": "11 4 3\n0 1 0 1 1 0 0 0 0 0 0",
"output": "Yes\n0 0 0 0 "
},
{
"input": "13 4 4\n1 1 0 3 2 4 1 0 3 4 2 4 3",
"output": "Yes\n0 4 0 4 "
},
{
"input": "5 5 1\n6 4 6 0 4",
"output": "Yes\n6 4 6 0 4 "
},
{
"input": "3 2 3\n1 2 3",
"output": "No"
},
{
"input": "6 3 4\n5 9 10 6 7 8",
"output": "No"
},
{
"input": "4 4 3\n4 7 2 5",
"output": "No"
},
{
"input": "4 2 6\n5 5 5 5",
"output": "Yes\n5 5 "
},
{
"input": "4 3 3\n5 1 4 7",
"output": "Yes\n1 4 7 "
},
{
"input": "4 3 10\n0 1 11 11",
"output": "Yes\n1 11 11 "
},
{
"input": "5 2 4\n1 2 2 2 2",
"output": "Yes\n2 2 "
},
{
"input": "5 5 9\n8 17 26 35 44",
"output": "Yes\n8 17 26 35 44 "
},
{
"input": "3 2 2\n1 2 4",
"output": "Yes\n2 4 "
},
{
"input": "5 4 2\n1 3 6 10 12",
"output": "No"
},
{
"input": "3 2 4\n1 2 3",
"output": "No"
},
{
"input": "8 3 5\n1 2 3 4 1 2 3 4",
"output": "No"
},
{
"input": "5 2 9\n8 8 8 8 8",
"output": "Yes\n8 8 "
},
{
"input": "3 3 3\n1 3 6",
"output": "No"
},
{
"input": "5 2 10\n4 5 6 19 29",
"output": "Yes\n19 29 "
},
{
"input": "5 3 3\n3 6 4 7 10",
"output": "Yes\n4 7 10 "
}
] | 1,590,679,562
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 63
| 358
| 9,216,000
|
'''input
3 2 3
1 8 4
'''
from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
from math import gcd
'''
Author : dhanyaabhirami
Hardwork beats talent if talent doesn't work hard
'''
'''
Stuck?
See github resources
Derive Formula
Kmcode blog
CP Algorithms Emaxx
'''
mod=pow(10,9) +7
def inp(flag=0):
if flag==0:
return list(map(int,input().strip().split(' ')))
else:
return int(input())
# Code credits
# assert(debug()==true)
# for _ in range(int(input())):
n,k,m=inp()
l=inp()
d=dd(int)
ans=[]
modulo = []
for i in range(n):
modulo.append(l[i]%m)
d[l[i]%m]+=1
for i in d:
if d[i]>=k:
for j in range(n):
if modulo[j]==i:
ans.append(l[j])
if len(ans)>=k:
print("Yes")
print(*ans[:k])
else:
print("No")
|
Title: Divisiblity of Differences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input Specification:
First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the numbers in the multiset.
Output Specification:
If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them.
Demo Input:
['3 2 3\n1 8 4\n', '3 3 3\n1 8 4\n', '4 3 5\n2 7 7 7\n']
Demo Output:
['Yes\n1 4 ', 'No', 'Yes\n2 7 7 ']
Note:
none
|
```python
'''input
3 2 3
1 8 4
'''
from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
from math import gcd
'''
Author : dhanyaabhirami
Hardwork beats talent if talent doesn't work hard
'''
'''
Stuck?
See github resources
Derive Formula
Kmcode blog
CP Algorithms Emaxx
'''
mod=pow(10,9) +7
def inp(flag=0):
if flag==0:
return list(map(int,input().strip().split(' ')))
else:
return int(input())
# Code credits
# assert(debug()==true)
# for _ in range(int(input())):
n,k,m=inp()
l=inp()
d=dd(int)
ans=[]
modulo = []
for i in range(n):
modulo.append(l[i]%m)
d[l[i]%m]+=1
for i in d:
if d[i]>=k:
for j in range(n):
if modulo[j]==i:
ans.append(l[j])
if len(ans)>=k:
print("Yes")
print(*ans[:k])
else:
print("No")
```
| 3
|
|
1,010
|
A
|
Fly
|
PROGRAMMING
| 1,500
|
[
"binary search",
"math"
] | null | null |
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$.
Flight from $x$ to $y$ consists of two phases: take-off from planet $x$ and landing to planet $y$. This way, the overall itinerary of the trip will be: the $1$-st planet $\to$ take-off from the $1$-st planet $\to$ landing to the $2$-nd planet $\to$ $2$-nd planet $\to$ take-off from the $2$-nd planet $\to$ $\ldots$ $\to$ landing to the $n$-th planet $\to$ the $n$-th planet $\to$ take-off from the $n$-th planet $\to$ landing to the $1$-st planet $\to$ the $1$-st planet.
The mass of the rocket together with all the useful cargo (but without fuel) is $m$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $1$ ton of fuel can lift off $a_i$ tons of rocket from the $i$-th planet or to land $b_i$ tons of rocket onto the $i$-th planet.
For example, if the weight of rocket is $9$ tons, weight of fuel is $3$ tons and take-off coefficient is $8$ ($a_i = 8$), then $1.5$ tons of fuel will be burnt (since $1.5 \cdot 8 = 9 + 3$). The new weight of fuel after take-off will be $1.5$ tons.
Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.
Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
|
The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets.
The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload.
The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted off by one ton of fuel.
The fourth line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le 1000$), where $b_i$ is the number of tons, which can be landed by one ton of fuel.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.
|
If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.
The answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$. Formally, let your answer be $p$, and the jury's answer be $q$. Your answer is considered correct if $\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$.
|
[
"2\n12\n11 8\n7 5\n",
"3\n1\n1 4 1\n2 5 3\n",
"6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n"
] |
[
"10.0000000000\n",
"-1\n",
"85.4800000000\n"
] |
Let's consider the first example.
Initially, the mass of a rocket with fuel is $22$ tons.
- At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fuel can land $5$ tons of cargo, so for landing $20$ tons you will need to burn $4$ tons of fuel. There will be $16$ tons of the rocket with fuel remaining.- While taking off from Mars, one ton of fuel can raise $8$ tons of cargo, so to lift off $16$ tons you will need to burn $2$ tons of fuel. There will be $14$ tons of rocket with fuel after that.- During landing on Earth, one ton of fuel can land $7$ tons of cargo, so for landing $14$ tons you will need to burn $2$ tons of fuel. Remaining weight is $12$ tons, that is, a rocket without any fuel.
In the second case, the rocket will not be able even to take off from Earth.
| 500
|
[
{
"input": "2\n12\n11 8\n7 5",
"output": "10.0000000000"
},
{
"input": "3\n1\n1 4 1\n2 5 3",
"output": "-1"
},
{
"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3",
"output": "85.4800000000"
},
{
"input": "3\n3\n1 2 1\n2 2 2",
"output": "-1"
},
{
"input": "4\n4\n2 3 2 2\n2 3 4 3",
"output": "284.0000000000"
},
{
"input": "5\n2\n1 2 2 1 2\n4 5 1 4 1",
"output": "-1"
},
{
"input": "7\n7\n3 2 6 2 2 2 5\n4 7 5 6 2 2 2",
"output": "4697.0000000000"
},
{
"input": "2\n1000\n12 34\n56 78",
"output": "159.2650775220"
},
{
"input": "8\n4\n1 1 4 1 3 1 8 1\n1 1 1 1 1 3 1 2",
"output": "-1"
},
{
"input": "9\n2\n8 7 1 1 3 7 1 2 4\n4 1 1 8 7 7 1 1 5",
"output": "-1"
},
{
"input": "10\n10\n9 8 8 7 2 10 2 9 2 4\n3 10 6 2 6 6 5 9 4 5",
"output": "3075.7142857143"
},
{
"input": "20\n12\n3 9 12 13 16 18 9 9 19 7 2 5 17 14 7 7 15 16 5 7\n16 9 13 5 14 10 4 3 16 16 12 20 17 11 4 5 5 14 6 15",
"output": "4670.8944493007"
},
{
"input": "30\n5\n25 1 28 1 27 25 24 1 28 1 12 1 29 16 1 1 1 1 27 1 24 1 1 1 1 1 1 1 30 3\n1 22 1 1 24 2 13 1 16 21 1 27 14 16 1 1 7 1 1 18 1 23 10 1 15 16 16 15 10 1",
"output": "-1"
},
{
"input": "40\n13\n1 1 1 23 21 1 1 1 1 1 40 32 1 21 1 8 1 1 36 15 33 1 30 1 1 37 22 1 4 39 7 1 9 37 1 1 1 28 1 1\n1 34 17 1 38 20 8 14 1 18 29 3 21 21 18 14 1 11 1 1 23 1 25 1 14 1 7 31 9 20 25 1 1 1 1 8 26 12 1 1",
"output": "-1"
},
{
"input": "50\n19\n17 7 13 42 19 25 10 25 2 36 17 40 30 48 34 43 34 20 5 15 8 7 43 35 21 40 40 19 30 11 49 7 24 23 43 30 38 49 10 8 30 11 28 50 48 25 25 20 48 24\n49 35 10 22 24 50 50 7 6 13 16 35 12 43 50 44 35 33 38 49 26 18 23 37 7 38 23 20 28 48 41 16 6 32 32 34 11 39 38 9 38 23 16 31 37 47 33 20 46 30",
"output": "7832.1821424977"
},
{
"input": "60\n21\n11 35 1 28 39 13 19 56 13 13 21 25 1 1 23 1 52 26 53 1 1 1 30 39 1 7 1 1 3 1 1 10 1 1 37 1 1 25 1 1 1 53 1 3 48 1 6 5 4 15 1 14 25 53 25 38 27 1 1 1\n1 1 1 35 40 58 10 22 1 56 1 59 1 6 33 1 1 1 1 18 14 1 1 40 25 47 1 34 1 1 53 1 1 25 1 45 1 1 25 34 3 1 1 1 53 27 11 58 1 1 1 10 12 1 1 1 31 52 1 1",
"output": "-1"
},
{
"input": "70\n69\n70 66 57 58 24 60 39 2 48 61 65 22 10 26 68 62 48 25 12 14 45 57 6 30 48 15 46 33 42 28 69 42 64 25 24 8 62 12 68 53 55 20 32 70 3 5 41 49 16 26 2 34 34 20 39 65 18 47 62 31 39 28 61 67 7 14 31 31 53 54\n40 33 24 20 68 20 22 39 53 56 48 38 59 45 47 46 7 69 11 58 61 40 35 38 62 66 18 36 44 48 67 24 14 27 67 63 68 30 50 6 58 7 6 35 20 58 6 12 12 23 14 2 63 27 29 22 49 16 55 40 70 27 27 70 42 38 66 55 69 47",
"output": "217989.4794743629"
},
{
"input": "80\n21\n65 4 26 25 1 1 1 1 1 1 60 1 29 43 48 6 48 13 29 1 1 62 1 1 1 1 1 1 1 26 9 1 22 1 35 13 66 36 1 1 1 38 55 21 70 1 58 70 1 1 38 1 1 20 1 1 51 1 1 28 1 23 11 1 39 47 1 52 41 1 63 1 1 52 1 45 11 10 80 1\n1 1 25 30 1 1 55 54 1 48 10 37 22 1 74 1 78 13 1 65 32 1 1 1 1 69 5 59 1 1 65 1 40 1 31 1 1 75 54 1 60 1 1 1 1 1 1 1 11 29 36 1 72 71 52 1 1 1 37 1 1 75 43 9 53 1 62 1 29 1 40 27 59 74 41 53 19 30 1 73",
"output": "-1"
},
{
"input": "90\n35\n1 68 16 30 24 1 1 1 35 1 1 67 1 1 1 1 33 16 37 77 83 1 77 26 1 1 68 67 70 62 1 47 1 1 1 84 1 65 1 32 83 1 1 1 28 1 71 76 84 1 1 5 1 74 10 1 1 1 38 87 13 1 7 66 81 49 1 9 1 11 1 25 1 1 1 1 7 1 1 36 61 47 51 1 1 69 40 1 37 1\n40 1 21 1 19 51 37 52 64 1 86 1 5 24 1 1 1 19 36 1 1 77 24 4 1 18 89 1 1 1 1 1 29 22 1 80 32 36 6 1 63 1 30 1 1 1 86 79 73 52 9 1 1 11 7 1 25 20 1 20 1 49 1 37 1 41 1 1 1 1 54 55 1 10 1 1 1 1 1 1 66 1 68 1 1 1 1 53 1 1",
"output": "-1"
},
{
"input": "2\n1\n1 1\n1 1",
"output": "-1"
},
{
"input": "2\n1\n1 1\n2 2",
"output": "-1"
},
{
"input": "2\n1\n2 2\n1 1",
"output": "-1"
},
{
"input": "2\n1\n2 2\n2 2",
"output": "15.0000000000"
},
{
"input": "2\n2\n1 1\n1 1",
"output": "-1"
},
{
"input": "2\n2\n1 1\n2 2",
"output": "-1"
},
{
"input": "2\n2\n2 2\n1 1",
"output": "-1"
},
{
"input": "2\n2\n2 2\n2 2",
"output": "30.0000000000"
},
{
"input": "40\n55\n1 382 1 1 1 629 111 689 396 614 1 1 995 148 7 820 913 1 1 169 157 1 702 1 159 1 1 226 1 253 1 319 1 130 1 1 1 466 1 756\n1 23 555 1 412 1 1 373 316 234 888 1 112 818 33 443 313 1 235 1 1 610 110 535 1 445 1 386 1 1 758 1 292 1 862 1 244 428 530 1",
"output": "-1"
},
{
"input": "49\n1\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\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 3 3",
"output": "695580114.6380882263"
},
{
"input": "2\n12\n11 8\n1 1",
"output": "-1"
},
{
"input": "3\n3\n7 11 17\n19 31 33",
"output": "1.6012429470"
}
] | 1,676,553,988
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 76
| 77
| 1,536,000
|
n = int(input())
m = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if 1 in a or 1 in b:
print(-1)
else:
t = m/(b[0]-1)
for i in range(n-1, 0, -1):
t += (t+m)/(a[i]-1)
t += (t+m)/(b[i]-1)
t += (t+m)/(a[0]-1)
print(t)
|
Title: Fly
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$.
Flight from $x$ to $y$ consists of two phases: take-off from planet $x$ and landing to planet $y$. This way, the overall itinerary of the trip will be: the $1$-st planet $\to$ take-off from the $1$-st planet $\to$ landing to the $2$-nd planet $\to$ $2$-nd planet $\to$ take-off from the $2$-nd planet $\to$ $\ldots$ $\to$ landing to the $n$-th planet $\to$ the $n$-th planet $\to$ take-off from the $n$-th planet $\to$ landing to the $1$-st planet $\to$ the $1$-st planet.
The mass of the rocket together with all the useful cargo (but without fuel) is $m$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $1$ ton of fuel can lift off $a_i$ tons of rocket from the $i$-th planet or to land $b_i$ tons of rocket onto the $i$-th planet.
For example, if the weight of rocket is $9$ tons, weight of fuel is $3$ tons and take-off coefficient is $8$ ($a_i = 8$), then $1.5$ tons of fuel will be burnt (since $1.5 \cdot 8 = 9 + 3$). The new weight of fuel after take-off will be $1.5$ tons.
Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.
Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
Input Specification:
The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets.
The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload.
The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted off by one ton of fuel.
The fourth line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le 1000$), where $b_i$ is the number of tons, which can be landed by one ton of fuel.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.
Output Specification:
If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.
The answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$. Formally, let your answer be $p$, and the jury's answer be $q$. Your answer is considered correct if $\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$.
Demo Input:
['2\n12\n11 8\n7 5\n', '3\n1\n1 4 1\n2 5 3\n', '6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n']
Demo Output:
['10.0000000000\n', '-1\n', '85.4800000000\n']
Note:
Let's consider the first example.
Initially, the mass of a rocket with fuel is $22$ tons.
- At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fuel can land $5$ tons of cargo, so for landing $20$ tons you will need to burn $4$ tons of fuel. There will be $16$ tons of the rocket with fuel remaining.- While taking off from Mars, one ton of fuel can raise $8$ tons of cargo, so to lift off $16$ tons you will need to burn $2$ tons of fuel. There will be $14$ tons of rocket with fuel after that.- During landing on Earth, one ton of fuel can land $7$ tons of cargo, so for landing $14$ tons you will need to burn $2$ tons of fuel. Remaining weight is $12$ tons, that is, a rocket without any fuel.
In the second case, the rocket will not be able even to take off from Earth.
|
```python
n = int(input())
m = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if 1 in a or 1 in b:
print(-1)
else:
t = m/(b[0]-1)
for i in range(n-1, 0, -1):
t += (t+m)/(a[i]-1)
t += (t+m)/(b[i]-1)
t += (t+m)/(a[0]-1)
print(t)
```
| 3
|
|
472
|
A
|
Design Tutorial: Learn from Math
|
PROGRAMMING
| 800
|
[
"math",
"number theory"
] | null | null |
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
|
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
|
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
|
[
"12\n",
"15\n",
"23\n",
"1000000\n"
] |
[
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] |
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
| 500
|
[
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
{
"input": "192",
"output": "4 188"
},
{
"input": "86",
"output": "4 82"
},
{
"input": "46220",
"output": "4 46216"
},
{
"input": "57114",
"output": "4 57110"
},
{
"input": "869",
"output": "4 865"
},
{
"input": "738457",
"output": "4 738453"
},
{
"input": "58113",
"output": "6 58107"
},
{
"input": "4864",
"output": "4 4860"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "74752",
"output": "4 74748"
},
{
"input": "6073",
"output": "4 6069"
},
{
"input": "1289",
"output": "4 1285"
},
{
"input": "20",
"output": "4 16"
},
{
"input": "58134",
"output": "4 58130"
},
{
"input": "57756",
"output": "4 57752"
},
{
"input": "765",
"output": "6 759"
},
{
"input": "59",
"output": "4 55"
},
{
"input": "991666",
"output": "4 991662"
},
{
"input": "70761",
"output": "4 70757"
},
{
"input": "13",
"output": "4 9"
},
{
"input": "999999",
"output": "4 999995"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "21",
"output": "6 15"
},
{
"input": "19",
"output": "4 15"
},
{
"input": "100007",
"output": "6 100001"
},
{
"input": "999987",
"output": "6 999981"
},
{
"input": "22",
"output": "4 18"
}
] | 1,693,521,532
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 31
| 0
|
n = int(input())
print(f"2 {n-2}")
|
Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
Input Specification:
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output Specification:
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
Demo Input:
['12\n', '15\n', '23\n', '1000000\n']
Demo Output:
['4 8\n', '6 9\n', '8 15\n', '500000 500000\n']
Note:
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
|
```python
n = int(input())
print(f"2 {n-2}")
```
| 0
|
|
733
|
A
|
Grasshopper And the String
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.
The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
|
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
|
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
|
[
"ABABBBACFEYUKOTT\n",
"AAA\n"
] |
[
"4",
"1"
] |
none
| 500
|
[
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
"output": "39"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIAEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOI",
"output": "1"
},
{
"input": "KMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVCKMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVC",
"output": "85"
},
{
"input": "QWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZ",
"output": "18"
},
{
"input": "PKLKBWTXVJ",
"output": "11"
},
{
"input": "CFHFPTGMOKXVLJJZJDQW",
"output": "12"
},
{
"input": "TXULTFSBUBFLRNQORMMULWNVLPWTYJXZBPBGAWNX",
"output": "9"
},
{
"input": "DAIUSEAUEUYUWEIOOEIOUYVYYOPEEWEBZOOOAOXUOIEUKYYOJOYAUYUUIYUXOUJLGIYEIIYUOCUAACRY",
"output": "4"
},
{
"input": "VRPHBNWNWVWBWMFJJDCTJQJDJBKSJRZLVQRVVFLTZFSGCGDXCWQVWWWMFVCQHPKXXVRKTGWGPSMQTPKNDQJHNSKLXPCXDJDQDZZD",
"output": "101"
},
{
"input": "SGDDFCDRDWGPNNFBBZZJSPXFYMZKPRXTCHVJSJJBWZXXQMDZBNKDHRGSRLGLRKPMWXNSXJPNJLDPXBSRCQMHJKPZNTPNTZXNPCJC",
"output": "76"
},
{
"input": "NVTQVNLGWFDBCBKSDLTBGWBMNQZWZQJWNGVCTCQBGWNTYJRDBPZJHXCXFMIXNRGSTXHQPCHNFQPCMDZWJGLJZWMRRFCVLBKDTDSC",
"output": "45"
},
{
"input": "SREZXQFVPQCLRCQGMKXCBRWKYZKWKRMZGXPMKWNMFZTRDPHJFCSXVPPXWKZMZTBFXGNLPLHZIPLFXNRRQFDTLFPKBGCXKTMCFKKT",
"output": "48"
},
{
"input": "ICKJKMVPDNZPLKDSLTPZNRLSQSGHQJQQPJJSNHNWVDLJRLZEJSXZDPHYXGGWXHLCTVQSKWNWGTLJMOZVJNZPVXGVPJKHFVZTGCCX",
"output": "47"
},
{
"input": "XXFPZDRPXLNHGDVCBDKJMKLGUQZXLLWYLOKFZVGXVNPJWZZZNRMQBRJCZTSDRHSNCVDMHKVXCXPCRBWSJCJWDRDPVZZLCZRTDRYA",
"output": "65"
},
{
"input": "HDDRZDKCHHHEDKHZMXQSNQGSGNNSCCPVJFGXGNCEKJMRKSGKAPQWPCWXXWHLSMRGSJWEHWQCSJJSGLQJXGVTBYALWMLKTTJMFPFS",
"output": "28"
},
{
"input": "PXVKJHXVDPWGLHWFWMJPMCCNHCKSHCPZXGIHHNMYNFQBUCKJJTXXJGKRNVRTQFDFMLLGPQKFOVNNLTNDIEXSARRJKGSCZKGGJCBW",
"output": "35"
},
{
"input": "EXNMTTFPJLDHXDQBJJRDRYBZVFFHUDCHCPNFZWXSMZXNFVJGHZWXVBRQFNUIDVLZOVPXQNVMFNBTJDSCKRLNGXPSADTGCAHCBJKL",
"output": "30"
},
{
"input": "NRNLSQQJGIJBCZFTNKJCXMGPARGWXPSHZXOBNSFOLDQVXTVAGJZNLXULHBRDGMNQKQGWMRRDPYCSNFVPUFTFBUBRXVJGNGSPJKLL",
"output": "19"
},
{
"input": "SRHOKCHQQMVZKTCVQXJJCFGYFXGMBZSZFNAFETXILZHPGHBWZRZQFMGSEYRUDVMCIQTXTBTSGFTHRRNGNTHHWWHCTDFHSVARMCMB",
"output": "30"
},
{
"input": "HBSVZHDKGNIRQUBYKYHUPJCEETGFMVBZJTHYHFQPFBVBSMQACYAVWZXSBGNKWXFNMQJFMSCHJVWBZXZGSNBRUHTHAJKVLEXFBOFB",
"output": "34"
},
{
"input": "NXKMUGOPTUQNSRYTKUKSCWCRQSZKKFPYUMDIBJAHJCEKZJVWZAWOLOEFBFXLQDDPNNZKCQHUPBFVDSXSUCVLMZXQROYQYIKPQPWR",
"output": "17"
},
{
"input": "TEHJDICFNOLQVQOAREVAGUAWODOCXJXIHYXFAEPEXRHPKEIIRCRIVASKNTVYUYDMUQKSTSSBYCDVZKDDHTSDWJWACPCLYYOXGCLT",
"output": "15"
},
{
"input": "LCJJUZZFEIUTMSEXEYNOOAIZMORQDOANAMUCYTFRARDCYHOYOPHGGYUNOGNXUAOYSEMXAZOOOFAVHQUBRNGORSPNQWZJYQQUNPEB",
"output": "9"
},
{
"input": "UUOKAOOJBXUTSMOLOOOOSUYYFTAVBNUXYFVOOGCGZYQEOYISIYOUULUAIJUYVVOENJDOCLHOSOHIHDEJOIGZNIXEMEGZACHUAQFW",
"output": "5"
},
{
"input": "OUUBEHXOOURMOAIAEHXCUOIYHUJEVAWYRCIIAGDRIPUIPAIUYAIWJEVYEYYUYBYOGVYESUJCFOJNUAHIOOKBUUHEJFEWPOEOUHYA",
"output": "4"
},
{
"input": "EMNOYEEUIOUHEWZITIAEZNCJUOUAOQEAUYEIHYUSUYUUUIAEDIOOERAEIRBOJIEVOMECOGAIAIUIYYUWYIHIOWVIJEYUEAFYULSE",
"output": "5"
},
{
"input": "BVOYEAYOIEYOREJUYEUOEOYIISYAEOUYAAOIOEOYOOOIEFUAEAAESUOOIIEUAAGAEISIAPYAHOOEYUJHUECGOYEIDAIRTBHOYOYA",
"output": "5"
},
{
"input": "GOIEOAYIEYYOOEOAIAEOOUWYEIOTNYAANAYOOXEEOEAVIOIAAIEOIAUIAIAAUEUAOIAEUOUUZYIYAIEUEGOOOOUEIYAEOSYAEYIO",
"output": "3"
},
{
"input": "AUEAOAYIAOYYIUIOAULIOEUEYAIEYYIUOEOEIEYRIYAYEYAEIIMMAAEAYAAAAEOUICAUAYOUIAOUIAIUOYEOEEYAEYEYAAEAOYIY",
"output": "3"
},
{
"input": "OAIIYEYYAOOEIUOEEIOUOIAEFIOAYETUYIOAAAEYYOYEYOEAUIIUEYAYYIIAOIEEYGYIEAAOOWYAIEYYYIAOUUOAIAYAYYOEUEOY",
"output": "2"
},
{
"input": "EEEAOEOEEIOUUUEUEAAOEOIUYJEYAIYIEIYYEAUOIIYIUOOEUCYEOOOYYYIUUAYIAOEUEIEAOUOIAACAOOUAUIYYEAAAOOUYIAAE",
"output": "2"
},
{
"input": "AYEYIIEUIYOYAYEUEIIIEUYUUAUEUIYAIAAUYONIEYIUIAEUUOUOYYOUUUIUIAEYEOUIIUOUUEOAIUUYAAEOAAEOYUUIYAYRAIII",
"output": "2"
},
{
"input": "YOOAAUUAAAYEUYIUIUYIUOUAEIEEIAUEOAUIIAAIUYEUUOYUIYEAYAAAYUEEOEEAEOEEYYOUAEUYEEAIIYEUEYJOIIYUIOIUOIEE",
"output": "2"
},
{
"input": "UYOIIIAYOOAIUUOOEEUYIOUAEOOEIOUIAIEYOAEAIOOEOOOIUYYUYIAAUIOUYYOOUAUIEYYUOAAUUEAAIEUIAUEUUIAUUOYOAYIU",
"output": "1"
},
{
"input": "ABBABBB",
"output": "4"
},
{
"input": "ABCD",
"output": "4"
},
{
"input": "XXYC",
"output": "3"
},
{
"input": "YYY",
"output": "1"
},
{
"input": "ABABBBBBBB",
"output": "8"
},
{
"input": "YYYY",
"output": "1"
},
{
"input": "YYYYY",
"output": "1"
},
{
"input": "AXXX",
"output": "4"
},
{
"input": "YYYYYYY",
"output": "1"
},
{
"input": "BYYBBB",
"output": "4"
},
{
"input": "YYYYYYYYY",
"output": "1"
},
{
"input": "CAAAAA",
"output": "2"
},
{
"input": "CCCACCCC",
"output": "5"
},
{
"input": "ABABBBACFEYUKOTTTT",
"output": "5"
},
{
"input": "AABBYYYYYYYY",
"output": "3"
},
{
"input": "BYBACYC",
"output": "2"
},
{
"input": "Y",
"output": "1"
},
{
"input": "ABBBBBB",
"output": "7"
},
{
"input": "BACDYDI",
"output": "3"
},
{
"input": "XEXXXXXXXXXXXXXXX",
"output": "16"
},
{
"input": "TTYTT",
"output": "3"
},
{
"input": "AAYBC",
"output": "3"
},
{
"input": "ABABBBACFEYUKOTTTTT",
"output": "6"
},
{
"input": "YYAYY",
"output": "1"
},
{
"input": "YZZY",
"output": "3"
},
{
"input": "YY",
"output": "1"
},
{
"input": "ZZYZZ",
"output": "3"
},
{
"input": "YBBBY",
"output": "4"
},
{
"input": "BBBACCCCCCC",
"output": "8"
},
{
"input": "YBBBBY",
"output": "5"
},
{
"input": "YYYYYYYYYY",
"output": "1"
},
{
"input": "ABABBBBBBBBBBBB",
"output": "13"
}
] | 1,666,382,608
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 6
| 46
| 0
|
vocales = ['A','E','I','O','U','Y']
secuencia_letras = str(input())
indice_vocales = []
for i in range(len(secuencia_letras)):
if secuencia_letras[i] in vocales:
indice_vocales.append(i)
lista_restas = []
if len(indice_vocales) == 0:
cantidad_minima = len(secuencia_letras)
elif len(indice_vocales) == 1:
cantidad_minima = len(secuencia_letras) - indice_vocales[0]
else:
for j in range(len(indice_vocales)):
if j == 0:
lista_restas.append(abs(indice_vocales[j]-indice_vocales[j+1]))
elif j == len(indice_vocales) - 1:
lista_restas.append(abs(indice_vocales[j-1] - indice_vocales[j]))
else:
lista_restas.append(abs(indice_vocales[j]-indice_vocales[j-1]))
lista_restas.append(abs(indice_vocales[j+1]-indice_vocales[j]))
cantidad_minima = max(lista_restas)
if cantidad_minima == 1:
if secuencia_letras[len(secuencia_letras)-1] not in vocales:
cantidad_minima = 2
print(cantidad_minima)
|
Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.
The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
Input Specification:
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Output Specification:
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
Demo Input:
['ABABBBACFEYUKOTT\n', 'AAA\n']
Demo Output:
['4', '1']
Note:
none
|
```python
vocales = ['A','E','I','O','U','Y']
secuencia_letras = str(input())
indice_vocales = []
for i in range(len(secuencia_letras)):
if secuencia_letras[i] in vocales:
indice_vocales.append(i)
lista_restas = []
if len(indice_vocales) == 0:
cantidad_minima = len(secuencia_letras)
elif len(indice_vocales) == 1:
cantidad_minima = len(secuencia_letras) - indice_vocales[0]
else:
for j in range(len(indice_vocales)):
if j == 0:
lista_restas.append(abs(indice_vocales[j]-indice_vocales[j+1]))
elif j == len(indice_vocales) - 1:
lista_restas.append(abs(indice_vocales[j-1] - indice_vocales[j]))
else:
lista_restas.append(abs(indice_vocales[j]-indice_vocales[j-1]))
lista_restas.append(abs(indice_vocales[j+1]-indice_vocales[j]))
cantidad_minima = max(lista_restas)
if cantidad_minima == 1:
if secuencia_letras[len(secuencia_letras)-1] not in vocales:
cantidad_minima = 2
print(cantidad_minima)
```
| 0
|
|
910
|
A
|
The Way to Home
|
PROGRAMMING
| 800
|
[
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null |
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*.
Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1.
|
The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one.
|
If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
|
[
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] |
[
"2\n",
"-1\n",
"3\n",
"4\n"
] |
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two.
| 500
|
[
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
"output": "1"
},
{
"input": "10 7\n1101111011",
"output": "2"
},
{
"input": "10 9\n1110000101",
"output": "1"
},
{
"input": "10 9\n1100000001",
"output": "1"
},
{
"input": "20 5\n11111111110111101001",
"output": "4"
},
{
"input": "20 11\n11100000111000011011",
"output": "2"
},
{
"input": "20 19\n10100000000000000001",
"output": "1"
},
{
"input": "50 13\n10011010100010100111010000010000000000010100000101",
"output": "5"
},
{
"input": "50 8\n11010100000011001100001100010001110000101100110011",
"output": "8"
},
{
"input": "99 4\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111",
"output": "25"
},
{
"input": "99 98\n100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "1"
},
{
"input": "100 5\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "20"
},
{
"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111",
"output": "25"
},
{
"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111101111111011111111111111111111111111111",
"output": "25"
},
{
"input": "100 3\n1111110111111111111111111111111111111111101111111111111111111111111101111111111111111111111111111111",
"output": "34"
},
{
"input": "100 8\n1111111111101110111111111111111111111111111111111111111111111111111111110011111111111111011111111111",
"output": "13"
},
{
"input": "100 7\n1011111111111111111011101111111011111101111111111101111011110111111111111111111111110111111011111111",
"output": "15"
},
{
"input": "100 9\n1101111110111110101111111111111111011001110111011101011111111111010101111111100011011111111010111111",
"output": "12"
},
{
"input": "100 6\n1011111011111111111011010110011001010101111110111111000111011011111110101101110110101111110000100111",
"output": "18"
},
{
"input": "100 7\n1110001111101001110011111111111101111101101001010001101000101100000101101101011111111101101000100001",
"output": "16"
},
{
"input": "100 11\n1000010100011100011011100000010011001111011110100100001011010100011011111001101101110110010110001101",
"output": "10"
},
{
"input": "100 9\n1001001110000011100100000001000110111101101010101001000101001010011001101100110011011110110011011111",
"output": "13"
},
{
"input": "100 7\n1010100001110101111011000111000001110100100110110001110110011010100001100100001110111100110000101001",
"output": "18"
},
{
"input": "100 10\n1110110000000110000000101110100000111000001011100000100110010001110111001010101000011000000001011011",
"output": "12"
},
{
"input": "100 13\n1000000100000000100011000010010000101010011110000000001000011000110100001000010001100000011001011001",
"output": "9"
},
{
"input": "100 11\n1000000000100000010000100001000100000000010000100100000000100100001000000001011000110001000000000101",
"output": "12"
},
{
"input": "100 22\n1000100000001010000000000000000001000000100000000000000000010000000000001000000000000000000100000001",
"output": "7"
},
{
"input": "100 48\n1000000000000000011000000000000000000000000000000001100000000000000000000000000000000000000000000001",
"output": "3"
},
{
"input": "100 48\n1000000000000000000000100000000000000000000000000000000000000000000001000000000000000000100000000001",
"output": "3"
},
{
"input": "100 75\n1000000100000000000000000000000000000000000000000000000000000000000000000000000001000000000000000001",
"output": "3"
},
{
"input": "100 73\n1000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 99\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "1"
},
{
"input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "99"
},
{
"input": "100 2\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111",
"output": "50"
},
{
"input": "100 1\n1111111111111111011111111111111111111111111111111111111111111111111101111111111111111111111111111111",
"output": "-1"
},
{
"input": "100 3\n1111111111111111111111111101111111111111111111111011111111111111111111111111111011111111111111111111",
"output": "33"
},
{
"input": "100 1\n1101111111111111111111101111111111111111111111111111111111111011111111101111101111111111111111111111",
"output": "-1"
},
{
"input": "100 6\n1111111111111111111111101111111101011110001111111111111111110111111111111111111111111110010111111111",
"output": "17"
},
{
"input": "100 2\n1111111101111010110111011011110111101111111011111101010101011111011111111111111011111001101111101111",
"output": "-1"
},
{
"input": "100 8\n1100110101111001101001111000111100110100011110111011001011111110000110101000001110111011100111011011",
"output": "14"
},
{
"input": "100 10\n1000111110100000001001101100000010011100010101001100010011111001001101111110110111101111001010001101",
"output": "11"
},
{
"input": "100 7\n1110000011010001110101011010000011110001000000011101110111010110001000011101111010010001101111110001",
"output": "-1"
},
{
"input": "100 3\n1111010001000001011011000011001111000100101000101101000010111101111000010000011110110011001101010111",
"output": "-1"
},
{
"input": "100 9\n1101010101101100010111011000010100001010000101010011001001100010110110000000010000101000000001101101",
"output": "13"
},
{
"input": "100 14\n1010100000000000010101000010001100000000000011100010000001000001011010001110001010100000100001101101",
"output": "9"
},
{
"input": "100 13\n1000000001101001110000010000011001000000000000001010000000100001001010000000000000000100010000000001",
"output": "-1"
},
{
"input": "100 18\n1000000000000000110000000000000000010000000001000001000001000000000100000000000010000000000000000001",
"output": "-1"
},
{
"input": "100 32\n1000000000000000000000000001000000000000000000000101000000000000000000000000000000000001000000000001",
"output": "-1"
},
{
"input": "100 79\n1000000001000000000101000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 41\n1000000000000000000000000000000000010000000000000000000000000000000000000000100000000000000000000001",
"output": "3"
},
{
"input": "100 82\n1000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 96\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "-1"
},
{
"input": "43 30\n1001000001111111010100100100110101011101101",
"output": "2"
},
{
"input": "7 1\n1111111",
"output": "6"
},
{
"input": "9 3\n101000001",
"output": "-1"
},
{
"input": "10 3\n1100000001",
"output": "-1"
},
{
"input": "8 2\n10000101",
"output": "-1"
},
{
"input": "2 1\n11",
"output": "1"
}
] | 1,678,475,445
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 63
| 46
| 0
|
n,d = map(int,input().split())
path = input()
count = 0
x = 0
preArr = [0]
for i in range(1,n):
if path[i] == '1':
preArr.append(i)
else:
preArr.append(preArr[i-1])
while x!=(n-1):
# y = path[:x+d+1].rfind('1')
y = preArr[min(n-1,x+d)]
if x == y:
count = -1
break
else:
count += 1
x = y
print(count)
|
Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*.
Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1.
Input Specification:
The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one.
Output Specification:
If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
Demo Input:
['8 4\n10010101\n', '4 2\n1001\n', '8 4\n11100101\n', '12 3\n101111100101\n']
Demo Output:
['2\n', '-1\n', '3\n', '4\n']
Note:
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two.
|
```python
n,d = map(int,input().split())
path = input()
count = 0
x = 0
preArr = [0]
for i in range(1,n):
if path[i] == '1':
preArr.append(i)
else:
preArr.append(preArr[i-1])
while x!=(n-1):
# y = path[:x+d+1].rfind('1')
y = preArr[min(n-1,x+d)]
if x == y:
count = -1
break
else:
count += 1
x = y
print(count)
```
| 3
|
|
602
|
B
|
Approximating a Constant Range
|
PROGRAMMING
| 1,400
|
[
"dp",
"implementation",
"two pointers"
] | null | null |
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it?
You're given a sequence of *n* data points *a*1,<=...,<=*a**n*. There aren't any big jumps between consecutive data points — for each 1<=≤<=*i*<=<<=*n*, it's guaranteed that |*a**i*<=+<=1<=-<=*a**i*|<=≤<=1.
A range [*l*,<=*r*] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let *M* be the maximum and *m* the minimum value of *a**i* for *l*<=≤<=*i*<=≤<=*r*; the range [*l*,<=*r*] is almost constant if *M*<=-<=*m*<=≤<=1.
Find the length of the longest almost constant range.
|
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000).
|
Print a single number — the maximum length of an almost constant range of the given sequence.
|
[
"5\n1 2 3 3 2\n",
"11\n5 4 5 5 6 7 8 8 8 7 6\n"
] |
[
"4\n",
"5\n"
] |
In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.
In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].
| 1,000
|
[
{
"input": "5\n1 2 3 3 2",
"output": "4"
},
{
"input": "11\n5 4 5 5 6 7 8 8 8 7 6",
"output": "5"
},
{
"input": "2\n3 2",
"output": "2"
},
{
"input": "4\n1001 1000 1000 1001",
"output": "4"
},
{
"input": "4\n1 1 2 3",
"output": "3"
},
{
"input": "3\n1 2 1",
"output": "3"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "18\n10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9",
"output": "3"
},
{
"input": "3\n1 2 2",
"output": "3"
},
{
"input": "4\n10 9 10 9",
"output": "4"
},
{
"input": "4\n4 3 2 3",
"output": "3"
},
{
"input": "4\n8 8 7 7",
"output": "4"
},
{
"input": "3\n99998 99999 100000",
"output": "2"
},
{
"input": "3\n100000 99999 99998",
"output": "2"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "2\n99999 100000",
"output": "2"
},
{
"input": "2\n100000 100000",
"output": "2"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "15\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "15"
}
] | 1,691,782,033
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 31
| 0
|
n = int(input())
a = list(map(int, input().split()))
c = [0]*(max(a)+2)
i, kq, k = 0, 0, 0
for j in range(n):
c[a[j]] += 1
if c[a[j]] == 1:
k += 1
while k > 2:
c[a[i]] -= 1
if [a[i]] == 0:
k-= 1
i += 1
if k <= 2:
kq = max(kq, j-i+1)
print(kg)
#dd
|
Title: Approximating a Constant Range
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it?
You're given a sequence of *n* data points *a*1,<=...,<=*a**n*. There aren't any big jumps between consecutive data points — for each 1<=≤<=*i*<=<<=*n*, it's guaranteed that |*a**i*<=+<=1<=-<=*a**i*|<=≤<=1.
A range [*l*,<=*r*] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let *M* be the maximum and *m* the minimum value of *a**i* for *l*<=≤<=*i*<=≤<=*r*; the range [*l*,<=*r*] is almost constant if *M*<=-<=*m*<=≤<=1.
Find the length of the longest almost constant range.
Input Specification:
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000).
Output Specification:
Print a single number — the maximum length of an almost constant range of the given sequence.
Demo Input:
['5\n1 2 3 3 2\n', '11\n5 4 5 5 6 7 8 8 8 7 6\n']
Demo Output:
['4\n', '5\n']
Note:
In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.
In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].
|
```python
n = int(input())
a = list(map(int, input().split()))
c = [0]*(max(a)+2)
i, kq, k = 0, 0, 0
for j in range(n):
c[a[j]] += 1
if c[a[j]] == 1:
k += 1
while k > 2:
c[a[i]] -= 1
if [a[i]] == 0:
k-= 1
i += 1
if k <= 2:
kq = max(kq, j-i+1)
print(kg)
#dd
```
| -1
|
|
1,000
|
A
|
Codehorses T-shirts
|
PROGRAMMING
| 1,200
|
[
"greedy",
"implementation"
] | null | null |
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners.
The valid sizes of T-shirts are either "M" or from $0$ to $3$ "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not.
There are $n$ winners to the cup for both the previous year and the current year. Ksenia has a list with the T-shirt sizes printed for the last year cup and is yet to send the new list to the printing office.
Organizers want to distribute the prizes as soon as possible, so now Ksenia is required not to write the whole list from the scratch but just make some changes to the list of the previous year. In one second she can choose arbitrary position in any word and replace its character with some uppercase Latin letter. Ksenia can't remove or add letters in any of the words.
What is the minimal number of seconds Ksenia is required to spend to change the last year list to the current one?
The lists are unordered. That means, two lists are considered equal if and only if the number of occurrences of any string is the same in both lists.
|
The first line contains one integer $n$ ($1 \le n \le 100$) — the number of T-shirts.
The $i$-th of the next $n$ lines contains $a_i$ — the size of the $i$-th T-shirt of the list for the previous year.
The $i$-th of the next $n$ lines contains $b_i$ — the size of the $i$-th T-shirt of the list for the current year.
It is guaranteed that all the sizes in the input are valid. It is also guaranteed that Ksenia can produce list $b$ from the list $a$.
|
Print the minimal number of seconds Ksenia is required to spend to change the last year list to the current one. If the lists are already equal, print 0.
|
[
"3\nXS\nXS\nM\nXL\nS\nXS\n",
"2\nXXXL\nXXL\nXXL\nXXXS\n",
"2\nM\nXS\nXS\nM\n"
] |
[
"2\n",
"1\n",
"0\n"
] |
In the first example Ksenia can replace "M" with "S" and "S" in one of the occurrences of "XS" with "L".
In the second example Ksenia should replace "L" in "XXXL" with "S".
In the third example lists are equal.
| 0
|
[
{
"input": "3\nXS\nXS\nM\nXL\nS\nXS",
"output": "2"
},
{
"input": "2\nXXXL\nXXL\nXXL\nXXXS",
"output": "1"
},
{
"input": "2\nM\nXS\nXS\nM",
"output": "0"
},
{
"input": "1\nXXXL\nXXXL",
"output": "0"
},
{
"input": "1\nM\nM",
"output": "0"
},
{
"input": "4\nS\nL\nXXS\nXXS\nM\nL\nXXS\nXXL",
"output": "2"
},
{
"input": "5\nXS\nXXXS\nL\nXS\nM\nXL\nS\nXS\nM\nXXXL",
"output": "3"
},
{
"input": "1\nS\nM",
"output": "1"
},
{
"input": "26\nS\nL\nM\nL\nS\nXXXS\nXXXS\nM\nXXXS\nXXXS\nM\nXXS\nM\nXXXL\nM\nXL\nXXXL\nXXXS\nXXL\nL\nM\nM\nL\nXL\nXS\nXXL\nXS\nXXXS\nXL\nXXXL\nXXXL\nL\nL\nXXXS\nL\nL\nXXL\nXXXS\nL\nM\nM\nXXL\nS\nL\nXXL\nXXXS\nL\nS\nL\nL\nXL\nXXXL",
"output": "7"
},
{
"input": "43\nL\nXXXL\nM\nXS\nL\nXXL\nS\nL\nM\nXXXL\nXXS\nS\nXS\nS\nXS\nXL\nXXL\nXXL\nXS\nXXS\nXXL\nL\nXXXL\nL\nL\nXXL\nXXL\nM\nXXXS\nM\nXXL\nXXXS\nXXXL\nXXS\nL\nL\nXS\nL\nXS\nXS\nL\nXXL\nM\nXXXL\nXXL\nXXL\nXL\nL\nXS\nM\nXL\nXXXS\nXXXS\nS\nXXL\nXXXL\nXXL\nXS\nXXS\nL\nS\nXXXS\nXL\nL\nXL\nXXXS\nM\nL\nXXL\nL\nXL\nM\nM\nL\nXXS\nS\nXXS\nXS\nXXL\nL\nM\nS\nL\nXXS\nXXS\nM",
"output": "10"
},
{
"input": "5\nXXXL\nXXL\nXL\nL\nM\nXXXS\nXXS\nXS\nS\nM",
"output": "4"
},
{
"input": "1\nL\nM",
"output": "1"
},
{
"input": "2\nL\nS\nS\nM",
"output": "1"
},
{
"input": "13\nS\nM\nL\nS\nL\nL\nXL\nS\nXL\nXXL\nXL\nXXL\nM\nM\nXS\nM\nXXL\nL\nM\nXXS\nXS\nM\nS\nS\nXS\nL",
"output": "6"
},
{
"input": "14\nXXL\nS\nS\nXXXL\nXL\nXXXS\nXS\nS\nS\nXL\nM\nXXXS\nM\nS\nL\nXXS\nXXXS\nS\nL\nXL\nL\nXXXL\nXS\nXL\nS\nM\nS\nXXXS",
"output": "4"
},
{
"input": "2\nL\nM\nS\nL",
"output": "1"
},
{
"input": "9\nM\nXXL\nXL\nL\nS\nXS\nXXL\nXL\nXXS\nS\nXXL\nXS\nXS\nS\nXXL\nXL\nXXS\nM",
"output": "2"
},
{
"input": "6\nM\nXXS\nXXL\nXXL\nL\nL\nXXS\nXXL\nS\nXXS\nL\nL",
"output": "2"
},
{
"input": "1\nL\nS",
"output": "1"
},
{
"input": "11\nM\nS\nS\nXXXS\nS\nXXXS\nM\nM\nL\nXXXL\nXL\nXXXL\nM\nM\nL\nXXXS\nXXXS\nL\nM\nL\nM\nXS",
"output": "4"
},
{
"input": "8\nXL\nXS\nS\nXXXL\nXXXL\nXL\nXXXL\nS\nXS\nXXXS\nXL\nL\nXXXS\nM\nXS\nXXXL",
"output": "5"
},
{
"input": "2\nL\nL\nM\nM",
"output": "2"
},
{
"input": "6\nL\nS\nXS\nM\nXL\nXXS\nXS\nM\nL\nXL\nXXL\nL",
"output": "2"
},
{
"input": "2\nL\nS\nM\nL",
"output": "1"
},
{
"input": "6\nXXL\nXXS\nXXXS\nL\nXXXS\nXXXL\nXXL\nL\nXXS\nXXXS\nXXXL\nXXXL",
"output": "1"
},
{
"input": "5\nXXS\nXXS\nXXL\nXXXS\nL\nXXS\nXXXL\nS\nXXS\nXXS",
"output": "3"
},
{
"input": "8\nXXL\nS\nXXS\nXXXS\nXXXL\nXL\nXXL\nS\nXXXS\nM\nXXS\nXXL\nXXS\nXXXL\nS\nXS",
"output": "3"
},
{
"input": "3\nL\nL\nM\nL\nM\nS",
"output": "1"
},
{
"input": "5\nXXXL\nXXXS\nXXXL\nXL\nL\nXXXS\nS\nXS\nXXXL\nXXXS",
"output": "3"
},
{
"input": "10\nXXXS\nXXXL\nXXL\nM\nXXXS\nXS\nL\nXL\nXXS\nM\nM\nM\nXL\nXXL\nXXXS\nXL\nXXXS\nXXXS\nL\nXXS",
"output": "2"
},
{
"input": "2\nM\nL\nM\nS",
"output": "1"
},
{
"input": "1\nXXXS\nXXXL",
"output": "1"
},
{
"input": "1\nXS\nXL",
"output": "1"
},
{
"input": "5\nL\nS\nL\nXL\nXL\nXL\nXS\nM\nL\nM",
"output": "3"
}
] | 1,655,401,582
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 37
| 92
| 0
|
import sys
input = sys.stdin.readline
n = int(input())
d = {'S':0, 'L':0, 'M':0, 'XS':0, 'XL':0, 'XXS':0, 'XXL':0, 'XXXS':0, 'XXXL':0}
for i in range(n):
d[input()[:-1]] += 1
for i in range(n):
d[input()[:-1]] -= 1
c = 0
for i in d:
if d[i] > 0:
c += d[i]
print(c)
|
Title: Codehorses T-shirts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners.
The valid sizes of T-shirts are either "M" or from $0$ to $3$ "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not.
There are $n$ winners to the cup for both the previous year and the current year. Ksenia has a list with the T-shirt sizes printed for the last year cup and is yet to send the new list to the printing office.
Organizers want to distribute the prizes as soon as possible, so now Ksenia is required not to write the whole list from the scratch but just make some changes to the list of the previous year. In one second she can choose arbitrary position in any word and replace its character with some uppercase Latin letter. Ksenia can't remove or add letters in any of the words.
What is the minimal number of seconds Ksenia is required to spend to change the last year list to the current one?
The lists are unordered. That means, two lists are considered equal if and only if the number of occurrences of any string is the same in both lists.
Input Specification:
The first line contains one integer $n$ ($1 \le n \le 100$) — the number of T-shirts.
The $i$-th of the next $n$ lines contains $a_i$ — the size of the $i$-th T-shirt of the list for the previous year.
The $i$-th of the next $n$ lines contains $b_i$ — the size of the $i$-th T-shirt of the list for the current year.
It is guaranteed that all the sizes in the input are valid. It is also guaranteed that Ksenia can produce list $b$ from the list $a$.
Output Specification:
Print the minimal number of seconds Ksenia is required to spend to change the last year list to the current one. If the lists are already equal, print 0.
Demo Input:
['3\nXS\nXS\nM\nXL\nS\nXS\n', '2\nXXXL\nXXL\nXXL\nXXXS\n', '2\nM\nXS\nXS\nM\n']
Demo Output:
['2\n', '1\n', '0\n']
Note:
In the first example Ksenia can replace "M" with "S" and "S" in one of the occurrences of "XS" with "L".
In the second example Ksenia should replace "L" in "XXXL" with "S".
In the third example lists are equal.
|
```python
import sys
input = sys.stdin.readline
n = int(input())
d = {'S':0, 'L':0, 'M':0, 'XS':0, 'XL':0, 'XXS':0, 'XXL':0, 'XXXS':0, 'XXXL':0}
for i in range(n):
d[input()[:-1]] += 1
for i in range(n):
d[input()[:-1]] -= 1
c = 0
for i in d:
if d[i] > 0:
c += d[i]
print(c)
```
| 3
|
|
186
|
A
|
Comparing Strings
|
PROGRAMMING
| 1,100
|
[
"implementation",
"strings"
] | null | null |
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.
|
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.
|
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
|
[
"ab\nba\n",
"aa\nab\n"
] |
[
"YES\n",
"NO\n"
] |
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
| 500
|
[
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "YES"
},
{
"input": "qxolmbkkt\naovlajmlf",
"output": "NO"
},
{
"input": "b\ng",
"output": "NO"
},
{
"input": "ab\naba",
"output": "NO"
},
{
"input": "ba\na",
"output": "NO"
},
{
"input": "a\nab",
"output": "NO"
},
{
"input": "a\naa",
"output": "NO"
},
{
"input": "a\nz",
"output": "NO"
},
{
"input": "aabb\nbbaa",
"output": "NO"
},
{
"input": "ab\nbd",
"output": "NO"
},
{
"input": "bac\ndae",
"output": "NO"
},
{
"input": "abc\nakl",
"output": "NO"
},
{
"input": "cb\naa",
"output": "NO"
},
{
"input": "abaab\naabba",
"output": "NO"
},
{
"input": "aab\naaa",
"output": "NO"
},
{
"input": "abcde\nedcba",
"output": "NO"
},
{
"input": "abab\nbaba",
"output": "NO"
},
{
"input": "ab\nbac",
"output": "NO"
},
{
"input": "abcd\naqcb",
"output": "NO"
},
{
"input": "abc\nbad",
"output": "NO"
},
{
"input": "ab\nca",
"output": "NO"
},
{
"input": "abc\nab",
"output": "NO"
},
{
"input": "ab\nbae",
"output": "NO"
},
{
"input": "aaaabcccca\naaaadccccb",
"output": "NO"
},
{
"input": "acaa\nabca",
"output": "NO"
},
{
"input": "aba\naab",
"output": "YES"
},
{
"input": "ah\nla",
"output": "NO"
},
{
"input": "aab\naa",
"output": "NO"
},
{
"input": "abab\nabcd",
"output": "NO"
},
{
"input": "ed\nab",
"output": "NO"
}
] | 1,684,053,627
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 31
| 186
| 7,372,800
|
l1=list(input())
l2=list(input())
c=0
if (len(l1)==len(l2)):
for i in range (len(l1)):
if (l1[i]!=l2[i]):
c=c+1
if (c==2):
print('YES')
else:
print('NO')
|
Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.
Input Specification:
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.
Output Specification:
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
Demo Input:
['ab\nba\n', 'aa\nab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
|
```python
l1=list(input())
l2=list(input())
c=0
if (len(l1)==len(l2)):
for i in range (len(l1)):
if (l1[i]!=l2[i]):
c=c+1
if (c==2):
print('YES')
else:
print('NO')
```
| 0
|
|
651
|
A
|
Joysticks
|
PROGRAMMING
| 1,100
|
[
"dp",
"greedy",
"implementation",
"math"
] | null | null |
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
|
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
|
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
|
[
"3 5\n",
"4 4\n"
] |
[
"6\n",
"5\n"
] |
In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.
After that the first joystick is completely discharged and the game is stopped.
| 500
|
[
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "8 8",
"output": "13"
},
{
"input": "7 2",
"output": "7"
},
{
"input": "24 15",
"output": "36"
},
{
"input": "19 30",
"output": "47"
},
{
"input": "15 31",
"output": "44"
},
{
"input": "14 15",
"output": "27"
},
{
"input": "58 33",
"output": "89"
},
{
"input": "15 25",
"output": "38"
},
{
"input": "59 45",
"output": "102"
},
{
"input": "3 73",
"output": "74"
},
{
"input": "48 1",
"output": "47"
},
{
"input": "100 25",
"output": "122"
},
{
"input": "40 49",
"output": "86"
},
{
"input": "85 73",
"output": "155"
},
{
"input": "29 1",
"output": "28"
},
{
"input": "74 25",
"output": "97"
},
{
"input": "24 57",
"output": "78"
},
{
"input": "23 12",
"output": "33"
},
{
"input": "2 99",
"output": "99"
},
{
"input": "98 2",
"output": "97"
},
{
"input": "2 97",
"output": "97"
},
{
"input": "30 54",
"output": "81"
},
{
"input": "32 53",
"output": "82"
},
{
"input": "32 54",
"output": "84"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "1 3",
"output": "2"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "3 2",
"output": "3"
}
] | 1,610,966,868
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 6
| 61
| 0
|
a = list(map(int, input().split()))
n = max(a[0], a[1])
m = min(a[0], a[1])
t = 0
while n > 0 and m > 0:
n -= 2
m += 1
t += 1
if n <= 2:
x = n
n = m
m = x
print(t)
|
Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
Input Specification:
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
Output Specification:
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
Demo Input:
['3 5\n', '4 4\n']
Demo Output:
['6\n', '5\n']
Note:
In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.
After that the first joystick is completely discharged and the game is stopped.
|
```python
a = list(map(int, input().split()))
n = max(a[0], a[1])
m = min(a[0], a[1])
t = 0
while n > 0 and m > 0:
n -= 2
m += 1
t += 1
if n <= 2:
x = n
n = m
m = x
print(t)
```
| 0
|
|
71
|
A
|
Way Too Long Words
|
PROGRAMMING
| 800
|
[
"strings"
] |
A. Way Too Long Words
|
1
|
256
|
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
|
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
|
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
|
[
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] |
[
"word\nl10n\ni18n\np43s\n"
] |
none
| 500
|
[
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,680,180,095
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
n=int(input())
for i in range(n):
str=input()
a=len(str)
if(a>=10)
{
print(str[0],a-2,str[a-1])
}
else{
print(str)
}
|
Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none
|
```python
n=int(input())
for i in range(n):
str=input()
a=len(str)
if(a>=10)
{
print(str[0],a-2,str[a-1])
}
else{
print(str)
}
```
| -1
|
80
|
A
|
Panoramix's Prediction
|
PROGRAMMING
| 800
|
[
"brute force"
] |
A. Panoramix's Prediction
|
2
|
256
|
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
|
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4.
|
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
|
[
"3 5\n",
"7 11\n",
"7 9\n"
] |
[
"YES",
"YES",
"NO"
] |
none
| 500
|
[
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
"output": "YES"
},
{
"input": "5 7",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "11 13",
"output": "YES"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "17 19",
"output": "YES"
},
{
"input": "19 23",
"output": "YES"
},
{
"input": "23 29",
"output": "YES"
},
{
"input": "29 31",
"output": "YES"
},
{
"input": "31 37",
"output": "YES"
},
{
"input": "37 41",
"output": "YES"
},
{
"input": "41 43",
"output": "YES"
},
{
"input": "43 47",
"output": "YES"
},
{
"input": "2 5",
"output": "NO"
},
{
"input": "2 7",
"output": "NO"
},
{
"input": "2 6",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
},
{
"input": "3 6",
"output": "NO"
},
{
"input": "3 7",
"output": "NO"
},
{
"input": "3 9",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 9",
"output": "NO"
},
{
"input": "5 11",
"output": "NO"
},
{
"input": "5 13",
"output": "NO"
},
{
"input": "5 15",
"output": "NO"
},
{
"input": "7 8",
"output": "NO"
},
{
"input": "7 13",
"output": "NO"
},
{
"input": "13 15",
"output": "NO"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "19 21",
"output": "NO"
},
{
"input": "13 20",
"output": "NO"
},
{
"input": "41 49",
"output": "NO"
},
{
"input": "43 49",
"output": "NO"
},
{
"input": "47 50",
"output": "NO"
},
{
"input": "47 49",
"output": "NO"
},
{
"input": "47 48",
"output": "NO"
},
{
"input": "23 25",
"output": "NO"
},
{
"input": "2 50",
"output": "NO"
},
{
"input": "31 33",
"output": "NO"
}
] | 1,676,466,741
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 45
| 124
| 0
|
a = input('')
lista = []
s = 0
div = 0
for j in a.split():
lista.append(int(j))
n = lista[0]
m = lista[1]
for i in range(1, n+1):
div = n%i
if div == 0:
s = s + 1
if s == 2:
while True:
s = 0
n = n + 1
for i in range(1, n+1):
div = n%i
if div == 0:
s = s + 1
if s == 2:
if m == n:
print('YES')
break
else:
print('NO')
break
else:
print('NO')
if s != 2:
print('NO')
|
Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
Input Specification:
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4.
Output Specification:
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
Demo Input:
['3 5\n', '7 11\n', '7 9\n']
Demo Output:
['YES', 'YES', 'NO']
Note:
none
|
```python
a = input('')
lista = []
s = 0
div = 0
for j in a.split():
lista.append(int(j))
n = lista[0]
m = lista[1]
for i in range(1, n+1):
div = n%i
if div == 0:
s = s + 1
if s == 2:
while True:
s = 0
n = n + 1
for i in range(1, n+1):
div = n%i
if div == 0:
s = s + 1
if s == 2:
if m == n:
print('YES')
break
else:
print('NO')
break
else:
print('NO')
if s != 2:
print('NO')
```
| 3.969
|
368
|
B
|
Sereja and Suffixes
|
PROGRAMMING
| 1,100
|
[
"data structures",
"dp"
] | null | null |
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.?
Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
|
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
|
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
|
[
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] |
[
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] |
none
| 1,000
|
[
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\n2\n5\n1\n3"
},
{
"input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2",
"output": "7\n7"
},
{
"input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1",
"output": "7"
},
{
"input": "2 2\n8 4\n1\n1",
"output": "2\n2"
},
{
"input": "1 5\n5\n1\n1\n1\n1\n1",
"output": "1\n1\n1\n1\n1"
},
{
"input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4",
"output": "1\n4\n3\n2\n3\n1\n1"
},
{
"input": "4 3\n9 1 7 1\n1\n4\n2",
"output": "3\n1\n2"
},
{
"input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7",
"output": "4\n3\n2"
},
{
"input": "1 1\n1\n1",
"output": "1"
}
] | 1,698,136,508
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 15
| 0
|
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.reverse();b=set();k=0;x=[]
for i in range(n):
if a[i] not in b:
b.add(a[i])
k+=1
x.append(k)
x.reverse()
print(x)
for i in range(m):
l=int(input())
print(x[l-1])
|
Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.?
Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Output Specification:
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
Demo Input:
['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n']
Demo Output:
['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n']
Note:
none
|
```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.reverse();b=set();k=0;x=[]
for i in range(n):
if a[i] not in b:
b.add(a[i])
k+=1
x.append(k)
x.reverse()
print(x)
for i in range(m):
l=int(input())
print(x[l-1])
```
| 0
|
|
518
|
A
|
Vitaly and Strings
|
PROGRAMMING
| 1,600
|
[
"constructive algorithms",
"strings"
] | null | null |
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase English letters, string *s* is lexicographically smaller than string *t*. Vitaly wondered if there is such string that is lexicographically larger than string *s* and at the same is lexicographically smaller than string *t*. This string should also consist of lowercase English letters and have the length equal to the lengths of strings *s* and *t*.
Let's help Vitaly solve this easy problem!
|
The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and string *s* is lexicographically less than string *t*.
|
If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them.
|
[
"a\nc\n",
"aaa\nzzz\n",
"abcdefg\nabcdefh\n"
] |
[
"b\n",
"kkk\n",
"No such string\n"
] |
String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ... *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, *s*<sub class="lower-index">*i*</sub> < *t*<sub class="lower-index">*i*</sub>.
| 500
|
[
{
"input": "a\nc",
"output": "b"
},
{
"input": "aaa\nzzz",
"output": "kkk"
},
{
"input": "abcdefg\nabcdefh",
"output": "No such string"
},
{
"input": "abcdefg\nabcfefg",
"output": "abcdefh"
},
{
"input": "frt\nfru",
"output": "No such string"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzx\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy"
},
{
"input": "q\nz",
"output": "r"
},
{
"input": "pnzcl\npnzdf",
"output": "pnzcm"
},
{
"input": "vklldrxnfgyorgfpfezvhbouyzzzzz\nvklldrxnfgyorgfpfezvhbouzaaadv",
"output": "vklldrxnfgyorgfpfezvhbouzaaaaa"
},
{
"input": "pkjlxzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\npkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaahr",
"output": "pkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "exoudpymnspkocwszzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nexoudpymnspkocwtaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabml",
"output": "exoudpymnspkocwtaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "anarzvsklmwvovozwnmhklkpcseeogdgauoppmzrukynbjjoxytuvsiecuzfquxnowewebhtuoxepocyeamqfrblpwqiokbcubil\nanarzvsklmwvovozwnmhklkpcseeogdgauoppmzrukynbjjoxytuvsiecuzfquxnowewebhtuoxepocyeamqfrblpwqiokbcubim",
"output": "No such string"
},
{
"input": "uqyugulumzwlxsjnxxkutzqayskrbjoaaekbhckjryhjjllzzz\nuqyugulumzwlxsjnxxkutzqayskrbjoaaekbhckjryhjjlmaaa",
"output": "No such string"
},
{
"input": "esfaeyxpblcrriizhnhfrxnbopqvhwtetgjqavlqdlxexaifgvkqfwzneibhxxdacbzzzzzzzzzzzzzz\nesfaeyxpblcrriizhnhfrxnbopqvhwtetgjqavlqdlxexaifgvkqfwzneibhxxdaccaaaaaaaaaaaatf",
"output": "esfaeyxpblcrriizhnhfrxnbopqvhwtetgjqavlqdlxexaifgvkqfwzneibhxxdaccaaaaaaaaaaaaaa"
},
{
"input": "oisjtilteipnzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\noisjtilteipoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaao",
"output": "oisjtilteipoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "svpoxbsudndfnnpugbouawegyxgtmvqzbewxpcwhopdbwscimgzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nsvpoxbsudndfnnpugbouawegyxgtmvqzbewxpcwhopdbwscimhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "No such string"
},
{
"input": "ddzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\ndeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaao",
"output": "deaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "xqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczdavdzz\nxqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczdavilj",
"output": "xqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczdaveaa"
},
{
"input": "poflpxucohdobeisxfsnkbdzwizjjhgngufssqhmfgmydmmrnuminrvxxamoebhczlwsfefdtnchaisfxkfcovxmvppxnrfawfoq\npoflpxucohdobeisxfsnkbdzwizjjhgngufssqhmfgmydmmrnuminrvxxamoebhczlwsfefdtnchaisfxkfcovxmvppxnrfawujg",
"output": "poflpxucohdobeisxfsnkbdzwizjjhgngufssqhmfgmydmmrnuminrvxxamoebhczlwsfefdtnchaisfxkfcovxmvppxnrfawfor"
},
{
"input": "vonggnmokmvmguwtobkxoqgxkuxtyjmxrygyliohlhwxuxjmlkqcfuxboxjnzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nvonggnmokmvmguwtobkxoqgxkuxtyjmxrygyliohlhwxuxjmlkqcfuxboxjoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac",
"output": "vonggnmokmvmguwtobkxoqgxkuxtyjmxrygyliohlhwxuxjmlkqcfuxboxjoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "bqycw\nquhod",
"output": "bqycx"
},
{
"input": "hceslswecf\nnmxshuymaa",
"output": "hceslswecg"
},
{
"input": "awqtzslxowuaefe\nvujscakjpvxviki",
"output": "awqtzslxowuaeff"
},
{
"input": "lerlcnaogdravnogfogcyoxgi\nojrbithvjdqtempegvqxmgmmw",
"output": "lerlcnaogdravnogfogcyoxgj"
},
{
"input": "jbrhvicytqaivheqeourrlosvnsujsxdinryyawgalidsaufxv\noevvkhujmhagaholrmsatdjjyfmyblvgetpnxgjcilugjsncjs",
"output": "jbrhvicytqaivheqeourrlosvnsujsxdinryyawgalidsaufxw"
},
{
"input": "jrpogrcuhqdpmyzpuabuhaptlxaeiqjxhqkmuzsjbhqxvdtoocrkusaeasqdwlunomwzww\nspvgaswympzlscnumemgiznngnxqgccbubmxgqmaakbnyngkxlxjjsafricchhpecdjgxw",
"output": "jrpogrcuhqdpmyzpuabuhaptlxaeiqjxhqkmuzsjbhqxvdtoocrkusaeasqdwlunomwzwx"
},
{
"input": "mzmhjmfxaxaplzjmjkbyadeweltagyyuzpvrmnyvirjpdmebxyzjvdoezhnayfrvtnccryhkvhcvakcf\nohhhhkujfpjbgouebtmmbzizuhuumvrsqfniwpmxdtzhyiaivdyxhywnqzagicydixjtvbqbevhbqttu",
"output": "mzmhjmfxaxaplzjmjkbyadeweltagyyuzpvrmnyvirjpdmebxyzjvdoezhnayfrvtnccryhkvhcvakcg"
},
{
"input": "cdmwmzutsicpzhcokbbhwktqbomozxvvjlhwdgtiledgurxsfreisgczdwgupzxmjnfyjxcpdwzkggludkcmgppndl\nuvuqvyrnhtyubpevizhjxdvmpueittksrnosmfuuzbimnqussasdjufrthrgjbyzomauaxbvwferfvtmydmwmjaoxg",
"output": "cdmwmzutsicpzhcokbbhwktqbomozxvvjlhwdgtiledgurxsfreisgczdwgupzxmjnfyjxcpdwzkggludkcmgppndm"
},
{
"input": "dpnmrwpbgzvcmrcodwgvvfwpyagdwlngmhrazyvalszhruprxzmwltftxmujfyrrnwzvphgqlcphreumqkytswxziugburwrlyay\nqibcfxdfovoejutaeetbbwrgexdrvqywwmhipxgfrvhzovxkfawpfnpjvlhkyahessodqcclangxefcaixysqijnitevwmpalkzd",
"output": "dpnmrwpbgzvcmrcodwgvvfwpyagdwlngmhrazyvalszhruprxzmwltftxmujfyrrnwzvphgqlcphreumqkytswxziugburwrlyaz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
"output": "No such string"
},
{
"input": "phdvmuwqmvzyurtnshitcypuzbhpceovkibzbhhjwxkdtvqmbpoumeoiztxtvkvsjrlnhowsdmgftuiulzebdigmun\nphdvmuwqmvzyurtnshitcypuzbhpceovkibzbhhjwxkdtvqmbpoumeoiztxtvkvsjrlnhowsdmgftuiulzebdigmuo",
"output": "No such string"
},
{
"input": "hrsantdquixzjyjtqytcmnflnyehzbibkbgkqffgqpkgeuqmbmxzhbjwsnfkizvbcyoghyvnxxjavoahlqjxomtsouzoog\nhrsantdquixzjyjtqytcmnflnyehzbibkbgkqffgqpkgeuqmbmxzhbjwsnfkizvbcyoghyvnxxjavoahlqjxomtsouzooh",
"output": "No such string"
},
{
"input": "kexdbtpkjbwwyibjndbtmwqzolopqitgkomqggojevoankiepxirrcidxldlzsppehmoazdywltmjbxgsxgihwnwpmczjrcwpywl\nkexdbtpkjbwwyibjndbtmwqzolopqitgkomqggojevoankiepxirrcidxldlzsppehmoazdywltmjbxgsxgihwnwpmczjrcwpywm",
"output": "No such string"
},
{
"input": "yijdysvzfcnaedvnecswgoylhzgguxecmucepgstjbdkbjyfdlxxxejkrrxfiuwjpdmdhhqhlqeqzjwudtdryrfkpwfxdjlkowmk\nyijdysvzfcnaedvnecswgoylhzgguxecmucepgstjbdkbjyfdlxxxejkrrxfiuwjpdmdhhqhlqeqzjwudtdryrfkpwfxdjlkowml",
"output": "No such string"
},
{
"input": "a\nb",
"output": "No such string"
},
{
"input": "x\nz",
"output": "y"
},
{
"input": "a\nz",
"output": "b"
},
{
"input": "y\nz",
"output": "No such string"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "No such string"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
},
{
"input": "yzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyz"
},
{
"input": "aaa\naac",
"output": "aab"
},
{
"input": "aaa\naab",
"output": "No such string"
},
{
"input": "zzx\nzzz",
"output": "zzy"
},
{
"input": "zzy\nzzz",
"output": "No such string"
},
{
"input": "aba\naca",
"output": "abb"
},
{
"input": "aaa\nbbb",
"output": "aab"
},
{
"input": "azzz\ncaaa",
"output": "baaa"
}
] | 1,544,859,578
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 124
| 0
|
"""
In reverse order
'z' - > 'a'
First element != 'z' -> break
"""
s = input()
t = input()
result = list(t)
for i in range(len(s) - 1, -1, -1):
if s[i] == 'z':
result[i] = 'a'
else:
result[i] = chr(ord(s[i]) + 1)
break
if ''.join(result) == t:
print('No such string')
else:
print(''.join(result))
|
Title: Vitaly and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase English letters, string *s* is lexicographically smaller than string *t*. Vitaly wondered if there is such string that is lexicographically larger than string *s* and at the same is lexicographically smaller than string *t*. This string should also consist of lowercase English letters and have the length equal to the lengths of strings *s* and *t*.
Let's help Vitaly solve this easy problem!
Input Specification:
The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and string *s* is lexicographically less than string *t*.
Output Specification:
If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them.
Demo Input:
['a\nc\n', 'aaa\nzzz\n', 'abcdefg\nabcdefh\n']
Demo Output:
['b\n', 'kkk\n', 'No such string\n']
Note:
String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ... *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, *s*<sub class="lower-index">*i*</sub> < *t*<sub class="lower-index">*i*</sub>.
|
```python
"""
In reverse order
'z' - > 'a'
First element != 'z' -> break
"""
s = input()
t = input()
result = list(t)
for i in range(len(s) - 1, -1, -1):
if s[i] == 'z':
result[i] = 'a'
else:
result[i] = chr(ord(s[i]) + 1)
break
if ''.join(result) == t:
print('No such string')
else:
print(''.join(result))
```
| 0
|
|
18
|
A
|
Triangle
|
PROGRAMMING
| 1,500
|
[
"brute force",
"geometry"
] |
A. Triangle
|
2
|
64
|
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle to Peter. Peter said that Bob's triangle is not right-angled, but is almost right-angled: the triangle itself is not right-angled, but it is possible to move one of the points exactly by distance 1 so, that all the coordinates remain integer, and the triangle become right-angled. Bob asks you to help him and find out if Peter tricks him. By the given coordinates of the triangle you should find out if it is right-angled, almost right-angled, or neither of these.
|
The first input line contains 6 space-separated integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3 — coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero.
|
If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, output NEITHER.
|
[
"0 0 2 0 0 1\n",
"2 3 4 5 6 6\n",
"-1 0 2 0 0 1\n"
] |
[
"RIGHT\n",
"NEITHER\n",
"ALMOST\n"
] |
none
| 0
|
[
{
"input": "0 0 2 0 0 1",
"output": "RIGHT"
},
{
"input": "2 3 4 5 6 6",
"output": "NEITHER"
},
{
"input": "-1 0 2 0 0 1",
"output": "ALMOST"
},
{
"input": "27 74 85 23 100 99",
"output": "NEITHER"
},
{
"input": "-97 -19 17 62 30 -76",
"output": "NEITHER"
},
{
"input": "28 -15 86 32 98 -41",
"output": "NEITHER"
},
{
"input": "-66 24 8 -29 17 62",
"output": "NEITHER"
},
{
"input": "-83 40 -80 52 -71 43",
"output": "NEITHER"
},
{
"input": "-88 67 -62 37 -49 75",
"output": "NEITHER"
},
{
"input": "58 45 6 22 13 79",
"output": "NEITHER"
},
{
"input": "75 86 -82 89 -37 -35",
"output": "NEITHER"
},
{
"input": "34 74 -2 -95 63 -33",
"output": "NEITHER"
},
{
"input": "-7 63 78 74 -39 -30",
"output": "NEITHER"
},
{
"input": "-49 -99 7 92 61 -28",
"output": "NEITHER"
},
{
"input": "-90 90 87 -92 -40 -26",
"output": "NEITHER"
},
{
"input": "-100 -100 100 -100 0 73",
"output": "NEITHER"
},
{
"input": "39 22 94 25 69 -23",
"output": "NEITHER"
},
{
"input": "100 100 -100 100 1 -73",
"output": "NEITHER"
},
{
"input": "0 0 0 1 1 0",
"output": "RIGHT"
},
{
"input": "-100 -100 100 100 -100 100",
"output": "RIGHT"
},
{
"input": "29 83 35 35 74 65",
"output": "NEITHER"
},
{
"input": "28 -15 86 32 -19 43",
"output": "RIGHT"
},
{
"input": "-28 12 -97 67 -83 -57",
"output": "RIGHT"
},
{
"input": "-83 40 -80 52 -79 39",
"output": "RIGHT"
},
{
"input": "30 8 49 13 25 27",
"output": "RIGHT"
},
{
"input": "23 6 63 -40 69 46",
"output": "RIGHT"
},
{
"input": "49 -7 19 -76 26 3",
"output": "RIGHT"
},
{
"input": "0 0 1 0 2 1",
"output": "ALMOST"
},
{
"input": "0 0 1 0 3 1",
"output": "ALMOST"
},
{
"input": "0 0 1 0 2 2",
"output": "ALMOST"
},
{
"input": "0 0 1 0 4 1",
"output": "NEITHER"
},
{
"input": "0 0 1 0 100 1",
"output": "NEITHER"
},
{
"input": "60 4 90 -53 32 -12",
"output": "ALMOST"
},
{
"input": "52 -34 -37 -63 23 54",
"output": "ALMOST"
},
{
"input": "39 22 95 25 42 -33",
"output": "ALMOST"
},
{
"input": "-10 -11 62 6 -12 -3",
"output": "ALMOST"
},
{
"input": "22 -15 -24 77 -69 -60",
"output": "ALMOST"
},
{
"input": "99 85 90 87 64 -20",
"output": "ALMOST"
},
{
"input": "-50 -37 -93 -6 -80 -80",
"output": "ALMOST"
},
{
"input": "4 -13 4 -49 -24 -13",
"output": "RIGHT"
},
{
"input": "0 -3 -3 -10 4 -7",
"output": "NEITHER"
},
{
"input": "-45 -87 -34 -79 -60 -62",
"output": "NEITHER"
},
{
"input": "-67 49 89 -76 -37 87",
"output": "NEITHER"
},
{
"input": "22 32 -33 -30 -18 68",
"output": "NEITHER"
},
{
"input": "36 1 -17 -54 -19 55",
"output": "ALMOST"
},
{
"input": "55 44 15 14 23 83",
"output": "NEITHER"
},
{
"input": "-19 0 -89 -54 25 -57",
"output": "NEITHER"
},
{
"input": "69 -45 1 11 56 -63",
"output": "NEITHER"
},
{
"input": "72 68 56 72 33 -88",
"output": "RIGHT"
},
{
"input": "59 86 74 -49 77 88",
"output": "RIGHT"
},
{
"input": "-50 0 0 50 0 -50",
"output": "RIGHT"
},
{
"input": "-50 0 0 50 0 -51",
"output": "ALMOST"
},
{
"input": "-50 0 0 50 0 -49",
"output": "ALMOST"
},
{
"input": "-50 0 0 50 1 -50",
"output": "ALMOST"
},
{
"input": "-50 0 0 50 -1 -50",
"output": "ALMOST"
},
{
"input": "-50 0 0 49 0 -50",
"output": "ALMOST"
},
{
"input": "-50 0 0 51 0 -50",
"output": "ALMOST"
},
{
"input": "-50 0 1 50 0 -50",
"output": "ALMOST"
},
{
"input": "-50 0 -1 50 0 -50",
"output": "ALMOST"
},
{
"input": "-50 1 0 50 0 -50",
"output": "ALMOST"
},
{
"input": "-50 -1 0 50 0 -50",
"output": "ALMOST"
},
{
"input": "-51 0 0 50 0 -50",
"output": "ALMOST"
},
{
"input": "-49 0 0 50 0 -50",
"output": "ALMOST"
}
] | 1,565,283,818
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 18
| 216
| 0
|
#https://codeforces.com/problemset/problem/18/A
coordenadas = input().split()
#longitud = len(coordenadas)
x1 = int(coordenadas[0])
y1 = int(coordenadas[1])
x2 = int(coordenadas[2])
y2 = int(coordenadas[3])
x3 = int(coordenadas[4])
y3 = int(coordenadas[5])
#Si x1 es igual a los puntos y1, y2 y x3 se cumple la condicion de triangulo righted
if(x1 == y1 and x1 == y2 and x1 == x3):
print("RIGHT")
else:
#Si a x1 le sumo 1 o resto 1 se deberia igualar a y1, y2 o x3
if(x1-1 == y1 or x1+1 == y1):
if(x1-1 == y2 or x1+1 == y2):
if(x1-1 == x3 or x1+1 == x3):
print("ALMOST")
else:
print("NEITHER")
else:
print("NEITHER")
else:
print("NEITHER")
|
Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle to Peter. Peter said that Bob's triangle is not right-angled, but is almost right-angled: the triangle itself is not right-angled, but it is possible to move one of the points exactly by distance 1 so, that all the coordinates remain integer, and the triangle become right-angled. Bob asks you to help him and find out if Peter tricks him. By the given coordinates of the triangle you should find out if it is right-angled, almost right-angled, or neither of these.
Input Specification:
The first input line contains 6 space-separated integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3 — coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero.
Output Specification:
If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, output NEITHER.
Demo Input:
['0 0 2 0 0 1\n', '2 3 4 5 6 6\n', '-1 0 2 0 0 1\n']
Demo Output:
['RIGHT\n', 'NEITHER\n', 'ALMOST\n']
Note:
none
|
```python
#https://codeforces.com/problemset/problem/18/A
coordenadas = input().split()
#longitud = len(coordenadas)
x1 = int(coordenadas[0])
y1 = int(coordenadas[1])
x2 = int(coordenadas[2])
y2 = int(coordenadas[3])
x3 = int(coordenadas[4])
y3 = int(coordenadas[5])
#Si x1 es igual a los puntos y1, y2 y x3 se cumple la condicion de triangulo righted
if(x1 == y1 and x1 == y2 and x1 == x3):
print("RIGHT")
else:
#Si a x1 le sumo 1 o resto 1 se deberia igualar a y1, y2 o x3
if(x1-1 == y1 or x1+1 == y1):
if(x1-1 == y2 or x1+1 == y2):
if(x1-1 == x3 or x1+1 == x3):
print("ALMOST")
else:
print("NEITHER")
else:
print("NEITHER")
else:
print("NEITHER")
```
| 0
|
9
|
C
|
Hexadecimal's Numbers
|
PROGRAMMING
| 1,200
|
[
"brute force",
"implementation",
"math"
] |
C. Hexadecimal's Numbers
|
1
|
64
|
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.
|
Input data contains the only number *n* (1<=≤<=*n*<=≤<=109).
|
Output the only number — answer to the problem.
|
[
"10\n"
] |
[
"2"
] |
For *n* = 10 the answer includes numbers 1 and 10.
| 0
|
[
{
"input": "10",
"output": "2"
},
{
"input": "20",
"output": "3"
},
{
"input": "72",
"output": "3"
},
{
"input": "99",
"output": "3"
},
{
"input": "100",
"output": "4"
},
{
"input": "101",
"output": "5"
},
{
"input": "102",
"output": "5"
},
{
"input": "111",
"output": "7"
},
{
"input": "112",
"output": "7"
},
{
"input": "745",
"output": "7"
},
{
"input": "23536",
"output": "31"
},
{
"input": "1",
"output": "1"
},
{
"input": "1010011",
"output": "83"
},
{
"input": "312410141",
"output": "511"
},
{
"input": "1000000000",
"output": "512"
},
{
"input": "999999999",
"output": "511"
},
{
"input": "111111111",
"output": "511"
},
{
"input": "101010101",
"output": "341"
},
{
"input": "121212121",
"output": "511"
},
{
"input": "106341103",
"output": "383"
},
{
"input": "901556123",
"output": "511"
},
{
"input": "832513432",
"output": "511"
},
{
"input": "3",
"output": "1"
},
{
"input": "732875234",
"output": "511"
},
{
"input": "7",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "11",
"output": "3"
},
{
"input": "12",
"output": "3"
},
{
"input": "13",
"output": "3"
},
{
"input": "101020101",
"output": "351"
},
{
"input": "111100100",
"output": "484"
},
{
"input": "110110101",
"output": "437"
},
{
"input": "100111001",
"output": "313"
},
{
"input": "100100",
"output": "36"
},
{
"input": "110100102",
"output": "421"
}
] | 1,584,252,314
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 1
| 310
| 0
|
n=int(input())
x=1
count=0
while(1):
t=bin(x)
t=t[2:len(t)]
if int(t)>=n:
count=count+1
break
else:
count=count+1
x=x+1
print(count)
|
Title: Hexadecimal's Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.
Input Specification:
Input data contains the only number *n* (1<=≤<=*n*<=≤<=109).
Output Specification:
Output the only number — answer to the problem.
Demo Input:
['10\n']
Demo Output:
['2']
Note:
For *n* = 10 the answer includes numbers 1 and 10.
|
```python
n=int(input())
x=1
count=0
while(1):
t=bin(x)
t=t[2:len(t)]
if int(t)>=n:
count=count+1
break
else:
count=count+1
x=x+1
print(count)
```
| 0
|
921
|
05
|
Labyrinth-5
|
PROGRAMMING
| 3,200
|
[] | null | null |
See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01).
|
none
|
none
|
[] |
[] |
none
| 83.362
|
[] | 1,518,020,025
| 2,147,483,647
|
Python 3
|
PARTIAL
|
TESTS
| 1
| 30
| 5,632,000
|
print('for-176 for-351 move-down move-right move-up move-right end move-down move-down for-351 move-down move-left move-up move-left end move-down move-down end')
|
Title: Labyrinth-5
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01).
Input Specification:
none
Output Specification:
none
Note:
none
|
```python
print('for-176 for-351 move-down move-right move-up move-right end move-down move-down for-351 move-down move-left move-up move-left end move-down move-down end')
```
| 2
|
|
711
|
A
|
Bus to Udayland
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation"
] | null | null |
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
|
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details.
|
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them.
|
[
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] |
[
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] |
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX
| 500
|
[
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
},
{
"input": "1\nXO|OX",
"output": "NO"
},
{
"input": "1\nOO|OO",
"output": "YES\n++|OO"
},
{
"input": "4\nXO|XX\nXX|XO\nOX|XX\nXO|XO",
"output": "NO"
},
{
"input": "9\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|OO\nOX|OX\nOX|XO\nOX|OX",
"output": "YES\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|++\nOX|OX\nOX|XO\nOX|OX"
},
{
"input": "61\nOX|XX\nOX|XX\nOX|XX\nXO|XO\nXX|XO\nXX|XX\nXX|XX\nOX|XX\nXO|XO\nOX|XO\nXO|OX\nXX|XX\nXX|XX\nOX|OX\nXX|OX\nOX|XO\nOX|XO\nXO|OX\nXO|XX\nOX|XX\nOX|XX\nXO|OX\nXO|XX\nXO|XX\nOX|XX\nXX|XX\nXX|XO\nXO|XX\nXX|XX\nXO|OX\nXX|XO\nXO|XX\nXO|XO\nXO|OX\nXX|OX\nXO|OX\nOX|XX\nXX|OX\nXX|XX\nOX|XO\nOX|XX\nXO|OX\nOX|XX\nOX|XX\nXO|XO\nXO|XX\nOX|XX\nXO|XO\nOX|XX\nXX|XX\nOX|XO\nXO|XO\nXO|XO\nOX|OX\nXX|OX\nXX|OX\nOX|XO\nOX|XX\nOX|OX\nXO|XX\nOX|XX",
"output": "NO"
},
{
"input": "1\nOO|XX",
"output": "YES\n++|XX"
},
{
"input": "10\nOO|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX",
"output": "YES\n++|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX"
},
{
"input": "10\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|OO",
"output": "YES\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|++"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nOO|OX\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\n++|OX\nOX|XO"
},
{
"input": "6\nOO|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX",
"output": "YES\n++|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX"
}
] | 1,646,384,453
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 30
| 0
|
# INput operation
lines=int(input())
seats=[]
for i in range(lines):
seats.append(input().split("|"))
# Output operation
result=""
for i in range(len(seats)):
for j in range(2):
if seats[i][j] =="OO" :
result="Yes"
seats[i][j] = "++"
break
else:
result="No"
if result =="Yes" :
print (result)
break
|
Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details.
Output Specification:
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them.
Demo Input:
['6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', '4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n', '5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n']
Demo Output:
['YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', 'NO\n', 'YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n']
Note:
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX
|
```python
# INput operation
lines=int(input())
seats=[]
for i in range(lines):
seats.append(input().split("|"))
# Output operation
result=""
for i in range(len(seats)):
for j in range(2):
if seats[i][j] =="OO" :
result="Yes"
seats[i][j] = "++"
break
else:
result="No"
if result =="Yes" :
print (result)
break
```
| 0
|
|
294
|
A
|
Shaass and Oskols
|
PROGRAMMING
| 800
|
[
"implementation",
"math"
] | null | null |
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire.
Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away.
Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
|
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
|
On the *i*-th line of the output print the number of birds on the *i*-th wire.
|
[
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] |
[
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] |
none
| 500
|
[
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51",
"output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52"
},
{
"input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1",
"output": "0\n0"
},
{
"input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5",
"output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21"
},
{
"input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0",
"output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95"
},
{
"input": "1\n100\n1\n1 100",
"output": "0"
},
{
"input": "1\n100\n1\n1 1",
"output": "0"
},
{
"input": "1\n50\n1\n1 25",
"output": "0"
},
{
"input": "2\n50 0\n1\n1 1",
"output": "0\n49"
},
{
"input": "1\n10\n0",
"output": "10"
}
] | 1,694,715,637
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 2
| 60
| 0
|
n = int(input())
y= input()
wires= y.split(" ")
for i in range(len(wires)):
wires[i]= int(wires[i])
m=int(input())
for i in range(m) :
z= input()
z=z.split(" ")
x1=int(z[0])
y1=int(z[1])
if(x1+1<=6):
wires[x1]=wires[x1-1]-y1+wires[x1]
if(x1-1>=1) :
wires[x1-2]=y1-1+wires[x1-2]
wires[x1-1]=0
for i in range(n) :
print(wires[i])
|
Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire.
Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away.
Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
Input Specification:
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
Output Specification:
On the *i*-th line of the output print the number of birds on the *i*-th wire.
Demo Input:
['5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n', '3\n2 4 1\n1\n2 2\n']
Demo Output:
['0\n12\n5\n0\n16\n', '3\n0\n3\n']
Note:
none
|
```python
n = int(input())
y= input()
wires= y.split(" ")
for i in range(len(wires)):
wires[i]= int(wires[i])
m=int(input())
for i in range(m) :
z= input()
z=z.split(" ")
x1=int(z[0])
y1=int(z[1])
if(x1+1<=6):
wires[x1]=wires[x1-1]-y1+wires[x1]
if(x1-1>=1) :
wires[x1-2]=y1-1+wires[x1-2]
wires[x1-1]=0
for i in range(n) :
print(wires[i])
```
| -1
|
|
918
|
B
|
Radio Station
|
PROGRAMMING
| 900
|
[
"implementation",
"strings"
] | null | null |
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
|
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers.
|
Print *m* lines, the commands in the configuration file after Dustin did his task.
|
[
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] |
[
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] |
none
| 1,000
|
[
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;",
"output": "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server"
},
{
"input": "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\nfwckqtz 88.28.31.198\nkal 224.226.34.213\nnacuyokm 49.57.13.44\nfouynv 243.18.250.17\ns 45.248.83.247\ne 75.69.23.169\nauwoqlch 100.44.219.187\nlkldjq 46.123.169.140\ngjcylatwzi 46.123.169.140;\ndxfi 88.28.31.198;\ngv 46.123.169.140;\nety 88.28.31.198;\notbmgcrn 46.123.169.140;\nw 112.147.123.173;\np 75.69.23.169;\nvdsnigk 46.123.169.140;\nmmc 46.123.169.140;\ngtc 49.57.13.44;",
"output": "gjcylatwzi 46.123.169.140; #lkldjq\ndxfi 88.28.31.198; #fwckqtz\ngv 46.123.169.140; #lkldjq\nety 88.28.31.198; #fwckqtz\notbmgcrn 46.123.169.140; #lkldjq\nw 112.147.123.173; #ittmcs\np 75.69.23.169; #e\nvdsnigk 46.123.169.140; #lkldjq\nmmc 46.123.169.140; #lkldjq\ngtc 49.57.13.44; #nacuyokm"
},
{
"input": "1 1\nervbfot 185.32.99.2\nzygoumbmx 185.32.99.2;",
"output": "zygoumbmx 185.32.99.2; #ervbfot"
},
{
"input": "1 2\ny 245.182.246.189\nlllq 245.182.246.189;\nxds 245.182.246.189;",
"output": "lllq 245.182.246.189; #y\nxds 245.182.246.189; #y"
},
{
"input": "2 1\ntdwmshz 203.115.124.110\neksckjya 201.80.191.212\nzbtjzzue 203.115.124.110;",
"output": "zbtjzzue 203.115.124.110; #tdwmshz"
},
{
"input": "8 5\nfhgkq 5.19.189.178\nphftablcr 75.18.177.178\nxnpcg 158.231.167.176\ncfahrkq 26.165.124.191\nfkgtnqtfoh 230.13.13.129\nt 101.24.94.85\nvjoirslx 59.6.179.72\ntwktmskb 38.194.117.184\nrvzzlygosc 26.165.124.191;\ndcsgxrkgv 101.24.94.85;\nyvmyppn 59.6.179.72;\ngpdjjuq 75.18.177.178;\nvdviz 101.24.94.85;",
"output": "rvzzlygosc 26.165.124.191; #cfahrkq\ndcsgxrkgv 101.24.94.85; #t\nyvmyppn 59.6.179.72; #vjoirslx\ngpdjjuq 75.18.177.178; #phftablcr\nvdviz 101.24.94.85; #t"
},
{
"input": "2 1\nmain 1.1.1.1\nget 11.1.1.1\ncommand 11.1.1.1;",
"output": "command 11.1.1.1; #get"
},
{
"input": "2 2\nmain 0.0.0.255\nmainn 0.0.2.55\nblock 0.0.0.255;\nblock 0.0.2.55;",
"output": "block 0.0.0.255; #main\nblock 0.0.2.55; #mainn"
},
{
"input": "2 2\nmain 0.0.63.0\nreplica 0.38.0.56\nblock 0.0.63.0;\nproxy 0.38.0.56;",
"output": "block 0.0.63.0; #main\nproxy 0.38.0.56; #replica"
},
{
"input": "2 2\nmain 192.168.10.12\nreplica 192.167.10.12\nblock 192.168.10.12;\nproxy 192.167.10.12;",
"output": "block 192.168.10.12; #main\nproxy 192.167.10.12; #replica"
},
{
"input": "2 1\nneserver 185.218.47.91\nserver 255.255.255.255\nblock 255.255.255.255;",
"output": "block 255.255.255.255; #server"
},
{
"input": "2 1\nalp 22.222.30.10\nbet 222.22.30.10\nblock 22.222.30.10;",
"output": "block 22.222.30.10; #alp"
}
] | 1,627,808,254
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 28
| 77
| 7,065,600
|
n,m=map(int,input().split())
dicn={}
for i in range(n):
value,key=input().split()
dicn[key]=value
for i in range(m):
key,value=input().split()
value=value[0:-1]
print(f'{key} {value}; #{dicn[value]}')
|
Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
Input Specification:
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers.
Output Specification:
Print *m* lines, the commands in the configuration file after Dustin did his task.
Demo Input:
['2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n', '3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n']
Demo Output:
['block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n', 'redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n']
Note:
none
|
```python
n,m=map(int,input().split())
dicn={}
for i in range(n):
value,key=input().split()
dicn[key]=value
for i in range(m):
key,value=input().split()
value=value[0:-1]
print(f'{key} {value}; #{dicn[value]}')
```
| 3
|
|
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,685,887,373
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 35
| 92
| 921,600
|
import sys
import re
import collections
import math
import itertools
class Point(object):
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def function(*args):
y, x = map(int, input().split())
res = []
for _ in range(y):
arr = [int(e) for e in input()]
res.append(arr)
prev = float('inf')
ans = 'YES'
for e in res:
if len(set(e)) > 1 or e[0] == prev:
ans = 'NO'
prev = e[0]
print(ans)
if __name__ == '__main__':
function()
|
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
import sys
import re
import collections
import math
import itertools
class Point(object):
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def function(*args):
y, x = map(int, input().split())
res = []
for _ in range(y):
arr = [int(e) for e in input()]
res.append(arr)
prev = float('inf')
ans = 'YES'
for e in res:
if len(set(e)) > 1 or e[0] == prev:
ans = 'NO'
prev = e[0]
print(ans)
if __name__ == '__main__':
function()
```
| 3.970134
|
526
|
C
|
Om Nom and Candies
|
PROGRAMMING
| 2,000
|
[
"brute force",
"greedy",
"math"
] | null | null |
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place?
One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs *W**r* grams and each blue candy weighs *W**b* grams. Eating a single red candy gives Om Nom *H**r* joy units and eating a single blue candy gives Om Nom *H**b* joy units.
Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than *C* grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.
|
The single line contains five integers *C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b* (1<=≤<=*C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b*<=≤<=109).
|
Print a single integer — the maximum number of joy units that Om Nom can get.
|
[
"10 3 5 2 3\n"
] |
[
"16\n"
] |
In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
| 1,250
|
[
{
"input": "10 3 5 2 3",
"output": "16"
},
{
"input": "5 3 1 6 7",
"output": "0"
},
{
"input": "982068341 55 57 106 109",
"output": "513558662"
},
{
"input": "930064129 32726326 25428197 83013449 64501049",
"output": "363523396"
},
{
"input": "927155987 21197 15994 54746 41309",
"output": "358983713"
},
{
"input": "902303498 609628987 152407246 8 2",
"output": "68758795931537065"
},
{
"input": "942733698 9180 9072 1020 1008",
"output": "8484603228"
},
{
"input": "951102310 39876134 24967176 70096104 43888451",
"output": "539219654"
},
{
"input": "910943911 107 105 60 59",
"output": "1624516635"
},
{
"input": "910943911 38162 31949 67084 56162",
"output": "518210503"
},
{
"input": "910943911 9063 9045 1007 1005",
"output": "8198495199"
},
{
"input": "903796108 270891702 270891702 1 1",
"output": "244830865957095816"
},
{
"input": "936111602 154673223 309346447 1 2",
"output": "144791399037089047"
},
{
"input": "947370735 115930744 347792233 1 3",
"output": "109829394468167085"
},
{
"input": "958629867 96557265 386229061 1 4",
"output": "92562678344491221"
},
{
"input": "969889000 84931386 424656931 1 5",
"output": "82374017230131800"
},
{
"input": "925819493 47350513 28377591 83230978 49881078",
"output": "520855643"
},
{
"input": "934395168 119 105 67 59",
"output": "1662906651"
},
{
"input": "934395168 29208 38362 51342 67432",
"output": "531576348"
},
{
"input": "934395168 9171 9045 1019 1005",
"output": "8409556512"
},
{
"input": "946401698 967136832 483568416 2 1",
"output": "457649970001570368"
},
{
"input": "962693577 967217455 967217455 2 2",
"output": "465567015261784540"
},
{
"input": "989976325 646076560 969114840 2 3",
"output": "319800249268721000"
},
{
"input": "901235456 485501645 971003291 2 4",
"output": "218775648435471424"
},
{
"input": "912494588 389153108 972882772 2 5",
"output": "177550052841687584"
},
{
"input": "995503930 29205027 18903616 51333090 33226507",
"output": "565303099"
},
{
"input": "983935533 115 108 65 61",
"output": "1742049794"
},
{
"input": "983935533 33986 27367 59737 48104",
"output": "559787479"
},
{
"input": "983935533 7105 7056 1015 1008",
"output": "6887548731"
},
{
"input": "994040035 740285170 246761723 3 1",
"output": "245291032098926983"
},
{
"input": "905299166 740361314 493574209 3 2",
"output": "223416160034288041"
},
{
"input": "911525551 740437472 740437472 3 3",
"output": "224975891301803200"
},
{
"input": "922784684 566833132 755777509 3 4",
"output": "174354977531116762"
},
{
"input": "955100178 462665160 771108601 3 5",
"output": "147297192414486195"
},
{
"input": "949164751 36679609 23634069 64467968 41539167",
"output": "537909080"
},
{
"input": "928443151 60 63 106 112",
"output": "525533853"
},
{
"input": "928443151 25031 33442 43995 58778",
"output": "528241752"
},
{
"input": "928443151 1006 1012 1006 1012",
"output": "928443150"
},
{
"input": "936645623 540336743 135084185 4 1",
"output": "126526011319256470"
},
{
"input": "947904756 540408420 270204210 4 2",
"output": "128063927875111380"
},
{
"input": "959163888 540480074 405360055 4 3",
"output": "129602242291091928"
},
{
"input": "970423020 540551739 540551739 4 4",
"output": "131140962756657945"
},
{
"input": "976649406 455467553 569334442 4 5",
"output": "111208028918928288"
},
{
"input": "923881933 18531902 53987967 32570076 94884602",
"output": "524563246"
},
{
"input": "977983517 57 63 101 112",
"output": "551931291"
},
{
"input": "977983517 29808 22786 52389 40047",
"output": "556454318"
},
{
"input": "977983517 9009 9108 1001 1012",
"output": "8801851608"
},
{
"input": "984283960 367291526 73458305 5 1",
"output": "72303831537144592"
},
{
"input": "990510345 367358723 146943489 5 2",
"output": "72774523091497887"
},
{
"input": "901769477 367425909 220455545 5 3",
"output": "66266693959035917"
},
{
"input": "907995862 367493085 293994468 5 4",
"output": "66736440098722854"
},
{
"input": "924287742 367560271 367560271 5 5",
"output": "67946290439275508"
},
{
"input": "1000000000 1000 999 100 1000000000",
"output": "10000000000"
},
{
"input": "999999999 10 499999995 2 99999999",
"output": "4999999995"
},
{
"input": "999999999 1 1000000000 2 1000000000",
"output": "499999999"
},
{
"input": "999999997 2 999999997 2 999999997",
"output": "999999997"
},
{
"input": "1000000000 1 1 11 11",
"output": "90909090"
},
{
"input": "999999999 999999998 5 999999999 5",
"output": "999999998"
},
{
"input": "100000001 3 100000000 3 100000001",
"output": "100000000"
},
{
"input": "999999999 2 3 1 2",
"output": "1999999998"
},
{
"input": "1000000000 2 1 3 4",
"output": "666666666"
},
{
"input": "999999999 10000 494999 2 99",
"output": "4999999994999"
},
{
"input": "1000000000 1 1 1 1",
"output": "1000000000"
},
{
"input": "998999 1000 999 1000 999",
"output": "998999"
},
{
"input": "3 100 101 2 3",
"output": "101"
},
{
"input": "345415838 13999 13997 13999 13997",
"output": "345415838"
},
{
"input": "5000005 3 2 5 1",
"output": "10000010"
},
{
"input": "1000000000 1 1 1 1000000000",
"output": "1000000000"
},
{
"input": "999999999 3 2 10 3",
"output": "666666666"
},
{
"input": "1000000000 1000 1000 1 1",
"output": "1000000000000"
},
{
"input": "200000001 100000002 1 100000001 1",
"output": "200000002"
},
{
"input": "100000000 1000000000 1 100000001 1",
"output": "100000000"
},
{
"input": "1000000000 99 100 1 2",
"output": "99000000000"
},
{
"input": "1000000000 5 5 1 1",
"output": "5000000000"
},
{
"input": "1000000000 1 1000000000 1 1000000000",
"output": "1000000000"
}
] | 1,445,165,218
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 75
| 312
| 2,457,600
|
def main():
c, hr, hb, wr, wb = map(int, input().split())
ans = 0
for i in range(10**6 + 1):
if i * wr <= c:
ans = max(ans, i * hr + ((c - i * wr) // wb) * hb)
if i * wb <= c:
ans = max(ans, i * hb + ((c - i * wb) // wr) * hr)
print(ans)
main()
|
Title: Om Nom and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place?
One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs *W**r* grams and each blue candy weighs *W**b* grams. Eating a single red candy gives Om Nom *H**r* joy units and eating a single blue candy gives Om Nom *H**b* joy units.
Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than *C* grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.
Input Specification:
The single line contains five integers *C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b* (1<=≤<=*C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b*<=≤<=109).
Output Specification:
Print a single integer — the maximum number of joy units that Om Nom can get.
Demo Input:
['10 3 5 2 3\n']
Demo Output:
['16\n']
Note:
In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
|
```python
def main():
c, hr, hb, wr, wb = map(int, input().split())
ans = 0
for i in range(10**6 + 1):
if i * wr <= c:
ans = max(ans, i * hr + ((c - i * wr) // wb) * hb)
if i * wb <= c:
ans = max(ans, i * hb + ((c - i * wb) // wr) * hr)
print(ans)
main()
```
| 3
|
|
999
|
A
|
Mishka and Contest
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation"
] | null | null |
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.
Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list.
How many problems can Mishka solve?
|
The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list.
|
Print one integer — the maximum number of problems Mishka can solve.
|
[
"8 4\n4 2 3 1 5 1 6 4\n",
"5 2\n3 1 2 1 3\n",
"5 100\n12 34 55 43 21\n"
] |
[
"5\n",
"0\n",
"5\n"
] |
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$.
In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
| 0
|
[
{
"input": "8 4\n4 2 3 1 5 1 6 4",
"output": "5"
},
{
"input": "5 2\n3 1 2 1 3",
"output": "0"
},
{
"input": "5 100\n12 34 55 43 21",
"output": "5"
},
{
"input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 18 54 19 71 2 25 33 65 49 53 5 95 90 100 68 25 5 87 48 45 72 34 14 100 44 94 75 80 26 25 7 57 82 49 73 55 43 42 60 34 8 51 11 71 41 81 23 20 89 12 72 68 26 96 92 32 63 13 47 19 9 35 56 79 62",
"output": "100"
},
{
"input": "100 99\n84 82 43 4 71 3 30 92 15 47 76 43 2 17 76 4 1 33 24 96 44 98 75 99 59 11 73 27 67 17 8 88 69 41 44 22 91 48 4 46 42 21 21 67 85 51 57 84 11 100 100 59 39 72 89 82 74 19 98 14 37 97 20 78 38 52 44 83 19 83 69 32 56 6 93 13 98 80 80 2 33 71 11 15 55 51 98 58 16 91 39 32 83 58 77 79 88 81 17 98",
"output": "98"
},
{
"input": "100 69\n80 31 12 89 16 35 8 28 39 12 32 51 42 67 64 53 17 88 63 97 29 41 57 28 51 33 82 75 93 79 57 86 32 100 83 82 99 33 1 27 86 22 65 15 60 100 42 37 38 85 26 43 90 62 91 13 1 92 16 20 100 19 28 30 23 6 5 69 24 22 9 1 10 14 28 14 25 9 32 8 67 4 39 7 10 57 15 7 8 35 62 6 53 59 62 13 24 7 53 2",
"output": "39"
},
{
"input": "100 2\n2 2 2 2 1 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 2 1 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 1 2 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 1 1 2 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 16",
"output": "99"
},
{
"input": "100 3\n86 53 82 40 2 20 59 2 46 63 75 49 24 81 70 22 9 9 93 72 47 23 29 77 78 51 17 59 19 71 35 3 20 60 70 9 11 96 71 94 91 19 88 93 50 49 72 19 53 30 38 67 62 71 81 86 5 26 5 32 63 98 1 97 22 32 87 65 96 55 43 85 56 37 56 67 12 100 98 58 77 54 18 20 33 53 21 66 24 64 42 71 59 32 51 69 49 79 10 1",
"output": "1"
},
{
"input": "13 7\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "13"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "3 2\n1 4 1",
"output": "2"
},
{
"input": "1 2\n100",
"output": "0"
},
{
"input": "7 4\n4 2 3 4 4 2 3",
"output": "7"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "1 2\n15",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "2"
},
{
"input": "5 3\n3 4 3 2 1",
"output": "4"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "1 5\n1",
"output": "1"
},
{
"input": "6 6\n7 1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n6 5 5 5 5",
"output": "4"
},
{
"input": "1 4\n2",
"output": "1"
},
{
"input": "9 4\n1 2 1 2 4 2 1 2 1",
"output": "9"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n5",
"output": "1"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "100 10\n2 5 1 10 10 2 7 7 9 4 1 8 1 1 8 4 7 9 10 5 7 9 5 6 7 2 7 5 3 2 1 82 4 80 9 8 6 1 10 7 5 7 1 5 6 7 19 4 2 4 6 2 1 8 31 6 2 2 57 42 3 2 7 1 9 5 10 8 5 4 10 8 3 5 8 7 2 7 6 5 3 3 4 10 6 7 10 8 7 10 7 2 4 6 8 10 10 2 6 4",
"output": "71"
},
{
"input": "100 90\n17 16 5 51 17 62 24 45 49 41 90 30 19 78 67 66 59 34 28 47 42 8 33 77 90 41 61 16 86 33 43 71 90 95 23 9 56 41 24 90 31 12 77 36 90 67 47 15 92 50 79 88 42 19 21 79 86 60 41 26 47 4 70 62 44 90 82 89 84 91 54 16 90 53 29 69 21 44 18 28 88 74 56 43 12 76 10 22 34 24 27 52 28 76 90 75 5 29 50 90",
"output": "63"
},
{
"input": "100 10\n6 4 8 4 1 9 4 8 5 2 2 5 2 6 10 2 2 5 3 5 2 3 10 5 2 9 1 1 6 1 5 9 16 42 33 49 26 31 81 27 53 63 81 90 55 97 70 51 87 21 79 62 60 91 54 95 26 26 30 61 87 79 47 11 59 34 40 82 37 40 81 2 7 1 8 4 10 7 1 10 8 7 3 5 2 8 3 3 9 2 1 1 5 7 8 7 1 10 9 8",
"output": "61"
},
{
"input": "100 90\n45 57 52 69 17 81 85 60 59 39 55 14 87 90 90 31 41 57 35 89 74 20 53 4 33 49 71 11 46 90 71 41 71 90 63 74 51 13 99 92 99 91 100 97 93 40 93 96 100 99 100 92 98 96 78 91 91 91 91 100 94 97 95 97 96 95 17 13 45 35 54 26 2 74 6 51 20 3 73 90 90 42 66 43 86 28 84 70 37 27 90 30 55 80 6 58 57 51 10 22",
"output": "72"
},
{
"input": "100 10\n10 2 10 10 10 10 10 10 10 7 10 10 10 10 10 10 9 10 10 10 10 10 10 10 10 7 9 10 10 10 37 10 4 10 10 10 59 5 95 10 10 10 10 39 10 10 10 10 10 10 10 5 10 10 10 10 10 10 10 10 10 10 10 10 66 10 10 10 10 10 5 10 10 10 10 10 10 44 10 10 10 10 10 10 10 10 10 10 10 7 10 10 10 10 10 10 10 10 10 2",
"output": "52"
},
{
"input": "100 90\n57 90 90 90 90 90 90 90 81 90 3 90 39 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 92 90 90 90 90 90 90 90 90 98 90 90 90 90 90 90 90 90 90 90 90 90 90 54 90 90 90 90 90 62 90 90 91 90 90 90 90 90 90 91 90 90 90 90 90 90 90 3 90 90 90 90 90 90 90 2 90 90 90 90 90 90 90 90 90 2 90 90 90 90 90",
"output": "60"
},
{
"input": "100 10\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 78 90 61 40 87 39 91 50 64 30 10 24 10 55 28 11 28 35 26 26 10 57 45 67 14 99 96 51 67 79 59 11 21 55 70 33 10 16 92 70 38 50 66 52 5 10 10 10 2 4 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 10 10 10 10 8 10 10 10 10 10",
"output": "56"
},
{
"input": "100 90\n90 90 90 90 90 90 55 21 90 90 90 90 90 90 90 90 90 90 69 83 90 90 90 90 90 90 90 90 93 95 92 98 92 97 91 92 92 91 91 95 94 95 100 100 96 97 94 93 90 90 95 95 97 99 90 95 98 91 94 96 99 99 94 95 95 97 99 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 12 90 3 90 90 90 90 90 90 90",
"output": "61"
},
{
"input": "100 49\n71 25 14 36 36 48 36 49 28 40 49 49 49 38 40 49 33 22 49 49 14 46 8 44 49 11 37 49 40 49 2 49 3 49 37 49 49 11 25 49 49 32 49 11 49 30 16 21 49 49 23 24 30 49 49 49 49 49 49 27 49 42 49 49 20 32 30 29 35 49 30 49 9 49 27 25 5 49 49 42 49 20 49 35 49 22 15 49 49 49 19 49 29 28 13 49 22 7 6 24",
"output": "99"
},
{
"input": "100 50\n38 68 9 6 50 18 19 50 50 20 33 34 43 50 24 50 50 2 50 50 50 50 50 21 30 50 41 40 50 50 50 50 50 7 50 21 19 23 1 50 24 50 50 50 25 50 50 50 50 50 50 50 7 24 28 18 50 5 43 50 20 50 13 50 50 16 50 3 2 24 50 50 18 5 50 4 50 50 38 50 33 49 12 33 11 14 50 50 50 33 50 50 50 50 50 50 7 4 50 50",
"output": "99"
},
{
"input": "100 48\n8 6 23 47 29 48 48 48 48 48 48 26 24 48 48 48 3 48 27 28 41 45 9 29 48 48 48 48 48 48 48 48 48 48 47 23 48 48 48 5 48 22 40 48 48 48 20 48 48 57 48 32 19 48 33 2 4 19 48 48 39 48 16 48 48 44 48 48 48 48 29 14 25 43 46 7 48 19 30 48 18 8 39 48 30 47 35 18 48 45 48 48 30 13 48 48 48 17 9 48",
"output": "99"
},
{
"input": "100 57\n57 9 57 4 43 57 57 57 57 26 57 18 57 57 57 57 57 57 57 47 33 57 57 43 57 57 55 57 14 57 57 4 1 57 57 57 57 57 46 26 57 57 57 57 57 57 57 39 57 57 57 5 57 12 11 57 57 57 25 37 34 57 54 18 29 57 39 57 5 57 56 34 57 24 7 57 57 57 2 57 57 57 57 1 55 39 19 57 57 57 57 21 3 40 13 3 57 57 62 57",
"output": "99"
},
{
"input": "100 51\n51 51 38 51 51 45 51 51 51 18 51 36 51 19 51 26 37 51 11 51 45 34 51 21 51 51 33 51 6 51 51 51 21 47 51 13 51 51 30 29 50 51 51 51 51 51 51 45 14 51 2 51 51 23 9 51 50 23 51 29 34 51 40 32 1 36 31 51 11 51 51 47 51 51 51 51 51 51 51 50 39 51 14 4 4 12 3 11 51 51 51 51 41 51 51 51 49 37 5 93",
"output": "99"
},
{
"input": "100 50\n87 91 95 73 50 50 16 97 39 24 58 50 33 89 42 37 50 50 12 71 3 55 50 50 80 10 76 50 52 36 88 44 66 69 86 71 77 50 72 50 21 55 50 50 78 61 75 89 65 2 50 69 62 47 11 92 97 77 41 31 55 29 35 51 36 48 50 91 92 86 50 36 50 94 51 74 4 27 55 63 50 36 87 50 67 7 65 75 20 96 88 50 41 73 35 51 66 21 29 33",
"output": "3"
},
{
"input": "100 50\n50 37 28 92 7 76 50 50 50 76 100 57 50 50 50 32 76 50 8 72 14 8 50 91 67 50 55 82 50 50 24 97 88 50 59 61 68 86 44 15 61 67 88 50 40 50 36 99 1 23 63 50 88 59 76 82 99 76 68 50 50 30 31 68 57 98 71 12 15 60 35 79 90 6 67 50 50 50 50 68 13 6 50 50 16 87 84 50 67 67 50 64 50 58 50 50 77 51 50 51",
"output": "3"
},
{
"input": "100 50\n43 50 50 91 97 67 6 50 86 50 76 60 50 59 4 56 11 38 49 50 37 50 50 20 60 47 33 54 95 58 22 50 77 77 72 9 57 40 81 57 95 50 81 63 62 76 13 87 50 39 74 69 50 99 63 1 11 62 84 31 97 99 56 73 70 36 45 100 28 91 93 9 19 52 73 50 83 58 84 52 86 12 50 44 64 52 97 50 12 71 97 52 87 66 83 66 86 50 9 49",
"output": "6"
},
{
"input": "88 10\n10 8 1 10 10 1 3 7 10 5 8 8 10 2 7 10 10 10 10 10 1 10 10 10 10 1 2 9 10 9 10 10 10 64 100 25 10 12 9 52 13 8 10 56 10 4 10 7 10 3 10 79 74 8 73 10 10 10 9 10 3 5 10 10 10 5 1 10 10 4 3 10 10 10 4 10 6 4 10 10 10 10 3 3 8 5 6 8",
"output": "66"
},
{
"input": "100 50\n80 39 33 69 75 50 23 88 50 50 67 90 87 50 29 15 55 32 60 50 50 50 38 95 62 50 50 88 8 97 45 50 42 12 22 93 49 50 24 50 50 71 60 4 50 72 57 57 50 50 50 83 69 17 1 31 72 55 50 11 50 80 93 41 91 94 20 60 50 50 51 48 53 56 76 73 50 72 19 98 50 50 50 50 50 28 48 45 62 11 16 67 93 88 63 50 50 66 48 95",
"output": "0"
},
{
"input": "100 50\n70 50 38 50 38 50 32 30 50 31 26 42 50 33 34 50 50 50 28 21 50 44 50 47 50 50 9 40 50 50 50 50 50 42 50 50 16 50 50 3 24 50 50 50 4 26 50 2 50 50 33 1 27 50 50 50 8 29 50 23 33 50 6 29 50 50 15 50 50 50 32 50 43 50 50 50 31 50 4 50 50 31 50 50 31 16 50 17 50 17 31 13 25 16 50 10 50 47 50 66",
"output": "0"
},
{
"input": "2 8\n8 8",
"output": "2"
},
{
"input": "1 6\n3",
"output": "1"
},
{
"input": "1 5\n5",
"output": "1"
}
] | 1,643,649,011
| 2,147,483,647
|
PyPy 3-64
|
RUNTIME_ERROR
|
TESTS
| 2
| 77
| 3,379,200
|
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=[]
for i in range(n):
if a[i]>k:
m.append(1)
else:
m.append(0)
p1=m.index(1)
p2=m[::-1].index(1)
print(p1+p2)
|
Title: Mishka and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.
Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list.
How many problems can Mishka solve?
Input Specification:
The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list.
Output Specification:
Print one integer — the maximum number of problems Mishka can solve.
Demo Input:
['8 4\n4 2 3 1 5 1 6 4\n', '5 2\n3 1 2 1 3\n', '5 100\n12 34 55 43 21\n']
Demo Output:
['5\n', '0\n', '5\n']
Note:
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$.
In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
|
```python
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=[]
for i in range(n):
if a[i]>k:
m.append(1)
else:
m.append(0)
p1=m.index(1)
p2=m[::-1].index(1)
print(p1+p2)
```
| -1
|
|
58
|
B
|
Coins
|
PROGRAMMING
| 1,300
|
[
"greedy"
] |
B. Coins
|
2
|
256
|
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be divisible by the denomination of any cheaper coin. It is known that among all the possible variants the variant with the largest number of new coins will be chosen. Find this variant. Print in the order of decreasing of the coins' denominations.
|
The first and only line contains an integer *n* (1<=≤<=*n*<=≤<=106) which represents the denomination of the most expensive coin.
|
Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination *n* of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coins should be different. If there are several solutins to that problem, print any of them.
|
[
"10\n",
"4\n",
"3\n"
] |
[
"10 5 1\n",
"4 2 1\n",
"3 1\n"
] |
none
| 1,000
|
[
{
"input": "10",
"output": "10 5 1"
},
{
"input": "4",
"output": "4 2 1"
},
{
"input": "3",
"output": "3 1"
},
{
"input": "2",
"output": "2 1"
},
{
"input": "5",
"output": "5 1"
},
{
"input": "6",
"output": "6 3 1"
},
{
"input": "7",
"output": "7 1"
},
{
"input": "1",
"output": "1"
},
{
"input": "8",
"output": "8 4 2 1"
},
{
"input": "12",
"output": "12 6 3 1"
},
{
"input": "100",
"output": "100 50 25 5 1"
},
{
"input": "1000",
"output": "1000 500 250 125 25 5 1"
},
{
"input": "10000",
"output": "10000 5000 2500 1250 625 125 25 5 1"
},
{
"input": "100000",
"output": "100000 50000 25000 12500 6250 3125 625 125 25 5 1"
},
{
"input": "1000000",
"output": "1000000 500000 250000 125000 62500 31250 15625 3125 625 125 25 5 1"
},
{
"input": "509149",
"output": "509149 1"
},
{
"input": "572877",
"output": "572877 190959 63653 1201 1"
},
{
"input": "152956",
"output": "152956 76478 38239 1"
},
{
"input": "733035",
"output": "733035 244345 48869 1"
},
{
"input": "313114",
"output": "313114 156557 3331 1"
},
{
"input": "893193",
"output": "893193 297731 42533 1"
},
{
"input": "473273",
"output": "473273 2243 1"
},
{
"input": "537000",
"output": "537000 268500 134250 67125 22375 4475 895 179 1"
},
{
"input": "117079",
"output": "117079 6887 97 1"
},
{
"input": "784653",
"output": "784653 261551 9019 311 1"
},
{
"input": "627251",
"output": "627251 1"
},
{
"input": "9",
"output": "9 3 1"
},
{
"input": "999999",
"output": "999999 333333 111111 37037 5291 481 37 1"
},
{
"input": "120",
"output": "120 60 30 15 5 1"
},
{
"input": "720",
"output": "720 360 180 90 45 15 5 1"
},
{
"input": "648",
"output": "648 324 162 81 27 9 3 1"
},
{
"input": "2430",
"output": "2430 1215 405 135 45 15 5 1"
},
{
"input": "119070",
"output": "119070 59535 19845 6615 2205 735 245 49 7 1"
},
{
"input": "15",
"output": "15 5 1"
},
{
"input": "21",
"output": "21 7 1"
},
{
"input": "25",
"output": "25 5 1"
},
{
"input": "100",
"output": "100 50 25 5 1"
},
{
"input": "524287",
"output": "524287 1"
},
{
"input": "1000000",
"output": "1000000 500000 250000 125000 62500 31250 15625 3125 625 125 25 5 1"
},
{
"input": "600",
"output": "600 300 150 75 25 5 1"
},
{
"input": "1000000",
"output": "1000000 500000 250000 125000 62500 31250 15625 3125 625 125 25 5 1"
},
{
"input": "36",
"output": "36 18 9 3 1"
},
{
"input": "1000000",
"output": "1000000 500000 250000 125000 62500 31250 15625 3125 625 125 25 5 1"
},
{
"input": "20",
"output": "20 10 5 1"
},
{
"input": "999983",
"output": "999983 1"
},
{
"input": "9",
"output": "9 3 1"
},
{
"input": "999983",
"output": "999983 1"
},
{
"input": "20",
"output": "20 10 5 1"
},
{
"input": "121",
"output": "121 11 1"
},
{
"input": "1331",
"output": "1331 121 11 1"
}
] | 1,597,158,694
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 186
| 6,656,000
|
n=int(input())
res=[1]
res.append(n)
for i in range(n):
if i*2==n:
res.append(i)
res=sorted(res,reverse=True)
print(*res)
|
Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be divisible by the denomination of any cheaper coin. It is known that among all the possible variants the variant with the largest number of new coins will be chosen. Find this variant. Print in the order of decreasing of the coins' denominations.
Input Specification:
The first and only line contains an integer *n* (1<=≤<=*n*<=≤<=106) which represents the denomination of the most expensive coin.
Output Specification:
Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination *n* of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coins should be different. If there are several solutins to that problem, print any of them.
Demo Input:
['10\n', '4\n', '3\n']
Demo Output:
['10 5 1\n', '4 2 1\n', '3 1\n']
Note:
none
|
```python
n=int(input())
res=[1]
res.append(n)
for i in range(n):
if i*2==n:
res.append(i)
res=sorted(res,reverse=True)
print(*res)
```
| 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,622,838,061
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 32
| 310
| 0
|
n = int(input())
numbers = [int(x) for x in input().split()]
is_evens = [x % 2 for x in numbers]
if is_evens.count(1) > is_evens.count(0):
print(is_evens.index(0) + 1)
else:
print(is_evens.index(1) + 1)
|
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())
numbers = [int(x) for x in input().split()]
is_evens = [x % 2 for x in numbers]
if is_evens.count(1) > is_evens.count(0):
print(is_evens.index(0) + 1)
else:
print(is_evens.index(1) + 1)
```
| 3.9225
|
975
|
C
|
Valhalla Siege
|
PROGRAMMING
| 1,400
|
[
"binary search"
] | null | null |
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack.
Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength.
Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$.
The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors.
|
The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors.
|
Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute.
|
[
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] |
[
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] |
In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1. - after the 5-th minute, the 2-nd warrior dies.
| 1,500
|
[
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
"input": "100 55\n1 2 4 4 3 5 5 2 3 4 2 1 1 2 3 5 1 5 4 2 5 4 4 3 3 5 3 4 4 5 5 2 3 3 4 4 3 4 5 5 5 5 3 5 1 2 4 3 4 5 3 3 2 1 4 5 3 4 4 1 5 1 5 2 2 1 4 5 3 3 1 4 2 5 4 5 3 2 5 5 2 3 2 3 2 2 3 4 4 4 1 4 2 4 5 3 1 3 3 1\n5 2 1 4 3 4 3 1 4 4 1 2 3 2 1 5 5 4 5 4 2 5 2 1 5 1 4 4 3 5 4 5 1 4 4 1 5 3 1 5 2 4 1 3 2 5 4 5 4 3 4 2 2 4 3",
"output": "98\n97\n97\n96\n95\n94\n94\n94\n92\n91\n91\n90\n87\n86\n86\n85\n83\n82\n80\n80\n79\n78\n77\n77\n75\n75\n74\n73\n72\n71\n70\n69\n69\n67\n66\n66\n65\n64\n63\n62\n62\n61\n61\n60\n60\n59\n58\n57\n54\n54\n52\n52\n51\n51\n50"
}
] | 1,565,855,901
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 3
| 358
| 15,052,800
|
n, q = map(int, input().split())
sas_warriors = list(map(int, input().split()))
arrows = list(map(int, input().split()))
p = {}
p[sas_warriors[0]] = 1
for i in range(1, n):
sas_warriors[i] += sas_warriors[i - 1]
p[sas_warriors[i]] = i + 1
g = 0
for i in range(q):
ass = arrows[i] + g
if ass >= sas_warriors[-1]:
print(len(sas_warriors))
g = 0
continue
if ass < sas_warriors[0] and g == 0:
print(len(sas_warriors))
continue
ls = 0
rs = n - 1
s = (ls + rs) // 2
while ls <= rs and sas_warriors[s] != ass:
s = (ls + rs) // 2
if sas_warriors[s] < ass:
ls = s + 1
if sas_warriors[s] > ass > sas_warriors[s - 1]:
break
if sas_warriors[s] > ass:
rs = s - 1
s = (ls + rs) // 2
g = ass
sas = 0
if sas_warriors[s] == ass:
sas = 1
print(n - s - sas)
|
Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack.
Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength.
Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$.
The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors.
Input Specification:
The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors.
Output Specification:
Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute.
Demo Input:
['5 5\n1 2 1 2 1\n3 10 1 1 1\n', '4 4\n1 2 3 4\n9 1 10 6\n']
Demo Output:
['3\n5\n4\n4\n3\n', '1\n4\n4\n1\n']
Note:
In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1. - after the 5-th minute, the 2-nd warrior dies.
|
```python
n, q = map(int, input().split())
sas_warriors = list(map(int, input().split()))
arrows = list(map(int, input().split()))
p = {}
p[sas_warriors[0]] = 1
for i in range(1, n):
sas_warriors[i] += sas_warriors[i - 1]
p[sas_warriors[i]] = i + 1
g = 0
for i in range(q):
ass = arrows[i] + g
if ass >= sas_warriors[-1]:
print(len(sas_warriors))
g = 0
continue
if ass < sas_warriors[0] and g == 0:
print(len(sas_warriors))
continue
ls = 0
rs = n - 1
s = (ls + rs) // 2
while ls <= rs and sas_warriors[s] != ass:
s = (ls + rs) // 2
if sas_warriors[s] < ass:
ls = s + 1
if sas_warriors[s] > ass > sas_warriors[s - 1]:
break
if sas_warriors[s] > ass:
rs = s - 1
s = (ls + rs) // 2
g = ass
sas = 0
if sas_warriors[s] == ass:
sas = 1
print(n - s - sas)
```
| 0
|
|
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,506,696,609
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 57
| 186
| 512,000
|
import sys
def main():
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split(' ')))
m = int(sys.stdin.readline())
b = list(map(int, sys.stdin.readline().split(' ')))
m = 0
for ai in a:
for bj in b:
if bj % ai == 0:
m = max(m, bj // ai)
s = set()
for ai in a:
for bj in b:
if bj % ai == 0 and bj // ai == m:
s.add((min(ai, bj), max(ai, bj)))
sys.stdout.write('{}\n'.format(len(s)))
main()
|
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
import sys
def main():
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split(' ')))
m = int(sys.stdin.readline())
b = list(map(int, sys.stdin.readline().split(' ')))
m = 0
for ai in a:
for bj in b:
if bj % ai == 0:
m = max(m, bj // ai)
s = set()
for ai in a:
for bj in b:
if bj % ai == 0 and bj // ai == m:
s.add((min(ai, bj), max(ai, bj)))
sys.stdout.write('{}\n'.format(len(s)))
main()
```
| 3
|
|
496
|
B
|
Secret Combination
|
PROGRAMMING
| 1,500
|
[
"brute force",
"constructive algorithms",
"implementation"
] | null | null |
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display.
|
Print a single line containing *n* digits — the desired state of the display containing the smallest possible number.
|
[
"3\n579\n",
"4\n2014\n"
] |
[
"024\n",
"0142\n"
] |
none
| 1,000
|
[
{
"input": "3\n579",
"output": "024"
},
{
"input": "4\n2014",
"output": "0142"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n039",
"output": "014"
},
{
"input": "4\n4444",
"output": "0000"
},
{
"input": "5\n46802",
"output": "02468"
},
{
"input": "10\n4447444444",
"output": "0000000003"
},
{
"input": "10\n5810438174",
"output": "0147609473"
},
{
"input": "30\n027027027027027027027027027027",
"output": "027027027027027027027027027027"
},
{
"input": "50\n41012516454101251645410125164541012516454101251645",
"output": "01076781720107678172010767817201076781720107678172"
},
{
"input": "72\n464553044645330446455304464553064645530445455304464553044645530446455304",
"output": "001011960020119600201196002011960020119600201996002011960020119620201196"
},
{
"input": "100\n2144315253572020279108092911160072328496568665545836825277616363478721946398140227406814602154768031",
"output": "0005996121738545755443472571416650525236761083528703911639570359104365792010332041424619191680979818"
},
{
"input": "200\n79025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544",
"output": "00274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086"
},
{
"input": "100\n6669666666666666666866266666666666666666666666666666666666666666626666666666666966666766665667666656",
"output": "0000000000000000000000000000000000000000006000000000000030000010000900100009000030000000000000002006"
},
{
"input": "1\n0",
"output": "0"
}
] | 1,418,973,826
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 28
| 62
| 4,812,800
|
def main():
input()
digits = list(map(int, input()))
l = [digits]
for a in range(1, 10):
l.append([(a + b) % 10 for b in digits])
for digits in l[:]:
a = digits[-1]
for i, b in enumerate(digits):
if a and not b:
l.append(digits[i:] + digits[:i])
a = b
print(''.join(map(str, min(l))))
if __name__ == '__main__':
main()
|
Title: Secret Combination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display.
Output Specification:
Print a single line containing *n* digits — the desired state of the display containing the smallest possible number.
Demo Input:
['3\n579\n', '4\n2014\n']
Demo Output:
['024\n', '0142\n']
Note:
none
|
```python
def main():
input()
digits = list(map(int, input()))
l = [digits]
for a in range(1, 10):
l.append([(a + b) % 10 for b in digits])
for digits in l[:]:
a = digits[-1]
for i, b in enumerate(digits):
if a and not b:
l.append(digits[i:] + digits[:i])
a = b
print(''.join(map(str, min(l))))
if __name__ == '__main__':
main()
```
| 3
|
|
802
|
G
|
Fake News (easy)
|
PROGRAMMING
| 800
|
[
"implementation",
"strings"
] | null | null |
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
|
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
|
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
|
[
"abcheaibcdi\n",
"hiedi\n"
] |
[
"YES",
"NO"
] |
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
| 0
|
[
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"input": "eihdi",
"output": "NO"
},
{
"input": "ehdii",
"output": "NO"
},
{
"input": "edhii",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "ehdii",
"output": "NO"
},
{
"input": "eufyajkssayhjhqcwxmctecaeepjwmfoscqprpcxsqfwnlgzsmmuwuoruantipholrauvxydfvftwfzhnckxswussvlidcojiciflpvkcxkkcmmvtfvxrkwcpeelwsuzqgamamdtdgzscmikvojfvqehblmjczkvtdeymgertgkwfwfukafqlfdhtedcctixhyetdypswgagrpyto",
"output": "YES"
},
{
"input": "arfbvxgdvqzuloojjrwoyqqbxamxybaqltfimofulusfebodjkwwrgwcppkwiodtpjaraglyplgerrpqjkpoggjmfxhwtqrijpijrcyxnoodvwpyjfpvqaoazllbrpzananbrvvybboedidtuvqquklkpeflfaltukjhzjgiofombhbmqbihgtapswykfvlgdoapjqntvqsaohmbvnphvyyhvhavslamczuqifxnwknkaenqmlvetrqogqxmlptgrmqvxzdxdmwobjesmgxckpmawtioavwdngyiwkzypfnxcovwzdohshwlavwsthdssiadhiwmhpvgkrbezm",
"output": "YES"
},
{
"input": "zcectngbqnejjjtsfrluummmqabzqbyccshjqbrjthzhlbmzjfxugvjouwhumsgrnopiyakfadjnbsesamhynsbfbfunupwbxvohfmpwlcpxhovwpfpciclatgmiufwdvtsqrsdcymvkldpnhfeisrzhyhhlkwdzthgprvkpyldeysvbmcibqkpudyrraqdlxpjecvwcvuiklcrsbgvqasmxmtxqzmawcjtozioqlfflinnxpeexbzloaeqjvglbdeufultpjqexvjjjkzemtzuzmxvawilcqdrcjzpqyhtwfphuonzwkotthsaxrmwtnlmcdylxqcfffyndqeouztluqwlhnkkvzwcfiscikv",
"output": "YES"
},
{
"input": "plqaykgovxkvsiahdbglktdlhcqwelxxmtlyymrsyubxdskvyjkrowvcbpdofpjqspsrgpakdczletxujzlsegepzleipiyycpinzxgwjsgslnxsotouddgfcybozfpjhhocpybfjbaywsehbcfrayvancbrumdfngqytnhihyxnlvilrqyhnxeckprqafofelospffhtwguzjbbjlzbqrtiielbvzutzgpqxosiaqznndgobcluuqlhmffiowkjdlkokehtjdyjvmxsiyxureflmdomerfekxdvtitvwzmdsdzplkpbtafxqfpudnhfqpoiwvjnylanunmagoweobdvfjgepbsymfutrjarlxclhgavpytiiqwvojrptofuvlohzeguxdsrihsbucelhhuedltnnjgzxwyblbqvnoliiydfinzlogbvucwykryzcyibnniggbkdkdcdgcsbvvnavtyhtkanrblpvomvjs",
"output": "YES"
},
{
"input": "fbldqzggeunkpwcfirxanmntbfrudijltoertsdvcvcmbwodbibsrxendzebvxwydpasaqnisrijctsuatihxxygbeovhxjdptdcppkvfytdpjspvrannxavmkmisqtygntxkdlousdypyfkrpzapysfpdbyprufwzhunlsfugojddkmxzinatiwfxdqmgyrnjnxvrclhxyuwxtshoqdjptmeecvgmrlvuwqtmnfnfeeiwcavwnqmyustawbjodzwsqmnjxhpqmgpysierlwbbdzcwprpsexyvreewcmlbvaiytjlxdqdaqftefdlmtmmjcwvfejshymhnouoshdzqcwzxpzupkbcievodzqkqvyjuuxxwepxjalvkzufnveji",
"output": "YES"
},
{
"input": "htsyljgoelbbuipivuzrhmfpkgderqpoprlxdpasxhpmxvaztccldtmujjzjmcpdvsdghzpretlsyyiljhjznseaacruriufswuvizwwuvdioazophhyytvbiogttnnouauxllbdn",
"output": "YES"
},
{
"input": "ikmxzqdzxqlvgeojsnhqzciujslwjyzzexnregabdqztpplosdakimjxmuqccbnwvzbajoiqgdobccwnrwmixohrbdarhoeeelzbpigiybtesybwefpcfx",
"output": "YES"
},
{
"input": "bpvbpjvbdfiodsmahxpcubjxdykesubnypalhypantshkjffmxjmelblqnjdmtaltneuyudyevkgedkqrdmrfeemgpghwrifcwincfixokfgurhqbcfzeajrgkgpwqwsepudxulywowwxzdxkumsicsvnzfxspmjpaixgejeaoyoibegosqoyoydmphfpbutrrewyjecowjckvpcceoamtfbitdneuwqfvnagswlskmsmkhmxyfsrpqwhxzocyffiumcy",
"output": "YES"
},
{
"input": "vllsexwrazvlfvhvrtqeohvzzresjdiuhomfpgqcxpqdevplecuaepixhlijatxzegciizpvyvxuembiplwklahlqibykfideysjygagjbgqkbhdhkatddcwlxboinfuomnpc",
"output": "YES"
},
{
"input": "pnjdwpxmvfoqkjtbhquqcuredrkwqzzfjmdvpnbqtypzdovemhhclkvigjvtprrpzbrbcbatkucaqteuciuozytsptvsskkeplaxdaqmjkmef",
"output": "NO"
},
{
"input": "jpwfhvlxvsdhtuozvlmnfiotrgapgjxtcsgcjnodcztupysvvvmjpzqkpommadppdrykuqkcpzojcwvlogvkddedwbggkrhuvtsvdiokehlkdlnukcufjvqxnikcdawvexxwffxtriqbdmkahxdtygodzohwtdmmuvmatdkvweqvaehaxiefpevkvqpyxsrhtmgjsdfcwzqobibeduooldrmglbinrepmunizheqzvgqvpdskhxfidxfnbisyizhepwyrcykcmjxnkyfjgrqlkixcvysa",
"output": "YES"
},
{
"input": "aftcrvuumeqbfvaqlltscnuhkpcifrrhnutjinxdhhdbzvizlrapzjdatuaynoplgjketupgaejciosofuhcgcjdcucarfvtsofgubtphijciswsvidnvpztlaarydkeqxzwdhfbmullkimerukusbrdnnujviydldrwhdfllsjtziwfeaiqotbiprespmxjulnyunkdtcghrzvhtcychkwatqqmladxpvmvlkzscthylbzkpgwlzfjqwarqvdeyngekqvrhrftpxnkfcibbowvnqdkulcdydspcubwlgoyinpnzgidbgunparnueddzwtzdiavbprbbg",
"output": "YES"
},
{
"input": "oagjghsidigeh",
"output": "NO"
},
{
"input": "chdhzpfzabupskiusjoefrwmjmqkbmdgboicnszkhdrlegeqjsldurmbshijadlwsycselhlnudndpdhcnhruhhvsgbthpruiqfirxkhpqhzhqdfpyozolbionodypfcqfeqbkcgmqkizgeyyelzeoothexcoaahedgrvoemqcwccbvoeqawqeuusyjxmgjkpfwcdttfmwunzuwvsihliexlzygqcgpbdiawfvqukikhbjerjkyhpcknlndaystrgsinghlmekbvhntcpypmchcwoglsmwwdulqneuabuuuvtyrnjxfcgoothalwkzzfxakneusezgnnepkpipzromqubraiggqndliz",
"output": "YES"
},
{
"input": "lgirxqkrkgjcutpqitmffvbujcljkqardlalyigxorscczuzikoylcxenryhskoavymexysvmhbsvhtycjlmzhijpuvcjshyfeycvvcfyzytzoyvxajpqdjtfiatnvxnyeqtfcagfftafllhhjhplbdsrfpctkqpinpdfrtlzyjllfbeffputywcckupyslkbbzpgcnxgbmhtqeqqehpdaokkjtatrhyiuusjhwgiiiikxpzdueasemosmmccoakafgvxduwiuflovhhfhffgnnjhoperhhjtvocpqytjxkmrknnknqeglffhfuplopmktykxuvcmbwpoeisrlyyhdpxfvzseucofyhziuiikihpqheqdyzwigeaqzhxzvporgisxgvhyicqyejovqloibhbunsvsunpvmdckkbuokitdzleilfwutcvuuytpupizinfjrzhxudsmjcjyfcpfgthujjowdwtgbvi",
"output": "YES"
},
{
"input": "uuehrvufgerqbzyzksmqnewacotuimawhlbycdbsmhshrsbqwybbkwjwsrkwptvlbbwjiivqugzrxxwgidrcrhrwsmwgeoleptfamzefgaeyxouxocrpvomjrazmxrnffdwrrmblgdiabdncvfougtmjgvvazasnygdrigbsrieoonirlivfyodvulouslxosswgpdexuldmkdbpdlgutiotvxjyecbrsvbmqxrlcpcipjjncduyqtohlzybvlemmfdeubihwlwqglkgjvnwrbgydcpwklmjeewqklmqdbajqgrpnynaxfvxjzgibqerxyhnxenrmcdqaaeksbzyrcaepozqpetaurlhjuxxhwppuhgoihxdxbmxeiahyaqkbknktlzkheaarjoqqrsyeducvoygwalgarldcdlqogfvsncejssmx",
"output": "YES"
},
{
"input": "iiopulfjxoitgiusqrhgbkiyzinphjtclodbkkydetylvuimkhdkklmyoacmekdvjpuxcrvqnjhqhhbfenlpzpwijtykqziocilvtpqhxuyrphdlamawjuzgjwiebkqyrzyqgtkcrhntjxqmcgkrqcslogjegfrivzidfedeegwbbsopvxvdoididlpypjogxaodtueebbwuwilacunqpozczcgrpaxxrtogpxgfkudtxchoravrrdtimhenwmnafxaruuojduxxglefejycfcyxllfimkszmbrhcwpnwjqgwvzysmlaaifdxfjjpgjmcksiigpanappjdloiolojmcqbnpnjjzaufdpjaknylmyvolhwypygwepmqwpiglpcnpypnudhdzpdvgzosyjthzcwtytxq",
"output": "YES"
}
] | 1,665,072,311
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 58
| 46
| 0
|
#!/usr/bin/env python
# coding: utf-8
# In[1]:
x='heidi'
s=input()
j=0
for i in range(len(s)):
if s[i]==x[j]:
j+=1
if j==5:
break
if j==5:
print('YES')
else:
print('NO')
# In[ ]:
|
Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
Input Specification:
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output Specification:
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
Demo Input:
['abcheaibcdi\n', 'hiedi\n']
Demo Output:
['YES', 'NO']
Note:
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
|
```python
#!/usr/bin/env python
# coding: utf-8
# In[1]:
x='heidi'
s=input()
j=0
for i in range(len(s)):
if s[i]==x[j]:
j+=1
if j==5:
break
if j==5:
print('YES')
else:
print('NO')
# In[ ]:
```
| 3
|
|
557
|
B
|
Pasha and Tea
|
PROGRAMMING
| 1,500
|
[
"constructive algorithms",
"implementation",
"math",
"sortings"
] | null | null |
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys and exactly *n* girls and all of them are going to come to the tea party. To please everyone, Pasha decided to pour the water for the tea as follows:
- Pasha can boil the teapot exactly once by pouring there at most *w* milliliters of water; - Pasha pours the same amount of water to each girl; - Pasha pours the same amount of water to each boy; - if each girl gets *x* milliliters of water, then each boy gets 2*x* milliliters of water.
In the other words, each boy should get two times more water than each girl does.
Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha's friends.
|
The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=109, 1<=≤<=*i*<=≤<=2*n*) — the capacities of Pasha's tea cups in milliliters.
|
Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
|
[
"2 4\n1 1 1 1\n",
"3 18\n4 4 4 2 2 2\n",
"1 5\n2 3\n"
] |
[
"3",
"18",
"4.5"
] |
Pasha also has candies that he is going to give to girls but that is another task...
| 1,000
|
[
{
"input": "2 4\n1 1 1 1",
"output": "3.0000000000"
},
{
"input": "3 18\n4 4 4 2 2 2",
"output": "18.0000000000"
},
{
"input": "1 5\n2 3",
"output": "4.5000000000"
},
{
"input": "1 1\n1000000000 1000000000",
"output": "1.0000000000"
},
{
"input": "4 1000000000\n1 1 1 1 1 1 1 1",
"output": "6.0000000000"
},
{
"input": "4 1000000000\n1 1 1 1 2 2 2 2",
"output": "12.0000000000"
},
{
"input": "4 1\n3 3 3 3 4 4 4 4",
"output": "1.0000000000"
},
{
"input": "2 19\n3 3 5 5",
"output": "15.0000000000"
},
{
"input": "3 31\n3 3 3 5 5 5",
"output": "22.5000000000"
},
{
"input": "5 15\n2 3 4 1 2 4 5 3 5 10",
"output": "15.0000000000"
},
{
"input": "5 14\n2 3 4 1 2 4 5 3 5 10",
"output": "14.0000000000"
},
{
"input": "5 16\n2 3 4 1 2 4 5 3 5 10",
"output": "15.0000000000"
},
{
"input": "1 100\n1 200",
"output": "3.0000000000"
},
{
"input": "1 1\n1 1",
"output": "1.0000000000"
},
{
"input": "2 1000000000\n1 1 1 100",
"output": "3.0000000000"
},
{
"input": "4 30\n3 3 3 3 4 5 6 7",
"output": "24.0000000000"
},
{
"input": "2 100\n1 1 1 10",
"output": "3.0000000000"
},
{
"input": "3 18\n1 1 1 1 1 5",
"output": "4.5000000000"
}
] | 1,435,681,081
| 4,681
|
Python 3
|
WRONG_ANSWER
|
PRETESTS
| 3
| 61
| 0
|
n, w = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = a[len(a)//2]
g = a[0]
if g < b/2 or a[len(a)//2 - 1] < b / 2:
print(g * n + 2 * g * n)
else:
print(n * b + n * (b / 2))
|
Title: Pasha and Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys and exactly *n* girls and all of them are going to come to the tea party. To please everyone, Pasha decided to pour the water for the tea as follows:
- Pasha can boil the teapot exactly once by pouring there at most *w* milliliters of water; - Pasha pours the same amount of water to each girl; - Pasha pours the same amount of water to each boy; - if each girl gets *x* milliliters of water, then each boy gets 2*x* milliliters of water.
In the other words, each boy should get two times more water than each girl does.
Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha's friends.
Input Specification:
The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=109, 1<=≤<=*i*<=≤<=2*n*) — the capacities of Pasha's tea cups in milliliters.
Output Specification:
Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
Demo Input:
['2 4\n1 1 1 1\n', '3 18\n4 4 4 2 2 2\n', '1 5\n2 3\n']
Demo Output:
['3', '18', '4.5']
Note:
Pasha also has candies that he is going to give to girls but that is another task...
|
```python
n, w = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = a[len(a)//2]
g = a[0]
if g < b/2 or a[len(a)//2 - 1] < b / 2:
print(g * n + 2 * g * n)
else:
print(n * b + n * (b / 2))
```
| 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,690,501,572
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 0
|
print("_RANDOM_GUESS_1690501572.2027423")# 1690501572.2027655
|
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
print("_RANDOM_GUESS_1690501572.2027423")# 1690501572.2027655
```
| 0
|
|
285
|
C
|
Building Permutation
|
PROGRAMMING
| 1,200
|
[
"greedy",
"implementation",
"sortings"
] | null | null |
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
You have a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. In one move, you are allowed to decrease or increase any number by one. Count the minimum number of moves, needed to build a permutation from this sequence.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
|
Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
|
[
"2\n3 0\n",
"3\n-1 -1 2\n"
] |
[
"2\n",
"6\n"
] |
In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2).
| 1,500
|
[
{
"input": "2\n3 0",
"output": "2"
},
{
"input": "3\n-1 -1 2",
"output": "6"
},
{
"input": "5\n-3 5 -3 3 3",
"output": "10"
},
{
"input": "10\n9 6 -2 4 1 1 1 9 6 2",
"output": "18"
},
{
"input": "9\n2 0 0 6 5 4 1 9 3",
"output": "15"
},
{
"input": "100\n-77 57 -95 -23 53 -28 82 -83 38 -73 85 28 25 6 -43 4 -10 -30 -9 -92 14 34 -93 61 36 -100 90 -68 28 16 100 -3 97 30 36 -55 62 -62 53 74 -50 -23 67 11 22 -30 -19 83 7 84 43 90 -65 -75 -15 97 90 15 66 2 13 -91 91 -44 46 51 51 -58 95 77 20 30 76 79 91 60 76 2 82 42 -93 94 -57 88 65 -95 -66 100 -9 33 -67 54 -99 97 53 13 54 66 60 -48",
"output": "3459"
}
] | 1,665,363,083
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 33
| 421
| 31,027,200
|
n = int(input())
v = sorted([int(x) for x in input().split()])
print(sum([abs(v[i] - i - 1) for i in range(n)]))
|
Title: Building Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
You have a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. In one move, you are allowed to decrease or increase any number by one. Count the minimum number of moves, needed to build a permutation from this sequence.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output Specification:
Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['2\n3 0\n', '3\n-1 -1 2\n']
Demo Output:
['2\n', '6\n']
Note:
In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2).
|
```python
n = int(input())
v = sorted([int(x) for x in input().split()])
print(sum([abs(v[i] - i - 1) for i in range(n)]))
```
| 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,654,784,007
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 62
| 0
|
#A WORD
upper=0
lower=0
s=input()
for i in range(0,len(s)):
#print(s[i])
if s[i]<'a':
upper=upper+1
else:
lower=lower+1
#print(upper,lower)
if upper>lower:
print(s.upper())
elif upper<lower:
print(s.lower())
|
Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none
|
```python
#A WORD
upper=0
lower=0
s=input()
for i in range(0,len(s)):
#print(s[i])
if s[i]<'a':
upper=upper+1
else:
lower=lower+1
#print(upper,lower)
if upper>lower:
print(s.upper())
elif upper<lower:
print(s.lower())
```
| 0
|
48
|
B
|
Land Lot
|
PROGRAMMING
| 1,200
|
[
"brute force",
"implementation"
] |
B. Land Lot
|
2
|
256
|
Vasya has a beautiful garden where wonderful fruit trees grow and yield fantastic harvest every year. But lately thieves started to sneak into the garden at nights and steal the fruit too often. Vasya can’t spend the nights in the garden and guard the fruit because there’s no house in the garden! Vasya had been saving in for some time and finally he decided to build the house. The rest is simple: he should choose in which part of the garden to build the house. In the evening he sat at his table and drew the garden’s plan. On the plan the garden is represented as a rectangular checkered field *n*<=×<=*m* in size divided into squares whose side length is 1. In some squares Vasya marked the trees growing there (one shouldn’t plant the trees too close to each other that’s why one square contains no more than one tree). Vasya wants to find a rectangular land lot *a*<=×<=*b* squares in size to build a house on, at that the land lot border should go along the lines of the grid that separates the squares. All the trees that grow on the building lot will have to be chopped off. Vasya loves his garden very much, so help him choose the building land lot location so that the number of chopped trees would be as little as possible.
|
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) which represent the garden location. The next *n* lines contain *m* numbers 0 or 1, which describe the garden on the scheme. The zero means that a tree doesn’t grow on this square and the 1 means that there is a growing tree. The last line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=50). Note that Vasya can choose for building an *a*<=×<=*b* rectangle as well a *b*<=×<=*a* one, i.e. the side of the lot with the length of *a* can be located as parallel to the garden side with the length of *n*, as well as parallel to the garden side with the length of *m*.
|
Print the minimum number of trees that needs to be chopped off to select a land lot *a*<=×<=*b* in size to build a house on. It is guaranteed that at least one lot location can always be found, i. e. either *a*<=≤<=*n* and *b*<=≤<=*m*, or *a*<=≤<=*m* и *b*<=≤<=*n*.
|
[
"2 2\n1 0\n1 1\n1 1\n",
"4 5\n0 0 1 0 1\n0 1 1 1 0\n1 0 1 0 1\n1 1 1 1 1\n2 3\n"
] |
[
"0\n",
"2\n"
] |
In the second example the upper left square is (1,1) and the lower right is (3,2).
| 0
|
[
{
"input": "2 2\n1 0\n1 1\n1 1",
"output": "0"
},
{
"input": "4 5\n0 0 1 0 1\n0 1 1 1 0\n1 0 1 0 1\n1 1 1 1 1\n2 3",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 0 0\n0 0 0\n1 2",
"output": "0"
},
{
"input": "3 3\n1 1 1\n1 1 1\n1 1 1\n2 1",
"output": "2"
},
{
"input": "3 2\n1 1\n1 1\n1 0\n2 1",
"output": "1"
},
{
"input": "2 3\n1 0 1\n0 1 0\n3 2",
"output": "3"
},
{
"input": "1 1\n0\n1 1",
"output": "0"
},
{
"input": "1 1\n1\n1 1",
"output": "1"
},
{
"input": "3 4\n1 0 1 0\n0 1 0 1\n1 0 1 0\n2 2",
"output": "2"
},
{
"input": "3 4\n1 1 1 1\n1 0 0 1\n1 1 1 1\n3 1",
"output": "1"
},
{
"input": "10 10\n1 1 1 0 0 0 0 1 1 0\n1 1 1 0 1 1 0 1 1 1\n1 0 1 1 0 1 1 1 1 0\n0 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1\n1 1 1 1 0 0 1 1 1 1\n1 1 1 1 0 1 1 1 0 1\n0 1 1 1 1 1 1 0 1 0\n1 1 1 1 1 0 0 1 0 1\n1 1 0 1 0 1 1 1 1 0\n5 4",
"output": "12"
},
{
"input": "10 10\n0 1 1 1 1 1 1 0 1 1\n0 1 1 1 1 1 0 0 1 1\n1 1 0 0 1 1 0 0 0 0\n0 0 0 0 1 0 1 1 1 0\n1 0 1 0 1 0 1 1 1 1\n1 0 0 1 1 1 1 1 0 1\n0 0 0 1 1 0 1 1 1 0\n1 0 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n0 0 0 1 1 0 0 1 1 1\n1 10",
"output": "4"
},
{
"input": "10 10\n1 0 1 1 1 1 0 0 1 1\n1 1 1 1 1 1 1 1 0 1\n1 0 0 1 1 1 1 1 1 1\n1 0 1 1 1 1 0 1 1 1\n0 0 1 0 1 1 1 1 1 1\n1 1 1 0 0 1 1 1 1 1\n0 1 1 0 1 1 0 1 1 0\n1 0 1 1 1 0 1 1 1 1\n1 0 1 1 1 0 1 1 0 1\n1 1 0 1 1 1 0 0 1 0\n10 1",
"output": "4"
},
{
"input": "10 7\n0 1 1 0 0 1 1\n1 1 0 0 0 0 1\n0 1 0 0 0 1 0\n0 1 0 1 1 1 1\n1 1 0 1 0 0 1\n0 1 0 0 0 0 0\n0 1 0 0 1 0 1\n0 1 0 1 1 0 0\n1 1 0 1 1 1 0\n1 1 0 0 0 1 0\n1 8",
"output": "0"
},
{
"input": "10 8\n1 1 0 1 1 1 0 0\n0 1 0 1 1 1 1 1\n1 1 0 0 1 0 0 1\n0 1 1 1 1 0 1 0\n0 1 1 0 1 1 0 1\n0 1 1 0 0 1 0 1\n1 0 0 0 1 1 0 1\n0 1 1 0 1 1 1 1\n0 1 1 1 0 1 0 1\n1 1 0 1 1 0 1 1\n4 9",
"output": "20"
},
{
"input": "10 10\n1 0 1 1 1 1 1 1 1 1\n1 1 1 0 1 1 0 1 1 1\n1 1 1 0 1 1 1 1 0 1\n1 1 0 1 1 1 0 0 0 1\n0 1 0 1 1 1 0 1 1 1\n1 0 1 0 1 0 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 0 1 1\n1 1 1 1 0 1 1 1 1 1\n0 1 1 1 1 0 1 1 0 1\n10 10",
"output": "80"
},
{
"input": "10 10\n0 1 1 0 0 0 1 0 0 0\n0 0 1 1 1 1 0 1 0 0\n1 1 0 1 1 0 0 1 0 0\n1 0 0 0 0 0 0 0 1 0\n0 0 0 1 0 0 0 1 0 0\n0 1 0 0 1 0 0 0 1 0\n0 1 0 1 1 1 1 0 0 0\n1 0 0 1 0 1 0 0 0 0\n0 0 0 0 1 0 0 0 0 0\n1 1 0 0 0 0 0 0 1 0\n3 7",
"output": "4"
},
{
"input": "10 10\n1 1 1 0 1 1 1 1 0 0\n1 1 1 1 1 0 0 0 0 1\n0 1 1 0 0 1 1 1 0 0\n1 1 1 1 0 1 1 1 1 1\n1 0 0 1 0 1 1 1 1 1\n1 1 1 1 1 1 0 1 0 1\n1 1 1 1 1 1 1 1 0 0\n0 1 0 0 1 1 1 1 1 1\n0 1 1 1 0 1 0 1 0 0\n1 1 0 1 0 1 1 1 1 0\n6 7",
"output": "27"
},
{
"input": "10 8\n0 1 1 1 1 1 1 0\n0 0 1 1 1 1 1 1\n0 1 0 1 1 1 1 0\n0 0 1 0 1 0 1 1\n0 1 1 1 1 1 1 1\n0 1 0 1 0 0 1 1\n0 0 0 0 0 0 0 1\n1 1 1 1 1 0 1 1\n1 1 1 0 1 1 1 0\n1 1 0 0 1 1 0 1\n8 10",
"output": "51"
},
{
"input": "10 1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1 5",
"output": "4"
}
] | 1,650,476,779
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 30
| 310
| 0
|
def calcTrees(cont, startRow, startCol, a, b):
trees = 0
for i in range(a):
for j in range(b):
if cont[startRow + i][startCol + j] == 1:
trees += 1
return trees
n, m = list(map(int, input().split(' ')))
cont = []
for i in range(n):
cont.append([int(item) for item in input().split(' ')])
a, b = list(map(int, input().split(' ')))
ans = a * b
for i in range(n):
for j in range(m):
if i <= n - a and j <= m - b:
helper = calcTrees(cont, i, j, a, b)
if ans > helper:
ans = helper
if i <= n - b and j <= m - a:
helper = calcTrees(cont, i, j, b, a)
if ans > helper:
ans = helper
print(ans)
|
Title: Land Lot
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has a beautiful garden where wonderful fruit trees grow and yield fantastic harvest every year. But lately thieves started to sneak into the garden at nights and steal the fruit too often. Vasya can’t spend the nights in the garden and guard the fruit because there’s no house in the garden! Vasya had been saving in for some time and finally he decided to build the house. The rest is simple: he should choose in which part of the garden to build the house. In the evening he sat at his table and drew the garden’s plan. On the plan the garden is represented as a rectangular checkered field *n*<=×<=*m* in size divided into squares whose side length is 1. In some squares Vasya marked the trees growing there (one shouldn’t plant the trees too close to each other that’s why one square contains no more than one tree). Vasya wants to find a rectangular land lot *a*<=×<=*b* squares in size to build a house on, at that the land lot border should go along the lines of the grid that separates the squares. All the trees that grow on the building lot will have to be chopped off. Vasya loves his garden very much, so help him choose the building land lot location so that the number of chopped trees would be as little as possible.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) which represent the garden location. The next *n* lines contain *m* numbers 0 or 1, which describe the garden on the scheme. The zero means that a tree doesn’t grow on this square and the 1 means that there is a growing tree. The last line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=50). Note that Vasya can choose for building an *a*<=×<=*b* rectangle as well a *b*<=×<=*a* one, i.e. the side of the lot with the length of *a* can be located as parallel to the garden side with the length of *n*, as well as parallel to the garden side with the length of *m*.
Output Specification:
Print the minimum number of trees that needs to be chopped off to select a land lot *a*<=×<=*b* in size to build a house on. It is guaranteed that at least one lot location can always be found, i. e. either *a*<=≤<=*n* and *b*<=≤<=*m*, or *a*<=≤<=*m* и *b*<=≤<=*n*.
Demo Input:
['2 2\n1 0\n1 1\n1 1\n', '4 5\n0 0 1 0 1\n0 1 1 1 0\n1 0 1 0 1\n1 1 1 1 1\n2 3\n']
Demo Output:
['0\n', '2\n']
Note:
In the second example the upper left square is (1,1) and the lower right is (3,2).
|
```python
def calcTrees(cont, startRow, startCol, a, b):
trees = 0
for i in range(a):
for j in range(b):
if cont[startRow + i][startCol + j] == 1:
trees += 1
return trees
n, m = list(map(int, input().split(' ')))
cont = []
for i in range(n):
cont.append([int(item) for item in input().split(' ')])
a, b = list(map(int, input().split(' ')))
ans = a * b
for i in range(n):
for j in range(m):
if i <= n - a and j <= m - b:
helper = calcTrees(cont, i, j, a, b)
if ans > helper:
ans = helper
if i <= n - b and j <= m - a:
helper = calcTrees(cont, i, j, b, a)
if ans > helper:
ans = helper
print(ans)
```
| 3.9225
|
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,616,585,733
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 30
| 0
|
R = lambda: map(int, input().split())
a = R()
b = sorted(R())
print("NO"if b[0]==1 or b[-1] == n or any(b[i+2] - b[i] < 3 for i in range(b[1] - 2)) else "YES")
|
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
R = lambda: map(int, input().split())
a = R()
b = sorted(R())
print("NO"if b[0]==1 or b[-1] == n or any(b[i+2] - b[i] < 3 for i in range(b[1] - 2)) else "YES")
```
| -1
|
|
169
|
A
|
Chores
|
PROGRAMMING
| 800
|
[
"sortings"
] | null | null |
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=><=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*).
In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores?
|
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
|
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
|
[
"5 2 3\n6 2 3 100 1\n",
"7 3 4\n1 1 9 1 1 1 1\n"
] |
[
"3\n",
"0\n"
] |
In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
| 500
|
[
{
"input": "5 2 3\n6 2 3 100 1",
"output": "3"
},
{
"input": "7 3 4\n1 1 9 1 1 1 1",
"output": "0"
},
{
"input": "2 1 1\n10 2",
"output": "8"
},
{
"input": "2 1 1\n7 7",
"output": "0"
},
{
"input": "2 1 1\n1 1000000000",
"output": "999999999"
},
{
"input": "3 1 2\n6 5 5",
"output": "1"
},
{
"input": "3 2 1\n10 10 8",
"output": "2"
},
{
"input": "8 3 5\n42 55 61 72 83 10 22 33",
"output": "6"
},
{
"input": "10 5 5\n1 2 3 4 5 999999999 999999998 999999997 999999996 999999995",
"output": "999999990"
},
{
"input": "4 1 3\n10 8 7 3",
"output": "2"
},
{
"input": "4 2 2\n402 10 10 402",
"output": "392"
},
{
"input": "4 1 3\n10 402 402 10",
"output": "0"
},
{
"input": "4 3 1\n100 100 200 200",
"output": "0"
},
{
"input": "150 10 140\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "102 101 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
}
] | 1,583,921,768
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 29
| 109
| 307,200
|
n, a, b = map(int, input().split())
lst = sorted(map(int, input().split()))
print(lst[b] - lst[b - 1])
|
Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=><=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*).
In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores?
Input Specification:
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output Specification:
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
Demo Input:
['5 2 3\n6 2 3 100 1\n', '7 3 4\n1 1 9 1 1 1 1\n']
Demo Output:
['3\n', '0\n']
Note:
In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
|
```python
n, a, b = map(int, input().split())
lst = sorted(map(int, input().split()))
print(lst[b] - lst[b - 1])
```
| 3
|
|
940
|
A
|
Points on the line
|
PROGRAMMING
| 1,200
|
[
"brute force",
"greedy",
"sortings"
] | null | null |
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
Diameter of multiset consisting of one point is 0.
You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*?
|
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points.
|
Output a single integer — the minimum number of points you have to remove.
|
[
"3 1\n2 1 4\n",
"3 0\n7 7 7\n",
"6 3\n1 3 4 6 9 10\n"
] |
[
"1\n",
"0\n",
"3\n"
] |
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.
| 500
|
[
{
"input": "3 1\n2 1 4",
"output": "1"
},
{
"input": "3 0\n7 7 7",
"output": "0"
},
{
"input": "6 3\n1 3 4 6 9 10",
"output": "3"
},
{
"input": "11 5\n10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "1 100\n1",
"output": "0"
},
{
"input": "100 10\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "84"
},
{
"input": "100 70\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "27"
},
{
"input": "1 10\n25",
"output": "0"
},
{
"input": "70 80\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",
"output": "0"
},
{
"input": "3 1\n25 26 27",
"output": "1"
},
{
"input": "100 5\n51 56 52 60 52 53 52 60 56 54 55 50 53 51 57 53 52 54 54 52 51 55 50 56 60 51 58 50 60 59 50 54 60 55 55 57 54 59 59 55 55 52 56 57 59 54 53 57 52 50 50 55 59 54 54 56 51 58 52 51 56 56 58 56 54 54 57 52 51 58 56 57 54 59 58 53 50 52 50 60 57 51 54 59 54 54 52 55 53 55 51 53 52 54 51 56 55 53 58 56",
"output": "34"
},
{
"input": "100 11\n44 89 57 64 94 96 73 96 55 52 91 73 73 93 51 62 63 85 43 75 60 78 98 55 80 84 65 75 61 88 62 71 53 57 94 85 60 96 66 96 61 72 97 64 51 44 63 82 67 86 60 57 74 85 57 79 61 94 86 78 84 56 60 75 91 91 92 62 89 85 79 57 76 97 65 56 46 78 51 69 50 52 85 80 76 71 81 51 90 71 77 60 63 62 84 59 79 84 69 81",
"output": "70"
},
{
"input": "100 0\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "96"
},
{
"input": "100 100\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "0"
},
{
"input": "76 32\n50 53 69 58 55 39 40 42 40 55 58 73 55 72 75 44 45 55 46 60 60 42 41 64 77 39 68 51 61 49 38 41 56 57 64 43 78 36 39 63 40 66 52 76 39 68 39 73 40 68 54 60 35 67 69 52 58 52 38 63 69 38 69 60 73 64 65 41 59 55 37 57 40 34 35 35",
"output": "13"
},
{
"input": "100 1\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "93"
},
{
"input": "100 5\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "89"
},
{
"input": "98 64\n2 29 36 55 58 15 25 33 7 16 61 1 4 24 63 26 36 16 16 3 57 39 56 7 11 24 20 12 22 10 56 5 11 39 61 52 27 54 21 6 61 36 40 52 54 5 15 52 58 23 45 39 65 16 27 40 13 64 47 24 51 29 9 18 49 49 8 47 2 64 7 63 49 10 20 26 34 3 45 66 8 46 16 32 16 38 3 6 15 17 35 48 36 5 57 29 61 15",
"output": "1"
},
{
"input": "100 56\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": "43"
},
{
"input": "100 0\n14 13 14 13 14 13 13 13 13 14 13 13 14 14 13 14 14 14 14 13 13 13 14 13 13 14 14 14 14 14 14 13 13 13 13 14 13 14 13 14 13 14 14 14 14 13 13 14 14 13 13 13 13 14 13 14 13 14 13 14 13 13 13 14 13 13 14 13 14 14 13 13 13 14 14 14 14 13 13 14 14 14 14 14 14 14 13 14 13 13 13 14 14 13 13 13 13 13 14 14",
"output": "50"
},
{
"input": "100 0\n14 17 18 22 19 18 19 21 19 19 22 22 19 21 24 23 24 19 25 24 24 21 20 13 26 18 17 15 25 13 17 20 20 21 13 22 27 15 18 27 19 15 16 25 18 17 18 22 19 17 18 24 14 16 18 16 22 16 17 27 18 17 18 24 22 13 14 20 23 19 16 21 19 13 14 14 25 15 27 24 26 22 16 20 16 14 21 27 15 23 23 24 27 14 24 17 19 24 15 27",
"output": "89"
},
{
"input": "100 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": "0"
},
{
"input": "1 100\n22",
"output": "0"
},
{
"input": "1 0\n22",
"output": "0"
},
{
"input": "1 99\n99",
"output": "0"
},
{
"input": "1 5\n6",
"output": "0"
},
{
"input": "3 1\n10 20 30",
"output": "2"
},
{
"input": "3 0\n1 2 3",
"output": "2"
},
{
"input": "3 2\n1 50 99",
"output": "2"
},
{
"input": "7 4\n1 3 4 9 10 11 12",
"output": "3"
},
{
"input": "2 5\n67 23",
"output": "1"
},
{
"input": "4 2\n1 4 7 9",
"output": "2"
},
{
"input": "2 0\n1 2",
"output": "1"
},
{
"input": "8 1\n3 3 3 5 5 5 5 5",
"output": "3"
},
{
"input": "5 1\n3 5 5 5 6",
"output": "1"
}
] | 1,613,139,167
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 35
| 77
| 0
|
n,d = map(int,input().split())
arr = list(map(int,input().split()))
arr.sort()
j = ans = 0
for i in range(n):
while j<n and arr[j]-arr[i]<=d: j += 1
ans = max(ans,j-i)
print(n-ans)
|
Title: Points on the line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
Diameter of multiset consisting of one point is 0.
You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*?
Input Specification:
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points.
Output Specification:
Output a single integer — the minimum number of points you have to remove.
Demo Input:
['3 1\n2 1 4\n', '3 0\n7 7 7\n', '6 3\n1 3 4 6 9 10\n']
Demo Output:
['1\n', '0\n', '3\n']
Note:
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.
|
```python
n,d = map(int,input().split())
arr = list(map(int,input().split()))
arr.sort()
j = ans = 0
for i in range(n):
while j<n and arr[j]-arr[i]<=d: j += 1
ans = max(ans,j-i)
print(n-ans)
```
| 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,681,657,960
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
n=int(input())
a=int(input())
dmini=dmaxi=a
mini=maxi=0
for _ in range(1,n):
a=int(input())
if a>dmaxi:
dmaxi=a
maxi=1
else:
dmini=a
mini=1
print(maxi+(n-1-mini)-(mini<maxi?1:0))
|
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())
a=int(input())
dmini=dmaxi=a
mini=maxi=0
for _ in range(1,n):
a=int(input())
if a>dmaxi:
dmaxi=a
maxi=1
else:
dmini=a
mini=1
print(maxi+(n-1-mini)-(mini<maxi?1:0))
```
| -1
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater than *v**i* meters per second in any of the two directions along the road: south or north.
You are to compute the minimum time needed to gather all the *n* friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate.
|
The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters.
The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — the maximum speeds of the friends, in meters per second.
|
Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road.
Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds.
|
[
"3\n7 1 3\n1 2 1\n",
"4\n5 10 3 2\n2 3 2 4\n"
] |
[
"2.000000000000\n",
"1.400000000000\n"
] |
In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
| 0
|
[
{
"input": "3\n7 1 3\n1 2 1",
"output": "2.000000000000"
},
{
"input": "4\n5 10 3 2\n2 3 2 4",
"output": "1.400000000000"
},
{
"input": "3\n1 1000000000 2\n1 2 1000000000",
"output": "333333332.999999999971"
},
{
"input": "2\n4 5\n10 8",
"output": "0.055555555556"
},
{
"input": "4\n14 12 10 17\n8 6 5 10",
"output": "0.466666666667"
},
{
"input": "5\n1 15 61 29 43\n15 11 19 19 19",
"output": "1.764705882353"
},
{
"input": "10\n20 11 17 38 15 27 2 40 24 37\n22 30 22 30 28 16 7 20 22 13",
"output": "1.750000000000"
},
{
"input": "2\n1000000000 1000000000\n1 1",
"output": "0.000000000000"
},
{
"input": "3\n1 1 1\n1 1 1",
"output": "0.000000000000"
}
] | 1,688,280,188
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 46
| 1,497
| 17,510,400
|
import sys
# sys.stdin = open(".in", "r")
# sys.stdout = open(".out", "w")
input = sys.stdin.readline
def print(*args, end='\n', sep=' ') -> None:
sys.stdout.write(sep.join(map(str, args)) + end)
def map_int():
return map(int, input().split())
def list_int():
return list(map(int, input().split()))
from collections import defaultdict
def possible(timme):
rangeL, rangeR = -10**25, 10**25
for i in range(n):
curL = pos_speed[i][0] - pos_speed[i][1]*timme
curR = pos_speed[i][0] + pos_speed[i][1]*timme
if curL > rangeR: return False
rangeL = curL
rangeR = min(rangeR, curR)
return True
n = int(input())
posisions = list_int()
speed = list_int()
pos_speed = sorted(zip(posisions, speed))
l, r = 0, 10**25
answer = r
while l <= r:
mid = l + (r-l)/2
if possible(mid):
answer = mid
r = mid - 0.0000001
else:
l = mid + 0.0000001
print(answer)
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater than *v**i* meters per second in any of the two directions along the road: south or north.
You are to compute the minimum time needed to gather all the *n* friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate.
Input Specification:
The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters.
The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — the maximum speeds of the friends, in meters per second.
Output Specification:
Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road.
Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds.
Demo Input:
['3\n7 1 3\n1 2 1\n', '4\n5 10 3 2\n2 3 2 4\n']
Demo Output:
['2.000000000000\n', '1.400000000000\n']
Note:
In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
|
```python
import sys
# sys.stdin = open(".in", "r")
# sys.stdout = open(".out", "w")
input = sys.stdin.readline
def print(*args, end='\n', sep=' ') -> None:
sys.stdout.write(sep.join(map(str, args)) + end)
def map_int():
return map(int, input().split())
def list_int():
return list(map(int, input().split()))
from collections import defaultdict
def possible(timme):
rangeL, rangeR = -10**25, 10**25
for i in range(n):
curL = pos_speed[i][0] - pos_speed[i][1]*timme
curR = pos_speed[i][0] + pos_speed[i][1]*timme
if curL > rangeR: return False
rangeL = curL
rangeR = min(rangeR, curR)
return True
n = int(input())
posisions = list_int()
speed = list_int()
pos_speed = sorted(zip(posisions, speed))
l, r = 0, 10**25
answer = r
while l <= r:
mid = l + (r-l)/2
if possible(mid):
answer = mid
r = mid - 0.0000001
else:
l = mid + 0.0000001
print(answer)
```
| 3
|
|
108
|
A
|
Palindromic Times
|
PROGRAMMING
| 1,000
|
[
"implementation",
"strings"
] |
A. Palindromic Times
|
2
|
256
|
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome.
In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment.
However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.
|
The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.
|
Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.
|
[
"12:21\n",
"23:59\n"
] |
[
"13:31\n",
"00:00\n"
] |
none
| 500
|
[
{
"input": "12:21",
"output": "13:31"
},
{
"input": "23:59",
"output": "00:00"
},
{
"input": "15:51",
"output": "20:02"
},
{
"input": "10:44",
"output": "11:11"
},
{
"input": "04:02",
"output": "04:40"
},
{
"input": "02:11",
"output": "02:20"
},
{
"input": "12:15",
"output": "12:21"
},
{
"input": "07:07",
"output": "10:01"
},
{
"input": "00:17",
"output": "01:10"
},
{
"input": "04:55",
"output": "05:50"
},
{
"input": "02:17",
"output": "02:20"
},
{
"input": "07:56",
"output": "10:01"
},
{
"input": "00:29",
"output": "01:10"
},
{
"input": "23:31",
"output": "23:32"
},
{
"input": "19:30",
"output": "20:02"
},
{
"input": "12:14",
"output": "12:21"
},
{
"input": "17:32",
"output": "20:02"
},
{
"input": "03:44",
"output": "04:40"
},
{
"input": "07:15",
"output": "10:01"
},
{
"input": "18:42",
"output": "20:02"
},
{
"input": "08:56",
"output": "10:01"
},
{
"input": "04:50",
"output": "05:50"
},
{
"input": "14:32",
"output": "14:41"
},
{
"input": "23:23",
"output": "23:32"
},
{
"input": "08:35",
"output": "10:01"
},
{
"input": "03:32",
"output": "04:40"
},
{
"input": "07:59",
"output": "10:01"
},
{
"input": "14:12",
"output": "14:41"
},
{
"input": "23:52",
"output": "00:00"
},
{
"input": "16:36",
"output": "20:02"
},
{
"input": "17:50",
"output": "20:02"
},
{
"input": "06:59",
"output": "10:01"
},
{
"input": "16:50",
"output": "20:02"
},
{
"input": "00:00",
"output": "01:10"
},
{
"input": "23:59",
"output": "00:00"
},
{
"input": "23:33",
"output": "00:00"
}
] | 1,690,514,070
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 7
| 92
| 0
|
hh, mm = input().split(":")
if int(mm) >= int(hh[::-1]):
hh = int(hh)
hh = hh + 1 if hh < 23 else 0
hh = hh if hh < 16 else 20
hh = f"{hh:02d}"
res = f"{hh}:{hh[::-1]}"
print(res)
|
Title: Palindromic Times
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome.
In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment.
However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.
Input Specification:
The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.
Output Specification:
Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.
Demo Input:
['12:21\n', '23:59\n']
Demo Output:
['13:31\n', '00:00\n']
Note:
none
|
```python
hh, mm = input().split(":")
if int(mm) >= int(hh[::-1]):
hh = int(hh)
hh = hh + 1 if hh < 23 else 0
hh = hh if hh < 16 else 20
hh = f"{hh:02d}"
res = f"{hh}:{hh[::-1]}"
print(res)
```
| 0
|
835
|
B
|
The number on the board
|
PROGRAMMING
| 1,100
|
[
"greedy"
] | null | null |
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
|
The first line contains integer *k* (1<=≤<=*k*<=≤<=109).
The second line contains integer *n* (1<=≤<=*n*<=<<=10100000).
There are no leading zeros in *n*. It's guaranteed that this situation is possible.
|
Print the minimum number of digits in which the initial number and *n* can differ.
|
[
"3\n11\n",
"3\n99\n"
] |
[
"1\n",
"0\n"
] |
In the first example, the initial number could be 12.
In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*.
| 750
|
[
{
"input": "3\n11",
"output": "1"
},
{
"input": "3\n99",
"output": "0"
},
{
"input": "10\n5205602270",
"output": "0"
},
{
"input": "70\n3326631213",
"output": "6"
},
{
"input": "200\n1000000010000000000000000000010000000000000001000001000000000000000000000000000000000000000000000000",
"output": "22"
},
{
"input": "500\n1899337170458531693764539600958943248270674811247191310452938511077656066239840703432499357537079035",
"output": "6"
},
{
"input": "700\n9307216756404590162143344901558545760612901767837570518638460182990196397856220673189163417019781185",
"output": "32"
},
{
"input": "900\n7570423817272967027553082464863962024635217372307919506594193055572300657732661146354209508997483330",
"output": "91"
},
{
"input": "18\n900",
"output": "1"
},
{
"input": "23\n12138",
"output": "1"
},
{
"input": "16\n333",
"output": "2"
},
{
"input": "3\n12",
"output": "0"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
{
"input": "17\n89",
"output": "0"
},
{
"input": "18\n99",
"output": "0"
},
{
"input": "42\n97779",
"output": "2"
},
{
"input": "2\n11",
"output": "0"
},
{
"input": "6\n33",
"output": "0"
},
{
"input": "45\n23456",
"output": "5"
},
{
"input": "3\n21",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "108\n199999899899",
"output": "3"
},
{
"input": "6\n222",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "9\n9",
"output": "0"
},
{
"input": "5\n5",
"output": "0"
},
{
"input": "27\n888",
"output": "3"
}
] | 1,640,214,440
| 560
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 3
| 93
| 512,000
|
import sys
input = sys.stdin.buffer.readline
def process(k, S):
d = [0 for i in range(10)]
n = len(S)
curr = 0
for i in range(n):
digit = int(S[i])
d[digit]+=1
curr+=(digit)
if curr >= k:
return 0
answer = 0
for i in range(9):
#curr < k
#curr-i*d[i]+9*d[i] >= k > curr
#(9-i)*d[i] >= (k-curr)
if curr-i*d[i]+9*d[i] >= k:
if (k-curr) % (9-i)==0:
R = (k-curr)//(9-i)
else:
R = (k-curr)//(9-i)+1
return answer+R
else:
curr = curr-i*d[i]+9*d[i]
k = int(input())
S = input().decode()[:-2]
print(process(k, S))
|
Title: The number on the board
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input Specification:
The first line contains integer *k* (1<=≤<=*k*<=≤<=109).
The second line contains integer *n* (1<=≤<=*n*<=<<=10100000).
There are no leading zeros in *n*. It's guaranteed that this situation is possible.
Output Specification:
Print the minimum number of digits in which the initial number and *n* can differ.
Demo Input:
['3\n11\n', '3\n99\n']
Demo Output:
['1\n', '0\n']
Note:
In the first example, the initial number could be 12.
In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*.
|
```python
import sys
input = sys.stdin.buffer.readline
def process(k, S):
d = [0 for i in range(10)]
n = len(S)
curr = 0
for i in range(n):
digit = int(S[i])
d[digit]+=1
curr+=(digit)
if curr >= k:
return 0
answer = 0
for i in range(9):
#curr < k
#curr-i*d[i]+9*d[i] >= k > curr
#(9-i)*d[i] >= (k-curr)
if curr-i*d[i]+9*d[i] >= k:
if (k-curr) % (9-i)==0:
R = (k-curr)//(9-i)
else:
R = (k-curr)//(9-i)+1
return answer+R
else:
curr = curr-i*d[i]+9*d[i]
k = int(input())
S = input().decode()[:-2]
print(process(k, S))
```
| 0
|
|
56
|
A
|
Bar
|
PROGRAMMING
| 1,000
|
[
"implementation"
] |
A. Bar
|
2
|
256
|
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
|
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
|
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
|
[
"5\n18\nVODKA\nCOKE\n19\n17\n"
] |
[
"2\n"
] |
In the sample test the second and fifth clients should be checked.
| 500
|
[
{
"input": "5\n18\nVODKA\nCOKE\n19\n17",
"output": "2"
},
{
"input": "2\n2\nGIN",
"output": "2"
},
{
"input": "3\nWHISKEY\n3\nGIN",
"output": "3"
},
{
"input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWINWJW",
"output": "1"
},
{
"input": "4\nSAKE\nSAKE\n13\n2",
"output": "4"
},
{
"input": "2\n0\n17",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
}
] | 1,594,664,767
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 28
| 216
| 6,963,200
|
r=0
l=["ABSINTH","BEER","BRANDY","CHAMPAGNE","GIN","RUM","SAKE","TEQUILA","VODKA","WHISKEY","WINE"]
l1=["0","1","2","3","4","5","6","7","8","9"]
for i in range(int(input())):
s=input()
if(s[0] in l1):
k=int(s)
else:
k=20
if(k<18):
r=r+1
elif(s in l):
r=r+1
print(r)
|
Title: Bar
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
Output Specification:
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
Demo Input:
['5\n18\nVODKA\nCOKE\n19\n17\n']
Demo Output:
['2\n']
Note:
In the sample test the second and fifth clients should be checked.
|
```python
r=0
l=["ABSINTH","BEER","BRANDY","CHAMPAGNE","GIN","RUM","SAKE","TEQUILA","VODKA","WHISKEY","WINE"]
l1=["0","1","2","3","4","5","6","7","8","9"]
for i in range(int(input())):
s=input()
if(s[0] in l1):
k=int(s)
else:
k=20
if(k<18):
r=r+1
elif(s in l):
r=r+1
print(r)
```
| 3.93303
|
834
|
A
|
The Useless Toy
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly *n* seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
|
There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number *n* is given (0<=≤<=*n*<=≤<=109) – the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a *n* second spin in any of the directions, assuming the given starting position.
|
Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
|
[
"^ >\n1\n",
"< ^\n3\n",
"^ v\n6\n"
] |
[
"cw\n",
"ccw\n",
"undefined\n"
] |
none
| 500
|
[
{
"input": "^ >\n1",
"output": "cw"
},
{
"input": "< ^\n3",
"output": "ccw"
},
{
"input": "^ v\n6",
"output": "undefined"
},
{
"input": "^ >\n999999999",
"output": "ccw"
},
{
"input": "> v\n1",
"output": "cw"
},
{
"input": "v <\n1",
"output": "cw"
},
{
"input": "< ^\n1",
"output": "cw"
},
{
"input": "v <\n422435957",
"output": "cw"
},
{
"input": "v >\n139018901",
"output": "ccw"
},
{
"input": "v ^\n571728018",
"output": "undefined"
},
{
"input": "^ ^\n0",
"output": "undefined"
},
{
"input": "< >\n2",
"output": "undefined"
},
{
"input": "> >\n1000000000",
"output": "undefined"
},
{
"input": "v v\n8",
"output": "undefined"
},
{
"input": "< <\n1568",
"output": "undefined"
},
{
"input": "^ v\n2",
"output": "undefined"
},
{
"input": "^ <\n1",
"output": "ccw"
},
{
"input": "< v\n1",
"output": "ccw"
},
{
"input": "v >\n1",
"output": "ccw"
},
{
"input": "> ^\n1",
"output": "ccw"
},
{
"input": "v <\n422435957",
"output": "cw"
},
{
"input": "v v\n927162384",
"output": "undefined"
},
{
"input": "v ^\n571728018",
"output": "undefined"
},
{
"input": "^ <\n467441155",
"output": "cw"
},
{
"input": "^ >\n822875521",
"output": "cw"
},
{
"input": "^ <\n821690113",
"output": "ccw"
},
{
"input": "^ <\n171288453",
"output": "ccw"
},
{
"input": "^ <\n110821381",
"output": "ccw"
},
{
"input": "^ ^\n539580280",
"output": "undefined"
},
{
"input": "^ >\n861895563",
"output": "ccw"
},
{
"input": "v v\n4",
"output": "undefined"
},
{
"input": "^ ^\n4",
"output": "undefined"
},
{
"input": "> >\n4",
"output": "undefined"
},
{
"input": "< <\n8",
"output": "undefined"
},
{
"input": "v v\n0",
"output": "undefined"
},
{
"input": "^ <\n11",
"output": "cw"
},
{
"input": "< <\n4",
"output": "undefined"
},
{
"input": "< <\n0",
"output": "undefined"
},
{
"input": "< v\n3",
"output": "cw"
},
{
"input": "^ <\n3",
"output": "cw"
},
{
"input": "^ <\n7",
"output": "cw"
},
{
"input": "< >\n6",
"output": "undefined"
},
{
"input": "v >\n3",
"output": "cw"
},
{
"input": "> >\n300",
"output": "undefined"
},
{
"input": "> >\n0",
"output": "undefined"
},
{
"input": "v <\n3",
"output": "ccw"
},
{
"input": "> >\n12",
"output": "undefined"
}
] | 1,613,301,595
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 0
|
s,v=input().split()
n=int(input())
i = (ord(v) - ord(s) + 4) % 4
if n%2==0:
print("undefined")
elif n%4==i:
print("cw")
else:
print("ccw")
|
Title: The Useless Toy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly *n* seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input Specification:
There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number *n* is given (0<=≤<=*n*<=≤<=109) – the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a *n* second spin in any of the directions, assuming the given starting position.
Output Specification:
Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
Demo Input:
['^ >\n1\n', '< ^\n3\n', '^ v\n6\n']
Demo Output:
['cw\n', 'ccw\n', 'undefined\n']
Note:
none
|
```python
s,v=input().split()
n=int(input())
i = (ord(v) - ord(s) + 4) % 4
if n%2==0:
print("undefined")
elif n%4==i:
print("cw")
else:
print("ccw")
```
| 0
|
|
59
|
A
|
Word
|
PROGRAMMING
| 800
|
[
"implementation",
"strings"
] |
A. Word
|
2
|
256
|
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
|
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
|
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
|
[
"HoUse\n",
"ViP\n",
"maTRIx\n"
] |
[
"house\n",
"VIP\n",
"matrix\n"
] |
none
| 500
|
[
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,607,070,461
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 30
| 216
| 0
|
s = input()
upperCount = 0
lowerCount = 0
for i in s:
if i.isupper() == True:
upperCount = upperCount + 1
else:
lowerCount = lowerCount + 1
if upperCount > lowerCount:
s = s.upper()
else:
s = s.lower()
print(s)
|
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 = input()
upperCount = 0
lowerCount = 0
for i in s:
if i.isupper() == True:
upperCount = upperCount + 1
else:
lowerCount = lowerCount + 1
if upperCount > lowerCount:
s = s.upper()
else:
s = s.lower()
print(s)
```
| 3.946
|
909
|
A
|
Generate Login
|
PROGRAMMING
| 1,000
|
[
"brute force",
"greedy",
"sortings"
] | null | null |
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users).
As a reminder, a prefix of a string *s* is its substring which occurs at the beginning of *s*: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string *a* is alphabetically earlier than a string *b*, if *a* is a prefix of *b*, or *a* and *b* coincide up to some position, and then *a* has a letter that is alphabetically earlier than the corresponding letter in *b*: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".
|
The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.
|
Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.
|
[
"harry potter\n",
"tom riddle\n"
] |
[
"hap\n",
"tomr\n"
] |
none
| 500
|
[
{
"input": "harry potter",
"output": "hap"
},
{
"input": "tom riddle",
"output": "tomr"
},
{
"input": "a qdpinbmcrf",
"output": "aq"
},
{
"input": "wixjzniiub ssdfodfgap",
"output": "wis"
},
{
"input": "z z",
"output": "zz"
},
{
"input": "ertuyivhfg v",
"output": "ertuv"
},
{
"input": "asdfghjkli ware",
"output": "asdfghjkliw"
},
{
"input": "udggmyop ze",
"output": "udggmyopz"
},
{
"input": "fapkdme rtzxovx",
"output": "fapkdmer"
},
{
"input": "mybiqxmnqq l",
"output": "ml"
},
{
"input": "dtbqya fyyymv",
"output": "df"
},
{
"input": "fyclu zokbxiahao",
"output": "fycluz"
},
{
"input": "qngatnviv rdych",
"output": "qngar"
},
{
"input": "ttvnhrnng lqkfulhrn",
"output": "tl"
},
{
"input": "fya fgx",
"output": "ff"
},
{
"input": "nuis zvjjqlre",
"output": "nuisz"
},
{
"input": "ly qtsmze",
"output": "lq"
},
{
"input": "d kgfpjsurfw",
"output": "dk"
},
{
"input": "lwli ewrpu",
"output": "le"
},
{
"input": "rr wldsfubcs",
"output": "rrw"
},
{
"input": "h qart",
"output": "hq"
},
{
"input": "vugvblnzx kqdwdulm",
"output": "vk"
},
{
"input": "xohesmku ef",
"output": "xe"
},
{
"input": "twvvsl wtcyawv",
"output": "tw"
},
{
"input": "obljndajv q",
"output": "obljndajq"
},
{
"input": "jjxwj kxccwx",
"output": "jjk"
},
{
"input": "sk fftzmv",
"output": "sf"
},
{
"input": "cgpegngs aufzxkyyrw",
"output": "ca"
},
{
"input": "reyjzjdvq skuch",
"output": "res"
},
{
"input": "ardaae mxgdulijf",
"output": "am"
},
{
"input": "bgopsdfji uaps",
"output": "bgopsdfjiu"
},
{
"input": "amolfed pun",
"output": "amolfedp"
},
{
"input": "badkiln yort",
"output": "badkilny"
},
{
"input": "aaaaaaaaaz york",
"output": "aaaaaaaaay"
},
{
"input": "bbbbcbbbbd c",
"output": "bbbbc"
},
{
"input": "aa ab",
"output": "aa"
},
{
"input": "ab b",
"output": "ab"
},
{
"input": "aaaaa ab",
"output": "aa"
},
{
"input": "aa a",
"output": "aa"
},
{
"input": "aba b",
"output": "ab"
},
{
"input": "aaaaaaa aaaaaa",
"output": "aa"
},
{
"input": "a a",
"output": "aa"
},
{
"input": "a aa",
"output": "aa"
},
{
"input": "a b",
"output": "ab"
},
{
"input": "b a",
"output": "ba"
},
{
"input": "z a",
"output": "za"
},
{
"input": "aaa a",
"output": "aa"
},
{
"input": "aa aa",
"output": "aa"
},
{
"input": "a aaa",
"output": "aa"
},
{
"input": "aaaaaaaaaa aaaaaaaaaa",
"output": "aa"
},
{
"input": "aaaaaaaaaa a",
"output": "aa"
},
{
"input": "a aaaaaaaaaa",
"output": "aa"
},
{
"input": "zzaa b",
"output": "zb"
},
{
"input": "ca cf",
"output": "cac"
},
{
"input": "abhi ia",
"output": "abhi"
},
{
"input": "aaaa aaaab",
"output": "aa"
},
{
"input": "aar raa",
"output": "aar"
},
{
"input": "harry hotter",
"output": "hah"
},
{
"input": "aaaaaaa a",
"output": "aa"
},
{
"input": "apple pie",
"output": "ap"
},
{
"input": "aaa aaa",
"output": "aa"
},
{
"input": "kabc buba",
"output": "kab"
},
{
"input": "asd ss",
"output": "as"
},
{
"input": "bbb b",
"output": "bb"
}
] | 1,635,178,524
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 23
| 77
| 17,715,200
|
s=input().split()
out=""
out+=s[0][0]
for i in range(1,len(s[0])):
if ord(s[0][i])>ord(s[1][0]):
break
out+=s[0][i]
out+=s[1][0]
print(out)
|
Title: Generate Login
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users).
As a reminder, a prefix of a string *s* is its substring which occurs at the beginning of *s*: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string *a* is alphabetically earlier than a string *b*, if *a* is a prefix of *b*, or *a* and *b* coincide up to some position, and then *a* has a letter that is alphabetically earlier than the corresponding letter in *b*: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".
Input Specification:
The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.
Output Specification:
Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.
Demo Input:
['harry potter\n', 'tom riddle\n']
Demo Output:
['hap\n', 'tomr\n']
Note:
none
|
```python
s=input().split()
out=""
out+=s[0][0]
for i in range(1,len(s[0])):
if ord(s[0][i])>ord(s[1][0]):
break
out+=s[0][i]
out+=s[1][0]
print(out)
```
| 0
|
|
214
|
A
|
System of Equations
|
PROGRAMMING
| 800
|
[
"brute force"
] | null | null |
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
|
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
|
On a single line print the answer to the problem.
|
[
"9 3\n",
"14 28\n",
"4 20\n"
] |
[
"1\n",
"1\n",
"0\n"
] |
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
| 500
|
[
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10",
"output": "0"
},
{
"input": "8 20",
"output": "0"
},
{
"input": "2 8",
"output": "0"
},
{
"input": "20 11",
"output": "0"
},
{
"input": "57 447",
"output": "1"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "66 296",
"output": "1"
},
{
"input": "75 683",
"output": "1"
},
{
"input": "227 975",
"output": "1"
},
{
"input": "247 499",
"output": "1"
},
{
"input": "266 116",
"output": "1"
},
{
"input": "286 916",
"output": "1"
},
{
"input": "307 341",
"output": "1"
},
{
"input": "451 121",
"output": "1"
},
{
"input": "471 921",
"output": "1"
},
{
"input": "502 346",
"output": "1"
},
{
"input": "535 59",
"output": "1"
},
{
"input": "555 699",
"output": "1"
},
{
"input": "747 351",
"output": "1"
},
{
"input": "790 64",
"output": "1"
},
{
"input": "810 704",
"output": "1"
},
{
"input": "855 225",
"output": "1"
},
{
"input": "902 34",
"output": "1"
},
{
"input": "922 514",
"output": "1"
},
{
"input": "971 131",
"output": "1"
},
{
"input": "991 931",
"output": "1"
},
{
"input": "840 780",
"output": "0"
},
{
"input": "102 595",
"output": "0"
},
{
"input": "139 433",
"output": "0"
},
{
"input": "968 288",
"output": "0"
},
{
"input": "563 354",
"output": "0"
},
{
"input": "994 975",
"output": "0"
},
{
"input": "456 221",
"output": "0"
},
{
"input": "205 210",
"output": "0"
},
{
"input": "1 11",
"output": "0"
},
{
"input": "1000 1000",
"output": "0"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "11 99",
"output": "0"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "11 1",
"output": "0"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "100 452",
"output": "0"
},
{
"input": "420 380",
"output": "0"
},
{
"input": "31 31",
"output": "0"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "112 134",
"output": "0"
},
{
"input": "13 13",
"output": "0"
},
{
"input": "1 571",
"output": "0"
}
] | 1,644,261,037
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 54
| 716
| 0
|
a,b = map(int,input().split())
ctr = 0
if a == 1 and b == 1:
ctr+=2
for i in range(a):
for j in range(b):
if i**2 + j == a and i + j**2 == b:
ctr+=1
print(ctr)
|
Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
Input Specification:
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
Output Specification:
On a single line print the answer to the problem.
Demo Input:
['9 3\n', '14 28\n', '4 20\n']
Demo Output:
['1\n', '1\n', '0\n']
Note:
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
|
```python
a,b = map(int,input().split())
ctr = 0
if a == 1 and b == 1:
ctr+=2
for i in range(a):
for j in range(b):
if i**2 + j == a and i + j**2 == b:
ctr+=1
print(ctr)
```
| 3
|
|
492
|
A
|
Vanya and Cubes
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes.
Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya.
|
Print the maximum possible height of the pyramid in the single line.
|
[
"1\n",
"25\n"
] |
[
"1\n",
"4\n"
] |
Illustration to the second sample:
| 500
|
[
{
"input": "1",
"output": "1"
},
{
"input": "25",
"output": "4"
},
{
"input": "2",
"output": "1"
},
{
"input": "4115",
"output": "28"
},
{
"input": "9894",
"output": "38"
},
{
"input": "7969",
"output": "35"
},
{
"input": "6560",
"output": "33"
},
{
"input": "4",
"output": "2"
},
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "19",
"output": "3"
},
{
"input": "20",
"output": "4"
},
{
"input": "9880",
"output": "38"
},
{
"input": "9879",
"output": "37"
},
{
"input": "7770",
"output": "35"
},
{
"input": "7769",
"output": "34"
},
{
"input": "2925",
"output": "25"
},
{
"input": "220",
"output": "10"
},
{
"input": "219",
"output": "9"
},
{
"input": "3046",
"output": "25"
},
{
"input": "7590",
"output": "34"
},
{
"input": "1014",
"output": "17"
},
{
"input": "7142",
"output": "34"
},
{
"input": "9999",
"output": "38"
},
{
"input": "10000",
"output": "38"
}
] | 1,688,984,176
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
#!/usr/bin/python
a=int(raw_input())
c=0
i=0
l=0
while c<=a:
i+=1
l+=i
c=c+l
print i-1
|
Title: Vanya and Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes.
Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya.
Output Specification:
Print the maximum possible height of the pyramid in the single line.
Demo Input:
['1\n', '25\n']
Demo Output:
['1\n', '4\n']
Note:
Illustration to the second sample:
|
```python
#!/usr/bin/python
a=int(raw_input())
c=0
i=0
l=0
while c<=a:
i+=1
l+=i
c=c+l
print i-1
```
| -1
|
|
546
|
A
|
Soldier and Bananas
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation",
"math"
] | null | null |
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
|
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
|
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
|
[
"3 17 4\n"
] |
[
"13"
] |
none
| 500
|
[
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 1,695,228,015
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 31
| 0
|
k, n, w = [int(i) for i in input().split()]
price = 0
for i in range(1, w+1):
price += i*k
print(price-n)
|
Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
Input Specification:
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output Specification:
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Demo Input:
['3 17 4\n']
Demo Output:
['13']
Note:
none
|
```python
k, n, w = [int(i) for i in input().split()]
price = 0
for i in range(1, w+1):
price += i*k
print(price-n)
```
| 0
|
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.