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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
609
|
B
|
The Best Gift
|
PROGRAMMING
| 1,100
|
[
"constructive algorithms",
"implementation"
] | null | null |
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book.
The books are given by indices of their genres. The genres are numbered from 1 to *m*.
|
The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres.
The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book.
It is guaranteed that for each genre there is at least one book of that genre.
|
Print the only integer — the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value 2·109.
|
[
"4 3\n2 1 3 1\n",
"7 4\n4 2 3 1 2 4 3\n"
] |
[
"5\n",
"18\n"
] |
The answer to the first test sample equals 5 as Sasha can choose:
1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books.
| 0
|
[
{
"input": "4 3\n2 1 3 1",
"output": "5"
},
{
"input": "7 4\n4 2 3 1 2 4 3",
"output": "18"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "3 2\n1 2 2",
"output": "2"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10",
"output": "45"
},
{
"input": "9 2\n1 1 1 1 2 1 1 1 1",
"output": "8"
},
{
"input": "12 3\n1 2 3 1 2 3 1 2 3 1 2 3",
"output": "48"
},
{
"input": "100 3\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3",
"output": "3296"
},
{
"input": "100 5\n5 5 2 4 5 4 4 4 4 2 5 3 4 2 4 4 1 1 5 3 2 2 1 3 3 2 5 3 4 5 1 3 5 4 4 4 3 1 4 4 3 4 5 2 5 4 2 1 2 2 3 5 5 5 1 4 5 3 1 4 2 2 5 1 5 3 4 1 5 1 2 2 3 5 1 3 2 4 2 4 2 2 4 1 3 5 2 2 2 3 3 4 3 2 2 5 5 4 2 5",
"output": "3953"
},
{
"input": "100 10\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6",
"output": "4428"
}
] | 1,670,052,588
| 1,188
|
PyPy 3-64
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 16
| 2,000
| 9,113,600
|
n,m=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
for i in range(n-1):
cnt+=len(a[i+1:])-a[i+1:].count(a[i])
print(cnt)
|
Title: The Best Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book.
The books are given by indices of their genres. The genres are numbered from 1 to *m*.
Input Specification:
The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres.
The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book.
It is guaranteed that for each genre there is at least one book of that genre.
Output Specification:
Print the only integer — the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value 2·109.
Demo Input:
['4 3\n2 1 3 1\n', '7 4\n4 2 3 1 2 4 3\n']
Demo Output:
['5\n', '18\n']
Note:
The answer to the first test sample equals 5 as Sasha can choose:
1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books.
|
```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
for i in range(n-1):
cnt+=len(a[i+1:])-a[i+1:].count(a[i])
print(cnt)
```
| 0
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
You are given an undirected graph that consists of *n* vertices and *m* edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue edges with an endpoint in this vertex change the color to red.
Find the minimum possible number of moves required to make the colors of all edges equal.
|
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — the number of vertices and edges, respectively.
The following *m* lines provide the description of the edges, as the *i*-th of them contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the indices of the vertices connected by the *i*-th edge, and a character *c**i* () providing the initial color of this edge. If *c**i* equals 'R', then this edge is initially colored red. Otherwise, *c**i* is equal to 'B' and this edge is initially colored blue. It's guaranteed that there are no self-loops and multiple edges.
|
If there is no way to make the colors of all edges equal output <=-<=1 in the only line of the output. Otherwise first output *k* — the minimum number of moves required to achieve the goal, then output *k* integers *a*1,<=*a*2,<=...,<=*a**k*, where *a**i* is equal to the index of the vertex that should be used at the *i*-th move.
If there are multiple optimal sequences of moves, output any of them.
|
[
"3 3\n1 2 B\n3 1 R\n3 2 B\n",
"6 5\n1 3 R\n2 3 R\n3 4 B\n4 5 R\n4 6 R\n",
"4 5\n1 2 R\n1 3 R\n2 3 B\n3 4 B\n1 4 B\n"
] |
[
"1\n2 \n",
"2\n3 4 \n",
"-1\n"
] |
none
| 0
|
[] | 1,690,489,158
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 0
|
print("_RANDOM_GUESS_1690489158.5509348")# 1690489158.5509531
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an undirected graph that consists of *n* vertices and *m* edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue edges with an endpoint in this vertex change the color to red.
Find the minimum possible number of moves required to make the colors of all edges equal.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — the number of vertices and edges, respectively.
The following *m* lines provide the description of the edges, as the *i*-th of them contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the indices of the vertices connected by the *i*-th edge, and a character *c**i* () providing the initial color of this edge. If *c**i* equals 'R', then this edge is initially colored red. Otherwise, *c**i* is equal to 'B' and this edge is initially colored blue. It's guaranteed that there are no self-loops and multiple edges.
Output Specification:
If there is no way to make the colors of all edges equal output <=-<=1 in the only line of the output. Otherwise first output *k* — the minimum number of moves required to achieve the goal, then output *k* integers *a*1,<=*a*2,<=...,<=*a**k*, where *a**i* is equal to the index of the vertex that should be used at the *i*-th move.
If there are multiple optimal sequences of moves, output any of them.
Demo Input:
['3 3\n1 2 B\n3 1 R\n3 2 B\n', '6 5\n1 3 R\n2 3 R\n3 4 B\n4 5 R\n4 6 R\n', '4 5\n1 2 R\n1 3 R\n2 3 B\n3 4 B\n1 4 B\n']
Demo Output:
['1\n2 \n', '2\n3 4 \n', '-1\n']
Note:
none
|
```python
print("_RANDOM_GUESS_1690489158.5509348")# 1690489158.5509531
```
| 0
|
|
611
|
A
|
New Year and Days
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month.
Limak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him.
|
The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month.
|
Print one integer — the number of candies Limak will save in the year 2016.
|
[
"4 of week\n",
"30 of month\n"
] |
[
"52\n",
"11\n"
] |
Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total.
In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total.
| 500
|
[
{
"input": "4 of week",
"output": "52"
},
{
"input": "30 of month",
"output": "11"
},
{
"input": "17 of month",
"output": "12"
},
{
"input": "31 of month",
"output": "7"
},
{
"input": "6 of week",
"output": "53"
},
{
"input": "1 of week",
"output": "52"
},
{
"input": "2 of week",
"output": "52"
},
{
"input": "3 of week",
"output": "52"
},
{
"input": "5 of week",
"output": "53"
},
{
"input": "7 of week",
"output": "52"
},
{
"input": "1 of month",
"output": "12"
},
{
"input": "2 of month",
"output": "12"
},
{
"input": "3 of month",
"output": "12"
},
{
"input": "4 of month",
"output": "12"
},
{
"input": "5 of month",
"output": "12"
},
{
"input": "6 of month",
"output": "12"
},
{
"input": "7 of month",
"output": "12"
},
{
"input": "8 of month",
"output": "12"
},
{
"input": "9 of month",
"output": "12"
},
{
"input": "10 of month",
"output": "12"
},
{
"input": "11 of month",
"output": "12"
},
{
"input": "12 of month",
"output": "12"
},
{
"input": "13 of month",
"output": "12"
},
{
"input": "14 of month",
"output": "12"
},
{
"input": "15 of month",
"output": "12"
},
{
"input": "16 of month",
"output": "12"
},
{
"input": "18 of month",
"output": "12"
},
{
"input": "19 of month",
"output": "12"
},
{
"input": "20 of month",
"output": "12"
},
{
"input": "21 of month",
"output": "12"
},
{
"input": "22 of month",
"output": "12"
},
{
"input": "23 of month",
"output": "12"
},
{
"input": "24 of month",
"output": "12"
},
{
"input": "25 of month",
"output": "12"
},
{
"input": "26 of month",
"output": "12"
},
{
"input": "27 of month",
"output": "12"
},
{
"input": "28 of month",
"output": "12"
},
{
"input": "29 of month",
"output": "12"
}
] | 1,451,488,209
| 309
|
Python 3
|
OK
|
TESTS
| 38
| 62
| 0
|
data = list(input().split())
if data[2] == "week":
if data[0] == "5" or data[0] == "6":
print(53)
else:
print(52)
else:
if int(data[0]) <= 29:
print(12)
elif data[0] == "30":
print(11)
else:
print(7)
|
Title: New Year and Days
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month.
Limak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him.
Input Specification:
The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month.
Output Specification:
Print one integer — the number of candies Limak will save in the year 2016.
Demo Input:
['4 of week\n', '30 of month\n']
Demo Output:
['52\n', '11\n']
Note:
Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total.
In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total.
|
```python
data = list(input().split())
if data[2] == "week":
if data[0] == "5" or data[0] == "6":
print(53)
else:
print(52)
else:
if int(data[0]) <= 29:
print(12)
elif data[0] == "30":
print(11)
else:
print(7)
```
| 3
|
|
757
|
A
|
Gotta Catch Em' All!
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different.
|
Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. .
|
Output a single integer, the answer to the problem.
|
[
"Bulbbasaur\n",
"F\n",
"aBddulbasaurrgndgbualdBdsagaurrgndbb\n"
] |
[
"1\n",
"0\n",
"2\n"
] |
In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
| 500
|
[
{
"input": "Bulbbasaur",
"output": "1"
},
{
"input": "F",
"output": "0"
},
{
"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb",
"output": "2"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr",
"output": "5"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "BBBBBBBBBBssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrr",
"output": "0"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrr",
"output": "10"
},
{
"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"output": "20"
},
{
"input": "CeSlSwec",
"output": "0"
},
{
"input": "PnMrWPBGzVcmRcO",
"output": "0"
},
{
"input": "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM",
"output": "0"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC",
"output": "6"
},
{
"input": "bulsar",
"output": "0"
},
{
"input": "Bblsar",
"output": "0"
},
{
"input": "Bbusar",
"output": "0"
},
{
"input": "Bbular",
"output": "0"
},
{
"input": "Bbulsr",
"output": "0"
},
{
"input": "Bbulsa",
"output": "0"
},
{
"input": "Bbulsar",
"output": "0"
},
{
"input": "Bbulsar",
"output": "0"
},
{
"input": "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh",
"output": "2"
},
{
"input": "Bulbasaur",
"output": "1"
},
{
"input": "BulbasaurBulbasaur",
"output": "2"
},
{
"input": "Bulbbasar",
"output": "0"
},
{
"input": "Bulbasur",
"output": "0"
},
{
"input": "Bulbsaur",
"output": "0"
},
{
"input": "BulbsurBulbsurBulbsurBulbsur",
"output": "0"
},
{
"input": "Blbbasar",
"output": "0"
},
{
"input": "Bulbasar",
"output": "0"
},
{
"input": "BBullllbbaassaauurr",
"output": "1"
},
{
"input": "BulbasaurBulbasar",
"output": "1"
},
{
"input": "BulbasaurBulbsaur",
"output": "1"
},
{
"input": "Bubasaur",
"output": "0"
},
{
"input": "ulbasaurulbasaur",
"output": "0"
},
{
"input": "Bulbasr",
"output": "0"
},
{
"input": "BBBuuulllbbbaaasssaaauuurrr",
"output": "3"
},
{
"input": "BBuuuullbbaaaassrr",
"output": "2"
},
{
"input": "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr",
"output": "4"
},
{
"input": "BBuullbbaassaarr",
"output": "1"
},
{
"input": "Bulbasau",
"output": "0"
},
{
"input": "BBuullbbaassaauurr",
"output": "2"
},
{
"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau",
"output": "0"
},
{
"input": "Blbasaur",
"output": "0"
},
{
"input": "BulbasaurBulbasaurd",
"output": "2"
},
{
"input": "ulbasaur",
"output": "0"
},
{
"input": "Bulbaaur",
"output": "0"
},
{
"input": "BBuuuullbbbbbbbbbbbbbbbaassrr",
"output": "1"
},
{
"input": "Bulbasua",
"output": "0"
},
{
"input": "Bubbasaur",
"output": "0"
},
{
"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr",
"output": "3"
},
{
"input": "BulbasaurBubasaur",
"output": "1"
},
{
"input": "Baab",
"output": "0"
},
{
"input": "BulbasaurBulbasau",
"output": "1"
},
{
"input": "Bulbasauu",
"output": "0"
},
{
"input": "BulbasauBulbasau",
"output": "0"
},
{
"input": "BBBBBBBBBBB",
"output": "0"
},
{
"input": "Bulbbasau",
"output": "0"
},
{
"input": "BulbbasaurBulbbasar",
"output": "1"
},
{
"input": "Bulaaaasaur",
"output": "0"
},
{
"input": "BulbasaurBulbasauBulbasauBulbasau",
"output": "1"
}
] | 1,501,951,546
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 21
| 62
| 4,710,400
|
p="Bulbasaur"
s=input()
ans=100000
for c in p:
k=s.count(c)
if c=='a':k//=2
ans=min(ans,k)
print(ans)
|
Title: Gotta Catch Em' All!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different.
Input Specification:
Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. .
Output Specification:
Output a single integer, the answer to the problem.
Demo Input:
['Bulbbasaur\n', 'F\n', 'aBddulbasaurrgndgbualdBdsagaurrgndbb\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
|
```python
p="Bulbasaur"
s=input()
ans=100000
for c in p:
k=s.count(c)
if c=='a':k//=2
ans=min(ans,k)
print(ans)
```
| 0
|
|
451
|
B
|
Sort the Array
|
PROGRAMMING
| 1,300
|
[
"implementation",
"sortings"
] | null | null |
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes.
|
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109).
|
Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.
|
[
"3\n3 2 1\n",
"4\n2 1 3 4\n",
"4\n3 1 2 4\n",
"2\n1 2\n"
] |
[
"yes\n1 3\n",
"yes\n1 2\n",
"no\n",
"yes\n1 1\n"
] |
Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment [*l*, *r*], the array will become:
*a*[1], *a*[2], ..., *a*[*l* - 2], *a*[*l* - 1], *a*[*r*], *a*[*r* - 1], ..., *a*[*l* + 1], *a*[*l*], *a*[*r* + 1], *a*[*r* + 2], ..., *a*[*n* - 1], *a*[*n*].
| 1,000
|
[
{
"input": "3\n3 2 1",
"output": "yes\n1 3"
},
{
"input": "4\n2 1 3 4",
"output": "yes\n1 2"
},
{
"input": "4\n3 1 2 4",
"output": "no"
},
{
"input": "2\n1 2",
"output": "yes\n1 1"
},
{
"input": "2\n58 4",
"output": "yes\n1 2"
},
{
"input": "5\n69 37 27 4 2",
"output": "yes\n1 5"
},
{
"input": "9\n6 78 63 59 28 24 8 96 99",
"output": "yes\n2 7"
},
{
"input": "6\n19517752 43452931 112792556 68417469 779722934 921694415",
"output": "yes\n3 4"
},
{
"input": "6\n169793171 335736854 449917902 513287332 811627074 938727967",
"output": "yes\n1 1"
},
{
"input": "6\n509329 173849943 297546987 591032670 796346199 914588283",
"output": "yes\n1 1"
},
{
"input": "25\n46 45 37 35 26 25 21 19 11 3 1 51 54 55 57 58 59 62 66 67 76 85 88 96 100",
"output": "yes\n1 11"
},
{
"input": "46\n10 12 17 19 20 21 22 24 25 26 27 28 29 30 32 37 42 43 47 48 50 51 52 56 87 86 81 79 74 71 69 67 66 65 60 59 57 89 91 92 94 96 97 98 99 100",
"output": "yes\n25 37"
},
{
"input": "96\n1 2 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 68 69 70 71 72 73 74 75 76 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "yes\n3 22"
},
{
"input": "2\n404928771 698395106",
"output": "yes\n1 1"
},
{
"input": "2\n699573624 308238132",
"output": "yes\n1 2"
},
{
"input": "5\n75531609 242194958 437796493 433259361 942142185",
"output": "yes\n3 4"
},
{
"input": "5\n226959376 840957605 833410429 273566427 872976052",
"output": "yes\n2 4"
},
{
"input": "5\n373362086 994096202 767275079 734424844 515504383",
"output": "yes\n2 5"
},
{
"input": "5\n866379155 593548704 259097686 216134784 879911740",
"output": "yes\n1 4"
},
{
"input": "5\n738083041 719956102 420866851 307749161 257917459",
"output": "yes\n1 5"
},
{
"input": "5\n90786760 107075352 139104198 424911569 858427981",
"output": "yes\n1 1"
},
{
"input": "6\n41533825 525419745 636375901 636653266 879043107 967434399",
"output": "yes\n1 1"
},
{
"input": "40\n22993199 75843013 76710455 99749069 105296587 122559115 125881005 153961749 163646706 175409222 185819807 214465092 264449243 278246513 295514446 322935239 370349154 375773209 390474983 775646826 767329655 740310077 718820037 708508595 693119912 680958422 669537382 629123011 607511013 546574974 546572137 511951383 506996390 493995578 458256840 815612821 881161983 901337648 962275390 986568907",
"output": "yes\n20 35"
},
{
"input": "40\n3284161 23121669 24630274 33434127 178753820 231503277 271972002 272578266 346450638 355655265 372217434 376132047 386622863 387235708 389799554 427160037 466577363 491873718 492746058 502535866 535768673 551570285 557477055 583643014 586216753 588981593 592960633 605923775 611051145 643142759 632768011 634888864 736715552 750574599 867737742 924365786 927179496 934453020 954090860 977765165",
"output": "no"
},
{
"input": "40\n42131757 49645896 49957344 78716964 120937785 129116222 172128600 211446903 247833196 779340466 717548386 709969818 696716905 636153997 635635467 614115746 609201167 533608141 521874836 273044950 291514539 394083281 399369419 448830087 485128983 487192341 488673105 497678164 501864738 265305156 799595875 831638598 835155840 845617770 847736630 851436542 879757553 885618675 964068808 969215471",
"output": "no"
},
{
"input": "40\n25722567 28250400 47661056 108729970 119887370 142272261 145287693 178946020 182917658 187405805 209478929 278713296 312035195 393514697 403876943 410188367 413061616 420619615 477231590 511200584 560288373 571690007 603093961 615463729 631624043 723138759 726089658 728151980 756393077 785590533 809755752 823601179 828357990 866942019 869575503 877310377 881382070 901314141 929048602 947139655",
"output": "yes\n1 1"
},
{
"input": "40\n17927221 33153935 60257083 110553879 114654567 119809916 163899753 167741765 182812464 188486743 220036903 220127072 227545828 229552200 244963635 248298934 299478582 354141058 371400641 430054473 452548736 458695269 466968129 469000714 478004472 478693873 509342093 750631027 609759323 669427158 688490225 690701652 696893030 704668825 749028408 557906039 545356441 926901326 955586118 972642992",
"output": "no"
},
{
"input": "4\n1 4 2 3",
"output": "no"
},
{
"input": "6\n1 2 5 4 3 6",
"output": "yes\n3 5"
},
{
"input": "1\n1",
"output": "yes\n1 1"
},
{
"input": "6\n1 5 3 4 2 6",
"output": "no"
},
{
"input": "4\n3 4 1 2",
"output": "no"
},
{
"input": "5\n2 5 4 3 1",
"output": "no"
},
{
"input": "4\n2 1 4 3",
"output": "no"
},
{
"input": "6\n2 1 4 3 5 6",
"output": "no"
}
] | 1,677,762,072
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 76
| 77
| 8,089,600
|
n = int(input())
s=list(map(int, input().split()))
s1= sorted(s)
g = 0
q = 0
d=0
for i in range(len(s1)):
if s[i]!=s1[i]:
d = s[i]
g = i
q = s1.index(s[i])
break
if s[0:g]+s[g:q+1:][::-1]+s[q+1:]==s1:
print('yes')
print(g+1,q+1)
else:
print('no')
|
Title: Sort the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109).
Output Specification:
Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.
Demo Input:
['3\n3 2 1\n', '4\n2 1 3 4\n', '4\n3 1 2 4\n', '2\n1 2\n']
Demo Output:
['yes\n1 3\n', 'yes\n1 2\n', 'no\n', 'yes\n1 1\n']
Note:
Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment [*l*, *r*], the array will become:
*a*[1], *a*[2], ..., *a*[*l* - 2], *a*[*l* - 1], *a*[*r*], *a*[*r* - 1], ..., *a*[*l* + 1], *a*[*l*], *a*[*r* + 1], *a*[*r* + 2], ..., *a*[*n* - 1], *a*[*n*].
|
```python
n = int(input())
s=list(map(int, input().split()))
s1= sorted(s)
g = 0
q = 0
d=0
for i in range(len(s1)):
if s[i]!=s1[i]:
d = s[i]
g = i
q = s1.index(s[i])
break
if s[0:g]+s[g:q+1:][::-1]+s[q+1:]==s1:
print('yes')
print(g+1,q+1)
else:
print('no')
```
| 3
|
|
443
|
A
|
Anton and Letters
|
PROGRAMMING
| 800
|
[
"constructive algorithms",
"implementation"
] | null | null |
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
|
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
|
Print a single number — the number of distinct letters in Anton's set.
|
[
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] |
[
"3\n",
"2\n",
"0\n"
] |
none
| 500
|
[
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}",
"output": "1"
},
{
"input": "{a, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 1,685,395,768
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 27
| 46
| 921,600
|
import re
def countDistinctCharacters(s):
# Remove non-alphabetic characters and convert to lowercase
s = re.sub('[^a-z]', '', s.lower())
# Count the number of distinct characters
distinct_chars = set(s)
count = len(distinct_chars)
return count
# Read the input string
input_string = input()
# Count the number of distinct characters
distinct_count = countDistinctCharacters(input_string)
# Print the result
print(distinct_count)
|
Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
Input Specification:
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Output Specification:
Print a single number — the number of distinct letters in Anton's set.
Demo Input:
['{a, b, c}\n', '{b, a, b, a}\n', '{}\n']
Demo Output:
['3\n', '2\n', '0\n']
Note:
none
|
```python
import re
def countDistinctCharacters(s):
# Remove non-alphabetic characters and convert to lowercase
s = re.sub('[^a-z]', '', s.lower())
# Count the number of distinct characters
distinct_chars = set(s)
count = len(distinct_chars)
return count
# Read the input string
input_string = input()
# Count the number of distinct characters
distinct_count = countDistinctCharacters(input_string)
# Print the result
print(distinct_count)
```
| 3
|
|
920
|
F
|
SUM and REPLACE
|
PROGRAMMING
| 2,000
|
[
"brute force",
"data structures",
"dsu",
"number theory"
] | null | null |
Let *D*(*x*) be the number of positive divisors of a positive integer *x*. For example, *D*(2)<==<=2 (2 is divisible by 1 and 2), *D*(6)<==<=4 (6 is divisible by 1, 2, 3 and 6).
You are given an array *a* of *n* integers. You have to process two types of queries:
1. REPLACE *l* *r* — for every replace *a**i* with *D*(*a**i*); 1. SUM *l* *r* — calculate .
Print the answer for each SUM query.
|
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the number of elements in the array and the number of queries to process, respectively.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the elements of the array.
Then *m* lines follow, each containing 3 integers *t**i*, *l**i*, *r**i* denoting *i*-th query. If *t**i*<==<=1, then *i*-th query is REPLACE *l**i* *r**i*, otherwise it's SUM *l**i* *r**i* (1<=≤<=*t**i*<=≤<=2, 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
There is at least one SUM query.
|
For each SUM query print the answer to it.
|
[
"7 6\n6 4 1 10 3 2 4\n2 1 7\n2 4 5\n1 3 5\n2 4 4\n1 5 7\n2 1 7\n"
] |
[
"30\n13\n4\n22\n"
] |
none
| 0
|
[
{
"input": "7 6\n6 4 1 10 3 2 4\n2 1 7\n2 4 5\n1 3 5\n2 4 4\n1 5 7\n2 1 7",
"output": "30\n13\n4\n22"
},
{
"input": "4 2\n1 1 1 3\n1 1 4\n2 1 4",
"output": "5"
},
{
"input": "10 2\n1 1 1 1 1 1 1 1 1 9\n1 1 10\n2 1 10",
"output": "12"
},
{
"input": "4 2\n1 1 3 1\n1 1 4\n2 1 4",
"output": "5"
},
{
"input": "5 3\n1 1 1 1 3\n2 1 5\n1 1 5\n2 1 5",
"output": "7\n6"
},
{
"input": "7 10\n1 1 1 1 1 1 1\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n2 1 7",
"output": "7"
}
] | 1,629,405,734
| 2,147,483,647
|
PyPy 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 1
| 2,000
| 47,616,000
|
from sys import stdin
import collections, heapq, bisect, math
input = stdin.readline
def rint():
return int(input())
def rstr():
return input().strip()
def rlstr():
return list(input().strip().split())
def rlint():
return list(map(int, input().split()))
def seive() :
n = 10**6 + 1
prime = [0]*n
for i in range(2 , n) :
if prime[i] == 0 :
prime[i] = i
for j in range(i*i , n , i) :
if prime[j] == 0 :
prime[j] = i
return prime
prime = seive()
def D(x) :
res = 1
while x > 1 :
div = prime[x]
a = 1
while div == prime[x] :
x = x // div
a += 1
res *= a
return res
def main():
n , m = rlint()
a = rlint()
tree = [0]*(2*n + 1)
for i in range(n) :
tree[i + n] = a[i]
for i in range(n - 1 , 0 , -1) :
tree[i] = tree[2*i] + tree[2*i + 1]
for _ in range(m) :
t , l , r = rlint()
l = l + n - 1
r = r + n - 1
if t == 1 :
for k in range(l , r + 1) :
tree[k] = D(tree[k])
k //= 2
while k > 0 :
tree[k] = tree[2*k] + tree[2*k + 1]
k //= 2
else :
res = 0
while l <= r :
if l % 2 == 1 :
res += tree[l]
l += 1
if r % 2 == 0 :
res += tree[r]
r -= 1
l //= 2
r //= 2
print(res)
if __name__ == "__main__":
main()
|
Title: SUM and REPLACE
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let *D*(*x*) be the number of positive divisors of a positive integer *x*. For example, *D*(2)<==<=2 (2 is divisible by 1 and 2), *D*(6)<==<=4 (6 is divisible by 1, 2, 3 and 6).
You are given an array *a* of *n* integers. You have to process two types of queries:
1. REPLACE *l* *r* — for every replace *a**i* with *D*(*a**i*); 1. SUM *l* *r* — calculate .
Print the answer for each SUM query.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the number of elements in the array and the number of queries to process, respectively.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the elements of the array.
Then *m* lines follow, each containing 3 integers *t**i*, *l**i*, *r**i* denoting *i*-th query. If *t**i*<==<=1, then *i*-th query is REPLACE *l**i* *r**i*, otherwise it's SUM *l**i* *r**i* (1<=≤<=*t**i*<=≤<=2, 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
There is at least one SUM query.
Output Specification:
For each SUM query print the answer to it.
Demo Input:
['7 6\n6 4 1 10 3 2 4\n2 1 7\n2 4 5\n1 3 5\n2 4 4\n1 5 7\n2 1 7\n']
Demo Output:
['30\n13\n4\n22\n']
Note:
none
|
```python
from sys import stdin
import collections, heapq, bisect, math
input = stdin.readline
def rint():
return int(input())
def rstr():
return input().strip()
def rlstr():
return list(input().strip().split())
def rlint():
return list(map(int, input().split()))
def seive() :
n = 10**6 + 1
prime = [0]*n
for i in range(2 , n) :
if prime[i] == 0 :
prime[i] = i
for j in range(i*i , n , i) :
if prime[j] == 0 :
prime[j] = i
return prime
prime = seive()
def D(x) :
res = 1
while x > 1 :
div = prime[x]
a = 1
while div == prime[x] :
x = x // div
a += 1
res *= a
return res
def main():
n , m = rlint()
a = rlint()
tree = [0]*(2*n + 1)
for i in range(n) :
tree[i + n] = a[i]
for i in range(n - 1 , 0 , -1) :
tree[i] = tree[2*i] + tree[2*i + 1]
for _ in range(m) :
t , l , r = rlint()
l = l + n - 1
r = r + n - 1
if t == 1 :
for k in range(l , r + 1) :
tree[k] = D(tree[k])
k //= 2
while k > 0 :
tree[k] = tree[2*k] + tree[2*k + 1]
k //= 2
else :
res = 0
while l <= r :
if l % 2 == 1 :
res += tree[l]
l += 1
if r % 2 == 0 :
res += tree[r]
r -= 1
l //= 2
r //= 2
print(res)
if __name__ == "__main__":
main()
```
| 0
|
|
8
|
A
|
Train and Peter
|
PROGRAMMING
| 1,200
|
[
"strings"
] |
A. Train and Peter
|
1
|
64
|
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.
|
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.
|
Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences.
|
[
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] |
[
"forward\n",
"both\n"
] |
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.
| 0
|
[
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
"output": "both"
},
{
"input": "a\na\na",
"output": "fantasy"
},
{
"input": "ab\nb\na",
"output": "backward"
},
{
"input": "aaa\naaaa\naaaa",
"output": "fantasy"
},
{
"input": "bbabbbbababbaabaabaa\nabb\nbaab",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\nabaabababaa\nabaabbaa",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\nabaabababaa\nabaabbaa",
"output": "backward"
},
{
"input": "aaaa\naaa\naa",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzzzz\nzzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzz",
"output": "both"
},
{
"input": "aabaa\naab\nbaa",
"output": "fantasy"
},
{
"input": "aabaab\naba\nab",
"output": "forward"
},
{
"input": "aab\nb\naa",
"output": "backward"
},
{
"input": "abacaba\naca\nba",
"output": "both"
}
] | 1,573,308,340
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 216
| 307,200
|
m1 = input()
a = input()
b = input()
length = len(m1)
m2 = ""
r1 = False
r2 = False
for i in range(length):
m2 = m2 + m1[length-i-1]
for i in range(length):
if m1[i:i+len(a)] == a :
r1 = True
if r1 == True and m1[i+len(a):i+len(a)+len(b)] == b :
r2 = True
if r1 == True and r2 == True : break
r3 = False
r4 = False
for i in range(length):
if m2[i:i + len(a)] == a:
r3 = True
if r3 == True and m2[i + len(a):i + len(a) + len(b)] == b:
r4 = True
if r3 == True and r4 == True: break
if r1 == True and r2 == True and r3 == True and r4 == True : print("both")
if r1 == True and r2 == True and (r3 == False or r4 == False) : print("forward")
if r1 == False or r2 == False and r3 == True and r4 == True : print("backward")
if r1 == False or r2 == False and (r3 == False or r4 == False) : print("fantasy")
|
Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.
Input Specification:
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.
Output Specification:
Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences.
Demo Input:
['atob\na\nb\n', 'aaacaaa\naca\naa\n']
Demo Output:
['forward\n', 'both\n']
Note:
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.
|
```python
m1 = input()
a = input()
b = input()
length = len(m1)
m2 = ""
r1 = False
r2 = False
for i in range(length):
m2 = m2 + m1[length-i-1]
for i in range(length):
if m1[i:i+len(a)] == a :
r1 = True
if r1 == True and m1[i+len(a):i+len(a)+len(b)] == b :
r2 = True
if r1 == True and r2 == True : break
r3 = False
r4 = False
for i in range(length):
if m2[i:i + len(a)] == a:
r3 = True
if r3 == True and m2[i + len(a):i + len(a) + len(b)] == b:
r4 = True
if r3 == True and r4 == True: break
if r1 == True and r2 == True and r3 == True and r4 == True : print("both")
if r1 == True and r2 == True and (r3 == False or r4 == False) : print("forward")
if r1 == False or r2 == False and r3 == True and r4 == True : print("backward")
if r1 == False or r2 == False and (r3 == False or r4 == False) : print("fantasy")
```
| 0
|
472
|
A
|
Design Tutorial: Learn from Math
|
PROGRAMMING
| 800
|
[
"math",
"number theory"
] | null | null |
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
|
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
|
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
|
[
"12\n",
"15\n",
"23\n",
"1000000\n"
] |
[
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] |
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
| 500
|
[
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
{
"input": "192",
"output": "4 188"
},
{
"input": "86",
"output": "4 82"
},
{
"input": "46220",
"output": "4 46216"
},
{
"input": "57114",
"output": "4 57110"
},
{
"input": "869",
"output": "4 865"
},
{
"input": "738457",
"output": "4 738453"
},
{
"input": "58113",
"output": "6 58107"
},
{
"input": "4864",
"output": "4 4860"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "74752",
"output": "4 74748"
},
{
"input": "6073",
"output": "4 6069"
},
{
"input": "1289",
"output": "4 1285"
},
{
"input": "20",
"output": "4 16"
},
{
"input": "58134",
"output": "4 58130"
},
{
"input": "57756",
"output": "4 57752"
},
{
"input": "765",
"output": "6 759"
},
{
"input": "59",
"output": "4 55"
},
{
"input": "991666",
"output": "4 991662"
},
{
"input": "70761",
"output": "4 70757"
},
{
"input": "13",
"output": "4 9"
},
{
"input": "999999",
"output": "4 999995"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "21",
"output": "6 15"
},
{
"input": "19",
"output": "4 15"
},
{
"input": "100007",
"output": "6 100001"
},
{
"input": "999987",
"output": "6 999981"
},
{
"input": "22",
"output": "4 18"
}
] | 1,662,284,906
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 30
| 0
|
def Tri_Bulle(L):
ok = True
while ok == True:
ok = False
for i in range(len(L) - 1):
if L[i] > L[i+1]:
Aux = L[i+1]
L[i+1] = L[i]
L[i] = Aux
ok = True
return L
x1,x2,x3 = Tri_Bulle(list(map(int, input().split())))
def diff(a,b):
while a != b:
if a > b:
return b - a
else:
return a - b
print(abs(diff(x1,x2) + diff(x3,x2)))
|
Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
Input Specification:
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output Specification:
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
Demo Input:
['12\n', '15\n', '23\n', '1000000\n']
Demo Output:
['4 8\n', '6 9\n', '8 15\n', '500000 500000\n']
Note:
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
|
```python
def Tri_Bulle(L):
ok = True
while ok == True:
ok = False
for i in range(len(L) - 1):
if L[i] > L[i+1]:
Aux = L[i+1]
L[i+1] = L[i]
L[i] = Aux
ok = True
return L
x1,x2,x3 = Tri_Bulle(list(map(int, input().split())))
def diff(a,b):
while a != b:
if a > b:
return b - a
else:
return a - b
print(abs(diff(x1,x2) + diff(x3,x2)))
```
| -1
|
|
289
|
A
|
Polo the Penguin and Segments
|
PROGRAMMING
| 1,100
|
[
"brute force",
"implementation"
] | null | null |
Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*).
He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [*l*; *r*] to either segment [*l*<=-<=1; *r*], or to segment [*l*; *r*<=+<=1].
The value of a set of segments that consists of *n* segments [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*] is the number of integers *x*, such that there is integer *j*, for which the following inequality holds, *l**j*<=≤<=*x*<=≤<=*r**j*.
Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by *k*.
|
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). Each of the following *n* lines contain a segment as a pair of integers *l**i* and *r**i* (<=-<=105<=≤<=*l**i*<=≤<=*r**i*<=≤<=105), separated by a space.
It is guaranteed that no two segments intersect. In other words, for any two integers *i*,<=*j* (1<=≤<=*i*<=<<=*j*<=≤<=*n*) the following inequality holds, *min*(*r**i*,<=*r**j*)<=<<=*max*(*l**i*,<=*l**j*).
|
In a single line print a single integer — the answer to the problem.
|
[
"2 3\n1 2\n3 4\n",
"3 7\n1 2\n3 3\n4 7\n"
] |
[
"2\n",
"0\n"
] |
none
| 500
|
[
{
"input": "2 3\n1 2\n3 4",
"output": "2"
},
{
"input": "3 7\n1 2\n3 3\n4 7",
"output": "0"
},
{
"input": "3 7\n1 10\n11 47\n74 128",
"output": "3"
},
{
"input": "5 4\n1 1\n2 2\n3 3\n4 4\n5 5",
"output": "3"
},
{
"input": "7 4\n2 2\n-1 -1\n0 1\n7 8\n-3 -2\n9 9\n4 6",
"output": "0"
},
{
"input": "10 2\n92 92\n55 59\n70 73\n78 81\n62 65\n95 99\n74 75\n85 87\n51 51\n60 60",
"output": "0"
},
{
"input": "10 474\n56 60\n82 82\n73 73\n105 109\n77 80\n51 51\n85 88\n97 100\n91 92\n64 68",
"output": "442"
},
{
"input": "47 21\n3 5\n-422 -417\n60 60\n-348 -348\n-3 -3\n-364 -361\n-49 -41\n-436 -430\n-250 -244\n-33 -26\n-162 -158\n-90 -88\n-357 -352\n-339 -337\n-25 -19\n-69 -67\n-261 -260\n-292 -283\n12 18\n44 44\n-277 -275\n-301 -293\n-108 -98\n-180 -172\n-327 -318\n-314 -309\n-12 -7\n-134 -130\n33 35\n-190 -184\n-65 -55\n-242 -240\n-448 -444\n-408 -405\n53 57\n-145 -144\n-207 -200\n-110 -110\n-221 -216\n-122 -112\n26 27\n-271 -269\n-82 -79\n-235 -229\n-382 -373\n-397 -391\n-155 -153",
"output": "18"
},
{
"input": "3 4587\n-49 368\n-734 -390\n-380 -117",
"output": "3560"
},
{
"input": "1 100000\n-100000 100000",
"output": "99999"
},
{
"input": "2 100000\n-100000 99999\n100000 100000",
"output": "99999"
},
{
"input": "1 7\n0 0",
"output": "6"
},
{
"input": "2 5848\n-100000 0\n1 100000",
"output": "4679"
},
{
"input": "3 99999\n-100000 -100000\n-99999 99998\n99999 100000",
"output": "99996"
}
] | 1,588,702,784
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 28
| 622
| 0
|
n,k=map(int,input().split())
value=0
for i in range(n):
l,r=map(int,input().split())
diff=r-l+1
value+=diff
if value%k==0: print('0')
else :
print((value//k+1)*k-value)
|
Title: Polo the Penguin and Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*).
He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [*l*; *r*] to either segment [*l*<=-<=1; *r*], or to segment [*l*; *r*<=+<=1].
The value of a set of segments that consists of *n* segments [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*] is the number of integers *x*, such that there is integer *j*, for which the following inequality holds, *l**j*<=≤<=*x*<=≤<=*r**j*.
Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by *k*.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). Each of the following *n* lines contain a segment as a pair of integers *l**i* and *r**i* (<=-<=105<=≤<=*l**i*<=≤<=*r**i*<=≤<=105), separated by a space.
It is guaranteed that no two segments intersect. In other words, for any two integers *i*,<=*j* (1<=≤<=*i*<=<<=*j*<=≤<=*n*) the following inequality holds, *min*(*r**i*,<=*r**j*)<=<<=*max*(*l**i*,<=*l**j*).
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['2 3\n1 2\n3 4\n', '3 7\n1 2\n3 3\n4 7\n']
Demo Output:
['2\n', '0\n']
Note:
none
|
```python
n,k=map(int,input().split())
value=0
for i in range(n):
l,r=map(int,input().split())
diff=r-l+1
value+=diff
if value%k==0: print('0')
else :
print((value//k+1)*k-value)
```
| 3
|
|
32
|
A
|
Reconnaissance
|
PROGRAMMING
| 800
|
[
"brute force"
] |
A. Reconnaissance
|
2
|
256
|
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1,<=2) and (2,<=1) should be regarded as different.
|
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
|
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*.
|
[
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] |
[
"6\n",
"6\n"
] |
none
| 500
|
[
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
"output": "20"
},
{
"input": "10 4\n11 6 76 49 28 20 57 152 5 32",
"output": "4"
},
{
"input": "100 100\n51 93 101 960 2 477 213 129 663 925 254 78 1486 274 160 481 132 156 412 372 5 57 152 298 1771 7 359 468 254 406 202 929 221 366 552 97 555 29 822 118 539 140 992 854 7 163 134 103 940 30 409 1003 398 43 555 79 107 40 23 103 643 171 310 382 770 337 18 189 570 177 29 54 855 171 205 291 299 935 620 180 114 358 88 292 118 400 218 537 369 60 683 192 13 537 59 824 264 191 3 300",
"output": "2404"
}
] | 1,627,872,076
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 32
| 248
| 21,708,800
|
def classroom(n,a,lst):
ans=0
for i in range(len(lst)):
for j in range(len(lst)):
if i==j: continue
if abs(lst[i]-lst[j])<=a:
ans+=1
return ans
n,a=map(int,input().split())
lst=list(map(int,input().split()))
print(classroom(n,a,lst))
|
Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1,<=2) and (2,<=1) should be regarded as different.
Input Specification:
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output Specification:
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*.
Demo Input:
['5 10\n10 20 50 60 65\n', '5 1\n55 30 29 31 55\n']
Demo Output:
['6\n', '6\n']
Note:
none
|
```python
def classroom(n,a,lst):
ans=0
for i in range(len(lst)):
for j in range(len(lst)):
if i==j: continue
if abs(lst[i]-lst[j])<=a:
ans+=1
return ans
n,a=map(int,input().split())
lst=list(map(int,input().split()))
print(classroom(n,a,lst))
```
| 3.897564
|
577
|
B
|
Modulo Sum
|
PROGRAMMING
| 1,900
|
[
"combinatorics",
"data structures",
"dp",
"two pointers"
] | null | null |
You are given a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n*, and a number *m*.
Check if it is possible to choose a non-empty subsequence *a**i**j* such that the sum of numbers in this subsequence is divisible by *m*.
|
The first line contains two numbers, *n* and *m* (1<=≤<=*n*<=≤<=106, 2<=≤<=*m*<=≤<=103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
|
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
|
[
"3 5\n1 2 3\n",
"1 6\n5\n",
"4 6\n3 1 1 3\n",
"6 6\n5 5 5 5 5 5\n"
] |
[
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] |
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
| 1,250
|
[
{
"input": "3 5\n1 2 3",
"output": "YES"
},
{
"input": "1 6\n5",
"output": "NO"
},
{
"input": "4 6\n3 1 1 3",
"output": "YES"
},
{
"input": "6 6\n5 5 5 5 5 5",
"output": "YES"
},
{
"input": "4 5\n1 1 1 1",
"output": "NO"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "YES"
},
{
"input": "4 7\n1 2 3 3",
"output": "YES"
},
{
"input": "1 47\n0",
"output": "YES"
},
{
"input": "2 47\n1 0",
"output": "YES"
},
{
"input": "9 11\n8 8 8 8 8 8 8 8 5",
"output": "NO"
},
{
"input": "10 11\n8 8 8 8 8 8 8 8 7 8",
"output": "YES"
},
{
"input": "3 5\n2 1 3",
"output": "YES"
},
{
"input": "100 968\n966 966 967 966 967 967 967 967 966 966 966 967 966 966 966 967 967 966 966 967 967 967 967 966 967 967 967 967 563 967 967 967 600 967 967 966 967 966 967 966 967 966 967 966 966 966 967 966 967 966 966 967 967 193 966 966 967 966 967 967 967 966 967 966 966 580 966 967 966 966 967 966 966 966 967 967 967 967 966 967 967 966 966 966 967 967 966 966 967 966 966 966 967 966 966 967 966 967 966 966",
"output": "YES"
},
{
"input": "100 951\n950 949 949 949 949 950 950 949 949 950 950 949 949 949 496 949 950 949 950 159 950 949 949 950 950 949 950 949 949 950 949 950 949 949 950 949 950 950 950 950 949 949 949 949 949 950 950 950 950 950 950 950 949 950 949 949 950 949 950 950 949 950 950 950 949 950 949 950 950 950 950 949 949 950 950 949 950 950 950 950 949 950 950 949 949 635 612 949 949 949 949 949 949 949 950 949 949 950 949 950",
"output": "YES"
},
{
"input": "100 940\n1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 1 1 1 2 2 1 1 1 2 2 2 2 1 1 1 1 2 2 1 403 2 2 1 1 1 2 2 2 1 2 2 1 1 2 2 1 1 1 1 2 1 2 691 1 2 1 1 1 1 1 2 2 2 2 2 1 2 1 1 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 1 1 2 2 1 1 2 786 1",
"output": "YES"
},
{
"input": "100 917\n2 1 2 2 2 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 1 1 1 1 2 1 1 1 2 1 1 2 1 1 1 1 2 1 2 340 2 399 2 1 2 2 2 2 178 1 1 2 1 1 1 2 2 1 2 2 2 1 2 1 1 1 1 1 1 2 1 1 1 2 2 1 1 2 2 2 1 2 2 2 2 1 2 1 2 2 2 2 2 1 1 2 2 2 2",
"output": "YES"
},
{
"input": "1 2\n1000000000",
"output": "YES"
}
] | 1,695,041,934
| 2,147,483,647
|
PyPy 3-64
|
MEMORY_LIMIT_EXCEEDED
|
TESTS
| 0
| 46
| 268,390,400
|
import sys
def input() : return sys.stdin.readline().strip()
def getints() : return map(int,sys.stdin.readline().strip().split())
import bisect
left = lambda l,a : bisect.bisect_left(l,a)
right = lambda l,a : bisect.bisect_right(l,a)
sys.setrecursionlimit(1000000)
n,m = getints()
l = list(getints())
c = {}
for x in l:
x %= m
if x in c: c[x] += 1
else: c[x] = 1
s = set()
for x in c:
t = x
for y in range(c[x]):
s.add(t%m)
t = (t+x)%m
l = list(s)
n = len(l)
def solve(t,i):
if t == 0: return True
if i >= n: return False
return solve((t+l[i])%m,i+1) or solve(t,i+1)
print('YES' if solve(m,0) else 'NO')
|
Title: Modulo Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n*, and a number *m*.
Check if it is possible to choose a non-empty subsequence *a**i**j* such that the sum of numbers in this subsequence is divisible by *m*.
Input Specification:
The first line contains two numbers, *n* and *m* (1<=≤<=*n*<=≤<=106, 2<=≤<=*m*<=≤<=103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
Output Specification:
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Demo Input:
['3 5\n1 2 3\n', '1 6\n5\n', '4 6\n3 1 1 3\n', '6 6\n5 5 5 5 5 5\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'YES\n']
Note:
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
```python
import sys
def input() : return sys.stdin.readline().strip()
def getints() : return map(int,sys.stdin.readline().strip().split())
import bisect
left = lambda l,a : bisect.bisect_left(l,a)
right = lambda l,a : bisect.bisect_right(l,a)
sys.setrecursionlimit(1000000)
n,m = getints()
l = list(getints())
c = {}
for x in l:
x %= m
if x in c: c[x] += 1
else: c[x] = 1
s = set()
for x in c:
t = x
for y in range(c[x]):
s.add(t%m)
t = (t+x)%m
l = list(s)
n = len(l)
def solve(t,i):
if t == 0: return True
if i >= n: return False
return solve((t+l[i])%m,i+1) or solve(t,i+1)
print('YES' if solve(m,0) else 'NO')
```
| 0
|
|
1
|
C
|
Ancient Berland Circus
|
PROGRAMMING
| 2,100
|
[
"geometry",
"math"
] |
C. Ancient Berland Circus
|
2
|
64
|
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.
In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a special pillar, and the rope strung between the pillars marked the arena edges.
Recently the scientists from Berland have discovered the remains of the ancient circus arena. They found only three pillars, the others were destroyed by the time.
You are given the coordinates of these three pillars. Find out what is the smallest area that the arena could have.
|
The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point.
|
Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100.
|
[
"0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000\n"
] |
[
"1.00000000\n"
] | 0
|
[
{
"input": "0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000",
"output": "1.00000000"
},
{
"input": "71.756151 7.532275\n-48.634784 100.159986\n91.778633 158.107739",
"output": "9991.27897663"
},
{
"input": "18.716839 40.852752\n66.147248 -4.083161\n111.083161 43.347248",
"output": "4268.87997505"
},
{
"input": "-13.242302 -45.014124\n-33.825369 51.083964\n84.512928 -55.134407",
"output": "16617.24002771"
},
{
"input": "115.715093 141.583620\n136.158119 -23.780834\n173.673212 64.802787",
"output": "24043.74046813"
},
{
"input": "17.288379 68.223317\n48.776683 71.688379\n23.170559 106.572762",
"output": "1505.27997374"
},
{
"input": "76.820252 66.709341\n61.392328 82.684207\n44.267775 -2.378694",
"output": "6503.44762335"
},
{
"input": "-46.482632 -31.161247\n19.689679 -70.646972\n-17.902656 -58.455808",
"output": "23949.55226823"
},
{
"input": "34.236058 108.163949\n28.639345 104.566515\n25.610069 86.002927",
"output": "780.93431702"
},
{
"input": "25.428124 39.407248\n17.868098 39.785933\n11.028461 43.028890",
"output": "1152.21351717"
},
{
"input": "36.856072 121.845502\n46.453956 109.898647\n-30.047767 77.590282",
"output": "5339.35578947"
},
{
"input": "-18.643272 56.008305\n9.107608 -22.094058\n-6.456146 70.308320",
"output": "9009.25177521"
},
{
"input": "88.653021 18.024220\n51.942488 -2.527850\n76.164701 24.553012",
"output": "1452.52866331"
},
{
"input": "80.181999 -38.076894\n23.381778 122.535736\n47.118815 140.734014",
"output": "28242.17663744"
},
{
"input": "1.514204 81.400629\n32.168797 100.161401\n7.778734 46.010993",
"output": "3149.43107333"
},
{
"input": "84.409605 38.496141\n77.788313 39.553807\n75.248391 59.413884",
"output": "438.85760782"
},
{
"input": "12.272903 101.825792\n-51.240438 -12.708472\n-29.729299 77.882032",
"output": "24908.67540438"
},
{
"input": "35.661751 27.283571\n96.513550 51.518022\n97.605986 131.258287",
"output": "13324.78113326"
},
{
"input": "-20.003518 -4.671086\n93.588632 6.362759\n-24.748109 24.792124",
"output": "11191.04493104"
},
{
"input": "93.583067 132.858352\n63.834975 19.353720\n33.677824 102.529376",
"output": "10866.49390021"
},
{
"input": "-7.347450 36.971423\n84.498728 89.423536\n75.469963 98.022482",
"output": "8977.83404724"
},
{
"input": "51.679280 56.072393\n-35.819256 73.390532\n-10.661374 129.756454",
"output": "7441.86549199"
},
{
"input": "97.326813 61.492460\n100.982131 57.717635\n68.385216 22.538372",
"output": "1840.59945324"
},
{
"input": "-16.356805 109.310423\n124.529388 25.066276\n-37.892043 80.604904",
"output": "22719.36404168"
},
{
"input": "103.967164 63.475916\n86.466163 59.341930\n69.260229 73.258917",
"output": "1621.96700296"
},
{
"input": "122.381894 -48.763263\n163.634346 -22.427845\n26.099674 73.681862",
"output": "22182.51901824"
},
{
"input": "119.209229 133.905087\n132.001535 22.179509\n96.096673 0.539763",
"output": "16459.52899209"
},
{
"input": "77.145533 85.041789\n67.452820 52.513188\n80.503843 85.000149",
"output": "1034.70898496"
},
{
"input": "28.718442 36.116251\n36.734593 35.617015\n76.193973 99.136077",
"output": "6271.48941610"
},
{
"input": "0.376916 17.054676\n100.187614 85.602831\n1.425829 132.750915",
"output": "13947.47744984"
},
{
"input": "46.172435 -22.819705\n17.485134 -1.663888\n101.027565 111.619705",
"output": "16483.23337238"
},
{
"input": "55.957968 -72.765994\n39.787413 -75.942282\n24.837014 128.144762",
"output": "32799.66697178"
},
{
"input": "40.562163 -47.610606\n10.073051 -54.490068\n54.625875 -40.685797",
"output": "31224.34817875"
},
{
"input": "20.965151 74.716562\n167.264364 81.864800\n5.931644 48.813212",
"output": "30115.26346791"
},
{
"input": "105.530943 80.920069\n40.206723 125.323331\n40.502256 -85.455877",
"output": "36574.64621711"
},
{
"input": "104.636703 49.583778\n85.940583 95.426299\n69.375168 93.234795",
"output": "2632.68754075"
},
{
"input": "72.873708 -59.083734\n110.911118 -6.206576\n-44.292395 13.106202",
"output": "19244.42781859"
},
{
"input": "49.320630 48.119616\n65.888396 93.514980\n27.342377 97.600590",
"output": "2437.50897386"
},
{
"input": "6.949504 69.606390\n26.139268 72.136945\n24.032442 57.407195",
"output": "372.09309018"
},
{
"input": "-21.925928 -24.623076\n-33.673619 -11.677794\n4.692348 52.266292",
"output": "5669.99444283"
},
{
"input": "109.515505 37.575315\n5.377080 101.729711\n17.501630 103.324931",
"output": "25142.85604936"
},
{
"input": "-56.880888 172.997993\n81.126977 42.144034\n-51.413417 17.057807",
"output": "29051.57171313"
},
{
"input": "80.895061 94.491414\n42.361631 65.191687\n77.556800 76.694829",
"output": "2386.01792476"
},
{
"input": "165.094169 94.574129\n46.867578 147.178855\n174.685774 62.705213",
"output": "32087.47120554"
},
{
"input": "146.604506 -3.502359\n24.935572 44.589981\n106.160918 -51.162271",
"output": "13799.61044048"
},
{
"input": "139.847022 19.153937\n104.096879 75.379874\n49.164271 46.404632",
"output": "7083.26303902"
},
{
"input": "31.312532 151.532355\n182.646053 56.534075\n15.953947 127.065925",
"output": "25712.80766033"
},
{
"input": "42.147045 64.165917\n70.260284 4.962470\n10.532991 76.277713",
"output": "14261.92257159"
},
{
"input": "129.400249 -44.695226\n122.278798 -53.696996\n44.828427 -83.507917",
"output": "26227.47891833"
},
{
"input": "28.420253 0.619862\n10.966628 21.724132\n14.618862 10.754642",
"output": "1760.14006648"
}
] | 1,661,992,446
| 2,147,483,647
|
PyPy 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 218
| 2,252,800
|
def r(a,b,c,d,e,f):
if f==d:
return (c+e-a,b)
if c==e:
return (d+f-a,a)
return (2*(b-(f-d)/(e-c)*a-((f+d)/2+(e-c)/(f-d)*(e+c)/2))/(-(e-c)/(f-d)-(f-d)/(e-c))-a,(f-d)/(e-c)*(2*((b-(f-d)/(e-c)*a)-((f+d)/2+(e-c)/(f-d)*(e+c)/2))/(-(e-c)/(f-d)-(f-d)/(e-c))-a)+b-(f-d)/(e-c)*a)
(a,b)=map(int,input().split())
(c,d)=map(int,input().split())
(e,f)=map(int,input().split())
l=sorted([(a,b),(c,d),(e,f)])
lo=[]
while l!=lo:
lt=[]
lo=sorted(l)
for i in range(len(l)):
for j in range(i):
for k in range(j):
lt.append(r(l[i][0],l[i][1],l[j][0],l[j][1],l[k][0],l[k][1]))
lt.append(r(l[j][0],l[j][1],l[i][0],l[i][1],l[k][0],l[k][1]))
lt.append(r(l[k][0],l[k][1],l[j][0],l[j][1],l[i][0],l[i][1]))
l.extend(lt)
l=sorted(list(set(l)))
print(len(l))
|
Title: Ancient Berland Circus
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.
In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a special pillar, and the rope strung between the pillars marked the arena edges.
Recently the scientists from Berland have discovered the remains of the ancient circus arena. They found only three pillars, the others were destroyed by the time.
You are given the coordinates of these three pillars. Find out what is the smallest area that the arena could have.
Input Specification:
The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point.
Output Specification:
Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100.
Demo Input:
['0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000\n']
Demo Output:
['1.00000000\n']
|
```python
def r(a,b,c,d,e,f):
if f==d:
return (c+e-a,b)
if c==e:
return (d+f-a,a)
return (2*(b-(f-d)/(e-c)*a-((f+d)/2+(e-c)/(f-d)*(e+c)/2))/(-(e-c)/(f-d)-(f-d)/(e-c))-a,(f-d)/(e-c)*(2*((b-(f-d)/(e-c)*a)-((f+d)/2+(e-c)/(f-d)*(e+c)/2))/(-(e-c)/(f-d)-(f-d)/(e-c))-a)+b-(f-d)/(e-c)*a)
(a,b)=map(int,input().split())
(c,d)=map(int,input().split())
(e,f)=map(int,input().split())
l=sorted([(a,b),(c,d),(e,f)])
lo=[]
while l!=lo:
lt=[]
lo=sorted(l)
for i in range(len(l)):
for j in range(i):
for k in range(j):
lt.append(r(l[i][0],l[i][1],l[j][0],l[j][1],l[k][0],l[k][1]))
lt.append(r(l[j][0],l[j][1],l[i][0],l[i][1],l[k][0],l[k][1]))
lt.append(r(l[k][0],l[k][1],l[j][0],l[j][1],l[i][0],l[i][1]))
l.extend(lt)
l=sorted(list(set(l)))
print(len(l))
```
| -1
|
|
869
|
A
|
The Artful Expedient
|
PROGRAMMING
| 1,100
|
[
"brute force",
"implementation"
] | null | null |
Rock... Paper!
After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.
A positive integer *n* is decided first. Both Koyomi and Karen independently choose *n* distinct positive integers, denoted by *x*1,<=*x*2,<=...,<=*x**n* and *y*1,<=*y*2,<=...,<=*y**n* respectively. They reveal their sequences, and repeat until all of 2*n* integers become distinct, which is the only final state to be kept and considered.
Then they count the number of ordered pairs (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) such that the value *x**i* xor *y**j* equals to one of the 2*n* integers. Here xor means the [bitwise exclusive or](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation on two integers, and is denoted by operators ^ and/or xor in most programming languages.
Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game.
|
The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=2<=000) — the length of both sequences.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=2·106) — the integers finally chosen by Koyomi.
The third line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (1<=≤<=*y**i*<=≤<=2·106) — the integers finally chosen by Karen.
Input guarantees that the given 2*n* integers are pairwise distinct, that is, no pair (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) exists such that one of the following holds: *x**i*<==<=*y**j*; *i*<=≠<=*j* and *x**i*<==<=*x**j*; *i*<=≠<=*j* and *y**i*<==<=*y**j*.
|
Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.
|
[
"3\n1 2 3\n4 5 6\n",
"5\n2 4 6 8 10\n9 7 5 3 1\n"
] |
[
"Karen\n",
"Karen\n"
] |
In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number.
In the second example, there are 16 such pairs, and Karen wins again.
| 500
|
[
{
"input": "3\n1 2 3\n4 5 6",
"output": "Karen"
},
{
"input": "5\n2 4 6 8 10\n9 7 5 3 1",
"output": "Karen"
},
{
"input": "1\n1\n2000000",
"output": "Karen"
},
{
"input": "2\n97153 2000000\n1999998 254",
"output": "Karen"
},
{
"input": "15\n31 30 29 28 27 26 25 24 23 22 21 20 19 18 17\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "Karen"
},
{
"input": "30\n79656 68607 871714 1858841 237684 1177337 532141 161161 1111201 527235 323345 1979059 665353 507265 1290761 610606 1238375 743262 106355 1167830 180315 1233029 816465 752968 782570 1499881 1328457 1867240 13948 1302782\n322597 1868510 1958236 1348157 765908 1023636 874300 537124 631783 414906 886318 1931572 1381013 992451 1305644 1525745 716087 83173 303248 1572710 43084 333341 992413 267806 70390 644521 1014900 497068 178940 1920268",
"output": "Karen"
},
{
"input": "30\n1143673 436496 1214486 1315862 148404 724601 1430740 1433008 1654610 1635673 614673 1713408 1270999 1697 1463796 50027 525482 1659078 688200 842647 518551 877506 1017082 1807856 3280 759698 1208220 470180 829800 1960886\n1312613 1965095 967255 1289012 1950383 582960 856825 49684 808824 319418 1968270 190821 344545 211332 1219388 1773751 1876402 132626 541448 1584672 24276 1053225 1823073 1858232 1209173 1035991 1956373 1237148 1973608 848873",
"output": "Karen"
},
{
"input": "1\n2\n3",
"output": "Karen"
},
{
"input": "1\n1048576\n1020000",
"output": "Karen"
},
{
"input": "3\n9 33 69\n71 74 100",
"output": "Karen"
},
{
"input": "3\n1 2 3\n9 5 6",
"output": "Karen"
},
{
"input": "3\n1 7 8\n9 10 20",
"output": "Karen"
},
{
"input": "3\n1 3 2\n4 5 8",
"output": "Karen"
},
{
"input": "3\n2 1 100\n3 4 9",
"output": "Karen"
},
{
"input": "3\n3 1 100\n2 1000 100000",
"output": "Karen"
},
{
"input": "3\n1 2 5\n3 4 6",
"output": "Karen"
},
{
"input": "3\n3 1 8\n2 4 17",
"output": "Karen"
},
{
"input": "3\n1 5 6\n7 8 3",
"output": "Karen"
},
{
"input": "1\n1\n3",
"output": "Karen"
},
{
"input": "3\n1 3 10\n2 4 20",
"output": "Karen"
},
{
"input": "3\n7 8 10\n15 9 11",
"output": "Karen"
},
{
"input": "3\n5 6 8\n3 100 9",
"output": "Karen"
},
{
"input": "3\n1 2 3\n4 5 8",
"output": "Karen"
},
{
"input": "3\n1 2 19\n3 7 30",
"output": "Karen"
},
{
"input": "3\n1 2 3\n6 7 8",
"output": "Karen"
},
{
"input": "3\n1 4 55\n2 3 9",
"output": "Karen"
},
{
"input": "3\n1 100 200\n5 4 500",
"output": "Karen"
},
{
"input": "1\n6\n7",
"output": "Karen"
},
{
"input": "3\n1 3 5\n2 4 13",
"output": "Karen"
},
{
"input": "3\n3 1 100\n2 1000 10000",
"output": "Karen"
},
{
"input": "3\n1 3 9\n2 4 40",
"output": "Karen"
},
{
"input": "2\n1 199999\n1935807 2000000",
"output": "Karen"
},
{
"input": "3\n1 3 8\n2 4 24",
"output": "Karen"
},
{
"input": "2\n4 1\n7 3",
"output": "Karen"
},
{
"input": "3\n1 2 4\n3 7 8",
"output": "Karen"
},
{
"input": "3\n1 6 10000\n2 3 100000",
"output": "Karen"
}
] | 1,595,618,302
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 5
| 1,000
| 7,270,400
|
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
count = 0
for i in range(n):
for j in range(n):
if x[i]^y[j] in x or x[i]^y[j] in y:
count+=1
if count%2==0:
print("Karen")
else:
print("Koyomi")
|
Title: The Artful Expedient
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Rock... Paper!
After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.
A positive integer *n* is decided first. Both Koyomi and Karen independently choose *n* distinct positive integers, denoted by *x*1,<=*x*2,<=...,<=*x**n* and *y*1,<=*y*2,<=...,<=*y**n* respectively. They reveal their sequences, and repeat until all of 2*n* integers become distinct, which is the only final state to be kept and considered.
Then they count the number of ordered pairs (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) such that the value *x**i* xor *y**j* equals to one of the 2*n* integers. Here xor means the [bitwise exclusive or](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation on two integers, and is denoted by operators ^ and/or xor in most programming languages.
Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game.
Input Specification:
The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=2<=000) — the length of both sequences.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=2·106) — the integers finally chosen by Koyomi.
The third line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (1<=≤<=*y**i*<=≤<=2·106) — the integers finally chosen by Karen.
Input guarantees that the given 2*n* integers are pairwise distinct, that is, no pair (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) exists such that one of the following holds: *x**i*<==<=*y**j*; *i*<=≠<=*j* and *x**i*<==<=*x**j*; *i*<=≠<=*j* and *y**i*<==<=*y**j*.
Output Specification:
Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.
Demo Input:
['3\n1 2 3\n4 5 6\n', '5\n2 4 6 8 10\n9 7 5 3 1\n']
Demo Output:
['Karen\n', 'Karen\n']
Note:
In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number.
In the second example, there are 16 such pairs, and Karen wins again.
|
```python
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
count = 0
for i in range(n):
for j in range(n):
if x[i]^y[j] in x or x[i]^y[j] in y:
count+=1
if count%2==0:
print("Karen")
else:
print("Koyomi")
```
| 0
|
|
4
|
A
|
Watermelon
|
PROGRAMMING
| 800
|
[
"brute force",
"math"
] |
A. Watermelon
|
1
|
64
|
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
|
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
|
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
|
[
"8\n"
] |
[
"YES\n"
] |
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
| 0
|
[
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 1,692,771,100
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 60
| 0
|
x=int(input())
if (x/2==0):{
print(" true")}
else:
print( "False")
|
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
x=int(input())
if (x/2==0):{
print(" true")}
else:
print( "False")
```
| 0
|
754
|
A
|
Lesha and array splitting
|
PROGRAMMING
| 1,200
|
[
"constructive algorithms",
"greedy",
"implementation"
] | null | null |
One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array *A*.
Lesha is tired now so he asked you to split the array. Help Lesha!
|
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array *A*.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=103<=≤<=*a**i*<=≤<=103) — the elements of the array *A*.
|
If it is not possible to split the array *A* and satisfy all the constraints, print single line containing "NO" (without quotes).
Otherwise in the first line print "YES" (without quotes). In the next line print single integer *k* — the number of new arrays. In each of the next *k* lines print two integers *l**i* and *r**i* which denote the subarray *A*[*l**i*... *r**i*] of the initial array *A* being the *i*-th new array. Integers *l**i*, *r**i* should satisfy the following conditions:
- *l*1<==<=1 - *r**k*<==<=*n* - *r**i*<=+<=1<==<=*l**i*<=+<=1 for each 1<=≤<=*i*<=<<=*k*.
If there are multiple answers, print any of them.
|
[
"3\n1 2 -3\n",
"8\n9 -12 3 4 -4 -10 7 3\n",
"1\n0\n",
"4\n1 2 3 -5\n"
] |
[
"YES\n2\n1 2\n3 3\n",
"YES\n2\n1 2\n3 8\n",
"NO\n",
"YES\n4\n1 1\n2 2\n3 3\n4 4\n"
] |
none
| 500
|
[
{
"input": "3\n1 2 -3",
"output": "YES\n3\n1 1\n2 2\n3 3"
},
{
"input": "8\n9 -12 3 4 -4 -10 7 3",
"output": "YES\n8\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8"
},
{
"input": "1\n0",
"output": "NO"
},
{
"input": "4\n1 2 3 -5",
"output": "YES\n4\n1 1\n2 2\n3 3\n4 4"
},
{
"input": "6\n0 0 0 0 0 0",
"output": "NO"
},
{
"input": "100\n507 -724 -243 -846 697 -569 -786 472 756 -272 731 -534 -664 202 592 -381 161 -668 -895 296 472 -868 599 396 -617 310 -283 -118 829 -218 807 939 -152 -343 -96 692 -570 110 442 159 -446 -631 -881 784 894 -3 -792 654 -273 -791 638 -599 -763 586 -812 248 -590 455 926 -402 61 228 209 419 -511 310 -283 857 369 472 -82 -435 -717 -421 862 -384 659 -235 406 793 -167 -504 -432 -951 0 165 36 650 -145 -500 988 -513 -495 -476 312 -754 332 819 -797 -715",
"output": "YES\n99\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75..."
},
{
"input": "100\n1 -2 -1 -1 2 2 0 1 -1 1 0 -2 1 -1 0 -2 -1 -1 2 0 -1 2 0 1 -2 -2 -1 1 2 0 -2 -2 -1 1 1 -1 -2 -1 0 -1 2 1 -1 -2 0 2 1 1 -2 1 1 -1 2 -2 2 0 1 -1 1 -2 0 0 0 0 0 0 -2 -2 2 1 2 2 0 -1 1 1 -2 -2 -2 1 0 2 -1 -2 -1 0 0 0 2 1 -2 0 -2 0 2 1 -2 -1 2 1",
"output": "YES\n78\n1 1\n2 2\n3 3\n4 4\n5 5\n6 7\n8 8\n9 9\n10 11\n12 12\n13 13\n14 15\n16 16\n17 17\n18 18\n19 20\n21 21\n22 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 39\n40 40\n41 41\n42 42\n43 43\n44 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 56\n57 57\n58 58\n59 59\n60 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 73\n74 74\n75 75\n76 76\n77 77\n78 78\n79 79\n80 81\n82 82\n83 83\n84 84\n85 88\n89 89\n90 90\n91 92\n93 94\n95 95\n96 96\n..."
},
{
"input": "7\n0 0 0 0 3 -3 0",
"output": "YES\n2\n1 5\n6 7"
},
{
"input": "5\n0 0 -4 0 0",
"output": "YES\n1\n1 5"
},
{
"input": "100\n2 -38 51 -71 -24 19 35 -27 48 18 64 -4 30 -28 74 -17 -19 -25 54 41 3 -46 -43 -42 87 -76 -62 28 1 32 7 -76 15 0 -82 -33 17 40 -41 -7 43 -18 -27 65 -27 -13 46 -38 75 7 62 -23 7 -12 80 36 37 14 6 -40 -11 -35 -77 -24 -59 75 -41 -21 17 -21 -14 67 -36 16 -1 34 -26 30 -62 -4 -63 15 -49 18 57 7 77 23 -26 8 -20 8 -16 9 50 -24 -33 9 -9 -33",
"output": "YES\n99\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75 75\n76..."
},
{
"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 -38 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "YES\n1\n1 100"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "100\n0 0 -17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "YES\n2\n1 34\n35 100"
},
{
"input": "3\n1 -3 3",
"output": "YES\n3\n1 1\n2 2\n3 3"
},
{
"input": "3\n1 0 -1",
"output": "YES\n2\n1 2\n3 3"
},
{
"input": "3\n3 0 0",
"output": "YES\n1\n1 3"
},
{
"input": "3\n0 0 0",
"output": "NO"
},
{
"input": "3\n-3 3 0",
"output": "YES\n2\n1 1\n2 3"
},
{
"input": "4\n3 -2 -1 3",
"output": "YES\n4\n1 1\n2 2\n3 3\n4 4"
},
{
"input": "4\n-1 0 1 0",
"output": "YES\n2\n1 2\n3 4"
},
{
"input": "4\n0 0 0 3",
"output": "YES\n1\n1 4"
},
{
"input": "4\n0 0 0 0",
"output": "NO"
},
{
"input": "4\n3 0 -3 0",
"output": "YES\n2\n1 2\n3 4"
},
{
"input": "5\n-3 2 2 0 -2",
"output": "YES\n4\n1 1\n2 2\n3 4\n5 5"
},
{
"input": "5\n0 -1 2 0 -1",
"output": "YES\n3\n1 2\n3 4\n5 5"
},
{
"input": "5\n0 2 0 0 0",
"output": "YES\n1\n1 5"
},
{
"input": "5\n0 0 0 0 0",
"output": "NO"
},
{
"input": "5\n0 0 0 0 0",
"output": "NO"
},
{
"input": "20\n101 89 -166 -148 -38 -135 -138 193 14 -134 -185 -171 -52 -191 195 39 -148 200 51 -73",
"output": "YES\n20\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20"
},
{
"input": "20\n-118 -5 101 7 9 144 55 -55 -9 -126 -71 -71 189 -64 -187 123 0 -48 -12 138",
"output": "YES\n19\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 17\n18 18\n19 19\n20 20"
},
{
"input": "20\n-161 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "YES\n1\n1 20"
},
{
"input": "20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 -137 0 0 0 0 137",
"output": "YES\n2\n1 19\n20 20"
},
{
"input": "40\n64 -94 -386 -78 35 -233 33 82 -5 -200 368 -259 124 353 390 -305 -247 -133 379 44 133 -146 151 -217 -16 53 -157 186 -203 -8 117 -71 272 -290 -97 133 52 113 -280 -176",
"output": "YES\n40\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40"
},
{
"input": "40\n120 -96 -216 131 231 -80 -166 -102 16 227 -120 105 43 -83 -53 229 24 190 -268 119 230 348 -33 19 0 -187 -349 -25 80 -38 -30 138 -104 337 -98 0 1 -66 -243 -231",
"output": "YES\n38\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 36\n37 37\n38 38\n39 39\n40 40"
},
{
"input": "40\n0 0 0 0 0 0 324 0 0 0 0 0 0 0 0 0 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": "YES\n1\n1 40"
},
{
"input": "40\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",
"output": "NO"
},
{
"input": "40\n0 0 0 0 0 308 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -308 0 0 0 0 0 0 0",
"output": "YES\n2\n1 32\n33 40"
},
{
"input": "60\n-288 -213 -213 -23 496 489 137 -301 -219 -296 -577 269 -153 -52 -505 -138 -377 500 -256 405 588 274 -115 375 -93 117 -360 -160 429 -339 502 310 502 572 -41 -26 152 -203 562 -525 -179 -67 424 62 -329 -127 352 -474 417 -30 518 326 200 -598 471 107 339 107 -9 -244",
"output": "YES\n60\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60"
},
{
"input": "60\n112 141 -146 -389 175 399 -59 327 -41 397 263 -422 157 0 471 -2 -381 -438 99 368 173 9 -171 118 24 111 120 70 11 317 -71 -574 -139 0 -477 -211 -116 -367 16 568 -75 -430 75 -179 -21 156 291 -422 441 -224 -8 -337 -104 381 60 -138 257 91 103 -359",
"output": "YES\n58\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60"
},
{
"input": "60\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 -238 0 0 0 0 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": "YES\n1\n1 60"
},
{
"input": "60\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",
"output": "NO"
},
{
"input": "60\n0 0 0 0 0 0 0 0 0 -98 0 0 0 0 0 0 0 0 98 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "YES\n2\n1 18\n19 60"
},
{
"input": "80\n-295 -774 -700 -366 -304 -173 -672 288 -721 -256 -348 650 223 211 379 -13 -483 162 800 631 -550 -704 -357 -306 490 713 -80 -234 -669 675 -688 471 315 607 -87 -327 -799 514 248 379 271 325 -244 98 -100 -447 574 -154 554 -377 380 -423 -140 -147 -189 -420 405 464 -110 273 -226 -109 -578 641 -426 -548 214 -184 -397 570 -428 -676 652 -155 127 462 338 534 -782 -481",
"output": "YES\n80\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75..."
},
{
"input": "80\n237 66 409 -208 -460 4 -448 29 -420 -192 -21 -76 -147 435 205 -42 -299 -29 244 -480 -4 -38 2 -214 -311 556 692 111 -19 -84 -90 -350 -354 125 -207 -137 93 367 -481 -462 -440 -92 424 -107 221 -100 -631 -72 105 201 226 -90 197 -264 427 113 202 -144 -115 398 331 147 56 -24 292 -267 -31 -11 202 506 334 -103 534 -155 -472 -124 -257 209 12 360",
"output": "YES\n80\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75..."
},
{
"input": "80\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 668 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "YES\n1\n1 80"
},
{
"input": "80\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",
"output": "NO"
},
{
"input": "80\n0 0 0 0 0 0 0 0 0 0 0 0 -137 137 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "YES\n2\n1 13\n14 80"
},
{
"input": "100\n-98 369 544 197 -991 231 399 521 582 -820 -650 -919 -615 -411 -843 -974 231 140 239 -209 721 84 -834 -27 162 460 -157 -40 0 -778 -491 -607 -34 -647 834 -7 -518 -5 -31 -766 -54 -698 -838 497 980 -77 238 549 -135 7 -629 -892 455 181 527 314 465 -321 656 -390 368 384 601 332 561 -1000 -636 -106 412 -216 -58 -365 -155 -445 404 114 260 -392 -20 840 -395 620 -860 -936 1 882 958 536 589 235 300 676 478 434 229 698 157 -95 908 -170",
"output": "YES\n99\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75 75\n76..."
},
{
"input": "100\n-149 -71 -300 288 -677 -580 248 49 -167 264 -215 878 7 252 -239 25 -369 -22 526 -415 -175 173 549 679 161 -411 743 -454 -34 -714 282 -198 -47 -519 -45 71 615 -214 -317 399 86 -97 246 689 -22 -197 -139 237 -501 477 -385 -421 -463 -641 409 -279 538 -382 48 189 652 -696 74 303 6 -183 336 17 -178 -617 -739 280 -202 454 864 218 480 293 -118 -518 -24 -866 -357 410 239 -833 510 316 -168 38 -370 -22 741 470 -60 -507 -209 704 141 -148",
"output": "YES\n100\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n7..."
},
{
"input": "100\n0 0 697 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "YES\n1\n1 100"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"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 -475 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 475 0 0 0 0",
"output": "YES\n2\n1 95\n96 100"
},
{
"input": "4\n0 0 3 -3",
"output": "YES\n2\n1 3\n4 4"
},
{
"input": "4\n1 0 0 0",
"output": "YES\n1\n1 4"
},
{
"input": "4\n3 3 3 3",
"output": "YES\n4\n1 1\n2 2\n3 3\n4 4"
},
{
"input": "2\n0 1",
"output": "YES\n1\n1 2"
},
{
"input": "4\n0 -1 1 0",
"output": "YES\n2\n1 2\n3 4"
},
{
"input": "1\n1",
"output": "YES\n1\n1 1"
},
{
"input": "5\n0 0 1 0 0",
"output": "YES\n1\n1 5"
},
{
"input": "4\n0 0 1 0",
"output": "YES\n1\n1 4"
},
{
"input": "10\n1 2 0 0 3 -3 0 0 -3 0",
"output": "YES\n5\n1 1\n2 4\n5 5\n6 8\n9 10"
},
{
"input": "3\n0 -1 0",
"output": "YES\n1\n1 3"
},
{
"input": "2\n1 0",
"output": "YES\n1\n1 2"
},
{
"input": "5\n3 -3 0 0 0",
"output": "YES\n2\n1 1\n2 5"
},
{
"input": "3\n0 1 0",
"output": "YES\n1\n1 3"
},
{
"input": "4\n0 0 0 1",
"output": "YES\n1\n1 4"
},
{
"input": "4\n1 -1 1 -1",
"output": "YES\n4\n1 1\n2 2\n3 3\n4 4"
},
{
"input": "1\n-1",
"output": "YES\n1\n1 1"
},
{
"input": "2\n1 1",
"output": "YES\n2\n1 1\n2 2"
},
{
"input": "2\n1 -1",
"output": "YES\n2\n1 1\n2 2"
},
{
"input": "2\n0 0",
"output": "NO"
},
{
"input": "2\n0 -1",
"output": "YES\n1\n1 2"
},
{
"input": "2\n-1 1",
"output": "YES\n2\n1 1\n2 2"
},
{
"input": "2\n-1 0",
"output": "YES\n1\n1 2"
},
{
"input": "2\n-1 -1",
"output": "YES\n2\n1 1\n2 2"
},
{
"input": "3\n5 -5 5",
"output": "YES\n3\n1 1\n2 2\n3 3"
},
{
"input": "5\n1 0 -1 0 1",
"output": "YES\n3\n1 2\n3 4\n5 5"
},
{
"input": "6\n0 0 0 3 0 0",
"output": "YES\n1\n1 6"
},
{
"input": "3\n1 -1 1",
"output": "YES\n3\n1 1\n2 2\n3 3"
}
] | 1,641,231,562
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 15
| 0
|
# -*- coding: utf-8 -*-
"""lesha and array.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/190yL8cUEV6-mOyNCORvfq9O2CbPsjNig
"""
n = int(input())
a = list(map(int,input().split()))
b = 1
if sum(a) == 0 :
for i in range (1,n):
s1 , s2 = a[:i] , a[i:]
if sum(s1) != 0 and sum(s2) != 0 :
ans = 1
print("yes")
print(2)
print(1,i)
print(i+1,len(a))
break
if ans == 0 :
print("no")
else :
print("yes")
print(1)
print(1,len(a))
|
Title: Lesha and array splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array *A*.
Lesha is tired now so he asked you to split the array. Help Lesha!
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array *A*.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=103<=≤<=*a**i*<=≤<=103) — the elements of the array *A*.
Output Specification:
If it is not possible to split the array *A* and satisfy all the constraints, print single line containing "NO" (without quotes).
Otherwise in the first line print "YES" (without quotes). In the next line print single integer *k* — the number of new arrays. In each of the next *k* lines print two integers *l**i* and *r**i* which denote the subarray *A*[*l**i*... *r**i*] of the initial array *A* being the *i*-th new array. Integers *l**i*, *r**i* should satisfy the following conditions:
- *l*1<==<=1 - *r**k*<==<=*n* - *r**i*<=+<=1<==<=*l**i*<=+<=1 for each 1<=≤<=*i*<=<<=*k*.
If there are multiple answers, print any of them.
Demo Input:
['3\n1 2 -3\n', '8\n9 -12 3 4 -4 -10 7 3\n', '1\n0\n', '4\n1 2 3 -5\n']
Demo Output:
['YES\n2\n1 2\n3 3\n', 'YES\n2\n1 2\n3 8\n', 'NO\n', 'YES\n4\n1 1\n2 2\n3 3\n4 4\n']
Note:
none
|
```python
# -*- coding: utf-8 -*-
"""lesha and array.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/190yL8cUEV6-mOyNCORvfq9O2CbPsjNig
"""
n = int(input())
a = list(map(int,input().split()))
b = 1
if sum(a) == 0 :
for i in range (1,n):
s1 , s2 = a[:i] , a[i:]
if sum(s1) != 0 and sum(s2) != 0 :
ans = 1
print("yes")
print(2)
print(1,i)
print(i+1,len(a))
break
if ans == 0 :
print("no")
else :
print("yes")
print(1)
print(1,len(a))
```
| 0
|
|
475
|
B
|
Strongly Connected City
|
PROGRAMMING
| 1,400
|
[
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null |
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.
The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.
|
The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length *n*, made of characters '<' and '>', denoting direction of each horizontal street. If the *i*-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.
The third line contains a string of length *m*, made of characters '^' and 'v', denoting direction of each vertical street. If the *i*-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.
|
If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".
|
[
"3 3\n><>\nv^v\n",
"4 6\n<><>\nv^v^v^\n"
] |
[
"NO\n",
"YES\n"
] |
The figure above shows street directions in the second sample test case.
| 1,000
|
[
{
"input": "3 3\n><>\nv^v",
"output": "NO"
},
{
"input": "4 6\n<><>\nv^v^v^",
"output": "YES"
},
{
"input": "2 2\n<>\nv^",
"output": "YES"
},
{
"input": "2 2\n>>\n^v",
"output": "NO"
},
{
"input": "3 3\n>><\n^^v",
"output": "YES"
},
{
"input": "3 4\n>><\n^v^v",
"output": "YES"
},
{
"input": "3 8\n>><\nv^^^^^^^",
"output": "NO"
},
{
"input": "7 2\n<><<<<>\n^^",
"output": "NO"
},
{
"input": "4 5\n><<<\n^^^^v",
"output": "YES"
},
{
"input": "2 20\n><\n^v^^v^^v^^^v^vv^vv^^",
"output": "NO"
},
{
"input": "2 20\n<>\nv^vv^v^^vvv^^^v^vvv^",
"output": "YES"
},
{
"input": "20 2\n<><<><<>><<<>><><<<<\n^^",
"output": "NO"
},
{
"input": "20 2\n><>><>><>><<<><<><><\n^v",
"output": "YES"
},
{
"input": "11 12\n><<<><><<>>\nvv^^^^vvvvv^",
"output": "NO"
},
{
"input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^",
"output": "YES"
},
{
"input": "16 11\n<<<<>><><<<<<><<\nvv^v^vvvv^v",
"output": "NO"
},
{
"input": "14 7\n><<<<>>>>>>><<\nvv^^^vv",
"output": "NO"
},
{
"input": "5 14\n<<><>\nv^vv^^vv^v^^^v",
"output": "NO"
},
{
"input": "8 18\n>>>><>>>\nv^vv^v^^^^^vvv^^vv",
"output": "NO"
},
{
"input": "18 18\n<<><>><<>><>><><<<\n^^v^v^vvvv^v^vv^vv",
"output": "NO"
},
{
"input": "4 18\n<<<>\n^^^^^vv^vv^^vv^v^v",
"output": "NO"
},
{
"input": "19 18\n><><>>><<<<<>>><<<>\n^^v^^v^^v^vv^v^vvv",
"output": "NO"
},
{
"input": "14 20\n<<<><><<>><><<\nvvvvvvv^v^vvvv^^^vv^",
"output": "NO"
},
{
"input": "18 18\n><>>><<<>><><>>>><\nvv^^^^v^v^^^^v^v^^",
"output": "NO"
},
{
"input": "8 18\n<><<<>>>\n^^^^^^v^^^vv^^vvvv",
"output": "NO"
},
{
"input": "11 12\n><><><<><><\n^^v^^^^^^^^v",
"output": "YES"
},
{
"input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^",
"output": "YES"
},
{
"input": "16 11\n>><<><<<<>>><><<\n^^^^vvvv^vv",
"output": "YES"
},
{
"input": "14 7\n<><><<<>>>><>>\nvv^^v^^",
"output": "YES"
},
{
"input": "5 14\n>>>><\n^v^v^^^vv^vv^v",
"output": "YES"
},
{
"input": "8 18\n<<<><>>>\nv^^vvv^^v^v^vvvv^^",
"output": "YES"
},
{
"input": "18 18\n><><<><><>>><>>>><\n^^vvv^v^^^v^vv^^^v",
"output": "YES"
},
{
"input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^",
"output": "YES"
},
{
"input": "19 18\n>>>><><<>>><<<><<<<\n^v^^^^vv^^v^^^^v^v",
"output": "YES"
},
{
"input": "14 20\n<>><<<><<>>>>>\nvv^^v^^^^v^^vv^^vvv^",
"output": "YES"
},
{
"input": "18 18\n><><<><><>>><>>>><\n^^vvv^v^^^v^vv^^^v",
"output": "YES"
},
{
"input": "8 18\n<<<><>>>\nv^^vvv^^v^v^vvvv^^",
"output": "YES"
},
{
"input": "20 19\n<><>>>>><<<<<><<>>>>\nv^vv^^vvvvvv^vvvv^v",
"output": "NO"
},
{
"input": "20 19\n<<<><<<>><<<>><><><>\nv^v^vvv^vvv^^^vvv^^",
"output": "YES"
},
{
"input": "19 20\n<><<<><><><<<<<<<<>\n^v^^^^v^^vvvv^^^^vvv",
"output": "NO"
},
{
"input": "19 20\n>>>>>>>><>>><><<<><\n^v^v^^^vvv^^^v^^vvvv",
"output": "YES"
},
{
"input": "20 20\n<<<>>>><>><<>><<>>>>\n^vvv^^^^vv^^^^^v^^vv",
"output": "NO"
},
{
"input": "20 20\n>>><><<><<<<<<<><<><\nvv^vv^vv^^^^^vv^^^^^",
"output": "NO"
},
{
"input": "20 20\n><<><<<<<<<>>><>>><<\n^^^^^^^^vvvv^vv^vvvv",
"output": "YES"
},
{
"input": "20 20\n<>>>>>>>><>>><>><<<>\nvv^^vv^^^^v^vv^v^^^^",
"output": "YES"
},
{
"input": "20 20\n><>><<>><>>>>>>>><<>\n^^v^vv^^^vvv^v^^^vv^",
"output": "NO"
},
{
"input": "20 20\n<<<<><<>><><<<>><<><\nv^^^^vvv^^^vvvv^v^vv",
"output": "NO"
},
{
"input": "20 20\n><<<><<><>>><><<<<<<\nvv^^vvv^^v^^v^vv^vvv",
"output": "NO"
},
{
"input": "20 20\n<<>>><>>>><<<<>>><<>\nv^vv^^^^^vvv^^v^^v^v",
"output": "NO"
},
{
"input": "20 20\n><<><<><<<<<<>><><>>\nv^^^v^vv^^v^^vvvv^vv",
"output": "NO"
},
{
"input": "20 20\n<<<<<<<<><>><><>><<<\n^vvv^^^v^^^vvv^^^^^v",
"output": "NO"
},
{
"input": "20 20\n>>><<<<<>>><><><<><<\n^^^vvv^^^v^^v^^v^vvv",
"output": "YES"
},
{
"input": "20 20\n<><<<><><>><><><<<<>\n^^^vvvv^vv^v^^^^v^vv",
"output": "NO"
},
{
"input": "20 20\n>>>>>>>>>><>>><>><>>\n^vvv^^^vv^^^^^^vvv^v",
"output": "NO"
},
{
"input": "20 20\n<><>><><<<<<>><<>>><\nv^^^v^v^v^vvvv^^^vv^",
"output": "NO"
},
{
"input": "20 20\n><<<><<<><<<><>>>><<\nvvvv^^^^^vv^v^^vv^v^",
"output": "NO"
},
{
"input": "20 20\n<<><<<<<<>>>>><<<>>>\nvvvvvv^v^vvv^^^^^^^^",
"output": "YES"
},
{
"input": "20 20\n><<><<>>>>><><>><>>>\nv^^^^vvv^^^^^v^v^vv^",
"output": "NO"
},
{
"input": "20 20\n<<>>><>><<>>>><<<><<\n^^vvv^^vvvv^vv^^v^v^",
"output": "NO"
},
{
"input": "20 20\n><<>><>>>><<><>><><<\n^v^^^^^^vvvv^v^v^v^^",
"output": "NO"
},
{
"input": "20 20\n<<><<<<><><<>>><>>>>\n^^vvvvv^v^^^^^^^vvv^",
"output": "NO"
},
{
"input": "20 20\n>><<<<<<><>>>><>>><>\n^^^v^v^vv^^vv^vvv^^^",
"output": "NO"
},
{
"input": "20 20\n>>>>>>>>>>>>>>>>>>>>\nvvvvvvvvvvvvvvvvvvvv",
"output": "NO"
},
{
"input": "2 2\n><\nv^",
"output": "NO"
},
{
"input": "2 2\n<>\n^v",
"output": "NO"
},
{
"input": "3 3\n>><\nvvv",
"output": "NO"
},
{
"input": "2 3\n<>\nv^^",
"output": "YES"
},
{
"input": "4 4\n>>><\nvvv^",
"output": "NO"
},
{
"input": "20 20\n<><><><><><><><><><>\nvvvvvvvvvvvvvvvvvvvv",
"output": "NO"
},
{
"input": "4 4\n<>>>\nv^^^",
"output": "YES"
},
{
"input": "20 20\n<><><><><><><><><><>\nv^v^v^v^v^v^v^v^v^v^",
"output": "YES"
},
{
"input": "2 3\n<>\n^v^",
"output": "NO"
},
{
"input": "4 3\n<><>\n^vv",
"output": "NO"
},
{
"input": "3 3\n<<>\nvv^",
"output": "YES"
},
{
"input": "2 3\n><\nvv^",
"output": "NO"
},
{
"input": "7 6\n>>><>><\n^vv^vv",
"output": "YES"
},
{
"input": "2 2\n<<\nv^",
"output": "NO"
},
{
"input": "3 3\n>><\n^^^",
"output": "NO"
},
{
"input": "3 3\n<><\nv^v",
"output": "NO"
},
{
"input": "20 20\n><><><><><><><><><><\n^v^v^v^v^v^v^v^v^v^v",
"output": "YES"
},
{
"input": "4 4\n<>>>\nvvv^",
"output": "YES"
}
] | 1,649,452,911
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 81
| 46
| 0
|
n,m = input().split(" ")
n = int(n) -1
m = int(m) -1
h = input()
v = input()
mov = h[0]+v[m]+h[n]+v[0]
if mov == ">v<^" or mov == "<^>v":
print("YES")
else:
print("NO")
|
Title: Strongly Connected City
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.
The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.
Input Specification:
The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length *n*, made of characters '<' and '>', denoting direction of each horizontal street. If the *i*-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.
The third line contains a string of length *m*, made of characters '^' and 'v', denoting direction of each vertical street. If the *i*-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.
Output Specification:
If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".
Demo Input:
['3 3\n><>\nv^v\n', '4 6\n<><>\nv^v^v^\n']
Demo Output:
['NO\n', 'YES\n']
Note:
The figure above shows street directions in the second sample test case.
|
```python
n,m = input().split(" ")
n = int(n) -1
m = int(m) -1
h = input()
v = input()
mov = h[0]+v[m]+h[n]+v[0]
if mov == ">v<^" or mov == "<^>v":
print("YES")
else:
print("NO")
```
| 3
|
|
837
|
A
|
Text Volume
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
|
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters.
|
Print one integer number — volume of text.
|
[
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] |
[
"5\n",
"0\n",
"1\n"
] |
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
| 0
|
[
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWdDCgaDvBfATIWPVSXlbcCLHPYahhxMEYUiaxoCebghJqvmRnaNHYTKLeOiaLDnATPZAOgSNfBzaxLymTGjfzvTegbXsAthTxyDTcmBUkqyGlVGZhoazQzVSoKbTFcCRvYsgSCwjGMxBfWEwMHuagTBxkz",
"output": "105"
},
{
"input": "199\no A r v H e J q k J k v w Q F p O R y R Z o a K R L Z E H t X y X N y y p b x B m r R S q i A x V S u i c L y M n N X c C W Z m S j e w C w T r I S X T D F l w o k f t X u n W w p Z r A k I Y E h s g",
"output": "1"
},
{
"input": "200\nhCyIdivIiISmmYIsCLbpKcTyHaOgTUQEwnQACXnrLdHAVFLtvliTEMlzBVzTesQbhXmcqvwPDeojglBMIjOXANfyQxCSjOJyO SIqOTnRzVzseGIDDYNtrwIusScWSuEhPyEmgQIVEzXofRptjeMzzhtUQxJgcUWILUhEaaRmYRBVsjoqgmyPIKwSajdlNPccOOtWrez",
"output": "50"
},
{
"input": "1\ne",
"output": "0"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "200\nABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU VWXYZABCDE KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KZ",
"output": "10"
},
{
"input": "200\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "200"
},
{
"input": "200\nffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"output": "0"
},
{
"input": "24\nHarbour Space UniversitY",
"output": "2"
},
{
"input": "5\naA AA",
"output": "2"
},
{
"input": "10\nas AS ASDA",
"output": "4"
},
{
"input": "10\nas AS ASDZ",
"output": "4"
},
{
"input": "3\na A",
"output": "1"
},
{
"input": "24\nHarbour space UniversitY",
"output": "2"
},
{
"input": "10\nas AS ASAa",
"output": "3"
},
{
"input": "15\naAb ABCDFGRHTJS",
"output": "11"
},
{
"input": "53\nsdfAZEZR AZE dfdf dsdRFGSDF ZZDZSD dfsd ERBGF dsfsdfR",
"output": "6"
},
{
"input": "10\nABC ABc AB",
"output": "3"
},
{
"input": "10\nA c de CDE",
"output": "3"
},
{
"input": "4\nA AB",
"output": "2"
},
{
"input": "18\nHARbour Space UNIV",
"output": "4"
},
{
"input": "13\na b c d e f A",
"output": "1"
},
{
"input": "6\nA B CA",
"output": "2"
},
{
"input": "4\naa A",
"output": "1"
},
{
"input": "3\nA a",
"output": "1"
}
] | 1,596,053,519
| 719
|
PyPy 3
|
OK
|
TESTS
| 29
| 186
| 20,172,800
|
n = int(input())
words = input().split()
ans = 0
for w in words:
cnt = 0
for c in w:
if (c.isupper()):
cnt += 1
ans = max(ans, cnt)
print(ans)
|
Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters.
Output Specification:
Print one integer number — volume of text.
Demo Input:
['7\nNonZERO\n', '24\nthis is zero answer text\n', '24\nHarbour Space University\n']
Demo Output:
['5\n', '0\n', '1\n']
Note:
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
|
```python
n = int(input())
words = input().split()
ans = 0
for w in words:
cnt = 0
for c in w:
if (c.isupper()):
cnt += 1
ans = max(ans, cnt)
print(ans)
```
| 3
|
|
746
|
B
|
Decoding
|
PROGRAMMING
| 900
|
[
"implementation",
"strings"
] | null | null |
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.
You are given an encoding *s* of some word, your task is to decode it.
|
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding.
|
Print the word that Polycarp encoded.
|
[
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] |
[
"volga\n",
"no\n",
"baba\n"
] |
In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.
In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.
In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba.
| 1,000
|
[
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"input": "1\nw",
"output": "w"
},
{
"input": "2\ncb",
"output": "cb"
},
{
"input": "3\nqok",
"output": "oqk"
},
{
"input": "4\naegi",
"output": "gaei"
},
{
"input": "5\noqquy",
"output": "uqoqy"
},
{
"input": "6\nulhpnm",
"output": "nhulpm"
},
{
"input": "7\nijvxljt",
"output": "jxjivlt"
},
{
"input": "8\nwwmiwkeo",
"output": "ewmwwiko"
},
{
"input": "9\ngmwqmpfow",
"output": "opqmgwmfw"
},
{
"input": "10\nhncmexsslh",
"output": "lsechnmxsh"
},
{
"input": "20\nrtcjbjlbtjfmvzdqutuw",
"output": "uudvftlbcrtjjbjmzqtw"
},
{
"input": "21\ngjyiqoebcnpsdegxnsauh",
"output": "usxesnboijgyqecpdgnah"
},
{
"input": "30\nudotcwvcwxajkadxqvxvwgmwmnqrby",
"output": "bqmmwxqdkawvcoudtwcxjaxvvgwnry"
},
{
"input": "31\nipgfrxxcgckksfgexlicjvtnhvrfbmb",
"output": "mfvnvclefkccxfpigrxgksgxijthrbb"
},
{
"input": "50\nwobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy",
"output": "vsolrruoeqehviaqtycivhrbwoevvkhujmhagaholrmsatdjjy"
},
{
"input": "200\nhvayscqiwpcfykibwyudkzuzdkgqqvbnrfeupjefevlvojngmlcjwzijrkzbsaovabkvvwmjgoonyhuiphwmqdoiuueuyqtychbsklflnvghipdgaxhuhiiqlqocpvhldgvnsrtcwxpidrjffwvwcirluyyxzxrglheczeuouklzkvnyubsvgvmdbrylimztotdbmjph",
"output": "pmdoziybmgsunkluuzelrzyurcvfjdpwtsvdhpolihhadignfkbctyeuoqwpuyogmvkaoszriwcmnoleeperbqgdukuwiycwqsahvycipfkbydzzkqvnfujfvvjgljzjkbavbvwjonhihmdiuuqyhsllvhpgxuiqqcvlgnrcxirfwwilyxxghceokzvybvvdrlmttbjh"
},
{
"input": "201\nrpkghhfibtmlkpdiklegblbuyshfirheatjkfoqkfayfbxeeqijwqdwkkrkbdxlhzkhyiifemsghwovorlqedngldskfbhmwrnzmtjuckxoqdszmsdnbuqnlqzswdfhagasmfswanifrjjcuwdsplytvmnfarchgqteedgfpumkssindxndliozojzlpznwedodzwrrus",
"output": "urzoenpzoolndismpgetgcanvypdujriasmaafwzlqbdmsqxcjmnwhfslneloohseiykhxbrkdwiexfakokterfsulglipltihgprkhfbmkdkebbyhihajfqfybeqjqwkkdlzhifmgwvrqdgdkbmrztukodzsnunqsdhgsfwnfjcwsltmfrhqedfuksnxdizjlzwddwrs"
},
{
"input": "500\naopxumqciwxewxvlxzebsztskjvjzwyewjztqrsuvamtvklhqrbodtncqdchjrlpywvmtgnkkwtvpggktewdgvnhydkexwoxkgltaesrtifbwpciqsvrgjtqrdnyqkgqwrryacluaqmgdwxinqieiblolyekcbzahlhxdwqcgieyfgmicvgbbitbzhejkshjunzjteyyfngigjwyqqndtjrdykzrnrpinkwtrlchhxvycrhstpecadszilicrqdeyyidohqvzfnsqfyuemigacysxvtrgxyjcvejkjstsnatfqlkeytxgsksgpcooypsmqgcluzwofaupegxppbupvtumjerohdteuenwcmqaoazohkilgpkjavcrjcslhzkyjcgfzxxzjfufichxcodcawonkxhbqgfimmlycswdzwbnmjwhbwihfoftpcqplncavmbxuwnsabiyvpcrhfgtqyaguoaigknushbqjwqmmyvsxwabrub",
"output": "ubwsymwqhukiogytfrpybswxmanpctohwhjnwdsymigbxnwcoxcffzxfcyzlcrvjplkoaamweedoemtpbpgpaozlgmpocgkgtelfasskecygtxyaieyqnzqoiydriisaethcvhcrwnpnzyrtnqwggfytzuhkeztbgcmfegqdhhzcelliinxdmalarwgqnrtgvqcwftsalkoxkyngwtgptkntvyljcqndbqlvmvsqzwyzvktsexvwxiqupaoxmcwexlzbzsjjwejtruatkhrotcdhrpwmgkwvgkedvhdewxgteribpisrjqdykqrycuqgwiqeboykbalxwciygivbibhjsjnjeynijyqdjdkrriktlhxyrspcdzlcqeydhvfsfumgcsvrxjvjjtntqkyxsspoysqcuwfuexpuvujrhtuncqozhigkacjshkjgzxjuihcdaokhqfmlcwzbmwbiffpqlcvbunaivchgqauagnsbjqmvxarb"
},
{
"input": "501\noilesjbgowlnayckhpoaitijewsyhgavnthycaecwnvzpxgjqfjyxnjcjknvvsmjbjwtcoyfbegmnnheeamvtfjkigqoanhvgdfrjchdqgowrstlmrjmcsuuwvvoeucfyhnxivosrxblfoqwikfxjnnyejdiihpenfcahtjwcnzwvxxseicvdfgqhtvefswznuyohmmljlnxubhevywpmnitnkhecsgccpstxkmdzabsnwxkokdfsogzbpnfvgudvqlstxojzfzugxbfrozveaiofrzksegdelxsdhcjlqwqlgjcqiujptoenxozhkqhcpkarretqzfkwuvbmfdcdoqliyzmlfrfhzrnkbhofuctkpeacqejwvdrlyvepudrlzncbhwrgmxrczphsoymvtuzqjscvbtqpymogupgzctepccravjcrfsadueyraqvwasravkubebojqspdntewnjohvccamvoxdauyakvehjhabpdyzyme",
"output": "mzdbhhvaudomcvonenpqoeuvravayuafcvrcecguoyqbcjztmohzrmrhczrueyrvjqaptuobnzffmylocfbukztraphkzxetjicgqqjhsldekroavofxufjxsqdgfpzofkkwsadktpcsektnpyebxllmouzsetqfvisxwnwtafehijynxkwolxsvxhfuovusmrlswgdcrdvnogkfvaenmefotjjsvkcnyfjxzncaytvgywjtapkynwgjeiolsbolachoiieshanhcewvpgqjxjjnvmbwcybgnhemtjiqahgfjhqortmjcuwvecyniorbfqifjnedipnchjczvxecdghvfwnyhmjnuhvwminhcgcsxmzbnxodsgbnvuvltozzgbrzeifzsgexdclwljquponohqckreqfwvmddqizlrhrkhfckecewdlvpdlnbwgxcpsyvuqsvtpmgpztpcajrsderqwsakbbjsdtwjhcavxaykejapyye"
}
] | 1,688,440,611
| 2,147,483,647
|
PyPy 3-64
|
MEMORY_LIMIT_EXCEEDED
|
TESTS
| 0
| 46
| 268,390,400
|
# Competitive programming boilerplate (CP standing for competitive programming, not _that_)
# https://github.com/rajatg98/Competitive-Coding-Python-Template/blob/master/template.py
import sys
import math # Math lib
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd, Counter as cnt # Default dict
from bisect import bisect_left as bl, bisect_right as br, bisect as bi
from heapq import nlargest as nl, nsmallest as ns
sys.setrecursionlimit(100000000)
inp =lambda: int(input())
strng =lambda: input().strip()
jn =lambda x,l: x.join(map(str,l))
strl =lambda: list(input().strip())
mul =lambda: map(int,input().strip().split())
mulf =lambda: map(float,input().strip().split())
seq =lambda: list(map(int,input().strip().split()))
ceil =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1
flush =lambda: stdout.flush()
stdstr =lambda: stdin.readline()
stdint =lambda: int(stdin.readline())
stdpr =lambda x: stdout.write(str(x))
mod=1000000007
# Template ends here
def slv(n: int, s: str):
s2 = ''
while n > 0:
s2 += s[(n // 2 - 1) if n % 2 == 0 else n // 2]
s = s.replace(s[(n // 2 - 1) if n % 2 == 0 else n // 2], "", 1)
n -= 1
return s2
def main():
n = inp()
s = input()
print(slv(n, s))
if __name__ == "__main__":
main()
|
Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.
You are given an encoding *s* of some word, your task is to decode it.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding.
Output Specification:
Print the word that Polycarp encoded.
Demo Input:
['5\nlogva\n', '2\nno\n', '4\nabba\n']
Demo Output:
['volga\n', 'no\n', 'baba\n']
Note:
In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.
In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.
In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba.
|
```python
# Competitive programming boilerplate (CP standing for competitive programming, not _that_)
# https://github.com/rajatg98/Competitive-Coding-Python-Template/blob/master/template.py
import sys
import math # Math lib
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd, Counter as cnt # Default dict
from bisect import bisect_left as bl, bisect_right as br, bisect as bi
from heapq import nlargest as nl, nsmallest as ns
sys.setrecursionlimit(100000000)
inp =lambda: int(input())
strng =lambda: input().strip()
jn =lambda x,l: x.join(map(str,l))
strl =lambda: list(input().strip())
mul =lambda: map(int,input().strip().split())
mulf =lambda: map(float,input().strip().split())
seq =lambda: list(map(int,input().strip().split()))
ceil =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1
flush =lambda: stdout.flush()
stdstr =lambda: stdin.readline()
stdint =lambda: int(stdin.readline())
stdpr =lambda x: stdout.write(str(x))
mod=1000000007
# Template ends here
def slv(n: int, s: str):
s2 = ''
while n > 0:
s2 += s[(n // 2 - 1) if n % 2 == 0 else n // 2]
s = s.replace(s[(n // 2 - 1) if n % 2 == 0 else n // 2], "", 1)
n -= 1
return s2
def main():
n = inp()
s = input()
print(slv(n, s))
if __name__ == "__main__":
main()
```
| 0
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen points doesn't matter.
|
The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input strictly increase.
|
Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
|
[
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] |
[
"4\n",
"2\n",
"1\n"
] |
In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}.
| 0
|
[
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"output": "25"
},
{
"input": "10 90\n24 27 40 41 61 69 73 87 95 97",
"output": "120"
},
{
"input": "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -67 -65 -64 -63 -62 -61 -54 -51 -50 -49 -48 -46 -45 -44 -37 -36 -33 -30 -28 -27 -16 -15 -13 -12 -10 -9 -7 -6 -5 -4 2 3 5 8 9 10 11 13 14 15 16 17 19 22 24 25 26 27 28 30 31 32 36 40 43 45 46 47 50 51 52 53 58 60 63 69 70 73 78 80 81 82 85 88 89 90 91 95 96 97 99",
"output": "79351"
},
{
"input": "1 14751211\n847188590",
"output": "0"
},
{
"input": "2 1000000000\n-907894512 -289906312",
"output": "0"
},
{
"input": "2 1000000000\n-14348867 1760823",
"output": "0"
},
{
"input": "3 1000000000\n-5 -1 1",
"output": "1"
}
] | 1,682,609,302
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 39
| 342
| 8,089,600
|
n,d=map(int,input().split())
a=list(map(int,input().split()))
s,x=0,0
for i in range(n):
while a[i]>d+a[x] and x<n:
x+=1
m=i-x-1
s+=(m+1)*m//2
print(s)
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen points doesn't matter.
Input Specification:
The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input strictly increase.
Output Specification:
Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['4 3\n1 2 3 4\n', '4 2\n-3 -2 -1 0\n', '5 19\n1 10 20 30 50\n']
Demo Output:
['4\n', '2\n', '1\n']
Note:
In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}.
|
```python
n,d=map(int,input().split())
a=list(map(int,input().split()))
s,x=0,0
for i in range(n):
while a[i]>d+a[x] and x<n:
x+=1
m=i-x-1
s+=(m+1)*m//2
print(s)
```
| 3
|
|
508
|
A
|
Pasha and Pixels
|
PROGRAMMING
| 1,100
|
[
"brute force"
] | null | null |
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed.
Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed.
|
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move.
|
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
|
[
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] |
[
"4\n",
"5\n",
"0\n"
] |
none
| 500
|
[
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
"output": "9"
},
{
"input": "2 2 5\n1 1\n2 1\n2 1\n1 2\n2 2",
"output": "5"
},
{
"input": "518 518 10\n37 97\n47 278\n17 467\n158 66\n483 351\n83 123\n285 219\n513 187\n380 75\n304 352",
"output": "0"
},
{
"input": "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "0"
},
{
"input": "1 5 5\n1 1\n1 2\n1 3\n1 4\n1 5",
"output": "0"
},
{
"input": "5 1 5\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "0"
},
{
"input": "1 1 1\n1 1",
"output": "0"
},
{
"input": "10 10 4\n5 9\n6 9\n6 10\n5 10",
"output": "4"
},
{
"input": "1000 1000 4\n999 999\n999 1000\n1000 999\n1000 1000",
"output": "4"
},
{
"input": "2 3 5\n2 3\n1 3\n1 2\n1 1\n2 2",
"output": "5"
},
{
"input": "1000 1000 4\n1000 1000\n999 999\n1000 999\n999 1000",
"output": "4"
}
] | 1,697,897,659
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 4
| 2,000
| 102,400
|
#false表示白,true表示黑
def check(matrix,line,row):
'''检验是否存在2x2黑格子'''
new_matrix = [[False] * (row + 2)]+[[False] + lines + [False] for lines in matrix]+ [[False] * (row + 2)]
flag=False
for x in range(line+2):
for y in range(row+2):
if new_matrix[x][y]:
if new_matrix[x+1][y] and new_matrix[x][y+1] and new_matrix[x+1][y+1]:
flag=True
if flag:
break
if flag:
break
return flag
n,m,k=map(int,input().split())
matrice=[[False]*m for _ in range(n)]
note=True
for move in range(1,k+1):
i,j=map(int,input().split())
matrice[i-1][j-1]=True
if check(matrice,n,m):
print(move)
note=False
break
if note:
print(0)
|
Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed.
Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed.
Input Specification:
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move.
Output Specification:
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
Demo Input:
['2 2 4\n1 1\n1 2\n2 1\n2 2\n', '2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n', '5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n']
Demo Output:
['4\n', '5\n', '0\n']
Note:
none
|
```python
#false表示白,true表示黑
def check(matrix,line,row):
'''检验是否存在2x2黑格子'''
new_matrix = [[False] * (row + 2)]+[[False] + lines + [False] for lines in matrix]+ [[False] * (row + 2)]
flag=False
for x in range(line+2):
for y in range(row+2):
if new_matrix[x][y]:
if new_matrix[x+1][y] and new_matrix[x][y+1] and new_matrix[x+1][y+1]:
flag=True
if flag:
break
if flag:
break
return flag
n,m,k=map(int,input().split())
matrice=[[False]*m for _ in range(n)]
note=True
for move in range(1,k+1):
i,j=map(int,input().split())
matrice[i-1][j-1]=True
if check(matrice,n,m):
print(move)
note=False
break
if note:
print(0)
```
| 0
|
|
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,525,090,834
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 8
| 1,000
| 13,209,600
|
n, a, b = list(map(int, input().split(' ')))
s = list(map(int, input().split(' ')))
s[1:] = sorted(s[1:])
count = 0
while True:
if s[0]*a/sum(s) >= b:
break
del s[-1]
count += 1
print(count)
|
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
n, a, b = list(map(int, input().split(' ')))
s = list(map(int, input().split(' ')))
s[1:] = sorted(s[1:])
count = 0
while True:
if s[0]*a/sum(s) >= b:
break
del s[-1]
count += 1
print(count)
```
| 0
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
|
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
|
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
|
[
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] |
[
"3\n",
"2\n"
] |
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
| 0
|
[
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000 1000",
"output": "100"
},
{
"input": "8\n200000 1 200000 1 200000 1 200000 2",
"output": "1"
},
{
"input": "5\n20000 1 2 3 4",
"output": "20000"
},
{
"input": "2\n200000 1",
"output": "200000"
},
{
"input": "3\n2 100 2",
"output": "100"
},
{
"input": "2\n10 1",
"output": "10"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n5 5 5",
"output": "5"
},
{
"input": "2\n5 1",
"output": "5"
}
] | 1,510,510,462
| 7,762
|
Python 3
|
WRONG_ANSWER
|
PRETESTS
| 0
| 30
| 0
|
n = int(input())
s = input()
s = s.split()
a = []
def mn(ar):
m=0
k=0
res = 0
while(m==0):
if k>=len(ar):
break
m = ar[k]
k+=1
for i in range(k, len(ar)):
if ar[i]!=0 and ar[i]<=m:
m = ar[i]
res=i
return res+1
for i in s:
a.append(int(i))
f=[0]*n
for i in range(1, n):
f[a[i]-1]=i+1
print(a)
print(f)
print(mn(f))
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input Specification:
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output Specification:
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Demo Input:
['5\n1 3 2 1 2\n', '6\n2 1 2 2 4 1\n']
Demo Output:
['3\n', '2\n']
Note:
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
|
```python
n = int(input())
s = input()
s = s.split()
a = []
def mn(ar):
m=0
k=0
res = 0
while(m==0):
if k>=len(ar):
break
m = ar[k]
k+=1
for i in range(k, len(ar)):
if ar[i]!=0 and ar[i]<=m:
m = ar[i]
res=i
return res+1
for i in s:
a.append(int(i))
f=[0]*n
for i in range(1, n):
f[a[i]-1]=i+1
print(a)
print(f)
print(mn(f))
```
| 0
|
|
500
|
A
|
New Year Transportation
|
PROGRAMMING
| 1,000
|
[
"dfs and similar",
"graphs",
"implementation"
] | null | null |
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
|
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
|
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
|
[
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] |
[
"YES\n",
"NO\n"
] |
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
| 500
|
[
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1",
"output": "YES"
},
{
"input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1",
"output": "NO"
},
{
"input": "10 3\n8 3 5 4 2 3 2 2 1",
"output": "NO"
},
{
"input": "10 9\n8 3 5 4 2 3 2 2 1",
"output": "YES"
},
{
"input": "3 2\n1 1",
"output": "YES"
},
{
"input": "3 2\n2 1",
"output": "NO"
},
{
"input": "4 2\n2 1 1",
"output": "NO"
},
{
"input": "4 4\n2 2 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 1 1",
"output": "YES"
},
{
"input": "3 3\n2 1",
"output": "YES"
},
{
"input": "4 4\n1 1 1",
"output": "YES"
},
{
"input": "8 8\n1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5 5\n1 1 1 1",
"output": "YES"
}
] | 1,681,406,584
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 31
| 1,433,600
|
# x, y = input("Enter a two value: ").split()
# print("Number of boys: ", x)
# print("Number of girls: ", y)
# print()
# n,t=input().split()
# print(n+t)
# L=[1,5,3]
# a=L[0]
# for i in L:
# if i>a:
# a=i
# print(a)
# def histogram(L,size):
# hist=[0 for i in range(size+1)]
# for element in L:
# hist[element]+=1
# return hist
# L=[1,9,9,7,7,7,6,5]
# size=10
# print(histogram(L,size))
# L=[2,2,8,15,23,23,23,26,29,30,32,32]
# emp=[]
# for i in L:
# if i not in emp:
# emp.append(i)
# print(len(emp))
N,T=input().split()
n=int(N)
t=int(T)
list1=list(map(int,input().split()))
list2=[]
i=0
while (i<n-1):
p=i+list1[i]+1
i=p
list2.append(p)
if t in list2:
print("YES")
else:
print('NO')
# def NewYear(n,t,a):
# j = 1
# while not (a[j-1] + j == t):
# j = j + a[j-1]
# if j >= n:
# break
# if j >= n:
# print("NO")
# else:
# print("YES")
#
# N,T = input().split()
# n = int(N)
# t = int(T)
# a = list(map(int,input().split()))
# NewYear(n,t,a)
|
Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
Input Specification:
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
Output Specification:
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
Demo Input:
['8 4\n1 2 1 2 1 2 1\n', '8 5\n1 2 1 2 1 1 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
|
```python
# x, y = input("Enter a two value: ").split()
# print("Number of boys: ", x)
# print("Number of girls: ", y)
# print()
# n,t=input().split()
# print(n+t)
# L=[1,5,3]
# a=L[0]
# for i in L:
# if i>a:
# a=i
# print(a)
# def histogram(L,size):
# hist=[0 for i in range(size+1)]
# for element in L:
# hist[element]+=1
# return hist
# L=[1,9,9,7,7,7,6,5]
# size=10
# print(histogram(L,size))
# L=[2,2,8,15,23,23,23,26,29,30,32,32]
# emp=[]
# for i in L:
# if i not in emp:
# emp.append(i)
# print(len(emp))
N,T=input().split()
n=int(N)
t=int(T)
list1=list(map(int,input().split()))
list2=[]
i=0
while (i<n-1):
p=i+list1[i]+1
i=p
list2.append(p)
if t in list2:
print("YES")
else:
print('NO')
# def NewYear(n,t,a):
# j = 1
# while not (a[j-1] + j == t):
# j = j + a[j-1]
# if j >= n:
# break
# if j >= n:
# print("NO")
# else:
# print("YES")
#
# N,T = input().split()
# n = int(N)
# t = int(T)
# a = list(map(int,input().split()))
# NewYear(n,t,a)
```
| 0
|
|
103
|
A
|
Testing Pants for Sadness
|
PROGRAMMING
| 1,100
|
[
"greedy",
"implementation",
"math"
] |
A. Testing Pants for Sadness
|
2
|
256
|
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
|
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*.
|
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
|
[
"2\n1 1\n",
"2\n2 2\n",
"1\n10\n"
] |
[
"2",
"5",
"10"
] |
Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished.
| 500
|
[
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n2 2",
"output": "5"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n2 4 1",
"output": "10"
},
{
"input": "4\n5 5 3 1",
"output": "22"
},
{
"input": "2\n1000000000 1000000000",
"output": "2999999999"
},
{
"input": "10\n5 7 8 1 10 3 6 4 10 6",
"output": "294"
},
{
"input": "100\n5 7 5 3 5 4 6 5 3 6 4 6 6 2 1 9 6 5 3 8 4 10 1 9 1 3 7 6 5 5 8 8 7 7 8 9 2 10 3 5 4 2 6 10 2 6 9 6 1 9 3 7 7 8 3 9 9 5 10 10 3 10 7 8 3 9 8 3 2 4 10 2 1 1 7 3 9 10 4 6 9 8 2 1 4 10 1 10 6 8 7 5 3 3 6 2 7 10 3 8",
"output": "24212"
},
{
"input": "100\n96 23 25 62 34 30 85 15 26 61 59 87 34 99 60 41 52 73 63 84 50 89 42 29 87 99 19 94 84 43 82 90 41 100 60 61 99 49 26 3 97 5 24 34 51 59 69 61 11 41 72 60 33 36 18 29 82 53 18 80 52 98 38 32 56 95 55 79 32 80 37 64 45 13 62 80 70 29 1 58 88 24 79 68 41 80 12 72 52 39 64 19 54 56 70 58 19 3 83 62",
"output": "261115"
},
{
"input": "100\n883 82 79 535 478 824 700 593 262 385 403 183 176 386 126 648 710 516 922 97 800 728 372 9 954 911 975 526 476 3 74 459 471 174 295 831 698 21 927 698 580 856 712 430 5 473 592 40 301 230 763 266 38 213 393 70 333 779 811 249 130 456 763 657 578 699 939 660 898 918 438 855 892 85 35 232 54 593 849 777 917 979 796 322 473 887 284 105 522 415 86 480 80 592 516 227 680 574 488 644",
"output": "2519223"
},
{
"input": "100\n6659 5574 5804 7566 7431 1431 3871 6703 200 300 3523 3580 8500 2312 4812 3149 3324 5846 8965 5758 5831 1341 7733 4477 355 3024 2941 9938 1494 16 1038 8262 9938 9230 5192 8113 7575 7696 5566 2884 8659 1951 1253 6480 3877 3707 5482 3825 5359 44 3219 3258 1785 5478 4525 5950 2417 1991 8885 4264 8769 2961 7107 8904 5097 2319 5713 8811 9723 8677 2153 3237 7174 9528 9260 7390 3050 6823 6239 5222 4602 933 7823 4198 8304 244 5845 3189 4490 3216 7877 6323 1938 4597 880 1206 1691 1405 4122 5950",
"output": "24496504"
},
{
"input": "50\n515844718 503470143 928669067 209884122 322869098 241621928 844696197 105586164 552680307 968792756 135928721 842094825 298782438 829020472 791637138 285482545 811025527 428952878 887796419 11883658 546401594 6272027 100292274 308219869 372132044 955814846 644008184 521195760 919389466 215065725 687764134 655750167 181397022 404292682 643251185 776299412 741398345 865144798 369796727 673902099 124966684 35796775 794385099 594562033 550366869 868093561 695094388 580789105 755076935 198783899",
"output": "685659563557"
},
{
"input": "10\n12528238 329065023 620046219 303914458 356423530 751571368 72944261 883971060 123105651 868129460",
"output": "27409624352"
},
{
"input": "1\n84355694",
"output": "84355694"
},
{
"input": "2\n885992042 510468669",
"output": "1906929379"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "100\n2 1 2 2 2 2 1 2 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 1 2 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 2 2 1 1 1 2 2 1 1 2 1 1 2 2 2 2 1 2 2 2 1 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 1 1 1 2 1 2 2 2 1 1 1",
"output": "2686"
},
{
"input": "100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1",
"output": "4667"
}
] | 1,586,886,570
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 216
| 0
|
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(n):
s += a[i]
if a[i] != 1:
s += i
print(s)
|
Title: Testing Pants for Sadness
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*.
Output Specification:
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Demo Input:
['2\n1 1\n', '2\n2 2\n', '1\n10\n']
Demo Output:
['2', '5', '10']
Note:
Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished.
|
```python
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(n):
s += a[i]
if a[i] != 1:
s += i
print(s)
```
| 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,667,310,016
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 62
| 0
|
alphabet="abcdefghijklmnopqrstuvwxyz"
w= input()
if sum([c in alphabet for c in w]) < (len(w)+1) / 2:
print(w.upper())
else:
print(w.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
alphabet="abcdefghijklmnopqrstuvwxyz"
w= input()
if sum([c in alphabet for c in w]) < (len(w)+1) / 2:
print(w.upper())
else:
print(w.lower())
```
| 0
|
855
|
A
|
Tom Riddle's Diary
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation",
"strings"
] | null | null |
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes).
|
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
|
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
|
[
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] |
[
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] |
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES".
| 500
|
[
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nhrtm\nssjqvixduertmotgagizamvfucfwtxqnhuowbqbzctgznivehelpcyigwrbbdsxnewfqvcf\nhyrtxvozpbveexfkgalmguozzakitjiwsduqxonb\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nbdbivqzvhggth",
"output": "NO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "10\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nmvutw\nqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuzepuezqqzxlfmdanoeaoqmor\nmvutw\nvchawxjoreboqzuklifv\nvchawxjoreboqzuklifv\nnivijte\nrflybruq\nvchawxjoreboqzuklifv",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nYES"
},
{
"input": "1\nz",
"output": "NO"
},
{
"input": "9\nl\ny\nm\nj\nn\nr\nj\nk\nf",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO"
},
{
"input": "14\nw\na\nh\np\nk\nw\ny\nv\ns\nf\nx\nd\nk\nr",
"output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "25\np\nk\nu\nl\nf\nt\nc\ns\nq\nd\nb\nq\no\ni\ni\nd\ni\nw\nn\ng\nw\nt\na\ne\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES"
},
{
"input": "20\nd\nh\ng\no\np\ne\nt\nj\nv\ni\nt\nh\ns\ni\nw\nf\nx\na\nl\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES"
},
{
"input": "3\nbbbbbbb\nbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO\nNO\nNO"
},
{
"input": "2\nab\nba",
"output": "NO\nNO"
},
{
"input": "6\ntom\nlucius\nginnys\nharpy\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "2\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde",
"output": "NO\nYES"
},
{
"input": "42\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na",
"output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 1,651,938,871
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 55
| 77
| 0
|
n = int(input())
m = set()
for i in range(n):
s = input()
print("YES" if s in m else "NO")
m.add(s)
|
Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes).
Input Specification:
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output Specification:
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Demo Input:
['6\ntom\nlucius\nginny\nharry\nginny\nharry\n', '3\na\na\na\n']
Demo Output:
['NO\nNO\nNO\nNO\nYES\nYES\n', 'NO\nYES\nYES\n']
Note:
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES".
|
```python
n = int(input())
m = set()
for i in range(n):
s = input()
print("YES" if s in m else "NO")
m.add(s)
```
| 3
|
|
381
|
A
|
Sereja and Dima
|
PROGRAMMING
| 800
|
[
"greedy",
"implementation",
"two pointers"
] | null | null |
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
|
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
|
[
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] |
[
"12 5\n",
"16 12\n"
] |
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
| 500
|
[
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24",
"output": "644 500"
},
{
"input": "1\n3",
"output": "3 0"
},
{
"input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646",
"output": "6848 6568"
},
{
"input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727",
"output": "9562 9561"
},
{
"input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12",
"output": "315 315"
},
{
"input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304",
"output": "3238 2222"
},
{
"input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325",
"output": "5246 4864"
},
{
"input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71",
"output": "8147 7807"
},
{
"input": "1\n1",
"output": "1 0"
}
] | 1,692,904,999
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 34
| 46
| 0
|
n = int(input())
l = [int(x) for x in input().split()]
s, d = [], []
while l:
s.append(l.pop(l.index(max(l[0], l[-1]))))
d.append(l.pop(l.index(max(l[0], l[-1]))) if l else 0)
print(sum(s), sum(d))
|
Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
Output Specification:
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
Demo Input:
['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n']
Demo Output:
['12 5\n', '16 12\n']
Note:
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
|
```python
n = int(input())
l = [int(x) for x in input().split()]
s, d = [], []
while l:
s.append(l.pop(l.index(max(l[0], l[-1]))))
d.append(l.pop(l.index(max(l[0], l[-1]))) if l else 0)
print(sum(s), sum(d))
```
| 3
|
|
813
|
C
|
The Tag Game
|
PROGRAMMING
| 1,700
|
[
"dfs and similar",
"graphs"
] | null | null |
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of *n* vertices. Vertex 1 is the root of the tree.
Alice starts at vertex 1 and Bob starts at vertex *x* (*x*<=≠<=1). The moves are made in turns, Bob goes first. In one move one can either stay at the current vertex or travel to the neighbouring one.
The game ends when Alice goes to the same vertex where Bob is standing. Alice wants to minimize the total number of moves and Bob wants to maximize it.
You should write a program which will determine how many moves will the game last.
|
The first line contains two integer numbers *n* and *x* (2<=≤<=*n*<=≤<=2·105, 2<=≤<=*x*<=≤<=*n*).
Each of the next *n*<=-<=1 lines contains two integer numbers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*) — edges of the tree. It is guaranteed that the edges form a valid tree.
|
Print the total number of moves Alice and Bob will make.
|
[
"4 3\n1 2\n2 3\n2 4\n",
"5 2\n1 2\n2 3\n3 4\n2 5\n"
] |
[
"4\n",
"6\n"
] |
In the first example the tree looks like this:
The red vertex is Alice's starting position, the blue one is Bob's. Bob will make the game run the longest by standing at the vertex 3 during all the game. So here are the moves:
B: stay at vertex 3
A: go to vertex 2
B: stay at vertex 3
A: go to vertex 3
In the second example the tree looks like this:
The moves in the optimal strategy are:
B: go to vertex 3
A: go to vertex 2
B: go to vertex 4
A: go to vertex 3
B: stay at vertex 4
A: go to vertex 4
| 0
|
[
{
"input": "4 3\n1 2\n2 3\n2 4",
"output": "4"
},
{
"input": "5 2\n1 2\n2 3\n3 4\n2 5",
"output": "6"
},
{
"input": "2 2\n2 1",
"output": "2"
},
{
"input": "3 3\n2 1\n3 1",
"output": "2"
},
{
"input": "3 3\n1 2\n3 2",
"output": "4"
},
{
"input": "10 4\n5 4\n8 3\n4 6\n5 3\n7 9\n1 3\n5 10\n2 9\n9 8",
"output": "8"
},
{
"input": "10 7\n8 7\n2 8\n2 3\n10 6\n4 6\n4 1\n10 5\n7 5\n9 8",
"output": "16"
},
{
"input": "8 3\n2 1\n3 1\n4 3\n5 1\n6 1\n7 1\n8 6",
"output": "4"
},
{
"input": "34 33\n2 1\n3 2\n4 3\n5 2\n6 3\n7 2\n8 5\n9 7\n10 8\n11 7\n12 7\n13 8\n14 2\n15 10\n16 1\n17 9\n18 14\n19 1\n20 2\n21 8\n22 21\n23 9\n24 6\n25 2\n26 20\n27 5\n28 20\n29 2\n30 10\n31 14\n32 12\n33 15\n34 8",
"output": "12"
}
] | 1,552,652,399
| 5,099
|
PyPy 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 13
| 1,000
| 19,456,000
|
import sys
sys.setrecursionlimit(10 ** 6)
n, x = map(int, input().split())
x -= 1
G = [[] for i in range(n)]
for i in range(n - 1):
a, b = map(int, input().split())
G[a - 1].append(b - 1)
G[b - 1].append(a - 1)
INF = float('inf')
dista = [0] * n
distb = [-1] * n
def dfsa(u, par, d):
dista[u] = d
for w in G[u]:
if w == par:
continue
dfsa(w, u, d + 1)
def dfsb(u, par, d):
distb[u] = d
for w in G[u]:
if w == par:
continue
if d + 1 >= dista[w]:
distb[w] = d + 1
continue
dfsb(w, u, d + 1)
dfsa(0, -1, 0)
dfsb(x, -1, 0)
num = 0
for i in range(n):
if distb[i] != -1:
num = max(num, dista[i] * 2)
print(num)
|
Title: The Tag Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of *n* vertices. Vertex 1 is the root of the tree.
Alice starts at vertex 1 and Bob starts at vertex *x* (*x*<=≠<=1). The moves are made in turns, Bob goes first. In one move one can either stay at the current vertex or travel to the neighbouring one.
The game ends when Alice goes to the same vertex where Bob is standing. Alice wants to minimize the total number of moves and Bob wants to maximize it.
You should write a program which will determine how many moves will the game last.
Input Specification:
The first line contains two integer numbers *n* and *x* (2<=≤<=*n*<=≤<=2·105, 2<=≤<=*x*<=≤<=*n*).
Each of the next *n*<=-<=1 lines contains two integer numbers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*) — edges of the tree. It is guaranteed that the edges form a valid tree.
Output Specification:
Print the total number of moves Alice and Bob will make.
Demo Input:
['4 3\n1 2\n2 3\n2 4\n', '5 2\n1 2\n2 3\n3 4\n2 5\n']
Demo Output:
['4\n', '6\n']
Note:
In the first example the tree looks like this:
The red vertex is Alice's starting position, the blue one is Bob's. Bob will make the game run the longest by standing at the vertex 3 during all the game. So here are the moves:
B: stay at vertex 3
A: go to vertex 2
B: stay at vertex 3
A: go to vertex 3
In the second example the tree looks like this:
The moves in the optimal strategy are:
B: go to vertex 3
A: go to vertex 2
B: go to vertex 4
A: go to vertex 3
B: stay at vertex 4
A: go to vertex 4
|
```python
import sys
sys.setrecursionlimit(10 ** 6)
n, x = map(int, input().split())
x -= 1
G = [[] for i in range(n)]
for i in range(n - 1):
a, b = map(int, input().split())
G[a - 1].append(b - 1)
G[b - 1].append(a - 1)
INF = float('inf')
dista = [0] * n
distb = [-1] * n
def dfsa(u, par, d):
dista[u] = d
for w in G[u]:
if w == par:
continue
dfsa(w, u, d + 1)
def dfsb(u, par, d):
distb[u] = d
for w in G[u]:
if w == par:
continue
if d + 1 >= dista[w]:
distb[w] = d + 1
continue
dfsb(w, u, d + 1)
dfsa(0, -1, 0)
dfsb(x, -1, 0)
num = 0
for i in range(n):
if distb[i] != -1:
num = max(num, dista[i] * 2)
print(num)
```
| 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,690,979,413
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 28
| 46
| 0
|
n, m = [int(i) for i in input().split()]
paint = []
counter = 0
for i in range(n):
if i%2 == 0:
paint.append('#'*m)
elif counter%2 == 0:
paint.append('.'*(m-1) + '#')
counter += 1
else:
paint.append('#' + '.'*(m-1))
counter += 1
print('\n'.join(paint))
|
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
n, m = [int(i) for i in input().split()]
paint = []
counter = 0
for i in range(n):
if i%2 == 0:
paint.append('#'*m)
elif counter%2 == 0:
paint.append('.'*(m-1) + '#')
counter += 1
else:
paint.append('#' + '.'*(m-1))
counter += 1
print('\n'.join(paint))
```
| 3
|
|
27
|
A
|
Next Test
|
PROGRAMMING
| 1,200
|
[
"implementation",
"sortings"
] |
A. Next Test
|
2
|
256
|
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
|
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
|
Output the required default value for the next test index.
|
[
"3\n1 7 2\n"
] |
[
"3\n"
] |
none
| 500
|
[
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
{
"input": "7\n3 2 1 6 5 7 4",
"output": "8"
},
{
"input": "8\n2 8 3 7 6 9 1 5",
"output": "4"
},
{
"input": "9\n10 5 9 3 8 7 1 2 4",
"output": "6"
},
{
"input": "10\n7 2 3 8 9 6 5 4 1 10",
"output": "11"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 4 1",
"output": "3"
},
{
"input": "4\n4 2 3 1",
"output": "5"
},
{
"input": "5\n3 1 4 2 5",
"output": "6"
},
{
"input": "6\n1 3 6 7 2 4",
"output": "5"
},
{
"input": "7\n1 5 4 7 2 3 6",
"output": "8"
},
{
"input": "8\n12 1 6 5 2 8 3 4",
"output": "7"
},
{
"input": "9\n3 2 7 5 6 4 1 9 10",
"output": "8"
},
{
"input": "10\n1 7 13 6 5 10 3 8 2 4",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n3000",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
},
{
"input": "2\n3000 1",
"output": "2"
}
] | 1,627,054,199
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 30
| 1,090
| 6,963,200
|
import sys
def getNextIndex(n, ind):
for j in range(n):
mn = j
for k in range(j+1, n):
mn = mn if ind[k] > ind[mn] else k
ind[mn], ind[j] = ind[j], ind[mn]
if ind[j] != (j + 1):
return j + 1
return n+1
if __name__ == '__main__':
n, *ind = map(int, sys.stdin.read().split())
print(getNextIndex(n, ind))
|
Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output Specification:
Output the required default value for the next test index.
Demo Input:
['3\n1 7 2\n']
Demo Output:
['3\n']
Note:
none
|
```python
import sys
def getNextIndex(n, ind):
for j in range(n):
mn = j
for k in range(j+1, n):
mn = mn if ind[k] > ind[mn] else k
ind[mn], ind[j] = ind[j], ind[mn]
if ind[j] != (j + 1):
return j + 1
return n+1
if __name__ == '__main__':
n, *ind = map(int, sys.stdin.read().split())
print(getNextIndex(n, ind))
```
| 3.71453
|
509
|
B
|
Painting Pebbles
|
PROGRAMMING
| 1,300
|
[
"constructive algorithms",
"greedy",
"implementation"
] | null | null |
There are *n* piles of pebbles on the table, the *i*-th pile contains *a**i* pebbles. Your task is to paint each pebble using one of the *k* given colors so that for each color *c* and any two piles *i* and *j* the difference between the number of pebbles of color *c* in pile *i* and number of pebbles of color *c* in pile *j* is at most one.
In other words, let's say that *b**i*,<=*c* is the number of pebbles of color *c* in the *i*-th pile. Then for any 1<=≤<=*c*<=≤<=*k*, 1<=≤<=*i*,<=*j*<=≤<=*n* the following condition must be satisfied |*b**i*,<=*c*<=-<=*b**j*,<=*c*|<=≤<=1. It isn't necessary to use all *k* colors: if color *c* hasn't been used in pile *i*, then *b**i*,<=*c* is considered to be zero.
|
The first line of the input contains positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100), separated by a space — the number of piles and the number of colors respectively.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) denoting number of pebbles in each of the piles.
|
If there is no way to paint the pebbles satisfying the given condition, output "NO" (without quotes) .
Otherwise in the first line output "YES" (without quotes). Then *n* lines should follow, the *i*-th of them should contain *a**i* space-separated integers. *j*-th (1<=≤<=*j*<=≤<=*a**i*) of these integers should be equal to the color of the *j*-th pebble in the *i*-th pile. If there are several possible answers, you may output any of them.
|
[
"4 4\n1 2 3 4\n",
"5 2\n3 2 4 1 3\n",
"5 4\n3 2 4 3 5\n"
] |
[
"YES\n1\n1 4\n1 2 4\n1 2 3 4\n",
"NO\n",
"YES\n1 2 3\n1 3\n1 2 3 4\n1 3 4\n1 1 2 3 4\n"
] |
none
| 0
|
[
{
"input": "4 4\n1 2 3 4",
"output": "YES\n1 \n1 1 \n1 1 2 \n1 1 2 3 "
},
{
"input": "5 2\n3 2 4 1 3",
"output": "NO"
},
{
"input": "5 4\n3 2 4 3 5",
"output": "YES\n1 1 1 \n1 1 \n1 1 1 2 \n1 1 1 \n1 1 1 2 3 "
},
{
"input": "4 3\n5 6 7 8",
"output": "YES\n1 1 1 1 1 \n1 1 1 1 1 1 \n1 1 1 1 1 1 2 \n1 1 1 1 1 1 2 3 "
},
{
"input": "5 6\n3 7 2 1 2",
"output": "YES\n1 1 2 \n1 1 2 3 4 5 6 \n1 1 \n1 \n1 1 "
},
{
"input": "9 5\n5 8 7 3 10 1 4 6 3",
"output": "NO"
},
{
"input": "2 1\n7 2",
"output": "NO"
},
{
"input": "87 99\n90 28 93 18 80 94 68 58 72 45 93 72 11 54 54 48 74 63 73 7 4 54 42 67 8 13 89 32 2 26 13 94 28 46 77 95 94 63 60 7 16 55 90 91 97 80 7 97 8 12 1 32 43 20 79 38 48 22 97 11 92 97 100 41 72 2 93 68 26 2 79 36 19 96 31 47 52 21 12 86 90 83 57 1 4 81 87",
"output": "YES\n1 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 \n1 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 \n1 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 5..."
},
{
"input": "5 92\n95 10 4 28 56",
"output": "YES\n1 1 1 1 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 \n1 1 1 1 1 2 3 4 5 6 \n1 1 1 1 \n1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 \n1 1 1 1 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..."
},
{
"input": "96 99\n54 72 100 93 68 36 73 98 79 31 51 88 53 65 69 84 19 65 52 19 62 12 80 45 100 45 78 93 70 56 57 97 21 70 55 15 95 100 51 44 93 1 67 29 4 39 57 82 81 66 66 89 42 18 48 70 81 67 17 62 70 76 79 82 70 26 66 22 16 8 49 23 16 30 46 71 36 20 96 18 53 5 45 5 96 66 95 20 87 3 45 4 47 22 24 7",
"output": "YES\n1 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 \n1 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 \n1 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 5..."
},
{
"input": "56 97\n96 81 39 97 2 75 85 17 9 90 2 31 32 10 42 87 71 100 39 81 2 38 90 81 96 7 57 23 2 25 5 62 22 61 47 94 63 83 91 51 8 93 33 65 38 50 5 64 76 57 96 19 13 100 56 39",
"output": "NO"
},
{
"input": "86 98\n27 94 18 86 16 11 74 59 62 64 37 84 100 4 48 6 37 11 50 73 11 30 87 14 89 55 35 8 99 63 54 16 99 20 40 91 75 18 28 36 31 76 98 40 90 41 83 32 81 61 81 43 5 36 33 35 63 15 86 38 63 27 21 2 68 67 12 55 36 79 93 93 29 5 22 52 100 17 81 50 6 42 59 57 83 20",
"output": "YES\n1 1 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 \n1 1 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 \n1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \n1 1 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 4..."
},
{
"input": "21 85\n83 25 85 96 23 80 54 14 71 57 44 88 30 92 90 61 17 80 59 85 12",
"output": "YES\n1 1 1 1 1 1 1 1 1 1 1 1 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 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 \n1 1 1 1 1 1 1 1 1 1 1 1 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 6..."
},
{
"input": "87 71\n44 88 67 57 57 80 69 69 40 32 92 54 64 51 69 54 31 53 29 42 32 85 100 90 46 56 40 46 68 81 60 42 99 89 61 96 48 42 78 95 71 67 30 42 57 82 41 76 29 79 32 62 100 89 81 55 88 90 86 54 54 31 28 67 69 49 45 54 68 77 64 32 60 60 66 66 83 57 56 89 57 82 73 86 60 61 62",
"output": "NO"
},
{
"input": "63 87\n12 63 17 38 52 19 27 26 24 40 43 12 84 99 59 37 37 12 36 88 22 56 55 57 33 64 45 71 85 73 84 38 51 36 14 15 98 68 50 33 92 97 44 79 40 60 43 15 52 58 38 95 74 64 77 79 85 41 59 55 43 29 27",
"output": "YES\n1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 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 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 \n1 1 1 1 1 1 1 1 1 1 1 1 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 \n1 1 1 1 1 1 1 1 1 1 1 1 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 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 \n1 ..."
},
{
"input": "39 39\n87 88 86 86 96 70 79 64 85 80 81 74 64 65 90 64 83 78 96 63 78 80 62 62 76 89 69 73 100 100 99 69 69 89 97 64 94 94 71",
"output": "YES\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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 \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 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 \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..."
},
{
"input": "100 67\n82 34 100 55 38 32 97 34 100 49 49 41 48 100 74 51 53 50 46 38 35 69 93 61 96 86 43 59 90 45 52 100 48 45 63 60 52 66 83 46 66 47 74 37 56 48 42 88 39 68 38 66 77 40 60 60 92 38 45 57 63 91 85 85 89 53 64 66 99 89 49 54 48 58 94 65 78 34 78 62 95 47 64 50 84 52 98 79 57 69 39 61 92 46 63 45 90 51 79 39",
"output": "NO"
},
{
"input": "100 35\n99 90 67 85 68 67 76 75 77 78 81 85 98 88 70 77 89 87 68 91 83 74 70 65 74 86 82 79 81 93 80 66 93 72 100 99 96 66 89 71 93 80 74 97 73 80 93 81 70 68 80 72 75 70 78 67 73 79 76 75 77 78 85 96 72 84 100 68 77 71 79 91 75 100 67 94 73 79 88 73 92 71 68 66 81 68 81 73 69 75 76 84 70 82 66 83 89 90 79 91",
"output": "YES\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 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 \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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 \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..."
},
{
"input": "100 15\n92 87 87 99 91 87 94 94 97 90 98 90 91 95 99 97 95 100 93 95 92 100 87 87 94 89 90 99 89 99 95 90 89 88 92 97 88 86 86 95 96 92 89 89 86 92 89 89 100 100 95 86 86 97 97 98 89 88 97 89 93 100 99 99 93 92 87 97 91 90 96 86 99 86 87 95 99 100 88 86 86 93 100 88 88 89 94 88 88 95 89 86 99 98 91 97 87 88 100 94",
"output": "YES\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 2 3 4 5 6 \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 \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 ..."
},
{
"input": "17 1\n79 79 79 79 79 79 79 79 79 79 79 79 79 79 79 79 79",
"output": "YES\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 \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 \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 \n1 1 1 1 1 1 1 1 1 1 1 1 1 ..."
},
{
"input": "27 2\n53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53",
"output": "YES\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 \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 \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 \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 \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 ..."
},
{
"input": "48 3\n85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85",
"output": "YES\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 \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 \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 ..."
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "1 100\n1",
"output": "YES\n1 "
}
] | 1,630,176,020
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 4
| 93
| 20,172,800
|
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
v = [x for x in range(1, k + 1)]
for i in range(1, n):
if a[i] > 2 * a[i - 1]:
print("NO")
exit(0)
print("YES")
for i in a:
for j in range(i):
print(v[j % k], end=" ")
print()
|
Title: Painting Pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* piles of pebbles on the table, the *i*-th pile contains *a**i* pebbles. Your task is to paint each pebble using one of the *k* given colors so that for each color *c* and any two piles *i* and *j* the difference between the number of pebbles of color *c* in pile *i* and number of pebbles of color *c* in pile *j* is at most one.
In other words, let's say that *b**i*,<=*c* is the number of pebbles of color *c* in the *i*-th pile. Then for any 1<=≤<=*c*<=≤<=*k*, 1<=≤<=*i*,<=*j*<=≤<=*n* the following condition must be satisfied |*b**i*,<=*c*<=-<=*b**j*,<=*c*|<=≤<=1. It isn't necessary to use all *k* colors: if color *c* hasn't been used in pile *i*, then *b**i*,<=*c* is considered to be zero.
Input Specification:
The first line of the input contains positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100), separated by a space — the number of piles and the number of colors respectively.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) denoting number of pebbles in each of the piles.
Output Specification:
If there is no way to paint the pebbles satisfying the given condition, output "NO" (without quotes) .
Otherwise in the first line output "YES" (without quotes). Then *n* lines should follow, the *i*-th of them should contain *a**i* space-separated integers. *j*-th (1<=≤<=*j*<=≤<=*a**i*) of these integers should be equal to the color of the *j*-th pebble in the *i*-th pile. If there are several possible answers, you may output any of them.
Demo Input:
['4 4\n1 2 3 4\n', '5 2\n3 2 4 1 3\n', '5 4\n3 2 4 3 5\n']
Demo Output:
['YES\n1\n1 4\n1 2 4\n1 2 3 4\n', 'NO\n', 'YES\n1 2 3\n1 3\n1 2 3 4\n1 3 4\n1 1 2 3 4\n']
Note:
none
|
```python
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
v = [x for x in range(1, k + 1)]
for i in range(1, n):
if a[i] > 2 * a[i - 1]:
print("NO")
exit(0)
print("YES")
for i in a:
for j in range(i):
print(v[j % k], end=" ")
print()
```
| 0
|
|
443
|
A
|
Anton and Letters
|
PROGRAMMING
| 800
|
[
"constructive algorithms",
"implementation"
] | null | null |
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
|
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
|
Print a single number — the number of distinct letters in Anton's set.
|
[
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] |
[
"3\n",
"2\n",
"0\n"
] |
none
| 500
|
[
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}",
"output": "1"
},
{
"input": "{a, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 1,694,080,529
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 27
| 46
| 0
|
n = input()
n1=n[1:-1].split(", ")
s = set()
for i in n1:
if i!='':
s.add(i)
length = len(s)
print(length)
|
Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
Input Specification:
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Output Specification:
Print a single number — the number of distinct letters in Anton's set.
Demo Input:
['{a, b, c}\n', '{b, a, b, a}\n', '{}\n']
Demo Output:
['3\n', '2\n', '0\n']
Note:
none
|
```python
n = input()
n1=n[1:-1].split(", ")
s = set()
for i in n1:
if i!='':
s.add(i)
length = len(s)
print(length)
```
| 3
|
|
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,603,474,740
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 45
| 124
| 0
|
n=int(input())
s=input().split()
s=sorted(s)
print(s[int(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())
s=input().split()
s=sorted(s)
print(s[int(n/2)])
```
| 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,525,891,967
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 4
| 1,000
| 35,225,600
|
n=int(input())
print(sum([len(str(i)) for i in range(1,n+1)]))
|
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
n=int(input())
print(sum([len(str(i)) for i in range(1,n+1)]))
```
| 0
|
|
784
|
G
|
BF Calculator
|
PROGRAMMING
| 2,000
|
[
"*special"
] | null | null |
In this problem you will write a simple generator of Brainfuck ([https://en.wikipedia.org/wiki/Brainfuck](https://en.wikipedia.org/wiki/Brainfuck)) calculators.
You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression.
We use a fairly standard Brainfuck interpreter for checking the programs:
- 30000 memory cells.- memory cells store integers from 0 to 255 with unsigned 8-bit wraparound.- console input (, command) is not supported, but it's not needed for this problem.
|
The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries).
|
Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps.
|
[
"2+3\n",
"9-7\n"
] |
[
"++>\n+++>\n<[<+>-]<\n++++++++++++++++++++++++++++++++++++++++++++++++.\n",
"+++++++++>\n+++++++>\n<[<->-]<\n++++++++++++++++++++++++++++++++++++++++++++++++.\n"
] |
You can download the source code of the Brainfuck interpreter by the link [http://assets.codeforces.com/rounds/784/bf.cpp](//assets.codeforces.com/rounds/784/bf.cpp). We use this code to interpret outputs.
| 0
|
[
{
"input": "2+3",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "9-7",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "1+1+1",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "1+11+111",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "111-11-1",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "1+1-1+1-1+1-1+1-1+1",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "9+1",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "10-1",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "31+49+49+71-51-61+59-111+51",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "255+255+255+255+255-255-255-255-255-255",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "100+100+10+10+10+10+10+5",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "255-255+255-255+255-255+255-255+255",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "0-255-255-255-255+255+255+255+255+255",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "34+45+29-49+52-111-4+4+2+9",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "0+0+0+0+0+0+0+0+0+0",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "193+235+47+150+222-3-90-248-187-100",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "66-165-34+209+76",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "36+90+6+102",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "255-12-34-56-69-78",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "243-173+90-56+78-53+53-21",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>"
}
] | 1,491,302,435
| 1,475
|
Python 3
|
OK
|
TESTS
| 20
| 77
| 5,632,000
|
a = str(eval(input()))
for c in a:
print('+' * ord(c) + ".>")
print()
|
Title: BF Calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you will write a simple generator of Brainfuck ([https://en.wikipedia.org/wiki/Brainfuck](https://en.wikipedia.org/wiki/Brainfuck)) calculators.
You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression.
We use a fairly standard Brainfuck interpreter for checking the programs:
- 30000 memory cells.- memory cells store integers from 0 to 255 with unsigned 8-bit wraparound.- console input (, command) is not supported, but it's not needed for this problem.
Input Specification:
The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries).
Output Specification:
Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps.
Demo Input:
['2+3\n', '9-7\n']
Demo Output:
['++>\n+++>\n<[<+>-]<\n++++++++++++++++++++++++++++++++++++++++++++++++.\n', '+++++++++>\n+++++++>\n<[<->-]<\n++++++++++++++++++++++++++++++++++++++++++++++++.\n']
Note:
You can download the source code of the Brainfuck interpreter by the link [http://assets.codeforces.com/rounds/784/bf.cpp](//assets.codeforces.com/rounds/784/bf.cpp). We use this code to interpret outputs.
|
```python
a = str(eval(input()))
for c in a:
print('+' * ord(c) + ".>")
print()
```
| 3
|
|
656
|
G
|
You're a Professional
|
PROGRAMMING
| 1,900
|
[
"*special"
] | null | null |
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user.
Output the number of items in the list liked by at least *T* of user's friends.
|
The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*).
The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise.
|
Output an integer — the number of items liked by at least *T* of user's friends.
|
[
"3 3 2\nYYY\nNNN\nYNY\n",
"4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n"
] |
[
"2\n",
"4\n"
] |
none
| 0
|
[
{
"input": "3 3 2\nYYY\nNNN\nYNY",
"output": "2"
},
{
"input": "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN",
"output": "4"
},
{
"input": "3 5 2\nNYNNY\nYNNNN\nNNYYN",
"output": "0"
},
{
"input": "1 10 1\nYYYNYNNYNN",
"output": "5"
},
{
"input": "10 1 5\nY\nN\nN\nN\nY\nN\nN\nY\nN\nN",
"output": "0"
},
{
"input": "10 10 1\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN",
"output": "0"
},
{
"input": "10 10 10\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY",
"output": "10"
},
{
"input": "8 9 1\nNYNNYYYYN\nNNNYNYNNY\nYYNYNYNNN\nNYYYNYNNN\nYNYNYNYYN\nYYNNYYYYY\nYYYYNYNYY\nNYYNNYYYY",
"output": "9"
},
{
"input": "5 2 3\nNN\nNY\nYY\nNN\nNY",
"output": "1"
},
{
"input": "6 4 5\nYNNY\nNYYY\nNNNY\nYNYN\nYYYN\nYNNY",
"output": "0"
},
{
"input": "6 1 3\nY\nY\nY\nY\nY\nN",
"output": "1"
},
{
"input": "6 2 2\nYN\nNN\nYN\nNN\nYN\nNN",
"output": "1"
},
{
"input": "2 4 2\nNYNY\nNYNY",
"output": "2"
},
{
"input": "9 6 3\nNYYYYN\nNNNYYN\nYYYYYY\nNYNNNN\nYNNYNY\nNNNNNY\nYNNYNN\nYYYYNY\nNNYYYY",
"output": "6"
},
{
"input": "6 9 6\nYYYYNYNNN\nYNNYNNNYN\nNYYYNNNYY\nNYYYNNNNY\nYYNYNNNYY\nYYYNYYNNN",
"output": "0"
},
{
"input": "9 7 8\nYNNNNYN\nNNNYYNN\nNNYYYNY\nNYYNYYY\nNNYYNYN\nNYYYNNY\nYYNYNYY\nNYYYYYY\nNNYYNYN",
"output": "0"
},
{
"input": "9 1 6\nN\nN\nY\nN\nY\nY\nY\nY\nY",
"output": "1"
},
{
"input": "7 7 2\nNNYNNYN\nNNNYYNY\nNNNYYNY\nYNNNNNY\nNNYNYYY\nYYNNYYN\nNNYYYNY",
"output": "6"
},
{
"input": "8 4 2\nYNYY\nYNYY\nYNNN\nNNNN\nNYNN\nYNNN\nNNYN\nNYNN",
"output": "4"
},
{
"input": "9 10 7\nNNYNNYYYYY\nYNYYNYYNYN\nNYNYYNNNNY\nYYYYYYYYYN\nYYNYNYYNNN\nYYYNNYYYYY\nNYYYYYNNNN\nNYNNYYYYNN\nYYYYYNNYYY",
"output": "2"
},
{
"input": "6 4 2\nNNNN\nNYYY\nNYNN\nNYNN\nYNNY\nNNNN",
"output": "2"
},
{
"input": "3 1 1\nN\nY\nN",
"output": "1"
},
{
"input": "7 1 3\nY\nY\nY\nN\nY\nY\nY",
"output": "1"
},
{
"input": "9 8 7\nNYYNNNYY\nYYYNYNNN\nYNYNYNNY\nNYYYNNNY\nNYYYYNYN\nNNNNYYNN\nYNYYYYYY\nNNYNYNYY\nNYYNNYYY",
"output": "1"
},
{
"input": "9 5 9\nYYYYN\nYYYNN\nNNYNN\nNNYYY\nYNNNN\nNYNNN\nYYYYN\nYNYYN\nNNNYN",
"output": "0"
},
{
"input": "8 4 1\nYYYN\nNNNN\nNYNY\nYNNY\nYNYY\nYNYN\nYNNY\nNNYN",
"output": "4"
},
{
"input": "7 9 5\nYNNYYYYNN\nYNYYYNNYY\nYNYYYYYNN\nYYNYYNYYN\nNNYYNNNYY\nYYNYNYYNN\nYYNNYYNYN",
"output": "3"
},
{
"input": "5 8 3\nNYYYNNNN\nYNNNNNYY\nYNYYYNYY\nNNNNNYNN\nYYYYYYYY",
"output": "5"
},
{
"input": "5 10 4\nYYYYNNNNYN\nYYYNYYYNNY\nNNNYNYNYNY\nYNYNNNNNNY\nNNYNYNYNYY",
"output": "2"
},
{
"input": "6 9 6\nNYYNNYNYN\nYNYNYNNNN\nNNYNNYYYY\nNNYNNNYNY\nNYYYNNYNY\nNNYYNNNYN",
"output": "1"
},
{
"input": "4 4 1\nYNYY\nNNNY\nYNNN\nNNYN",
"output": "3"
},
{
"input": "1 3 1\nYYN",
"output": "2"
},
{
"input": "10 4 5\nNNYN\nYYNY\nYYNY\nNYYN\nYNYY\nYNYY\nYYNN\nYNYN\nYYYY\nYYNY",
"output": "4"
}
] | 1,459,888,185
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 0
| 0
|
n, m, t = map(int, input().split())
#print(n, m, t)
ans = 0
f = [0] * n
for i in range(n) :
f[i] = input()
#print(f)
for j in range(m) :
likes = 0;
for i in range(n) :
if (f[i][j] == 'Y') :
likes += 1;
if (likes >= t) :
ans += 1;
print(ans)
|
Title: You're a Professional
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user.
Output the number of items in the list liked by at least *T* of user's friends.
Input Specification:
The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*).
The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise.
Output Specification:
Output an integer — the number of items liked by at least *T* of user's friends.
Demo Input:
['3 3 2\nYYY\nNNN\nYNY\n', '4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n']
Demo Output:
['2\n', '4\n']
Note:
none
|
```python
n, m, t = map(int, input().split())
#print(n, m, t)
ans = 0
f = [0] * n
for i in range(n) :
f[i] = input()
#print(f)
for j in range(m) :
likes = 0;
for i in range(n) :
if (f[i][j] == 'Y') :
likes += 1;
if (likes >= t) :
ans += 1;
print(ans)
```
| 0
|
|
245
|
A
|
System Administrator
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost.
Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.
Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
|
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost.
It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
|
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format.
|
[
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] |
[
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] |
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.
Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
| 0
|
[
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1",
"output": "LIVE\nDEAD"
},
{
"input": "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3",
"output": "DEAD\nLIVE"
},
{
"input": "13\n1 8 2\n1 4 6\n1 5 5\n1 5 5\n2 10 0\n2 9 1\n1 3 7\n2 6 4\n2 6 4\n2 5 5\n1 7 3\n2 3 7\n2 9 1",
"output": "LIVE\nLIVE"
},
{
"input": "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3",
"output": "DEAD\nDEAD"
}
] | 1,545,311,349
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 13
| 218
| 0
|
num=eval(input())
alist=[]
for i in range(num):
a=input()
b=a.split()
c=[int(x) for x in b]
alist.append(c)
geshua=0
geshub=0
zongshua=0
zongshub=0
for k in alist:
if k[0]==1:
geshua=geshua+1
zongshua=zongshua+k[1]
else:
geshub=geshub+1
zongshub=zongshub+k[1]
if zongshua>=geshua*5:
print("LIVE")
else:
print('DEAD')
if zongshub>=geshub*5:
print("LIVE")
else:
print('DEAD')
|
Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost.
Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.
Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost.
It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
Output Specification:
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format.
Demo Input:
['2\n1 5 5\n2 6 4\n', '3\n1 0 10\n2 0 10\n1 10 0\n']
Demo Output:
['LIVE\nLIVE\n', 'LIVE\nDEAD\n']
Note:
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.
Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
|
```python
num=eval(input())
alist=[]
for i in range(num):
a=input()
b=a.split()
c=[int(x) for x in b]
alist.append(c)
geshua=0
geshub=0
zongshua=0
zongshub=0
for k in alist:
if k[0]==1:
geshua=geshua+1
zongshua=zongshua+k[1]
else:
geshub=geshub+1
zongshub=zongshub+k[1]
if zongshua>=geshua*5:
print("LIVE")
else:
print('DEAD')
if zongshub>=geshub*5:
print("LIVE")
else:
print('DEAD')
```
| 3
|
|
69
|
A
|
Young Physicist
|
PROGRAMMING
| 1,000
|
[
"implementation",
"math"
] |
A. Young Physicist
|
2
|
256
|
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
|
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
|
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
|
[
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] |
[
"NO",
"YES"
] |
none
| 500
|
[
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,660,372,465
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 81
| 92
| 0
|
print('NO' if any(map(sum, zip(*[tuple(map(int, input().split())) for i in range(int(input()))]))) else 'YES')
|
Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none
|
```python
print('NO' if any(map(sum, zip(*[tuple(map(int, input().split())) for i in range(int(input()))]))) else 'YES')
```
| 3.977
|
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,670,942,369
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 31
| 0
|
word = input()
if len(word) > 10:
word = word[0] + str(len(word) - 2) + word[len(word) - 1]
print(word)
|
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
word = input()
if len(word) > 10:
word = word[0] + str(len(word) - 2) + word[len(word) - 1]
print(word)
```
| 0
|
622
|
A
|
Infinite Sequence
|
PROGRAMMING
| 1,000
|
[
"implementation",
"math"
] | null | null |
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the *n*-th position of the sequence.
|
The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
|
Print the element in the *n*-th position of the sequence (the elements are numerated from one).
|
[
"3\n",
"5\n",
"10\n",
"55\n",
"56\n"
] |
[
"2\n",
"2\n",
"4\n",
"10\n",
"1\n"
] |
none
| 0
|
[
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "55",
"output": "10"
},
{
"input": "56",
"output": "1"
},
{
"input": "1000000000000",
"output": "88209"
},
{
"input": "847194127849",
"output": "255708"
},
{
"input": "294719472984",
"output": "593358"
},
{
"input": "999999911791",
"output": "1414213"
},
{
"input": "999999911792",
"output": "1"
},
{
"input": "100000000000000",
"output": "1749820"
},
{
"input": "1",
"output": "1"
},
{
"input": "99993",
"output": "312"
},
{
"input": "99994",
"output": "313"
},
{
"input": "99995",
"output": "314"
},
{
"input": "99990",
"output": "309"
},
{
"input": "2",
"output": "1"
},
{
"input": "99991",
"output": "310"
},
{
"input": "99992",
"output": "311"
},
{
"input": "99996",
"output": "315"
},
{
"input": "99997",
"output": "316"
},
{
"input": "99998",
"output": "317"
},
{
"input": "99999",
"output": "318"
},
{
"input": "1021",
"output": "31"
},
{
"input": "4",
"output": "1"
},
{
"input": "23",
"output": "2"
},
{
"input": "9994",
"output": "124"
},
{
"input": "99939",
"output": "258"
},
{
"input": "99999998250180",
"output": "14142135"
},
{
"input": "6",
"output": "3"
},
{
"input": "8",
"output": "2"
},
{
"input": "35",
"output": "7"
},
{
"input": "100",
"output": "9"
},
{
"input": "10101010",
"output": "745"
},
{
"input": "103",
"output": "12"
},
{
"input": "102",
"output": "11"
},
{
"input": "101",
"output": "10"
}
] | 1,658,039,750
| 2,147,483,647
|
PyPy 3-64
|
MEMORY_LIMIT_EXCEEDED
|
TESTS
| 0
| 46
| 268,390,400
|
import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br
sys.setrecursionlimit(100000000)
stdstr = lambda: stdin.readline()
getint = lambda: int(stdin.readline())
mulint = lambda: map(int, stdin.readline().strip().split())
seqint = lambda: list(map(int, stdin.readline().strip().split()))
ceil = lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv= lambda x,d: x//d if(x%d==0) else x//d+1
stdpr = lambda x: stdout.write(str(x))
flush = lambda: stdout.flush()
mod=1000000007
##################
#main code
#t = int(input())
t = 1
res = 1
prev= 1
for _ in range(t):
n = int(input())
while res + prev <= n:
res += prev
prev += 1
print(1 + (n - res))
|
Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the *n*-th position of the sequence.
Input Specification:
The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Output Specification:
Print the element in the *n*-th position of the sequence (the elements are numerated from one).
Demo Input:
['3\n', '5\n', '10\n', '55\n', '56\n']
Demo Output:
['2\n', '2\n', '4\n', '10\n', '1\n']
Note:
none
|
```python
import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br
sys.setrecursionlimit(100000000)
stdstr = lambda: stdin.readline()
getint = lambda: int(stdin.readline())
mulint = lambda: map(int, stdin.readline().strip().split())
seqint = lambda: list(map(int, stdin.readline().strip().split()))
ceil = lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv= lambda x,d: x//d if(x%d==0) else x//d+1
stdpr = lambda x: stdout.write(str(x))
flush = lambda: stdout.flush()
mod=1000000007
##################
#main code
#t = int(input())
t = 1
res = 1
prev= 1
for _ in range(t):
n = int(input())
while res + prev <= n:
res += prev
prev += 1
print(1 + (n - res))
```
| 0
|
|
522
|
A
|
Reposts
|
PROGRAMMING
| 1,200
|
[
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null |
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.
Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.
|
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.
We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.
|
Print a single integer — the maximum length of a repost chain.
|
[
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe reposted PoLyCaRp\n"
] |
[
"6\n",
"2\n",
"2\n"
] |
none
| 500
|
[
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp",
"output": "2"
},
{
"input": "1\nSoMeStRaNgEgUe reposted PoLyCaRp",
"output": "2"
},
{
"input": "1\niuNtwVf reposted POlYcarP",
"output": "2"
},
{
"input": "10\ncs reposted poLYCaRp\nAFIkDrY7Of4V7Mq reposted CS\nsoBiwyN7KOvoFUfbhux reposted aFikDry7Of4v7MQ\nvb6LbwA reposted sObIWYN7KOvoFufBHUx\nDtWKIcVwIHgj4Rcv reposted vb6lbwa\nkt reposted DTwKicvwihgJ4rCV\n75K reposted kT\njKzyxx1 reposted 75K\nuoS reposted jkZyXX1\npZJskHTCIqE3YyZ5ME reposted uoS",
"output": "11"
},
{
"input": "10\nvxrUpCXvx8Isq reposted pOLYcaRP\nICb1 reposted vXRUpCxvX8ISq\nJFMt4b8jZE7iF2m8by7y2 reposted Icb1\nqkG6ZkMIf9QRrBFQU reposted ICb1\nnawsNfcR2palIMnmKZ reposted pOlYcaRP\nKksyH reposted jFMT4b8JzE7If2M8by7y2\nwJtWwQS5FvzN0h8CxrYyL reposted NawsNfcR2paLIMnmKz\nDpBcBPYAcTXEdhldI6tPl reposted NaWSnFCr2pALiMnmkZ\nlEnwTVnlwdQg2vaIRQry reposted kKSYh\nQUVFgwllaWO reposted Wjtwwqs5FVzN0H8cxRyyl",
"output": "6"
},
{
"input": "10\nkkuLGEiHv reposted POLYcArp\n3oX1AoUqyw1eR3nCADY9hLwd reposted kkuLGeIHV\nwf97dqq5bx1dPIchCoT reposted 3OX1AOuQYW1eR3ncAdY9hLwD\nWANr8h reposted Wf97dQQ5bx1dpIcHcoT\n3Fb736lkljZK2LtSbfL reposted wANR8h\n6nq9xLOn reposted 3fB736lKlJZk2LtSbFL\nWL reposted 3Fb736lKLjZk2LTSbfl\ndvxn4Xtc6SBcvKf1 reposted wF97DQq5bX1dPiChCOt\nMCcPLIMISqxDzrj reposted 6nQ9XLOn\nxsQL4Z2Iu reposted MCcpLiMiSqxdzrj",
"output": "9"
},
{
"input": "10\nsMA4 reposted pOLyCARP\nlq3 reposted pOlycARp\nEa16LSFTQxLJnE reposted polYcARp\nkvZVZhJwXcWsnC7NA1DV2WvS reposted polYCArp\nEYqqlrjRwddI reposted pOlyCArP\nsPqQCA67Y6PBBbcaV3EhooO reposted ea16LSFTqxLJne\njjPnneZdF6WLZ3v reposted Ea16LSFTqxLjNe\nWEoi6UpnfBUx79 reposted ea16LSFtqXljNe\nqi4yra reposted eYqqlRJrWDDI\ncw7E1UCSUD reposted eYqqLRJRwDdI",
"output": "3"
}
] | 1,568,598,582
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 4
| 93
| 0
|
arg = int(input())
list2 = [[] for a in range(0, 405)]
for a in range(0,arg):
list1 = input().strip().split()
list1[0] = list1[0].lower()
list1[2] = list1[2].lower()
if [list1[2]] in list2:
list2[list2.index([list1[2]]) * 2].append(list1[0])
else:
counter = 1
while True:
if list2[counter] == []:
# print(counter)
list2[counter].append(list1[2])
list2[counter * 2].append(list1[0])
break
counter += 1
# print(list2)
if ["polycarp"] in list2:
chain = 1
temp = list2[list2.index(["polycarp"])]
while True:
# print(temp)
temp2 = []
for a in temp:
if [a] in list2:
temp2.extend(list2[list2.index([a]) * 2])
temp = temp2
if temp2 == []:
print(chain)
break
else:
chain += 1
else:
print(1)
|
Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.
Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.
We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.
Output Specification:
Print a single integer — the maximum length of a repost chain.
Demo Input:
['5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n', '6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n', '1\nSoMeStRaNgEgUe reposted PoLyCaRp\n']
Demo Output:
['6\n', '2\n', '2\n']
Note:
none
|
```python
arg = int(input())
list2 = [[] for a in range(0, 405)]
for a in range(0,arg):
list1 = input().strip().split()
list1[0] = list1[0].lower()
list1[2] = list1[2].lower()
if [list1[2]] in list2:
list2[list2.index([list1[2]]) * 2].append(list1[0])
else:
counter = 1
while True:
if list2[counter] == []:
# print(counter)
list2[counter].append(list1[2])
list2[counter * 2].append(list1[0])
break
counter += 1
# print(list2)
if ["polycarp"] in list2:
chain = 1
temp = list2[list2.index(["polycarp"])]
while True:
# print(temp)
temp2 = []
for a in temp:
if [a] in list2:
temp2.extend(list2[list2.index([a]) * 2])
temp = temp2
if temp2 == []:
print(chain)
break
else:
chain += 1
else:
print(1)
```
| -1
|
|
405
|
A
|
Gravity Flip
|
PROGRAMMING
| 900
|
[
"greedy",
"implementation",
"sortings"
] | null | null |
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch!
|
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
|
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
|
[
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] |
[
"1 2 2 3 \n",
"2 3 8 \n"
] |
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns.
| 500
|
[
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20 1 80",
"output": "1 20 40 60 80 100 "
},
{
"input": "10\n10 8 6 7 5 3 4 2 9 1",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91",
"output": "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100 "
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 "
},
{
"input": "10\n1 9 7 6 2 4 7 8 1 3",
"output": "1 1 2 3 4 6 7 7 8 9 "
},
{
"input": "20\n53 32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59",
"output": "20 20 22 30 32 41 50 53 54 59 60 61 64 66 68 72 74 80 97 97 "
},
{
"input": "30\n7 17 4 18 16 12 14 10 1 13 2 16 13 17 8 16 13 14 9 17 17 5 13 5 1 7 6 20 18 12",
"output": "1 1 2 4 5 5 6 7 7 8 9 10 12 12 13 13 13 13 14 14 16 16 16 17 17 17 17 18 18 20 "
},
{
"input": "40\n22 58 68 58 48 53 52 1 16 78 75 17 63 15 36 32 78 75 49 14 42 46 66 54 49 82 40 43 46 55 12 73 5 45 61 60 1 11 31 84",
"output": "1 1 5 11 12 14 15 16 17 22 31 32 36 40 42 43 45 46 46 48 49 49 52 53 54 55 58 58 60 61 63 66 68 73 75 75 78 78 82 84 "
},
{
"input": "70\n1 3 3 1 3 3 1 1 1 3 3 2 3 3 1 1 1 2 3 1 3 2 3 3 3 2 2 3 1 3 3 2 1 1 2 1 2 1 2 2 1 1 1 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3 3 3 1 1 3 3 1 1 1 1 3 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52",
"output": "2 3 4 5 5 5 6 6 6 7 7 7 7 10 10 11 11 15 16 17 17 17 18 19 19 20 21 21 21 23 24 24 27 27 30 34 40 43 43 44 46 46 48 48 49 49 50 51 51 51 52 52 53 55 55 58 63 64 65 66 66 66 67 71 71 73 75 75 76 76 77 79 82 85 85 88 88 90 91 91 92 93 95 95 95 96 98 99 100 100 "
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "100\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6",
"output": "1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 "
},
{
"input": "100\n12 10 5 11 13 12 14 13 7 15 15 12 13 19 12 18 14 10 10 3 1 10 16 11 19 8 10 15 5 10 12 16 11 13 11 15 14 12 16 8 11 8 15 2 18 2 14 13 15 20 8 8 4 12 14 7 10 3 9 1 7 19 6 7 2 14 8 20 7 17 18 20 3 18 18 9 6 10 4 1 4 19 9 13 3 3 12 11 11 20 8 2 13 6 7 12 1 4 17 3",
"output": "1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 "
},
{
"input": "100\n5 13 1 40 30 10 23 32 33 12 6 4 15 29 31 17 23 5 36 31 32 38 24 11 34 39 19 21 6 19 31 35 1 15 6 29 22 15 17 15 1 17 2 34 20 8 27 2 29 26 13 9 22 27 27 3 20 40 4 40 33 29 36 30 35 16 19 28 26 11 36 24 29 5 40 10 38 34 33 23 34 39 31 7 10 31 22 6 36 24 14 31 34 23 2 4 26 16 2 32",
"output": "1 1 1 2 2 2 2 3 4 4 4 5 5 5 6 6 6 6 7 8 9 10 10 10 11 11 12 13 13 14 15 15 15 15 16 16 17 17 17 19 19 19 20 20 21 22 22 22 23 23 23 23 24 24 24 26 26 26 27 27 27 28 29 29 29 29 29 30 30 31 31 31 31 31 31 32 32 32 33 33 33 34 34 34 34 34 35 35 36 36 36 36 38 38 39 39 40 40 40 40 "
},
{
"input": "100\n72 44 34 74 9 60 26 37 55 77 74 69 28 66 54 55 8 36 57 31 31 48 32 66 40 70 77 43 64 28 37 10 21 58 51 32 60 28 51 52 28 35 7 33 1 68 38 70 57 71 8 20 42 57 59 4 58 10 17 47 22 48 16 3 76 67 32 37 64 47 33 41 75 69 2 76 39 9 27 75 20 21 52 25 71 21 11 29 38 10 3 1 45 55 63 36 27 7 59 41",
"output": "1 1 2 3 3 4 7 7 8 8 9 9 10 10 10 11 16 17 20 20 21 21 21 22 25 26 27 27 28 28 28 28 29 31 31 32 32 32 33 33 34 35 36 36 37 37 37 38 38 39 40 41 41 42 43 44 45 47 47 48 48 51 51 52 52 54 55 55 55 57 57 57 58 58 59 59 60 60 63 64 64 66 66 67 68 69 69 70 70 71 71 72 74 74 75 75 76 76 77 77 "
},
{
"input": "100\n75 18 61 10 56 53 42 57 79 80 31 2 50 45 54 99 84 52 71 21 86 3 19 98 14 37 40 62 63 68 5 10 87 8 81 85 52 52 57 94 2 7 56 96 19 76 1 13 81 6 80 47 22 59 99 32 9 5 36 88 98 91 70 70 12 93 12 22 85 1 97 48 94 16 84 84 51 34 62 7 68 51 30 2 37 82 4 7 27 1 80 9 61 16 59 55 12 96 94 82",
"output": "1 1 1 2 2 2 3 4 5 5 6 7 7 7 8 9 9 10 10 12 12 12 13 14 16 16 18 19 19 21 22 22 27 30 31 32 34 36 37 37 40 42 45 47 48 50 51 51 52 52 52 53 54 55 56 56 57 57 59 59 61 61 62 62 63 68 68 70 70 71 75 76 79 80 80 80 81 81 82 82 84 84 84 85 85 86 87 88 91 93 94 94 94 96 96 97 98 98 99 99 "
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 "
},
{
"input": "49\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 "
},
{
"input": "30\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88",
"output": "1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 "
},
{
"input": "100\n100 51 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 51 100 "
},
{
"input": "10\n100 90 80 70 60 50 40 30 20 10",
"output": "10 20 30 40 50 60 70 80 90 100 "
},
{
"input": "1\n10",
"output": "10 "
}
] | 1,694,780,336
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 32
| 46
| 0
|
number_of_columns = int(input())
blocks = input()
blocks_list = blocks.split(' ')
blocks_list = [int(x) for x in blocks_list]
blocks_list = sorted(blocks_list)
output_str = ''
for i in blocks_list:
output_str += str(i)
output_str += " "
print(output_str.strip())
|
Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch!
Input Specification:
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output Specification:
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
Demo Input:
['4\n3 2 1 2\n', '3\n2 3 8\n']
Demo Output:
['1 2 2 3 \n', '2 3 8 \n']
Note:
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns.
|
```python
number_of_columns = int(input())
blocks = input()
blocks_list = blocks.split(' ')
blocks_list = [int(x) for x in blocks_list]
blocks_list = sorted(blocks_list)
output_str = ''
for i in blocks_list:
output_str += str(i)
output_str += " "
print(output_str.strip())
```
| 3
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:
In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.
|
The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.
|
Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).
|
[
"AB\nXC\nXB\nAC\n",
"AB\nXC\nAC\nBX\n"
] |
[
"YES\n",
"NO\n"
] |
The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all...
| 0
|
[
{
"input": "AB\nXC\nXB\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nAC\nBX",
"output": "NO"
},
{
"input": "XC\nBA\nCB\nAX",
"output": "NO"
},
{
"input": "AB\nXC\nAX\nCB",
"output": "YES"
},
{
"input": "CB\nAX\nXA\nBC",
"output": "YES"
},
{
"input": "BC\nXA\nBA\nXC",
"output": "NO"
},
{
"input": "CA\nXB\nBA\nCX",
"output": "NO"
},
{
"input": "CA\nXB\nAC\nBX",
"output": "NO"
},
{
"input": "CB\nAX\nCX\nAB",
"output": "YES"
},
{
"input": "AX\nCB\nBC\nXA",
"output": "YES"
},
{
"input": "CA\nXB\nBA\nXC",
"output": "NO"
},
{
"input": "CX\nAB\nAX\nCB",
"output": "NO"
},
{
"input": "AB\nXC\nAB\nCX",
"output": "YES"
},
{
"input": "XC\nBA\nXC\nAB",
"output": "NO"
},
{
"input": "BA\nXC\nAC\nXB",
"output": "YES"
},
{
"input": "AX\nBC\nAC\nBX",
"output": "YES"
},
{
"input": "XC\nBA\nCB\nXA",
"output": "NO"
},
{
"input": "CB\nAX\nXC\nBA",
"output": "NO"
},
{
"input": "AX\nCB\nBC\nAX",
"output": "YES"
},
{
"input": "AB\nXC\nBX\nAC",
"output": "YES"
},
{
"input": "XA\nCB\nBA\nCX",
"output": "NO"
},
{
"input": "CX\nBA\nBX\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nXC\nAB",
"output": "NO"
},
{
"input": "BA\nCX\nAC\nBX",
"output": "YES"
},
{
"input": "XA\nCB\nAB\nXC",
"output": "YES"
},
{
"input": "XC\nBA\nAC\nBX",
"output": "NO"
},
{
"input": "CA\nBX\nBA\nXC",
"output": "NO"
},
{
"input": "AX\nBC\nCA\nXB",
"output": "NO"
},
{
"input": "BC\nAX\nXC\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nBX\nAC",
"output": "YES"
},
{
"input": "CX\nBA\nAX\nBC",
"output": "NO"
},
{
"input": "XB\nCA\nXC\nBA",
"output": "NO"
},
{
"input": "BX\nCA\nXB\nCA",
"output": "YES"
},
{
"input": "XB\nAC\nXC\nAB",
"output": "NO"
},
{
"input": "CX\nBA\nCX\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nCA\nBX",
"output": "YES"
},
{
"input": "BA\nXC\nBC\nAX",
"output": "NO"
},
{
"input": "AC\nXB\nCX\nBA",
"output": "NO"
},
{
"input": "XB\nCA\nCX\nBA",
"output": "NO"
},
{
"input": "AB\nCX\nXA\nBC",
"output": "NO"
},
{
"input": "CX\nAB\nXB\nAC",
"output": "NO"
},
{
"input": "BC\nAX\nAC\nBX",
"output": "NO"
},
{
"input": "XA\nBC\nCB\nAX",
"output": "YES"
},
{
"input": "XC\nAB\nCB\nAX",
"output": "YES"
},
{
"input": "CX\nBA\nCX\nAB",
"output": "NO"
},
{
"input": "CA\nBX\nXC\nBA",
"output": "YES"
},
{
"input": "CX\nBA\nBA\nXC",
"output": "NO"
},
{
"input": "CA\nBX\nCB\nXA",
"output": "NO"
},
{
"input": "CB\nAX\nBC\nAX",
"output": "NO"
},
{
"input": "CB\nAX\nBC\nXA",
"output": "NO"
},
{
"input": "AC\nXB\nCB\nXA",
"output": "YES"
},
{
"input": "AB\nCX\nXB\nAC",
"output": "YES"
},
{
"input": "CX\nBA\nXB\nAC",
"output": "YES"
},
{
"input": "BX\nAC\nAB\nXC",
"output": "YES"
},
{
"input": "CX\nAB\nXC\nBA",
"output": "NO"
},
{
"input": "XB\nAC\nCX\nAB",
"output": "NO"
},
{
"input": "CB\nAX\nXB\nAC",
"output": "NO"
},
{
"input": "CB\nAX\nCA\nXB",
"output": "NO"
},
{
"input": "XC\nBA\nBA\nXC",
"output": "NO"
},
{
"input": "AC\nBX\nCB\nAX",
"output": "YES"
},
{
"input": "CA\nBX\nAC\nXB",
"output": "NO"
},
{
"input": "BX\nAC\nCX\nBA",
"output": "YES"
},
{
"input": "XB\nCA\nAX\nCB",
"output": "NO"
},
{
"input": "CB\nXA\nBC\nXA",
"output": "NO"
},
{
"input": "AX\nCB\nCX\nAB",
"output": "NO"
},
{
"input": "BC\nAX\nXC\nAB",
"output": "NO"
},
{
"input": "XB\nCA\nBC\nXA",
"output": "NO"
},
{
"input": "XB\nAC\nCX\nBA",
"output": "YES"
},
{
"input": "BC\nXA\nCB\nXA",
"output": "NO"
},
{
"input": "AX\nCB\nAX\nBC",
"output": "NO"
},
{
"input": "CA\nBX\nBX\nCA",
"output": "NO"
},
{
"input": "BA\nXC\nXB\nAC",
"output": "NO"
},
{
"input": "XA\nBC\nBX\nAC",
"output": "NO"
},
{
"input": "BX\nCA\nAC\nBX",
"output": "YES"
},
{
"input": "XB\nAC\nXC\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nAB\nXC",
"output": "YES"
},
{
"input": "BA\nCX\nCX\nBA",
"output": "NO"
},
{
"input": "CA\nXB\nXB\nCA",
"output": "NO"
},
{
"input": "BA\nCX\nBA\nXC",
"output": "YES"
},
{
"input": "BA\nCX\nAB\nCX",
"output": "NO"
},
{
"input": "BX\nCA\nXA\nBC",
"output": "YES"
},
{
"input": "XC\nBA\nBX\nCA",
"output": "NO"
},
{
"input": "XC\nAB\nBC\nXA",
"output": "NO"
},
{
"input": "BC\nXA\nXC\nAB",
"output": "NO"
},
{
"input": "BX\nCA\nXB\nAC",
"output": "NO"
},
{
"input": "BA\nXC\nCA\nXB",
"output": "NO"
},
{
"input": "CX\nBA\nAC\nXB",
"output": "NO"
},
{
"input": "AB\nCX\nAC\nBX",
"output": "NO"
},
{
"input": "BC\nXA\nBX\nCA",
"output": "NO"
},
{
"input": "XA\nBC\nCX\nAB",
"output": "YES"
},
{
"input": "AX\nBC\nAX\nCB",
"output": "NO"
},
{
"input": "CB\nAX\nCA\nBX",
"output": "NO"
},
{
"input": "CB\nAX\nBA\nXC",
"output": "YES"
},
{
"input": "AB\nCX\nXC\nBA",
"output": "YES"
},
{
"input": "AC\nXB\nBA\nCX",
"output": "YES"
},
{
"input": "AX\nCB\nCB\nAX",
"output": "NO"
},
{
"input": "CX\nBA\nCA\nXB",
"output": "YES"
},
{
"input": "AC\nBX\nAB\nXC",
"output": "NO"
},
{
"input": "XA\nCB\nXA\nBC",
"output": "NO"
},
{
"input": "XC\nBA\nCA\nBX",
"output": "YES"
},
{
"input": "XA\nBC\nXB\nCA",
"output": "YES"
},
{
"input": "CA\nBX\nCB\nAX",
"output": "NO"
}
] | 1,458,322,082
| 3,182
|
Python 3
|
OK
|
TESTS
| 102
| 62
| 307,200
|
def find(state):
global results
global board2
if state==board2:
return True;
t = state.index('X')
if t==0:
state1 = state[1]+"X"+state[2]+state[3]
state2 = state[2]+state[1]+"X"+state[3]
if state1 in results and state2 in results:
return False
if state1 not in results:
results+=[state1]
if find(state1): return True;
if state2 not in results:
results+=[state2]
if find(state2): return True;
elif t==1:
state1 = state[0]+state[3]+state[2]+"X"
state2 = "X"+state[0]+state[2]+state[3]
if state1 in results and state2 in results:
return False
if state1 not in results:
results+=[state1]
if find(state1): return True;
if state2 not in results:
results+=[state2]
if find(state2): return True;
elif t==2:
state1 = "X"+state[1]+state[0]+state[3]
state2 = state[0]+state[1]+state[3]+"X"
if state1 in results and state2 in results:
return False
if state1 not in results:
results+=[state1]
if find(state1): return True;
if state2 not in results:
results+=[state2]
if find(state2): return True;
elif t==3:
state1 = state[0]+"X"+state[2]+state[1]
state2 = state[0]+state[1]+"X"+state[2]
if state1 in results and state2 in results:
return False
if state1 not in results:
results+=[state1]
if find(state1): return True;
if state2 not in results:
results+=[state2]
if find(state2): return True;
return False
board1 = input()
board1+=input()
board2 = input()
board2+=input()
results=[]
results+=[board1]
print(["NO","YES"][find(board1)])
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:
In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.
Input Specification:
The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.
Output Specification:
Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).
Demo Input:
['AB\nXC\nXB\nAC\n', 'AB\nXC\nAC\nBX\n']
Demo Output:
['YES\n', 'NO\n']
Note:
The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all...
|
```python
def find(state):
global results
global board2
if state==board2:
return True;
t = state.index('X')
if t==0:
state1 = state[1]+"X"+state[2]+state[3]
state2 = state[2]+state[1]+"X"+state[3]
if state1 in results and state2 in results:
return False
if state1 not in results:
results+=[state1]
if find(state1): return True;
if state2 not in results:
results+=[state2]
if find(state2): return True;
elif t==1:
state1 = state[0]+state[3]+state[2]+"X"
state2 = "X"+state[0]+state[2]+state[3]
if state1 in results and state2 in results:
return False
if state1 not in results:
results+=[state1]
if find(state1): return True;
if state2 not in results:
results+=[state2]
if find(state2): return True;
elif t==2:
state1 = "X"+state[1]+state[0]+state[3]
state2 = state[0]+state[1]+state[3]+"X"
if state1 in results and state2 in results:
return False
if state1 not in results:
results+=[state1]
if find(state1): return True;
if state2 not in results:
results+=[state2]
if find(state2): return True;
elif t==3:
state1 = state[0]+"X"+state[2]+state[1]
state2 = state[0]+state[1]+"X"+state[2]
if state1 in results and state2 in results:
return False
if state1 not in results:
results+=[state1]
if find(state1): return True;
if state2 not in results:
results+=[state2]
if find(state2): return True;
return False
board1 = input()
board1+=input()
board2 = input()
board2+=input()
results=[]
results+=[board1]
print(["NO","YES"][find(board1)])
```
| 3
|
|
344
|
A
|
Magnets
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
|
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
|
On the single line of the output print the number of groups of magnets.
|
[
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] |
[
"3\n",
"2\n"
] |
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets.
| 500
|
[
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",
"output": "3"
},
{
"input": "1\n01",
"output": "1"
},
{
"input": "2\n01\n01",
"output": "1"
},
{
"input": "2\n10\n01",
"output": "2"
},
{
"input": "3\n01\n01\n01",
"output": "1"
},
{
"input": "3\n10\n10\n01",
"output": "2"
},
{
"input": "3\n01\n10\n10",
"output": "2"
},
{
"input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10",
"output": "55"
}
] | 1,696,257,481
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 62
| 0
|
a=int(input())
b=input()
last=b[1]
for i in range(a-1):
b=input()
if b[1]!=last:
a=a-1
last=b[1]
print(a-1)
|
Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output Specification:
On the single line of the output print the number of groups of magnets.
Demo Input:
['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n']
Demo Output:
['3\n', '2\n']
Note:
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets.
|
```python
a=int(input())
b=input()
last=b[1]
for i in range(a-1):
b=input()
if b[1]!=last:
a=a-1
last=b[1]
print(a-1)
```
| 0
|
|
1
|
A
|
Theatre Square
|
PROGRAMMING
| 1,000
|
[
"math"
] |
A. Theatre Square
|
1
|
256
|
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
|
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
|
Write the needed number of flagstones.
|
[
"6 6 4\n"
] |
[
"4\n"
] |
none
| 0
|
[
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,678,438,718
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 46
| 0
|
a,b,c=map(int,input().split())
d=c*c
r=a*b
s=a/c
t=b/c
if a%c==0:
u=0
else:
u=1
if b%c==0:
i=1
else:
i=0
an=(a/c)+u
a2=(b/c)+i
print(round(an*a2))
|
Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none
|
```python
a,b,c=map(int,input().split())
d=c*c
r=a*b
s=a/c
t=b/c
if a%c==0:
u=0
else:
u=1
if b%c==0:
i=1
else:
i=0
an=(a/c)+u
a2=(b/c)+i
print(round(an*a2))
```
| 0
|
67
|
A
|
Partial Teacher
|
PROGRAMMING
| 1,800
|
[
"dp",
"graphs",
"greedy",
"implementation"
] |
A. Partial Teacher
|
1
|
256
|
A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks they get the same number of toffees. The same procedure is followed for each pair of adjacent students starting from the first one to the last one.
It is given that each student receives at least one toffee. You have to find the number of toffees given to each student by the teacher such that the total number of toffees is minimum.
|
The first line of input contains the number of students *n* (2<=≤<=*n*<=≤<=1000). The second line gives (*n*<=-<=1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal marks.
|
Output consists of *n* integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one.
|
[
"5\nLRLR\n",
"5\n=RRR\n"
] |
[
"2 1 2 1 2\n",
"1 1 2 3 4\n"
] |
none
| 500
|
[
{
"input": "5\nLRLR",
"output": "2 1 2 1 2"
},
{
"input": "5\n=RRR",
"output": "1 1 2 3 4"
},
{
"input": "6\nRLRL=",
"output": "1 2 1 2 1 1"
},
{
"input": "3\nR=",
"output": "1 2 2"
},
{
"input": "7\nRR==RR",
"output": "1 2 3 3 3 4 5"
},
{
"input": "166\nR===RL=LRRR=RRRL=LRR=R=RR==L=R=R=RRR=RR=RLLRRL=LLRL==L=R==RLR==RL=RR=LR==R=R=LLRLRLR=RR=RLLRLR=RRLL==L=LR=RR=RRRL=RLLLR==L=RRLRLLLLLLLRL===LRLRLRLRRLL=LRLL===LRLRR==",
"output": "1 2 2 2 2 3 2 2 1 2 3 4 4 5 6 7 2 2 1 2 3 3 4 4 5 6 6 6 1 1 2 2 3 3 4 5 6 6 7 8 8 9 2 1 2 4 3 3 2 1 3 2 2 2 1 1 2 2 2 3 1 2 2 2 3 1 1 2 3 3 1 2 2 2 3 3 4 4 2 1 2 1 2 1 2 2 3 4 4 5 2 1 2 1 2 2 3 5 4 3 3 3 2 2 1 2 2 3 4 4 5 6 7 1 1 4 3 2 1 2 2 2 1 1 2 3 1 8 7 6 5 4 3 2 1 3 2 2 2 2 1 2 1 2 1 2 1 2 4 3 2 2 1 4 3 2 2 2 2 1 2 1 2 3 3 3"
},
{
"input": "333\nLL=LR=R=RRR=L=LRR=RLRLLLR=LRL=RRLRRRLLRRLL====RL=L====LLRL=RR==L==RLL==L=R=RLRR==LRRL=LRL=RLRLRR=R=LR=LLR===LRL=RRL====R==LRLR===LLLLL=LLLRLRLLLLLL==RLL=RL==LR=RRLRLL=R=R=R=RLRLRLLRRL==L==LRR=L=R=R===RLR=R=L=LR=LRLRR=RRL=L=RRLR=RRL=RRRL=RLRRRLLLRR=RRRLRLLLR==RR=RL===R=RL=RLL====RRRR=LR=LL=RL==RRLR====R=L=R==L=R=R=RLR=RR=R=LRRRRLLL",
"output": "4 3 2 2 1 2 2 3 3 4 5 6 6 2 2 1 2 3 3 4 1 4 3 2 1 2 2 1 2 1 1 2 3 1 2 3 4 2 1 2 3 2 1 1 1 1 1 5 4 4 3 3 3 3 3 2 1 2 1 1 2 3 3 3 1 1 1 4 3 2 2 2 1 1 2 2 3 1 2 3 3 3 1 2 3 2 2 1 2 1 1 2 1 2 1 2 3 3 4 4 1 3 3 2 1 2 2 2 2 1 2 1 1 2 3 1 1 1 1 1 2 2 2 1 2 1 9 9 9 9 8 7 6 5 4 4 3 2 1 2 1 7 6 5 4 3 2 1 1 1 3 2 1 1 3 2 2 2 1 2 2 3 4 1 3 2 1 1 2 2 3 3 4 4 5 1 2 1 3 2 1 2 4 3 3 3 2 2 2 1 2 3 3 1 1 2 2 3 3 3 3 4 1 2 2 3 3 2 2 1 2 2 1 2 1 2 3 3 4 5 2 2 1 1 2 3 1 2 2 3 4 1 1 2 3 4 1 1 2 1 2 3 4 3 2 1 2 3 3 4 5 6 1 4 3 2..."
},
{
"input": "24\nR=R==RL=RL=RLL=LLL=LLRL",
"output": "1 2 2 3 3 3 4 1 1 2 1 1 8 7 6 6 5 4 3 3 2 1 2 1"
},
{
"input": "438\nLR=RLLLRL=R==LLR=RRLRRR==RLRLRLLRRRRRLRL=RRRRLRR==RR=RR=LLRR=L=LLRRRLLR==RL=L=LLR=L=R==LLR=L=RR==LRL=LLL=RRR=R=LRLLRLLLR==LRRLLL=L==LLR=RL=LLLLR=RR=LR=RL==LRLRR=RRRRRLRLRR==RR=LLLRLR====LRRLL==LR==LL=LLRR=LRL=RRRRLR=RLLR=R=LLLRRRRR===R==LRLLRLR=LLL=L=L=R=RLLR=R=RR=RL=LLRRLLRR=LRRRR==LR==L==R=L=L=R===LLL=LL==L=L=LLLLL==RRRR==R=RLL=RLR=RRRR=R=L=RRRLLRRLRRRLLRLLRRRL=LR=R=LRLRL=R=RLRRLRRL==R=RRR=RLLR=RR=LL=RLR=R==R===RRLR=LLLR=L===LR=L=R",
"output": "2 1 2 2 4 3 2 1 2 1 1 3 3 3 2 1 2 2 3 4 1 2 3 4 4 4 5 1 2 1 3 2 1 2 3 4 5 6 1 2 1 1 2 3 4 5 1 2 3 3 3 4 5 5 6 7 7 2 1 2 4 4 3 3 2 1 2 3 4 2 1 2 2 2 5 4 4 3 3 2 1 2 2 1 1 3 3 3 2 1 2 2 1 1 2 3 3 3 1 5 4 4 3 2 1 1 2 3 4 4 5 5 1 3 2 1 4 3 2 1 2 2 2 1 2 7 6 5 4 4 3 3 3 2 1 2 2 6 5 5 4 3 2 1 2 2 3 4 4 1 2 2 3 2 2 2 1 2 1 2 3 3 4 5 6 7 8 1 2 1 2 3 3 3 4 5 5 3 2 1 2 1 2 2 2 2 2 1 2 4 3 2 2 2 1 5 5 5 4 3 3 2 1 2 3 3 1 2 1 1 2 3 4 5 1 2 2 3 2 1 2 2 4 4 3 2 1 2 3 4 5 6 6 6 6 7 7 7 1 3 2 1 2 1 6 6 5 4 3 3 2 2 1 1 2 2..."
},
{
"input": "453\nR==LL==RRLLRRLR=L=LRLL=LRRR=R====L=RL======RR==RRRR=LRR=LLLRR=LLLLL===LL=LLL=LR=RLRL===L==R=LRL=L=R==RRLLR=L==LRR=RRLRLLRR=LL==RLRLLRRRL=RRL=R====L=RLRR=RR=RRRL=R=RL=LLR=LR=L=RR=RR====LRRLRRLLR==R==L==RRLLRLR=RLLLLR==L=L=L=RR==L=LRRRL=R==RRL=LRR=RRRRRL===RLRLR=RLRLRLRLRR=RL=LL=RLLRR=LL=RLL=L=LRLLLLLR==RRL=R=L===LRLLL=RRRLR=LR====RR=L===LLLL=R=LLLRRRLL=LL==RLRL=LRLRL=RR=RLR==LLR=LR=RLLRLRRLL==L=LL==L==RLRLRLL=L=RLLR==LLRRLRRL==L=R=RLLRLLLL====L=====",
"output": "1 3 3 3 2 1 1 1 2 3 2 1 2 3 1 3 3 2 2 1 4 3 2 2 1 2 3 4 4 5 5 5 5 5 1 1 2 1 1 1 1 1 1 1 2 3 3 3 4 5 6 7 7 1 2 4 4 3 2 1 2 12 12 11 10 9 8 7 7 7 7 6 5 5 4 3 2 2 1 2 2 3 1 3 2 2 2 2 1 1 1 2 2 1 3 2 2 1 1 2 2 2 3 4 2 1 3 3 2 2 2 1 2 3 3 4 5 1 3 2 1 2 3 3 2 1 1 1 2 1 3 2 1 2 3 4 1 1 2 3 1 1 2 2 2 2 2 1 1 2 1 2 3 3 4 5 5 6 7 8 1 1 2 2 4 3 3 2 1 2 2 1 2 2 1 1 2 3 3 4 5 5 5 5 5 1 2 3 1 2 3 2 1 2 2 2 3 3 3 1 1 1 2 3 2 1 2 1 2 2 5 4 3 2 1 4 4 4 3 3 2 2 1 1 2 3 3 3 2 2 1 2 3 4 1 1 2 2 2 3 4 2 2 1 2 3 3 4 5 6 7 8 1 1..."
},
{
"input": "100\n=L=L=L=R=LR=RRRLRL=LRL=RRLLLLRL=R==R=LLLRR===RR=LR==LRLR===RRLRLLRLLR=LRLRR=L=LRRLLLRR==LLRLLLL==RL",
"output": "4 4 3 3 2 2 1 1 2 2 1 2 2 3 4 5 1 3 2 2 1 2 1 1 2 5 4 3 2 1 2 1 1 2 2 2 4 4 3 2 1 2 3 3 3 3 4 5 5 1 2 2 2 1 2 1 2 2 2 2 3 4 1 3 2 1 3 2 1 2 2 1 2 1 2 3 3 2 2 1 2 4 3 2 1 2 3 3 3 2 1 5 4 3 2 1 1 1 2 1"
},
{
"input": "484\nLLRRRL==RRLRRLR=LRR=RL=LLLRL===RLRRRLRR=RRRL=LLLLRL==RL==R==LLLRL=RLLRLRLLLLLLLRRLL=LLR=LLR==RLL==LLLR=RL==LL=LRRL=LLRRRLR====R=R=LRRRLLL==RLRRLR=LL==LLRLR===RR=LR==RL==L==R====LRL=LR=R=R=R=LL=L=RLR=RL==R==LRLRL==L==LL=LR=L=RRRR=R==RRLRRRLR==R=LL===R===RLRRR===LRRLLRRRRR=L==LLRRRRLRRRLL===L==LR==LR==RRLRRLRLLLL=RRL=L=LLLRLRRLLL=LRRRRLLLR=L=LL=LRLL=R==L=LRR=R=LLLRR=LRRRLR=R=RLLRR=LRL===LL==LR===L=L=L=RLL=LRRL=LL==RL==RRL====RR=L=R==L==RRL=LLRLR=RLLLL==R==RRL=====LR=RRR=LRLRRR=RLR",
"output": "3 2 1 2 3 4 1 1 1 2 3 1 2 3 1 2 2 1 2 3 3 5 4 4 3 2 1 2 1 1 1 1 2 1 2 3 4 1 2 3 3 4 5 6 5 5 4 3 2 1 2 1 1 1 2 1 1 1 4 4 4 3 2 1 2 1 1 3 2 1 2 1 8 7 6 5 4 3 2 1 2 5 4 3 3 2 1 3 3 2 1 2 2 2 6 5 4 4 4 3 2 1 2 2 5 4 4 4 3 2 2 1 2 4 3 3 2 1 2 3 4 1 2 2 2 2 2 3 3 4 4 1 2 3 4 3 2 1 1 1 2 1 2 3 1 5 5 4 3 3 3 2 1 2 1 2 2 2 2 3 4 4 1 2 2 2 3 2 2 2 1 1 1 2 2 2 2 2 1 3 2 2 1 2 2 3 3 4 4 5 5 3 2 2 1 1 2 1 2 2 3 1 1 1 2 2 2 1 2 1 6 5 5 5 4 4 4 3 2 2 1 2 2 1 1 2 3 4 5 5 6 6 6 7 8 1 2 3 4 1 2 2 2 3 3 2 1 1 1 1 2 2 2 2 3 1..."
},
{
"input": "338\n==R===L=RLRLR===RR=RRL==R=R=RLRLLRLRRRLR=LR=RR=RLLRR=RRRLLRLL=RRRRRLRLLLL=RLLRLLLRL===RRR=RRLLR=LLLL===RLL==LRLLLLRLLLLR=====RLRLRLRL=L==RRLL=RLL===LL=R=RRL=LL=L==RRLLR=LLRLL=LL=LL==RRLR=L=RLLL=LRLLLRRLR=RL=RR=R=L==RLRLL=LRRLLLLLL=RRL==RLL==R===LR===LRLRLR==LR=RR==RR=RRRRRLRRRLRLLRRRLL=LR=RRR=RL=R=LRRLR==RRR=LLL===RR=RL==RRLLL=RL=L=RLL",
"output": "1 1 1 2 2 2 2 1 1 2 1 2 1 2 2 2 2 3 4 4 5 6 1 1 1 2 2 3 3 4 1 3 2 1 2 1 2 3 4 1 2 2 1 2 2 3 4 4 5 2 1 2 3 3 4 5 6 2 1 3 2 1 1 2 3 4 5 6 1 5 4 3 2 1 1 3 2 1 4 3 2 1 2 1 1 1 1 2 3 4 4 5 6 2 1 5 5 4 3 2 1 1 1 1 4 3 2 2 2 1 5 4 3 2 1 5 4 3 2 1 2 2 2 2 2 2 3 1 2 1 2 1 3 2 2 1 1 1 2 3 2 1 1 5 4 3 3 3 3 2 1 1 2 2 3 5 4 4 3 2 2 1 1 1 2 3 2 1 3 3 2 1 7 6 5 5 4 3 3 2 1 1 1 2 3 1 2 2 1 1 5 4 3 2 2 1 4 3 2 1 2 3 1 2 2 3 1 1 2 3 3 4 4 1 1 1 2 1 4 3 2 2 1 2 7 6 5 4 3 2 1 1 2 3 1 1 1 3 2 1 1 1 2 2 2 2 1 2 2 2 2 1 2 1 2 1..."
},
{
"input": "198\nLLRRR=RRRRLRRLRR=R===R=RL==R=RLLLR=R=L=LR=R====RRL=RRR=LL=R=RR=RRRLRRLRRR==L=LRLLL====LR=RL==L===LRR=L=L==R==R==L=LLL===R=LLL=R=L=LLLLRLL=RL=LRRLR=RL==RR=R==RLR==R=R==RLRL=LL=RRR=R===LLLRRRRL=RLRLL",
"output": "3 2 1 2 3 4 4 5 6 7 8 1 2 3 1 2 3 3 4 4 4 4 5 5 6 1 1 1 2 2 4 3 2 1 2 2 3 3 2 2 1 2 2 3 3 3 3 3 4 5 1 1 2 3 4 4 2 1 1 2 2 3 4 4 5 6 7 1 2 3 1 2 3 4 4 4 2 2 1 5 4 3 2 2 2 2 2 1 2 2 4 3 3 3 2 2 2 2 1 2 3 3 2 2 1 1 1 2 2 2 5 5 5 4 4 3 2 1 1 1 1 4 4 3 2 1 1 6 6 5 5 4 3 2 1 3 2 1 1 3 2 2 1 2 3 1 2 2 3 1 1 1 2 3 3 4 4 4 5 1 2 2 2 3 3 4 4 4 5 1 4 3 3 2 1 1 2 3 4 4 5 5 5 5 3 2 1 2 3 4 5 1 1 2 1 3 2 1"
},
{
"input": "426\nR==LRRRL=R==LLRRRLRLLLR=====R=RRRLLR==LL=L=RR=L=L==LRRR=LL=RR=LRRRLRLLR=R==RL=RRL===RRRL=RLRRRRRLRLLR=LR==LL=R=RRRLRLLLRL=L=RL=R==L==RRLLRRR=RRR==RL=====R=R==RLR=R==L==RL=RRR=RLL=L=LL=RLLR===R=RL==LR=LRLLLR==L==LR=RLLLRRRRL=RRRL=RL=LR=====R=RR=L=RL==L=LLRL=LL=L==LR=RLLRR=RLRLR=LRLLRR===L===RLL=RR==RR=R====RRLR=L=RLRLRLLRLLL=R=R=LLLRRRLR=L==L=R==LLR=L=L==RRLR=LR=R=LR=RR=R=LLRL=L=R=LLLLLR==L=LR=R=L=LL==LRR=L===RL==LL==R==RL",
"output": "1 2 2 2 1 2 3 4 1 1 3 3 3 2 1 2 3 4 1 4 3 2 1 2 2 2 2 2 2 3 3 4 5 6 2 1 4 4 4 3 2 2 1 1 2 4 4 3 3 2 2 2 1 2 3 4 4 2 1 1 2 3 3 1 2 3 4 1 3 2 1 2 2 3 3 3 4 1 1 2 3 1 1 1 1 2 3 4 1 1 2 1 2 3 4 5 6 1 3 2 1 2 2 1 3 3 3 2 1 1 2 2 3 4 5 1 4 3 2 1 3 2 2 1 1 2 1 1 2 2 2 1 1 1 2 3 2 1 2 3 4 4 5 6 7 7 7 8 1 1 1 1 1 1 2 2 3 3 3 4 1 2 2 3 3 3 1 1 1 2 1 1 2 3 4 4 6 5 4 4 3 3 2 1 1 3 2 1 2 2 2 2 3 3 4 2 2 2 1 2 2 1 4 3 2 1 3 3 3 2 2 2 1 2 2 4 3 2 1 2 3 4 5 1 1 2 3 4 1 1 3 2 2 1 2 2 2 2 2 2 3 3 4 5 5 1 1 5 4 4 4 3 3 2 1 6..."
},
{
"input": "10\nRL=R=RLR=",
"output": "1 2 1 1 2 2 3 1 2 2"
},
{
"input": "2\nL",
"output": "2 1"
},
{
"input": "100\nR=R=RRR=R=RR=RRLL=RLRLLLLLR==L=======L=LLR==RL=R=LRLLLR==LLLL=RRRL=LRL=LR=====L=LLLRRL=LLR===RLR=RR",
"output": "1 2 2 3 3 4 5 6 6 7 7 8 9 9 10 11 2 1 1 2 1 6 5 4 3 2 1 5 5 5 4 4 4 4 4 4 4 4 3 3 2 1 2 2 2 3 1 1 2 2 1 4 3 2 1 5 5 5 4 3 2 1 1 2 3 4 2 2 1 3 2 2 1 5 5 5 5 5 5 4 4 3 2 1 2 4 3 3 2 1 2 2 2 2 3 1 2 2 3 4"
},
{
"input": "23\nL=LLLLRL=RR=RLLLL=RR==",
"output": "6 5 5 4 3 2 1 2 1 1 2 3 3 5 4 3 2 1 1 2 3 3 3"
},
{
"input": "432\n=R=RRL=LLR=LLRLLRL=RL==R===L===LR=RR=LL==RLRLRRL=LRL=RLLRRLLL==RLLR=LLLRL=RLRRLLRRL=RLRRL=LL=RR=RL==LL===R==RR=LLL=RRR===R=RLLLR====R==RL=LRL=LLRLRLLRL=LLR==R==LLLL===R=R=LR=L=LRR=LR==LLL=L=LR=R=RLR=L=R==L=RLLLRR=R===R==L==R===L=RLLRLLLLLLL=LRRL=LLLL=RR==R===RR=LLLLRLRL==R====LR==LRL=L=R=R=L====LRLRL=RRR=RRRL====R=LRLRL===LRLLLR==R==LL=R==L==L=LRRRL==LL=R=L=LL=RRRLLRLRL==LLR===RRR=RRLRRR=R=RL===L=RRRR=R=RL===R==L===LLR=LLRLLLRL",
"output": "1 1 2 2 3 4 3 3 2 1 3 3 2 1 3 2 1 2 1 1 2 1 1 1 3 3 3 3 2 2 2 2 1 2 2 3 4 4 2 1 1 1 2 1 2 1 2 3 2 2 1 2 1 1 3 2 1 2 4 3 2 1 1 1 3 2 1 4 4 3 2 1 2 1 1 2 1 2 3 2 1 2 3 1 1 2 1 2 4 3 3 2 1 1 2 3 3 4 3 3 3 2 1 1 1 1 2 2 2 3 4 4 3 2 1 1 2 3 4 4 4 4 5 5 6 3 2 1 2 2 2 2 2 3 3 3 4 2 2 1 4 3 3 2 1 2 1 3 2 1 4 3 3 2 1 2 2 2 5 5 5 4 3 2 1 1 1 1 2 2 3 3 1 3 3 2 2 1 2 3 3 1 6 6 6 5 4 3 3 2 2 1 2 2 3 3 4 1 2 2 1 1 2 2 2 1 1 4 3 2 1 2 3 3 4 4 4 4 5 5 5 1 1 1 2 2 2 2 1 1 3 2 1 9 8 7 6 5 4 3 2 2 1 2 6 5 5 4 3 2 1 1 2 3 3 3..."
},
{
"input": "4\nRRL",
"output": "1 2 3 1"
},
{
"input": "17\n=RRR=L==LLLLRRRL",
"output": "1 1 2 3 6 6 5 5 5 4 3 2 1 2 3 4 1"
},
{
"input": "20\nRRLLLLLRRRRRRRRLRLR",
"output": "1 2 6 5 4 3 2 1 2 3 4 5 6 7 8 9 1 2 1 2"
},
{
"input": "9\nR===RRLL",
"output": "1 2 2 2 2 3 4 2 1"
},
{
"input": "15\n=RRR=LLLLLRRRL",
"output": "1 1 2 3 6 6 5 4 3 2 1 2 3 4 1"
}
] | 1,522,510,605
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 43
| 186
| 7,065,600
|
n=int(input())
s=input()
w=[1]*n
for i in range(n-1):
if s[i]=='=':
w[i+1]=w[i]
elif s[i]=='R':
if w[i+1]<=w[i]:
w[i+1]=w[i]+1
else:
if w[i]<=w[i+1]:
w[i]=w[i+1]+1
for i in range(n-2,-1,-1):
if s[i]=='=':
w[i]=w[i+1]
elif s[i]=='R':
if w[i+1]==w[i]:
w[i+1]=w[i]+1
else:
if w[i]<=w[i+1]:
w[i]=w[i+1]+1
for i in range(n):
print(w[i],end=' ')
|
Title: Partial Teacher
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks they get the same number of toffees. The same procedure is followed for each pair of adjacent students starting from the first one to the last one.
It is given that each student receives at least one toffee. You have to find the number of toffees given to each student by the teacher such that the total number of toffees is minimum.
Input Specification:
The first line of input contains the number of students *n* (2<=≤<=*n*<=≤<=1000). The second line gives (*n*<=-<=1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal marks.
Output Specification:
Output consists of *n* integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one.
Demo Input:
['5\nLRLR\n', '5\n=RRR\n']
Demo Output:
['2 1 2 1 2\n', '1 1 2 3 4\n']
Note:
none
|
```python
n=int(input())
s=input()
w=[1]*n
for i in range(n-1):
if s[i]=='=':
w[i+1]=w[i]
elif s[i]=='R':
if w[i+1]<=w[i]:
w[i+1]=w[i]+1
else:
if w[i]<=w[i+1]:
w[i]=w[i+1]+1
for i in range(n-2,-1,-1):
if s[i]=='=':
w[i]=w[i+1]
elif s[i]=='R':
if w[i+1]==w[i]:
w[i+1]=w[i]+1
else:
if w[i]<=w[i+1]:
w[i]=w[i+1]+1
for i in range(n):
print(w[i],end=' ')
```
| 3.893839
|
867
|
A
|
Between the Offices
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not.
|
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.
|
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower).
|
[
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] |
[
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] |
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.
| 500
|
[
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFFFFSFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "20\nSSFSFSFSFSFSFSFSSFSF",
"output": "YES"
},
{
"input": "20\nSSSSFSFSSFSFSSSSSSFS",
"output": "NO"
},
{
"input": "100\nFFFSFSFSFSSFSFFSSFFFFFSSSSFSSFFFFSFFFFFSFFFSSFSSSFFFFSSFFSSFSFFSSFSSSFSFFSFSFFSFSFFSSFFSFSSSSFSFSFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFSFFFFFFFFFSFSSFFFFFFFFFFFFFFFFFFFFFFSFFSFFFFFSFFFFFFFFSFFFFFFFFFFFFFSFFFFFFFFSFFFFFFFSF",
"output": "NO"
},
{
"input": "100\nSFFSSFFFFFFSSFFFSSFSFFFFFSSFFFSFFFFFFSFSSSFSFSFFFFSFSSFFFFFFFFSFFFFFSFFFFFSSFFFSFFSFSFFFFSFFSFFFFFFF",
"output": "YES"
},
{
"input": "100\nFFFFSSSSSFFSSSFFFSFFFFFSFSSFSFFSFFSSFFSSFSFFFFFSFSFSFSFFFFFFFFFSFSFFSFFFFSFSFFFFFFFFFFFFSFSSFFSSSSFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFSSFFFFSFSFFFSFSSSFSSSSSFSSSSFFSSFFFSFSFSSFFFSSSFFSFSFSSFSFSSFSFFFSFFFFFSSFSFFFSSSFSSSFFS",
"output": "NO"
},
{
"input": "100\nFFFSSSFSFSSSSFSSFSFFSSSFFSSFSSFFSSFFSFSSSSFFFSFFFSFSFSSSFSSFSFSFSFFSSSSSFSSSFSFSFFSSFSFSSFFSSFSFFSFS",
"output": "NO"
},
{
"input": "100\nFFSSSSFSSSFSSSSFSSSFFSFSSFFSSFSSSFSSSFFSFFSSSSSSSSSSSSFSSFSSSSFSFFFSSFFFFFFSFSFSSSSSSFSSSFSFSSFSSFSS",
"output": "NO"
},
{
"input": "100\nSSSFFFSSSSFFSSSSSFSSSSFSSSFSSSSSFSSSSSSSSFSFFSSSFFSSFSSSSFFSSSSSSFFSSSSFSSSSSSFSSSFSSSSSSSFSSSSFSSSS",
"output": "NO"
},
{
"input": "100\nFSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSSSSSSFSSSSSSSSSSSSSFSSFSSSSSFSSFSSSSSSSSSFFSSSSSFSFSSSFFSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSFSSSSSSSSSSSSFSSSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSFS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFSFFFFFFFFFFFSFSFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFSSFFFFSFFFFFFFFFFFFFFFFFFFSFFFSSFFFFSFSFFFSFFFFFFFFFFFFFFFSSFFFFFFFFSSFFFFFFFFFFFFFFSFF",
"output": "YES"
},
{
"input": "100\nSFFSSSFFSFSFSFFFFSSFFFFSFFFFFFFFSFSFFFSFFFSFFFSFFFFSFSFFFFFFFSFFFFFFFFFFSFFSSSFFSSFFFFSFFFFSFFFFSFFF",
"output": "YES"
},
{
"input": "100\nSFFFSFFFFSFFFSSFFFSFSFFFSFFFSSFSFFFFFSFFFFFFFFSFSFSFFSFFFSFSSFSFFFSFSFFSSFSFSSSFFFFFFSSFSFFSFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSSSSFFFFSFFFFFFFSFFFFSFSFFFFSSFFFFFFFFFSFFSSFFFFFFSFSFSSFSSSFFFFFFFSFSFFFSSSFFFFFFFSFFFSSFFFFSSFFFSF",
"output": "YES"
},
{
"input": "100\nSSSFSSFFFSFSSSSFSSFSSSSFSSFFFFFSFFSSSSFFSSSFSSSFSSSSFSSSSFSSSSSSSFSFSSFFFSSFFSFFSSSSFSSFFSFSSFSFFFSF",
"output": "YES"
},
{
"input": "100\nSFFSFSSSSSSSFFSSSFSSSSFSFSSFFFSSSSSSFSSSSFSSFSSSFSSSSSSSFSSFSFFFSSFSSFSFSFSSSSSSSSSSSSFFFFSSSSSFSFFF",
"output": "YES"
},
{
"input": "100\nSSSFSFFSFSFFSSSSSFSSSFSSSFFFSSSSSSSSSFSFSFSSSSFSFSSFFFFFSSSSSSSSSSSSSSSSSSSFFSSSSSFSFSSSSFFSSSSFSSSF",
"output": "YES"
},
{
"input": "100\nSSSFSSSSSSSSSSFSSSSFSSSSSSFSSSSSSFSSSSSSSSSSSSSSFSSSFSSSFSSSSSSSSSSSFSSSSSSFSFSSSSFSSSSSSFSSSSSSSSFF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFFSSSSSSSSSFSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "2\nSS",
"output": "NO"
}
] | 1,604,386,016
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 34
| 109
| 0
|
t=1
while t>0:
t-=1
n=int(input())
s=input()
sf=0
sea=0
for i in range(n-1):
if s[i]!=s[i+1]:
if s[i]=="S":
sf+=1
else:
sea+=1
if sea>=sf:
print("NO")
else:
print("YES")
|
Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not.
Input Specification:
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.
Output Specification:
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower).
Demo Input:
['4\nFSSF\n', '2\nSF\n', '10\nFFFFFFFFFF\n', '10\nSSFFSFFSFF\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n', 'YES\n']
Note:
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.
|
```python
t=1
while t>0:
t-=1
n=int(input())
s=input()
sf=0
sea=0
for i in range(n-1):
if s[i]!=s[i+1]:
if s[i]=="S":
sf+=1
else:
sea+=1
if sea>=sf:
print("NO")
else:
print("YES")
```
| 3
|
|
940
|
A
|
Points on the line
|
PROGRAMMING
| 1,200
|
[
"brute force",
"greedy",
"sortings"
] | null | null |
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
Diameter of multiset consisting of one point is 0.
You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*?
|
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points.
|
Output a single integer — the minimum number of points you have to remove.
|
[
"3 1\n2 1 4\n",
"3 0\n7 7 7\n",
"6 3\n1 3 4 6 9 10\n"
] |
[
"1\n",
"0\n",
"3\n"
] |
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.
| 500
|
[
{
"input": "3 1\n2 1 4",
"output": "1"
},
{
"input": "3 0\n7 7 7",
"output": "0"
},
{
"input": "6 3\n1 3 4 6 9 10",
"output": "3"
},
{
"input": "11 5\n10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "1 100\n1",
"output": "0"
},
{
"input": "100 10\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "84"
},
{
"input": "100 70\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "27"
},
{
"input": "1 10\n25",
"output": "0"
},
{
"input": "70 80\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70",
"output": "0"
},
{
"input": "3 1\n25 26 27",
"output": "1"
},
{
"input": "100 5\n51 56 52 60 52 53 52 60 56 54 55 50 53 51 57 53 52 54 54 52 51 55 50 56 60 51 58 50 60 59 50 54 60 55 55 57 54 59 59 55 55 52 56 57 59 54 53 57 52 50 50 55 59 54 54 56 51 58 52 51 56 56 58 56 54 54 57 52 51 58 56 57 54 59 58 53 50 52 50 60 57 51 54 59 54 54 52 55 53 55 51 53 52 54 51 56 55 53 58 56",
"output": "34"
},
{
"input": "100 11\n44 89 57 64 94 96 73 96 55 52 91 73 73 93 51 62 63 85 43 75 60 78 98 55 80 84 65 75 61 88 62 71 53 57 94 85 60 96 66 96 61 72 97 64 51 44 63 82 67 86 60 57 74 85 57 79 61 94 86 78 84 56 60 75 91 91 92 62 89 85 79 57 76 97 65 56 46 78 51 69 50 52 85 80 76 71 81 51 90 71 77 60 63 62 84 59 79 84 69 81",
"output": "70"
},
{
"input": "100 0\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "96"
},
{
"input": "100 100\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "0"
},
{
"input": "76 32\n50 53 69 58 55 39 40 42 40 55 58 73 55 72 75 44 45 55 46 60 60 42 41 64 77 39 68 51 61 49 38 41 56 57 64 43 78 36 39 63 40 66 52 76 39 68 39 73 40 68 54 60 35 67 69 52 58 52 38 63 69 38 69 60 73 64 65 41 59 55 37 57 40 34 35 35",
"output": "13"
},
{
"input": "100 1\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "93"
},
{
"input": "100 5\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "89"
},
{
"input": "98 64\n2 29 36 55 58 15 25 33 7 16 61 1 4 24 63 26 36 16 16 3 57 39 56 7 11 24 20 12 22 10 56 5 11 39 61 52 27 54 21 6 61 36 40 52 54 5 15 52 58 23 45 39 65 16 27 40 13 64 47 24 51 29 9 18 49 49 8 47 2 64 7 63 49 10 20 26 34 3 45 66 8 46 16 32 16 38 3 6 15 17 35 48 36 5 57 29 61 15",
"output": "1"
},
{
"input": "100 56\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "43"
},
{
"input": "100 0\n14 13 14 13 14 13 13 13 13 14 13 13 14 14 13 14 14 14 14 13 13 13 14 13 13 14 14 14 14 14 14 13 13 13 13 14 13 14 13 14 13 14 14 14 14 13 13 14 14 13 13 13 13 14 13 14 13 14 13 14 13 13 13 14 13 13 14 13 14 14 13 13 13 14 14 14 14 13 13 14 14 14 14 14 14 14 13 14 13 13 13 14 14 13 13 13 13 13 14 14",
"output": "50"
},
{
"input": "100 0\n14 17 18 22 19 18 19 21 19 19 22 22 19 21 24 23 24 19 25 24 24 21 20 13 26 18 17 15 25 13 17 20 20 21 13 22 27 15 18 27 19 15 16 25 18 17 18 22 19 17 18 24 14 16 18 16 22 16 17 27 18 17 18 24 22 13 14 20 23 19 16 21 19 13 14 14 25 15 27 24 26 22 16 20 16 14 21 27 15 23 23 24 27 14 24 17 19 24 15 27",
"output": "89"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "1 100\n22",
"output": "0"
},
{
"input": "1 0\n22",
"output": "0"
},
{
"input": "1 99\n99",
"output": "0"
},
{
"input": "1 5\n6",
"output": "0"
},
{
"input": "3 1\n10 20 30",
"output": "2"
},
{
"input": "3 0\n1 2 3",
"output": "2"
},
{
"input": "3 2\n1 50 99",
"output": "2"
},
{
"input": "7 4\n1 3 4 9 10 11 12",
"output": "3"
},
{
"input": "2 5\n67 23",
"output": "1"
},
{
"input": "4 2\n1 4 7 9",
"output": "2"
},
{
"input": "2 0\n1 2",
"output": "1"
},
{
"input": "8 1\n3 3 3 5 5 5 5 5",
"output": "3"
},
{
"input": "5 1\n3 5 5 5 6",
"output": "1"
}
] | 1,519,563,519
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 4
| 62
| 5,632,000
|
str1=input()
str2=input()
a=str1.split(" ")
b=str2.split(" ")
n,d=int(a[0]),int(a[1])
multiset=[]
for i in b:
multiset.append(int(i))
multiset.sort()
maximum=0
for i in range(1,n):
j=i-1
count=1
while (j>=0 and abs(multiset[i]-multiset[j])<=d):
count+=1
j-=1
if (count>maximum):
maximum=count
print(n-maximum)
|
Title: Points on the line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
Diameter of multiset consisting of one point is 0.
You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*?
Input Specification:
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points.
Output Specification:
Output a single integer — the minimum number of points you have to remove.
Demo Input:
['3 1\n2 1 4\n', '3 0\n7 7 7\n', '6 3\n1 3 4 6 9 10\n']
Demo Output:
['1\n', '0\n', '3\n']
Note:
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.
|
```python
str1=input()
str2=input()
a=str1.split(" ")
b=str2.split(" ")
n,d=int(a[0]),int(a[1])
multiset=[]
for i in b:
multiset.append(int(i))
multiset.sort()
maximum=0
for i in range(1,n):
j=i-1
count=1
while (j>=0 and abs(multiset[i]-multiset[j])<=d):
count+=1
j-=1
if (count>maximum):
maximum=count
print(n-maximum)
```
| 0
|
|
581
|
A
|
Vasya the Hipster
|
PROGRAMMING
| 800
|
[
"implementation",
"math"
] | null | null |
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
|
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
|
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
|
[
"3 1\n",
"2 3\n",
"7 3\n"
] |
[
"1 1\n",
"2 0\n",
"3 2\n"
] |
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
| 500
|
[
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,694,963,083
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
p,q=sorted(map(int,input().split())
print((a,(b-a)//2))
|
Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
|
```python
p,q=sorted(map(int,input().split())
print((a,(b-a)//2))
```
| -1
|
|
960
|
B
|
Minimize the error
|
PROGRAMMING
| 1,500
|
[
"data structures",
"greedy",
"sortings"
] | null | null |
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the minimum possible value of error after *k*1 operations on array *A* and *k*2 operations on array *B* have been performed.
|
The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively.
Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — array *A*.
Third line contains *n* space separated integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=106<=≤<=*b**i*<=≤<=106)— array *B*.
|
Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*.
|
[
"2 0 0\n1 2\n2 3\n",
"2 1 0\n1 2\n2 2\n",
"2 5 7\n3 4\n14 4\n"
] |
[
"2",
"0",
"1"
] |
In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2.
In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we increment the first element of *A* by 1. Now, *A* = [2, 2]. The error is now *E* = (2 - 2)<sup class="upper-index">2</sup> + (2 - 2)<sup class="upper-index">2</sup> = 0. This is the minimum possible error obtainable.
In the third sample case, we can increase the first element of *A* to 8, using the all of the 5 moves available to us. Also, the first element of *B* can be reduced to 8 using the 6 of the 7 available moves. Now *A* = [8, 4] and *B* = [8, 4]. The error is now *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 4)<sup class="upper-index">2</sup> = 0, but we are still left with 1 move for array *B*. Increasing the second element of *B* to 5 using the left move, we get *B* = [8, 5] and *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 5)<sup class="upper-index">2</sup> = 1.
| 1,000
|
[
{
"input": "2 0 0\n1 2\n2 3",
"output": "2"
},
{
"input": "2 1 0\n1 2\n2 2",
"output": "0"
},
{
"input": "2 5 7\n3 4\n14 4",
"output": "1"
},
{
"input": "2 0 1\n1 2\n2 2",
"output": "0"
},
{
"input": "2 1 1\n0 0\n1 1",
"output": "0"
},
{
"input": "5 5 5\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "3 4 5\n1 2 3\n3 2 1",
"output": "1"
},
{
"input": "3 1000 0\n1 2 3\n-1000 -1000 -1000",
"output": "1341346"
},
{
"input": "10 300 517\n-6 -2 6 5 -3 8 9 -10 8 6\n5 -9 -2 6 1 4 6 -2 5 -3",
"output": "1"
},
{
"input": "10 819 133\n87 22 30 89 82 -97 -52 25 76 -22\n-20 95 21 25 2 -3 45 -7 -98 -56",
"output": "0"
},
{
"input": "10 10 580\n302 -553 -281 -299 -270 -890 -989 -749 -418 486\n735 330 6 725 -984 209 -855 -786 -502 967",
"output": "2983082"
},
{
"input": "10 403 187\n9691 -3200 3016 3540 -9475 8840 -4705 7940 6293 -2631\n-2288 9129 4067 696 -6754 9869 -5747 701 3344 -3426",
"output": "361744892"
},
{
"input": "10 561 439\n76639 67839 10670 -23 -18393 65114 46538 67596 86615 90480\n50690 620 -33631 -75857 75634 91321 -81662 -93668 -98557 -43621",
"output": "116776723778"
},
{
"input": "10 765 62\n-929885 -995154 254071 -370672 -435272 584846 -301610 -234118 -82557 743536\n-36327 439149 -977780 -821019 -585558 953598 -151943 140715 -311253 -383103",
"output": "6216649853365"
},
{
"input": "22 334 246\n-462653 -618002 4973 -348485 366658 192390 274752 200590 138367 779540 -661269 642587 113645 -110388 -604418 -491231 -933401 -219332 -603140 836439 167007 210226\n357638 -646669 -558432 -434313 -285851 -119233 323088 -512237 -729293 215256 39316 -984201 -209814 715016 -271932 796550 988227 -89577 67202 462973 -942079 -823339",
"output": "15389604923763"
},
{
"input": "1 1000 0\n1000000\n-1000000",
"output": "3996001000000"
},
{
"input": "1 1000 0\n1000000\n1000000",
"output": "0"
},
{
"input": "1 0 1000\n-1000000\n1000000",
"output": "3996001000000"
},
{
"input": "1 0 1000\n1000000\n1000000",
"output": "0"
},
{
"input": "1 5 7\n1\n2",
"output": "1"
},
{
"input": "2 1 3\n2 2\n2 2",
"output": "0"
},
{
"input": "3 3 0\n1 1 1\n1 1 1",
"output": "1"
},
{
"input": "1 0 6\n0\n0",
"output": "0"
},
{
"input": "2 1 1\n2 2\n0 0",
"output": "2"
},
{
"input": "3 1 4\n0 0 0\n1 5 6",
"output": "19"
},
{
"input": "1 1 2\n0\n8",
"output": "25"
},
{
"input": "2 2 0\n3 3\n3 3",
"output": "0"
}
] | 1,523,123,783
| 6,683
|
Python 3
|
WRONG_ANSWER
|
PRETESTS
| 5
| 77
| 7,065,600
|
n, k1, k2 = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
da = []
for i in range(len(A)):
da.append(abs(A[i]-B[i]))
da.sort(reverse=1)
op = k1 + k2
op2 = op
for i in range(len(A)-1):
if da[i] != da[i+1]:
pop = (i+1) * (da[i]-da[i+1])
if pop <= op:
op = op - pop
for j in range(i+1):
da[j] = da[i+1]
else:
while op > 0:
for k in range(i+1):
da[i] -= 1
op -= 1
if op2 == op:
while op > 0:
for i in range(len(da)):
da[i] -= 1
op -= 1
if op == 0:
break
if op % 2 != 0 and op != op2:
da[da.index((min(da)))] += 1
fa = da[:]
da = [x**2 for x in fa]
print(sum(da))
|
Title: Minimize the error
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the minimum possible value of error after *k*1 operations on array *A* and *k*2 operations on array *B* have been performed.
Input Specification:
The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively.
Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — array *A*.
Third line contains *n* space separated integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=106<=≤<=*b**i*<=≤<=106)— array *B*.
Output Specification:
Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*.
Demo Input:
['2 0 0\n1 2\n2 3\n', '2 1 0\n1 2\n2 2\n', '2 5 7\n3 4\n14 4\n']
Demo Output:
['2', '0', '1']
Note:
In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2.
In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we increment the first element of *A* by 1. Now, *A* = [2, 2]. The error is now *E* = (2 - 2)<sup class="upper-index">2</sup> + (2 - 2)<sup class="upper-index">2</sup> = 0. This is the minimum possible error obtainable.
In the third sample case, we can increase the first element of *A* to 8, using the all of the 5 moves available to us. Also, the first element of *B* can be reduced to 8 using the 6 of the 7 available moves. Now *A* = [8, 4] and *B* = [8, 4]. The error is now *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 4)<sup class="upper-index">2</sup> = 0, but we are still left with 1 move for array *B*. Increasing the second element of *B* to 5 using the left move, we get *B* = [8, 5] and *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 5)<sup class="upper-index">2</sup> = 1.
|
```python
n, k1, k2 = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
da = []
for i in range(len(A)):
da.append(abs(A[i]-B[i]))
da.sort(reverse=1)
op = k1 + k2
op2 = op
for i in range(len(A)-1):
if da[i] != da[i+1]:
pop = (i+1) * (da[i]-da[i+1])
if pop <= op:
op = op - pop
for j in range(i+1):
da[j] = da[i+1]
else:
while op > 0:
for k in range(i+1):
da[i] -= 1
op -= 1
if op2 == op:
while op > 0:
for i in range(len(da)):
da[i] -= 1
op -= 1
if op == 0:
break
if op % 2 != 0 and op != op2:
da[da.index((min(da)))] += 1
fa = da[:]
da = [x**2 for x in fa]
print(sum(da))
```
| 0
|
|
5
|
A
|
Chat Servers Outgoing Traffic
|
PROGRAMMING
| 1,000
|
[
"implementation"
] |
A. Chat Server's Outgoing Traffic
|
1
|
64
|
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
- Include a person to the chat ('Add' command). - Remove a person from the chat ('Remove' command). - Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command).
Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.
Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends *l* bytes to each participant of the chat, where *l* is the length of the message.
As Polycarp has no time, he is asking for your help in solving this problem.
|
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
- +<name> for 'Add' command. - -<name> for 'Remove' command. - <sender_name>:<message_text> for 'Send' command.
<name> and <sender_name> is a non-empty sequence of Latin letters and digits. <message_text> can contain letters, digits and spaces, but can't start or end with a space. <message_text> can be an empty line.
It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc.
All names are case-sensitive.
|
Print a single number — answer to the problem.
|
[
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n"
] |
[
"9\n",
"14\n"
] |
none
| 0
|
[
{
"input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate",
"output": "9"
},
{
"input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate",
"output": "14"
},
{
"input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM\nDmitry:And digits too\nDmitry:1234567890 0987654321\n-Dmitry",
"output": "224"
},
{
"input": "+Dmitry\n+Mike\n+Kate\nDmitry:",
"output": "0"
},
{
"input": "+Dmitry\nDmitry:No phrases with spaces at the beginning and at the end\n+Mike\nDmitry:spaces spaces\n-Dmitry",
"output": "86"
},
{
"input": "+XqD\n+aT537\nXqD:x6ZPjMR1DDKG2\nXqD:lLCriywPnB\n-XqD",
"output": "46"
},
{
"input": "+8UjgAJ\n8UjgAJ:02hR7UBc1tqqfL\n-8UjgAJ\n+zdi\n-zdi",
"output": "14"
},
{
"input": "+6JPKkgXDrA\n+j6JHjv70An\n+QGtsceK0zJ\n6JPKkgXDrA:o4\n+CSmwi9zDra\nQGtsceK0zJ:Zl\nQGtsceK0zJ:0\nj6JHjv70An:7\nj6JHjv70An:B\nQGtsceK0zJ:OO",
"output": "34"
},
{
"input": "+1aLNq9S7uLV\n-1aLNq9S7uLV\n+O9ykq3xDJv\n-O9ykq3xDJv\n+54Yq1xJq14F\n+0zJ5Vo0RDZ\n-54Yq1xJq14F\n-0zJ5Vo0RDZ\n+lxlH7sdolyL\n-lxlH7sdolyL",
"output": "0"
},
{
"input": "+qlHEc2AuYy\nqlHEc2AuYy:YYRwD0 edNZgpE nGfOguRWnMYpTpGUVM aXDKGXo1Gv1tHL9\nqlHEc2AuYy:yvh3GsPcImqrvoUcBNQcP6ezwpU0 xAVltaKZp94VKiNao\nqlHEc2AuYy:zuCO6Opey L eu7lTwysaSk00zjpv zrDfbt8l hpHfu\n+pErDMxgVgh\nqlHEc2AuYy:I1FLis mmQbZtd8Ui7y 1vcax6yZBMhVRdD6Ahlq7MNCw\nqlHEc2AuYy:lz MFUNJZhlqBYckHUDlNhLiEkmecRh1o0t7alXBvCRVEFVx\npErDMxgVgh:jCyMbu1dkuEj5TzbBOjyUhpfC50cL8R900Je3R KxRgAI dT\nqlHEc2AuYy:62b47eabo2hf vSUD7KioN ZHki6WB6gh3u GKv5rgwyfF\npErDMxgVgh:zD5 9 ympl4wR gy7a7eAGAn5xVdGP9FbL6hRCZAR6O4pT6zb",
"output": "615"
},
{
"input": "+adabacaba0",
"output": "0"
},
{
"input": "+acabadab\n+caba0aba",
"output": "0"
},
{
"input": "+dabaca\n-dabaca\n+aba0ab",
"output": "0"
},
{
"input": "+cab\n+abac\n-abac\n+baca",
"output": "0"
},
{
"input": "+cabadabac\n-cabadabac\n+abacaba1ab\n-abacaba1ab\n+ba0abaca",
"output": "0"
},
{
"input": "+adabacaba\n-adabacaba\n+aca\naca:caba\n-aca\n+bacaba\n-bacaba\n+aba\n-aba\n+bad",
"output": "4"
},
{
"input": "+acabadab\n-acabadab\n+aba0abacab\n+baca\n+abacaba0ab\n-baca\n-abacaba0ab\n-aba0abacab\n+cab\n-cab\n+abacabada\n-abacabada\n+badabaca\n-badabaca\n+badaba",
"output": "0"
},
{
"input": "+badabac\nbadabac:abacabad\n-badabac\n+0ab\n-0ab\n+dabacab\n-dabacab\n+a0ab\n-a0ab\n+0abaca\n-0abaca\n+dabac\n-dabac\n+abaca\n-abaca\n+bacabada\n-bacabada\n+aca\n-aca\n+abadabaca\n-abadabaca\n+acaba\n-acaba\n+abacabadab\n-abacabadab",
"output": "8"
}
] | 1,487,662,482
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 30
| 186
| 4,710,400
|
members = 0
size = 0
while 1 > 0:
try:
a = input ()
if a[0] == '+':
members = members + 1
if a[0] == '-':
members = members - 1
for i in range ( len( a ) ):
if a[i] == ':':
break
message = len(a) - i - 1
size += message * members;
except:
print( size )
break
|
Title: Chat Servers Outgoing Traffic
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
- Include a person to the chat ('Add' command). - Remove a person from the chat ('Remove' command). - Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command).
Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.
Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends *l* bytes to each participant of the chat, where *l* is the length of the message.
As Polycarp has no time, he is asking for your help in solving this problem.
Input Specification:
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
- +<name> for 'Add' command. - -<name> for 'Remove' command. - <sender_name>:<message_text> for 'Send' command.
<name> and <sender_name> is a non-empty sequence of Latin letters and digits. <message_text> can contain letters, digits and spaces, but can't start or end with a space. <message_text> can be an empty line.
It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc.
All names are case-sensitive.
Output Specification:
Print a single number — answer to the problem.
Demo Input:
['+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n', '+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n']
Demo Output:
['9\n', '14\n']
Note:
none
|
```python
members = 0
size = 0
while 1 > 0:
try:
a = input ()
if a[0] == '+':
members = members + 1
if a[0] == '-':
members = members - 1
for i in range ( len( a ) ):
if a[i] == ':':
break
message = len(a) - i - 1
size += message * members;
except:
print( size )
break
```
| 3.871905
|
80
|
A
|
Panoramix's Prediction
|
PROGRAMMING
| 800
|
[
"brute force"
] |
A. Panoramix's Prediction
|
2
|
256
|
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
|
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4.
|
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
|
[
"3 5\n",
"7 11\n",
"7 9\n"
] |
[
"YES",
"YES",
"NO"
] |
none
| 500
|
[
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
"output": "YES"
},
{
"input": "5 7",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "11 13",
"output": "YES"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "17 19",
"output": "YES"
},
{
"input": "19 23",
"output": "YES"
},
{
"input": "23 29",
"output": "YES"
},
{
"input": "29 31",
"output": "YES"
},
{
"input": "31 37",
"output": "YES"
},
{
"input": "37 41",
"output": "YES"
},
{
"input": "41 43",
"output": "YES"
},
{
"input": "43 47",
"output": "YES"
},
{
"input": "2 5",
"output": "NO"
},
{
"input": "2 7",
"output": "NO"
},
{
"input": "2 6",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
},
{
"input": "3 6",
"output": "NO"
},
{
"input": "3 7",
"output": "NO"
},
{
"input": "3 9",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 9",
"output": "NO"
},
{
"input": "5 11",
"output": "NO"
},
{
"input": "5 13",
"output": "NO"
},
{
"input": "5 15",
"output": "NO"
},
{
"input": "7 8",
"output": "NO"
},
{
"input": "7 13",
"output": "NO"
},
{
"input": "13 15",
"output": "NO"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "19 21",
"output": "NO"
},
{
"input": "13 20",
"output": "NO"
},
{
"input": "41 49",
"output": "NO"
},
{
"input": "43 49",
"output": "NO"
},
{
"input": "47 50",
"output": "NO"
},
{
"input": "47 49",
"output": "NO"
},
{
"input": "47 48",
"output": "NO"
},
{
"input": "23 25",
"output": "NO"
},
{
"input": "2 50",
"output": "NO"
},
{
"input": "31 33",
"output": "NO"
}
] | 1,655,387,652
| 2,147,483,647
|
PyPy 3-64
|
RUNTIME_ERROR
|
TESTS
| 0
| 154
| 3,379,200
|
from sympy import *
n,m = map(int, input().split())
for i in range(n+1, m+1):
if isprime(i) and i == m:
print("YES")
else:
print("NO")
|
Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
Input Specification:
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4.
Output Specification:
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
Demo Input:
['3 5\n', '7 11\n', '7 9\n']
Demo Output:
['YES', 'YES', 'NO']
Note:
none
|
```python
from sympy import *
n,m = map(int, input().split())
for i in range(n+1, m+1):
if isprime(i) and i == m:
print("YES")
else:
print("NO")
```
| -1
|
133
|
A
|
HQ9+
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
|
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
|
Output "YES", if executing the program will produce any output, and "NO" otherwise.
|
[
"Hi!\n",
"Codeforces\n"
] |
[
"YES\n",
"NO\n"
] |
In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions.
| 500
|
[
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"input": "H",
"output": "YES"
},
{
"input": "+",
"output": "NO"
},
{
"input": "~",
"output": "NO"
},
{
"input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR",
"output": "YES"
},
{
"input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC",
"output": "YES"
},
{
"input": "@F%K2=%RyL/",
"output": "NO"
},
{
"input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J",
"output": "YES"
},
{
"input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)",
"output": "YES"
},
{
"input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C",
"output": "YES"
},
{
"input": "p-UXsbd&f",
"output": "NO"
},
{
"input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_",
"output": "YES"
},
{
"input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]",
"output": "YES"
},
{
"input": "}do5RU<(w<q[\"-NR)IAH_HyiD{",
"output": "YES"
},
{
"input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8",
"output": "YES"
},
{
"input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv",
"output": "YES"
},
{
"input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`",
"output": "YES"
},
{
"input": "OKBB5z7ud81[Tn@P\"nDUd,>@",
"output": "NO"
},
{
"input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv",
"output": "YES"
},
{
"input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh",
"output": "YES"
},
{
"input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp",
"output": "NO"
},
{
"input": "!3YPv@2JQ44@)R2O_4`GO",
"output": "YES"
},
{
"input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\",
"output": "YES"
},
{
"input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L",
"output": "NO"
},
{
"input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&",
"output": "YES"
},
{
"input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}",
"output": "YES"
},
{
"input": "Uh3>ER](J",
"output": "NO"
},
{
"input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,",
"output": "YES"
},
{
"input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!",
"output": "YES"
},
{
"input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@",
"output": "YES"
},
{
"input": "'jdL(vX",
"output": "NO"
},
{
"input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5",
"output": "YES"
},
{
"input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s",
"output": "YES"
},
{
"input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]",
"output": "YES"
},
{
"input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU",
"output": "YES"
},
{
"input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->",
"output": "YES"
},
{
"input": "&ppw0._:\\p-PuWM@l}%%=",
"output": "NO"
},
{
"input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr",
"output": "YES"
},
{
"input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q",
"output": "YES"
},
{
"input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0",
"output": "YES"
},
{
"input": "VXB&r9Z)IlKOJ:??KDA",
"output": "YES"
},
{
"input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R",
"output": "YES"
},
{
"input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C",
"output": "YES"
},
{
"input": "O.&=qt(`z(",
"output": "NO"
},
{
"input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@",
"output": "YES"
},
{
"input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp",
"output": "YES"
},
{
"input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8",
"output": "YES"
},
{
"input": "!0WKT:$O",
"output": "NO"
},
{
"input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)",
"output": "YES"
},
{
"input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly",
"output": "YES"
},
{
"input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(",
"output": "NO"
},
{
"input": "Qv)X8",
"output": "YES"
},
{
"input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F",
"output": "YES"
},
{
"input": "e{}2vQ+/r@p0}cLKNe4MCk",
"output": "YES"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH",
"output": "YES"
},
{
"input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky",
"output": "YES"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky",
"output": "YES"
},
{
"input": "1H1",
"output": "YES"
},
{
"input": "+Q",
"output": "YES"
},
{
"input": "1ab",
"output": "NO"
},
{
"input": "!",
"output": "NO"
},
{
"input": "0+",
"output": "NO"
},
{
"input": "+H",
"output": "YES"
},
{
"input": "cH",
"output": "YES"
},
{
"input": "+8",
"output": "NO"
},
{
"input": "8+",
"output": "NO"
},
{
"input": "++++++++++++++++++++++++++",
"output": "NO"
},
{
"input": "(+)",
"output": "NO"
},
{
"input": "H+",
"output": "YES"
},
{
"input": "a!",
"output": "NO"
},
{
"input": "++++++++++++++",
"output": "NO"
},
{
"input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
"output": "NO"
},
{
"input": "8",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "HQ9",
"output": "YES"
},
{
"input": "+++H",
"output": "YES"
},
{
"input": "++++++++++",
"output": "NO"
},
{
"input": "HHHHHHH",
"output": "YES"
},
{
"input": "abacabaH",
"output": "YES"
},
{
"input": "+G",
"output": "NO"
}
] | 1,699,698,989
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 92
| 0
|
p = str(input())
arr = ["H","Q","9","+"]
ln = len(p)
i = 0
count = 0
while i < ln:
q = 0
while q < len(arr):
if p[i] == arr[q]:
count += 1
q += 1
i += 1
if count > 0:
print("YES")
else:
print("NO")
|
Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
Input Specification:
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output Specification:
Output "YES", if executing the program will produce any output, and "NO" otherwise.
Demo Input:
['Hi!\n', 'Codeforces\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions.
|
```python
p = str(input())
arr = ["H","Q","9","+"]
ln = len(p)
i = 0
count = 0
while i < ln:
q = 0
while q < len(arr):
if p[i] == arr[q]:
count += 1
q += 1
i += 1
if count > 0:
print("YES")
else:
print("NO")
```
| 0
|
|
608
|
A
|
Saitama Destroys Hotel
|
PROGRAMMING
| 1,000
|
[
"implementation",
"math"
] | null | null |
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0.
The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0.
|
The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*.
|
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
|
[
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] |
[
"11\n",
"79\n"
] |
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: takes 1 second.
7. Pick up passenger 1.
8. Go to floor 0: takes 2 seconds.
This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds.
| 500
|
[
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
{
"input": "1 1000\n1 1000",
"output": "1001"
},
{
"input": "100 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\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\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\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\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\n1 1",
"output": "2"
},
{
"input": "2 7\n6 3\n1 5",
"output": "9"
},
{
"input": "2 100\n99 2\n1 10",
"output": "101"
},
{
"input": "5 5\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "6"
},
{
"input": "3 7\n1 6\n5 5\n6 1",
"output": "10"
},
{
"input": "2 100\n4 100\n7 99",
"output": "106"
},
{
"input": "2 10\n9 3\n1 4",
"output": "12"
},
{
"input": "2 5\n4 4\n5 4",
"output": "9"
},
{
"input": "2 10\n9 10\n6 11",
"output": "19"
},
{
"input": "2 100\n99 9\n1 10",
"output": "108"
},
{
"input": "2 7\n3 5\n7 4",
"output": "11"
},
{
"input": "4 4\n4 6\n4 8\n1 7\n2 9",
"output": "12"
},
{
"input": "2 1000\n1 2\n1000 1",
"output": "1001"
},
{
"input": "2 20\n1 1\n2 2",
"output": "20"
},
{
"input": "2 20\n10 10\n19 9",
"output": "28"
}
] | 1,621,016,951
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 39
| 77
| 0
|
line = list(map(int,input().split()))
n = line[0]
s = line[1]
l = []
for i in range(0,n):
line = list(map(int,input().split()))
l.append(line)
l.sort(reverse=True)
t = 0
for k in l:
if k[0] < s:
t = t + s - k[0]
s = k[0]
if t < k[1]:
t = k[1]
if s != 0:
t = t + s
print(t)
|
Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0.
The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0.
Input Specification:
The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*.
Output Specification:
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
Demo Input:
['3 7\n2 1\n3 8\n5 2\n', '5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n']
Demo Output:
['11\n', '79\n']
Note:
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: takes 1 second.
7. Pick up passenger 1.
8. Go to floor 0: takes 2 seconds.
This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds.
|
```python
line = list(map(int,input().split()))
n = line[0]
s = line[1]
l = []
for i in range(0,n):
line = list(map(int,input().split()))
l.append(line)
l.sort(reverse=True)
t = 0
for k in l:
if k[0] < s:
t = t + s - k[0]
s = k[0]
if t < k[1]:
t = k[1]
if s != 0:
t = t + s
print(t)
```
| 3
|
|
556
|
A
|
Case of the Zeros and Ones
|
PROGRAMMING
| 900
|
[
"greedy"
] | null | null |
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
|
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones.
|
Output the minimum length of the string that may remain after applying the described operations several times.
|
[
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] |
[
"0\n",
"1\n",
"6\n"
] |
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
| 250
|
[
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "2\n01",
"output": "0"
},
{
"input": "2\n10",
"output": "0"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "3\n001",
"output": "1"
},
{
"input": "6\n110110",
"output": "2"
},
{
"input": "7\n0000011",
"output": "3"
},
{
"input": "6\n110010",
"output": "0"
},
{
"input": "6\n110100",
"output": "0"
},
{
"input": "3\n100",
"output": "1"
},
{
"input": "6\n010111",
"output": "2"
},
{
"input": "8\n01011100",
"output": "0"
},
{
"input": "6\n001011",
"output": "0"
},
{
"input": "7\n1110000",
"output": "1"
},
{
"input": "9\n011111101",
"output": "5"
}
] | 1,686,450,729
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 31
| 0
|
s = input.split()[1]
while '01' in s or '10' in s:
if '01' in s:
i = s.index('01')
else:
i = s.index('10')
s = s[:i] + s[i+2:]
print(len(s))
|
Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones.
Output Specification:
Output the minimum length of the string that may remain after applying the described operations several times.
Demo Input:
['4\n1100\n', '5\n01010\n', '8\n11101111\n']
Demo Output:
['0\n', '1\n', '6\n']
Note:
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
|
```python
s = input.split()[1]
while '01' in s or '10' in s:
if '01' in s:
i = s.index('01')
else:
i = s.index('10')
s = s[:i] + s[i+2:]
print(len(s))
```
| -1
|
|
940
|
A
|
Points on the line
|
PROGRAMMING
| 1,200
|
[
"brute force",
"greedy",
"sortings"
] | null | null |
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
Diameter of multiset consisting of one point is 0.
You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*?
|
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points.
|
Output a single integer — the minimum number of points you have to remove.
|
[
"3 1\n2 1 4\n",
"3 0\n7 7 7\n",
"6 3\n1 3 4 6 9 10\n"
] |
[
"1\n",
"0\n",
"3\n"
] |
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.
| 500
|
[
{
"input": "3 1\n2 1 4",
"output": "1"
},
{
"input": "3 0\n7 7 7",
"output": "0"
},
{
"input": "6 3\n1 3 4 6 9 10",
"output": "3"
},
{
"input": "11 5\n10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "1 100\n1",
"output": "0"
},
{
"input": "100 10\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "84"
},
{
"input": "100 70\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "27"
},
{
"input": "1 10\n25",
"output": "0"
},
{
"input": "70 80\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70",
"output": "0"
},
{
"input": "3 1\n25 26 27",
"output": "1"
},
{
"input": "100 5\n51 56 52 60 52 53 52 60 56 54 55 50 53 51 57 53 52 54 54 52 51 55 50 56 60 51 58 50 60 59 50 54 60 55 55 57 54 59 59 55 55 52 56 57 59 54 53 57 52 50 50 55 59 54 54 56 51 58 52 51 56 56 58 56 54 54 57 52 51 58 56 57 54 59 58 53 50 52 50 60 57 51 54 59 54 54 52 55 53 55 51 53 52 54 51 56 55 53 58 56",
"output": "34"
},
{
"input": "100 11\n44 89 57 64 94 96 73 96 55 52 91 73 73 93 51 62 63 85 43 75 60 78 98 55 80 84 65 75 61 88 62 71 53 57 94 85 60 96 66 96 61 72 97 64 51 44 63 82 67 86 60 57 74 85 57 79 61 94 86 78 84 56 60 75 91 91 92 62 89 85 79 57 76 97 65 56 46 78 51 69 50 52 85 80 76 71 81 51 90 71 77 60 63 62 84 59 79 84 69 81",
"output": "70"
},
{
"input": "100 0\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "96"
},
{
"input": "100 100\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "0"
},
{
"input": "76 32\n50 53 69 58 55 39 40 42 40 55 58 73 55 72 75 44 45 55 46 60 60 42 41 64 77 39 68 51 61 49 38 41 56 57 64 43 78 36 39 63 40 66 52 76 39 68 39 73 40 68 54 60 35 67 69 52 58 52 38 63 69 38 69 60 73 64 65 41 59 55 37 57 40 34 35 35",
"output": "13"
},
{
"input": "100 1\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "93"
},
{
"input": "100 5\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "89"
},
{
"input": "98 64\n2 29 36 55 58 15 25 33 7 16 61 1 4 24 63 26 36 16 16 3 57 39 56 7 11 24 20 12 22 10 56 5 11 39 61 52 27 54 21 6 61 36 40 52 54 5 15 52 58 23 45 39 65 16 27 40 13 64 47 24 51 29 9 18 49 49 8 47 2 64 7 63 49 10 20 26 34 3 45 66 8 46 16 32 16 38 3 6 15 17 35 48 36 5 57 29 61 15",
"output": "1"
},
{
"input": "100 56\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "43"
},
{
"input": "100 0\n14 13 14 13 14 13 13 13 13 14 13 13 14 14 13 14 14 14 14 13 13 13 14 13 13 14 14 14 14 14 14 13 13 13 13 14 13 14 13 14 13 14 14 14 14 13 13 14 14 13 13 13 13 14 13 14 13 14 13 14 13 13 13 14 13 13 14 13 14 14 13 13 13 14 14 14 14 13 13 14 14 14 14 14 14 14 13 14 13 13 13 14 14 13 13 13 13 13 14 14",
"output": "50"
},
{
"input": "100 0\n14 17 18 22 19 18 19 21 19 19 22 22 19 21 24 23 24 19 25 24 24 21 20 13 26 18 17 15 25 13 17 20 20 21 13 22 27 15 18 27 19 15 16 25 18 17 18 22 19 17 18 24 14 16 18 16 22 16 17 27 18 17 18 24 22 13 14 20 23 19 16 21 19 13 14 14 25 15 27 24 26 22 16 20 16 14 21 27 15 23 23 24 27 14 24 17 19 24 15 27",
"output": "89"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "1 100\n22",
"output": "0"
},
{
"input": "1 0\n22",
"output": "0"
},
{
"input": "1 99\n99",
"output": "0"
},
{
"input": "1 5\n6",
"output": "0"
},
{
"input": "3 1\n10 20 30",
"output": "2"
},
{
"input": "3 0\n1 2 3",
"output": "2"
},
{
"input": "3 2\n1 50 99",
"output": "2"
},
{
"input": "7 4\n1 3 4 9 10 11 12",
"output": "3"
},
{
"input": "2 5\n67 23",
"output": "1"
},
{
"input": "4 2\n1 4 7 9",
"output": "2"
},
{
"input": "2 0\n1 2",
"output": "1"
},
{
"input": "8 1\n3 3 3 5 5 5 5 5",
"output": "3"
},
{
"input": "5 1\n3 5 5 5 6",
"output": "1"
}
] | 1,520,452,267
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 5
| 46
| 5,632,000
|
a,b=input().split()
a=int(a)
b=int(b)
ar=[int(x) for x in input().split()]
ar.sort()
c=0
for i in ar[::-1]:
if(i-ar[0]>b):
c=c+1
else:
break
print(c)
|
Title: Points on the line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
Diameter of multiset consisting of one point is 0.
You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*?
Input Specification:
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points.
Output Specification:
Output a single integer — the minimum number of points you have to remove.
Demo Input:
['3 1\n2 1 4\n', '3 0\n7 7 7\n', '6 3\n1 3 4 6 9 10\n']
Demo Output:
['1\n', '0\n', '3\n']
Note:
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.
|
```python
a,b=input().split()
a=int(a)
b=int(b)
ar=[int(x) for x in input().split()]
ar.sort()
c=0
for i in ar[::-1]:
if(i-ar[0]>b):
c=c+1
else:
break
print(c)
```
| 0
|
|
80
|
A
|
Panoramix's Prediction
|
PROGRAMMING
| 800
|
[
"brute force"
] |
A. Panoramix's Prediction
|
2
|
256
|
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
|
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4.
|
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
|
[
"3 5\n",
"7 11\n",
"7 9\n"
] |
[
"YES",
"YES",
"NO"
] |
none
| 500
|
[
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
"output": "YES"
},
{
"input": "5 7",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "11 13",
"output": "YES"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "17 19",
"output": "YES"
},
{
"input": "19 23",
"output": "YES"
},
{
"input": "23 29",
"output": "YES"
},
{
"input": "29 31",
"output": "YES"
},
{
"input": "31 37",
"output": "YES"
},
{
"input": "37 41",
"output": "YES"
},
{
"input": "41 43",
"output": "YES"
},
{
"input": "43 47",
"output": "YES"
},
{
"input": "2 5",
"output": "NO"
},
{
"input": "2 7",
"output": "NO"
},
{
"input": "2 6",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
},
{
"input": "3 6",
"output": "NO"
},
{
"input": "3 7",
"output": "NO"
},
{
"input": "3 9",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 9",
"output": "NO"
},
{
"input": "5 11",
"output": "NO"
},
{
"input": "5 13",
"output": "NO"
},
{
"input": "5 15",
"output": "NO"
},
{
"input": "7 8",
"output": "NO"
},
{
"input": "7 13",
"output": "NO"
},
{
"input": "13 15",
"output": "NO"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "19 21",
"output": "NO"
},
{
"input": "13 20",
"output": "NO"
},
{
"input": "41 49",
"output": "NO"
},
{
"input": "43 49",
"output": "NO"
},
{
"input": "47 50",
"output": "NO"
},
{
"input": "47 49",
"output": "NO"
},
{
"input": "47 48",
"output": "NO"
},
{
"input": "23 25",
"output": "NO"
},
{
"input": "2 50",
"output": "NO"
},
{
"input": "31 33",
"output": "NO"
}
] | 1,659,892,466
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 92
| 0
|
import math
n,m= map(int,input().split())
def isPrime(n):
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
return False
return True
n+=2
while not isPrime(n) and n<m:
n = n+2
if n==m:
print('YES')
else:
print('NO')
|
Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
Input Specification:
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4.
Output Specification:
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
Demo Input:
['3 5\n', '7 11\n', '7 9\n']
Demo Output:
['YES', 'YES', 'NO']
Note:
none
|
```python
import math
n,m= map(int,input().split())
def isPrime(n):
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
return False
return True
n+=2
while not isPrime(n) and n<m:
n = n+2
if n==m:
print('YES')
else:
print('NO')
```
| 0
|
992
|
A
|
Nastya and an Array
|
PROGRAMMING
| 800
|
[
"implementation",
"sortings"
] | null | null |
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. - When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array.
|
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
|
[
"5\n1 1 1 1 1\n",
"3\n2 0 -1\n",
"4\n5 -6 -5 1\n"
] |
[
"1\n",
"2\n",
"4\n"
] |
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element.
| 500
|
[
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "3\n2 0 -1",
"output": "2"
},
{
"input": "4\n5 -6 -5 1",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n21794 -79194",
"output": "2"
},
{
"input": "3\n-63526 95085 -5239",
"output": "3"
},
{
"input": "3\n0 53372 -20572",
"output": "2"
},
{
"input": "13\n-2075 -32242 27034 -37618 -96962 82203 64846 48249 -71761 28908 -21222 -61370 46899",
"output": "13"
},
{
"input": "5\n806 0 1308 1954 683",
"output": "4"
},
{
"input": "8\n-26 0 -249 -289 -126 -206 288 -11",
"output": "7"
},
{
"input": "10\n2 2 2 1 2 -1 0 2 -1 1",
"output": "3"
},
{
"input": "1\n8",
"output": "1"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "5\n2 0 -1 0 0",
"output": "2"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "2\n1 0",
"output": "1"
},
{
"input": "2\n-1 0",
"output": "1"
},
{
"input": "4\n0 0 0 0",
"output": "0"
},
{
"input": "8\n10 9 -1 0 0 3 2 3",
"output": "5"
},
{
"input": "5\n5 0 1 2 3",
"output": "4"
},
{
"input": "3\n1 1 0",
"output": "1"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "5\n1 2 0 0 0",
"output": "2"
},
{
"input": "5\n1 0 0 0 0",
"output": "1"
},
{
"input": "5\n4 5 6 0 0",
"output": "3"
},
{
"input": "4\n-1 0 0 1",
"output": "2"
},
{
"input": "5\n3 0 0 4 5",
"output": "3"
},
{
"input": "3\n0 0 2",
"output": "1"
},
{
"input": "3\n1 0 0",
"output": "1"
},
{
"input": "4\n0 0 0 4",
"output": "1"
},
{
"input": "5\n-1 0 0 0 0",
"output": "1"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "10\n0 0 0 0 0 1 2 3 0 0",
"output": "3"
},
{
"input": "4\n0 1 2 3",
"output": "3"
},
{
"input": "3\n0 1 2",
"output": "2"
},
{
"input": "4\n2 0 0 -1",
"output": "2"
}
] | 1,530,278,598
| 2,298
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 1
| 124
| 0
|
n = int(input())
l = map(int, input().split())
s = set(l)
l = len(s)
print(l)
|
Title: Nastya and an Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. - When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array.
Output Specification:
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
Demo Input:
['5\n1 1 1 1 1\n', '3\n2 0 -1\n', '4\n5 -6 -5 1\n']
Demo Output:
['1\n', '2\n', '4\n']
Note:
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element.
|
```python
n = int(input())
l = map(int, input().split())
s = set(l)
l = len(s)
print(l)
```
| 0
|
|
4
|
A
|
Watermelon
|
PROGRAMMING
| 800
|
[
"brute force",
"math"
] |
A. Watermelon
|
1
|
64
|
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
|
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
|
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
|
[
"8\n"
] |
[
"YES\n"
] |
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
| 0
|
[
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 1,689,410,656
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 7
| 92
| 0
|
n = int(input())
if n%2==0 and (n/2)%2==0:
print("YES")
else:
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())
if n%2==0 and (n/2)%2==0:
print("YES")
else:
print("NO")
```
| 0
|
117
|
B
|
Very Interesting Game
|
PROGRAMMING
| 1,800
|
[
"brute force",
"number theory"
] | null | null |
In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string *s*1, consisting of exactly nine digits and representing a number that does not exceed *a*. After that second player looks at *s*1 and writes a string *s*2, consisting of exactly nine digits and representing a number that does not exceed *b*. Here *a* and *b* are some given constants, *s*1 and *s*2 are chosen by the players. The strings are allowed to contain leading zeroes.
If a number obtained by the concatenation (joining together) of strings *s*1 and *s*2 is divisible by *mod*, then the second player wins. Otherwise the first player wins. You are given numbers *a*, *b*, *mod*. Your task is to determine who wins if both players play in the optimal manner. If the first player wins, you are also required to find the lexicographically minimum winning move.
|
The first line contains three integers *a*, *b*, *mod* (0<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*mod*<=≤<=107).
|
If the first player wins, print "1" and the lexicographically minimum string *s*1 he has to write to win. If the second player wins, print the single number "2".
|
[
"1 10 7\n",
"4 0 9\n"
] |
[
"2\n",
"1 000000001\n"
] |
The lexical comparison of strings is performed by the < operator in modern programming languages. String *x* is lexicographically less than string *y* if exists such *i* (1 ≤ *i* ≤ 9), that *x*<sub class="lower-index">*i*</sub> < *y*<sub class="lower-index">*i*</sub>, and for any *j* (1 ≤ *j* < *i*) *x*<sub class="lower-index">*j*</sub> = *y*<sub class="lower-index">*j*</sub>. These strings always have length 9.
| 1,000
|
[
{
"input": "1 10 7",
"output": "2"
},
{
"input": "4 0 9",
"output": "1 000000001"
},
{
"input": "10 7 8",
"output": "2"
},
{
"input": "6 4 10",
"output": "2"
},
{
"input": "4 1 4",
"output": "2"
},
{
"input": "4 7 9",
"output": "1 000000001"
},
{
"input": "13 4 51",
"output": "1 000000001"
},
{
"input": "0 0 1",
"output": "2"
},
{
"input": "1 0 1",
"output": "2"
},
{
"input": "2 1 3",
"output": "1 000000001"
},
{
"input": "0 2 2",
"output": "2"
},
{
"input": "2 3 1",
"output": "2"
},
{
"input": "3 0 3",
"output": "1 000000001"
},
{
"input": "1 1 2",
"output": "2"
},
{
"input": "3 2 1",
"output": "2"
},
{
"input": "0 3 3",
"output": "2"
},
{
"input": "4 0 13",
"output": "1 000000001"
},
{
"input": "1 2 13",
"output": "2"
},
{
"input": "4 3 12",
"output": "1 000000001"
},
{
"input": "1 2 11",
"output": "2"
},
{
"input": "4 3 12",
"output": "1 000000001"
},
{
"input": "815 216 182",
"output": "2"
},
{
"input": "218 550 593",
"output": "1 000000011"
},
{
"input": "116482865 344094604 3271060",
"output": "2"
},
{
"input": "19749161 751031022 646204",
"output": "2"
},
{
"input": "70499104 10483793 5504995",
"output": "2"
},
{
"input": "1960930 562910 606828",
"output": "1 000000011"
},
{
"input": "8270979 4785512 9669629",
"output": "1 000000001"
},
{
"input": "9323791 4748006 5840080",
"output": "1 000000005"
},
{
"input": "972037745 4602117 5090186",
"output": "1 000000011"
},
{
"input": "585173560 4799128 5611727",
"output": "1 000000036"
},
{
"input": "22033548 813958 4874712",
"output": "1 000000001"
},
{
"input": "702034015 6007275 9777625",
"output": "1 000000001"
},
{
"input": "218556 828183 7799410",
"output": "1 000000001"
},
{
"input": "1167900 2709798 6800151",
"output": "1 000000001"
},
{
"input": "7004769 3114686 4659684",
"output": "1 000000002"
},
{
"input": "1000000000 1000000000 10000000",
"output": "2"
},
{
"input": "3631 1628 367377",
"output": "1 000000009"
},
{
"input": "3966 5002 273075",
"output": "1 000000008"
},
{
"input": "2388 2896 73888",
"output": "1 000000016"
},
{
"input": "0 0 1",
"output": "2"
},
{
"input": "1 0 1",
"output": "2"
},
{
"input": "0 1 1",
"output": "2"
},
{
"input": "1 1 1",
"output": "2"
},
{
"input": "1000000000 0 1",
"output": "2"
},
{
"input": "0 1000000000 1",
"output": "2"
},
{
"input": "1000000000 1000000000 1",
"output": "2"
},
{
"input": "1000000000 0 10000000",
"output": "2"
},
{
"input": "0 1000000000 10000000",
"output": "2"
},
{
"input": "0 0 10000000",
"output": "2"
},
{
"input": "0 999999999 10000000",
"output": "2"
},
{
"input": "999999999 0 10000000",
"output": "2"
},
{
"input": "999999999 999999999 10000000",
"output": "2"
},
{
"input": "999999999 1000000000 10000000",
"output": "2"
},
{
"input": "1000000000 999999999 10000000",
"output": "2"
},
{
"input": "1000000000 10000 10000000",
"output": "2"
},
{
"input": "1 1 1337",
"output": "1 000000001"
},
{
"input": "576694 1234562 1234567",
"output": "2"
},
{
"input": "12350 12000 12345",
"output": "1 000000011"
},
{
"input": "576695 1234562 1234567",
"output": "1 000576695"
},
{
"input": "0 0 11",
"output": "2"
},
{
"input": "999999999 999999999 9009009",
"output": "2"
},
{
"input": "1 0 7",
"output": "1 000000001"
},
{
"input": "1 1 7",
"output": "2"
},
{
"input": "1000000000 9999991 10000000",
"output": "2"
},
{
"input": "9902593 9902584 9902593",
"output": "1 002490619"
},
{
"input": "10000000 9999977 9999979",
"output": "1 009909503"
},
{
"input": "1000000000 1000000000 9999999",
"output": "2"
},
{
"input": "11 9 11",
"output": "1 000000010"
},
{
"input": "0 7 13",
"output": "2"
},
{
"input": "1 0 3",
"output": "1 000000001"
},
{
"input": "100 2 3",
"output": "2"
},
{
"input": "2 7 13",
"output": "2"
},
{
"input": "1 0 9",
"output": "1 000000001"
},
{
"input": "1000000000 9999995 10000000",
"output": "2"
},
{
"input": "1000000000 25 30",
"output": "2"
},
{
"input": "243 1001 1003",
"output": "2"
},
{
"input": "9 9 11",
"output": "2"
},
{
"input": "0 1 11",
"output": "2"
},
{
"input": "4 4 7",
"output": "2"
},
{
"input": "1000000000 1 10",
"output": "2"
},
{
"input": "1 0 11",
"output": "1 000000001"
},
{
"input": "0 0 11",
"output": "2"
},
{
"input": "0 0 3",
"output": "2"
},
{
"input": "10 12000 12345",
"output": "2"
},
{
"input": "1000000000 0 2",
"output": "2"
},
{
"input": "0 1 3",
"output": "2"
},
{
"input": "3 1 7",
"output": "1 000000002"
},
{
"input": "1000000000 2 1000000",
"output": "2"
},
{
"input": "23 0 23",
"output": "1 000000001"
},
{
"input": "123456789 1234561 1234567",
"output": "1 000549636"
},
{
"input": "11 10 13",
"output": "1 000000011"
},
{
"input": "138 11711 11829",
"output": "2"
},
{
"input": "1000000000 100050 1000001",
"output": "1 000000101"
}
] | 1,652,507,383
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 5
| 122
| 0
|
a, b, mod = list(map(int, input().split()))
for i in range(mod):
rem = (i * pow(10, 9)) % mod
if rem > b:
print(1, str(i).zfill(9))
break
else:
print(2)
|
Title: Very Interesting Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string *s*1, consisting of exactly nine digits and representing a number that does not exceed *a*. After that second player looks at *s*1 and writes a string *s*2, consisting of exactly nine digits and representing a number that does not exceed *b*. Here *a* and *b* are some given constants, *s*1 and *s*2 are chosen by the players. The strings are allowed to contain leading zeroes.
If a number obtained by the concatenation (joining together) of strings *s*1 and *s*2 is divisible by *mod*, then the second player wins. Otherwise the first player wins. You are given numbers *a*, *b*, *mod*. Your task is to determine who wins if both players play in the optimal manner. If the first player wins, you are also required to find the lexicographically minimum winning move.
Input Specification:
The first line contains three integers *a*, *b*, *mod* (0<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*mod*<=≤<=107).
Output Specification:
If the first player wins, print "1" and the lexicographically minimum string *s*1 he has to write to win. If the second player wins, print the single number "2".
Demo Input:
['1 10 7\n', '4 0 9\n']
Demo Output:
['2\n', '1 000000001\n']
Note:
The lexical comparison of strings is performed by the < operator in modern programming languages. String *x* is lexicographically less than string *y* if exists such *i* (1 ≤ *i* ≤ 9), that *x*<sub class="lower-index">*i*</sub> < *y*<sub class="lower-index">*i*</sub>, and for any *j* (1 ≤ *j* < *i*) *x*<sub class="lower-index">*j*</sub> = *y*<sub class="lower-index">*j*</sub>. These strings always have length 9.
|
```python
a, b, mod = list(map(int, input().split()))
for i in range(mod):
rem = (i * pow(10, 9)) % mod
if rem > b:
print(1, str(i).zfill(9))
break
else:
print(2)
```
| 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,727,265
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 34
| 92
| 0
|
n = input()
count = 0
output = 'YES'
for index in range(len(n)):
if (int(n[index]) == 7 ) | (int(n[index]) == 4 ):
count += 1
if (count == 7 ) | (count==4 ):
output = 'YES'
else :
output = 'NO'
print(output)
|
Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
Input Specification:
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output Specification:
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
Demo Input:
['40047\n', '7747774\n', '1000000000000000000\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO".
|
```python
n = input()
count = 0
output = 'YES'
for index in range(len(n)):
if (int(n[index]) == 7 ) | (int(n[index]) == 4 ):
count += 1
if (count == 7 ) | (count==4 ):
output = 'YES'
else :
output = 'NO'
print(output)
```
| 3.977
|
577
|
A
|
Multiplication Table
|
PROGRAMMING
| 1,000
|
[
"implementation",
"number theory"
] | null | null |
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*.
|
The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table.
|
Print a single number: the number of times *x* occurs in the table.
|
[
"10 5\n",
"6 12\n",
"5 13\n"
] |
[
"2\n",
"4\n",
"0\n"
] |
A table for the second sample test is given below. The occurrences of number 12 are marked bold.
| 500
|
[
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 1000000000",
"output": "0"
},
{
"input": "100000 1000000000",
"output": "16"
},
{
"input": "100000 362880",
"output": "154"
},
{
"input": "1 4",
"output": "0"
},
{
"input": "9 12",
"output": "4"
},
{
"input": "10 123",
"output": "0"
},
{
"input": "9551 975275379",
"output": "0"
},
{
"input": "17286 948615687",
"output": "0"
},
{
"input": "58942 936593001",
"output": "0"
},
{
"input": "50000 989460910",
"output": "4"
},
{
"input": "22741 989460910",
"output": "0"
},
{
"input": "22740 989460910",
"output": "0"
},
{
"input": "100000 989460910",
"output": "4"
},
{
"input": "100000 98280",
"output": "128"
},
{
"input": "100000 997920",
"output": "222"
},
{
"input": "100000 720720",
"output": "226"
},
{
"input": "100000 2162160",
"output": "282"
},
{
"input": "100000 4324320",
"output": "320"
},
{
"input": "100000 8648640",
"output": "348"
},
{
"input": "100000 183783600",
"output": "438"
},
{
"input": "100000 551350800",
"output": "392"
},
{
"input": "40000 551350800",
"output": "150"
},
{
"input": "20000 400000000",
"output": "1"
},
{
"input": "19999 400000000",
"output": "0"
},
{
"input": "19999 399960001",
"output": "1"
},
{
"input": "31621 999887641",
"output": "1"
},
{
"input": "31622 999887641",
"output": "1"
},
{
"input": "31620 999887641",
"output": "0"
},
{
"input": "100000 999887641",
"output": "3"
},
{
"input": "100000 25",
"output": "3"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "100000 3628800",
"output": "220"
},
{
"input": "100000 39916800",
"output": "328"
},
{
"input": "100000 479001600",
"output": "254"
},
{
"input": "4 9",
"output": "1"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "20 100",
"output": "3"
},
{
"input": "10 3",
"output": "2"
},
{
"input": "4 4",
"output": "3"
},
{
"input": "2 4",
"output": "1"
},
{
"input": "89874 1",
"output": "1"
}
] | 1,666,938,729
| 2,147,483,647
|
PyPy 3-64
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 5
| 1,000
| 1,638,400
|
n, x = map(int, input().split())
total = 0
for i in range(1, n + 1):
for j in range(1, n + 1):
if i * j == x:
total += 1
else:
total += 0
print(total)
|
Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*.
Input Specification:
The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table.
Output Specification:
Print a single number: the number of times *x* occurs in the table.
Demo Input:
['10 5\n', '6 12\n', '5 13\n']
Demo Output:
['2\n', '4\n', '0\n']
Note:
A table for the second sample test is given below. The occurrences of number 12 are marked bold.
|
```python
n, x = map(int, input().split())
total = 0
for i in range(1, n + 1):
for j in range(1, n + 1):
if i * j == x:
total += 1
else:
total += 0
print(total)
```
| 0
|
|
242
|
B
|
Big Segment
|
PROGRAMMING
| 1,100
|
[
"implementation",
"sortings"
] | null | null |
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.
Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments coincide.
|
Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input.
|
[
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] |
[
"-1\n",
"3\n"
] |
none
| 1,000
|
[
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 7\n4 7\n2 8",
"output": "-1"
},
{
"input": "3\n2 5\n3 4\n2 3",
"output": "1"
},
{
"input": "16\n15 15\n8 12\n6 9\n15 16\n8 14\n3 12\n7 19\n9 13\n5 16\n9 17\n10 15\n9 14\n9 9\n18 19\n5 15\n6 19",
"output": "-1"
},
{
"input": "9\n1 10\n7 8\n6 7\n1 4\n5 9\n2 8\n3 10\n1 1\n2 3",
"output": "1"
},
{
"input": "1\n1 100000",
"output": "1"
},
{
"input": "6\n2 2\n3 3\n3 5\n4 5\n1 1\n1 5",
"output": "6"
},
{
"input": "33\n2 18\n4 14\n2 16\n10 12\n4 6\n9 17\n2 8\n4 12\n8 20\n1 10\n11 14\n11 17\n8 15\n3 16\n3 4\n6 9\n6 19\n4 17\n17 19\n6 16\n3 12\n1 7\n6 20\n8 16\n12 19\n1 3\n12 18\n6 11\n7 20\n16 18\n4 15\n3 15\n15 19",
"output": "-1"
},
{
"input": "34\n3 8\n5 9\n2 9\n1 4\n3 7\n3 3\n8 9\n6 10\n4 7\n6 7\n5 8\n5 10\n1 5\n8 8\n2 5\n3 5\n7 7\n2 8\n4 5\n1 1\n7 9\n5 6\n2 3\n1 2\n2 4\n8 10\n7 8\n1 3\n4 8\n9 10\n1 7\n10 10\n2 2\n1 8",
"output": "-1"
},
{
"input": "55\n3 4\n6 8\n9 10\n3 9\n9 9\n2 5\n4 8\n3 8\n8 10\n1 1\n4 9\n10 10\n6 6\n8 8\n1 8\n5 5\n4 5\n5 9\n2 2\n3 10\n4 6\n3 6\n1 6\n1 7\n6 10\n2 6\n3 7\n2 4\n4 4\n5 10\n1 4\n2 9\n1 3\n7 9\n7 8\n1 9\n1 10\n2 8\n8 9\n6 7\n1 2\n6 9\n7 7\n4 7\n3 3\n2 7\n4 10\n7 10\n2 3\n2 10\n5 7\n3 5\n5 8\n1 5\n5 6",
"output": "37"
},
{
"input": "1\n999999999 1000000000",
"output": "1"
},
{
"input": "3\n1 20\n2 22\n3 18",
"output": "-1"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "2\n100001 100008\n100005 100006",
"output": "1"
},
{
"input": "1\n1000000 10000000",
"output": "1"
},
{
"input": "3\n3 6\n2 4\n1 5",
"output": "-1"
},
{
"input": "2\n3 5\n1 2",
"output": "-1"
}
] | 1,666,331,750
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 45
| 746
| 9,625,600
|
o = []
q = range(int(input()) - 1, -1, -1)
for _ in q:
o.append(sorted([int(i) for i in input().split()]))
for i in q:
for x in q:
if o[i][0] > o[x][0] or o[x][1] > o[i][1]:
break
else:
print(i + 1)
break
else:
print(-1)
|
Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.
Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments coincide.
Output Specification:
Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n']
Demo Output:
['-1\n', '3\n']
Note:
none
|
```python
o = []
q = range(int(input()) - 1, -1, -1)
for _ in q:
o.append(sorted([int(i) for i in input().split()]))
for i in q:
for x in q:
if o[i][0] > o[x][0] or o[x][1] > o[i][1]:
break
else:
print(i + 1)
break
else:
print(-1)
```
| 3
|
|
433
|
A
|
Kitahara Haruki's Gift
|
PROGRAMMING
| 1,100
|
[
"brute force",
"implementation"
] | null | null |
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
|
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple.
|
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
|
[
"3\n100 200 100\n",
"4\n100 100 100 200\n"
] |
[
"YES\n",
"NO\n"
] |
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
| 500
|
[
{
"input": "3\n100 200 100",
"output": "YES"
},
{
"input": "4\n100 100 100 200",
"output": "NO"
},
{
"input": "1\n100",
"output": "NO"
},
{
"input": "1\n200",
"output": "NO"
},
{
"input": "2\n100 100",
"output": "YES"
},
{
"input": "2\n200 200",
"output": "YES"
},
{
"input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "YES"
},
{
"input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "52\n200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 100 200 100 200 200 200 100 200 200",
"output": "YES"
},
{
"input": "2\n100 200",
"output": "NO"
},
{
"input": "2\n200 100",
"output": "NO"
},
{
"input": "3\n100 100 100",
"output": "NO"
},
{
"input": "3\n200 200 200",
"output": "NO"
},
{
"input": "3\n200 100 200",
"output": "NO"
},
{
"input": "4\n100 100 100 100",
"output": "YES"
},
{
"input": "4\n200 200 200 200",
"output": "YES"
},
{
"input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "YES"
},
{
"input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"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": "YES"
},
{
"input": "100\n100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "NO"
},
{
"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 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "YES"
},
{
"input": "100\n100 100 100 100 100 100 100 100 200 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "NO"
},
{
"input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "YES"
},
{
"input": "99\n200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "99\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",
"output": "NO"
},
{
"input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "YES"
},
{
"input": "99\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 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 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": "NO"
},
{
"input": "100\n100 100 200 100 100 200 200 200 200 100 200 100 100 100 200 100 100 100 100 200 100 100 100 100 100 100 200 100 100 200 200 100 100 100 200 200 200 100 200 200 100 200 100 100 200 100 200 200 100 200 200 100 100 200 200 100 200 200 100 100 200 100 200 100 200 200 200 200 200 100 200 200 200 200 200 200 100 100 200 200 200 100 100 100 200 100 100 200 100 100 100 200 200 100 100 200 200 200 200 100",
"output": "YES"
},
{
"input": "100\n100 100 200 200 100 200 100 100 100 100 100 100 200 100 200 200 200 100 100 200 200 200 200 200 100 200 100 200 100 100 100 200 100 100 200 100 200 100 100 100 200 200 100 100 100 200 200 200 200 200 100 200 200 100 100 100 100 200 100 100 200 100 100 100 100 200 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 200 100 200 200 100 200 100 200 200 200 200 200 200 100 100 100 200 200 100",
"output": "NO"
},
{
"input": "100\n100 200 100 100 200 200 200 200 100 200 200 200 200 200 200 200 200 200 100 100 100 200 200 200 200 200 100 200 200 200 200 100 200 200 100 100 200 100 100 100 200 100 100 100 200 100 200 100 200 200 200 100 100 200 100 200 100 200 100 100 100 200 100 200 100 100 100 100 200 200 200 200 100 200 200 100 200 100 100 100 200 100 100 100 100 100 200 100 100 100 200 200 200 100 200 100 100 100 200 200",
"output": "YES"
},
{
"input": "99\n100 200 200 200 100 200 100 200 200 100 100 100 100 200 100 100 200 100 200 100 100 200 100 100 200 200 100 100 100 100 200 200 200 200 200 100 100 200 200 100 100 100 100 200 200 100 100 100 100 100 200 200 200 100 100 100 200 200 200 100 200 100 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 100 200 100 200 200 200 200 100 200 100 100 100 100 100 100 100 100 100",
"output": "YES"
},
{
"input": "99\n100 200 100 100 100 100 200 200 100 200 100 100 200 100 100 100 100 100 100 200 100 100 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 200 200 200 200 200 200 200 100 200 100 200 100 200 100 200 100 100 200 200 200 100 200 200 200 200 100 200 100 200 200 200 200 100 200 100 200 200 100 200 200 200 200 200 100 100 200 100 100 100 100 200 200 200 100 100 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "99\n200 100 100 100 200 200 200 100 100 100 100 100 100 100 100 100 200 200 100 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 100 100 100 200 200 200 200 100 200 200 200 100 100 100 200 200 200 100 200 100 200 100 100 100 200 100 200 200 100 200 200 200 100 100 100 200 200 200 100 200 200 200 100 100 100 200 100 200 100 100 100 200 200",
"output": "YES"
},
{
"input": "56\n100 200 200 200 200 200 100 200 100 100 200 100 100 100 100 100 200 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 100 100 100 100 200 100 200 100 200 200 200 100 100 200 200 200 200 200 200 200 200 200 200 100",
"output": "YES"
},
{
"input": "72\n200 100 200 200 200 100 100 200 200 100 100 100 100 200 100 200 100 100 100 100 200 100 200 100 100 200 100 100 200 100 200 100 100 200 100 200 100 100 200 200 200 200 200 100 100 200 200 200 200 100 100 100 200 200 100 100 100 100 100 200 100 100 200 100 100 200 200 100 100 200 100 200",
"output": "YES"
},
{
"input": "32\n200 200 200 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200",
"output": "YES"
},
{
"input": "48\n200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "60\n100 100 200 200 100 200 100 200 100 100 100 100 100 100 200 100 100 100 200 100 200 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100",
"output": "YES"
},
{
"input": "24\n200 200 100 100 200 100 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 100",
"output": "YES"
},
{
"input": "40\n100 100 200 200 200 200 100 100 100 200 100 100 200 200 100 100 100 100 100 200 100 200 200 100 200 200 200 100 100 100 100 100 200 200 100 200 100 100 200 100",
"output": "NO"
},
{
"input": "5\n200 200 200 200 200",
"output": "NO"
},
{
"input": "9\n100 100 100 200 100 100 200 100 200",
"output": "YES"
},
{
"input": "1\n200",
"output": "NO"
},
{
"input": "7\n200 200 200 100 200 200 200",
"output": "NO"
},
{
"input": "4\n100 100 200 200",
"output": "YES"
},
{
"input": "6\n100 100 100 200 200 200",
"output": "NO"
},
{
"input": "4\n200 100 100 200",
"output": "YES"
},
{
"input": "5\n100 100 100 100 200",
"output": "YES"
}
] | 1,692,276,923
| 2,147,483,647
|
PyPy 3-64
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 3
| 1,000
| 1,433,600
|
import sys
from os import path
from math import gcd,floor,sqrt,log,ceil
from bisect import bisect_left, bisect_right
import heapq
############ ---- Input Functions ---- ####################
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def inst():
return(list(map(str,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
def inmatrix(n,m):
arr=[]
for i in range(n):
temp=inlt()
arr.append(temp)
return arr
############################################################
def cuberoot(x):
if 0<=x: return x**(1./2.)
return -(-x)**(1./2.)
def is_anagram(str1, str2):
return sorted(str1) == sorted(str2)
############################################################
mod=1000000007
############################################################
if(path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
sys.stderr = open("error.txt", "w")
else:
input = sys.stdin.readline
###########################################################
def solve():
n=inp()
a=inlt()
s=sum(a)
s=s//2
dic={100:0,200:0}
for i in a:
dic[i]+=1
while s>0:
if s>100 and dic[200]>0:
s-=200
dic[200]-=1
elif s>0 and dic[100]>0:
s-=1
dic[100]-=1
elif dic[100]<=0 and dic[200]<=0:
break
if s!=0:
print("NO")
else:
print("YES")
return
def main():
# T=inp()
T=1
for i in range(1,T+1):
#print("Case #{}:".format(i),end=" ")
solve()
return
main()
|
Title: Kitahara Haruki's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple.
Output Specification:
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Demo Input:
['3\n100 200 100\n', '4\n100 100 100 200\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
|
```python
import sys
from os import path
from math import gcd,floor,sqrt,log,ceil
from bisect import bisect_left, bisect_right
import heapq
############ ---- Input Functions ---- ####################
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def inst():
return(list(map(str,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
def inmatrix(n,m):
arr=[]
for i in range(n):
temp=inlt()
arr.append(temp)
return arr
############################################################
def cuberoot(x):
if 0<=x: return x**(1./2.)
return -(-x)**(1./2.)
def is_anagram(str1, str2):
return sorted(str1) == sorted(str2)
############################################################
mod=1000000007
############################################################
if(path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
sys.stderr = open("error.txt", "w")
else:
input = sys.stdin.readline
###########################################################
def solve():
n=inp()
a=inlt()
s=sum(a)
s=s//2
dic={100:0,200:0}
for i in a:
dic[i]+=1
while s>0:
if s>100 and dic[200]>0:
s-=200
dic[200]-=1
elif s>0 and dic[100]>0:
s-=1
dic[100]-=1
elif dic[100]<=0 and dic[200]<=0:
break
if s!=0:
print("NO")
else:
print("YES")
return
def main():
# T=inp()
T=1
for i in range(1,T+1):
#print("Case #{}:".format(i),end=" ")
solve()
return
main()
```
| 0
|
|
50
|
A
|
Domino piling
|
PROGRAMMING
| 800
|
[
"greedy",
"math"
] |
A. Domino piling
|
2
|
256
|
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
|
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
|
Output one number — the maximal number of dominoes, which can be placed.
|
[
"2 4\n",
"3 3\n"
] |
[
"4\n",
"4\n"
] |
none
| 500
|
[
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,689,430,604
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 92
| 0
|
n = input()
m = input()
total = int(m*n / 2)
print(total)
|
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
n = input()
m = input()
total = int(m*n / 2)
print(total)
```
| -1
|
637
|
C
|
Promocodes with Mistakes
|
PROGRAMMING
| 1,400
|
[
"*special",
"brute force",
"constructive algorithms",
"implementation"
] | null | null |
During a New Year special offer the "Sudislavl Bars" offered *n* promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.
As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum *k*, that the promotional code could be uniquely identified if it was typed with no more than *k* errors. At that, *k*<==<=0 means that the promotional codes must be entered exactly.
A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits.
|
The first line of the output contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of promocodes.
Each of the next *n* lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0".
|
Print the maximum *k* (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most *k* mistakes.
|
[
"2\n000000\n999999\n",
"6\n211111\n212111\n222111\n111111\n112111\n121111\n"
] |
[
"2\n",
"0\n"
] |
In the first sample *k* < 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it.
| 1,500
|
[
{
"input": "2\n000000\n999999",
"output": "2"
},
{
"input": "6\n211111\n212111\n222111\n111111\n112111\n121111",
"output": "0"
},
{
"input": "1\n123456",
"output": "6"
},
{
"input": "2\n000000\n099999",
"output": "2"
},
{
"input": "2\n000000\n009999",
"output": "1"
},
{
"input": "2\n000000\n000999",
"output": "1"
},
{
"input": "2\n000000\n000099",
"output": "0"
},
{
"input": "2\n000000\n000009",
"output": "0"
},
{
"input": "1\n000000",
"output": "6"
},
{
"input": "1\n999999",
"output": "6"
},
{
"input": "10\n946965\n781372\n029568\n336430\n456975\n119377\n179098\n925374\n878716\n461563",
"output": "1"
},
{
"input": "10\n878711\n193771\n965021\n617901\n333641\n307811\n989461\n461561\n956811\n253741",
"output": "1"
},
{
"input": "10\n116174\n914694\n615024\n115634\n717464\n910984\n513744\n111934\n915684\n817874",
"output": "0"
},
{
"input": "10\n153474\n155468\n151419\n151479\n158478\n159465\n150498\n157416\n150429\n159446",
"output": "0"
},
{
"input": "10\n141546\n941544\n141547\n041542\n641545\n841547\n941540\n741544\n941548\n641549",
"output": "0"
},
{
"input": "10\n114453\n114456\n114457\n114450\n114459\n114451\n114458\n114452\n114455\n114454",
"output": "0"
},
{
"input": "5\n145410\n686144\n859775\n922809\n470967",
"output": "2"
},
{
"input": "9\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652",
"output": "2"
},
{
"input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386",
"output": "2"
},
{
"input": "20\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832",
"output": "2"
},
{
"input": "50\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173",
"output": "2"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
},
{
"input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809",
"output": "2"
},
{
"input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809",
"output": "2"
},
{
"input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809",
"output": "2"
},
{
"input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809",
"output": "2"
},
{
"input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809",
"output": "2"
},
{
"input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386",
"output": "2"
},
{
"input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386",
"output": "2"
},
{
"input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386",
"output": "2"
},
{
"input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386",
"output": "2"
},
{
"input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386",
"output": "2"
},
{
"input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237",
"output": "1"
},
{
"input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237",
"output": "1"
},
{
"input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237",
"output": "1"
},
{
"input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237",
"output": "1"
},
{
"input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237",
"output": "1"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
}
] | 1,458,341,207
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 61
| 0
|
n=int(input())
l=[input() for i in range(n)]
print(min([sum(1 for k in range(6) if l[i][k]!=l[i][k])-1 for i in range(n) for j in range(i+1,n)]+[12])//2)
|
Title: Promocodes with Mistakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During a New Year special offer the "Sudislavl Bars" offered *n* promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.
As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum *k*, that the promotional code could be uniquely identified if it was typed with no more than *k* errors. At that, *k*<==<=0 means that the promotional codes must be entered exactly.
A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits.
Input Specification:
The first line of the output contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of promocodes.
Each of the next *n* lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0".
Output Specification:
Print the maximum *k* (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most *k* mistakes.
Demo Input:
['2\n000000\n999999\n', '6\n211111\n212111\n222111\n111111\n112111\n121111\n']
Demo Output:
['2\n', '0\n']
Note:
In the first sample *k* < 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it.
|
```python
n=int(input())
l=[input() for i in range(n)]
print(min([sum(1 for k in range(6) if l[i][k]!=l[i][k])-1 for i in range(n) for j in range(i+1,n)]+[12])//2)
```
| 0
|
|
920
|
B
|
Tea Queue
|
PROGRAMMING
| 1,200
|
[
"implementation"
] | null | null |
Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
*i*-th student comes to the end of the queue at the beginning of *l**i*-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of *r**i*-th second student *i* still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
For each student determine the second he will use the teapot and get his tea (if he actually gets it).
|
The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=1000).
Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of students.
Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=5000) — the second *i*-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
It is guaranteed that for every condition *l**i*<=-<=1<=≤<=*l**i* holds.
The sum of *n* over all test cases doesn't exceed 1000.
Note that in hacks you have to set *t*<==<=1.
|
For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea.
|
[
"2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n"
] |
[
"1 2 \n1 0 2 \n"
] |
The example contains 2 tests:
1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
| 0
|
[
{
"input": "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3",
"output": "1 2 \n1 0 2 "
},
{
"input": "19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2\n1 2\n1 1\n2\n1 2000\n1 1\n2\n1 1\n1 2000\n2\n1 2000\n2 2\n2\n2 2000\n2 2\n2\n2 2\n2 2000",
"output": "1 \n1 \n1 \n1 \n2 \n2 \n2 \n2 \n1999 \n1999 \n2000 \n1 0 \n1 2 \n1 0 \n1 0 \n1 2 \n1 2 \n2 0 \n2 3 "
},
{
"input": "1\n11\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "1 0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "1\n5\n1 1\n1 2\n1 5\n1 1\n1 1",
"output": "1 2 3 0 0 "
}
] | 1,517,588,713
| 6,613
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 61
| 5,632,000
|
t=int(input())
n=[]
x=[]
xl=[]
xr=[]
for i in range(t):
n0=int(input())
x.append([])
xl.append([])
xr.append([])
n.append(n0)
for j in range(n0):
x[i].append([int(x) for x in input().split()])
x[i][j].extend([i])
xl[i].append(x[i][j][0])
xr[i].append(x[i][j][1])
for i in range(t):
s=[]
s1=[]
v=[]
for t in range(5000):
if t in xl[i]:
s.append(x[i][xl[i].index(t)])
x[i].remove(s[-1])
if len(x[i])==0:
break
xl[i].remove(t)
s1.append(s[-1][1])
xr[i].remove(s1[-1])
if t in s1:
id=s1.index(t)
v.append([s[id][2],0])
s.remove(s[id])
s1.remove(t)
if len(s)>0:
v.append([s[0][2],t+1])
s.remove(s[0])
s1.remove(s1[0])
for i in v:
for j in i:
print(j,end=" ")
|
Title: Tea Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
*i*-th student comes to the end of the queue at the beginning of *l**i*-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of *r**i*-th second student *i* still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
For each student determine the second he will use the teapot and get his tea (if he actually gets it).
Input Specification:
The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=1000).
Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of students.
Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=5000) — the second *i*-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
It is guaranteed that for every condition *l**i*<=-<=1<=≤<=*l**i* holds.
The sum of *n* over all test cases doesn't exceed 1000.
Note that in hacks you have to set *t*<==<=1.
Output Specification:
For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea.
Demo Input:
['2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n']
Demo Output:
['1 2 \n1 0 2 \n']
Note:
The example contains 2 tests:
1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
|
```python
t=int(input())
n=[]
x=[]
xl=[]
xr=[]
for i in range(t):
n0=int(input())
x.append([])
xl.append([])
xr.append([])
n.append(n0)
for j in range(n0):
x[i].append([int(x) for x in input().split()])
x[i][j].extend([i])
xl[i].append(x[i][j][0])
xr[i].append(x[i][j][1])
for i in range(t):
s=[]
s1=[]
v=[]
for t in range(5000):
if t in xl[i]:
s.append(x[i][xl[i].index(t)])
x[i].remove(s[-1])
if len(x[i])==0:
break
xl[i].remove(t)
s1.append(s[-1][1])
xr[i].remove(s1[-1])
if t in s1:
id=s1.index(t)
v.append([s[id][2],0])
s.remove(s[id])
s1.remove(t)
if len(s)>0:
v.append([s[0][2],t+1])
s.remove(s[0])
s1.remove(s1[0])
for i in v:
for j in i:
print(j,end=" ")
```
| 0
|
|
390
|
A
|
Inna and Alarm Clock
|
PROGRAMMING
| 0
|
[
"implementation"
] | null | null |
Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner at point (100,<=100). Then the alarm clocks are points with integer coordinates in this square.
The morning has come. All *n* alarm clocks in Inna's room are ringing, so Inna wants to turn them off. For that Inna has come up with an amusing game:
- First Inna chooses a type of segments that she will use throughout the game. The segments can be either vertical or horizontal. - Then Inna makes multiple moves. In a single move, Inna can paint a segment of any length on the plane, she chooses its type at the beginning of the game (either vertical or horizontal), then all alarm clocks that are on this segment switch off. The game ends when all the alarm clocks are switched off.
Inna is very sleepy, so she wants to get through the alarm clocks as soon as possible. Help her, find the minimum number of moves in the game that she needs to turn off all the alarm clocks!
|
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of the alarm clocks. The next *n* lines describe the clocks: the *i*-th line contains two integers *x**i*, *y**i* — the coordinates of the *i*-th alarm clock (0<=≤<=*x**i*,<=*y**i*<=≤<=100).
Note that a single point in the room can contain any number of alarm clocks and the alarm clocks can lie on the sides of the square that represents the room.
|
In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally.
|
[
"4\n0 0\n0 1\n0 2\n1 0\n",
"4\n0 0\n0 1\n1 0\n1 1\n",
"4\n1 1\n1 2\n2 3\n3 3\n"
] |
[
"2\n",
"2\n",
"3\n"
] |
In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.
In the third sample it is important to note that Inna doesn't have the right to change the type of the segments during the game. That's why she will need 3 horizontal or 3 vertical segments to end the game.
| 500
|
[
{
"input": "4\n0 0\n0 1\n0 2\n1 0",
"output": "2"
},
{
"input": "4\n0 0\n0 1\n1 0\n1 1",
"output": "2"
},
{
"input": "4\n1 1\n1 2\n2 3\n3 3",
"output": "3"
},
{
"input": "1\n0 0",
"output": "1"
},
{
"input": "42\n28 87\n26 16\n59 90\n47 61\n28 83\n36 30\n67 10\n6 95\n9 49\n86 94\n52 24\n74 9\n86 24\n28 51\n25 99\n40 98\n57 33\n18 96\n43 36\n3 79\n4 86\n38 61\n25 61\n6 100\n58 81\n28 19\n64 4\n3 40\n2 56\n41 49\n97 100\n86 34\n42 36\n44 40\n14 85\n21 60\n76 99\n64 47\n69 13\n49 37\n97 37\n3 70",
"output": "31"
},
{
"input": "21\n54 85\n69 37\n42 87\n53 18\n28 22\n13 3\n62 97\n38 91\n67 19\n100 79\n29 18\n48 40\n68 84\n44 20\n37 34\n73 53\n21 5\n20 73\n24 94\n23 52\n7 55",
"output": "20"
},
{
"input": "19\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19",
"output": "1"
},
{
"input": "12\n1 1\n1 3\n1 5\n2 1\n2 2\n2 4\n3 1\n3 3\n3 5\n4 1\n4 2\n4 3",
"output": "4"
}
] | 1,631,908,750
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 19
| 218
| 7,168,000
|
n = int(input())
x_set = set()
y_set = set()
x_count = 0
y_count = 0
for i in range(n):
x, y = [int(x) for x in input().split()]
if x not in x_set :
x_set.add(x)
x_count += 1
if y not in y_set :
y_set.add(y)
y_count += 1
print(min(x_count, y_count))
|
Title: Inna and Alarm Clock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner at point (100,<=100). Then the alarm clocks are points with integer coordinates in this square.
The morning has come. All *n* alarm clocks in Inna's room are ringing, so Inna wants to turn them off. For that Inna has come up with an amusing game:
- First Inna chooses a type of segments that she will use throughout the game. The segments can be either vertical or horizontal. - Then Inna makes multiple moves. In a single move, Inna can paint a segment of any length on the plane, she chooses its type at the beginning of the game (either vertical or horizontal), then all alarm clocks that are on this segment switch off. The game ends when all the alarm clocks are switched off.
Inna is very sleepy, so she wants to get through the alarm clocks as soon as possible. Help her, find the minimum number of moves in the game that she needs to turn off all the alarm clocks!
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of the alarm clocks. The next *n* lines describe the clocks: the *i*-th line contains two integers *x**i*, *y**i* — the coordinates of the *i*-th alarm clock (0<=≤<=*x**i*,<=*y**i*<=≤<=100).
Note that a single point in the room can contain any number of alarm clocks and the alarm clocks can lie on the sides of the square that represents the room.
Output Specification:
In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally.
Demo Input:
['4\n0 0\n0 1\n0 2\n1 0\n', '4\n0 0\n0 1\n1 0\n1 1\n', '4\n1 1\n1 2\n2 3\n3 3\n']
Demo Output:
['2\n', '2\n', '3\n']
Note:
In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.
In the third sample it is important to note that Inna doesn't have the right to change the type of the segments during the game. That's why she will need 3 horizontal or 3 vertical segments to end the game.
|
```python
n = int(input())
x_set = set()
y_set = set()
x_count = 0
y_count = 0
for i in range(n):
x, y = [int(x) for x in input().split()]
if x not in x_set :
x_set.add(x)
x_count += 1
if y not in y_set :
y_set.add(y)
y_count += 1
print(min(x_count, y_count))
```
| 3
|
|
580
|
A
|
Kefa and First Steps
|
PROGRAMMING
| 900
|
[
"brute force",
"dp",
"implementation"
] | null | null |
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.
Help Kefa cope with this task!
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
|
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
|
[
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] |
[
"3",
"3"
] |
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
| 750
|
[
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "100\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 605 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 27 533 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 835 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 992",
"output": "42"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "6\n5 4 3 2 1 2",
"output": "2"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "7\n99 100 1 2 3 4 5",
"output": "5"
},
{
"input": "5\n3 3 1 2 3",
"output": "3"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "1\n5",
"output": "1"
}
] | 1,692,364,079
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 28
| 93
| 13,619,200
|
# 580A - Kefa and First Steps
n = int(input())
li = list(map(int, input().split()))
c = 0
tmp = 0
res = 0
for i in range(n):
if li[i] >= tmp:
c += 1
tmp = li[i]
res = max(res, c)
else:
c = 1
tmp = li[i]
print(res)
|
Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.
Help Kefa cope with this task!
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
Demo Input:
['6\n2 2 1 3 4 1\n', '3\n2 2 9\n']
Demo Output:
['3', '3']
Note:
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
|
```python
# 580A - Kefa and First Steps
n = int(input())
li = list(map(int, input().split()))
c = 0
tmp = 0
res = 0
for i in range(n):
if li[i] >= tmp:
c += 1
tmp = li[i]
res = max(res, c)
else:
c = 1
tmp = li[i]
print(res)
```
| 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,685,425,664
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 44
| 92
| 0
|
k = input()
t=0
for i in range(len(k)-1):
if(k[i]==k[i+1]):
t=t+1
else:
t=0
if(t==6):
break
if(t==6):
print("YES")
else:
print("NO")
|
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
k = input()
t=0
for i in range(len(k)-1):
if(k[i]==k[i+1]):
t=t+1
else:
t=0
if(t==6):
break
if(t==6):
print("YES")
else:
print("NO")
```
| 3.977
|
455
|
A
|
Boredom
|
PROGRAMMING
| 1,500
|
[
"dp"
] | null | null |
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
|
Print a single integer — the maximum number of points that Alex can earn.
|
[
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] |
[
"2\n",
"4\n",
"10\n"
] |
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
| 500
|
[
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
"output": "9"
},
{
"input": "10\n10 5 8 9 5 6 8 7 2 8",
"output": "46"
},
{
"input": "10\n1 1 1 1 1 1 2 3 4 4",
"output": "14"
},
{
"input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4",
"output": "296"
},
{
"input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2",
"output": "313"
},
{
"input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9",
"output": "298"
},
{
"input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5",
"output": "312"
},
{
"input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2",
"output": "287"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2",
"output": "265"
},
{
"input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9",
"output": "328"
},
{
"input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9",
"output": "324"
},
{
"input": "10\n7 4 5 3 9 1 10 3 4 5",
"output": "34"
},
{
"input": "10\n8 9 6 5 6 4 10 9 1 4",
"output": "39"
},
{
"input": "10\n1 7 1 4 9 10 8 2 9 9",
"output": "40"
},
{
"input": "1\n100000",
"output": "100000"
}
] | 1,699,995,716
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 47
| 108
| 13,721,600
|
# merge two arrays
import math
def main():
n = int(input())
m = int((1e5+2))
nums = list(map(int, input().split()))
counters = [0]*m
resFrom = [-1] * m
for num in nums:
counters[num] += 1
resFrom[-1] = counters[-1] * (m-1)
resFrom[-2] = max(resFrom[-1], counters[-2]*(m-2))
for i in reversed(range(m-2)):
resFrom[i] = max(counters[i]*i + resFrom[i+2], resFrom[i+1])
print(resFrom[0])
main()
|
Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Print a single integer — the maximum number of points that Alex can earn.
Demo Input:
['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n']
Demo Output:
['2\n', '4\n', '10\n']
Note:
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
|
```python
# merge two arrays
import math
def main():
n = int(input())
m = int((1e5+2))
nums = list(map(int, input().split()))
counters = [0]*m
resFrom = [-1] * m
for num in nums:
counters[num] += 1
resFrom[-1] = counters[-1] * (m-1)
resFrom[-2] = max(resFrom[-1], counters[-2]*(m-2))
for i in reversed(range(m-2)):
resFrom[i] = max(counters[i]*i + resFrom[i+2], resFrom[i+1])
print(resFrom[0])
main()
```
| 3
|
|
486
|
A
|
Calculating Function
|
PROGRAMMING
| 800
|
[
"implementation",
"math"
] | null | null |
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
|
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
|
Print *f*(*n*) in a single line.
|
[
"4\n",
"5\n"
] |
[
"2\n",
"-3\n"
] |
*f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3
| 500
|
[
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
"output": "50"
},
{
"input": "101",
"output": "-51"
},
{
"input": "102",
"output": "51"
},
{
"input": "103",
"output": "-52"
},
{
"input": "104",
"output": "52"
},
{
"input": "105",
"output": "-53"
},
{
"input": "106",
"output": "53"
},
{
"input": "107",
"output": "-54"
},
{
"input": "108",
"output": "54"
},
{
"input": "109",
"output": "-55"
},
{
"input": "208170109961052",
"output": "104085054980526"
},
{
"input": "46017661651072",
"output": "23008830825536"
},
{
"input": "4018154546667",
"output": "-2009077273334"
},
{
"input": "288565475053",
"output": "-144282737527"
},
{
"input": "3052460231",
"output": "-1526230116"
},
{
"input": "29906716",
"output": "14953358"
},
{
"input": "87897701693326",
"output": "43948850846663"
},
{
"input": "8240",
"output": "4120"
},
{
"input": "577935",
"output": "-288968"
},
{
"input": "62",
"output": "31"
},
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "1"
},
{
"input": "9999999999999",
"output": "-5000000000000"
},
{
"input": "1000000000000",
"output": "500000000000"
},
{
"input": "99999999999999",
"output": "-50000000000000"
},
{
"input": "999999999999999",
"output": "-500000000000000"
},
{
"input": "42191359342",
"output": "21095679671"
},
{
"input": "100000000000000",
"output": "50000000000000"
},
{
"input": "145645214654154",
"output": "72822607327077"
},
{
"input": "4294967296",
"output": "2147483648"
},
{
"input": "3037000499",
"output": "-1518500250"
},
{
"input": "10000000000001",
"output": "-5000000000001"
},
{
"input": "100000017040846",
"output": "50000008520423"
},
{
"input": "98979894985999",
"output": "-49489947493000"
}
] | 1,692,469,621
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 2
| 1,000
| 0
|
n = int(input())
ans = 0
for i in range(1, n+1):
ans += i * ((-1)**i)
print(ans)
|
Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Output Specification:
Print *f*(*n*) in a single line.
Demo Input:
['4\n', '5\n']
Demo Output:
['2\n', '-3\n']
Note:
*f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3
|
```python
n = int(input())
ans = 0
for i in range(1, n+1):
ans += i * ((-1)**i)
print(ans)
```
| 0
|
|
299
|
B
|
Ksusha the Squirrel
|
PROGRAMMING
| 900
|
[
"brute force",
"implementation"
] | null | null |
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)?
|
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".".
|
Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).
|
[
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] |
[
"YES\n",
"YES\n",
"NO\n"
] |
none
| 1,000
|
[
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "YES"
},
{
"input": "2 100000\n..",
"output": "YES"
},
{
"input": "3 1\n.#.",
"output": "NO"
},
{
"input": "3 2\n.#.",
"output": "YES"
},
{
"input": "3 10000\n.#.",
"output": "YES"
}
] | 1,682,843,619
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 33
| 156
| 18,841,600
|
n, k = map(int, input().split())
r=input()
a=list(r)
cnt = 0
for i in range(n):
if a[i]=='#':
cnt+=1
else:
cnt=0
if cnt==k:
print("NO")
break
if cnt!= k:
print("YES")
|
Title: Ksusha the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)?
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".".
Output Specification:
Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).
Demo Input:
['2 1\n..\n', '5 2\n.#.#.\n', '7 3\n.#.###.\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none
|
```python
n, k = map(int, input().split())
r=input()
a=list(r)
cnt = 0
for i in range(n):
if a[i]=='#':
cnt+=1
else:
cnt=0
if cnt==k:
print("NO")
break
if cnt!= k:
print("YES")
```
| 3
|
|
554
|
B
|
Ohana Cleans Up
|
PROGRAMMING
| 1,200
|
[
"brute force",
"greedy",
"strings"
] | null | null |
Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column.
Return the maximum number of rows that she can make completely clean.
|
The first line of input will be a single integer *n* (1<=≤<=*n*<=≤<=100).
The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-th row is clean, and '0' if it is dirty.
|
The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.
|
[
"4\n0101\n1000\n1111\n0101\n",
"3\n111\n111\n111\n"
] |
[
"2\n",
"3\n"
] |
In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean.
In the second sample, everything is already clean, so Ohana doesn't need to do anything.
| 500
|
[
{
"input": "4\n0101\n1000\n1111\n0101",
"output": "2"
},
{
"input": "3\n111\n111\n111",
"output": "3"
},
{
"input": "10\n0100000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000",
"output": "9"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n0111010011\n0111010011\n1010010001\n0111010011\n0000110000\n0111010011\n0111010011\n0000110000\n1010010001\n0111010011",
"output": "6"
},
{
"input": "20\n10101011101000011010\n11111010001100110101\n01011100010000001111\n10110100000101010011\n11010001110111101101\n00100110011011101010\n01000110101011001100\n01101100111101101101\n10111010010100111100\n00010010110001101110\n10111110010000101010\n10010111110100100100\n11010111001111110100\n11110111101100000001\n00011010100111011000\n11110001011000011010\n10001101010000011011\n01010101110010000111\n11100110111101101111\n11011111110010001111",
"output": "1"
},
{
"input": "10\n1001000000\n0111101111\n1111001011\n1000010100\n0111101111\n0101100110\n1001000000\n1000010100\n0111101111\n1001000000",
"output": "3"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000",
"output": "10"
},
{
"input": "10\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111",
"output": "10"
},
{
"input": "10\n1000000000\n0100000000\n0010000000\n0001000000\n0000100000\n0000010000\n0000001000\n0000000100\n0000000010\n0000000001",
"output": "1"
},
{
"input": "2\n10\n01",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "4\n0000\n0000\n1111\n1111",
"output": "2"
},
{
"input": "11\n10000000001\n10000000001\n10000000001\n10000000001\n10001000001\n10001000000\n10001000001\n10001000001\n10001000000\n10001000000\n10001000100",
"output": "4"
}
] | 1,570,095,790
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 36
| 140
| 102,400
|
n=int(input())
l=[]
cou=[]
for i in range(n):
l.append(input())
for i in set(l):
cou.append(l.count(i))
print(max(cou))
|
Title: Ohana Cleans Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column.
Return the maximum number of rows that she can make completely clean.
Input Specification:
The first line of input will be a single integer *n* (1<=≤<=*n*<=≤<=100).
The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-th row is clean, and '0' if it is dirty.
Output Specification:
The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.
Demo Input:
['4\n0101\n1000\n1111\n0101\n', '3\n111\n111\n111\n']
Demo Output:
['2\n', '3\n']
Note:
In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean.
In the second sample, everything is already clean, so Ohana doesn't need to do anything.
|
```python
n=int(input())
l=[]
cou=[]
for i in range(n):
l.append(input())
for i in set(l):
cou.append(l.count(i))
print(max(cou))
```
| 3
|
|
844
|
B
|
Rectangles
|
PROGRAMMING
| 1,300
|
[
"combinatorics",
"math"
] | null | null |
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column.
|
The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black.
|
Output single integer — the number of non-empty sets from the problem description.
|
[
"1 1\n0\n",
"2 3\n1 0 1\n0 1 0\n"
] |
[
"1\n",
"8\n"
] |
In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
| 1,000
|
[
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 3\n1 0 1\n0 1 0",
"output": "8"
},
{
"input": "2 2\n1 1\n1 1",
"output": "8"
},
{
"input": "1 10\n0 0 0 0 0 0 0 0 0 0",
"output": "1023"
},
{
"input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "2047"
},
{
"input": "10 11\n1 1 0 1 1 0 0 0 1 0 0\n1 0 0 1 1 1 0 0 1 1 0\n0 0 1 0 1 1 0 1 0 1 1\n0 1 1 1 0 1 0 1 0 0 0\n1 1 1 1 1 1 1 0 1 0 0\n1 1 0 1 1 1 1 0 0 1 1\n1 0 1 0 1 0 0 1 1 1 0\n1 1 0 0 0 0 0 1 0 1 1\n1 1 0 1 1 1 0 0 1 1 0\n1 0 1 1 0 0 1 0 0 1 1",
"output": "2444"
},
{
"input": "50 1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n1\n0\n1\n1\n0\n1\n1\n1\n0\n1\n0\n0\n0\n1\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n0\n0\n0\n1\n1\n0\n1",
"output": "142606334"
},
{
"input": "1 50\n0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 1 1 0 1",
"output": "142606334"
},
{
"input": "2 20\n0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0",
"output": "589853"
},
{
"input": "5 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "285"
},
{
"input": "6 6\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1",
"output": "720"
},
{
"input": "21 2\n0 1\n1 1\n0 1\n0 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",
"output": "1310745"
},
{
"input": "3 15\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 1 0 0 0 0 0 1 0\n1 0 0 1 0 0 0 0 0 0 0 0 1 0 1",
"output": "22587"
},
{
"input": "10 11\n0 1 0 0 0 0 0 0 0 0 0\n0 1 0 1 0 0 1 0 0 0 0\n0 0 0 0 0 0 1 1 1 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 1 0 0 0 0 1 0\n0 0 0 0 0 0 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 1 0\n0 0 1 0 0 0 1 1 0 0 0\n0 0 0 0 0 0 0 0 1 0 0\n0 0 1 0 1 0 0 0 0 1 1",
"output": "12047"
},
{
"input": "14 15\n0 1 0 0 0 0 0 0 1 0 0 0 1 0 1\n0 0 0 1 1 1 1 0 1 0 0 1 1 0 0\n1 0 0 0 0 1 1 0 0 0 0 0 0 0 0\n0 1 0 0 0 1 0 1 1 0 0 1 0 0 0\n0 0 1 1 0 1 0 1 0 1 1 0 1 0 0\n0 0 0 1 1 0 0 0 0 0 1 1 0 1 0\n0 0 1 0 0 0 0 0 0 1 0 0 1 1 0\n1 1 0 0 0 1 0 0 0 0 0 0 1 1 0\n0 0 0 0 1 0 1 1 1 0 0 0 1 0 1\n1 0 1 1 0 1 0 0 1 0 0 1 1 1 0\n1 0 0 0 0 1 0 0 0 0 0 1 0 0 0\n0 0 0 1 0 1 0 0 0 0 1 0 0 0 1\n0 0 1 0 1 0 0 0 1 1 1 1 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 1 0 0 0",
"output": "53166"
},
{
"input": "1 50\n0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 0",
"output": "1099511628798"
},
{
"input": "50 1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1",
"output": "35184372088862"
},
{
"input": "1 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1125899906842623"
},
{
"input": "5 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\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\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\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\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "5629499534214415"
},
{
"input": "32 2\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\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": "8589934622"
},
{
"input": "1 50\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",
"output": "562949953421312"
},
{
"input": "50 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "1125899906842623"
},
{
"input": "1 49\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",
"output": "562949953421311"
},
{
"input": "2 50\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\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",
"output": "2251799813685296"
},
{
"input": "3 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\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\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3377699720528069"
},
{
"input": "1 50\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",
"output": "1125899906842623"
},
{
"input": "1 40\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",
"output": "1099511627775"
},
{
"input": "1 33\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",
"output": "8589934591"
},
{
"input": "2 40\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\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",
"output": "2199023255590"
},
{
"input": "1 35\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",
"output": "34359738367"
},
{
"input": "50 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0",
"output": "1125899906842623"
}
] | 1,504,015,777
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 55
| 62
| 0
|
# encoding: utf-8
l = []
kl = []
n, m = map(int, input().split())
for _ in range(n):
l.append(input().split())
for i in range(n):
white = 0
black = 0
for j in range(m):
j_ = l[i][j]
if j_ == '1':
white += 1
else:
black += 1
kl.append(white)
kl.append(black)
for i in range(m):
white = 0
black = 0
for j in range(n):
if l[j][i] == '1':
white += 1
else:
black += 1
kl.append(white)
kl.append(black)
s = 0
for k in kl:
s += 2 ** k - 1
print(s - m * n)
|
Title: Rectangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column.
Input Specification:
The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black.
Output Specification:
Output single integer — the number of non-empty sets from the problem description.
Demo Input:
['1 1\n0\n', '2 3\n1 0 1\n0 1 0\n']
Demo Output:
['1\n', '8\n']
Note:
In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
|
```python
# encoding: utf-8
l = []
kl = []
n, m = map(int, input().split())
for _ in range(n):
l.append(input().split())
for i in range(n):
white = 0
black = 0
for j in range(m):
j_ = l[i][j]
if j_ == '1':
white += 1
else:
black += 1
kl.append(white)
kl.append(black)
for i in range(m):
white = 0
black = 0
for j in range(n):
if l[j][i] == '1':
white += 1
else:
black += 1
kl.append(white)
kl.append(black)
s = 0
for k in kl:
s += 2 ** k - 1
print(s - m * 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,674,842,683
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 20
| 46
| 0
|
t=int(input())
for i in range(t):
strg=input()
if len(strg)>10:
print(strg[0],end="")
print(len(strg)-2,end="")
print(strg[len(strg)-1])
else:
print(strg)
|
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
t=int(input())
for i in range(t):
strg=input()
if len(strg)>10:
print(strg[0],end="")
print(len(strg)-2,end="")
print(strg[len(strg)-1])
else:
print(strg)
```
| 3.977
|
33
|
A
|
What is for dinner?
|
PROGRAMMING
| 1,200
|
[
"greedy",
"implementation"
] |
A. What is for dinner?
|
2
|
256
|
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).
It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again.
Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative.
As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.
We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.
|
The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where belongs the corresponding tooth, and *c* (0<=≤<=*c*<=≤<=106) — its residual viability.
It's guaranteed that each tooth row has positive amount of teeth.
|
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
|
[
"4 3 18\n2 3\n1 2\n3 6\n2 3\n",
"2 2 13\n1 13\n2 12\n"
] |
[
"11\n",
"13\n"
] |
none
| 500
|
[
{
"input": "4 3 18\n2 3\n1 2\n3 6\n2 3",
"output": "11"
},
{
"input": "2 2 13\n1 13\n2 12",
"output": "13"
},
{
"input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3",
"output": "8"
},
{
"input": "1 1 0\n1 3",
"output": "0"
},
{
"input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 16\n1 16",
"output": "5"
},
{
"input": "4 2 8\n1 9\n1 10\n1 4\n2 6",
"output": "8"
},
{
"input": "10 4 14\n2 6\n1 5\n2 8\n2 6\n2 5\n4 1\n4 0\n2 4\n3 4\n1 0",
"output": "8"
},
{
"input": "54 22 1009\n15 7\n17 7\n11 9\n5 11\n12 9\n13 8\n13 12\n22 11\n20 9\n20 7\n16 11\n19 12\n3 12\n15 9\n1 12\n2 10\n16 10\n16 10\n14 10\n9 11\n9 9\n14 8\n10 10\n16 12\n1 8\n3 8\n21 11\n18 12\n2 6\n9 11\n11 7\n15 9\n20 11\n6 8\n8 8\n19 11\n15 7\n9 9\n22 7\n12 9\n17 9\n17 11\n12 7\n15 9\n5 11\n11 6\n18 8\n7 10\n4 10\n13 12\n4 8\n20 6\n15 12\n9 7",
"output": "180"
},
{
"input": "1 1 1000000\n1 1000000",
"output": "1000000"
},
{
"input": "4 3 181818\n3 1299\n1 1694\n3 1164\n2 1278",
"output": "4136"
},
{
"input": "50 50 0\n33 0\n26 0\n30 0\n41 0\n38 0\n36 0\n16 0\n7 0\n23 0\n5 0\n39 0\n29 0\n40 0\n47 0\n24 0\n43 0\n14 0\n10 0\n20 0\n3 0\n6 0\n34 0\n13 0\n18 0\n21 0\n9 0\n8 0\n22 0\n25 0\n4 0\n11 0\n17 0\n32 0\n44 0\n49 0\n50 0\n27 0\n28 0\n45 0\n12 0\n35 0\n15 0\n42 0\n31 0\n2 0\n1 0\n48 0\n19 0\n37 0\n46 0",
"output": "0"
},
{
"input": "19 12 199\n7 1\n8 6\n6 14\n1 7\n4 1\n6 6\n3 4\n1 5\n9 2\n5 3\n11 3\n9 4\n1 12\n4 7\n7 3\n12 14\n2 1\n10 8\n6 12",
"output": "54"
}
] | 1,640,419,780
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 31
| 92
| 0
|
n,m,k=map(int,input().split())
dic={}
sum=0
for i in range(n):
r,c=map(int,input().split())
if r not in dic:
dic[r]=c
else:
dic[r]=min(c,dic[r])
for i in dic:
sum+=dic[i]
if sum>=k:
print(k)
else:
print(sum)
|
Title: What is for dinner?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).
It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again.
Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative.
As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.
We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.
Input Specification:
The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where belongs the corresponding tooth, and *c* (0<=≤<=*c*<=≤<=106) — its residual viability.
It's guaranteed that each tooth row has positive amount of teeth.
Output Specification:
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
Demo Input:
['4 3 18\n2 3\n1 2\n3 6\n2 3\n', '2 2 13\n1 13\n2 12\n']
Demo Output:
['11\n', '13\n']
Note:
none
|
```python
n,m,k=map(int,input().split())
dic={}
sum=0
for i in range(n):
r,c=map(int,input().split())
if r not in dic:
dic[r]=c
else:
dic[r]=min(c,dic[r])
for i in dic:
sum+=dic[i]
if sum>=k:
print(k)
else:
print(sum)
```
| 3.977
|
805
|
B
|
3-palindrome
|
PROGRAMMING
| 1,000
|
[
"constructive algorithms"
] | null | null |
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
|
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string.
|
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
|
[
"2\n",
"3\n"
] |
[
"aa\n",
"bba\n"
] |
A palindrome is a sequence of characters which reads the same backward and forward.
| 1,000
|
[
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "67",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "77",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "89",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "98",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "109",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "117",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "1",
"output": "a"
},
{
"input": "200000",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "100000",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "143670",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "104217",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "17879",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "131809",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "140873",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "77859",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "153022",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "179227",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "182801",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "5188",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "86539",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "12802",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "120289",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "132866",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "133377",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "31775",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "160397",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "161415",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "163623",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "22942",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "134767",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "52257",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "64905",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "183758",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "60131",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "146883",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "6",
"output": "aabbaa"
},
{
"input": "4",
"output": "aabb"
}
] | 1,574,697,824
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 42
| 139
| 614,400
|
x=int(input())
s=""
A="bb"
for i in range(x//2):
if A=="aa":A="bb"
else:A="aa"
s+=A
if x%2==0:print(s)
else:print(s+"b" if A=="aa" else s+"a")
|
Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string.
Output Specification:
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Demo Input:
['2\n', '3\n']
Demo Output:
['aa\n', 'bba\n']
Note:
A palindrome is a sequence of characters which reads the same backward and forward.
|
```python
x=int(input())
s=""
A="bb"
for i in range(x//2):
if A=="aa":A="bb"
else:A="aa"
s+=A
if x%2==0:print(s)
else:print(s+"b" if A=="aa" else s+"a")
```
| 3
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
|
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
|
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
|
[
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] |
[
"YES\n",
"NO\n"
] |
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
| 0
|
[
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
"input": "353 313 327 470 597 31",
"output": "NO"
},
{
"input": "835 638 673 624 232 266",
"output": "NO"
},
{
"input": "936 342 19 398 247 874",
"output": "NO"
},
{
"input": "417 666 978 553 271 488",
"output": "NO"
},
{
"input": "71 66 124 199 67 147",
"output": "YES"
},
{
"input": "54 26 0 171 239 12",
"output": "YES"
},
{
"input": "72 8 186 92 267 69",
"output": "YES"
},
{
"input": "180 179 188 50 75 214",
"output": "YES"
},
{
"input": "16 169 110 136 404 277",
"output": "YES"
},
{
"input": "101 400 9 200 300 10",
"output": "YES"
},
{
"input": "101 400 200 9 300 10",
"output": "YES"
},
{
"input": "101 200 400 9 300 10",
"output": "YES"
},
{
"input": "101 400 200 300 9 10",
"output": "YES"
},
{
"input": "101 200 400 300 9 10",
"output": "YES"
},
{
"input": "4 4 4 4 5 4",
"output": "NO"
},
{
"input": "2 2 2 2 2 1",
"output": "NO"
},
{
"input": "1000 1000 999 1000 1000 1000",
"output": "NO"
},
{
"input": "129 1 10 29 8 111",
"output": "NO"
},
{
"input": "1000 1000 1000 999 999 1000",
"output": "YES"
},
{
"input": "101 200 300 400 9 10",
"output": "YES"
},
{
"input": "101 400 200 300 10 9",
"output": "YES"
},
{
"input": "101 200 400 300 10 9",
"output": "YES"
},
{
"input": "101 200 300 400 10 9",
"output": "YES"
},
{
"input": "101 200 300 10 400 9",
"output": "YES"
},
{
"input": "1 1 1 1 1 5",
"output": "NO"
},
{
"input": "8 1 1 3 3 0",
"output": "NO"
},
{
"input": "1 1 2 2 3 3",
"output": "YES"
},
{
"input": "1 2 2 5 2 5",
"output": "NO"
},
{
"input": "1 2 3 6 6 6",
"output": "NO"
},
{
"input": "36 91 7 86 51 89",
"output": "NO"
},
{
"input": "10 1 1 1 23 24",
"output": "NO"
},
{
"input": "1 1 1 10 23 24",
"output": "NO"
},
{
"input": "20 10 1 2 3 44",
"output": "NO"
},
{
"input": "7 0 14 11 8 6",
"output": "NO"
},
{
"input": "100 496 1 1 1 1",
"output": "NO"
},
{
"input": "5 4 2 5 11 3",
"output": "NO"
},
{
"input": "1 3 7 8 8 9",
"output": "YES"
},
{
"input": "1 3 4 5 18 19",
"output": "YES"
},
{
"input": "5 5 1 2 2 15",
"output": "NO"
},
{
"input": "2 1 0 0 0 5",
"output": "NO"
},
{
"input": "1 6 6 1 20 2",
"output": "NO"
},
{
"input": "2 10 0 0 0 0",
"output": "NO"
},
{
"input": "1 1 3 1 1 11",
"output": "NO"
},
{
"input": "10 10 1 1 1 37",
"output": "NO"
},
{
"input": "1 1 0 0 0 4",
"output": "NO"
},
{
"input": "1 1 10 1 1 28",
"output": "NO"
},
{
"input": "1 5 5 5 6 8",
"output": "YES"
},
{
"input": "0 2 3 4 4 5",
"output": "YES"
}
] | 1,516,707,959
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 9
| 61
| 5,632,000
|
a = list(map(int, input().split()))
a.sort()
s = sum(a)/2
f = s-a[0]-a[-1]
if f in a:
print("YES")
else:
print("NO")
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
Input Specification:
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Output Specification:
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Demo Input:
['1 3 2 1 2 1\n', '1 1 1 1 1 99\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
|
```python
a = list(map(int, input().split()))
a.sort()
s = sum(a)/2
f = s-a[0]-a[-1]
if f in a:
print("YES")
else:
print("NO")
```
| 0
|
|
448
|
A
|
Rewards
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals.
Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:
- any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals.
Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.
|
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces.
|
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
|
[
"1 1 1\n1 1 1\n4\n",
"1 1 3\n2 3 4\n2\n",
"1 0 0\n1 0 0\n1\n"
] |
[
"YES\n",
"YES\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "1 1 1\n1 1 1\n4",
"output": "YES"
},
{
"input": "1 1 3\n2 3 4\n2",
"output": "YES"
},
{
"input": "1 0 0\n1 0 0\n1",
"output": "NO"
},
{
"input": "0 0 0\n0 0 0\n1",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n100",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n1",
"output": "NO"
},
{
"input": "1 10 100\n100 10 1\n20",
"output": "NO"
},
{
"input": "1 1 1\n0 0 0\n1",
"output": "YES"
},
{
"input": "0 0 0\n1 1 1\n1",
"output": "YES"
},
{
"input": "5 5 5\n0 0 0\n2",
"output": "NO"
},
{
"input": "0 0 0\n10 10 10\n2",
"output": "NO"
},
{
"input": "21 61 39\n63 58 69\n44",
"output": "YES"
},
{
"input": "18 95 4\n7 1 75\n46",
"output": "YES"
},
{
"input": "64 27 81\n72 35 23\n48",
"output": "YES"
},
{
"input": "6 6 6\n11 11 11\n7",
"output": "NO"
},
{
"input": "1 2 3\n2 4 6\n3",
"output": "NO"
},
{
"input": "1 2 3\n2 4 6\n4",
"output": "YES"
},
{
"input": "99 99 99\n99 99 99\n89",
"output": "NO"
},
{
"input": "5 0 0\n15 0 0\n2",
"output": "NO"
},
{
"input": "10 10 10\n0 0 0\n1",
"output": "NO"
},
{
"input": "1 1 1\n1 1 1\n15",
"output": "YES"
},
{
"input": "2 3 5\n2 3 5\n2",
"output": "NO"
},
{
"input": "2 2 2\n3 3 5\n3",
"output": "NO"
},
{
"input": "1 2 2\n2 4 4\n1",
"output": "NO"
},
{
"input": "1 2 3\n1 5 5\n2",
"output": "NO"
}
] | 1,665,267,616
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 0
|
# Rewards Problem
import math
cups = input().split()
medals = input().split()
shelves = int(input())
#total cups
total_cups = 0
for c in cups:
total_cups += int(c)
total_cups = math.ceil(total_cups/5)
print(total_cups)
#total medals
total_medals = 0
for m in medals:
total_medals += int(m)
total_medals = math.ceil(total_medals/10)
print(total_medals)
if total_cups + total_medals <= shelves:
print("YES")
else:
print("NO")
|
Title: Rewards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals.
Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:
- any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals.
Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.
Input Specification:
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces.
Output Specification:
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
Demo Input:
['1 1 1\n1 1 1\n4\n', '1 1 3\n2 3 4\n2\n', '1 0 0\n1 0 0\n1\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none
|
```python
# Rewards Problem
import math
cups = input().split()
medals = input().split()
shelves = int(input())
#total cups
total_cups = 0
for c in cups:
total_cups += int(c)
total_cups = math.ceil(total_cups/5)
print(total_cups)
#total medals
total_medals = 0
for m in medals:
total_medals += int(m)
total_medals = math.ceil(total_medals/10)
print(total_medals)
if total_cups + total_medals <= shelves:
print("YES")
else:
print("NO")
```
| 0
|
|
731
|
A
|
Night at the Museum
|
PROGRAMMING
| 800
|
[
"implementation",
"strings"
] | null | null |
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
|
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
|
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
|
[
"zeus\n",
"map\n",
"ares\n"
] |
[
"18\n",
"35\n",
"34\n"
] |
To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
| 500
|
[
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"output": "99"
},
{
"input": "gngvi",
"output": "44"
},
{
"input": "aaaaa",
"output": "0"
},
{
"input": "a",
"output": "0"
},
{
"input": "z",
"output": "1"
},
{
"input": "vyadeehhikklnoqrs",
"output": "28"
},
{
"input": "jjiihhhhgggfedcccbazyxx",
"output": "21"
},
{
"input": "fyyptqqxuciqvwdewyppjdzur",
"output": "117"
},
{
"input": "fqcnzmzmbobmancqcoalzmanaobpdse",
"output": "368"
},
{
"input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza",
"output": "8"
},
{
"input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy",
"output": "644"
},
{
"input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss",
"output": "8"
},
{
"input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl",
"output": "421"
},
{
"input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa",
"output": "84"
},
{
"input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco",
"output": "666"
},
{
"input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww",
"output": "22"
},
{
"input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh",
"output": "643"
},
{
"input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib",
"output": "245"
},
{
"input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro",
"output": "468"
},
{
"input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned",
"output": "523"
},
{
"input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna",
"output": "130"
},
{
"input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh",
"output": "163"
},
{
"input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb",
"output": "155"
},
{
"input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp",
"output": "57"
},
{
"input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs",
"output": "1236"
},
{
"input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx",
"output": "49"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt",
"output": "331"
},
{
"input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte",
"output": "692"
},
{
"input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh",
"output": "1293"
},
{
"input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg",
"output": "16"
},
{
"input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple",
"output": "616"
},
{
"input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl",
"output": "605"
},
{
"input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud",
"output": "549"
},
{
"input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore",
"output": "688"
},
{
"input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc",
"output": "604"
},
{
"input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa",
"output": "572"
},
{
"input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp",
"output": "609"
},
{
"input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl",
"output": "223"
},
{
"input": "aa",
"output": "0"
}
] | 1,686,313,138
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 44
| 46
| 0
|
x = input()
n = ord('a')
cnt = 0
for i in range(len(x)):
cnt += min(abs(ord(x[i])-n), 26 - abs(ord(x[i])-n))
n = ord(x[i])
print(cnt)
|
Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
Input Specification:
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Output Specification:
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
Demo Input:
['zeus\n', 'map\n', 'ares\n']
Demo Output:
['18\n', '35\n', '34\n']
Note:
To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
|
```python
x = input()
n = ord('a')
cnt = 0
for i in range(len(x)):
cnt += min(abs(ord(x[i])-n), 26 - abs(ord(x[i])-n))
n = ord(x[i])
print(cnt)
```
| 3
|
|
298
|
B
|
Sail
|
PROGRAMMING
| 1,200
|
[
"brute force",
"greedy",
"implementation"
] | null | null |
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1).
Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)?
|
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).
|
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
|
[
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] |
[
"4\n",
"-1\n"
] |
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination.
| 500
|
[
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSSWESNSSEESNSESWSWNSWESNENWNWEE",
"output": "4"
},
{
"input": "41 -264908123 -86993764 -264908123 -86993723\nNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
"output": "41"
},
{
"input": "34 -1000000000 -1000000000 -999999983 -1000000000\nEEEEESSEWNSSSESWEWSWESEWSEESNEWEEE",
"output": "-1"
},
{
"input": "1 0 0 0 -1\nS",
"output": "1"
},
{
"input": "1 5 5 5 6\nE",
"output": "-1"
},
{
"input": "15 1 1 1 2\nNNNNNNNNNNNNNNN",
"output": "1"
},
{
"input": "11 1 1 1 2\nNNNNNNNNNNN",
"output": "1"
}
] | 1,614,869,974
| 2,147,483,647
|
PyPy 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 218
| 2,048,000
|
time, x, y, x1, y1 = [int(x) for x in input().split()]
st = input()
for i in range(time):
if x1 > x and st[i] == 'E':
a += 1
elif y1 > y and st[i] == 'N':
b += 1
elif x1 < x and st[i] == 'W':
a -= 1
elif x1 > x and st[i] == 'S':
b -= 1
if x == x1 and y == y1:
print(i+1)
break
else:
print("-1")
|
Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1).
Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)?
Input Specification:
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).
Output Specification:
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
Demo Input:
['5 0 0 1 1\nSESNW\n', '10 5 3 3 6\nNENSWESNEE\n']
Demo Output:
['4\n', '-1\n']
Note:
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination.
|
```python
time, x, y, x1, y1 = [int(x) for x in input().split()]
st = input()
for i in range(time):
if x1 > x and st[i] == 'E':
a += 1
elif y1 > y and st[i] == 'N':
b += 1
elif x1 < x and st[i] == 'W':
a -= 1
elif x1 > x and st[i] == 'S':
b -= 1
if x == x1 and y == y1:
print(i+1)
break
else:
print("-1")
```
| -1
|
|
160
|
A
|
Twins
|
PROGRAMMING
| 900
|
[
"greedy",
"sortings"
] | null | null |
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.
As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
|
In the single line print the single number — the minimum needed number of coins.
|
[
"2\n3 3\n",
"3\n2 1 2\n"
] |
[
"2\n",
"2\n"
] |
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
| 500
|
[
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "4"
},
{
"input": "7\n10 10 5 5 5 5 1",
"output": "3"
},
{
"input": "20\n2 1 2 2 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1",
"output": "8"
},
{
"input": "20\n4 2 4 4 3 4 2 2 4 2 3 1 1 2 2 3 3 3 1 4",
"output": "8"
},
{
"input": "20\n35 26 41 40 45 46 22 26 39 23 11 15 47 42 18 15 27 10 45 40",
"output": "8"
},
{
"input": "20\n7 84 100 10 31 35 41 2 63 44 57 4 63 11 23 49 98 71 16 90",
"output": "6"
},
{
"input": "50\n19 2 12 26 17 27 10 26 17 17 5 24 11 15 3 9 16 18 19 1 25 23 18 6 2 7 25 7 21 25 13 29 16 9 25 3 14 30 18 4 10 28 6 10 8 2 2 4 8 28",
"output": "14"
},
{
"input": "70\n2 18 18 47 25 5 14 9 19 46 36 49 33 32 38 23 32 39 8 29 31 17 24 21 10 15 33 37 46 21 22 11 20 35 39 13 11 30 28 40 39 47 1 17 24 24 21 46 12 2 20 43 8 16 44 11 45 10 13 44 31 45 45 46 11 10 33 35 23 42",
"output": "22"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "51"
},
{
"input": "100\n1 2 2 1 2 1 1 2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 1 1 2 1 1 1 1 2 2 2 2",
"output": "37"
},
{
"input": "100\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2",
"output": "36"
},
{
"input": "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3",
"output": "33"
},
{
"input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2",
"output": "30"
},
{
"input": "100\n16 9 11 8 11 4 9 17 4 8 4 10 9 10 6 3 3 15 1 6 1 15 12 18 6 14 13 18 1 7 18 4 10 7 10 12 3 16 14 4 10 8 10 7 19 13 15 1 4 8 16 10 6 4 3 16 11 10 7 3 4 16 1 20 1 11 4 16 10 7 7 12 18 19 3 17 19 3 4 19 2 12 11 3 18 20 2 2 14 4 20 13 13 11 16 20 19 14 7 2",
"output": "29"
},
{
"input": "100\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1",
"output": "30"
},
{
"input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52",
"output": "29"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "30"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "4\n4 1 2 3",
"output": "2"
},
{
"input": "5\n2 2 2 4 4",
"output": "2"
},
{
"input": "4\n100 99 99 100",
"output": "2"
}
] | 1,687,693,629
| 2,147,483,647
|
PyPy 3-64
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int n;
cin >> n;
int sum = 0 , running_sum = 0 , half_sum = 0;
vector<int> arr(n);
for(int i=0 ; i < n ;i++)
{
cin >> arr.at(i);
sum += arr[i];
}
half_sum = sum /2;
sort(arr.rbegin() , arr.rend());
int counter = 0;
for(int i=0 ; i < n ;i++)
{
running_sum += arr[i];
counter++;
if(running_sum > half_sum)
break;
}
cout << counter;
return 0;
}
|
Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.
As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
Output Specification:
In the single line print the single number — the minimum needed number of coins.
Demo Input:
['2\n3 3\n', '3\n2 1 2\n']
Demo Output:
['2\n', '2\n']
Note:
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
|
```python
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int n;
cin >> n;
int sum = 0 , running_sum = 0 , half_sum = 0;
vector<int> arr(n);
for(int i=0 ; i < n ;i++)
{
cin >> arr.at(i);
sum += arr[i];
}
half_sum = sum /2;
sort(arr.rbegin() , arr.rend());
int counter = 0;
for(int i=0 ; i < n ;i++)
{
running_sum += arr[i];
counter++;
if(running_sum > half_sum)
break;
}
cout << counter;
return 0;
}
```
| -1
|
|
408
|
A
|
Line to Cashier
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that:
- the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.
Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has.
|
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
|
[
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] |
[
"20\n",
"100\n"
] |
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.
| 500
|
[
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3",
"output": "125"
},
{
"input": "5\n10 10 10 10 10\n6 7 8 6 8 5 9 8 10 5\n9 6 9 8 7 8 8 10 8 5\n8 7 7 8 7 5 6 8 9 5\n6 5 10 5 5 10 7 8 5 5\n10 9 8 7 6 9 7 9 6 5",
"output": "480"
},
{
"input": "10\n9 10 10 10 9 5 9 7 8 7\n11 6 10 4 4 15 7 15 5\n3 9 11 12 11 1 13 13 1 5\n6 15 9 12 3 2 8 12 11 10\n7 1 1 6 10 2 6 1 14 2\n8 14 2 3 6 1 14 1 12\n6 10 9 3 5\n13 12 12 7 13 4 4 8 10\n5 6 4 3 14 9 13\n8 12 1 5 7 4 13 1\n1 9 5 3 5 1 4",
"output": "240"
},
{
"input": "10\n5 5 5 5 5 5 5 5 5 5\n5 5 4 5 4\n6 5 7 7 6\n5 4 4 5 5\n4 4 5 5 5\n7 6 4 5 7\n4 6 5 4 5\n6 6 7 6 6\n4 5 4 4 7\n7 5 4 4 5\n6 6 7 4 4",
"output": "190"
},
{
"input": "1\n1\n100",
"output": "515"
},
{
"input": "1\n90\n90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90",
"output": "41850"
}
] | 1,616,454,345
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 20
| 62
| 307,200
|
import math
n=int(input())
a=[]
a=list(map(int,input().strip().split()))
m=10000000
s=0
for i in range(n):
x=[]
x=list(map(int,input().strip().split()))
s=0
s=sum(x)*5+len(x)*15
m=min(m,s)
print(m)
|
Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that:
- the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.
Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has.
Output Specification:
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
Demo Input:
['1\n1\n1\n', '4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n']
Demo Output:
['20\n', '100\n']
Note:
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.
|
```python
import math
n=int(input())
a=[]
a=list(map(int,input().strip().split()))
m=10000000
s=0
for i in range(n):
x=[]
x=list(map(int,input().strip().split()))
s=0
s=sum(x)*5+len(x)*15
m=min(m,s)
print(m)
```
| 3
|
|
385
|
A
|
Bear and Raspberry
|
PROGRAMMING
| 1,000
|
[
"brute force",
"greedy",
"implementation"
] | null | null |
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=<<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel.
The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.
|
The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*.
|
Print a single integer — the answer to the problem.
|
[
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] |
[
"3\n",
"97\n",
"0\n"
] |
In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97.
| 500
|
[
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"input": "100 4\n2 57 70 8 44 10 88 67 50 44 93 79 72 50 69 19 21 9 71 47 95 13 46 10 68 72 54 40 15 83 57 92 58 25 4 22 84 9 8 55 87 0 16 46 86 58 5 21 32 28 10 46 11 29 13 33 37 34 78 33 33 21 46 70 77 51 45 97 6 21 68 61 87 54 8 91 37 12 76 61 57 9 100 45 44 88 5 71 98 98 26 45 37 87 34 50 33 60 64 77",
"output": "87"
},
{
"input": "100 5\n15 91 86 53 18 52 26 89 8 4 5 100 11 64 88 91 35 57 67 72 71 71 69 73 97 23 11 1 59 86 37 82 6 67 71 11 7 31 11 68 21 43 89 54 27 10 3 33 8 57 79 26 90 81 6 28 24 7 33 50 24 13 27 85 4 93 14 62 37 67 33 40 7 48 41 4 14 9 95 10 64 62 7 93 23 6 28 27 97 64 26 83 70 0 97 74 11 82 70 93",
"output": "84"
},
{
"input": "6 100\n10 9 8 7 6 5",
"output": "0"
},
{
"input": "100 9\n66 71 37 41 23 38 77 11 74 13 51 26 93 56 81 17 12 70 85 37 54 100 14 99 12 83 44 16 99 65 13 48 92 32 69 33 100 57 58 88 25 45 44 85 5 41 82 15 37 18 21 45 3 68 33 9 52 64 8 73 32 41 87 99 26 26 47 24 79 93 9 44 11 34 85 26 14 61 49 38 25 65 49 81 29 82 28 23 2 64 38 13 77 68 67 23 58 57 83 46",
"output": "78"
},
{
"input": "100 100\n9 72 46 37 26 94 80 1 43 85 26 53 58 18 24 19 67 2 100 52 61 81 48 15 73 41 97 93 45 1 73 54 75 51 28 79 0 14 41 42 24 50 70 18 96 100 67 1 68 48 44 39 63 77 78 18 10 51 32 53 26 60 1 13 66 39 55 27 23 71 75 0 27 88 73 31 16 95 87 84 86 71 37 40 66 70 65 83 19 4 81 99 26 51 67 63 80 54 23 44",
"output": "0"
},
{
"input": "43 65\n32 58 59 75 85 18 57 100 69 0 36 38 79 95 82 47 7 55 28 88 27 88 63 71 80 86 67 53 69 37 99 54 81 19 55 12 2 17 84 77 25 26 62",
"output": "4"
},
{
"input": "12 64\n14 87 40 24 32 36 4 41 38 77 68 71",
"output": "0"
},
{
"input": "75 94\n80 92 25 48 78 17 69 52 79 73 12 15 59 55 25 61 96 27 98 43 30 43 36 94 67 54 86 99 100 61 65 8 65 19 18 21 75 31 2 98 55 87 14 1 17 97 94 11 57 29 34 71 76 67 45 0 78 29 86 82 29 23 77 100 48 43 65 62 88 34 7 28 13 1 1",
"output": "0"
},
{
"input": "59 27\n76 61 24 66 48 18 69 84 21 8 64 90 19 71 36 90 9 36 30 37 99 37 100 56 9 79 55 37 54 63 11 11 49 71 91 70 14 100 10 44 52 23 21 19 96 13 93 66 52 79 76 5 62 6 90 35 94 7 27",
"output": "63"
},
{
"input": "86 54\n41 84 16 5 20 79 73 13 23 24 42 73 70 80 69 71 33 44 62 29 86 88 40 64 61 55 58 19 16 23 84 100 38 91 89 98 47 50 55 87 12 94 2 12 0 1 4 26 50 96 68 34 94 80 8 22 60 3 72 84 65 89 44 52 50 9 24 34 81 28 56 17 38 85 78 90 62 60 1 40 91 2 7 41 84 22",
"output": "38"
},
{
"input": "37 2\n65 36 92 92 92 76 63 56 15 95 75 26 15 4 73 50 41 92 26 20 19 100 63 55 25 75 61 96 35 0 14 6 96 3 28 41 83",
"output": "91"
},
{
"input": "19 4\n85 2 56 70 33 75 89 60 100 81 42 28 18 92 29 96 49 23 14",
"output": "79"
},
{
"input": "89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 35 55 88 53 87 61 22 100 56 14 87 36 84 24",
"output": "91"
},
{
"input": "67 0\n40 48 15 46 90 7 65 52 24 15 42 81 2 6 71 94 32 18 97 67 83 98 48 51 10 47 8 68 36 46 65 75 90 30 62 9 5 35 80 60 69 58 62 68 58 73 80 9 22 46 56 64 44 11 93 73 62 54 15 20 17 69 16 33 85 62 49",
"output": "83"
},
{
"input": "96 0\n38 97 82 43 80 40 1 99 50 94 81 63 92 13 57 24 4 10 25 32 79 56 96 19 25 14 69 56 66 22 23 78 87 76 37 30 75 77 61 64 35 64 62 32 44 62 6 84 91 44 99 5 71 19 17 12 35 52 1 14 35 18 8 36 54 42 4 67 80 11 88 44 34 35 12 38 66 42 4 90 45 10 1 44 37 96 23 28 100 90 75 17 27 67 51 70",
"output": "94"
},
{
"input": "14 14\n87 63 62 31 59 47 40 89 92 43 80 30 99 42",
"output": "43"
},
{
"input": "12 0\n100 1 100 2 100 3 100 4 100 5 100 0",
"output": "100"
},
{
"input": "3 1\n1 2 3",
"output": "0"
},
{
"input": "3 2\n3 3 3",
"output": "0"
},
{
"input": "3 3\n3 2 1",
"output": "0"
},
{
"input": "3 100\n1 2 3",
"output": "0"
},
{
"input": "2 100\n0 0",
"output": "0"
},
{
"input": "2 90\n10 5",
"output": "0"
},
{
"input": "2 5\n5 4",
"output": "0"
},
{
"input": "3 1\n19 20 1",
"output": "18"
},
{
"input": "5 1\n5 10 7 4 20",
"output": "2"
},
{
"input": "5 1\n1 2 3 4 5",
"output": "0"
}
] | 1,651,408,508
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 32
| 46
| 0
|
import sys
input = sys.stdin.readline
n, c = map(int, input().split())
w = list(map(int, input().split()))
s = 0
for i in range(n-1):
if w[i] - w[i+1] > s:
s = w[i] - w[i+1]
print(0 if s <= c else s-c)
|
Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=<<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel.
The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.
Input Specification:
The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['5 1\n5 10 7 3 20\n', '6 2\n100 1 10 40 10 40\n', '3 0\n1 2 3\n']
Demo Output:
['3\n', '97\n', '0\n']
Note:
In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97.
|
```python
import sys
input = sys.stdin.readline
n, c = map(int, input().split())
w = list(map(int, input().split()))
s = 0
for i in range(n-1):
if w[i] - w[i+1] > s:
s = w[i] - w[i+1]
print(0 if s <= c else s-c)
```
| 3
|
|
810
|
A
|
Straight <<A>>
|
PROGRAMMING
| 900
|
[
"implementation",
"math"
] | null | null |
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8.
For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8.
To graduate with «A» certificate, Noora has to have mark *k*.
Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*.
|
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack.
|
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*.
|
[
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] |
[
"4",
"3"
] |
Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation.
In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
| 500
|
[
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 22 23 14 21 27 18 25 12",
"output": "712"
},
{
"input": "38 12\n2 7 10 8 5 3 5 6 3 6 5 1 9 7 7 8 3 4 4 4 5 2 3 6 6 1 6 7 4 4 8 7 4 5 3 6 6 6",
"output": "482"
},
{
"input": "63 86\n32 31 36 29 36 26 28 38 39 32 29 26 33 38 36 38 36 28 43 48 28 33 25 39 39 27 34 25 37 28 40 26 30 31 42 32 36 44 29 36 30 35 48 40 26 34 30 33 33 46 42 24 36 38 33 51 33 41 38 29 29 32 28",
"output": "6469"
},
{
"input": "100 38\n30 24 38 31 31 33 32 32 29 34 29 22 27 23 34 25 32 30 30 26 16 27 38 33 38 38 37 34 32 27 33 23 33 32 24 24 30 36 29 30 33 30 29 30 36 33 33 35 28 24 30 32 38 29 30 36 31 30 27 38 31 36 15 37 32 27 29 24 38 33 28 29 34 21 37 35 32 31 27 25 27 28 31 31 36 38 35 35 36 29 35 22 38 31 38 28 31 27 34 31",
"output": "1340"
},
{
"input": "33 69\n60 69 68 69 69 60 64 60 62 59 54 47 60 62 69 69 69 58 67 69 62 69 68 53 69 69 66 66 57 58 65 69 61",
"output": "329"
},
{
"input": "39 92\n19 17 16 19 15 30 21 25 14 17 19 19 23 16 14 15 17 19 29 15 11 25 19 14 18 20 10 16 11 15 18 20 20 17 18 16 12 17 16",
"output": "5753"
},
{
"input": "68 29\n29 29 29 29 29 28 29 29 29 27 29 29 29 29 29 29 29 23 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 22 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29",
"output": "0"
},
{
"input": "75 30\n22 18 21 26 23 18 28 30 24 24 19 25 28 30 23 29 18 23 23 30 26 30 17 30 18 19 25 26 26 15 27 23 30 21 19 26 25 30 25 28 20 22 22 21 26 17 23 23 24 15 25 19 18 22 30 30 29 21 30 28 28 30 27 25 24 15 22 19 30 21 20 30 18 20 25",
"output": "851"
},
{
"input": "78 43\n2 7 6 5 5 6 4 5 3 4 6 8 4 5 5 4 3 1 2 4 4 6 5 6 4 4 6 4 8 4 6 5 6 1 4 5 6 3 2 5 2 5 3 4 8 8 3 3 4 4 6 6 5 4 5 5 7 9 3 9 6 4 7 3 6 9 6 5 1 7 2 5 6 3 6 2 5 4",
"output": "5884"
},
{
"input": "82 88\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1",
"output": "14170"
},
{
"input": "84 77\n28 26 36 38 37 44 48 34 40 22 42 35 40 37 30 31 33 35 36 55 47 36 33 47 40 38 27 38 36 33 35 31 47 33 30 38 38 47 49 24 38 37 28 43 39 36 34 33 29 38 36 43 48 38 36 34 33 34 35 31 26 33 39 37 37 37 35 52 47 30 24 46 38 26 43 46 41 50 33 40 36 41 37 30",
"output": "6650"
},
{
"input": "94 80\n21 19 15 16 27 16 20 18 19 19 15 15 20 19 19 21 20 19 13 17 15 9 17 15 23 15 12 18 12 13 15 12 14 13 14 17 20 20 14 21 15 6 10 23 24 8 18 18 13 23 17 22 17 19 19 18 17 24 8 16 18 20 24 19 10 19 15 10 13 14 19 15 16 19 20 15 14 21 16 16 14 14 22 19 12 11 14 13 19 32 16 16 13 20",
"output": "11786"
},
{
"input": "96 41\n13 32 27 34 28 34 30 26 21 24 29 20 25 34 25 16 27 15 22 22 34 22 25 19 23 17 17 22 26 24 23 20 21 27 19 33 13 24 22 18 30 30 27 14 26 24 20 20 22 11 19 31 19 29 18 28 30 22 17 15 28 32 17 24 17 24 24 19 26 23 22 29 18 22 23 29 19 32 26 23 22 22 24 23 27 30 24 25 21 21 33 19 35 27 34 28",
"output": "3182"
},
{
"input": "1 26\n26",
"output": "0"
},
{
"input": "99 39\n25 28 30 28 32 34 31 28 29 28 29 30 33 19 33 31 27 33 29 24 27 30 25 38 28 34 35 31 34 37 30 22 21 24 34 27 34 33 34 33 26 26 36 19 30 22 35 30 21 28 23 35 33 29 21 22 36 31 34 32 34 32 30 32 27 33 38 25 35 26 39 27 29 29 19 33 28 29 34 38 26 30 36 26 29 30 26 34 22 32 29 38 25 27 24 17 25 28 26",
"output": "1807"
},
{
"input": "100 12\n7 6 6 3 5 5 9 8 7 7 4 7 12 6 9 5 6 3 4 7 9 10 7 7 5 3 9 6 9 9 6 7 4 10 4 8 8 6 9 8 6 5 7 4 10 7 5 6 8 9 3 4 8 5 4 8 6 10 5 8 7 5 9 8 5 8 5 6 9 11 4 9 5 5 11 4 6 6 7 3 8 9 6 7 10 4 7 6 9 4 8 11 5 4 10 8 5 10 11 4",
"output": "946"
},
{
"input": "100 18\n1 2 2 2 2 2 1 1 1 2 3 1 3 1 1 4 2 4 1 2 1 2 1 3 2 1 2 1 1 1 2 1 2 2 1 1 4 3 1 1 2 1 3 3 2 1 2 2 1 1 1 1 3 1 1 2 2 1 1 1 5 1 2 1 3 2 2 1 4 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 3 1 1 2 1 1 2",
"output": "3164"
},
{
"input": "100 27\n16 20 21 10 16 17 18 25 19 18 20 12 11 21 21 23 20 26 20 21 27 16 25 18 25 21 27 12 20 27 18 17 27 13 21 26 12 22 15 21 25 21 18 27 24 15 16 18 23 21 24 27 19 17 24 14 21 16 24 26 13 14 25 18 27 26 22 16 27 27 17 25 17 12 22 10 19 27 19 20 23 22 25 23 17 25 14 20 22 10 22 27 21 20 15 26 24 27 12 16",
"output": "1262"
},
{
"input": "100 29\n20 18 23 24 14 14 16 23 22 17 18 22 21 21 19 19 14 11 18 19 16 22 25 20 14 13 21 24 18 16 18 29 17 25 12 10 18 28 11 16 17 14 15 20 17 20 18 22 10 16 16 20 18 19 29 18 25 27 17 19 24 15 24 25 16 23 19 16 16 20 19 15 12 21 20 13 21 15 15 23 16 23 17 13 17 21 13 18 17 18 18 20 16 12 19 15 27 14 11 18",
"output": "2024"
},
{
"input": "100 30\n16 10 20 11 14 27 15 17 22 26 24 17 15 18 19 22 22 15 21 22 14 21 22 22 21 22 15 17 17 22 18 19 26 18 22 20 22 25 18 18 17 23 18 18 20 13 19 30 17 24 22 19 29 20 20 21 17 18 26 25 22 19 15 18 18 20 19 19 18 18 24 16 19 17 12 21 20 16 23 21 16 17 26 23 25 28 22 20 9 21 17 24 15 19 17 21 29 13 18 15",
"output": "1984"
},
{
"input": "100 59\n56 58 53 59 59 48 59 54 46 59 59 58 48 59 55 59 59 50 59 56 59 59 59 59 59 59 59 57 59 53 45 53 50 59 50 55 58 54 59 56 54 59 59 59 59 48 56 59 59 57 59 59 48 43 55 57 39 59 46 55 55 52 58 57 51 59 59 59 59 53 59 43 51 54 46 59 57 43 50 59 47 58 59 59 59 55 46 56 55 59 56 47 56 56 46 51 47 48 59 55",
"output": "740"
},
{
"input": "100 81\n6 7 6 6 7 6 6 6 3 9 4 5 4 3 4 6 6 6 1 3 9 5 2 3 8 5 6 9 6 6 6 5 4 4 7 7 3 6 11 7 6 4 8 7 12 6 4 10 2 4 9 11 7 4 7 7 8 8 6 7 9 8 4 5 8 13 6 6 6 8 6 2 5 6 7 5 4 4 4 4 2 6 4 8 3 4 7 7 6 7 7 10 5 10 6 7 4 11 8 4",
"output": "14888"
},
{
"input": "100 100\n30 35 23 43 28 49 31 32 30 44 32 37 33 34 38 28 43 32 33 32 50 32 41 38 33 20 40 36 29 21 42 25 23 34 43 32 37 31 30 27 36 32 45 37 33 29 38 34 35 33 28 19 37 33 28 41 31 29 41 27 32 39 30 34 37 40 33 38 35 32 32 34 35 34 28 39 28 34 40 45 31 25 42 28 29 31 33 21 36 33 34 37 40 42 39 30 36 34 34 40",
"output": "13118"
},
{
"input": "100 100\n71 87 100 85 89 98 90 90 71 65 76 75 85 100 81 100 91 80 73 89 86 78 82 89 77 92 78 90 100 81 85 89 73 100 66 60 72 88 91 73 93 76 88 81 86 78 83 77 74 93 97 94 85 78 82 78 91 91 100 78 89 76 78 82 81 78 83 88 87 83 78 98 85 97 98 89 88 75 76 86 74 81 70 76 86 84 99 100 89 94 72 84 82 88 83 89 78 99 87 76",
"output": "3030"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "19700"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100 100\n1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "19696"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99",
"output": "0"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 100 100 100 100 98 100 100 100 100 100 100 99 98 100 100 93 100 100 98 100 100 100 100 93 100 96 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 95 88 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100 100\n95 100 100 100 100 100 100 100 100 100 100 100 100 100 87 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 90 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 96 100 98 100 100 100 100 100 96 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 100",
"output": "2"
},
{
"input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "100 2\n2 1 1 2 1 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 2 2 2 2 1 2 2 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 2 1 1",
"output": "16"
},
{
"input": "3 5\n5 5 5",
"output": "0"
},
{
"input": "7 7\n1 1 1 1 1 1 1",
"output": "77"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "19700"
},
{
"input": "4 10\n10 10 10 10",
"output": "0"
},
{
"input": "1 10\n10",
"output": "0"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3 10\n10 10 10",
"output": "0"
},
{
"input": "2 4\n3 4",
"output": "0"
},
{
"input": "1 2\n2",
"output": "0"
},
{
"input": "3 4\n4 4 4",
"output": "0"
},
{
"input": "3 2\n2 2 1",
"output": "0"
},
{
"input": "5 5\n5 5 5 5 5",
"output": "0"
},
{
"input": "3 3\n3 3 3",
"output": "0"
},
{
"input": "2 9\n8 9",
"output": "0"
},
{
"input": "3 10\n9 10 10",
"output": "0"
},
{
"input": "1 3\n3",
"output": "0"
},
{
"input": "2 2\n1 2",
"output": "0"
},
{
"input": "2 10\n10 10",
"output": "0"
},
{
"input": "23 14\n7 11 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14",
"output": "0"
},
{
"input": "2 10\n9 10",
"output": "0"
},
{
"input": "2 2\n2 2",
"output": "0"
},
{
"input": "10 5\n5 5 5 5 5 5 5 5 5 4",
"output": "0"
},
{
"input": "3 5\n4 5 5",
"output": "0"
},
{
"input": "5 4\n4 4 4 4 4",
"output": "0"
},
{
"input": "2 10\n10 9",
"output": "0"
},
{
"input": "4 5\n3 5 5 5",
"output": "0"
},
{
"input": "10 5\n5 5 5 5 5 5 5 5 5 5",
"output": "0"
},
{
"input": "3 10\n10 10 9",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "4 10\n9 10 10 10",
"output": "0"
},
{
"input": "5 2\n2 2 2 2 2",
"output": "0"
},
{
"input": "2 5\n4 5",
"output": "0"
},
{
"input": "5 10\n10 10 10 10 10",
"output": "0"
},
{
"input": "2 6\n6 6",
"output": "0"
},
{
"input": "2 9\n9 9",
"output": "0"
},
{
"input": "3 10\n10 9 10",
"output": "0"
},
{
"input": "4 40\n39 40 40 40",
"output": "0"
},
{
"input": "3 4\n3 4 4",
"output": "0"
},
{
"input": "9 9\n9 9 9 9 9 9 9 9 9",
"output": "0"
},
{
"input": "1 4\n4",
"output": "0"
},
{
"input": "4 7\n1 1 1 1",
"output": "44"
},
{
"input": "1 5\n5",
"output": "0"
},
{
"input": "3 1\n1 1 1",
"output": "0"
},
{
"input": "1 100\n100",
"output": "0"
},
{
"input": "2 7\n3 5",
"output": "10"
},
{
"input": "3 6\n6 6 6",
"output": "0"
},
{
"input": "4 2\n1 2 2 2",
"output": "0"
},
{
"input": "4 5\n4 5 5 5",
"output": "0"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "35"
},
{
"input": "66 2\n1 2 2 2 2 1 1 2 1 2 2 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 2 1 2 2 1 1 2 1 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 1 2 2 1",
"output": "0"
},
{
"input": "2 2\n2 1",
"output": "0"
},
{
"input": "5 5\n5 5 5 4 5",
"output": "0"
},
{
"input": "3 7\n1 1 1",
"output": "33"
},
{
"input": "2 5\n5 5",
"output": "0"
},
{
"input": "1 7\n1",
"output": "11"
},
{
"input": "6 7\n1 1 1 1 1 1",
"output": "66"
},
{
"input": "99 97\n15 80 78 69 12 84 36 51 89 77 88 10 1 19 67 85 6 36 8 70 14 45 88 97 22 13 75 57 83 27 13 97 9 90 68 51 76 37 5 2 16 92 11 48 13 77 35 19 15 74 22 29 21 12 28 42 56 5 32 41 62 75 71 71 68 72 24 77 11 28 78 27 53 88 74 66 1 42 18 16 18 39 75 38 81 5 13 39 40 75 13 36 53 83 9 54 57 63 64",
"output": "10077"
},
{
"input": "8 7\n1 1 1 1 1 1 1 1",
"output": "88"
},
{
"input": "3 2\n2 2 2",
"output": "0"
},
{
"input": "6 5\n5 5 5 5 5 5",
"output": "0"
},
{
"input": "10 5\n5 5 5 5 5 5 5 4 1 1",
"output": "8"
},
{
"input": "1 5\n1",
"output": "7"
},
{
"input": "10 10\n10 10 10 10 10 10 10 10 10 10",
"output": "0"
},
{
"input": "2 3\n2 3",
"output": "0"
},
{
"input": "1 9\n9",
"output": "0"
},
{
"input": "74 2\n2 2 2 2 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 2 1 2 1 1 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 1 1 2 1 1 1 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 1 2",
"output": "0"
},
{
"input": "5 5\n5 5 5 5 4",
"output": "0"
}
] | 1,495,498,855
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 11
| 62
| 0
|
n, k = map(int, input().split())
A = sum(list(map(int, input().split())))
print(2 * n * k - n - 2 * A)
|
Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8.
For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8.
To graduate with «A» certificate, Noora has to have mark *k*.
Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack.
Output Specification:
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*.
Demo Input:
['2 10\n8 9\n', '3 5\n4 4 4\n']
Demo Output:
['4', '3']
Note:
Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation.
In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
|
```python
n, k = map(int, input().split())
A = sum(list(map(int, input().split())))
print(2 * n * k - n - 2 * A)
```
| 0
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful.
Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters.
Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with.
|
The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character.
|
If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.
If there are several possible answers, you may output any of them.
|
[
"(((#)((#)\n",
"()((#((#(#()\n",
"#\n",
"(#)\n"
] |
[
"1\n2\n",
"2\n2\n1",
"-1\n",
"-1\n"
] |
|*s*| denotes the length of the string *s*.
| 0
|
[
{
"input": "(((#)((#)",
"output": "1\n2"
},
{
"input": "()((#((#(#()",
"output": "1\n1\n3"
},
{
"input": "#",
"output": "-1"
},
{
"input": "(#)",
"output": "-1"
},
{
"input": "(((((#(#(#(#()",
"output": "1\n1\n1\n5"
},
{
"input": "#))))",
"output": "-1"
},
{
"input": "((#(()#(##",
"output": "1\n1\n1\n1"
},
{
"input": "##((((((()",
"output": "-1"
},
{
"input": "(((((((((((((((((((###################",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "((#)(",
"output": "-1"
},
{
"input": "((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((##",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": ")((##((###",
"output": "-1"
},
{
"input": "(#))(#(#)((((#(##((#(#((((#(##((((((#((()(()(())((()#((((#((()((((#(((((#(##)(##()((((()())(((((#(((",
"output": "-1"
},
{
"input": "#(#(#((##((()))(((#)(#()#(((()()(()#(##(((()(((()))#(((((()(((((((()#((#((()(#(((()(()##(()(((()((#(",
"output": "-1"
},
{
"input": "((#(",
"output": "-1"
},
{
"input": "()#(#())()()#)(#)()##)#((()#)((#)()#())((#((((((((#)()()(()()(((((#)#(#((((#((##()(##(((#(()(#((#))#",
"output": "-1"
},
{
"input": "(())((((#)",
"output": "3"
},
{
"input": "(#(",
"output": "-1"
},
{
"input": "((#)(",
"output": "-1"
},
{
"input": "(((()#(#)(",
"output": "-1"
},
{
"input": "#((#",
"output": "-1"
},
{
"input": "(#((((()",
"output": "-1"
},
{
"input": "(#((",
"output": "-1"
},
{
"input": ")(((())#",
"output": "-1"
}
] | 1,418,492,989
| 4,789
|
Python 3
|
CHALLENGED
|
CHALLENGES
| 12
| 109
| 716,800
|
def main():
s = input()
cnt = cntx = 0
for c in s:
if c == '(':
cnt += 1
elif c == ')':
cnt -= 1
if cnt < 0:
print(-1)
return
else:
cnt -= 1
if cnt < 0:
print(-1)
return
cntx += 1
for x in range(cntx - 1):
print(1)
print(cnt + 1)
if __name__ == '__main__':
main()
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful.
Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters.
Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with.
Input Specification:
The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character.
Output Specification:
If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.
If there are several possible answers, you may output any of them.
Demo Input:
['(((#)((#)\n', '()((#((#(#()\n', '#\n', '(#)\n']
Demo Output:
['1\n2\n', '2\n2\n1', '-1\n', '-1\n']
Note:
|*s*| denotes the length of the string *s*.
|
```python
def main():
s = input()
cnt = cntx = 0
for c in s:
if c == '(':
cnt += 1
elif c == ')':
cnt -= 1
if cnt < 0:
print(-1)
return
else:
cnt -= 1
if cnt < 0:
print(-1)
return
cntx += 1
for x in range(cntx - 1):
print(1)
print(cnt + 1)
if __name__ == '__main__':
main()
```
| -1
|
|
934
|
B
|
A Prosperous Lot
|
PROGRAMMING
| 1,200
|
[
"constructive algorithms",
"implementation"
] | null | null |
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.
He would like to find a positive integer *n* not greater than 1018, such that there are exactly *k* loops in the decimal representation of *n*, or determine that such *n* does not exist.
A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms.
|
The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops.
|
Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018.
|
[
"2\n",
"6\n"
] |
[
"462",
"8080"
] |
none
| 1,000
|
[
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output": "6"
},
{
"input": "7",
"output": "8886"
},
{
"input": "8",
"output": "8888"
},
{
"input": "9",
"output": "88886"
},
{
"input": "10",
"output": "88888"
},
{
"input": "11",
"output": "888886"
},
{
"input": "12",
"output": "888888"
},
{
"input": "13",
"output": "8888886"
},
{
"input": "14",
"output": "8888888"
},
{
"input": "15",
"output": "88888886"
},
{
"input": "16",
"output": "88888888"
},
{
"input": "17",
"output": "888888886"
},
{
"input": "18",
"output": "888888888"
},
{
"input": "19",
"output": "8888888886"
},
{
"input": "20",
"output": "8888888888"
},
{
"input": "21",
"output": "88888888886"
},
{
"input": "22",
"output": "88888888888"
},
{
"input": "23",
"output": "888888888886"
},
{
"input": "24",
"output": "888888888888"
},
{
"input": "25",
"output": "8888888888886"
},
{
"input": "26",
"output": "8888888888888"
},
{
"input": "27",
"output": "88888888888886"
},
{
"input": "28",
"output": "88888888888888"
},
{
"input": "29",
"output": "888888888888886"
},
{
"input": "30",
"output": "888888888888888"
},
{
"input": "31",
"output": "8888888888888886"
},
{
"input": "32",
"output": "8888888888888888"
},
{
"input": "33",
"output": "88888888888888886"
},
{
"input": "34",
"output": "88888888888888888"
},
{
"input": "35",
"output": "888888888888888886"
},
{
"input": "36",
"output": "888888888888888888"
},
{
"input": "37",
"output": "-1"
},
{
"input": "38",
"output": "-1"
},
{
"input": "39",
"output": "-1"
},
{
"input": "40",
"output": "-1"
},
{
"input": "462",
"output": "-1"
},
{
"input": "1317",
"output": "-1"
},
{
"input": "88",
"output": "-1"
},
{
"input": "87",
"output": "-1"
}
] | 1,519,204,343
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 5
| 61
| 6,758,400
|
k=int(input())
if k==0:
print(1)
elif k%2==0:
print("8"*(k//2))
else:
print('9'*k)
|
Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.
He would like to find a positive integer *n* not greater than 1018, such that there are exactly *k* loops in the decimal representation of *n*, or determine that such *n* does not exist.
A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms.
Input Specification:
The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops.
Output Specification:
Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018.
Demo Input:
['2\n', '6\n']
Demo Output:
['462', '8080']
Note:
none
|
```python
k=int(input())
if k==0:
print(1)
elif k%2==0:
print("8"*(k//2))
else:
print('9'*k)
```
| 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,543,289,999
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 32
| 248
| 0
|
if __name__ == '__main__':
input()
numbers = [int(x) for x in input().split(' ')]
even = 0
odd = 0
for n in numbers:
if n % 2 == 0:
even += 1
else:
odd += 1
if even > odd:
# find the index of the odd number
for i, n in enumerate(numbers):
if n % 2 == 1:
print(i + 1)
break
else:
# find the index of the even number
for i, n in enumerate(numbers):
if n % 2 == 0:
print(i + 1)
break
|
Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none
|
```python
if __name__ == '__main__':
input()
numbers = [int(x) for x in input().split(' ')]
even = 0
odd = 0
for n in numbers:
if n % 2 == 0:
even += 1
else:
odd += 1
if even > odd:
# find the index of the odd number
for i, n in enumerate(numbers):
if n % 2 == 1:
print(i + 1)
break
else:
# find the index of the even number
for i, n in enumerate(numbers):
if n % 2 == 0:
print(i + 1)
break
```
| 3.938
|
522
|
B
|
Photo to Remember
|
PROGRAMMING
| 1,100
|
[
"*special",
"data structures",
"dp",
"implementation"
] | null | null |
One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the *i*-th of them occupies the rectangle of width *w**i* pixels and height *h**i* pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is *W*<=×<=*H*, where *W* is the total sum of all widths and *H* is the maximum height of all the photographed friends.
As is usually the case, the friends made *n* photos — the *j*-th (1<=≤<=*j*<=≤<=*n*) photo had everybody except for the *j*-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
|
The first line contains integer *n* (2<=≤<=*n*<=≤<=200<=000) — the number of friends.
Then *n* lines follow: the *i*-th line contains information about the *i*-th friend. The line contains a pair of integers *w**i*,<=*h**i* (1<=≤<=*w**i*<=≤<=10,<=1<=≤<=*h**i*<=≤<=1000) — the width and height in pixels of the corresponding rectangle.
|
Print *n* space-separated numbers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* — the total number of pixels on the minimum photo containing all friends expect for the *i*-th one.
|
[
"3\n1 10\n5 5\n10 1\n",
"3\n2 1\n1 2\n2 1\n"
] |
[
"75 110 60 ",
"6 4 6 "
] |
none
| 1,000
|
[
{
"input": "3\n1 10\n5 5\n10 1",
"output": "75 110 60 "
},
{
"input": "3\n2 1\n1 2\n2 1",
"output": "6 4 6 "
},
{
"input": "2\n1 5\n2 3",
"output": "6 5 "
},
{
"input": "2\n2 3\n1 1",
"output": "1 6 "
},
{
"input": "3\n1 10\n2 10\n3 10",
"output": "50 40 30 "
},
{
"input": "3\n2 10\n1 9\n3 7",
"output": "36 50 30 "
},
{
"input": "3\n1 1\n3 2\n2 3",
"output": "15 9 8 "
},
{
"input": "3\n3 123\n1 456\n2 789",
"output": "2367 3945 1824 "
},
{
"input": "3\n2 987\n3 654\n1 321",
"output": "2616 2961 4935 "
},
{
"input": "3\n3 143\n2 543\n1 893",
"output": "2679 3572 2715 "
},
{
"input": "2\n1 1\n1 2",
"output": "2 1 "
},
{
"input": "3\n2 22\n1 11\n2 22",
"output": "66 88 66 "
},
{
"input": "3\n1 11\n1 12\n1 13",
"output": "26 26 24 "
},
{
"input": "3\n1 11\n1 12\n2 10",
"output": "36 33 24 "
},
{
"input": "10\n6 20\n1 175\n1 758\n1 169\n2 490\n2 600\n4 463\n7 377\n9 40\n4 961",
"output": "29791 34596 34596 34596 33635 33635 31713 28830 26908 25014 "
},
{
"input": "10\n8 158\n1 709\n6 766\n4 335\n5 356\n2 972\n1 108\n4 235\n3 631\n1 414",
"output": "26244 33048 28188 30132 29160 25278 33048 30132 31104 33048 "
},
{
"input": "10\n7 549\n9 115\n8 141\n3 650\n5 730\n3 841\n7 18\n9 170\n2 217\n1 155",
"output": "39527 37845 38686 42891 41209 37230 39527 37845 43732 44573 "
},
{
"input": "10\n6 386\n9 816\n9 268\n9 481\n8 284\n10 715\n9 351\n7 580\n4 327\n7 392",
"output": "58752 49335 56304 56304 57120 55488 56304 57936 60384 57936 "
},
{
"input": "10\n9 292\n4 6\n6 638\n8 461\n10 970\n10 488\n9 769\n10 644\n8 280\n5 334",
"output": "67900 72750 70810 68870 53061 66930 67900 66930 68870 71780 "
},
{
"input": "10\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000",
"output": "90000 90000 90000 90000 90000 90000 90000 90000 90000 90000 "
}
] | 1,529,136,640
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 44
| 1,669
| 19,046,400
|
n=int(input())
w=[0]*n
h=[0]*n
c=[x for x in range(n)]
ss=0
for i in range(n):
w[i],h[i]=map(int,input().split())
ss+=w[i]
s=sorted(zip(h,c))
a=s[n-1][1]
b=s[n-2][1]
for i in range(n):
vv=ss-w[i]
if(i==a):
cc=h[b]
else:
cc=h[a]
print(cc*vv,end=" ")
|
Title: Photo to Remember
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the *i*-th of them occupies the rectangle of width *w**i* pixels and height *h**i* pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is *W*<=×<=*H*, where *W* is the total sum of all widths and *H* is the maximum height of all the photographed friends.
As is usually the case, the friends made *n* photos — the *j*-th (1<=≤<=*j*<=≤<=*n*) photo had everybody except for the *j*-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=200<=000) — the number of friends.
Then *n* lines follow: the *i*-th line contains information about the *i*-th friend. The line contains a pair of integers *w**i*,<=*h**i* (1<=≤<=*w**i*<=≤<=10,<=1<=≤<=*h**i*<=≤<=1000) — the width and height in pixels of the corresponding rectangle.
Output Specification:
Print *n* space-separated numbers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* — the total number of pixels on the minimum photo containing all friends expect for the *i*-th one.
Demo Input:
['3\n1 10\n5 5\n10 1\n', '3\n2 1\n1 2\n2 1\n']
Demo Output:
['75 110 60 ', '6 4 6 ']
Note:
none
|
```python
n=int(input())
w=[0]*n
h=[0]*n
c=[x for x in range(n)]
ss=0
for i in range(n):
w[i],h[i]=map(int,input().split())
ss+=w[i]
s=sorted(zip(h,c))
a=s[n-1][1]
b=s[n-2][1]
for i in range(n):
vv=ss-w[i]
if(i==a):
cc=h[b]
else:
cc=h[a]
print(cc*vv,end=" ")
```
| 3
|
|
363
|
B
|
Fence
|
PROGRAMMING
| 1,100
|
[
"brute force",
"dp"
] | null | null |
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible.
Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
|
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence.
|
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
|
[
"7 3\n1 2 6 1 1 7 1\n"
] |
[
"3\n"
] |
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
| 1,000
|
[
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"input": "2 2\n20 10",
"output": "1"
},
{
"input": "2 1\n20 1",
"output": "2"
},
{
"input": "3 1\n1 2 3",
"output": "1"
},
{
"input": "3 1\n2 1 3",
"output": "2"
},
{
"input": "3 1\n3 2 1",
"output": "3"
},
{
"input": "3 2\n1 2 3",
"output": "1"
},
{
"input": "3 2\n3 2 1",
"output": "2"
},
{
"input": "3 3\n1 2 3",
"output": "1"
},
{
"input": "4 2\n9 8 11 7",
"output": "1"
},
{
"input": "4 2\n10 1 2 3",
"output": "2"
},
{
"input": "6 3\n56 56 56 2 1 2",
"output": "4"
},
{
"input": "8 3\n1 1 1 1 2 60 90 1",
"output": "1"
},
{
"input": "4 1\n1 5 2 2",
"output": "1"
},
{
"input": "4 2\n4 6 7 4",
"output": "1"
},
{
"input": "10 4\n1 1 1 4 4 4 4 4 4 3",
"output": "1"
},
{
"input": "6 3\n1 2 1 3 1 1",
"output": "1"
},
{
"input": "5 2\n100 100 100 1 1",
"output": "4"
}
] | 1,668,089,061
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 51
| 124
| 20,172,800
|
"""THIS TEMPLATE belongs to anuj_negi"""
#Try to use bisect in case of binary search, bisect_left, bisect_right
#Try to use sortedcontainers when available
#Try to use Multiset when available
from bisect import *
from heapq import *
#from functools import cache, lru_cache
from math import *
from collections import defaultdict as ddc
from collections import Counter
from functools import *
from itertools import *
from sys import setrecursionlimit
def intin(): return int(input())
def mapin(): return map(int, input().split())
def strin(): return input().split()
#----------------------------------------------
"""
SOME FACTS THAT CAN BE USED LATER -
-> if n is prime, then -> (a**(n-1)) % n = 1
-> When cases like DEFICIENT CITY to SURPLUS CITY, work on BFS using SURPLUS city and check for DEFICIENT city
-> PALINDROMEs and str-len FACTORS have some relations. if P = XQ where P, X, Q are palindromes, then X have the possible length in Factors of 'n'
"""
#----------------------------------------------
"""
-> THIS IS A Interval Based Segmented Trees
-> Can be modified or used later for similar
"""
class IntervalSeg:
def __init__(self):
self.Seg = ddc(int)
self.otherAdded = ddc(int)
def update(self, s, e, l = 0, r = 10**9, index = 1):
if r<=s or e<=l: return
if s<=l<r<=e:
self.Seg[index]+=1
self.otherAdded[index]+=1
else:
m = (l+r)//2
self.update(s, e, l, m, 2*index)
self.update(s, e, m, r, 2*index + 1)
self.Seg[index] = self.otherAdded[index] + max(self.Seg[2*index], self.Seg[2*index + 1])
def use(self, start, end):
self.update(start, end)
return self.Seg[1]
#----------------------------------------------
INF = 10**20
mod = 1000000007
#----------------------------------------------
def hashit(arr, size, mod = (10**9 + 7)):
#Subarray size - Rolling Hash - Custom
"""
mul -> must be greater than max(arr)
rest can be modified
"""
if not size: return
mul, hashh, div = 256, 0, (1<<(8*size-8))%mod
C = ddc(list)
for i in range(size):
hashh = (mul * hashh + arr[i])%mod
C[hashh].append(0)
for i in range(len(arr)-size):
#update the hashh
hashh = (mul*(hashh-arr[i]*div) + arr[i+size])%mod
C[hashh].append(i+1)
return C
#----------------------------------------------
def LIS(arr, n):
dp = [10**9]*(n+1)
for ele in arr:
dp[bisect_left(dp, ele)] = ele
#print(dp)
return bisect_left(dp, 10**9)
#----------------------------------------------
def exponentiation(bas, exp, mod = (10**9 + 7)):
t = 1
while(exp > 0):
if (exp % 2 != 0):
t = (t * bas) % mod
bas = (bas * bas) % mod
exp //= 2
return t % mod
#----------------------------------------------
def MOD(p, q=1, mod = 1000000007):
expo = 0
expo = mod - 2
while (expo):
if (expo & 1):
p = (p * q) % mod
q = (q * q) % mod
expo >>= 1
return p
#----------------------------------------------
yes = "YES"
no = "NO"
even = "EVEN"
odd = "ODD"
alice = "ALICE"
bob = "BOB"
#------------------------
def graphin(n):
zz = ddc(set)
for i in range(n-1):
a, b = mapin()
zz[a].add(b)
zz[b].add(a)
return zz
def process(arr, n, k):
ans = [1e9, 0]
curr = 0
for i in range(k):
curr += arr[i]
ans[0] = curr
for i in range(n-k):
curr = curr-arr[i]+arr[i+k]
if curr<ans[0]:
ans = [curr, i+1]
return ans[1]+1
def main():
#T-testcases
#graph = graphin(n)
n, k = mapin()
arr = list(mapin())
ans = process(arr, n, k)
print(ans)
#print("Case {0}: {1}".format(ans, _+1))
#--------------------------
if __name__ == "__main__":
main()
|
Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible.
Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
Input Specification:
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence.
Output Specification:
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
Demo Input:
['7 3\n1 2 6 1 1 7 1\n']
Demo Output:
['3\n']
Note:
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
|
```python
"""THIS TEMPLATE belongs to anuj_negi"""
#Try to use bisect in case of binary search, bisect_left, bisect_right
#Try to use sortedcontainers when available
#Try to use Multiset when available
from bisect import *
from heapq import *
#from functools import cache, lru_cache
from math import *
from collections import defaultdict as ddc
from collections import Counter
from functools import *
from itertools import *
from sys import setrecursionlimit
def intin(): return int(input())
def mapin(): return map(int, input().split())
def strin(): return input().split()
#----------------------------------------------
"""
SOME FACTS THAT CAN BE USED LATER -
-> if n is prime, then -> (a**(n-1)) % n = 1
-> When cases like DEFICIENT CITY to SURPLUS CITY, work on BFS using SURPLUS city and check for DEFICIENT city
-> PALINDROMEs and str-len FACTORS have some relations. if P = XQ where P, X, Q are palindromes, then X have the possible length in Factors of 'n'
"""
#----------------------------------------------
"""
-> THIS IS A Interval Based Segmented Trees
-> Can be modified or used later for similar
"""
class IntervalSeg:
def __init__(self):
self.Seg = ddc(int)
self.otherAdded = ddc(int)
def update(self, s, e, l = 0, r = 10**9, index = 1):
if r<=s or e<=l: return
if s<=l<r<=e:
self.Seg[index]+=1
self.otherAdded[index]+=1
else:
m = (l+r)//2
self.update(s, e, l, m, 2*index)
self.update(s, e, m, r, 2*index + 1)
self.Seg[index] = self.otherAdded[index] + max(self.Seg[2*index], self.Seg[2*index + 1])
def use(self, start, end):
self.update(start, end)
return self.Seg[1]
#----------------------------------------------
INF = 10**20
mod = 1000000007
#----------------------------------------------
def hashit(arr, size, mod = (10**9 + 7)):
#Subarray size - Rolling Hash - Custom
"""
mul -> must be greater than max(arr)
rest can be modified
"""
if not size: return
mul, hashh, div = 256, 0, (1<<(8*size-8))%mod
C = ddc(list)
for i in range(size):
hashh = (mul * hashh + arr[i])%mod
C[hashh].append(0)
for i in range(len(arr)-size):
#update the hashh
hashh = (mul*(hashh-arr[i]*div) + arr[i+size])%mod
C[hashh].append(i+1)
return C
#----------------------------------------------
def LIS(arr, n):
dp = [10**9]*(n+1)
for ele in arr:
dp[bisect_left(dp, ele)] = ele
#print(dp)
return bisect_left(dp, 10**9)
#----------------------------------------------
def exponentiation(bas, exp, mod = (10**9 + 7)):
t = 1
while(exp > 0):
if (exp % 2 != 0):
t = (t * bas) % mod
bas = (bas * bas) % mod
exp //= 2
return t % mod
#----------------------------------------------
def MOD(p, q=1, mod = 1000000007):
expo = 0
expo = mod - 2
while (expo):
if (expo & 1):
p = (p * q) % mod
q = (q * q) % mod
expo >>= 1
return p
#----------------------------------------------
yes = "YES"
no = "NO"
even = "EVEN"
odd = "ODD"
alice = "ALICE"
bob = "BOB"
#------------------------
def graphin(n):
zz = ddc(set)
for i in range(n-1):
a, b = mapin()
zz[a].add(b)
zz[b].add(a)
return zz
def process(arr, n, k):
ans = [1e9, 0]
curr = 0
for i in range(k):
curr += arr[i]
ans[0] = curr
for i in range(n-k):
curr = curr-arr[i]+arr[i+k]
if curr<ans[0]:
ans = [curr, i+1]
return ans[1]+1
def main():
#T-testcases
#graph = graphin(n)
n, k = mapin()
arr = list(mapin())
ans = process(arr, n, k)
print(ans)
#print("Case {0}: {1}".format(ans, _+1))
#--------------------------
if __name__ == "__main__":
main()
```
| 3
|
|
88
|
A
|
Chord
|
PROGRAMMING
| 1,200
|
[
"brute force",
"implementation"
] |
A. Chord
|
2
|
256
|
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes *X*, *Y* and *Z*. If we can order the notes so as the distance along the musical scale between *X* and *Y* equals 4 semitones and the distance between *Y* and *Z* is 3 semitones, then the triad is major. The distance between *X* and *Z*, accordingly, equals 7 semitones.
A minor triad is different in that the distance between *X* and *Y* should be 3 semitones and between *Y* and *Z* — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
|
The only line contains 3 space-separated notes in the above-given notation.
|
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
|
[
"C E G\n",
"C# B F\n",
"A B H\n"
] |
[
"major\n",
"minor\n",
"strange\n"
] |
none
| 500
|
[
{
"input": "C E G",
"output": "major"
},
{
"input": "C# B F",
"output": "minor"
},
{
"input": "A B H",
"output": "strange"
},
{
"input": "G H E",
"output": "minor"
},
{
"input": "D# B G",
"output": "major"
},
{
"input": "D# B F#",
"output": "minor"
},
{
"input": "F H E",
"output": "strange"
},
{
"input": "B F# G",
"output": "strange"
},
{
"input": "F# H C",
"output": "strange"
},
{
"input": "C# F C",
"output": "strange"
},
{
"input": "G# C# E",
"output": "minor"
},
{
"input": "D# H G#",
"output": "minor"
},
{
"input": "C F A",
"output": "major"
},
{
"input": "H E G#",
"output": "major"
},
{
"input": "G D# B",
"output": "major"
},
{
"input": "E C G",
"output": "major"
},
{
"input": "G# C# F",
"output": "major"
},
{
"input": "D# C G#",
"output": "major"
},
{
"input": "C# F B",
"output": "minor"
},
{
"input": "D# C G",
"output": "minor"
},
{
"input": "A D F",
"output": "minor"
},
{
"input": "F# H D",
"output": "minor"
},
{
"input": "D A F",
"output": "minor"
},
{
"input": "D A F#",
"output": "major"
},
{
"input": "C# B F",
"output": "minor"
},
{
"input": "A C F",
"output": "major"
},
{
"input": "D F# H",
"output": "minor"
},
{
"input": "H G# D#",
"output": "minor"
},
{
"input": "A D F#",
"output": "major"
},
{
"input": "H E G#",
"output": "major"
},
{
"input": "D# B F#",
"output": "minor"
},
{
"input": "D# H F#",
"output": "major"
},
{
"input": "A D F#",
"output": "major"
},
{
"input": "B G D#",
"output": "major"
},
{
"input": "E A C#",
"output": "major"
},
{
"input": "D H G",
"output": "major"
},
{
"input": "H D F#",
"output": "minor"
},
{
"input": "G D# C",
"output": "minor"
},
{
"input": "H D G",
"output": "major"
},
{
"input": "E C G",
"output": "major"
},
{
"input": "D# A E",
"output": "strange"
},
{
"input": "A F E",
"output": "strange"
},
{
"input": "C E F",
"output": "strange"
},
{
"input": "A B C",
"output": "strange"
},
{
"input": "E F D#",
"output": "strange"
},
{
"input": "C G# G#",
"output": "strange"
},
{
"input": "F D# G#",
"output": "strange"
},
{
"input": "B G D#",
"output": "major"
},
{
"input": "E E G#",
"output": "strange"
},
{
"input": "A G H",
"output": "strange"
},
{
"input": "F E A",
"output": "strange"
},
{
"input": "D B E",
"output": "strange"
},
{
"input": "G# C# D",
"output": "strange"
},
{
"input": "D# D# F#",
"output": "strange"
},
{
"input": "H B G",
"output": "strange"
},
{
"input": "D C B",
"output": "strange"
},
{
"input": "D B B",
"output": "strange"
},
{
"input": "C A H",
"output": "strange"
},
{
"input": "F# H F#",
"output": "strange"
},
{
"input": "A F F#",
"output": "strange"
},
{
"input": "C D C",
"output": "strange"
},
{
"input": "G F# A",
"output": "strange"
},
{
"input": "C C# D",
"output": "strange"
},
{
"input": "C A E",
"output": "minor"
},
{
"input": "A H B",
"output": "strange"
},
{
"input": "B E F#",
"output": "strange"
},
{
"input": "G# G# A",
"output": "strange"
},
{
"input": "B C# C#",
"output": "strange"
},
{
"input": "C G D#",
"output": "minor"
},
{
"input": "C B D#",
"output": "strange"
},
{
"input": "F H F",
"output": "strange"
},
{
"input": "E G# C",
"output": "strange"
},
{
"input": "F# F# F#",
"output": "strange"
},
{
"input": "F C F",
"output": "strange"
},
{
"input": "A F D",
"output": "minor"
}
] | 1,655,735,496
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 62
| 0
|
chord=[ "C", "C#", "D"," D#", "E", "F", "F#", "G", "G#", "A", "B", "H"]
vor=list(input().split())
chord+=chord
vorind=[]
for i in range(len(chord)):
if vor[0]==chord[i]:
vorind.append(i)
break
for i in range(2):
for j in range(len(chord)):
if vor[i+1] == chord[j] and j > vorind[i]:
vorind.append(j)
break
if vorind[2]-vorind[1]==3 and vorind[1]-vorind[0]==4:
print("major")
elif vorind[2]-vorind[1]==4 and vorind[1]-vorind[0]==3:
print("minor")
else:
print("strange")
|
Title: Chord
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes *X*, *Y* and *Z*. If we can order the notes so as the distance along the musical scale between *X* and *Y* equals 4 semitones and the distance between *Y* and *Z* is 3 semitones, then the triad is major. The distance between *X* and *Z*, accordingly, equals 7 semitones.
A minor triad is different in that the distance between *X* and *Y* should be 3 semitones and between *Y* and *Z* — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input Specification:
The only line contains 3 space-separated notes in the above-given notation.
Output Specification:
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Demo Input:
['C E G\n', 'C# B F\n', 'A B H\n']
Demo Output:
['major\n', 'minor\n', 'strange\n']
Note:
none
|
```python
chord=[ "C", "C#", "D"," D#", "E", "F", "F#", "G", "G#", "A", "B", "H"]
vor=list(input().split())
chord+=chord
vorind=[]
for i in range(len(chord)):
if vor[0]==chord[i]:
vorind.append(i)
break
for i in range(2):
for j in range(len(chord)):
if vor[i+1] == chord[j] and j > vorind[i]:
vorind.append(j)
break
if vorind[2]-vorind[1]==3 and vorind[1]-vorind[0]==4:
print("major")
elif vorind[2]-vorind[1]==4 and vorind[1]-vorind[0]==3:
print("minor")
else:
print("strange")
```
| 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,375,931
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 28
| 46
| 0
|
a,b=map(int,input().split())
c=1
x=b-1
while c<=a:
if c%4==0:
print('#'+str('.'*x))
c +=1
elif c%2==0:
print(str('.'* x)+'#')
c +=1
else:
print('#'*b)
c+=1
|
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().split())
c=1
x=b-1
while c<=a:
if c%4==0:
print('#'+str('.'*x))
c +=1
elif c%2==0:
print(str('.'* x)+'#')
c +=1
else:
print('#'*b)
c+=1
```
| 3
|
|
265
|
A
|
Colorful Stones (Simplified Edition)
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
|
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
|
Print the final 1-based position of Liss in a single line.
|
[
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] |
[
"2\n",
"3\n",
"15\n"
] |
none
| 500
|
[
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
{
"input": "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB",
"output": "1"
},
{
"input": "RRGGBRGRBG\nBRRGGBBGGR",
"output": "7"
},
{
"input": "BBRRGBGGRGBRGBRBRBGR\nGGGRBGGGBRRRRGRBGBGRGRRBGRBGBG",
"output": "15"
},
{
"input": "GBRRBGBGBBBBRRRGBGRRRGBGBBBRGR\nRRGBRRGRBBBBBBGRRBBR",
"output": "8"
},
{
"input": "BRGRRGRGRRGBBGBBBRRBBRRBGBBGRGBBGGRGBRBGGGRRRBGGBB\nRGBBGRRBBBRRGRRBRBBRGBBGGGRGBGRRRRBRBGGBRBGGGRGBRR",
"output": "16"
},
{
"input": "GGRGGBRRGRGBRRGGRBBGGRRGBBBGBBBGGRBGGBRBBRGBRRRBRG\nGGRGRRRRRRRRRGBBBBRGBRGRGRRGBBRGGBRBBRBGBRGRRRRGGR",
"output": "18"
},
{
"input": "RBBRBGBBGGGBRRBGBRGRRGGRBBBBGRBGGBRRBGBBRBRGBBGGGG\nBRRGRBGRBGBRGBRBGGBBBGBBRGRBGRGRBGRBGGRRBGBRGRRBBG",
"output": "23"
},
{
"input": "RRGGRRBRGRGBRGBRGBBRGGGBRBGBRGBRGGBRBRGBGRRBBGGRBR\nBRGRBBBGRBGRRGGRRRRRRRRGGGGGGGGBGGGGGGGRGRBBRGRGBR",
"output": "14"
},
{
"input": "RBRBRRRRRGGR\nBBBBRRGGBGRBRGBBRGGGRGGBRRBRBRBGGG",
"output": "12"
},
{
"input": "GGRGGGBRGRGRBBRGGGRBGRRR\nGBBBBGBGBGBBBRGGRGGBGRRGRRRGBGB",
"output": "12"
},
{
"input": "RGRBGBRBBGBRRGGGBBGBRRBGRGBBBBBGRRRGGRBB\nBGR",
"output": "2"
},
{
"input": "R\nB",
"output": "1"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "50"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
},
{
"input": "R\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
}
] | 1,678,023,561
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 19
| 154
| 0
|
def colourfulstones(a,b):
i,j=0,0
while i<len(a) and j<len(b):
if a[i]==b[j]:
i=i+1
j=j+1
return i+1
s=str(input())
t=str(input())
print(colourfulstones(s,t))
|
Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input Specification:
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output Specification:
Print the final 1-based position of Liss in a single line.
Demo Input:
['RGB\nRRR\n', 'RRRBGBRBBB\nBBBRR\n', 'BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n']
Demo Output:
['2\n', '3\n', '15\n']
Note:
none
|
```python
def colourfulstones(a,b):
i,j=0,0
while i<len(a) and j<len(b):
if a[i]==b[j]:
i=i+1
j=j+1
return i+1
s=str(input())
t=str(input())
print(colourfulstones(s,t))
```
| 3
|
|
965
|
A
|
Paper Airplanes
|
PROGRAMMING
| 800
|
[
"math"
] | null | null |
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy?
|
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
|
Print a single integer — the minimum number of packs they should buy.
|
[
"5 3 2 3\n",
"5 3 100 1\n"
] |
[
"4\n",
"5\n"
] |
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets.
| 500
|
[
{
"input": "5 3 2 3",
"output": "4"
},
{
"input": "5 3 100 1",
"output": "5"
},
{
"input": "10000 10000 1 1",
"output": "100000000"
},
{
"input": "1 1 10000 10000",
"output": "1"
},
{
"input": "300 300 21 23",
"output": "196"
},
{
"input": "300 2 37 51",
"output": "6"
},
{
"input": "2 400 23 57",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "10000 10000 3 2",
"output": "16670000"
},
{
"input": "1 2 1 2",
"output": "1"
},
{
"input": "1 1 2 2",
"output": "1"
},
{
"input": "1 1 10 10",
"output": "1"
},
{
"input": "5324 5439 32 13",
"output": "69622"
},
{
"input": "9000 1 2432 1",
"output": "9000"
},
{
"input": "230 1234 9124 23",
"output": "10"
},
{
"input": "11 1 1 1",
"output": "11"
},
{
"input": "6246 8489 1227 9",
"output": "4858"
},
{
"input": "9 20 5 7",
"output": "6"
}
] | 1,581,590,333
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 18
| 109
| 0
|
import math
k,n,s,p=map(int,input().split())
z=(math.ceil(n/s))*k
print(math.ceil(z/p))
|
Title: Paper Airplanes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy?
Input Specification:
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output Specification:
Print a single integer — the minimum number of packs they should buy.
Demo Input:
['5 3 2 3\n', '5 3 100 1\n']
Demo Output:
['4\n', '5\n']
Note:
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets.
|
```python
import math
k,n,s,p=map(int,input().split())
z=(math.ceil(n/s))*k
print(math.ceil(z/p))
```
| 3
|
|
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,602,750,141
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 57
| 248
| 0
|
lz = 0
lo = 0
rz = 0
ro = 0
for i in range(int(input())):
l,r = list(map(int,input().split()))
if l==0:
lz+=1
else:
lo+=1
if r==0:
rz += 1
else:
ro += 1
print(min(lz,lo)+min(ro,rz))
|
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
lz = 0
lo = 0
rz = 0
ro = 0
for i in range(int(input())):
l,r = list(map(int,input().split()))
if l==0:
lz+=1
else:
lo+=1
if r==0:
rz += 1
else:
ro += 1
print(min(lz,lo)+min(ro,rz))
```
| 3
|
|
540
|
A
|
Combination Lock
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
|
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
|
[
"5\n82195\n64723\n"
] |
[
"13\n"
] |
In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
| 500
|
[
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
"input": "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746",
"output": "245"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "3\n607\n684",
"output": "5"
},
{
"input": "4\n0809\n0636",
"output": "8"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8037856825987124762280548\n9519431339078678836940020",
"output": "72"
},
{
"input": "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024",
"output": "305"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8037856825987124762285484\n9519431339078678836940202",
"output": "74"
},
{
"input": "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831",
"output": "357"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8378525987476228048406972\n9194339078883694020217816",
"output": "55"
},
{
"input": "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599",
"output": "274"
},
{
"input": "1\n0\n0",
"output": "0"
},
{
"input": "1\n7\n7",
"output": "0"
},
{
"input": "1\n0\n5",
"output": "5"
},
{
"input": "1\n2\n7",
"output": "5"
},
{
"input": "1\n7\n9",
"output": "2"
},
{
"input": "1\n9\n7",
"output": "2"
},
{
"input": "1\n2\n9",
"output": "3"
},
{
"input": "1\n9\n2",
"output": "3"
},
{
"input": "25\n3164978461316464614169874\n9413979197249127496597357",
"output": "66"
},
{
"input": "4\n9999\n9999",
"output": "0"
},
{
"input": "2\n11\n11",
"output": "0"
}
] | 1,614,797,346
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 43
| 109
| 0
|
n = int(input())
a = input()
b = input()
def get_diff(x, y):
x, y = int(x), int(y)
return min(abs(x - y), x + 10 - y, 10 - x + y)
ans = 0
for i in range(n):
ans += get_diff(a[i], b[i])
print(ans)
|
Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Output Specification:
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
Demo Input:
['5\n82195\n64723\n']
Demo Output:
['13\n']
Note:
In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
|
```python
n = int(input())
a = input()
b = input()
def get_diff(x, y):
x, y = int(x), int(y)
return min(abs(x - y), x + 10 - y, 10 - x + y)
ans = 0
for i in range(n):
ans += get_diff(a[i], b[i])
print(ans)
```
| 3
|
|
744
|
C
|
Hongcow Buys a Deck of Cards
|
PROGRAMMING
| 2,400
|
[
"bitmasks",
"brute force",
"dp"
] | null | null |
One day, Hongcow goes to the store and sees a brand new deck of *n* special cards. Each individual card is either red or blue. He decides he wants to buy them immediately. To do this, he needs to play a game with the owner of the store.
This game takes some number of turns to complete. On a turn, Hongcow may do one of two things:
- Collect tokens. Hongcow collects 1 red token and 1 blue token by choosing this option (thus, 2 tokens in total per one operation). - Buy a card. Hongcow chooses some card and spends tokens to purchase it as specified below.
The *i*-th card requires *r**i* red resources and *b**i* blue resources. Suppose Hongcow currently has *A* red cards and *B* blue cards. Then, the *i*-th card will require Hongcow to spend *max*(*r**i*<=-<=*A*,<=0) red tokens, and *max*(*b**i*<=-<=*B*,<=0) blue tokens. Note, only tokens disappear, but the cards stay with Hongcow forever. Each card can be bought only once.
Given a description of the cards and their costs determine the minimum number of turns Hongcow needs to purchase all cards.
|
The first line of input will contain a single integer *n* (1<=≤<=*n*<=≤<=16).
The next *n* lines of input will contain three tokens *c**i*, *r**i* and *b**i*. *c**i* will be 'R' or 'B', denoting the color of the card as red or blue. *r**i* will be an integer denoting the amount of red resources required to obtain the card, and *b**i* will be an integer denoting the amount of blue resources required to obtain the card (0<=≤<=*r**i*,<=*b**i*<=≤<=107).
|
Output a single integer, denoting the minimum number of turns needed to acquire all the cards.
|
[
"3\nR 0 1\nB 1 0\nR 1 1\n",
"3\nR 3 0\nR 2 0\nR 1 0\n"
] |
[
"4\n",
"6\n"
] |
For the first sample, Hongcow's four moves are as follows:
1. Collect tokens 1. Buy card 1 1. Buy card 2 1. Buy card 3
For the second sample, one optimal strategy is as follows:
1. Collect tokens 1. Collect tokens 1. Buy card 2 1. Collect tokens 1. Buy card 3 1. Buy card 1
| 1,750
|
[
{
"input": "3\nR 0 1\nB 1 0\nR 1 1",
"output": "4"
},
{
"input": "3\nR 3 0\nR 2 0\nR 1 0",
"output": "6"
},
{
"input": "8\nB 0 1\nR 2 3\nB 2 1\nR 4 2\nB 1 3\nB 1 10\nB 3 4\nR 3 4",
"output": "17"
},
{
"input": "16\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000",
"output": "160000016"
},
{
"input": "16\nB 7 5\nB 3 16\nB 8 15\nR 11 1\nR 13 14\nB 0 9\nR 2 0\nR 7 14\nB 11 6\nR 16 2\nB 3 2\nB 0 6\nR 11 7\nR 15 4\nB 2 9\nB 7 13",
"output": "78"
},
{
"input": "16\nB 1 8676796\nB 0 8580604\nB 8174626 1318206\nB 16 3440389\nB 3756148 7936397\nB 10 16\nB 9 10\nB 15 6\nB 15 8227291\nB 16 1620609\nB 15 4853663\nB 3 12\nB 7 5\nB 14 3597451\nB 340789 2345477\nB 3250968 6094874",
"output": "56691702"
},
{
"input": "16\nB 9 3105751\nR 2 7471542\nR 10 586804\nB 6430003 13\nR 2499494 421369\nB 15 6781522\nB 3963729 2\nR 5415223 1877343\nB 1 3992706\nR 8 430677\nB 890666 16\nB 16 1\nB 6 1289788\nB 6737490 11\nR 6473547 4969305\nR 9328312 10",
"output": "41738470"
},
{
"input": "16\nB 7 10\nB 6362480 9731034\nB 12 2191046\nR 10 5\nB 3904695 40732\nB 5 11\nB 181094 5743754\nR 139173 4\nB 9893259 12\nR 12 7283868\nB 9308033 742089\nB 16 4013981\nB 6996517 4733956\nR 9581205 682792\nB 1 16\nB 7 886568",
"output": "46366491"
},
{
"input": "5\nR 0 4\nR 0 1\nB 5 4\nR 4 2\nB 1 2",
"output": "12"
},
{
"input": "16\nB 2 14\nR 6 13\nR 4 12\nR 3 3\nB 21 8\nB 4 3\nB 10 10\nR 21 13\nR 16 13\nR 0 14\nR 16 18\nB 6 13\nR 14 8\nB 18 14\nB 2 20\nR 11 9",
"output": "126"
},
{
"input": "15\nR 0 11\nB 1 10\nR 21 13\nR 18 16\nB 1 4\nR 18 9\nR 15 10\nB 4 1\nB 9 9\nR 14 13\nB 1 16\nR 3 7\nR 2 7\nR 17 4\nR 13 5",
"output": "99"
},
{
"input": "14\nB 9 9\nR 6 20\nB 3 6\nR 7 20\nR 20 8\nR 19 15\nB 7 14\nB 20 7\nB 9 9\nB 11 1\nR 4 15\nB 13 14\nB 21 2\nB 5 12",
"output": "122"
},
{
"input": "13\nB 15 14\nB 20 17\nB 3 7\nR 14 15\nB 8 7\nB 16 17\nB 17 11\nR 21 13\nB 6 0\nB 3 8\nB 15 2\nB 9 21\nB 14 12",
"output": "151"
},
{
"input": "12\nB 20 11\nR 7 6\nR 20 0\nB 11 2\nB 5 3\nB 13 1\nB 8 15\nR 8 20\nB 16 0\nB 14 10\nB 1 4\nR 20 15",
"output": "120"
},
{
"input": "7\nR 10 6\nR 18 2\nB 19 6\nR 0 2\nR 16 14\nR 8 6\nR 17 18",
"output": "74"
},
{
"input": "6\nB 16 7\nB 13 9\nB 1 17\nB 11 11\nB 5 14\nB 5 12",
"output": "61"
},
{
"input": "5\nR 3 4\nB 18 6\nR 4 18\nB 8 16\nB 19 10",
"output": "53"
},
{
"input": "4\nR 1 1\nR 14 16\nR 0 11\nR 15 2",
"output": "34"
},
{
"input": "3\nR 10 7\nB 19 13\nB 0 12",
"output": "32"
},
{
"input": "2\nB 12 12\nB 10 2",
"output": "24"
},
{
"input": "1\nR 0 9",
"output": "10"
},
{
"input": "16\nR 11 0\nR 6 0\nR 7 2\nR 12 6\nR 14 9\nR 10 15\nR 1 6\nR 14 16\nR 14 5\nR 11 13\nR 10 11\nR 7 16\nR 1 3\nR 15 12\nR 14 5\nR 9 7",
"output": "142"
},
{
"input": "16\nB 16 2\nB 13 4\nB 8 2\nB 13 11\nB 14 15\nR 5 16\nB 0 16\nB 10 9\nB 5 9\nB 8 9\nB 2 7\nB 14 11\nB 8 12\nB 14 0\nR 16 13\nB 6 16",
"output": "141"
},
{
"input": "16\nR 10 6\nB 4 0\nB 10 4\nR 16 14\nR 6 13\nR 8 0\nB 8 0\nR 12 1\nB 11 4\nR 3 5\nR 2 1\nB 12 6\nR 14 12\nB 11 13\nB 10 4\nB 4 8",
"output": "74"
},
{
"input": "16\nR 15 9\nR 4 4\nR 10 5\nR 1 1\nR 5 11\nR 3 0\nR 16 0\nB 9 11\nR 0 8\nR 15 9\nR 1 14\nR 3 16\nR 3 10\nR 1 9\nB 13 12\nR 2 10",
"output": "121"
},
{
"input": "16\nB 11 3\nR 12 1\nR 10 6\nR 11 5\nR 6 9\nB 6 1\nB 8 10\nR 4 4\nR 7 4\nR 10 6\nR 9 8\nB 0 11\nB 9 2\nB 16 4\nR 6 4\nR 16 2",
"output": "69"
},
{
"input": "16\nB 14 7\nB 3 13\nB 12 7\nR 13 9\nB 13 7\nB 0 1\nR 6 10\nB 0 5\nB 13 16\nB 6 2\nR 9 3\nB 8 6\nB 0 1\nB 14 9\nR 0 3\nR 4 12",
"output": "83"
},
{
"input": "16\nR 1 10\nR 2 1\nR 12 9\nR 16 13\nR 14 12\nR 3 2\nB 15 11\nR 12 13\nR 2 4\nR 3 6\nR 8 15\nR 6 0\nR 5 16\nR 4 4\nB 1 11\nR 3 4",
"output": "121"
},
{
"input": "16\nB 14 14\nR 10 13\nB 14 10\nR 0 10\nB 4 10\nB 14 11\nR 6 4\nB 0 6\nB 9 0\nB 15 2\nB 8 10\nB 14 3\nR 12 9\nR 2 16\nR 12 3\nB 0 13",
"output": "93"
},
{
"input": "16\nR 13 14\nR 2 12\nR 2 14\nR 12 16\nR 10 11\nR 9 2\nB 8 7\nR 16 7\nB 15 4\nB 15 0\nR 5 9\nR 2 12\nB 1 0\nR 0 5\nR 2 2\nR 15 8",
"output": "90"
},
{
"input": "16\nR 8 16\nB 10 8\nR 4 15\nR 12 3\nB 11 9\nR 12 1\nR 8 7\nB 11 0\nR 4 8\nB 3 12\nR 15 5\nR 9 5\nR 8 8\nR 7 8\nB 11 10\nB 14 0",
"output": "88"
},
{
"input": "16\nR 13 3\nB 1 4\nR 4 0\nB 15 6\nB 2 7\nB 6 3\nR 16 8\nB 15 10\nB 11 3\nB 16 16\nR 13 0\nB 8 9\nB 15 7\nR 5 4\nR 13 1\nR 11 10",
"output": "108"
},
{
"input": "16\nB 7 13\nR 0 7\nR 15 1\nR 9 4\nB 2 12\nB 10 4\nR 7 1\nR 11 3\nR 0 0\nR 11 12\nR 13 12\nB 14 3\nB 4 7\nR 2 16\nB 7 1\nB 8 11",
"output": "72"
},
{
"input": "16\nB 12 0\nB 9 5\nB 16 2\nB 11 8\nB 2 10\nB 4 4\nB 6 2\nB 6 12\nB 6 3\nB 7 9\nB 5 6\nB 14 15\nB 10 14\nB 10 12\nB 1 9\nB 6 4",
"output": "141"
},
{
"input": "16\nB 0 4\nR 0 8\nR 0 3\nB 13 11\nB 10 9\nR 7 5\nR 15 2\nR 2 5\nR 13 16\nR 2 13\nB 4 2\nB 3 9\nR 0 15\nB 7 0\nB 4 1\nR 4 14",
"output": "64"
},
{
"input": "16\nR 12 7\nB 16 4\nB 0 5\nR 15 16\nR 11 7\nR 1 4\nR 6 12\nR 6 14\nR 3 11\nR 15 10\nR 4 13\nB 2 3\nR 6 6\nB 15 12\nR 14 8\nR 1 7",
"output": "101"
},
{
"input": "16\nB 16 10\nB 7 9\nB 1 6\nB 8 3\nB 1 5\nB 6 5\nB 14 13\nB 2 6\nB 9 15\nB 11 6\nB 11 8\nB 9 16\nB 5 4\nB 12 8\nB 8 0\nB 16 16",
"output": "152"
},
{
"input": "16\nB 12 4\nB 15 5\nB 2 6\nB 11 6\nB 2 3\nB 0 6\nB 13 13\nB 14 16\nB 6 11\nB 7 10\nB 11 3\nB 7 10\nB 12 4\nR 10 4\nB 11 0\nB 14 0",
"output": "149"
},
{
"input": "16\nR 15 8\nR 15 1\nB 3 9\nR 13 2\nR 9 9\nB 3 6\nR 5 13\nB 10 0\nR 12 15\nB 11 6\nR 11 16\nR 14 4\nR 0 12\nR 0 8\nB 4 7\nR 11 10",
"output": "89"
},
{
"input": "16\nB 16 4\nB 4 13\nB 3 1\nB 6 7\nR 2 0\nB 11 1\nR 8 2\nR 15 16\nR 2 16\nR 14 13\nB 3 4\nR 2 15\nB 7 4\nB 8 16\nR 1 12\nR 4 12",
"output": "80"
},
{
"input": "16\nR 3 16\nR 12 0\nR 3 3\nR 9 11\nR 10 16\nR 6 2\nR 16 3\nR 11 8\nR 8 12\nR 11 9\nR 4 16\nR 0 9\nR 15 3\nR 16 11\nR 12 2\nR 10 4",
"output": "141"
},
{
"input": "16\nR 7 1\nB 3 14\nB 5 4\nB 9 0\nR 10 14\nR 8 2\nR 8 3\nB 6 1\nB 14 9\nR 7 13\nB 12 10\nR 8 5\nB 4 11\nR 13 8\nB 15 11\nB 7 14",
"output": "85"
},
{
"input": "16\nR 3 5\nB 3 9\nB 6 5\nB 12 3\nB 1 3\nR 3 3\nB 16 13\nB 3 10\nB 4 12\nR 2 10\nR 12 7\nR 5 16\nB 2 11\nR 12 3\nR 8 3\nB 5 15",
"output": "71"
},
{
"input": "16\nR 7 7\nR 11 14\nR 6 6\nR 6 7\nR 1 1\nR 6 4\nR 16 14\nR 6 3\nR 10 8\nR 14 6\nR 12 1\nR 13 9\nR 9 11\nR 1 7\nR 2 2\nR 2 8",
"output": "124"
},
{
"input": "16\nB 3 11\nR 2 10\nB 0 8\nB 8 3\nB 1 16\nR 1 4\nR 6 15\nR 2 3\nB 16 12\nB 9 10\nB 2 13\nR 11 5\nB 15 1\nB 16 3\nB 5 11\nB 0 1",
"output": "72"
},
{
"input": "16\nB 7 6\nR 0 14\nR 0 9\nR 11 7\nR 9 13\nR 4 4\nR 15 7\nR 14 13\nR 6 8\nR 6 6\nR 2 8\nR 2 7\nR 5 0\nR 6 16\nR 14 1\nR 15 11",
"output": "132"
},
{
"input": "16\nR 1 9\nR 8 9\nR 1 10\nR 12 11\nR 10 11\nR 16 4\nR 14 7\nR 10 6\nR 12 4\nR 1 2\nB 1 3\nR 0 2\nR 11 0\nR 4 3\nR 8 10\nR 12 3",
"output": "96"
},
{
"input": "16\nR 6 12\nB 0 7\nB 2 12\nR 6 15\nB 1 9\nR 1 5\nB 6 8\nR 6 15\nB 1 7\nR 5 7\nR 1 14\nR 6 13\nR 0 8\nB 2 16\nB 11 1\nR 10 4",
"output": "90"
},
{
"input": "16\nR 10 16\nB 16 11\nR 4 13\nR 8 1\nR 1 15\nR 14 6\nR 13 2\nR 10 8\nB 9 4\nB 1 4\nR 10 10\nB 5 8\nR 7 8\nR 9 12\nR 3 0\nR 8 14",
"output": "103"
},
{
"input": "16\nR 11 2\nR 6 6\nR 2 6\nR 1 16\nR 0 8\nR 4 11\nR 0 15\nR 7 7\nR 14 6\nR 5 10\nR 2 16\nR 9 2\nR 7 15\nR 1 2\nR 1 5\nR 0 15",
"output": "158"
},
{
"input": "16\nB 15 6\nB 14 1\nB 3 8\nB 4 4\nB 1 6\nB 8 10\nB 9 15\nB 11 8\nB 4 1\nB 1 6\nB 3 11\nB 0 13\nB 13 7\nB 8 14\nB 12 12\nB 15 7",
"output": "137"
},
{
"input": "16\nB 10 9\nB 13 15\nB 5 8\nB 5 8\nR 8 4\nB 2 11\nR 16 8\nR 6 0\nR 1 5\nB 13 10\nB 2 6\nB 16 7\nB 2 7\nR 5 1\nR 6 5\nR 12 0",
"output": "73"
},
{
"input": "16\nB 15 3\nR 3 2\nR 5 9\nB 7 12\nR 9 2\nB 5 11\nR 16 9\nB 2 10\nR 7 2\nB 8 7\nR 10 0\nR 5 2\nB 9 6\nB 4 14\nB 8 13\nB 10 1",
"output": "70"
},
{
"input": "16\nR 10 7\nB 12 15\nR 7 11\nR 9 16\nR 8 7\nB 16 12\nB 7 9\nB 15 3\nR 14 4\nR 4 3\nR 10 13\nB 3 13\nB 16 14\nR 10 10\nR 2 4\nB 7 11",
"output": "107"
},
{
"input": "16\nR 14 9\nB 11 2\nB 8 13\nB 4 2\nB 0 5\nB 3 13\nB 16 10\nR 10 13\nB 3 0\nR 1 7\nB 9 8\nB 11 9\nR 5 13\nB 9 6\nR 5 3\nB 6 4",
"output": "76"
},
{
"input": "16\nR 1 13\nR 2 16\nR 0 13\nR 5 7\nR 0 4\nR 15 13\nR 14 2\nR 13 4\nR 10 13\nR 13 4\nR 9 4\nR 8 2\nR 11 4\nR 15 10\nR 16 11\nR 3 14",
"output": "150"
},
{
"input": "16\nB 13 16\nR 11 11\nB 1 15\nB 7 3\nB 8 2\nB 1 13\nR 6 4\nB 9 14\nB 0 0\nB 0 8\nB 0 15\nB 16 14\nB 1 4\nB 14 6\nB 8 3\nB 0 6",
"output": "93"
},
{
"input": "16\nB 1 11\nR 9 15\nR 3 0\nR 9 6\nB 8 0\nR 12 13\nR 14 4\nR 4 7\nR 6 13\nR 13 4\nR 16 10\nR 15 9\nR 7 4\nB 11 2\nR 11 11\nB 16 7",
"output": "92"
},
{
"input": "16\nR 13 14\nR 1 12\nR 3 0\nR 3 11\nR 0 6\nR 14 14\nR 6 14\nR 0 16\nR 11 8\nR 9 0\nR 16 5\nR 5 4\nR 14 11\nR 0 14\nR 5 3\nR 13 0",
"output": "148"
},
{
"input": "16\nB 6 10\nR 7 7\nB 2 10\nB 4 16\nR 9 15\nB 6 2\nB 10 11\nB 5 6\nB 1 10\nB 13 7\nB 9 11\nB 1 14\nB 13 4\nB 11 4\nB 2 6\nB 13 2",
"output": "101"
},
{
"input": "16\nB 1 4\nB 15 3\nR 4 12\nR 16 3\nB 16 12\nB 1 1\nB 1 10\nB 2 16\nB 7 14\nB 8 11\nB 1 6\nB 7 8\nB 2 2\nB 0 8\nR 13 6\nB 11 11",
"output": "92"
},
{
"input": "16\nR 5 8\nR 14 7\nR 4 13\nR 1 8\nB 0 10\nB 3 2\nB 1 3\nB 14 9\nB 15 10\nR 3 7\nB 0 1\nR 14 2\nR 9 10\nR 16 4\nR 6 14\nR 9 4",
"output": "70"
},
{
"input": "16\nB 10 11\nB 6 3\nB 6 14\nR 2 3\nB 0 8\nB 16 3\nB 8 4\nB 1 0\nB 4 14\nB 16 5\nB 0 12\nB 13 15\nB 16 10\nR 13 0\nB 9 6\nB 6 5",
"output": "118"
},
{
"input": "16\nR 6 14\nR 14 8\nB 7 16\nR 4 7\nB 8 14\nB 2 11\nB 0 5\nB 13 10\nB 10 10\nB 12 8\nR 9 8\nB 3 9\nR 4 8\nR 4 12\nR 2 14\nR 3 15",
"output": "94"
},
{
"input": "16\nR 8 0\nR 13 3\nR 8 0\nB 7 11\nR 8 12\nR 14 12\nB 15 15\nR 9 3\nR 16 6\nB 7 4\nR 8 2\nB 2 11\nR 11 1\nR 1 16\nR 12 5\nB 2 8",
"output": "83"
},
{
"input": "16\nB 4 11\nB 4 8\nB 8 1\nB 0 15\nB 16 10\nB 16 13\nB 7 15\nR 5 13\nB 5 10\nB 3 0\nB 7 14\nB 8 6\nB 2 0\nB 8 13\nR 15 4\nB 16 1",
"output": "113"
},
{
"input": "16\nB 9 15\nB 12 4\nB 10 3\nR 3 2\nR 0 7\nR 12 12\nB 15 16\nB 1 5\nB 11 6\nB 7 4\nB 6 9\nB 7 1\nB 7 16\nR 5 8\nB 8 12\nR 13 2",
"output": "81"
},
{
"input": "16\nB 3 1\nR 11 0\nR 2 4\nR 4 7\nR 7 5\nR 14 13\nB 6 9\nR 4 15\nB 1 1\nR 2 1\nR 15 5\nB 14 13\nB 14 7\nR 3 12\nR 11 5\nR 12 11",
"output": "73"
},
{
"input": "16\nB 8 4\nB 2 3\nB 3 4\nB 6 2\nB 8 11\nB 8 14\nB 6 9\nB 16 8\nB 16 6\nB 16 15\nB 15 16\nB 13 6\nB 3 7\nB 10 9\nB 5 12\nB 9 4",
"output": "160"
},
{
"input": "16\nB 0 8\nB 9 7\nB 3 6\nB 0 8\nB 8 4\nB 0 1\nB 1 5\nB 14 15\nB 6 8\nB 2 4\nB 7 5\nB 0 0\nB 3 15\nB 2 0\nB 11 16\nB 1 5",
"output": "83"
},
{
"input": "16\nB 13 12\nB 0 12\nB 3 9\nB 1 12\nB 8 2\nB 3 2\nB 1 6\nB 1 7\nB 11 3\nB 16 8\nB 8 16\nB 15 12\nB 9 5\nB 10 12\nB 13 16\nB 8 14",
"output": "136"
},
{
"input": "16\nB 1 14\nR 0 9\nB 5 10\nR 13 16\nB 16 0\nB 14 1\nB 9 16\nB 14 0\nR 0 6\nB 11 4\nB 16 13\nR 5 6\nR 16 5\nR 7 7\nR 7 7\nR 5 7",
"output": "89"
},
{
"input": "16\nR 12 2\nR 7 12\nR 6 10\nR 15 3\nR 16 16\nR 1 2\nR 1 0\nR 10 10\nR 7 2\nR 6 1\nR 15 7\nR 13 1\nR 4 5\nR 5 3\nR 9 16\nR 2 8",
"output": "114"
},
{
"input": "16\nR 16 13\nB 15 9\nB 7 12\nB 16 7\nB 16 4\nR 12 3\nB 9 1\nR 5 2\nR 13 15\nB 2 5\nR 15 2\nR 10 12\nB 11 14\nB 12 8\nB 2 6\nR 0 1",
"output": "103"
},
{
"input": "16\nR 12 16\nB 14 13\nB 8 14\nR 2 2\nR 7 2\nB 16 3\nR 8 10\nR 9 12\nB 3 2\nR 15 1\nR 14 14\nR 2 7\nR 1 12\nB 10 3\nR 13 15\nB 15 11",
"output": "100"
},
{
"input": "16\nR 16 2\nR 5 9\nR 8 14\nR 4 7\nR 8 0\nR 10 4\nR 0 11\nR 4 12\nR 10 14\nR 2 15\nR 6 9\nR 16 2\nR 7 12\nR 0 16\nR 15 14\nR 12 4",
"output": "161"
},
{
"input": "16\nB 3 5\nB 14 5\nB 10 16\nR 15 12\nB 15 15\nR 12 4\nR 8 11\nB 0 5\nB 16 11\nR 14 3\nB 5 3\nR 7 12\nR 14 3\nB 15 4\nB 8 5\nB 10 5",
"output": "117"
},
{
"input": "16\nR 16 16\nR 13 10\nR 10 0\nR 0 15\nB 16 13\nR 7 5\nR 8 4\nR 13 14\nR 5 15\nR 11 15\nR 4 16\nR 5 7\nR 12 3\nR 12 16\nR 2 15\nR 8 14",
"output": "180"
},
{
"input": "16\nR 3 3\nR 4 5\nR 12 2\nR 2 2\nR 6 2\nR 10 6\nR 15 5\nR 8 7\nR 12 10\nR 6 11\nR 13 10\nR 12 10\nR 2 11\nR 3 12\nR 5 5\nR 5 7",
"output": "124"
},
{
"input": "16\nB 3 16\nR 10 0\nB 2 13\nB 12 16\nR 16 11\nB 1 10\nB 2 0\nB 13 6\nR 0 12\nB 10 1\nB 6 0\nB 8 12\nB 9 1\nB 11 1\nB 11 10\nB 14 9",
"output": "106"
},
{
"input": "16\nR 8 2\nB 10 13\nB 3 13\nB 14 3\nB 6 8\nB 13 10\nB 10 11\nB 9 16\nB 7 16\nB 5 5\nB 6 12\nB 15 8\nB 16 1\nR 1 14\nB 12 1\nB 13 1",
"output": "135"
},
{
"input": "16\nB 3 14\nR 1 1\nR 5 14\nR 16 8\nR 7 6\nR 0 10\nR 1 12\nR 4 16\nR 14 12\nR 0 2\nR 5 6\nR 13 1\nB 5 9\nR 16 2\nR 6 0\nR 10 11",
"output": "115"
},
{
"input": "16\nB 6 16\nB 8 14\nB 6 16\nB 10 11\nB 6 4\nB 12 10\nR 10 13\nB 8 8\nB 11 8\nB 14 15\nB 5 11\nB 4 13\nB 12 9\nB 14 14\nB 9 9\nB 7 12",
"output": "143"
},
{
"input": "16\nB 11 4\nB 8 1\nR 7 0\nR 13 15\nR 15 10\nR 14 11\nR 9 4\nB 4 1\nR 1 12\nR 9 2\nB 14 6\nB 10 16\nR 10 8\nR 4 10\nR 3 16\nR 5 5",
"output": "86"
},
{
"input": "16\nR 7 7\nR 16 14\nR 7 1\nR 13 2\nR 15 8\nR 8 12\nB 1 5\nR 16 10\nR 7 7\nR 14 15\nR 13 1\nR 9 10\nR 0 16\nB 1 5\nR 13 8\nB 3 15",
"output": "115"
},
{
"input": "16\nB 11 1\nB 8 11\nR 9 2\nB 16 7\nB 6 6\nB 12 13\nB 8 6\nR 12 3\nB 13 4\nB 9 2\nB 12 13\nB 16 5\nR 5 15\nB 9 10\nB 16 15\nB 0 8",
"output": "139"
},
{
"input": "16\nR 6 4\nB 16 14\nR 9 3\nB 1 3\nB 6 4\nB 6 13\nB 8 16\nR 7 13\nR 2 7\nB 6 16\nB 4 8\nB 15 16\nB 13 16\nR 6 6\nR 10 16\nB 15 9",
"output": "103"
},
{
"input": "16\nR 11 8\nR 14 11\nR 11 5\nR 12 7\nR 14 2\nR 9 13\nB 16 16\nR 12 6\nR 9 2\nR 1 12\nR 3 3\nR 5 11\nB 2 6\nR 5 1\nR 3 7\nR 12 1",
"output": "100"
},
{
"input": "16\nB 6 10\nB 5 15\nB 12 6\nB 13 10\nB 14 8\nB 3 14\nB 8 0\nB 7 15\nB 15 16\nB 13 0\nB 3 15\nB 2 6\nR 8 6\nB 11 14\nB 6 15\nB 9 11",
"output": "136"
},
{
"input": "16\nR 16 15\nB 13 1\nB 2 0\nB 8 16\nB 14 1\nR 12 9\nB 11 14\nB 13 5\nB 5 9\nB 0 15\nB 12 4\nB 7 15\nB 7 14\nB 3 4\nB 11 3\nB 10 12",
"output": "133"
},
{
"input": "16\nR 2 1\nB 11 5\nB 4 0\nB 9 3\nB 15 16\nB 15 10\nB 2 7\nR 9 15\nR 11 4\nR 12 2\nB 13 16\nR 5 11\nB 14 5\nB 10 9\nR 14 10\nR 8 4",
"output": "94"
},
{
"input": "16\nB 14 4\nB 2 1\nB 5 1\nB 12 7\nB 14 14\nB 10 9\nB 11 7\nB 4 8\nB 0 0\nR 9 16\nB 4 10\nB 13 5\nB 3 5\nB 7 4\nB 6 2\nB 5 14",
"output": "121"
},
{
"input": "16\nR 2 7\nB 11 6\nR 6 4\nB 13 3\nR 6 12\nB 14 10\nB 9 8\nB 16 0\nB 6 3\nB 4 3\nB 4 6\nB 12 16\nB 10 3\nB 6 16\nR 0 1\nB 3 15",
"output": "85"
},
{
"input": "16\nR 14 1\nR 10 2\nR 7 4\nB 8 7\nR 5 1\nR 8 10\nB 1 0\nB 12 10\nB 12 0\nB 16 16\nR 3 0\nR 1 11\nB 0 12\nR 12 13\nR 3 9\nR 0 8",
"output": "72"
},
{
"input": "16\nB 2 5\nB 1 15\nB 8 5\nB 9 11\nB 14 15\nB 10 12\nB 9 1\nB 16 3\nB 3 13\nB 4 12\nB 11 12\nB 9 5\nB 5 12\nB 11 0\nB 13 1\nB 15 1",
"output": "156"
},
{
"input": "16\nR 14 9\nB 8 3\nR 8 7\nB 11 16\nB 15 13\nR 5 13\nB 9 1\nR 12 11\nB 9 16\nR 16 0\nB 11 8\nB 7 0\nB 13 11\nB 8 12\nR 16 9\nR 13 11",
"output": "114"
},
{
"input": "16\nR 1 12\nR 7 15\nB 10 8\nR 13 3\nR 5 11\nB 7 13\nB 16 12\nB 7 4\nB 15 12\nR 12 13\nR 11 3\nB 13 12\nB 2 2\nB 16 8\nR 10 1\nB 10 12",
"output": "104"
},
{
"input": "16\nB 6 15\nB 16 3\nB 11 9\nB 16 6\nB 6 9\nB 3 13\nB 8 13\nB 3 14\nB 5 9\nB 7 9\nB 2 14\nB 13 14\nB 8 2\nB 13 13\nB 3 0\nB 8 4",
"output": "144"
},
{
"input": "16\nB 0 10\nB 7 16\nB 12 10\nB 9 2\nR 5 15\nR 6 13\nB 16 12\nR 15 6\nB 11 12\nB 4 13\nB 1 10\nR 3 9\nR 14 0\nR 3 8\nR 5 8\nR 6 14",
"output": "95"
},
{
"input": "16\nB 10 5\nB 14 11\nB 3 13\nB 3 7\nB 6 7\nR 13 0\nB 3 1\nB 4 14\nR 7 14\nB 7 3\nB 11 14\nB 15 11\nR 15 1\nB 13 16\nB 11 13\nR 15 16",
"output": "115"
},
{
"input": "16\nR 5 9\nR 12 7\nR 4 13\nB 4 11\nB 6 5\nB 10 1\nR 12 2\nR 16 6\nR 15 10\nR 2 16\nR 12 11\nB 5 6\nR 3 0\nB 2 11\nR 14 3\nR 4 8",
"output": "80"
},
{
"input": "16\nB 9 3\nB 4 10\nB 5 15\nB 6 16\nB 14 2\nB 12 1\nB 11 3\nB 4 16\nB 4 14\nB 16 13\nB 10 5\nR 3 9\nB 10 16\nR 1 8\nR 7 12\nB 2 10",
"output": "93"
},
{
"input": "16\nR 5 6\nB 12 7\nB 6 0\nR 9 2\nB 14 0\nR 6 2\nB 3 11\nR 16 8\nR 11 10\nR 11 0\nB 2 0\nB 11 2\nB 16 9\nB 15 3\nB 1 3\nB 16 2",
"output": "107"
},
{
"input": "16\nR 10 9\nR 12 4\nR 8 1\nR 10 7\nR 5 7\nR 9 3\nR 10 12\nR 12 0\nR 0 6\nR 16 13\nR 2 12\nR 9 15\nR 6 7\nR 6 7\nR 4 2\nR 13 12",
"output": "133"
},
{
"input": "16\nB 13 12\nB 2 7\nB 7 1\nR 5 3\nB 6 5\nB 4 3\nB 2 14\nR 7 10\nR 6 9\nB 11 9\nB 1 7\nB 16 9\nB 13 16\nB 3 3\nB 14 11\nR 12 5",
"output": "92"
},
{
"input": "16\nB 9 15\nB 10 4\nB 9 4\nR 7 7\nR 13 3\nR 7 4\nB 1 15\nR 3 3\nR 13 5\nB 7 14\nB 10 1\nR 7 4\nR 2 15\nR 1 16\nB 8 2\nR 9 15",
"output": "80"
},
{
"input": "16\nR 13 10\nB 10 8\nR 10 5\nB 8 11\nR 14 1\nR 1 5\nB 9 7\nB 6 3\nR 3 0\nB 3 10\nR 9 14\nR 4 15\nR 8 14\nR 8 3\nR 9 11\nB 6 16",
"output": "90"
},
{
"input": "16\nR 8 14\nR 1 4\nB 10 5\nR 11 15\nR 4 15\nB 5 4\nR 16 7\nB 2 13\nR 8 4\nB 15 6\nR 8 9\nB 12 10\nR 14 6\nB 6 16\nB 3 2\nB 5 8",
"output": "89"
},
{
"input": "16\nR 12 0\nR 10 8\nR 12 8\nR 13 1\nR 5 4\nR 0 5\nB 16 8\nB 14 5\nR 15 0\nB 10 11\nR 8 4\nR 10 4\nB 5 6\nB 13 12\nB 5 1\nR 2 1",
"output": "71"
},
{
"input": "16\nR 13 4\nR 7 11\nR 11 0\nR 6 16\nR 4 14\nR 8 9\nR 13 14\nR 3 5\nR 4 1\nR 14 0\nR 0 10\nB 15 15\nB 4 13\nR 4 2\nR 11 5\nR 11 2",
"output": "113"
},
{
"input": "16\nR 0 7\nR 15 0\nR 12 2\nR 0 2\nR 4 12\nR 10 9\nR 11 14\nR 15 15\nB 10 6\nR 10 14\nR 10 4\nR 14 8\nR 10 4\nR 11 14\nR 14 13\nR 9 11",
"output": "137"
},
{
"input": "16\nB 4 11\nB 6 12\nB 5 3\nR 1 7\nB 4 10\nB 6 11\nB 3 14\nB 11 7\nB 0 2\nB 6 10\nB 9 0\nB 3 4\nR 16 4\nB 9 2\nB 8 4\nR 7 13",
"output": "75"
},
{
"input": "16\nB 0 14\nB 14 16\nR 6 4\nB 4 12\nB 13 8\nB 8 11\nB 11 8\nB 7 8\nB 6 14\nB 10 14\nR 9 12\nB 1 15\nR 7 3\nB 7 14\nB 1 13\nB 4 5",
"output": "96"
},
{
"input": "16\nR 4 0\nR 13 13\nR 7 5\nR 5 15\nR 12 14\nR 3 11\nR 3 9\nR 3 1\nR 4 2\nR 5 10\nR 0 7\nR 8 10\nR 12 12\nR 14 10\nR 4 12\nR 1 15",
"output": "162"
},
{
"input": "16\nR 16 11\nB 4 9\nB 7 6\nR 8 2\nB 4 11\nB 5 12\nB 2 9\nB 6 10\nB 10 15\nB 1 14\nB 16 2\nB 7 4\nB 2 10\nB 12 6\nB 14 4\nB 0 8",
"output": "104"
},
{
"input": "16\nB 3 14\nR 12 13\nR 9 8\nR 2 7\nR 4 9\nB 0 3\nB 10 2\nR 2 2\nR 16 10\nB 15 12\nR 16 14\nB 15 16\nB 9 10\nR 10 10\nB 7 12\nB 14 1",
"output": "100"
},
{
"input": "16\nR 16 0\nR 11 9\nR 9 9\nR 3 2\nB 12 7\nR 4 4\nR 1 2\nB 14 12\nB 6 14\nR 10 7\nB 16 8\nR 4 2\nB 15 2\nR 0 5\nR 10 3\nR 11 2",
"output": "72"
},
{
"input": "16\nB 2 4\nB 2 14\nR 11 10\nR 5 6\nB 12 5\nB 16 4\nB 1 2\nB 11 4\nB 12 10\nR 5 11\nB 7 4\nB 3 13\nR 5 1\nB 14 2\nB 4 12\nR 10 11",
"output": "84"
},
{
"input": "16\nB 7 15\nB 10 9\nR 12 12\nR 8 10\nB 12 12\nB 1 4\nB 10 12\nB 14 14\nB 1 14\nR 1 7\nR 7 15\nB 10 7\nR 2 0\nB 5 14\nR 6 10\nB 7 4",
"output": "92"
},
{
"input": "16\nB 5 3\nB 7 0\nB 4 13\nB 15 15\nB 6 4\nB 5 16\nB 1 0\nB 5 12\nB 8 11\nB 6 10\nB 8 5\nB 5 12\nB 9 5\nB 10 9\nB 7 4\nB 8 4",
"output": "125"
},
{
"input": "16\nB 0 6\nR 14 3\nB 6 16\nB 1 3\nB 14 1\nB 0 16\nB 9 1\nB 0 4\nR 14 8\nB 2 13\nB 8 0\nR 13 7\nB 15 13\nB 0 4\nR 10 13\nB 6 13",
"output": "95"
},
{
"input": "16\nR 4 9\nR 13 16\nR 7 0\nR 11 6\nB 14 16\nR 2 0\nR 8 2\nR 13 14\nR 3 11\nB 6 10\nR 7 12\nR 10 0\nR 4 13\nR 14 10\nR 3 5\nR 3 15",
"output": "132"
},
{
"input": "16\nB 0 13\nR 4 13\nR 0 1\nR 14 10\nR 5 14\nR 14 0\nR 16 3\nR 9 7\nR 10 7\nR 3 6\nR 16 7\nR 2 13\nR 11 12\nR 13 5\nR 14 13\nR 1 7",
"output": "133"
},
{
"input": "16\nB 3 7\nB 12 0\nR 1 2\nB 16 14\nB 5 12\nB 0 1\nR 8 11\nR 5 16\nR 16 2\nR 15 10\nB 16 1\nB 0 7\nB 0 3\nR 2 0\nR 0 12\nR 16 1",
"output": "73"
},
{
"input": "16\nR 7 10\nB 12 12\nR 3 4\nR 0 1\nR 13 1\nR 13 1\nB 16 12\nR 8 9\nR 5 7\nR 11 7\nR 14 15\nR 6 2\nR 7 2\nR 1 5\nR 9 3\nR 13 10",
"output": "91"
},
{
"input": "16\nB 3 14\nB 3 1\nB 3 5\nB 12 14\nB 13 16\nB 7 2\nR 15 13\nB 3 2\nB 13 3\nR 6 3\nR 14 9\nB 5 13\nB 13 10\nB 7 1\nB 12 12\nB 11 2",
"output": "114"
},
{
"input": "16\nB 7 16\nB 10 13\nR 4 6\nB 14 2\nR 13 14\nB 10 2\nR 6 7\nB 16 11\nB 10 6\nB 2 8\nR 6 4\nB 12 15\nB 2 10\nB 6 13\nR 6 2\nB 9 4",
"output": "90"
},
{
"input": "16\nR 3 3\nR 10 9\nR 5 7\nB 16 5\nR 5 12\nR 4 3\nB 15 7\nR 12 3\nR 0 3\nR 14 4\nR 6 16\nR 10 11\nR 8 9\nR 3 9\nR 15 11\nR 6 13",
"output": "112"
},
{
"input": "16\nB 7 13\nR 1 15\nB 5 9\nB 1 10\nB 5 10\nR 8 4\nR 14 7\nB 16 13\nB 5 16\nB 10 0\nB 6 11\nB 1 5\nR 16 1\nB 10 14\nB 1 11\nB 4 6",
"output": "84"
},
{
"input": "16\nB 0 10\nB 7 9\nB 5 12\nB 11 14\nB 5 10\nB 15 16\nB 10 13\nR 14 4\nB 11 0\nB 14 6\nB 15 0\nB 5 8\nR 14 8\nR 2 5\nB 7 14\nB 4 8",
"output": "116"
},
{
"input": "16\nR 12 13\nB 15 5\nR 6 12\nR 13 2\nR 4 8\nB 1 16\nR 10 14\nB 9 13\nR 1 4\nR 1 10\nB 7 12\nB 4 2\nR 4 9\nR 8 0\nR 10 7\nB 2 0",
"output": "80"
},
{
"input": "16\nR 16 8\nR 15 1\nR 7 13\nR 15 15\nR 13 6\nR 13 16\nR 1 14\nR 13 6\nR 8 0\nR 14 8\nR 6 7\nB 10 4\nR 11 0\nR 7 12\nR 3 15\nR 0 2",
"output": "130"
},
{
"input": "16\nB 11 11\nB 6 4\nB 8 14\nB 9 1\nB 12 4\nB 16 0\nB 9 7\nB 8 16\nB 14 12\nR 9 4\nB 5 2\nR 8 0\nB 0 15\nB 4 8\nB 13 6\nB 14 11",
"output": "135"
},
{
"input": "16\nR 16 14\nR 15 2\nR 1 16\nR 11 5\nR 5 1\nB 11 0\nR 0 7\nB 5 8\nB 4 16\nB 5 8\nR 5 13\nB 0 11\nR 7 15\nR 12 13\nR 16 14\nR 12 4",
"output": "106"
},
{
"input": "16\nB 10 1\nR 13 5\nR 2 0\nR 13 10\nR 4 7\nR 14 1\nR 0 9\nR 0 0\nR 9 12\nR 1 3\nR 13 9\nR 14 4\nR 13 6\nR 9 8\nR 10 13\nR 10 13",
"output": "104"
},
{
"input": "16\nB 15 4\nB 4 1\nR 3 1\nR 14 14\nB 5 5\nR 9 1\nB 8 1\nR 12 1\nR 15 15\nB 13 0\nB 13 3\nR 5 0\nB 2 6\nR 16 3\nB 3 4\nR 7 5",
"output": "86"
},
{
"input": "16\nB 3 16\nR 13 6\nB 5 2\nB 9 1\nB 12 3\nB 4 2\nR 16 2\nB 16 11\nR 5 12\nB 9 4\nR 14 16\nR 3 11\nR 1 5\nR 14 15\nB 6 12\nB 5 7",
"output": "87"
},
{
"input": "16\nB 14 1\nR 12 2\nB 5 4\nR 11 14\nB 13 2\nB 6 3\nR 14 2\nR 10 3\nR 12 7\nB 4 1\nB 4 11\nB 10 6\nR 8 14\nB 12 3\nR 0 5\nB 3 16",
"output": "83"
},
{
"input": "16\nB 2 5\nB 3 15\nR 6 5\nR 13 1\nB 4 0\nR 1 3\nR 6 11\nB 7 13\nR 2 11\nR 10 5\nR 4 6\nR 8 0\nB 13 12\nB 2 16\nR 2 13\nB 0 9",
"output": "79"
},
{
"input": "16\nR 2 9\nR 9 10\nR 5 16\nR 7 6\nB 12 0\nB 0 7\nB 2 8\nR 12 12\nB 16 13\nB 14 4\nB 13 11\nB 13 10\nR 4 5\nR 11 7\nB 8 0\nB 9 11",
"output": "91"
},
{
"input": "16\nB 6 12\nR 1 6\nB 5 16\nB 8 11\nR 4 14\nR 12 8\nB 1 9\nR 8 4\nB 4 9\nB 9 8\nB 13 7\nR 11 6\nB 11 12\nR 0 2\nB 1 16\nR 7 3",
"output": "85"
},
{
"input": "16\nR 2 15\nR 0 11\nR 7 0\nR 10 14\nR 3 12\nR 14 7\nR 10 10\nR 4 4\nR 11 5\nR 4 4\nR 12 1\nR 1 0\nR 10 11\nR 15 15\nR 4 8\nB 5 5",
"output": "125"
},
{
"input": "16\nB 6 2\nB 8 6\nB 8 3\nB 13 1\nB 12 11\nB 11 8\nB 1 2\nB 16 14\nB 0 9\nB 16 8\nB 4 14\nB 8 11\nB 15 11\nB 13 3\nB 14 15\nB 2 14",
"output": "163"
},
{
"input": "16\nR 10 4\nB 16 11\nR 10 3\nR 6 14\nR 12 9\nR 13 8\nR 0 3\nB 2 7\nR 6 4\nB 13 4\nR 4 8\nR 7 6\nB 5 2\nR 3 15\nB 16 7\nR 0 7",
"output": "75"
},
{
"input": "16\nR 6 16\nR 14 7\nR 10 4\nR 9 2\nB 12 15\nR 8 10\nR 8 4\nR 15 0\nR 14 9\nB 8 1\nR 2 3\nR 13 0\nR 12 2\nR 1 10\nR 10 15\nR 15 0",
"output": "91"
},
{
"input": "16\nR 10 3\nR 6 11\nR 4 6\nB 10 6\nB 3 13\nB 2 11\nB 0 14\nB 11 9\nB 3 5\nR 3 6\nB 11 15\nB 13 4\nB 1 10\nR 8 16\nB 3 14\nR 12 9",
"output": "82"
},
{
"input": "16\nB 5 6\nB 14 6\nR 5 8\nB 12 10\nB 3 10\nB 5 10\nB 0 14\nR 7 2\nB 9 0\nB 16 2\nB 12 10\nB 3 14\nB 8 9\nB 6 11\nR 6 6\nR 10 11",
"output": "89"
},
{
"input": "16\nB 9 10\nB 13 4\nR 5 8\nB 6 13\nB 12 8\nB 0 11\nB 7 14\nR 2 11\nB 16 4\nB 4 15\nB 11 4\nB 1 9\nB 13 8\nB 3 6\nB 0 14\nB 16 3",
"output": "110"
},
{
"input": "16\nB 4 3\nR 4 7\nR 6 9\nB 9 1\nB 11 6\nB 3 12\nR 16 7\nR 6 3\nB 5 16\nR 16 1\nB 3 1\nB 8 4\nB 3 1\nB 11 3\nB 10 6\nB 13 13",
"output": "86"
},
{
"input": "16\nR 13 0\nB 12 11\nR 5 3\nR 2 14\nB 12 6\nR 10 15\nB 2 4\nB 4 11\nR 11 2\nR 3 8\nR 12 6\nB 3 14\nB 3 8\nB 3 8\nB 7 10\nB 5 15",
"output": "79"
},
{
"input": "16\nR 1 3\nB 9 15\nB 6 4\nR 4 2\nR 12 4\nR 14 16\nB 10 5\nR 16 4\nR 1 5\nB 15 5\nR 12 1\nR 11 9\nB 10 7\nB 10 14\nR 1 1\nR 4 7",
"output": "76"
},
{
"input": "16\nB 14 6\nB 1 12\nB 7 5\nB 5 6\nB 3 3\nB 9 16\nB 1 14\nB 3 14\nB 7 1\nB 11 2\nB 11 13\nB 10 3\nB 15 16\nB 8 9\nB 4 1\nB 1 9",
"output": "126"
},
{
"input": "16\nB 0 0\nR 9 16\nB 9 7\nB 7 9\nR 3 1\nB 12 16\nB 1 15\nR 16 6\nR 14 14\nR 7 6\nB 10 8\nB 16 14\nB 5 15\nR 6 4\nB 14 8\nR 15 1",
"output": "99"
},
{
"input": "16\nR 13 4\nR 8 12\nB 9 8\nR 10 14\nR 11 15\nR 6 1\nB 10 16\nR 11 15\nR 3 1\nR 3 2\nB 2 4\nR 7 10\nR 12 15\nR 13 1\nR 0 0\nB 14 11",
"output": "106"
},
{
"input": "16\nR 1 6\nR 0 16\nR 11 8\nR 3 2\nR 11 13\nR 10 9\nR 1 8\nR 7 8\nR 9 13\nR 15 14\nR 1 15\nR 4 4\nR 1 5\nR 10 5\nR 11 7\nR 11 3",
"output": "152"
},
{
"input": "16\nR 13 10\nB 8 13\nB 12 11\nR 6 14\nB 11 2\nB 4 10\nB 9 9\nB 10 1\nR 15 9\nB 11 2\nB 1 10\nR 12 15\nR 8 5\nB 1 0\nR 4 0\nR 8 12",
"output": "87"
},
{
"input": "16\nR 0 3\nR 7 8\nB 13 12\nR 8 1\nR 3 0\nR 16 11\nR 8 9\nR 7 10\nR 4 14\nR 6 15\nR 11 5\nR 10 10\nR 14 5\nR 15 13\nR 7 16\nR 7 14",
"output": "148"
},
{
"input": "16\nB 4 8\nB 15 12\nB 5 12\nB 9 5\nR 2 16\nR 1 10\nB 0 9\nB 2 3\nB 2 9\nB 11 12\nB 9 0\nB 1 5\nB 4 13\nR 14 9\nB 1 7\nB 4 6",
"output": "68"
},
{
"input": "16\nB 16 12\nB 6 9\nB 7 15\nR 4 9\nB 11 14\nB 15 11\nB 8 3\nB 15 13\nR 9 5\nB 7 16\nR 9 11\nB 16 0\nR 10 12\nR 3 13\nR 11 16\nR 1 16",
"output": "118"
},
{
"input": "16\nR 9 6\nR 12 3\nR 5 16\nB 5 14\nB 2 14\nB 12 15\nB 11 0\nB 3 3\nB 15 15\nR 10 5\nB 2 1\nB 3 10\nR 10 2\nR 13 4\nR 7 2\nB 0 1",
"output": "78"
},
{
"input": "16\nB 4 2\nR 12 16\nR 6 1\nR 16 2\nB 11 12\nR 8 15\nB 3 1\nR 16 11\nB 5 10\nR 6 2\nR 1 12\nB 1 4\nR 15 12\nB 2 0\nB 1 11\nR 16 10",
"output": "81"
},
{
"input": "16\nR 8 5\nB 3 4\nB 8 2\nB 2 14\nB 10 9\nB 11 16\nB 2 9\nB 11 4\nB 10 7\nB 2 15\nB 9 8\nB 9 16\nB 5 11\nB 0 13\nB 4 11\nB 13 12",
"output": "109"
},
{
"input": "16\nB 4 8\nB 11 0\nR 8 3\nB 2 2\nB 2 7\nB 6 0\nB 10 10\nR 6 14\nR 16 11\nB 14 2\nB 9 11\nB 7 10\nB 12 10\nB 15 8\nR 15 1\nB 10 4",
"output": "113"
},
{
"input": "16\nR 8 11\nB 11 4\nR 10 4\nR 5 6\nR 2 5\nR 8 0\nR 1 11\nR 10 6\nR 7 6\nR 10 15\nB 9 7\nB 15 5\nR 1 1\nR 4 13\nR 8 10\nR 9 14",
"output": "97"
},
{
"input": "16\nB 13 6\nB 1 0\nB 11 5\nB 15 10\nB 3 3\nB 3 1\nB 10 4\nB 6 16\nB 13 3\nB 5 13\nR 0 1\nB 5 7\nB 7 1\nB 3 7\nB 11 0\nB 6 6",
"output": "113"
},
{
"input": "16\nR 8 8\nR 10 14\nR 11 15\nB 1 14\nR 10 9\nB 5 1\nR 9 3\nR 1 9\nR 2 6\nR 0 0\nR 16 14\nB 3 2\nR 14 0\nR 9 3\nR 5 10\nR 3 16",
"output": "104"
},
{
"input": "16\nR 11 12\nR 8 0\nR 13 16\nR 3 1\nR 11 6\nR 1 2\nR 0 5\nR 14 10\nR 9 1\nR 5 13\nR 0 9\nR 10 14\nR 3 9\nR 8 8\nR 6 8\nR 2 1",
"output": "131"
},
{
"input": "16\nR 7 14\nB 16 14\nR 13 0\nB 4 4\nR 2 4\nR 12 2\nB 8 15\nB 1 1\nR 15 14\nR 2 0\nB 8 4\nR 7 7\nB 10 8\nB 5 3\nB 0 0\nR 16 10",
"output": "72"
},
{
"input": "16\nR 11 1\nB 8 0\nR 6 2\nR 6 1\nR 2 2\nB 15 2\nB 8 16\nB 14 11\nB 4 1\nR 14 12\nB 8 15\nR 16 2\nB 0 16\nB 12 15\nR 11 8\nB 13 3",
"output": "90"
},
{
"input": "16\nR 12 5\nB 15 4\nR 5 4\nB 0 5\nR 2 12\nB 7 6\nB 4 12\nR 11 11\nR 10 3\nR 1 3\nR 0 5\nR 11 13\nR 16 8\nR 4 6\nR 9 12\nR 6 5",
"output": "78"
},
{
"input": "16\nR 16 9\nR 14 9\nR 7 5\nR 2 10\nR 1 1\nR 10 8\nR 12 4\nB 15 4\nR 8 16\nR 13 16\nR 0 16\nR 1 7\nR 6 6\nR 11 2\nB 2 4\nR 4 14",
"output": "119"
},
{
"input": "16\nB 3 12\nR 4 4\nR 7 7\nB 14 15\nR 10 16\nR 4 8\nB 12 5\nR 10 13\nR 15 2\nR 9 4\nR 16 12\nB 0 3\nB 12 15\nB 9 15\nR 5 12\nB 1 16",
"output": "102"
},
{
"input": "16\nB 16 7\nR 12 9\nR 8 7\nB 15 1\nB 9 14\nR 7 8\nR 3 6\nR 6 14\nR 4 16\nR 5 0\nB 8 6\nR 6 13\nR 2 14\nB 7 2\nR 16 11\nR 16 8",
"output": "94"
},
{
"input": "16\nB 4 10\nB 11 6\nB 10 9\nB 0 14\nB 10 12\nB 2 9\nB 11 6\nB 1 6\nB 10 12\nB 0 12\nB 7 1\nB 5 9\nB 7 14\nB 13 15\nB 9 2\nB 14 1",
"output": "130"
},
{
"input": "16\nB 14 13\nB 3 1\nB 10 11\nB 2 2\nB 0 10\nR 5 9\nB 10 0\nB 15 15\nB 0 15\nB 12 0\nB 6 13\nB 13 3\nB 15 5\nB 12 11\nB 10 11\nR 11 10",
"output": "129"
},
{
"input": "16\nR 2 0\nR 11 6\nR 12 11\nR 13 5\nR 1 16\nR 16 10\nR 2 0\nR 1 8\nR 6 11\nR 1 13\nR 15 8\nR 2 14\nR 4 5\nR 1 15\nR 4 3\nR 9 2",
"output": "143"
},
{
"input": "16\nB 15 2\nB 10 2\nB 13 13\nB 15 9\nB 10 14\nB 2 10\nB 10 0\nB 14 1\nB 13 8\nB 13 9\nB 16 2\nB 1 9\nB 10 3\nB 0 11\nB 14 11\nB 7 4",
"output": "179"
},
{
"input": "16\nR 2 14\nB 1 6\nR 13 15\nR 0 14\nR 9 12\nB 15 10\nB 9 10\nB 9 11\nB 2 11\nB 8 14\nB 15 16\nB 8 3\nB 8 12\nR 14 7\nB 0 10\nR 12 13",
"output": "108"
},
{
"input": "16\nR 6 16\nR 9 2\nR 14 15\nR 1 0\nR 1 10\nR 9 11\nR 0 11\nB 4 3\nR 8 7\nR 3 10\nR 14 10\nR 6 6\nB 15 12\nR 5 2\nR 11 1\nR 10 6",
"output": "112"
},
{
"input": "16\nR 7 13\nR 7 13\nB 5 8\nB 12 14\nR 10 2\nR 8 7\nR 13 7\nB 10 10\nB 15 9\nR 7 0\nB 7 16\nB 11 9\nB 5 2\nR 14 9\nB 9 5\nR 2 8",
"output": "93"
},
{
"input": "16\nB 11 7\nB 14 10\nB 6 9\nB 14 3\nB 1 8\nB 4 7\nB 12 16\nB 6 2\nB 4 12\nB 4 13\nB 15 11\nB 9 3\nB 12 11\nB 3 13\nB 2 14\nB 0 0",
"output": "133"
},
{
"input": "16\nR 6 11\nB 6 14\nB 7 12\nR 16 6\nR 1 5\nB 6 8\nB 3 0\nR 2 12\nB 10 9\nB 16 0\nR 15 6\nR 0 15\nR 1 10\nB 2 10\nB 5 5\nB 15 2",
"output": "76"
},
{
"input": "16\nR 11 13\nR 14 10\nB 9 12\nR 11 10\nB 9 3\nR 1 7\nB 12 2\nB 6 4\nB 0 4\nR 11 13\nR 14 2\nR 14 9\nR 16 10\nB 16 5\nR 15 13\nR 12 11",
"output": "106"
},
{
"input": "16\nB 5 1\nB 14 15\nB 9 13\nB 11 14\nB 9 1\nB 3 8\nB 11 12\nB 1 14\nB 6 8\nB 7 9\nB 6 13\nB 4 11\nB 7 1\nB 7 0\nB 8 13\nB 10 4",
"output": "134"
},
{
"input": "16\nB 9 3\nR 5 11\nB 11 15\nB 14 1\nB 9 16\nB 16 9\nB 2 11\nR 14 7\nB 12 4\nB 3 15\nB 5 8\nR 3 7\nB 13 0\nB 4 5\nB 11 4\nR 8 13",
"output": "104"
},
{
"input": "16\nR 14 15\nR 13 7\nR 12 16\nR 16 14\nB 0 5\nR 1 9\nR 10 12\nR 10 16\nR 2 16\nB 8 11\nB 5 3\nR 10 0\nR 2 16\nB 12 1\nB 5 12\nB 5 6",
"output": "106"
},
{
"input": "16\nR 10 2\nR 12 11\nR 13 0\nR 10 1\nR 0 3\nR 13 10\nR 2 5\nR 5 9\nR 8 3\nR 3 7\nR 5 15\nR 1 12\nR 8 9\nR 9 13\nR 16 4\nR 2 8",
"output": "128"
},
{
"input": "16\nB 13 4\nR 2 8\nB 13 2\nB 13 5\nB 9 0\nB 16 9\nB 1 6\nR 9 1\nR 14 16\nB 16 10\nB 13 9\nR 16 7\nB 16 7\nB 7 9\nB 1 12\nR 1 0",
"output": "119"
},
{
"input": "16\nR 9 8\nR 11 11\nR 15 2\nR 14 10\nR 8 15\nR 10 10\nR 10 6\nR 3 10\nR 12 12\nR 11 7\nR 13 5\nR 6 2\nR 4 7\nR 13 13\nR 12 11\nR 15 10",
"output": "155"
},
{
"input": "16\nB 1 12\nB 9 15\nR 5 12\nR 7 14\nR 8 8\nR 2 15\nR 13 2\nR 1 2\nR 1 5\nR 15 14\nR 5 10\nB 2 12\nR 4 6\nR 5 4\nR 10 15\nR 15 12",
"output": "134"
},
{
"input": "16\nB 14 15\nB 0 2\nR 6 15\nB 10 2\nB 8 14\nB 5 15\nB 4 13\nB 5 11\nR 8 1\nR 11 10\nB 5 6\nB 8 6\nB 10 6\nR 13 0\nB 2 6\nR 13 4",
"output": "82"
},
{
"input": "16\nR 1 1\nR 8 15\nR 8 16\nR 11 15\nR 16 13\nB 16 16\nR 12 14\nR 0 4\nR 14 13\nR 6 15\nB 14 0\nB 7 1\nB 0 6\nR 10 13\nR 12 15\nB 11 6",
"output": "119"
},
{
"input": "16\nR 4 5\nR 8 3\nR 9 16\nR 14 1\nR 16 11\nR 3 16\nR 11 14\nB 14 14\nR 3 0\nB 2 10\nB 13 12\nB 14 13\nR 6 13\nR 9 8\nR 15 6\nR 8 15",
"output": "127"
},
{
"input": "16\nR 0 15\nB 15 16\nB 10 1\nB 8 6\nR 0 9\nR 14 16\nB 3 7\nR 9 5\nR 10 14\nB 14 7\nR 12 7\nB 12 6\nR 13 13\nB 15 12\nB 9 6\nB 6 8",
"output": "106"
},
{
"input": "16\nR 5 2\nR 5 12\nR 11 3\nR 9 10\nR 8 6\nB 16 0\nB 11 7\nB 13 15\nR 16 9\nR 2 11\nB 11 3\nB 3 2\nR 2 4\nB 13 8\nR 11 14\nR 4 0",
"output": "79"
},
{
"input": "16\nR 0 5\nR 5 0\nR 13 4\nR 11 13\nB 9 12\nR 12 1\nR 3 7\nR 8 8\nR 6 13\nR 14 7\nR 3 15\nB 0 13\nR 9 4\nR 11 3\nR 5 5\nR 1 9",
"output": "109"
},
{
"input": "16\nB 4 9\nR 13 12\nB 13 4\nR 14 0\nB 0 10\nR 15 1\nB 1 0\nB 3 0\nB 13 9\nB 10 11\nB 4 10\nB 8 8\nB 16 3\nB 1 7\nB 16 14\nB 15 11",
"output": "127"
},
{
"input": "16\nR 0 3\nR 5 0\nR 13 6\nR 7 6\nB 0 8\nB 10 2\nR 10 2\nR 0 1\nR 2 5\nR 6 8\nR 3 4\nB 16 10\nR 4 12\nR 16 4\nR 1 4\nR 14 3",
"output": "58"
},
{
"input": "16\nR 4 6\nR 4 13\nR 15 8\nR 10 1\nR 8 6\nR 12 2\nR 1 2\nR 12 11\nR 7 9\nR 2 5\nR 11 0\nR 14 5\nR 11 10\nR 6 16\nR 12 4\nR 11 13",
"output": "127"
},
{
"input": "16\nR 14 3\nB 10 8\nR 13 10\nB 3 6\nB 16 15\nB 4 6\nB 5 7\nR 1 10\nB 14 10\nB 5 11\nR 4 5\nB 1 7\nB 10 2\nB 15 7\nB 9 8\nB 3 15",
"output": "94"
},
{
"input": "16\nB 8 14\nB 1 4\nR 7 11\nR 5 11\nB 8 4\nR 16 7\nR 14 8\nB 14 2\nB 3 6\nB 1 15\nB 4 1\nR 16 2\nR 1 10\nR 4 2\nR 3 16\nR 2 7",
"output": "72"
},
{
"input": "16\nR 13 0\nR 10 7\nR 8 12\nR 7 14\nB 7 1\nB 1 7\nR 4 9\nR 9 11\nB 1 11\nB 14 11\nB 3 12\nR 6 13\nR 6 9\nB 2 14\nR 13 8\nR 16 9",
"output": "95"
},
{
"input": "16\nR 8 3\nR 8 4\nR 9 13\nR 9 1\nR 8 16\nR 13 7\nR 4 2\nR 13 4\nR 8 6\nR 9 7\nR 11 7\nR 6 16\nR 13 9\nR 0 3\nR 16 16\nR 13 1",
"output": "131"
},
{
"input": "16\nR 12 7\nB 16 0\nR 10 15\nB 11 14\nB 15 14\nR 16 8\nR 11 1\nR 8 5\nB 14 1\nB 14 12\nR 11 2\nB 12 10\nR 2 0\nR 7 15\nR 10 8\nB 12 11",
"output": "108"
},
{
"input": "16\nR 8 9\nR 8 4\nR 11 16\nB 6 1\nR 16 12\nR 11 8\nR 3 2\nB 4 14\nB 3 5\nB 10 9\nR 10 14\nR 11 5\nR 9 0\nR 5 10\nR 3 6\nR 9 3",
"output": "87"
},
{
"input": "16\nB 12 4\nB 7 1\nR 12 0\nB 6 5\nB 7 2\nB 14 0\nB 2 12\nR 0 7\nB 9 1\nB 5 5\nB 10 8\nB 0 0\nB 15 16\nB 3 16\nB 5 15\nB 6 12",
"output": "102"
},
{
"input": "16\nR 16 6\nB 16 5\nR 13 1\nB 9 9\nR 7 0\nB 8 1\nB 11 14\nR 12 0\nR 15 5\nR 0 8\nB 2 5\nB 16 11\nB 5 7\nB 10 11\nR 16 7\nR 4 15",
"output": "93"
},
{
"input": "16\nR 12 11\nB 6 1\nR 14 3\nR 11 14\nR 15 14\nR 11 2\nR 2 14\nR 16 8\nR 5 0\nR 12 4\nR 1 16\nR 6 6\nR 11 6\nR 8 6\nR 2 14\nR 10 7",
"output": "128"
},
{
"input": "16\nB 16 14\nR 5 5\nB 14 4\nB 5 1\nB 15 12\nB 6 2\nB 1 14\nB 12 1\nR 12 14\nB 9 1\nR 1 11\nB 13 0\nB 1 7\nB 14 2\nR 12 7\nB 7 0",
"output": "111"
},
{
"input": "16\nB 16 1\nB 12 8\nB 13 15\nB 7 15\nB 16 5\nR 14 6\nB 15 3\nB 0 9\nB 2 16\nB 13 8\nB 10 0\nR 9 11\nB 0 6\nB 6 9\nB 0 9\nB 0 2",
"output": "128"
},
{
"input": "16\nB 4 4\nR 3 14\nB 15 15\nB 0 2\nR 16 11\nR 0 6\nB 5 4\nB 14 2\nR 7 3\nB 8 12\nR 2 12\nR 16 5\nR 6 5\nB 13 14\nR 3 9\nR 15 11",
"output": "85"
},
{
"input": "16\nB 15 8\nR 11 9\nB 15 16\nR 2 6\nR 16 9\nR 12 7\nR 5 4\nR 9 12\nR 13 15\nB 3 9\nR 2 8\nB 14 16\nR 13 5\nR 11 9\nB 13 1\nR 12 13",
"output": "113"
},
{
"input": "16\nB 3 11\nB 10 5\nB 9 1\nB 4 9\nB 7 7\nB 14 7\nB 13 13\nB 4 4\nB 3 11\nR 7 4\nB 1 2\nB 5 12\nB 3 13\nR 9 5\nB 16 9\nB 10 5",
"output": "106"
},
{
"input": "16\nR 7 5\nB 2 10\nB 10 2\nB 6 14\nB 7 5\nB 10 7\nR 5 14\nB 16 13\nR 9 15\nR 4 9\nB 1 14\nR 2 6\nB 9 13\nR 15 1\nB 10 1\nB 8 15",
"output": "89"
},
{
"input": "16\nR 2 9\nB 9 6\nB 11 3\nB 8 1\nR 15 3\nR 12 8\nR 4 15\nR 2 6\nR 15 11\nB 0 5\nB 8 9\nR 11 0\nB 15 11\nR 14 5\nR 4 8\nR 5 7",
"output": "78"
},
{
"input": "16\nB 7 11\nB 9 10\nB 12 4\nB 1 14\nB 15 8\nB 8 9\nB 12 8\nB 16 15\nB 6 15\nB 12 1\nB 8 4\nB 9 12\nR 5 3\nB 11 1\nB 6 8\nB 3 8",
"output": "141"
},
{
"input": "16\nR 2 15\nR 16 6\nB 14 6\nB 3 1\nR 7 6\nB 10 10\nB 4 9\nR 11 8\nB 12 10\nR 8 5\nB 9 15\nR 16 14\nR 10 3\nB 2 13\nB 16 16\nR 0 1",
"output": "95"
},
{
"input": "16\nR 6 8\nR 7 11\nR 13 7\nR 6 6\nR 6 4\nR 5 10\nR 12 9\nR 7 1\nR 1 7\nR 4 3\nR 0 11\nR 14 9\nR 10 11\nB 16 9\nR 10 7\nR 15 10",
"output": "124"
},
{
"input": "16\nR 1 13\nR 7 6\nR 15 8\nR 8 9\nR 15 2\nR 7 10\nR 11 1\nR 2 10\nR 8 11\nR 16 16\nR 0 6\nR 3 3\nR 0 10\nR 7 14\nR 12 16\nB 13 3",
"output": "139"
},
{
"input": "16\nR 7 12\nB 2 3\nR 7 15\nR 3 10\nR 12 7\nR 6 11\nR 1 11\nR 14 4\nR 12 8\nR 3 3\nR 3 5\nR 0 8\nR 8 7\nR 14 13\nR 15 15\nR 1 3",
"output": "136"
},
{
"input": "16\nR 7 0\nR 7 2\nR 11 2\nR 11 2\nR 12 2\nR 4 1\nR 1 1\nB 4 0\nR 14 2\nB 1 2\nR 9 1\nR 11 0\nR 13 0\nR 0 2\nR 11 0\nR 2 0",
"output": "38"
},
{
"input": "16\nB 2 3\nB 1 0\nB 1 1\nB 0 4\nR 1 4\nR 0 5\nB 1 6\nR 1 3\nB 2 4\nB 2 13\nB 2 2\nB 1 1\nB 1 9\nB 0 13\nB 3 2\nB 2 10",
"output": "20"
},
{
"input": "16\nB 0 9\nR 3 11\nB 0 5\nB 4 3\nB 1 1\nB 2 8\nR 3 12\nB 1 2\nB 3 10\nR 4 11\nB 1 1\nR 3 4\nB 3 9\nB 3 1\nB 2 3\nB 1 10",
"output": "29"
},
{
"input": "16\nB 8 1\nR 0 7\nB 2 4\nB 9 6\nR 4 0\nB 5 0\nR 3 0\nR 3 1\nR 1 3\nB 8 0\nB 2 3\nB 8 3\nR 6 5\nR 7 1\nR 0 3\nR 6 6",
"output": "24"
},
{
"input": "16\nB 3 4\nR 1 4\nR 8 1\nB 2 7\nB 0 5\nR 6 0\nR 3 3\nR 4 4\nB 7 0\nR 2 2\nR 7 0\nR 3 0\nB 6 2\nB 8 5\nB 9 7\nR 0 0",
"output": "26"
},
{
"input": "16\nB 0 1\nB 0 6\nB 0 13\nB 0 5\nB 0 13\nB 0 12\nB 0 2\nB 0 9\nB 0 8\nB 0 6\nB 0 0\nB 0 15\nB 0 9\nB 0 0\nB 0 14\nB 0 12",
"output": "24"
},
{
"input": "16\nB 0 4\nB 1 2\nR 1 1\nB 0 0\nB 0 8\nB 0 0\nB 0 13\nB 0 7\nB 2 9\nB 2 14\nB 2 9\nB 1 6\nB 2 11\nB 0 10\nB 1 8\nR 1 13",
"output": "27"
},
{
"input": "16\nB 2 5\nB 0 3\nB 4 11\nB 1 4\nR 1 3\nB 1 10\nB 1 8\nB 1 2\nR 3 1\nB 0 7\nB 2 11\nR 0 11\nR 4 4\nB 4 11\nB 1 3\nB 1 10",
"output": "35"
},
{
"input": "16\nB 0 15\nB 0 2\nB 0 8\nB 1 3\nB 0 0\nB 1 7\nB 0 5\nB 1 7\nB 1 9\nB 1 15\nB 0 1\nB 1 13\nB 1 8\nB 1 5\nB 0 10\nR 0 15",
"output": "23"
},
{
"input": "16\nR 10 4\nR 4 2\nB 0 0\nR 5 4\nB 9 5\nB 2 0\nR 4 2\nR 4 3\nR 1 1\nR 10 5\nR 6 2\nB 7 4\nB 10 6\nB 5 6\nR 5 2\nR 2 2",
"output": "25"
},
{
"input": "16\nB 4 4\nR 5 7\nB 5 6\nR 4 5\nR 2 10\nR 3 0\nB 1 9\nR 4 2\nB 2 2\nB 1 2\nB 5 8\nB 4 6\nB 4 9\nB 2 10\nB 5 5\nB 4 11",
"output": "34"
},
{
"input": "16\nR 0 3\nR 5 6\nR 1 2\nR 0 0\nB 0 5\nB 2 0\nB 5 0\nR 2 4\nB 4 4\nR 4 5\nB 1 6\nR 6 3\nR 7 4\nR 8 2\nB 3 3\nR 6 2",
"output": "21"
},
{
"input": "16\nR 4 0\nR 3 0\nR 2 0\nR 6 0\nR 5 0\nR 3 0\nR 7 0\nR 3 0\nR 6 0\nR 14 0\nR 0 0\nR 14 0\nR 10 0\nR 14 0\nR 9 0\nR 6 0",
"output": "19"
},
{
"input": "16\nB 0 5\nB 0 15\nB 0 10\nB 0 5\nB 0 13\nB 0 5\nB 0 13\nB 0 4\nB 0 12\nB 0 9\nB 0 0\nB 0 13\nB 0 0\nB 0 4\nB 0 4\nB 0 14",
"output": "26"
},
{
"input": "16\nB 1 12\nB 0 13\nB 0 7\nB 1 9\nB 1 15\nB 0 9\nB 0 2\nB 0 10\nB 1 5\nB 0 9\nB 1 2\nR 1 9\nB 0 5\nB 0 1\nB 1 15\nB 0 12",
"output": "37"
},
{
"input": "16\nR 8 6\nR 5 2\nR 4 5\nB 0 2\nR 9 4\nR 9 2\nB 5 4\nB 0 5\nB 9 2\nB 2 3\nB 0 0\nR 5 6\nR 0 2\nR 6 6\nR 3 2\nB 2 6",
"output": "29"
},
{
"input": "16\nB 0 6\nB 0 13\nB 0 2\nB 0 16\nB 0 6\nB 0 12\nB 0 10\nB 0 11\nB 0 4\nB 0 10\nB 0 12\nB 0 8\nB 0 4\nB 0 11\nB 0 0\nB 0 0",
"output": "24"
},
{
"input": "16\nR 6 2\nB 7 3\nR 13 3\nR 4 0\nR 0 2\nR 3 3\nR 5 0\nR 3 3\nR 8 0\nB 8 2\nR 4 3\nR 5 0\nR 9 0\nR 13 3\nB 10 1\nR 10 2",
"output": "28"
},
{
"input": "16\nR 1 0\nR 9 1\nR 11 2\nR 5 2\nR 7 0\nR 11 1\nR 5 1\nR 9 3\nR 11 4\nB 10 4\nR 10 2\nB 9 2\nB 8 3\nB 3 4\nR 5 3\nR 0 0",
"output": "34"
},
{
"input": "16\nR 10 1\nR 13 0\nR 14 1\nR 2 1\nR 4 1\nR 5 0\nR 7 0\nR 11 0\nR 8 1\nR 14 0\nR 10 1\nR 11 0\nR 4 0\nR 3 1\nB 2 0\nR 13 0",
"output": "40"
},
{
"input": "16\nB 0 2\nB 0 8\nB 0 7\nB 0 1\nB 0 14\nB 0 7\nB 0 13\nB 0 12\nB 0 10\nB 0 5\nB 0 4\nB 0 7\nB 0 8\nB 0 15\nB 0 12\nB 0 14",
"output": "35"
},
{
"input": "16\nB 10 3\nB 10 4\nR 9 2\nB 1 3\nR 5 5\nB 8 5\nR 10 6\nR 3 2\nR 8 4\nR 2 4\nR 10 2\nR 6 3\nR 9 5\nB 0 3\nR 7 6\nB 3 5",
"output": "40"
},
{
"input": "16\nR 3 5\nR 7 0\nR 7 1\nB 0 6\nB 4 1\nB 2 7\nR 0 3\nR 8 3\nB 7 1\nB 0 5\nR 4 2\nR 9 7\nR 9 7\nB 6 3\nB 9 6\nR 9 2",
"output": "36"
},
{
"input": "16\nB 1 7\nR 6 4\nR 5 6\nB 9 7\nB 1 6\nR 5 0\nB 0 5\nR 3 6\nR 9 6\nR 0 7\nR 5 7\nB 7 3\nR 4 4\nB 1 0\nR 3 2\nB 9 5",
"output": "33"
},
{
"input": "16\nR 2 0\nB 7 3\nR 4 0\nB 8 3\nB 12 3\nR 7 4\nB 1 2\nR 4 4\nR 3 3\nR 3 3\nR 12 1\nR 2 2\nR 8 0\nR 6 1\nR 8 3\nR 1 0",
"output": "25"
},
{
"input": "16\nB 7 7\nR 1 3\nB 0 3\nB 5 5\nB 5 4\nB 3 0\nB 5 3\nR 2 0\nR 2 1\nB 7 3\nR 3 8\nR 3 1\nR 3 8\nR 2 5\nB 0 5\nB 5 3",
"output": "23"
},
{
"input": "16\nR 1 0\nR 12 0\nR 8 0\nR 6 0\nR 9 0\nR 7 0\nR 5 0\nR 7 0\nR 14 0\nR 6 0\nR 16 0\nR 8 0\nR 2 0\nR 5 0\nR 1 0\nR 10 0",
"output": "22"
},
{
"input": "16\nR 4 11\nR 3 10\nB 4 7\nB 4 11\nR 4 11\nB 3 1\nB 0 6\nB 4 2\nB 1 5\nB 1 2\nB 1 5\nR 2 7\nR 0 8\nB 3 2\nB 3 4\nB 5 9",
"output": "31"
},
{
"input": "16\nR 3 12\nB 2 1\nB 0 8\nB 3 0\nR 1 7\nB 2 6\nB 3 6\nB 2 13\nB 0 3\nB 0 8\nB 2 6\nR 3 10\nB 2 6\nB 3 13\nB 2 9\nB 2 3",
"output": "30"
},
{
"input": "16\nR 10 0\nR 2 4\nB 6 3\nB 2 5\nB 5 4\nR 7 3\nR 2 4\nR 5 5\nR 1 0\nR 5 2\nB 1 3\nR 2 3\nR 1 3\nR 1 4\nR 1 0\nB 10 1",
"output": "25"
},
{
"input": "16\nR 0 6\nB 7 2\nB 0 2\nB 1 4\nR 6 5\nB 0 9\nR 4 4\nB 7 4\nR 1 9\nB 1 5\nR 0 7\nB 1 2\nR 7 8\nB 7 3\nB 1 2\nR 2 1",
"output": "26"
},
{
"input": "16\nB 0 0\nB 0 7\nB 0 15\nB 0 5\nB 0 0\nR 1 13\nB 0 14\nB 0 15\nB 1 10\nB 1 11\nB 1 6\nB 1 9\nB 0 13\nB 0 1\nB 1 9\nB 0 3",
"output": "31"
},
{
"input": "16\nR 12 2\nR 1 3\nR 5 1\nB 6 2\nR 4 1\nR 7 2\nR 1 0\nB 6 2\nR 4 2\nR 11 1\nB 0 0\nR 0 1\nR 8 2\nR 0 2\nR 6 1\nR 8 1",
"output": "19"
},
{
"input": "16\nR 1 10\nR 4 9\nB 4 5\nB 3 2\nB 0 0\nR 2 8\nB 6 10\nB 0 3\nR 0 10\nR 6 6\nB 4 8\nB 0 2\nB 2 6\nB 2 4\nR 0 6\nB 4 6",
"output": "26"
},
{
"input": "16\nB 4 5\nR 5 6\nR 1 0\nB 1 6\nR 5 5\nR 7 3\nR 6 6\nB 7 7\nB 6 6\nB 6 4\nR 2 8\nB 2 5\nB 0 3\nR 1 0\nB 6 4\nR 0 7",
"output": "30"
},
{
"input": "16\nR 3 0\nR 10 1\nR 3 1\nB 9 2\nR 11 2\nR 6 0\nB 7 0\nR 5 2\nR 7 1\nR 3 2\nR 13 0\nR 2 1\nR 5 2\nR 9 2\nR 5 0\nR 7 1",
"output": "23"
},
{
"input": "16\nR 9 1\nR 6 2\nB 1 0\nB 7 6\nR 6 3\nR 10 2\nR 4 4\nR 9 4\nR 9 1\nR 5 2\nB 10 4\nB 7 1\nB 1 4\nB 10 1\nR 10 4\nR 8 5",
"output": "47"
},
{
"input": "16\nB 1 3\nB 2 5\nB 0 3\nB 0 5\nB 0 14\nB 1 10\nB 1 7\nR 1 10\nB 2 6\nB 0 13\nB 1 10\nR 2 1\nB 1 11\nB 2 12\nB 2 12\nB 2 7",
"output": "43"
},
{
"input": "16\nR 3 7\nR 4 5\nB 3 3\nB 2 1\nB 1 5\nR 1 3\nB 8 5\nB 0 4\nB 7 0\nB 7 6\nR 1 0\nR 7 1\nR 9 1\nR 0 6\nR 3 5\nR 1 0",
"output": "23"
},
{
"input": "16\nB 1 11\nR 0 7\nB 2 11\nR 2 4\nR 3 8\nB 0 11\nB 0 13\nB 2 2\nB 2 13\nB 3 13\nB 0 10\nB 1 12\nB 1 0\nB 3 5\nB 0 5\nB 3 0",
"output": "45"
},
{
"input": "16\nR 2 10\nB 6 3\nB 6 6\nR 3 6\nB 5 8\nR 4 7\nB 3 9\nB 1 5\nB 2 10\nB 3 4\nB 1 8\nR 3 6\nB 0 1\nB 6 3\nR 2 3\nR 3 3",
"output": "32"
},
{
"input": "16\nB 3 5\nB 5 0\nB 5 3\nR 3 0\nB 2 9\nR 5 6\nR 1 1\nB 0 0\nR 1 0\nB 1 4\nB 2 2\nB 0 3\nR 3 4\nB 5 6\nB 1 8\nR 5 8",
"output": "20"
},
{
"input": "16\nR 0 1\nB 4 6\nR 4 1\nB 4 6\nB 3 4\nB 5 3\nB 1 0\nB 4 1\nR 5 2\nR 6 2\nR 2 2\nR 6 0\nB 6 4\nR 0 4\nR 5 4\nB 3 4",
"output": "21"
},
{
"input": "16\nR 14 0\nR 13 0\nR 15 0\nR 9 0\nR 1 0\nR 6 0\nR 7 0\nR 16 0\nR 2 0\nR 2 0\nR 13 0\nR 1 0\nR 1 0\nR 6 0\nR 5 0\nR 2 0",
"output": "23"
},
{
"input": "16\nB 0 3\nB 0 0\nB 1 11\nB 0 15\nB 1 4\nB 1 5\nB 0 2\nB 0 7\nB 1 13\nR 0 0\nB 1 2\nB 1 14\nB 0 15\nB 1 3\nB 0 11\nB 1 5",
"output": "27"
},
{
"input": "16\nB 3 13\nB 1 11\nR 1 9\nB 1 8\nR 1 1\nB 2 9\nR 2 2\nB 1 0\nB 0 2\nB 0 10\nB 2 1\nB 1 11\nB 0 6\nB 2 13\nB 2 2\nB 3 7",
"output": "32"
},
{
"input": "16\nB 1 5\nB 2 11\nR 3 12\nB 0 13\nB 1 10\nB 3 0\nB 0 2\nB 3 9\nB 0 9\nB 0 0\nR 1 7\nB 0 13\nB 3 11\nR 0 12\nB 2 0\nB 3 1",
"output": "30"
},
{
"input": "16\nR 6 1\nB 0 2\nR 2 0\nR 4 3\nR 10 3\nR 5 2\nB 8 2\nB 3 2\nR 7 0\nR 6 4\nR 0 1\nR 6 3\nR 2 1\nB 7 3\nR 1 4\nR 7 2",
"output": "21"
},
{
"input": "16\nB 1 0\nR 4 0\nR 1 3\nB 0 1\nR 1 6\nB 1 1\nB 2 3\nB 4 11\nR 0 10\nB 4 5\nB 1 3\nB 4 8\nB 5 9\nB 2 10\nR 0 8\nB 0 7",
"output": "22"
},
{
"input": "15\nB 6 10\nB 7 14\nB 13 0\nB 5 0\nB 13 11\nB 14 12\nB 1 1\nB 2 3\nB 7 12\nB 14 2\nR 13 13\nB 3 2\nB 2 0\nB 7 13\nB 11 0",
"output": "119"
},
{
"input": "14\nB 7 4\nB 2 1\nR 1 4\nR 4 3\nR 2 5\nB 7 0\nR 7 4\nR 9 3\nB 7 2\nR 2 0\nR 4 0\nB 8 2\nR 3 2\nR 1 4",
"output": "24"
},
{
"input": "13\nR 8 13\nB 0 13\nR 4 11\nR 0 6\nR 4 10\nR 12 10\nR 6 2\nR 5 12\nB 4 5\nR 13 9\nR 11 13\nR 7 4\nR 13 10",
"output": "108"
},
{
"input": "12\nB 8 3\nB 0 0\nR 7 2\nB 6 4\nR 2 2\nR 6 1\nR 2 4\nR 8 2\nB 2 2\nR 8 0\nR 4 0\nR 3 0",
"output": "24"
},
{
"input": "16\nB 48694 9\nB 11 8\nB 7024045 1878252\nB 4314597 581044\nB 1 16\nB 7 2365205\nR 13 1772097\nB 9915366 3\nB 1307090 0\nB 512257 14\nB 9 8\nB 8248718 572520\nB 1179802 6591054\nB 7502375 8\nB 6877665 5323304\nB 10 2",
"output": "46930661"
},
{
"input": "16\nR 3194022 2206633\nR 7598252 2294127\nR 4555177 16\nR 7 16\nR 5524187 3\nR 8961703 3137543\nR 6110473 1664451\nB 1 6506251\nR 4 8\nB 9444007 1207864\nR 8660519 5933919\nB 8900264 1190948\nR 4095397 14\nR 6940958 5\nR 3653725 4642427\nR 8457106 7",
"output": "86095713"
},
{
"input": "16\nR 8674993 8971233\nR 2582520 6282477\nR 7 0\nR 15 2629469\nR 2 6589926\nR 8684638 12\nR 1018413 1\nR 4381377 1\nR 14 6\nR 507034 4035379\nR 5823342 8192458\nR 6034370 16\nR 5409631 7943477\nR 15 10\nR 703657 12\nR 1 2",
"output": "44644495"
},
{
"input": "16\nB 7 3400189\nB 7573338 3483856\nB 16 6456081\nB 1 5619084\nB 9287202 11\nB 7 0\nB 8 8\nB 9002360 9\nB 8386052 676560\nB 15 2171807\nB 12 7196573\nB 4 1\nB 7574499 10\nB 3467159 5\nB 8233088 7\nB 3658327 4",
"output": "57182111"
},
{
"input": "16\nR 15 2862279\nB 11 7341661\nR 8113224 14\nR 12 4\nB 7500326 13\nR 11 7864692\nB 10 1600216\nB 6272417 7\nB 2413107 2262787\nB 2903722 5275102\nB 7 6983199\nB 13 10\nR 7358386 5\nB 2121403 9689488\nB 8642840 5\nB 7 7",
"output": "45325462"
},
{
"input": "16\nB 5479752 7\nR 6 9\nR 14 7\nR 5308962 11\nR 8 3317512\nR 0 800093\nR 14 0\nR 3 7\nR 9 5\nR 8 4\nR 1 15\nR 3241174 16\nR 5911816 8\nR 9 202382\nB 16 9\nB 3 14",
"output": "19941704"
},
{
"input": "16\nB 5993857 6753325\nB 3 4\nR 12 10\nB 3 3961508\nR 9 16\nB 13 2097511\nB 5654201 5\nB 12 2\nB 3136140 6284762\nB 9597778 7602232\nR 12 2467450\nB 5531904 663702\nR 1615498 6\nB 15 7101011\nR 8797406 2991867\nB 13 16",
"output": "40326831"
},
{
"input": "16\nB 13 3517924\nR 7769913 8\nB 3512765 15\nB 15 4314415\nR 11 2\nB 2333262 0\nR 14 6299314\nR 418234 3\nB 15 4818359\nB 5 15\nR 740265 4457029\nB 6345450 3\nB 3874715 11\nB 15 1\nB 15 6381009\nB 1989067 2167759",
"output": "31955793"
},
{
"input": "16\nB 14 2561206\nB 4 8\nB 12 2\nB 1227117 1332663\nR 12 5155350\nR 4174184 9854210\nB 15 12\nR 6369564 6\nB 3159971 228465\nB 1244479 7016135\nR 15 3\nB 615684 3778774\nB 10 3940746\nB 9 5973308\nB 9 8571654\nR 8575546 12",
"output": "48412473"
},
{
"input": "7\nR 4 3\nB 1 2\nR 3 12\nR 6 3\nB 7 3\nB 9 5\nB 10 8",
"output": "35"
},
{
"input": "7\nB 1 7\nB 2 0\nB 12 3\nB 8 11\nB 6 11\nB 7 11\nB 6 5",
"output": "49"
},
{
"input": "7\nR 6 5\nR 7 2\nR 5 7\nR 4 10\nB 0 5\nB 6 8\nB 9 8",
"output": "38"
},
{
"input": "7\nR 2 5\nR 3 12\nR 1 3\nR 1 6\nR 12 3\nR 4 2\nR 4 11",
"output": "49"
},
{
"input": "8\nR 9 13\nB 4 5\nB 1 8\nB 9 9\nB 0 11\nB 0 2\nR 1 7\nB 10 11",
"output": "47"
},
{
"input": "8\nB 0 4\nR 2 1\nB 11 11\nR 2 4\nR 6 8\nB 5 11\nB 4 12\nR 9 4",
"output": "44"
},
{
"input": "8\nB 13 12\nB 9 5\nB 7 14\nB 4 0\nB 3 5\nB 2 3\nB 7 10\nB 7 6",
"output": "60"
},
{
"input": "8\nB 3 11\nB 1 7\nB 1 0\nR 13 2\nR 9 9\nB 8 10\nB 2 8\nR 13 8",
"output": "47"
},
{
"input": "6\nR 2 9\nB 3 2\nR 10 7\nR 9 8\nB 9 11\nB 9 7",
"output": "42"
},
{
"input": "6\nB 3 3\nB 3 6\nB 5 10\nB 8 10\nB 0 8\nB 7 9",
"output": "37"
},
{
"input": "6\nR 9 0\nB 0 5\nB 5 4\nR 0 8\nB 3 5\nB 5 11",
"output": "29"
},
{
"input": "6\nB 7 2\nB 1 4\nR 0 2\nR 0 10\nR 6 2\nR 3 9",
"output": "26"
}
] | 1,693,061,199
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 0
|
print("_RANDOM_GUESS_1693061199.6010046")# 1693061199.601023
|
Title: Hongcow Buys a Deck of Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Hongcow goes to the store and sees a brand new deck of *n* special cards. Each individual card is either red or blue. He decides he wants to buy them immediately. To do this, he needs to play a game with the owner of the store.
This game takes some number of turns to complete. On a turn, Hongcow may do one of two things:
- Collect tokens. Hongcow collects 1 red token and 1 blue token by choosing this option (thus, 2 tokens in total per one operation). - Buy a card. Hongcow chooses some card and spends tokens to purchase it as specified below.
The *i*-th card requires *r**i* red resources and *b**i* blue resources. Suppose Hongcow currently has *A* red cards and *B* blue cards. Then, the *i*-th card will require Hongcow to spend *max*(*r**i*<=-<=*A*,<=0) red tokens, and *max*(*b**i*<=-<=*B*,<=0) blue tokens. Note, only tokens disappear, but the cards stay with Hongcow forever. Each card can be bought only once.
Given a description of the cards and their costs determine the minimum number of turns Hongcow needs to purchase all cards.
Input Specification:
The first line of input will contain a single integer *n* (1<=≤<=*n*<=≤<=16).
The next *n* lines of input will contain three tokens *c**i*, *r**i* and *b**i*. *c**i* will be 'R' or 'B', denoting the color of the card as red or blue. *r**i* will be an integer denoting the amount of red resources required to obtain the card, and *b**i* will be an integer denoting the amount of blue resources required to obtain the card (0<=≤<=*r**i*,<=*b**i*<=≤<=107).
Output Specification:
Output a single integer, denoting the minimum number of turns needed to acquire all the cards.
Demo Input:
['3\nR 0 1\nB 1 0\nR 1 1\n', '3\nR 3 0\nR 2 0\nR 1 0\n']
Demo Output:
['4\n', '6\n']
Note:
For the first sample, Hongcow's four moves are as follows:
1. Collect tokens 1. Buy card 1 1. Buy card 2 1. Buy card 3
For the second sample, one optimal strategy is as follows:
1. Collect tokens 1. Collect tokens 1. Buy card 2 1. Collect tokens 1. Buy card 3 1. Buy card 1
|
```python
print("_RANDOM_GUESS_1693061199.6010046")# 1693061199.601023
```
| 0
|
|
652
|
E
|
Pursuit For Artifacts
|
PROGRAMMING
| 2,300
|
[
"dfs and similar",
"dsu",
"graphs",
"trees"
] | null | null |
Johnny is playing a well-known computer game. The game are in some country, where the player can freely travel, pass quests and gain an experience.
In that country there are *n* islands and *m* bridges between them, so you can travel from any island to any other. In the middle of some bridges are lying ancient powerful artifacts. Johnny is not interested in artifacts, but he can get some money by selling some artifact.
At the start Johnny is in the island *a* and the artifact-dealer is in the island *b* (possibly they are on the same island). Johnny wants to find some artifact, come to the dealer and sell it. The only difficulty is that bridges are too old and destroying right after passing over them. Johnnie's character can't swim, fly and teleport, so the problem became too difficult.
Note that Johnny can't pass the half of the bridge, collect the artifact and return to the same island.
Determine if Johnny can find some artifact and sell it.
|
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=3·105, 0<=≤<=*m*<=≤<=3·105) — the number of islands and bridges in the game.
Each of the next *m* lines contains the description of the bridge — three integers *x**i*, *y**i*, *z**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*, 0<=≤<=*z**i*<=≤<=1), where *x**i* and *y**i* are the islands connected by the *i*-th bridge, *z**i* equals to one if that bridge contains an artifact and to zero otherwise. There are no more than one bridge between any pair of islands. It is guaranteed that it's possible to travel between any pair of islands.
The last line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*) — the islands where are Johnny and the artifact-dealer respectively.
|
If Johnny can find some artifact and sell it print the only word "YES" (without quotes). Otherwise print the word "NO" (without quotes).
|
[
"6 7\n1 2 0\n2 3 0\n3 1 0\n3 4 1\n4 5 0\n5 6 0\n6 4 0\n1 6\n",
"5 4\n1 2 0\n2 3 0\n3 4 0\n2 5 1\n1 4\n",
"5 6\n1 2 0\n2 3 0\n3 1 0\n3 4 0\n4 5 1\n5 3 0\n1 2\n"
] |
[
"YES\n",
"NO\n",
"YES\n"
] |
none
| 0
|
[
{
"input": "6 7\n1 2 0\n2 3 0\n3 1 0\n3 4 1\n4 5 0\n5 6 0\n6 4 0\n1 6",
"output": "YES"
},
{
"input": "5 4\n1 2 0\n2 3 0\n3 4 0\n2 5 1\n1 4",
"output": "NO"
},
{
"input": "5 6\n1 2 0\n2 3 0\n3 1 0\n3 4 0\n4 5 1\n5 3 0\n1 2",
"output": "YES"
},
{
"input": "1 0\n1 1",
"output": "NO"
},
{
"input": "2 1\n1 2 1\n1 2",
"output": "YES"
},
{
"input": "2 1\n1 2 1\n1 1",
"output": "NO"
},
{
"input": "3 2\n1 2 1\n2 3 0\n3 1",
"output": "YES"
},
{
"input": "3 2\n1 2 1\n2 3 0\n2 3",
"output": "NO"
},
{
"input": "3 3\n1 2 0\n2 3 0\n3 1 1\n2 2",
"output": "YES"
},
{
"input": "4 4\n1 2 0\n2 3 0\n3 4 1\n4 2 0\n1 2",
"output": "YES"
},
{
"input": "4 4\n1 2 1\n2 3 0\n3 4 0\n4 2 0\n2 3",
"output": "NO"
},
{
"input": "5 5\n1 2 0\n2 3 0\n3 4 1\n4 2 0\n2 5 0\n1 5",
"output": "YES"
},
{
"input": "6 6\n1 2 0\n2 3 0\n3 4 0\n2 5 0\n5 4 1\n4 6 0\n1 6",
"output": "YES"
},
{
"input": "9 11\n1 2 0\n2 3 0\n3 1 0\n3 4 0\n4 5 0\n5 6 1\n6 4 0\n6 7 0\n7 8 0\n8 9 0\n9 7 0\n1 9",
"output": "YES"
},
{
"input": "9 11\n1 2 0\n2 3 1\n3 1 0\n3 4 0\n4 5 0\n5 6 0\n6 4 0\n6 7 0\n7 8 0\n8 9 0\n9 7 0\n1 9",
"output": "YES"
},
{
"input": "9 11\n1 2 0\n2 3 0\n3 1 0\n3 4 0\n4 5 0\n5 6 0\n6 4 0\n6 7 1\n7 8 0\n8 9 0\n9 7 0\n1 9",
"output": "YES"
},
{
"input": "9 11\n1 2 0\n2 3 0\n3 1 0\n3 4 0\n4 5 0\n5 6 1\n6 4 0\n6 7 0\n7 8 0\n8 9 0\n9 7 0\n4 5",
"output": "YES"
},
{
"input": "9 11\n1 2 0\n2 3 0\n3 1 1\n3 4 0\n4 5 0\n5 6 0\n6 4 0\n6 7 0\n7 8 0\n8 9 1\n9 7 0\n4 5",
"output": "NO"
},
{
"input": "12 11\n1 10 0\n5 10 0\n8 10 0\n6 5 0\n9 10 1\n3 6 1\n12 6 0\n4 8 0\n7 9 1\n2 4 1\n11 9 1\n7 2",
"output": "YES"
},
{
"input": "12 15\n5 1 0\n11 1 1\n4 11 0\n3 4 0\n2 3 1\n8 4 0\n12 11 0\n6 12 0\n10 6 0\n7 3 0\n9 4 0\n7 8 0\n11 10 0\n10 12 0\n1 6 0\n2 8",
"output": "YES"
},
{
"input": "12 17\n8 3 0\n11 8 0\n4 8 0\n6 11 1\n12 11 0\n7 8 0\n10 11 0\n5 4 0\n9 10 0\n2 6 0\n1 4 0\n10 12 0\n9 11 0\n12 1 0\n7 1 0\n9 12 0\n10 8 0\n2 8",
"output": "YES"
},
{
"input": "8 7\n3 7 0\n5 3 0\n2 5 0\n1 3 0\n8 3 0\n6 5 0\n4 6 0\n5 8",
"output": "NO"
},
{
"input": "33 58\n17 11 0\n9 17 0\n14 9 0\n3 9 0\n26 14 0\n5 14 0\n10 11 0\n23 11 0\n30 9 0\n18 3 0\n25 17 0\n21 5 0\n13 11 0\n20 14 0\n32 23 0\n29 21 0\n16 21 0\n33 20 0\n1 32 0\n15 16 0\n22 13 0\n12 17 0\n8 32 0\n7 11 0\n6 29 0\n2 21 0\n19 3 0\n4 6 0\n27 8 0\n24 26 0\n28 27 0\n31 4 0\n20 23 0\n4 26 0\n33 25 0\n4 20 0\n32 7 0\n24 12 0\n13 17 0\n33 3 0\n22 15 0\n32 17 0\n11 30 0\n19 18 0\n14 22 0\n13 26 0\n6 25 0\n6 15 0\n15 11 0\n20 12 0\n14 11 0\n11 19 0\n19 21 0\n16 28 0\n22 19 0\n21 14 0\n14 27 0\n11 9 0\n3 7",
"output": "NO"
}
] | 1,643,271,493
| 2,147,483,647
|
PyPy 3-64
|
RUNTIME_ERROR
|
TESTS
| 21
| 2,495
| 118,579,200
|
from collections import defaultdict
I = lambda: [int(i) for i in input().split()]
G = defaultdict(list)
def bridges(n, G):
used, tin, fup = [0] * n, [-1] * n, [-1] * n
timer, ans = [0], []
def dfs(node, par=-1):
used[node] = 1
tin[node] = fup[node] = timer[0] + 1
timer[0] += 1
for child, _ in G[node]:
if child == par: continue
if used[child] == 1:
fup[node] = min(fup[node], tin[child])
else:
dfs(child, node)
fup[node] = min(fup[node], fup[child])
if fup[child] > tin[node]: ans.append((node, child))
for i in range(n):
if not used[i]: dfs(i)
return ans
n, m = I()
edges = {}
for _ in range(m):
x, y, w = I()
G[x-1] += [(y-1, w)]
G[y-1] += [(x-1, w)]
edges[x-1, y-1] = w
V = set()
par = {}
def dfs(node):
V.add(node)
for child, _ in G[node]:
if child in V: continue
par[child] = node
dfs(child)
a, b = I()
dfs(a - 1)
br = set(bridges(n, G)) # with -1 shift already, set of bridges
path = [b - 1]
last = b - 1
while last != a - 1:
last = par[last]
path += [last]
#print(path) # path from pavel to trader
for x, y in zip(path, path[1:]):
br.discard((x, y))
br.discard((y, x))
#print("BBR", br)
G2 = defaultdict(list)
for x, y in edges:
w = edges[x, y]
if (x, y) in br or (y, x) in br: continue
G2[x] += [(y, w)]
G2[y] += [(x, w)]
ans = [False]
V2 = set()
def dfs2(node):
V2.add(node)
for child, w in G2[node]:
if w == 1: ans[0] = True
if child in V2: continue
dfs2(child)
dfs2(a - 1)
print("YES" if ans[0] else "NO")
|
Title: Pursuit For Artifacts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johnny is playing a well-known computer game. The game are in some country, where the player can freely travel, pass quests and gain an experience.
In that country there are *n* islands and *m* bridges between them, so you can travel from any island to any other. In the middle of some bridges are lying ancient powerful artifacts. Johnny is not interested in artifacts, but he can get some money by selling some artifact.
At the start Johnny is in the island *a* and the artifact-dealer is in the island *b* (possibly they are on the same island). Johnny wants to find some artifact, come to the dealer and sell it. The only difficulty is that bridges are too old and destroying right after passing over them. Johnnie's character can't swim, fly and teleport, so the problem became too difficult.
Note that Johnny can't pass the half of the bridge, collect the artifact and return to the same island.
Determine if Johnny can find some artifact and sell it.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=3·105, 0<=≤<=*m*<=≤<=3·105) — the number of islands and bridges in the game.
Each of the next *m* lines contains the description of the bridge — three integers *x**i*, *y**i*, *z**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*, 0<=≤<=*z**i*<=≤<=1), where *x**i* and *y**i* are the islands connected by the *i*-th bridge, *z**i* equals to one if that bridge contains an artifact and to zero otherwise. There are no more than one bridge between any pair of islands. It is guaranteed that it's possible to travel between any pair of islands.
The last line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*) — the islands where are Johnny and the artifact-dealer respectively.
Output Specification:
If Johnny can find some artifact and sell it print the only word "YES" (without quotes). Otherwise print the word "NO" (without quotes).
Demo Input:
['6 7\n1 2 0\n2 3 0\n3 1 0\n3 4 1\n4 5 0\n5 6 0\n6 4 0\n1 6\n', '5 4\n1 2 0\n2 3 0\n3 4 0\n2 5 1\n1 4\n', '5 6\n1 2 0\n2 3 0\n3 1 0\n3 4 0\n4 5 1\n5 3 0\n1 2\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none
|
```python
from collections import defaultdict
I = lambda: [int(i) for i in input().split()]
G = defaultdict(list)
def bridges(n, G):
used, tin, fup = [0] * n, [-1] * n, [-1] * n
timer, ans = [0], []
def dfs(node, par=-1):
used[node] = 1
tin[node] = fup[node] = timer[0] + 1
timer[0] += 1
for child, _ in G[node]:
if child == par: continue
if used[child] == 1:
fup[node] = min(fup[node], tin[child])
else:
dfs(child, node)
fup[node] = min(fup[node], fup[child])
if fup[child] > tin[node]: ans.append((node, child))
for i in range(n):
if not used[i]: dfs(i)
return ans
n, m = I()
edges = {}
for _ in range(m):
x, y, w = I()
G[x-1] += [(y-1, w)]
G[y-1] += [(x-1, w)]
edges[x-1, y-1] = w
V = set()
par = {}
def dfs(node):
V.add(node)
for child, _ in G[node]:
if child in V: continue
par[child] = node
dfs(child)
a, b = I()
dfs(a - 1)
br = set(bridges(n, G)) # with -1 shift already, set of bridges
path = [b - 1]
last = b - 1
while last != a - 1:
last = par[last]
path += [last]
#print(path) # path from pavel to trader
for x, y in zip(path, path[1:]):
br.discard((x, y))
br.discard((y, x))
#print("BBR", br)
G2 = defaultdict(list)
for x, y in edges:
w = edges[x, y]
if (x, y) in br or (y, x) in br: continue
G2[x] += [(y, w)]
G2[y] += [(x, w)]
ans = [False]
V2 = set()
def dfs2(node):
V2.add(node)
for child, w in G2[node]:
if w == 1: ans[0] = True
if child in V2: continue
dfs2(child)
dfs2(a - 1)
print("YES" if ans[0] else "NO")
```
| -1
|
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.