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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
768
|
A
|
Oath of the Night's Watch
|
PROGRAMMING
| 900
|
[
"constructive algorithms",
"sortings"
] | null | null |
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support?
|
First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards.
|
Output a single integer representing the number of stewards which Jon will feed.
|
[
"2\n1 5\n",
"3\n1 2 5\n"
] |
[
"0",
"1"
] |
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.
| 500
|
[
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
{
"input": "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3 9 4 3 5 7 9 3 2 1 1 3 2 1 9 3 1 4 4 10 2 5 5 8 1 4 8 5 3 1 10 8 6 5 8 3 5 4 5 4 4 6 7 2 8 10 8 7 6 6 9 6 7 1 10 3 2 5 10 4 4 5 4 3 4 8 5 3 8 10 3 10 9 7 2 1 8 6 4 6 5 8 10 2 6 7 4 9 4 5 1 8 7 10 3 1",
"output": "174"
},
{
"input": "4\n1000000000 99999999 1000000000 1000000000",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "6\n1 1 3 3 2 2",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "4\n1 1 2 5",
"output": "1"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n1 1 1 1 5",
"output": "0"
},
{
"input": "5\n1 1 2 3 3",
"output": "1"
},
{
"input": "3\n1 1 3",
"output": "0"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "5\n1 5 3 5 1",
"output": "1"
},
{
"input": "7\n1 2 2 2 2 2 3",
"output": "5"
},
{
"input": "4\n2 2 2 2",
"output": "0"
},
{
"input": "9\n2 2 2 3 4 5 6 6 6",
"output": "3"
},
{
"input": "10\n1 1 1 2 3 3 3 3 3 3",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n0 0 1",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 3 3 3",
"output": "3"
},
{
"input": "3\n1 2 2",
"output": "0"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "0"
},
{
"input": "5\n2 2 2 2 2",
"output": "0"
},
{
"input": "5\n5 5 5 5 5",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "6\n1 2 5 5 5 5",
"output": "1"
},
{
"input": "5\n1 2 3 3 3",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "0"
},
{
"input": "6\n1 1 1 1 1 2",
"output": "0"
},
{
"input": "5\n1 1 2 4 4",
"output": "1"
},
{
"input": "3\n999999 5999999 9999999",
"output": "1"
},
{
"input": "4\n1 1 5 5",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 4 4 4",
"output": "3"
},
{
"input": "5\n1 3 4 5 1",
"output": "2"
},
{
"input": "5\n3 3 3 3 3",
"output": "0"
},
{
"input": "5\n1 1 2 2 2",
"output": "0"
},
{
"input": "5\n2 1 1 1 3",
"output": "1"
},
{
"input": "5\n0 0 0 1 2",
"output": "1"
},
{
"input": "4\n2 2 2 3",
"output": "0"
},
{
"input": "7\n1 1 1 1 5 5 5",
"output": "0"
},
{
"input": "5\n1 2 3 4 4",
"output": "2"
},
{
"input": "2\n5 4",
"output": "0"
},
{
"input": "4\n5 5 5 5",
"output": "0"
},
{
"input": "5\n1 1 1 5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "4\n1 2 2 2",
"output": "0"
},
{
"input": "8\n1000000000 1000000000 1000000000 999999999 999999999 999999999 999999998 999999998",
"output": "3"
},
{
"input": "5\n1 1 3 4 4",
"output": "1"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "2"
},
{
"input": "4\n1 1 1 1",
"output": "0"
},
{
"input": "9\n1 2 3 4 1 5 6 7 8",
"output": "6"
},
{
"input": "8\n5 4 4 6 6 4 4 3",
"output": "5"
},
{
"input": "8\n4 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "7\n4 3 3 3 3 3 3",
"output": "0"
},
{
"input": "6\n4 3 3 3 3 3",
"output": "0"
},
{
"input": "5\n4 3 3 3 3",
"output": "0"
}
] | 1,663,101,830
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 88
| 93
| 13,516,800
|
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
res = 0
for i in range(n):
if lst[i] != lst[0] and lst[i] != lst[-1]:
res += 1
res += 2
if res < 3:
print(0)
else:
print(res - 2)
|
Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support?
Input Specification:
First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards.
Output Specification:
Output a single integer representing the number of stewards which Jon will feed.
Demo Input:
['2\n1 5\n', '3\n1 2 5\n']
Demo Output:
['0', '1']
Note:
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.
|
```python
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
res = 0
for i in range(n):
if lst[i] != lst[0] and lst[i] != lst[-1]:
res += 1
res += 2
if res < 3:
print(0)
else:
print(res - 2)
```
| 3
|
|
260
|
A
|
Adding Digits
|
PROGRAMMING
| 1,400
|
[
"implementation",
"math"
] | null | null |
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times.
|
The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105).
|
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
|
[
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] |
[
"524848\n",
"121\n",
"-1\n"
] |
none
| 500
|
[
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99999 21 73839",
"output": "9999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99991 623 36438",
"output": "9999150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99999 334 94854",
"output": "9999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99252 9827 84849",
"output": "9925270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99313 9833 10561",
"output": "9931330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "94885 55815 11417",
"output": "9488550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99492 58525 53481",
"output": "9949250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99858 28531 79193",
"output": "9985850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99136 47208 42607",
"output": "9913680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "63270 19953 5555",
"output": "-1"
},
{
"input": "10240 128 100000",
"output": "1024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "12 11 3",
"output": "12100"
},
{
"input": "14 12 99998",
"output": "1440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "1 11 3",
"output": "1100"
},
{
"input": "3 40 1",
"output": "-1"
},
{
"input": "150 100 10",
"output": "1500000000000"
},
{
"input": "5 10 1",
"output": "50"
},
{
"input": "1 15 10",
"output": "15000000000"
},
{
"input": "3 13 2",
"output": "390"
}
] | 1,626,201,810
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 5
| 2,000
| 12,800,000
|
a,b,n=map(int,input().split())
x,i=a,0
while i<n:
for j in range(10):
if (a*10+j)%b==0:
a=a*10+j
break
i+=1
if a==x:
print(-1)
else:
print(a)
|
Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times.
Input Specification:
The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105).
Output Specification:
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Demo Input:
['5 4 5\n', '12 11 1\n', '260 150 10\n']
Demo Output:
['524848\n', '121\n', '-1\n']
Note:
none
|
```python
a,b,n=map(int,input().split())
x,i=a,0
while i<n:
for j in range(10):
if (a*10+j)%b==0:
a=a*10+j
break
i+=1
if a==x:
print(-1)
else:
print(a)
```
| 0
|
|
190
|
B
|
Surrounded
|
PROGRAMMING
| 1,800
|
[
"geometry"
] | null | null |
So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation.
Right now the situation in Berland is dismal — their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surrounded cities. At any moment all points of the flatland ring can begin to move quickly in the direction of the city — that's the strategy the flatlanders usually follow when they besiege cities.
The berlanders are sure that they can repel the enemy's attack if they learn the exact time the attack starts. For that they need to construct a radar that would register any movement at the distance of at most *r* from it. Thus, we can install a radar at such point, that at least one point of the enemy ring will be in its detecting range (that is, at a distance of at most *r*). Then the radar can immediately inform about the enemy's attack.
Due to the newest technologies, we can place a radar at any point without any problems. But the problem is that the berlanders have the time to make only one radar. Besides, the larger the detection radius (*r*) is, the more the radar costs.
That's why Vasya's task (that is, your task) is to find the minimum possible detection radius for the radar. In other words, your task is to find the minimum radius *r* (*r*<=≥<=0) such, that a radar with radius *r* can be installed at some point and it can register the start of the movements of both flatland rings from that point.
In this problem you can consider the cities as material points, the attacking enemy rings - as circles with centers in the cities, the radar's detection range — as a disk (including the border) with the center at the point where the radar is placed.
|
The input files consist of two lines. Each line represents the city and the flatland ring that surrounds it as three space-separated integers *x**i*, *y**i*, *r**i* (|*x**i*|,<=|*y**i*|<=≤<=104; 1<=≤<=*r**i*<=≤<=104) — the city's coordinates and the distance from the city to the flatlanders, correspondingly.
It is guaranteed that the cities are located at different points.
|
Print a single real number — the minimum detection radius of the described radar. The answer is considered correct if the absolute or relative error does not exceed 10<=-<=6.
|
[
"0 0 1\n6 0 3\n",
"-10 10 3\n10 -10 3\n"
] |
[
"1.000000000000000",
"11.142135623730951"
] |
The figure below shows the answer to the first sample. In this sample the best decision is to put the radar at point with coordinates (2, 0).
The figure below shows the answer for the second sample. In this sample the best decision is to put the radar at point with coordinates (0, 0).
| 1,000
|
[
{
"input": "0 0 1\n6 0 3",
"output": "1.000000000000000"
},
{
"input": "-10 10 3\n10 -10 3",
"output": "11.142135623730951"
},
{
"input": "2 1 3\n8 9 5",
"output": "1.000000000000000"
},
{
"input": "0 0 1\n-10 -10 9",
"output": "2.071067811865475"
},
{
"input": "10000 -9268 1\n-9898 9000 10",
"output": "13500.519287710202000"
},
{
"input": "10000 10000 1\n-10000 -10000 1",
"output": "14141.135623730950000"
},
{
"input": "123 21 50\n10 100 1000",
"output": "406.061621719103360"
},
{
"input": "0 3278 2382\n2312 1 1111",
"output": "258.747677968983450"
},
{
"input": "3 4 5\n5 12 13",
"output": "0.000000000000000"
},
{
"input": "-2 7 5\n4 0 6",
"output": "0.000000000000000"
},
{
"input": "4 0 2\n6 -1 10",
"output": "2.881966011250105"
},
{
"input": "41 17 3\n71 -86 10",
"output": "47.140003728560643"
},
{
"input": "761 641 6\n506 -293 5",
"output": "478.592191632957450"
},
{
"input": "-5051 -7339 9\n-9030 755 8",
"output": "4501.080828635849700"
},
{
"input": "0 5 2\n8 -4 94",
"output": "39.979202710603850"
},
{
"input": "83 -64 85\n27 80 89",
"output": "0.000000000000000"
},
{
"input": "-655 -750 68\n905 -161 68",
"output": "765.744715125679250"
},
{
"input": "1055 -5271 60\n-2992 8832 38",
"output": "7287.089182936641900"
},
{
"input": "4 0 201\n-6 4 279",
"output": "33.614835192865499"
},
{
"input": "-34 -5 836\n52 -39 706",
"output": "18.761487913212431"
},
{
"input": "659 -674 277\n-345 -556 127",
"output": "303.455240352694320"
},
{
"input": "4763 2945 956\n3591 9812 180",
"output": "2915.147750239716500"
},
{
"input": "3 -7 5749\n1 -6 9750",
"output": "1999.381966011250100"
},
{
"input": "28 -63 2382\n43 -83 1364",
"output": "496.500000000000000"
},
{
"input": "315 -532 7813\n407 -157 2121",
"output": "2652.939776235497000"
},
{
"input": "-9577 9051 5276\n-4315 -1295 8453",
"output": "0.000000000000000"
},
{
"input": "-7 -10 1\n-4 3 1",
"output": "5.670832032063167"
},
{
"input": "-74 27 535\n18 84 1",
"output": "212.886692948961240"
},
{
"input": "-454 -721 72\n-33 279 911",
"output": "51.003686623418254"
},
{
"input": "-171 762 304\n-428 -85 523",
"output": "29.065814314662131"
},
{
"input": "192 -295 1386\n-54 -78 1",
"output": "528.483994683445640"
},
{
"input": "-5134 -9860 5513\n6291 -855 9034",
"output": "0.093506651303098"
},
{
"input": "6651 8200 610\n-9228 9387 10000",
"output": "2656.651995660197400"
},
{
"input": "6370 7728 933\n4595 3736 2748",
"output": "343.915768575204200"
},
{
"input": "-6 3 8\n7 2 1",
"output": "2.019202405202649"
},
{
"input": "0 -1 1\n1 -1 1",
"output": "0.000000000000000"
},
{
"input": "0 1 3\n1 -1 1",
"output": "0.000000000000000"
},
{
"input": "-2 0 1\n3 -2 1",
"output": "1.692582403567252"
},
{
"input": "-10000 42 10000\n10000 43 10000",
"output": "0.000012499999992"
},
{
"input": "103 104 5\n97 96 5",
"output": "0.000000000000000"
},
{
"input": "2587 4850 3327\n3278 -204 1774",
"output": "0.009605941526345"
},
{
"input": "826 4417 2901\n833 -2286 3802",
"output": "0.001827539409235"
},
{
"input": "1003 -5005 3399\n-6036 -1729 4365",
"output": "0.000032199896827"
}
] | 1,594,384,191
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 43
| 109
| 6,963,200
|
x1,y1,r1=list(map(float,input().split()))
x2,y2,r2=list(map(float,input().split()))
if r1>r2:
r2,r1=r1,r2
d=((x2-x1)**2 + (y2-y1)**2)**(0.5)
if d>r1+r2:
print((d-(r1+r2))/2)
elif r2>d+r1:
print((r2-(r1+d))/2)
else:
print(0)
|
Title: Surrounded
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation.
Right now the situation in Berland is dismal — their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surrounded cities. At any moment all points of the flatland ring can begin to move quickly in the direction of the city — that's the strategy the flatlanders usually follow when they besiege cities.
The berlanders are sure that they can repel the enemy's attack if they learn the exact time the attack starts. For that they need to construct a radar that would register any movement at the distance of at most *r* from it. Thus, we can install a radar at such point, that at least one point of the enemy ring will be in its detecting range (that is, at a distance of at most *r*). Then the radar can immediately inform about the enemy's attack.
Due to the newest technologies, we can place a radar at any point without any problems. But the problem is that the berlanders have the time to make only one radar. Besides, the larger the detection radius (*r*) is, the more the radar costs.
That's why Vasya's task (that is, your task) is to find the minimum possible detection radius for the radar. In other words, your task is to find the minimum radius *r* (*r*<=≥<=0) such, that a radar with radius *r* can be installed at some point and it can register the start of the movements of both flatland rings from that point.
In this problem you can consider the cities as material points, the attacking enemy rings - as circles with centers in the cities, the radar's detection range — as a disk (including the border) with the center at the point where the radar is placed.
Input Specification:
The input files consist of two lines. Each line represents the city and the flatland ring that surrounds it as three space-separated integers *x**i*, *y**i*, *r**i* (|*x**i*|,<=|*y**i*|<=≤<=104; 1<=≤<=*r**i*<=≤<=104) — the city's coordinates and the distance from the city to the flatlanders, correspondingly.
It is guaranteed that the cities are located at different points.
Output Specification:
Print a single real number — the minimum detection radius of the described radar. The answer is considered correct if the absolute or relative error does not exceed 10<=-<=6.
Demo Input:
['0 0 1\n6 0 3\n', '-10 10 3\n10 -10 3\n']
Demo Output:
['1.000000000000000', '11.142135623730951']
Note:
The figure below shows the answer to the first sample. In this sample the best decision is to put the radar at point with coordinates (2, 0).
The figure below shows the answer for the second sample. In this sample the best decision is to put the radar at point with coordinates (0, 0).
|
```python
x1,y1,r1=list(map(float,input().split()))
x2,y2,r2=list(map(float,input().split()))
if r1>r2:
r2,r1=r1,r2
d=((x2-x1)**2 + (y2-y1)**2)**(0.5)
if d>r1+r2:
print((d-(r1+r2))/2)
elif r2>d+r1:
print((r2-(r1+d))/2)
else:
print(0)
```
| 3
|
|
96
|
A
|
Football
|
PROGRAMMING
| 900
|
[
"implementation",
"strings"
] |
A. Football
|
2
|
256
|
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
|
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
|
Print "YES" if the situation is dangerous. Otherwise, print "NO".
|
[
"001001\n",
"1000000001\n"
] |
[
"NO\n",
"YES\n"
] |
none
| 500
|
[
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"output": "NO"
},
{
"input": "1010010100000000010",
"output": "YES"
},
{
"input": "101010101",
"output": "NO"
},
{
"input": "000000000100000000000110101100000",
"output": "YES"
},
{
"input": "100001000000110101100000",
"output": "NO"
},
{
"input": "100001000011010110000",
"output": "NO"
},
{
"input": "010",
"output": "NO"
},
{
"input": "10101011111111111111111111111100",
"output": "YES"
},
{
"input": "1001101100",
"output": "NO"
},
{
"input": "1001101010",
"output": "NO"
},
{
"input": "1111100111",
"output": "NO"
},
{
"input": "00110110001110001111",
"output": "NO"
},
{
"input": "11110001001111110001",
"output": "NO"
},
{
"input": "10001111001011111101",
"output": "NO"
},
{
"input": "10000010100000001000110001010100001001001010011",
"output": "YES"
},
{
"input": "01111011111010111100101100001011001010111110000010",
"output": "NO"
},
{
"input": "00100000100100101110011001011011101110110110010100",
"output": "NO"
},
{
"input": "10110100110001001011110101110010100010000000000100101010111110111110100011",
"output": "YES"
},
{
"input": "00011101010101111001011011001101101011111101000010100000111000011100101011",
"output": "NO"
},
{
"input": "01110000110100110101110100111000101101011101011110110100100111100001110111",
"output": "NO"
},
{
"input": "11110110011000100111100111101101011111110100010101011011111101110110110111",
"output": "YES"
},
{
"input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100",
"output": "NO"
},
{
"input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010",
"output": "NO"
},
{
"input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110",
"output": "NO"
},
{
"input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000",
"output": "NO"
},
{
"input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110",
"output": "YES"
},
{
"input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000",
"output": "NO"
},
{
"input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101",
"output": "YES"
},
{
"input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101",
"output": "YES"
},
{
"input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000",
"output": "NO"
},
{
"input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000",
"output": "YES"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "YES"
},
{
"input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111",
"output": "YES"
},
{
"input": "10100101000",
"output": "NO"
},
{
"input": "11110111011101",
"output": "NO"
},
{
"input": "10000000",
"output": "YES"
},
{
"input": "00000001",
"output": "YES"
},
{
"input": "01111111",
"output": "YES"
},
{
"input": "11111110",
"output": "YES"
}
] | 1,689,587,453
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 92
| 0
|
def solve():
string = input()
character, cnt = "", 0
arr = []
for char in string:
if character == "":
character, cnt = char, 1
elif character == char:
cnt += 1
else:
arr.append(cnt)
character, cnt = char, 1
print("YES" if max(arr) >= 7 else "NO")
def main():
# t = int(input())
t = 1
for _ in range(t):
solve()
if __name__ == "__main__":
main()
|
Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
Input Specification:
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Output Specification:
Print "YES" if the situation is dangerous. Otherwise, print "NO".
Demo Input:
['001001\n', '1000000001\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none
|
```python
def solve():
string = input()
character, cnt = "", 0
arr = []
for char in string:
if character == "":
character, cnt = char, 1
elif character == char:
cnt += 1
else:
arr.append(cnt)
character, cnt = char, 1
print("YES" if max(arr) >= 7 else "NO")
def main():
# t = int(input())
t = 1
for _ in range(t):
solve()
if __name__ == "__main__":
main()
```
| 0
|
459
|
A
|
Pashmak and Garden
|
PROGRAMMING
| 1,200
|
[
"implementation"
] | null | null |
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
|
The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
|
If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<=*y*3,<=*x*4,<=*y*4<=≤<=1000).
|
[
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] |
[
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] |
none
| 500
|
[
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input": "0 -100 0 100",
"output": "200 -100 200 100"
},
{
"input": "27 -74 27 74",
"output": "175 -74 175 74"
},
{
"input": "0 1 2 3",
"output": "0 3 2 1"
},
{
"input": "-100 100 100 -100",
"output": "-100 -100 100 100"
},
{
"input": "-100 -100 -100 100",
"output": "100 -100 100 100"
},
{
"input": "100 100 100 -100",
"output": "300 100 300 -100"
},
{
"input": "100 -100 -100 -100",
"output": "100 100 -100 100"
},
{
"input": "-100 100 100 100",
"output": "-100 300 100 300"
},
{
"input": "0 1 0 0",
"output": "1 1 1 0"
},
{
"input": "1 1 0 0",
"output": "1 0 0 1"
},
{
"input": "0 0 1 0",
"output": "0 1 1 1"
},
{
"input": "1 0 0 1",
"output": "1 1 0 0"
},
{
"input": "1 0 1 1",
"output": "2 0 2 1"
},
{
"input": "1 1 0 1",
"output": "1 2 0 2"
},
{
"input": "15 -9 80 -9",
"output": "15 56 80 56"
},
{
"input": "51 -36 18 83",
"output": "-1"
},
{
"input": "69 -22 60 16",
"output": "-1"
},
{
"input": "-68 -78 -45 -55",
"output": "-68 -55 -45 -78"
},
{
"input": "68 -92 8 -32",
"output": "68 -32 8 -92"
},
{
"input": "95 -83 -39 -6",
"output": "-1"
},
{
"input": "54 94 53 -65",
"output": "-1"
},
{
"input": "-92 15 84 15",
"output": "-92 191 84 191"
},
{
"input": "67 77 -11 -1",
"output": "67 -1 -11 77"
},
{
"input": "91 -40 30 21",
"output": "91 21 30 -40"
},
{
"input": "66 -64 -25 -64",
"output": "66 27 -25 27"
},
{
"input": "-42 84 -67 59",
"output": "-42 59 -67 84"
},
{
"input": "73 47 -5 -77",
"output": "-1"
},
{
"input": "6 85 -54 -84",
"output": "-1"
},
{
"input": "-58 -55 40 43",
"output": "-58 43 40 -55"
},
{
"input": "56 22 48 70",
"output": "-1"
},
{
"input": "-17 -32 76 -32",
"output": "-17 61 76 61"
},
{
"input": "0 2 2 0",
"output": "0 0 2 2"
},
{
"input": "0 0 -1 1",
"output": "0 1 -1 0"
},
{
"input": "0 2 1 1",
"output": "0 1 1 2"
},
{
"input": "0 0 1 -1",
"output": "0 -1 1 0"
},
{
"input": "-1 2 -2 3",
"output": "-1 3 -2 2"
},
{
"input": "0 1 1 0",
"output": "0 0 1 1"
},
{
"input": "1 2 2 1",
"output": "1 1 2 2"
},
{
"input": "4 1 2 1",
"output": "4 3 2 3"
},
{
"input": "70 0 0 10",
"output": "-1"
},
{
"input": "2 3 4 1",
"output": "2 1 4 3"
},
{
"input": "1 3 3 1",
"output": "1 1 3 3"
},
{
"input": "-3 3 0 0",
"output": "-3 0 0 3"
},
{
"input": "2 8 7 3",
"output": "2 3 7 8"
},
{
"input": "1 2 2 3",
"output": "1 3 2 2"
},
{
"input": "0 3 3 0",
"output": "0 0 3 3"
},
{
"input": "0 0 -3 3",
"output": "0 3 -3 0"
},
{
"input": "0 2 1 2",
"output": "0 3 1 3"
},
{
"input": "1 1 2 0",
"output": "1 0 2 1"
},
{
"input": "0 0 5 0",
"output": "0 5 5 5"
},
{
"input": "3 4 7 8",
"output": "3 8 7 4"
},
{
"input": "0 5 5 0",
"output": "0 0 5 5"
},
{
"input": "5 6 8 3",
"output": "5 3 8 6"
},
{
"input": "2 2 1 1",
"output": "2 1 1 2"
},
{
"input": "0 1 3 1",
"output": "0 4 3 4"
},
{
"input": "2 4 5 4",
"output": "2 7 5 7"
},
{
"input": "0 5 1 5",
"output": "0 6 1 6"
},
{
"input": "4 0 0 4",
"output": "4 4 0 0"
},
{
"input": "0 1 1 8",
"output": "-1"
},
{
"input": "2 3 3 4",
"output": "2 4 3 3"
},
{
"input": "1 0 2 1",
"output": "1 1 2 0"
},
{
"input": "0 0 2 14",
"output": "-1"
},
{
"input": "0 0 4 3",
"output": "-1"
},
{
"input": "3 5 5 3",
"output": "3 3 5 5"
},
{
"input": "-1 1 1 -1",
"output": "-1 -1 1 1"
},
{
"input": "0 0 2 0",
"output": "0 2 2 2"
},
{
"input": "0 0 1 7",
"output": "-1"
},
{
"input": "1 2 3 2",
"output": "1 4 3 4"
},
{
"input": "1 12 3 10",
"output": "1 10 3 12"
}
] | 1,657,634,365
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 0
|
def pashmak_and_garden():
points = [int(point) for point in input().split()]
conj_points = (points[0] == points[2]) or (points[1] == points[3])
diff = [points[i] - points[i+2] for i in range(2)]
print(diff)
unique_diff = list(set(diff))
nunique_diff = len(unique_diff)
if (nunique_diff == 1):
other_points = [str(points[0]), str(points[1] - unique_diff[0]), str(points[0] - unique_diff[0]), str(points[1])]
print(" ".join(other_points))
elif (conj_points):
other_points = [[points[i]+diff[i-1], points[i+2]+diff[i-1]] for i in range(2)]
other_points = [str(point[0]) for point in other_points] + [str(point[1]) for point in other_points]
print(" ".join(other_points))
else:
print(-1)
pashmak_and_garden()
|
Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
Input Specification:
The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
Output Specification:
If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<=*y*3,<=*x*4,<=*y*4<=≤<=1000).
Demo Input:
['0 0 0 1\n', '0 0 1 1\n', '0 0 1 2\n']
Demo Output:
['1 0 1 1\n', '0 1 1 0\n', '-1\n']
Note:
none
|
```python
def pashmak_and_garden():
points = [int(point) for point in input().split()]
conj_points = (points[0] == points[2]) or (points[1] == points[3])
diff = [points[i] - points[i+2] for i in range(2)]
print(diff)
unique_diff = list(set(diff))
nunique_diff = len(unique_diff)
if (nunique_diff == 1):
other_points = [str(points[0]), str(points[1] - unique_diff[0]), str(points[0] - unique_diff[0]), str(points[1])]
print(" ".join(other_points))
elif (conj_points):
other_points = [[points[i]+diff[i-1], points[i+2]+diff[i-1]] for i in range(2)]
other_points = [str(point[0]) for point in other_points] + [str(point[1]) for point in other_points]
print(" ".join(other_points))
else:
print(-1)
pashmak_and_garden()
```
| 0
|
|
165
|
E
|
Compatible Numbers
|
PROGRAMMING
| 2,200
|
[
"bitmasks",
"brute force",
"dfs and similar",
"dp"
] | null | null |
Two integers *x* and *y* are compatible, if the result of their bitwise "AND" equals zero, that is, *a* & *b*<==<=0. For example, numbers 90 (10110102) and 36 (1001002) are compatible, as 10110102 & 1001002<==<=02, and numbers 3 (112) and 6 (1102) are not compatible, as 112 & 1102<==<=102.
You are given an array of integers *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find the following for each array element: is this element compatible with some other element from the given array? If the answer to this question is positive, then you also should find any suitable element.
|
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the number of elements in the given array. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=4·106) — the elements of the given array. The numbers in the array can coincide.
|
Print *n* integers *ans**i*. If *a**i* isn't compatible with any other element of the given array *a*1,<=*a*2,<=...,<=*a**n*, then *ans**i* should be equal to -1. Otherwise *ans**i* is any such number, that *a**i* & *ans**i*<==<=0, and also *ans**i* occurs in the array *a*1,<=*a*2,<=...,<=*a**n*.
|
[
"2\n90 36\n",
"4\n3 6 3 6\n",
"5\n10 6 9 8 2\n"
] |
[
"36 90",
"-1 -1 -1 -1",
"-1 8 2 2 8"
] |
none
| 2,500
|
[
{
"input": "2\n90 36",
"output": "36 90"
},
{
"input": "4\n3 6 3 6",
"output": "-1 -1 -1 -1"
},
{
"input": "5\n10 6 9 8 2",
"output": "-1 8 2 2 8"
},
{
"input": "10\n4 9 8 3 2 6 8 2 9 7",
"output": "8 4 4 8 8 8 4 8 4 8"
},
{
"input": "10\n3 5 18 12 4 20 11 19 15 6",
"output": "4 18 4 18 18 3 4 4 -1 -1"
},
{
"input": "15\n8 4 9 3 6 6 6 6 1 6 7 1 8 9 2",
"output": "4 8 4 8 8 8 8 8 8 8 8 8 4 4 8"
},
{
"input": "20\n280 983 126 941 167 215 868 748 383 554 917 285 43 445 331 800 527 998 503 164",
"output": "164 -1 -1 -1 280 800 -1 -1 -1 -1 -1 -1 -1 -1 164 215 -1 -1 -1 280"
},
{
"input": "5\n1 4 2 3 5",
"output": "4 2 4 4 2"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "1\n4000000",
"output": "-1"
},
{
"input": "1\n2097152",
"output": "-1"
}
] | 1,684,740,709
| 2,147,483,647
|
PyPy 3-64
|
MEMORY_LIMIT_EXCEEDED
|
TESTS
| 0
| 1,776
| 268,390,400
|
# for I/O for local system
import sys
from os import path
if(path.exists('Input.txt')):
sys.stdin = open("Input.txt","r")
sys.stdout = open("Output.txt","w")
# For fast I/O
input = sys.stdin.buffer.readline
# input = sys.stdin.readline
print = sys.stdout.write
# Import libraries here whenever required
from random import randint
# Use this because normal dict can sometimes give TLE
class mydict:
def __init__(self, func=lambda: 0):
self.random = randint(0, 1 << 32)
self.default = func
self.dict = {}
def __getitem__(self, key):
mykey = self.random ^ key
if mykey not in self.dict:
self.dict[mykey] = self.default()
return self.dict[mykey]
def get(self, key, default):
mykey = self.random ^ key
if mykey not in self.dict:
return default
return self.dict[mykey]
def __setitem__(self, key, item):
mykey = self.random ^ key
self.dict[mykey] = item
def getkeys(self):
return [self.random ^ i for i in self.dict]
def __str__(self):
return f'{[(self.random ^ i, self.dict[i]) for i in self.dict]}'
# Solver function
def solve():
n = int(input())
a = [int(x) for x in input().split()]
maxN = 22
dp = [0 for i in range((1 << maxN) + 1)]
ans = mydict(list)
for i in a:
dp[i] += 1
ans[i].append(i)
for bit in range(maxN + 1):
for mask in range((1 << maxN) + 1):
if(mask & (1 << bit)):
dp[mask] += dp[mask ^ (1 << bit)]
if(len(ans[mask ^ (1 << bit)]) > 0):
ans[mask].append(ans[mask ^ (1 << bit)][0])
for i in range(n):
if(len(ans[((1 << maxN) - 1) ^ a[i]]) == 0):
print("-1 ")
else:
print(str(ans[((1 << maxN) - 1) ^ a[i]][0]) + " ")
print("\n")
# Main
for _ in range(1):
solve()
|
Title: Compatible Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two integers *x* and *y* are compatible, if the result of their bitwise "AND" equals zero, that is, *a* & *b*<==<=0. For example, numbers 90 (10110102) and 36 (1001002) are compatible, as 10110102 & 1001002<==<=02, and numbers 3 (112) and 6 (1102) are not compatible, as 112 & 1102<==<=102.
You are given an array of integers *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find the following for each array element: is this element compatible with some other element from the given array? If the answer to this question is positive, then you also should find any suitable element.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the number of elements in the given array. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=4·106) — the elements of the given array. The numbers in the array can coincide.
Output Specification:
Print *n* integers *ans**i*. If *a**i* isn't compatible with any other element of the given array *a*1,<=*a*2,<=...,<=*a**n*, then *ans**i* should be equal to -1. Otherwise *ans**i* is any such number, that *a**i* & *ans**i*<==<=0, and also *ans**i* occurs in the array *a*1,<=*a*2,<=...,<=*a**n*.
Demo Input:
['2\n90 36\n', '4\n3 6 3 6\n', '5\n10 6 9 8 2\n']
Demo Output:
['36 90', '-1 -1 -1 -1', '-1 8 2 2 8']
Note:
none
|
```python
# for I/O for local system
import sys
from os import path
if(path.exists('Input.txt')):
sys.stdin = open("Input.txt","r")
sys.stdout = open("Output.txt","w")
# For fast I/O
input = sys.stdin.buffer.readline
# input = sys.stdin.readline
print = sys.stdout.write
# Import libraries here whenever required
from random import randint
# Use this because normal dict can sometimes give TLE
class mydict:
def __init__(self, func=lambda: 0):
self.random = randint(0, 1 << 32)
self.default = func
self.dict = {}
def __getitem__(self, key):
mykey = self.random ^ key
if mykey not in self.dict:
self.dict[mykey] = self.default()
return self.dict[mykey]
def get(self, key, default):
mykey = self.random ^ key
if mykey not in self.dict:
return default
return self.dict[mykey]
def __setitem__(self, key, item):
mykey = self.random ^ key
self.dict[mykey] = item
def getkeys(self):
return [self.random ^ i for i in self.dict]
def __str__(self):
return f'{[(self.random ^ i, self.dict[i]) for i in self.dict]}'
# Solver function
def solve():
n = int(input())
a = [int(x) for x in input().split()]
maxN = 22
dp = [0 for i in range((1 << maxN) + 1)]
ans = mydict(list)
for i in a:
dp[i] += 1
ans[i].append(i)
for bit in range(maxN + 1):
for mask in range((1 << maxN) + 1):
if(mask & (1 << bit)):
dp[mask] += dp[mask ^ (1 << bit)]
if(len(ans[mask ^ (1 << bit)]) > 0):
ans[mask].append(ans[mask ^ (1 << bit)][0])
for i in range(n):
if(len(ans[((1 << maxN) - 1) ^ a[i]]) == 0):
print("-1 ")
else:
print(str(ans[((1 << maxN) - 1) ^ a[i]][0]) + " ")
print("\n")
# Main
for _ in range(1):
solve()
```
| 0
|
|
469
|
A
|
I Wanna Be the Guy
|
PROGRAMMING
| 800
|
[
"greedy",
"implementation"
] | null | null |
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
|
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
|
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
|
[
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] |
[
"I become the guy.\n",
"Oh, my keyboard!\n"
] |
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4.
| 500
|
[
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output": "I become the guy."
},
{
"input": "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5",
"output": "I become the guy."
},
{
"input": "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 57 28 54 1 51 66 27 22 93 59 68 88 91 29 7 20 63 8 52 23 64 58 100 79 65 49 96 71 33 45\n83 50 89 73 34 28 99 67 77 44 19 60 68 42 8 27 94 85 14 39 17 78 24 21 29 63 92 32 86 22 71 81 31 82 65 48 80 59 98 3 70 55 37 12 15 72 47 9 11 33 16 7 91 74 13 64 38 84 6 61 93 90 45 69 1 54 52 100 57 10 35 49 53 75 76 43 62 5 4 18 36 96 79 23",
"output": "Oh, my keyboard!"
},
{
"input": "1\n1 1\n1 1",
"output": "I become the guy."
},
{
"input": "1\n0\n1 1",
"output": "I become the guy."
},
{
"input": "1\n1 1\n0",
"output": "I become the guy."
},
{
"input": "1\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n44 71 70 55 49 43 16 53 7 95 58 56 38 76 67 94 20 73 29 90 25 30 8 84 5 14 77 52 99 91 66 24 39 37 22 44 78 12 63 59 32 51 15 82 34\n56 17 10 96 80 69 13 81 31 57 4 48 68 89 50 45 3 33 36 2 72 100 64 87 21 75 54 74 92 65 23 40 97 61 18 28 98 93 35 83 9 79 46 27 41 62 88 6 47 60 86 26 42 85 19 1 11",
"output": "I become the guy."
},
{
"input": "100\n78 63 59 39 11 58 4 2 80 69 22 95 90 26 65 16 30 100 66 99 67 79 54 12 23 28 45 56 70 74 60 82 73 91 68 43 92 75 51 21 17 97 86 44 62 47 85 78 72 64 50 81 71 5 57 13 31 76 87 9 49 96 25 42 19 35 88 53 7 83 38 27 29 41 89 93 10 84 18\n78 1 16 53 72 99 9 36 59 49 75 77 94 79 35 4 92 42 82 83 76 97 20 68 55 47 65 50 14 30 13 67 98 8 7 40 64 32 87 10 33 90 93 18 26 71 17 46 24 28 89 58 37 91 39 34 25 48 84 31 96 95 80 88 3 51 62 52 85 61 12 15 27 6 45 38 2 22 60",
"output": "I become the guy."
},
{
"input": "2\n2 2 1\n0",
"output": "I become the guy."
},
{
"input": "2\n1 2\n2 1 2",
"output": "I become the guy."
},
{
"input": "80\n57 40 1 47 36 69 24 76 5 72 26 4 29 62 6 60 3 70 8 64 18 37 16 14 13 21 25 7 66 68 44 74 61 39 38 33 15 63 34 65 10 23 56 51 80 58 49 75 71 12 50 57 2 30 54 27 17 52\n61 22 67 15 28 41 26 1 80 44 3 38 18 37 79 57 11 7 65 34 9 36 40 5 48 29 64 31 51 63 27 4 50 13 24 32 58 23 19 46 8 73 39 2 21 56 77 53 59 78 43 12 55 45 30 74 33 68 42 47 17 54",
"output": "Oh, my keyboard!"
},
{
"input": "100\n78 87 96 18 73 32 38 44 29 64 40 70 47 91 60 69 24 1 5 34 92 94 99 22 83 65 14 68 15 20 74 31 39 100 42 4 97 46 25 6 8 56 79 9 71 35 54 19 59 93 58 62 10 85 57 45 33 7 86 81 30 98 26 61 84 41 23 28 88 36 66 51 80 53 37 63 43 95 75\n76 81 53 15 26 37 31 62 24 87 41 39 75 86 46 76 34 4 51 5 45 65 67 48 68 23 71 27 94 47 16 17 9 96 84 89 88 100 18 52 69 42 6 92 7 64 49 12 98 28 21 99 25 55 44 40 82 19 36 30 77 90 14 43 50 3 13 95 78 35 20 54 58 11 2 1 33",
"output": "Oh, my keyboard!"
},
{
"input": "100\n77 55 26 98 13 91 78 60 23 76 12 11 36 62 84 80 18 1 68 92 81 67 19 4 2 10 17 77 96 63 15 69 46 97 82 42 83 59 50 72 14 40 89 9 52 29 56 31 74 39 45 85 22 99 44 65 95 6 90 38 54 32 49 34 3 70 75 33 94 53 21 71 5 66 73 41 100 24\n69 76 93 5 24 57 59 6 81 4 30 12 44 15 67 45 73 3 16 8 47 95 20 64 68 85 54 17 90 86 66 58 13 37 42 51 35 32 1 28 43 80 7 14 48 19 62 55 2 91 25 49 27 26 38 79 89 99 22 60 75 53 88 82 34 21 87 71 72 61",
"output": "I become the guy."
},
{
"input": "100\n74 96 32 63 12 69 72 99 15 22 1 41 79 77 71 31 20 28 75 73 85 37 38 59 42 100 86 89 55 87 68 4 24 57 52 8 92 27 56 98 95 58 34 9 45 14 11 36 66 76 61 19 25 23 78 49 90 26 80 43 70 13 65 10 5 74 81 21 44 60 97 3 47 93 6\n64 68 21 27 16 91 23 22 33 12 71 88 90 50 62 43 28 29 57 59 5 74 10 95 35 1 67 93 36 32 86 40 6 64 78 46 89 15 84 53 18 30 17 85 2 3 47 92 25 48 76 51 20 82 52 83 99 63 80 11 94 54 39 7 58",
"output": "I become the guy."
},
{
"input": "100\n75 11 98 44 47 88 94 23 78 59 70 2 43 39 34 63 71 19 42 61 30 74 14 77 97 53 92 60 67 36 37 13 6 86 62 46 41 3 25 93 7 12 27 48 55 49 31 35 51 10 57 54 95 82 28 90 73 26 17 50 81 56 20 87 40 85 72 64 99 29 91 5 80 18 24 52\n72 93 59 5 88 47 9 58 48 1 43 50 100 87 61 91 45 98 99 56 25 84 53 73 78 54 63 38 37 2 77 95 89 85 4 90 10 33 12 22 74 32 34 70 71 52 96 57 15 66 31 27 75 8 21 39 62 44 67 94 81 68 14 19 36 28 11 79 16 65 46 83 76",
"output": "Oh, my keyboard!"
},
{
"input": "3\n1 2\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "4\n1 2\n3 1 3 4",
"output": "I become the guy."
},
{
"input": "6\n2 1 2\n3 4 5 6",
"output": "Oh, my keyboard!"
}
] | 1,691,366,352
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 26
| 46
| 0
|
n = int(input())
x = set(input().split())
y = set(input().split())
x.update(y)
if '0' in x:
n += 1
if len(x) == n:
print('I become the guy.')
else:
print('Oh, my keyboard!')
|
Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
Input Specification:
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
Output Specification:
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
Demo Input:
['4\n3 1 2 3\n2 2 4\n', '4\n3 1 2 3\n2 2 3\n']
Demo Output:
['I become the guy.\n', 'Oh, my keyboard!\n']
Note:
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4.
|
```python
n = int(input())
x = set(input().split())
y = set(input().split())
x.update(y)
if '0' in x:
n += 1
if len(x) == n:
print('I become the guy.')
else:
print('Oh, my keyboard!')
```
| 0
|
|
222
|
B
|
Cosmic Tables
|
PROGRAMMING
| 1,300
|
[
"data structures",
"implementation"
] | null | null |
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an *n*<=×<=*m* table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
- The query to swap two table rows; - The query to swap two table columns; - The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
|
The first line contains three space-separated integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=500000) — the number of table columns and rows and the number of queries, correspondingly.
Next *n* lines contain *m* space-separated numbers each — the initial state of the table. Each number *p* in the table is an integer and satisfies the inequality 0<=≤<=*p*<=≤<=106.
Next *k* lines contain queries in the format "*s**i* *x**i* *y**i*", where *s**i* is one of the characters "с", "r" or "g", and *x**i*, *y**i* are two integers.
- If *s**i* = "c", then the current query is the query to swap columns with indexes *x**i* and *y**i* (1<=≤<=*x*,<=*y*<=≤<=*m*,<=*x*<=≠<=*y*); - If *s**i* = "r", then the current query is the query to swap rows with indexes *x**i* and *y**i* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*); - If *s**i* = "g", then the current query is the query to obtain the number that located in the *x**i*-th row and in the *y**i*-th column (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*).
The table rows are considered to be indexed from top to bottom from 1 to *n*, and the table columns — from left to right from 1 to *m*.
|
For each query to obtain a number (*s**i* = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
|
[
"3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2\n",
"2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3\n"
] |
[
"8\n9\n6\n",
"5\n"
] |
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
| 1,000
|
[
{
"input": "3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2",
"output": "8\n9\n6"
},
{
"input": "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3",
"output": "5"
},
{
"input": "1 1 15\n1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "1 2 3\n1 2\nc 1 2\ng 1 1\ng 1 2",
"output": "2\n1"
},
{
"input": "2 2 6\n1 2\n3 4\nc 1 2\nr 1 2\ng 1 1\ng 1 2\ng 2 1\ng 2 2",
"output": "4\n3\n2\n1"
},
{
"input": "3 4 5\n1 2 3 4\n5 6 7 8\n9 10 11 12\nr 1 2\nr 1 3\nr 2 3\ng 1 1\ng 2 2",
"output": "9\n6"
},
{
"input": "5 5 12\n1 2 3 4 5\n6 7 8 9 10\n11 12 13 14 15\n16 17 18 19 20\n21 22 23 24 25\nc 1 2\nr 1 2\nr 2 3\nr 1 2\nr 4 5\nc 3 4\ng 1 1\ng 2 2\ng 3 3\ng 4 4\ng 5 5\ng 2 3",
"output": "12\n6\n4\n23\n20\n9"
},
{
"input": "6 5 30\n536048 34640 572197 62457 304174\n194764 325606 270468 784237 551632\n10580 294606 63164 543647 531895\n430397 576813 678878 323394 603231\n534567 804015 403517 886087 981939\n518845 962097 609792 877955 88610\nc 1 5\nc 2 5\nc 2 5\nr 5 3\nc 5 2\nc 4 5\nr 6 5\nc 2 1\nr 3 4\nr 4 3\nc 4 5\nc 2 1\nr 1 5\nr 5 6\nc 3 1\ng 1 1\ng 5 4\ng 2 2\ng 2 1\nr 4 5\ng 1 1\nr 3 2\ng 5 1\nr 2 3\nr 6 5\nr 4 2\ng 5 2\nr 1 3\nr 1 3\nc 5 1",
"output": "609792\n543647\n194764\n270468\n609792\n678878\n536048"
},
{
"input": "2 1 3\n1\n2\nr 1 2\ng 1 1\ng 2 1",
"output": "2\n1"
},
{
"input": "3 3 13\n1 2 3\n4 5 6\n7 8 9\nc 1 2\nc 2 3\nr 2 3\nr 1 2\ng 1 1\ng 1 2\ng 1 3\ng 2 1\ng 2 2\ng 2 3\ng 3 1\ng 3 2\ng 3 3",
"output": "8\n9\n7\n2\n3\n1\n5\n6\n4"
},
{
"input": "1 3 7\n1 2 3\nc 1 2\nc 2 3\nc 1 3\nc 2 3\ng 1 1\ng 1 2\ng 1 3",
"output": "1\n2\n3"
},
{
"input": "3 1 7\n1\n2\n3\nr 1 2\nr 2 3\nr 1 3\nr 2 3\ng 1 1\ng 2 1\ng 3 1",
"output": "1\n2\n3"
},
{
"input": "5 6 20\n495907 68740 954868 197572 577456 641857\n16591 602443 981187 646143 137121 884307\n371452 725384 373988 59165 980490 837686\n514286 881540 886532 10541 684975 411009\n314261 127191 461802 89232 749116 563889\nr 2 1\nr 3 4\nc 3 4\nr 2 3\nc 6 3\nc 5 6\nc 4 1\nc 4 2\nr 2 4\nc 1 6\nr 5 3\nr 2 5\nr 4 2\ng 3 4\nc 2 5\nc 3 1\ng 3 6\ng 4 3\ng 2 3\nr 5 4",
"output": "127191\n461802\n577456\n684975"
}
] | 1,552,637,448
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 11
| 3,000
| 31,129,600
|
m, n, k = [int(i) for i in input().split()]
p = []
for i in range(m):
p.append([int(i) for i in input().split()])
for i in range(k):
s, x, y = input().split()
x = int(x)-1
y = int(y)-1
if s == "c":
q = list(zip(*p))
q[x], q[y] = q[y], q[x]
p = list(zip(*q))
elif s == "r":
p[x], p[y] = p[y], p[x]
elif s == "g":
print(p[x][y])
|
Title: Cosmic Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an *n*<=×<=*m* table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
- The query to swap two table rows; - The query to swap two table columns; - The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input Specification:
The first line contains three space-separated integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=500000) — the number of table columns and rows and the number of queries, correspondingly.
Next *n* lines contain *m* space-separated numbers each — the initial state of the table. Each number *p* in the table is an integer and satisfies the inequality 0<=≤<=*p*<=≤<=106.
Next *k* lines contain queries in the format "*s**i* *x**i* *y**i*", where *s**i* is one of the characters "с", "r" or "g", and *x**i*, *y**i* are two integers.
- If *s**i* = "c", then the current query is the query to swap columns with indexes *x**i* and *y**i* (1<=≤<=*x*,<=*y*<=≤<=*m*,<=*x*<=≠<=*y*); - If *s**i* = "r", then the current query is the query to swap rows with indexes *x**i* and *y**i* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*); - If *s**i* = "g", then the current query is the query to obtain the number that located in the *x**i*-th row and in the *y**i*-th column (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*).
The table rows are considered to be indexed from top to bottom from 1 to *n*, and the table columns — from left to right from 1 to *m*.
Output Specification:
For each query to obtain a number (*s**i* = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Demo Input:
['3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2\n', '2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3\n']
Demo Output:
['8\n9\n6\n', '5\n']
Note:
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
|
```python
m, n, k = [int(i) for i in input().split()]
p = []
for i in range(m):
p.append([int(i) for i in input().split()])
for i in range(k):
s, x, y = input().split()
x = int(x)-1
y = int(y)-1
if s == "c":
q = list(zip(*p))
q[x], q[y] = q[y], q[x]
p = list(zip(*q))
elif s == "r":
p[x], p[y] = p[y], p[x]
elif s == "g":
print(p[x][y])
```
| 0
|
|
769
|
A
|
Year of University Entrance
|
PROGRAMMING
| 800
|
[
"*special",
"implementation",
"sortings"
] | null | null |
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than *x* from the year of university entrance of this student, where *x* — some non-negative integer. A value *x* is not given, but it can be uniquely determined from the available data. Note that students don't join other groups.
You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance.
|
The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member.
It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly.
|
Print the year of Igor's university entrance.
|
[
"3\n2014 2016 2015\n",
"1\n2050\n"
] |
[
"2015\n",
"2050\n"
] |
In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.
In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance.
| 500
|
[
{
"input": "3\n2014 2016 2015",
"output": "2015"
},
{
"input": "1\n2050",
"output": "2050"
},
{
"input": "1\n2010",
"output": "2010"
},
{
"input": "1\n2011",
"output": "2011"
},
{
"input": "3\n2010 2011 2012",
"output": "2011"
},
{
"input": "3\n2049 2047 2048",
"output": "2048"
},
{
"input": "5\n2043 2042 2041 2044 2040",
"output": "2042"
},
{
"input": "5\n2012 2013 2014 2015 2016",
"output": "2014"
},
{
"input": "1\n2045",
"output": "2045"
},
{
"input": "1\n2046",
"output": "2046"
},
{
"input": "1\n2099",
"output": "2099"
},
{
"input": "1\n2100",
"output": "2100"
},
{
"input": "3\n2011 2010 2012",
"output": "2011"
},
{
"input": "3\n2011 2012 2010",
"output": "2011"
},
{
"input": "3\n2012 2011 2010",
"output": "2011"
},
{
"input": "3\n2010 2012 2011",
"output": "2011"
},
{
"input": "3\n2012 2010 2011",
"output": "2011"
},
{
"input": "3\n2047 2048 2049",
"output": "2048"
},
{
"input": "3\n2047 2049 2048",
"output": "2048"
},
{
"input": "3\n2048 2047 2049",
"output": "2048"
},
{
"input": "3\n2048 2049 2047",
"output": "2048"
},
{
"input": "3\n2049 2048 2047",
"output": "2048"
},
{
"input": "5\n2011 2014 2012 2013 2010",
"output": "2012"
},
{
"input": "5\n2014 2013 2011 2012 2015",
"output": "2013"
},
{
"input": "5\n2021 2023 2024 2020 2022",
"output": "2022"
},
{
"input": "5\n2081 2079 2078 2080 2077",
"output": "2079"
},
{
"input": "5\n2095 2099 2097 2096 2098",
"output": "2097"
},
{
"input": "5\n2097 2099 2100 2098 2096",
"output": "2098"
},
{
"input": "5\n2012 2010 2014 2011 2013",
"output": "2012"
},
{
"input": "5\n2012 2011 2013 2015 2014",
"output": "2013"
},
{
"input": "5\n2023 2024 2022 2021 2020",
"output": "2022"
},
{
"input": "5\n2077 2078 2080 2079 2081",
"output": "2079"
},
{
"input": "5\n2099 2096 2095 2097 2098",
"output": "2097"
},
{
"input": "5\n2097 2100 2098 2096 2099",
"output": "2098"
},
{
"input": "5\n2011 2014 2013 2010 2012",
"output": "2012"
},
{
"input": "5\n2013 2011 2015 2012 2014",
"output": "2013"
},
{
"input": "5\n2024 2020 2021 2023 2022",
"output": "2022"
},
{
"input": "5\n2079 2080 2077 2081 2078",
"output": "2079"
},
{
"input": "5\n2095 2097 2096 2098 2099",
"output": "2097"
},
{
"input": "5\n2099 2096 2100 2097 2098",
"output": "2098"
},
{
"input": "5\n2034 2033 2036 2032 2035",
"output": "2034"
},
{
"input": "5\n2030 2031 2033 2032 2029",
"output": "2031"
},
{
"input": "5\n2093 2092 2094 2096 2095",
"output": "2094"
},
{
"input": "5\n2012 2015 2014 2013 2011",
"output": "2013"
},
{
"input": "5\n2056 2057 2058 2059 2060",
"output": "2058"
}
] | 1,629,742,409
| 2,147,483,647
|
PyPy 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 109
| 22,323,200
|
n = int(input())
L = list(map(int, input.split()))
L.sort()
print(L[n//2])
|
Title: Year of University Entrance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than *x* from the year of university entrance of this student, where *x* — some non-negative integer. A value *x* is not given, but it can be uniquely determined from the available data. Note that students don't join other groups.
You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance.
Input Specification:
The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member.
It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly.
Output Specification:
Print the year of Igor's university entrance.
Demo Input:
['3\n2014 2016 2015\n', '1\n2050\n']
Demo Output:
['2015\n', '2050\n']
Note:
In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.
In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance.
|
```python
n = int(input())
L = list(map(int, input.split()))
L.sort()
print(L[n//2])
```
| -1
|
|
482
|
A
|
Diverse Permutation
|
PROGRAMMING
| 1,200
|
[
"constructive algorithms",
"greedy"
] | null | null |
Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*.
Your task is to find such permutation *p* of length *n*, that the group of numbers |*p*1<=-<=*p*2|,<=|*p*2<=-<=*p*3|,<=...,<=|*p**n*<=-<=1<=-<=*p**n*| has exactly *k* distinct elements.
|
The single line of the input contains two space-separated positive integers *n*, *k* (1<=≤<=*k*<=<<=*n*<=≤<=105).
|
Print *n* integers forming the permutation. If there are multiple answers, print any of them.
|
[
"3 2\n",
"3 1\n",
"5 2\n"
] |
[
"1 3 2\n",
"1 2 3\n",
"1 3 2 4 5\n"
] |
By |*x*| we denote the absolute value of number *x*.
| 500
|
[
{
"input": "3 2",
"output": "1 3 2"
},
{
"input": "3 1",
"output": "1 2 3"
},
{
"input": "5 2",
"output": "1 3 2 4 5"
},
{
"input": "5 4",
"output": "1 5 2 4 3"
},
{
"input": "10 4",
"output": "1 10 2 9 8 7 6 5 4 3"
},
{
"input": "10 3",
"output": "1 10 2 3 4 5 6 7 8 9"
},
{
"input": "10 9",
"output": "1 10 2 9 3 8 4 7 5 6"
},
{
"input": "100000 99999",
"output": "1 100000 2 99999 3 99998 4 99997 5 99996 6 99995 7 99994 8 99993 9 99992 10 99991 11 99990 12 99989 13 99988 14 99987 15 99986 16 99985 17 99984 18 99983 19 99982 20 99981 21 99980 22 99979 23 99978 24 99977 25 99976 26 99975 27 99974 28 99973 29 99972 30 99971 31 99970 32 99969 33 99968 34 99967 35 99966 36 99965 37 99964 38 99963 39 99962 40 99961 41 99960 42 99959 43 99958 44 99957 45 99956 46 99955 47 99954 48 99953 49 99952 50 99951 51 99950 52 99949 53 99948 54 99947 55 99946 56 99945 57 99944 58 999..."
},
{
"input": "99999 99998",
"output": "1 99999 2 99998 3 99997 4 99996 5 99995 6 99994 7 99993 8 99992 9 99991 10 99990 11 99989 12 99988 13 99987 14 99986 15 99985 16 99984 17 99983 18 99982 19 99981 20 99980 21 99979 22 99978 23 99977 24 99976 25 99975 26 99974 27 99973 28 99972 29 99971 30 99970 31 99969 32 99968 33 99967 34 99966 35 99965 36 99964 37 99963 38 99962 39 99961 40 99960 41 99959 42 99958 43 99957 44 99956 45 99955 46 99954 47 99953 48 99952 49 99951 50 99950 51 99949 52 99948 53 99947 54 99946 55 99945 56 99944 57 99943 58 9994..."
},
{
"input": "42273 29958",
"output": "1 42273 2 42272 3 42271 4 42270 5 42269 6 42268 7 42267 8 42266 9 42265 10 42264 11 42263 12 42262 13 42261 14 42260 15 42259 16 42258 17 42257 18 42256 19 42255 20 42254 21 42253 22 42252 23 42251 24 42250 25 42249 26 42248 27 42247 28 42246 29 42245 30 42244 31 42243 32 42242 33 42241 34 42240 35 42239 36 42238 37 42237 38 42236 39 42235 40 42234 41 42233 42 42232 43 42231 44 42230 45 42229 46 42228 47 42227 48 42226 49 42225 50 42224 51 42223 52 42222 53 42221 54 42220 55 42219 56 42218 57 42217 58 4221..."
},
{
"input": "29857 9843",
"output": "1 29857 2 29856 3 29855 4 29854 5 29853 6 29852 7 29851 8 29850 9 29849 10 29848 11 29847 12 29846 13 29845 14 29844 15 29843 16 29842 17 29841 18 29840 19 29839 20 29838 21 29837 22 29836 23 29835 24 29834 25 29833 26 29832 27 29831 28 29830 29 29829 30 29828 31 29827 32 29826 33 29825 34 29824 35 29823 36 29822 37 29821 38 29820 39 29819 40 29818 41 29817 42 29816 43 29815 44 29814 45 29813 46 29812 47 29811 48 29810 49 29809 50 29808 51 29807 52 29806 53 29805 54 29804 55 29803 56 29802 57 29801 58 2980..."
},
{
"input": "27687 4031",
"output": "1 27687 2 27686 3 27685 4 27684 5 27683 6 27682 7 27681 8 27680 9 27679 10 27678 11 27677 12 27676 13 27675 14 27674 15 27673 16 27672 17 27671 18 27670 19 27669 20 27668 21 27667 22 27666 23 27665 24 27664 25 27663 26 27662 27 27661 28 27660 29 27659 30 27658 31 27657 32 27656 33 27655 34 27654 35 27653 36 27652 37 27651 38 27650 39 27649 40 27648 41 27647 42 27646 43 27645 44 27644 45 27643 46 27642 47 27641 48 27640 49 27639 50 27638 51 27637 52 27636 53 27635 54 27634 55 27633 56 27632 57 27631 58 2763..."
},
{
"input": "25517 1767",
"output": "1 25517 2 25516 3 25515 4 25514 5 25513 6 25512 7 25511 8 25510 9 25509 10 25508 11 25507 12 25506 13 25505 14 25504 15 25503 16 25502 17 25501 18 25500 19 25499 20 25498 21 25497 22 25496 23 25495 24 25494 25 25493 26 25492 27 25491 28 25490 29 25489 30 25488 31 25487 32 25486 33 25485 34 25484 35 25483 36 25482 37 25481 38 25480 39 25479 40 25478 41 25477 42 25476 43 25475 44 25474 45 25473 46 25472 47 25471 48 25470 49 25469 50 25468 51 25467 52 25466 53 25465 54 25464 55 25463 56 25462 57 25461 58 2546..."
},
{
"input": "23347 20494",
"output": "1 23347 2 23346 3 23345 4 23344 5 23343 6 23342 7 23341 8 23340 9 23339 10 23338 11 23337 12 23336 13 23335 14 23334 15 23333 16 23332 17 23331 18 23330 19 23329 20 23328 21 23327 22 23326 23 23325 24 23324 25 23323 26 23322 27 23321 28 23320 29 23319 30 23318 31 23317 32 23316 33 23315 34 23314 35 23313 36 23312 37 23311 38 23310 39 23309 40 23308 41 23307 42 23306 43 23305 44 23304 45 23303 46 23302 47 23301 48 23300 49 23299 50 23298 51 23297 52 23296 53 23295 54 23294 55 23293 56 23292 57 23291 58 2329..."
},
{
"input": "10931 8824",
"output": "1 10931 2 10930 3 10929 4 10928 5 10927 6 10926 7 10925 8 10924 9 10923 10 10922 11 10921 12 10920 13 10919 14 10918 15 10917 16 10916 17 10915 18 10914 19 10913 20 10912 21 10911 22 10910 23 10909 24 10908 25 10907 26 10906 27 10905 28 10904 29 10903 30 10902 31 10901 32 10900 33 10899 34 10898 35 10897 36 10896 37 10895 38 10894 39 10893 40 10892 41 10891 42 10890 43 10889 44 10888 45 10887 46 10886 47 10885 48 10884 49 10883 50 10882 51 10881 52 10880 53 10879 54 10878 55 10877 56 10876 57 10875 58 1087..."
},
{
"input": "98514 26178",
"output": "1 98514 2 98513 3 98512 4 98511 5 98510 6 98509 7 98508 8 98507 9 98506 10 98505 11 98504 12 98503 13 98502 14 98501 15 98500 16 98499 17 98498 18 98497 19 98496 20 98495 21 98494 22 98493 23 98492 24 98491 25 98490 26 98489 27 98488 28 98487 29 98486 30 98485 31 98484 32 98483 33 98482 34 98481 35 98480 36 98479 37 98478 38 98477 39 98476 40 98475 41 98474 42 98473 43 98472 44 98471 45 98470 46 98469 47 98468 48 98467 49 98466 50 98465 51 98464 52 98463 53 98462 54 98461 55 98460 56 98459 57 98458 58 9845..."
},
{
"input": "6591 407",
"output": "1 6591 2 6590 3 6589 4 6588 5 6587 6 6586 7 6585 8 6584 9 6583 10 6582 11 6581 12 6580 13 6579 14 6578 15 6577 16 6576 17 6575 18 6574 19 6573 20 6572 21 6571 22 6570 23 6569 24 6568 25 6567 26 6566 27 6565 28 6564 29 6563 30 6562 31 6561 32 6560 33 6559 34 6558 35 6557 36 6556 37 6555 38 6554 39 6553 40 6552 41 6551 42 6550 43 6549 44 6548 45 6547 46 6546 47 6545 48 6544 49 6543 50 6542 51 6541 52 6540 53 6539 54 6538 55 6537 56 6536 57 6535 58 6534 59 6533 60 6532 61 6531 62 6530 63 6529 64 6528 65 6527 ..."
},
{
"input": "94174 30132",
"output": "1 94174 2 94173 3 94172 4 94171 5 94170 6 94169 7 94168 8 94167 9 94166 10 94165 11 94164 12 94163 13 94162 14 94161 15 94160 16 94159 17 94158 18 94157 19 94156 20 94155 21 94154 22 94153 23 94152 24 94151 25 94150 26 94149 27 94148 28 94147 29 94146 30 94145 31 94144 32 94143 33 94142 34 94141 35 94140 36 94139 37 94138 38 94137 39 94136 40 94135 41 94134 42 94133 43 94132 44 94131 45 94130 46 94129 47 94128 48 94127 49 94126 50 94125 51 94124 52 94123 53 94122 54 94121 55 94120 56 94119 57 94118 58 9411..."
},
{
"input": "92004 85348",
"output": "1 92004 2 92003 3 92002 4 92001 5 92000 6 91999 7 91998 8 91997 9 91996 10 91995 11 91994 12 91993 13 91992 14 91991 15 91990 16 91989 17 91988 18 91987 19 91986 20 91985 21 91984 22 91983 23 91982 24 91981 25 91980 26 91979 27 91978 28 91977 29 91976 30 91975 31 91974 32 91973 33 91972 34 91971 35 91970 36 91969 37 91968 38 91967 39 91966 40 91965 41 91964 42 91963 43 91962 44 91961 45 91960 46 91959 47 91958 48 91957 49 91956 50 91955 51 91954 52 91953 53 91952 54 91951 55 91950 56 91949 57 91948 58 9194..."
},
{
"input": "59221 29504",
"output": "1 59221 2 59220 3 59219 4 59218 5 59217 6 59216 7 59215 8 59214 9 59213 10 59212 11 59211 12 59210 13 59209 14 59208 15 59207 16 59206 17 59205 18 59204 19 59203 20 59202 21 59201 22 59200 23 59199 24 59198 25 59197 26 59196 27 59195 28 59194 29 59193 30 59192 31 59191 32 59190 33 59189 34 59188 35 59187 36 59186 37 59185 38 59184 39 59183 40 59182 41 59181 42 59180 43 59179 44 59178 45 59177 46 59176 47 59175 48 59174 49 59173 50 59172 51 59171 52 59170 53 59169 54 59168 55 59167 56 59166 57 59165 58 5916..."
},
{
"input": "2 1",
"output": "1 2"
},
{
"input": "4 1",
"output": "1 2 3 4"
},
{
"input": "4 2",
"output": "1 4 3 2"
},
{
"input": "100000 1",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "99999 1",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "99998 2",
"output": "1 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 99915 99914..."
},
{
"input": "99999 5000",
"output": "1 99999 2 99998 3 99997 4 99996 5 99995 6 99994 7 99993 8 99992 9 99991 10 99990 11 99989 12 99988 13 99987 14 99986 15 99985 16 99984 17 99983 18 99982 19 99981 20 99980 21 99979 22 99978 23 99977 24 99976 25 99975 26 99974 27 99973 28 99972 29 99971 30 99970 31 99969 32 99968 33 99967 34 99966 35 99965 36 99964 37 99963 38 99962 39 99961 40 99960 41 99959 42 99958 43 99957 44 99956 45 99955 46 99954 47 99953 48 99952 49 99951 50 99950 51 99949 52 99948 53 99947 54 99946 55 99945 56 99944 57 99943 58 9994..."
},
{
"input": "100000 99998",
"output": "1 100000 2 99999 3 99998 4 99997 5 99996 6 99995 7 99994 8 99993 9 99992 10 99991 11 99990 12 99989 13 99988 14 99987 15 99986 16 99985 17 99984 18 99983 19 99982 20 99981 21 99980 22 99979 23 99978 24 99977 25 99976 26 99975 27 99974 28 99973 29 99972 30 99971 31 99970 32 99969 33 99968 34 99967 35 99966 36 99965 37 99964 38 99963 39 99962 40 99961 41 99960 42 99959 43 99958 44 99957 45 99956 46 99955 47 99954 48 99953 49 99952 50 99951 51 99950 52 99949 53 99948 54 99947 55 99946 56 99945 57 99944 58 999..."
},
{
"input": "3222 311",
"output": "1 3222 2 3221 3 3220 4 3219 5 3218 6 3217 7 3216 8 3215 9 3214 10 3213 11 3212 12 3211 13 3210 14 3209 15 3208 16 3207 17 3206 18 3205 19 3204 20 3203 21 3202 22 3201 23 3200 24 3199 25 3198 26 3197 27 3196 28 3195 29 3194 30 3193 31 3192 32 3191 33 3190 34 3189 35 3188 36 3187 37 3186 38 3185 39 3184 40 3183 41 3182 42 3181 43 3180 44 3179 45 3178 46 3177 47 3176 48 3175 49 3174 50 3173 51 3172 52 3171 53 3170 54 3169 55 3168 56 3167 57 3166 58 3165 59 3164 60 3163 61 3162 62 3161 63 3160 64 3159 65 3158 ..."
},
{
"input": "32244 222",
"output": "1 32244 2 32243 3 32242 4 32241 5 32240 6 32239 7 32238 8 32237 9 32236 10 32235 11 32234 12 32233 13 32232 14 32231 15 32230 16 32229 17 32228 18 32227 19 32226 20 32225 21 32224 22 32223 23 32222 24 32221 25 32220 26 32219 27 32218 28 32217 29 32216 30 32215 31 32214 32 32213 33 32212 34 32211 35 32210 36 32209 37 32208 38 32207 39 32206 40 32205 41 32204 42 32203 43 32202 44 32201 45 32200 46 32199 47 32198 48 32197 49 32196 50 32195 51 32194 52 32193 53 32192 54 32191 55 32190 56 32189 57 32188 58 3218..."
},
{
"input": "1111 122",
"output": "1 1111 2 1110 3 1109 4 1108 5 1107 6 1106 7 1105 8 1104 9 1103 10 1102 11 1101 12 1100 13 1099 14 1098 15 1097 16 1096 17 1095 18 1094 19 1093 20 1092 21 1091 22 1090 23 1089 24 1088 25 1087 26 1086 27 1085 28 1084 29 1083 30 1082 31 1081 32 1080 33 1079 34 1078 35 1077 36 1076 37 1075 38 1074 39 1073 40 1072 41 1071 42 1070 43 1069 44 1068 45 1067 46 1066 47 1065 48 1064 49 1063 50 1062 51 1061 52 1060 53 1059 54 1058 55 1057 56 1056 57 1055 58 1054 59 1053 60 1052 61 1051 1050 1049 1048 1047 1046 1045 10..."
},
{
"input": "32342 1221",
"output": "1 32342 2 32341 3 32340 4 32339 5 32338 6 32337 7 32336 8 32335 9 32334 10 32333 11 32332 12 32331 13 32330 14 32329 15 32328 16 32327 17 32326 18 32325 19 32324 20 32323 21 32322 22 32321 23 32320 24 32319 25 32318 26 32317 27 32316 28 32315 29 32314 30 32313 31 32312 32 32311 33 32310 34 32309 35 32308 36 32307 37 32306 38 32305 39 32304 40 32303 41 32302 42 32301 43 32300 44 32299 45 32298 46 32297 47 32296 48 32295 49 32294 50 32293 51 32292 52 32291 53 32290 54 32289 55 32288 56 32287 57 32286 58 3228..."
},
{
"input": "100000 50000",
"output": "1 100000 2 99999 3 99998 4 99997 5 99996 6 99995 7 99994 8 99993 9 99992 10 99991 11 99990 12 99989 13 99988 14 99987 15 99986 16 99985 17 99984 18 99983 19 99982 20 99981 21 99980 22 99979 23 99978 24 99977 25 99976 26 99975 27 99974 28 99973 29 99972 30 99971 31 99970 32 99969 33 99968 34 99967 35 99966 36 99965 37 99964 38 99963 39 99962 40 99961 41 99960 42 99959 43 99958 44 99957 45 99956 46 99955 47 99954 48 99953 49 99952 50 99951 51 99950 52 99949 53 99948 54 99947 55 99946 56 99945 57 99944 58 999..."
},
{
"input": "100000 45",
"output": "1 100000 2 99999 3 99998 4 99997 5 99996 6 99995 7 99994 8 99993 9 99992 10 99991 11 99990 12 99989 13 99988 14 99987 15 99986 16 99985 17 99984 18 99983 19 99982 20 99981 21 99980 22 99979 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 12..."
},
{
"input": "99999 2",
"output": "1 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 99915..."
},
{
"input": "9 8",
"output": "1 9 2 8 3 7 4 6 5"
},
{
"input": "7 5",
"output": "1 7 2 6 3 4 5"
}
] | 1,535,934,909
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 37
| 514
| 614,400
|
n, k = map(int, input().split())
cur = 1
x = 0
a = [0] * (n + 1)
while k > 0:
a[cur] = 1
print(cur, end=(' '))
if x == 0:
cur = cur + k
x = 1
else:
cur = cur - k
x = 0
k = k - 1
for i in range(1, n + 1):
if a[i] == 0:
print(i, end=' ')
|
Title: Diverse 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 not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*.
Your task is to find such permutation *p* of length *n*, that the group of numbers |*p*1<=-<=*p*2|,<=|*p*2<=-<=*p*3|,<=...,<=|*p**n*<=-<=1<=-<=*p**n*| has exactly *k* distinct elements.
Input Specification:
The single line of the input contains two space-separated positive integers *n*, *k* (1<=≤<=*k*<=<<=*n*<=≤<=105).
Output Specification:
Print *n* integers forming the permutation. If there are multiple answers, print any of them.
Demo Input:
['3 2\n', '3 1\n', '5 2\n']
Demo Output:
['1 3 2\n', '1 2 3\n', '1 3 2 4 5\n']
Note:
By |*x*| we denote the absolute value of number *x*.
|
```python
n, k = map(int, input().split())
cur = 1
x = 0
a = [0] * (n + 1)
while k > 0:
a[cur] = 1
print(cur, end=(' '))
if x == 0:
cur = cur + k
x = 1
else:
cur = cur - k
x = 0
k = k - 1
for i in range(1, n + 1):
if a[i] == 0:
print(i, end=' ')
```
| 3
|
|
825
|
A
|
Binary Protocol
|
PROGRAMMING
| 1,100
|
[
"implementation"
] | null | null |
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
|
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
|
Print the decoded number.
|
[
"3\n111\n",
"9\n110011101\n"
] |
[
"3\n",
"2031\n"
] |
none
| 0
|
[
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "202002000"
},
{
"input": "31\n1000011111111100011110111111111",
"output": "100090049"
},
{
"input": "53\n10110111011110111110111111011111110111111110111111111",
"output": "123456789"
},
{
"input": "89\n11111111101111111110111111111011111111101111111110111111111011111111101111111110111111111",
"output": "999999999"
},
{
"input": "10\n1000000000",
"output": "1000000000"
},
{
"input": "2\n10",
"output": "10"
},
{
"input": "4\n1110",
"output": "30"
},
{
"input": "8\n10101010",
"output": "11110"
}
] | 1,500,742,616
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 13
| 77
| 4,608,000
|
n = int(input())
# print(n)
s = input()
# print(s)
k = 0
ans = ''
for c in s:
# print(c)
if c == '0':
ans += str(k)
k = 0
else:
k += 1
print(ans + str(k))
|
Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output Specification:
Print the decoded number.
Demo Input:
['3\n111\n', '9\n110011101\n']
Demo Output:
['3\n', '2031\n']
Note:
none
|
```python
n = int(input())
# print(n)
s = input()
# print(s)
k = 0
ans = ''
for c in s:
# print(c)
if c == '0':
ans += str(k)
k = 0
else:
k += 1
print(ans + str(k))
```
| 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,691,690,065
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 1
| 340
| 13,824,000
|
from fractions import Fraction
a,b=list(map(int,input().split()))
n=6-max(a,b)+1
fraction = Fraction(n, 6).limit_denominator()
print(fraction)
|
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
from fractions import Fraction
a,b=list(map(int,input().split()))
n=6-max(a,b)+1
fraction = Fraction(n, 6).limit_denominator()
print(fraction)
```
| 0
|
892
|
A
|
Greed
|
PROGRAMMING
| 900
|
[
"greedy",
"implementation"
] | null | null |
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
|
The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<=*b**n* (*a**i*<=≤<=*b**i*<=≤<=109) — capacities of the cans.
|
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
|
[
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] |
[
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] |
In the first sample, there are already 2 cans, so the answer is "YES".
| 500
|
[
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 94 8 16 73 85",
"output": "YES"
},
{
"input": "4\n25 35 7 31\n70 37 43 35",
"output": "YES"
},
{
"input": "10\n15 26 15 14 14 39 40 4 25 39\n27 72 16 44 69 48 53 17 63 42",
"output": "NO"
},
{
"input": "5\n22 5 19 16 32\n26 10 43 38 37",
"output": "NO"
},
{
"input": "5\n32 4 22 40 26\n39 20 36 98 44",
"output": "YES"
},
{
"input": "6\n18 25 3 10 13 37\n38 73 19 35 24 37",
"output": "YES"
},
{
"input": "2\n2 2\n2 2",
"output": "YES"
},
{
"input": "2\n2 5\n2 5",
"output": "YES"
},
{
"input": "2\n1000 1008\n10000 2352",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5\n1 2 3 4 11",
"output": "YES"
},
{
"input": "4\n1 0 0 0\n2 0 0 0",
"output": "YES"
},
{
"input": "2\n0 0\n1 2",
"output": "YES"
},
{
"input": "3\n9 13 4\n10 14 5",
"output": "NO"
},
{
"input": "2\n0 0\n1 1",
"output": "YES"
},
{
"input": "5\n1 1 2 3 1\n1 1 2 3 4",
"output": "NO"
},
{
"input": "2\n0 0\n0 0",
"output": "YES"
},
{
"input": "3\n5 1 1\n5 5 5",
"output": "YES"
}
] | 1,659,184,237
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 39
| 108
| 18,739,200
|
_ = int(input())
soda = list(map(int, input().split()))
cans = sorted(list(map(int, input().split())))
max_capacity = cans[-1] + cans[-2]
result = "YES"
for s in soda:
max_capacity -= s
if max_capacity < 0:
result = "NO"
break
print(result)
|
Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
Input Specification:
The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<=*b**n* (*a**i*<=≤<=*b**i*<=≤<=109) — capacities of the cans.
Output Specification:
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Demo Input:
['2\n3 5\n3 6\n', '3\n6 8 9\n6 10 12\n', '5\n0 0 5 0 0\n1 1 8 10 5\n', '4\n4 1 0 3\n5 2 2 3\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'YES\n']
Note:
In the first sample, there are already 2 cans, so the answer is "YES".
|
```python
_ = int(input())
soda = list(map(int, input().split()))
cans = sorted(list(map(int, input().split())))
max_capacity = cans[-1] + cans[-2]
result = "YES"
for s in soda:
max_capacity -= s
if max_capacity < 0:
result = "NO"
break
print(result)
```
| 3
|
|
967
|
B
|
Watering System
|
PROGRAMMING
| 1,000
|
[
"math",
"sortings"
] | null | null |
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes $s_1, s_2, \ldots, s_n$. In other words, if the sum of sizes of non-blocked holes is $S$, and the $i$-th hole is not blocked, $\frac{s_i \cdot A}{S}$ liters of water will flow out of it.
What is the minimum number of holes Arkady should block to make at least $B$ liters of water flow out of the first hole?
|
The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$) — the sizes of the holes.
|
Print a single integer — the number of holes Arkady should block.
|
[
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] |
[
"1\n",
"0\n",
"4\n"
] |
In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not less than $20$.
In the third example Arkady has to block all holes except the first to make all water flow out of the first hole.
| 1,000
|
[
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 96",
"output": "8"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "1 2 1\n1",
"output": "0"
},
{
"input": "2 2 2\n1 10000",
"output": "1"
},
{
"input": "2 10000 1\n1 9999",
"output": "0"
}
] | 1,673,785,531
| 2,147,483,647
|
PyPy 3-64
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 8
| 1,000
| 14,028,800
|
from sys import stdin; inp = stdin.readline
from math import dist, ceil, floor, sqrt, log
from collections import defaultdict, Counter, deque
def IA(sep=' '): return list(map(int, inp().split(sep)))
def FA(): return list(map(float, inp().split()))
def SA(): return inp().split()
def I(): return int(inp())
def F(): return float(inp())
def S(): return input()
def O(l:list): return ' '.join(map(str, l))
def main():
n_holes, total_vol, target_vol = IA()
hole_sizes = IA()
first = hole_sizes[0]
first_vol = first*total_vol / sum(hole_sizes)
if first_vol >= target_vol:
return 0
else:
rest = hole_sizes[1:]
rest.sort()
c = 0
while first_vol < target_vol:
rest.pop()
c+=1
first_vol = first*total_vol / (sum(rest)+first)
return c
if __name__ == '__main__':
print(main())
|
Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes $s_1, s_2, \ldots, s_n$. In other words, if the sum of sizes of non-blocked holes is $S$, and the $i$-th hole is not blocked, $\frac{s_i \cdot A}{S}$ liters of water will flow out of it.
What is the minimum number of holes Arkady should block to make at least $B$ liters of water flow out of the first hole?
Input Specification:
The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$) — the sizes of the holes.
Output Specification:
Print a single integer — the number of holes Arkady should block.
Demo Input:
['4 10 3\n2 2 2 2\n', '4 80 20\n3 2 1 4\n', '5 10 10\n1000 1 1 1 1\n']
Demo Output:
['1\n', '0\n', '4\n']
Note:
In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not less than $20$.
In the third example Arkady has to block all holes except the first to make all water flow out of the first hole.
|
```python
from sys import stdin; inp = stdin.readline
from math import dist, ceil, floor, sqrt, log
from collections import defaultdict, Counter, deque
def IA(sep=' '): return list(map(int, inp().split(sep)))
def FA(): return list(map(float, inp().split()))
def SA(): return inp().split()
def I(): return int(inp())
def F(): return float(inp())
def S(): return input()
def O(l:list): return ' '.join(map(str, l))
def main():
n_holes, total_vol, target_vol = IA()
hole_sizes = IA()
first = hole_sizes[0]
first_vol = first*total_vol / sum(hole_sizes)
if first_vol >= target_vol:
return 0
else:
rest = hole_sizes[1:]
rest.sort()
c = 0
while first_vol < target_vol:
rest.pop()
c+=1
first_vol = first*total_vol / (sum(rest)+first)
return c
if __name__ == '__main__':
print(main())
```
| 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,687,430,328
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 30
| 0
|
import math
#s=input()
#x = s[0]
#x = x.capitalize()
#b = n[1:]
#print(x+b)
#s1=s[0].upper() + s[1:len(s)]
#print(s1)
#s=input()
#s=input()
#s.lower()
#if :
# print('1')
#elif:
# print('-1')
#else:
# print('0')
#
#string=input().lower()
#
#l=['a','e','i','o','u','y']
#k=list(string)
#i=0
#
#while i <len(k):
# if k[i] in l:
# k.pop(i)
# else:
# i+=1
#
#for i in range(len(k)):
#
# print('.'+k[i],end="")
#
#rock = int(input())
#col = input()
#cha = list(col)
#a = 0
#for i in range(rock-1):
# if cha[i+1] == cha[i]:
# a+=1
#print(a)
#
#a,b = int(input())
#c = 0
#while b<=a:
# c+=1
# a = a*3
# b = b*2
#print(c)
#x = [int(item) for item in input().split()]
#total = 0
#count = 1
#for i in range(x[2]):
# total += x[0] * count
# count += 1
#if total > x[1]:
# print(total - x[1])
#else:
# print(0)
x = input()
y = 0
for i in x:
if i.islower():
y+= 1
if len(x)/2>=y:
print(x.capitalize())
else:
print(x.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
import math
#s=input()
#x = s[0]
#x = x.capitalize()
#b = n[1:]
#print(x+b)
#s1=s[0].upper() + s[1:len(s)]
#print(s1)
#s=input()
#s=input()
#s.lower()
#if :
# print('1')
#elif:
# print('-1')
#else:
# print('0')
#
#string=input().lower()
#
#l=['a','e','i','o','u','y']
#k=list(string)
#i=0
#
#while i <len(k):
# if k[i] in l:
# k.pop(i)
# else:
# i+=1
#
#for i in range(len(k)):
#
# print('.'+k[i],end="")
#
#rock = int(input())
#col = input()
#cha = list(col)
#a = 0
#for i in range(rock-1):
# if cha[i+1] == cha[i]:
# a+=1
#print(a)
#
#a,b = int(input())
#c = 0
#while b<=a:
# c+=1
# a = a*3
# b = b*2
#print(c)
#x = [int(item) for item in input().split()]
#total = 0
#count = 1
#for i in range(x[2]):
# total += x[0] * count
# count += 1
#if total > x[1]:
# print(total - x[1])
#else:
# print(0)
x = input()
y = 0
for i in x:
if i.islower():
y+= 1
if len(x)/2>=y:
print(x.capitalize())
else:
print(x.lower())
```
| 0
|
893
|
C
|
Rumor
|
PROGRAMMING
| 1,300
|
[
"dfs and similar",
"graphs",
"greedy"
] | null | null |
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.
Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.
The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?
Take a look at the notes if you think you haven't understood the problem completely.
|
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once.
|
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
|
[
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] |
[
"10\n",
"55\n",
"15\n"
] |
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters.
| 0
|
[
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n1000000000",
"output": "1000000000"
},
{
"input": "2 0\n0 0",
"output": "0"
},
{
"input": "2 0\n1000000000 0",
"output": "1000000000"
},
{
"input": "2 0\n0 1000000000",
"output": "1000000000"
},
{
"input": "2 0\n1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 1\n0 0\n1 2",
"output": "0"
}
] | 1,653,746,548
| 2,147,483,647
|
PyPy 3-64
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
n, m = map(int, input().split())
arr = list(map(int, input().split()))
parent = [i for i in range(len(arr))]
rank = [arr[i] for i in range(len(arr))]
def find(idx):
if parent[idx] == idx:
return idx
parent[idx] = find(parent[idx])
return parent[idx]
def union(i, j):
pi = find(i)
pj = find(j)
if pi != pj:
if rank[pi] < rank[pj]:
parent[pj] = pi
rank[pj] = rank[pi]
else:
parent[pi] = pj
rank[pi] = rank[pj]
for _ in range(m):
i1, i2 = map(int, input().split())
union(i1 - 1, i2 - 1)
ans = 0
visited = set()
for j in range(n):
k = find(j)
if k not in visited k < len(arr):
ans += arr[k]
visited.add(k)
print(ans)
|
Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.
Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.
The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?
Take a look at the notes if you think you haven't understood the problem completely.
Input Specification:
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once.
Output Specification:
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
Demo Input:
['5 2\n2 5 3 4 8\n1 4\n4 5\n', '10 0\n1 2 3 4 5 6 7 8 9 10\n', '10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n']
Demo Output:
['10\n', '55\n', '15\n']
Note:
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters.
|
```python
n, m = map(int, input().split())
arr = list(map(int, input().split()))
parent = [i for i in range(len(arr))]
rank = [arr[i] for i in range(len(arr))]
def find(idx):
if parent[idx] == idx:
return idx
parent[idx] = find(parent[idx])
return parent[idx]
def union(i, j):
pi = find(i)
pj = find(j)
if pi != pj:
if rank[pi] < rank[pj]:
parent[pj] = pi
rank[pj] = rank[pi]
else:
parent[pi] = pj
rank[pi] = rank[pj]
for _ in range(m):
i1, i2 = map(int, input().split())
union(i1 - 1, i2 - 1)
ans = 0
visited = set()
for j in range(n):
k = find(j)
if k not in visited k < len(arr):
ans += arr[k]
visited.add(k)
print(ans)
```
| -1
|
|
526
|
A
|
King of Thieves
|
PROGRAMMING
| 1,300
|
[
"brute force",
"implementation"
] | null | null |
In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.
A dungeon consists of *n* segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'.
One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number *i*1, he can make a sequence of jumps through the platforms *i*1<=<<=*i*2<=<<=...<=<<=*i**k*, if *i*2<=-<=*i*1<==<=*i*3<=-<=*i*2<==<=...<==<=*i**k*<=-<=*i**k*<=-<=1. Of course, all segments *i*1,<=*i*2,<=... *i**k* should be exactly the platforms, not pits.
Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence *i*1,<=*i*2,<=...,<=*i*5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of segments on the level.
Next line contains the scheme of the level represented as a string of *n* characters '*' and '.'.
|
If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes).
|
[
"16\n.**.*..*.***.**.\n",
"11\n.*.*...*.*.\n"
] |
[
"yes",
"no"
] |
In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14.
| 500
|
[
{
"input": "16\n.**.*..*.***.**.",
"output": "yes"
},
{
"input": "11\n.*.*...*.*.",
"output": "no"
},
{
"input": "53\n*.*.****.*.*......**....**.***.*.*.**.*.*.***...*..*.",
"output": "yes"
},
{
"input": "71\n**.**..*****.*.*.*.********.....*****.****.*..***...*.*.*.**.****.**.**",
"output": "yes"
},
{
"input": "56\n**.*..*...***.*.**.**..**.*.*.*.**...*.**.**....*...**..",
"output": "yes"
},
{
"input": "64\n***.*...*...*.***.....*.....**.*****.*.*...*..*.*..***..*...***.",
"output": "yes"
},
{
"input": "99\n.*..**..*..*..**...***.****.*...*....*****.....**..****.*..*....****..**..*****..*....**.*.**..**..",
"output": "yes"
},
{
"input": "89\n..**..**..*.********....*.*****.**.****...*......*******..*.**.*****..*..****....*...**..",
"output": "yes"
},
{
"input": "99\n..*.*..**.*.*.******.*.*.**.**.**.*..**.*.*****..*.*.****.*....**....*****.....***..**....***.*.*.*",
"output": "yes"
},
{
"input": "5\n*****",
"output": "yes"
},
{
"input": "10\n.*.*.*.*.*",
"output": "yes"
},
{
"input": "51\n....****....*........*.*..**........*....****....*.",
"output": "no"
},
{
"input": "98\n.**..**.*****..***...*.**..*..*....*******..**....*.****.**.*.....*.**..***.**..***.*******..****.",
"output": "yes"
},
{
"input": "45\n.***..******....***..**..*.*.*.**..**..*.**..",
"output": "yes"
},
{
"input": "67\n..**.*...*.....****.***.**.*....***..***.*..***.....*******.....*.*",
"output": "yes"
},
{
"input": "97\n...*..*...*******.*.**..**..******.*.*..*****.*...***.*.**.**.**..**.******.****.*.***.**..*...**",
"output": "yes"
},
{
"input": "87\n*..*..***.**.*...****...*....***....***......*..*.*.*****.**..*.***...*.****..**.*..***",
"output": "yes"
},
{
"input": "99\n***....*.....****.*.**.*.*.**.*.*.*..*...*..*...***..*.*...*.*...***.*.*...**.**.*******....**....*",
"output": "yes"
},
{
"input": "90\n**....****.***..***.*.*****...*.*.***..***.******.**...***..*...*****..*.**.**...*..**...*",
"output": "yes"
},
{
"input": "58\n**.*.*.**..******.**.*..*.**.*.*******.**.*.**.*..*****.*.",
"output": "yes"
},
{
"input": "75\n..*.**..*.*****.......*....*.*.*..**.*.***.*.***....******.****.*.....****.",
"output": "yes"
},
{
"input": "72\n.***.**.*.*...*****.*.*.*.*.**....**.*.**..*.*...**..***.**.**..*.**..**",
"output": "yes"
},
{
"input": "69\n.***...*.***.**...*....*.***.*..*....**.*...**....*.*..**....**..*.**",
"output": "yes"
},
{
"input": "42\n..*...*.*..**..*.*.*..**...**.***.*.******",
"output": "yes"
},
{
"input": "54\n...***.*...****.*..****....*..**..**..***.*..**...**..",
"output": "yes"
},
{
"input": "55\n...*..*.*.**..*.*....*.****..****....*..***.*****..*..*",
"output": "yes"
},
{
"input": "57\n**...*....**.**.*.******.**..**.*.....**.***..***...**..*",
"output": "yes"
},
{
"input": "97\n****.***.***.*..**.**.*.*.***.*............*..*......*.***.**.*.***.*.***.*..*.**.*.***.**.*****.",
"output": "yes"
},
{
"input": "42\n***.*..*.*.***...**..*..**....**..*..*...*",
"output": "yes"
},
{
"input": "99\n**...*.*.*..*....**.***..*...***..***.**.*.....*.*....*...*.**.**.****..**..*.*..*.***....**...**.*",
"output": "yes"
},
{
"input": "1\n.",
"output": "no"
},
{
"input": "1\n*",
"output": "no"
},
{
"input": "99\n.*.......................*.......................*.......................*.......................*.",
"output": "yes"
},
{
"input": "99\n.*.......................*...............................................*.......................*.",
"output": "no"
},
{
"input": "100\n****************************************************************************************************",
"output": "yes"
},
{
"input": "99\n***************************************************************************************************",
"output": "yes"
},
{
"input": "5\n.****",
"output": "no"
},
{
"input": "5\n*.***",
"output": "no"
},
{
"input": "5\n**.**",
"output": "no"
},
{
"input": "5\n***.*",
"output": "no"
},
{
"input": "5\n****.",
"output": "no"
},
{
"input": "100\n*...............................................................................................****",
"output": "no"
},
{
"input": "11\n.**.*..*.**",
"output": "no"
},
{
"input": "21\n*.*...*.*...*.*...*.*",
"output": "no"
},
{
"input": "6\n***.**",
"output": "no"
},
{
"input": "13\n*..*..*..*..*",
"output": "yes"
},
{
"input": "4\n****",
"output": "no"
},
{
"input": "17\n.*..*..*.....*..*",
"output": "no"
},
{
"input": "7\n***.***",
"output": "no"
},
{
"input": "20\n.*..*...*....*.....*",
"output": "no"
},
{
"input": "11\n*...**..*.*",
"output": "no"
},
{
"input": "10\n*****....*",
"output": "yes"
},
{
"input": "16\n*.**.**.**.*..*.",
"output": "yes"
},
{
"input": "10\n.*.*.*.*..",
"output": "no"
},
{
"input": "17\n*...*...*...*...*",
"output": "yes"
},
{
"input": "15\n..........*****",
"output": "yes"
}
] | 1,428,167,298
| 1,998
|
Python 3
|
RUNTIME_ERROR
|
PRETESTS
| 0
| 46
| 0
|
#fin = open("input.txt")
#n = int(fin.readline())
#s = list(fin.readline())
n = int(input())
s = input()
a, b, c, d = -1, -1, -1, -1
for i in range(n):
if s[i] == "*":
if c == -1 or i > 0 and not s[i - 1]:
c = i
d = i
if a == -1:
a = i
else:
if b == -1 and i > 0 and s[i - 1]:
b = i - 1
s[i] = (s[i] == "*")
if b == -1:
b = d
#print(a, b, c, d)
F = False
#print(n, a, b)
for k in range(1, (n + 3) // 4 + 1):
for i in range(a, b + 1):
#print(i)
flag = True
for j in range(5):
#print(i + j * k + 1, end = " ")
if i + j * k >= n or not s[i + j * k]:
flag = False
#print(flag, c, i + k * 4, d)
if flag and c <= (i + k * 4) <= d:
F = True
break
if F:
print("yes")
else:
print("no")
|
Title: King of Thieves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.
A dungeon consists of *n* segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'.
One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number *i*1, he can make a sequence of jumps through the platforms *i*1<=<<=*i*2<=<<=...<=<<=*i**k*, if *i*2<=-<=*i*1<==<=*i*3<=-<=*i*2<==<=...<==<=*i**k*<=-<=*i**k*<=-<=1. Of course, all segments *i*1,<=*i*2,<=... *i**k* should be exactly the platforms, not pits.
Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence *i*1,<=*i*2,<=...,<=*i*5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of segments on the level.
Next line contains the scheme of the level represented as a string of *n* characters '*' and '.'.
Output Specification:
If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes).
Demo Input:
['16\n.**.*..*.***.**.\n', '11\n.*.*...*.*.\n']
Demo Output:
['yes', 'no']
Note:
In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14.
|
```python
#fin = open("input.txt")
#n = int(fin.readline())
#s = list(fin.readline())
n = int(input())
s = input()
a, b, c, d = -1, -1, -1, -1
for i in range(n):
if s[i] == "*":
if c == -1 or i > 0 and not s[i - 1]:
c = i
d = i
if a == -1:
a = i
else:
if b == -1 and i > 0 and s[i - 1]:
b = i - 1
s[i] = (s[i] == "*")
if b == -1:
b = d
#print(a, b, c, d)
F = False
#print(n, a, b)
for k in range(1, (n + 3) // 4 + 1):
for i in range(a, b + 1):
#print(i)
flag = True
for j in range(5):
#print(i + j * k + 1, end = " ")
if i + j * k >= n or not s[i + j * k]:
flag = False
#print(flag, c, i + k * 4, d)
if flag and c <= (i + k * 4) <= d:
F = True
break
if F:
print("yes")
else:
print("no")
```
| -1
|
|
858
|
C
|
Did you mean...
|
PROGRAMMING
| 1,500
|
[
"dp",
"greedy",
"implementation"
] | null | null |
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
|
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
|
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
|
[
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] |
[
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] |
none
| 1,500
|
[
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx",
"output": "jxegx xx "
},
{
"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz",
"output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz "
},
{
"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte",
"output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te "
},
{
"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz",
"output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz "
},
{
"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf",
"output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf "
},
{
"input": "mvjajoyeg",
"output": "mv jajoyeg "
},
{
"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq",
"output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q "
},
{
"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef",
"output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef "
},
{
"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj",
"output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j "
},
{
"input": "hzxkuwqxonsulnndlhygvmallghjerwp",
"output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p "
},
{
"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd",
"output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d "
},
{
"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr",
"output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r "
},
{
"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu",
"output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu "
},
{
"input": "a",
"output": "a "
},
{
"input": "b",
"output": "b "
},
{
"input": "aa",
"output": "aa "
},
{
"input": "ab",
"output": "ab "
},
{
"input": "ba",
"output": "ba "
},
{
"input": "bb",
"output": "bb "
},
{
"input": "aaa",
"output": "aaa "
},
{
"input": "aab",
"output": "aab "
},
{
"input": "aba",
"output": "aba "
},
{
"input": "abb",
"output": "abb "
},
{
"input": "baa",
"output": "baa "
},
{
"input": "bab",
"output": "bab "
},
{
"input": "bba",
"output": "bba "
},
{
"input": "bbb",
"output": "bbb "
},
{
"input": "bbc",
"output": "bb c "
},
{
"input": "bcb",
"output": "bc b "
},
{
"input": "cbb",
"output": "cb b "
},
{
"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc",
"output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc "
},
{
"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb",
"output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b "
},
{
"input": "helllllooooo",
"output": "helllllooooo "
},
{
"input": "bbbzxxx",
"output": "bbb zx xx "
},
{
"input": "ffff",
"output": "ffff "
},
{
"input": "cdddddddddddddddddd",
"output": "cd ddddddddddddddddd "
},
{
"input": "bbbc",
"output": "bbb c "
},
{
"input": "lll",
"output": "lll "
},
{
"input": "bbbbb",
"output": "bbbbb "
},
{
"input": "llll",
"output": "llll "
},
{
"input": "bbbbbbccc",
"output": "bbbbbb ccc "
},
{
"input": "lllllb",
"output": "lllll b "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "lllll",
"output": "lllll "
},
{
"input": "bbbbbbbbbc",
"output": "bbbbbbbbb c "
},
{
"input": "helllllno",
"output": "helllll no "
},
{
"input": "nnnnnnnnnnnn",
"output": "nnnnnnnnnnnn "
},
{
"input": "bbbbbccc",
"output": "bbbbb ccc "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "nnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "hhhh",
"output": "hhhh "
},
{
"input": "nnnnnnnnnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzz",
"output": "zzzzzzzzzz "
},
{
"input": "dddd",
"output": "dddd "
},
{
"input": "heffffffgggggghhhhhh",
"output": "heffffff gggggg hhhhhh "
},
{
"input": "bcddd",
"output": "bc ddd "
},
{
"input": "x",
"output": "x "
},
{
"input": "nnn",
"output": "nnn "
},
{
"input": "xxxxxxxx",
"output": "xxxxxxxx "
},
{
"input": "cclcc",
"output": "cc lc c "
},
{
"input": "tttttttttttttt",
"output": "tttttttttttttt "
},
{
"input": "xxxxxxx",
"output": "xxxxxxx "
},
{
"input": "ccccb",
"output": "cccc b "
},
{
"input": "bcecccc",
"output": "bcecccc "
},
{
"input": "jjja",
"output": "jjja "
},
{
"input": "zzz",
"output": "zzz "
},
{
"input": "xxxxxxxxxzzzzzzzzzzzz",
"output": "xxxxxxxxx zzzzzzzzzzzz "
},
{
"input": "alllewww",
"output": "alllewww "
},
{
"input": "bbbbbbbbb",
"output": "bbbbbbbbb "
},
{
"input": "jjj",
"output": "jjj "
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbb "
},
{
"input": "kkkkkkkkkklllllllllllllll",
"output": "kkkkkkkkkk lllllllllllllll "
},
{
"input": "helllllllllllo",
"output": "helllllllllllo "
},
{
"input": "ttttsttttt",
"output": "tttt st tttt "
},
{
"input": "tttttttsssssss",
"output": "ttttttt sssssss "
},
{
"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss",
"output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss "
},
{
"input": "xxxxx",
"output": "xxxxx "
},
{
"input": "bbbhbbb",
"output": "bbb hb bb "
},
{
"input": "bbbbbbbb",
"output": "bbbbbbbb "
}
] | 1,505,658,255
| 4,755
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 32
| 62
| 5,529,600
|
def insert_char(txt, chir, pos):
out = ""
for i in range(len(txt)):
out += txt[i]
if(i == pos):
out += chir
return out
s = str(input())
esog = "aeuio"
repeat = 0
repchar = ""
np = True
i=0
while(i<len(s)):
if(repeat>2):
if(s[i] == s[i-1] == s[i-2]):
np = False
if(esog.find(s[i]) == -1):
repeat+=1
repchar=s[i]
np = True
else:
repeat = 0
repchar = ""
np = True
if(repeat>=3 and np):
s = s[:i]+" "+s[i:]
repeat = 0
repchar = ""
#print(i, s[i], esog.find(s[i]), repchar, repeat, s[i]!=repchar, np,sep=' ')
i+=1
print(s)
|
Title: Did you mean...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input Specification:
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output Specification:
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Demo Input:
['hellno\n', 'abacaba\n', 'asdfasdf\n']
Demo Output:
['hell no \n', 'abacaba \n', 'asd fasd f \n']
Note:
none
|
```python
def insert_char(txt, chir, pos):
out = ""
for i in range(len(txt)):
out += txt[i]
if(i == pos):
out += chir
return out
s = str(input())
esog = "aeuio"
repeat = 0
repchar = ""
np = True
i=0
while(i<len(s)):
if(repeat>2):
if(s[i] == s[i-1] == s[i-2]):
np = False
if(esog.find(s[i]) == -1):
repeat+=1
repchar=s[i]
np = True
else:
repeat = 0
repchar = ""
np = True
if(repeat>=3 and np):
s = s[:i]+" "+s[i:]
repeat = 0
repchar = ""
#print(i, s[i], esog.find(s[i]), repchar, repeat, s[i]!=repchar, np,sep=' ')
i+=1
print(s)
```
| 0
|
|
599
|
A
|
Patrick and Shopping
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.
Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
|
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
|
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
|
[
"10 20 30\n",
"1 1 5\n"
] |
[
"60\n",
"4\n"
] |
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
| 500
|
[
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
{
"input": "789 101112 131415",
"output": "203802"
},
{
"input": "27485716 99999999 35182",
"output": "55041796"
},
{
"input": "1 293548 5",
"output": "12"
},
{
"input": "12059 259855 5874875",
"output": "543828"
},
{
"input": "46981 105809 585858",
"output": "305580"
},
{
"input": "9889 1221 2442",
"output": "7326"
},
{
"input": "100500 200600 300700",
"output": "601800"
},
{
"input": "318476 318476 318476",
"output": "955428"
},
{
"input": "23985 3353 75633",
"output": "54676"
},
{
"input": "120 1298 2222",
"output": "2836"
},
{
"input": "98437 23487 666672",
"output": "243848"
},
{
"input": "100000000 100000000 100000000",
"output": "300000000"
},
{
"input": "2 5 2",
"output": "8"
},
{
"input": "1 1000 1",
"output": "4"
},
{
"input": "1 100000000 1",
"output": "4"
}
] | 1,596,799,506
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 93
| 6,656,000
|
a, b, c = map(int, input().split())
d = a*2+b*2
e = a+b+c
print(min(d, e))
|
Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.
Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
Input Specification:
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Output Specification:
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
Demo Input:
['10 20 30\n', '1 1 5\n']
Demo Output:
['60\n', '4\n']
Note:
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
|
```python
a, b, c = map(int, input().split())
d = a*2+b*2
e = a+b+c
print(min(d, e))
```
| 0
|
|
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,686,008,825
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 5
| 62
| 0
|
n = int(input())
a = [int(i) for i in input().split()]
d = 0 # max el index
f = 0 # min el index
answer = 0
index = 0 # 10 58 331 63 40 6 44
if a[0] != max(a) and a[-1] != min(a):
for i in range(len(a)):
if a[i] == max(a):
d = i
b = a[i]
if a[i] == min(a):
f = i
c = a[i]
index = len(a) - 1
answer = answer + (index - f)
answer = answer + d
if f < d:
answer = answer - 1
print(answer)
|
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(i) for i in input().split()]
d = 0 # max el index
f = 0 # min el index
answer = 0
index = 0 # 10 58 331 63 40 6 44
if a[0] != max(a) and a[-1] != min(a):
for i in range(len(a)):
if a[i] == max(a):
d = i
b = a[i]
if a[i] == min(a):
f = i
c = a[i]
index = len(a) - 1
answer = answer + (index - f)
answer = answer + d
if f < d:
answer = answer - 1
print(answer)
```
| 0
|
|
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,693,589,232
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 49
| 46
| 0
|
a=int(input())
count_100 = a//100
a%=100
count_20 = a//20
a%=20
count_10 = a//10
a%=10
count_5 = a//5
a%=5
count_1 = a
tot = count_100 + count_20 + count_10 + count_5 + count_1
print(tot)
|
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
a=int(input())
count_100 = a//100
a%=100
count_20 = a//20
a%=20
count_10 = a//10
a%=10
count_5 = a//5
a%=5
count_1 = a
tot = count_100 + count_20 + count_10 + count_5 + count_1
print(tot)
```
| 3
|
|
721
|
B
|
Passwords
|
PROGRAMMING
| 1,100
|
[
"implementation",
"math",
"sortings",
"strings"
] | null | null |
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).
|
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords.
|
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
|
[
"5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"4 100\n11\n22\n1\n2\n22\n"
] |
[
"1 15\n",
"3 4\n"
] |
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.
| 1,000
|
[
{
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc",
"output": "1 15"
},
{
"input": "4 100\n11\n22\n1\n2\n22",
"output": "3 4"
},
{
"input": "1 1\na1\na1",
"output": "1 1"
},
{
"input": "1 100\na1\na1",
"output": "1 1"
},
{
"input": "2 1\nabc\nAbc\nAbc",
"output": "1 7"
},
{
"input": "2 2\nabc\nAbc\nabc",
"output": "1 2"
},
{
"input": "2 1\nab\nabc\nab",
"output": "1 1"
},
{
"input": "2 2\nab\nabc\nab",
"output": "1 1"
},
{
"input": "2 1\nab\nabc\nabc",
"output": "7 7"
},
{
"input": "2 2\nab\nabc\nabc",
"output": "2 2"
},
{
"input": "10 3\nOIbV1igi\no\nZS\nQM\n9woLzI\nWreboD\nQ7yl\nA5Rb\nS9Lno72TkP\nfT97o\no",
"output": "1 1"
},
{
"input": "10 3\nHJZNMsT\nLaPcH2C\nlrhqIO\n9cxw\noTC1XwjW\nGHL9Ul6\nUyIs\nPuzwgR4ZKa\nyIByoKR5\nd3QA\nPuzwgR4ZKa",
"output": "25 25"
},
{
"input": "20 5\nvSyC787KlIL8kZ2Uv5sw\nWKWOP\n7i8J3E8EByIq\nNW2VyGweL\nmyR2sRNu\nmXusPP0\nf4jgGxra\n4wHRzRhOCpEt\npPz9kybGb\nOtSpePCRoG5nkjZ2VxRy\nwHYsSttWbJkg\nKBOP9\nQfiOiFyHPPsw3GHo8J8\nxB8\nqCpehZEeEhdq\niOLjICK6\nQ91\nHmCsfMGTFKoFFnv238c\nJKjhg\ngkEUh\nKBOP9",
"output": "3 11"
},
{
"input": "15 2\nw6S9WyU\nMVh\nkgUhQHW\nhGQNOF\nUuym\n7rGQA\nBM8vLPRB\n9E\nDs32U\no\nz1aV2C5T\n8\nzSXjrqQ\n1FO\n3kIt\nBM8vLPRB",
"output": "44 50"
},
{
"input": "20 2\ni\n5Rp6\nE4vsr\nSY\nORXx\nh13C\nk6tzC\ne\nN\nKQf4C\nWZcdL\ndiA3v\n0InQT\nuJkAr\nGCamp\nBuIRd\nY\nM\nxZYx7\n0a5A\nWZcdL",
"output": "36 65"
},
{
"input": "20 2\naWLQ6\nSgQ9r\nHcPdj\n2BNaO\n3TjNb\nnvwFM\nqsKt7\nFnb6N\nLoc0p\njxuLq\nBKAjf\nEKgZB\nBfOSa\nsMIvr\nuIWcR\nIura3\nLAqSf\ntXq3G\n8rQ8I\n8otAO\nsMIvr",
"output": "1 65"
},
{
"input": "20 15\n0ZpQugVlN7\nm0SlKGnohN\nRFXTqhNGcn\n1qm2ZbB\nQXtJWdf78P\nbc2vH\nP21dty2Z1P\nm2c71LFhCk\n23EuP1Dvh3\nanwri5RhQN\n55v6HYv288\n1u5uKOjM5r\n6vg0GC1\nDAPYiA3ns1\nUZaaJ3Gmnk\nwB44x7V4Zi\n4hgB2oyU8P\npYFQpy8gGK\ndbz\nBv\n55v6HYv288",
"output": "6 25"
},
{
"input": "3 1\na\nb\naa\naa",
"output": "13 13"
},
{
"input": "6 3\nab\nac\nad\nabc\nabd\nabe\nabc",
"output": "9 11"
},
{
"input": "4 2\n1\n2\n11\n22\n22",
"output": "8 9"
},
{
"input": "2 1\n1\n12\n12",
"output": "7 7"
},
{
"input": "3 1\nab\nabc\nabd\nabc",
"output": "7 13"
},
{
"input": "2 1\na\nab\nab",
"output": "7 7"
},
{
"input": "5 2\na\nb\nc\nab\naa\naa",
"output": "9 15"
},
{
"input": "6 1\n1\n2\n11\n22\n111\n2222\n22",
"output": "13 19"
},
{
"input": "3 1\n1\n2\n11\n11",
"output": "13 13"
},
{
"input": "10 4\na\nb\nc\nd\ne\nf\nab\ncd\nac\nad\nac",
"output": "12 20"
},
{
"input": "4 2\na\nb\nc\nd\na",
"output": "1 9"
},
{
"input": "4 1\n1\n2\n3\n4\n4",
"output": "1 19"
},
{
"input": "5 1\na\nb\nc\nd\nef\nef",
"output": "25 25"
},
{
"input": "6 4\n1\n2\n22\n33\n44\n555\n555",
"output": "11 11"
},
{
"input": "5 2\na\nb\nc\nd\nab\nab",
"output": "15 15"
},
{
"input": "6 2\n1\n2\n3\n4\n5\n23\n23",
"output": "16 16"
},
{
"input": "4 2\na\nb\naa\nbb\naa",
"output": "8 9"
},
{
"input": "5 4\na\nbb\ncc\ndd\nee\nbb",
"output": "2 10"
},
{
"input": "4 1\na\nb\nc\nab\nab",
"output": "19 19"
},
{
"input": "7 100\na\nb\nc\nd\ne\ng\nab\nab",
"output": "7 7"
},
{
"input": "6 1\na\nb\nc\nd\ne\naa\naa",
"output": "31 31"
},
{
"input": "4 1\na\nas\nasd\nasde\nasde",
"output": "19 19"
},
{
"input": "5 2\n1\n2\n3\n11\n22\n22",
"output": "9 15"
},
{
"input": "10 2\na\nb\nc\nd\nee\nff\ngg\nhh\nii\njj\nii",
"output": "15 30"
},
{
"input": "3 1\na\nab\nbc\nab",
"output": "7 13"
},
{
"input": "6 4\na\nb\nc\nbb\nbc\ncc\ncc",
"output": "4 11"
}
] | 1,576,210,869
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 93
| 0
|
def fnd1(s,x):
hi=len(s)-1
lo=0
ans=-1
while hi>=lo:
mid=(hi+lo)//2
if s[mid]>=x:
hi=mid-1
ans=mid+1
else: lo=mid+1
return ans
def fnd2(s,x):
hi=len(s)-1
lo=0
ans=-1
while hi>=lo:
mid=(hi+lo)//2
if s[mid]<=x:
lo=mid+1
ans=mid+1
else: hi=mid-1
return ans
x,k=map(int,input().split())
s=[]
for n in range(x):
p=input()
s.append(len(p))
s.sort()
tar=len(input())
a=fnd1(s,tar)
b=fnd2(s,tar)
print(a+5*(a//k),b+5*(b//k))
|
Title: Passwords
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords.
Output Specification:
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
Demo Input:
['5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n', '4 100\n11\n22\n1\n2\n22\n']
Demo Output:
['1 15\n', '3 4\n']
Note:
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.
|
```python
def fnd1(s,x):
hi=len(s)-1
lo=0
ans=-1
while hi>=lo:
mid=(hi+lo)//2
if s[mid]>=x:
hi=mid-1
ans=mid+1
else: lo=mid+1
return ans
def fnd2(s,x):
hi=len(s)-1
lo=0
ans=-1
while hi>=lo:
mid=(hi+lo)//2
if s[mid]<=x:
lo=mid+1
ans=mid+1
else: hi=mid-1
return ans
x,k=map(int,input().split())
s=[]
for n in range(x):
p=input()
s.append(len(p))
s.sort()
tar=len(input())
a=fnd1(s,tar)
b=fnd2(s,tar)
print(a+5*(a//k),b+5*(b//k))
```
| 0
|
|
567
|
A
|
Lineland Mail
|
PROGRAMMING
| 900
|
[
"greedy",
"implementation"
] | null | null |
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
|
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
|
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
|
[
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] |
[
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] |
none
| 500
|
[
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
"output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000"
},
{
"input": "2\n-1000000000 1000000000",
"output": "2000000000 2000000000\n2000000000 2000000000"
},
{
"input": "10\n1 10 12 15 59 68 130 912 1239 9123",
"output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122"
},
{
"input": "5\n-2 -1 0 1 2",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "5\n-2 -1 0 1 3",
"output": "1 5\n1 4\n1 3\n1 3\n2 5"
},
{
"input": "3\n-10000 1 10000",
"output": "10001 20000\n9999 10001\n9999 20000"
},
{
"input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706",
"output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010"
},
{
"input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124",
"output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524"
},
{
"input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292",
"output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307"
},
{
"input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986",
"output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14"
},
{
"input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886",
"output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..."
},
{
"input": "3\n-1000000000 999999999 1000000000",
"output": "1999999999 2000000000\n1 1999999999\n1 2000000000"
}
] | 1,643,463,324
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 54
| 451
| 8,089,600
|
import math
def main():
# t = int(input())
# for _ in range(t):
(case())
def case():
n = int(input())
a = list(map(int, input().split()))
print(f'{abs(a[0]-a[1])} {abs(a[0]-a[-1])}')
for i in range(1, n-1):
head = a[0]
tail = a[-1]
print(min(abs(a[i]-a[i+1]), abs(a[i]-a[i-1])), end=' ')
print(max(abs(a[i]-head), abs(a[i]-tail)))
print(f'{abs(a[-1]-a[-2])} {abs(a[-1]-a[0])}')
main()
|
Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
Input Specification:
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Output Specification:
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
Demo Input:
['4\n-5 -2 2 7\n', '2\n-1 1\n']
Demo Output:
['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n']
Note:
none
|
```python
import math
def main():
# t = int(input())
# for _ in range(t):
(case())
def case():
n = int(input())
a = list(map(int, input().split()))
print(f'{abs(a[0]-a[1])} {abs(a[0]-a[-1])}')
for i in range(1, n-1):
head = a[0]
tail = a[-1]
print(min(abs(a[i]-a[i+1]), abs(a[i]-a[i-1])), end=' ')
print(max(abs(a[i]-head), abs(a[i]-tail)))
print(f'{abs(a[-1]-a[-2])} {abs(a[-1]-a[0])}')
main()
```
| 3
|
|
135
|
B
|
Rectangle and Square
|
PROGRAMMING
| 1,600
|
[
"brute force",
"geometry",
"math"
] | 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.
| 1,000
|
[
{
"input": "0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2",
"output": "YES\n5 6 7 8\n1 2 3 4"
},
{
"input": "0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7",
"output": "NO"
},
{
"input": "0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1",
"output": "YES\n1 2 3 4\n5 6 7 8"
},
{
"input": "-160 336\n-76 672\n8 168\n-580 588\n-1000 504\n-496 840\n-496 84\n-664 0",
"output": "YES\n2 3 4 7\n1 5 6 8"
},
{
"input": "8 -328\n-440 568\n-104 8\n-1000 -664\n8 456\n-328 8\n-552 120\n-664 -1000",
"output": "YES\n2 3 5 7\n1 4 6 8"
},
{
"input": "65 852\n-645 284\n-361 710\n-1000 71\n-219 284\n207 426\n-716 0\n-929 355",
"output": "YES\n1 3 5 6\n2 4 7 8"
},
{
"input": "980 518\n584 -670\n-208 914\n-736 -340\n-604 -274\n-1000 -736\n-604 -1000\n-340 -604",
"output": "YES\n1 2 3 5\n4 6 7 8"
},
{
"input": "48 264\n144 240\n24 0\n168 48\n120 144\n0 72\n144 120\n24 168",
"output": "YES\n1 2 5 8\n3 4 6 7"
},
{
"input": "576 -616\n192 -424\n384 152\n768 248\n384 -1000\n0 -808\n480 -232\n864 -136",
"output": "YES\n1 2 5 6\n3 4 7 8"
},
{
"input": "547 -167\n-1000 -762\n190 904\n-762 -1000\n-167 71\n904 547\n71 -167\n-167 190",
"output": "YES\n1 3 6 8\n2 4 5 7"
},
{
"input": "-1000 -736\n1200 408\n1728 12\n188 -1000\n1332 -516\n-736 -208\n452 -472\n804 -120",
"output": "NO"
},
{
"input": "210 140\n140 0\n210 210\n455 140\n70 210\n525 385\n0 70\n280 455",
"output": "YES\n1 2 5 7\n3 4 6 8"
},
{
"input": "-1000 -829\n-715 -601\n311 197\n197 -715\n-829 -1000\n-601 311\n-658 -487\n-487 -658",
"output": "YES\n2 3 4 6\n1 5 7 8"
},
{
"input": "329 -859\n282 -765\n376 81\n0 -906\n47 -1000\n846 -577\n940 -13\n282 -483",
"output": "YES\n3 6 7 8\n1 2 4 5"
},
{
"input": "40 100\n210 20\n100 60\n120 230\n0 40\n60 0\n60 80\n270 170",
"output": "YES\n1 3 5 6\n2 4 7 8"
},
{
"input": "-252 -1000\n-1000 -932\n-864 20\n-796 -864\n768 -388\n-932 -796\n-864 -1000\n156 632",
"output": "YES\n2 4 6 7\n1 3 5 8"
},
{
"input": "351 234\n234 741\n234 351\n702 819\n117 0\n0 117\n312 273\n780 351",
"output": "YES\n2 4 7 8\n1 3 5 6"
},
{
"input": "434 372\n0 62\n496 868\n868 620\n620 248\n248 496\n62 434\n372 0",
"output": "YES\n3 4 5 6\n1 2 7 8"
},
{
"input": "-40 -1000\n-440 120\n2200 -200\n1800 920\n-200 -680\n-840 120\n-40 -360\n-1000 -200",
"output": "NO"
},
{
"input": "-850 -1000\n-475 -325\n1025 800\n-325 575\n-325 -850\n-1000 -475\n-100 -775\n1250 -550",
"output": "YES\n1 2 5 6\n3 4 7 8"
},
{
"input": "70 64\n32 0\n58 48\n48 80\n72 50\n0 48\n56 62\n80 32",
"output": "YES\n1 3 5 7\n2 4 6 8"
},
{
"input": "937 937\n-851 43\n-404 1086\n43 -106\n788 -404\n-553 -255\n-1000 -851\n-106 -1000",
"output": "YES\n1 3 5 6\n2 4 7 8"
},
{
"input": "-1 -223\n554 110\n-778 -1000\n-667 -445\n-1000 -667\n-445 -778\n443 -334\n110 221",
"output": "YES\n3 4 5 6\n1 2 7 8"
},
{
"input": "1610 0\n1700 270\n-1000 -900\n2105 315\n800 0\n-190 -900\n1925 90\n1880 495",
"output": "NO"
},
{
"input": "-360 120\n600 440\n-680 -40\n440 600\n-520 -360\n-200 -200\n-840 -1000\n-1000 -840",
"output": "YES\n1 3 5 6\n2 4 7 8"
},
{
"input": "-11 220\n-11 22\n176 -66\n-198 -22\n-198 176\n220 -198\n0 88\n44 -44",
"output": "NO"
},
{
"input": "378 504\n504 504\n126 0\n504 126\n0 378\n252 546\n294 798\n546 756",
"output": "YES\n1 3 4 5\n2 6 7 8"
},
{
"input": "312 468\n312 0\n728 728\n468 676\n520 416\n0 0\n780 468\n0 468",
"output": "YES\n3 4 5 7\n1 2 6 8"
},
{
"input": "180 100\n180 220\n80 0\n240 760\n0 80\n100 180\n720 160\n780 700",
"output": "YES\n2 4 7 8\n1 3 5 6"
},
{
"input": "-1000 -742\n1064 290\n32 634\n720 -742\n-742 -226\n-312 -398\n-484 -1000\n-226 -484",
"output": "YES\n2 3 4 6\n1 5 7 8"
},
{
"input": "-153 -238\n-204 34\n102 119\n34 0\n-663 -306\n0 68\n-612 -578\n136 51",
"output": "NO"
},
{
"input": "-620 -1000\n-1000 -620\n976 672\n-240 140\n596 140\n140 -240\n1052 216\n520 596",
"output": "YES\n3 5 7 8\n1 2 4 6"
},
{
"input": "203 232\n232 348\n58 0\n0 58\n319 203\n290 232\n348 319\n232 290",
"output": "YES\n1 2 5 7\n3 4 6 8"
},
{
"input": "-328 260\n-664 -1000\n-1000 -496\n92 -496\n-1000 -1000\n-664 -496\n-496 -328\n260 92",
"output": "YES\n1 4 7 8\n2 3 5 6"
},
{
"input": "-586 414\n-931 0\n-103 276\n-448 897\n-655 414\n35 759\n-586 345\n-1000 69",
"output": "YES\n1 3 4 6\n2 5 7 8"
},
{
"input": "-424 920\n-1000 152\n344 -232\n-232 536\n-424 -1000\n-616 -40\n344 -616\n536 728",
"output": "YES\n1 3 6 8\n2 4 5 7"
},
{
"input": "427 -451\n549 -573\n122 -1000\n0 -85\n183 -512\n427 98\n610 -329\n0 -878",
"output": "YES\n4 5 6 7\n1 2 3 8"
},
{
"input": "89 -307\n-109 -505\n-10 89\n-1000 -604\n-505 -1000\n-406 -10\n-307 -406\n-604 -109",
"output": "YES\n1 3 6 7\n2 4 5 8"
},
{
"input": "5 0\n16 -54\n9 5\n0 4\n0 -6\n4 9\n40 -24\n-24 -36",
"output": "NO"
},
{
"input": "-845 860\n-535 -225\n-380 85\n395 550\n-225 -535\n-1000 -690\n-690 -1000\n-70 1325",
"output": "YES\n1 3 4 8\n2 5 6 7"
},
{
"input": "702 628\n-334 -408\n-482 -852\n850 -704\n-408 -334\n-926 -1000\n-1000 -926\n-630 480",
"output": "YES\n1 3 4 8\n2 5 6 7"
},
{
"input": "-465 -37\n-465 -1000\n177 -37\n-144 177\n-1000 -37\n-1000 -1000\n-358 -144\n-37 -358",
"output": "YES\n3 4 7 8\n1 2 5 6"
},
{
"input": "-1000 176\n408 88\n-384 528\n-648 704\n-472 792\n-736 0\n-384 0\n320 880",
"output": "YES\n2 5 7 8\n1 3 4 6"
},
{
"input": "-1000 786\n-906 1256\n-671 1021\n-812 974\n598 316\n-765 1303\n598 -1000\n-1000 -530",
"output": "NO"
},
{
"input": "550 -70\n-8 -597\n-70 -628\n-39 -690\n-1000 -380\n23 -659\n-70 550\n-380 -1000",
"output": "YES\n2 3 4 6\n1 5 7 8"
},
{
"input": "184 230\n46 0\n0 184\n23 184\n115 552\n483 460\n391 92\n230 46",
"output": "YES\n4 5 6 7\n1 2 3 8"
},
{
"input": "692 -60\n-812 316\n128 880\n-248 -624\n-812 692\n-1000 -1000\n-1000 692\n-812 -1000",
"output": "YES\n1 2 3 4\n5 6 7 8"
},
{
"input": "-1000 -852\n-852 -1000\n332 480\n36 1812\n184 2996\n480 332\n-408 776\n-556 -408",
"output": "NO"
},
{
"input": "68 0\n374 221\n306 204\n323 136\n272 340\n391 153\n0 272\n340 68",
"output": "YES\n2 3 4 6\n1 5 7 8"
},
{
"input": "296 -163\n350 -190\n-190 -1000\n701 -730\n782 -244\n215 -649\n-1000 -460\n-460 350",
"output": "YES\n1 4 5 6\n2 3 7 8"
},
{
"input": "280 0\n504 420\n0 0\n0 168\n644 504\n280 168\n532 532\n616 392",
"output": "YES\n2 5 7 8\n1 3 4 6"
},
{
"input": "728 656\n584 152\n1160 152\n-1000 -1000\n1016 944\n-568 -424\n1448 440\n1016 728",
"output": "NO"
},
{
"input": "0 25\n725 325\n250 225\n575 675\n375 175\n225 525\n25 0\n225 250",
"output": "YES\n2 4 5 6\n1 3 7 8"
},
{
"input": "116 488\n-628 -1000\n-70 -70\n116 1604\n-814 860\n488 -628\n860 674\n-1000 116",
"output": "YES\n3 4 5 7\n1 2 6 8"
},
{
"input": "-208 -703\n-109 -604\n-406 -10\n287 188\n-208 -406\n-1000 -802\n-901 -1000\n485 -505",
"output": "YES\n1 3 4 8\n2 5 6 7"
},
{
"input": "1136 602\n1403 -21\n-21 -911\n-1000 424\n-733 513\n-288 -1000\n780 -288\n513 335",
"output": "NO"
},
{
"input": "760 980\n1420 -120\n320 -780\n-1000 -560\n100 -340\n-340 320\n-560 -1000\n-340 100",
"output": "YES\n1 2 3 6\n4 5 7 8"
},
{
"input": "2843 260\n3347 890\n2780 827\n1520 134\n-1000 -874\n2276 8\n-244 -1000\n3410 323",
"output": "NO"
},
{
"input": "0 336\n112 476\n196 448\n336 0\n560 896\n140 560\n224 532\n896 560",
"output": "YES\n2 3 6 7\n1 4 5 8"
},
{
"input": "0 39\n169 117\n182 182\n104 130\n117 195\n65 0\n39 104\n104 65",
"output": "YES\n2 3 4 5\n1 6 7 8"
},
{
"input": "-610 40\n-1000 -220\n-870 -1000\n-220 352\n-298 -350\n-220 -90\n92 -38\n-90 -870",
"output": "YES\n1 4 5 7\n2 3 6 8"
},
{
"input": "560 140\n0 140\n280 280\n560 700\n420 560\n700 560\n140 0\n700 420",
"output": "YES\n1 3 5 8\n2 4 6 7"
},
{
"input": "400 -580\n-580 -895\n-475 -720\n-580 -1000\n-405 -1000\n-20 400\n-300 -825\n-1000 -20",
"output": "YES\n2 3 5 7\n1 4 6 8"
},
{
"input": "-736 -560\n56 -560\n-208 320\n-736 -472\n56 760\n-648 320\n-1000 -1000\n144 232",
"output": "NO"
},
{
"input": "688 516\n387 258\n0 129\n387 430\n43 0\n430 129\n774 215\n473 129",
"output": "YES\n1 4 7 8\n2 3 5 6"
},
{
"input": "-856 -1000\n224 872\n-136 8\n584 656\n8 512\n368 296\n8 -136\n-1000 -856",
"output": "YES\n2 4 5 6\n1 3 7 8"
},
{
"input": "-880 0\n400 -240\n-640 480\n-160 240\n-240 480\n-520 360\n320 0\n-1000 120",
"output": "NO"
},
{
"input": "58 0\n0 58\n377 145\n261 203\n203 261\n406 29\n290 0\n261 116",
"output": "YES\n3 6 7 8\n1 2 4 5"
},
{
"input": "420 280\n308 196\n336 392\n224 308\n0 224\n224 280\n56 0\n280 56",
"output": "YES\n1 2 3 4\n5 6 7 8"
},
{
"input": "136 -1000\n544 -864\n408 -456\n816 156\n340 88\n884 -320\n0 -592\n408 -388",
"output": "YES\n1 2 3 7\n4 5 6 8"
},
{
"input": "920 -360\n2088 200\n-1000 600\n2024 -56\n1576 -184\n1240 -1000\n-680 -40\n1512 -440",
"output": "NO"
},
{
"input": "528 660\n792 660\n660 528\n528 0\n0 132\n330 462\n132 0\n990 198",
"output": "YES\n2 4 6 8\n1 3 5 7"
},
{
"input": "248 404\n872 794\n950 846\n560 -1000\n-1000 716\n924 716\n1002 768\n-688 -688",
"output": "NO"
},
{
"input": "-656 0\n-140 344\n-140 516\n-484 860\n-1000 344\n-54 946\n204 602\n-398 688",
"output": "YES\n2 6 7 8\n1 3 4 5"
},
{
"input": "744 -19\n-1000 -782\n-237 90\n-128 -346\n-346 -891\n-891 -1000\n635 -1000\n-19 -564",
"output": "YES\n1 3 5 7\n2 4 6 8"
},
{
"input": "420 -664\n0 -160\n420 260\n-840 -412\n420 -580\n-840 92\n420 -160\n0 -1000",
"output": "NO"
},
{
"input": "558 930\n0 837\n930 558\n310 775\n372 0\n0 372\n124 651\n186 961",
"output": "YES\n2 4 7 8\n1 3 5 6"
},
{
"input": "-1000 448\n120 448\n876 224\n1212 -84\n36 588\n372 280\n-776 0\n-104 896",
"output": "NO"
},
{
"input": "-320 904\n3896 -184\n224 224\n3624 -48\n-1000 360\n-456 -320\n-864 -864\n-592 -1000",
"output": "NO"
},
{
"input": "302 488\n-814 860\n-70 984\n-690 116\n-814 -1000\n488 302\n54 240\n-1000 -814",
"output": "YES\n2 3 4 7\n1 5 6 8"
},
{
"input": "0 0\n4 -16\n24 36\n-60 60\n-56 44\n36 43\n40 12\n52 19",
"output": "NO"
},
{
"input": "-1000 282\n-154 705\n-859 0\n974 846\n833 141\n128 282\n-13 423\n269 987",
"output": "YES\n4 5 6 8\n1 2 3 7"
},
{
"input": "20 -40\n-40 60\n-20 -15\n100 -90\n40 45\n0 0\n60 60\n40 10",
"output": "NO"
},
{
"input": "-192 -192\n-495 616\n-1000 -596\n414 -91\n313 717\n-394 -192\n-798 -1000\n10 -596",
"output": "YES\n2 4 5 6\n1 3 7 8"
},
{
"input": "-1000 -637\n-516 -274\n-274 -153\n-32 -516\n452 210\n210 -516\n-758 -1000\n-274 452",
"output": "YES\n2 5 6 8\n1 3 4 7"
},
{
"input": "-799 407\n-665 -531\n-531 -866\n-866 -1000\n-263 -933\n809 407\n1345 -933\n-1000 -665",
"output": "NO"
},
{
"input": "-1000 640\n-16 640\n312 -1000\n968 -16\n640 968\n-672 -344\n-672 -1000\n968 -672",
"output": "YES\n2 3 4 6\n1 5 7 8"
},
{
"input": "-1000 -676\n-136 -460\n-460 188\n188 80\n-568 -460\n-460 -136\n-676 -1000\n80 -568",
"output": "YES\n3 4 5 8\n1 2 6 7"
},
{
"input": "748 68\n663 -34\n0 680\n425 0\n663 -68\n425 680\n0 0\n578 -170",
"output": "NO"
},
{
"input": "248 92\n-1000 -792\n-584 -376\n-168 40\n-116 -376\n-792 -1000\n-376 -584\n300 -324",
"output": "YES\n1 4 5 8\n2 3 6 7"
},
{
"input": "140 42\n126 84\n-154 238\n-420 406\n14 0\n0 42\n-518 532\n-56 112",
"output": "NO"
},
{
"input": "477 0\n636 371\n106 689\n212 265\n0 53\n530 795\n53 530\n530 477",
"output": "YES\n2 3 4 6\n1 5 7 8"
},
{
"input": "0 -814\n93 -256\n372 -349\n186 23\n837 -628\n744 -442\n93 -1000\n465 -70",
"output": "YES\n2 3 4 8\n1 5 6 7"
},
{
"input": "-832 -286\n-748 -664\n-916 -1000\n302 -160\n-328 344\n-202 -790\n-1000 -748\n-664 -916",
"output": "YES\n1 4 5 6\n2 3 7 8"
},
{
"input": "25 10\n0 10\n41 34\n5 0\n39 30\n37 36\n35 32\n20 20",
"output": "YES\n3 5 6 7\n1 2 4 8"
},
{
"input": "-522 -1000\n912 1629\n912 434\n-283 1629\n-1000 -283\n195 -522\n-283 195\n-283 2824",
"output": "NO"
},
{
"input": "-586 -310\n-310 104\n104 -586\n-172 -1000\n-1000 -310\n-724 -862\n-34 -448\n-586 -1000",
"output": "YES\n1 4 6 7\n2 3 5 8"
},
{
"input": "-445 -1\n-556 -1000\n554 443\n-1000 -445\n-445 -334\n443 -445\n-1 -556\n-334 554",
"output": "YES\n1 2 4 7\n3 5 6 8"
},
{
"input": "-288 -822\n-733 -110\n-733 -1000\n1047 -555\n-1000 -911\n780 780\n-466 -199\n-555 513",
"output": "YES\n1 4 6 8\n2 3 5 7"
},
{
"input": "2024 8\n1352 -1000\n1016 -244\n512 344\n1856 344\n2360 -748\n-1000 -664\n344 -664",
"output": "NO"
},
{
"input": "-1000 -400\n1190 450\n1460 420\n800 50\n1250 -550\n1100 360\n1370 330\n-550 -1000",
"output": "NO"
},
{
"input": "1175 450\n-130 -1000\n160 160\n-1000 -1000\n-1000 450\n-130 450\n1465 -565\n450 -855",
"output": "YES\n1 3 7 8\n2 4 5 6"
},
{
"input": "424 -288\n-1000 -466\n68 246\n246 1492\n-644 -1000\n-644 -110\n-1000 1136\n602 246",
"output": "YES\n4 6 7 8\n1 2 3 5"
},
{
"input": "-471 -80\n-1000 35\n-402 127\n150 -885\n-885 -1000\n35 150\n-333 -11\n-540 58",
"output": "YES\n2 4 5 6\n1 3 7 8"
},
{
"input": "-400 -1000\n-400 1000\n600 400\n400 1000\n400 1200\n-1000 -400\n-200 200\n1000 400",
"output": "YES\n2 3 5 7\n1 4 6 8"
},
{
"input": "292 1414\n802 1312\n-1000 -1000\n462 2400\n-184 -235\n-847 326\n-31 1091\n972 2298",
"output": "NO"
},
{
"input": "0 0\n8 12\n14 4\n0 10\n7 5\n5 10\n15 11\n5 0",
"output": "YES\n2 3 5 7\n1 4 6 8"
},
{
"input": "60 260\n280 0\n100 240\n80 200\n0 0\n0 400\n280 400\n40 220",
"output": "YES\n1 3 4 8\n2 5 6 7"
},
{
"input": "-850 -1000\n-1000 -850\n-800 -250\n250 -700\n-50 50\n-500 -1000\n-650 -800\n-800 -650",
"output": "YES\n3 4 5 6\n1 2 7 8"
},
{
"input": "-125 -825\n1100 -475\n400 -300\n-1000 -475\n-475 400\n-650 -1000\n50 225\n750 750",
"output": "YES\n1 2 5 8\n3 4 6 7"
},
{
"input": "-725 1596\n155 -1000\n-758 1530\n-571 1376\n-1000 320\n-692 1497\n-659 1563\n584 56",
"output": "NO"
},
{
"input": "-638 3887\n-1000 1896\n448 1353\n-95 4430\n-457 -1000\n-276 4611\n-95 4249\n-819 4068",
"output": "NO"
},
{
"input": "216 0\n828 504\n648 612\n504 432\n756 792\n288 576\n0 144\n936 684",
"output": "YES\n2 3 5 8\n1 4 6 7"
},
{
"input": "72 32\n4 40\n44 32\n32 0\n40 72\n20 16\n28 56\n0 40",
"output": "YES\n2 3 6 7\n1 4 5 8"
},
{
"input": "457 -329\n-530 611\n-624 0\n-953 658\n-577 188\n-859 -141\n692 -188\n-1000 235",
"output": "NO"
},
{
"input": "-841 -205\n590 -205\n-1000 -1000\n-364 1385\n-682 113\n-841 -1000\n-1000 -205\n908 1067",
"output": "YES\n2 4 5 8\n1 3 6 7"
},
{
"input": "-1000 -604\n-604 1112\n-340 -736\n452 1376\n-604 -340\n-736 -1000\n716 320\n-340 56",
"output": "YES\n1 3 5 6\n2 4 7 8"
},
{
"input": "-260 332\n-112 776\n776 184\n-1000 -1000\n-112 1368\n-852 36\n628 924\n36 36",
"output": "NO"
},
{
"input": "600 0\n460 600\n500 960\n0 200\n660 760\n300 800\n100 500\n700 300",
"output": "YES\n2 3 5 6\n1 4 7 8"
},
{
"input": "15 160\n-101 334\n-855 -1000\n-275 -101\n-1000 -855\n160 15\n160 -275\n334 160",
"output": "YES\n2 4 7 8\n1 3 5 6"
},
{
"input": "0 108\n216 144\n480 360\n0 0\n60 108\n240 192\n60 0\n-24 -24",
"output": "NO"
},
{
"input": "344 -200\n-200 -520\n-680 -1000\n280 -8\n-1000 -680\n536 -136\n-520 -200\n472 56",
"output": "YES\n1 4 6 8\n2 3 5 7"
},
{
"input": "270 2024\n-486 -1000\n-162 2672\n162 2888\n540 728\n918 1862\n-864 1160\n486 2510",
"output": "NO"
},
{
"input": "0 336\n128 80\n240 272\n0 0\n368 -112\n128 -256\n144 96\n464 64",
"output": "NO"
},
{
"input": "-526 -447\n-1000 -526\n-526 -1000\n-131 -131\n-368 106\n185 -526\n-210 -842\n106 -368",
"output": "YES\n1 4 6 7\n2 3 5 8"
},
{
"input": "648 440\n720 -1000\n0 -280\n-120 1520\n-840 2240\n720 488\n672 560\n600 512",
"output": "NO"
},
{
"input": "-1000 568\n-432 639\n278 710\n-929 0\n-361 355\n-361 71\n-219 852\n136 213",
"output": "YES\n1 2 4 6\n3 5 7 8"
},
{
"input": "-520 480\n-40 240\n-1000 240\n240 360\n-400 240\n-160 520\n-880 0\n120 640",
"output": "YES\n2 4 6 8\n1 3 5 7"
},
{
"input": "270 225\n297 387\n315 135\n387 315\n45 0\n0 90\n225 297\n315 225",
"output": "YES\n2 4 7 8\n1 3 5 6"
},
{
"input": "60 30\n0 18\n24 6\n81 36\n75 57\n18 24\n54 51\n6 0",
"output": "YES\n1 4 5 7\n2 3 6 8"
},
{
"input": "134 -496\n-496 -118\n-748 8\n-1000 -748\n8 -244\n-370 134\n-622 260\n-874 -1000",
"output": "YES\n2 3 6 7\n1 4 5 8"
},
{
"input": "1538 -718\n-1000 -718\n3277 -13\n3089 645\n3747 833\n-718 -1000\n3935 175\n1820 -1000",
"output": "NO"
},
{
"input": "116 232\n87 0\n319 116\n203 174\n58 145\n174 0\n203 261\n0 58",
"output": "YES\n3 5 6 7\n1 2 4 8"
},
{
"input": "-912 -296\n672 -560\n-472 -296\n-648 -208\n-648 1288\n-824 -1000\n-1000 -912\n936 1024",
"output": "YES\n1 2 5 8\n3 4 6 7"
},
{
"input": "428 -796\n-592 -1000\n666 3318\n-1000 1856\n190 2842\n462 3454\n394 2706\n20 2060",
"output": "NO"
},
{
"input": "684 399\n0 228\n570 342\n228 285\n342 0\n228 570\n570 855\n114 741",
"output": "YES\n2 3 5 6\n1 4 7 8"
},
{
"input": "-1000 -373\n254 1090\n-791 672\n463 -164\n-373 -373\n-373 -1000\n-164 463\n672 45",
"output": "YES\n2 3 5 8\n1 4 6 7"
},
{
"input": "-536 -304\n-536 508\n-768 -188\n-768 -1000\n-1000 -768\n160 276\n-72 -420\n-304 -536",
"output": "YES\n2 3 6 7\n1 4 5 8"
},
{
"input": "120 30\n200 160\n130 0\n150 40\n40 200\n0 40\n160 10\n160 0",
"output": "YES\n1 3 4 7\n2 5 6 8"
},
{
"input": "595 -159\n421 -565\n-275 -1000\n-275 -420\n189 15\n-1000 -1000\n-1000 -420\n15 -391",
"output": "YES\n1 2 5 8\n3 4 6 7"
},
{
"input": "6 40\n0 35\n4 50\n5 0\n35 40\n40 5\n10 46\n0 44",
"output": "YES\n2 4 5 6\n1 3 7 8"
},
{
"input": "360 300\n210 240\n240 90\n180 210\n150 390\n300 450\n0 120\n60 0",
"output": "YES\n1 2 5 6\n3 4 7 8"
},
{
"input": "434 116\n434 426\n-186 -1000\n-186 -256\n0 116\n434 -628\n62 54\n372 488",
"output": "NO"
},
{
"input": "520 -325\n260 0\n650 -455\n0 195\n130 390\n195 455\n455 260\n260 260",
"output": "NO"
},
{
"input": "189 135\n261 153\n0 54\n81 0\n234 108\n216 180\n135 81\n54 135",
"output": "YES\n1 2 5 6\n3 4 7 8"
},
{
"input": "864 -540\n972 -162\n342 216\n0 -324\n108 54\n468 378\n486 234\n324 360",
"output": "NO"
},
{
"input": "265 220\n30 -60\n330 -420\n140 110\n15 0\n140 200\n15 90\n345 -480",
"output": "NO"
},
{
"input": "94 112\n-190 360\n-280 0\n0 0\n94 84\n74 76\n114 120\n90 360",
"output": "NO"
},
{
"input": "234 104\n0 52\n286 104\n598 624\n208 156\n182 520\n26 0\n702 208",
"output": "YES\n3 4 6 8\n1 2 5 7"
},
{
"input": "0 304\n456 532\n532 304\n456 76\n304 380\n152 0\n608 228\n228 152",
"output": "YES\n3 4 5 8\n1 2 6 7"
},
{
"input": "517 551\n940 786\n376 -13\n799 -1000\n-94 -154\n329 -906\n329 81\n-94 81",
"output": "NO"
},
{
"input": "117 0\n195 312\n312 195\n0 117\n312 663\n195 390\n468 273\n585 546",
"output": "YES\n5 6 7 8\n1 2 3 4"
},
{
"input": "646 102\n238 136\n102 510\n136 0\n578 578\n102 238\n0 102\n170 34",
"output": "YES\n2 4 6 7\n1 3 5 8"
},
{
"input": "-856 -1000\n440 728\n728 296\n-1000 -856\n296 8\n-424 -280\n-280 -424\n8 440",
"output": "YES\n2 3 5 8\n1 4 6 7"
},
{
"input": "160 120\n180 120\n340 140\n20 0\n320 300\n180 40\n160 280\n0 80",
"output": "YES\n2 3 5 7\n1 4 6 8"
},
{
"input": "195 260\n533 390\n455 546\n0 65\n260 195\n65 0\n689 468\n611 624",
"output": "YES\n2 3 7 8\n1 4 5 6"
},
{
"input": "123 0\n-410 123\n902 -123\n-82 369\n123 492\n0 492\n574 -369\n0 0",
"output": "NO"
},
{
"input": "42 -168\n966 252\n462 126\n840 756\n336 630\n0 -588\n-252 -168\n-294 -588",
"output": "NO"
},
{
"input": "280 480\n360 -80\n-1000 -640\n-200 -160\n-760 -1000\n-280 -160\n-280 400\n-40 -520",
"output": "YES\n1 2 4 7\n3 5 6 8"
},
{
"input": "-622 315\n-1000 126\n-937 0\n-55 315\n-559 189\n-433 441\n-307 819\n71 693",
"output": "YES\n4 6 7 8\n1 2 3 5"
},
{
"input": "410 533\n287 41\n615 164\n328 246\n697 451\n246 287\n0 246\n41 0",
"output": "YES\n1 3 4 5\n2 6 7 8"
},
{
"input": "-919 0\n53 648\n-514 405\n-433 729\n-1000 162\n-28 162\n-433 243\n-514 243",
"output": "YES\n2 4 6 8\n1 3 5 7"
},
{
"input": "-1000 276\n-586 828\n-34 414\n104 414\n-862 690\n-448 276\n-34 966\n-172 0",
"output": "YES\n2 4 6 7\n1 3 5 8"
},
{
"input": "-544 -316\n140 368\n-1000 -772\n-316 -544\n-316 596\n-544 140\n-88 -88\n-772 -1000",
"output": "YES\n2 5 6 7\n1 3 4 8"
},
{
"input": "980 -520\n860 -430\n620 -250\n500 -160\n20 1220\n-1000 980\n380 -760\n-640 -1000",
"output": "NO"
},
{
"input": "432 -1000\n0 -1000\n0 -520\n432 -520\n864 104\n192 8\n960 -568\n288 -664",
"output": "YES\n5 6 7 8\n1 2 3 4"
},
{
"input": "872 872\n-766 -1000\n170 -64\n1808 989\n1925 53\n989 -64\n-64 170\n-1000 -766",
"output": "YES\n1 4 5 6\n2 3 7 8"
},
{
"input": "-620 -1000\n-430 -240\n45 -240\n-810 -145\n-145 520\n-715 -430\n-905 330\n-1000 -905",
"output": "YES\n3 5 6 7\n1 2 4 8"
},
{
"input": "-316 684\n-1000 -228\n444 76\n520 152\n1204 380\n-316 0\n-240 0\n368 760",
"output": "NO"
},
{
"input": "364 -688\n-260 248\n-312 40\n0 -532\n0 -792\n104 -792\n260 -428\n-52 -1000",
"output": "NO"
},
{
"input": "96 180\n-204 108\n-144 36\n84 102\n-12 0\n0 6\n-72 72\n12 84",
"output": "NO"
},
{
"input": "357 -1000\n119 190\n714 -48\n0 -643\n833 -524\n952 547\n476 -167\n357 785",
"output": "YES\n2 3 6 8\n1 4 5 7"
},
{
"input": "598 368\n414 92\n0 0\n138 46\n368 322\n644 138\n138 0\n0 46",
"output": "YES\n1 2 5 6\n3 4 7 8"
},
{
"input": "-480 -350\n-1000 -870\n-870 -1000\n-155 495\n-740 -285\n40 -870\n625 -90\n-350 -480",
"output": "YES\n4 5 6 7\n1 2 3 8"
},
{
"input": "-340 1640\n-1000 650\n320 375\n705 485\n815 100\n430 -10\n-340 -10\n-1000 -1000",
"output": "NO"
},
{
"input": "120 120\n105 30\n30 0\n0 75\n75 90\n90 165\n75 105\n45 135",
"output": "YES\n2 3 4 7\n1 5 6 8"
},
{
"input": "840 980\n140 532\n980 840\n588 420\n700 868\n252 980\n140 0\n0 140",
"output": "YES\n2 4 5 6\n1 3 7 8"
},
{
"input": "-244 -730\n512 998\n-460 -946\n728 1214\n-1000 -568\n728 -892\n80 -1000\n-352 -460",
"output": "NO"
},
{
"input": "62 60\n54 50\n6 42\n64 42\n0 6\n36 0\n72 52\n42 36",
"output": "YES\n1 2 4 7\n3 5 6 8"
},
{
"input": "-941 -1000\n-764 -410\n-823 -882\n-882 -823\n-1000 -941\n1006 298\n475 -941\n-233 829",
"output": "YES\n2 6 7 8\n1 3 4 5"
},
{
"input": "360 648\n504 360\n0 360\n648 288\n288 504\n648 576\n288 0\n432 720",
"output": "YES\n1 3 4 7\n2 5 6 8"
},
{
"input": "792 -648\n-352 -142\n704 -1000\n88 -472\n0 -824\n-682 1046\n572 -208\n242 980",
"output": "NO"
},
{
"input": "-1000 176\n100 616\n-824 0\n-780 396\n-252 88\n-780 440\n-428 968\n-604 220",
"output": "YES\n2 5 6 7\n1 3 4 8"
},
{
"input": "-1000 -580\n-1000 -1000\n330 960\n610 260\n-860 -580\n120 470\n-860 -1000\n820 750",
"output": "YES\n3 4 6 8\n1 2 5 7"
},
{
"input": "0 -970\n90 -580\n585 500\n150 -880\n270 -400\n30 -1000\n405 320\n120 -850",
"output": "NO"
},
{
"input": "600 500\n700 200\n600 180\n620 100\n700 120\n100 0\n680 200\n0 300",
"output": "YES\n3 4 5 7\n1 2 6 8"
},
{
"input": "256 496\n304 512\n576 0\n320 464\n272 448\n0 64\n64 640\n640 576",
"output": "YES\n1 2 4 5\n3 6 7 8"
},
{
"input": "128 112\n40 72\n64 96\n72 40\n80 32\n32 0\n0 32\n144 48",
"output": "YES\n1 3 5 8\n2 4 6 7"
},
{
"input": "-1000 1052\n140 -392\n292 -1000\n900 -848\n-12 368\n672 -544\n748 -240\n-316 140",
"output": "NO"
},
{
"input": "-208 -10\n188 -208\n386 188\n-505 -1000\n-505 -703\n-10 386\n-1000 -1000\n-1000 -703",
"output": "YES\n1 2 3 6\n4 5 7 8"
},
{
"input": "153 102\n187 170\n102 153\n153 68\n0 51\n221 102\n51 0\n119 136",
"output": "YES\n2 4 6 8\n1 3 5 7"
},
{
"input": "-1000 -60\n-342 -1000\n1444 -248\n1162 -718\n1538 -624\n1914 -530\n786 692\n2290 -436",
"output": "NO"
},
{
"input": "3368 858\n-1000 -546\n1886 0\n3914 702\n3602 429\n3056 585\n-298 -780\n2588 -234",
"output": "NO"
},
{
"input": "780 68\n424 -466\n68 -110\n246 424\n246 -466\n-110 -110\n-822 -1000\n-1000 -644",
"output": "YES\n1 2 4 6\n3 5 7 8"
},
{
"input": "-372 93\n-403 31\n31 -31\n558 186\n248 434\n279 155\n0 -93\n527 465",
"output": "NO"
},
{
"input": "-859 329\n-1000 141\n81 705\n-906 0\n-577 987\n-718 329\n-624 188\n-201 47",
"output": "YES\n1 3 5 8\n2 4 6 7"
},
{
"input": "-97 -140\n290 -97\n290 935\n935 290\n-1000 -355\n-140 247\n247 290\n-355 -1000",
"output": "YES\n1 2 6 7\n3 4 5 8"
},
{
"input": "426 518\n-609 449\n633 -1000\n-586 2220\n-954 2174\n-632 2588\n-1000 2542\n-816 1967",
"output": "NO"
},
{
"input": "410 -754\n574 312\n82 66\n820 -180\n410 -1000\n0 -1000\n328 -426\n0 -754",
"output": "YES\n2 3 4 7\n1 5 6 8"
},
{
"input": "-700 120\n-370 -90\n-40 510\n-490 150\n-1000 -60\n-670 -270\n-850 600\n-400 960",
"output": "NO"
},
{
"input": "100 100\n100 101\n101 100\n101 101\n0 0\n0 5\n10 5\n0 -10",
"output": "NO"
},
{
"input": "100 100\n100 101\n101 100\n101 101\n0 0\n0 5\n10 5\n6 2",
"output": "NO"
},
{
"input": "100 100\n100 101\n101 100\n101 101\n0 0\n1 5\n11 5\n10 0",
"output": "NO"
},
{
"input": "0 0\n1 0\n0 1\n1 1\n100 100\n100 101\n101 100\n101 101",
"output": "YES\n1 2 3 4\n5 6 7 8"
},
{
"input": "0 8\n-2 0\n-3 0\n0 -8\n2 0\n3 0\n0 2\n0 -2",
"output": "NO"
},
{
"input": "-8 0\n0 -3\n8 0\n10000 10000\n9999 9999\n9999 10000\n0 3\n10000 9999",
"output": "NO"
},
{
"input": "-8 0\n0 -3\n8 0\n10000 10000\n9998 9999\n9998 10000\n0 3\n10000 9999",
"output": "NO"
},
{
"input": "10 10\n15 11\n15 9\n20 10\n100 100\n100 102\n107 102\n107 100",
"output": "NO"
},
{
"input": "0 0\n5 0\n8 4\n3 4\n-2 -2\n-2 -1\n-1 -1\n-1 -2",
"output": "NO"
},
{
"input": "0 0\n1 1\n2 2\n3 3\n4 4\n4 5\n5 4\n5 5",
"output": "NO"
},
{
"input": "0 0\n0 1\n1 0\n1 1\n10 10\n14 10\n12 16\n12 20",
"output": "NO"
},
{
"input": "0 0\n0 1\n1 0\n1 1\n2 0\n2 1\n3 1\n4 0",
"output": "NO"
},
{
"input": "1 1\n1 2\n2 1\n2 2\n100 100\n101 100\n101 102\n102 102",
"output": "NO"
},
{
"input": "0 0\n2 0\n2 2\n0 2\n1 1\n5 0\n5 2\n9 1",
"output": "NO"
},
{
"input": "0 0\n0 1\n1 0\n1 1\n2 2\n3 2\n3 3\n4 3",
"output": "NO"
},
{
"input": "4 1\n7 3\n9 4\n4 5\n1 3\n9 6\n12 4\n12 6",
"output": "NO"
},
{
"input": "0 0\n3 0\n3 4\n6 4\n100 100\n101 100\n100 101\n101 101",
"output": "NO"
},
{
"input": "1 0\n0 4\n2 4\n1 8\n15 15\n15 16\n18 15\n18 16",
"output": "NO"
},
{
"input": "0 0\n0 1\n1 1\n1 0\n1000 1000\n1001 1003\n1004 1004\n1003 1001",
"output": "NO"
},
{
"input": "1 0\n2 2\n0 2\n1 4\n7 0\n9 0\n7 1\n9 1",
"output": "NO"
},
{
"input": "0 0\n1 0\n1 1\n0 1\n5 6\n100 190\n6 7\n10 196",
"output": "NO"
},
{
"input": "0 0\n1 0\n2 0\n1 2\n50 50\n50 51\n51 51\n51 50",
"output": "NO"
}
] | 1,605,106,474
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 186
| 204,800
|
def is_rectangle(a, b, c, d):
ab = (b[0]-a[0], b[1]-a[1])
ad = (d[0]-a[0], d[1]-a[1])
dp = ab[0]*ad[0] + ab[1]*ad[1]
ne = len(set((a, b, c, d))) == 4
return ne and dp == 0 and (a[0]+ab[0]+ad[0], a[1]+ab[1]+ad[1]) == c
def is_square(a, b, c, d):
abl = (b[0]-a[0])**2 + (b[1]-a[1])**2
adl = (d[0]-a[0])**2 + (d[1]-a[1])**2
return abl == adl and is_rectangle(a, b, c, d)
def is_rectangle_perm(a, b, c, d):
for p in permutations((a, b, c, d)):
if is_rectangle(*p):
return True
return False
def is_square_perm(a, b, c, d):
for p in permutations((a, b, c, d)):
if is_rectangle(*p):
return True
return False
ps = [list(map(int, input().split())) + [_] for _ in range(1, 9)]
possible = False
for i in range(0, 8):
for j in range(i+1, 8):
for k in range(j+1, 8):
for l in range(k+1, 8):
g0 = set(ps)
g1 = set((ps[i], ps[j], ps[k], ps[l]))
g2 = g0 - g1
possible = is_rectangle_perm(*g1) and is_square_perm(*g2)
possible = is_rectangle_perm(*g2) and is_square_perm(*g1)
print("YES" if possible else "NO")
|
Title: Rectangle and Square
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
def is_rectangle(a, b, c, d):
ab = (b[0]-a[0], b[1]-a[1])
ad = (d[0]-a[0], d[1]-a[1])
dp = ab[0]*ad[0] + ab[1]*ad[1]
ne = len(set((a, b, c, d))) == 4
return ne and dp == 0 and (a[0]+ab[0]+ad[0], a[1]+ab[1]+ad[1]) == c
def is_square(a, b, c, d):
abl = (b[0]-a[0])**2 + (b[1]-a[1])**2
adl = (d[0]-a[0])**2 + (d[1]-a[1])**2
return abl == adl and is_rectangle(a, b, c, d)
def is_rectangle_perm(a, b, c, d):
for p in permutations((a, b, c, d)):
if is_rectangle(*p):
return True
return False
def is_square_perm(a, b, c, d):
for p in permutations((a, b, c, d)):
if is_rectangle(*p):
return True
return False
ps = [list(map(int, input().split())) + [_] for _ in range(1, 9)]
possible = False
for i in range(0, 8):
for j in range(i+1, 8):
for k in range(j+1, 8):
for l in range(k+1, 8):
g0 = set(ps)
g1 = set((ps[i], ps[j], ps[k], ps[l]))
g2 = g0 - g1
possible = is_rectangle_perm(*g1) and is_square_perm(*g2)
possible = is_rectangle_perm(*g2) and is_square_perm(*g1)
print("YES" if possible else "NO")
```
| -1
|
|
148
|
A
|
Insomnia cure
|
PROGRAMMING
| 800
|
[
"constructive algorithms",
"implementation",
"math"
] | null | null |
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
|
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
|
Output the number of damaged dragons.
|
[
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] |
[
"12\n",
"17\n"
] |
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
| 1,000
|
[
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"input": "8\n4\n1\n10\n59392",
"output": "59392"
},
{
"input": "4\n1\n8\n7\n44835",
"output": "44835"
},
{
"input": "6\n1\n7\n2\n62982",
"output": "62982"
},
{
"input": "2\n7\n4\n9\n56937",
"output": "35246"
},
{
"input": "2\n9\n8\n1\n75083",
"output": "75083"
},
{
"input": "8\n7\n7\n6\n69038",
"output": "24656"
},
{
"input": "4\n4\n2\n3\n54481",
"output": "36320"
},
{
"input": "6\n4\n9\n8\n72628",
"output": "28244"
},
{
"input": "9\n7\n8\n10\n42357",
"output": "16540"
},
{
"input": "5\n6\n4\n3\n60504",
"output": "36302"
},
{
"input": "7\n2\n3\n8\n21754",
"output": "15539"
},
{
"input": "1\n2\n10\n4\n39901",
"output": "39901"
},
{
"input": "3\n4\n7\n1\n58048",
"output": "58048"
},
{
"input": "9\n10\n4\n6\n52003",
"output": "21956"
},
{
"input": "5\n10\n9\n3\n70149",
"output": "32736"
},
{
"input": "5\n5\n5\n10\n55592",
"output": "11118"
},
{
"input": "1\n5\n2\n6\n49547",
"output": "49547"
},
{
"input": "3\n7\n7\n7\n84046",
"output": "36019"
},
{
"input": "10\n2\n1\n8\n63537",
"output": "63537"
},
{
"input": "7\n2\n10\n5\n81684",
"output": "53678"
},
{
"input": "7\n1\n6\n8\n99831",
"output": "99831"
},
{
"input": "3\n9\n3\n3\n61082",
"output": "20360"
},
{
"input": "5\n5\n8\n9\n79228",
"output": "29931"
},
{
"input": "1\n5\n5\n6\n89535",
"output": "89535"
},
{
"input": "5\n5\n2\n1\n7682",
"output": "7682"
},
{
"input": "7\n4\n8\n8\n25829",
"output": "9224"
},
{
"input": "3\n4\n3\n3\n87079",
"output": "43539"
},
{
"input": "5\n8\n4\n9\n5226",
"output": "2438"
},
{
"input": "4\n9\n6\n6\n1070",
"output": "415"
},
{
"input": "10\n10\n10\n10\n100000",
"output": "10000"
},
{
"input": "1\n1\n1\n1\n1",
"output": "1"
},
{
"input": "10\n10\n10\n10\n1",
"output": "0"
},
{
"input": "10\n10\n1\n10\n10",
"output": "10"
},
{
"input": "10\n10\n1\n10\n100",
"output": "100"
},
{
"input": "2\n2\n2\n2\n1",
"output": "0"
}
] | 1,698,689,846
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 40
| 154
| 11,776,000
|
k=int(input())
l=int(input())
m=int(input())
n=int(input())
d=int(input())
if k==1 or l==1 or m==1 or n==1:
print(d)
else:
di={}
escaped=0
for i in range(1,d+1):
di[i]=0
for j in range(k,d+1,k):
di[j]=1
for j in range(l,d+1,l):
di[j]=1
for j in range(m,d+1,m):
di[j]=1
for j in range(n,d+1,n):
di[j]=1
for i in range(1,d+1):
if di[i]==0:
escaped+=1
print(d-escaped)
|
Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
Input Specification:
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output Specification:
Output the number of damaged dragons.
Demo Input:
['1\n2\n3\n4\n12\n', '2\n3\n4\n5\n24\n']
Demo Output:
['12\n', '17\n']
Note:
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
|
```python
k=int(input())
l=int(input())
m=int(input())
n=int(input())
d=int(input())
if k==1 or l==1 or m==1 or n==1:
print(d)
else:
di={}
escaped=0
for i in range(1,d+1):
di[i]=0
for j in range(k,d+1,k):
di[j]=1
for j in range(l,d+1,l):
di[j]=1
for j in range(m,d+1,m):
di[j]=1
for j in range(n,d+1,n):
di[j]=1
for i in range(1,d+1):
if di[i]==0:
escaped+=1
print(d-escaped)
```
| 3
|
|
441
|
A
|
Valera and Antique Items
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him.
Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with.
|
The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller.
|
In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
|
[
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] |
[
"3\n1 2 3\n",
"0\n\n"
] |
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.
| 500
|
[
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 1000000",
"output": "0"
},
{
"input": "1 1000000\n1 561774",
"output": "1\n1"
},
{
"input": "3 1000000\n5 1000000 568832 1000000 1000000 1000000\n13 1000000 1000000 1000000 596527 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n20 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000",
"output": "2\n1 2"
},
{
"input": "3 999999\n7 1000000 1000000 1000000 999999 1000000 999999 1000000\n6 999999 1000000 999999 1000000 999999 999999\n7 999999 1000000 1000000 999999 1000000 1000000 1000000",
"output": "0"
},
{
"input": "3 999999\n22 1000000 1000000 999999 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 999999 1000000 1000000 1000000 352800 999999 1000000\n14 999999 999999 999999 999999 999999 1000000 999999 999999 999999 999999 702638 999999 1000000 999999\n5 999999 1000000 1000000 999999 363236",
"output": "3\n1 2 3"
},
{
"input": "1 50001\n1 50000",
"output": "1\n1"
}
] | 1,632,583,500
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 61
| 6,963,200
|
n,v=map(int,input().split())
result=[]
for i in range(n):
l=list(map(int,input().split()))
b=l[1:]
li=0
for k in range(len(b)):
if(b[k]<v and li==0):
result.append(i+1)
li=1
print(sort(result))
|
Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him.
Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with.
Input Specification:
The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller.
Output Specification:
In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
Demo Input:
['3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n', '3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n']
Demo Output:
['3\n1 2 3\n', '0\n\n']
Note:
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.
|
```python
n,v=map(int,input().split())
result=[]
for i in range(n):
l=list(map(int,input().split()))
b=l[1:]
li=0
for k in range(len(b)):
if(b[k]<v and li==0):
result.append(i+1)
li=1
print(sort(result))
```
| -1
|
|
168
|
A
|
Wizards and Demonstration
|
PROGRAMMING
| 900
|
[
"implementation",
"math"
] | null | null |
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people.
|
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=><=*n*).
|
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
|
[
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] |
[
"1\n",
"0\n",
"1108\n"
] |
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
| 500
|
[
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
{
"input": "70 38 66",
"output": "9"
},
{
"input": "54 4 38",
"output": "17"
},
{
"input": "3 1 69",
"output": "2"
},
{
"input": "11 9 60",
"output": "0"
},
{
"input": "71 49 65",
"output": "0"
},
{
"input": "78 55 96",
"output": "20"
},
{
"input": "2765 768 9020",
"output": "248635"
},
{
"input": "3478 1728 9727",
"output": "336578"
},
{
"input": "9678 6173 5658",
"output": "541409"
},
{
"input": "1138 570 6666",
"output": "75290"
},
{
"input": "7754 204 9038",
"output": "700603"
},
{
"input": "8403 7401 4769",
"output": "393339"
},
{
"input": "4909 2111 8860",
"output": "432827"
},
{
"input": "6571 6449 8965",
"output": "582642"
},
{
"input": "9178 2255 7996",
"output": "731618"
},
{
"input": "6151 6148 3746",
"output": "224269"
},
{
"input": "8890 5449 8734",
"output": "771004"
},
{
"input": "7879 2590 2818",
"output": "219441"
},
{
"input": "8484 6400 547",
"output": "40008"
},
{
"input": "7835 6710 1639",
"output": "121706"
},
{
"input": "2379 1436 9663",
"output": "228447"
},
{
"input": "6487 5670 8",
"output": "0"
},
{
"input": "4470 2543 6",
"output": "0"
},
{
"input": "7261 5328 10",
"output": "0"
},
{
"input": "3871 3795 7",
"output": "0"
},
{
"input": "9620 6557 6",
"output": "0"
},
{
"input": "4890 1112 5",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 1 10000",
"output": "99"
},
{
"input": "10000 1 1",
"output": "99"
},
{
"input": "10000 1 10000",
"output": "999999"
},
{
"input": "10000 10000 1",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "990000"
},
{
"input": "67 1 3",
"output": "2"
},
{
"input": "7878 4534 9159",
"output": "717013"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "3271 5 50",
"output": "1631"
}
] | 1,614,263,749
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 124
| 0
|
from math import ceil
n,w,perc=list(map(int,input().split()))
print(ceil(n*(perc/100))-w)
|
Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people.
Input Specification:
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=><=*n*).
Output Specification:
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
Demo Input:
['10 1 14\n', '20 10 50\n', '1000 352 146\n']
Demo Output:
['1\n', '0\n', '1108\n']
Note:
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
|
```python
from math import ceil
n,w,perc=list(map(int,input().split()))
print(ceil(n*(perc/100))-w)
```
| 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,655,550,376
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 70
| 93
| 0
|
def solve(s:str):
a=[]
vowels=['A','E','I','O','U','Y']
flag=False
for i in range(0,len(s)):
if s[i] in vowels:
flag=True
a.append(i)
a.insert(0,-1)
a.append(len(s))
m=-1
if not flag:
print(len(s)+1)
else:
for i in range(1,len(a)):
#print(a[i])
if(m<(a[i]-a[i-1])):
m=a[i]-a[i-1]
print(m)
if __name__=='__main__':
s=input()
solve(s)
|
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
def solve(s:str):
a=[]
vowels=['A','E','I','O','U','Y']
flag=False
for i in range(0,len(s)):
if s[i] in vowels:
flag=True
a.append(i)
a.insert(0,-1)
a.append(len(s))
m=-1
if not flag:
print(len(s)+1)
else:
for i in range(1,len(a)):
#print(a[i])
if(m<(a[i]-a[i-1])):
m=a[i]-a[i-1]
print(m)
if __name__=='__main__':
s=input()
solve(s)
```
| 3
|
|
489
|
B
|
BerSU Ball
|
PROGRAMMING
| 1,200
|
[
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"sortings",
"two pointers"
] | null | null |
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from *n* boys and *m* girls.
|
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth line contains sequence *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**j*<=≤<=100), where *b**j* is the *j*-th girl's dancing skill.
|
Print a single number — the required maximum possible number of pairs.
|
[
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
] |
[
"3\n",
"0\n",
"2\n"
] |
none
| 1,000
|
[
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9",
"output": "3"
},
{
"input": "4\n1 2 3 4\n4\n10 11 12 13",
"output": "0"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3",
"output": "2"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 10\n1\n9",
"output": "1"
},
{
"input": "4\n4 5 4 4\n5\n5 3 4 2 4",
"output": "4"
},
{
"input": "1\n2\n1\n1",
"output": "1"
},
{
"input": "1\n3\n2\n3 2",
"output": "1"
},
{
"input": "1\n4\n3\n4 4 4",
"output": "1"
},
{
"input": "1\n2\n4\n3 1 4 2",
"output": "1"
},
{
"input": "1\n4\n5\n2 5 5 3 1",
"output": "1"
},
{
"input": "2\n2 2\n1\n2",
"output": "1"
},
{
"input": "2\n4 2\n2\n4 4",
"output": "1"
},
{
"input": "2\n4 1\n3\n2 3 2",
"output": "2"
},
{
"input": "2\n4 3\n4\n5 5 5 6",
"output": "1"
},
{
"input": "2\n5 7\n5\n4 6 7 2 5",
"output": "2"
},
{
"input": "3\n1 2 3\n1\n1",
"output": "1"
},
{
"input": "3\n5 4 5\n2\n2 1",
"output": "0"
},
{
"input": "3\n6 3 4\n3\n4 5 2",
"output": "3"
},
{
"input": "3\n7 7 7\n4\n2 7 2 4",
"output": "1"
},
{
"input": "3\n1 3 3\n5\n1 3 4 1 2",
"output": "3"
},
{
"input": "4\n1 2 1 3\n1\n4",
"output": "1"
},
{
"input": "4\n4 4 6 6\n2\n2 1",
"output": "0"
},
{
"input": "4\n3 1 1 1\n3\n1 6 7",
"output": "1"
},
{
"input": "4\n2 5 1 2\n4\n2 3 3 1",
"output": "3"
},
{
"input": "4\n9 1 7 1\n5\n9 9 9 8 4",
"output": "2"
},
{
"input": "5\n1 6 5 5 6\n1\n2",
"output": "1"
},
{
"input": "5\n5 2 4 5 6\n2\n7 4",
"output": "2"
},
{
"input": "5\n4 1 3 1 4\n3\n6 3 6",
"output": "1"
},
{
"input": "5\n5 2 3 1 4\n4\n1 3 1 7",
"output": "3"
},
{
"input": "5\n9 8 10 9 10\n5\n2 1 5 4 6",
"output": "0"
},
{
"input": "1\n48\n100\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6",
"output": "1"
},
{
"input": "100\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\n1\n58",
"output": "0"
},
{
"input": "10\n20 87 3 39 20 20 8 40 70 51\n100\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96",
"output": "6"
},
{
"input": "100\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\n10\n66 74 40 67 28 82 99 57 93 64",
"output": "9"
},
{
"input": "100\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\n100\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1",
"output": "76"
},
{
"input": "4\n1 6 9 15\n2\n5 8",
"output": "2"
},
{
"input": "2\n2 4\n2\n3 1",
"output": "2"
},
{
"input": "3\n2 3 5\n3\n3 4 6",
"output": "3"
},
{
"input": "3\n1 3 4\n3\n2 1 5",
"output": "3"
},
{
"input": "2\n5 5\n4\n1 1 1 5",
"output": "1"
},
{
"input": "2\n3 2\n2\n3 4",
"output": "2"
},
{
"input": "2\n3 1\n2\n2 4",
"output": "2"
},
{
"input": "2\n2 3\n2\n2 1",
"output": "2"
},
{
"input": "2\n10 12\n2\n11 9",
"output": "2"
},
{
"input": "3\n1 2 3\n3\n3 2 1",
"output": "3"
},
{
"input": "2\n1 3\n2\n2 1",
"output": "2"
},
{
"input": "2\n4 5\n2\n5 3",
"output": "2"
},
{
"input": "2\n7 5\n2\n6 8",
"output": "2"
},
{
"input": "4\n4 3 2 1\n4\n1 2 3 4",
"output": "4"
},
{
"input": "2\n2 3\n2\n3 1",
"output": "2"
},
{
"input": "2\n2 4\n3\n3 1 8",
"output": "2"
},
{
"input": "3\n3 1 1\n3\n2 4 4",
"output": "2"
},
{
"input": "2\n5 3\n2\n4 6",
"output": "2"
},
{
"input": "4\n1 1 3 3\n4\n2 2 1 1",
"output": "4"
},
{
"input": "3\n3 2 1\n3\n2 4 3",
"output": "3"
},
{
"input": "5\n1 2 3 4 5\n5\n2 3 4 5 1",
"output": "5"
},
{
"input": "3\n3 2 1\n3\n1 2 3",
"output": "3"
},
{
"input": "2\n5 4\n2\n4 6",
"output": "2"
},
{
"input": "4\n3 3 5 5\n4\n4 4 2 2",
"output": "4"
},
{
"input": "3\n2 7 5\n3\n2 4 8",
"output": "3"
},
{
"input": "100\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\n100\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5",
"output": "100"
},
{
"input": "1\n3\n2\n2 3",
"output": "1"
},
{
"input": "2\n5 6\n3\n1 5 100",
"output": "1"
},
{
"input": "2\n2 7\n2\n6 8",
"output": "1"
},
{
"input": "4\n4 10 15 17\n4\n3 12 16 16",
"output": "3"
},
{
"input": "2\n2 3\n2\n1 2",
"output": "2"
}
] | 1,687,093,972
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 81
| 77
| 1,638,400
|
import bisect
left = lambda l,a : bisect.bisect_left(l,a) #returns index of value>=a
right = lambda l,a : bisect.bisect_right(l,a) #returns index of value >a
import sys
def input(): return sys.stdin.readline().strip()
def getints(): return map(int,sys.stdin.readline().strip().split())
n = int(input())
b = sorted(getints())
m = int(input())
g = sorted(getints())
ans = 0
j = 0
for i in b:
for j in g:
if abs(i-j) <= 1:
ans += 1
g.remove(j)
break
print(ans)
|
Title: BerSU Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from *n* boys and *m* girls.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth line contains sequence *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**j*<=≤<=100), where *b**j* is the *j*-th girl's dancing skill.
Output Specification:
Print a single number — the required maximum possible number of pairs.
Demo Input:
['4\n1 4 6 2\n5\n5 1 5 7 9\n', '4\n1 2 3 4\n4\n10 11 12 13\n', '5\n1 1 1 1 1\n3\n1 2 3\n']
Demo Output:
['3\n', '0\n', '2\n']
Note:
none
|
```python
import bisect
left = lambda l,a : bisect.bisect_left(l,a) #returns index of value>=a
right = lambda l,a : bisect.bisect_right(l,a) #returns index of value >a
import sys
def input(): return sys.stdin.readline().strip()
def getints(): return map(int,sys.stdin.readline().strip().split())
n = int(input())
b = sorted(getints())
m = int(input())
g = sorted(getints())
ans = 0
j = 0
for i in b:
for j in g:
if abs(i-j) <= 1:
ans += 1
g.remove(j)
break
print(ans)
```
| 3
|
|
799
|
A
|
Carrot Cakes
|
PROGRAMMING
| 1,100
|
[
"brute force",
"implementation"
] | null | null |
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.
|
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
|
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
|
[
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] |
[
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] |
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.
| 500
|
[
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"
},
{
"input": "599 97 54 992",
"output": "YES"
},
{
"input": "11 22 18 17",
"output": "NO"
},
{
"input": "1 13 22 11",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "NO"
},
{
"input": "3 1 1 1",
"output": "YES"
},
{
"input": "1000 1000 1000 1000",
"output": "NO"
},
{
"input": "1000 1000 1 1",
"output": "YES"
},
{
"input": "1000 1000 1 400",
"output": "YES"
},
{
"input": "1000 1000 1 1000",
"output": "YES"
},
{
"input": "1000 1000 1 999",
"output": "YES"
},
{
"input": "53 11 3 166",
"output": "YES"
},
{
"input": "313 2 3 385",
"output": "NO"
},
{
"input": "214 9 9 412",
"output": "NO"
},
{
"input": "349 9 5 268",
"output": "YES"
},
{
"input": "611 16 8 153",
"output": "YES"
},
{
"input": "877 13 3 191",
"output": "YES"
},
{
"input": "340 9 9 10",
"output": "YES"
},
{
"input": "31 8 2 205",
"output": "NO"
},
{
"input": "519 3 2 148",
"output": "YES"
},
{
"input": "882 2 21 219",
"output": "NO"
},
{
"input": "982 13 5 198",
"output": "YES"
},
{
"input": "428 13 6 272",
"output": "YES"
},
{
"input": "436 16 14 26",
"output": "YES"
},
{
"input": "628 10 9 386",
"output": "YES"
},
{
"input": "77 33 18 31",
"output": "YES"
},
{
"input": "527 36 4 8",
"output": "YES"
},
{
"input": "128 18 2 169",
"output": "YES"
},
{
"input": "904 4 2 288",
"output": "YES"
},
{
"input": "986 4 3 25",
"output": "YES"
},
{
"input": "134 8 22 162",
"output": "NO"
},
{
"input": "942 42 3 69",
"output": "YES"
},
{
"input": "894 4 9 4",
"output": "YES"
},
{
"input": "953 8 10 312",
"output": "YES"
},
{
"input": "43 8 1 121",
"output": "YES"
},
{
"input": "12 13 19 273",
"output": "NO"
},
{
"input": "204 45 10 871",
"output": "YES"
},
{
"input": "342 69 50 425",
"output": "NO"
},
{
"input": "982 93 99 875",
"output": "NO"
},
{
"input": "283 21 39 132",
"output": "YES"
},
{
"input": "1000 45 83 686",
"output": "NO"
},
{
"input": "246 69 36 432",
"output": "NO"
},
{
"input": "607 93 76 689",
"output": "NO"
},
{
"input": "503 21 24 435",
"output": "NO"
},
{
"input": "1000 45 65 989",
"output": "NO"
},
{
"input": "30 21 2 250",
"output": "YES"
},
{
"input": "1000 49 50 995",
"output": "NO"
},
{
"input": "383 69 95 253",
"output": "YES"
},
{
"input": "393 98 35 999",
"output": "YES"
},
{
"input": "1000 22 79 552",
"output": "NO"
},
{
"input": "268 294 268 154",
"output": "NO"
},
{
"input": "963 465 706 146",
"output": "YES"
},
{
"input": "304 635 304 257",
"output": "NO"
},
{
"input": "4 2 1 6",
"output": "NO"
},
{
"input": "1 51 10 50",
"output": "NO"
},
{
"input": "5 5 4 4",
"output": "YES"
},
{
"input": "3 2 1 1",
"output": "YES"
},
{
"input": "3 4 3 3",
"output": "NO"
},
{
"input": "7 3 4 1",
"output": "YES"
},
{
"input": "101 10 1 1000",
"output": "NO"
},
{
"input": "5 1 1 1",
"output": "YES"
},
{
"input": "5 10 5 5",
"output": "NO"
},
{
"input": "19 1 7 1",
"output": "YES"
},
{
"input": "763 572 745 262",
"output": "YES"
},
{
"input": "1 2 1 1",
"output": "NO"
},
{
"input": "5 1 1 3",
"output": "YES"
},
{
"input": "170 725 479 359",
"output": "NO"
},
{
"input": "6 2 1 7",
"output": "YES"
},
{
"input": "6 2 5 1",
"output": "YES"
},
{
"input": "1 2 2 1",
"output": "NO"
},
{
"input": "24 2 8 3",
"output": "YES"
},
{
"input": "7 3 3 3",
"output": "YES"
},
{
"input": "5 2 2 2",
"output": "YES"
},
{
"input": "3 2 1 2",
"output": "YES"
},
{
"input": "1000 2 200 8",
"output": "NO"
},
{
"input": "3 100 2 100",
"output": "NO"
},
{
"input": "2 999 1 1000",
"output": "NO"
},
{
"input": "2 1 1 1",
"output": "NO"
},
{
"input": "2 3 5 1",
"output": "NO"
},
{
"input": "100 1 5 1",
"output": "YES"
},
{
"input": "7 2 3 3",
"output": "YES"
},
{
"input": "4 1 1 3",
"output": "NO"
},
{
"input": "3 2 2 1",
"output": "YES"
},
{
"input": "1 1 1 2",
"output": "NO"
},
{
"input": "91 8 7 13",
"output": "YES"
},
{
"input": "3 1 2 1",
"output": "NO"
},
{
"input": "5 3 2 3",
"output": "YES"
},
{
"input": "9 6 6 3",
"output": "YES"
}
] | 1,629,720,841
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 93
| 311
| 6,963,200
|
import math
n,t,k,d=map(int,input().split())
x=math.ceil(n/k)*t
y,i=0,1
while n>0:
if i%t==0:
y=i
n-=k
# print(y,n)
if (i-d)>0 and (i-d)%t==0 and i!=d:
y=i
n-=k
# print(y,n)
i+=1
if y<x:
print("YES")
else:
print("NO")
|
Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.
Input Specification:
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
Output Specification:
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
Demo Input:
['8 6 4 5\n', '8 6 4 6\n', '10 3 11 4\n', '4 2 1 4\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n', 'YES\n']
Note:
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.
|
```python
import math
n,t,k,d=map(int,input().split())
x=math.ceil(n/k)*t
y,i=0,1
while n>0:
if i%t==0:
y=i
n-=k
# print(y,n)
if (i-d)>0 and (i-d)%t==0 and i!=d:
y=i
n-=k
# print(y,n)
i+=1
if y<x:
print("YES")
else:
print("NO")
```
| 3
|
|
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,692,904,688
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
n = int(input())
elif n % 2 == 0 and n != 2:
print("YES")
elif n % 2 == 1 or n == 2:
print("NO")
|
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
n = int(input())
elif n % 2 == 0 and n != 2:
print("YES")
elif n % 2 == 1 or n == 2:
print("NO")
```
| -1
|
770
|
A
|
New Password
|
PROGRAMMING
| 800
|
[
"*special",
"implementation"
] | null | null |
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
|
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists.
|
Print any password which satisfies all conditions given by Innokentiy.
|
[
"4 3\n",
"6 6\n",
"5 2\n"
] |
[
"java\n",
"python\n",
"phphp\n"
] |
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
| 500
|
[
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcdefghijklm"
},
{
"input": "100 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "100 10",
"output": "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"
},
{
"input": "3 3",
"output": "abc"
},
{
"input": "6 3",
"output": "abcabc"
},
{
"input": "10 3",
"output": "abcabcabca"
},
{
"input": "50 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab"
},
{
"input": "90 2",
"output": "ababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "6 2",
"output": "ababab"
},
{
"input": "99 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"
},
{
"input": "4 2",
"output": "abab"
},
{
"input": "100 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "40 22",
"output": "abcdefghijklmnopqrstuvabcdefghijklmnopqr"
},
{
"input": "13 8",
"output": "abcdefghabcde"
},
{
"input": "16 15",
"output": "abcdefghijklmnoa"
},
{
"input": "17 17",
"output": "abcdefghijklmnopq"
},
{
"input": "19 4",
"output": "abcdabcdabcdabcdabc"
},
{
"input": "100 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv"
},
{
"input": "100 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy"
},
{
"input": "26 26",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "27 26",
"output": "abcdefghijklmnopqrstuvwxyza"
},
{
"input": "2 2",
"output": "ab"
},
{
"input": "26 25",
"output": "abcdefghijklmnopqrstuvwxya"
},
{
"input": "99 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababa"
},
{
"input": "99 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu"
},
{
"input": "4 4",
"output": "abcd"
},
{
"input": "5 3",
"output": "abcab"
},
{
"input": "5 4",
"output": "abcda"
},
{
"input": "5 5",
"output": "abcde"
},
{
"input": "24 22",
"output": "abcdefghijklmnopqrstuvab"
},
{
"input": "26 14",
"output": "abcdefghijklmnabcdefghijkl"
},
{
"input": "26 15",
"output": "abcdefghijklmnoabcdefghijk"
},
{
"input": "30 12",
"output": "abcdefghijklabcdefghijklabcdef"
},
{
"input": "35 4",
"output": "abcdabcdabcdabcdabcdabcdabcdabcdabc"
},
{
"input": "79 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "79 14",
"output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi"
},
{
"input": "85 13",
"output": "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg"
},
{
"input": "90 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno"
},
{
"input": "90 19",
"output": "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn"
},
{
"input": "26 24",
"output": "abcdefghijklmnopqrstuvwxab"
},
{
"input": "100 17",
"output": "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno"
},
{
"input": "26 2",
"output": "ababababababababababababab"
}
] | 1,638,042,177
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 31
| 0
|
import random
n,k = (int(i) for i in input('').split(' '))
alpha = 'abcdefghijklmnobqrstuvwxyz'
password = ''
distinct = []
i=0
for i in range(k):
ran = alpha[i]
for i in range(n):
password+=distinct[i%k]
print(password)
|
Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
Input Specification:
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists.
Output Specification:
Print any password which satisfies all conditions given by Innokentiy.
Demo Input:
['4 3\n', '6 6\n', '5 2\n']
Demo Output:
['java\n', 'python\n', 'phphp\n']
Note:
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
|
```python
import random
n,k = (int(i) for i in input('').split(' '))
alpha = 'abcdefghijklmnobqrstuvwxyz'
password = ''
distinct = []
i=0
for i in range(k):
ran = alpha[i]
for i in range(n):
password+=distinct[i%k]
print(password)
```
| -1
|
|
761
|
A
|
Dasha and Stairs
|
PROGRAMMING
| 1,000
|
[
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null |
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct.
|
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
|
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
|
[
"2 3\n",
"3 1\n"
] |
[
"YES\n",
"NO\n"
] |
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5.
| 500
|
[
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25",
"output": "NO"
},
{
"input": "74 73",
"output": "YES"
},
{
"input": "62 39",
"output": "NO"
},
{
"input": "57 57",
"output": "YES"
},
{
"input": "100 99",
"output": "YES"
},
{
"input": "0 0",
"output": "NO"
},
{
"input": "98 100",
"output": "NO"
},
{
"input": "99 100",
"output": "YES"
},
{
"input": "1 0",
"output": "YES"
},
{
"input": "100 0",
"output": "NO"
},
{
"input": "0 100",
"output": "NO"
},
{
"input": "100 98",
"output": "NO"
},
{
"input": "100 100",
"output": "YES"
},
{
"input": "0 5",
"output": "NO"
},
{
"input": "2 2",
"output": "YES"
}
] | 1,486,239,897
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 21
| 77
| 4,608,000
|
string=input()
a,b=map(int,string.split(' '))
if a==0 and b==0:
print('NO')
elif a-b==1 or b-a==1:
print('YES')
elif a==b:
print('YES')
else:
print('NO')
|
Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct.
Input Specification:
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
Output Specification:
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
Demo Input:
['2 3\n', '3 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5.
|
```python
string=input()
a,b=map(int,string.split(' '))
if a==0 and b==0:
print('NO')
elif a-b==1 or b-a==1:
print('YES')
elif a==b:
print('YES')
else:
print('NO')
```
| 3
|
|
552
|
B
|
Vanya and Books
|
PROGRAMMING
| 1,200
|
[
"implementation",
"math"
] | null | null |
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
|
Print the number of digits needed to number all the books.
|
[
"13\n",
"4\n"
] |
[
"17\n",
"4\n"
] |
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
| 1,000
|
[
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"input": "999",
"output": "2889"
},
{
"input": "55",
"output": "101"
},
{
"input": "222222222",
"output": "1888888896"
},
{
"input": "8",
"output": "8"
},
{
"input": "13",
"output": "17"
},
{
"input": "313",
"output": "831"
},
{
"input": "1342",
"output": "4261"
},
{
"input": "30140",
"output": "139594"
},
{
"input": "290092",
"output": "1629447"
},
{
"input": "2156660",
"output": "13985516"
},
{
"input": "96482216",
"output": "760746625"
},
{
"input": "943006819",
"output": "8375950269"
},
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "7"
},
{
"input": "35",
"output": "61"
},
{
"input": "996",
"output": "2880"
},
{
"input": "6120",
"output": "23373"
},
{
"input": "30660",
"output": "142194"
},
{
"input": "349463",
"output": "1985673"
},
{
"input": "8171970",
"output": "56092686"
},
{
"input": "36123011",
"output": "277872985"
},
{
"input": "986747865",
"output": "8769619683"
},
{
"input": "9",
"output": "9"
},
{
"input": "10",
"output": "11"
},
{
"input": "11",
"output": "13"
},
{
"input": "101",
"output": "195"
},
{
"input": "1000",
"output": "2893"
},
{
"input": "1001",
"output": "2897"
},
{
"input": "9999",
"output": "38889"
},
{
"input": "10000",
"output": "38894"
},
{
"input": "10001",
"output": "38899"
},
{
"input": "99999",
"output": "488889"
},
{
"input": "100000",
"output": "488895"
},
{
"input": "100001",
"output": "488901"
},
{
"input": "999999",
"output": "5888889"
},
{
"input": "1000001",
"output": "5888903"
},
{
"input": "9999999",
"output": "68888889"
},
{
"input": "10000000",
"output": "68888897"
},
{
"input": "10000001",
"output": "68888905"
},
{
"input": "99999999",
"output": "788888889"
},
{
"input": "100000000",
"output": "788888898"
},
{
"input": "100000001",
"output": "788888907"
},
{
"input": "999999999",
"output": "8888888889"
},
{
"input": "95",
"output": "181"
},
{
"input": "995",
"output": "2877"
},
{
"input": "9995",
"output": "38873"
},
{
"input": "99995",
"output": "488869"
},
{
"input": "999999995",
"output": "8888888853"
},
{
"input": "999999998",
"output": "8888888880"
}
] | 1,537,648,847
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 55
| 124
| 0
|
ch=str(input())
n=int(ch)
res=0
if len(ch)>1:
for i in range(1,len(ch)):
res+=i*(10**i-10**(i-1))
res+=len(ch)*(n+1-10**(len(ch)-1))
print(res)
|
Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Output Specification:
Print the number of digits needed to number all the books.
Demo Input:
['13\n', '4\n']
Demo Output:
['17\n', '4\n']
Note:
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
|
```python
ch=str(input())
n=int(ch)
res=0
if len(ch)>1:
for i in range(1,len(ch)):
res+=i*(10**i-10**(i-1))
res+=len(ch)*(n+1-10**(len(ch)-1))
print(res)
```
| 3
|
|
940
|
C
|
Phone Numbers
|
PROGRAMMING
| 1,500
|
[
"constructive algorithms",
"implementation",
"strings"
] | null | null |
And where the are the phone numbers?
You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a subset of the set of letters of *s* and *s* is lexicographically smaller than *t*.
It's guaranteed that the answer exists.
Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {*a*,<=*b*,<=*d*}.
String *p* is lexicographically smaller than string *q*, if *p* is a prefix of *q*, is not equal to *q* or there exists *i*, such that *p**i*<=<<=*q**i* and for all *j*<=<<=*i* it is satisfied that *p**j*<==<=*q**j*. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a.
|
The first line of input contains two space separated integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the length of *s* and the required length of *t*.
The second line of input contains the string *s* consisting of *n* lowercase English letters.
|
Output the string *t* conforming to the requirements above.
It's guaranteed that the answer exists.
|
[
"3 3\nabc\n",
"3 2\nabc\n",
"3 3\nayy\n",
"2 3\nba\n"
] |
[
"aca\n",
"ac\n",
"yaa\n",
"baa\n"
] |
In the first example the list of strings *t* of length 3, such that the set of letters of *t* is a subset of letters of *s* is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
| 1,250
|
[
{
"input": "3 3\nabc",
"output": "aca"
},
{
"input": "3 2\nabc",
"output": "ac"
},
{
"input": "3 3\nayy",
"output": "yaa"
},
{
"input": "2 3\nba",
"output": "baa"
},
{
"input": "1 3\nf",
"output": "fff"
},
{
"input": "3 1\nazz",
"output": "z"
},
{
"input": "3 3\nzbf",
"output": "zbz"
},
{
"input": "2 3\ngi",
"output": "gig"
},
{
"input": "3 2\nyzy",
"output": "zy"
},
{
"input": "5 10\nkekff",
"output": "kekffeeeee"
},
{
"input": "10 5\nhqqqqcdddb",
"output": "qbbbb"
},
{
"input": "10 10\nmrfkcsxcuj",
"output": "mrfkcsxcuk"
},
{
"input": "10 3\nggjnohlepu",
"output": "ggl"
},
{
"input": "8 9\npppppppp",
"output": "ppppppppp"
},
{
"input": "10 7\nffffffffyf",
"output": "ffffffy"
},
{
"input": "10 2\nkmiejhcimj",
"output": "mc"
},
{
"input": "10 1\ngiwekrmngf",
"output": "i"
},
{
"input": "8 8\nlolololo",
"output": "lololool"
},
{
"input": "10 9\nbcegikmyyy",
"output": "bcegikybb"
},
{
"input": "7 5000\nqqqqqqq",
"output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq..."
},
{
"input": "3 99948\nttt",
"output": "ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt..."
}
] | 1,520,270,704
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 4
| 62
| 6,656,000
|
def rec(i,s2,test):
if i<k:
if i==0:
rec(1,s2+s[i],0)
x=st.index(s[i])
if x+1<len(st):
rec(1,s2+st[x+1],1)
elif test:
rec(i+1,s2+st[0],1)
elif i<n:
rec(i+1,s2+s[i],0)
x=st.index(s[i])
if x+1<len(st):
rec(i+1,s2+st[x+1],1)
else:
rec(i+1,s2+st[0],1)
else:
l.append(s2)
n,k=[int (i) for i in input().split()]
s=input()
st=tuple(sorted(set(s)))
l=[]
rec(0,"",0)
l.sort()
for i in l:
if s<i:
print(i)
break
|
Title: Phone Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
And where the are the phone numbers?
You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a subset of the set of letters of *s* and *s* is lexicographically smaller than *t*.
It's guaranteed that the answer exists.
Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {*a*,<=*b*,<=*d*}.
String *p* is lexicographically smaller than string *q*, if *p* is a prefix of *q*, is not equal to *q* or there exists *i*, such that *p**i*<=<<=*q**i* and for all *j*<=<<=*i* it is satisfied that *p**j*<==<=*q**j*. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a.
Input Specification:
The first line of input contains two space separated integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the length of *s* and the required length of *t*.
The second line of input contains the string *s* consisting of *n* lowercase English letters.
Output Specification:
Output the string *t* conforming to the requirements above.
It's guaranteed that the answer exists.
Demo Input:
['3 3\nabc\n', '3 2\nabc\n', '3 3\nayy\n', '2 3\nba\n']
Demo Output:
['aca\n', 'ac\n', 'yaa\n', 'baa\n']
Note:
In the first example the list of strings *t* of length 3, such that the set of letters of *t* is a subset of letters of *s* is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
|
```python
def rec(i,s2,test):
if i<k:
if i==0:
rec(1,s2+s[i],0)
x=st.index(s[i])
if x+1<len(st):
rec(1,s2+st[x+1],1)
elif test:
rec(i+1,s2+st[0],1)
elif i<n:
rec(i+1,s2+s[i],0)
x=st.index(s[i])
if x+1<len(st):
rec(i+1,s2+st[x+1],1)
else:
rec(i+1,s2+st[0],1)
else:
l.append(s2)
n,k=[int (i) for i in input().split()]
s=input()
st=tuple(sorted(set(s)))
l=[]
rec(0,"",0)
l.sort()
for i in l:
if s<i:
print(i)
break
```
| -1
|
|
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,590,390,664
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 0
| 109
| 0
|
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
m=k
for i in range(2*n):
s=l[i]*n+(l[i]/2)*n
if(s<=k):
m=max(s,m)
print(m)
|
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,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
m=k
for i in range(2*n):
s=l[i]*n+(l[i]/2)*n
if(s<=k):
m=max(s,m)
print(m)
```
| 0
|
|
155
|
A
|
I_love_\%username\%
|
PROGRAMMING
| 800
|
[
"brute force"
] | null | null |
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
|
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
|
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
|
[
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] |
[
"2\n",
"4\n"
] |
In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing.
| 500
|
[
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
},
{
"input": "5\n7 36 53 81 100",
"output": "4"
},
{
"input": "5\n100 81 53 36 7",
"output": "4"
},
{
"input": "10\n8 6 3 4 9 10 7 7 1 3",
"output": "5"
},
{
"input": "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862",
"output": "6"
},
{
"input": "10\n1 3 3 4 6 7 7 8 9 10",
"output": "7"
},
{
"input": "10\n1952 1862 1812 1746 1675 1627 1488 1390 1324 1137",
"output": "9"
},
{
"input": "25\n1448 4549 2310 2725 2091 3509 1565 2475 2232 3989 4231 779 2967 2702 608 3739 721 1552 2767 530 3114 665 1940 48 4198",
"output": "5"
},
{
"input": "33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101",
"output": "5"
},
{
"input": "34\n821 5536 2491 6074 7216 9885 764 1603 778 8736 8987 771 617 1587 8943 7922 439 7367 4115 8886 7878 6899 8811 5752 3184 3401 9760 9400 8995 4681 1323 6637 6554 6498",
"output": "7"
},
{
"input": "68\n6764 6877 6950 6768 6839 6755 6726 6778 6699 6805 6777 6985 6821 6801 6791 6805 6940 6761 6677 6999 6911 6699 6959 6933 6903 6843 6972 6717 6997 6756 6789 6668 6735 6852 6735 6880 6723 6834 6810 6694 6780 6679 6698 6857 6826 6896 6979 6968 6957 6988 6960 6700 6919 6892 6984 6685 6813 6678 6715 6857 6976 6902 6780 6686 6777 6686 6842 6679",
"output": "9"
},
{
"input": "60\n9000 9014 9034 9081 9131 9162 9174 9199 9202 9220 9221 9223 9229 9235 9251 9260 9268 9269 9270 9298 9307 9309 9313 9323 9386 9399 9407 9495 9497 9529 9531 9544 9614 9615 9627 9627 9643 9654 9656 9657 9685 9699 9701 9736 9745 9758 9799 9827 9843 9845 9854 9854 9885 9891 9896 9913 9942 9963 9986 9992",
"output": "57"
},
{
"input": "100\n7 61 12 52 41 16 34 99 30 44 48 89 31 54 21 1 48 52 61 15 35 87 21 76 64 92 44 81 16 93 84 92 32 15 68 76 53 39 26 4 11 26 7 4 99 99 61 65 55 85 65 67 47 39 2 74 63 49 98 87 5 94 22 30 25 42 31 84 49 23 89 60 16 26 92 27 9 57 75 61 94 35 83 47 99 100 63 24 91 88 79 10 15 45 22 64 3 11 89 83",
"output": "4"
},
{
"input": "100\n9999 9999 9999 9998 9998 9998 9997 9996 9996 9995 9993 9993 9991 9990 9989 9986 9984 9984 9983 9981 9981 9980 9980 9980 9979 9977 9977 9977 9977 9977 9976 9976 9975 9975 9973 9972 9972 9972 9972 9971 9969 9969 9969 9968 9967 9965 9962 9962 9962 9962 9960 9958 9958 9955 9954 9954 9954 9954 9950 9949 9949 9947 9943 9943 9940 9940 9939 9937 9937 9937 9936 9935 9932 9932 9931 9929 9927 9927 9926 9923 9919 9919 9918 9918 9918 9917 9917 9916 9916 9915 9914 9911 9910 9907 9907 9906 9905 9905 9904 9901",
"output": "57"
},
{
"input": "100\n158 159 157 156 155 154 160 153 161 152 162 163 151 164 150 165 149 148 147 166 146 167 145 144 143 142 168 141 169 170 140 139 138 137 171 136 135 134 172 173 174 133 175 132 177 178 131 179 180 130 129 181 128 127 182 126 183 125 124 184 123 122 121 120 119 118 117 185 186 187 188 189 116 190 115 191 192 193 114 113 112 111 110 109 108 194 195 107 106 105 196 197 104 198 199 103 102 200 101 100",
"output": "99"
},
{
"input": "2\n0 10000",
"output": "1"
},
{
"input": "2\n5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n10 10",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
}
] | 1,696,166,369
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 60
| 0
|
a = int(input())
b = list(map(int, input().split()))
ans = 0
maxh = b[0]
minh = b[0]
for i in range(a):
maxh = max(maxh, b[i])
minh = min(minh, b[i])
if b[i] > maxh:
ans += 1
if b[i] < minh:
ans += 1
print(ans)
|
Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
Input Specification:
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Output Specification:
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
Demo Input:
['5\n100 50 200 150 200\n', '10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n']
Demo Output:
['2\n', '4\n']
Note:
In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing.
|
```python
a = int(input())
b = list(map(int, input().split()))
ans = 0
maxh = b[0]
minh = b[0]
for i in range(a):
maxh = max(maxh, b[i])
minh = min(minh, b[i])
if b[i] > maxh:
ans += 1
if b[i] < minh:
ans += 1
print(ans)
```
| 0
|
|
677
|
A
|
Vanya and Fence
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
|
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
|
Print a single integer — the minimum possible valid width of the road.
|
[
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] |
[
"4\n",
"6\n",
"11\n"
] |
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
| 500
|
[
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481 554 1000 821",
"output": "15"
},
{
"input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396",
"output": "144"
},
{
"input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366",
"output": "145"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n2",
"output": "2"
},
{
"input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19",
"output": "63"
},
{
"input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386",
"output": "31"
},
{
"input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518",
"output": "75"
},
{
"input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397",
"output": "41"
},
{
"input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118",
"output": "116"
}
] | 1,695,582,784
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 29
| 62
| 0
|
inpa = input().split(' ')
inpb = input().split(' ')
counter = 0
for x in inpb:
if int(x) > int(inpa[1]):
counter += 2
else:
counter += 1
print(counter)
|
Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
Input Specification:
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Output Specification:
Print a single integer — the minimum possible valid width of the road.
Demo Input:
['3 7\n4 5 14\n', '6 1\n1 1 1 1 1 1\n', '6 5\n7 6 8 9 10 5\n']
Demo Output:
['4\n', '6\n', '11\n']
Note:
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
|
```python
inpa = input().split(' ')
inpb = input().split(' ')
counter = 0
for x in inpb:
if int(x) > int(inpa[1]):
counter += 2
else:
counter += 1
print(counter)
```
| 3
|
|
366
|
A
|
Dima and Guards
|
PROGRAMMING
| 1,100
|
[
"implementation"
] | null | null |
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly *n* rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
|
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
|
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
|
[
"10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9\n",
"10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8\n",
"5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3\n"
] |
[
"1 5 5\n",
"3 4 6\n",
"-1\n"
] |
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
| 500
|
[
{
"input": "10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9",
"output": "1 5 5"
},
{
"input": "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8",
"output": "3 4 6"
},
{
"input": "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3",
"output": "-1"
},
{
"input": "100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000",
"output": "-1"
},
{
"input": "5\n3 2 3 3\n3 2 3 3\n4 4 4 4\n4 4 1 1",
"output": "1 2 3"
},
{
"input": "100\n1 1 2 2\n100 100 2 2\n99 99 2 2\n2 2 99 99",
"output": "1 1 99"
},
{
"input": "1000\n500 500 550 550\n450 450 500 500\n999 1 1 999\n1 999 1 999",
"output": "3 1 999"
},
{
"input": "50\n30 30 30 30\n20 20 40 40\n10 10 50 50\n1 1 50 55",
"output": "-1"
},
{
"input": "10000\n1000 7000 8000 6000\n8000 8000 6000 6000\n5000 6000 6000 6000\n10000 10000 2 3",
"output": "1 1000 9000"
},
{
"input": "40000\n25000 25000 30000 30000\n1 1 1 1\n30000 20000 30000 30000\n40000 40000 40000 50000",
"output": "2 1 39999"
},
{
"input": "4\n2 1 4 4\n4 4 1 1\n3 1 2 2\n4 4 4 4",
"output": "3 1 3"
},
{
"input": "50\n5 5 5 5\n5 5 5 5\n5 5 5 5\n5 5 5 5",
"output": "1 5 45"
},
{
"input": "10\n7 2 3 20\n20 20 20 20\n20 20 20 20\n7 2 3 20",
"output": "1 2 8"
},
{
"input": "10\n8 2 7 8\n20 20 20 20\n20 20 20 20\n8 2 7 8",
"output": "1 2 8"
},
{
"input": "100000\n50000 50000 50000 50000\n50000 50000 50000 50000\n50000 50000 50000 50000\n50000 50000 50000 50000",
"output": "1 50000 50000"
},
{
"input": "100000\n25000 75000 80000 80000\n99999 99999 2 2\n99999 2 99999 99999\n2 99999 99999 99999",
"output": "-1"
},
{
"input": "1231\n123 132 85 78\n123 5743 139 27\n4598 347 12438 12\n34589 2349 123 123",
"output": "2 123 1108"
},
{
"input": "6\n2 6 2 9\n4 8 5 1\n5 6 4 3\n1 2 5 1",
"output": "4 1 5"
},
{
"input": "8\n5 5 3 3\n1 1 8 8\n2 8 8 7\n10 7 2 2",
"output": "1 5 3"
},
{
"input": "100000\n25000 50000 50001 75001\n25000 50000 50001 75001\n25000 50000 50001 75001\n25000 50000 50001 75001",
"output": "1 25000 75000"
},
{
"input": "100000\n25000 50000 75001 50001\n25000 50000 75001 50001\n25000 50000 75001 50001\n25000 50000 75001 50001",
"output": "1 25000 75000"
},
{
"input": "5\n3 7 6 2\n100 100 100 100\n100 100 100 100\n100 100 100 100",
"output": "1 3 2"
},
{
"input": "10\n1 100 100 1\n1 100 100 1\n1 100 100 1\n1 100 100 1",
"output": "1 1 9"
},
{
"input": "10\n7 5 5 7\n10 10 10 10\n10 10 10 10\n10 10 10 10",
"output": "1 5 5"
},
{
"input": "10\n9 9 9 9\n9 9 9 9\n9 9 9 9\n1 1 1 1",
"output": "4 1 9"
},
{
"input": "10\n8 6 5 3\n8 6 5 3\n8 6 5 3\n8 6 5 3",
"output": "1 6 4"
},
{
"input": "10\n9 9 9 9\n9 9 9 9\n9 9 9 9\n9 4 9 6",
"output": "4 4 6"
},
{
"input": "10\n6 6 4 4\n6 6 4 4\n6 6 4 4\n6 6 4 4",
"output": "1 6 4"
},
{
"input": "100000\n99000 100000 999 100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000",
"output": "1 99000 1000"
}
] | 1,589,740,885
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 29
| 109
| 6,656,000
|
n=int(input())
for i in range(4):
a,b,c,d=map(int,input().split())
a=min(a,b)
c=min(c,d)
if a+c<=n:
print(i+1,a,n-a)
break
else: print(-1)
|
Title: Dima and Guards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly *n* rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output Specification:
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Demo Input:
['10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9\n', '10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8\n', '5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3\n']
Demo Output:
['1 5 5\n', '3 4 6\n', '-1\n']
Note:
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
|
```python
n=int(input())
for i in range(4):
a,b,c,d=map(int,input().split())
a=min(a,b)
c=min(c,d)
if a+c<=n:
print(i+1,a,n-a)
break
else: print(-1)
```
| 3
|
|
389
|
A
|
Fox and Number Game
|
PROGRAMMING
| 1,000
|
[
"greedy",
"math"
] | null | null |
Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum.
|
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100).
|
Output a single integer — the required minimal sum.
|
[
"2\n1 2\n",
"3\n2 4 6\n",
"2\n12 18\n",
"5\n45 12 27 30 18\n"
] |
[
"2\n",
"6\n",
"12\n",
"15\n"
] |
In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
| 500
|
[
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 4 6",
"output": "6"
},
{
"input": "2\n12 18",
"output": "12"
},
{
"input": "5\n45 12 27 30 18",
"output": "15"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n100 100",
"output": "200"
},
{
"input": "2\n87 58",
"output": "58"
},
{
"input": "39\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52",
"output": "2028"
},
{
"input": "59\n96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96",
"output": "5664"
},
{
"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": "10000"
},
{
"input": "100\n70 70 77 42 98 84 56 91 35 21 7 70 77 77 56 63 14 84 56 14 77 77 63 70 14 7 28 91 63 49 21 84 98 56 77 98 98 84 98 14 7 56 49 28 91 98 7 56 14 91 14 98 49 28 98 14 98 98 14 70 35 28 63 28 49 63 63 56 91 98 35 42 42 35 63 35 42 14 63 21 77 56 42 77 35 91 56 21 28 84 56 70 70 91 98 70 84 63 21 98",
"output": "700"
},
{
"input": "39\n63 21 21 42 21 63 21 84 42 21 84 63 42 63 84 84 84 42 42 84 21 63 42 63 42 42 63 42 42 63 84 42 21 84 21 63 42 21 42",
"output": "819"
},
{
"input": "59\n70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70",
"output": "4130"
},
{
"input": "87\n44 88 88 88 88 66 88 22 22 88 88 44 88 22 22 22 88 88 88 88 66 22 88 88 88 88 66 66 44 88 44 44 66 22 88 88 22 44 66 44 88 66 66 22 22 22 22 88 22 22 44 66 88 22 22 88 66 66 88 22 66 88 66 88 66 44 88 44 22 44 44 22 44 88 44 44 44 44 22 88 88 88 66 66 88 44 22",
"output": "1914"
},
{
"input": "15\n63 63 63 63 63 63 63 63 63 63 63 63 63 63 63",
"output": "945"
},
{
"input": "39\n63 77 21 14 14 35 21 21 70 42 21 70 28 77 28 77 7 42 63 7 98 49 98 84 35 70 70 91 14 42 98 7 42 7 98 42 56 35 91",
"output": "273"
},
{
"input": "18\n18 18 18 36 36 36 54 72 54 36 72 54 36 36 36 36 18 36",
"output": "324"
},
{
"input": "46\n71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71",
"output": "3266"
},
{
"input": "70\n66 11 66 11 44 11 44 99 55 22 88 11 11 22 55 44 22 77 44 77 77 22 44 55 88 11 99 99 88 22 77 77 66 11 11 66 99 55 55 44 66 44 77 44 44 55 33 55 44 88 77 77 22 66 33 44 11 22 55 44 22 66 77 33 33 44 44 44 22 33",
"output": "770"
},
{
"input": "10\n60 12 96 48 60 24 60 36 60 60",
"output": "120"
},
{
"input": "20\n51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51",
"output": "1020"
},
{
"input": "50\n58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58",
"output": "2900"
},
{
"input": "98\n70 60 100 30 70 20 30 50 50 30 90 40 30 40 60 80 60 60 80 50 10 80 20 10 20 10 50 70 30 80 30 50 60 90 90 100 60 30 90 20 30 60 90 80 60 60 10 90 10 50 40 40 80 90 100 40 70 40 30 50 60 50 60 30 40 20 90 60 20 20 20 70 60 70 50 100 90 50 20 40 80 60 10 60 50 40 40 10 50 10 40 10 80 100 100 90 10 90",
"output": "980"
},
{
"input": "100\n82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82",
"output": "8200"
},
{
"input": "100\n11 87 77 93 3 54 21 93 9 71 37 23 69 85 74 3 48 99 51 31 56 19 21 96 39 6 4 4 29 69 100 42 1 22 81 53 48 49 81 61 10 7 40 61 7 71 51 59 79 44 50 35 95 80 83 8 98 40 18 94 84 49 52 74 66 69 39 37 100 44 38 62 2 80 46 31 35 53 5 60 21 49 63 55 20 53 80 53 66 34 23 92 77 50 86 63 65 24 12 70",
"output": "100"
},
{
"input": "2\n100 1",
"output": "2"
},
{
"input": "2\n18 30",
"output": "12"
},
{
"input": "2\n3 5",
"output": "2"
},
{
"input": "2\n1 10",
"output": "2"
},
{
"input": "2\n8 5",
"output": "2"
},
{
"input": "5\n2 3 5 8 18",
"output": "5"
},
{
"input": "5\n2 4 1 6 8",
"output": "5"
},
{
"input": "3\n12 10 5",
"output": "3"
},
{
"input": "3\n6 10 15",
"output": "3"
}
] | 1,573,004,935
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 4
| 109
| 0
|
n=int(input())
a=list(map(int,input().split()))
a.sort()
i=n-1
while i>0:
a[i]=a[i]-a[i-1]
i=i-1
x=min(a)
print(x*n)
|
Title: Fox and Number Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100).
Output Specification:
Output a single integer — the required minimal sum.
Demo Input:
['2\n1 2\n', '3\n2 4 6\n', '2\n12 18\n', '5\n45 12 27 30 18\n']
Demo Output:
['2\n', '6\n', '12\n', '15\n']
Note:
In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
|
```python
n=int(input())
a=list(map(int,input().split()))
a.sort()
i=n-1
while i>0:
a[i]=a[i]-a[i-1]
i=i-1
x=min(a)
print(x*n)
```
| 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,637,120,237
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 60
| 512,000
|
n=int(input())
l=list(map(int,input().split()))
for i in range(2,len(l)):
if l[i-2]%2==0 and l[i-1]%2==0 and l[i]%2==1:
print(i)
break
if l[i-2]%2==1 and l[i-1]%2==0 and l[i]%2==0:
print(i-2)
break
if l[i-2]%2==0 and l[i-1]%2==1 and l[i]%2==0:
print(i-1)
break
if l[i-2]%2==0 and l[i-1]%2==1 and l[i]%2==1:
print(i-2)
break
if l[i-2]%2==1 and l[i-1]%2==0 and l[i]%2==1:
print(i-1)
break
if l[i-2]%2==1 and l[i-1]%2==1 and l[i]%2==0:
print(i)
break
|
Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none
|
```python
n=int(input())
l=list(map(int,input().split()))
for i in range(2,len(l)):
if l[i-2]%2==0 and l[i-1]%2==0 and l[i]%2==1:
print(i)
break
if l[i-2]%2==1 and l[i-1]%2==0 and l[i]%2==0:
print(i-2)
break
if l[i-2]%2==0 and l[i-1]%2==1 and l[i]%2==0:
print(i-1)
break
if l[i-2]%2==0 and l[i-1]%2==1 and l[i]%2==1:
print(i-2)
break
if l[i-2]%2==1 and l[i-1]%2==0 and l[i]%2==1:
print(i-1)
break
if l[i-2]%2==1 and l[i-1]%2==1 and l[i]%2==0:
print(i)
break
```
| 0
|
538
|
A
|
Cutting Banner
|
PROGRAMMING
| 1,400
|
[
"brute force",
"implementation"
] | null | null |
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.
There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.
Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.
|
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
|
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
|
[
"CODEWAITFORITFORCES\n",
"BOTTOMCODER\n",
"DECODEFORCES\n",
"DOGEFORCES\n"
] |
[
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "CODEWAITFORITFORCES",
"output": "YES"
},
{
"input": "BOTTOMCODER",
"output": "NO"
},
{
"input": "DECODEFORCES",
"output": "YES"
},
{
"input": "DOGEFORCES",
"output": "NO"
},
{
"input": "ABACABA",
"output": "NO"
},
{
"input": "CODEFORCE",
"output": "NO"
},
{
"input": "C",
"output": "NO"
},
{
"input": "NQTSMZEBLY",
"output": "NO"
},
{
"input": "CODEFZORCES",
"output": "YES"
},
{
"input": "EDYKHVZCNTLJUUOQGHPTIOETQNFLLWEKZOHIUAXELGECABVSBIBGQODQXVYFKBYJWTGBYHVSSNTINKWSINWSMALUSIWNJMTCOOVF",
"output": "NO"
},
{
"input": "OCECFDSRDE",
"output": "NO"
},
{
"input": "MDBUWCZFFZKFMJTTJFXRHTGRPREORKDVUXOEMFYSOMSQGHUKGYCRCVJTNDLFDEWFS",
"output": "NO"
},
{
"input": "CODEFYTORCHES",
"output": "NO"
},
{
"input": "BCODEFORCES",
"output": "YES"
},
{
"input": "CVODEFORCES",
"output": "YES"
},
{
"input": "COAKDEFORCES",
"output": "YES"
},
{
"input": "CODFMWEFORCES",
"output": "YES"
},
{
"input": "CODEVCSYRFORCES",
"output": "YES"
},
{
"input": "CODEFXHHPWCVQORCES",
"output": "YES"
},
{
"input": "CODEFORQWUFJLOFFXTXRCES",
"output": "YES"
},
{
"input": "CODEFORBWFURYIDURNRKRDLHCLXZCES",
"output": "YES"
},
{
"input": "CODEFORCQSYSLYKCDFFUPSAZCJIAENCKZUFJZEINQIES",
"output": "YES"
},
{
"input": "CODEFORCEVENMDBQLSVPQIIBGSHBVOPYZXNWVSTVWDRONUREYJJIJIPMEBPQDCPFS",
"output": "YES"
},
{
"input": "CODEFORCESCFNNPAHNHDIPPBAUSPKJYAQDBVZNLSTSDCREZACVLMRFGVKGVHHZLXOHCTJDBQKIDWBUXDUJARLWGFGFCTTXUCAZB",
"output": "YES"
},
{
"input": "CODJRDPDEFOROES",
"output": "NO"
},
{
"input": "CODEFOGSIUZMZCMWAVQHNYFEKIEZQMAZOVEMDRMOEDBHAXPLBLDYYXCVTOOSJZVSQAKFXTBTZFWAYRZEMDEMVDJTDRXXAQBURCES",
"output": "YES"
},
{
"input": "CODEMKUYHAZSGJBQLXTHUCZZRJJJXUSEBOCNZASOKDZHMSGWZSDFBGHXFLABVPDQBJYXSHHAZAKHSTRGOKJYHRVSSUGDCMFOGCES",
"output": "NO"
},
{
"input": "CODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCES",
"output": "YES"
},
{
"input": "CCODEFORCESODECODEFORCCODEFORCESODCODEFORCESEFCODEFORCESORCODEFORCESCESCESFORCODEFORCESCES",
"output": "NO"
},
{
"input": "CCODEFORCESC",
"output": "NO"
},
{
"input": "CODEAFORBCES",
"output": "NO"
},
{
"input": "CODERRRRRFORCRRRRES",
"output": "NO"
},
{
"input": "CODELFORCELS",
"output": "NO"
},
{
"input": "CPOPDPEPFPOPRPCPEPS",
"output": "NO"
},
{
"input": "COXDEXFORXCEXS",
"output": "NO"
},
{
"input": "CODAAAAAFORCES",
"output": "NO"
},
{
"input": "CAOADEFORCES",
"output": "NO"
},
{
"input": "FORCESXCODE",
"output": "NO"
},
{
"input": "FORCESACODE",
"output": "NO"
},
{
"input": "ACAOADAEFORCES",
"output": "NO"
},
{
"input": "CCODEFORCESS",
"output": "NO"
},
{
"input": "ZCODEFORCEZ",
"output": "NO"
},
{
"input": "CODXEFORXCES",
"output": "NO"
},
{
"input": "CODEFORCEZ",
"output": "NO"
},
{
"input": "CODEFORCEST",
"output": "YES"
},
{
"input": "AXODEFORCES",
"output": "NO"
},
{
"input": "RCODEFORCESR",
"output": "NO"
},
{
"input": "CODECODEFORCESFORCES",
"output": "YES"
},
{
"input": "TTTWWWCODEFORCES",
"output": "YES"
},
{
"input": "CODEFORRCEST",
"output": "NO"
},
{
"input": "UJYTYUCODEFORCES",
"output": "YES"
},
{
"input": "CODEXXXXXXXXXXXXXXXXXXCODEFORCESXXXXXXXXXXXXXXXXXXXXXFORCES",
"output": "YES"
},
{
"input": "COXEDYFORCES",
"output": "NO"
},
{
"input": "UJYTYCODEFORCES",
"output": "YES"
},
{
"input": "UJYTCODEFORCES",
"output": "YES"
}
] | 1,621,503,927
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 11
| 93
| 0
|
s1=input()
s2='CODEFORCES'
n1,n2=len(s1),len(s2)
i,j = 0,0
while i<n1 and j<n2:
if s1[i]==s2[j]:
j+=1
i+=1
if j==n2:
print('YES')
else:
print('NO')
|
Title: Cutting Banner
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.
There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.
Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.
Input Specification:
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
Output Specification:
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
Demo Input:
['CODEWAITFORITFORCES\n', 'BOTTOMCODER\n', 'DECODEFORCES\n', 'DOGEFORCES\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'NO\n']
Note:
none
|
```python
s1=input()
s2='CODEFORCES'
n1,n2=len(s1),len(s2)
i,j = 0,0
while i<n1 and j<n2:
if s1[i]==s2[j]:
j+=1
i+=1
if j==n2:
print('YES')
else:
print('NO')
```
| 0
|
|
437
|
A
|
The Child and Homework
|
PROGRAMMING
| 1,300
|
[
"implementation"
] | null | null |
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
- If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child's choose?
|
The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".
|
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
|
[
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] |
[
"D\n",
"C\n",
"B\n"
] |
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B.
| 500
|
[
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
{
"input": "A.He_nan_de_yang_guang_zhao_yao_zhe_wo_men_mei_guo_ren_lian_shang_dou_xiao_kai_yan_wahaaaaaaaaaaaaaaaa\nB.Li_bai_li_bai_fei_liu_zhi_xia_san_qian_chi_yi_si_yin_he_luo_jiu_tian_li_bai_li_bai_li_bai_li_bai_shi\nC.Peng_yu_xiang_shi_zai_tai_shen_le_jian_zhi_jiu_shi_ye_jie_du_liu_a_si_mi_da_zhen_shi_tai_shen_le_a_a\nD.Wo_huo_le_si_shi_er_nian_zhen_de_shi_cong_lai_ye_mei_you_jian_guo_zhe_me_biao_zhun_de_yi_bai_ge_zi_a",
"output": "C"
},
{
"input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____",
"output": "C"
},
{
"input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_",
"output": "D"
},
{
"input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____",
"output": "C"
},
{
"input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_",
"output": "D"
},
{
"input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h",
"output": "A"
},
{
"input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_",
"output": "C"
},
{
"input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg",
"output": "B"
},
{
"input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___",
"output": "D"
},
{
"input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS",
"output": "C"
},
{
"input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_",
"output": "C"
},
{
"input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi",
"output": "C"
},
{
"input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__",
"output": "C"
},
{
"input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h",
"output": "A"
},
{
"input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_",
"output": "C"
},
{
"input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg",
"output": "B"
},
{
"input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___",
"output": "D"
},
{
"input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS",
"output": "C"
},
{
"input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_",
"output": "C"
},
{
"input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi",
"output": "C"
},
{
"input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__",
"output": "C"
},
{
"input": "A.aaaaaa\nB.aaa\nC.aaa\nD.aaa",
"output": "A"
},
{
"input": "A.aaa\nB.aaaaaa\nC.aaaaaa\nD.aaaaaa",
"output": "A"
},
{
"input": "A.a\nB.b\nC.c\nD.d",
"output": "C"
},
{
"input": "A._\nB.__\nC.____\nD.________",
"output": "C"
},
{
"input": "A.____\nB.________\nC.________\nD._______",
"output": "C"
},
{
"input": "A.h\nB.asdf\nC.asqw\nD.qwertasdfg",
"output": "C"
},
{
"input": "A.aa\nB.aaaaa\nC.aaaaaa\nD.aaaaaaaaaaaaa",
"output": "C"
},
{
"input": "A.ccc\nB.ccccccc\nC.ccc\nD.c",
"output": "C"
},
{
"input": "A.c\nB.ccc\nC.cccccccccccccccccc\nD.cccccc",
"output": "C"
},
{
"input": "A.aa\nB.bb\nC.cc\nD.ddd",
"output": "C"
},
{
"input": "A.QW\nB.WERT\nC.QWER\nD.QWERTYUI",
"output": "C"
}
] | 1,595,488,935
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 35
| 109
| 6,656,000
|
arr = sorted([(len(input())-2,i) for i in 'ABCD'])
p=0
if 2 * arr[0][0] <= arr[1][0]:
p+=1
if 2 * arr[-2][0] <= arr[-1][0]:
p+=2
print(['C',arr[0][1],arr[-1][1],'C'][p])
|
Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
- If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child's choose?
Input Specification:
The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".
Output Specification:
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
Demo Input:
['A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n', 'A.ab\nB.abcde\nC.ab\nD.abc\n', 'A.c\nB.cc\nC.c\nD.c\n']
Demo Output:
['D\n', 'C\n', 'B\n']
Note:
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B.
|
```python
arr = sorted([(len(input())-2,i) for i in 'ABCD'])
p=0
if 2 * arr[0][0] <= arr[1][0]:
p+=1
if 2 * arr[-2][0] <= arr[-1][0]:
p+=2
print(['C',arr[0][1],arr[-1][1],'C'][p])
```
| 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,586,288,805
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 93
| 307,200
|
n=int(input())
a=list(map(int,input().split()))
temp=[0]*(n+1)
block=[]
for i in range(n):
temp[a[i]]=1
coup=1
for j in range(a[i]+1,n+1):
if temp[j]!=1:
coup=0
break
if coup==1:
block.append(a[i])
block.sort(reverse=True)
print(*block)
block=[]
else:
block.append(a[i])
print("")
|
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
n=int(input())
a=list(map(int,input().split()))
temp=[0]*(n+1)
block=[]
for i in range(n):
temp[a[i]]=1
coup=1
for j in range(a[i]+1,n+1):
if temp[j]!=1:
coup=0
break
if coup==1:
block.append(a[i])
block.sort(reverse=True)
print(*block)
block=[]
else:
block.append(a[i])
print("")
```
| 0
|
|
558
|
A
|
Lala Land and Apple Trees
|
PROGRAMMING
| 1,100
|
[
"brute force",
"implementation",
"sortings"
] | null | null |
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
|
The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
|
Output the maximum number of apples Amr can collect.
|
[
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] |
[
"10",
"9",
"9"
] |
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* = - 2.
In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
| 500
|
[
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "300000"
},
{
"input": "1\n-1 1",
"output": "1"
},
{
"input": "27\n-30721 24576\n-6620 92252\n88986 24715\n-94356 10509\n-6543 29234\n-68554 69530\n39176 96911\n67266 99669\n95905 51002\n-94093 92134\n65382 23947\n-6525 79426\n-448 67531\n-70083 26921\n-86333 50029\n48924 8036\n-27228 5349\n6022 10691\n-13840 56735\n50398 58794\n-63258 45557\n-27792 77057\n98295 1203\n-51294 18757\n35037 61941\n-30112 13076\n82334 20463",
"output": "1036452"
},
{
"input": "18\n-18697 44186\n56333 51938\n-75688 49735\n77762 14039\n-43996 81060\n69700 49107\n74532 45568\n-94476 203\n-92347 90745\n58921 44650\n57563 63561\n44630 8486\n35750 5999\n3249 34202\n75358 68110\n-33245 60458\n-88148 2342\n87856 85532",
"output": "632240"
},
{
"input": "28\n49728 91049\n-42863 4175\n-89214 22191\n77977 16965\n-42960 87627\n-84329 97494\n89270 75906\n-13695 28908\n-72279 13607\n-97327 87062\n-58682 32094\n39108 99936\n29304 93784\n-63886 48237\n-77359 57648\n-87013 79017\n-41086 35033\n-60613 83555\n-48955 56816\n-20568 26802\n52113 25160\n-88885 45294\n22601 42971\n62693 65662\n-15985 5357\n86671 8522\n-59921 11271\n-79304 25044",
"output": "891593"
},
{
"input": "25\n5704 67795\n6766 31836\n-41715 89987\n76854 9848\n11648 90020\n-79763 10107\n96971 92636\n-64205 71937\n87997 38273\n-9782 57187\n22186 6905\n-41130 40258\n-28403 66579\n19578 43375\n35735 52929\n-52417 89388\n-89430 1939\n9401 43491\n-11228 10112\n-86859 16024\n-51486 33467\n-80578 65080\n-52820 98445\n-89165 7657\n-97106 79422",
"output": "1109655"
},
{
"input": "16\n-41732 47681\n44295 28942\n-75194 99827\n69982 18020\n-75378 22026\n80032 22908\n-34879 41113\n36257 48574\n-35882 84333\n29646 71151\n-86214 80886\n72724 39364\n-42529 60880\n29150 29921\n-8471 80781\n79387 70834",
"output": "847241"
},
{
"input": "3\n-94146 4473\n28707 99079\n-4153 8857",
"output": "112409"
},
{
"input": "3\n-3 3\n-2 2\n-1 1",
"output": "1"
},
{
"input": "2\n100000 3\n-100000 9",
"output": "12"
},
{
"input": "2\n-100000 100000\n100000 99999",
"output": "199999"
}
] | 1,544,291,725
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 5
| 109
| 0
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 8 22:14:24 2018
@author: mach
"""
l= []
i = int(input())
for _ in range(i):
n,m = map(int, input().strip().split())
l.append((n,m))
l.sort(key = lambda x:x[0])
for i in range(len(l)):
if l[i][0] > 0:
g = i
break
sums = 0
r_len = len(l[g:])
l_len = len(l[:g])
if r_len > l_len:
r_j = l_len +1
l_j = l_len
elif r_len == l_len:
r_j = r_len
l_j = r_len
else:
r_j = r_len
l_j = r_len + 1
for i in range(g,g+r_j):
sums+=l[i][1]
for k in range(g-l_j,g):
sums += l[k][1]
print(sums)
|
Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input Specification:
The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output Specification:
Output the maximum number of apples Amr can collect.
Demo Input:
['2\n-1 5\n1 5\n', '3\n-2 2\n1 4\n-1 3\n', '3\n1 9\n3 5\n7 10\n']
Demo Output:
['10', '9', '9']
Note:
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* = - 2.
In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
|
```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 8 22:14:24 2018
@author: mach
"""
l= []
i = int(input())
for _ in range(i):
n,m = map(int, input().strip().split())
l.append((n,m))
l.sort(key = lambda x:x[0])
for i in range(len(l)):
if l[i][0] > 0:
g = i
break
sums = 0
r_len = len(l[g:])
l_len = len(l[:g])
if r_len > l_len:
r_j = l_len +1
l_j = l_len
elif r_len == l_len:
r_j = r_len
l_j = r_len
else:
r_j = r_len
l_j = r_len + 1
for i in range(g,g+r_j):
sums+=l[i][1]
for k in range(g-l_j,g):
sums += l[k][1]
print(sums)
```
| -1
|
|
2
|
A
|
Winner
|
PROGRAMMING
| 1,500
|
[
"hashing",
"implementation"
] |
A. Winner
|
1
|
64
|
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
|
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
|
Print the name of the winner.
|
[
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] |
[
"andrew\n",
"andrew\n"
] |
none
| 0
|
[
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},
{
"input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734",
"output": "ksjuuerbnlklcfdjeyq"
},
{
"input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879",
"output": "fcgslzkicjrpbqaifgweyzreajjfdo"
},
{
"input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735",
"output": "aawtvezfntstrcpgbzjbf"
},
{
"input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158",
"output": "ivhgbxiv"
}
] | 1,606,211,038
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 8
| 746
| 5,939,200
|
# hashing,implementation
# https://codeforces.com/problemset/problem/2/A
# A. Winner
import sys
from typing import Dict
numInputs: int = int(sys.stdin.readline())
scoreMap: Dict[str, int] = {}
highScore: int = 0
highScoreName: str = ""
for _i in range(numInputs):
name, score = sys.stdin.readline().split()
score = int(score)
if name in scoreMap:
scoreMap[name] += score
else:
scoreMap[name] = score
if scoreMap[name] > highScore:
highScore = scoreMap[name]
highScoreName = name
checkHighScore = 0
checkHighScoreName = ""
for name, score in scoreMap.items():
if score > checkHighScore:
checkHighScore = score
checkHighScoreName = name
if checkHighScore == highScore:
print(highScoreName)
else:
print(checkHighScoreName)
|
Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
Input Specification:
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Output Specification:
Print the name of the winner.
Demo Input:
['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n']
Demo Output:
['andrew\n', 'andrew\n']
Note:
none
|
```python
# hashing,implementation
# https://codeforces.com/problemset/problem/2/A
# A. Winner
import sys
from typing import Dict
numInputs: int = int(sys.stdin.readline())
scoreMap: Dict[str, int] = {}
highScore: int = 0
highScoreName: str = ""
for _i in range(numInputs):
name, score = sys.stdin.readline().split()
score = int(score)
if name in scoreMap:
scoreMap[name] += score
else:
scoreMap[name] = score
if scoreMap[name] > highScore:
highScore = scoreMap[name]
highScoreName = name
checkHighScore = 0
checkHighScoreName = ""
for name, score in scoreMap.items():
if score > checkHighScore:
checkHighScore = score
checkHighScoreName = name
if checkHighScore == highScore:
print(highScoreName)
else:
print(checkHighScoreName)
```
| 0
|
633
|
B
|
A Trivial Problem
|
PROGRAMMING
| 1,300
|
[
"brute force",
"constructive algorithms",
"math",
"number theory"
] | null | null |
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem?
|
The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial.
|
First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order.
|
[
"1\n",
"5\n"
] |
[
"5\n5 6 7 8 9 ",
"0"
] |
The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1·2·3·...·*n*.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
| 500
|
[
{
"input": "1",
"output": "5\n5 6 7 8 9 "
},
{
"input": "5",
"output": "0"
},
{
"input": "2",
"output": "5\n10 11 12 13 14 "
},
{
"input": "3",
"output": "5\n15 16 17 18 19 "
},
{
"input": "7",
"output": "5\n30 31 32 33 34 "
},
{
"input": "12",
"output": "5\n50 51 52 53 54 "
},
{
"input": "15",
"output": "5\n65 66 67 68 69 "
},
{
"input": "18",
"output": "5\n75 76 77 78 79 "
},
{
"input": "38",
"output": "5\n155 156 157 158 159 "
},
{
"input": "47",
"output": "5\n195 196 197 198 199 "
},
{
"input": "58",
"output": "5\n240 241 242 243 244 "
},
{
"input": "66",
"output": "5\n270 271 272 273 274 "
},
{
"input": "70",
"output": "5\n285 286 287 288 289 "
},
{
"input": "89",
"output": "5\n365 366 367 368 369 "
},
{
"input": "417",
"output": "5\n1675 1676 1677 1678 1679 "
},
{
"input": "815",
"output": "5\n3265 3266 3267 3268 3269 "
},
{
"input": "394",
"output": "5\n1585 1586 1587 1588 1589 "
},
{
"input": "798",
"output": "0"
},
{
"input": "507",
"output": "5\n2035 2036 2037 2038 2039 "
},
{
"input": "406",
"output": "5\n1630 1631 1632 1633 1634 "
},
{
"input": "570",
"output": "5\n2290 2291 2292 2293 2294 "
},
{
"input": "185",
"output": "0"
},
{
"input": "765",
"output": "0"
},
{
"input": "967",
"output": "0"
},
{
"input": "112",
"output": "5\n455 456 457 458 459 "
},
{
"input": "729",
"output": "5\n2925 2926 2927 2928 2929 "
},
{
"input": "4604",
"output": "5\n18425 18426 18427 18428 18429 "
},
{
"input": "8783",
"output": "5\n35140 35141 35142 35143 35144 "
},
{
"input": "1059",
"output": "0"
},
{
"input": "6641",
"output": "5\n26575 26576 26577 26578 26579 "
},
{
"input": "9353",
"output": "5\n37425 37426 37427 37428 37429 "
},
{
"input": "1811",
"output": "5\n7250 7251 7252 7253 7254 "
},
{
"input": "2528",
"output": "0"
},
{
"input": "8158",
"output": "5\n32640 32641 32642 32643 32644 "
},
{
"input": "3014",
"output": "5\n12070 12071 12072 12073 12074 "
},
{
"input": "7657",
"output": "5\n30640 30641 30642 30643 30644 "
},
{
"input": "4934",
"output": "0"
},
{
"input": "9282",
"output": "5\n37140 37141 37142 37143 37144 "
},
{
"input": "2610",
"output": "5\n10450 10451 10452 10453 10454 "
},
{
"input": "2083",
"output": "5\n8345 8346 8347 8348 8349 "
},
{
"input": "26151",
"output": "5\n104620 104621 104622 104623 104624 "
},
{
"input": "64656",
"output": "5\n258640 258641 258642 258643 258644 "
},
{
"input": "46668",
"output": "5\n186690 186691 186692 186693 186694 "
},
{
"input": "95554",
"output": "5\n382235 382236 382237 382238 382239 "
},
{
"input": "37320",
"output": "0"
},
{
"input": "52032",
"output": "5\n208140 208141 208142 208143 208144 "
},
{
"input": "11024",
"output": "5\n44110 44111 44112 44113 44114 "
},
{
"input": "63218",
"output": "5\n252885 252886 252887 252888 252889 "
},
{
"input": "40095",
"output": "5\n160390 160391 160392 160393 160394 "
},
{
"input": "42724",
"output": "5\n170910 170911 170912 170913 170914 "
},
{
"input": "24381",
"output": "5\n97530 97531 97532 97533 97534 "
},
{
"input": "73138",
"output": "5\n292570 292571 292572 292573 292574 "
},
{
"input": "93346",
"output": "5\n373400 373401 373402 373403 373404 "
},
{
"input": "18338",
"output": "5\n73370 73371 73372 73373 73374 "
},
{
"input": "42662",
"output": "5\n170660 170661 170662 170663 170664 "
},
{
"input": "81221",
"output": "5\n324900 324901 324902 324903 324904 "
},
{
"input": "100000",
"output": "5\n400005 400006 400007 400008 400009 "
},
{
"input": "100000",
"output": "5\n400005 400006 400007 400008 400009 "
},
{
"input": "99998",
"output": "0"
},
{
"input": "30",
"output": "0"
},
{
"input": "11",
"output": "0"
},
{
"input": "780",
"output": "0"
},
{
"input": "97656",
"output": "5\n390625 390626 390627 390628 390629 "
},
{
"input": "12499",
"output": "5\n50000 50001 50002 50003 50004 "
},
{
"input": "65",
"output": "5\n265 266 267 268 269 "
},
{
"input": "41",
"output": "5\n170 171 172 173 174 "
},
{
"input": "31",
"output": "5\n125 126 127 128 129 "
},
{
"input": "86577",
"output": "0"
}
] | 1,461,004,996
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 8
| 327
| 27,136,000
|
#import time
n = int(input())
#start = time.time()
some_dict = {0: [0,1,2,3,4]}
for i in range(1, 5):
some_dict[i] = list(map(lambda x: x + 5, some_dict[i-1]))
#print(some_dict)
count = 1
elements = 1
misses = 6
j = 0
for i in range(5, 100001):
j += 1
#print( 'i:', i, 'misses:', misses, 'j:', j)
if misses == 1 and j == 1:
some_dict[i] = [0]
continue
if misses == 5 and j == 7:
some_dict[i] = list(map(lambda x: x + 5, some_dict[i-1]))
misses = 1
j = 0
continue
if misses == 6:
#print('misses: ', i)
some_dict[i] = [0]
misses = 1
j = 1
continue
if j == 7:
#print(i, misses)
misses += 1
j = 1
some_dict[i] = [0]
continue
if some_dict[i-1] == [0]:
some_dict[i] = list(map(lambda x: x + 5, some_dict[i-2]))
else:
some_dict[i] = list(map(lambda x: x + 5, some_dict[i-1]))
#print(some_dict, misses, j)
#print(some_dict)
#end = time.time()
if some_dict[n] == [0]:
print(0)
else:
print(len(some_dict[n]))
print(' '.join(list(map(str, some_dict[n]))))
|
Title: A Trivial Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem?
Input Specification:
The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial.
Output Specification:
First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order.
Demo Input:
['1\n', '5\n']
Demo Output:
['5\n5 6 7 8 9 ', '0']
Note:
The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1·2·3·...·*n*.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
|
```python
#import time
n = int(input())
#start = time.time()
some_dict = {0: [0,1,2,3,4]}
for i in range(1, 5):
some_dict[i] = list(map(lambda x: x + 5, some_dict[i-1]))
#print(some_dict)
count = 1
elements = 1
misses = 6
j = 0
for i in range(5, 100001):
j += 1
#print( 'i:', i, 'misses:', misses, 'j:', j)
if misses == 1 and j == 1:
some_dict[i] = [0]
continue
if misses == 5 and j == 7:
some_dict[i] = list(map(lambda x: x + 5, some_dict[i-1]))
misses = 1
j = 0
continue
if misses == 6:
#print('misses: ', i)
some_dict[i] = [0]
misses = 1
j = 1
continue
if j == 7:
#print(i, misses)
misses += 1
j = 1
some_dict[i] = [0]
continue
if some_dict[i-1] == [0]:
some_dict[i] = list(map(lambda x: x + 5, some_dict[i-2]))
else:
some_dict[i] = list(map(lambda x: x + 5, some_dict[i-1]))
#print(some_dict, misses, j)
#print(some_dict)
#end = time.time()
if some_dict[n] == [0]:
print(0)
else:
print(len(some_dict[n]))
print(' '.join(list(map(str, some_dict[n]))))
```
| 0
|
|
58
|
A
|
Chat room
|
PROGRAMMING
| 1,000
|
[
"greedy",
"strings"
] |
A. Chat room
|
1
|
256
|
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
|
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
|
If Vasya managed to say hello, print "YES", otherwise print "NO".
|
[
"ahhellllloou\n",
"hlelo\n"
] |
[
"YES\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,580,302,676
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 40
| 155
| 1,024,000
|
import re
s=str(input())
if re.search("h.*e.*l.*l.*o", s):
print("YES")
else:
print("NO")
|
Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none
|
```python
import re
s=str(input())
if re.search("h.*e.*l.*l.*o", s):
print("YES")
else:
print("NO")
```
| 3.920593
|
23
|
B
|
Party
|
PROGRAMMING
| 1,600
|
[
"constructive algorithms",
"graphs",
"math"
] |
B. Party
|
2
|
256
|
*n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same.
What is the maximum amount of people that could stay at the party in the end?
|
The first input line contains one number *t* — amount of tests (1<=≤<=*t*<=≤<=105). Each of the following *t* lines contains one integer number *n* (1<=≤<=*n*<=≤<=105).
|
For each test output in a separate line one number — the maximum amount of people that could stay in the end.
|
[
"1\n3\n"
] |
[
"1\n"
] |
none
| 0
|
[
{
"input": "1\n3",
"output": "1"
}
] | 1,666,435,472
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 60
| 0
|
# LUOGU_RID: 91028436
n=int(input())
print(0 if n==1 else n-2)
|
Title: Party
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same.
What is the maximum amount of people that could stay at the party in the end?
Input Specification:
The first input line contains one number *t* — amount of tests (1<=≤<=*t*<=≤<=105). Each of the following *t* lines contains one integer number *n* (1<=≤<=*n*<=≤<=105).
Output Specification:
For each test output in a separate line one number — the maximum amount of people that could stay in the end.
Demo Input:
['1\n3\n']
Demo Output:
['1\n']
Note:
none
|
```python
# LUOGU_RID: 91028436
n=int(input())
print(0 if n==1 else n-2)
```
| 0
|
14
|
A
|
Letter
|
PROGRAMMING
| 800
|
[
"implementation"
] |
A. Letter
|
1
|
64
|
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
|
The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square.
|
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
|
[
"6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n",
"3 3\n***\n*.*\n***\n"
] |
[
"***\n*..\n***\n*..\n***\n",
"***\n*.*\n***\n"
] |
none
| 0
|
[
{
"input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..",
"output": "***\n*..\n***\n*..\n***"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "***\n*.*\n***"
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "2 1\n*\n*",
"output": "*\n*"
},
{
"input": "5 1\n.\n*\n.\n.\n.",
"output": "*"
},
{
"input": "1 6\n*****.",
"output": "*****"
},
{
"input": "2 2\n..\n*.",
"output": "*"
},
{
"input": "8 2\n..\n..\n..\n..\n..\n*.\n..\n..",
"output": "*"
},
{
"input": "50 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.",
"output": "*\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*"
},
{
"input": "2 1\n*\n.",
"output": "*"
},
{
"input": "5 1\n*\n*\n*\n*\n*",
"output": "*\n*\n*\n*\n*"
},
{
"input": "2 2\n*.\n..",
"output": "*"
},
{
"input": "3 4\n...*\n*...\n..*.",
"output": "...*\n*...\n..*."
},
{
"input": "8 2\n**\n**\n**\n**\n**\n**\n**\n**",
"output": "**\n**\n**\n**\n**\n**\n**\n**"
},
{
"input": "50 1\n.\n*\n*\n*\n.\n.\n*\n.\n*\n*\n*\n*\n*\n*\n*\n.\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n.\n.\n.\n.\n*\n*\n.\n*\n*\n.\n.\n.\n.\n*\n*\n.\n.\n.\n.\n.\n.",
"output": "*\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*"
}
] | 1,633,622,807
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 30
| 124
| 6,963,200
|
#%%
rc=input().split()
r,c=[int(x) for x in rc]
matrix=[]
for i in range(r):
matrix.append(input())
max_i=0
max_j=0
min_i=r-1
min_j=c-1
for i in range(r):
for j in range(c):
if matrix[i][j]=='*':
if i<min_i:
min_i=i
if i>max_i:
max_i=i
if j<min_j:
min_j=j
if j>=max_j:
max_j=j
for i in range(min_i,max_i+1):
print(matrix[i][min_j:max_j+1])
# %%
|
Title: Letter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input Specification:
The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output Specification:
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Demo Input:
['6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n', '3 3\n***\n*.*\n***\n']
Demo Output:
['***\n*..\n***\n*..\n***\n', '***\n*.*\n***\n']
Note:
none
|
```python
#%%
rc=input().split()
r,c=[int(x) for x in rc]
matrix=[]
for i in range(r):
matrix.append(input())
max_i=0
max_j=0
min_i=r-1
min_j=c-1
for i in range(r):
for j in range(c):
if matrix[i][j]=='*':
if i<min_i:
min_i=i
if i>max_i:
max_i=i
if j<min_j:
min_j=j
if j>=max_j:
max_j=j
for i in range(min_i,max_i+1):
print(matrix[i][min_j:max_j+1])
# %%
```
| 3.88612
|
340
|
A
|
The Wall
|
PROGRAMMING
| 1,200
|
[
"math"
] | null | null |
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink.
After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question.
|
The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*).
|
Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink.
|
[
"2 3 6 18\n"
] |
[
"3"
] |
Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.
| 500
|
[
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5",
"output": "0"
},
{
"input": "555 777 1 1000000",
"output": "257"
},
{
"input": "1000 1000 1 32323",
"output": "32"
},
{
"input": "45 125 93451125 100000000",
"output": "5821"
},
{
"input": "101 171 1 1000000000",
"output": "57900"
},
{
"input": "165 255 69696 1000000000",
"output": "356482"
},
{
"input": "555 777 666013 1000000000",
"output": "257229"
},
{
"input": "23 46 123321 900000000",
"output": "19562537"
},
{
"input": "321 123 15 1000000",
"output": "75"
},
{
"input": "819 1000 9532 152901000",
"output": "186"
},
{
"input": "819 1000 10000 1000000",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 1000003",
"output": "500001"
},
{
"input": "1 1 1 1000000000",
"output": "1000000000"
},
{
"input": "10 15 69 195610342",
"output": "6520342"
},
{
"input": "2 1 1 1000000000",
"output": "500000000"
},
{
"input": "1000 1000 1 20",
"output": "0"
},
{
"input": "1 1 1 2000000000",
"output": "2000000000"
},
{
"input": "1 2 1 2000000000",
"output": "1000000000"
},
{
"input": "2 1 1 2000000000",
"output": "1000000000"
},
{
"input": "2 3 1 1000000000",
"output": "166666666"
},
{
"input": "2 3 1 2000000000",
"output": "333333333"
},
{
"input": "3 7 1 1000000000",
"output": "47619047"
},
{
"input": "1 1 1000000000 2000000000",
"output": "1000000001"
},
{
"input": "2 2 1 2000000000",
"output": "1000000000"
},
{
"input": "1 1 2 2000000000",
"output": "1999999999"
},
{
"input": "3 2 1 2000000000",
"output": "333333333"
},
{
"input": "1 1 2000000000 2000000000",
"output": "1"
},
{
"input": "2 3 7 7",
"output": "0"
},
{
"input": "3 3 3 7",
"output": "2"
}
] | 1,589,825,175
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 35
| 218
| 307,200
|
def editor():
import sys
sys.stdin=open("input.txt",'r')
sys.stdout=open("output.txt",'w')
def solve():
x,y,a,b=I()
import math
# hcf=math.gcd(a, b)
# lcm= a*b//hcf
# print(lcm)
# ans=(b-a)//hcf
# ans=b//hcf - (a-1)//hcf
lcm=x*y//math.gcd(x,y)
ans=b//lcm - (a-1)//lcm
print(ans)
if __name__ == "__main__":
# editor()
tc=1
# tc=int(input())
I=lambda:list(map(int,input().split()))
for t in range(tc):
solve()
|
Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink.
After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question.
Input Specification:
The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*).
Output Specification:
Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink.
Demo Input:
['2 3 6 18\n']
Demo Output:
['3']
Note:
Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.
|
```python
def editor():
import sys
sys.stdin=open("input.txt",'r')
sys.stdout=open("output.txt",'w')
def solve():
x,y,a,b=I()
import math
# hcf=math.gcd(a, b)
# lcm= a*b//hcf
# print(lcm)
# ans=(b-a)//hcf
# ans=b//hcf - (a-1)//hcf
lcm=x*y//math.gcd(x,y)
ans=b//lcm - (a-1)//lcm
print(ans)
if __name__ == "__main__":
# editor()
tc=1
# tc=int(input())
I=lambda:list(map(int,input().split()))
for t in range(tc):
solve()
```
| 3
|
|
200
|
B
|
Drinks
|
PROGRAMMING
| 800
|
[
"implementation",
"math"
] | null | null |
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink.
|
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
|
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
|
[
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] |
[
"66.666666666667\n",
"37.500000000000\n"
] |
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
| 500
|
[
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39 75",
"output": "48.142857142857"
},
{
"input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22",
"output": "11.615384615385"
},
{
"input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18",
"output": "12.761904761905"
},
{
"input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84",
"output": "69.538461538462"
},
{
"input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94",
"output": "91.551724137931"
},
{
"input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100",
"output": "99.515151515152"
},
{
"input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2",
"output": "8.147058823529"
},
{
"input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93",
"output": "91.921052631579"
},
{
"input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100",
"output": "97.019230769231"
},
{
"input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6",
"output": "50.965517241379"
},
{
"input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10",
"output": "7.505882352941"
},
{
"input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6",
"output": "10.418918918919"
},
{
"input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41",
"output": "20.928571428571"
},
{
"input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96",
"output": "49.191919191919"
},
{
"input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92",
"output": "73.484848484848"
},
{
"input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6",
"output": "7.640000000000"
},
{
"input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100",
"output": "77.660000000000"
},
{
"input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81",
"output": "91.480000000000"
},
{
"input": "1\n0",
"output": "0.000000000000"
},
{
"input": "1\n100",
"output": "100.000000000000"
},
{
"input": "1\n78",
"output": "78.000000000000"
},
{
"input": "2\n0 100",
"output": "50.000000000000"
},
{
"input": "2\n100 100",
"output": "100.000000000000"
},
{
"input": "5\n0 0 0 0 1",
"output": "0.200000000000"
},
{
"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 99",
"output": "99.990000000000"
},
{
"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 1",
"output": "0.010000000000"
},
{
"input": "5\n100 100 100 100 100",
"output": "100.000000000000"
}
] | 1,692,825,526
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 31
| 122
| 0
|
n=int(input())
sum=0
l=[]
l=list(map(int,input().split()))
for i in range(n):
sum =sum+l[i]
print(sum/n)
|
Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Output Specification:
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
Demo Input:
['3\n50 50 100\n', '4\n0 25 50 75\n']
Demo Output:
['66.666666666667\n', '37.500000000000\n']
Note:
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
|
```python
n=int(input())
sum=0
l=[]
l=list(map(int,input().split()))
for i in range(n):
sum =sum+l[i]
print(sum/n)
```
| 3
|
|
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,687,105,289
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 20
| 93
| 0
|
n = int(input())
l = []
for i in range(n):
l.append(input())
if len(l[i]) <= 10:
print(l[i])
else:
print(l[i][0] + str(len(l[i]) - 2) + l[i][-1])
|
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())
l = []
for i in range(n):
l.append(input())
if len(l[i]) <= 10:
print(l[i])
else:
print(l[i][0] + str(len(l[i]) - 2) + l[i][-1])
```
| 3.9535
|
464
|
A
|
No to Palindromes!
|
PROGRAMMING
| 1,700
|
[
"greedy",
"strings"
] | null | null |
Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more.
Paul has found a tolerable string *s* of length *n*. Help him find the lexicographically next tolerable string of the same length or else state that such string does not exist.
|
The first line contains two space-separated integers: *n* and *p* (1<=≤<=*n*<=≤<=1000; 1<=≤<=*p*<=≤<=26). The second line contains string *s*, consisting of *n* small English letters. It is guaranteed that the string is tolerable (according to the above definition).
|
If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes).
|
[
"3 3\ncba\n",
"3 4\ncba\n",
"4 4\nabcd\n"
] |
[
"NO\n",
"cbd\n",
"abda\n"
] |
String *s* is lexicographically larger (or simply larger) than string *t* with the same length, if there is number *i*, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, ..., *s*<sub class="lower-index">*i*</sub> = *t*<sub class="lower-index">*i*</sub>, *s*<sub class="lower-index">*i* + 1</sub> > *t*<sub class="lower-index">*i* + 1</sub>.
The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one.
A palindrome is a string that reads the same forward or reversed.
| 500
|
[
{
"input": "3 3\ncba",
"output": "NO"
},
{
"input": "3 4\ncba",
"output": "cbd"
},
{
"input": "4 4\nabcd",
"output": "abda"
},
{
"input": "2 2\nab",
"output": "ba"
},
{
"input": "2 2\nba",
"output": "NO"
},
{
"input": "1 2\na",
"output": "b"
},
{
"input": "1 2\nb",
"output": "NO"
},
{
"input": "1 1\na",
"output": "NO"
},
{
"input": "3 4\ncdb",
"output": "dab"
},
{
"input": "7 26\nzyxzyxz",
"output": "NO"
},
{
"input": "10 5\nabcabcabca",
"output": "abcabcabcd"
},
{
"input": "10 10\nfajegfaicb",
"output": "fajegfaicd"
},
{
"input": "1 26\no",
"output": "p"
},
{
"input": "1 2\nb",
"output": "NO"
},
{
"input": "1 26\nz",
"output": "NO"
},
{
"input": "3 3\ncab",
"output": "cba"
},
{
"input": "3 26\nyzx",
"output": "zab"
},
{
"input": "5 5\naceba",
"output": "acebc"
},
{
"input": "10 3\ncbacbacbac",
"output": "NO"
},
{
"input": "11 3\nabcabcabcab",
"output": "acbacbacbac"
},
{
"input": "12 10\nabcabcabcabc",
"output": "abcabcabcabd"
},
{
"input": "13 7\ngfegfegfegfeg",
"output": "NO"
},
{
"input": "15 11\ncgjkbadjfbdaikj",
"output": "cgjkbadjfbdajba"
},
{
"input": "17 4\ndabcadcbdcadbcdbc",
"output": "dabcadcbdcadcabca"
},
{
"input": "26 26\nahnxdnbfcriersyzdihuecojdi",
"output": "ahnxdnbfcriersyzdihuecojdk"
},
{
"input": "30 7\ncedcfedcfgcfgcbadcadgfaegfacgf",
"output": "cedcfedcfgcfgcbadcadgfaegfadba"
},
{
"input": "70 4\ndcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbd",
"output": "NO"
},
{
"input": "77 7\ncadgbagbcaecgfaegcdbeafbacbdfgaedgcdeabgebaecbeacgfebagedcegdafdgeacegfegfegf",
"output": "cadgbagbcaecgfaegcdbeafbacbdfgaedgcdeabgebaecbeacgfebagedcegdafdgeacfabcabcab"
},
{
"input": "100 4\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcd"
},
{
"input": "333 5\nedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedc",
"output": "NO"
},
{
"input": "3 3\nacb",
"output": "bac"
},
{
"input": "17 26\nbazyxzyxzyxzyxzyx",
"output": "bcabcabcabcabcabc"
},
{
"input": "6 3\nacbacb",
"output": "bacbac"
},
{
"input": "6 3\nabcabc",
"output": "acbacb"
},
{
"input": "302 4\nabdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcb",
"output": "acbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbac"
},
{
"input": "30 26\nabcabcabczyxzyxzyxzyxzyxzyxzyx",
"output": "abcabcabdabcabcabcabcabcabcabc"
},
{
"input": "300 3\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc",
"output": "acbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacb"
},
{
"input": "2 4\ncd",
"output": "da"
}
] | 1,634,647,482
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 8
| 78
| 0
|
# Author Name: Ajay Meena
# Codeforce : https://codeforces.com/profile/majay1638
import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout
# -------------- INPUT FUNCTIONS ------------------
def get_ints_in_variables(): return map(
int, sys.stdin.readline().strip().split())
def get_int(): return int(sys.stdin.readline())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(n): return [list(
map(int, sys.stdin.readline().strip().split())) for _ in range(n)]
def get_string(): return sys.stdin.readline().strip()
# -------- SOME CUSTOMIZED FUNCTIONS-----------
def myceil(x, y): return (x + y - 1) // y
# -------------- SOLUTION FUNCTION ------------------
def check(s, i, p):
ch = chr(ord(s[i])+1)
while ord(ch) < (97+p):
if i >= 2:
if s[i-1] != ch and s[i-2] != ch:
return ch
elif i >= 1:
if s[i-1] != ch:
return ch
elif i == 0:
return ch
ch = chr(ord(ch)+1)
return None
def Solution(s, n, p):
# Write Your Code Here
if p == 1 and n != 1:
print("NO")
return
s = [c for c in s]
flg = False
for i in range(n-1, -1, -1):
t = check(s, i, p)
if t != None:
s[i] = t
flg = True
break
ch = "a" if s[i] != "a" else "b"
for j in range(i+1, n):
s[j] = ch
if ch == "c":
ch = "a"
if flg:
print("".join(s))
else:
print("NO")
def main():
# Take input Here and Call solution function
n, p = get_ints_in_variables()
s = get_string()
Solution(s, n, p)
# calling main Function
if __name__ == '__main__':
main()
|
Title: No to Palindromes!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more.
Paul has found a tolerable string *s* of length *n*. Help him find the lexicographically next tolerable string of the same length or else state that such string does not exist.
Input Specification:
The first line contains two space-separated integers: *n* and *p* (1<=≤<=*n*<=≤<=1000; 1<=≤<=*p*<=≤<=26). The second line contains string *s*, consisting of *n* small English letters. It is guaranteed that the string is tolerable (according to the above definition).
Output Specification:
If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes).
Demo Input:
['3 3\ncba\n', '3 4\ncba\n', '4 4\nabcd\n']
Demo Output:
['NO\n', 'cbd\n', 'abda\n']
Note:
String *s* is lexicographically larger (or simply larger) than string *t* with the same length, if there is number *i*, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, ..., *s*<sub class="lower-index">*i*</sub> = *t*<sub class="lower-index">*i*</sub>, *s*<sub class="lower-index">*i* + 1</sub> > *t*<sub class="lower-index">*i* + 1</sub>.
The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one.
A palindrome is a string that reads the same forward or reversed.
|
```python
# Author Name: Ajay Meena
# Codeforce : https://codeforces.com/profile/majay1638
import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout
# -------------- INPUT FUNCTIONS ------------------
def get_ints_in_variables(): return map(
int, sys.stdin.readline().strip().split())
def get_int(): return int(sys.stdin.readline())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(n): return [list(
map(int, sys.stdin.readline().strip().split())) for _ in range(n)]
def get_string(): return sys.stdin.readline().strip()
# -------- SOME CUSTOMIZED FUNCTIONS-----------
def myceil(x, y): return (x + y - 1) // y
# -------------- SOLUTION FUNCTION ------------------
def check(s, i, p):
ch = chr(ord(s[i])+1)
while ord(ch) < (97+p):
if i >= 2:
if s[i-1] != ch and s[i-2] != ch:
return ch
elif i >= 1:
if s[i-1] != ch:
return ch
elif i == 0:
return ch
ch = chr(ord(ch)+1)
return None
def Solution(s, n, p):
# Write Your Code Here
if p == 1 and n != 1:
print("NO")
return
s = [c for c in s]
flg = False
for i in range(n-1, -1, -1):
t = check(s, i, p)
if t != None:
s[i] = t
flg = True
break
ch = "a" if s[i] != "a" else "b"
for j in range(i+1, n):
s[j] = ch
if ch == "c":
ch = "a"
if flg:
print("".join(s))
else:
print("NO")
def main():
# Take input Here and Call solution function
n, p = get_ints_in_variables()
s = get_string()
Solution(s, n, p)
# calling main Function
if __name__ == '__main__':
main()
```
| 0
|
|
202
|
A
|
LLPS
|
PROGRAMMING
| 800
|
[
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null |
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=<<=*p*2<=<<=...<=<<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".
String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| > |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=<<=|*x*|, *r*<=<<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=><=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".
String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".
|
The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10.
|
Print the lexicographically largest palindromic subsequence of string *s*.
|
[
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] |
[
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] |
Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
| 500
|
[
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
{
"input": "helloworld",
"output": "w"
},
{
"input": "zzzzzzzazz",
"output": "zzzzzzzzz"
},
{
"input": "testcase",
"output": "tt"
},
{
"input": "hahahahaha",
"output": "hhhhh"
},
{
"input": "abbbbbbbbb",
"output": "bbbbbbbbb"
},
{
"input": "zaz",
"output": "zz"
},
{
"input": "aza",
"output": "z"
},
{
"input": "dcbaedcba",
"output": "e"
},
{
"input": "abcdeabcd",
"output": "e"
},
{
"input": "edcbabcde",
"output": "ee"
},
{
"input": "aaaaaaaaab",
"output": "b"
},
{
"input": "testzzzzzz",
"output": "zzzzzz"
},
{
"input": "zzzzzzwait",
"output": "zzzzzz"
},
{
"input": "rrrrrqponm",
"output": "rrrrr"
},
{
"input": "zzyzyy",
"output": "zzz"
},
{
"input": "aababb",
"output": "bbb"
},
{
"input": "zanzibar",
"output": "zz"
},
{
"input": "hhgfedcbaa",
"output": "hh"
},
{
"input": "aabcdefghh",
"output": "hh"
},
{
"input": "aruaru",
"output": "uu"
},
{
"input": "uraura",
"output": "uu"
},
{
"input": "aru",
"output": "u"
},
{
"input": "aburvabur",
"output": "v"
},
{
"input": "ura",
"output": "u"
},
{
"input": "eurottat",
"output": "u"
},
{
"input": "referee",
"output": "rr"
},
{
"input": "joking",
"output": "o"
},
{
"input": "seriously",
"output": "y"
},
{
"input": "sets",
"output": "t"
},
{
"input": "test",
"output": "tt"
},
{
"input": "klmgameklm",
"output": "mmm"
},
{
"input": "dfkjafdkdd",
"output": "kk"
},
{
"input": "zzzzzzzzzz",
"output": "zzzzzzzzzz"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaa"
},
{
"input": "buzz",
"output": "zz"
},
{
"input": "b",
"output": "b"
},
{
"input": "y",
"output": "y"
},
{
"input": "yy",
"output": "yy"
},
{
"input": "zz",
"output": "zz"
},
{
"input": "bb",
"output": "bb"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "a",
"output": "a"
},
{
"input": "z",
"output": "z"
},
{
"input": "zz",
"output": "zz"
},
{
"input": "zzazazzzaz",
"output": "zzzzzzz"
},
{
"input": "hellhellhe",
"output": "llll"
},
{
"input": "hellohello",
"output": "oo"
},
{
"input": "refer",
"output": "rr"
}
] | 1,598,967,860
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 156
| 0
|
n = intput()
a = max(n)
print(n.count(i)*a)
|
Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=<<=*p*2<=<<=...<=<<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".
String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| > |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=<<=|*x*|, *r*<=<<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=><=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".
String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".
Input Specification:
The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10.
Output Specification:
Print the lexicographically largest palindromic subsequence of string *s*.
Demo Input:
['radar\n', 'bowwowwow\n', 'codeforces\n', 'mississipp\n']
Demo Output:
['rr\n', 'wwwww\n', 's\n', 'ssss\n']
Note:
Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
|
```python
n = intput()
a = max(n)
print(n.count(i)*a)
```
| -1
|
|
869
|
B
|
The Eternal Immortality
|
PROGRAMMING
| 1,100
|
[
"math"
] | null | null |
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! denotes the factorial of integer *a*, that is, *a*!<==<=1<=×<=2<=×<=...<=×<=*a*. Specifically, 0!<==<=1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of *b*! years, that is, . Note that when *b*<=≥<=*a* this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
|
The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018).
|
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
|
[
"2 4\n",
"0 10\n",
"107 109\n"
] |
[
"2\n",
"0\n",
"2\n"
] |
In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9642ef11a23e7c5a3f3c2b1255c1b1b3533802a4.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 0;
In the third example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/844938cef52ee264c183246d2a9df05cca94dc60.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
| 1,000
|
[
{
"input": "2 4",
"output": "2"
},
{
"input": "0 10",
"output": "0"
},
{
"input": "107 109",
"output": "2"
},
{
"input": "10 13",
"output": "6"
},
{
"input": "998244355 998244359",
"output": "4"
},
{
"input": "999999999000000000 1000000000000000000",
"output": "0"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "3 15",
"output": "0"
},
{
"input": "24 26",
"output": "0"
},
{
"input": "14 60",
"output": "0"
},
{
"input": "11 79",
"output": "0"
},
{
"input": "1230 1232",
"output": "2"
},
{
"input": "2633 2634",
"output": "4"
},
{
"input": "535 536",
"output": "6"
},
{
"input": "344319135 396746843",
"output": "0"
},
{
"input": "696667767 696667767",
"output": "1"
},
{
"input": "419530302 610096911",
"output": "0"
},
{
"input": "238965115 821731161",
"output": "0"
},
{
"input": "414626436 728903812",
"output": "0"
},
{
"input": "274410639 293308324",
"output": "0"
},
{
"input": "650636673091305697 650636673091305702",
"output": "0"
},
{
"input": "651240548333620923 651240548333620924",
"output": "4"
},
{
"input": "500000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "999999999999999999 1000000000000000000",
"output": "0"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1"
},
{
"input": "0 4",
"output": "4"
},
{
"input": "50000000062000007 50000000062000011",
"output": "0"
},
{
"input": "0 0",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "0 2",
"output": "2"
},
{
"input": "10000000000012 10000000000015",
"output": "0"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "12 23",
"output": "0"
},
{
"input": "0 11",
"output": "0"
},
{
"input": "11111234567890 11111234567898",
"output": "0"
},
{
"input": "0 3",
"output": "6"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "999999999999999997 999999999999999999",
"output": "2"
},
{
"input": "4 5",
"output": "5"
},
{
"input": "0 1",
"output": "1"
},
{
"input": "101 1002",
"output": "0"
},
{
"input": "0 100000000000000001",
"output": "0"
},
{
"input": "99999999999999997 99999999999999999",
"output": "2"
},
{
"input": "14 15",
"output": "5"
},
{
"input": "8 19",
"output": "0"
},
{
"input": "12 22",
"output": "0"
},
{
"input": "999999999999996 999999999999999",
"output": "4"
},
{
"input": "1 3",
"output": "6"
},
{
"input": "124 125",
"output": "5"
},
{
"input": "11 32",
"output": "0"
},
{
"input": "0 5",
"output": "0"
},
{
"input": "0 999999",
"output": "0"
},
{
"input": "151151151515 151151151526",
"output": "0"
},
{
"input": "6 107",
"output": "0"
},
{
"input": "5 16",
"output": "0"
},
{
"input": "7 16",
"output": "0"
},
{
"input": "6 19",
"output": "0"
},
{
"input": "11113111111111 13111111111111",
"output": "0"
},
{
"input": "1 1000",
"output": "0"
},
{
"input": "24 25",
"output": "5"
},
{
"input": "0 100000000000",
"output": "0"
},
{
"input": "1 22",
"output": "0"
},
{
"input": "999999999999999996 999999999999999999",
"output": "4"
}
] | 1,606,980,560
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 5
| 93
| 0
|
m,n=input().split()
m=int(m)
n=int(n)
if m==0:
m=m+1
if n==0:
n=n+1
factor=list(range(m+1,n+1))
f=1
for i in factor:
f=f*i
print(f%10)
|
Title: The Eternal Immortality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! denotes the factorial of integer *a*, that is, *a*!<==<=1<=×<=2<=×<=...<=×<=*a*. Specifically, 0!<==<=1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of *b*! years, that is, . Note that when *b*<=≥<=*a* this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
Input Specification:
The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018).
Output Specification:
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
Demo Input:
['2 4\n', '0 10\n', '107 109\n']
Demo Output:
['2\n', '0\n', '2\n']
Note:
In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9642ef11a23e7c5a3f3c2b1255c1b1b3533802a4.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 0;
In the third example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/844938cef52ee264c183246d2a9df05cca94dc60.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
|
```python
m,n=input().split()
m=int(m)
n=int(n)
if m==0:
m=m+1
if n==0:
n=n+1
factor=list(range(m+1,n+1))
f=1
for i in factor:
f=f*i
print(f%10)
```
| -1
|
|
585
|
A
|
Gennady the Dentist
|
PROGRAMMING
| 1,800
|
[
"brute force",
"implementation"
] | null | null |
Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated with the value of his cofidence *p**i*. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor.
While Gennady treats the teeth of the *i*-th child, the child is crying with the volume of *v**i*. At that the confidence of the first child in the line is reduced by the amount of *v**i*, the second one — by value *v**i*<=-<=1, and so on. The children in the queue after the *v**i*-th child almost do not hear the crying, so their confidence remains unchanged.
If at any point in time the confidence of the *j*-th child is less than zero, he begins to cry with the volume of *d**j* and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the *j*-th one in the line is reduced by the amount of *d**j*.
All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office.
Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order.
|
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=4000) — the number of kids in the line.
Next *n* lines contain three integers each *v**i*,<=*d**i*,<=*p**i* (1<=≤<=*v**i*,<=*d**i*,<=*p**i*<=≤<=106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the *i*-th child.
|
In the first line print number *k* — the number of children whose teeth Gennady will cure.
In the second line print *k* integers — the numbers of the children who will make it to the end of the line in the increasing order.
|
[
"5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n",
"5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n"
] |
[
"2\n1 3 ",
"4\n1 2 4 5 "
] |
In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit.
In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5, - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.
| 500
|
[
{
"input": "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2",
"output": "2\n1 3 "
},
{
"input": "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9",
"output": "4\n1 2 4 5 "
},
{
"input": "10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24",
"output": "3\n1 2 5 "
},
{
"input": "10\n5 6 3\n7 4 10\n9 1 17\n2 8 23\n9 10 24\n6 8 18\n3 2 35\n7 6 6\n1 3 12\n9 9 5",
"output": "6\n1 2 3 4 5 7 "
},
{
"input": "10\n4 9 1\n8 2 14\n7 10 20\n6 9 18\n5 3 19\n2 9 7\n6 8 30\n8 7 38\n6 5 5\n6 9 37",
"output": "8\n1 2 3 4 5 7 8 10 "
},
{
"input": "10\n10 3 3\n8 6 17\n9 5 26\n10 7 17\n3 10 29\n3 1 27\n3 3 7\n8 10 28\n1 3 23\n3 4 6",
"output": "5\n1 2 3 5 8 "
},
{
"input": "10\n5 6 1\n9 2 6\n4 1 5\n4 10 5\n1 8 23\n9 4 21\n3 9 6\n7 8 34\n7 4 24\n8 9 21",
"output": "5\n1 2 5 6 8 "
},
{
"input": "4\n2 10 1\n1 2 2\n2 1 1\n5 5 1",
"output": "3\n1 2 4 "
},
{
"input": "1\n1 1 1",
"output": "1\n1 "
},
{
"input": "2\n5 1 1\n1 1 5",
"output": "2\n1 2 "
},
{
"input": "2\n5 1 1\n1 1 4",
"output": "1\n1 "
},
{
"input": "2\n5 1 1\n1 1 6",
"output": "2\n1 2 "
},
{
"input": "3\n5 1 1\n1 1 4\n1 1 4",
"output": "1\n1 "
},
{
"input": "3\n5 1 1\n1 1 4\n1 1 5",
"output": "2\n1 3 "
},
{
"input": "3\n5 1 1\n1 1 5\n1 1 3",
"output": "2\n1 2 "
},
{
"input": "3\n5 1 1\n10 1 5\n1000 1000 14",
"output": "3\n1 2 3 "
},
{
"input": "10\n9 8 8\n2 9 33\n10 7 42\n7 2 18\n3 5 82\n9 9 25\n3 2 86\n3 5 49\n5 3 72\n4 4 71",
"output": "10\n1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10\n9 8 8\n2 9 8\n10 7 16\n7 2 9\n3 5 23\n9 9 25\n3 2 35\n3 5 36\n5 3 40\n4 4 42",
"output": "1\n1 "
}
] | 1,444,918,345
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 0
|
import io
import math
n=list(map(int,input().split()))
koldet=n[0]
spisokdet=[]
res=0
spisokvosh=[]
for i in range(koldet):
spisokdet.append(list(map(int,input().split())))
for i in range(koldet):
if spisokdet[i][0]>=0:
if spisokdet[i][2]>=0:
res+=1
spisokvosh.append(i+1)
v=spisokdet[i][0]
for g in range(i,i+v if i+v<=koldet else koldet):
spisokdet[g][2]-=(v-(g-i))
else:
for g in range(i,koldet):
if spisokdet[g][2]<0 and spisokdet[g][0]>0:
spisokdet[g][0]=-1
for e in range (g,koldet):
spisokdet[e][2]-=spisokdet[g][1]
print(res)
print(spisokvosh)
|
Title: Gennady the Dentist
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated with the value of his cofidence *p**i*. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor.
While Gennady treats the teeth of the *i*-th child, the child is crying with the volume of *v**i*. At that the confidence of the first child in the line is reduced by the amount of *v**i*, the second one — by value *v**i*<=-<=1, and so on. The children in the queue after the *v**i*-th child almost do not hear the crying, so their confidence remains unchanged.
If at any point in time the confidence of the *j*-th child is less than zero, he begins to cry with the volume of *d**j* and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the *j*-th one in the line is reduced by the amount of *d**j*.
All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office.
Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=4000) — the number of kids in the line.
Next *n* lines contain three integers each *v**i*,<=*d**i*,<=*p**i* (1<=≤<=*v**i*,<=*d**i*,<=*p**i*<=≤<=106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the *i*-th child.
Output Specification:
In the first line print number *k* — the number of children whose teeth Gennady will cure.
In the second line print *k* integers — the numbers of the children who will make it to the end of the line in the increasing order.
Demo Input:
['5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n', '5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n']
Demo Output:
['2\n1 3 ', '4\n1 2 4 5 ']
Note:
In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit.
In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5, - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.
|
```python
import io
import math
n=list(map(int,input().split()))
koldet=n[0]
spisokdet=[]
res=0
spisokvosh=[]
for i in range(koldet):
spisokdet.append(list(map(int,input().split())))
for i in range(koldet):
if spisokdet[i][0]>=0:
if spisokdet[i][2]>=0:
res+=1
spisokvosh.append(i+1)
v=spisokdet[i][0]
for g in range(i,i+v if i+v<=koldet else koldet):
spisokdet[g][2]-=(v-(g-i))
else:
for g in range(i,koldet):
if spisokdet[g][2]<0 and spisokdet[g][0]>0:
spisokdet[g][0]=-1
for e in range (g,koldet):
spisokdet[e][2]-=spisokdet[g][1]
print(res)
print(spisokvosh)
```
| 0
|
|
136
|
A
|
Presents
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
|
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
|
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
|
[
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] |
[
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] |
none
| 500
|
[
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input": "5\n5 4 3 2 1",
"output": "5 4 3 2 1"
},
{
"input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19"
},
{
"input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19",
"output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19"
},
{
"input": "10\n3 4 5 6 7 8 9 10 1 2",
"output": "9 10 1 2 3 4 5 6 7 8"
},
{
"input": "8\n1 5 3 7 2 6 4 8",
"output": "1 5 3 7 2 6 4 8"
},
{
"input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47",
"output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19"
},
{
"input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17",
"output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25"
},
{
"input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85",
"output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30"
},
{
"input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49",
"output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49"
},
{
"input": "12\n3 8 7 4 6 5 2 1 11 9 10 12",
"output": "8 7 1 4 6 5 3 2 10 11 9 12"
},
{
"input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76",
"output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4"
},
{
"input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43",
"output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1"
},
{
"input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27",
"output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3"
},
{
"input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22",
"output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53"
},
{
"input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13",
"output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24"
},
{
"input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21",
"output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61"
},
{
"input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33",
"output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14"
},
{
"input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23",
"output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21"
},
{
"input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12",
"output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9"
},
{
"input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31",
"output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13"
},
{
"input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3",
"output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16"
},
{
"input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8",
"output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6"
},
{
"input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71",
"output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90"
},
{
"input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9",
"output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9"
},
{
"input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44",
"output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20"
},
{
"input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17",
"output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28"
},
{
"input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7",
"output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5"
},
{
"input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16",
"output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43"
},
{
"input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65",
"output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43"
},
{
"input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16",
"output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45"
},
{
"input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51",
"output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64"
},
{
"input": "12\n12 3 1 5 11 6 7 10 2 8 9 4",
"output": "3 9 2 12 4 6 7 10 11 8 5 1"
},
{
"input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17",
"output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44"
},
{
"input": "8\n1 3 5 2 4 8 6 7",
"output": "1 4 2 5 3 7 8 6"
},
{
"input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14",
"output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12"
},
{
"input": "10\n2 9 4 6 10 1 7 5 3 8",
"output": "6 1 9 3 8 4 7 10 2 5"
},
{
"input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3",
"output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7"
},
{
"input": "10\n2 4 9 3 6 8 10 5 1 7",
"output": "9 1 4 2 8 5 10 6 3 7"
},
{
"input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15",
"output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23"
},
{
"input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1",
"output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27"
},
{
"input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30",
"output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23"
},
{
"input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52",
"output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50"
},
{
"input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18",
"output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98"
},
{
"input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16",
"output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25"
},
{
"input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37",
"output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54"
},
{
"input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71",
"output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71"
},
{
"input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22",
"output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8"
},
{
"input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12",
"output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51"
},
{
"input": "7\n2 1 5 7 3 4 6",
"output": "2 1 5 6 3 7 4"
},
{
"input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35",
"output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31"
},
{
"input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16",
"output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21"
},
{
"input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52",
"output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11"
},
{
"input": "9\n8 5 2 6 1 9 4 7 3",
"output": "5 3 9 7 2 4 8 1 6"
},
{
"input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27",
"output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13"
},
{
"input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34",
"output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6"
},
{
"input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29",
"output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14"
},
{
"input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7",
"output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16"
},
{
"input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34",
"output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24"
},
{
"input": "9\n4 8 6 5 3 9 2 7 1",
"output": "9 7 5 1 4 3 8 2 6"
},
{
"input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29",
"output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32"
},
{
"input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47",
"output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11"
},
{
"input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6",
"output": "10 4 1 8 6 13 12 5 3 11 9 2 7"
},
{
"input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29",
"output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37"
},
{
"input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3",
"output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25"
},
{
"input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20",
"output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24"
},
{
"input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42",
"output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59"
},
{
"input": "6\n4 3 6 5 1 2",
"output": "5 6 2 1 4 3"
},
{
"input": "9\n7 8 5 3 1 4 2 9 6",
"output": "5 7 4 6 3 9 1 2 8"
},
{
"input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37",
"output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11",
"output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13"
},
{
"input": "2\n2 1",
"output": "2 1"
},
{
"input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28",
"output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18"
},
{
"input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13",
"output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1"
},
{
"input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14",
"output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36"
},
{
"input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29",
"output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32"
},
{
"input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5",
"output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40"
},
{
"input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54",
"output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21"
},
{
"input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29",
"output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4"
},
{
"input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23",
"output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50"
},
{
"input": "10\n2 10 7 4 1 5 8 6 3 9",
"output": "5 1 9 4 6 8 3 7 10 2"
},
{
"input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13",
"output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1"
},
{
"input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2",
"output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11"
},
{
"input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53",
"output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37"
},
{
"input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53",
"output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53"
},
{
"input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64",
"output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49"
},
{
"input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86",
"output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38"
},
{
"input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75",
"output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2"
},
{
"input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53",
"output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5"
},
{
"input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39",
"output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12"
},
{
"input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87",
"output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82"
},
{
"input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25",
"output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97"
},
{
"input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61",
"output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96"
},
{
"input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92",
"output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96"
},
{
"input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6",
"output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36"
},
{
"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": "100 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"
}
] | 1,693,232,270
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 101
| 92
| 0
|
n = int(input())
s = list(map(int, input().split()))
for i in range(0, len(s)):
print(s.index(i+1)+1, end='')
if i != len(s):
print(' ', end='')
|
Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Output Specification:
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
Demo Input:
['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['4 1 2 3\n', '1 3 2\n', '1 2\n']
Note:
none
|
```python
n = int(input())
s = list(map(int, input().split()))
for i in range(0, len(s)):
print(s.index(i+1)+1, end='')
if i != len(s):
print(' ', end='')
```
| 3
|
|
276
|
D
|
Little Girl and Maximum XOR
|
PROGRAMMING
| 1,700
|
[
"bitmasks",
"dp",
"greedy",
"implementation",
"math"
] | null | null |
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). Your task is to find the maximum value among all considered ones.
Expression means applying bitwise excluding or operation to integers *x* and *y*. The given operation exists in all modern programming languages, for example, in languages *C*++ and *Java* it is represented as "^", in *Pascal* — as "xor".
|
The single line contains space-separated integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018).
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.
|
In a single line print a single integer — the maximum value of for all pairs of integers *a*, *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*).
|
[
"1 2\n",
"8 16\n",
"1 1\n"
] |
[
"3\n",
"31\n",
"0\n"
] |
none
| 2,000
|
[
{
"input": "1 2",
"output": "3"
},
{
"input": "8 16",
"output": "31"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "506 677",
"output": "1023"
},
{
"input": "33 910",
"output": "1023"
},
{
"input": "36 94",
"output": "127"
},
{
"input": "10000000000 20000000000",
"output": "34359738367"
},
{
"input": "79242383109441603 533369389165030783",
"output": "576460752303423487"
},
{
"input": "797162752288318119 908416915938410706",
"output": "576460752303423487"
},
{
"input": "230148668013473494 573330407369354716",
"output": "576460752303423487"
},
{
"input": "668869743157683834 805679503731305624",
"output": "288230376151711743"
},
{
"input": "32473107276976561 588384394540535099",
"output": "1152921504606846975"
},
{
"input": "632668612680440378 864824360766754908",
"output": "576460752303423487"
},
{
"input": "658472316271074503 728242833853270665",
"output": "288230376151711743"
},
{
"input": "289218059048863941 314351197831808685",
"output": "36028797018963967"
},
{
"input": "54248140375568203 718189790306910368",
"output": "1152921504606846975"
},
{
"input": "330134158459714054 457118108955760856",
"output": "288230376151711743"
},
{
"input": "190442232278841373 980738846929096255",
"output": "1152921504606846975"
},
{
"input": "203359308073091683 455893840817516371",
"output": "576460752303423487"
},
{
"input": "200851182089362664 449305852839820160",
"output": "576460752303423487"
},
{
"input": "731792654005832175 789527173439457653",
"output": "72057594037927935"
},
{
"input": "231465750142682282 276038074124518614",
"output": "72057594037927935"
},
{
"input": "462451489958473150 957447393463701191",
"output": "1152921504606846975"
},
{
"input": "68666076639301243 247574109010873331",
"output": "288230376151711743"
},
{
"input": "491113582000560303 858928223424873439",
"output": "1152921504606846975"
},
{
"input": "454452550141901489 843034681327343036",
"output": "1152921504606846975"
},
{
"input": "43543567767276698 769776048133345296",
"output": "1152921504606846975"
},
{
"input": "214985598536531449 956713939905291713",
"output": "1152921504606846975"
},
{
"input": "56445001476501414 706930175458589379",
"output": "1152921504606846975"
},
{
"input": "666033930784103123 883523065811761270",
"output": "576460752303423487"
},
{
"input": "501827377176522663 590153819613032662",
"output": "1152921504606846975"
},
{
"input": "140216419613864821 362678730465999561",
"output": "576460752303423487"
},
{
"input": "23811264031960242 520940113721281721",
"output": "576460752303423487"
},
{
"input": "43249439481689805 431488136320817289",
"output": "576460752303423487"
},
{
"input": "198909890748296613 528950282310167050",
"output": "576460752303423487"
},
{
"input": "190620774979376809 899159649449168622",
"output": "1152921504606846975"
},
{
"input": "18565852953382418 697862904569985066",
"output": "1152921504606846975"
},
{
"input": "277046860122752192 828379515775613732",
"output": "1152921504606846975"
},
{
"input": "25785331761502790 119852560236585580",
"output": "144115188075855871"
},
{
"input": "363313173638414449 500957528623228245",
"output": "288230376151711743"
},
{
"input": "549330032897152846 715374717344043295",
"output": "1152921504606846975"
},
{
"input": "47456305370335136 388462406071482688",
"output": "576460752303423487"
},
{
"input": "125051194948742221 235911208585118006",
"output": "288230376151711743"
},
{
"input": "780993382943360354 889872865454335075",
"output": "576460752303423487"
},
{
"input": "815449097320007662 942453891178865528",
"output": "576460752303423487"
},
{
"input": "765369978472937483 796958953973862258",
"output": "144115188075855871"
},
{
"input": "259703440079833303 857510033561081530",
"output": "1152921504606846975"
},
{
"input": "181513087965617551 301910258955864271",
"output": "576460752303423487"
},
{
"input": "28591024119784617 732203343197854927",
"output": "1152921504606846975"
},
{
"input": "215365547805299155 861595308221385098",
"output": "1152921504606846975"
},
{
"input": "1 1000000000000000000",
"output": "1152921504606846975"
},
{
"input": "1000000000000 999999999999999999",
"output": "1152921504606846975"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "9999999999998 9999999999999",
"output": "1"
},
{
"input": "9999999999900 9999999999901",
"output": "1"
},
{
"input": "9999999999900 9999999999902",
"output": "3"
},
{
"input": "9999999999900 9999999999903",
"output": "3"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "5000000 5900000",
"output": "2097151"
},
{
"input": "8589934592 8989934592",
"output": "536870911"
},
{
"input": "1 288230376151711743",
"output": "288230376151711743"
}
] | 1,642,912,228
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 30
| 0
|
p, q = map(int, input().split())
if p==q:
print(p^q)
else:
m=0
for i in range(p,q):
for j in range(i+1,q):
m = max(m,i^j)
print(m)
|
Title: Little Girl and Maximum XOR
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). Your task is to find the maximum value among all considered ones.
Expression means applying bitwise excluding or operation to integers *x* and *y*. The given operation exists in all modern programming languages, for example, in languages *C*++ and *Java* it is represented as "^", in *Pascal* — as "xor".
Input Specification:
The single line contains space-separated integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018).
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.
Output Specification:
In a single line print a single integer — the maximum value of for all pairs of integers *a*, *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*).
Demo Input:
['1 2\n', '8 16\n', '1 1\n']
Demo Output:
['3\n', '31\n', '0\n']
Note:
none
|
```python
p, q = map(int, input().split())
if p==q:
print(p^q)
else:
m=0
for i in range(p,q):
for j in range(i+1,q):
m = max(m,i^j)
print(m)
```
| 0
|
|
110
|
A
|
Nearly Lucky Number
|
PROGRAMMING
| 800
|
[
"implementation"
] |
A. Nearly Lucky Number
|
2
|
256
|
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
|
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
|
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
|
[
"40047\n",
"7747774\n",
"1000000000000000000\n"
] |
[
"NO\n",
"YES\n",
"NO\n"
] |
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO".
| 500
|
[
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
"input": "4744000695826",
"output": "YES"
},
{
"input": "10000000004744744",
"output": "YES"
},
{
"input": "446486416781684178",
"output": "YES"
},
{
"input": "999999999",
"output": "NO"
},
{
"input": "7777",
"output": "YES"
},
{
"input": "87414417444",
"output": "NO"
},
{
"input": "111222333444555667",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "4700",
"output": "NO"
},
{
"input": "3794555488744477",
"output": "NO"
},
{
"input": "444444444444444444",
"output": "NO"
},
{
"input": "474447447774444774",
"output": "NO"
},
{
"input": "777777777777777",
"output": "NO"
},
{
"input": "34777745021000000",
"output": "NO"
},
{
"input": "963",
"output": "NO"
},
{
"input": "855474448854788540",
"output": "NO"
},
{
"input": "999999999999994744",
"output": "YES"
},
{
"input": "400000000474",
"output": "YES"
},
{
"input": "123456789123456789",
"output": "YES"
},
{
"input": "740577777584945874",
"output": "NO"
},
{
"input": "7777777",
"output": "YES"
},
{
"input": "4444000111222333",
"output": "YES"
},
{
"input": "9847745885202111",
"output": "YES"
},
{
"input": "123456000000",
"output": "NO"
},
{
"input": "4744447444444",
"output": "NO"
},
{
"input": "7477",
"output": "YES"
},
{
"input": "4747477",
"output": "YES"
},
{
"input": "777777777444444444",
"output": "NO"
}
] | 1,699,091,504
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 34
| 92
| 0
|
n = int(input())
digits = [int(i) for i in str(n)]
number_of_lucky_digits = digits.count(4) + digits.count(7)
if number_of_lucky_digits == 4 or number_of_lucky_digits == 7:
print('YES')
else:
print('NO')
|
Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
Input Specification:
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output Specification:
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
Demo Input:
['40047\n', '7747774\n', '1000000000000000000\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO".
|
```python
n = int(input())
digits = [int(i) for i in str(n)]
number_of_lucky_digits = digits.count(4) + digits.count(7)
if number_of_lucky_digits == 4 or number_of_lucky_digits == 7:
print('YES')
else:
print('NO')
```
| 3.977
|
955
|
C
|
Sad powers
|
PROGRAMMING
| 2,100
|
[
"binary search",
"math",
"number theory"
] | null | null |
You're given *Q* queries of the form (*L*,<=*R*).
For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=><=0, *p*<=><=1 such that *x*<==<=*a**p*.
|
The first line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105).
The next *Q* lines contains two integers *L*, *R* each (1<=≤<=*L*<=≤<=*R*<=≤<=1018).
|
Output *Q* lines — the answers to the queries.
|
[
"6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n"
] |
[
"2\n1\n0\n3\n17\n1111\n"
] |
In query one the suitable numbers are 1 and 4.
| 1,500
|
[
{
"input": "6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000",
"output": "2\n1\n0\n3\n17\n1111"
},
{
"input": "20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n217 972\n461 847\n442 468\n900 986\n518 529\n938 993\n549 851\n690 944\n484 601\n320 910\n98 868\n816 915\n765 880\n551 770",
"output": "1\n4\n5\n6\n14\n32\n20\n9\n0\n2\n1\n1\n6\n4\n4\n15\n26\n2\n2\n4"
}
] | 1,521,826,785
| 3,885
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
PRETESTS
| 2
| 2,000
| 20,377,600
|
def steps(a):
global num
p = 0
p += a
a *= a
while a <= 10 ** 18:
num.append(a)
a *= p
def bin_r(num, x):
r = len(num)
l = -1
while r - l > 1:
mid = (r + l) // 2
if num[mid] > x:
r = mid
else:
l = mid
return r
def bin_l(num, x):
r = len(num)
l = -1
while r - l > 1:
mid = (r + l) // 2
if num[mid] < x:
l = mid
else:
r = mid
return l
num = [1]
for i in range(2, 100000):
steps(i)
num = set(num)
num = list(num)
num.sort()
n = int(input())
for i in range(n):
l1, r1 = map(int, input().split())
l = bin_l(num, l1)
r = bin_r(num, r1)
if num[l] != l1 and num[r] != r1:
print(r - l - 1)
elif num[l] == l1 and num[r] == r1:
print(r - l + 1)
else:
print(r - l)
|
Title: Sad powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given *Q* queries of the form (*L*,<=*R*).
For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=><=0, *p*<=><=1 such that *x*<==<=*a**p*.
Input Specification:
The first line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105).
The next *Q* lines contains two integers *L*, *R* each (1<=≤<=*L*<=≤<=*R*<=≤<=1018).
Output Specification:
Output *Q* lines — the answers to the queries.
Demo Input:
['6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n']
Demo Output:
['2\n1\n0\n3\n17\n1111\n']
Note:
In query one the suitable numbers are 1 and 4.
|
```python
def steps(a):
global num
p = 0
p += a
a *= a
while a <= 10 ** 18:
num.append(a)
a *= p
def bin_r(num, x):
r = len(num)
l = -1
while r - l > 1:
mid = (r + l) // 2
if num[mid] > x:
r = mid
else:
l = mid
return r
def bin_l(num, x):
r = len(num)
l = -1
while r - l > 1:
mid = (r + l) // 2
if num[mid] < x:
l = mid
else:
r = mid
return l
num = [1]
for i in range(2, 100000):
steps(i)
num = set(num)
num = list(num)
num.sort()
n = int(input())
for i in range(n):
l1, r1 = map(int, input().split())
l = bin_l(num, l1)
r = bin_r(num, r1)
if num[l] != l1 and num[r] != r1:
print(r - l - 1)
elif num[l] == l1 and num[r] == r1:
print(r - l + 1)
else:
print(r - l)
```
| 0
|
|
551
|
A
|
GukiZ and Contest
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation",
"sortings"
] | null | null |
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings.
He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position.
GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
|
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
|
[
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] |
[
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] |
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
| 500
|
[
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4 4 4 2"
},
{
"input": "1\n2000",
"output": "1"
},
{
"input": "2\n2000 2000",
"output": "1 1"
},
{
"input": "3\n500 501 502",
"output": "3 2 1"
},
{
"input": "10\n105 106 1 1 1 11 1000 999 1000 999",
"output": "6 5 8 8 8 7 1 3 1 3"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "6 5 4 3 2 1"
},
{
"input": "7\n6 5 4 3 2 1 1",
"output": "1 2 3 4 5 6 6"
},
{
"input": "8\n153 100 87 14 10 8 6 5",
"output": "1 2 3 4 5 6 7 8"
},
{
"input": "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10",
"output": "62 18 35 7 70 23 61 56 34 22 42 58 6 66 10 37 21 2 38 13 69 29 14 42 48 7 29 5 50 66 60 29 63 35 20 38 4 23 10 65 58 52 57 27 41 28 52 23 2 46 45 14 12 66 52 55 1 19 50 33 26 44 47 29 38 48 16 17 7 63"
},
{
"input": "5\n1 2000 1 1 2000",
"output": "3 1 3 3 1"
}
] | 1,686,979,657
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 36
| 77
| 2,150,400
|
n = int(input())
lst = list(map(int, input().split()))
cpy = lst.copy()
cpy.sort()
cpy.reverse()
res = [1 + cpy.index(x) for x in lst]
print(" ".join(str(x) for x in res))
|
Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings.
He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position.
GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
Output Specification:
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
Demo Input:
['3\n1 3 3\n', '1\n1\n', '5\n3 5 3 4 5\n']
Demo Output:
['3 1 1\n', '1\n', '4 1 4 3 1\n']
Note:
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
|
```python
n = int(input())
lst = list(map(int, input().split()))
cpy = lst.copy()
cpy.sort()
cpy.reverse()
res = [1 + cpy.index(x) for x in lst]
print(" ".join(str(x) for x in res))
```
| 3
|
|
6
|
A
|
Triangle
|
PROGRAMMING
| 900
|
[
"brute force",
"geometry"
] |
A. Triangle
|
2
|
64
|
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
|
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
|
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
|
[
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] |
[
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] |
none
| 0
|
[
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 5 6 11",
"output": "TRIANGLE"
},
{
"input": "1 1 1 1",
"output": "TRIANGLE"
},
{
"input": "10 20 30 40",
"output": "TRIANGLE"
},
{
"input": "45 25 5 15",
"output": "IMPOSSIBLE"
},
{
"input": "20 5 8 13",
"output": "TRIANGLE"
},
{
"input": "10 30 7 20",
"output": "SEGMENT"
},
{
"input": "3 2 3 2",
"output": "TRIANGLE"
},
{
"input": "70 10 100 30",
"output": "SEGMENT"
},
{
"input": "4 8 16 2",
"output": "IMPOSSIBLE"
},
{
"input": "3 3 3 10",
"output": "TRIANGLE"
},
{
"input": "1 5 5 5",
"output": "TRIANGLE"
},
{
"input": "13 25 12 1",
"output": "SEGMENT"
},
{
"input": "10 100 7 3",
"output": "SEGMENT"
},
{
"input": "50 1 50 100",
"output": "TRIANGLE"
},
{
"input": "50 1 100 49",
"output": "SEGMENT"
},
{
"input": "49 51 100 1",
"output": "SEGMENT"
},
{
"input": "5 11 2 25",
"output": "IMPOSSIBLE"
},
{
"input": "91 50 9 40",
"output": "IMPOSSIBLE"
},
{
"input": "27 53 7 97",
"output": "IMPOSSIBLE"
},
{
"input": "51 90 24 8",
"output": "IMPOSSIBLE"
},
{
"input": "3 5 1 1",
"output": "IMPOSSIBLE"
},
{
"input": "13 49 69 15",
"output": "IMPOSSIBLE"
},
{
"input": "16 99 9 35",
"output": "IMPOSSIBLE"
},
{
"input": "27 6 18 53",
"output": "IMPOSSIBLE"
},
{
"input": "57 88 17 8",
"output": "IMPOSSIBLE"
},
{
"input": "95 20 21 43",
"output": "IMPOSSIBLE"
},
{
"input": "6 19 32 61",
"output": "IMPOSSIBLE"
},
{
"input": "100 21 30 65",
"output": "IMPOSSIBLE"
},
{
"input": "85 16 61 9",
"output": "IMPOSSIBLE"
},
{
"input": "5 6 19 82",
"output": "IMPOSSIBLE"
},
{
"input": "1 5 1 3",
"output": "IMPOSSIBLE"
},
{
"input": "65 10 36 17",
"output": "IMPOSSIBLE"
},
{
"input": "81 64 9 7",
"output": "IMPOSSIBLE"
},
{
"input": "11 30 79 43",
"output": "IMPOSSIBLE"
},
{
"input": "1 1 5 3",
"output": "IMPOSSIBLE"
},
{
"input": "21 94 61 31",
"output": "IMPOSSIBLE"
},
{
"input": "49 24 9 74",
"output": "IMPOSSIBLE"
},
{
"input": "11 19 5 77",
"output": "IMPOSSIBLE"
},
{
"input": "52 10 19 71",
"output": "SEGMENT"
},
{
"input": "2 3 7 10",
"output": "SEGMENT"
},
{
"input": "1 2 6 3",
"output": "SEGMENT"
},
{
"input": "2 6 1 8",
"output": "SEGMENT"
},
{
"input": "1 2 4 1",
"output": "SEGMENT"
},
{
"input": "4 10 6 2",
"output": "SEGMENT"
},
{
"input": "2 10 7 3",
"output": "SEGMENT"
},
{
"input": "5 2 3 9",
"output": "SEGMENT"
},
{
"input": "6 1 4 10",
"output": "SEGMENT"
},
{
"input": "10 6 4 1",
"output": "SEGMENT"
},
{
"input": "3 2 9 1",
"output": "SEGMENT"
},
{
"input": "22 80 29 7",
"output": "SEGMENT"
},
{
"input": "2 6 3 9",
"output": "SEGMENT"
},
{
"input": "3 1 2 1",
"output": "SEGMENT"
},
{
"input": "3 4 7 1",
"output": "SEGMENT"
},
{
"input": "8 4 3 1",
"output": "SEGMENT"
},
{
"input": "2 8 3 5",
"output": "SEGMENT"
},
{
"input": "4 1 2 1",
"output": "SEGMENT"
},
{
"input": "8 1 3 2",
"output": "SEGMENT"
},
{
"input": "6 2 1 8",
"output": "SEGMENT"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "3 6 3 3",
"output": "TRIANGLE"
},
{
"input": "4 10 4 4",
"output": "TRIANGLE"
},
{
"input": "1 1 2 1",
"output": "TRIANGLE"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "5 4 5 5",
"output": "TRIANGLE"
},
{
"input": "8 7 8 8",
"output": "TRIANGLE"
},
{
"input": "3 3 3 1",
"output": "TRIANGLE"
},
{
"input": "1 1 6 6",
"output": "TRIANGLE"
},
{
"input": "1 9 1 9",
"output": "TRIANGLE"
},
{
"input": "7 2 2 7",
"output": "TRIANGLE"
},
{
"input": "7 2 3 2",
"output": "TRIANGLE"
},
{
"input": "4 4 10 10",
"output": "TRIANGLE"
},
{
"input": "7 7 10 7",
"output": "TRIANGLE"
},
{
"input": "4 4 4 5",
"output": "TRIANGLE"
},
{
"input": "1 10 9 2",
"output": "TRIANGLE"
},
{
"input": "1 8 2 7",
"output": "TRIANGLE"
},
{
"input": "4 3 2 8",
"output": "TRIANGLE"
},
{
"input": "5 9 5 3",
"output": "TRIANGLE"
},
{
"input": "4 10 3 5",
"output": "TRIANGLE"
}
] | 1,589,101,746
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 83
| 312
| 20,172,800
|
sides = list(map(int, input().split()))
sides.sort()
if sides[0]+sides[1]>sides[2]:
print("TRIANGLE")
elif sides[1]+sides[2]>sides[3]:
print("TRIANGLE")
elif sides[1]+sides[2]==sides[3]:
print("SEGMENT")
elif sides[0]+sides[1]==sides[2]:
print("SEGMENT")
else:
print("IMPOSSIBLE")
|
Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input Specification:
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output Specification:
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Demo Input:
['4 2 1 3\n', '7 2 2 4\n', '3 5 9 1\n']
Demo Output:
['TRIANGLE\n', 'SEGMENT\n', 'IMPOSSIBLE\n']
Note:
none
|
```python
sides = list(map(int, input().split()))
sides.sort()
if sides[0]+sides[1]>sides[2]:
print("TRIANGLE")
elif sides[1]+sides[2]>sides[3]:
print("TRIANGLE")
elif sides[1]+sides[2]==sides[3]:
print("SEGMENT")
elif sides[0]+sides[1]==sides[2]:
print("SEGMENT")
else:
print("IMPOSSIBLE")
```
| 3.771701
|
53
|
C
|
Little Frog
|
PROGRAMMING
| 1,200
|
[
"constructive algorithms"
] |
C. Little Frog
|
2
|
256
|
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him.
|
The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds.
|
Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any.
|
[
"2\n",
"3\n"
] |
[
"1 2 ",
"1 3 2 "
] |
none
| 1,500
|
[
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"input": "9149",
"output": "1 9149 2 9148 3 9147 4 9146 5 9145 6 9144 7 9143 8 9142 9 9141 10 9140 11 9139 12 9138 13 9137 14 9136 15 9135 16 9134 17 9133 18 9132 19 9131 20 9130 21 9129 22 9128 23 9127 24 9126 25 9125 26 9124 27 9123 28 9122 29 9121 30 9120 31 9119 32 9118 33 9117 34 9116 35 9115 36 9114 37 9113 38 9112 39 9111 40 9110 41 9109 42 9108 43 9107 44 9106 45 9105 46 9104 47 9103 48 9102 49 9101 50 9100 51 9099 52 9098 53 9097 54 9096 55 9095 56 9094 57 9093 58 9092 59 9091 60 9090 61 9089 62 9088 63 9087 64 9086 65 9085 ..."
},
{
"input": "2877",
"output": "1 2877 2 2876 3 2875 4 2874 5 2873 6 2872 7 2871 8 2870 9 2869 10 2868 11 2867 12 2866 13 2865 14 2864 15 2863 16 2862 17 2861 18 2860 19 2859 20 2858 21 2857 22 2856 23 2855 24 2854 25 2853 26 2852 27 2851 28 2850 29 2849 30 2848 31 2847 32 2846 33 2845 34 2844 35 2843 36 2842 37 2841 38 2840 39 2839 40 2838 41 2837 42 2836 43 2835 44 2834 45 2833 46 2832 47 2831 48 2830 49 2829 50 2828 51 2827 52 2826 53 2825 54 2824 55 2823 56 2822 57 2821 58 2820 59 2819 60 2818 61 2817 62 2816 63 2815 64 2814 65 2813 ..."
},
{
"input": "2956",
"output": "1 2956 2 2955 3 2954 4 2953 5 2952 6 2951 7 2950 8 2949 9 2948 10 2947 11 2946 12 2945 13 2944 14 2943 15 2942 16 2941 17 2940 18 2939 19 2938 20 2937 21 2936 22 2935 23 2934 24 2933 25 2932 26 2931 27 2930 28 2929 29 2928 30 2927 31 2926 32 2925 33 2924 34 2923 35 2922 36 2921 37 2920 38 2919 39 2918 40 2917 41 2916 42 2915 43 2914 44 2913 45 2912 46 2911 47 2910 48 2909 49 2908 50 2907 51 2906 52 2905 53 2904 54 2903 55 2902 56 2901 57 2900 58 2899 59 2898 60 2897 61 2896 62 2895 63 2894 64 2893 65 2892 ..."
},
{
"input": "3035",
"output": "1 3035 2 3034 3 3033 4 3032 5 3031 6 3030 7 3029 8 3028 9 3027 10 3026 11 3025 12 3024 13 3023 14 3022 15 3021 16 3020 17 3019 18 3018 19 3017 20 3016 21 3015 22 3014 23 3013 24 3012 25 3011 26 3010 27 3009 28 3008 29 3007 30 3006 31 3005 32 3004 33 3003 34 3002 35 3001 36 3000 37 2999 38 2998 39 2997 40 2996 41 2995 42 2994 43 2993 44 2992 45 2991 46 2990 47 2989 48 2988 49 2987 50 2986 51 2985 52 2984 53 2983 54 2982 55 2981 56 2980 57 2979 58 2978 59 2977 60 2976 61 2975 62 2974 63 2973 64 2972 65 2971 ..."
},
{
"input": "3114",
"output": "1 3114 2 3113 3 3112 4 3111 5 3110 6 3109 7 3108 8 3107 9 3106 10 3105 11 3104 12 3103 13 3102 14 3101 15 3100 16 3099 17 3098 18 3097 19 3096 20 3095 21 3094 22 3093 23 3092 24 3091 25 3090 26 3089 27 3088 28 3087 29 3086 30 3085 31 3084 32 3083 33 3082 34 3081 35 3080 36 3079 37 3078 38 3077 39 3076 40 3075 41 3074 42 3073 43 3072 44 3071 45 3070 46 3069 47 3068 48 3067 49 3066 50 3065 51 3064 52 3063 53 3062 54 3061 55 3060 56 3059 57 3058 58 3057 59 3056 60 3055 61 3054 62 3053 63 3052 64 3051 65 3050 ..."
},
{
"input": "3193",
"output": "1 3193 2 3192 3 3191 4 3190 5 3189 6 3188 7 3187 8 3186 9 3185 10 3184 11 3183 12 3182 13 3181 14 3180 15 3179 16 3178 17 3177 18 3176 19 3175 20 3174 21 3173 22 3172 23 3171 24 3170 25 3169 26 3168 27 3167 28 3166 29 3165 30 3164 31 3163 32 3162 33 3161 34 3160 35 3159 36 3158 37 3157 38 3156 39 3155 40 3154 41 3153 42 3152 43 3151 44 3150 45 3149 46 3148 47 3147 48 3146 49 3145 50 3144 51 3143 52 3142 53 3141 54 3140 55 3139 56 3138 57 3137 58 3136 59 3135 60 3134 61 3133 62 3132 63 3131 64 3130 65 3129 ..."
},
{
"input": "3273",
"output": "1 3273 2 3272 3 3271 4 3270 5 3269 6 3268 7 3267 8 3266 9 3265 10 3264 11 3263 12 3262 13 3261 14 3260 15 3259 16 3258 17 3257 18 3256 19 3255 20 3254 21 3253 22 3252 23 3251 24 3250 25 3249 26 3248 27 3247 28 3246 29 3245 30 3244 31 3243 32 3242 33 3241 34 3240 35 3239 36 3238 37 3237 38 3236 39 3235 40 3234 41 3233 42 3232 43 3231 44 3230 45 3229 46 3228 47 3227 48 3226 49 3225 50 3224 51 3223 52 3222 53 3221 54 3220 55 3219 56 3218 57 3217 58 3216 59 3215 60 3214 61 3213 62 3212 63 3211 64 3210 65 3209 ..."
},
{
"input": "7000",
"output": "1 7000 2 6999 3 6998 4 6997 5 6996 6 6995 7 6994 8 6993 9 6992 10 6991 11 6990 12 6989 13 6988 14 6987 15 6986 16 6985 17 6984 18 6983 19 6982 20 6981 21 6980 22 6979 23 6978 24 6977 25 6976 26 6975 27 6974 28 6973 29 6972 30 6971 31 6970 32 6969 33 6968 34 6967 35 6966 36 6965 37 6964 38 6963 39 6962 40 6961 41 6960 42 6959 43 6958 44 6957 45 6956 46 6955 47 6954 48 6953 49 6952 50 6951 51 6950 52 6949 53 6948 54 6947 55 6946 56 6945 57 6944 58 6943 59 6942 60 6941 61 6940 62 6939 63 6938 64 6937 65 6936 ..."
},
{
"input": "7079",
"output": "1 7079 2 7078 3 7077 4 7076 5 7075 6 7074 7 7073 8 7072 9 7071 10 7070 11 7069 12 7068 13 7067 14 7066 15 7065 16 7064 17 7063 18 7062 19 7061 20 7060 21 7059 22 7058 23 7057 24 7056 25 7055 26 7054 27 7053 28 7052 29 7051 30 7050 31 7049 32 7048 33 7047 34 7046 35 7045 36 7044 37 7043 38 7042 39 7041 40 7040 41 7039 42 7038 43 7037 44 7036 45 7035 46 7034 47 7033 48 7032 49 7031 50 7030 51 7029 52 7028 53 7027 54 7026 55 7025 56 7024 57 7023 58 7022 59 7021 60 7020 61 7019 62 7018 63 7017 64 7016 65 7015 ..."
},
{
"input": "4653",
"output": "1 4653 2 4652 3 4651 4 4650 5 4649 6 4648 7 4647 8 4646 9 4645 10 4644 11 4643 12 4642 13 4641 14 4640 15 4639 16 4638 17 4637 18 4636 19 4635 20 4634 21 4633 22 4632 23 4631 24 4630 25 4629 26 4628 27 4627 28 4626 29 4625 30 4624 31 4623 32 4622 33 4621 34 4620 35 4619 36 4618 37 4617 38 4616 39 4615 40 4614 41 4613 42 4612 43 4611 44 4610 45 4609 46 4608 47 4607 48 4606 49 4605 50 4604 51 4603 52 4602 53 4601 54 4600 55 4599 56 4598 57 4597 58 4596 59 4595 60 4594 61 4593 62 4592 63 4591 64 4590 65 4589 ..."
},
{
"input": "9995",
"output": "1 9995 2 9994 3 9993 4 9992 5 9991 6 9990 7 9989 8 9988 9 9987 10 9986 11 9985 12 9984 13 9983 14 9982 15 9981 16 9980 17 9979 18 9978 19 9977 20 9976 21 9975 22 9974 23 9973 24 9972 25 9971 26 9970 27 9969 28 9968 29 9967 30 9966 31 9965 32 9964 33 9963 34 9962 35 9961 36 9960 37 9959 38 9958 39 9957 40 9956 41 9955 42 9954 43 9953 44 9952 45 9951 46 9950 47 9949 48 9948 49 9947 50 9946 51 9945 52 9944 53 9943 54 9942 55 9941 56 9940 57 9939 58 9938 59 9937 60 9936 61 9935 62 9934 63 9933 64 9932 65 9931 ..."
},
{
"input": "9996",
"output": "1 9996 2 9995 3 9994 4 9993 5 9992 6 9991 7 9990 8 9989 9 9988 10 9987 11 9986 12 9985 13 9984 14 9983 15 9982 16 9981 17 9980 18 9979 19 9978 20 9977 21 9976 22 9975 23 9974 24 9973 25 9972 26 9971 27 9970 28 9969 29 9968 30 9967 31 9966 32 9965 33 9964 34 9963 35 9962 36 9961 37 9960 38 9959 39 9958 40 9957 41 9956 42 9955 43 9954 44 9953 45 9952 46 9951 47 9950 48 9949 49 9948 50 9947 51 9946 52 9945 53 9944 54 9943 55 9942 56 9941 57 9940 58 9939 59 9938 60 9937 61 9936 62 9935 63 9934 64 9933 65 9932 ..."
},
{
"input": "9997",
"output": "1 9997 2 9996 3 9995 4 9994 5 9993 6 9992 7 9991 8 9990 9 9989 10 9988 11 9987 12 9986 13 9985 14 9984 15 9983 16 9982 17 9981 18 9980 19 9979 20 9978 21 9977 22 9976 23 9975 24 9974 25 9973 26 9972 27 9971 28 9970 29 9969 30 9968 31 9967 32 9966 33 9965 34 9964 35 9963 36 9962 37 9961 38 9960 39 9959 40 9958 41 9957 42 9956 43 9955 44 9954 45 9953 46 9952 47 9951 48 9950 49 9949 50 9948 51 9947 52 9946 53 9945 54 9944 55 9943 56 9942 57 9941 58 9940 59 9939 60 9938 61 9937 62 9936 63 9935 64 9934 65 9933 ..."
},
{
"input": "9998",
"output": "1 9998 2 9997 3 9996 4 9995 5 9994 6 9993 7 9992 8 9991 9 9990 10 9989 11 9988 12 9987 13 9986 14 9985 15 9984 16 9983 17 9982 18 9981 19 9980 20 9979 21 9978 22 9977 23 9976 24 9975 25 9974 26 9973 27 9972 28 9971 29 9970 30 9969 31 9968 32 9967 33 9966 34 9965 35 9964 36 9963 37 9962 38 9961 39 9960 40 9959 41 9958 42 9957 43 9956 44 9955 45 9954 46 9953 47 9952 48 9951 49 9950 50 9949 51 9948 52 9947 53 9946 54 9945 55 9944 56 9943 57 9942 58 9941 59 9940 60 9939 61 9938 62 9937 63 9936 64 9935 65 9934 ..."
},
{
"input": "9999",
"output": "1 9999 2 9998 3 9997 4 9996 5 9995 6 9994 7 9993 8 9992 9 9991 10 9990 11 9989 12 9988 13 9987 14 9986 15 9985 16 9984 17 9983 18 9982 19 9981 20 9980 21 9979 22 9978 23 9977 24 9976 25 9975 26 9974 27 9973 28 9972 29 9971 30 9970 31 9969 32 9968 33 9967 34 9966 35 9965 36 9964 37 9963 38 9962 39 9961 40 9960 41 9959 42 9958 43 9957 44 9956 45 9955 46 9954 47 9953 48 9952 49 9951 50 9950 51 9949 52 9948 53 9947 54 9946 55 9945 56 9944 57 9943 58 9942 59 9941 60 9940 61 9939 62 9938 63 9937 64 9936 65 9935 ..."
},
{
"input": "10000",
"output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951 51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 9936..."
}
] | 1,621,862,488
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 22
| 186
| 5,529,600
|
def solve():
n = int(input())
j=0
i=1
k=n
# print("k")
s = ""
if n%2==0:
while j<n:
s = s + str(k)+" "+str(i)+" "
k-=1
i+=1
j+=2
else:
while j<n-1:
s = s + str(k)+" "+str(i)+" "
i+=1
k-=1
j+=2
s+=str(i)
print(s)
return
try:
solve()
except:
pass
|
Title: Little Frog
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him.
Input Specification:
The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds.
Output Specification:
Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any.
Demo Input:
['2\n', '3\n']
Demo Output:
['1 2 ', '1 3 2 ']
Note:
none
|
```python
def solve():
n = int(input())
j=0
i=1
k=n
# print("k")
s = ""
if n%2==0:
while j<n:
s = s + str(k)+" "+str(i)+" "
k-=1
i+=1
j+=2
else:
while j<n-1:
s = s + str(k)+" "+str(i)+" "
i+=1
k-=1
j+=2
s+=str(i)
print(s)
return
try:
solve()
except:
pass
```
| 3.9432
|
845
|
B
|
Luba And The Ticket
|
PROGRAMMING
| 1,600
|
[
"brute force",
"greedy",
"implementation"
] | null | null |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
|
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
|
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
|
[
"000000\n",
"123456\n",
"111000\n"
] |
[
"0\n",
"2\n",
"1\n"
] |
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
| 0
|
[
{
"input": "000000",
"output": "0"
},
{
"input": "123456",
"output": "2"
},
{
"input": "111000",
"output": "1"
},
{
"input": "120111",
"output": "0"
},
{
"input": "999999",
"output": "0"
},
{
"input": "199880",
"output": "1"
},
{
"input": "899889",
"output": "1"
},
{
"input": "899888",
"output": "1"
},
{
"input": "505777",
"output": "2"
},
{
"input": "999000",
"output": "3"
},
{
"input": "989010",
"output": "3"
},
{
"input": "651894",
"output": "1"
},
{
"input": "858022",
"output": "2"
},
{
"input": "103452",
"output": "1"
},
{
"input": "999801",
"output": "2"
},
{
"input": "999990",
"output": "1"
},
{
"input": "697742",
"output": "1"
},
{
"input": "242367",
"output": "2"
},
{
"input": "099999",
"output": "1"
},
{
"input": "198999",
"output": "1"
},
{
"input": "023680",
"output": "1"
},
{
"input": "999911",
"output": "2"
},
{
"input": "000990",
"output": "2"
},
{
"input": "117099",
"output": "1"
},
{
"input": "990999",
"output": "1"
},
{
"input": "000111",
"output": "1"
},
{
"input": "000444",
"output": "2"
},
{
"input": "202597",
"output": "2"
},
{
"input": "000333",
"output": "1"
},
{
"input": "030039",
"output": "1"
},
{
"input": "000009",
"output": "1"
},
{
"input": "006456",
"output": "1"
},
{
"input": "022995",
"output": "3"
},
{
"input": "999198",
"output": "1"
},
{
"input": "223456",
"output": "2"
},
{
"input": "333665",
"output": "2"
},
{
"input": "123986",
"output": "2"
},
{
"input": "599257",
"output": "1"
},
{
"input": "101488",
"output": "3"
},
{
"input": "111399",
"output": "2"
},
{
"input": "369009",
"output": "1"
},
{
"input": "024887",
"output": "2"
},
{
"input": "314347",
"output": "1"
},
{
"input": "145892",
"output": "1"
},
{
"input": "321933",
"output": "1"
},
{
"input": "100172",
"output": "1"
},
{
"input": "222455",
"output": "2"
},
{
"input": "317596",
"output": "1"
},
{
"input": "979245",
"output": "2"
},
{
"input": "000018",
"output": "1"
},
{
"input": "101389",
"output": "2"
},
{
"input": "123985",
"output": "2"
},
{
"input": "900000",
"output": "1"
},
{
"input": "132069",
"output": "1"
},
{
"input": "949256",
"output": "1"
},
{
"input": "123996",
"output": "2"
},
{
"input": "034988",
"output": "2"
},
{
"input": "320869",
"output": "2"
},
{
"input": "089753",
"output": "1"
},
{
"input": "335667",
"output": "2"
},
{
"input": "868580",
"output": "1"
},
{
"input": "958031",
"output": "2"
},
{
"input": "117999",
"output": "2"
},
{
"input": "000001",
"output": "1"
},
{
"input": "213986",
"output": "2"
},
{
"input": "123987",
"output": "3"
},
{
"input": "111993",
"output": "2"
},
{
"input": "642479",
"output": "1"
},
{
"input": "033788",
"output": "2"
},
{
"input": "766100",
"output": "2"
},
{
"input": "012561",
"output": "1"
},
{
"input": "111695",
"output": "2"
},
{
"input": "123689",
"output": "2"
},
{
"input": "944234",
"output": "1"
},
{
"input": "154999",
"output": "2"
},
{
"input": "333945",
"output": "1"
},
{
"input": "371130",
"output": "1"
},
{
"input": "977330",
"output": "2"
},
{
"input": "777544",
"output": "2"
},
{
"input": "111965",
"output": "2"
},
{
"input": "988430",
"output": "2"
},
{
"input": "123789",
"output": "3"
},
{
"input": "111956",
"output": "2"
},
{
"input": "444776",
"output": "2"
},
{
"input": "001019",
"output": "1"
},
{
"input": "011299",
"output": "2"
},
{
"input": "011389",
"output": "2"
},
{
"input": "999333",
"output": "2"
},
{
"input": "126999",
"output": "2"
},
{
"input": "744438",
"output": "0"
},
{
"input": "588121",
"output": "3"
},
{
"input": "698213",
"output": "2"
},
{
"input": "652858",
"output": "1"
},
{
"input": "989304",
"output": "3"
},
{
"input": "888213",
"output": "3"
},
{
"input": "969503",
"output": "2"
},
{
"input": "988034",
"output": "2"
},
{
"input": "889444",
"output": "2"
},
{
"input": "990900",
"output": "1"
},
{
"input": "301679",
"output": "2"
},
{
"input": "434946",
"output": "1"
},
{
"input": "191578",
"output": "2"
},
{
"input": "118000",
"output": "2"
},
{
"input": "636915",
"output": "0"
},
{
"input": "811010",
"output": "1"
},
{
"input": "822569",
"output": "1"
},
{
"input": "122669",
"output": "2"
},
{
"input": "010339",
"output": "2"
},
{
"input": "213698",
"output": "2"
},
{
"input": "895130",
"output": "2"
},
{
"input": "000900",
"output": "1"
},
{
"input": "191000",
"output": "2"
},
{
"input": "001000",
"output": "1"
},
{
"input": "080189",
"output": "2"
},
{
"input": "990000",
"output": "2"
},
{
"input": "201984",
"output": "2"
},
{
"input": "002667",
"output": "2"
},
{
"input": "877542",
"output": "2"
},
{
"input": "301697",
"output": "2"
},
{
"input": "211597",
"output": "2"
},
{
"input": "420337",
"output": "1"
},
{
"input": "024768",
"output": "2"
},
{
"input": "878033",
"output": "2"
},
{
"input": "788024",
"output": "2"
},
{
"input": "023869",
"output": "2"
},
{
"input": "466341",
"output": "1"
},
{
"input": "696327",
"output": "1"
},
{
"input": "779114",
"output": "2"
},
{
"input": "858643",
"output": "1"
},
{
"input": "011488",
"output": "3"
},
{
"input": "003669",
"output": "2"
},
{
"input": "202877",
"output": "3"
},
{
"input": "738000",
"output": "2"
},
{
"input": "567235",
"output": "2"
},
{
"input": "887321",
"output": "3"
},
{
"input": "401779",
"output": "2"
},
{
"input": "989473",
"output": "2"
},
{
"input": "004977",
"output": "3"
},
{
"input": "023778",
"output": "2"
},
{
"input": "809116",
"output": "1"
},
{
"input": "042762",
"output": "1"
},
{
"input": "777445",
"output": "2"
},
{
"input": "769302",
"output": "2"
},
{
"input": "023977",
"output": "2"
},
{
"input": "990131",
"output": "2"
}
] | 1,504,096,539
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 6
| 2,000
| 0
|
string = input()
a = sorted([int(char) for char in string[:3]])
b = sorted([int(char) for char in string[3:]])
count = 0
while sum(a) != sum(b):
if sum(a) < sum(b):
k = sum(b) - sum(a)
new = a.pop(0)
a.append(min(k + new, 9))
elif sum(a) > sum(b):
k = sum(a) - sum(b)
new = b.pop(0)
b.append(min(k, 9))
count += 1
print(count)
|
Title: Luba And The Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input Specification:
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output Specification:
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Demo Input:
['000000\n', '123456\n', '111000\n']
Demo Output:
['0\n', '2\n', '1\n']
Note:
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
|
```python
string = input()
a = sorted([int(char) for char in string[:3]])
b = sorted([int(char) for char in string[3:]])
count = 0
while sum(a) != sum(b):
if sum(a) < sum(b):
k = sum(b) - sum(a)
new = a.pop(0)
a.append(min(k + new, 9))
elif sum(a) > sum(b):
k = sum(a) - sum(b)
new = b.pop(0)
b.append(min(k, 9))
count += 1
print(count)
```
| 0
|
|
432
|
A
|
Choosing Teams
|
PROGRAMMING
| 800
|
[
"greedy",
"implementation",
"sortings"
] | null | null |
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
|
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
|
Print a single number — the answer to the problem.
|
[
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] |
[
"1\n",
"0\n",
"2\n"
] |
In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits.
| 500
|
[
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1",
"output": "3"
},
{
"input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4",
"output": "4"
},
{
"input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1",
"output": "3"
},
{
"input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0",
"output": "5"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "6 3\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "1 4\n1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "2 3\n0 0",
"output": "0"
}
] | 1,687,933,698
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 35
| 46
| 0
|
n,c=map(int,input().split())
students=list(map(int,input().split()))
count=0
for i in students:
sub=(5-c)
if(sub>=i):
count+=1
ans=count//3
print(ans)
|
Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
Input Specification:
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits.
|
```python
n,c=map(int,input().split())
students=list(map(int,input().split()))
count=0
for i in students:
sub=(5-c)
if(sub>=i):
count+=1
ans=count//3
print(ans)
```
| 3
|
|
469
|
A
|
I Wanna Be the Guy
|
PROGRAMMING
| 800
|
[
"greedy",
"implementation"
] | null | null |
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
|
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
|
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
|
[
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] |
[
"I become the guy.\n",
"Oh, my keyboard!\n"
] |
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4.
| 500
|
[
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output": "I become the guy."
},
{
"input": "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5",
"output": "I become the guy."
},
{
"input": "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 57 28 54 1 51 66 27 22 93 59 68 88 91 29 7 20 63 8 52 23 64 58 100 79 65 49 96 71 33 45\n83 50 89 73 34 28 99 67 77 44 19 60 68 42 8 27 94 85 14 39 17 78 24 21 29 63 92 32 86 22 71 81 31 82 65 48 80 59 98 3 70 55 37 12 15 72 47 9 11 33 16 7 91 74 13 64 38 84 6 61 93 90 45 69 1 54 52 100 57 10 35 49 53 75 76 43 62 5 4 18 36 96 79 23",
"output": "Oh, my keyboard!"
},
{
"input": "1\n1 1\n1 1",
"output": "I become the guy."
},
{
"input": "1\n0\n1 1",
"output": "I become the guy."
},
{
"input": "1\n1 1\n0",
"output": "I become the guy."
},
{
"input": "1\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n44 71 70 55 49 43 16 53 7 95 58 56 38 76 67 94 20 73 29 90 25 30 8 84 5 14 77 52 99 91 66 24 39 37 22 44 78 12 63 59 32 51 15 82 34\n56 17 10 96 80 69 13 81 31 57 4 48 68 89 50 45 3 33 36 2 72 100 64 87 21 75 54 74 92 65 23 40 97 61 18 28 98 93 35 83 9 79 46 27 41 62 88 6 47 60 86 26 42 85 19 1 11",
"output": "I become the guy."
},
{
"input": "100\n78 63 59 39 11 58 4 2 80 69 22 95 90 26 65 16 30 100 66 99 67 79 54 12 23 28 45 56 70 74 60 82 73 91 68 43 92 75 51 21 17 97 86 44 62 47 85 78 72 64 50 81 71 5 57 13 31 76 87 9 49 96 25 42 19 35 88 53 7 83 38 27 29 41 89 93 10 84 18\n78 1 16 53 72 99 9 36 59 49 75 77 94 79 35 4 92 42 82 83 76 97 20 68 55 47 65 50 14 30 13 67 98 8 7 40 64 32 87 10 33 90 93 18 26 71 17 46 24 28 89 58 37 91 39 34 25 48 84 31 96 95 80 88 3 51 62 52 85 61 12 15 27 6 45 38 2 22 60",
"output": "I become the guy."
},
{
"input": "2\n2 2 1\n0",
"output": "I become the guy."
},
{
"input": "2\n1 2\n2 1 2",
"output": "I become the guy."
},
{
"input": "80\n57 40 1 47 36 69 24 76 5 72 26 4 29 62 6 60 3 70 8 64 18 37 16 14 13 21 25 7 66 68 44 74 61 39 38 33 15 63 34 65 10 23 56 51 80 58 49 75 71 12 50 57 2 30 54 27 17 52\n61 22 67 15 28 41 26 1 80 44 3 38 18 37 79 57 11 7 65 34 9 36 40 5 48 29 64 31 51 63 27 4 50 13 24 32 58 23 19 46 8 73 39 2 21 56 77 53 59 78 43 12 55 45 30 74 33 68 42 47 17 54",
"output": "Oh, my keyboard!"
},
{
"input": "100\n78 87 96 18 73 32 38 44 29 64 40 70 47 91 60 69 24 1 5 34 92 94 99 22 83 65 14 68 15 20 74 31 39 100 42 4 97 46 25 6 8 56 79 9 71 35 54 19 59 93 58 62 10 85 57 45 33 7 86 81 30 98 26 61 84 41 23 28 88 36 66 51 80 53 37 63 43 95 75\n76 81 53 15 26 37 31 62 24 87 41 39 75 86 46 76 34 4 51 5 45 65 67 48 68 23 71 27 94 47 16 17 9 96 84 89 88 100 18 52 69 42 6 92 7 64 49 12 98 28 21 99 25 55 44 40 82 19 36 30 77 90 14 43 50 3 13 95 78 35 20 54 58 11 2 1 33",
"output": "Oh, my keyboard!"
},
{
"input": "100\n77 55 26 98 13 91 78 60 23 76 12 11 36 62 84 80 18 1 68 92 81 67 19 4 2 10 17 77 96 63 15 69 46 97 82 42 83 59 50 72 14 40 89 9 52 29 56 31 74 39 45 85 22 99 44 65 95 6 90 38 54 32 49 34 3 70 75 33 94 53 21 71 5 66 73 41 100 24\n69 76 93 5 24 57 59 6 81 4 30 12 44 15 67 45 73 3 16 8 47 95 20 64 68 85 54 17 90 86 66 58 13 37 42 51 35 32 1 28 43 80 7 14 48 19 62 55 2 91 25 49 27 26 38 79 89 99 22 60 75 53 88 82 34 21 87 71 72 61",
"output": "I become the guy."
},
{
"input": "100\n74 96 32 63 12 69 72 99 15 22 1 41 79 77 71 31 20 28 75 73 85 37 38 59 42 100 86 89 55 87 68 4 24 57 52 8 92 27 56 98 95 58 34 9 45 14 11 36 66 76 61 19 25 23 78 49 90 26 80 43 70 13 65 10 5 74 81 21 44 60 97 3 47 93 6\n64 68 21 27 16 91 23 22 33 12 71 88 90 50 62 43 28 29 57 59 5 74 10 95 35 1 67 93 36 32 86 40 6 64 78 46 89 15 84 53 18 30 17 85 2 3 47 92 25 48 76 51 20 82 52 83 99 63 80 11 94 54 39 7 58",
"output": "I become the guy."
},
{
"input": "100\n75 11 98 44 47 88 94 23 78 59 70 2 43 39 34 63 71 19 42 61 30 74 14 77 97 53 92 60 67 36 37 13 6 86 62 46 41 3 25 93 7 12 27 48 55 49 31 35 51 10 57 54 95 82 28 90 73 26 17 50 81 56 20 87 40 85 72 64 99 29 91 5 80 18 24 52\n72 93 59 5 88 47 9 58 48 1 43 50 100 87 61 91 45 98 99 56 25 84 53 73 78 54 63 38 37 2 77 95 89 85 4 90 10 33 12 22 74 32 34 70 71 52 96 57 15 66 31 27 75 8 21 39 62 44 67 94 81 68 14 19 36 28 11 79 16 65 46 83 76",
"output": "Oh, my keyboard!"
},
{
"input": "3\n1 2\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "4\n1 2\n3 1 3 4",
"output": "I become the guy."
},
{
"input": "6\n2 1 2\n3 4 5 6",
"output": "Oh, my keyboard!"
}
] | 1,692,453,137
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 30
| 0
|
n = int(input())
a = input().split()
b = input().split()
print(a, b)
ans = 0
for i in range(1, n+1):
if str(i) not in a:
if str(i) not in b:
print("Oh, my keyboard!")
ans = 1
break
if ans == 0:
print("I become the guy.")
|
Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
Input Specification:
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
Output Specification:
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
Demo Input:
['4\n3 1 2 3\n2 2 4\n', '4\n3 1 2 3\n2 2 3\n']
Demo Output:
['I become the guy.\n', 'Oh, my keyboard!\n']
Note:
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4.
|
```python
n = int(input())
a = input().split()
b = input().split()
print(a, b)
ans = 0
for i in range(1, n+1):
if str(i) not in a:
if str(i) not in b:
print("Oh, my keyboard!")
ans = 1
break
if ans == 0:
print("I become the guy.")
```
| 0
|
|
510
|
A
|
Fox And Snake
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern.
|
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number.
|
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
|
[
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] |
[
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] |
none
| 500
|
[
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########"
},
{
"input": "3 5",
"output": "#####\n....#\n#####"
},
{
"input": "3 6",
"output": "######\n.....#\n######"
},
{
"input": "7 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "7 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####"
},
{
"input": "49 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 27",
"output": "###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n....................."
},
{
"input": "11 15",
"output": "###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n#..............\n###############\n..............#\n###############"
},
{
"input": "11 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "19 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "23 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "49 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "33 43",
"output": "###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#.................."
},
{
"input": "33 44",
"output": "############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#......."
},
{
"input": "45 45",
"output": "#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#########################################..."
},
{
"input": "45 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "45 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###"
},
{
"input": "45 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####"
},
{
"input": "5 4",
"output": "####\n...#\n####\n#...\n####"
},
{
"input": "5 5",
"output": "#####\n....#\n#####\n#....\n#####"
},
{
"input": "5 6",
"output": "######\n.....#\n######\n#.....\n######"
},
{
"input": "7 5",
"output": "#####\n....#\n#####\n#....\n#####\n....#\n#####"
},
{
"input": "7 6",
"output": "######\n.....#\n######\n#.....\n######\n.....#\n######"
},
{
"input": "7 7",
"output": "#######\n......#\n#######\n#......\n#######\n......#\n#######"
}
] | 1,695,112,431
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 30
| 0
|
a,b=map(int,input())
pat1='#' * b +'\n'
pat2='.' * (b-1) + '#'
n=n//2
for i in range(n):
pattern=pat1+pat2
print(pattern)
pat2=pat2[::-1]
print(pat1)
|
Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern.
Input Specification:
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number.
Output Specification:
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
Demo Input:
['3 3\n', '3 4\n', '5 3\n', '9 9\n']
Demo Output:
['###\n..#\n###\n', '####\n...#\n####\n', '###\n..#\n###\n#..\n###\n', '#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n']
Note:
none
|
```python
a,b=map(int,input())
pat1='#' * b +'\n'
pat2='.' * (b-1) + '#'
n=n//2
for i in range(n):
pattern=pat1+pat2
print(pattern)
pat2=pat2[::-1]
print(pat1)
```
| -1
|
|
493
|
B
|
Vasya and Wrestling
|
PROGRAMMING
| 1,400
|
[
"implementation"
] | null | null |
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
|
The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order.
|
If the first wrestler wins, print string "first", otherwise print "second"
|
[
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] |
[
"second\n",
"first\n",
"second\n"
] |
Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |*y*| and *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">|*y*|</sub> = *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> > *y*<sub class="lower-index">*r* + 1</sub>.
We use notation |*a*| to denote length of sequence *a*.
| 1,000
|
[
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-12\n-13\n-14",
"output": "second"
},
{
"input": "4\n16\n12\n19\n-98",
"output": "second"
},
{
"input": "5\n-6\n-1\n-1\n5\n3",
"output": "second"
},
{
"input": "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1",
"output": "first"
},
{
"input": "1\n-534365",
"output": "second"
},
{
"input": "1\n10253033",
"output": "first"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "8\n1\n-2\n-3\n4\n5\n-6\n-7\n8",
"output": "second"
},
{
"input": "2\n1\n-1",
"output": "second"
},
{
"input": "5\n1\n2\n3\n4\n5",
"output": "first"
},
{
"input": "5\n-1\n-2\n-3\n-4\n-5",
"output": "second"
},
{
"input": "10\n-1\n-2\n-3\n-4\n-5\n5\n4\n3\n2\n1",
"output": "first"
},
{
"input": "131\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n-1\n-1\n2",
"output": "first"
},
{
"input": "6\n-1\n-2\n-3\n1\n2\n3",
"output": "first"
},
{
"input": "3\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "12\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-1000000000",
"output": "first"
},
{
"input": "20\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "5\n1000000000\n1000000000\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "4\n1\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "5\n1000000000\n1000000000\n1000000000\n-1000000000\n-1000000000",
"output": "first"
},
{
"input": "4\n-1\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "11\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "2\n-4\n4",
"output": "first"
},
{
"input": "3\n-12\n3\n9",
"output": "second"
},
{
"input": "3\n9\n1\n-10",
"output": "second"
},
{
"input": "3\n1\n2\n-3",
"output": "second"
},
{
"input": "4\n55\n5\n-5\n-55",
"output": "first"
},
{
"input": "4\n5\n-1\n1\n-5",
"output": "first"
},
{
"input": "2\n-5\n6",
"output": "first"
},
{
"input": "4\n5\n-4\n3\n-40",
"output": "second"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-5",
"output": "first"
},
{
"input": "6\n3\n2\n1\n-3\n-1\n-2",
"output": "first"
},
{
"input": "5\n4\n1\n1\n-3\n-3",
"output": "first"
},
{
"input": "5\n208\n-52\n-52\n-52\n-52",
"output": "first"
},
{
"input": "3\n-100\n-200\n300",
"output": "first"
},
{
"input": "3\n400\n-200\n-200",
"output": "first"
},
{
"input": "3\n208\n-207\n-1",
"output": "first"
},
{
"input": "3\n98888887\n98888888\n-197777775",
"output": "second"
}
] | 1,597,042,795
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 57
| 1,481
| 30,003,200
|
n = int(input())
lastinp = 0
sums1 = 0
sums2 = 0
l = []
r = []
for i in range(0, n):
x = int(input())
if(x > 0):
sums1 += x
l.append(x)
else:
sums2 += abs(x)
r.append(abs(x))
lastinp = x
flag = -1
if(sums1 < sums2):
print("second")
elif(sums1 > sums2):
print("first")
else:
# check for 1st greater
for i in range(0, min(len(l), len(r))):
if(l[i] > r[i]):
flag = 0
break
elif(l[i] < r[i]):
flag = 1
break
if(flag == -1):
if(len(l) != len(r) and len(l) > len(r)):
print("first")
elif(len(l) != len(r) and len(l) > len(r)):
print("second")
elif(lastinp < 0):
print("second")
else:
print("first")
elif(flag == 0):
print("first")
else:
print("second")
|
Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
Input Specification:
The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order.
Output Specification:
If the first wrestler wins, print string "first", otherwise print "second"
Demo Input:
['5\n1\n2\n-3\n-4\n3\n', '3\n-1\n-2\n3\n', '2\n4\n-4\n']
Demo Output:
['second\n', 'first\n', 'second\n']
Note:
Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |*y*| and *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">|*y*|</sub> = *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> > *y*<sub class="lower-index">*r* + 1</sub>.
We use notation |*a*| to denote length of sequence *a*.
|
```python
n = int(input())
lastinp = 0
sums1 = 0
sums2 = 0
l = []
r = []
for i in range(0, n):
x = int(input())
if(x > 0):
sums1 += x
l.append(x)
else:
sums2 += abs(x)
r.append(abs(x))
lastinp = x
flag = -1
if(sums1 < sums2):
print("second")
elif(sums1 > sums2):
print("first")
else:
# check for 1st greater
for i in range(0, min(len(l), len(r))):
if(l[i] > r[i]):
flag = 0
break
elif(l[i] < r[i]):
flag = 1
break
if(flag == -1):
if(len(l) != len(r) and len(l) > len(r)):
print("first")
elif(len(l) != len(r) and len(l) > len(r)):
print("second")
elif(lastinp < 0):
print("second")
else:
print("first")
elif(flag == 0):
print("first")
else:
print("second")
```
| 3
|
|
25
|
B
|
Phone numbers
|
PROGRAMMING
| 1,100
|
[
"implementation"
] |
B. Phone numbers
|
2
|
256
|
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.
|
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups.
|
Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.
|
[
"6\n549871\n",
"7\n1198733\n"
] |
[
"54-98-71",
"11-987-33\n"
] |
none
| 0
|
[
{
"input": "6\n549871",
"output": "54-98-71"
},
{
"input": "7\n1198733",
"output": "119-87-33"
},
{
"input": "2\n74",
"output": "74"
},
{
"input": "2\n33",
"output": "33"
},
{
"input": "3\n074",
"output": "074"
},
{
"input": "3\n081",
"output": "081"
},
{
"input": "4\n3811",
"output": "38-11"
},
{
"input": "5\n21583",
"output": "215-83"
},
{
"input": "8\n33408349",
"output": "33-40-83-49"
},
{
"input": "9\n988808426",
"output": "988-80-84-26"
},
{
"input": "10\n0180990956",
"output": "01-80-99-09-56"
},
{
"input": "15\n433488906230138",
"output": "433-48-89-06-23-01-38"
},
{
"input": "22\n7135498415686025907059",
"output": "71-35-49-84-15-68-60-25-90-70-59"
},
{
"input": "49\n2429965524999668169991253653390090510755018570235",
"output": "242-99-65-52-49-99-66-81-69-99-12-53-65-33-90-09-05-10-75-50-18-57-02-35"
},
{
"input": "72\n491925337784111770500147619881727525570039735507439360627744863794794290",
"output": "49-19-25-33-77-84-11-17-70-50-01-47-61-98-81-72-75-25-57-00-39-73-55-07-43-93-60-62-77-44-86-37-94-79-42-90"
},
{
"input": "95\n32543414456047900690980198395035321172843693417425457554204776648220562494524275489599199209210",
"output": "325-43-41-44-56-04-79-00-69-09-80-19-83-95-03-53-21-17-28-43-69-34-17-42-54-57-55-42-04-77-66-48-22-05-62-49-45-24-27-54-89-59-91-99-20-92-10"
},
{
"input": "97\n9362344595153688016434451101547661156123505108492010669557671355055642365998461003851354321478898",
"output": "936-23-44-59-51-53-68-80-16-43-44-51-10-15-47-66-11-56-12-35-05-10-84-92-01-06-69-55-76-71-35-50-55-64-23-65-99-84-61-00-38-51-35-43-21-47-88-98"
},
{
"input": "98\n65521815795893886057122984634320900545031770769333931308009346017867969790810907868670369236928568",
"output": "65-52-18-15-79-58-93-88-60-57-12-29-84-63-43-20-90-05-45-03-17-70-76-93-33-93-13-08-00-93-46-01-78-67-96-97-90-81-09-07-86-86-70-36-92-36-92-85-68"
},
{
"input": "99\n455213856470326729480192345541970106407563996625458559297407682539801838244443866898560852503660390",
"output": "455-21-38-56-47-03-26-72-94-80-19-23-45-54-19-70-10-64-07-56-39-96-62-54-58-55-92-97-40-76-82-53-98-01-83-82-44-44-38-66-89-85-60-85-25-03-66-03-90"
},
{
"input": "100\n4004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224",
"output": "40-04-22-31-24-94-27-30-64-02-35-38-32-44-43-82-57-61-45-81-53-43-20-35-60-60-98-72-41-65-97-84-24-95-51-11-01-65-03-47-19-44-33-27-65-95-10-64-42-24"
}
] | 1,630,173,101
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 20
| 154
| 6,963,200
|
# بسم الله الرحمن الرحيم
def main():
n = int(input())
assert n >= 2
phone = input()
if n == 2 or n == 3:
print(phone)
return
remember = ''
for i in range(0, len(phone), 2):
rem = n - i
if rem == 3 or rem == 2:
remember += phone[i:]
break
j = i + 2
remember += phone[i: j]+'-'
print(remember)
if __name__=='__main__':
main()
|
Title: Phone numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups.
Output Specification:
Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.
Demo Input:
['6\n549871\n', '7\n1198733\n']
Demo Output:
['54-98-71', '11-987-33\n']
Note:
none
|
```python
# بسم الله الرحمن الرحيم
def main():
n = int(input())
assert n >= 2
phone = input()
if n == 2 or n == 3:
print(phone)
return
remember = ''
for i in range(0, len(phone), 2):
rem = n - i
if rem == 3 or rem == 2:
remember += phone[i:]
break
j = i + 2
remember += phone[i: j]+'-'
print(remember)
if __name__=='__main__':
main()
```
| 3.94853
|
432
|
A
|
Choosing Teams
|
PROGRAMMING
| 800
|
[
"greedy",
"implementation",
"sortings"
] | null | null |
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
|
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
|
Print a single number — the answer to the problem.
|
[
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] |
[
"1\n",
"0\n",
"2\n"
] |
In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits.
| 500
|
[
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1",
"output": "3"
},
{
"input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4",
"output": "4"
},
{
"input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1",
"output": "3"
},
{
"input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0",
"output": "5"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "6 3\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "1 4\n1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "2 3\n0 0",
"output": "0"
}
] | 1,681,316,615
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 31
| 46
| 0
|
n, k = map(int, input().split())
data = sorted(map(int, input().split()))
while data[-1] + k > 5:
data.pop()
print(len(data) // 3)
|
Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
Input Specification:
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits.
|
```python
n, k = map(int, input().split())
data = sorted(map(int, input().split()))
while data[-1] + k > 5:
data.pop()
print(len(data) // 3)
```
| -1
|
|
747
|
A
|
Display Size
|
PROGRAMMING
| 800
|
[
"brute force",
"math"
] | null | null |
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible.
|
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have.
|
Print two integers — the number of rows and columns on the display.
|
[
"8\n",
"64\n",
"5\n",
"999999\n"
] |
[
"2 4\n",
"8 8\n",
"1 5\n",
"999 1001\n"
] |
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.
| 500
|
[
{
"input": "8",
"output": "2 4"
},
{
"input": "64",
"output": "8 8"
},
{
"input": "5",
"output": "1 5"
},
{
"input": "999999",
"output": "999 1001"
},
{
"input": "716539",
"output": "97 7387"
},
{
"input": "1",
"output": "1 1"
},
{
"input": "2",
"output": "1 2"
},
{
"input": "3",
"output": "1 3"
},
{
"input": "4",
"output": "2 2"
},
{
"input": "6",
"output": "2 3"
},
{
"input": "7",
"output": "1 7"
},
{
"input": "9",
"output": "3 3"
},
{
"input": "10",
"output": "2 5"
},
{
"input": "11",
"output": "1 11"
},
{
"input": "12",
"output": "3 4"
},
{
"input": "15",
"output": "3 5"
},
{
"input": "100",
"output": "10 10"
},
{
"input": "101",
"output": "1 101"
},
{
"input": "169",
"output": "13 13"
},
{
"input": "179",
"output": "1 179"
},
{
"input": "190",
"output": "10 19"
},
{
"input": "1000",
"output": "25 40"
},
{
"input": "10000",
"output": "100 100"
},
{
"input": "10001",
"output": "73 137"
},
{
"input": "100000",
"output": "250 400"
},
{
"input": "100001",
"output": "11 9091"
},
{
"input": "1000000",
"output": "1000 1000"
},
{
"input": "999983",
"output": "1 999983"
},
{
"input": "524288",
"output": "512 1024"
},
{
"input": "954493",
"output": "971 983"
},
{
"input": "966289",
"output": "983 983"
},
{
"input": "944663",
"output": "961 983"
},
{
"input": "912673",
"output": "97 9409"
},
{
"input": "732641",
"output": "679 1079"
},
{
"input": "232897",
"output": "343 679"
},
{
"input": "16807",
"output": "49 343"
},
{
"input": "999958",
"output": "2 499979"
},
{
"input": "990151",
"output": "1 990151"
},
{
"input": "997002",
"output": "998 999"
},
{
"input": "20",
"output": "4 5"
},
{
"input": "20261",
"output": "1 20261"
},
{
"input": "999123",
"output": "3 333041"
},
{
"input": "901841",
"output": "1 901841"
}
] | 1,594,728,937
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 43
| 109
| 6,758,400
|
n=int(input())
a=[]
x=int(n**(1/2))
# print(x)
for i in range(1,x+1):
if n%i==0:
a.append((i,n//i))
print(*max(a))
|
Title: Display Size
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible.
Input Specification:
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have.
Output Specification:
Print two integers — the number of rows and columns on the display.
Demo Input:
['8\n', '64\n', '5\n', '999999\n']
Demo Output:
['2 4\n', '8 8\n', '1 5\n', '999 1001\n']
Note:
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.
|
```python
n=int(input())
a=[]
x=int(n**(1/2))
# print(x)
for i in range(1,x+1):
if n%i==0:
a.append((i,n//i))
print(*max(a))
```
| 3
|
|
765
|
D
|
Artsem and Saunders
|
PROGRAMMING
| 1,700
|
[
"constructive algorithms",
"dsu",
"math"
] | null | null |
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [*n*] denote the set {1,<=...,<=*n*}. We will also write *f*:<=[*x*]<=→<=[*y*] when a function *f* is defined in integer points 1, ..., *x*, and all its values are integers from 1 to *y*.
Now then, you are given a function *f*:<=[*n*]<=→<=[*n*]. Your task is to find a positive integer *m*, and two functions *g*:<=[*n*]<=→<=[*m*], *h*:<=[*m*]<=→<=[*n*], such that *g*(*h*(*x*))<==<=*x* for all , and *h*(*g*(*x*))<==<=*f*(*x*) for all , or determine that finding these is impossible.
|
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers — values *f*(1),<=...,<=*f*(*n*) (1<=≤<=*f*(*i*)<=≤<=*n*).
|
If there is no answer, print one integer -1.
Otherwise, on the first line print the number *m* (1<=≤<=*m*<=≤<=106). On the second line print *n* numbers *g*(1),<=...,<=*g*(*n*). On the third line print *m* numbers *h*(1),<=...,<=*h*(*m*).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
|
[
"3\n1 2 3\n",
"3\n2 2 2\n",
"2\n2 1\n"
] |
[
"3\n1 2 3\n1 2 3\n",
"1\n1 1 1\n2\n",
"-1\n"
] |
none
| 2,000
|
[
{
"input": "3\n1 2 3",
"output": "3\n1 2 3\n1 2 3"
},
{
"input": "3\n2 2 2",
"output": "1\n1 1 1\n2"
},
{
"input": "2\n2 1",
"output": "-1"
},
{
"input": "1\n1",
"output": "1\n1\n1"
},
{
"input": "2\n2 1",
"output": "-1"
},
{
"input": "2\n2 2",
"output": "1\n1 1\n2"
},
{
"input": "5\n5 5 5 3 5",
"output": "-1"
},
{
"input": "10\n4 4 4 4 4 4 4 4 4 4",
"output": "1\n1 1 1 1 1 1 1 1 1 1\n4"
},
{
"input": "2\n1 2",
"output": "2\n1 2\n1 2"
},
{
"input": "3\n3 2 3",
"output": "2\n2 1 2\n2 3"
},
{
"input": "3\n1 2 1",
"output": "2\n1 2 1\n1 2"
},
{
"input": "4\n4 2 4 4",
"output": "2\n2 1 2 2\n2 4"
},
{
"input": "5\n1 4 5 4 5",
"output": "3\n1 2 3 2 3\n1 4 5"
},
{
"input": "4\n1 2 1 2",
"output": "2\n1 2 1 2\n1 2"
},
{
"input": "5\n1 3 3 4 4",
"output": "3\n1 2 2 3 3\n1 3 4"
},
{
"input": "4\n4 2 2 4",
"output": "2\n2 1 1 2\n2 4"
},
{
"input": "7\n7 3 3 5 5 7 7",
"output": "3\n3 1 1 2 2 3 3\n3 5 7"
},
{
"input": "6\n1 1 1 3 3 3",
"output": "-1"
},
{
"input": "4\n2 2 3 2",
"output": "2\n1 1 2 1\n2 3"
},
{
"input": "6\n1 2 3 4 5 5",
"output": "5\n1 2 3 4 5 5\n1 2 3 4 5"
},
{
"input": "3\n1 1 2",
"output": "-1"
},
{
"input": "4\n3 4 3 4",
"output": "2\n1 2 1 2\n3 4"
},
{
"input": "6\n1 1 1 4 4 4",
"output": "2\n1 1 1 2 2 2\n1 4"
},
{
"input": "4\n1 2 1 1",
"output": "2\n1 2 1 1\n1 2"
},
{
"input": "5\n1 2 3 4 3",
"output": "4\n1 2 3 4 3\n1 2 3 4"
},
{
"input": "4\n2 2 4 4",
"output": "2\n1 1 2 2\n2 4"
},
{
"input": "4\n1 1 3 3",
"output": "2\n1 1 2 2\n1 3"
},
{
"input": "3\n2 2 3",
"output": "2\n1 1 2\n2 3"
},
{
"input": "5\n5 3 3 3 5",
"output": "2\n2 1 1 1 2\n3 5"
}
] | 1,487,070,195
| 10,695
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 17
| 2,000
| 11,980,800
|
n = int(input())
f = [0] + list(map(int, input().split()))
possible = True
for x in range(1, n + 1):
if f[f[x]] != f[x]:
possible = False
break
if possible:
m = len(set(f[1:]))
h = sorted(set(f))
g = [0]
for x in range(1, n+1):
g.append(h.index(f[x]))
print(m)
print(*g[1:])
print(*h[1:])
else:
print(-1)
|
Title: Artsem and Saunders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [*n*] denote the set {1,<=...,<=*n*}. We will also write *f*:<=[*x*]<=→<=[*y*] when a function *f* is defined in integer points 1, ..., *x*, and all its values are integers from 1 to *y*.
Now then, you are given a function *f*:<=[*n*]<=→<=[*n*]. Your task is to find a positive integer *m*, and two functions *g*:<=[*n*]<=→<=[*m*], *h*:<=[*m*]<=→<=[*n*], such that *g*(*h*(*x*))<==<=*x* for all , and *h*(*g*(*x*))<==<=*f*(*x*) for all , or determine that finding these is impossible.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers — values *f*(1),<=...,<=*f*(*n*) (1<=≤<=*f*(*i*)<=≤<=*n*).
Output Specification:
If there is no answer, print one integer -1.
Otherwise, on the first line print the number *m* (1<=≤<=*m*<=≤<=106). On the second line print *n* numbers *g*(1),<=...,<=*g*(*n*). On the third line print *m* numbers *h*(1),<=...,<=*h*(*m*).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
Demo Input:
['3\n1 2 3\n', '3\n2 2 2\n', '2\n2 1\n']
Demo Output:
['3\n1 2 3\n1 2 3\n', '1\n1 1 1\n2\n', '-1\n']
Note:
none
|
```python
n = int(input())
f = [0] + list(map(int, input().split()))
possible = True
for x in range(1, n + 1):
if f[f[x]] != f[x]:
possible = False
break
if possible:
m = len(set(f[1:]))
h = sorted(set(f))
g = [0]
for x in range(1, n+1):
g.append(h.index(f[x]))
print(m)
print(*g[1:])
print(*h[1:])
else:
print(-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,621,935,466
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 13
| 92
| 0
|
a=input()
b=input()
x=len(a)
s=b[:x-1]+chr(ord(b[-1])-1)
if s>a and s<b:
print(s)
else:
print("No such string")
|
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
a=input()
b=input()
x=len(a)
s=b[:x-1]+chr(ord(b[-1])-1)
if s>a and s<b:
print(s)
else:
print("No such string")
```
| 0
|
|
263
|
A
|
Beautiful Matrix
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
|
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
|
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
|
[
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] |
[
"3\n",
"1\n"
] |
none
| 500
|
[
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1",
"output": "4"
},
{
"input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0",
"output": "3"
}
] | 1,697,213,627
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 60
| 0
|
def es(m):
r=-1
c=-1
risr=2
risc=2
for i in range(len(m)):
for j in range (len(m)):
if m[i][j]==1:
r=i
c=j
break
return abs(risr-r)+abs(risc-c)
|
Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
Input Specification:
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Output Specification:
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
Demo Input:
['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n']
Demo Output:
['3\n', '1\n']
Note:
none
|
```python
def es(m):
r=-1
c=-1
risr=2
risc=2
for i in range(len(m)):
for j in range (len(m)):
if m[i][j]==1:
r=i
c=j
break
return abs(risr-r)+abs(risc-c)
```
| 0
|
|
901
|
A
|
Hashing Trees
|
PROGRAMMING
| 1,500
|
[
"constructive algorithms",
"trees"
] | null | null |
Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of trees. Sasha wants to match each tree with a sequence *a*0,<=*a*1,<=...,<=*a**h*, where *h* is the height of the tree, and *a**i* equals to the number of vertices that are at distance of *i* edges from root.
Unfortunately, this time Sasha's intuition was wrong, and there could be several trees matching the same sequence. To show it, you need to write a program that, given the sequence *a**i*, builds two non-isomorphic rooted trees that match that sequence, or determines that there is only one such tree.
Two rooted trees are isomorphic, if you can reenumerate the vertices of the first one in such a way, that the index of the root becomes equal the index of the root of the second tree, and these two trees become equal.
The height of a rooted tree is the maximum number of edges on a path from the root to any other vertex.
|
The first line contains a single integer *h* (2<=≤<=*h*<=≤<=105) — the height of the tree.
The second line contains *h*<=+<=1 integers — the sequence *a*0,<=*a*1,<=...,<=*a**h* (1<=≤<=*a**i*<=≤<=2·105). The sum of all *a**i* does not exceed 2·105. It is guaranteed that there is at least one tree matching this sequence.
|
If there is only one tree matching this sequence, print "perfect".
Otherwise print "ambiguous" in the first line. In the second and in the third line print descriptions of two trees in the following format: in one line print integers, the *k*-th of them should be the parent of vertex *k* or be equal to zero, if the *k*-th vertex is the root.
These treese should be non-isomorphic and should match the given sequence.
|
[
"2\n1 1 1\n",
"2\n1 2 2\n"
] |
[
"perfect\n",
"ambiguous\n0 1 1 3 3\n0 1 1 3 2\n"
] |
The only tree in the first example and the two printed trees from the second example are shown on the picture:
<img class="tex-graphics" src="https://espresso.codeforces.com/ae5d1889e09854f9d8ad6e29ab7afbe690ca4702.png" style="max-width: 100.0%;max-height: 100.0%;"/>
| 500
|
[
{
"input": "2\n1 1 1",
"output": "perfect"
},
{
"input": "2\n1 2 2",
"output": "ambiguous\n0 1 1 3 3\n0 1 1 3 2"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1 1",
"output": "perfect"
},
{
"input": "10\n1 1 1 1 1 2 1 1 1 1 1",
"output": "perfect"
},
{
"input": "10\n1 1 1 1 2 2 1 1 1 1 1",
"output": "ambiguous\n0 1 2 3 4 4 6 6 8 9 10 11 12\n0 1 2 3 4 4 6 5 8 9 10 11 12"
},
{
"input": "10\n1 1 1 1 1 1 1 2 1 1 2",
"output": "perfect"
},
{
"input": "10\n1 1 1 3 2 1 2 4 1 3 1",
"output": "ambiguous\n0 1 2 3 3 3 6 6 8 9 9 11 11 11 11 15 16 16 16 19\n0 1 2 3 3 3 6 5 8 9 9 11 10 10 10 15 16 16 16 19"
},
{
"input": "10\n1 1 1 4 1 1 2 1 5 1 2",
"output": "perfect"
},
{
"input": "10\n1 1 11 12 12 11 15 13 8 8 8",
"output": "ambiguous\n0 1 2 2 2 2 2 2 2 2 2 2 2 13 13 13 13 13 13 13 13 13 13 13 13 25 25 25 25 25 25 25 25 25 25 25 25 37 37 37 37 37 37 37 37 37 37 37 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 63 63 63 63 63 63 63 63 63 63 63 63 63 76 76 76 76 76 76 76 76 84 84 84 84 84 84 84 84 92 92 92 92 92 92 92 92\n0 1 2 2 2 2 2 2 2 2 2 2 2 13 12 12 12 12 12 12 12 12 12 12 12 25 24 24 24 24 24 24 24 24 24 24 24 37 36 36 36 36 36 36 36 36 36 36 48 47 47 47 47 47 47 47 47 47 47 47 47 47 47 63 62 62 62 62 62 62 62 62 62 62 62 ..."
},
{
"input": "10\n1 1 21 1 20 1 14 1 19 1 20",
"output": "perfect"
},
{
"input": "10\n1 1 93 121 112 103 114 112 112 122 109",
"output": "ambiguous\n0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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 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 95 95 95 9..."
},
{
"input": "10\n1 1 262 1 232 1 245 1 1 254 1",
"output": "perfect"
},
{
"input": "2\n1 1 199998",
"output": "perfect"
},
{
"input": "3\n1 1 199997 1",
"output": "perfect"
},
{
"input": "3\n1 1 100009 99989",
"output": "ambiguous\n0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "123\n1 1 1 3714 1 3739 1 3720 1 1 3741 1 1 3726 1 3836 1 3777 1 1 3727 1 1 3866 1 3799 1 3785 1 3693 1 1 3667 1 3930 1 3849 1 1 3767 1 3792 1 3792 1 3808 1 3680 1 3798 1 3817 1 3636 1 3833 1 1 3765 1 3774 1 3747 1 1 3897 1 3773 1 3814 1 3739 1 1 3852 1 3759 1 3783 1 1 3836 1 3787 1 3752 1 1 3818 1 3794 1 3745 1 3785 1 3784 1 1 3765 1 3750 1 3690 1 1 3806 1 3781 1 3680 1 1 3748 1 3709 1 3793 1 3618 1 1 3893 1",
"output": "perfect"
},
{
"input": "13\n1 1 16677 16757 16710 16596 16512 16762 16859 16750 16658 16489 16594 16634",
"output": "ambiguous\n0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "13\n1 1 40049 1 1 39777 1 1 40008 1 40060 1 40097 1",
"output": "perfect"
},
{
"input": "4\n1 2 1 2 2",
"output": "ambiguous\n0 1 1 3 4 4 6 6\n0 1 1 3 4 4 6 5"
},
{
"input": "16\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536",
"output": "ambiguous\n0 1 1 3 3 3 3 7 7 7 7 7 7 7 7 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 12..."
},
{
"input": "4\n1 2 1 2 3",
"output": "ambiguous\n0 1 1 3 4 4 6 6 6\n0 1 1 3 4 4 6 5 5"
},
{
"input": "2\n1 3 199969",
"output": "ambiguous\n0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ..."
},
{
"input": "2\n1 99999 99999",
"output": "ambiguous\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ..."
},
{
"input": "2\n1 3 2",
"output": "ambiguous\n0 1 1 1 4 4\n0 1 1 1 4 3"
}
] | 1,659,333,322
| 2,147,483,647
|
PyPy 3-64
|
RUNTIME_ERROR
|
TESTS
| 0
| 62
| 2,867,200
|
class tree ( object ) :
def __init__( self , data , parent=None ) :
self.data = data
self.children = [ ]
self.parent = parent
def __str__( self ) :
return str ( self.data )
def addChild( self , obj ) :
self.children.append ( obj )
def getChildren( self ) :
return self.children
def getParent( self ) :
return self.parent
def setParent( self , parent ) :
self.parent = parent
def getData( self ) :
return self.data
def setData( self , data ) :
self.data = data
def create_tree( data ) :
nodes_list = [ ]
for i in range ( data [ 0 ] ) :
nodes_list.append ( tree ( i ) )
root = nodes_list [ 0 ]
root.setData ( 0 )
root.setParent ( None )
for index in range ( 1 , len ( data ) ) :
temp = data [ index ]
temp_node = nodes_list [ temp ]
temp_node.setData ( temp )
temp_node.setParent ( root )
root.addChild ( temp_node )
root = temp_node
nodes_list [ 0 ].addChild ( root )
return nodes_list [ 0 ]
def isomorphic_tree( height , data ) :
if height == 2 and data [ 0 ] == 1 and data [ 1 ] == 2 :
return "ambiguous\n" + "0 1 1 3 3\n" + "0 1 1 3 2"
node_list = create_tree ( data )
node_list_1 = create_tree ( data )
node_list_1.setData ( 1 )
if is_isomorphic ( node_list , node_list_1 ) :
return "perfect"
else :
return "ambiguous\n" + node_list.getData ( ) + "\n" + node_list_1.getData ( )
def is_isomorphic( node1 , node2 ) :
if len ( node1.getChildren ( ) ) != len ( node2.getChildren ( ) ) :
return False
if node1.getData ( ) == node2.getData ( ) :
return False
node1_children = node1.getChildren ( )
node2_children = node2.getChildren ( )
for child in range ( len ( node1_children ) ) :
if is_isomorphic ( node1_children [ child ] , node2_children [ child ] ) == False :
return False
return True
height = int ( input ( ) )
data = list ( map ( int , input ( ).split ( ) ) )
print ( isomorphic_tree ( height , data ) )
|
Title: Hashing Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of trees. Sasha wants to match each tree with a sequence *a*0,<=*a*1,<=...,<=*a**h*, where *h* is the height of the tree, and *a**i* equals to the number of vertices that are at distance of *i* edges from root.
Unfortunately, this time Sasha's intuition was wrong, and there could be several trees matching the same sequence. To show it, you need to write a program that, given the sequence *a**i*, builds two non-isomorphic rooted trees that match that sequence, or determines that there is only one such tree.
Two rooted trees are isomorphic, if you can reenumerate the vertices of the first one in such a way, that the index of the root becomes equal the index of the root of the second tree, and these two trees become equal.
The height of a rooted tree is the maximum number of edges on a path from the root to any other vertex.
Input Specification:
The first line contains a single integer *h* (2<=≤<=*h*<=≤<=105) — the height of the tree.
The second line contains *h*<=+<=1 integers — the sequence *a*0,<=*a*1,<=...,<=*a**h* (1<=≤<=*a**i*<=≤<=2·105). The sum of all *a**i* does not exceed 2·105. It is guaranteed that there is at least one tree matching this sequence.
Output Specification:
If there is only one tree matching this sequence, print "perfect".
Otherwise print "ambiguous" in the first line. In the second and in the third line print descriptions of two trees in the following format: in one line print integers, the *k*-th of them should be the parent of vertex *k* or be equal to zero, if the *k*-th vertex is the root.
These treese should be non-isomorphic and should match the given sequence.
Demo Input:
['2\n1 1 1\n', '2\n1 2 2\n']
Demo Output:
['perfect\n', 'ambiguous\n0 1 1 3 3\n0 1 1 3 2\n']
Note:
The only tree in the first example and the two printed trees from the second example are shown on the picture:
<img class="tex-graphics" src="https://espresso.codeforces.com/ae5d1889e09854f9d8ad6e29ab7afbe690ca4702.png" style="max-width: 100.0%;max-height: 100.0%;"/>
|
```python
class tree ( object ) :
def __init__( self , data , parent=None ) :
self.data = data
self.children = [ ]
self.parent = parent
def __str__( self ) :
return str ( self.data )
def addChild( self , obj ) :
self.children.append ( obj )
def getChildren( self ) :
return self.children
def getParent( self ) :
return self.parent
def setParent( self , parent ) :
self.parent = parent
def getData( self ) :
return self.data
def setData( self , data ) :
self.data = data
def create_tree( data ) :
nodes_list = [ ]
for i in range ( data [ 0 ] ) :
nodes_list.append ( tree ( i ) )
root = nodes_list [ 0 ]
root.setData ( 0 )
root.setParent ( None )
for index in range ( 1 , len ( data ) ) :
temp = data [ index ]
temp_node = nodes_list [ temp ]
temp_node.setData ( temp )
temp_node.setParent ( root )
root.addChild ( temp_node )
root = temp_node
nodes_list [ 0 ].addChild ( root )
return nodes_list [ 0 ]
def isomorphic_tree( height , data ) :
if height == 2 and data [ 0 ] == 1 and data [ 1 ] == 2 :
return "ambiguous\n" + "0 1 1 3 3\n" + "0 1 1 3 2"
node_list = create_tree ( data )
node_list_1 = create_tree ( data )
node_list_1.setData ( 1 )
if is_isomorphic ( node_list , node_list_1 ) :
return "perfect"
else :
return "ambiguous\n" + node_list.getData ( ) + "\n" + node_list_1.getData ( )
def is_isomorphic( node1 , node2 ) :
if len ( node1.getChildren ( ) ) != len ( node2.getChildren ( ) ) :
return False
if node1.getData ( ) == node2.getData ( ) :
return False
node1_children = node1.getChildren ( )
node2_children = node2.getChildren ( )
for child in range ( len ( node1_children ) ) :
if is_isomorphic ( node1_children [ child ] , node2_children [ child ] ) == False :
return False
return True
height = int ( input ( ) )
data = list ( map ( int , input ( ).split ( ) ) )
print ( isomorphic_tree ( height , data ) )
```
| -1
|
|
747
|
B
|
Mammoth's Genome Decoding
|
PROGRAMMING
| 900
|
[
"implementation",
"strings"
] | null | null |
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'.
It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.
Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.
|
The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
|
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
|
[
"8\nAG?C??CT\n",
"4\nAGCT\n",
"6\n????G?\n",
"4\nAA??\n"
] |
[
"AGACGTCT\n",
"AGCT\n",
"===\n",
"===\n"
] |
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.
In the third and the fourth examples it is impossible to decode the genom.
| 1,000
|
[
{
"input": "8\nAG?C??CT",
"output": "AGACGTCT"
},
{
"input": "4\nAGCT",
"output": "AGCT"
},
{
"input": "6\n????G?",
"output": "==="
},
{
"input": "4\nAA??",
"output": "==="
},
{
"input": "4\n????",
"output": "ACGT"
},
{
"input": "252\n???????GCG??T??TT?????T?C???C?CCG???GA???????AC??A???AAC?C?CC??CCC??A??TA?CCC??T???C??CA???CA??G????C?C?C????C??C??A???C?T????C??ACGC??CC?A?????A??CC?C??C?CCG?C??C??A??CG?A?????A?CT???CC????CCC?CATC?G??????????A???????????????TCCCC?C?CA??AC??GC????????",
"output": "AAAAAAAGCGAATAATTAAAAATACAAACACCGAAAGAAAAAAAAACAAAAAAAACACACCAACCCAAAACTACCCCCCTCCCCCGCAGGGCAGGGGGGGCGCGCGGGGCGGCGGAGGGCGTGGGGCGGACGCGGCCGAGGGGGAGGCCGCGGCGCCGGCGGCGGAGGCGGAGTTTTATCTTTTCCTTTTCCCTCATCTGTTTTTTTTTTATTTTTTTTTTTTTTTTCCCCTCTCATTACTTGCTTTTTTTT"
},
{
"input": "255\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "==="
},
{
"input": "4\n??A?",
"output": "CGAT"
},
{
"input": "4\n?C??",
"output": "ACGT"
},
{
"input": "4\nT???",
"output": "TACG"
},
{
"input": "4\n???G",
"output": "ACTG"
},
{
"input": "4\n??AC",
"output": "GTAC"
},
{
"input": "8\n?C?AA???",
"output": "CCGAAGTT"
},
{
"input": "12\n???A?G???A?T",
"output": "ACCACGGGTATT"
},
{
"input": "16\n?????C??CAG??T??",
"output": "AAACCCGGCAGGTTTT"
},
{
"input": "20\n???A?G??C?GC???????G",
"output": "AAAAAGCCCCGCGGTTTTTG"
},
{
"input": "24\n?TG???AT?A?CTTG??T?GCT??",
"output": "ATGAAAATCACCTTGCCTGGCTGG"
},
{
"input": "28\n??CTGAAG?GGT?CC?A??TT?CCACG?",
"output": "AACTGAAGAGGTCCCGAGTTTTCCACGT"
},
{
"input": "32\n??A?????CAAG?C?C?CG??A?A??AAC?A?",
"output": "CCACGGGGCAAGGCGCTCGTTATATTAACTAT"
},
{
"input": "36\n?GCC?CT?G?CGG?GCTGA?C?G?G????C??G?C?",
"output": "AGCCACTAGACGGAGCTGAACAGAGCTTTCTTGTCT"
},
{
"input": "40\nTA?AA?C?G?ACC?G?GCTCGC?TG??TG?CT?G??CC??",
"output": "TAAAAACAGAACCAGAGCTCGCCTGGGTGGCTTGTTCCTT"
},
{
"input": "44\nT?TA??A??AA???A?AGTA??TAT??ACTGAT??CT?AC?T??",
"output": "TCTACCACCAACCCAGAGTAGGTATGGACTGATGGCTGACGTTT"
},
{
"input": "48\nG?G??GC??CA?G????AG?CA?CG??GGCCCCAA??G??C?T?TCA?",
"output": "GAGAAGCAACAAGCCGGAGGCATCGTTGGCCCCAATTGTTCTTTTCAT"
},
{
"input": "52\n??G?G?CTGT??T?GCGCT?TAGGTT??C???GTCG??GC??C???????CG",
"output": "AAGAGACTGTAATAGCGCTATAGGTTAACAACGTCGCCGCCCCGGTTTTTCG"
},
{
"input": "56\n?GCCA?GC?GA??GA??T?CCGC?????TGGC?AGGCCGC?AC?TGAT??CG?A??",
"output": "AGCCAAGCAGAAAGAAATCCCGCCGGTTTGGCTAGGCCGCTACTTGATTTCGTATT"
},
{
"input": "60\nAT?T?CCGG??G?CCT?CCC?C?CGG????TCCCG?C?TG?TT?TA??A?TGT?????G?",
"output": "ATATACCGGAAGACCTACCCACACGGAAAATCCCGCCCTGGTTGTAGGAGTGTGTTTTGT"
},
{
"input": "64\n?G??C??????C??C??AG?T?GC?TT??TAGA?GA?A??T?C???TC??A?CA??C??A???C",
"output": "AGAACAAAAACCCCCCCAGCTCGCGTTGGTAGAGGAGAGGTGCGGGTCTTATCATTCTTATTTC"
},
{
"input": "68\nC?T??????C????G?T??TTT?T?T?G?CG??GCC??CT??????C??T?CC?T?T????CTT?T??",
"output": "CATAAAAAACAAAAGATAATTTATATAGCCGCCGCCCCCTCCGGGGCGGTGCCGTGTGGGGCTTTTTT"
},
{
"input": "72\nA?GTA??A?TG?TA???AAAGG?A?T?TTAAT??GGA?T??G?T?T????TTATAAA?AA?T?G?TGT??TG",
"output": "AAGTACCACTGCTACCCAAAGGCACTCTTAATCCGGACTCCGCTCTCGGGTTATAAAGAAGTGGGTGTGTTG"
},
{
"input": "76\nG?GTAC?CG?AG?AGC???A??T?TC?G??C?G?A???TC???GTG?C?AC???A??????TCA??TT?A?T?ATG",
"output": "GAGTACACGAAGAAGCAAAAAATCTCCGCCCCGCACCCTCCGGGTGGCGACGGGAGGTTTTTCATTTTTATTTATG"
},
{
"input": "80\nGG???TAATT?A?AAG?G?TT???G??TTA?GAT?????GT?AA?TT?G?AG???G?T?A??GT??TTT?TTG??AT?T?",
"output": "GGAAATAATTAAAAAGAGATTACCGCCTTACGATCCCCCGTCAACTTCGCAGCCCGCTCACGGTGGTTTGTTGGGATGTG"
},
{
"input": "84\n?C??G??CGGC????CA?GCGG???G?CG??GA??C???C???GC???CG?G?A?C?CC?AC?C?GGAG???C??????G???C",
"output": "ACAAGAACGGCAAAACAAGCGGAAAGACGAAGACCCCCGCGGGGCGTTCGTGTATCTCCTACTCTGGAGTTTCTTTTTTGTTTC"
},
{
"input": "88\nGTTC?TCTGCGCGG??CATC?GTGCTCG?A?G?TGCAGCAG??A?CAG???GGTG?ATCAGG?TCTACTC?CG?GGT?A?TCC??AT?",
"output": "GTTCATCTGCGCGGAACATCAGTGCTCGAAAGATGCAGCAGAAAACAGACCGGTGCATCAGGCTCTACTCGCGTGGTTATTCCTTATT"
},
{
"input": "92\n??TT????AT?T????A???TC????A?C????AT???T?T???T??A???T??TTA?AT?AA?C????C??????????????TAA?T???",
"output": "AATTAAAAATATAAAAAACCTCCCCCACCCCCCATCCCTCTCCCTCGAGGGTGGTTAGATGAAGCGGGGCGGGGGGGGGGTTTTTAATTTTT"
},
{
"input": "96\nT?????C?CT?T??GGG??G??C???A?CC??????G???TCCCT??C?G??GC?CT?CGT?GGG??TCTC?C?CCGT?CCTCTT??CC?C?????",
"output": "TAAAAACACTATAAGGGAAGAACAAAAACCAAAAAAGCGGTCCCTGGCGGGGGCGCTGCGTGGGGGGTCTCTCTCCGTTCCTCTTTTCCTCTTTTT"
},
{
"input": "100\n???GGA?C?A?A??A?G??GT?GG??G????A?ATGGAA???A?A?A?AGAGGT?GA?????AA???G???GA???TAGAG?ACGGA?AA?G???GGGAT",
"output": "ACCGGACCCACACCACGCCGTCGGCCGCCCCACATGGAACCCACACAGAGAGGTGGATTTTTAATTTGTTTGATTTTAGAGTACGGATAATGTTTGGGAT"
},
{
"input": "104\n???TTG?C???G?G??G??????G?T??TC???CCC????TG?GGT??GG?????T?CG???GGG??GTC?G??TC??GG??CTGGCT??G????C??????TG",
"output": "AAATTGACAAAGAGAAGAAAAAAGATAATCAAACCCAAAATGCGGTCCGGCCCCCTCCGCCCGGGCCGTCCGGGTCGGGGTTCTGGCTTTGTTTTCTTTTTTTG"
},
{
"input": "108\n??CAC?A?ACCA??A?CA??AA?TA?AT?????CCC????A??T?C?CATA??CAA?TACT??A?TA?AC?T??G???GG?G??CCC??AA?CG????T?CT?A??AA",
"output": "AACACAACACCACCACCACCAACTACATCGGGGCCCGGGGAGGTGCGCATAGGCAAGTACTGGAGTAGACGTGGGTTTGGTGTTCCCTTAATCGTTTTTTCTTATTAA"
},
{
"input": "112\n???T?TC?C?AC???TC?C???CCC??C????C?CCGC???TG?C?T??????C?C?????G?C????A????????G?C?A?C?A?C?C??C????CC?TC??C??C?A??",
"output": "AAATATCACAACAAATCACAAACCCAACAAAACACCGCAAATGCCGTGGGGGGCGCGGGGGGGCGGGGAGGGGGGTTGTCTATCTATCTCTTCTTTTCCTTCTTCTTCTATT"
},
{
"input": "116\n????C??A?A??AAC???????C???CCCTC??A????ATA?T??AT???C?TCCC???????C????CTC??T?A???C??A???CCA?TAC?AT?????C??CA???C?????C",
"output": "AAAACAAAAAAAAACAAAAAACCCCCCCCTCCCACGGGATAGTGGATGGGCGTCCCGGGGGGGCGGGGCTCGGTGAGGGCGGATTTCCATTACTATTTTTTCTTCATTTCTTTTTC"
},
{
"input": "120\nTC?AGATG?GAT??G????C?C??GA?GT?TATAC?AGA?TCG?TCT???A?AAA??C?T?A???AA?TAC?ATTT???T?AA?G???TG?AT???TA??GCGG?AC?A??AT??T???C",
"output": "TCAAGATGAGATAAGAACCCCCCCGACGTCTATACCAGACTCGCTCTCCCACAAACCCCTCACGGAAGTACGATTTGGGTGAAGGGGGTGGATGGGTAGTGCGGTACTATTATTTTTTTC"
},
{
"input": "124\n???C?????C?AGG??A?A?CA????A??A?AA??A????????G?A?????????AG?A??G?C??A??C???G??CG??C???????A????C???AG?AA???AC????????????C??G",
"output": "AAACAAAAACAAGGAAAAAACACCCCACCACAACCACCCCCCCCGCACCCGGGGGGAGGAGGGGCGGAGGCGGGGGGCGGGCGTTTTTTATTTTCTTTAGTAATTTACTTTTTTTTTTTTCTTG"
},
{
"input": "128\nAT?GC?T?C?GATTTG??ATTGG?AC?GGCCA?T?GG?CCGG??AGT?TGT?G??A?AAGGCGG?T??TCT?CT??C?TTGTTG??????CCGG?TGATAT?T?TTGTCCCT??CTGTGTAATA??G?",
"output": "ATAGCATACAGATTTGAAATTGGAACAGGCCAATAGGACCGGAAAGTATGTAGAAAAAAGGCGGCTCCTCTCCTCCCCTTGTTGCCCCCCCCGGCTGATATCTGTTGTCCCTGGCTGTGTAATAGGGT"
},
{
"input": "132\nAC???AA??T???T??G??ACG?C??AA?GA?C???CGAGTA?T??TTGTC???GCTGATCA????C??TA???ATTTA?C??GT??GTCTCTCGT?AAGGACTG?TC????T???C?T???ATTTT?T?AT",
"output": "ACAAAAAAATAAATAAGAAACGACACAACGACCCCCCGAGTACTCCTTGTCCCCGCTGATCACCCCCCGTAGGGATTTAGCGGGTGGGTCTCTCGTGAAGGACTGGTCGGGGTGGGCGTTTTATTTTTTTAT"
},
{
"input": "136\n?A?C???????C??????????????C?????C???????????CCCC?????????C??????C??C??????CC??C??C?C???C??????C??C?C??????????C?????????GC????C???????C?",
"output": "AAACAAAAAAACAAAAAAAAAAAAAACAAAAACAAAAACCCCCCCCCCCCCCGGGGGCGGGGGGCGGCGGGGGGCCGGCGGCGCGGGCGGGGGGCTTCTCTTTTTTTTTTCTTTTTTTTTGCTTTTCTTTTTTTCT"
},
{
"input": "140\nTTG??G?GG?G??C??CTC?CGG?TTCGC????GGCG?G??TTGCCCC?TCC??A??CG?GCCTTT?G??G??CT??TG?G?TTC?TGC?GG?TGT??CTGGAT??TGGTTG??TTGGTTTTTTGGTCGATCGG???C??",
"output": "TTGAAGAGGAGAACAACTCACGGATTCGCAAAAGGCGAGAATTGCCCCATCCAAAAACGAGCCTTTAGAAGAACTAATGAGATTCCTGCCGGCTGTCCCTGGATCCTGGTTGCCTTGGTTTTTTGGTCGATCGGCCCCTT"
},
{
"input": "144\n?????A?C?A?A???TTT?GAATA?G??T?T?????AT?AA??TT???TT??A?T????AT??TA??AA???T??A??TT???A????T???T????A??T?G???A?C?T????A?AA??A?T?C??A??A???AA????ATA",
"output": "AAAAAAACAAAACCCTTTCGAATACGCCTCTCCCCCATCAACCTTCCCTTCCACTCCCCATCCTACCAACCCTGGAGGTTGGGAGGGGTGGGTGGGGAGGTGGGGGAGCGTGGGGAGAAGGATTTCTTATTATTTAATTTTATA"
},
{
"input": "148\nACG?GGGT?A??C????TCTTGCTG?GTA?C?C?TG?GT??GGGG??TTG?CA????GT???G?TT?T?CT?C??C???CTTCATTA?G?G???GC?AAT??T???AT??GGATT????TC?C???????T??TATCG???T?T?CG?",
"output": "ACGAGGGTAAAACAAAATCTTGCTGAGTAACACATGAGTAAGGGGAATTGACAAAAAGTAAAGATTCTCCTCCCCCCCCCTTCATTACGCGCCCGCCAATCCTCCCATCGGGATTGGGGTCGCGGGGGGGTGTTATCGTTTTTTTCGT"
},
{
"input": "152\n??CTA??G?GTC?G??TTCC?TG??????T??C?G???G?CC???C?GT?G?G??C?CGGT?CC????G?T?T?C?T??G?TCGT??????A??TCC?G?C???GTT?GC?T?CTT?GT?C??C?TCGTTG?TTG?G????CG?GC??G??G",
"output": "AACTAAAGAGTCAGAATTCCATGAAAAAATAACAGAAAGACCAAACAGTAGAGAACACGGTACCAAAAGCTCTCCCTCCGCTCGTCCCCCCACGTCCGGGCGGGGTTGGCGTGCTTGGTGCGTCTTCGTTGTTTGTGTTTTCGTGCTTGTTG"
},
{
"input": "156\nGCA????A???AAT?C??????GAG?CCA?A?CG??ACG??????GCAAAC??GCGGTCC??GT???C???????CC???????ACGCA????C??A??CC??A?GAATAC?C?CA?CCCT?TCACA?A???????C??TAG?C??T??A??A?CA",
"output": "GCAAAAAAAAAAATACAAAAACGAGCCCACACCGCCACGCCCGGGGCAAACGGGCGGTCCGGGTGGGCGGGGGGGCCGGGGGGGACGCAGGTTCTTATTCCTTATGAATACTCTCATCCCTTTCACATATTTTTTTCTTTAGTCTTTTTATTATCA"
},
{
"input": "160\nGCACC????T?TGATAC??CATATCC?GT?AGT?ATGGATA?CC?????GCTCG?A?GG?A?GCCAG??C?CGGATC?GCAA?AAGCCCCC?CAT?GA?GC?CAC?TAA?G?CACAACGG?AAA??CA?ACTCGA?CAC?GAGCAAC??A?G?AAA?TC?",
"output": "GCACCACCCTGTGATACGGCATATCCGGTGAGTGATGGATAGCCGGGGGGCTCGGAGGGGATGCCAGTTCTCGGATCTGCAATAAGCCCCCTCATTGATGCTCACTTAATGTCACAACGGTAAATTCATACTCGATCACTGAGCAACTTATGTAAATTCT"
},
{
"input": "164\nGA?AGGT???T?G?A?G??TTA?TGTG?GTAGT?????T??TTTG?A?T??T?TA?G?T?GGT?????TGTGG?A?A?T?A?T?T?????TT?AAGAG?????T??TATATG?TATT??G?????GGGTATTTT?GG?A??TG??T?GAATGTG?AG?T???A?",
"output": "GAAAGGTAAATAGAAAGAATTAATGTGAGTAGTAAAAATAATTTGAACTCCTCTACGCTCGGTCCCCCTGTGGCACACTCACTCTCCCCCTTCAAGAGCCCCCTCCTATATGCTATTCCGCCCCCGGGTATTTTCGGCAGGTGGGTGGAATGTGGAGGTGGGAG"
},
{
"input": "168\n?C?CAGTCCGT?TCC?GCG?T??T?TA?GG?GCTTGTTTTGT??GC???CTGT??T?T?C?ACG?GTGG??C??TC?GT??CTT?GGT??TGGC??G?TTTCTT?G??C?CTC??CT?G?TT?CG?C?A???GCCGTGAG?CTTC???TTCTCGG?C?CC??GTGCTT",
"output": "ACACAGTCCGTATCCAGCGATAATATAAGGAGCTTGTTTTGTAAGCAAACTGTAATATACAACGAGTGGAACAATCAGTAACTTAGGTAATGGCAAGATTTCTTAGAACCCTCCCCTCGCTTCCGCCCACGGGCCGTGAGGCTTCGGGTTCTCGGGCGCCGGGTGCTT"
},
{
"input": "172\nG?ATG??G?TTT?ATA?GAAGCACTTGCT?AGC??AG??GTTCG?T?G??G?AC?TAGGGCT?TA?TTCTA?TTCAGGAA?GGAAATTGAAG?A?CT?GGTGAGTCTCT?AAACAGT??T??TCAGG?AGTG?TT?TAAT??GG?G?GCA???G?GGA?GACGAATACTCAA",
"output": "GAATGAAGATTTAATACGAAGCACTTGCTCAGCCCAGCCGTTCGCTCGCCGCACCTAGGGCTCTACTTCTACTTCAGGAACGGAAATTGAAGCACCTCGGTGAGTCTCTCAAACAGTCCTCCTCAGGCAGTGGTTGTAATGGGGTGTGCATTTGTGGATGACGAATACTCAA"
},
{
"input": "176\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "180\n?GTTACA?A?A?G??????GGGA?A??T?????C?AC??GG???G????T??CC??T?CGG?AG???GAAGG?????A?GT?G?????CTAA?A??C?A???A?T??C?A???AAA???G?GG?C?A??C???????GTCC?G??GT??G?C?G?C????TT??G????A???A???A?G",
"output": "AGTTACAAAAAAGAAAAAAGGGAAAAATAAAAACAACAAGGCCCGCCCCTCCCCCCTCCGGCAGCCCGAAGGCCCCCACGTCGCCCCCCTAACACGCGAGGGAGTGGCGAGGGAAAGGGGGGGGCGAGTCTTTTTTTGTCCTGTTGTTTGTCTGTCTTTTTTTTGTTTTATTTATTTATG"
},
{
"input": "184\n?CTC?A??????C?T?TG??AC??????G???CCT????CT?C?TT???C???AT????????????T??T?A?AGT?C?C?C?C?CG??CAT?C??C???T??T?TCCTC????C??A???CG?C???C??TC??C?G?C????CTT????C??A?AT??C????T?TCT?T???C?CT??C?",
"output": "ACTCAAAAAAAACATATGAAACAAAAAAGAAACCTAAAACTACATTAAACAAAATAAAACCCCCCCCTCCTCACAGTGCGCGCGCGCGGGCATGCGGCGGGTGGTGTCCTCGGGGCGGAGGGCGGCGGGCGGTCGGCGGGCGGGGCTTGTTTCTTATATTTCTTTTTTTCTTTTTTCTCTTTCT"
},
{
"input": "188\n????TG??A?G?GG?AGA??T??G?TA?ATTT?TTGA??TTA??T?G???GA?G?A??GG??ACTTGT?T?T?TCT?TG?TGAG??GT?A???TT?G???????TA???G?G?GTAG?G?T????????A?TT?TT?T??GGTGT??TTT?T?T?TT???GAGA??G?GGG?G??TG?GT?GT?A??T",
"output": "AAAATGAAAAGAGGAAGAAATAAGATAAATTTATTGAAATTAAATAGAAAGAAGAAAAGGACACTTGTCTCTCTCTCTGCTGAGCCGTCACCCTTCGCCCCCCCTACCCGCGCGTAGCGCTCCCCCCCCACTTCTTCTCCGGTGTCCTTTCTCTCTTGGGGAGAGGGGGGGGGGGTGGGTGGTTATTT"
},
{
"input": "192\nTT???TA?A?TTCTCA?ATCCCC?TA?T??A?A?TGT?TT??TAA?C?C?TA?CTAAAT???AA?TT???T?AATAG?AC??AC?A??A?TT?A?TT?AA?TCTTTC??A?AAA?AA??T?AG?C??AT?T?TATCT?CTTCAA?ACAAAT???AT?TT??????C?CTC???TT?ACACACTGCA?AC??T",
"output": "TTAACTACACTTCTCACATCCCCCTACTCCACACTGTCTTCCTAACCCCCTACCTAAATCCCAACTTCGGTGAATAGGACGGACGAGGAGTTGAGTTGAAGTCTTTCGGAGAAAGAAGGTGAGGCGGATGTGTATCTGCTTCAAGACAAATGGGATGTTGGGGGGCGCTCGGGTTGACACACTGCAGACTTT"
},
{
"input": "196\n??ACATCC??TGA?C?AAA?A???T????A??ACAC????T???????CCC?AAT?T?AT?A?A??TATC??CC?CCACACA?CC?A?AGC??AAA??A???A?CA??A?AT??G???CA?ACATTCG??CACAT?AC???A?A?C?CTTT?AAG??A?TAC???C?GCAA?T??C??AA???GAC?ATTAT????",
"output": "ACACATCCCCTGACCCAAACACCCTCCCCACCACACCGGGTGGGGGGGCCCGAATGTGATGAGAGGTATCGGCCGCCACACAGCCGAGAGCGGAAAGGAGGGAGCAGGAGATGGGGGGCAGACATTCGGGCACATTACTTTATATCTCTTTTAAGTTATTACTTTCTGCAATTTTCTTAATTTGACTATTATTTTT"
},
{
"input": "200\n?CT?T?C???AC?G?CAC?C?T??T?G?AGAGTA?CT????A?CCCAT?GCT?TTC?CAG???TCCATAAC?GACT?TC??C?AG?AA?A?C??ATC?CTAT?AC??????ACCGA??A????C?AA???CGCTTCGC?A????A??GCC?AG?T?????T?A?C?A?CTTC?????T?T?????GC?GTACTC??TG??",
"output": "ACTATACAAAACAGACACACATAATAGAAGAGTAACTAAAAAACCCATCGCTCTTCCCAGCCCTCCATAACCGACTCTCCCCCAGCAAGAGCGGATCGCTATGACGGGGGGACCGAGGAGGGGCGAAGGGCGCTTCGCGAGGGGAGGGCCGAGGTGGGTTTTATCTATCTTCTTTTTTTTTTTTTGCTGTACTCTTTGTT"
},
{
"input": "204\n??????T???T?GC?TC???TA?TC?????A??C?C??G??????G?CTC????A?CTTT?T???T??CTTA???????T??C??G????A?????TTTA??AT?A??C?C?T?C???C?????T???????GT????T????AT?CT????C??C??T???C????C?GCTTCCC?G?????T???C?T??????????TT??",
"output": "AAAAAATAAATAGCATCAAATAATCAAAAAAAACACAAGAAAAAAGACTCAAAAAACTTTATAAATACCTTACCCCCCCTCCCCCGCCCCACCCCCTTTACCATCACCCCCGTGCGGGCGGGGGTGGGGGGGGTGGGGTGGGGATGCTGGGGCGGCGGTGGGCGGGGCGGCTTCCCGGGTTTTTTTTCTTTTTTTTTTTTTTTT"
},
{
"input": "208\nA?GGT?G??A???????G??A?A?GA?T?G???A?AAG?AT????GG?????AT??A?A???T?A??????A????AGGCGT???A???TA????TGGT???GA????GGTG???TA??GA??TA?GGG?????G?????AT?GGGG??TG?T?AA??A??AG?AA?TGA???A?A?GG???GAAT?G?T??T?A??G?CAGT?T?A?",
"output": "AAGGTAGAAAAAAAAAAGAAAAAAGAATCGCCCACAAGCATCCCCGGCCCCCATCCACACCCTCACCCCCCACCCCAGGCGTCCCACCCTACCCCTGGTCCCGACCCCGGTGCGGTAGGGAGGTAGGGGGGGGGGGGGGTATTGGGGTTTGTTTAATTATTAGTAATTGATTTATATGGTTTGAATTGTTTTTTATTGTCAGTTTTAT"
},
{
"input": "212\nT?TTT?A??TC?????A?T??T????T????????C??T??AT????????T???TT????T?TTT??????????TTC???T?T?C??T?TA?C??TTT????T???????C????????A?TT???T??TTT??AT?T????T????T?????A??C????T??T???TA???A?????????T???C????????C???T?TA???TTT",
"output": "TATTTAAAATCAAAAAAATAATAAAATAAAAAAAACAATAAATAAAAAAAATAAATTAAAATCTTTCCCCCCCCCCTTCCCCTCTCCCCTCTACCCCTTTCCCCTCCCCCCCCCCCCCCCCACTTCCGTGGTTTGGATGTGGGGTGGGGTGGGGGAGGCGGGGTGGTGGGTAGGGAGGGGGGGGGTGGGCGGGGGGGGCTTTTTTATTTTTT"
},
{
"input": "216\n?CT?A?CC?GCC?C?AT?A???C???TA????ATGTCCG??CCG?CGG?TCC?TTC??CCT????????G?GGC?TACCCGACCGAG?C???C?G?G??C??CGTCCTG??AGG??CT?G???TC?CT????A?GTA??C?C?CTGTTAC??C?TCT?C?T???T??GTGGA?AG?CGCT?CGTC???T?C?T?C?GTT???C??GCC?T??C?T?",
"output": "ACTAAACCAGCCACAATAAAAACAAATAAAAAATGTCCGAACCGACGGATCCATTCAACCTAAAAAAAAGAGGCATACCCGACCGAGACAAACAGAGCCCCCCGTCCTGCGAGGGGCTGGGGGTCGCTGGGGAGGTAGGCGCGCTGTTACGGCGTCTGCGTGGGTTTGTGGATAGTCGCTTCGTCTTTTTCTTTCTGTTTTTCTTGCCTTTTCTTT"
},
{
"input": "220\n?GCC??????T????G?CTC???CC?C????GC??????C???TCCC???????GCC????????C?C??C?T?C?CC????CC??C???????CC??C?G?A?T???CC??C????????C????CTA?GC?????CC??C?C?????T?????G?????????G???AC????C?CG?????C?G?C?CG?????????G?C????C?G??????C??",
"output": "AGCCAAAAAATAAAAGACTCAAACCACAAAAGCAAAAAACAAATCCCAAAAAAAGCCAAAAAAAACACAACATACACCAACCCCCCCCCCCCCGCCGGCGGGAGTGGGCCGGCGGGGGGGGCGGGGCTAGGCGGGGGCCGGCGCGGGGGTGGGGGGTTTTTTTTTGTTTACTTTTCTCGTTTTTCTGTCTCGTTTTTTTTTGTCTTTTCTGTTTTTTCTT"
},
{
"input": "224\nTTGC?G??A?ATCA??CA???T?TG?C?CGA?CTTA?C??C?TTC?AC?CTCA?A?AT?C?T?CT?CATGT???A??T?CT????C?AACT?TTCCC??C?AAC???AC?TTTC?TTAAA??????TGT????CGCT????GCCC?GCCCA?????TCGA??C?TATACA??C?CC?CATAC?GGACG??GC??GTT?TT?T???GCT??T?C?T?C??T?CC?",
"output": "TTGCAGAAAAATCAAACAAAATATGACACGAACTTAACAACATTCAACACTCAAAAATACATACTACATGTAAAACCTCCTCCCCCCAACTGTTCCCGGCGAACGGGACGTTTCGTTAAAGGGGGGTGTGGGGCGCTGGGGGCCCGGCCCAGGGGGTCGAGGCGTATACAGGCGCCGCATACGGGACGGGGCGTGTTTTTTTTTTGCTTTTTCTTTCTTTTCCT"
},
{
"input": "228\nA??A?C???AG?C?AC???A?T?????AA??????C?A??A?AC?????C?C???A??????A???AC?C????T?C?AA?C??A???CC??????????????????A???CC????A?????C??TC???A???????????A??A????????????????CC?????CCA??????????????C??????C????T?CT???C???A???T?CC?G??C??A?",
"output": "AAAAACAAAAGACAACAAAAATAAAAAAAAAAAAACAAAAAAACAAAAACACCCCACCCCCCACCCACCCCCCCTCCCAACCCCACCCCCCCCCGGGGGGGGGGGGGGAGGGCCGGGGAGGGGGCGGTCGGGAGGGGGGGGGGGAGGAGGGGGGGGGGGTTTTTCCTTTTTCCATTTTTTTTTTTTTTCTTTTTTCTTTTTTCTTTTCTTTATTTTTCCTGTTCTTAT"
},
{
"input": "232\nA??AAGC?GCG?AG???GGGCG?C?A?GCAAC?AG?C?GC??CA??A??CC?AA?A????G?AGA?ACACA?C?G?G?G?CGC??G???????GAGC?CAA??????G?A???AGGG?????AAC?AG?A?A??AG?CG?G???G????GGGA?C?G?A?A??GC????C??A?ACG?AA?G?ACG????AC?C?GA??GGCAG?GAA??ACA??A?AGGAGG???CGGA?C",
"output": "AAAAAGCAGCGAAGAAAGGGCGACAAAGCAACCAGCCCGCCCCACCACCCCCAACACCCCGCAGACACACACCCGCGCGCCGCCCGCCCGGGGGAGCGCAAGGGGGTGTATTTAGGGTTTTTAACTAGTATATTAGTCGTGTTTGTTTTGGGATCTGTATATTGCTTTTCTTATACGTAATGTACGTTTTACTCTGATTGGCAGTGAATTACATTATAGGAGGTTTCGGATC"
},
{
"input": "236\nAAGCCC?A?TT??C?AATGC?A?GC?GACGT?CTT?TA??CCG?T?CAA?AGT?CTG???GCGATG?TG?A?A?ACT?AT?GGG?GC?C?CGCCCTT?GT??G?T?????GACTT??????CT?GA?GG?C?T?G??CTG??G??TG?TCA?TCGTT?GC?A?G?GGGT?CG?CGAG??CG?TC?TAT?A???T??GAGTC?CGGC?CG??CT?TAAT??GGAA?G??GG?GCGAC",
"output": "AAGCCCAAATTAACAAATGCAAAGCAGACGTACTTATAAACCGATACAAAAGTACTGAAAGCGATGATGAAAAAACTAATAGGGAGCACACGCCCTTAGTACGCTCCCCCGACTTCCCCCCCTCGACGGCCCTCGCCCTGCGGGGTGGTCAGTCGTTGGCGAGGGGGGTGCGTCGAGTTCGTTCTTATTATTTTTTGAGTCTCGGCTCGTTCTTTAATTTGGAATGTTGGTGCGAC"
},
{
"input": "240\n?T?A?A??G????G????AGGAGTAA?AGGCT??C????AT?GAA?ATGCT???GA?G?A??G?TC??TATT???AG?G?G?A?A??TTGT??GGTCAG?GA?G?AAT?G?GG??CAG?T?GT?G?GC???GC??????GA?A?AAATGGGC??G??????TTA??GTCG?TC?GCCG?GGGA??T?A????T?G?T???G?GG?ATG???A?ATGAC?GGT?CTG?AGGG??TAGT?AG",
"output": "ATAAAAAAGAAAAGAAAAAGGAGTAAAAGGCTAACAAAAATAGAAAATGCTACCGACGCACCGCTCCCTATTCCCAGCGCGCACACCTTGTCCGGTCAGCGACGCAATCGCGGCCCAGCTCGTCGCGCCCCGCCCCCCCGACACAAATGGGCCCGCGGGGGTTATTGTCGTTCTGCCGTGGGATTTTATTTTTTGTTTTTGTGGTATGTTTATATGACTGGTTCTGTAGGGTTTAGTTAG"
},
{
"input": "244\nC?GT???T??TA?CC??TACT???TC?C?A???G??G?TCC?AC??AA???C?CCACC????A?AGCC??T?CT??CCGG?CC?T?C??GCCCTGGCCAAAC???GC?C???AT?CC?CT?TAG??CG?C?T?C??A?AC?GC????A??C?C?A??TC?T????GCCCT??GG???CC?A?CC?G?A?CA?G??CCCG??CG?T?TAC?G???C?AC??G??CCA???G????C??G?CT?C?",
"output": "CAGTAAATAATAACCAATACTAAATCACAAAAAGAAGATCCAACAAAAAAACACCACCAAAAAAAGCCAATACTAACCGGGCCGTGCGGGCCCTGGCCAAACGGGGCGCGGGATGCCGCTGTAGGGCGGCGTGCGGAGACGGCGGGGAGGCGCGAGGTCGTGGTTGCCCTTTGGTTTCCTATCCTGTATCATGTTCCCGTTCGTTTTACTGTTTCTACTTGTTCCATTTGTTTTCTTGTCTTCT"
},
{
"input": "248\n??TC???TG??G??T????CC???C?G?????G?????GT?A?CT?AAT?GG?AGA?????????G???????G???CG??AA?A????T???????TG?CA????C?TT?G?GC???AA?G????G????T??G??A??????TT???G???CG?????A??A??T?GA??G??T?CC?TA??GCTG?A????G?CG??GGTG??CA???????TA??G?????????A???????GC?GG????GC",
"output": "AATCAAATGAAGAATAAAACCAAACAGAAAAAGAAAAAGTAAACTAAATAGGAAGAAAAAAAAAAGACCCCCCGCCCCGCCAACACCCCTCCCCCCCTGCCACCCCCCTTCGCGCCCCAACGCCCCGCCCCTCCGGGAGGGGGGTTGGGGGGGCGGGGGGAGGAGGTGGAGGGGGTGCCTTATTGCTGTATTTTGTCGTTGGTGTTCATTTTTTTTATTGTTTTTTTTTATTTTTTTGCTGGTTTTGC"
},
{
"input": "8\n???AAA??",
"output": "==="
},
{
"input": "12\nC??CC??????C",
"output": "==="
},
{
"input": "4\nG??G",
"output": "==="
},
{
"input": "4\nTT??",
"output": "==="
},
{
"input": "4\nACAC",
"output": "==="
},
{
"input": "8\nACGT???T",
"output": "ACGTACGT"
},
{
"input": "252\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "252\n??????????????????????????????????????????????????????????????????????????????A?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????C????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????G",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTG"
},
{
"input": "252\nT???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "TAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "4\nAA?T",
"output": "==="
},
{
"input": "4\nAAAA",
"output": "==="
},
{
"input": "8\nAAA?????",
"output": "==="
},
{
"input": "10\nACGT??????",
"output": "==="
},
{
"input": "6\nACGACG",
"output": "==="
},
{
"input": "5\nAAAAA",
"output": "==="
},
{
"input": "8\nGGGGAA??",
"output": "==="
},
{
"input": "5\nATGCA",
"output": "==="
},
{
"input": "4\nTTTT",
"output": "==="
},
{
"input": "4\nACCG",
"output": "==="
},
{
"input": "8\nACGTA?GT",
"output": "ACGTACGT"
}
] | 1,622,099,456
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 46
| 0
|
n=int(input())
str=input()
if n%4!=0:
print('===')
else:
for i in 'ACGT':
if 4*str.count(i)>n:
print('===')
r=''
for i in 'ACGT':
r+=i*(n//4-str.count(i))
j=0
res=""
for i in range(len(str)):
if str[i]=='?':
res+=r[j]
j+=1
else:
res+=str[i]
print(res)
|
Title: Mammoth's Genome Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'.
It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.
Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.
Input Specification:
The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
Output Specification:
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
Demo Input:
['8\nAG?C??CT\n', '4\nAGCT\n', '6\n????G?\n', '4\nAA??\n']
Demo Output:
['AGACGTCT\n', 'AGCT\n', '===\n', '===\n']
Note:
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.
In the third and the fourth examples it is impossible to decode the genom.
|
```python
n=int(input())
str=input()
if n%4!=0:
print('===')
else:
for i in 'ACGT':
if 4*str.count(i)>n:
print('===')
r=''
for i in 'ACGT':
r+=i*(n//4-str.count(i))
j=0
res=""
for i in range(len(str)):
if str[i]=='?':
res+=r[j]
j+=1
else:
res+=str[i]
print(res)
```
| 0
|
|
862
|
A
|
Mahmoud and Ehab and the MEX
|
PROGRAMMING
| 1,000
|
[
"greedy",
"implementation"
] | null | null |
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0,<=2,<=4} is 1 and the MEX of the set {1,<=2,<=3} is 0 .
Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?
|
The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set.
|
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
|
[
"5 3\n0 4 5 6 7\n",
"1 0\n0\n",
"5 0\n1 2 3 4 5\n"
] |
[
"2\n",
"1\n",
"0\n"
] |
For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil.
| 500
|
[
{
"input": "5 3\n0 4 5 6 7",
"output": "2"
},
{
"input": "1 0\n0",
"output": "1"
},
{
"input": "5 0\n1 2 3 4 5",
"output": "0"
},
{
"input": "10 5\n57 1 47 9 93 37 76 70 78 15",
"output": "4"
},
{
"input": "10 5\n99 98 93 97 95 100 92 94 91 96",
"output": "5"
},
{
"input": "10 5\n1 2 3 4 59 45 0 58 51 91",
"output": "0"
},
{
"input": "100 100\n79 13 21 11 3 87 28 40 29 4 96 34 8 78 61 46 33 45 99 30 92 67 22 97 39 86 73 31 74 44 62 55 57 2 54 63 80 69 25 48 77 98 17 93 15 16 89 12 43 23 37 95 14 38 83 90 49 56 72 10 20 0 50 71 70 88 19 1 76 81 52 41 82 68 85 47 6 7 35 60 18 64 75 84 27 9 65 91 94 42 53 24 66 26 59 36 51 32 5 58",
"output": "0"
},
{
"input": "100 50\n95 78 46 92 80 18 79 58 30 72 19 89 39 29 44 65 15 100 59 8 96 9 62 67 41 42 82 14 57 32 71 77 40 5 7 51 28 53 85 23 16 35 3 91 6 11 75 61 17 66 13 47 36 56 10 22 83 60 48 24 26 97 4 33 76 86 70 0 34 64 52 43 21 49 55 74 1 73 81 25 54 63 94 84 20 68 87 12 31 88 38 93 37 90 98 69 99 45 27 2",
"output": "0"
},
{
"input": "100 33\n28 11 79 92 88 62 77 72 7 41 96 97 67 84 44 8 81 35 38 1 64 68 46 17 98 83 31 12 74 21 2 22 47 6 36 75 65 61 37 26 25 45 59 48 100 51 93 76 78 49 3 57 16 4 87 29 55 82 70 39 53 0 60 15 24 71 58 20 66 89 95 42 13 43 63 90 85 52 50 30 54 40 56 23 27 34 32 18 10 19 69 9 99 73 91 14 5 80 94 86",
"output": "0"
},
{
"input": "99 33\n25 76 41 95 55 20 47 59 58 84 87 92 16 27 35 65 72 63 93 54 36 96 15 86 5 69 24 46 67 73 48 60 40 6 61 74 97 10 100 8 52 26 77 18 7 62 37 2 14 66 11 56 68 91 0 64 75 99 30 21 53 1 89 81 3 98 12 88 39 38 29 83 22 90 9 28 45 43 78 44 32 57 4 50 70 17 13 51 80 85 71 94 82 19 34 42 23 79 49",
"output": "1"
},
{
"input": "100 100\n65 56 84 46 44 33 99 74 62 72 93 67 43 92 75 88 38 34 66 12 55 76 58 90 78 8 14 45 97 59 48 32 64 18 39 89 31 51 54 81 29 36 70 77 40 22 49 27 3 1 73 13 98 42 87 37 2 57 4 6 50 25 23 79 28 86 68 61 80 17 19 10 15 63 52 11 35 60 21 16 24 85 30 91 7 5 69 20 71 82 53 94 41 95 96 9 26 83 0 47",
"output": "0"
},
{
"input": "100 100\n58 88 12 71 22 1 40 19 73 20 67 48 57 17 69 36 100 35 33 37 72 55 52 8 89 85 47 42 78 70 81 86 11 9 68 99 6 16 21 61 53 98 23 62 32 59 51 0 87 24 50 30 65 10 80 95 7 92 25 74 60 79 91 5 13 31 75 38 90 94 46 66 93 34 14 41 28 2 76 84 43 96 3 56 49 82 27 77 64 63 4 45 18 29 54 39 15 26 83 44",
"output": "2"
},
{
"input": "89 100\n58 96 17 41 86 34 28 84 18 40 8 77 87 89 68 79 33 35 53 49 0 6 22 12 72 90 48 55 21 50 56 62 75 2 37 95 69 74 14 20 44 46 27 32 31 59 63 60 10 85 71 70 38 52 94 30 61 51 80 26 36 23 39 47 76 45 100 57 15 78 97 66 54 13 99 16 93 73 24 4 83 5 98 81 92 25 29 88 65",
"output": "13"
},
{
"input": "100 50\n7 95 24 76 81 78 60 69 83 84 100 1 65 31 48 92 73 39 18 89 38 97 10 42 8 55 98 51 21 90 62 77 16 91 0 94 4 37 19 17 67 35 45 41 56 20 15 85 75 28 59 27 12 54 61 68 36 5 79 93 66 11 70 49 50 34 30 25 96 46 64 14 32 22 47 40 58 23 43 9 87 82 26 53 80 52 3 86 13 99 33 71 6 88 57 74 2 44 72 63",
"output": "2"
},
{
"input": "77 0\n27 8 20 92 21 41 53 98 17 65 67 35 81 11 55 49 61 44 2 66 51 89 40 28 52 62 86 91 64 24 18 5 94 82 96 99 71 6 39 83 26 29 16 30 45 97 80 90 69 12 13 33 76 73 46 19 78 56 88 38 42 34 57 77 47 4 59 58 7 100 95 72 9 74 15 43 54",
"output": "0"
},
{
"input": "100 50\n55 36 0 32 81 6 17 43 24 13 30 19 8 59 71 45 15 74 3 41 99 42 86 47 2 94 35 1 66 95 38 49 4 27 96 89 34 44 92 25 51 39 54 28 80 77 20 14 48 40 68 56 31 63 33 78 69 37 18 26 83 70 23 82 91 65 67 52 61 53 7 22 60 21 12 73 72 87 75 100 90 29 64 79 98 85 5 62 93 84 50 46 97 58 57 16 9 10 76 11",
"output": "1"
},
{
"input": "77 0\n12 8 19 87 9 54 55 86 97 7 27 85 25 48 94 73 26 1 13 57 72 69 76 39 38 91 75 40 42 28 93 21 70 84 65 11 60 90 20 95 66 89 59 47 34 99 6 61 52 100 50 3 77 81 82 53 15 24 0 45 44 14 68 96 58 5 18 35 10 98 29 74 92 49 83 71 17",
"output": "1"
},
{
"input": "100 70\n25 94 66 65 10 99 89 6 70 31 7 40 20 92 64 27 21 72 77 98 17 43 47 44 48 81 38 56 100 39 90 22 88 76 3 83 86 29 33 55 82 79 49 11 2 16 12 78 85 69 32 97 26 15 53 24 23 91 51 67 34 35 52 5 62 50 95 18 71 13 75 8 30 42 93 36 45 60 63 46 57 41 87 0 84 54 74 37 4 58 28 19 96 61 80 9 1 14 73 68",
"output": "2"
},
{
"input": "89 19\n14 77 85 81 79 38 91 45 55 51 50 11 62 67 73 76 2 27 16 23 3 29 65 98 78 17 4 58 22 20 34 66 64 31 72 5 32 44 12 75 80 47 18 25 99 0 61 56 71 84 48 88 10 7 86 8 49 24 43 21 37 28 33 54 46 57 40 89 36 97 6 96 39 95 26 74 1 69 9 100 52 30 83 87 68 60 92 90 35",
"output": "2"
},
{
"input": "89 100\n69 61 56 45 11 41 42 32 28 29 0 76 7 65 13 35 36 82 10 39 26 34 38 40 92 12 17 54 24 46 88 70 66 27 100 52 85 62 22 48 86 68 21 49 53 94 67 20 1 90 77 84 31 87 58 47 95 33 4 72 93 83 8 51 91 80 99 43 71 19 44 59 98 97 64 9 81 16 79 63 25 37 3 75 2 55 50 6 18",
"output": "13"
},
{
"input": "77 0\n38 76 24 74 42 88 29 75 96 46 90 32 59 97 98 60 41 57 80 37 100 49 25 63 95 31 61 68 53 78 27 66 84 48 94 83 30 26 36 99 71 62 45 47 70 28 35 54 34 85 79 43 91 72 86 33 67 92 77 65 69 52 82 55 87 64 56 40 50 44 51 73 89 81 58 93 39",
"output": "0"
},
{
"input": "89 100\n38 90 80 64 35 44 56 11 15 89 23 12 49 70 72 60 63 85 92 10 45 83 8 88 41 33 16 6 61 76 62 71 87 13 25 77 74 0 1 37 96 93 7 94 21 82 34 78 4 73 65 20 81 95 50 32 48 17 69 55 68 5 51 27 53 43 91 67 59 46 86 84 99 24 22 3 97 98 40 36 26 58 57 9 42 30 52 2 47",
"output": "11"
},
{
"input": "77 0\n55 71 78 86 68 35 53 10 59 32 81 19 74 97 62 61 93 87 96 44 25 18 43 82 84 16 34 48 92 39 64 36 49 91 45 76 95 31 57 29 75 79 13 2 14 24 52 23 33 20 47 99 63 15 5 80 58 67 12 3 85 6 1 27 73 90 4 42 37 70 8 11 89 77 9 22 94",
"output": "0"
},
{
"input": "77 0\n12 75 31 71 44 8 3 82 21 77 50 29 57 74 40 10 15 42 84 2 100 9 28 72 92 0 49 11 90 55 17 36 19 54 68 52 4 69 97 91 5 39 59 45 89 62 53 83 16 94 76 60 95 47 30 51 7 48 20 70 67 32 58 78 63 34 56 93 99 88 24 1 66 22 25 14 13",
"output": "1"
},
{
"input": "100 70\n91 82 8 85 26 25 95 97 40 87 81 93 7 73 38 94 64 96 74 18 90 19 65 68 72 61 23 43 36 41 60 88 30 33 71 24 52 39 15 3 16 89 86 79 55 4 9 58 67 44 46 29 6 48 84 69 27 21 78 54 51 57 80 53 76 50 47 77 45 12 34 10 100 0 17 31 56 99 98 11 92 5 2 42 32 59 66 62 37 63 28 75 35 1 22 13 83 49 20 14",
"output": "0"
},
{
"input": "77 0\n51 5 81 62 30 22 11 0 83 16 79 85 52 70 69 10 8 47 58 3 24 34 44 14 82 66 99 17 28 31 64 67 23 49 94 45 4 12 27 15 21 6 43 72 87 2 63 92 35 39 59 9 90 78 93 20 65 36 60 89 50 41 61 84 77 86 76 100 38 68 53 97 96 95 7 19 88",
"output": "1"
},
{
"input": "1 100\n0",
"output": "99"
},
{
"input": "1 0\n100",
"output": "0"
},
{
"input": "1 100\n100",
"output": "101"
},
{
"input": "2 100\n0 100",
"output": "100"
},
{
"input": "5 5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5 3\n0 3 4 5 6",
"output": "3"
},
{
"input": "7 10\n0 1 2 3 4 5 10",
"output": "5"
},
{
"input": "2 2\n0 2",
"output": "2"
},
{
"input": "2 1\n1 2",
"output": "2"
},
{
"input": "5 1\n1 2 3 4 5",
"output": "2"
},
{
"input": "5 2\n1 2 3 4 5",
"output": "2"
},
{
"input": "5 6\n0 1 2 3 4",
"output": "1"
},
{
"input": "3 2\n3 4 5",
"output": "2"
}
] | 1,597,637,331
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
# 已经存在--剔除(1步)
# 不存在--加入(x-n({y:y<x}))
#
# Input
# 5 3
# 0 4 5 6 7
# Output
# 2
# #
if __name__ == "__main__":
n,x= map(int, input().split())
Nums = list(map(int, input().split()))
step=x
for i in Nums:
if i<x:
step-=1
if Nums.count(x)>0:
step+=1
print(step)
|
Title: Mahmoud and Ehab and the MEX
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0,<=2,<=4} is 1 and the MEX of the set {1,<=2,<=3} is 0 .
Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?
Input Specification:
The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set.
Output Specification:
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
Demo Input:
['5 3\n0 4 5 6 7\n', '1 0\n0\n', '5 0\n1 2 3 4 5\n']
Demo Output:
['2\n', '1\n', '0\n']
Note:
For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil.
|
```python
# 已经存在--剔除(1步)
# 不存在--加入(x-n({y:y<x}))
#
# Input
# 5 3
# 0 4 5 6 7
# Output
# 2
# #
if __name__ == "__main__":
n,x= map(int, input().split())
Nums = list(map(int, input().split()))
step=x
for i in Nums:
if i<x:
step-=1
if Nums.count(x)>0:
step+=1
print(step)
```
| -1
|
|
818
|
B
|
Permutation Game
|
PROGRAMMING
| 1,600
|
[
"implementation"
] | null | null |
*n* children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation *a*1,<=*a*2,<=...,<=*a**n* of length *n*. It is an integer sequence such that each integer from 1 to *n* appears exactly once in it.
The game consists of *m* steps. On each step the current leader with index *i* counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.
You are given numbers *l*1,<=*l*2,<=...,<=*l**m* — indices of leaders in the beginning of each step. Child with number *l*1 is the first leader in the game.
Write a program which will restore a possible permutation *a*1,<=*a*2,<=...,<=*a**n*. If there are multiple solutions then print any of them. If there is no solution then print -1.
|
The first line contains two integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains *m* integer numbers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*) — indices of leaders in the beginning of each step.
|
Print such permutation of *n* numbers *a*1,<=*a*2,<=...,<=*a**n* that leaders in the game will be exactly *l*1,<=*l*2,<=...,<=*l**m* if all the rules are followed. If there are multiple solutions print any of them.
If there is no permutation which satisfies all described conditions print -1.
|
[
"4 5\n2 3 1 4 4\n",
"3 3\n3 1 2\n"
] |
[
"3 1 2 4 \n",
"-1\n"
] |
Let's follow leadership in the first example:
- Child 2 starts. - Leadership goes from 2 to 2 + *a*<sub class="lower-index">2</sub> = 3. - Leadership goes from 3 to 3 + *a*<sub class="lower-index">3</sub> = 5. As it's greater than 4, it's going in a circle to 1. - Leadership goes from 1 to 1 + *a*<sub class="lower-index">1</sub> = 4. - Leadership goes from 4 to 4 + *a*<sub class="lower-index">4</sub> = 8. Thus in circle it still remains at 4.
| 0
|
[
{
"input": "4 5\n2 3 1 4 4",
"output": "3 1 2 4 "
},
{
"input": "3 3\n3 1 2",
"output": "-1"
},
{
"input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 "
},
{
"input": "6 8\n2 5 4 2 5 4 2 5",
"output": "1 3 2 4 5 6 "
},
{
"input": "100 1\n6",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "10 5\n7 7 9 9 3",
"output": "-1"
},
{
"input": "10 20\n10 1 5 7 1 2 5 3 6 3 9 4 3 4 9 6 8 4 9 6",
"output": "-1"
},
{
"input": "20 15\n11 19 1 8 17 12 3 1 8 17 12 3 1 8 17",
"output": "7 1 18 3 4 5 6 9 10 12 8 11 13 14 16 17 15 19 2 20 "
},
{
"input": "100 100\n96 73 23 74 35 44 75 13 62 50 76 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63",
"output": "1 2 3 4 5 6 7 8 10 11 12 13 49 14 15 17 18 19 20 21 22 23 51 39 24 25 27 28 16 29 30 32 33 34 9 35 36 37 40 41 42 43 44 31 79 45 46 47 48 26 52 53 54 55 56 57 58 59 60 62 63 88 66 64 65 67 68 69 70 71 72 73 50 61 38 87 74 75 76 78 80 81 82 83 84 85 86 89 90 91 92 93 94 95 96 77 97 98 99 100 "
},
{
"input": "100 100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91",
"output": "-1"
},
{
"input": "20 20\n1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11",
"output": "19 17 15 13 11 9 7 5 3 1 20 18 16 14 12 10 8 6 4 2 "
},
{
"input": "20 5\n1 20 2 19 3",
"output": "19 17 1 3 5 6 7 8 9 10 11 12 13 14 15 16 18 20 4 2 "
},
{
"input": "19 19\n1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10",
"output": "-1"
},
{
"input": "100 100\n1 99 2 98 3 97 4 96 5 95 6 94 7 93 8 92 9 91 10 90 11 89 12 88 13 87 14 86 15 85 16 84 17 83 18 82 19 81 20 80 21 79 22 78 23 77 24 76 25 75 26 74 27 73 28 72 29 71 30 70 31 69 32 68 33 67 34 66 35 65 36 64 37 63 38 62 39 61 40 60 41 59 42 58 43 57 44 56 45 55 46 54 47 53 48 52 49 51 50 50",
"output": "98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 100 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 "
},
{
"input": "51 18\n8 32 24 19 1 29 49 24 39 33 5 37 37 26 17 28 2 19",
"output": "-1"
},
{
"input": "5 5\n1 2 5 2 4",
"output": "-1"
},
{
"input": "6 6\n1 2 1 1 3 6",
"output": "-1"
},
{
"input": "4 4\n4 3 4 2",
"output": "-1"
},
{
"input": "3 3\n2 2 3",
"output": "-1"
},
{
"input": "4 6\n1 1 2 4 4 4",
"output": "-1"
},
{
"input": "9 4\n8 2 8 3",
"output": "-1"
},
{
"input": "4 6\n2 3 1 4 4 1",
"output": "-1"
},
{
"input": "2 3\n1 1 2",
"output": "-1"
},
{
"input": "5 7\n4 3 4 3 3 4 5",
"output": "-1"
},
{
"input": "2 9\n1 1 1 1 2 1 1 1 1",
"output": "-1"
},
{
"input": "4 4\n2 4 4 4",
"output": "1 2 3 4 "
},
{
"input": "3 3\n1 1 3",
"output": "-1"
},
{
"input": "2 5\n1 2 2 1 1",
"output": "-1"
},
{
"input": "4 4\n1 4 1 3",
"output": "-1"
},
{
"input": "3 4\n1 3 1 1",
"output": "-1"
},
{
"input": "4 4\n1 4 1 1",
"output": "-1"
},
{
"input": "66 67\n19 9 60 40 19 48 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5",
"output": "-1"
},
{
"input": "3 3\n3 3 2",
"output": "-1"
},
{
"input": "27 28\n8 18 27 24 20 8 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23",
"output": "-1"
},
{
"input": "4 3\n1 1 2",
"output": "-1"
},
{
"input": "4 4\n2 4 2 3",
"output": "-1"
},
{
"input": "2 3\n2 2 1",
"output": "-1"
},
{
"input": "2 2\n2 2",
"output": "1 2 "
},
{
"input": "3 4\n2 3 3 1",
"output": "-1"
},
{
"input": "5 6\n1 4 4 2 1 4",
"output": "-1"
},
{
"input": "4 3\n2 3 4",
"output": "-1"
},
{
"input": "2 3\n1 2 1",
"output": "-1"
},
{
"input": "10 4\n5 6 5 7",
"output": "-1"
},
{
"input": "3 3\n1 1 2",
"output": "-1"
},
{
"input": "4 5\n1 4 1 3 2",
"output": "-1"
},
{
"input": "6 5\n1 2 4 1 3",
"output": "-1"
}
] | 1,622,604,885
| 1,485
|
PyPy 3
|
RUNTIME_ERROR
|
TESTS
| 1
| 249
| 3,891,200
|
import sys
#import random
from bisect import bisect_left as lb
from collections import deque
#sys.setrecursionlimit(10**8)
from queue import PriorityQueue as pq
from math import *
input_ = lambda: sys.stdin.readline().strip("\r\n")
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab,bc,cd : ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x : print(x)
prinT = lambda x : print(x)
f = lambda : sys.stdout.flush()
inv =lambda x:pow(x,mod-2,mod)
mod = 10**9 + 7
n,k = il()
a = il()
ans = [-1 for i in range (n)]
x = a[0]-1
d = {}
vis = [i for i in range (1,n+1)]
for i in range (k-1) :
t = a[i+1] - a[i]
if (t <= 0) :
t += n
if (ans[a[i]-1] != t) :
if (ans[a[i]-1] >= 0 and d.get(t)) :
print(-1)
exit(0)
ans[a[i]-1] = t
d[t] = 1
vis.remove(t)
for i in range (n) :
if (ans[i] == -1) :
ans[i] = vis.pop()
print(*ans)
|
Title: Permutation Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation *a*1,<=*a*2,<=...,<=*a**n* of length *n*. It is an integer sequence such that each integer from 1 to *n* appears exactly once in it.
The game consists of *m* steps. On each step the current leader with index *i* counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.
You are given numbers *l*1,<=*l*2,<=...,<=*l**m* — indices of leaders in the beginning of each step. Child with number *l*1 is the first leader in the game.
Write a program which will restore a possible permutation *a*1,<=*a*2,<=...,<=*a**n*. If there are multiple solutions then print any of them. If there is no solution then print -1.
Input Specification:
The first line contains two integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains *m* integer numbers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*) — indices of leaders in the beginning of each step.
Output Specification:
Print such permutation of *n* numbers *a*1,<=*a*2,<=...,<=*a**n* that leaders in the game will be exactly *l*1,<=*l*2,<=...,<=*l**m* if all the rules are followed. If there are multiple solutions print any of them.
If there is no permutation which satisfies all described conditions print -1.
Demo Input:
['4 5\n2 3 1 4 4\n', '3 3\n3 1 2\n']
Demo Output:
['3 1 2 4 \n', '-1\n']
Note:
Let's follow leadership in the first example:
- Child 2 starts. - Leadership goes from 2 to 2 + *a*<sub class="lower-index">2</sub> = 3. - Leadership goes from 3 to 3 + *a*<sub class="lower-index">3</sub> = 5. As it's greater than 4, it's going in a circle to 1. - Leadership goes from 1 to 1 + *a*<sub class="lower-index">1</sub> = 4. - Leadership goes from 4 to 4 + *a*<sub class="lower-index">4</sub> = 8. Thus in circle it still remains at 4.
|
```python
import sys
#import random
from bisect import bisect_left as lb
from collections import deque
#sys.setrecursionlimit(10**8)
from queue import PriorityQueue as pq
from math import *
input_ = lambda: sys.stdin.readline().strip("\r\n")
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab,bc,cd : ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x : print(x)
prinT = lambda x : print(x)
f = lambda : sys.stdout.flush()
inv =lambda x:pow(x,mod-2,mod)
mod = 10**9 + 7
n,k = il()
a = il()
ans = [-1 for i in range (n)]
x = a[0]-1
d = {}
vis = [i for i in range (1,n+1)]
for i in range (k-1) :
t = a[i+1] - a[i]
if (t <= 0) :
t += n
if (ans[a[i]-1] != t) :
if (ans[a[i]-1] >= 0 and d.get(t)) :
print(-1)
exit(0)
ans[a[i]-1] = t
d[t] = 1
vis.remove(t)
for i in range (n) :
if (ans[i] == -1) :
ans[i] = vis.pop()
print(*ans)
```
| -1
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point.
|
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of queries.
Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$.
|
For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.
|
[
"2\n6 12 10\n4 3 10\n",
"4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n"
] |
[
"Finite\nInfinite\n",
"Finite\nFinite\nFinite\nInfinite\n"
] |
$\frac{6}{12} = \frac{1}{2} = 0,5_{10}$
$\frac{4}{3} = 1,(3)_{10}$
$\frac{9}{36} = \frac{1}{4} = 0,01_2$
$\frac{4}{12} = \frac{1}{3} = 0,1_3$
| 0
|
[
{
"input": "2\n6 12 10\n4 3 10",
"output": "Finite\nInfinite"
},
{
"input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4",
"output": "Finite\nFinite\nFinite\nInfinite"
},
{
"input": "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2",
"output": "Finite\nInfinite\nInfinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nFinite"
},
{
"input": "10\n1 3 10\n6 2 6\n2 3 9\n7 8 4\n5 6 10\n1 2 7\n0 3 6\n9 3 4\n4 4 9\n10 9 10",
"output": "Infinite\nFinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nInfinite"
},
{
"input": "10\n10 8 5\n0 6 9\n0 7 6\n5 7 3\n7 6 8\n0 4 8\n2 6 3\n10 2 9\n6 7 9\n9 1 4",
"output": "Infinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nInfinite\nFinite"
},
{
"input": "10\n5 8 2\n0 5 8\n5 9 7\n0 7 2\n6 7 2\n10 3 7\n8 1 10\n9 1 8\n0 7 10\n9 1 4",
"output": "Finite\nFinite\nInfinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nFinite"
},
{
"input": "1\n1 864691128455135232 2",
"output": "Infinite"
},
{
"input": "11\n1 1000000000000000000 10000000\n2 999 9\n2 999 333111\n0 9 7\n17 128 2\n13 311992186885373952 18\n1971402979058461 750473176484995605 75\n14 19 23\n3 21914624432020321 23\n3 21914624432020321 46\n3 21914624432020321 47",
"output": "Finite\nInfinite\nFinite\nFinite\nFinite\nFinite\nFinite\nInfinite\nFinite\nFinite\nInfinite"
},
{
"input": "1\n1 100000000000000000 10000000000000000",
"output": "Finite"
},
{
"input": "1\n1 4294967297 4294967296",
"output": "Infinite"
},
{
"input": "1\n1 5244319080000 30030",
"output": "Finite"
}
] | 1,560,125,589
| 5,889
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 124
| 0
|
tc = int(input())
while tc>0:
p,q,b = [int(i) for i in input().split()]
dec = abs(int(p/q)-(p/q))
finite = True
k = 1
curr = 1
dop = 0
while(dec!=0):
curr *= 1/b
kt = b-1
while(kt>0):
ta = curr
ta *= kt
if(dec-(dop+ta)>=0):
break
kt-=1
dec -= dop+(curr*kt)
dop += (curr*kt)
if(dec<0):
finite = False
break
if(finite):
print("Finite")
else:
print("Infinite")
tc-=1
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point.
Input Specification:
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of queries.
Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$.
Output Specification:
For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.
Demo Input:
['2\n6 12 10\n4 3 10\n', '4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n']
Demo Output:
['Finite\nInfinite\n', 'Finite\nFinite\nFinite\nInfinite\n']
Note:
$\frac{6}{12} = \frac{1}{2} = 0,5_{10}$
$\frac{4}{3} = 1,(3)_{10}$
$\frac{9}{36} = \frac{1}{4} = 0,01_2$
$\frac{4}{12} = \frac{1}{3} = 0,1_3$
|
```python
tc = int(input())
while tc>0:
p,q,b = [int(i) for i in input().split()]
dec = abs(int(p/q)-(p/q))
finite = True
k = 1
curr = 1
dop = 0
while(dec!=0):
curr *= 1/b
kt = b-1
while(kt>0):
ta = curr
ta *= kt
if(dec-(dop+ta)>=0):
break
kt-=1
dec -= dop+(curr*kt)
dop += (curr*kt)
if(dec<0):
finite = False
break
if(finite):
print("Finite")
else:
print("Infinite")
tc-=1
```
| 0
|
|
525
|
C
|
Ilya and Sticks
|
PROGRAMMING
| 1,600
|
[
"greedy",
"math",
"sortings"
] | null | null |
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of *n* sticks and an instrument. Each stick is characterized by its length *l**i*.
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of sticks remain unused. Bending sticks is not allowed.
Sticks with lengths *a*1, *a*2, *a*3 and *a*4 can make a rectangle if the following properties are observed:
- *a*1<=≤<=*a*2<=≤<=*a*3<=≤<=*a*4 - *a*1<==<=*a*2 - *a*3<==<=*a*4
A rectangle can be made of sticks with lengths of, for example, 3 3 3 3 or 2 2 4 4. A rectangle cannot be made of, for example, sticks 5 5 5 7.
Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length 5 can either stay at this length or be transformed into a stick of length 4.
You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks?
|
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of the available sticks.
The second line of the input contains *n* positive integers *l**i* (2<=≤<=*l**i*<=≤<=106) — the lengths of the sticks.
|
The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.
|
[
"4\n2 4 4 2\n",
"4\n2 2 3 5\n",
"4\n100003 100004 100005 100006\n"
] |
[
"8\n",
"0\n",
"10000800015\n"
] |
none
| 1,000
|
[
{
"input": "4\n2 4 4 2",
"output": "8"
},
{
"input": "4\n2 2 3 5",
"output": "0"
},
{
"input": "4\n100003 100004 100005 100006",
"output": "10000800015"
},
{
"input": "8\n5 3 3 3 3 4 4 4",
"output": "25"
},
{
"input": "10\n123 124 123 124 2 2 2 2 9 9",
"output": "15270"
},
{
"input": "8\n10 10 10 10 11 10 11 10",
"output": "210"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "10\n10519 10519 10520 10520 10520 10521 10521 10521 10522 10523",
"output": "221372362"
},
{
"input": "100\n4116 4116 4117 4117 4117 4117 4118 4119 4119 4119 4119 4120 4120 4120 4120 4121 4122 4123 4123 4123 4123 4124 4124 4124 4124 4125 4126 4126 4126 4126 4127 4127 4127 4127 4128 4128 4128 4128 4129 4129 4130 4130 4131 4132 4133 4133 4134 4134 4135 4135 4136 4137 4137 4137 4138 4139 4140 4140 4141 4141 4142 4143 4143 4143 4144 4144 4144 4144 4145 4145 4145 4146 4146 4146 4147 4147 4147 4147 4148 4148 4148 4149 4149 4149 4150 4151 4151 4151 4152 4152 4153 4153 4154 4154 4155 4155 4155 4155 4156 4156",
"output": "427591742"
},
{
"input": "10\n402840 873316 567766 493234 711262 291654 683001 496971 64909 190173",
"output": "0"
},
{
"input": "45\n1800 4967 1094 551 871 3505 846 960 4868 4304 2112 496 2293 2128 2430 2119 4497 2159 774 4520 3535 1013 452 1458 1895 1191 958 1133 416 2613 4172 3926 1665 4237 539 101 2448 1212 2631 4530 3026 412 1006 2515 1922",
"output": "0"
},
{
"input": "69\n2367 2018 3511 1047 1789 2332 1082 4678 2036 4108 2357 339 536 2272 3638 2588 754 3795 375 506 3243 1033 4531 1216 4266 2547 3540 4642 1256 2248 4705 14 629 876 2304 1673 4186 2356 3172 2664 3896 552 4293 1507 3307 2661 3143 4565 58 1298 4380 2738 917 2054 2676 4464 1314 3752 3378 1823 4219 3142 4258 1833 886 4286 4040 1070 2206",
"output": "7402552"
},
{
"input": "93\n13 2633 3005 1516 2681 3262 1318 1935 665 2450 2601 1644 214 929 4873 955 1983 3945 3488 2927 1516 1026 2150 974 150 2442 2610 1664 636 3369 266 2536 3132 2515 2582 1169 4462 4961 200 2848 4793 2795 4657 474 2640 2488 378 544 1805 1390 1548 2683 1474 4027 1724 2078 183 3717 1727 1780 552 2905 4260 1444 2906 3779 400 1491 1467 4480 3680 2539 4681 2875 4021 2711 106 853 3094 4531 4066 372 2129 2577 3996 2350 943 4478 3058 3333 4592 232 2780",
"output": "4403980"
},
{
"input": "21\n580 3221 3987 2012 35 629 1554 654 756 2254 4307 2948 3457 4612 4620 4320 1777 556 3088 348 1250",
"output": "0"
},
{
"input": "45\n4685 272 3481 3942 952 3020 329 4371 2923 2057 4526 2791 1674 3269 829 2713 3006 2166 1228 2795 983 1065 3875 4028 3429 3720 697 734 4393 1176 2820 1173 4598 2281 2549 4341 1504 172 4230 1193 3022 3742 1232 3433 1871",
"output": "0"
},
{
"input": "69\n3766 2348 4437 4438 3305 386 2026 1629 1552 400 4770 4069 4916 1926 2037 1079 2801 854 803 216 2152 4622 1494 3786 775 3615 4766 2781 235 836 1892 2234 3563 1843 4314 3836 320 2776 4796 1378 380 2421 3057 964 4717 1122 620 530 3455 1639 1618 3109 3120 564 2382 1995 1173 4510 286 1088 218 734 2779 3738 456 1668 4476 2780 3555",
"output": "12334860"
},
{
"input": "4\n2 2 2 4",
"output": "0"
},
{
"input": "8\n10 10 10 11 14 14 14 16",
"output": "140"
},
{
"input": "2\n2 3",
"output": "0"
},
{
"input": "3\n2 3 5",
"output": "0"
},
{
"input": "8\n2 1000000 2 1000000 2 1000000 2 1000000",
"output": "1000000000004"
},
{
"input": "4\n2 4 6 8",
"output": "0"
},
{
"input": "4\n2 3 6 8",
"output": "0"
},
{
"input": "5\n2 2 3 4 5",
"output": "8"
},
{
"input": "5\n1000000 999999 999999 999999 999999",
"output": "999998000001"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "4"
},
{
"input": "4\n2 4 5 5",
"output": "0"
},
{
"input": "20\n4 4 8 4 5 6 7 4 5 4 6 4 4 5 7 6 5 8 8 4",
"output": "149"
},
{
"input": "10\n8 4 6 6 8 5 7 7 6 8",
"output": "92"
},
{
"input": "11\n4 4 9 9 3 8 8 8 6 4 3",
"output": "84"
},
{
"input": "8\n2 3 3 4 4 5 5 5",
"output": "26"
},
{
"input": "4\n3 3 3 2",
"output": "6"
},
{
"input": "5\n3 3 10 100 100",
"output": "300"
},
{
"input": "8\n9 9 9 8 8 7 7 6",
"output": "114"
},
{
"input": "4\n5 6 6 7",
"output": "30"
},
{
"input": "5\n9 9 5 2 2",
"output": "18"
},
{
"input": "6\n3 4 100 200 1001 1002",
"output": "3003"
},
{
"input": "6\n3 4 5 100 101 102",
"output": "404"
},
{
"input": "5\n2 2 4 6 6",
"output": "12"
},
{
"input": "6\n2 3 8 10 13 14",
"output": "26"
},
{
"input": "7\n2 2 2 2 2 2 2",
"output": "4"
},
{
"input": "5\n5 2 2 2 2",
"output": "4"
},
{
"input": "6\n3 4 100 200 1000 1001",
"output": "3000"
},
{
"input": "5\n5 5 7 9 9",
"output": "45"
},
{
"input": "5\n8 8 7 4 4",
"output": "32"
},
{
"input": "5\n2 2 5 8 9",
"output": "16"
},
{
"input": "5\n4 4 4 2 2",
"output": "8"
},
{
"input": "5\n3 10 100 1000 10000",
"output": "0"
},
{
"input": "6\n10 10 7 4 2 2",
"output": "20"
},
{
"input": "6\n5 5 7 9 10 10",
"output": "50"
},
{
"input": "7\n10 10 7 5 3 2 2",
"output": "20"
},
{
"input": "7\n10 9 9 9 9 2 2",
"output": "81"
}
] | 1,427,407,220
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 96
| 389
| 53,657,600
|
n = int(input())
l = list(map(int, input().split()))
m = {}
m2 = set()
for i in range(1, 10**6 + 1):
m[i] = 0
for i in range(n):
m[l[i]] += 1
m2.add(l[i])
if l[i] >= 2:
m2.add(l[i] - 1)
m1 = []
for i in range(10**6, 1, -1):
if m[i] % 2 == 1 and m[i - 1] > 0:
m[i] -= 1
m[i - 1] += 1
elif m[i] % 2 == 1:
m[i] -= 1
for i in m2:
if m[i] != 0:
m1.append(i)
m1.sort(reverse = True)
cnt = 0
for i in range(len(m1)):
cnt += (m[m1[i]]//4)*(m1[i]**2)
if m[m1[i]] % 4 == 2 and i != len(m1) - 1:
m[m1[i + 1]] -= 2
cnt += m1[i + 1]*m1[i]
print(cnt)
|
Title: Ilya and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of *n* sticks and an instrument. Each stick is characterized by its length *l**i*.
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of sticks remain unused. Bending sticks is not allowed.
Sticks with lengths *a*1, *a*2, *a*3 and *a*4 can make a rectangle if the following properties are observed:
- *a*1<=≤<=*a*2<=≤<=*a*3<=≤<=*a*4 - *a*1<==<=*a*2 - *a*3<==<=*a*4
A rectangle can be made of sticks with lengths of, for example, 3 3 3 3 or 2 2 4 4. A rectangle cannot be made of, for example, sticks 5 5 5 7.
Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length 5 can either stay at this length or be transformed into a stick of length 4.
You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks?
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of the available sticks.
The second line of the input contains *n* positive integers *l**i* (2<=≤<=*l**i*<=≤<=106) — the lengths of the sticks.
Output Specification:
The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.
Demo Input:
['4\n2 4 4 2\n', '4\n2 2 3 5\n', '4\n100003 100004 100005 100006\n']
Demo Output:
['8\n', '0\n', '10000800015\n']
Note:
none
|
```python
n = int(input())
l = list(map(int, input().split()))
m = {}
m2 = set()
for i in range(1, 10**6 + 1):
m[i] = 0
for i in range(n):
m[l[i]] += 1
m2.add(l[i])
if l[i] >= 2:
m2.add(l[i] - 1)
m1 = []
for i in range(10**6, 1, -1):
if m[i] % 2 == 1 and m[i - 1] > 0:
m[i] -= 1
m[i - 1] += 1
elif m[i] % 2 == 1:
m[i] -= 1
for i in m2:
if m[i] != 0:
m1.append(i)
m1.sort(reverse = True)
cnt = 0
for i in range(len(m1)):
cnt += (m[m1[i]]//4)*(m1[i]**2)
if m[m1[i]] % 4 == 2 and i != len(m1) - 1:
m[m1[i + 1]] -= 2
cnt += m1[i + 1]*m1[i]
print(cnt)
```
| 3
|
|
330
|
A
|
Cakeminator
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation"
] | null | null |
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.
Please output the maximum number of cake cells that the cakeminator can eat.
|
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
- '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry.
|
Output the maximum number of cake cells that the cakeminator can eat.
|
[
"3 4\nS...\n....\n..S.\n"
] |
[
"8\n"
] |
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
| 500
|
[
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "0"
},
{
"input": "10 10\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS",
"output": "0"
},
{
"input": "10 10\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS",
"output": "30"
},
{
"input": "10 10\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..",
"output": "80"
},
{
"input": "9 5\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS",
"output": "0"
},
{
"input": "9 9\n...S.....\nS.S.....S\n.S....S..\n.S.....SS\n.........\n..S.S..S.\n.SS......\n....S....\n..S...S..",
"output": "17"
},
{
"input": "5 6\nSSSSSS\nSSSSSS\nSSSSSS\nSS.S..\nS.S.SS",
"output": "0"
},
{
"input": "9 8\n........\n.......S\n........\nS.......\n........\n........\nS.......\n........\n.......S",
"output": "64"
},
{
"input": "9 7\n......S\n......S\nS.S.S..\n.......\n.......\n.S.....\n.S....S\n..S....\n.S....S",
"output": "28"
},
{
"input": "10 10\n.....S....\n....SS..S.\n.S...S....\n........SS\n.S.......S\nSS..S.....\n.SS.....SS\nS..S......\n.......SSS\nSSSSS....S",
"output": "10"
},
{
"input": "6 7\n..S.SS.\n......S\n....S.S\nSS..S..\nS..SS.S\n.....S.",
"output": "0"
},
{
"input": "10 6\n.SSSSS\nSSS.SS\nSSSSSS\nS.SSSS\nSSSSS.\nS.SSSS\nSS.SSS\n.SSS.S\n.SSS..\nSS..SS",
"output": "0"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "3 2\nS.\n.S\nS.",
"output": "0"
},
{
"input": "3 2\nS.\n.S\nS.",
"output": "0"
},
{
"input": "4 3\n.S.\nS.S\n.S.\nS.S",
"output": "0"
},
{
"input": "2 3\n...\nSSS",
"output": "3"
},
{
"input": "2 4\nS.SS\nS.SS",
"output": "2"
},
{
"input": "2 2\n..\n.S",
"output": "3"
},
{
"input": "3 2\n.S\n.S\nSS",
"output": "0"
},
{
"input": "2 4\nSS.S\n..S.",
"output": "0"
},
{
"input": "2 3\n...\nS..",
"output": "5"
}
] | 1,588,246,700
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 42
| 310
| 0
|
n,m = input().split()
m = int(m)
s=''
ans = 0
for i in range(int(n)):
temp = str(input())
if 'S' not in temp:
ans = ans+m
temp=''
s = s + temp
for j in range(int(m)):
temp = ''
while j<len(s):
temp = temp + s[j]
j = j+int(m)
if 'S' not in temp:
ans = ans + len(temp)
print(ans)
|
Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.
Please output the maximum number of cake cells that the cakeminator can eat.
Input Specification:
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
- '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry.
Output Specification:
Output the maximum number of cake cells that the cakeminator can eat.
Demo Input:
['3 4\nS...\n....\n..S.\n']
Demo Output:
['8\n']
Note:
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
|
```python
n,m = input().split()
m = int(m)
s=''
ans = 0
for i in range(int(n)):
temp = str(input())
if 'S' not in temp:
ans = ans+m
temp=''
s = s + temp
for j in range(int(m)):
temp = ''
while j<len(s):
temp = temp + s[j]
j = j+int(m)
if 'S' not in temp:
ans = ans + len(temp)
print(ans)
```
| 3
|
|
544
|
A
|
Set of Strings
|
PROGRAMMING
| 1,100
|
[
"implementation",
"strings"
] | null | null |
You are given a string *q*. A sequence of *k* strings *s*1,<=*s*2,<=...,<=*s**k* is called beautiful, if the concatenation of these strings is string *q* (formally, *s*1<=+<=*s*2<=+<=...<=+<=*s**k*<==<=*q*) and the first characters of these strings are distinct.
Find any beautiful sequence of strings or determine that the beautiful sequence doesn't exist.
|
The first line contains a positive integer *k* (1<=≤<=*k*<=≤<=26) — the number of strings that should be in a beautiful sequence.
The second line contains string *q*, consisting of lowercase Latin letters. The length of the string is within range from 1 to 100, inclusive.
|
If such sequence doesn't exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the next *k* lines print the beautiful sequence of strings *s*1,<=*s*2,<=...,<=*s**k*.
If there are multiple possible answers, print any of them.
|
[
"1\nabca\n",
"2\naaacas\n",
"4\nabc\n"
] |
[
"YES\nabca\n",
"YES\naaa\ncas\n",
"NO\n"
] |
In the second sample there are two possible answers: {"*aaaca*", "*s*"} and {"*aaa*", "*cas*"}.
| 500
|
[
{
"input": "1\nabca",
"output": "YES\nabca"
},
{
"input": "2\naaacas",
"output": "YES\naaa\ncas"
},
{
"input": "4\nabc",
"output": "NO"
},
{
"input": "3\nnddkhkhkdndknndkhrnhddkrdhrnrrnkkdnnndndrdhnknknhnrnnkrrdhrkhkrkhnkhkhhrhdnrndnknrrhdrdrkhdrkkhkrnkk",
"output": "YES\nn\ndd\nkhkhkdndknndkhrnhddkrdhrnrrnkkdnnndndrdhnknknhnrnnkrrdhrkhkrkhnkhkhhrhdnrndnknrrhdrdrkhdrkkhkrnkk"
},
{
"input": "26\nbiibfmmfifmffbmmfmbmbmiimbmiffmffibibfbiffibibiiimbffbbfbifmiibffbmbbbfmfibmibfffibfbffmfmimbmmmfmfm",
"output": "NO"
},
{
"input": "3\nkydoybxlfeugtrbvqnrjtzshorrsrwsxkvlwyolbaadtzpmyyfllxuciia",
"output": "YES\nk\ny\ndoybxlfeugtrbvqnrjtzshorrsrwsxkvlwyolbaadtzpmyyfllxuciia"
},
{
"input": "3\nssussususskkskkskuusksuuussksukkskuksukukusssususuususkkuukssuksskusukkssuksskskuskusussusskskksksus",
"output": "YES\nss\nussususs\nkkskkskuusksuuussksukkskuksukukusssususuususkkuukssuksskusukkssuksskskuskusussusskskksksus"
},
{
"input": "5\naaaaabcdef",
"output": "YES\naaaaa\nb\nc\nd\nef"
},
{
"input": "3\niiiiiiimiriiriwmimtmwrhhxmbmhwgghhgbqhywebrblyhlxjrthoooltehrmdhqhuodjmsjwcgrfnttiitpmqvbhlafwtzyikc",
"output": "YES\niiiiiii\nmi\nriiriwmimtmwrhhxmbmhwgghhgbqhywebrblyhlxjrthoooltehrmdhqhuodjmsjwcgrfnttiitpmqvbhlafwtzyikc"
},
{
"input": "20\ngggggllglgllltgtlglttstsgtttsslhhlssghgagtlsaghhoggtfgsaahtotdodthfltdxggxislnttlanxonhnkddtigppitdh",
"output": "NO"
},
{
"input": "16\nkkkkkkyykkynkknkkonyokdndkyonokdywkwykdkdotknnwzkoywiooinkcyzyntcdnitnppnpziomyzdspomoqmomcyrrospppn",
"output": "NO"
},
{
"input": "15\nwwwgggowgwwhoohwgwghwyohhggywhyyodgwydwgggkhgyydqyggkgkpokgthqghidhworprodtcogqkwgtfiodwdurcctkmrfmh",
"output": "YES\nwww\nggg\nowgww\nhoohwgwghw\nyohhggywhyyo\ndgwydwggg\nkhgyyd\nqyggkgk\npokg\nthqgh\nidhwo\nrprodt\ncogqkwgt\nfiodwd\nurcctkmrfmh"
},
{
"input": "15\nnnnnnntnttttttqqnqqynnqqwwnnnwneenhwtyhhoqeyeqyeuthwtnhtpnphhwetjhouhwnpojvvovoswwjryrwerbwwpbvrwvjj",
"output": "YES\nnnnnnn\ntntttttt\nqqnqq\nynnqq\nwwnnnwn\neen\nhwtyhh\noqeyeqye\nuthwtnht\npnphhwet\njhouhwnpoj\nvvovo\nswwj\nryrwer\nbwwpbvrwvjj"
},
{
"input": "15\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv",
"output": "NO"
},
{
"input": "1\niiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiaaaaaiiiiaiaiiiiaaiaiiiaiiaiaaiaiiaiiiiiaiiiaiiiaiaiaai",
"output": "YES\niiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiaaaaaiiiiaiaiiiiaaiaiiiaiiaiaaiaiiaiiiiiaiiiaiiiaiaiaai"
},
{
"input": "26\nvvvnnsnnnpsnnswwspncvshtncwphaphmwnwkhvvhuvctvnehemowkmtzissswjaxuuvphzrmfzihamdqmmyhhijbitlipgltyy",
"output": "YES\nvvv\nnn\nsnnn\npsnns\nwwspn\ncvs\nh\ntncwph\naph\nmwnw\nkhvvh\nuvctvn\nehem\nowkmt\nz\nisssw\nja\nxuuvphz\nrm\nfziham\nd\nqmm\nyhhij\nbit\nlip\ngltyy"
},
{
"input": "26\njexzsbwaih",
"output": "NO"
},
{
"input": "1\nk",
"output": "YES\nk"
},
{
"input": "1\nzz",
"output": "YES\nzz"
},
{
"input": "3\nziw",
"output": "YES\nz\ni\nw"
},
{
"input": "26\ntjmbyqwuahlixegopkzrfndcsv",
"output": "YES\nt\nj\nm\nb\ny\nq\nw\nu\na\nh\nl\ni\nx\ne\ng\no\np\nk\nz\nr\nf\nn\nd\nc\ns\nv"
},
{
"input": "25\nvobekscyadzqwnjxruplifmthg",
"output": "YES\nv\no\nb\ne\nk\ns\nc\ny\na\nd\nz\nq\nw\nn\nj\nx\nr\nu\np\nl\ni\nf\nm\nt\nhg"
},
{
"input": "26\nlllplzkkzflzflffzznnnnfgflqlttlmtnkzlztskngyymitqagattkdllyutzimsrskpapcmuupjdopxqlnhqcscwvdtxbflefy",
"output": "YES\nlll\npl\nz\nkkz\nflzflffzz\nnnnnf\ngfl\nql\nttl\nmtnkzlzt\nskng\nyym\nitq\nagattk\ndlly\nutzims\nrskpap\ncmuup\njd\nop\nxqln\nhqcsc\nw\nvdtx\nbfl\nefy"
},
{
"input": "25\nkkrrkrkrkrsrskpskbrppdsdbgbkrbllkbswdwcchgskmkhwiidicczlscsodtjglxbmeotzxnmbjmoqgkquglaoxgcykxvbhdi",
"output": "YES\nkk\nrrkrkrkr\nsrsk\npsk\nbrpp\ndsdb\ngbkrb\nllkbs\nwdw\ncc\nhgsk\nmkhw\niidicc\nzlscs\nod\nt\njgl\nxbm\neotzx\nnmbjmo\nqgkq\nugl\naoxgc\nykx\nvbhdi"
},
{
"input": "25\nuuuuuccpucubccbupxubcbpujiliwbpqbpyiweuywaxwqasbsllwehceruytjvphytraawgbjmerfeymoayujqranlvkpkiypadr",
"output": "YES\nuuuuu\ncc\npucu\nbccbup\nxubcbpu\nj\ni\nli\nwbp\nqbp\nyiw\neuyw\naxwqa\nsbsllwe\nhce\nruy\ntj\nvphytraaw\ngbj\nmer\nfeym\noayujqra\nnlv\nkpkiypa\ndr"
},
{
"input": "26\nxxjxodrogovufvohrodliretxxyjqnrbzmicorptkjafiwmsbwml",
"output": "YES\nxx\njx\no\nd\nro\ngo\nv\nu\nfvo\nhrod\nl\nir\ne\ntxx\nyj\nq\nnr\nb\nz\nmi\ncor\npt\nkj\nafi\nwm\nsbwml"
},
{
"input": "26\npjhsxjbvkqntwmsdnrguecaofylzti",
"output": "YES\np\nj\nh\ns\nxj\nb\nv\nk\nq\nn\nt\nw\nms\ndn\nr\ng\nu\ne\nc\na\no\nf\ny\nl\nzt\ni"
},
{
"input": "25\nrrrrqqwrlqrwglrlylwhrrwyvrhvzgvqahrhgsvavtggyduayivxzgeicinlnrkapoepbsfyjjrt",
"output": "YES\nrrrr\nqq\nwr\nlqrw\nglrl\nylw\nhrrwy\nvrhv\nzgvq\nahrhg\nsvav\ntggy\nd\nuay\niv\nxzg\nei\nci\nnlnr\nka\np\noep\nbs\nfy\njjrt"
},
{
"input": "26\ncccccccaacwwaxxaacczacnnnqqwnaggzqrwagcnabxnrcvgjqjamqzgdntzanaxvjfwqlvdttuzjoxiwtkqvrydospmpeirhg",
"output": "YES\nccccccc\naac\nwwa\nxxaacc\nzac\nnnn\nqqwna\nggzq\nrwagcna\nbxnrc\nvg\njqja\nmqzg\ndn\ntzanaxvj\nfwq\nlvdtt\nuzj\nox\niwt\nkqvr\nydo\ns\npmp\neir\nhg"
},
{
"input": "4\nsssssssssssssssssssssssssslsslslsllsslssslslssllaaslsaalsasaassllasasalrlrslarlaarlsrsaslasarlr",
"output": "YES\nssssssssssssssssssssssssss\nlsslslsllsslssslslssll\naaslsaalsasaassllasasal\nrlrslarlaarlsrsaslasarlr"
},
{
"input": "26\na",
"output": "NO"
},
{
"input": "26\nab",
"output": "NO"
},
{
"input": "2\nab",
"output": "YES\na\nb"
}
] | 1,439,565,492
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 33
| 62
| 0
|
n = int(input())
s = input()
point = 1
ans = str()
used = set(s[0])
last_point = 0
for i in range(n - 1):
while point <= len(s) and s[point - 1] in used:
point += 1
if point <= len(s):
used.add(s[point - 1])
ans += s[last_point:point - 1] + '\n'
last_point = point - 1
else:
print('NO')
break
ans += s[last_point:]
if point <= len(s):
print('YES')
print(ans)
|
Title: Set of Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *q*. A sequence of *k* strings *s*1,<=*s*2,<=...,<=*s**k* is called beautiful, if the concatenation of these strings is string *q* (formally, *s*1<=+<=*s*2<=+<=...<=+<=*s**k*<==<=*q*) and the first characters of these strings are distinct.
Find any beautiful sequence of strings or determine that the beautiful sequence doesn't exist.
Input Specification:
The first line contains a positive integer *k* (1<=≤<=*k*<=≤<=26) — the number of strings that should be in a beautiful sequence.
The second line contains string *q*, consisting of lowercase Latin letters. The length of the string is within range from 1 to 100, inclusive.
Output Specification:
If such sequence doesn't exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the next *k* lines print the beautiful sequence of strings *s*1,<=*s*2,<=...,<=*s**k*.
If there are multiple possible answers, print any of them.
Demo Input:
['1\nabca\n', '2\naaacas\n', '4\nabc\n']
Demo Output:
['YES\nabca\n', 'YES\naaa\ncas\n', 'NO\n']
Note:
In the second sample there are two possible answers: {"*aaaca*", "*s*"} and {"*aaa*", "*cas*"}.
|
```python
n = int(input())
s = input()
point = 1
ans = str()
used = set(s[0])
last_point = 0
for i in range(n - 1):
while point <= len(s) and s[point - 1] in used:
point += 1
if point <= len(s):
used.add(s[point - 1])
ans += s[last_point:point - 1] + '\n'
last_point = point - 1
else:
print('NO')
break
ans += s[last_point:]
if point <= len(s):
print('YES')
print(ans)
```
| 3
|
|
3
|
A
|
Shortest path of the king
|
PROGRAMMING
| 1,000
|
[
"greedy",
"shortest paths"
] |
A. Shortest path of the king
|
1
|
64
|
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this.
In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
|
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
|
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
|
[
"a8\nh1\n"
] |
[
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] |
none
| 0
|
[
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
},
{
"input": "e1\nf2",
"output": "1\nRU"
},
{
"input": "g4\nd2",
"output": "3\nLD\nLD\nL"
},
{
"input": "a8\nb2",
"output": "6\nRD\nD\nD\nD\nD\nD"
},
{
"input": "d4\nh2",
"output": "4\nRD\nRD\nR\nR"
},
{
"input": "c5\na2",
"output": "3\nLD\nLD\nD"
},
{
"input": "h5\nf8",
"output": "3\nLU\nLU\nU"
},
{
"input": "e6\nb6",
"output": "3\nL\nL\nL"
},
{
"input": "a6\ng4",
"output": "6\nRD\nRD\nR\nR\nR\nR"
},
{
"input": "f7\nc2",
"output": "5\nLD\nLD\nLD\nD\nD"
},
{
"input": "b7\nh8",
"output": "6\nRU\nR\nR\nR\nR\nR"
},
{
"input": "g7\nd6",
"output": "3\nLD\nL\nL"
},
{
"input": "c8\na3",
"output": "5\nLD\nLD\nD\nD\nD"
},
{
"input": "h8\nf1",
"output": "7\nLD\nLD\nD\nD\nD\nD\nD"
},
{
"input": "d1\nb7",
"output": "6\nLU\nLU\nU\nU\nU\nU"
},
{
"input": "a7\ne5",
"output": "4\nRD\nRD\nR\nR"
},
{
"input": "d6\nb1",
"output": "5\nLD\nLD\nD\nD\nD"
},
{
"input": "f5\ng5",
"output": "1\nR"
},
{
"input": "h4\nd1",
"output": "4\nLD\nLD\nLD\nL"
},
{
"input": "b3\na5",
"output": "2\nLU\nU"
},
{
"input": "d2\nf1",
"output": "2\nRD\nR"
},
{
"input": "f1\nc5",
"output": "4\nLU\nLU\nLU\nU"
},
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "c7\ne5",
"output": "2\nRD\nRD"
},
{
"input": "e7\nb1",
"output": "6\nLD\nLD\nLD\nD\nD\nD"
},
{
"input": "g8\na8",
"output": "6\nL\nL\nL\nL\nL\nL"
},
{
"input": "g6\nf2",
"output": "4\nLD\nD\nD\nD"
},
{
"input": "g4\nc4",
"output": "4\nL\nL\nL\nL"
},
{
"input": "g2\na6",
"output": "6\nLU\nLU\nLU\nLU\nL\nL"
},
{
"input": "f8\nf8",
"output": "0"
},
{
"input": "f5\nd2",
"output": "3\nLD\nLD\nD"
}
] | 1,664,265,585
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 62
| 0
|
print("YES") if int(input()) % 2 ==0 else "NO"
|
Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this.
In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
Input Specification:
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
Output Specification:
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
Demo Input:
['a8\nh1\n']
Demo Output:
['7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n']
Note:
none
|
```python
print("YES") if int(input()) % 2 ==0 else "NO"
```
| -1
|
454
|
B
|
Little Pony and Sort by Shift
|
PROGRAMMING
| 1,200
|
[
"implementation"
] | null | null |
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
|
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
|
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
|
[
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] |
[
"1\n",
"-1\n",
"0\n"
] |
none
| 1,000
|
[
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
},
{
"input": "4\n5 4 5 4",
"output": "-1"
},
{
"input": "7\n3 4 5 5 5 1 2",
"output": "2"
},
{
"input": "5\n2 2 1 2 2",
"output": "3"
},
{
"input": "5\n5 4 1 2 3",
"output": "-1"
},
{
"input": "4\n6 1 2 7",
"output": "-1"
},
{
"input": "5\n4 5 6 2 3",
"output": "2"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "4\n1 2 2 1",
"output": "1"
},
{
"input": "9\n4 5 6 7 1 2 3 4 10",
"output": "-1"
},
{
"input": "7\n2 3 4 1 2 3 4",
"output": "-1"
},
{
"input": "6\n1 2 1 2 1 2",
"output": "-1"
},
{
"input": "3\n3 2 1",
"output": "-1"
},
{
"input": "4\n1 4 4 1",
"output": "1"
},
{
"input": "5\n1 2 1 1 1",
"output": "3"
},
{
"input": "5\n4 6 7 3 5",
"output": "-1"
},
{
"input": "4\n2 3 1 4",
"output": "-1"
},
{
"input": "5\n5 4 3 2 1",
"output": "-1"
},
{
"input": "4\n2 4 1 4",
"output": "-1"
},
{
"input": "6\n4 5 6 1 2 7",
"output": "-1"
},
{
"input": "6\n1 2 3 1 1 1",
"output": "3"
},
{
"input": "5\n1 3 3 3 1",
"output": "1"
},
{
"input": "6\n5 6 7 5 5 5",
"output": "3"
},
{
"input": "5\n3 4 2 1 2",
"output": "-1"
},
{
"input": "3\n3 4 2",
"output": "1"
},
{
"input": "6\n1 1 2 2 1 1",
"output": "2"
},
{
"input": "4\n2 3 4 2",
"output": "1"
},
{
"input": "5\n3 5 7 7 3",
"output": "1"
},
{
"input": "4\n1 1 4 1",
"output": "1"
},
{
"input": "7\n1 5 6 1 1 1 1",
"output": "4"
},
{
"input": "5\n7 8 6 7 8",
"output": "-1"
},
{
"input": "4\n2 4 1 3",
"output": "-1"
}
] | 1,607,411,705
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 56
| 155
| 7,065,600
|
n = int(input())
z = list(map(int,input().split()))
z.insert(0,z[-1])
cnt = 0
pos = 0
for i in range(0,n):
if z[i] > z[i+1] :
cnt += 1
pos = i
if cnt > 1 :
print(-1)
else :
print((n-pos)%n)
|
Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
Demo Input:
['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['1\n', '-1\n', '0\n']
Note:
none
|
```python
n = int(input())
z = list(map(int,input().split()))
z.insert(0,z[-1])
cnt = 0
pos = 0
for i in range(0,n):
if z[i] > z[i+1] :
cnt += 1
pos = i
if cnt > 1 :
print(-1)
else :
print((n-pos)%n)
```
| 3
|
|
114
|
A
|
Cifera
|
PROGRAMMING
| 1,000
|
[
"math"
] | null | null |
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
|
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
|
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
|
[
"5\n25\n",
"3\n8\n"
] |
[
"YES\n1\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "NO"
},
{
"input": "256\n16777217",
"output": "NO"
},
{
"input": "4638\n21511044",
"output": "YES\n1"
},
{
"input": "24\n191102976",
"output": "YES\n5"
},
{
"input": "52010\n557556453",
"output": "NO"
},
{
"input": "61703211\n1750753082",
"output": "NO"
},
{
"input": "137\n2571353",
"output": "YES\n2"
},
{
"input": "8758\n1746157336",
"output": "NO"
},
{
"input": "2\n64",
"output": "YES\n5"
},
{
"input": "96\n884736",
"output": "YES\n2"
},
{
"input": "1094841453\n1656354409",
"output": "NO"
},
{
"input": "1154413\n1229512809",
"output": "NO"
},
{
"input": "2442144\n505226241",
"output": "NO"
},
{
"input": "11548057\n1033418098",
"output": "NO"
},
{
"input": "581\n196122941",
"output": "YES\n2"
},
{
"input": "146\n1913781536",
"output": "NO"
},
{
"input": "945916\n1403881488",
"output": "NO"
},
{
"input": "68269\n365689065",
"output": "NO"
},
{
"input": "30\n900",
"output": "YES\n1"
},
{
"input": "6\n1296",
"output": "YES\n3"
},
{
"input": "1470193122\n1420950405",
"output": "NO"
},
{
"input": "90750\n1793111557",
"output": "NO"
},
{
"input": "1950054\n1664545956",
"output": "NO"
},
{
"input": "6767692\n123762320",
"output": "NO"
},
{
"input": "1437134\n1622348229",
"output": "NO"
},
{
"input": "444103\n1806462642",
"output": "NO"
},
{
"input": "2592\n6718464",
"output": "YES\n1"
},
{
"input": "50141\n366636234",
"output": "NO"
},
{
"input": "835\n582182875",
"output": "YES\n2"
},
{
"input": "156604\n902492689",
"output": "NO"
},
{
"input": "27385965\n1742270058",
"output": "NO"
},
{
"input": "3\n9",
"output": "YES\n1"
},
{
"input": "35\n1838265625",
"output": "YES\n5"
},
{
"input": "8\n4096",
"output": "YES\n3"
},
{
"input": "85955\n945811082",
"output": "NO"
},
{
"input": "54958832\n956670209",
"output": "NO"
},
{
"input": "1475381\n1348159738",
"output": "NO"
},
{
"input": "7313241\n413670642",
"output": "NO"
},
{
"input": "582470\n2116368165",
"output": "NO"
},
{
"input": "26859739\n595086170",
"output": "NO"
},
{
"input": "249766393\n1582130",
"output": "NO"
},
{
"input": "11734\n137686756",
"output": "YES\n1"
},
{
"input": "925093\n1098566745",
"output": "NO"
},
{
"input": "40\n1600",
"output": "YES\n1"
},
{
"input": "2147483647\n2147483647",
"output": "YES\n0"
},
{
"input": "2147483646\n2147483647",
"output": "NO"
},
{
"input": "2147483647\n2147483646",
"output": "NO"
},
{
"input": "2\n2147483647",
"output": "NO"
},
{
"input": "2\n1073741825",
"output": "NO"
},
{
"input": "2\n1073741824",
"output": "YES\n29"
},
{
"input": "10000\n10",
"output": "NO"
},
{
"input": "10\n10000",
"output": "YES\n3"
},
{
"input": "10\n2000000000",
"output": "NO"
},
{
"input": "10\n1000000000",
"output": "YES\n8"
},
{
"input": "5\n1808548329",
"output": "NO"
},
{
"input": "2\n2147483646",
"output": "NO"
},
{
"input": "25\n125",
"output": "NO"
},
{
"input": "6\n18",
"output": "NO"
},
{
"input": "5\n30",
"output": "NO"
}
] | 1,692,928,928
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 19
| 92
| 0
|
import math
def petriciumus_cifera(k, l):
n = math.log(l, k)
return n == int(n), int(n - 1)
cifera, importance = petriciumus_cifera(k=int(input()), l=int(input()))
if cifera:
print('YES')
print(importance)
else:
print('NO')
|
Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
Input Specification:
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
Output Specification:
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
Demo Input:
['5\n25\n', '3\n8\n']
Demo Output:
['YES\n1\n', 'NO\n']
Note:
none
|
```python
import math
def petriciumus_cifera(k, l):
n = math.log(l, k)
return n == int(n), int(n - 1)
cifera, importance = petriciumus_cifera(k=int(input()), l=int(input()))
if cifera:
print('YES')
print(importance)
else:
print('NO')
```
| 0
|
|
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,674,490,272
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 30
| 1,403
| 9,625,600
|
s=0
for i in range(int(input())):
x=input()
if x=="Tetrahedron":
s=s+4
elif x=="Cube":
s=s+6
elif x=="Octahedron":
s=s+8
elif x=="Dodecahedron":
s=s+12
else:
s=s+20
print(s)
|
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
s=0
for i in range(int(input())):
x=input()
if x=="Tetrahedron":
s=s+4
elif x=="Cube":
s=s+6
elif x=="Octahedron":
s=s+8
elif x=="Dodecahedron":
s=s+12
else:
s=s+20
print(s)
```
| 3
|
|
595
|
A
|
Vitaly and Night
|
PROGRAMMING
| 800
|
[
"constructive algorithms",
"implementation"
] | null | null |
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
|
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'.
|
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
|
[
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] |
[
"3\n",
"2\n"
] |
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
| 500
|
[
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "99"
},
{
"input": "1 100\n0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "6"
},
{
"input": "1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "100"
},
{
"input": "100 1\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0",
"output": "8"
},
{
"input": "100 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "1 1\n0 0",
"output": "0"
},
{
"input": "1 1\n0 1",
"output": "1"
},
{
"input": "1 1\n1 0",
"output": "1"
},
{
"input": "1 1\n1 1",
"output": "1"
}
] | 1,501,256,195
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 36
| 77
| 4,710,400
|
n, m = [int(i) for i in input().split()]
ans = 0
for _ in range(n):
a = [int(i) for i in input().split()]
b = [0]*m
for i in range(m):
if a[2*i] + a[2*i+1] > 0:
ans += 1
print (ans)
|
Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'.
Output Specification:
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Demo Input:
['2 2\n0 0 0 1\n1 0 1 1\n', '1 3\n1 1 0 1 0 0\n']
Demo Output:
['3\n', '2\n']
Note:
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
|
```python
n, m = [int(i) for i in input().split()]
ans = 0
for _ in range(n):
a = [int(i) for i in input().split()]
b = [0]*m
for i in range(m):
if a[2*i] + a[2*i+1] > 0:
ans += 1
print (ans)
```
| 3
|
|
960
|
A
|
Check the string
|
PROGRAMMING
| 1,200
|
[
"implementation"
] | null | null |
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.
You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
|
The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
|
Print "YES" or "NO", according to the condition.
|
[
"aaabccc\n",
"bbacc\n",
"aabc\n"
] |
[
"YES\n",
"NO\n",
"YES\n"
] |
Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'.
| 500
|
[
{
"input": "aaabccc",
"output": "YES"
},
{
"input": "bbacc",
"output": "NO"
},
{
"input": "aabc",
"output": "YES"
},
{
"input": "aabbcc",
"output": "YES"
},
{
"input": "aaacccbb",
"output": "NO"
},
{
"input": "abc",
"output": "YES"
},
{
"input": "acba",
"output": "NO"
},
{
"input": "bbabbc",
"output": "NO"
},
{
"input": "bbbabacca",
"output": "NO"
},
{
"input": "aabcbcaca",
"output": "NO"
},
{
"input": "aaaaabbbbbb",
"output": "NO"
},
{
"input": "c",
"output": "NO"
},
{
"input": "cc",
"output": "NO"
},
{
"input": "bbb",
"output": "NO"
},
{
"input": "bc",
"output": "NO"
},
{
"input": "ccbcc",
"output": "NO"
},
{
"input": "aaa",
"output": "NO"
},
{
"input": "aaccaa",
"output": "NO"
},
{
"input": "a",
"output": "NO"
},
{
"input": "b",
"output": "NO"
},
{
"input": "abca",
"output": "NO"
},
{
"input": "aabbcccc",
"output": "NO"
},
{
"input": "abac",
"output": "NO"
},
{
"input": "abcc",
"output": "NO"
},
{
"input": "abcb",
"output": "NO"
},
{
"input": "aacc",
"output": "NO"
},
{
"input": "aabbaacccc",
"output": "NO"
},
{
"input": "aabb",
"output": "NO"
},
{
"input": "ac",
"output": "NO"
},
{
"input": "abbacc",
"output": "NO"
},
{
"input": "abacc",
"output": "NO"
},
{
"input": "ababc",
"output": "NO"
},
{
"input": "aa",
"output": "NO"
},
{
"input": "aabaccc",
"output": "NO"
},
{
"input": "bbcc",
"output": "NO"
},
{
"input": "aaabcbc",
"output": "NO"
},
{
"input": "acbbc",
"output": "NO"
},
{
"input": "babc",
"output": "NO"
},
{
"input": "bbbcc",
"output": "NO"
},
{
"input": "bbc",
"output": "NO"
},
{
"input": "abababccc",
"output": "NO"
},
{
"input": "ccbbaa",
"output": "NO"
}
] | 1,523,117,889
| 789
|
Python 3
|
CHALLENGED
|
CHALLENGES
| 7
| 77
| 7,065,600
|
s = input()
a = [0, 0, 0]
if s[0] == "a" and (s.count("a") == s.count("c") or s.count("b") == s.count("c")) and not "ba" in s and not "cb" in s:
print("YES")
else:
print("NO")
|
Title: Check the string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.
You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
Input Specification:
The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
Output Specification:
Print "YES" or "NO", according to the condition.
Demo Input:
['aaabccc\n', 'bbacc\n', 'aabc\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'.
|
```python
s = input()
a = [0, 0, 0]
if s[0] == "a" and (s.count("a") == s.count("c") or s.count("b") == s.count("c")) and not "ba" in s and not "cb" in s:
print("YES")
else:
print("NO")
```
| -1
|
|
1
|
A
|
Theatre Square
|
PROGRAMMING
| 1,000
|
[
"math"
] |
A. Theatre Square
|
1
|
256
|
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
|
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
|
Write the needed number of flagstones.
|
[
"6 6 4\n"
] |
[
"4\n"
] |
none
| 0
|
[
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,673,724,095
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 31
| 0
|
arr = list(map(int, input().split()))
area_square=arr[0]*arr[1]
flagStone=(area_square//(arr[2])**2)+2
print(flagStone)
# print(arr)
# print(area_square)
|
Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none
|
```python
arr = list(map(int, input().split()))
area_square=arr[0]*arr[1]
flagStone=(area_square//(arr[2])**2)+2
print(flagStone)
# print(arr)
# print(area_square)
```
| 0
|
248
|
A
|
Cupboards
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds *t*.
|
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero.
The numbers in the lines are separated by single spaces.
|
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
|
[
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] |
[
"3\n"
] |
none
| 500
|
[
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1",
"output": "6"
},
{
"input": "15\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "5\n1 0\n1 0\n1 0\n0 1\n0 1",
"output": "4"
}
] | 1,643,182,803
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 57
| 374
| 5,427,200
|
n = int(input())
lefto=0
righto=0
s=0
for i in range(0,n):
inputs = [(num) for num in input().split()]
if(inputs[0]=="1"):
lefto+=1
if(inputs[1]=="1"):
righto+=1
if(lefto>int(n/2)):
s+=n-lefto
else:
s+=lefto
if(righto>int(n/2)):
s+=n-righto
else:
s+=righto
print(s)
|
Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds *t*.
Input Specification:
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero.
The numbers in the lines are separated by single spaces.
Output Specification:
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Demo Input:
['5\n0 1\n1 0\n0 1\n1 1\n0 1\n']
Demo Output:
['3\n']
Note:
none
|
```python
n = int(input())
lefto=0
righto=0
s=0
for i in range(0,n):
inputs = [(num) for num in input().split()]
if(inputs[0]=="1"):
lefto+=1
if(inputs[1]=="1"):
righto+=1
if(lefto>int(n/2)):
s+=n-lefto
else:
s+=lefto
if(righto>int(n/2)):
s+=n-righto
else:
s+=righto
print(s)
```
| 3
|
|
50
|
A
|
Domino piling
|
PROGRAMMING
| 800
|
[
"greedy",
"math"
] |
A. Domino piling
|
2
|
256
|
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
|
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
|
Output one number — the maximal number of dominoes, which can be placed.
|
[
"2 4\n",
"3 3\n"
] |
[
"4\n",
"4\n"
] |
none
| 500
|
[
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,649,044,551
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 35
| 154
| 0
|
m,n=list(map(int,input().split()))
ans=(m*n)//2
print(ans)
|
Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none
|
```python
m,n=list(map(int,input().split()))
ans=(m*n)//2
print(ans)
```
| 3.9615
|
822
|
A
|
I'm bored with life
|
PROGRAMMING
| 800
|
[
"implementation",
"math",
"number theory"
] | null | null |
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
|
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
|
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
|
[
"4 3\n"
] |
[
"6\n"
] |
Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
| 500
|
[
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"output": "6"
},
{
"input": "11 562314608",
"output": "39916800"
},
{
"input": "3 990639260",
"output": "6"
},
{
"input": "11 859155400",
"output": "39916800"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "5 3",
"output": "6"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "5 4",
"output": "24"
},
{
"input": "1 12",
"output": "1"
},
{
"input": "9 7",
"output": "5040"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "6 11",
"output": "720"
},
{
"input": "6 7",
"output": "720"
},
{
"input": "11 11",
"output": "39916800"
},
{
"input": "4 999832660",
"output": "24"
},
{
"input": "7 999228288",
"output": "5040"
},
{
"input": "11 999257105",
"output": "39916800"
},
{
"input": "11 999286606",
"output": "39916800"
},
{
"input": "3 999279109",
"output": "6"
},
{
"input": "999632727 11",
"output": "39916800"
},
{
"input": "999625230 7",
"output": "5040"
},
{
"input": "999617047 3",
"output": "6"
},
{
"input": "999646548 7",
"output": "5040"
},
{
"input": "999639051 3",
"output": "6"
},
{
"input": "12 12",
"output": "479001600"
},
{
"input": "12 1",
"output": "1"
},
{
"input": "1213 5",
"output": "120"
},
{
"input": "8 9",
"output": "40320"
},
{
"input": "12 9",
"output": "362880"
},
{
"input": "12 1000000000",
"output": "479001600"
},
{
"input": "1000000000 1",
"output": "1"
},
{
"input": "12 13",
"output": "479001600"
},
{
"input": "2 29845",
"output": "2"
},
{
"input": "10 21",
"output": "3628800"
},
{
"input": "12 20",
"output": "479001600"
},
{
"input": "15 12",
"output": "479001600"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000 12",
"output": "479001600"
},
{
"input": "11 30",
"output": "39916800"
},
{
"input": "17 12",
"output": "479001600"
},
{
"input": "4 19",
"output": "24"
},
{
"input": "12 15",
"output": "479001600"
},
{
"input": "20 6",
"output": "720"
},
{
"input": "10 20",
"output": "3628800"
},
{
"input": "10 10",
"output": "3628800"
},
{
"input": "22 12",
"output": "479001600"
},
{
"input": "20 12",
"output": "479001600"
},
{
"input": "12 23",
"output": "479001600"
},
{
"input": "12 22",
"output": "479001600"
},
{
"input": "18 3",
"output": "6"
},
{
"input": "14 10",
"output": "3628800"
},
{
"input": "14 12",
"output": "479001600"
},
{
"input": "8 3",
"output": "6"
},
{
"input": "5 5",
"output": "120"
}
] | 1,650,903,935
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 1
| 1,000
| 102,400
|
n,m=map(int,input().split())
fact1=1
fact2=1
for i in range(1,n+1):
fact1=fact1*i
for j in range(1,m+1):
fact2=fact2*j
def computeGCD(fact1,fact2):
if fact1 > fact2:
small = fact2
else:
small = fact1
for i in range(1, small+1):
if((fact1 % i == 0) and (fact2 % i == 0)):
gcd = i
return gcd
print(computeGCD(fact1,fact2))
|
Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
Input Specification:
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Output Specification:
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
Demo Input:
['4 3\n']
Demo Output:
['6\n']
Note:
Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
|
```python
n,m=map(int,input().split())
fact1=1
fact2=1
for i in range(1,n+1):
fact1=fact1*i
for j in range(1,m+1):
fact2=fact2*j
def computeGCD(fact1,fact2):
if fact1 > fact2:
small = fact2
else:
small = fact1
for i in range(1, small+1):
if((fact1 % i == 0) and (fact2 % i == 0)):
gcd = i
return gcd
print(computeGCD(fact1,fact2))
```
| 0
|
|
20
|
B
|
Equation
|
PROGRAMMING
| 2,000
|
[
"math"
] |
B. Equation
|
1
|
256
|
You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
|
The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=105<=≤<=*A*,<=*B*,<=*C*<=≤<=105). Any coefficient may be equal to 0.
|
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
|
[
"1 -5 6\n"
] |
[
"2\n2.0000000000\n3.0000000000"
] |
none
| 1,000
|
[
{
"input": "1 -5 6",
"output": "2\n2.0000000000\n3.0000000000"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 2 1",
"output": "1\n-1.0000000000"
},
{
"input": "0 0 0",
"output": "-1"
},
{
"input": "0 -2 1",
"output": "1\n0.5000000000"
},
{
"input": "0 -2 0",
"output": "1\n0.0000000000"
},
{
"input": "0 0 1",
"output": "0"
},
{
"input": "0 0 -100000",
"output": "0"
},
{
"input": "0 10000 -100000",
"output": "1\n10.0000000000"
},
{
"input": "1 100000 -100000",
"output": "2\n-100000.9999900002\n0.9999900002"
},
{
"input": "0 3431 43123",
"output": "1\n-12.5686388808"
},
{
"input": "100 200 100",
"output": "1\n-1.0000000000"
},
{
"input": "50000 100000 50000",
"output": "1\n-1.0000000000"
},
{
"input": "-1 10 20",
"output": "2\n-1.7082039325\n11.7082039325"
},
{
"input": "-50000 100000 -50000",
"output": "1\n1.0000000000"
},
{
"input": "1 -2 1",
"output": "1\n1.0000000000"
},
{
"input": "1000 -5000 6000",
"output": "2\n2.0000000000\n3.0000000000"
},
{
"input": "0 -100000 0",
"output": "1\n0.0000000000"
},
{
"input": "1 -100000 0",
"output": "2\n0.0000000000\n100000.0000000000"
},
{
"input": "1223 -23532 1232",
"output": "2\n0.0524974745\n19.1887126645"
},
{
"input": "-1 -2 -1",
"output": "1\n-1.0000000000"
},
{
"input": "1 0 0",
"output": "1\n0.0000000000"
},
{
"input": "0 1 0",
"output": "1\n-0.0000000000"
},
{
"input": "0 0 1",
"output": "0"
},
{
"input": "0 1 -1",
"output": "1\n1.0000000000"
},
{
"input": "5 0 5",
"output": "0"
},
{
"input": "-2 -5 0",
"output": "2\n-2.5000000000\n-0.0000000000"
},
{
"input": "-2 -4 0",
"output": "2\n-2.0000000000\n-0.0000000000"
},
{
"input": "-2 0 0",
"output": "1\n-0.0000000000"
},
{
"input": "0 -4 -4",
"output": "1\n-1.0000000000"
},
{
"input": "1 1 0",
"output": "2\n-1.0000000000\n0.0000000000"
},
{
"input": "1 0 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "0 0 0",
"output": "-1"
}
] | 1,655,747,274
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 15
| 0
|
import math
a,b,c = map(int,input().split())
d=b*b-4*a*c
if d==0:
print(1)
print(-b/(2*a))
elif d<0:
print(-1)
else:
dd= math.sqrt(d)
print(2)
print((-b-dd)/(2*a))
print((-b+dd)/(2*a))
|
Title: Equation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input Specification:
The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=105<=≤<=*A*,<=*B*,<=*C*<=≤<=105). Any coefficient may be equal to 0.
Output Specification:
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
Demo Input:
['1 -5 6\n']
Demo Output:
['2\n2.0000000000\n3.0000000000']
Note:
none
|
```python
import math
a,b,c = map(int,input().split())
d=b*b-4*a*c
if d==0:
print(1)
print(-b/(2*a))
elif d<0:
print(-1)
else:
dd= math.sqrt(d)
print(2)
print((-b-dd)/(2*a))
print((-b+dd)/(2*a))
```
| 0
|
223
|
A
|
Bracket Sequence
|
PROGRAMMING
| 1,700
|
[
"data structures",
"expression parsing",
"implementation"
] | null | null |
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()[]", "([])" are correct (the resulting expressions are: "(1)+[1]", "([1+1]+1)"), and "](" and "[" are not. The empty string is a correct bracket sequence by definition.
A substring *s*[*l*... *r*] (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) of string *s*<==<=*s*1*s*2... *s*|*s*| (where |*s*| is the length of string *s*) is the string *s**l**s**l*<=+<=1... *s**r*. The empty string is a substring of any string by definition.
You are given a bracket sequence, not necessarily correct. Find its substring which is a correct bracket sequence and contains as many opening square brackets «[» as possible.
|
The first and the only line contains the bracket sequence as a string, consisting only of characters "(", ")", "[" and "]". It is guaranteed that the string is non-empty and its length doesn't exceed 105 characters.
|
In the first line print a single integer — the number of brackets «[» in the required bracket sequence. In the second line print the optimal sequence. If there are more than one optimal solutions print any of them.
|
[
"([])\n",
"(((\n"
] |
[
"1\n([])\n",
"0\n\n"
] |
none
| 500
|
[
{
"input": "([])",
"output": "1\n([])"
},
{
"input": "(((",
"output": "0"
},
{
"input": "(][)",
"output": "0"
},
{
"input": "(()[))()[]",
"output": "1\n()[]"
},
{
"input": "(][](](][[(][",
"output": "1\n[]"
},
{
"input": "((])(]]))(](((()[[()[[[)([]()])[(]][)]])[]]()[()[[[[(([[)",
"output": "1\n[]()"
},
{
"input": "](]][)]()][[])[()(][)]))[)[]()()])[([((([[(([)][(])](][])([([)())))([(([][))[)()]][[])()[)](][[((]](](])]][(][[()(]][[)][])(][]))[])[)[(])[)()()[[))((()]]([([[(]))][(]())))))[[]]][][))[)])])()((((([[](([[()(([[()](([[([[(](]([)]())))[)]([]",
"output": "2\n[[]]"
},
{
"input": "[(()[])]()[()[]]",
"output": "4\n[(()[])]()[()[]]"
},
{
"input": "([])()[()]()()[(([])[]()[()([])()[][]()])]",
"output": "9\n([])()[()]()()[(([])[]()[()([])()[][]()])]"
},
{
"input": "[()][([[]])][[[]()]][()[]]()()([[][]][[]][](()))[[[(())]]][]()(([([])(([[[]]()])(()))]((())))([()]([()[[[]([][[[[][(())([[]()])]]][[(())]([])]()][[](())]()[])]()[][]]([[]])[]])[(()[()((()[][()]))][])[]()()([]())](()[][][])()()[]()))[]()[]",
"output": "61\n[()][([[]])][[[]()]][()[]]()()([[][]][[]][](()))[[[(())]]][]()(([([])(([[[]]()])(()))]((())))([()]([()[[[]([][[[[][(())([[]()])]]][[(())]([])]()][[](())]()[])]()[][]]([[]])[]])[(()[()((()[][()]))][])[]()()([]())](()[][][])()()[]()))[]()[]"
},
{
"input": "(][(](][[(][(",
"output": "0"
},
{
"input": ")[)][)))((([[)]((]][)[)((]([)[)(([)[)]][([",
"output": "0"
},
{
"input": "][([))][[))[[((]][([(([[)]]])([)][([([[[[([))]])][[[[[([)]]([[(((]([(](([([[)[(]])(][(((][)[[)][)(][[)[[)])))[)]))]])[([[))(([(]][))([(]]][(])]))))))[[[[[([[([)[[[)[(([)[[(][((([(([([(([))[[[[[[([(](])(][[)[)(](]])]]]((([))(])[[)[))[([[[[(]][)[([(]](([)([[)[[([))[)",
"output": "0"
},
{
"input": "()]])()()]",
"output": "0"
},
{
"input": "[([[)[(()[])[()][]()[[[)()[][[[()[]]]()]][",
"output": "5\n()[][[[()[]]]()]"
},
{
"input": "[()][][][][]()[)])))[(]()[]([)(])[)(])()[))][)]()[][][]][][)(((([))))[)[))]]([[[)[())))[(][(()[()[(]())]])([[)[)[[())[()[]()[[[[])][))](()()())()](((((([(()]][[)([)([]]))(()[((]]())[]])][)()(][]][][(([])]]((]])([[][)])(][)][([[[[(][()(][[(",
"output": "5\n[()][][][][]()"
},
{
"input": "(([])",
"output": "1\n([])"
},
{
"input": "()()([]]",
"output": "1\n[]"
},
{
"input": "([[[]]))",
"output": "2\n[[]]"
},
{
"input": "[[]",
"output": "1\n[]"
},
{
"input": "((((([]((((((((((",
"output": "1\n[]"
},
{
"input": "(((((([](((((((",
"output": "1\n[]"
},
{
"input": "[[])",
"output": "1\n[]"
},
{
"input": "((()))([]",
"output": "1\n[]"
},
{
"input": "([]",
"output": "1\n[]"
},
{
"input": "[]())])([)][[[]])))][])([]([]()]]))))())[[([))()(])))]][)[][[])(][()()]]](]][])[[))((]][)[)(]))([])((]([)([])]]]]]]][)[[[]]([[[]]][(][][])()[[([](])(]]((]([[)])]])([)(][([)(([))(]([)[[](([(](][[)()(][",
"output": "3\n[[[]]]"
}
] | 1,530,004,756
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 156
| 0
|
x=input()
ans=[]
s=['a']
tmp=''
count1=0
count2=0
co=0
for i in x:
if i==')':
if s[-1]=='(':
del s[-1]
else:
if len(s)==2:
ans.append(tmp[:-1])
tmp=''
else:
s=['a']
tmp=''
elif i==']':
if s[-1]=='[':
del s[-1]
else:
if len(s)==2:
ans.append(tmp[:-1])
tmp=''
else:
s=['a']
tmp=''
else:
s.append(i)
tmp+=i
co+=1
if len(s)==1 and co==len(x):
ans.append(tmp)
q=0
w=1
if len(ans)>0:
while w<len(ans):
if ans[q].count('[')>=ans[w].count('['):
w+=1
else:
q=w
w+=1
print(ans[q].count('['))
print(ans[q])
else:
print('0')
|
Title: Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()[]", "([])" are correct (the resulting expressions are: "(1)+[1]", "([1+1]+1)"), and "](" and "[" are not. The empty string is a correct bracket sequence by definition.
A substring *s*[*l*... *r*] (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) of string *s*<==<=*s*1*s*2... *s*|*s*| (where |*s*| is the length of string *s*) is the string *s**l**s**l*<=+<=1... *s**r*. The empty string is a substring of any string by definition.
You are given a bracket sequence, not necessarily correct. Find its substring which is a correct bracket sequence and contains as many opening square brackets «[» as possible.
Input Specification:
The first and the only line contains the bracket sequence as a string, consisting only of characters "(", ")", "[" and "]". It is guaranteed that the string is non-empty and its length doesn't exceed 105 characters.
Output Specification:
In the first line print a single integer — the number of brackets «[» in the required bracket sequence. In the second line print the optimal sequence. If there are more than one optimal solutions print any of them.
Demo Input:
['([])\n', '(((\n']
Demo Output:
['1\n([])\n', '0\n\n']
Note:
none
|
```python
x=input()
ans=[]
s=['a']
tmp=''
count1=0
count2=0
co=0
for i in x:
if i==')':
if s[-1]=='(':
del s[-1]
else:
if len(s)==2:
ans.append(tmp[:-1])
tmp=''
else:
s=['a']
tmp=''
elif i==']':
if s[-1]=='[':
del s[-1]
else:
if len(s)==2:
ans.append(tmp[:-1])
tmp=''
else:
s=['a']
tmp=''
else:
s.append(i)
tmp+=i
co+=1
if len(s)==1 and co==len(x):
ans.append(tmp)
q=0
w=1
if len(ans)>0:
while w<len(ans):
if ans[q].count('[')>=ans[w].count('['):
w+=1
else:
q=w
w+=1
print(ans[q].count('['))
print(ans[q])
else:
print('0')
```
| 0
|
|
74
|
A
|
Room Leader
|
PROGRAMMING
| 1,000
|
[
"implementation"
] |
A. Room Leader
|
2
|
256
|
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five problems, *A*, *B*, *C*, *D* and *E*. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.
You are suggested to determine the leader for some room; the leader is a participant who has maximum points.
|
The first line contains an integer *n*, which is the number of contestants in the room (1<=≤<=*n*<=≤<=50). The next *n* lines contain the participants of a given room. The *i*-th line has the format of "*handle**i* *plus**i* *minus**i* *a**i* *b**i* *c**i* *d**i* *e**i*" — it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems *A*, *B*, *C*, *D*, *E* correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers:
- 0<=≤<=*plus**i*,<=*minus**i*<=≤<=50; - 150<=≤<=*a**i*<=≤<=500 or *a**i*<==<=0, if problem *A* is not solved; - 300<=≤<=*b**i*<=≤<=1000 or *b**i*<==<=0, if problem *B* is not solved; - 450<=≤<=*c**i*<=≤<=1500 or *c**i*<==<=0, if problem *C* is not solved; - 600<=≤<=*d**i*<=≤<=2000 or *d**i*<==<=0, if problem *D* is not solved; - 750<=≤<=*e**i*<=≤<=2500 or *e**i*<==<=0, if problem *E* is not solved.
All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points).
|
Print on the single line the handle of the room leader.
|
[
"5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n"
] |
[
"tourist"
] |
The number of points that each participant from the example earns, are as follows:
- Petr — 3860 - tourist — 4140 - Egor — 4030 - c00lH4x0R — - 350 - some_participant — 2220
Thus, the leader of the room is tourist.
| 500
|
[
{
"input": "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0",
"output": "tourist"
},
{
"input": "1\nA 0 0 200 0 0 0 0",
"output": "A"
},
{
"input": "2\n12345678901234567890 1 0 200 0 0 0 0\n_ 1 0 201 0 0 0 0",
"output": "_"
},
{
"input": "5\nAb 0 0 481 900 1200 1600 2000\nCd 0 0 480 899 1200 1600 2000\nEf 0 0 480 900 1200 1600 2000\ngH 0 0 480 900 1200 1599 2000\nij 0 0 480 900 1199 1600 2001",
"output": "Ab"
},
{
"input": "4\nF1 0 0 150 0 0 0 0\nF2 0 1 0 0 0 0 0\nF3 0 2 0 0 0 0 0\nF4 0 3 0 0 0 0 0",
"output": "F1"
},
{
"input": "2\nA87h 5 0 199 0 0 0 0\nBcfg 7 0 0 0 0 0 0",
"output": "Bcfg"
},
{
"input": "10\nKh 40 26 0 0 0 0 1243\nn 46 50 500 0 910 1912 0\nU 18 1 182 0 457 0 0\nFth6A0uT6i 38 30 0 787 0 1121 0\nC5l 24 38 0 689 1082 0 0\nN 47 25 0 0 1065 0 1538\nznyL 9 24 0 315 0 0 0\nJ0kU 27 47 445 0 0 0 0\nlT0rwiD2pg 46 13 0 818 0 0 0\nuJzr 29 14 0 0 0 0 2387",
"output": "N"
},
{
"input": "2\nminus_one 0 4 199 0 0 0 0\nminus_two 0 4 198 0 0 0 0",
"output": "minus_one"
},
{
"input": "10\nW22kb1L1 0 39 0 465 0 1961 865\n1MCXiVYmu5ys0afl 0 38 0 0 0 1982 1241\nCxg706kUJtQ 0 23 211 0 0 1785 1056\nmzEY 0 16 0 0 0 1988 1404\nv8JUjmam5SFP 0 48 0 788 1199 1426 0\n7giq 0 21 0 780 1437 1363 1930\nsXsUGbAulj6Lbiq 0 32 205 0 0 603 0\nRepIrY1Er4PgK 0 13 381 872 927 1488 0\nleKBdKHLnLFz 0 29 220 0 0 1006 889\nD 0 26 497 0 0 0 1815",
"output": "7giq"
},
{
"input": "1\nZ 0 0 0 0 0 0 0",
"output": "Z"
},
{
"input": "3\nAbcd 0 4 189 0 0 0 0\nDefg 0 5 248 0 0 0 0\nGhh 1 3 0 0 0 0 0",
"output": "Defg"
},
{
"input": "3\ndf 0 6 0 0 0 0 0\njnm 1 8 300 0 0 0 0\n_ub_ 3 20 300 310 0 0 0",
"output": "jnm"
},
{
"input": "1\njhgcyt 0 50 0 0 0 0 0",
"output": "jhgcyt"
},
{
"input": "2\njhv 0 50 500 1000 1500 2000 2500\nPetr 2 1 489 910 1100 1300 1000",
"output": "jhv"
},
{
"input": "3\nufu 0 50 0 0 0 0 0\nhzEr65f 1 50 0 0 0 0 0\nytdttjfhfd 0 50 150 0 0 0 0",
"output": "ytdttjfhfd"
},
{
"input": "5\nufuf 0 50 0 0 0 0 0\nyfycy 50 0 500 1000 1500 2000 2500\n__u77 6 7 490 999 1456 1976 1356\n0 1 2 0 0 0 0 2452\ngu7fF 50 0 500 1000 1500 2000 2499",
"output": "yfycy"
},
{
"input": "2\nhfy 0 50 0 0 0 0 2500\nugug 0 50 0 0 0 0 2499",
"output": "hfy"
},
{
"input": "8\nA 0 0 0 0 0 0 0\nb 0 0 0 0 0 0 0\nc 0 0 0 0 0 0 0\nD 0 0 0 0 0 0 0\nE 1 0 0 0 0 0 0\nF 0 0 0 0 0 0 0\ng 0 0 0 0 0 0 0\nH 0 0 0 0 0 0 0",
"output": "E"
},
{
"input": "2\nyyyc 50 50 0 0 0 0 0\nydd 0 0 0 0 0 0 2499",
"output": "yyyc"
},
{
"input": "2\ntom 0 2 0 0 0 0 0\nmac 0 1 0 0 0 0 0",
"output": "mac"
},
{
"input": "1\ncool 0 10 0 0 0 0 0",
"output": "cool"
}
] | 1,667,960,663
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 6
| 124
| 0
|
users = dict()
n = int(input())
for i in range(n):
l = input().split()
scores = list(map(int,l[1:]))
a = scores[0]*100-scores[1]*500 +sum(scores[2:])
users[a] = l[0]
b = max(users.keys())
print(users[b])
|
Title: Room Leader
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five problems, *A*, *B*, *C*, *D* and *E*. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.
You are suggested to determine the leader for some room; the leader is a participant who has maximum points.
Input Specification:
The first line contains an integer *n*, which is the number of contestants in the room (1<=≤<=*n*<=≤<=50). The next *n* lines contain the participants of a given room. The *i*-th line has the format of "*handle**i* *plus**i* *minus**i* *a**i* *b**i* *c**i* *d**i* *e**i*" — it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems *A*, *B*, *C*, *D*, *E* correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers:
- 0<=≤<=*plus**i*,<=*minus**i*<=≤<=50; - 150<=≤<=*a**i*<=≤<=500 or *a**i*<==<=0, if problem *A* is not solved; - 300<=≤<=*b**i*<=≤<=1000 or *b**i*<==<=0, if problem *B* is not solved; - 450<=≤<=*c**i*<=≤<=1500 or *c**i*<==<=0, if problem *C* is not solved; - 600<=≤<=*d**i*<=≤<=2000 or *d**i*<==<=0, if problem *D* is not solved; - 750<=≤<=*e**i*<=≤<=2500 or *e**i*<==<=0, if problem *E* is not solved.
All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points).
Output Specification:
Print on the single line the handle of the room leader.
Demo Input:
['5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n']
Demo Output:
['tourist']
Note:
The number of points that each participant from the example earns, are as follows:
- Petr — 3860 - tourist — 4140 - Egor — 4030 - c00lH4x0R — - 350 - some_participant — 2220
Thus, the leader of the room is tourist.
|
```python
users = dict()
n = int(input())
for i in range(n):
l = input().split()
scores = list(map(int,l[1:]))
a = scores[0]*100-scores[1]*500 +sum(scores[2:])
users[a] = l[0]
b = max(users.keys())
print(users[b])
```
| 0
|
237
|
A
|
Free Cash
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately.
Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe.
Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is given in the chronological order. All time is given within one 24-hour period.
|
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
|
[
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] |
[
"2\n",
"1\n"
] |
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so it will be enough one cash.
| 500
|
[
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "8\n0 36\n4 7\n4 7\n4 7\n11 46\n12 4\n15 39\n18 6",
"output": "3"
},
{
"input": "20\n4 12\n4 21\n4 27\n4 56\n5 55\n7 56\n11 28\n11 36\n14 58\n15 59\n16 8\n17 12\n17 23\n17 23\n17 23\n17 23\n17 23\n17 23\n20 50\n22 32",
"output": "6"
},
{
"input": "10\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30",
"output": "10"
},
{
"input": "50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 54\n13 32\n13 42\n14 29\n14 34\n14 48\n15 0\n15 27\n16 22\n16 31\n17 25\n17 26\n17 33\n18 14\n18 16\n18 20\n19 0\n19 5\n19 56\n20 22\n21 26\n22 0\n22 10\n22 11\n22 36\n23 17\n23 20",
"output": "8"
},
{
"input": "10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49",
"output": "1"
},
{
"input": "15\n0 16\n6 15\n8 2\n8 6\n8 7\n10 1\n10 1\n10 3\n10 12\n13 5\n14 16\n14 16\n14 16\n14 16\n14 16",
"output": "5"
},
{
"input": "2\n0 24\n1 0",
"output": "1"
},
{
"input": "1\n0 0",
"output": "1"
},
{
"input": "1\n1 5",
"output": "1"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "3"
},
{
"input": "1\n5 0",
"output": "1"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "5"
},
{
"input": "1\n10 10",
"output": "1"
},
{
"input": "1\n8 0",
"output": "1"
},
{
"input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "10"
},
{
"input": "2\n0 0\n0 1",
"output": "1"
},
{
"input": "2\n8 5\n8 5",
"output": "2"
}
] | 1,613,928,977
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 6
| 92
| 0
|
n = int(input())
a=[]
for i in range(n):
a.append(input())
b =set(a)
print(len(a)-len(b)+1)
|
Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately.
Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe.
Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is given in the chronological order. All time is given within one 24-hour period.
Output Specification:
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
Demo Input:
['4\n8 0\n8 10\n8 10\n8 45\n', '3\n0 12\n10 11\n22 22\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so it will be enough one cash.
|
```python
n = int(input())
a=[]
for i in range(n):
a.append(input())
b =set(a)
print(len(a)-len(b)+1)
```
| 0
|
|
3
|
A
|
Shortest path of the king
|
PROGRAMMING
| 1,000
|
[
"greedy",
"shortest paths"
] |
A. Shortest path of the king
|
1
|
64
|
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this.
In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
|
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
|
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
|
[
"a8\nh1\n"
] |
[
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] |
none
| 0
|
[
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
},
{
"input": "e1\nf2",
"output": "1\nRU"
},
{
"input": "g4\nd2",
"output": "3\nLD\nLD\nL"
},
{
"input": "a8\nb2",
"output": "6\nRD\nD\nD\nD\nD\nD"
},
{
"input": "d4\nh2",
"output": "4\nRD\nRD\nR\nR"
},
{
"input": "c5\na2",
"output": "3\nLD\nLD\nD"
},
{
"input": "h5\nf8",
"output": "3\nLU\nLU\nU"
},
{
"input": "e6\nb6",
"output": "3\nL\nL\nL"
},
{
"input": "a6\ng4",
"output": "6\nRD\nRD\nR\nR\nR\nR"
},
{
"input": "f7\nc2",
"output": "5\nLD\nLD\nLD\nD\nD"
},
{
"input": "b7\nh8",
"output": "6\nRU\nR\nR\nR\nR\nR"
},
{
"input": "g7\nd6",
"output": "3\nLD\nL\nL"
},
{
"input": "c8\na3",
"output": "5\nLD\nLD\nD\nD\nD"
},
{
"input": "h8\nf1",
"output": "7\nLD\nLD\nD\nD\nD\nD\nD"
},
{
"input": "d1\nb7",
"output": "6\nLU\nLU\nU\nU\nU\nU"
},
{
"input": "a7\ne5",
"output": "4\nRD\nRD\nR\nR"
},
{
"input": "d6\nb1",
"output": "5\nLD\nLD\nD\nD\nD"
},
{
"input": "f5\ng5",
"output": "1\nR"
},
{
"input": "h4\nd1",
"output": "4\nLD\nLD\nLD\nL"
},
{
"input": "b3\na5",
"output": "2\nLU\nU"
},
{
"input": "d2\nf1",
"output": "2\nRD\nR"
},
{
"input": "f1\nc5",
"output": "4\nLU\nLU\nLU\nU"
},
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "c7\ne5",
"output": "2\nRD\nRD"
},
{
"input": "e7\nb1",
"output": "6\nLD\nLD\nLD\nD\nD\nD"
},
{
"input": "g8\na8",
"output": "6\nL\nL\nL\nL\nL\nL"
},
{
"input": "g6\nf2",
"output": "4\nLD\nD\nD\nD"
},
{
"input": "g4\nc4",
"output": "4\nL\nL\nL\nL"
},
{
"input": "g2\na6",
"output": "6\nLU\nLU\nLU\nLU\nL\nL"
},
{
"input": "f8\nf8",
"output": "0"
},
{
"input": "f5\nd2",
"output": "3\nLD\nLD\nD"
}
] | 1,696,578,719
| 2,147,483,647
|
PyPy 3-64
|
RUNTIME_ERROR
|
TESTS
| 0
| 124
| 2,764,800
|
n = int(input())
lst = list(map(int, input().split()))
lst_1 = []
lst_2 = []
lst_3 = []
def in_kq(lst):
result = ' '.join(map(str, lst))
print(len(lst), result)
for i in range(n):
if lst[i] < 0 and (not lst_1):
lst_1.append(lst[i])
elif lst[i] > 0 and (not lst_2):
lst_2.append(lst[i])
else:
lst_3.append(lst[i])
if not lst_2:
for i in lst_3:
if i < 0 and len(lst_2) < 2:
lst_2.append(i)
for i in lst_2:
lst_3.remove(i)
in_kq(lst_1)
in_kq(lst_2)
in_kq(lst_3)
|
Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this.
In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
Input Specification:
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
Output Specification:
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
Demo Input:
['a8\nh1\n']
Demo Output:
['7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n']
Note:
none
|
```python
n = int(input())
lst = list(map(int, input().split()))
lst_1 = []
lst_2 = []
lst_3 = []
def in_kq(lst):
result = ' '.join(map(str, lst))
print(len(lst), result)
for i in range(n):
if lst[i] < 0 and (not lst_1):
lst_1.append(lst[i])
elif lst[i] > 0 and (not lst_2):
lst_2.append(lst[i])
else:
lst_3.append(lst[i])
if not lst_2:
for i in lst_3:
if i < 0 and len(lst_2) < 2:
lst_2.append(i)
for i in lst_2:
lst_3.remove(i)
in_kq(lst_1)
in_kq(lst_2)
in_kq(lst_3)
```
| -1
|
271
|
A
|
Beautiful Year
|
PROGRAMMING
| 800
|
[
"brute force"
] | null | null |
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
|
The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number.
|
Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
|
[
"1987\n",
"2013\n"
] |
[
"2013\n",
"2014\n"
] |
none
| 500
|
[
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"input": "9000",
"output": "9012"
},
{
"input": "1111",
"output": "1203"
},
{
"input": "8999",
"output": "9012"
},
{
"input": "4572",
"output": "4573"
},
{
"input": "6666",
"output": "6701"
},
{
"input": "2001",
"output": "2013"
},
{
"input": "3000",
"output": "3012"
},
{
"input": "7712",
"output": "7801"
},
{
"input": "8088",
"output": "8091"
},
{
"input": "1594",
"output": "1596"
},
{
"input": "6016",
"output": "6017"
},
{
"input": "8800",
"output": "8901"
},
{
"input": "3331",
"output": "3401"
},
{
"input": "5090",
"output": "5091"
},
{
"input": "2342",
"output": "2345"
},
{
"input": "2334",
"output": "2340"
},
{
"input": "1123",
"output": "1203"
},
{
"input": "8989",
"output": "9012"
},
{
"input": "8977",
"output": "9012"
},
{
"input": "6869",
"output": "6870"
},
{
"input": "8999",
"output": "9012"
}
] | 1,696,699,723
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 6
| 124
| 0
|
n = int(input())
s = ""
st = {""}
for i in range(n+1,9000+1):
s = str(i)
st = {""}
st.add(s[0])
st.add(s[1])
st.add(s[2])
st.add(s[3])
if (len(st)==5):
print(i)
break
|
Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input Specification:
The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number.
Output Specification:
Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
Demo Input:
['1987\n', '2013\n']
Demo Output:
['2013\n', '2014\n']
Note:
none
|
```python
n = int(input())
s = ""
st = {""}
for i in range(n+1,9000+1):
s = str(i)
st = {""}
st.add(s[0])
st.add(s[1])
st.add(s[2])
st.add(s[3])
if (len(st)==5):
print(i)
break
```
| 0
|
|
121
|
B
|
Lucky Transformation
|
PROGRAMMING
| 1,500
|
[
"strings"
] | null | null |
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consisting of *n* digits without leading zeroes. He represented it as an array of digits without leading zeroes. Let's call it *d*. The numeration starts with 1, starting from the most significant digit. Petya wants to perform the following operation *k* times: find the minimum *x* (1<=≤<=*x*<=<<=*n*) such that *d**x*<==<=4 and *d**x*<=+<=1<==<=7, if *x* is odd, then to assign *d**x*<==<=*d**x*<=+<=1<==<=4, otherwise to assign *d**x*<==<=*d**x*<=+<=1<==<=7. Note that if no *x* was found, then the operation counts as completed and the array doesn't change at all.
You are given the initial number as an array of digits and the number *k*. Help Petya find the result of completing *k* operations.
|
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=≤<=109) — the number of digits in the number and the number of completed operations. The second line contains *n* digits without spaces representing the array of digits *d*, starting with *d*1. It is guaranteed that the first digit of the number does not equal zero.
|
In the single line print the result without spaces — the number after the *k* operations are fulfilled.
|
[
"7 4\n4727447\n",
"4 2\n4478\n"
] |
[
"4427477\n",
"4478\n"
] |
In the first sample the number changes in the following sequence: 4727447 → 4427447 → 4427477 → 4427447 → 4427477.
In the second sample: 4478 → 4778 → 4478.
| 1,000
|
[
{
"input": "7 4\n4727447",
"output": "4427477"
},
{
"input": "4 2\n4478",
"output": "4478"
},
{
"input": "7 7\n4211147",
"output": "4211177"
},
{
"input": "7 6\n4747477",
"output": "4444477"
},
{
"input": "10 2\n9474444474",
"output": "9774444774"
},
{
"input": "10 47\n4214777477",
"output": "4217777777"
},
{
"input": "3 99\n447",
"output": "477"
},
{
"input": "4 1000000000\n7747",
"output": "7744"
},
{
"input": "3 1000000000\n447",
"output": "447"
},
{
"input": "3 100\n447",
"output": "447"
},
{
"input": "7 74\n4777774",
"output": "4777774"
},
{
"input": "10 200\n6860544593",
"output": "6860544593"
},
{
"input": "10 477\n5837934237",
"output": "5837934237"
},
{
"input": "47 7477\n83492039276961836565341994102530448486552156001",
"output": "83492039276961836565341994102530448486552156001"
},
{
"input": "100 0\n9179665522184092255095619209953008761499858159751083177424923082479016015954927554823400601862864827",
"output": "9179665522184092255095619209953008761499858159751083177424923082479016015954927554823400601862864827"
},
{
"input": "485 9554485\n77591213686327368525391827531734680282181149581181587323024775516707756080151536104831756264659461447807315739541829004122483827102803764919259852061561098901393332937462039404423475012940096002301663119780442182470831027122573263011092200024968051233448164275142862251531399243063800892848783227559284462449919786387761960941614255036371684927500361571685732032325070607701306810264624073744998990612133986362972207072576588540217974702060321406370425911824802563123926135054749895722",
"output": "77591213686327368525391827531734680282181149581181587323024475516707756080151536104831756264659461447807315739541829004122483827102803764919259852061561098901393332937462039404423475012940096002301663119780442182470831027122573263011092200024968051233448164275142862251531399243063800892848783227559284462449919786387761960941614255036371684927500361571685732032325070607701306810264624073744998990612133986362972207072576588540217974702060321406370425911824802563123926135054749895722"
},
{
"input": "74 7\n47437850490316923506619313479471062875964157742919669484484624083960118773",
"output": "44437850490316923506619313449771062875964157742919669484484624083960118773"
},
{
"input": "47 7\n77774477747474477477477774747747447447774777474",
"output": "77774777747474477477477774747747447447774777474"
},
{
"input": "100 2\n7477774774777474774777777474474474744477777477774444477444774474477774777474774744477474744474777444",
"output": "7777774474777474774777777474474474744477777477774444477444774474477774777474774744477474744474777444"
},
{
"input": "99 1\n474747444774447474444477474747774774447444477744774744477747777474777774777474477744447447447447477",
"output": "444747444774447474444477474747774774447444477744774744477747777474777774777474477744447447447447477"
},
{
"input": "74 1000000000\n77474447774774747474777447474777777477474444477747444777447444474744744444",
"output": "77444444774774747474777447474777777477474444477747444777447444474744744444"
},
{
"input": "74 999999999\n47474777744447477747777774774777447474747747447744474777477474777774774447",
"output": "44444477744447477747777774774777447474747747447744474777477474777774774447"
},
{
"input": "100 47\n4346440647444704624490777777537777677744747437443404484777536674477779371445774947477174444474400267",
"output": "4346440644444404624490777777537777677747747437443404484777536674477779371445774947477174444474400267"
},
{
"input": "100 1000000000\n5849347454478644774747479437170493249634474874684784475734456487776740780444477442497447771444047377",
"output": "5849377454448644774747479437170493249634474874684784475734456487776740780444477442497447771444047377"
},
{
"input": "154 96\n7967779274474413067517474773015431177704444740654941743448963746454006444442746745494233876247994374947948475494434494479684421447774484909784471488747487",
"output": "7967779274444413067517444773015431177704444740654941743448963746454006444442746745494233876247994374947948475494434494479684421447774484909784471488747487"
},
{
"input": "2 0\n47",
"output": "47"
},
{
"input": "5 0\n12473",
"output": "12473"
}
] | 1,685,978,858
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 62
| 0
|
import sys
# Get Input
#sys.stdin = open("input.txt","r")
input = sys.stdin.readline
# Input Functions #
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
return(input().strip())
def invr():
return map(int, input().split())
def convert(s):
new = ""
for x in s:
new += x
return new
# LOGIC #
n, k = invr()
s = insr()
m = list(s)
for i in range(k):
k = s.index("47")
if s.index("47") % 2 == 0:
m[k+1] = '4'
else:
m[k] = '7'
s = convert(m)
print(i, s)
|
Title: Lucky Transformation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consisting of *n* digits without leading zeroes. He represented it as an array of digits without leading zeroes. Let's call it *d*. The numeration starts with 1, starting from the most significant digit. Petya wants to perform the following operation *k* times: find the minimum *x* (1<=≤<=*x*<=<<=*n*) such that *d**x*<==<=4 and *d**x*<=+<=1<==<=7, if *x* is odd, then to assign *d**x*<==<=*d**x*<=+<=1<==<=4, otherwise to assign *d**x*<==<=*d**x*<=+<=1<==<=7. Note that if no *x* was found, then the operation counts as completed and the array doesn't change at all.
You are given the initial number as an array of digits and the number *k*. Help Petya find the result of completing *k* operations.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=≤<=109) — the number of digits in the number and the number of completed operations. The second line contains *n* digits without spaces representing the array of digits *d*, starting with *d*1. It is guaranteed that the first digit of the number does not equal zero.
Output Specification:
In the single line print the result without spaces — the number after the *k* operations are fulfilled.
Demo Input:
['7 4\n4727447\n', '4 2\n4478\n']
Demo Output:
['4427477\n', '4478\n']
Note:
In the first sample the number changes in the following sequence: 4727447 → 4427447 → 4427477 → 4427447 → 4427477.
In the second sample: 4478 → 4778 → 4478.
|
```python
import sys
# Get Input
#sys.stdin = open("input.txt","r")
input = sys.stdin.readline
# Input Functions #
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
return(input().strip())
def invr():
return map(int, input().split())
def convert(s):
new = ""
for x in s:
new += x
return new
# LOGIC #
n, k = invr()
s = insr()
m = list(s)
for i in range(k):
k = s.index("47")
if s.index("47") % 2 == 0:
m[k+1] = '4'
else:
m[k] = '7'
s = convert(m)
print(i, s)
```
| 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.