contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
sequencelengths 0
11
| title
stringclasses 522
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
sequencelengths 0
7
| demo-output
sequencelengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"output": "8"
},
{
"input": "31",
"output": "3"
},
{
"input": "59",
"output": "8"
},
{
"input": "79",
"output": "9"
},
{
"input": "7",
"output": "3"
},
{
"input": "55",
"output": "4"
},
{
"input": "40",
"output": "2"
},
{
"input": "719",
"output": "13"
},
{
"input": "847",
"output": "13"
},
{
"input": "225",
"output": "4"
},
{
"input": "4704",
"output": "51"
},
{
"input": "1132",
"output": "15"
},
{
"input": "7811",
"output": "80"
},
{
"input": "7981",
"output": "84"
},
{
"input": "82655",
"output": "830"
},
{
"input": "6364",
"output": "70"
},
{
"input": "74611",
"output": "748"
},
{
"input": "45391",
"output": "459"
},
{
"input": "620448",
"output": "6210"
},
{
"input": "265145",
"output": "2654"
},
{
"input": "671704",
"output": "6721"
},
{
"input": "365173",
"output": "3658"
},
{
"input": "7130872",
"output": "71314"
},
{
"input": "9628747",
"output": "96292"
},
{
"input": "8898399",
"output": "88993"
},
{
"input": "9497953",
"output": "94985"
},
{
"input": "19070947",
"output": "190714"
},
{
"input": "20185520",
"output": "201856"
},
{
"input": "91402248",
"output": "914028"
},
{
"input": "27035533",
"output": "270360"
},
{
"input": "22717528",
"output": "227180"
},
{
"input": "24403439",
"output": "244041"
},
{
"input": "163565555",
"output": "1635659"
},
{
"input": "152541908",
"output": "1525423"
},
{
"input": "668439837",
"output": "6684403"
},
{
"input": "20",
"output": "1"
},
{
"input": "999999999",
"output": "10000009"
},
{
"input": "10",
"output": "1"
},
{
"input": "7",
"output": "3"
},
{
"input": "6",
"output": "2"
},
{
"input": "99999999",
"output": "1000009"
},
{
"input": "1000001",
"output": "10001"
},
{
"input": "2521",
"output": "27"
}
] | 1,696,308,138 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
ans = 0
a = [100,20,10,5,1]
for i in range(len(a)):
ans+=n/a[i]
n = n%a[i]
print(int(ans) -1) | Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
Input Specification:
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output Specification:
Output the minimum number of bills that Allen could receive.
Demo Input:
['125\n', '43\n', '1000000000\n']
Demo Output:
['3\n', '5\n', '10000000\n']
Note:
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | ```python
n = int(input())
ans = 0
a = [100,20,10,5,1]
for i in range(len(a)):
ans+=n/a[i]
n = n%a[i]
print(int(ans) -1)
``` | 0 |
|
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well. | The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. | Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". | [
")((())))(()())\n",
"))(\n"
] | [
"6 2\n",
"0 1\n"
] | none | 0 | [
{
"input": ")((())))(()())",
"output": "6 2"
},
{
"input": "))(",
"output": "0 1"
},
{
"input": "()(())()",
"output": "8 1"
},
{
"input": "((((()(((",
"output": "2 1"
},
{
"input": "))))()())))",
"output": "4 1"
},
{
"input": "(()())()(())()()())())()((()(()(())()()())((()(())()(()()()()))()(())()(((()())()(()((())()(())(()))",
"output": "28 1"
},
{
"input": ")(()(((((())))))(((()))))))((()(((((((())())()))))((((((((())))((((((())))))(()((((()))))(()))))))))",
"output": "68 1"
},
{
"input": "())(((((())())((((()))(())))())())(((()(()()()())(())()))((()(())())()()))()(()())))))(()))((())((((",
"output": "80 1"
},
{
"input": "))(((((((()((((())(((((((((()()))))(()())()((())())))((((()))(()()()))))(()()))())))))((())())()))((",
"output": "92 1"
}
] | 1,598,145,106 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 20,172,800 | line = input()
maxLength = 0
n = 1
brackets = 0
length = 0
for b in line:
if b == "(":
brackets += 1
else:
brackets -= 1
if brackets >= 0:
length += 1
if brackets <= 0:
if length > maxLength:
maxLength = length
n = 1
elif length == maxLength:
n += 1
length = 0
brackets = max(brackets, 0)
print(str(maxLength) + " " + str(1 if maxLength == 0 else n)) | Title: Longest Regular Bracket Sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well.
Input Specification:
The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106.
Output Specification:
Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".
Demo Input:
[')((())))(()())\n', '))(\n']
Demo Output:
['6 2\n', '0 1\n']
Note:
none | ```python
line = input()
maxLength = 0
n = 1
brackets = 0
length = 0
for b in line:
if b == "(":
brackets += 1
else:
brackets -= 1
if brackets >= 0:
length += 1
if brackets <= 0:
if length > maxLength:
maxLength = length
n = 1
elif length == maxLength:
n += 1
length = 0
brackets = max(brackets, 0)
print(str(maxLength) + " " + str(1 if maxLength == 0 else n))
``` | 0 |
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo"
},
{
"input": "805",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1000",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1",
"output": "O"
},
{
"input": "2",
"output": "OO"
},
{
"input": "3",
"output": "OOO"
},
{
"input": "5",
"output": "OOOoO"
},
{
"input": "17",
"output": "OOOoOooOooooOoooo"
},
{
"input": "49",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo"
},
{
"input": "256",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo"
},
{
"input": "512",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "933",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "61",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo"
},
{
"input": "781",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "999",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
}
] | 1,653,969,963 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 46 | 0 | l=[1,1,2]
a,b,c=1,1,2
for i in range(1,1000):
a,b,c=b,a+b,b+c
l.append(c)
n=int(input())
for i in range(1,n+1):
if i in l:
print('O', end='')
else:
print('o', end='') | Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
Input Specification:
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Output Specification:
Print Eleven's new name on the first and only line of output.
Demo Input:
['8\n', '15\n']
Demo Output:
['OOOoOooO\n', 'OOOoOooOooooOoo\n']
Note:
none | ```python
l=[1,1,2]
a,b,c=1,1,2
for i in range(1,1000):
a,b,c=b,a+b,b+c
l.append(c)
n=int(input())
for i in range(1,n+1):
if i in l:
print('O', end='')
else:
print('o', end='')
``` | 3 |
|
780 | C | Andryusha and Colored Balloons | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"greedy",
"trees"
] | null | null | Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of *n* squares connected with (*n*<=-<=1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a colored balloon at each of the squares. The baloons' colors are described by positive integers, starting from 1. In order to make the park varicolored, Andryusha wants to choose the colors in a special way. More precisely, he wants to use such colors that if *a*, *b* and *c* are distinct squares that *a* and *b* have a direct path between them, and *b* and *c* have a direct path between them, then balloon colors on these three squares are distinct.
Andryusha wants to use as little different colors as possible. Help him to choose the colors! | The first line contains single integer *n* (3<=≤<=*n*<=≤<=2·105) — the number of squares in the park.
Each of the next (*n*<=-<=1) lines contains two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*) — the indices of two squares directly connected by a path.
It is guaranteed that any square is reachable from any other using the paths. | In the first line print single integer *k* — the minimum number of colors Andryusha has to use.
In the second line print *n* integers, the *i*-th of them should be equal to the balloon color on the *i*-th square. Each of these numbers should be within range from 1 to *k*. | [
"3\n2 3\n1 3\n",
"5\n2 3\n5 3\n4 3\n1 3\n",
"5\n2 1\n3 2\n4 3\n5 4\n"
] | [
"3\n1 3 2 ",
"5\n1 3 2 5 4 ",
"3\n1 2 3 1 2 "
] | In the first sample the park consists of three squares: 1 → 3 → 2. Thus, the balloon colors have to be distinct.
In the second example there are following triples of consequently connected squares:
- 1 → 3 → 2 - 1 → 3 → 4 - 1 → 3 → 5 - 2 → 3 → 4 - 2 → 3 → 5 - 4 → 3 → 5
In the third example there are following triples:
- 1 → 2 → 3 - 2 → 3 → 4 - 3 → 4 → 5 | 1,250 | [
{
"input": "3\n2 3\n1 3",
"output": "3\n1 3 2 "
},
{
"input": "5\n2 3\n5 3\n4 3\n1 3",
"output": "5\n1 3 2 5 4 "
},
{
"input": "5\n2 1\n3 2\n4 3\n5 4",
"output": "3\n1 2 3 1 2 "
},
{
"input": "10\n5 3\n9 2\n7 1\n3 8\n4 1\n1 9\n10 1\n8 9\n6 2",
"output": "5\n1 2 1 3 2 1 2 3 4 5 "
},
{
"input": "3\n2 1\n3 2",
"output": "3\n1 2 3 "
},
{
"input": "10\n2 7\n8 2\n9 8\n1 9\n4 1\n3 4\n6 3\n10 6\n5 10",
"output": "3\n1 1 2 3 2 1 2 3 2 3 "
},
{
"input": "5\n4 2\n3 1\n3 4\n3 5",
"output": "4\n1 1 2 3 4 "
},
{
"input": "7\n3 6\n3 1\n3 2\n3 5\n3 4\n3 7",
"output": "7\n1 4 2 6 5 3 7 "
},
{
"input": "10\n8 6\n10 5\n8 4\n2 7\n3 8\n10 3\n3 9\n2 1\n3 2",
"output": "5\n1 2 4 3 1 2 3 1 5 3 "
},
{
"input": "50\n45 2\n4 48\n16 4\n17 29\n29 33\n31 2\n47 41\n41 33\n22 6\n44 40\n32 24\n12 40\n28 16\n18 30\n20 41\n25 45\n35 29\n10 32\n1 48\n15 50\n6 9\n43 2\n33 2\n38 33\n8 2\n36 7\n26 48\n50 8\n34 31\n48 33\n13 45\n37 33\n7 6\n40 32\n3 6\n30 49\n49 33\n11 40\n19 40\n24 2\n14 50\n5 50\n42 16\n23 2\n9 45\n39 6\n46 48\n27 13\n21 2",
"output": "9\n1 4 4 3 4 2 3 6 5 2 5 4 3 3 2 1 2 2 6 2 9 1 8 7 2 4 2 2 1 1 2 1 5 1 3 1 7 6 6 3 3 4 3 2 1 6 1 2 8 1 "
},
{
"input": "50\n8 37\n40 8\n38 40\n10 38\n29 10\n33 29\n17 33\n25 17\n19 25\n3 19\n13 3\n24 13\n12 24\n5 12\n41 5\n11 41\n27 11\n45 27\n6 45\n35 6\n9 35\n50 9\n32 50\n21 32\n22 21\n1 22\n31 1\n28 31\n4 28\n30 4\n7 30\n48 7\n46 48\n16 46\n49 16\n39 49\n18 39\n14 18\n34 14\n23 34\n20 23\n15 20\n44 15\n42 44\n2 42\n36 2\n43 36\n26 43\n47 26",
"output": "3\n1 3 2 1 1 2 2 2 3 2 2 2 1 1 3 2 2 2 3 1 3 2 2 3 1 3 1 2 1 3 3 1 3 3 1 2 3 3 3 1 3 1 1 2 3 3 2 1 1 2 "
},
{
"input": "50\n7 5\n6 40\n49 43\n48 2\n44 11\n10 3\n46 49\n22 18\n17 33\n4 29\n48 4\n47 41\n24 19\n48 8\n1 21\n2 17\n17 34\n16 10\n17 20\n1 22\n44 32\n6 28\n7 1\n47 26\n28 44\n23 50\n21 15\n1 30\n7 27\n28 25\n17 23\n14 42\n6 46\n5 24\n44 9\n25 39\n46 47\n21 35\n7 16\n34 12\n45 14\n35 36\n28 13\n6 48\n46 37\n39 45\n40 7\n2 31\n30 38",
"output": "6\n1 2 2 3 2 1 4 5 5 1 1 2 5 3 3 5 1 2 3 5 2 3 6 1 4 2 3 2 1 5 3 4 3 4 4 1 5 2 1 6 1 1 1 3 2 3 4 4 2 2 "
}
] | 1,488,713,041 | 7,741 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 62 | 5,120,000 | from collections import deque
n = int(input())
g = [[] for i in range(n)]
for i in range(n - 1):
v, u = map(int, input().split())
g[v - 1].append(u - 1)
g[u - 1].append(v - 1)
ans = 0
cnt = 0
for i in range(n):
ans = max(ans, len(g[i]))
ans += 1
used = [False for i in range(n)]
q = deque()
q.append([0, -1])
ansi = [-1 for i in range(n + 1)]
prev = [-1 for i in range(n)]
while len(q):
v = q.popleft()
used[v[0]] = True
if cnt % ans == prev[v[1]]:
cnt += 1
cnt += 1
ansi[v[0]] = cnt % ans
for elem in g[v[0]]:
if not used[elem]:
prev[elem] = v[0]
q.append([elem, v[0]])
print(ans)
for i in range(n):
print(ansi[i] + 1, end=" ") | Title: Andryusha and Colored Balloons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of *n* squares connected with (*n*<=-<=1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a colored balloon at each of the squares. The baloons' colors are described by positive integers, starting from 1. In order to make the park varicolored, Andryusha wants to choose the colors in a special way. More precisely, he wants to use such colors that if *a*, *b* and *c* are distinct squares that *a* and *b* have a direct path between them, and *b* and *c* have a direct path between them, then balloon colors on these three squares are distinct.
Andryusha wants to use as little different colors as possible. Help him to choose the colors!
Input Specification:
The first line contains single integer *n* (3<=≤<=*n*<=≤<=2·105) — the number of squares in the park.
Each of the next (*n*<=-<=1) lines contains two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*) — the indices of two squares directly connected by a path.
It is guaranteed that any square is reachable from any other using the paths.
Output Specification:
In the first line print single integer *k* — the minimum number of colors Andryusha has to use.
In the second line print *n* integers, the *i*-th of them should be equal to the balloon color on the *i*-th square. Each of these numbers should be within range from 1 to *k*.
Demo Input:
['3\n2 3\n1 3\n', '5\n2 3\n5 3\n4 3\n1 3\n', '5\n2 1\n3 2\n4 3\n5 4\n']
Demo Output:
['3\n1 3 2 ', '5\n1 3 2 5 4 ', '3\n1 2 3 1 2 ']
Note:
In the first sample the park consists of three squares: 1 → 3 → 2. Thus, the balloon colors have to be distinct.
In the second example there are following triples of consequently connected squares:
- 1 → 3 → 2 - 1 → 3 → 4 - 1 → 3 → 5 - 2 → 3 → 4 - 2 → 3 → 5 - 4 → 3 → 5
In the third example there are following triples:
- 1 → 2 → 3 - 2 → 3 → 4 - 3 → 4 → 5 | ```python
from collections import deque
n = int(input())
g = [[] for i in range(n)]
for i in range(n - 1):
v, u = map(int, input().split())
g[v - 1].append(u - 1)
g[u - 1].append(v - 1)
ans = 0
cnt = 0
for i in range(n):
ans = max(ans, len(g[i]))
ans += 1
used = [False for i in range(n)]
q = deque()
q.append([0, -1])
ansi = [-1 for i in range(n + 1)]
prev = [-1 for i in range(n)]
while len(q):
v = q.popleft()
used[v[0]] = True
if cnt % ans == prev[v[1]]:
cnt += 1
cnt += 1
ansi[v[0]] = cnt % ans
for elem in g[v[0]]:
if not used[elem]:
prev[elem] = v[0]
q.append([elem, v[0]])
print(ans)
for i in range(n):
print(ansi[i] + 1, end=" ")
``` | 0 |
|
548 | B | Mike and Fun | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"greedy",
"implementation"
] | null | null | Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of row number *i* by (*i*,<=*j*). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.
They play for *q* rounds. In each round, Mike chooses a bear (*i*,<=*j*) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | The first line of input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=500 and 1<=≤<=*q*<=≤<=5000).
The next *n* lines contain the grid description. There are *m* integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next *q* lines contain the information about the rounds. Each of them contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n* and 1<=≤<=*j*<=≤<=*m*), the row number and the column number of the bear changing his state. | After each round, print the current score of the bears. | [
"5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3\n"
] | [
"3\n4\n3\n3\n4\n"
] | none | 1,000 | [
{
"input": "5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3",
"output": "3\n4\n3\n3\n4"
},
{
"input": "2 2 10\n1 1\n0 1\n1 1\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 2\n1 1\n1 1",
"output": "1\n2\n2\n2\n1\n1\n1\n1\n2\n1"
},
{
"input": "2 2 10\n1 1\n0 1\n2 2\n2 2\n1 1\n2 1\n2 1\n1 1\n1 1\n2 1\n1 1\n2 1",
"output": "2\n2\n1\n2\n1\n2\n1\n2\n2\n2"
},
{
"input": "5 5 30\n0 1 1 1 0\n1 1 0 1 1\n0 1 1 1 1\n0 0 1 1 0\n0 0 0 0 0\n3 2\n2 2\n2 2\n4 3\n1 4\n3 2\n4 1\n2 4\n1 4\n2 1\n5 2\n4 1\n4 1\n5 1\n2 4\n2 4\n4 4\n1 2\n3 1\n4 5\n1 2\n2 3\n1 1\n5 1\n3 4\n1 1\n5 4\n1 5\n5 4\n2 2",
"output": "3\n3\n3\n3\n3\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n5\n5\n5\n5\n5\n5\n4\n3\n3\n4\n4\n4"
},
{
"input": "1 1 10\n0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "1\n0\n1\n0\n1\n0\n1\n0\n1\n0"
},
{
"input": "1 1 3\n1\n1 1\n1 1\n1 1",
"output": "0\n1\n0"
},
{
"input": "1 5 5\n0 0 0 0 0\n1 2\n1 1\n1 4\n1 5\n1 3",
"output": "1\n2\n2\n2\n5"
},
{
"input": "5 1 5\n0\n0\n0\n0\n0\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "1\n1\n1\n1\n1"
},
{
"input": "1 1 1\n0\n1 1",
"output": "1"
},
{
"input": "2 2 1\n1 1\n1 1\n1 1",
"output": "2"
}
] | 1,668,913,763 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 343 | 1,433,600 | n, m, q = map(int, input().split(" "))
grid = []
pontuacoes = []
for i in range(n):
linha = list(input().split(" "))
grid.append(linha)
pontuacoes.append(max(map(len, "".join(linha).split('0'))))
for i in range(q):
x, y = map(int, input().split(" "))
if grid[x - 1][y - 1] == '0':
grid[x - 1][y - 1] = '1'
else:
grid[x - 1][y - 1] = '0'
pontuacoes[x - 1] = max(list(map(len, "".join(grid[x - 1]).split('0'))))
print(max(pontuacoes))
| Title: Mike and Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of row number *i* by (*i*,<=*j*). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.
They play for *q* rounds. In each round, Mike chooses a bear (*i*,<=*j*) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
Input Specification:
The first line of input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=500 and 1<=≤<=*q*<=≤<=5000).
The next *n* lines contain the grid description. There are *m* integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next *q* lines contain the information about the rounds. Each of them contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n* and 1<=≤<=*j*<=≤<=*m*), the row number and the column number of the bear changing his state.
Output Specification:
After each round, print the current score of the bears.
Demo Input:
['5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3\n']
Demo Output:
['3\n4\n3\n3\n4\n']
Note:
none | ```python
n, m, q = map(int, input().split(" "))
grid = []
pontuacoes = []
for i in range(n):
linha = list(input().split(" "))
grid.append(linha)
pontuacoes.append(max(map(len, "".join(linha).split('0'))))
for i in range(q):
x, y = map(int, input().split(" "))
if grid[x - 1][y - 1] == '0':
grid[x - 1][y - 1] = '1'
else:
grid[x - 1][y - 1] = '0'
pontuacoes[x - 1] = max(list(map(len, "".join(grid[x - 1]).split('0'))))
print(max(pontuacoes))
``` | 3 |
|
285 | C | Building Permutation | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"sortings"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
You have a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. In one move, you are allowed to decrease or increase any number by one. Count the minimum number of moves, needed to build a permutation from this sequence. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"2\n3 0\n",
"3\n-1 -1 2\n"
] | [
"2\n",
"6\n"
] | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | 1,500 | [
{
"input": "2\n3 0",
"output": "2"
},
{
"input": "3\n-1 -1 2",
"output": "6"
},
{
"input": "5\n-3 5 -3 3 3",
"output": "10"
},
{
"input": "10\n9 6 -2 4 1 1 1 9 6 2",
"output": "18"
},
{
"input": "9\n2 0 0 6 5 4 1 9 3",
"output": "15"
},
{
"input": "100\n-77 57 -95 -23 53 -28 82 -83 38 -73 85 28 25 6 -43 4 -10 -30 -9 -92 14 34 -93 61 36 -100 90 -68 28 16 100 -3 97 30 36 -55 62 -62 53 74 -50 -23 67 11 22 -30 -19 83 7 84 43 90 -65 -75 -15 97 90 15 66 2 13 -91 91 -44 46 51 51 -58 95 77 20 30 76 79 91 60 76 2 82 42 -93 94 -57 88 65 -95 -66 100 -9 33 -67 54 -99 97 53 13 54 66 60 -48",
"output": "3459"
}
] | 1,627,216,247 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 451 | 46,080,000 | n = int(input())
l = list(map(int,input().split()))
l.sort()
c=0
for i in range(len(l)):
c+=abs(l[i]-(i+1))
print(c) | Title: Building Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
You have a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. In one move, you are allowed to decrease or increase any number by one. Count the minimum number of moves, needed to build a permutation from this sequence.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output Specification:
Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['2\n3 0\n', '3\n-1 -1 2\n']
Demo Output:
['2\n', '6\n']
Note:
In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | ```python
n = int(input())
l = list(map(int,input().split()))
l.sort()
c=0
for i in range(len(l)):
c+=abs(l[i]-(i+1))
print(c)
``` | 3 |
|
687 | B | Remainders Game | PROGRAMMING | 1,800 | [
"chinese remainder theorem",
"math",
"number theory"
] | null | null | Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has a winning strategy independent of value of *x* or not. Formally, is it true that Arya can understand the value for any positive integer *x*?
Note, that means the remainder of *x* after dividing it by *y*. | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000). | Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise. | [
"4 5\n2 3 5 12\n",
"2 7\n2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers.
In the second sample, Arya can't be sure what <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/57b5f6a96f5db073270dd3ed4266c69299ec701d.png" style="max-width: 100.0%;max-height: 100.0%;"/> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7. | 1,000 | [
{
"input": "4 5\n2 3 5 12",
"output": "Yes"
},
{
"input": "2 7\n2 3",
"output": "No"
},
{
"input": "1 6\n8",
"output": "No"
},
{
"input": "2 3\n9 4",
"output": "Yes"
},
{
"input": "4 16\n19 16 13 9",
"output": "Yes"
},
{
"input": "5 10\n5 16 19 9 17",
"output": "Yes"
},
{
"input": "11 95\n31 49 8 139 169 121 71 17 43 29 125",
"output": "No"
},
{
"input": "17 71\n173 43 139 73 169 199 49 81 11 89 131 107 23 29 125 152 17",
"output": "No"
},
{
"input": "13 86\n41 64 17 31 13 97 19 25 81 47 61 37 71",
"output": "No"
},
{
"input": "15 91\n49 121 83 67 128 125 27 113 41 169 149 19 37 29 71",
"output": "Yes"
},
{
"input": "2 4\n2 2",
"output": "No"
},
{
"input": "14 87\n1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619",
"output": "No"
},
{
"input": "12 100\n1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766",
"output": "No"
},
{
"input": "1 994619\n216000",
"output": "No"
},
{
"input": "1 651040\n911250",
"output": "No"
},
{
"input": "1 620622\n60060",
"output": "No"
},
{
"input": "1 1\n559872",
"output": "Yes"
},
{
"input": "88 935089\n967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967",
"output": "No"
},
{
"input": "93 181476\n426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426",
"output": "No"
},
{
"input": "91 4900\n630 630 70 630 910 630 630 630 770 70 770 630 630 770 70 630 70 630 70 630 70 630 630 70 910 630 630 630 770 630 630 630 70 910 70 630 70 630 770 630 630 70 630 770 70 630 70 70 630 630 70 70 70 70 630 70 70 770 910 630 70 630 770 70 910 70 630 910 630 70 770 70 70 630 770 630 70 630 70 70 630 70 630 770 630 70 630 630 70 910 630",
"output": "No"
},
{
"input": "61 531012\n698043 698043 698043 963349 698043 698043 698043 963349 698043 698043 698043 963349 698043 698043 698043 698043 966694 698043 698043 698043 698043 698043 698043 636247 698043 963349 698043 698043 698043 698043 697838 698043 963349 698043 698043 966694 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 963349 698043 698043 698043 698043 963349 698043",
"output": "No"
},
{
"input": "1 216000\n648000",
"output": "Yes"
},
{
"input": "2 8\n4 4",
"output": "No"
},
{
"input": "3 8\n4 4 4",
"output": "No"
},
{
"input": "2 8\n2 4",
"output": "No"
},
{
"input": "3 12\n2 2 3",
"output": "No"
},
{
"input": "10 4\n2 2 2 2 2 2 2 2 2 2",
"output": "No"
},
{
"input": "10 1024\n1 2 4 8 16 32 64 128 256 512",
"output": "No"
},
{
"input": "3 24\n2 2 3",
"output": "No"
},
{
"input": "1 8\n2",
"output": "No"
},
{
"input": "2 9\n3 3",
"output": "No"
},
{
"input": "3 4\n2 2 2",
"output": "No"
},
{
"input": "3 4\n1 2 2",
"output": "No"
},
{
"input": "1 4\n2",
"output": "No"
},
{
"input": "1 100003\n2",
"output": "No"
},
{
"input": "1 2\n12",
"output": "Yes"
},
{
"input": "2 988027\n989018 995006",
"output": "Yes"
},
{
"input": "3 9\n3 3 3",
"output": "No"
},
{
"input": "1 49\n7",
"output": "No"
},
{
"input": "2 600000\n200000 300000",
"output": "Yes"
},
{
"input": "3 8\n2 2 2",
"output": "No"
},
{
"input": "7 510510\n524288 531441 390625 823543 161051 371293 83521",
"output": "Yes"
},
{
"input": "2 30\n6 10",
"output": "Yes"
},
{
"input": "2 27000\n5400 4500",
"output": "Yes"
},
{
"input": "3 8\n1 2 4",
"output": "No"
},
{
"input": "4 16\n2 2 2 2",
"output": "No"
},
{
"input": "2 16\n4 8",
"output": "No"
},
{
"input": "2 8\n4 2",
"output": "No"
},
{
"input": "3 4\n2 2 3",
"output": "No"
},
{
"input": "1 8\n4",
"output": "No"
},
{
"input": "1 999983\n2",
"output": "No"
},
{
"input": "3 16\n2 4 8",
"output": "No"
},
{
"input": "2 216\n12 18",
"output": "No"
},
{
"input": "2 16\n8 8",
"output": "No"
},
{
"input": "2 36\n18 12",
"output": "Yes"
},
{
"input": "2 36\n12 18",
"output": "Yes"
},
{
"input": "2 1000000\n1000000 1000000",
"output": "Yes"
},
{
"input": "3 20\n2 2 5",
"output": "No"
},
{
"input": "1 2\n6",
"output": "Yes"
},
{
"input": "4 4\n2 3 6 5",
"output": "No"
},
{
"input": "1 2\n1",
"output": "No"
},
{
"input": "1 6\n6",
"output": "Yes"
},
{
"input": "2 16\n4 4",
"output": "No"
},
{
"input": "2 3779\n1 2",
"output": "No"
},
{
"input": "2 8\n4 12",
"output": "No"
},
{
"input": "2 24\n4 6",
"output": "No"
},
{
"input": "1 1\n5",
"output": "Yes"
},
{
"input": "10 255255\n1000000 700000 300000 110000 130000 170000 190000 230000 290000 310000",
"output": "Yes"
},
{
"input": "2 1000\n500 2",
"output": "No"
},
{
"input": "4 8\n2 2 2 2",
"output": "No"
},
{
"input": "1 666013\n1",
"output": "No"
},
{
"input": "1 999983\n1",
"output": "No"
},
{
"input": "1 125\n5",
"output": "No"
},
{
"input": "2 32\n4 8",
"output": "No"
},
{
"input": "3 32\n2 4 8",
"output": "No"
},
{
"input": "3 8\n2 4 11",
"output": "No"
},
{
"input": "1 32\n2",
"output": "No"
},
{
"input": "4 4\n2 2 2 2",
"output": "No"
},
{
"input": "8 32\n2 2 2 2 2 2 2 2",
"output": "No"
},
{
"input": "3 24\n2 4 3",
"output": "No"
},
{
"input": "2 4\n2 6",
"output": "No"
},
{
"input": "2 24\n6 4",
"output": "No"
},
{
"input": "1 20998\n2",
"output": "No"
},
{
"input": "1 1\n1",
"output": "Yes"
},
{
"input": "2 20998\n2 10499",
"output": "Yes"
},
{
"input": "1 5\n1",
"output": "No"
},
{
"input": "2 25\n5 5",
"output": "No"
},
{
"input": "5 2\n2 2 2 2 2",
"output": "Yes"
},
{
"input": "3 12\n2 3 6",
"output": "No"
},
{
"input": "1 1\n3",
"output": "Yes"
},
{
"input": "2 16\n8 4",
"output": "No"
},
{
"input": "40 10\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "No"
}
] | 1,601,740,208 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | import math as ma
a, b = [int(x) for x in input().split()]
c = list(map(int,input().split()))
if b in c:
print('YES')
else:
print('NO') | Title: Remainders Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has a winning strategy independent of value of *x* or not. Formally, is it true that Arya can understand the value for any positive integer *x*?
Note, that means the remainder of *x* after dividing it by *y*.
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000).
Output Specification:
Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise.
Demo Input:
['4 5\n2 3 5 12\n', '2 7\n2 3\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers.
In the second sample, Arya can't be sure what <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/57b5f6a96f5db073270dd3ed4266c69299ec701d.png" style="max-width: 100.0%;max-height: 100.0%;"/> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7. | ```python
import math as ma
a, b = [int(x) for x in input().split()]
c = list(map(int,input().split()))
if b in c:
print('YES')
else:
print('NO')
``` | 0 |
|
476 | A | Dreamoon and Stairs | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10). | Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. | [
"10 2\n",
"3 5\n"
] | [
"6\n",
"-1\n"
] | For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | 500 | [
{
"input": "10 2",
"output": "6"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "29 7",
"output": "21"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "10000 2",
"output": "5000"
},
{
"input": "10000 3",
"output": "5001"
},
{
"input": "10000 10",
"output": "5000"
},
{
"input": "9999 3",
"output": "5001"
},
{
"input": "9999 2",
"output": "5000"
},
{
"input": "9999 10",
"output": "5000"
},
{
"input": "9999 9",
"output": "5004"
},
{
"input": "18 10",
"output": "10"
},
{
"input": "19 10",
"output": "10"
},
{
"input": "20 10",
"output": "10"
},
{
"input": "21 10",
"output": "20"
},
{
"input": "7688 5",
"output": "3845"
},
{
"input": "4608 5",
"output": "2305"
},
{
"input": "3979 2",
"output": "1990"
},
{
"input": "9985 6",
"output": "4998"
},
{
"input": "3230 8",
"output": "1616"
},
{
"input": "24 9",
"output": "18"
},
{
"input": "3275 8",
"output": "1640"
},
{
"input": "6240 7",
"output": "3122"
},
{
"input": "5227 4",
"output": "2616"
},
{
"input": "3832 6",
"output": "1920"
},
{
"input": "4 2",
"output": "2"
},
{
"input": "6 3",
"output": "3"
},
{
"input": "10 5",
"output": "5"
},
{
"input": "3 2",
"output": "2"
},
{
"input": "6 4",
"output": "4"
},
{
"input": "5 2",
"output": "4"
},
{
"input": "8 2",
"output": "4"
},
{
"input": "9 9",
"output": "9"
},
{
"input": "4 5",
"output": "-1"
}
] | 1,667,482,709 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n,m=[int(x) for x in input().split()]
min_move = n//2 + n%2
if m>n:
print(-1)
if min_move%m == 0:
print(min_move)
else:
print(min_move + m-min_move%m) | Title: Dreamoon and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
Input Specification:
The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10).
Output Specification:
Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead.
Demo Input:
['10 2\n', '3 5\n']
Demo Output:
['6\n', '-1\n']
Note:
For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | ```python
n,m=[int(x) for x in input().split()]
min_move = n//2 + n%2
if m>n:
print(-1)
if min_move%m == 0:
print(min_move)
else:
print(min_move + m-min_move%m)
``` | 0 |
|
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,661,465,176 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 154 | 0 | s=input()
t=input()
pos=0
for i in t:
if i == s[pos] :
pos+=1
print(pos+1)
| 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
s=input()
t=input()
pos=0
for i in t:
if i == s[pos] :
pos+=1
print(pos+1)
``` | 3 |
|
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 1,699,854,946 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | k, n, w = map(int, input().split())
total = k*(w*(w+1)/2)
if total>n:
print(int(total-n))
else:
print(0) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
Input Specification:
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output Specification:
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Demo Input:
['3 17 4\n']
Demo Output:
['13']
Note:
none | ```python
k, n, w = map(int, input().split())
total = k*(w*(w+1)/2)
if total>n:
print(int(total-n))
else:
print(0)
``` | 3 |
|
588 | A | Duff and Meat | PROGRAMMING | 900 | [
"greedy"
] | null | null | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers *a*1,<=...,<=*a**n* and *p*1,<=...,<=*p**n*. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for *n* days. | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day. | Print the minimum money needed to keep Duff happy for *n* days, in one line. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 3\n2 1\n3 2\n"
] | [
"10\n",
"8\n"
] | In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | 750 | [
{
"input": "3\n1 3\n2 2\n3 1",
"output": "10"
},
{
"input": "3\n1 3\n2 1\n3 2",
"output": "8"
},
{
"input": "1\n39 52",
"output": "2028"
},
{
"input": "2\n25 56\n94 17",
"output": "2998"
},
{
"input": "5\n39 21\n95 89\n73 90\n9 55\n85 32",
"output": "6321"
},
{
"input": "12\n70 11\n74 27\n32 11\n26 83\n57 18\n97 28\n75 43\n75 21\n84 29\n16 2\n89 63\n21 88",
"output": "6742"
},
{
"input": "2\n100 68\n38 80",
"output": "9384"
}
] | 1,683,393,208 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | n = int(input())
a = []
p = []
for i in range(n):
a1, p1 = [int(i) for i in input().split()]
a.append(a1)
p.append(p1)
price = 0
if p.index(min(p)) == 0:
for i in a:
price += i * p[0]
else:
for i in range(0, p.index(min(p))):
price += a[i] * p[i]
for i in range(p.index(min(p)), n):
price += a[i] * p[p.index(min(p))]
print(price) | Title: Duff and Meat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers *a*1,<=...,<=*a**n* and *p*1,<=...,<=*p**n*. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for *n* days.
Input Specification:
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day.
Output Specification:
Print the minimum money needed to keep Duff happy for *n* days, in one line.
Demo Input:
['3\n1 3\n2 2\n3 1\n', '3\n1 3\n2 1\n3 2\n']
Demo Output:
['10\n', '8\n']
Note:
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | ```python
n = int(input())
a = []
p = []
for i in range(n):
a1, p1 = [int(i) for i in input().split()]
a.append(a1)
p.append(p1)
price = 0
if p.index(min(p)) == 0:
for i in a:
price += i * p[0]
else:
for i in range(0, p.index(min(p))):
price += a[i] * p[i]
for i in range(p.index(min(p)), n):
price += a[i] * p[p.index(min(p))]
print(price)
``` | 0 |
|
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit. | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output": "1"
},
{
"input": "86",
"output": "2"
},
{
"input": "2",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "34",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "28",
"output": "2"
},
{
"input": "23",
"output": "1"
},
{
"input": "57",
"output": "2"
},
{
"input": "29",
"output": "2"
},
{
"input": "353869285",
"output": "3"
},
{
"input": "549548646",
"output": "2"
},
{
"input": "858893424",
"output": "2"
},
{
"input": "644818852",
"output": "3"
},
{
"input": "360322525",
"output": "3"
},
{
"input": "122937520",
"output": "2"
},
{
"input": "288403032",
"output": "2"
},
{
"input": "677257481",
"output": "3"
},
{
"input": "58059561",
"output": "3"
},
{
"input": "211288847",
"output": "2"
},
{
"input": "339900034079539584",
"output": "2"
},
{
"input": "784084029310269952",
"output": "3"
},
{
"input": "774730557264864000",
"output": "3"
},
{
"input": "478233807148352256",
"output": "3"
},
{
"input": "165646874056812544",
"output": "3"
},
{
"input": "477533739511673792",
"output": "3"
},
{
"input": "660119944377002240",
"output": "3"
},
{
"input": "448375218506078080",
"output": "3"
},
{
"input": "77213334785795616",
"output": "3"
},
{
"input": "165767221702271872",
"output": "3"
},
{
"input": "1",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561",
"output": "3"
},
{
"input": "9",
"output": "0"
}
] | 1,634,656,839 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 614,400 | n = int(input())
i = 0
while True:
sim = 0
l = list(str(n))
if len(str(n)) == 1:
break;
else:
x = sum([int(char) for char in l])
n = x
i += 1
print(i) | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
Input Specification:
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Output Specification:
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
Demo Input:
['0\n', '10\n', '991\n']
Demo Output:
['0\n', '1\n', '3\n']
Note:
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit. | ```python
n = int(input())
i = 0
while True:
sim = 0
l = list(str(n))
if len(str(n)) == 1:
break;
else:
x = sum([int(char) for char in l])
n = x
i += 1
print(i)
``` | 0 |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
"input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ",
"output": "1077"
},
{
"input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA",
"output": "568"
},
{
"input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA",
"output": "70"
},
{
"input": "W",
"output": "0"
},
{
"input": "DBA",
"output": "0"
},
{
"input": "RQAWNACASAAKAGAAAAQ",
"output": "10"
},
{
"input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA",
"output": "111"
},
{
"input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA",
"output": "411"
},
{
"input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ",
"output": "625"
},
{
"input": "QORZOYAQ",
"output": "1"
},
{
"input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA",
"output": "13174"
},
{
"input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT",
"output": "10420"
},
{
"input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ",
"output": "12488"
},
{
"input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA",
"output": "9114"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "35937"
},
{
"input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE",
"output": "254"
},
{
"input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE",
"output": "2174"
},
{
"input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ",
"output": "2962"
},
{
"input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA",
"output": "2482"
},
{
"input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ",
"output": "7768"
},
{
"input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA",
"output": "5422"
},
{
"input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ",
"output": "3024"
},
{
"input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ",
"output": "4527"
},
{
"input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH",
"output": "6416"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ",
"output": "13136"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA",
"output": "14231"
},
{
"input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "15296"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA",
"output": "20825"
},
{
"input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ",
"output": "20825"
},
{
"input": "Q",
"output": "0"
},
{
"input": "A",
"output": "0"
},
{
"input": "FFF",
"output": "0"
},
{
"input": "AAAAAA",
"output": "0"
}
] | 1,635,868,304 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 46 | 17,715,200 | def problem3(_str):
g_count = 0
before_u = []
after_u = []
for char in _str: # O(n)
if char == 'G':
g_count += 1
if before_u:
for i in range(len(after_u)): # breaks the linear time
after_u[i] += 1
elif char == 'U':
if g_count:
before_u.append(g_count)
after_u.append(0)
ans = 0
for i in range(len(before_u)): # worst case again O(n)
ans += before_u[i] * after_u[i]
print(g_count)
print(before_u)
print(after_u)
return ans
s = input()
print(problem3(s)) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
Input Specification:
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Output Specification:
Print a single integer — the number of subsequences "QAQ" in the string.
Demo Input:
['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n']
Demo Output:
['4\n', '3\n']
Note:
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | ```python
def problem3(_str):
g_count = 0
before_u = []
after_u = []
for char in _str: # O(n)
if char == 'G':
g_count += 1
if before_u:
for i in range(len(after_u)): # breaks the linear time
after_u[i] += 1
elif char == 'U':
if g_count:
before_u.append(g_count)
after_u.append(0)
ans = 0
for i in range(len(before_u)): # worst case again O(n)
ans += before_u[i] * after_u[i]
print(g_count)
print(before_u)
print(after_u)
return ans
s = input()
print(problem3(s))
``` | 0 |
|
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,689,965,648 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | n = int(input())
nums = input().split(" ")
nums.sort()
total = 0
for num in nums:
total += int(num)
target = int(total/2)
curr = 0
count = 0
for i in reversed(range(0, len(nums))):
curr += int(nums[i])
count += 1
if curr > target:
break
print(count)
| Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.
As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
Output Specification:
In the single line print the single number — the minimum needed number of coins.
Demo Input:
['2\n3 3\n', '3\n2 1 2\n']
Demo Output:
['2\n', '2\n']
Note:
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2. | ```python
n = int(input())
nums = input().split(" ")
nums.sort()
total = 0
for num in nums:
total += int(num)
target = int(total/2)
curr = 0
count = 0
for i in reversed(range(0, len(nums))):
curr += int(nums[i])
count += 1
if curr > target:
break
print(count)
``` | 0 |
|
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps. | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "1"
},
{
"input": "99125 26876 -21414 14176 17443",
"output": "1"
},
{
"input": "8066 7339 19155 -90534 -60666",
"output": "8"
},
{
"input": "100000 -100000 -100000 100000 100000",
"output": "2"
},
{
"input": "10 20 0 41 0",
"output": "2"
},
{
"input": "25 -64 -6 -56 64",
"output": "2"
},
{
"input": "125 455 450 439 721",
"output": "2"
},
{
"input": "5 6 3 7 2",
"output": "1"
},
{
"input": "24 130 14786 3147 2140",
"output": "271"
},
{
"input": "125 -363 176 93 330",
"output": "2"
},
{
"input": "1 14 30 30 14",
"output": "12"
},
{
"input": "25 96 13 7 2",
"output": "2"
},
{
"input": "4 100000 -100000 100000 -100000",
"output": "0"
},
{
"input": "1 3 4 2 5",
"output": "1"
},
{
"input": "1 -3 3 2 6",
"output": "3"
},
{
"input": "2 7 20 13 -5",
"output": "7"
},
{
"input": "1 1 1 1 4",
"output": "2"
},
{
"input": "249 -54242 -30537 -45023 -89682",
"output": "121"
},
{
"input": "4 100000 -100000 100000 -99999",
"output": "1"
},
{
"input": "97741 23818 78751 97583 26933",
"output": "1"
},
{
"input": "56767 -29030 51625 79823 -56297",
"output": "2"
},
{
"input": "98260 13729 74998 23701 9253",
"output": "1"
},
{
"input": "67377 -80131 -90254 -57320 14102",
"output": "1"
},
{
"input": "1 100000 100000 100000 -100000",
"output": "100000"
},
{
"input": "19312 19470 82059 58064 62231",
"output": "2"
},
{
"input": "67398 -68747 -79056 -34193 29400",
"output": "1"
},
{
"input": "91099 37184 -71137 75650 -3655",
"output": "1"
},
{
"input": "46456 -2621 -23623 -98302 -99305",
"output": "2"
},
{
"input": "100 100000 -100000 100000 -99999",
"output": "1"
},
{
"input": "1 100000 -100000 100000 -100000",
"output": "0"
},
{
"input": "8 0 0 0 32",
"output": "2"
},
{
"input": "100000 100000 1 -100000 0",
"output": "2"
}
] | 1,578,217,297 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | import math
r , x , y , x1 , y1 = map(int , input().split())
d = math.sqrt((x - x1)**2 + (y-y1)**2)
print((math.ceil(d)+1)//2) | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps.
Input Specification:
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output Specification:
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
Demo Input:
['2 0 0 0 4\n', '1 1 1 4 4\n', '4 5 6 5 6\n']
Demo Output:
['1\n', '3\n', '0\n']
Note:
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
import math
r , x , y , x1 , y1 = map(int , input().split())
d = math.sqrt((x - x1)**2 + (y-y1)**2)
print((math.ceil(d)+1)//2)
``` | 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,630,374,354 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 6,963,200 | word = str(input())
upper = ""
lower = ""
for i in word:
if i.islower() == True:
lower += i
elif i.isupper() == True:
upper += i
if len(upper)>len(lower):
print(word.upper())
elif len(lower)>len(upper):
print(word.lower())
elif len(lower)==len(upper):
print(word.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
word = str(input())
upper = ""
lower = ""
for i in word:
if i.islower() == True:
lower += i
elif i.isupper() == True:
upper += i
if len(upper)>len(lower):
print(word.upper())
elif len(lower)>len(upper):
print(word.lower())
elif len(lower)==len(upper):
print(word.lower())
``` | 3.94853 |
291 | A | Spyke Talks | PROGRAMMING | 800 | [
"*special",
"implementation",
"sortings"
] | null | null | Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number.
One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment.
Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so.
Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted — that is, one call connects exactly two people. | The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=≤<=*id**i*<=≤<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is talking via Spyke, or zero otherwise.
Consider the secretaries indexed from 1 to *n* in some way. | Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. | [
"6\n0 1 7 1 7 10\n",
"3\n1 1 1\n",
"1\n0\n"
] | [
"2\n",
"-1\n",
"0\n"
] | In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.
In the second test sample the described situation is impossible as conferences aren't allowed. | 500 | [
{
"input": "6\n0 1 7 1 7 10",
"output": "2"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "5\n2 2 1 1 3",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n4 21 3 21 21 1 1 2 2 3",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "6\n6 6 0 8 0 0",
"output": "1"
},
{
"input": "10\n0 0 0 0 0 1 0 1 0 1",
"output": "-1"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 0 3 0 0 3 0 0 0 0 0 0 3 0 0 3 0 0 0 0 0 0 0 3 0 0 0 0 0",
"output": "-1"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 0",
"output": "0"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "5\n1 0 0 0 1",
"output": "1"
},
{
"input": "15\n380515742 842209759 945171461 664384656 945171461 474872104 0 0 131648973 131648973 474872104 842209759 664384656 0 380515742",
"output": "6"
},
{
"input": "123\n0 6361 8903 10428 0 258 0 10422 0 0 2642 1958 0 0 0 0 0 8249 1958 0 0 2642 0 0 0 11566 4709 1847 3998 0 1331 0 0 10289 2739 6135 3450 0 0 10994 6069 4337 5854 1331 5854 0 630 630 11244 5928 2706 0 683 214 0 9080 0 0 0 10422 683 11566 10994 0 0 3450 11244 11542 3998 1847 2708 9871 2739 2001 0 12216 6069 0 5928 0 10289 1307 0 1307 8903 0 6361 6135 6632 10428 0 0 632 258 9080 12216 4709 4967 2706 0 11542 2001 6632 0 8249 214 0 10301 4967 10301 7296 7296 10914 2708 4337 0 0 632 0 10914 0 9871 0",
"output": "40"
},
{
"input": "10\n0 3 2 3 2 0 1 3 3 0",
"output": "-1"
},
{
"input": "20\n0 1 2 0 0 0 0 5 3 4 0 0 1 1 3 0 4 0 1 0",
"output": "-1"
},
{
"input": "47\n1 6 0 6 1 1 6 4 3 6 5 3 6 3 2 2 5 1 4 7 3 5 6 1 6 7 4 5 6 3 3 3 7 4 1 6 1 1 7 1 3 1 5 5 1 3 6",
"output": "-1"
},
{
"input": "74\n0 0 0 0 0 37 0 0 0 0 0 0 0 8 0 0 9 0 0 0 0 0 0 0 0 0 8 0 0 0 0 0 9 0 7 0 0 0 0 0 0 19 19 0 0 0 0 0 0 0 0 0 0 0 0 17 0 30 0 0 0 0 0 0 30 0 0 0 0 0 0 0 37 0",
"output": "5"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "2\n2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n10000 10000 1 1 10000",
"output": "-1"
}
] | 1,375,906,392 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 156 | 0 | import sys
my_file = sys.stdin
#my_file = open("input.txt", "r")
my_file.readline()
nums = [int(i) for i in my_file.readline().split(" ")]
speaking = 0
for i in nums:
if i > 0:
if nums.count(i) == 2:
speaking += 1
elif nums.count(i) > 2:
speaking = -1
break
if speaking > 0:
print(int(speaking/2))
else:
print(speaking) | Title: Spyke Talks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number.
One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment.
Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so.
Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted — that is, one call connects exactly two people.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=≤<=*id**i*<=≤<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is talking via Spyke, or zero otherwise.
Consider the secretaries indexed from 1 to *n* in some way.
Output Specification:
Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place.
Demo Input:
['6\n0 1 7 1 7 10\n', '3\n1 1 1\n', '1\n0\n']
Demo Output:
['2\n', '-1\n', '0\n']
Note:
In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.
In the second test sample the described situation is impossible as conferences aren't allowed. | ```python
import sys
my_file = sys.stdin
#my_file = open("input.txt", "r")
my_file.readline()
nums = [int(i) for i in my_file.readline().split(" ")]
speaking = 0
for i in nums:
if i > 0:
if nums.count(i) == 2:
speaking += 1
elif nums.count(i) > 2:
speaking = -1
break
if speaking > 0:
print(int(speaking/2))
else:
print(speaking)
``` | 3 |
|
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,647,679,137 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 184 | 1,945,600 | n, k = map(int, input().split())
s = input()
if s.find("#" * k) == -1:
print("YES")
else:
print("NO")
| 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())
s = input()
if s.find("#" * k) == -1:
print("YES")
else:
print("NO")
``` | 3 |
|
591 | B | Rebranding | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.
For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation.
Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive.
Satisfy Arkady's curiosity and tell him the final version of the name. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*. | Print the new name of the corporation. | [
"6 1\npolice\np m\n",
"11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n"
] | [
"molice\n",
"cdcbcdcfcdc\n"
] | In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "6 1\npolice\np m",
"output": "molice"
},
{
"input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b",
"output": "cdcbcdcfcdc"
},
{
"input": "1 1\nf\nz h",
"output": "f"
},
{
"input": "1 1\na\na b",
"output": "b"
},
{
"input": "10 10\nlellelleel\ne l\ne l\ne l\ne l\ne l\ne e\nl l\nl e\nl l\ne e",
"output": "lellelleel"
}
] | 1,554,569,473 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 0 | n, m = [int(elt) for elt in input().split(" ")]
name = list(input())
for i in range(m):
x, y = input().split(" ")
for i in range(n):
if name[i] == x:
name[i] = y
elif name[i] == y:
name[i] = x
print("".join(name)) | Title: Rebranding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.
For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation.
Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive.
Satisfy Arkady's curiosity and tell him the final version of the name.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*.
Output Specification:
Print the new name of the corporation.
Demo Input:
['6 1\npolice\np m\n', '11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n']
Demo Output:
['molice\n', 'cdcbcdcfcdc\n']
Note:
In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
n, m = [int(elt) for elt in input().split(" ")]
name = list(input())
for i in range(m):
x, y = input().split(" ")
for i in range(n):
if name[i] == x:
name[i] = y
elif name[i] == y:
name[i] = x
print("".join(name))
``` | 0 |
|
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"input": "ABAXXXAB",
"output": "YES"
},
{
"input": "TESTABAXXABTEST",
"output": "YES"
},
{
"input": "A",
"output": "NO"
},
{
"input": "B",
"output": "NO"
},
{
"input": "X",
"output": "NO"
},
{
"input": "BA",
"output": "NO"
},
{
"input": "AB",
"output": "NO"
},
{
"input": "AA",
"output": "NO"
},
{
"input": "BB",
"output": "NO"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "AAB",
"output": "NO"
},
{
"input": "BAA",
"output": "NO"
},
{
"input": "ABB",
"output": "NO"
},
{
"input": "BBA",
"output": "NO"
},
{
"input": "AAA",
"output": "NO"
},
{
"input": "BBB",
"output": "NO"
},
{
"input": "AXBXBXA",
"output": "NO"
},
{
"input": "SKDSKDJABSDBADKFJDK",
"output": "YES"
},
{
"input": "ABAXXBBXXAA",
"output": "NO"
},
{
"input": "ABAB",
"output": "NO"
},
{
"input": "BABA",
"output": "NO"
},
{
"input": "AAAB",
"output": "NO"
},
{
"input": "AAAA",
"output": "NO"
},
{
"input": "AABA",
"output": "NO"
},
{
"input": "ABAA",
"output": "NO"
},
{
"input": "BAAA",
"output": "NO"
},
{
"input": "AABB",
"output": "NO"
},
{
"input": "BAAB",
"output": "YES"
},
{
"input": "BBAA",
"output": "NO"
},
{
"input": "BBBA",
"output": "NO"
},
{
"input": "BBAB",
"output": "NO"
},
{
"input": "BABB",
"output": "NO"
},
{
"input": "ABBB",
"output": "NO"
},
{
"input": "BBBB",
"output": "NO"
},
{
"input": "BABAB",
"output": "YES"
},
{
"input": "ABABA",
"output": "YES"
},
{
"input": "AAABAAACBBBC",
"output": "NO"
},
{
"input": "AABBBACBBBBBBAACBCCACBBAABBBBBCAACABAACABCACCBCBCCCBCBCABCBBCCBCBBAACBACAABACBBCACCBCCACCABBCBABBAAC",
"output": "YES"
},
{
"input": "CBBABDDBBADAC",
"output": "YES"
},
{
"input": "ABYFAB",
"output": "NO"
},
{
"input": "BABXXAB",
"output": "YES"
},
{
"input": "ABAXAB",
"output": "YES"
},
{
"input": "ABABXAB",
"output": "YES"
},
{
"input": "ABXABXABXABXABXBAXBAXBAXBA",
"output": "YES"
},
{
"input": "QQQQQQQQQABABQQQQQQQQ",
"output": "NO"
}
] | 1,691,068,999 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 78 | 5,632,000 | text = list(input())
length = len(text)
ba = []
ab = []
for index in range(1 , length) :
if text[index] + text[index - 1] == "BA" :
ba.append(index)
elif text[index] + text[index - 1] == "AB" :
ab.append(index)
if ba and ab :
for i in ba :
for j in ab :
if abs(i - j) > 1 :
quit(print("YES"))
print("NO") | Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters.
Output Specification:
Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
Demo Input:
['ABA\n', 'BACFAB\n', 'AXBYBXA\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | ```python
text = list(input())
length = len(text)
ba = []
ab = []
for index in range(1 , length) :
if text[index] + text[index - 1] == "BA" :
ba.append(index)
elif text[index] + text[index - 1] == "AB" :
ab.append(index)
if ba and ab :
for i in ba :
for j in ab :
if abs(i - j) > 1 :
quit(print("YES"))
print("NO")
``` | 3 |
|
714 | B | Filya and Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than once), subtract *x* from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer *x* and change some elements of the array using this *x* in order to make all elements equal. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. | If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | 1,000 | [
{
"input": "5\n1 3 3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "2\n1 1000000000",
"output": "YES"
},
{
"input": "4\n1 2 3 4",
"output": "NO"
},
{
"input": "10\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "2\n4 2",
"output": "YES"
},
{
"input": "4\n1 1 4 7",
"output": "YES"
},
{
"input": "3\n99999999 1 50000000",
"output": "YES"
},
{
"input": "1\n0",
"output": "YES"
},
{
"input": "5\n0 0 0 0 0",
"output": "YES"
},
{
"input": "4\n4 2 2 1",
"output": "NO"
},
{
"input": "3\n1 4 2",
"output": "NO"
},
{
"input": "3\n1 4 100",
"output": "NO"
},
{
"input": "3\n2 5 11",
"output": "NO"
},
{
"input": "3\n1 4 6",
"output": "NO"
},
{
"input": "3\n1 2 4",
"output": "NO"
},
{
"input": "3\n1 2 7",
"output": "NO"
},
{
"input": "5\n1 1 1 4 5",
"output": "NO"
},
{
"input": "2\n100000001 100000003",
"output": "YES"
},
{
"input": "3\n7 4 5",
"output": "NO"
},
{
"input": "3\n2 3 5",
"output": "NO"
},
{
"input": "3\n1 2 5",
"output": "NO"
},
{
"input": "2\n2 3",
"output": "YES"
},
{
"input": "3\n2 100 29",
"output": "NO"
},
{
"input": "3\n0 1 5",
"output": "NO"
},
{
"input": "3\n1 3 6",
"output": "NO"
},
{
"input": "3\n2 1 3",
"output": "YES"
},
{
"input": "3\n1 5 100",
"output": "NO"
},
{
"input": "3\n1 4 8",
"output": "NO"
},
{
"input": "3\n1 7 10",
"output": "NO"
},
{
"input": "3\n5 4 1",
"output": "NO"
},
{
"input": "3\n1 6 10",
"output": "NO"
},
{
"input": "4\n1 3 4 5",
"output": "NO"
},
{
"input": "3\n1 5 4",
"output": "NO"
},
{
"input": "5\n1 2 3 3 5",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "YES"
},
{
"input": "3\n2 3 8",
"output": "NO"
},
{
"input": "3\n0 3 5",
"output": "NO"
},
{
"input": "3\n1 5 10",
"output": "NO"
},
{
"input": "3\n1 7 2",
"output": "NO"
},
{
"input": "3\n1 3 9",
"output": "NO"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "7\n1 1 1 1 1 2 4",
"output": "NO"
},
{
"input": "5\n1 4 4 4 6",
"output": "NO"
},
{
"input": "5\n1 2 2 4 4",
"output": "NO"
},
{
"input": "3\n1 9 10",
"output": "NO"
},
{
"input": "8\n1 1 1 1 1 1 2 3",
"output": "YES"
},
{
"input": "3\n1 2 100",
"output": "NO"
},
{
"input": "3\n1 3 4",
"output": "NO"
},
{
"input": "3\n1 15 14",
"output": "NO"
},
{
"input": "3\n1 3 8",
"output": "NO"
},
{
"input": "3\n1 2 10",
"output": "NO"
},
{
"input": "4\n2 2 4 5",
"output": "NO"
},
{
"input": "3\n1 3 5",
"output": "YES"
},
{
"input": "5\n3 6 7 8 9",
"output": "NO"
},
{
"input": "3\n7 6 8",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 2 2 3",
"output": "YES"
},
{
"input": "3\n4 6 7",
"output": "NO"
},
{
"input": "3\n2 0 4",
"output": "YES"
},
{
"input": "4\n10 20 21 30",
"output": "NO"
},
{
"input": "4\n0 2 3 4",
"output": "NO"
},
{
"input": "3\n3 6 12",
"output": "NO"
},
{
"input": "5\n0 0 1 3 5",
"output": "NO"
},
{
"input": "3\n3 5 8",
"output": "NO"
},
{
"input": "3\n1 4 4",
"output": "YES"
},
{
"input": "4\n2 4 5 6",
"output": "NO"
}
] | 1,576,602,798 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 307,200 | n=int(input())
a=list(map(int,input().split()))
c=0
a.sort()
s=set(a)
if(len(s)<3 or (len(s)==3 and s[0]+s[2]==2*s[1])):
print("YES")
else:
print("NO") | Title: Filya and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than once), subtract *x* from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer *x* and change some elements of the array using this *x* in order to make all elements equal.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array.
Output Specification:
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
Demo Input:
['5\n1 3 3 2 1\n', '5\n1 2 3 4 5\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | ```python
n=int(input())
a=list(map(int,input().split()))
c=0
a.sort()
s=set(a)
if(len(s)<3 or (len(s)==3 and s[0]+s[2]==2*s[1])):
print("YES")
else:
print("NO")
``` | -1 |
|
465 | B | Inbox (100500) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations:
- Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.
The program cannot delete the letters from the list or rearrange them.
Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. | Print a single number — the minimum number of operations needed to make all the letters read. | [
"5\n0 1 0 1 0\n",
"5\n1 1 0 0 1\n",
"2\n0 0\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already read. | 1,000 | [
{
"input": "5\n0 1 0 1 0",
"output": "3"
},
{
"input": "5\n1 1 0 0 1",
"output": "4"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "9\n1 0 1 0 1 0 1 0 1",
"output": "9"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
},
{
"input": "14\n0 0 1 1 1 0 1 1 1 0 1 1 1 0",
"output": "11"
},
{
"input": "23\n1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1",
"output": "23"
},
{
"input": "27\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 0",
"output": "25"
},
{
"input": "10\n1 0 0 0 0 1 0 0 0 1",
"output": "5"
},
{
"input": "10\n1 0 0 1 0 0 1 1 0 1",
"output": "8"
},
{
"input": "27\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",
"output": "0"
},
{
"input": "39\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1",
"output": "39"
},
{
"input": "48\n1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1",
"output": "39"
},
{
"input": "71\n0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0",
"output": "59"
},
{
"input": "99\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1",
"output": "99"
},
{
"input": "99\n1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1",
"output": "99"
},
{
"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\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 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "99"
},
{
"input": "193\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "1"
},
{
"input": "213\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "5"
},
{
"input": "2\n1 0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "5\n0 0 0 0 1",
"output": "1"
},
{
"input": "12\n0 1 1 0 1 1 0 1 1 0 0 0",
"output": "8"
},
{
"input": "3\n1 0 0",
"output": "1"
},
{
"input": "5\n0 0 1 0 0",
"output": "1"
},
{
"input": "3\n0 1 0",
"output": "1"
},
{
"input": "6\n1 1 0 0 0 0",
"output": "2"
},
{
"input": "4\n0 1 0 0",
"output": "1"
},
{
"input": "5\n1 1 1 0 0",
"output": "3"
},
{
"input": "4\n1 0 0 0",
"output": "1"
},
{
"input": "6\n1 1 1 1 0 0",
"output": "4"
}
] | 1,541,943,872 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 124 | 0 | n = int(input())
states = [int(c) for c in input().split()]
while states and states[-1] == 0:
states.pop()
if not states:
print(0)
exit()
i = 0
while states[i] == 0:
i += 1
ans = 0
while i < len(states):
if states[i] == 1:
ans += 1
i += 1
elif states[i] == 0:
ans += 1
i += 1
while i < n and states[i] == 0:
i += 1
print(ans)
| Title: Inbox (100500)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations:
- Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.
The program cannot delete the letters from the list or rearrange them.
Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read.
Output Specification:
Print a single number — the minimum number of operations needed to make all the letters read.
Demo Input:
['5\n0 1 0 1 0\n', '5\n1 1 0 0 1\n', '2\n0 0\n']
Demo Output:
['3\n', '4\n', '0\n']
Note:
In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already read. | ```python
n = int(input())
states = [int(c) for c in input().split()]
while states and states[-1] == 0:
states.pop()
if not states:
print(0)
exit()
i = 0
while states[i] == 0:
i += 1
ans = 0
while i < len(states):
if states[i] == 1:
ans += 1
i += 1
elif states[i] == 0:
ans += 1
i += 1
while i < n and states[i] == 0:
i += 1
print(ans)
``` | 3 |
|
946 | B | Weird Subtraction Process | PROGRAMMING | 1,100 | [
"math",
"number theory"
] | null | null | You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process.
Initially the values of *a* and *b* are positive integers, and so the process will be finite.
You have to determine the values of *a* and *b* after the process ends. | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*. | Print two integers — the values of *a* and *b* after the end of the process. | [
"12 5\n",
"31 12\n"
] | [
"0 1\n",
"7 12\n"
] | Explanations to the samples:
1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12. | 0 | [
{
"input": "12 5",
"output": "0 1"
},
{
"input": "31 12",
"output": "7 12"
},
{
"input": "1000000000000000000 7",
"output": "8 7"
},
{
"input": "31960284556200 8515664064180",
"output": "14928956427840 8515664064180"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1000000000000000000 1000000000000000000"
},
{
"input": "1 1000",
"output": "1 0"
},
{
"input": "1 1000000",
"output": "1 0"
},
{
"input": "1 1000000000000000",
"output": "1 0"
},
{
"input": "1 99999999999999999",
"output": "1 1"
},
{
"input": "1 4",
"output": "1 0"
},
{
"input": "1000000000000001 500000000000000",
"output": "1 0"
},
{
"input": "1 1000000000000000000",
"output": "1 0"
},
{
"input": "2 4",
"output": "2 0"
},
{
"input": "2 1",
"output": "0 1"
},
{
"input": "6 19",
"output": "6 7"
},
{
"input": "22 5",
"output": "0 1"
},
{
"input": "10000000000000000 100000000000000001",
"output": "0 1"
},
{
"input": "1 1000000000000",
"output": "1 0"
},
{
"input": "2 1000000000000000",
"output": "2 0"
},
{
"input": "2 10",
"output": "2 2"
},
{
"input": "51 100",
"output": "51 100"
},
{
"input": "3 1000000000000000000",
"output": "3 4"
},
{
"input": "1000000000000000000 3",
"output": "4 3"
},
{
"input": "1 10000000000000000",
"output": "1 0"
},
{
"input": "8796203 7556",
"output": "1019 1442"
},
{
"input": "5 22",
"output": "1 0"
},
{
"input": "1000000000000000000 1",
"output": "0 1"
},
{
"input": "1 100000000000",
"output": "1 0"
},
{
"input": "2 1000000000000",
"output": "2 0"
},
{
"input": "5 4567865432345678",
"output": "5 8"
},
{
"input": "576460752303423487 288230376151711743",
"output": "1 1"
},
{
"input": "499999999999999999 1000000000000000000",
"output": "3 2"
},
{
"input": "1 9999999999999",
"output": "1 1"
},
{
"input": "103 1000000000000000000",
"output": "103 196"
},
{
"input": "7 1",
"output": "1 1"
},
{
"input": "100000000000000001 10000000000000000",
"output": "1 0"
},
{
"input": "5 10",
"output": "5 0"
},
{
"input": "7 11",
"output": "7 11"
},
{
"input": "1 123456789123456",
"output": "1 0"
},
{
"input": "5000000000000 100000000000001",
"output": "0 1"
},
{
"input": "1000000000000000 1",
"output": "0 1"
},
{
"input": "1000000000000000000 499999999999999999",
"output": "2 3"
},
{
"input": "10 5",
"output": "0 5"
},
{
"input": "9 18917827189272",
"output": "9 0"
},
{
"input": "179 100000000000497000",
"output": "179 270"
},
{
"input": "5 100000000000001",
"output": "1 1"
},
{
"input": "5 20",
"output": "5 0"
},
{
"input": "100000001 50000000",
"output": "1 0"
},
{
"input": "345869461223138161 835002744095575440",
"output": "1 0"
},
{
"input": "8589934592 4294967296",
"output": "0 4294967296"
},
{
"input": "4 8",
"output": "4 0"
},
{
"input": "1 100000000000000000",
"output": "1 0"
},
{
"input": "1000000000000000000 333333333333333",
"output": "1000 1333"
},
{
"input": "25 12",
"output": "1 0"
},
{
"input": "24 54",
"output": "0 6"
},
{
"input": "6 12",
"output": "6 0"
},
{
"input": "129200000000305 547300000001292",
"output": "1 0"
},
{
"input": "1000000000000000000 49999999999999999",
"output": "20 39"
},
{
"input": "1 2",
"output": "1 0"
},
{
"input": "1 123456789876",
"output": "1 0"
},
{
"input": "2 3",
"output": "2 3"
},
{
"input": "1 3",
"output": "1 1"
},
{
"input": "1 1",
"output": "1 1"
},
{
"input": "19 46",
"output": "3 2"
},
{
"input": "3 6",
"output": "3 0"
},
{
"input": "129 1000000000000000000",
"output": "1 0"
},
{
"input": "12 29",
"output": "0 1"
},
{
"input": "8589934592 2147483648",
"output": "0 2147483648"
},
{
"input": "2147483648 8589934592",
"output": "2147483648 0"
},
{
"input": "5 6",
"output": "5 6"
},
{
"input": "1000000000000000000 2",
"output": "0 2"
},
{
"input": "2 7",
"output": "2 3"
},
{
"input": "17174219820754872 61797504734333370",
"output": "17174219820754872 27449065092823626"
},
{
"input": "49 100",
"output": "1 0"
},
{
"input": "7 17",
"output": "1 1"
},
{
"input": "1000000000000000000 10000001",
"output": "0 1"
},
{
"input": "49999999999999999 2",
"output": "3 2"
},
{
"input": "49999999999999999 1",
"output": "1 1"
},
{
"input": "576460752303423487 2",
"output": "3 2"
},
{
"input": "19395 19395",
"output": "19395 19395"
},
{
"input": "19394 19394",
"output": "19394 19394"
}
] | 1,595,604,376 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 20,172,800 | import sys
m,n=[int(x) for x in input().split()]
if n==0 or m==0:
print(m,n)
sys.exit();
if n>=2*m and n%m==0 :
print(m,0)
sys.exit()
elif m>=2*n and m%n==0:
print(0,n)
sys.exit()
while (m>=2*n or n>=2*m) and (m>0 and n>0):
if m>=(2*n):
m=m%(2*n)
else:
n=n%(2*m)
print(m,n)
print(m,n) | Title: Weird Subtraction Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process.
Initially the values of *a* and *b* are positive integers, and so the process will be finite.
You have to determine the values of *a* and *b* after the process ends.
Input Specification:
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*.
Output Specification:
Print two integers — the values of *a* and *b* after the end of the process.
Demo Input:
['12 5\n', '31 12\n']
Demo Output:
['0 1\n', '7 12\n']
Note:
Explanations to the samples:
1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12. | ```python
import sys
m,n=[int(x) for x in input().split()]
if n==0 or m==0:
print(m,n)
sys.exit();
if n>=2*m and n%m==0 :
print(m,0)
sys.exit()
elif m>=2*n and m%n==0:
print(0,n)
sys.exit()
while (m>=2*n or n>=2*m) and (m>0 and n>0):
if m>=(2*n):
m=m%(2*n)
else:
n=n%(2*m)
print(m,n)
print(m,n)
``` | 0 |
|
29 | B | Traffic Lights | PROGRAMMING | 1,500 | [
"implementation"
] | B. Traffic Lights | 2 | 256 | A car moves from point A to point B at speed *v* meters per second. The action takes place on the X-axis. At the distance *d* meters from A there are traffic lights. Starting from time 0, for the first *g* seconds the green light is on, then for the following *r* seconds the red light is on, then again the green light is on for the *g* seconds, and so on.
The car can be instantly accelerated from 0 to *v* and vice versa, can instantly slow down from the *v* to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules? | The first line contains integers *l*, *d*, *v*, *g*, *r* (1<=≤<=*l*,<=*d*,<=*v*,<=*g*,<=*r*<=≤<=1000,<=*d*<=<<=*l*) — the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light. | Output a single number — the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10<=-<=6. | [
"2 1 3 4 5\n",
"5 4 3 1 1\n"
] | [
"0.66666667\n",
"2.33333333\n"
] | none | 1,000 | [
{
"input": "2 1 3 4 5",
"output": "0.66666667"
},
{
"input": "5 4 3 1 1",
"output": "2.33333333"
},
{
"input": "862 33 604 888 704",
"output": "1.42715232"
},
{
"input": "458 251 49 622 472",
"output": "9.34693878"
},
{
"input": "772 467 142 356 889",
"output": "5.43661972"
},
{
"input": "86 64 587 89 657",
"output": "0.14650767"
},
{
"input": "400 333 31 823 74",
"output": "12.90322581"
},
{
"input": "714 474 124 205 491",
"output": "5.75806452"
},
{
"input": "29 12 569 939 259",
"output": "0.05096661"
},
{
"input": "65 24 832 159 171",
"output": "0.07812500"
},
{
"input": "2 1 1 1 1",
"output": "3.00000000"
},
{
"input": "2 1 1 1 1000",
"output": "1002.00000000"
},
{
"input": "2 1 1 1000 1",
"output": "2.00000000"
},
{
"input": "2 1 1 1000 1000",
"output": "2.00000000"
},
{
"input": "2 1 1000 1 1",
"output": "0.00200000"
},
{
"input": "2 1 1000 1 1000",
"output": "0.00200000"
},
{
"input": "2 1 1000 1000 1",
"output": "0.00200000"
},
{
"input": "2 1 1000 1000 1000",
"output": "0.00200000"
},
{
"input": "1000 1 1 1 1",
"output": "1001.00000000"
},
{
"input": "1000 1 1 1 1000",
"output": "2000.00000000"
},
{
"input": "1000 1 1 1000 1",
"output": "1000.00000000"
},
{
"input": "1000 1 1 1000 1000",
"output": "1000.00000000"
},
{
"input": "1000 1 1000 1 1",
"output": "1.00000000"
},
{
"input": "1000 1 1000 1 1000",
"output": "1.00000000"
},
{
"input": "1000 1 1000 1000 1",
"output": "1.00000000"
},
{
"input": "1000 1 1000 1000 1000",
"output": "1.00000000"
},
{
"input": "1000 999 1 1 1",
"output": "1001.00000000"
},
{
"input": "1000 999 1 1 1000",
"output": "1002.00000000"
},
{
"input": "1000 999 1 1000 1",
"output": "1000.00000000"
},
{
"input": "1000 999 1 1000 1000",
"output": "1000.00000000"
},
{
"input": "1000 999 1000 1 1",
"output": "1.00000000"
},
{
"input": "1000 999 1000 1 1000",
"output": "1.00000000"
},
{
"input": "1000 999 1000 1000 1",
"output": "1.00000000"
},
{
"input": "1000 999 1000 1000 1000",
"output": "1.00000000"
}
] | 1,619,986,372 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 10 | 186 | 0 | l, d, v, g, r = map(int, input().split())
modulus = g+r
time_to_light = d/v
t = time_to_light
arrival = time_to_light % modulus
if arrival > g:
t += r+g-arrival
t += (l-d)/v
print(t)
| Title: Traffic Lights
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A car moves from point A to point B at speed *v* meters per second. The action takes place on the X-axis. At the distance *d* meters from A there are traffic lights. Starting from time 0, for the first *g* seconds the green light is on, then for the following *r* seconds the red light is on, then again the green light is on for the *g* seconds, and so on.
The car can be instantly accelerated from 0 to *v* and vice versa, can instantly slow down from the *v* to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.
What is the minimum time for the car to get from point A to point B without breaking the traffic rules?
Input Specification:
The first line contains integers *l*, *d*, *v*, *g*, *r* (1<=≤<=*l*,<=*d*,<=*v*,<=*g*,<=*r*<=≤<=1000,<=*d*<=<<=*l*) — the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light.
Output Specification:
Output a single number — the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10<=-<=6.
Demo Input:
['2 1 3 4 5\n', '5 4 3 1 1\n']
Demo Output:
['0.66666667\n', '2.33333333\n']
Note:
none | ```python
l, d, v, g, r = map(int, input().split())
modulus = g+r
time_to_light = d/v
t = time_to_light
arrival = time_to_light % modulus
if arrival > g:
t += r+g-arrival
t += (l-d)/v
print(t)
``` | 0 |
793 | A | Oleg and shares | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices. | Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. | [
"3 3\n12 9 15\n",
"2 2\n10 9\n",
"4 1\n1 1000000000 1000000000 1000000000\n"
] | [
"3",
"-1",
"2999999997"
] | Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3.
In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal.
In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time. | 500 | [
{
"input": "3 3\n12 9 15",
"output": "3"
},
{
"input": "2 2\n10 9",
"output": "-1"
},
{
"input": "4 1\n1 1000000000 1000000000 1000000000",
"output": "2999999997"
},
{
"input": "1 11\n123",
"output": "0"
},
{
"input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14",
"output": "151"
},
{
"input": "20 5\n59 54 19 88 55 100 54 3 6 13 99 38 36 71 59 6 64 85 45 54",
"output": "-1"
},
{
"input": "100 10\n340 70 440 330 130 120 340 210 440 110 410 120 180 40 50 230 70 110 310 360 480 70 230 120 230 310 470 60 210 60 210 480 290 250 450 440 150 40 500 230 280 250 30 50 310 50 230 360 420 260 330 80 50 160 70 470 140 180 380 190 250 30 220 410 80 310 280 50 20 430 440 180 310 190 190 330 90 190 320 390 170 460 230 30 80 500 470 370 80 500 400 120 220 150 70 120 70 320 260 260",
"output": "2157"
},
{
"input": "100 18\n489 42 300 366 473 105 220 448 70 488 201 396 168 281 67 235 324 291 313 387 407 223 39 144 224 233 72 318 229 377 62 171 448 119 354 282 147 447 260 384 172 199 67 326 311 431 337 142 281 202 404 468 38 120 90 437 33 420 249 372 367 253 255 411 309 333 103 176 162 120 203 41 352 478 216 498 224 31 261 493 277 99 375 370 394 229 71 488 246 194 233 13 66 111 366 456 277 360 116 354",
"output": "-1"
},
{
"input": "4 2\n1 2 3 4",
"output": "-1"
},
{
"input": "3 4\n3 5 5",
"output": "-1"
},
{
"input": "3 2\n88888884 88888886 88888888",
"output": "3"
},
{
"input": "2 1\n1000000000 1000000000",
"output": "0"
},
{
"input": "4 2\n1000000000 100000000 100000000 100000000",
"output": "450000000"
},
{
"input": "2 2\n1000000000 1000000000",
"output": "0"
},
{
"input": "3 3\n3 2 1",
"output": "-1"
},
{
"input": "3 4\n3 5 3",
"output": "-1"
},
{
"input": "3 2\n1 2 2",
"output": "-1"
},
{
"input": "4 2\n2 3 3 2",
"output": "-1"
},
{
"input": "3 2\n1 2 4",
"output": "-1"
},
{
"input": "3 2\n3 4 4",
"output": "-1"
},
{
"input": "3 3\n4 7 10",
"output": "3"
},
{
"input": "4 3\n2 2 5 1",
"output": "-1"
},
{
"input": "3 3\n1 3 5",
"output": "-1"
},
{
"input": "2 5\n5 9",
"output": "-1"
},
{
"input": "2 3\n5 7",
"output": "-1"
},
{
"input": "3 137\n1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "5 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "3 5\n1 2 5",
"output": "-1"
},
{
"input": "3 3\n1000000000 1000000000 999999997",
"output": "2"
},
{
"input": "2 4\n5 6",
"output": "-1"
},
{
"input": "4 1\n1000000000 1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "2 3\n5 8",
"output": "1"
},
{
"input": "2 6\n8 16",
"output": "-1"
},
{
"input": "5 3\n15 14 9 12 18",
"output": "-1"
},
{
"input": "3 3\n1 2 3",
"output": "-1"
},
{
"input": "3 3\n3 4 5",
"output": "-1"
},
{
"input": "2 5\n8 17",
"output": "-1"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "0"
},
{
"input": "3 3\n5 3 4",
"output": "-1"
},
{
"input": "3 6\n10 14 12",
"output": "-1"
},
{
"input": "2 2\n3 5",
"output": "1"
},
{
"input": "3 5\n1 3 4",
"output": "-1"
},
{
"input": "4 3\n1 6 6 6",
"output": "-1"
},
{
"input": "2 3\n1 8",
"output": "-1"
},
{
"input": "3 5\n6 11 17",
"output": "-1"
},
{
"input": "2 2\n1 4",
"output": "-1"
},
{
"input": "2 4\n6 8",
"output": "-1"
},
{
"input": "2 1\n2 3",
"output": "1"
},
{
"input": "4 4\n1 5 8 14",
"output": "-1"
},
{
"input": "3 3\n1 5 3",
"output": "-1"
},
{
"input": "4 3\n1 2 2 5",
"output": "-1"
},
{
"input": "3 2\n1 4 6",
"output": "-1"
},
{
"input": "2 3\n6 9",
"output": "1"
},
{
"input": "3 3\n2 3 4",
"output": "-1"
},
{
"input": "3 2\n9 10 10",
"output": "-1"
},
{
"input": "2 2\n9 12",
"output": "-1"
},
{
"input": "2 2\n100000003 100000005",
"output": "1"
},
{
"input": "2 3\n2 4",
"output": "-1"
},
{
"input": "3 2\n2 3 5",
"output": "-1"
},
{
"input": "3 3\n1 3 4",
"output": "-1"
},
{
"input": "10 2\n2 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "4499999991"
},
{
"input": "3 5\n2 4 5",
"output": "-1"
},
{
"input": "2 3\n7 10",
"output": "1"
},
{
"input": "3 10\n10 13 17",
"output": "-1"
},
{
"input": "2 3\n1 6",
"output": "-1"
},
{
"input": "1 7\n1000000000",
"output": "0"
},
{
"input": "2 4\n3 7",
"output": "1"
},
{
"input": "2 3\n2 5",
"output": "1"
},
{
"input": "20 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "3 3\n7 8 8",
"output": "-1"
},
{
"input": "4 10\n1 11 100 11",
"output": "-1"
}
] | 1,596,386,178 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 218 | 31,027,200 | n,m=map(int,input().split())
l=list(map(int,input().split()))
a=min(l)
c=0
flag=0
if a%m==0:
for i in l:
if i%m==0:
c=c+(i-a)//m
elif i%m:
flag=1
break
else:
flag=1
if flag==1:
print(-1)
else:
print(c)
| Title: Oleg and shares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices.
Output Specification:
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
Demo Input:
['3 3\n12 9 15\n', '2 2\n10 9\n', '4 1\n1 1000000000 1000000000 1000000000\n']
Demo Output:
['3', '-1', '2999999997']
Note:
Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3.
In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal.
In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time. | ```python
n,m=map(int,input().split())
l=list(map(int,input().split()))
a=min(l)
c=0
flag=0
if a%m==0:
for i in l:
if i%m==0:
c=c+(i-a)//m
elif i%m:
flag=1
break
else:
flag=1
if flag==1:
print(-1)
else:
print(c)
``` | 0 |
|
879 | B | Table Tennis | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | null | null | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner. | The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct. | Output a single integer — power of the winner. | [
"2 2\n1 2\n",
"4 2\n3 1 2 4\n",
"6 2\n6 5 3 1 2 4\n",
"2 10000000000\n2 1\n"
] | [
"2 ",
"3 ",
"6 ",
"2\n"
] | Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | 1,000 | [
{
"input": "2 2\n1 2",
"output": "2 "
},
{
"input": "4 2\n3 1 2 4",
"output": "3 "
},
{
"input": "6 2\n6 5 3 1 2 4",
"output": "6 "
},
{
"input": "2 10000000000\n2 1",
"output": "2"
},
{
"input": "4 4\n1 3 4 2",
"output": "4 "
},
{
"input": "2 2147483648\n2 1",
"output": "2"
},
{
"input": "3 2\n1 3 2",
"output": "3 "
},
{
"input": "3 3\n1 2 3",
"output": "3 "
},
{
"input": "5 2\n2 1 3 4 5",
"output": "5 "
},
{
"input": "10 2\n7 10 5 8 9 3 4 6 1 2",
"output": "10 "
},
{
"input": "100 2\n62 70 29 14 12 87 94 78 39 92 84 91 61 49 60 33 69 37 19 82 42 8 45 97 81 43 54 67 1 22 77 58 65 17 18 28 25 57 16 90 40 13 4 21 68 35 15 76 73 93 56 95 79 47 74 75 30 71 66 99 41 24 88 83 5 6 31 96 38 80 27 46 51 53 2 86 32 9 20 100 26 36 63 7 52 55 23 3 50 59 48 89 85 44 34 64 10 72 11 98",
"output": "70 "
},
{
"input": "4 10\n2 1 3 4",
"output": "4"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "10 "
},
{
"input": "10 2\n10 9 8 7 6 5 4 3 2 1",
"output": "10 "
},
{
"input": "4 1000000000000\n3 4 1 2",
"output": "4"
},
{
"input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "91 "
},
{
"input": "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34",
"output": "100 "
},
{
"input": "2 1000000000000\n1 2",
"output": "2"
},
{
"input": "5 2\n1 4 3 5 2",
"output": "4 "
},
{
"input": "5 2\n1 3 2 4 5",
"output": "3 "
},
{
"input": "4 1000000000000\n3 1 2 4",
"output": "4"
},
{
"input": "4 2\n1 3 2 4",
"output": "3 "
},
{
"input": "10 3\n8 1 9 2 3 10 4 5 6 7",
"output": "9 "
},
{
"input": "5 2\n2 1 4 3 5",
"output": "4 "
},
{
"input": "3 4294967297\n2 1 3",
"output": "3"
},
{
"input": "4 4294967297\n3 2 1 4",
"output": "4"
},
{
"input": "5 4294967298\n3 2 1 4 5",
"output": "5"
},
{
"input": "10 4\n5 4 7 1 2 9 3 6 8 10",
"output": "9 "
},
{
"input": "11 21474836489\n10 1 2 3 4 5 6 7 8 9 11",
"output": "11"
}
] | 1,683,489,463 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | #Q6
n, k = map(int, input().split())
if k >= n:
print(n)
else:
powers = list(map(int, input().split()))
cnt = 0
for i in range(n):
x = powers[i]
while powers[i]!=powers[n-1]:
if x > powers[i+1]:
cnt+=1
i+=1
else:
break
if cnt >= k:
print(x)
break
else:
cnt = 1
q = powers.pop(0)
powers.append(q)
| Title: Table Tennis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.
Input Specification:
The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct.
Output Specification:
Output a single integer — power of the winner.
Demo Input:
['2 2\n1 2\n', '4 2\n3 1 2 4\n', '6 2\n6 5 3 1 2 4\n', '2 10000000000\n2 1\n']
Demo Output:
['2 ', '3 ', '6 ', '2\n']
Note:
Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | ```python
#Q6
n, k = map(int, input().split())
if k >= n:
print(n)
else:
powers = list(map(int, input().split()))
cnt = 0
for i in range(n):
x = powers[i]
while powers[i]!=powers[n-1]:
if x > powers[i+1]:
cnt+=1
i+=1
else:
break
if cnt >= k:
print(x)
break
else:
cnt = 1
q = powers.pop(0)
powers.append(q)
``` | 0 |
|
911 | D | Inversion Counting | PROGRAMMING | 1,800 | [
"brute force",
"math"
] | null | null | A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=><=*j* and *a**i*<=<<=*a**j*. For example, a permutation [4,<=1,<=3,<=2] contains 4 inversions: (2,<=1), (3,<=1), (4,<=1), (4,<=3).
You are given a permutation *a* of size *n* and *m* queries to it. Each query is represented by two indices *l* and *r* denoting that you have to reverse the segment [*l*,<=*r*] of the permutation. For example, if *a*<==<=[1,<=2,<=3,<=4] and a query *l*<==<=2, *r*<==<=4 is applied, then the resulting permutation is [1,<=4,<=3,<=2].
After each query you have to determine whether the number of inversions is odd or even. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=1500) — the size of the permutation.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of the permutation. These integers are pairwise distinct.
The third line contains one integer *m* (1<=≤<=*m*<=≤<=2·105) — the number of queries to process.
Then *m* lines follow, *i*-th line containing two integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting that *i*-th query is to reverse a segment [*l**i*,<=*r**i*] of the permutation. All queries are performed one after another. | Print *m* lines. *i*-th of them must be equal to odd if the number of inversions in the permutation after *i*-th query is odd, and even otherwise. | [
"3\n1 2 3\n2\n1 2\n2 3\n",
"4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n"
] | [
"odd\neven\n",
"odd\nodd\nodd\neven\n"
] | The first example:
1. after the first query *a* = [2, 1, 3], inversion: (2, 1); 1. after the second query *a* = [2, 3, 1], inversions: (3, 1), (3, 2).
The second example:
1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); 1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [1, 4, 2, 3], inversions: (3, 2), (4, 2). | 0 | [
{
"input": "3\n1 2 3\n2\n1 2\n2 3",
"output": "odd\neven"
},
{
"input": "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3",
"output": "odd\nodd\nodd\neven"
},
{
"input": "7\n2 6 1 7 4 5 3\n5\n4 5\n7 7\n5 6\n4 5\n4 5",
"output": "odd\nodd\neven\nodd\neven"
},
{
"input": "3\n2 1 3\n3\n2 3\n1 1\n1 3",
"output": "even\neven\nodd"
},
{
"input": "1\n1\n10\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "even\neven\neven\neven\neven\neven\neven\neven\neven\neven"
}
] | 1,568,368,970 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 11,366,400 | if __name__ == "__main__":
n = int(input())
nums = [int(a) for a in input().strip().split()]
counts = 0
for i in range(n-1):
for j in range(i + 1, n):
if nums[i] > nums[j]:
counts += 1
m = int(input())
for i in range(m):
l, r = [int(a) for a in input().strip().split()]
tmp = r - l + 1
counts += (tmp * (tmp - 1) // 2)
if counts % 2 == 0:
print("even")
else:
print("odd")
| Title: Inversion Counting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=><=*j* and *a**i*<=<<=*a**j*. For example, a permutation [4,<=1,<=3,<=2] contains 4 inversions: (2,<=1), (3,<=1), (4,<=1), (4,<=3).
You are given a permutation *a* of size *n* and *m* queries to it. Each query is represented by two indices *l* and *r* denoting that you have to reverse the segment [*l*,<=*r*] of the permutation. For example, if *a*<==<=[1,<=2,<=3,<=4] and a query *l*<==<=2, *r*<==<=4 is applied, then the resulting permutation is [1,<=4,<=3,<=2].
After each query you have to determine whether the number of inversions is odd or even.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=1500) — the size of the permutation.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of the permutation. These integers are pairwise distinct.
The third line contains one integer *m* (1<=≤<=*m*<=≤<=2·105) — the number of queries to process.
Then *m* lines follow, *i*-th line containing two integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting that *i*-th query is to reverse a segment [*l**i*,<=*r**i*] of the permutation. All queries are performed one after another.
Output Specification:
Print *m* lines. *i*-th of them must be equal to odd if the number of inversions in the permutation after *i*-th query is odd, and even otherwise.
Demo Input:
['3\n1 2 3\n2\n1 2\n2 3\n', '4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n']
Demo Output:
['odd\neven\n', 'odd\nodd\nodd\neven\n']
Note:
The first example:
1. after the first query *a* = [2, 1, 3], inversion: (2, 1); 1. after the second query *a* = [2, 3, 1], inversions: (3, 1), (3, 2).
The second example:
1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); 1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [1, 4, 2, 3], inversions: (3, 2), (4, 2). | ```python
if __name__ == "__main__":
n = int(input())
nums = [int(a) for a in input().strip().split()]
counts = 0
for i in range(n-1):
for j in range(i + 1, n):
if nums[i] > nums[j]:
counts += 1
m = int(input())
for i in range(m):
l, r = [int(a) for a in input().strip().split()]
tmp = r - l + 1
counts += (tmp * (tmp - 1) // 2)
if counts % 2 == 0:
print("even")
else:
print("odd")
``` | 0 |
|
680 | B | Bear and Finding Criminals | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city.
Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city *a*. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.
You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD. | The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. | Print the number of criminals Limak will catch. | [
"6 3\n1 1 1 0 1 0\n",
"5 2\n0 0 0 1 0\n"
] | [
"3\n",
"1\n"
] | In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city. - There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city. - There are zero criminals for every greater distance.
So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total.
In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is. | 1,000 | [
{
"input": "6 3\n1 1 1 0 1 0",
"output": "3"
},
{
"input": "5 2\n0 0 0 1 0",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "9 3\n1 1 1 1 1 1 1 1 0",
"output": "8"
},
{
"input": "9 5\n1 0 1 0 1 0 1 0 1",
"output": "5"
},
{
"input": "20 17\n1 1 0 1 1 1 1 0 1 0 1 1 1 0 1 1 0 0 0 0",
"output": "10"
},
{
"input": "100 60\n1 1 1 1 1 1 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 0 1 0 0 0 1 1 1 0 1 0 0 1 1 1 0 1 1 1 0 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 1 0 0",
"output": "27"
},
{
"input": "8 1\n1 0 1 1 0 0 1 0",
"output": "4"
},
{
"input": "11 11\n0 1 0 0 1 1 1 0 0 0 0",
"output": "4"
},
{
"input": "19 10\n0 1 1 0 1 0 0 1 1 0 0 1 0 1 0 0 1 0 1",
"output": "4"
},
{
"input": "100 38\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100 38\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "1"
},
{
"input": "100 38\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "3"
},
{
"input": "99 38\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "25"
},
{
"input": "99 38\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "24"
},
{
"input": "99 38\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "24"
},
{
"input": "98 70\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 0 0 0 0 0 0 0 0 0 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": "41"
},
{
"input": "99 70\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 1 1 1 1 1 1 1 1 1 1 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": "9"
},
{
"input": "99 60\n0 0 0 1 1 0 1 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1",
"output": "34"
},
{
"input": "98 24\n0 0 0 1 1 0 1 1 0 0 0 0 1 0 0 1 0 0 1 1 1 0 0 1 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0 0 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1 1 0 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 1 0 1 0 0 1 1",
"output": "39"
},
{
"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": "100"
},
{
"input": "100 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "2 1\n0 1",
"output": "1"
}
] | 1,658,491,434 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 |
num_inp=lambda: int(input())
arr_inp=lambda: list(map(int,input().split()))
sp_inp=lambda: map(int,input().split())
str_inp=lambda:input()
n,m=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int,input().split()))
z=lambda:map(int,input().split());a,b=z();c=list(z());i=j=b-1;s=sum(c)
while(i>=0 and j<a):
if c[i]+c[j]==1:s-=1
i-=1;j+=1
print(s) | Title: Bear and Finding Criminals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city.
Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city *a*. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.
You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.
Input Specification:
The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city.
Output Specification:
Print the number of criminals Limak will catch.
Demo Input:
['6 3\n1 1 1 0 1 0\n', '5 2\n0 0 0 1 0\n']
Demo Output:
['3\n', '1\n']
Note:
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city. - There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city. - There are zero criminals for every greater distance.
So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total.
In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is. | ```python
num_inp=lambda: int(input())
arr_inp=lambda: list(map(int,input().split()))
sp_inp=lambda: map(int,input().split())
str_inp=lambda:input()
n,m=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int,input().split()))
z=lambda:map(int,input().split());a,b=z();c=list(z());i=j=b-1;s=sum(c)
while(i>=0 and j<a):
if c[i]+c[j]==1:s-=1
i-=1;j+=1
print(s)
``` | -1 |
|
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,670,512,897 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | n = int(input())
a = list(map(int,input().split()))
if a[0]%2 + a[1]%2 + a[2]%2 >= 2:
for i in range(n):
if not a[i]%2:
print(i+1)
else:
for i in range(n):
if a[i]%2:
print(i+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n = int(input())
a = list(map(int,input().split()))
if a[0]%2 + a[1]%2 + a[2]%2 >= 2:
for i in range(n):
if not a[i]%2:
print(i+1)
else:
for i in range(n):
if a[i]%2:
print(i+1)
``` | 3.977 |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894",
"output": "894"
},
{
"input": "6058 8581",
"output": "8581"
},
{
"input": "97259 41764",
"output": "125292"
},
{
"input": "453145 333625",
"output": "667250"
},
{
"input": "2233224 4394826",
"output": "4394826"
},
{
"input": "76770926 13350712",
"output": "80104272"
},
{
"input": "687355301 142098087",
"output": "710490435"
},
{
"input": "1000000000 999999999",
"output": "1999999998"
},
{
"input": "1000000000 1000000000",
"output": "2000000000"
},
{
"input": "999999999 1000000000",
"output": "1000000000"
},
{
"input": "1000000000 1",
"output": "1000000001"
},
{
"input": "1000000000 2",
"output": "1000000002"
},
{
"input": "999999999 1",
"output": "1000000000"
},
{
"input": "100000000 1",
"output": "100000001"
},
{
"input": "999999999 500000000",
"output": "1000000000"
},
{
"input": "999999990 10",
"output": "1000000000"
},
{
"input": "1000000000 999999997",
"output": "1999999994"
},
{
"input": "999999999 2",
"output": "1000000000"
},
{
"input": "999999984 1",
"output": "999999985"
},
{
"input": "999999983 1",
"output": "999999984"
},
{
"input": "666666666 1",
"output": "666666667"
},
{
"input": "1000000000 990000000",
"output": "1980000000"
},
{
"input": "41 48",
"output": "48"
},
{
"input": "123456 2",
"output": "123458"
},
{
"input": "111 111",
"output": "222"
},
{
"input": "878787 1",
"output": "878788"
},
{
"input": "121 1",
"output": "122"
},
{
"input": "114514 114514",
"output": "229028"
},
{
"input": "500000001 1000000000",
"output": "1000000000"
},
{
"input": "999999997 1",
"output": "999999998"
},
{
"input": "100000000 10",
"output": "100000010"
}
] | 1,554,373,604 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<iostream>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
cout<<n+k-n%k;
return 0;
} | Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
Output Specification:
Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*.
Demo Input:
['5 3\n', '25 13\n', '26 13\n']
Demo Output:
['6\n', '26\n', '39\n']
Note:
none | ```python
#include<iostream>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
cout<<n+k-n%k;
return 0;
}
``` | -1 |
|
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,667,284,281 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | a,b=map(int,input().split())
s=0
for i in range(1,a+1):
if b%i==0:
s=s+1
print(s)
| 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
a,b=map(int,input().split())
s=0
for i in range(1,a+1):
if b%i==0:
s=s+1
print(s)
``` | 0 |
|
856 | B | Similar Words | PROGRAMMING | 2,300 | [
"dp",
"hashing",
"strings",
"trees"
] | null | null | Let us call a non-empty sequence of lowercase English letters a word. Prefix of a word *x* is a word *y* that can be obtained from *x* by removing zero or more last letters of *x*.
Let us call two words similar, if one of them can be obtained from the other by removing its first letter.
You are given a set *S* of words. Find the maximal possible size of set of non-empty words *X* such that they satisfy the following:
- each word of *X* is prefix of some word from *S*; - *X* has no similar words. | Input data contains multiple test cases. The first line of the input data contains an integer *t* — the number of test cases. The descriptions of test cases follow.
The first line of each description contains an integer *n* — the number of words in the set *S* (1<=≤<=*n*<=≤<=106). Each of the following *n* lines contains one non-empty word — elements of *S*. All words in *S* are different.
It is guaranteed that the total length of all words in one input data doesn't exceed 106. | For each test case print one line that contains one integer *m* — the maximal number of words that *X* can contain. | [
"2\n3\naba\nbaba\naaab\n2\naa\na\n"
] | [
"6\n1\n"
] | none | 0 | [] | 1,505,456,603 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 2,000 | 0 | t = int(input())
for _ in range(t):
words = int(input())
ans = set()
for _ in range(words):
word = input()
while len(word)>0:
if word not in ans:
if word[1:] not in ans:
check=0
for x in ans:
if x[1:]==word:
check=1
if check==0:
ans.add(word)
else:
ans.remove(word[1:])
ans.add(word)
word = word[:-1]
print(len(ans)) | Title: Similar Words
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let us call a non-empty sequence of lowercase English letters a word. Prefix of a word *x* is a word *y* that can be obtained from *x* by removing zero or more last letters of *x*.
Let us call two words similar, if one of them can be obtained from the other by removing its first letter.
You are given a set *S* of words. Find the maximal possible size of set of non-empty words *X* such that they satisfy the following:
- each word of *X* is prefix of some word from *S*; - *X* has no similar words.
Input Specification:
Input data contains multiple test cases. The first line of the input data contains an integer *t* — the number of test cases. The descriptions of test cases follow.
The first line of each description contains an integer *n* — the number of words in the set *S* (1<=≤<=*n*<=≤<=106). Each of the following *n* lines contains one non-empty word — elements of *S*. All words in *S* are different.
It is guaranteed that the total length of all words in one input data doesn't exceed 106.
Output Specification:
For each test case print one line that contains one integer *m* — the maximal number of words that *X* can contain.
Demo Input:
['2\n3\naba\nbaba\naaab\n2\naa\na\n']
Demo Output:
['6\n1\n']
Note:
none | ```python
t = int(input())
for _ in range(t):
words = int(input())
ans = set()
for _ in range(words):
word = input()
while len(word)>0:
if word not in ans:
if word[1:] not in ans:
check=0
for x in ans:
if x[1:]==word:
check=1
if check==0:
ans.add(word)
else:
ans.remove(word[1:])
ans.add(word)
word = word[:-1]
print(len(ans))
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Bear Limak has *n* colored balls, arranged in one long row. Balls are numbered 1 through *n*, from left to right. There are *n* possible colors, also numbered 1 through *n*. The *i*-th ball has color *t**i*.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — the number of balls.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=*n*) where *t**i* is the color of the *i*-th ball. | Print *n* integers. The *i*-th of them should be equal to the number of intervals where *i* is a dominant color. | [
"4\n1 2 1 2\n",
"3\n1 1 1\n"
] | [
"7 3 0 0 \n",
"6 0 0 \n"
] | In the first sample, color 2 is dominant in three intervals:
- An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color. - An interval [4, 4] contains one ball, with color 2 again. - An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them. | 0 | [
{
"input": "4\n1 2 1 2",
"output": "7 3 0 0 "
},
{
"input": "3\n1 1 1",
"output": "6 0 0 "
},
{
"input": "10\n9 1 5 2 9 2 9 2 1 1",
"output": "18 30 0 0 1 0 0 0 6 0 "
},
{
"input": "50\n17 13 19 19 19 34 32 24 24 13 34 17 19 19 7 32 19 13 13 30 19 34 34 28 41 24 24 47 22 34 21 21 30 7 22 21 32 19 34 19 34 22 7 28 6 13 19 30 13 30",
"output": "0 0 0 0 0 22 40 0 0 0 0 0 98 0 0 0 5 0 675 0 165 9 0 61 0 0 0 5 0 6 0 4 0 183 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 "
},
{
"input": "150\n28 124 138 71 71 18 78 136 138 93 145 93 18 15 71 47 47 64 18 72 138 72 18 150 7 71 109 149 18 115 149 149 15 78 124 27 72 124 28 108 138 109 108 111 148 138 78 27 28 150 138 65 15 145 109 47 102 62 28 7 115 108 102 149 150 27 111 64 149 124 13 21 108 64 7 15 72 72 124 47 102 28 109 18 124 28 111 138 7 13 21 62 136 62 13 64 71 7 130 47 77 65 71 148 15 93 64 65 28 65 13 78 78 47 115 138 28 115 72 136 124 145 150 62 105 78 71 102 109 150 27 130 62 7 93 72 93 62 7 124 72 21 62 18 62 7 108 78 148 149",
"output": "0 0 0 0 0 0 1863 0 0 0 0 0 604 0 97 0 0 1026 0 0 12 0 0 0 0 0 208 2982 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 67 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1400 0 158 371 0 0 0 0 0 92 296 0 0 0 0 1 199 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 0 0 0 0 151 0 0 1 0 0 230 37 0 6 0 0 0 44 0 0 0 0 0 0 0 0 174 0 0 0 0 0 2 0 0 0 0 0 4 0 729 0 0 0 0 0 0 4 0 0 4 486 29 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n2 1",
"output": "2 1 "
}
] | 1,494,080,649 | 4,749 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 307,200 | n = int(input())
C = [int(i)-1 for i in input().split()]
A = [0 for _ in range(n)]
for i in range(n):
ct = [0 for _ in range(n)]
mc = 0
mi = n
for j in range(i, n):
ct[C[j]] += 1
if ct[C[j]] > mc:
mc = ct[C[j]]
mi = C[j]
elif ct[C[j]] == mc:
mi = min(C[j], mi)
A[mi] += 1
print(' '.join(str(i) for i in A))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak has *n* colored balls, arranged in one long row. Balls are numbered 1 through *n*, from left to right. There are *n* possible colors, also numbered 1 through *n*. The *i*-th ball has color *t**i*.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — the number of balls.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=*n*) where *t**i* is the color of the *i*-th ball.
Output Specification:
Print *n* integers. The *i*-th of them should be equal to the number of intervals where *i* is a dominant color.
Demo Input:
['4\n1 2 1 2\n', '3\n1 1 1\n']
Demo Output:
['7 3 0 0 \n', '6 0 0 \n']
Note:
In the first sample, color 2 is dominant in three intervals:
- An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color. - An interval [4, 4] contains one ball, with color 2 again. - An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them. | ```python
n = int(input())
C = [int(i)-1 for i in input().split()]
A = [0 for _ in range(n)]
for i in range(n):
ct = [0 for _ in range(n)]
mc = 0
mi = n
for j in range(i, n):
ct[C[j]] += 1
if ct[C[j]] > mc:
mc = ct[C[j]]
mi = C[j]
elif ct[C[j]] == mc:
mi = min(C[j], mi)
A[mi] += 1
print(' '.join(str(i) for i in A))
``` | 0 |
|
409 | H | A + B Strikes Back | PROGRAMMING | 1,500 | [
"*special",
"brute force",
"constructive algorithms",
"dsu",
"implementation"
] | null | null | A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? | The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space. | Output the sum of the given integers. | [
"5 14\n",
"381 492\n"
] | [
"19\n",
"873\n"
] | none | 0 | [
{
"input": "5 14",
"output": "19"
},
{
"input": "381 492",
"output": "873"
},
{
"input": "536 298",
"output": "834"
},
{
"input": "143 522",
"output": "665"
},
{
"input": "433 126",
"output": "559"
},
{
"input": "723 350",
"output": "1073"
},
{
"input": "632 264",
"output": "896"
},
{
"input": "923 488",
"output": "1411"
},
{
"input": "522 92",
"output": "614"
},
{
"input": "953 553",
"output": "1506"
},
{
"input": "242 86",
"output": "328"
},
{
"input": "151 691",
"output": "842"
},
{
"input": "441 915",
"output": "1356"
},
{
"input": "740 519",
"output": "1259"
},
{
"input": "339 433",
"output": "772"
},
{
"input": "629 657",
"output": "1286"
},
{
"input": "538 261",
"output": "799"
},
{
"input": "828 485",
"output": "1313"
},
{
"input": "117 399",
"output": "516"
},
{
"input": "399 280",
"output": "679"
}
] | 1,589,907,205 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 0 | 0 | c,d=map(int,input().split())
print(c+d) | Title: A + B Strikes Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try?
Input Specification:
The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space.
Output Specification:
Output the sum of the given integers.
Demo Input:
['5 14\n', '381 492\n']
Demo Output:
['19\n', '873\n']
Note:
none | ```python
c,d=map(int,input().split())
print(c+d)
``` | 0 |
|
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand. | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "100 100 100",
"output": "300"
},
{
"input": "1 1 1",
"output": "2"
},
{
"input": "30 70 35",
"output": "130"
},
{
"input": "89 44 76",
"output": "208"
},
{
"input": "0 100 100",
"output": "200"
},
{
"input": "100 0 100",
"output": "200"
},
{
"input": "100 1 100",
"output": "200"
},
{
"input": "1 100 100",
"output": "200"
},
{
"input": "100 100 0",
"output": "200"
},
{
"input": "100 100 1",
"output": "200"
},
{
"input": "1 2 1",
"output": "4"
},
{
"input": "0 0 100",
"output": "100"
},
{
"input": "0 100 0",
"output": "0"
},
{
"input": "100 0 0",
"output": "0"
},
{
"input": "10 8 7",
"output": "24"
},
{
"input": "45 47 16",
"output": "108"
},
{
"input": "59 43 100",
"output": "202"
},
{
"input": "34 1 30",
"output": "62"
},
{
"input": "14 81 1",
"output": "30"
},
{
"input": "53 96 94",
"output": "242"
},
{
"input": "62 81 75",
"output": "218"
},
{
"input": "21 71 97",
"output": "188"
},
{
"input": "49 82 73",
"output": "204"
},
{
"input": "88 19 29",
"output": "96"
},
{
"input": "89 4 62",
"output": "132"
},
{
"input": "58 3 65",
"output": "126"
},
{
"input": "27 86 11",
"output": "76"
},
{
"input": "35 19 80",
"output": "134"
},
{
"input": "4 86 74",
"output": "156"
},
{
"input": "32 61 89",
"output": "182"
},
{
"input": "68 60 98",
"output": "226"
},
{
"input": "37 89 34",
"output": "142"
},
{
"input": "92 9 28",
"output": "74"
},
{
"input": "79 58 98",
"output": "234"
},
{
"input": "35 44 88",
"output": "166"
},
{
"input": "16 24 19",
"output": "58"
},
{
"input": "74 71 75",
"output": "220"
},
{
"input": "83 86 99",
"output": "268"
},
{
"input": "97 73 15",
"output": "176"
},
{
"input": "77 76 73",
"output": "226"
},
{
"input": "48 85 55",
"output": "188"
},
{
"input": "1 2 2",
"output": "4"
},
{
"input": "2 2 2",
"output": "6"
},
{
"input": "2 1 2",
"output": "4"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "3 2 1",
"output": "6"
},
{
"input": "1 2 3",
"output": "6"
},
{
"input": "1 3 2",
"output": "6"
},
{
"input": "2 1 3",
"output": "6"
},
{
"input": "2 3 1",
"output": "6"
},
{
"input": "3 1 2",
"output": "6"
},
{
"input": "99 99 99",
"output": "296"
},
{
"input": "99 99 100",
"output": "298"
},
{
"input": "99 100 99",
"output": "298"
},
{
"input": "99 100 100",
"output": "298"
},
{
"input": "100 99 99",
"output": "298"
},
{
"input": "100 99 100",
"output": "298"
},
{
"input": "100 100 99",
"output": "298"
},
{
"input": "89 32 23",
"output": "110"
},
{
"input": "4 5 0",
"output": "8"
},
{
"input": "3 0 3",
"output": "6"
},
{
"input": "0 0 2",
"output": "2"
},
{
"input": "97 97 0",
"output": "194"
},
{
"input": "1 4 0",
"output": "2"
},
{
"input": "5 2 0",
"output": "4"
},
{
"input": "0 5 10",
"output": "14"
},
{
"input": "0 1 2",
"output": "2"
},
{
"input": "5 2 3",
"output": "10"
},
{
"input": "5 5 0",
"output": "10"
},
{
"input": "0 0 10",
"output": "10"
},
{
"input": "0 1 1",
"output": "2"
},
{
"input": "0 0 1",
"output": "0"
}
] | 1,694,352,596 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 79 | 62 | 0 | l,r,a = map(int, input().split())
if (max(l,r)-min(l,r)) >= a:
print(2*(min(l,r)+a))
else:
print(2*(int((a-(max(l,r)-min(l,r)))/2) + max(l,r))) | Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
Input Specification:
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Output Specification:
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
Demo Input:
['1 4 2\n', '5 5 5\n', '0 2 0\n']
Demo Output:
['6\n', '14\n', '0\n']
Note:
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand. | ```python
l,r,a = map(int, input().split())
if (max(l,r)-min(l,r)) >= a:
print(2*(min(l,r)+a))
else:
print(2*(int((a-(max(l,r)-min(l,r)))/2) + max(l,r)))
``` | 3 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,557,669,945 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 218 | 0 | s = [i for i in input()]
t = input()
s.reverse()
if ''.join(s) == t:
print('YES')
else:
print('NO')
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
s = [i for i in input()]
t = input()
s.reverse()
if ''.join(s) == t:
print('YES')
else:
print('NO')
``` | 3.9455 |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b",
"output": "f jpggvr b hnxsd b"
},
{
"input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb",
"output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs"
},
{
"input": "1 1\namit am\namit",
"output": "am"
},
{
"input": "1 1\na c\na",
"output": "a"
}
] | 1,689,767,239 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 921,600 | dic={}
n1,n2=map(int,input().split())
for i in range(n2):
s1,s2=input().split()
dic[str(s1)]=s2
l1=input().split(" ")
for l in l1:
if len(dic[l])<len(l):
print(dic[l],end=" ")
else:
print(l,end=" ") | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input Specification:
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output Specification:
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Demo Input:
['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n']
Demo Output:
['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n']
Note:
none | ```python
dic={}
n1,n2=map(int,input().split())
for i in range(n2):
s1,s2=input().split()
dic[str(s1)]=s2
l1=input().split(" ")
for l in l1:
if len(dic[l])<len(l):
print(dic[l],end=" ")
else:
print(l,end=" ")
``` | 3 |
|
177 | A1 | Good Matrix Elements | PROGRAMMING | 800 | [
"implementation"
] | null | null | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it.
Help the Smart Beaver count the sum of good elements of the given matrix. | The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 points are:
- 1<=≤<=*n*<=≤<=101 | Print a single integer — the sum of good matrix elements. | [
"3\n1 2 3\n4 5 6\n7 8 9\n",
"5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n"
] | [
"45\n",
"17\n"
] | In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | 30 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "45"
},
{
"input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "17"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33",
"output": "756"
},
{
"input": "3\n19 7 16\n12 15 5\n15 15 5",
"output": "109"
},
{
"input": "3\n36 4 33\n11 46 32\n20 49 34",
"output": "265"
},
{
"input": "3\n79 91 74\n33 82 22\n18 28 54",
"output": "481"
},
{
"input": "5\n7 0 8 1 7\n5 1 1 0 4\n4 2 8 1 6\n1 2 3 2 7\n6 0 1 9 6",
"output": "65"
},
{
"input": "5\n27 20 28 11 17\n25 21 1 20 14\n14 22 28 1 6\n1 2 23 2 7\n6 0 1 29 6",
"output": "225"
},
{
"input": "5\n57 50 58 41 17\n25 21 1 50 44\n44 22 28 31 36\n31 32 23 32 37\n6 0 31 59 6",
"output": "495"
},
{
"input": "5\n57 80 28 41 47\n85 51 61 50 74\n44 82 28 31 36\n31 32 23 32 37\n66 60 31 59 6",
"output": "705"
},
{
"input": "5\n13 58 10 17 43\n61 73 100 0 9\n52 38 16 22 96\n11 4 14 67 62\n70 89 7 98 83",
"output": "708"
},
{
"input": "5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n0 1 0 1 0\n0 0 0 0 1\n0 0 5 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "5"
},
{
"input": "5\n0 0 0 0 1\n0 1 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "3\n0 0 0\n0 0 0\n0 0 0",
"output": "0"
}
] | 1,647,081,424 | 2,147,483,647 | Python 3 | OK | TESTS1 | 17 | 62 | 0 | l = []
n = int(input())
for i in range(n):
a = map(int, input().split())
l.append(list(a))
add = 0
for i in range(n):
for j in range(n):
if (i == j):
add += l[i][j]
if (i+j == n-1):
add += l[i][j]
if (i == n//2) or (j == n//2):
add += l[i][j]
add = add-(2*(l[n//2][n//2]))
print(add)
| Title: Good Matrix Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input Specification:
The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 points are:
- 1<=≤<=*n*<=≤<=101
Output Specification:
Print a single integer — the sum of good matrix elements.
Demo Input:
['3\n1 2 3\n4 5 6\n7 8 9\n', '5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n']
Demo Output:
['45\n', '17\n']
Note:
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | ```python
l = []
n = int(input())
for i in range(n):
a = map(int, input().split())
l.append(list(a))
add = 0
for i in range(n):
for j in range(n):
if (i == j):
add += l[i][j]
if (i+j == n-1):
add += l[i][j]
if (i == n//2) or (j == n//2):
add += l[i][j]
add = add-(2*(l[n//2][n//2]))
print(add)
``` | 3 |
|
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},
{
"input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn",
"output": "IGNORE HIM!"
},
{
"input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx",
"output": "CHAT WITH HER!"
},
{
"input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt",
"output": "IGNORE HIM!"
},
{
"input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk",
"output": "IGNORE HIM!"
},
{
"input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz",
"output": "IGNORE HIM!"
},
{
"input": "tgcdptnkc",
"output": "IGNORE HIM!"
},
{
"input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi",
"output": "IGNORE HIM!"
},
{
"input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp",
"output": "IGNORE HIM!"
},
{
"input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia",
"output": "IGNORE HIM!"
},
{
"input": "fpellxwskyekoyvrfnuf",
"output": "CHAT WITH HER!"
},
{
"input": "xninyvkuvakfbs",
"output": "IGNORE HIM!"
},
{
"input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak",
"output": "CHAT WITH HER!"
},
{
"input": "kmsk",
"output": "IGNORE HIM!"
},
{
"input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz",
"output": "CHAT WITH HER!"
},
{
"input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq",
"output": "CHAT WITH HER!"
},
{
"input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm",
"output": "IGNORE HIM!"
},
{
"input": "ppcpbnhwoizajrl",
"output": "IGNORE HIM!"
},
{
"input": "sgubujztzwkzvztitssxxxwzanfmddfqvv",
"output": "CHAT WITH HER!"
},
{
"input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw",
"output": "IGNORE HIM!"
},
{
"input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu",
"output": "CHAT WITH HER!"
},
{
"input": "ojjvpnkrxibyevxk",
"output": "CHAT WITH HER!"
},
{
"input": "wjweqcrqfuollfvfbiyriijovweg",
"output": "IGNORE HIM!"
},
{
"input": "hkdbykboclchfdsuovvpknwqr",
"output": "IGNORE HIM!"
},
{
"input": "stjvyfrfowopwfjdveduedqylerqugykyu",
"output": "IGNORE HIM!"
},
{
"input": "rafcaanqytfclvfdegak",
"output": "CHAT WITH HER!"
},
{
"input": "xczn",
"output": "CHAT WITH HER!"
},
{
"input": "arcoaeozyeawbveoxpmafxxzdjldsielp",
"output": "IGNORE HIM!"
},
{
"input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika",
"output": "CHAT WITH HER!"
},
{
"input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh",
"output": "CHAT WITH HER!"
},
{
"input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg",
"output": "CHAT WITH HER!"
},
{
"input": "udlpagtpq",
"output": "CHAT WITH HER!"
},
{
"input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy",
"output": "CHAT WITH HER!"
},
{
"input": "qagzrqjomdwhagkhrjahhxkieijyten",
"output": "CHAT WITH HER!"
},
{
"input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb",
"output": "CHAT WITH HER!"
},
{
"input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr",
"output": "CHAT WITH HER!"
},
{
"input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc",
"output": "IGNORE HIM!"
},
{
"input": "lnpdosnceumubvk",
"output": "IGNORE HIM!"
},
{
"input": "efrk",
"output": "CHAT WITH HER!"
},
{
"input": "temnownneghnrujforif",
"output": "IGNORE HIM!"
},
{
"input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta",
"output": "IGNORE HIM!"
},
{
"input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh",
"output": "IGNORE HIM!"
},
{
"input": "gwntwbpj",
"output": "IGNORE HIM!"
},
{
"input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim",
"output": "IGNORE HIM!"
},
{
"input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd",
"output": "CHAT WITH HER!"
},
{
"input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx",
"output": "IGNORE HIM!"
},
{
"input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks",
"output": "CHAT WITH HER!"
},
{
"input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx",
"output": "CHAT WITH HER!"
},
{
"input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc",
"output": "CHAT WITH HER!"
},
{
"input": "yzlzmesxdttfcztooypjztlgxwcr",
"output": "IGNORE HIM!"
},
{
"input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc",
"output": "IGNORE HIM!"
},
{
"input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq",
"output": "CHAT WITH HER!"
},
{
"input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj",
"output": "IGNORE HIM!"
},
{
"input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom",
"output": "CHAT WITH HER!"
},
{
"input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo",
"output": "CHAT WITH HER!"
},
{
"input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh",
"output": "IGNORE HIM!"
},
{
"input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa",
"output": "CHAT WITH HER!"
},
{
"input": "oh",
"output": "CHAT WITH HER!"
},
{
"input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri",
"output": "IGNORE HIM!"
},
{
"input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp",
"output": "CHAT WITH HER!"
},
{
"input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp",
"output": "CHAT WITH HER!"
},
{
"input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo",
"output": "CHAT WITH HER!"
},
{
"input": "mnmbupgo",
"output": "IGNORE HIM!"
},
{
"input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl",
"output": "IGNORE HIM!"
},
{
"input": "yocxrzspinchmhtmqo",
"output": "CHAT WITH HER!"
},
{
"input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv",
"output": "CHAT WITH HER!"
},
{
"input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad",
"output": "IGNORE HIM!"
},
{
"input": "ubvhyaebyxoghakajqrpqpctwbrfqzli",
"output": "CHAT WITH HER!"
},
{
"input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy",
"output": "IGNORE HIM!"
},
{
"input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd",
"output": "IGNORE HIM!"
},
{
"input": "acrzbavz",
"output": "CHAT WITH HER!"
},
{
"input": "drvzznznvrzskftnrhvvzxcalwutxmdza",
"output": "IGNORE HIM!"
},
{
"input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws",
"output": "CHAT WITH HER!"
},
{
"input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff",
"output": "CHAT WITH HER!"
},
{
"input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu",
"output": "CHAT WITH HER!"
},
{
"input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw",
"output": "IGNORE HIM!"
},
{
"input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy",
"output": "CHAT WITH HER!"
},
{
"input": "rhh",
"output": "CHAT WITH HER!"
},
{
"input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo",
"output": "IGNORE HIM!"
},
{
"input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn",
"output": "CHAT WITH HER!"
},
{
"input": "urigreuzpxnej",
"output": "CHAT WITH HER!"
}
] | 1,695,231,452 | 2,147,483,647 | PyPy 3 | OK | TESTS | 85 | 186 | 0 | line = input()
i = 0
distinct = []
for j in line:
if j not in distinct:
distinct.append(j)
if (len(distinct) % 2) == 0:
print('CHAT WITH HER!')
else:
print('IGNORE HIM!')
| Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
Input Specification:
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
Output Specification:
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
Demo Input:
['wjmzbmr\n', 'xiaodao\n', 'sevenkplus\n']
Demo Output:
['CHAT WITH HER!\n', 'IGNORE HIM!\n', 'CHAT WITH HER!\n']
Note:
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | ```python
line = input()
i = 0
distinct = []
for j in line:
if j not in distinct:
distinct.append(j)
if (len(distinct) % 2) == 0:
print('CHAT WITH HER!')
else:
print('IGNORE HIM!')
``` | 3 |
|
710 | B | Optimal Point on a Line | PROGRAMMING | 1,400 | [
"brute force",
"sortings"
] | null | null | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points. | Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. | [
"4\n1 2 3 4\n"
] | [
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "5\n-1 -10 2 6 7",
"output": "2"
},
{
"input": "10\n-68 10 87 22 30 89 82 -97 -52 25",
"output": "22"
},
{
"input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -239 826 318 811 20 -732 -91 460 551 -610 555 -493 -154 442 -141 946 -913 -104 704 -380 699 32 106 -455 -518 214 -464 -861 243 -798 -472 559 529 -844 -32 871 -459 236 387 626 -318 -580 -611 -842 790 486 64 951 81 78 -693 403 -731 309 678 696 891 846 -106 918 212 -44 994 606 -829 -454 243 -477 -402 -818 -819 -310 -837 -209 736 424",
"output": "64"
},
{
"input": "2\n-1 0",
"output": "-1"
},
{
"input": "48\n-777 -767 -764 -713 -688 -682 -606 -586 -585 -483 -465 -440 -433 -397 -390 -377 -299 -252 -159 -147 -96 -29 -15 15 52 109 124 129 142 218 231 314 320 339 442 496 505 548 575 576 594 624 694 827 891 979 981 981",
"output": "15"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "4\n-1 -1 0 1",
"output": "-1"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 1000000000",
"output": "0"
},
{
"input": "2\n1 -1",
"output": "-1"
},
{
"input": "2\n100 50",
"output": "50"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n606194955 -856471310 117647402",
"output": "117647402"
},
{
"input": "2\n615002717 -843553590",
"output": "-843553590"
},
{
"input": "2\n-1 2",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "5\n-638512131 348325781 -550537933 -618161835 -567935532",
"output": "-567935532"
},
{
"input": "1\n120",
"output": "120"
},
{
"input": "2\n-1000000000 1000000000",
"output": "-1000000000"
},
{
"input": "1\n618309368",
"output": "618309368"
}
] | 1,484,338,587 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 4,608,000 | def main():
n = int(input())
arr = map(int, str(input()).split())
arr = list(sorted(arr))
print(arr[int((n + 1) / 2)])
main() | Title: Optimal Point on a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points.
Output Specification:
Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Demo Input:
['4\n1 2 3 4\n']
Demo Output:
['2\n']
Note:
none | ```python
def main():
n = int(input())
arr = map(int, str(input()).split())
arr = list(sorted(arr))
print(arr[int((n + 1) / 2)])
main()
``` | 0 |
|
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively. | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 5\n2 6\n2 5\n2 5\n2 4\n2 5",
"output": "Chris"
},
{
"input": "8\n4 1\n2 6\n4 2\n2 5\n5 2\n3 5\n5 2\n1 5",
"output": "Friendship is magic!^^"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "9\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 4\n6 6\n3 2\n1 5\n5 2\n1 5\n1 5\n3 1\n6 5\n4 3\n1 1\n5 1\n3 3\n2 4\n1 5\n3 4\n5 1\n5 5\n2 5\n2 1\n4 3\n6 5\n1 1\n2 1\n1 3\n1 1\n6 4\n4 6\n6 4\n2 1\n2 5\n6 2\n3 4\n5 5\n1 4\n4 6\n3 4\n1 6\n5 1\n4 3\n3 4\n2 2\n1 2\n2 3\n1 3\n4 4\n5 5\n4 5\n4 4\n3 1\n4 5\n2 3\n2 6\n6 5\n6 1\n6 6\n2 3\n6 4\n3 3\n2 5\n4 4\n3 1\n2 4\n6 1\n3 2\n1 3\n5 4\n6 6\n2 5\n5 1\n1 1\n2 5\n6 5\n3 6\n5 6\n4 3\n3 4\n3 4\n6 5\n5 2\n4 2\n1 1\n3 1\n2 6\n1 6\n1 2\n6 1\n3 4\n1 6\n3 1\n5 3\n1 3\n5 6\n2 1\n6 4\n3 1\n1 6\n6 3\n3 3\n4 3",
"output": "Chris"
},
{
"input": "100\n4 1\n3 4\n4 6\n4 5\n6 5\n5 3\n6 2\n6 3\n5 2\n4 5\n1 5\n5 4\n1 4\n4 5\n4 6\n1 6\n4 4\n5 1\n6 4\n6 4\n4 6\n2 3\n6 2\n4 6\n1 4\n2 3\n4 3\n1 3\n6 2\n3 1\n3 4\n2 6\n4 5\n5 4\n2 2\n2 5\n4 1\n2 2\n3 3\n1 4\n5 6\n6 4\n4 2\n6 1\n5 5\n4 1\n2 1\n6 4\n4 4\n4 3\n5 3\n4 5\n5 3\n3 5\n6 3\n1 1\n3 4\n6 3\n6 1\n5 1\n2 4\n4 3\n2 2\n5 5\n1 5\n5 3\n4 6\n1 4\n6 3\n4 3\n2 4\n3 2\n2 4\n3 4\n6 2\n5 6\n1 2\n1 5\n5 5\n2 6\n5 1\n1 6\n5 3\n3 5\n2 6\n4 6\n6 2\n3 1\n5 5\n6 1\n3 6\n4 4\n1 1\n4 6\n5 3\n4 2\n5 1\n3 3\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "100\n6 3\n4 5\n4 3\n5 4\n5 1\n6 3\n4 2\n4 6\n3 1\n2 4\n2 2\n4 6\n5 3\n5 5\n4 2\n6 2\n2 3\n4 4\n6 4\n3 5\n2 4\n2 2\n5 2\n3 5\n2 4\n4 4\n3 5\n6 5\n1 3\n1 6\n2 2\n2 4\n3 2\n5 4\n1 6\n3 4\n4 1\n1 5\n1 4\n5 3\n2 2\n4 5\n6 3\n4 4\n1 1\n4 1\n2 4\n4 1\n4 5\n5 3\n1 1\n1 6\n5 6\n6 6\n4 2\n4 3\n3 4\n3 6\n3 4\n6 5\n3 4\n5 4\n5 1\n5 3\n5 1\n1 2\n2 6\n3 4\n6 5\n4 3\n1 1\n5 5\n5 1\n3 3\n5 2\n1 3\n6 6\n5 6\n1 4\n4 4\n1 4\n3 6\n6 5\n3 3\n3 6\n1 5\n1 2\n3 6\n3 6\n4 1\n5 2\n1 2\n5 2\n3 3\n4 4\n4 2\n6 2\n5 4\n6 1\n6 3",
"output": "Mishka"
},
{
"input": "8\n4 1\n6 2\n4 1\n5 3\n4 1\n5 3\n6 2\n5 3",
"output": "Mishka"
},
{
"input": "5\n3 6\n3 5\n3 5\n1 6\n3 5",
"output": "Chris"
},
{
"input": "4\n4 1\n2 4\n5 3\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "6\n6 3\n5 1\n6 3\n4 3\n4 3\n5 2",
"output": "Mishka"
},
{
"input": "7\n3 4\n1 4\n2 5\n1 6\n1 6\n1 5\n3 4",
"output": "Chris"
},
{
"input": "6\n6 2\n2 5\n5 2\n3 6\n4 3\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "8\n6 1\n5 3\n4 3\n4 1\n5 1\n4 2\n4 2\n4 1",
"output": "Mishka"
},
{
"input": "9\n2 5\n2 5\n1 4\n2 6\n2 4\n2 5\n2 6\n1 5\n2 5",
"output": "Chris"
},
{
"input": "4\n6 2\n2 4\n4 2\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "9\n5 2\n4 1\n4 1\n5 1\n6 2\n6 1\n5 3\n6 1\n6 2",
"output": "Mishka"
},
{
"input": "8\n2 4\n3 6\n1 6\n1 6\n2 4\n3 4\n3 6\n3 4",
"output": "Chris"
},
{
"input": "6\n5 3\n3 6\n6 2\n1 6\n5 1\n3 5",
"output": "Friendship is magic!^^"
},
{
"input": "6\n5 2\n5 1\n6 1\n5 2\n4 2\n5 1",
"output": "Mishka"
},
{
"input": "5\n1 4\n2 5\n3 4\n2 6\n3 4",
"output": "Chris"
},
{
"input": "4\n6 2\n3 4\n5 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "93\n4 3\n4 1\n4 2\n5 2\n5 3\n6 3\n4 3\n6 2\n6 3\n5 1\n4 2\n4 2\n5 1\n6 2\n6 3\n6 1\n4 1\n6 2\n5 3\n4 3\n4 1\n4 2\n5 2\n6 3\n5 2\n5 2\n6 3\n5 1\n6 2\n5 2\n4 1\n5 2\n5 1\n4 1\n6 1\n5 2\n4 3\n5 3\n5 3\n5 1\n4 3\n4 3\n4 2\n4 1\n6 2\n6 1\n4 1\n5 2\n5 2\n6 2\n5 3\n5 1\n6 2\n5 1\n6 3\n5 2\n6 2\n6 2\n4 2\n5 2\n6 1\n6 3\n6 3\n5 1\n5 1\n4 1\n5 1\n4 3\n5 3\n6 3\n4 1\n4 3\n6 1\n6 1\n4 2\n6 2\n4 2\n5 2\n4 1\n5 2\n4 1\n5 1\n5 2\n5 1\n4 1\n6 3\n6 2\n4 3\n4 1\n5 2\n4 3\n5 2\n5 1",
"output": "Mishka"
},
{
"input": "11\n1 6\n1 6\n2 4\n2 5\n3 4\n1 5\n1 6\n1 5\n1 6\n2 6\n3 4",
"output": "Chris"
},
{
"input": "70\n6 1\n3 6\n4 3\n2 5\n5 2\n1 4\n6 2\n1 6\n4 3\n1 4\n5 3\n2 4\n5 3\n1 6\n5 1\n3 5\n4 2\n2 4\n5 1\n3 5\n6 2\n1 5\n4 2\n2 5\n5 3\n1 5\n4 2\n1 4\n5 2\n2 6\n4 3\n1 5\n6 2\n3 4\n4 2\n3 5\n6 3\n3 4\n5 1\n1 4\n4 2\n1 4\n6 3\n2 6\n5 2\n1 6\n6 1\n2 6\n5 3\n1 5\n5 1\n1 6\n4 1\n1 5\n4 2\n2 4\n5 1\n2 5\n6 3\n1 4\n6 3\n3 6\n5 1\n1 4\n5 3\n3 5\n4 2\n3 4\n6 2\n1 4",
"output": "Friendship is magic!^^"
},
{
"input": "59\n4 1\n5 3\n6 1\n4 2\n5 1\n4 3\n6 1\n5 1\n4 3\n4 3\n5 2\n5 3\n4 1\n6 2\n5 1\n6 3\n6 3\n5 2\n5 2\n6 1\n4 1\n6 1\n4 3\n5 3\n5 3\n4 3\n4 2\n4 2\n6 3\n6 3\n6 1\n4 3\n5 1\n6 2\n6 1\n4 1\n6 1\n5 3\n4 2\n5 1\n6 2\n6 2\n4 3\n5 3\n4 3\n6 3\n5 2\n5 2\n4 3\n5 1\n5 3\n6 1\n6 3\n6 3\n4 3\n5 2\n5 2\n5 2\n4 3",
"output": "Mishka"
},
{
"input": "42\n1 5\n1 6\n1 6\n1 4\n2 5\n3 6\n1 6\n3 4\n2 5\n2 5\n2 4\n1 4\n3 4\n2 4\n2 6\n1 5\n3 6\n2 6\n2 6\n3 5\n1 4\n1 5\n2 6\n3 6\n1 4\n3 4\n2 4\n1 6\n3 4\n2 4\n2 6\n1 6\n1 4\n1 6\n1 6\n2 4\n1 5\n1 6\n2 5\n3 6\n3 5\n3 4",
"output": "Chris"
},
{
"input": "78\n4 3\n3 5\n4 3\n1 5\n5 1\n1 5\n4 3\n1 4\n6 3\n1 5\n4 1\n2 4\n4 3\n2 4\n5 1\n3 6\n4 2\n3 6\n6 3\n3 4\n4 3\n3 6\n5 3\n1 5\n4 1\n2 6\n4 2\n2 4\n4 1\n3 5\n5 2\n3 6\n4 3\n2 4\n6 3\n1 6\n4 3\n3 5\n6 3\n2 6\n4 1\n2 4\n6 2\n1 6\n4 2\n1 4\n4 3\n1 4\n4 3\n2 4\n6 2\n3 5\n6 1\n3 6\n5 3\n1 6\n6 1\n2 6\n4 2\n1 5\n6 2\n2 6\n6 3\n2 4\n4 2\n3 5\n6 1\n2 5\n5 3\n2 6\n5 1\n3 6\n4 3\n3 6\n6 3\n2 5\n6 1\n2 6",
"output": "Friendship is magic!^^"
},
{
"input": "76\n4 1\n5 2\n4 3\n5 2\n5 3\n5 2\n6 1\n4 2\n6 2\n5 3\n4 2\n6 2\n4 1\n4 2\n5 1\n5 1\n6 2\n5 2\n5 3\n6 3\n5 2\n4 3\n6 3\n6 1\n4 3\n6 2\n6 1\n4 1\n6 1\n5 3\n4 1\n5 3\n4 2\n5 2\n4 3\n6 1\n6 2\n5 2\n6 1\n5 3\n4 3\n5 1\n5 3\n4 3\n5 1\n5 1\n4 1\n4 1\n4 1\n4 3\n5 3\n6 3\n6 3\n5 2\n6 2\n6 3\n5 1\n6 3\n5 3\n6 1\n5 3\n4 1\n5 3\n6 1\n4 2\n6 2\n4 3\n4 1\n6 2\n4 3\n5 3\n5 2\n5 3\n5 1\n6 3\n5 2",
"output": "Mishka"
},
{
"input": "84\n3 6\n3 4\n2 5\n2 4\n1 6\n3 4\n1 5\n1 6\n3 5\n1 6\n2 4\n2 6\n2 6\n2 4\n3 5\n1 5\n3 6\n3 6\n3 4\n3 4\n2 6\n1 6\n1 6\n3 5\n3 4\n1 6\n3 4\n3 5\n2 4\n2 5\n2 5\n3 5\n1 6\n3 4\n2 6\n2 6\n3 4\n3 4\n2 5\n2 5\n2 4\n3 4\n2 5\n3 4\n3 4\n2 6\n2 6\n1 6\n2 4\n1 5\n3 4\n2 5\n2 5\n3 4\n2 4\n2 6\n2 6\n1 4\n3 5\n3 5\n2 4\n2 5\n3 4\n1 5\n1 5\n2 6\n1 5\n3 5\n2 4\n2 5\n3 4\n2 6\n1 6\n2 5\n3 5\n3 5\n3 4\n2 5\n2 6\n3 4\n1 6\n2 5\n2 6\n1 4",
"output": "Chris"
},
{
"input": "44\n6 1\n1 6\n5 2\n1 4\n6 2\n2 5\n5 3\n3 6\n5 2\n1 6\n4 1\n2 4\n6 1\n3 4\n6 3\n3 6\n4 3\n2 4\n6 1\n3 4\n6 1\n1 6\n4 1\n3 5\n6 1\n3 6\n4 1\n1 4\n4 2\n2 6\n6 1\n2 4\n6 2\n1 4\n6 2\n2 4\n5 2\n3 6\n6 3\n2 6\n5 3\n3 4\n5 3\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "42\n5 3\n5 1\n5 2\n4 1\n6 3\n6 1\n6 2\n4 1\n4 3\n4 1\n5 1\n5 3\n5 1\n4 1\n4 2\n6 1\n6 3\n5 1\n4 1\n4 1\n6 3\n4 3\n6 3\n5 2\n6 1\n4 1\n5 3\n4 3\n5 2\n6 3\n6 1\n5 1\n4 2\n4 3\n5 2\n5 3\n6 3\n5 2\n5 1\n5 3\n6 2\n6 1",
"output": "Mishka"
},
{
"input": "50\n3 6\n2 6\n1 4\n1 4\n1 4\n2 5\n3 4\n3 5\n2 6\n1 6\n3 5\n1 5\n2 6\n2 4\n2 4\n3 5\n1 6\n1 5\n1 5\n1 4\n3 5\n1 6\n3 5\n1 4\n1 5\n1 4\n3 6\n1 6\n1 4\n1 4\n1 4\n1 5\n3 6\n1 6\n1 6\n2 4\n1 5\n2 6\n2 5\n3 5\n3 6\n3 4\n2 4\n2 6\n3 4\n2 5\n3 6\n3 5\n2 4\n2 4",
"output": "Chris"
},
{
"input": "86\n6 3\n2 4\n6 3\n3 5\n6 3\n1 5\n5 2\n2 4\n4 3\n2 6\n4 1\n2 6\n5 2\n1 4\n5 1\n2 4\n4 1\n1 4\n6 2\n3 5\n4 2\n2 4\n6 2\n1 5\n5 3\n2 5\n5 1\n1 6\n6 1\n1 4\n4 3\n3 4\n5 2\n2 4\n5 3\n2 5\n4 3\n3 4\n4 1\n1 5\n6 3\n3 4\n4 3\n3 4\n4 1\n3 4\n5 1\n1 6\n4 2\n1 6\n5 1\n2 4\n5 1\n3 6\n4 1\n1 5\n5 2\n1 4\n4 3\n2 5\n5 1\n1 5\n6 2\n2 6\n4 2\n2 4\n4 1\n2 5\n5 3\n3 4\n5 1\n3 4\n6 3\n3 4\n4 3\n2 6\n6 2\n2 5\n5 2\n3 5\n4 2\n3 6\n6 2\n3 4\n4 2\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "84\n6 1\n6 3\n6 3\n4 1\n4 3\n4 2\n6 3\n5 3\n6 1\n6 3\n4 3\n5 2\n5 3\n5 1\n6 2\n6 2\n6 1\n4 1\n6 3\n5 2\n4 1\n5 3\n6 3\n4 2\n6 2\n6 3\n4 3\n4 1\n4 3\n5 1\n5 1\n5 1\n4 1\n6 1\n4 3\n6 2\n5 1\n5 1\n6 2\n5 2\n4 1\n6 1\n6 1\n6 3\n6 2\n4 3\n6 3\n6 2\n5 2\n5 1\n4 3\n6 2\n4 1\n6 2\n6 1\n5 2\n5 1\n6 2\n6 1\n5 3\n5 2\n6 1\n6 3\n5 2\n6 1\n6 3\n4 3\n5 1\n6 3\n6 1\n5 3\n4 3\n5 2\n5 1\n6 2\n5 3\n6 1\n5 1\n4 1\n5 1\n5 1\n5 2\n5 2\n5 1",
"output": "Mishka"
},
{
"input": "92\n1 5\n2 4\n3 5\n1 6\n2 5\n1 6\n3 6\n1 6\n2 4\n3 4\n3 4\n3 6\n1 5\n2 5\n1 5\n1 5\n2 6\n2 4\n3 6\n1 4\n1 6\n2 6\n3 4\n2 6\n2 6\n1 4\n3 5\n2 5\n2 6\n1 5\n1 4\n1 5\n3 6\n3 5\n2 5\n1 5\n3 5\n3 6\n2 6\n2 6\n1 5\n3 4\n2 4\n3 6\n2 5\n1 5\n2 4\n1 4\n2 6\n2 6\n2 6\n1 5\n3 6\n3 6\n2 5\n1 4\n2 4\n3 4\n1 5\n2 5\n2 4\n2 5\n3 5\n3 4\n3 6\n2 6\n3 5\n1 4\n3 4\n1 6\n3 6\n2 6\n1 4\n3 6\n3 6\n2 5\n2 6\n1 6\n2 6\n3 5\n2 5\n3 6\n2 5\n2 6\n1 5\n2 4\n1 4\n2 4\n1 5\n2 5\n2 5\n2 6",
"output": "Chris"
},
{
"input": "20\n5 1\n1 4\n4 3\n1 5\n4 2\n3 6\n6 2\n1 6\n4 1\n1 4\n5 2\n3 4\n5 1\n1 6\n5 1\n2 6\n6 3\n2 5\n6 2\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "100\n4 3\n4 3\n4 2\n4 3\n4 1\n4 3\n5 2\n5 2\n6 2\n4 2\n5 1\n4 2\n5 2\n6 1\n4 1\n6 3\n5 3\n5 1\n5 1\n5 1\n5 3\n6 1\n6 1\n4 1\n5 2\n5 2\n6 1\n6 3\n4 2\n4 1\n5 3\n4 1\n5 3\n5 1\n6 3\n6 3\n6 1\n5 2\n5 3\n5 3\n6 1\n4 1\n6 2\n6 1\n6 2\n6 3\n4 3\n4 3\n6 3\n4 2\n4 2\n5 3\n5 2\n5 2\n4 3\n5 3\n5 2\n4 2\n5 1\n4 2\n5 1\n5 3\n6 3\n5 3\n5 3\n4 2\n4 1\n4 2\n4 3\n6 3\n4 3\n6 2\n6 1\n5 3\n5 2\n4 1\n6 1\n5 2\n6 2\n4 2\n6 3\n4 3\n5 1\n6 3\n5 2\n4 3\n5 3\n5 3\n4 3\n6 3\n4 3\n4 1\n5 1\n6 2\n6 3\n5 3\n6 1\n6 3\n5 3\n6 1",
"output": "Mishka"
},
{
"input": "100\n1 5\n1 4\n1 5\n2 4\n2 6\n3 6\n3 5\n1 5\n2 5\n3 6\n3 5\n1 6\n1 4\n1 5\n1 6\n2 6\n1 5\n3 5\n3 4\n2 6\n2 6\n2 5\n3 4\n1 6\n1 4\n2 4\n1 5\n1 6\n3 5\n1 6\n2 6\n3 5\n1 6\n3 4\n3 5\n1 6\n3 6\n2 4\n2 4\n3 5\n2 6\n1 5\n3 5\n3 6\n2 4\n2 4\n2 6\n3 4\n3 4\n1 5\n1 4\n2 5\n3 4\n1 4\n2 6\n2 5\n2 4\n2 4\n2 5\n1 5\n1 6\n1 5\n1 5\n1 5\n1 6\n3 4\n2 4\n3 5\n3 5\n1 6\n3 5\n1 5\n1 6\n3 6\n3 4\n1 5\n3 5\n3 6\n1 4\n3 6\n1 5\n3 5\n3 6\n3 5\n1 4\n3 4\n2 4\n2 4\n2 5\n3 6\n3 5\n1 5\n2 4\n1 4\n3 4\n1 5\n3 4\n3 6\n3 5\n3 4",
"output": "Chris"
},
{
"input": "100\n4 3\n3 4\n5 1\n2 5\n5 3\n1 5\n6 3\n2 4\n5 2\n2 6\n5 2\n1 5\n6 3\n1 5\n6 3\n3 4\n5 2\n1 5\n6 1\n1 5\n4 2\n3 5\n6 3\n2 6\n6 3\n1 4\n6 2\n3 4\n4 1\n3 6\n5 1\n2 4\n5 1\n3 4\n6 2\n3 5\n4 1\n2 6\n4 3\n2 6\n5 2\n3 6\n6 2\n3 5\n4 3\n1 5\n5 3\n3 6\n4 2\n3 4\n6 1\n3 4\n5 2\n2 6\n5 2\n2 4\n6 2\n3 6\n4 3\n2 4\n4 3\n2 6\n4 2\n3 4\n6 3\n2 4\n6 3\n3 5\n5 2\n1 5\n6 3\n3 6\n4 3\n1 4\n5 2\n1 6\n4 1\n2 5\n4 1\n2 4\n4 2\n2 5\n6 1\n2 4\n6 3\n1 5\n4 3\n2 6\n6 3\n2 6\n5 3\n1 5\n4 1\n1 5\n6 2\n2 5\n5 1\n3 6\n4 3\n3 4",
"output": "Friendship is magic!^^"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "99\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "84\n6 2\n1 5\n6 2\n2 3\n5 5\n1 2\n3 4\n3 4\n6 5\n6 4\n2 5\n4 1\n1 2\n1 1\n1 4\n2 5\n5 6\n6 3\n2 4\n5 5\n2 6\n3 4\n5 1\n3 3\n5 5\n4 6\n4 6\n2 4\n4 1\n5 2\n2 2\n3 6\n3 3\n4 6\n1 1\n2 4\n6 5\n5 2\n6 5\n5 5\n2 5\n6 4\n1 1\n6 2\n3 6\n6 5\n4 4\n1 5\n5 6\n4 4\n3 5\n6 1\n3 4\n1 5\n4 6\n4 6\n4 1\n3 6\n6 2\n1 1\n4 5\n5 4\n5 3\n3 4\n6 4\n1 1\n5 2\n6 5\n6 1\n2 2\n2 4\n3 3\n4 6\n1 3\n6 6\n5 2\n1 6\n6 2\n6 6\n4 1\n3 6\n6 4\n2 3\n3 4",
"output": "Chris"
},
{
"input": "70\n3 4\n2 3\n2 3\n6 5\n6 6\n4 3\n2 3\n3 1\n3 5\n5 6\n1 6\n2 5\n5 3\n2 5\n4 6\n5 1\n6 1\n3 1\n3 3\n5 3\n2 1\n3 3\n6 4\n6 3\n4 3\n4 5\n3 5\n5 5\n5 2\n1 6\n3 4\n5 2\n2 4\n1 6\n4 3\n4 3\n6 2\n1 3\n1 5\n6 1\n3 1\n1 1\n1 3\n2 2\n3 2\n6 4\n1 1\n4 4\n3 1\n4 5\n4 2\n6 3\n4 4\n3 2\n1 2\n2 6\n3 3\n1 5\n1 1\n6 5\n2 2\n3 1\n5 4\n5 2\n6 4\n6 3\n6 6\n6 3\n3 3\n5 4",
"output": "Mishka"
},
{
"input": "56\n6 4\n3 4\n6 1\n3 3\n1 4\n2 3\n1 5\n2 5\n1 5\n5 5\n2 3\n1 1\n3 2\n3 5\n4 6\n4 4\n5 2\n4 3\n3 1\n3 6\n2 3\n3 4\n5 6\n5 2\n5 6\n1 5\n1 5\n4 1\n6 3\n2 2\n2 1\n5 5\n2 1\n4 1\n5 4\n2 5\n4 1\n6 2\n3 4\n4 2\n6 4\n5 4\n4 2\n4 3\n6 2\n6 2\n3 1\n1 4\n3 6\n5 1\n5 5\n3 6\n6 4\n2 3\n6 5\n3 3",
"output": "Mishka"
},
{
"input": "94\n2 4\n6 4\n1 6\n1 4\n5 1\n3 3\n4 3\n6 1\n6 5\n3 2\n2 3\n5 1\n5 3\n1 2\n4 3\n3 2\n2 3\n4 6\n1 3\n6 3\n1 1\n3 2\n4 3\n1 5\n4 6\n3 2\n6 3\n1 6\n1 1\n1 2\n3 5\n1 3\n3 5\n4 4\n4 2\n1 4\n4 5\n1 3\n1 2\n1 1\n5 4\n5 5\n6 1\n2 1\n2 6\n6 6\n4 2\n3 6\n1 6\n6 6\n1 5\n3 2\n1 2\n4 4\n6 4\n4 1\n1 5\n3 3\n1 3\n3 4\n4 4\n1 1\n2 5\n4 5\n3 1\n3 1\n3 6\n3 2\n1 4\n1 6\n6 3\n2 4\n1 1\n2 2\n2 2\n2 1\n5 4\n1 2\n6 6\n2 2\n3 3\n6 3\n6 3\n1 6\n2 3\n2 4\n2 3\n6 6\n2 6\n6 3\n3 5\n1 4\n1 1\n3 5",
"output": "Chris"
},
{
"input": "81\n4 2\n1 2\n2 3\n4 5\n6 2\n1 6\n3 6\n3 4\n4 6\n4 4\n3 5\n4 6\n3 6\n3 5\n3 1\n1 3\n5 3\n3 4\n1 1\n4 1\n1 2\n6 1\n1 3\n6 5\n4 5\n4 2\n4 5\n6 2\n1 2\n2 6\n5 2\n1 5\n2 4\n4 3\n5 4\n1 2\n5 3\n2 6\n6 4\n1 1\n1 3\n3 1\n3 1\n6 5\n5 5\n6 1\n6 6\n5 2\n1 3\n1 4\n2 3\n5 5\n3 1\n3 1\n4 4\n1 6\n6 4\n2 2\n4 6\n4 4\n2 6\n2 4\n2 4\n4 1\n1 6\n1 4\n1 3\n6 5\n5 1\n1 3\n5 1\n1 4\n3 5\n2 6\n1 3\n5 6\n3 5\n4 4\n5 5\n5 6\n4 3",
"output": "Chris"
},
{
"input": "67\n6 5\n3 6\n1 6\n5 3\n5 4\n5 1\n1 6\n1 1\n3 2\n4 4\n3 1\n4 1\n1 5\n5 3\n3 3\n6 4\n2 4\n2 2\n4 3\n1 4\n1 4\n6 1\n1 2\n2 2\n5 1\n6 2\n3 5\n5 5\n2 2\n6 5\n6 2\n4 4\n3 1\n4 2\n6 6\n6 4\n5 1\n2 2\n4 5\n5 5\n4 6\n1 5\n6 3\n4 4\n1 5\n6 4\n3 6\n3 4\n1 6\n2 4\n2 1\n2 5\n6 5\n6 4\n4 1\n3 2\n1 2\n5 1\n5 6\n1 5\n3 5\n3 1\n5 3\n3 2\n5 1\n4 6\n6 6",
"output": "Mishka"
},
{
"input": "55\n6 6\n6 5\n2 2\n2 2\n6 4\n5 5\n6 5\n5 3\n1 3\n2 2\n5 6\n3 3\n3 3\n6 5\n3 5\n5 5\n1 2\n1 1\n4 6\n1 2\n5 5\n6 2\n6 3\n1 2\n5 1\n1 3\n3 3\n4 4\n2 5\n1 1\n5 3\n4 3\n2 2\n4 5\n5 6\n4 5\n6 3\n1 6\n6 4\n3 6\n1 6\n5 2\n6 3\n2 3\n5 5\n4 3\n3 1\n4 2\n1 1\n2 5\n5 3\n2 2\n6 3\n4 5\n2 2",
"output": "Mishka"
},
{
"input": "92\n2 3\n1 3\n2 6\n5 1\n5 5\n3 2\n5 6\n2 5\n3 1\n3 6\n4 5\n2 5\n1 2\n2 3\n6 5\n3 6\n4 4\n6 2\n4 5\n4 4\n5 1\n6 1\n3 4\n3 5\n6 6\n3 2\n6 4\n2 2\n3 5\n6 4\n6 3\n6 6\n3 4\n3 3\n6 1\n5 4\n6 2\n2 6\n5 6\n1 4\n4 6\n6 3\n3 1\n4 1\n6 6\n3 5\n6 3\n6 1\n1 6\n3 2\n6 6\n4 3\n3 4\n1 3\n3 5\n5 3\n6 5\n4 3\n5 5\n4 1\n1 5\n6 4\n2 3\n2 3\n1 5\n1 2\n5 2\n4 3\n3 6\n5 5\n5 4\n1 4\n3 3\n1 6\n5 6\n5 4\n5 3\n1 1\n6 2\n5 5\n2 5\n4 3\n6 6\n5 1\n1 1\n4 6\n4 6\n3 1\n6 4\n2 4\n2 2\n2 1",
"output": "Chris"
},
{
"input": "79\n5 3\n4 6\n3 6\n2 1\n5 2\n2 3\n4 4\n6 2\n2 5\n1 6\n6 6\n2 6\n3 3\n4 5\n6 2\n2 1\n1 5\n5 1\n2 1\n2 6\n5 3\n6 2\n2 6\n2 3\n1 5\n4 4\n6 3\n5 2\n3 2\n1 3\n1 3\n6 3\n2 6\n3 6\n5 3\n4 5\n6 1\n3 5\n3 5\n6 5\n1 5\n4 2\n6 2\n2 3\n4 6\n3 6\n2 5\n4 4\n1 1\n4 6\n2 6\n6 4\n3 2\n4 1\n1 2\n6 4\n5 6\n1 4\n2 2\n5 4\n3 2\n1 2\n2 4\n2 5\n2 1\n3 6\n3 3\n1 1\n2 2\n4 4\n4 5\n3 3\n5 3\n6 2\n4 5\n6 5\n2 5\n5 6\n2 2",
"output": "Chris"
},
{
"input": "65\n1 1\n5 1\n2 2\n5 4\n4 5\n2 5\n3 2\n5 6\n6 3\n1 1\n6 1\n1 5\n1 1\n5 2\n6 4\n1 6\n1 1\n4 3\n2 3\n5 6\n4 4\n6 2\n1 3\n4 3\n1 3\n6 3\n3 5\n4 2\n4 1\n6 1\n3 2\n2 6\n3 2\n3 5\n6 3\n4 3\n1 5\n2 6\n1 3\n4 1\n4 1\n2 5\n2 5\n6 2\n5 3\n3 1\n3 3\n5 1\n2 4\n5 3\n3 3\n1 1\n6 3\n3 3\n5 1\n1 6\n4 5\n6 6\n5 5\n2 5\n4 1\n2 2\n1 4\n1 6\n6 5",
"output": "Mishka"
},
{
"input": "1\n1 1",
"output": "Friendship is magic!^^"
}
] | 1,698,832,556 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 46 | 0 | n = int(input(""))
r1,r2 = list(map(int,input().split()))
r3,r4 = list(map(int,input().split()))
r5,r6 = list(map(int,input().split()))
c = 0
b = 0
if r1 > r2:
c += 1
if r3 > r4:
c += 1
if r5 > r6:
b += 1
if r1 < r2:
b += 1
if r3 < r4:
b += 1
if r5 < r6:
b += 1
if r1 == r2:
c += 1
b += 1
if r3 == r4:
c += 1
b += 1
if r5 == r6:
c += 1
b += 1
if c < b:
print("Mishka")
if c > b:
print("Chris")
if c == b:
print("Friendship is magic!^^")
| Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
Input Specification:
The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively.
Output Specification:
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
Demo Input:
['3\n3 5\n2 1\n4 2\n', '2\n6 1\n1 6\n', '3\n1 5\n3 3\n2 2\n']
Demo Output:
['Mishka', 'Friendship is magic!^^', 'Chris']
Note:
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | ```python
n = int(input(""))
r1,r2 = list(map(int,input().split()))
r3,r4 = list(map(int,input().split()))
r5,r6 = list(map(int,input().split()))
c = 0
b = 0
if r1 > r2:
c += 1
if r3 > r4:
c += 1
if r5 > r6:
b += 1
if r1 < r2:
b += 1
if r3 < r4:
b += 1
if r5 < r6:
b += 1
if r1 == r2:
c += 1
b += 1
if r3 == r4:
c += 1
b += 1
if r5 == r6:
c += 1
b += 1
if c < b:
print("Mishka")
if c > b:
print("Chris")
if c == b:
print("Friendship is magic!^^")
``` | -1 |
|
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "ZJWUBWUBWUBJWUBWUBWUBL",
"output": "ZJ J L "
},
{
"input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB",
"output": "C B E Q "
},
{
"input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB",
"output": "JKD WBIRAQKF YE WV "
},
{
"input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB",
"output": "KSDHEMIXUJ R S H "
},
{
"input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB",
"output": "OG X I KO "
},
{
"input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH",
"output": "Q QQ I WW JOPJPBRH "
},
{
"input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB",
"output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C "
},
{
"input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV",
"output": "E IQMJNIQ GZZBQZAUHYP PMR DCV "
},
{
"input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB",
"output": "FV BPS RXNETCJ JDMBH B V B "
},
{
"input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL",
"output": "FBQ IDFSY CTWDM SXO QI L "
},
{
"input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL",
"output": "I QLHD YIIKZDFQ CX U K NL "
},
{
"input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE",
"output": "K UPDYXGOKU AGOAH IZD IY V P E "
},
{
"input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB",
"output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ "
},
{
"input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB",
"output": "PAMJGY XGPQM TKGSXUY E N H E "
},
{
"input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB",
"output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB "
},
{
"input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM",
"output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M "
},
{
"input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW",
"output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W "
},
{
"input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG",
"output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G "
},
{
"input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN",
"output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N "
},
{
"input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG",
"output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG "
},
{
"input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB",
"output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L "
},
{
"input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB",
"output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U "
},
{
"input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB",
"output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ "
},
{
"input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB",
"output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J "
},
{
"input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO",
"output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O "
},
{
"input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR",
"output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R "
},
{
"input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB",
"output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM "
},
{
"input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB",
"output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H "
},
{
"input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB",
"output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S "
},
{
"input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB",
"output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J "
},
{
"input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF",
"output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F "
},
{
"input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY",
"output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y "
},
{
"input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB",
"output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO "
},
{
"input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW",
"output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W "
},
{
"input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD",
"output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D "
},
{
"input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB",
"output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A "
},
{
"input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB",
"output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y "
},
{
"input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB",
"output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R "
},
{
"input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY",
"output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y "
},
{
"input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE",
"output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E "
},
{
"input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS",
"output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S "
},
{
"input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP",
"output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP "
},
{
"input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB",
"output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y "
},
{
"input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL",
"output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL "
},
{
"input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO",
"output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O "
},
{
"input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU",
"output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU "
},
{
"input": "A",
"output": "A "
},
{
"input": "WUBA",
"output": "A "
},
{
"input": "WUBWUBA",
"output": "A "
},
{
"input": "AWUBWUBWUB",
"output": "A "
},
{
"input": "AWUBBWUBCWUBD",
"output": "A B C D "
},
{
"input": "WUBWWUBWUBWUBUWUBWUBBWUB",
"output": "W U B "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "WUWUBBWWUBUB",
"output": "WU BW UB "
},
{
"input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB",
"output": "WUAB "
},
{
"input": "ZWUB",
"output": "Z "
},
{
"input": "WU",
"output": "WU "
},
{
"input": "UB",
"output": "UB "
},
{
"input": "U",
"output": "U "
},
{
"input": "WUBW",
"output": "W "
},
{
"input": "WUBWU",
"output": "WU "
},
{
"input": "WUWUB",
"output": "WU "
},
{
"input": "UBWUB",
"output": "UB "
},
{
"input": "WUWUBUBWUBUWUB",
"output": "WU UB U "
},
{
"input": "WUBWWUBAWUB",
"output": "W A "
},
{
"input": "WUUUUU",
"output": "WUUUUU "
}
] | 1,686,828,123 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 154 | 0 | txt = input();
lst = txt.rsplit("WUB")
for item in lst:
if len(item) > 0:
print(item, end=" ")
print()
| Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
Input Specification:
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Output Specification:
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
Demo Input:
['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n']
Demo Output:
['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND ']
Note:
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | ```python
txt = input();
lst = txt.rsplit("WUB")
for item in lst:
if len(item) > 0:
print(item, end=" ")
print()
``` | 3 |
|
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given *a*, *b* and *n* who wins the game. | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*.
In the first sample the game will go like that:
- Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that. | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "41 12 65",
"output": "1"
},
{
"input": "13 61 100",
"output": "1"
},
{
"input": "100 100 10",
"output": "0"
},
{
"input": "12 24 26",
"output": "1"
},
{
"input": "73 21 96",
"output": "1"
},
{
"input": "17 22 81",
"output": "1"
},
{
"input": "14 88 97",
"output": "1"
},
{
"input": "42 81 17",
"output": "0"
},
{
"input": "34 36 19",
"output": "1"
},
{
"input": "21 87 12",
"output": "1"
},
{
"input": "97 92 98",
"output": "1"
},
{
"input": "49 25 62",
"output": "1"
},
{
"input": "29 17 44",
"output": "1"
},
{
"input": "10 1 10",
"output": "0"
},
{
"input": "99 98 100",
"output": "1"
},
{
"input": "100 100 1",
"output": "0"
},
{
"input": "11 99 55",
"output": "0"
},
{
"input": "8 13 21",
"output": "0"
},
{
"input": "34 55 89",
"output": "0"
},
{
"input": "21 34 55",
"output": "1"
},
{
"input": "13 21 34",
"output": "1"
},
{
"input": "34 21 55",
"output": "0"
},
{
"input": "10 20 84",
"output": "1"
},
{
"input": "4 2 5",
"output": "0"
},
{
"input": "3 2 3",
"output": "0"
},
{
"input": "31 23 1",
"output": "0"
},
{
"input": "100 100 100",
"output": "0"
},
{
"input": "100 1 100",
"output": "0"
},
{
"input": "1 100 100",
"output": "1"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "17 23 100",
"output": "1"
},
{
"input": "99 98 100",
"output": "1"
},
{
"input": "1 1 2",
"output": "1"
},
{
"input": "2 1 1",
"output": "0"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "2 1 2",
"output": "0"
},
{
"input": "10 10 3",
"output": "1"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "9 5 1",
"output": "0"
}
] | 1,620,973,326 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 124 | 6,758,400 | import math
# n = int(input())
a,b,n = map(int,input().split())
lost = False
lose = -1
while not lost:
n -= math.gcd(a,n)
if n < 0:
lose = 0
lost = True
break
n -= math.gcd(b,n)
if n < 0:
lose = 1
lost = True
print( 1 - lose)
| Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given *a*, *b* and *n* who wins the game.
Input Specification:
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output Specification:
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Demo Input:
['3 5 9\n', '1 1 100\n']
Demo Output:
['0', '1']
Note:
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*.
In the first sample the game will go like that:
- Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that. | ```python
import math
# n = int(input())
a,b,n = map(int,input().split())
lost = False
lose = -1
while not lost:
n -= math.gcd(a,n)
if n < 0:
lose = 0
lost = True
break
n -= math.gcd(b,n)
if n < 0:
lose = 1
lost = True
print( 1 - lose)
``` | 3 |
|
854 | B | Maxim Buys an Apartment | PROGRAMMING | 1,200 | [
"constructive algorithms",
"math"
] | null | null | Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has *n* apartments that are numbered from 1 to *n* and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.
Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly *k* already inhabited apartments, but he doesn't know their indices yet.
Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim. | The only line of the input contains two integers: *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=*n*). | Print the minimum possible and the maximum possible number of apartments good for Maxim. | [
"6 3\n"
] | [
"1 3\n"
] | In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good. | 1,000 | [
{
"input": "6 3",
"output": "1 3"
},
{
"input": "10 1",
"output": "1 2"
},
{
"input": "10 9",
"output": "1 1"
},
{
"input": "8 0",
"output": "0 0"
},
{
"input": "8 8",
"output": "0 0"
},
{
"input": "966871928 890926970",
"output": "1 75944958"
},
{
"input": "20 2",
"output": "1 4"
},
{
"input": "1 0",
"output": "0 0"
},
{
"input": "1 1",
"output": "0 0"
},
{
"input": "2 0",
"output": "0 0"
},
{
"input": "2 1",
"output": "1 1"
},
{
"input": "2 2",
"output": "0 0"
},
{
"input": "7 2",
"output": "1 4"
},
{
"input": "8 3",
"output": "1 5"
},
{
"input": "9 4",
"output": "1 5"
},
{
"input": "10 3",
"output": "1 6"
},
{
"input": "10 4",
"output": "1 6"
},
{
"input": "10 5",
"output": "1 5"
},
{
"input": "1000 1000",
"output": "0 0"
},
{
"input": "1000 333",
"output": "1 666"
},
{
"input": "1000 334",
"output": "1 666"
},
{
"input": "999 333",
"output": "1 666"
},
{
"input": "999 334",
"output": "1 665"
},
{
"input": "998 332",
"output": "1 664"
},
{
"input": "998 333",
"output": "1 665"
},
{
"input": "89 4",
"output": "1 8"
},
{
"input": "66 50",
"output": "1 16"
},
{
"input": "88 15",
"output": "1 30"
},
{
"input": "95 43",
"output": "1 52"
},
{
"input": "900 344",
"output": "1 556"
},
{
"input": "777 113",
"output": "1 226"
},
{
"input": "964 42",
"output": "1 84"
},
{
"input": "982 867",
"output": "1 115"
},
{
"input": "1000000000 0",
"output": "0 0"
},
{
"input": "1000000000 1000000000",
"output": "0 0"
},
{
"input": "1000000000 333333333",
"output": "1 666666666"
},
{
"input": "1000000000 333333334",
"output": "1 666666666"
},
{
"input": "999999999 333333333",
"output": "1 666666666"
},
{
"input": "999999999 333333334",
"output": "1 666666665"
},
{
"input": "999999998 333333332",
"output": "1 666666664"
},
{
"input": "999999998 333333333",
"output": "1 666666665"
},
{
"input": "78602604 42160832",
"output": "1 36441772"
},
{
"input": "35679021 9137902",
"output": "1 18275804"
},
{
"input": "41949373 13173511",
"output": "1 26347022"
},
{
"input": "77855558 49163875",
"output": "1 28691683"
},
{
"input": "87187123 2851901",
"output": "1 5703802"
},
{
"input": "66849627 25004217",
"output": "1 41845410"
},
{
"input": "873046672 517064947",
"output": "1 355981725"
},
{
"input": "639857373 1393427",
"output": "1 2786854"
},
{
"input": "637563683 69636269",
"output": "1 139272538"
},
{
"input": "911669737 141068293",
"output": "1 282136586"
},
{
"input": "547575919 313272818",
"output": "1 234303101"
},
{
"input": "955020006 297895809",
"output": "1 595791618"
},
{
"input": "10 4",
"output": "1 6"
},
{
"input": "11 3",
"output": "1 6"
},
{
"input": "10 3",
"output": "1 6"
},
{
"input": "4 1",
"output": "1 2"
},
{
"input": "9 3",
"output": "1 6"
},
{
"input": "7 2",
"output": "1 4"
},
{
"input": "7 3",
"output": "1 4"
},
{
"input": "12 5",
"output": "1 7"
},
{
"input": "8 3",
"output": "1 5"
},
{
"input": "1000 8",
"output": "1 16"
}
] | 1,513,287,045 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 62 | 5,529,600 | n, k = map(int, input().split())
a = 1 if k and k < n else 0
b = 2 * k if k <= n // 3 else n - k
print(a, b) | Title: Maxim Buys an Apartment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has *n* apartments that are numbered from 1 to *n* and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.
Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly *k* already inhabited apartments, but he doesn't know their indices yet.
Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.
Input Specification:
The only line of the input contains two integers: *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=*n*).
Output Specification:
Print the minimum possible and the maximum possible number of apartments good for Maxim.
Demo Input:
['6 3\n']
Demo Output:
['1 3\n']
Note:
In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good. | ```python
n, k = map(int, input().split())
a = 1 if k and k < n else 0
b = 2 * k if k <= n // 3 else n - k
print(a, b)
``` | 3 |
|
50 | B | Choosing Symbol Pairs | PROGRAMMING | 1,500 | [
"strings"
] | B. Choosing Symbol Pairs | 2 | 256 | There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th. | The single input line contains *S*, consisting of lowercase Latin letters and digits. It is guaranteed that string *S* in not empty and its length does not exceed 105. | Print a single number which represents the number of pairs *i* and *j* with the needed property. Pairs (*x*,<=*y*) and (*y*,<=*x*) should be considered different, i.e. the ordered pairs count. | [
"great10\n",
"aaaaaaaaaa\n"
] | [
"7\n",
"100\n"
] | none | 1,000 | [
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "aabb",
"output": "8"
},
{
"input": "w",
"output": "1"
},
{
"input": "129a",
"output": "4"
},
{
"input": "233444",
"output": "14"
},
{
"input": "abacaba",
"output": "21"
},
{
"input": "abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321",
"output": "324"
},
{
"input": "zazaeeeeeeeq34443333444tttttt",
"output": "155"
},
{
"input": "00000000000000000000000",
"output": "529"
},
{
"input": "999000888775646453342311",
"output": "62"
}
] | 1,616,225,570 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 186 | 307,200 | s=input()
m=0
d={}
for i in s:
d[i]=d.get(i,0)+1
ls=list(d.items())
for each in ls:
if each[1]>1:
m+=each[1]**2
else:
m+=1
print(m) | Title: Choosing Symbol Pairs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th.
Input Specification:
The single input line contains *S*, consisting of lowercase Latin letters and digits. It is guaranteed that string *S* in not empty and its length does not exceed 105.
Output Specification:
Print a single number which represents the number of pairs *i* and *j* with the needed property. Pairs (*x*,<=*y*) and (*y*,<=*x*) should be considered different, i.e. the ordered pairs count.
Demo Input:
['great10\n', 'aaaaaaaaaa\n']
Demo Output:
['7\n', '100\n']
Note:
none | ```python
s=input()
m=0
d={}
for i in s:
d[i]=d.get(i,0)+1
ls=list(d.items())
for each in ls:
if each[1]>1:
m+=each[1]**2
else:
m+=1
print(m)
``` | 3.952928 |
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,663,001,035 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def main():
def recur(m, n):
m, n = max(m, n), min(n, m)
if m == 1 and n == 1:
return 0
if m == 2 and n == 1:
return 1
return recur(m // 2, n) + recur(m - m // 2, n)
m, n = tuple(map(lambda x: int(x), input().split()))
recur(m, n)
if __name__ == "__main__":
main() | 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
def main():
def recur(m, n):
m, n = max(m, n), min(n, m)
if m == 1 and n == 1:
return 0
if m == 2 and n == 1:
return 1
return recur(m // 2, n) + recur(m - m // 2, n)
m, n = tuple(map(lambda x: int(x), input().split()))
recur(m, n)
if __name__ == "__main__":
main()
``` | 0 |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold. | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one). | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4. | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9 16 25 36 49 64 81 100",
"output": "19"
},
{
"input": "10\n300 315 325 338 350 365 379 391 404 416",
"output": "23"
},
{
"input": "15\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112",
"output": "2"
},
{
"input": "60\n3 5 7 8 15 16 18 21 24 26 40 41 43 47 48 49 50 51 52 54 55 60 62 71 74 84 85 89 91 96 406 407 409 412 417 420 423 424 428 431 432 433 436 441 445 446 447 455 458 467 469 471 472 475 480 485 492 493 497 500",
"output": "310"
},
{
"input": "3\n159 282 405",
"output": "246"
},
{
"input": "81\n6 7 22 23 27 38 40 56 59 71 72 78 80 83 86 92 95 96 101 122 125 127 130 134 154 169 170 171 172 174 177 182 184 187 195 197 210 211 217 223 241 249 252 253 256 261 265 269 274 277 291 292 297 298 299 300 302 318 338 348 351 353 381 386 387 397 409 410 419 420 428 430 453 460 461 473 478 493 494 500 741",
"output": "241"
},
{
"input": "10\n218 300 388 448 535 629 680 740 836 925",
"output": "111"
},
{
"input": "100\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996",
"output": "20"
},
{
"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 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000",
"output": "901"
},
{
"input": "100\n1 9 15 17 28 29 30 31 32 46 48 49 52 56 62 77 82 85 90 91 94 101 102 109 111 113 116 118 124 125 131 132 136 138 139 143 145 158 161 162 165 167 171 173 175 177 179 183 189 196 801 802 804 806 817 819 827 830 837 840 842 846 850 855 858 862 863 866 869 870 878 881 883 884 896 898 899 901 904 906 908 909 910 911 912 917 923 924 925 935 939 943 945 956 963 964 965 972 976 978",
"output": "605"
},
{
"input": "100\n2 43 47 49 50 57 59 67 74 98 901 903 904 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 938 939 940 942 943 944 945 946 947 948 949 950 952 953 954 956 957 958 959 960 961 962 963 965 966 967 968 969 970 971 972 973 974 975 976 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 998 999",
"output": "803"
},
{
"input": "72\n178 186 196 209 217 226 236 248 260 273 281 291 300 309 322 331 343 357 366 377 389 399 409 419 429 442 450 459 469 477 491 501 512 524 534 548 557 568 582 593 602 616 630 643 652 660 670 679 693 707 715 728 737 750 759 768 776 789 797 807 815 827 837 849 863 873 881 890 901 910 920 932",
"output": "17"
},
{
"input": "38\n1 28 55 82 109 136 163 190 217 244 271 298 325 352 379 406 433 460 487 514 541 568 595 622 649 676 703 730 757 784 811 838 865 892 919 946 973 1000",
"output": "54"
},
{
"input": "28\n1 38 75 112 149 186 223 260 297 334 371 408 445 482 519 556 593 630 667 704 741 778 815 852 889 926 963 1000",
"output": "74"
}
] | 1,492,692,712 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 61 | 5,529,600 | n = int(input())
l = list(map(lambda x: int(x), input().split()))
res = 1000
for i in range(1, n - 1):
d = l.pop(i)
m = 1
for j in range(0, n - 2):
m = max(l[j + 1] - l[j], m)
res = min(res, m)
l.insert(i, d)
print(res)
| Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold.
Input Specification:
The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one).
Output Specification:
Print a single number — the minimum difficulty of the track after removing a single hold.
Demo Input:
['3\n1 4 6\n', '5\n1 2 3 4 5\n', '5\n1 2 3 7 8\n']
Demo Output:
['5\n', '2\n', '4\n']
Note:
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4. | ```python
n = int(input())
l = list(map(lambda x: int(x), input().split()))
res = 1000
for i in range(1, n - 1):
d = l.pop(i)
m = 1
for j in range(0, n - 2):
m = max(l[j + 1] - l[j], m)
res = min(res, m)
l.insert(i, d)
print(res)
``` | 3 |
|
746 | D | Green and Black Tea | PROGRAMMING | 1,500 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | Innokentiy likes tea very much and today he wants to drink exactly *n* cups of tea. He would be happy to drink more but he had exactly *n* tea bags, *a* of them are green and *b* are black.
Innokentiy doesn't like to drink the same tea (green or black) more than *k* times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink *n* cups of tea, without drinking the same tea more than *k* times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once. | The first line contains four integers *n*, *k*, *a* and *b* (1<=≤<=*k*<=≤<=*n*<=≤<=105, 0<=≤<=*a*,<=*b*<=≤<=*n*) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that *a*<=+<=*b*<==<=*n*. | If it is impossible to drink *n* cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length *n*, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.
If there are multiple answers, print any of them. | [
"5 1 3 2\n",
"7 2 2 5\n",
"4 3 4 0\n"
] | [
"GBGBG\n",
"BBGBGBB",
"NO\n"
] | none | 2,000 | [
{
"input": "5 1 3 2",
"output": "GBGBG"
},
{
"input": "7 2 2 5",
"output": "BBGBBGB"
},
{
"input": "4 3 4 0",
"output": "NO"
},
{
"input": "2 2 0 2",
"output": "BB"
},
{
"input": "3 2 0 3",
"output": "NO"
},
{
"input": "1 1 0 1",
"output": "B"
},
{
"input": "1 1 1 0",
"output": "G"
},
{
"input": "11 2 3 8",
"output": "BBGBBGBBGBB"
},
{
"input": "100000 39 24855 75145",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "2 2 2 0",
"output": "GG"
},
{
"input": "2 2 1 1",
"output": "GB"
},
{
"input": "3 2 2 1",
"output": "GGB"
},
{
"input": "3 2 1 2",
"output": "BBG"
},
{
"input": "5 1 4 1",
"output": "NO"
},
{
"input": "10 1 7 3",
"output": "NO"
},
{
"input": "20 1 5 15",
"output": "NO"
},
{
"input": "1000 123 447 553",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB..."
},
{
"input": "3000 70 2946 54",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGG..."
},
{
"input": "10000 590 4020 5980",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "10001 1841 1052 8949",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "50000 104 31045 18955",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "59999 16660 46835 13164",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "70000 3017 31589 38411",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "99999 15805 82842 17157",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "100000 6397 59122 40878",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "100000 856 69042 30958",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "6 1 3 3",
"output": "GBGBGB"
},
{
"input": "9 2 3 6",
"output": "BBGBBGBBG"
},
{
"input": "9 1 6 3",
"output": "NO"
},
{
"input": "10 1 4 6",
"output": "NO"
},
{
"input": "10 1 3 7",
"output": "NO"
},
{
"input": "10 1 2 8",
"output": "NO"
},
{
"input": "10 1 5 5",
"output": "GBGBGBGBGB"
},
{
"input": "11 1 2 9",
"output": "NO"
},
{
"input": "11 2 4 7",
"output": "BBGBBGBBGBG"
},
{
"input": "11 2 5 6",
"output": "BBGBGBGBGBG"
},
{
"input": "11 2 6 5",
"output": "GGBGBGBGBGB"
},
{
"input": "11 1 7 4",
"output": "NO"
},
{
"input": "11 2 8 3",
"output": "GGBGGBGGBGG"
},
{
"input": "11 1 9 2",
"output": "NO"
},
{
"input": "99999 10760 33333 66666",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "99999 3434 66666 33333",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "99999 7343 33332 66667",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "99999 177 33334 66665",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "99999 3580 66665 33334",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "99999 1681 66667 33332",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "7 3 2 5",
"output": "BBBGBBG"
},
{
"input": "9 2 7 2",
"output": "NO"
},
{
"input": "10 2 8 2",
"output": "NO"
},
{
"input": "100000 50000 50000 50000",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBG..."
}
] | 1,630,861,153 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 140 | 25,702,400 | from collections import deque
n,k,a,b = map(int,input().split())
ka = a
kb = b
# GB
l = []
for i in range(n):
if a > 0 and b > 0:
if i%2 == 0:
l.append("G")
a -= 1
else:
l.append("B")
b -= 1
stack = []
if a > 0:
i = 0
while i < len(l):
if l[i] == "G":
stack.append("G")
cnt = 0
while cnt < k-1 and a > 0:
cnt += 1
a -= 1
stack.append("G")
else:
stack.append("B")
i += 1
if len(stack) > 0:
if stack[-1] == "B":
cnt = 0
while cnt < k and a > 0:
cnt += 1
a -= 1
stack.append("G")
if b > 0:
cnt = 0
while cnt < k and b > 0:
cnt += 1
b -= 1
stack.append("B")
i = 0
while i < len(l):
if l[i] == "G":
stack.append("G")
else:
stack.append("B")
cnt = 0
while cnt < k-1 and b > 0:
cnt += 1
b -= 1
stack.append("B")
i += 1
if len(stack) > 0:
if stack[-1] == "G":
cnt = 0
while cnt < k and b > 0:
cnt += 1
b -= 1
stack.append("B")
if len(stack) == n:
print("".join(stack))
exit()
# BG
l = []
for i in range(n):
if a > 0 and b > 0:
if i % 2 == 0:
l.append("B")
a -= 1
else:
l.append("G")
b -= 1
stack = []
if a > 0:
cnt = 0
while cnt < k and a > 0:
cnt += 1
a -= 1
stack.append("G")
i = 0
while i < len(l):
if l[i] == "G":
stack.append("G")
cnt = 0
while cnt < k - 1 and a > 0:
cnt += 1
a -= 1
stack.append("G")
else:
stack.append("B")
i += 1
if len(stack) > 0:
if stack[-1] == "B":
cnt = 0
while cnt < k and a > 0:
cnt += 1
a -= 1
stack.append("G")
if b > 0:
cnt = 0
while cnt < k and b > 0:
cnt += 1
b -= 1
stack.append("B")
i = 0
while i < len(l):
if l[i] == "G":
stack.append("G")
else:
stack.append("B")
cnt = 0
while cnt < k - 1 and b > 0:
cnt += 1
b -= 1
stack.append("B")
i += 1
if len(stack) > 0:
if stack[-1] == "G":
cnt = 0
while cnt < k and b > 0:
cnt += 1
b -= 1
stack.append("B")
if len(stack) == n:
print("".join(stack))
exit()
print("NO") | Title: Green and Black Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy likes tea very much and today he wants to drink exactly *n* cups of tea. He would be happy to drink more but he had exactly *n* tea bags, *a* of them are green and *b* are black.
Innokentiy doesn't like to drink the same tea (green or black) more than *k* times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink *n* cups of tea, without drinking the same tea more than *k* times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
Input Specification:
The first line contains four integers *n*, *k*, *a* and *b* (1<=≤<=*k*<=≤<=*n*<=≤<=105, 0<=≤<=*a*,<=*b*<=≤<=*n*) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that *a*<=+<=*b*<==<=*n*.
Output Specification:
If it is impossible to drink *n* cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length *n*, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.
If there are multiple answers, print any of them.
Demo Input:
['5 1 3 2\n', '7 2 2 5\n', '4 3 4 0\n']
Demo Output:
['GBGBG\n', 'BBGBGBB', 'NO\n']
Note:
none | ```python
from collections import deque
n,k,a,b = map(int,input().split())
ka = a
kb = b
# GB
l = []
for i in range(n):
if a > 0 and b > 0:
if i%2 == 0:
l.append("G")
a -= 1
else:
l.append("B")
b -= 1
stack = []
if a > 0:
i = 0
while i < len(l):
if l[i] == "G":
stack.append("G")
cnt = 0
while cnt < k-1 and a > 0:
cnt += 1
a -= 1
stack.append("G")
else:
stack.append("B")
i += 1
if len(stack) > 0:
if stack[-1] == "B":
cnt = 0
while cnt < k and a > 0:
cnt += 1
a -= 1
stack.append("G")
if b > 0:
cnt = 0
while cnt < k and b > 0:
cnt += 1
b -= 1
stack.append("B")
i = 0
while i < len(l):
if l[i] == "G":
stack.append("G")
else:
stack.append("B")
cnt = 0
while cnt < k-1 and b > 0:
cnt += 1
b -= 1
stack.append("B")
i += 1
if len(stack) > 0:
if stack[-1] == "G":
cnt = 0
while cnt < k and b > 0:
cnt += 1
b -= 1
stack.append("B")
if len(stack) == n:
print("".join(stack))
exit()
# BG
l = []
for i in range(n):
if a > 0 and b > 0:
if i % 2 == 0:
l.append("B")
a -= 1
else:
l.append("G")
b -= 1
stack = []
if a > 0:
cnt = 0
while cnt < k and a > 0:
cnt += 1
a -= 1
stack.append("G")
i = 0
while i < len(l):
if l[i] == "G":
stack.append("G")
cnt = 0
while cnt < k - 1 and a > 0:
cnt += 1
a -= 1
stack.append("G")
else:
stack.append("B")
i += 1
if len(stack) > 0:
if stack[-1] == "B":
cnt = 0
while cnt < k and a > 0:
cnt += 1
a -= 1
stack.append("G")
if b > 0:
cnt = 0
while cnt < k and b > 0:
cnt += 1
b -= 1
stack.append("B")
i = 0
while i < len(l):
if l[i] == "G":
stack.append("G")
else:
stack.append("B")
cnt = 0
while cnt < k - 1 and b > 0:
cnt += 1
b -= 1
stack.append("B")
i += 1
if len(stack) > 0:
if stack[-1] == "G":
cnt = 0
while cnt < k and b > 0:
cnt += 1
b -= 1
stack.append("B")
if len(stack) == n:
print("".join(stack))
exit()
print("NO")
``` | 3 |
|
195 | A | Let's Watch Football | PROGRAMMING | 1,000 | [
"binary search",
"brute force",
"math"
] | null | null | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the size of downloaded data per second.
The guys want to watch the whole video without any pauses, so they have to wait some integer number of seconds for a part of the video to download. After this number of seconds passes, they can start watching. Waiting for the whole video to download isn't necessary as the video can download after the guys started to watch.
Let's suppose that video's length is *c* seconds and Valeric and Valerko wait *t* seconds before the watching. Then for any moment of time *t*0, *t*<=≤<=*t*0<=≤<=*c*<=+<=*t*, the following condition must fulfill: the size of data received in *t*0 seconds is not less than the size of data needed to watch *t*0<=-<=*t* seconds of the video.
Of course, the guys want to wait as little as possible, so your task is to find the minimum integer number of seconds to wait before turning the video on. The guys must watch the video without pauses. | The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=1000,<=*a*<=><=*b*). The first number (*a*) denotes the size of data needed to watch one second of the video. The second number (*b*) denotes the size of data Valeric and Valerko can download from the Net per second. The third number (*c*) denotes the video's length in seconds. | Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses. | [
"4 1 1\n",
"10 3 2\n",
"13 12 1\n"
] | [
"3\n",
"5\n",
"1\n"
] | In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 · 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watching video 1 second, one unit of data will be downloaded and Valerik and Valerko will have 4 units of data by the end of watching. Also every moment till the end of video guys will have more data then necessary for watching.
In the second sample guys need 2 · 10 = 20 units of data, so they have to wait 5 seconds and after that they will have 20 units before the second second ends. However, if guys wait 4 seconds, they will be able to watch first second of video without pauses, but they will download 18 units of data by the end of second second and it is less then necessary. | 500 | [
{
"input": "4 1 1",
"output": "3"
},
{
"input": "10 3 2",
"output": "5"
},
{
"input": "13 12 1",
"output": "1"
},
{
"input": "2 1 3",
"output": "3"
},
{
"input": "6 2 4",
"output": "8"
},
{
"input": "5 2 1",
"output": "2"
},
{
"input": "2 1 1",
"output": "1"
},
{
"input": "2 1 4",
"output": "4"
},
{
"input": "5 1 5",
"output": "20"
},
{
"input": "2 1 2",
"output": "2"
},
{
"input": "60 16 1",
"output": "3"
},
{
"input": "64 12 8",
"output": "35"
},
{
"input": "66 38 4",
"output": "3"
},
{
"input": "70 32 1",
"output": "2"
},
{
"input": "24 12 12",
"output": "12"
},
{
"input": "24 19 9",
"output": "3"
},
{
"input": "244 87 4",
"output": "8"
},
{
"input": "305 203 421",
"output": "212"
},
{
"input": "888 777 1",
"output": "1"
},
{
"input": "888 777 1000",
"output": "143"
},
{
"input": "888 777 888",
"output": "127"
},
{
"input": "5 4 10",
"output": "3"
},
{
"input": "1000 1 1",
"output": "999"
},
{
"input": "1000 1 1000",
"output": "999000"
},
{
"input": "1000 999 1",
"output": "1"
},
{
"input": "1000 999 1000",
"output": "2"
},
{
"input": "945 812 917",
"output": "151"
},
{
"input": "993 992 991",
"output": "1"
},
{
"input": "17 7 10",
"output": "15"
},
{
"input": "17 10 7",
"output": "5"
},
{
"input": "500 300 300",
"output": "200"
},
{
"input": "196 169 144",
"output": "24"
},
{
"input": "7 3 200",
"output": "267"
},
{
"input": "9 3 300",
"output": "600"
},
{
"input": "561 31 917",
"output": "15678"
},
{
"input": "100 10 1",
"output": "9"
},
{
"input": "1000 100 10",
"output": "90"
},
{
"input": "18 14 10",
"output": "3"
},
{
"input": "93 74 831",
"output": "214"
},
{
"input": "960 935 994",
"output": "27"
},
{
"input": "894 1 999",
"output": "892107"
},
{
"input": "767 2 514",
"output": "196605"
},
{
"input": "765 123 45",
"output": "235"
},
{
"input": "1000 1 1000",
"output": "999000"
},
{
"input": "765 123 899",
"output": "4693"
},
{
"input": "759 10 258",
"output": "19325"
},
{
"input": "100 1 10",
"output": "990"
},
{
"input": "99 8 99",
"output": "1127"
},
{
"input": "27 26 1",
"output": "1"
}
] | 1,644,777,161 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 30 | 186 | 0 | import math
def main():
a, b, c = list(map(int, input().split()))
print(max(math.ceil(c * (a / b - 1)), 0))
if __name__ == "__main__":
main()
| Title: Let's Watch Football
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the size of downloaded data per second.
The guys want to watch the whole video without any pauses, so they have to wait some integer number of seconds for a part of the video to download. After this number of seconds passes, they can start watching. Waiting for the whole video to download isn't necessary as the video can download after the guys started to watch.
Let's suppose that video's length is *c* seconds and Valeric and Valerko wait *t* seconds before the watching. Then for any moment of time *t*0, *t*<=≤<=*t*0<=≤<=*c*<=+<=*t*, the following condition must fulfill: the size of data received in *t*0 seconds is not less than the size of data needed to watch *t*0<=-<=*t* seconds of the video.
Of course, the guys want to wait as little as possible, so your task is to find the minimum integer number of seconds to wait before turning the video on. The guys must watch the video without pauses.
Input Specification:
The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=1000,<=*a*<=><=*b*). The first number (*a*) denotes the size of data needed to watch one second of the video. The second number (*b*) denotes the size of data Valeric and Valerko can download from the Net per second. The third number (*c*) denotes the video's length in seconds.
Output Specification:
Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses.
Demo Input:
['4 1 1\n', '10 3 2\n', '13 12 1\n']
Demo Output:
['3\n', '5\n', '1\n']
Note:
In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 · 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watching video 1 second, one unit of data will be downloaded and Valerik and Valerko will have 4 units of data by the end of watching. Also every moment till the end of video guys will have more data then necessary for watching.
In the second sample guys need 2 · 10 = 20 units of data, so they have to wait 5 seconds and after that they will have 20 units before the second second ends. However, if guys wait 4 seconds, they will be able to watch first second of video without pauses, but they will download 18 units of data by the end of second second and it is less then necessary. | ```python
import math
def main():
a, b, c = list(map(int, input().split()))
print(max(math.ceil(c * (a / b - 1)), 0))
if __name__ == "__main__":
main()
``` | 0 |
|
376 | A | Lever | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | You have a description of a lever as string *s*. We'll represent the string length as record |*s*|, then the lever looks as a horizontal bar with weights of length |*s*|<=-<=1 with exactly one pivot. We will assume that the bar is a segment on the *Ox* axis between points 0 and |*s*|<=-<=1.
The decoding of the lever description is given below.
- If the *i*-th character of the string equals "^", that means that at coordinate *i* there is the pivot under the bar. - If the *i*-th character of the string equals "=", that means that at coordinate *i* there is nothing lying on the bar. - If the *i*-th character of the string equals digit *c* (1-9), that means that at coordinate *i* there is a weight of mass *c* on the bar.
Your task is, given the lever description, print if it will be in balance or not. Assume that the bar doesn't weight anything. Assume that the bar initially is in balance then all weights are simultaneously put on it. After that the bar either tilts to the left, or tilts to the right, or is in balance. | The first line contains the lever description as a non-empty string *s* (3<=≤<=|*s*|<=≤<=106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar.
To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs. | Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance. | [
"=^==\n",
"9===^==1\n",
"2==^7==\n",
"41^52==\n"
] | [
"balance\n",
"left\n",
"right\n",
"balance\n"
] | As you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever.
The pictures to the examples: | 500 | [
{
"input": "=^==",
"output": "balance"
},
{
"input": "9===^==1",
"output": "left"
},
{
"input": "2==^7==",
"output": "right"
},
{
"input": "41^52==",
"output": "balance"
},
{
"input": "=^2=4=1===1=",
"output": "right"
},
{
"input": "9=6===5==3=9=1=1^7=1==",
"output": "left"
},
{
"input": "85=61=36=^93===4==44==35==94===39===15===",
"output": "right"
},
{
"input": "==88=^95==83=45===8====73===7==7====1=29====29=8=85=",
"output": "right"
},
{
"input": "==41^52==",
"output": "balance"
},
{
"input": "2===================^2",
"output": "left"
},
{
"input": "9^=============1",
"output": "right"
},
{
"input": "4=========^=55",
"output": "left"
},
{
"input": "123^321",
"output": "balance"
},
{
"input": "7^1=2",
"output": "balance"
},
{
"input": "589==^==958",
"output": "right"
}
] | 1,511,108,580 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 795 | 8,704,000 | string = input()
pivot = string.index("^")
#print(pivot)
sm = 0
for index in range(0,len(string)):
if (string[index:index+1] != "^" and string[index:index+1] != "="):
sm += (pivot-index)*int(string[index:index+1])
#print(sm)
if sm < 0:
print("right")
elif sm > 0:
print("left")
else:
print("balance") | Title: Lever
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a description of a lever as string *s*. We'll represent the string length as record |*s*|, then the lever looks as a horizontal bar with weights of length |*s*|<=-<=1 with exactly one pivot. We will assume that the bar is a segment on the *Ox* axis between points 0 and |*s*|<=-<=1.
The decoding of the lever description is given below.
- If the *i*-th character of the string equals "^", that means that at coordinate *i* there is the pivot under the bar. - If the *i*-th character of the string equals "=", that means that at coordinate *i* there is nothing lying on the bar. - If the *i*-th character of the string equals digit *c* (1-9), that means that at coordinate *i* there is a weight of mass *c* on the bar.
Your task is, given the lever description, print if it will be in balance or not. Assume that the bar doesn't weight anything. Assume that the bar initially is in balance then all weights are simultaneously put on it. After that the bar either tilts to the left, or tilts to the right, or is in balance.
Input Specification:
The first line contains the lever description as a non-empty string *s* (3<=≤<=|*s*|<=≤<=106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar.
To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs.
Output Specification:
Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance.
Demo Input:
['=^==\n', '9===^==1\n', '2==^7==\n', '41^52==\n']
Demo Output:
['balance\n', 'left\n', 'right\n', 'balance\n']
Note:
As you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever.
The pictures to the examples: | ```python
string = input()
pivot = string.index("^")
#print(pivot)
sm = 0
for index in range(0,len(string)):
if (string[index:index+1] != "^" and string[index:index+1] != "="):
sm += (pivot-index)*int(string[index:index+1])
#print(sm)
if sm < 0:
print("right")
elif sm > 0:
print("left")
else:
print("balance")
``` | 3 |
|
614 | A | Link/Cut Tree | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers *l*, *r* and *k*, you need to print all powers of number *k* within range from *l* to *r* inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him! | The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). | Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). | [
"1 10 2\n",
"2 4 5\n"
] | [
"1 2 4 8 ",
"-1"
] | Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | 500 | [
{
"input": "1 10 2",
"output": "1 2 4 8 "
},
{
"input": "2 4 5",
"output": "-1"
},
{
"input": "18102 43332383920 28554",
"output": "28554 815330916 "
},
{
"input": "19562 31702689720 17701",
"output": "313325401 "
},
{
"input": "11729 55221128400 313",
"output": "97969 30664297 9597924961 "
},
{
"input": "5482 100347128000 342",
"output": "116964 40001688 13680577296 "
},
{
"input": "3680 37745933600 10",
"output": "10000 100000 1000000 10000000 100000000 1000000000 10000000000 "
},
{
"input": "17098 191120104800 43",
"output": "79507 3418801 147008443 6321363049 "
},
{
"input": "10462 418807699200 2",
"output": "16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 "
},
{
"input": "30061 641846400000 3",
"output": "59049 177147 531441 1594323 4782969 14348907 43046721 129140163 387420489 1162261467 3486784401 10460353203 31381059609 94143178827 282429536481 "
},
{
"input": "1 1000000000000000000 2",
"output": "1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888 1099511627776 2199023255552 4398046511104 8796093022208 17592186044416 35184372088832 70368744177664 140737488355328 281474976710656 562949953421312 1125899906842624 2251799813685248 4503599627370496 900719925474099..."
},
{
"input": "32 2498039712000 4",
"output": "64 256 1024 4096 16384 65536 262144 1048576 4194304 16777216 67108864 268435456 1073741824 4294967296 17179869184 68719476736 274877906944 1099511627776 "
},
{
"input": "1 2576683920000 2",
"output": "1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888 1099511627776 2199023255552 "
},
{
"input": "5 25 5",
"output": "5 25 "
},
{
"input": "1 90 90",
"output": "1 90 "
},
{
"input": "95 2200128528000 68",
"output": "4624 314432 21381376 1453933568 98867482624 "
},
{
"input": "64 426314644000 53",
"output": "2809 148877 7890481 418195493 22164361129 "
},
{
"input": "198765 198765 198765",
"output": "198765 "
},
{
"input": "42 2845016496000 12",
"output": "144 1728 20736 248832 2985984 35831808 429981696 5159780352 61917364224 743008370688 "
},
{
"input": "6 6 3",
"output": "-1"
},
{
"input": "1 10 11",
"output": "1 "
},
{
"input": "2 10 11",
"output": "-1"
},
{
"input": "87 160 41",
"output": "-1"
},
{
"input": "237171123124584251 923523399718980912 7150",
"output": "-1"
},
{
"input": "101021572000739548 453766043506276015 8898",
"output": "-1"
},
{
"input": "366070689449360724 928290634811046396 8230",
"output": "-1"
},
{
"input": "438133886369772308 942612870269666780 7193",
"output": "-1"
},
{
"input": "10 10 10",
"output": "10 "
},
{
"input": "16 16 256",
"output": "-1"
},
{
"input": "1 1000000000000000000 1000000000",
"output": "1 1000000000 1000000000000000000 "
},
{
"input": "1000000000000000000 1000000000000000000 1000000000",
"output": "1000000000000000000 "
},
{
"input": "1000000000 1000000000000000000 1000000000",
"output": "1000000000 1000000000000000000 "
},
{
"input": "1 1 4",
"output": "1 "
},
{
"input": "1 999999999999999999 1000000000",
"output": "1 1000000000 "
},
{
"input": "1 1000000000000000000 999999990",
"output": "1 999999990 999999980000000100 "
},
{
"input": "1 1000000000000000000 999999984",
"output": "1 999999984 999999968000000256 "
},
{
"input": "1 1000000000000000000 324325",
"output": "1 324325 105186705625 34114678301828125 "
},
{
"input": "1 1000000000000000000 999999523",
"output": "1 999999523 999999046000227529 "
},
{
"input": "1 243 3",
"output": "1 3 9 27 81 243 "
},
{
"input": "62769392426654367 567152589733560993 688813",
"output": "326816522793383797 "
},
{
"input": "1 1000000000000000000 690852001",
"output": "1 690852001 477276487285704001 "
},
{
"input": "1 1000000000000000000 918745157",
"output": "1 918745157 844092663510954649 "
},
{
"input": "1 1000000000000000000 131299843",
"output": "1 131299843 17239648771824649 "
},
{
"input": "2861381721051425 2861381721051425 1234",
"output": "-1"
}
] | 1,562,750,607 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 7,782,400 | l,r,k=map(int,input().split())
ans=[]
j=0
for i in range(1,10000):
if l<=k**j<=r:
ans.append(k**j)
j+=1
if not ans:
print(-1)
else:
print(*ans) | Title: Link/Cut Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers *l*, *r* and *k*, you need to print all powers of number *k* within range from *l* to *r* inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input Specification:
The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109).
Output Specification:
Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Demo Input:
['1 10 2\n', '2 4 5\n']
Demo Output:
['1 2 4 8 ', '-1']
Note:
Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | ```python
l,r,k=map(int,input().split())
ans=[]
j=0
for i in range(1,10000):
if l<=k**j<=r:
ans.append(k**j)
j+=1
if not ans:
print(-1)
else:
print(*ans)
``` | 0 |
|
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?
Please help Haruhi solve this problem. | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"input": "xulsyfkuizjauadjjopu",
"output": "526"
},
{
"input": "e",
"output": "51"
},
{
"input": "zv",
"output": "76"
},
{
"input": "jgv",
"output": "101"
},
{
"input": "zsfo",
"output": "126"
},
{
"input": "jselr",
"output": "151"
},
{
"input": "dwemig",
"output": "176"
},
{
"input": "mddoxsf",
"output": "201"
},
{
"input": "jgirkrmi",
"output": "226"
},
{
"input": "spkxurcum",
"output": "251"
},
{
"input": "fykkiubdkt",
"output": "276"
},
{
"input": "fznbcxsxygs",
"output": "301"
},
{
"input": "qcrvrdqcbtou",
"output": "326"
},
{
"input": "qktrbjzrqgmlr",
"output": "351"
},
{
"input": "foamodbvptlxxg",
"output": "376"
},
{
"input": "ydzpjhsidipricw",
"output": "401"
},
{
"input": "lpfpndmjfvqejdgf",
"output": "426"
},
{
"input": "ofkvparuvjtggnmab",
"output": "451"
},
{
"input": "xxncfutrtxcwdzwbgs",
"output": "476"
},
{
"input": "zovhffccflkgqncsdte",
"output": "501"
},
{
"input": "cskgsxywlvfeicoueglr",
"output": "526"
},
{
"input": "gggggggggggggggggggg",
"output": "526"
},
{
"input": "qdqdddqddqqddqddqdqd",
"output": "526"
},
{
"input": "takttttaakaaktakttkt",
"output": "526"
},
{
"input": "coccoooogogcgocccmcg",
"output": "526"
},
{
"input": "kskkskkkssksssk",
"output": "401"
},
{
"input": "lllllllllllllll",
"output": "401"
}
] | 1,623,898,775 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | l=input()
print((len(l)+1)*26-len(l)) | Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?
Please help Haruhi solve this problem.
Input Specification:
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters.
Output Specification:
Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.
Demo Input:
['a\n', 'hi\n']
Demo Output:
['51\n', '76\n']
Note:
In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | ```python
l=input()
print((len(l)+1)*26-len(l))
``` | 3 |
|
624 | A | Save Luke | PROGRAMMING | 800 | [
"math"
] | null | null | Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other with speed *v*1 and *v*2, respectively. Luke has width *d* and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive. | The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=<<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively. | Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"2 6 2 2\n",
"1 9 1 2\n"
] | [
"1.00000000000000000000\n",
"2.66666666666666650000\n"
] | In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.
In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In this case both presses move to his edges at the same time. | 500 | [
{
"input": "2 6 2 2",
"output": "1.00000000000000000000"
},
{
"input": "1 9 1 2",
"output": "2.66666666666666650000"
},
{
"input": "1 10000 1 1",
"output": "4999.50000000000000000000"
},
{
"input": "9999 10000 10000 10000",
"output": "0.00005000000000000000"
},
{
"input": "1023 2340 1029 3021",
"output": "0.32518518518518519000"
},
{
"input": "2173 2176 10000 9989",
"output": "0.00015008254539996998"
},
{
"input": "1 2 123 1",
"output": "0.00806451612903225780"
},
{
"input": "123 1242 12 312",
"output": "3.45370370370370370000"
},
{
"input": "2 9997 3 12",
"output": "666.33333333333337000000"
},
{
"input": "1 10000 10000 10000",
"output": "0.49995000000000001000"
},
{
"input": "3274 4728 888 4578",
"output": "0.26600804976216613000"
},
{
"input": "4600 9696 5634 8248",
"output": "0.36709407866301685000"
},
{
"input": "2255 7902 8891 429",
"output": "0.60590128755364803000"
},
{
"input": "6745 9881 2149 9907",
"output": "0.26011944260119441000"
},
{
"input": "4400 8021 6895 2089",
"output": "0.40304986642920748000"
},
{
"input": "5726 9082 7448 3054",
"output": "0.31955817939440107000"
},
{
"input": "3381 9769 4898 2532",
"output": "0.85975773889636609000"
},
{
"input": "1036 6259 5451 4713",
"output": "0.51387249114521838000"
},
{
"input": "5526 6455 197 4191",
"output": "0.21171376481312670000"
},
{
"input": "1196 4082 4071 9971",
"output": "0.20552627830793335000"
},
{
"input": "8850 9921 8816 9449",
"output": "0.05863673692855187600"
},
{
"input": "3341 7299 2074 8927",
"output": "0.35978547404781386000"
},
{
"input": "7831 8609 6820 2596",
"output": "0.08262531860662701600"
},
{
"input": "2322 7212 77 4778",
"output": "1.00720906282183310000"
},
{
"input": "9976 9996 4823 4255",
"output": "0.00220312844238819110"
},
{
"input": "7631 9769 5377 6437",
"output": "0.18097172845776197000"
},
{
"input": "8957 9525 8634 107",
"output": "0.06498112344125385500"
},
{
"input": "6612 9565 3380 2288",
"output": "0.52099505998588569000"
},
{
"input": "1103 6256 3934 9062",
"output": "0.39650661742074483000"
},
{
"input": "1854 3280 1481 2140",
"output": "0.39381386357359843000"
}
] | 1,457,973,018 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 62 | 0 | n=input().split()
a=int(n[0])
b=int(n[1])
c=int(n[2])
k=int(n[3])
print(float((b-a)/(c+k)))
| Title: Save Luke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other with speed *v*1 and *v*2, respectively. Luke has width *d* and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.
Input Specification:
The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=<<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively.
Output Specification:
Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
Demo Input:
['2 6 2 2\n', '1 9 1 2\n']
Demo Output:
['1.00000000000000000000\n', '2.66666666666666650000\n']
Note:
In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.
In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In this case both presses move to his edges at the same time. | ```python
n=input().split()
a=int(n[0])
b=int(n[1])
c=int(n[2])
k=int(n[3])
print(float((b-a)/(c+k)))
``` | 3 |
|
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining. | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
"input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46",
"output": "46 0"
},
{
"input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100",
"output": "700 0"
},
{
"input": "1 0\n- 526403222",
"output": "0 1"
},
{
"input": "1 897986543\n- 371188251",
"output": "526798292 0"
},
{
"input": "1 0\n+ 1",
"output": "1 0"
},
{
"input": "1 0\n- 1",
"output": "0 1"
},
{
"input": "1 10\n+ 10",
"output": "20 0"
},
{
"input": "1 3\n- 5",
"output": "3 1"
},
{
"input": "1 0\n- 5",
"output": "0 1"
},
{
"input": "1 0\n+ 5",
"output": "5 0"
}
] | 1,670,544,749 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | x = input()
d =input()
kids =0 ;
for i in range(x):
s=input()
ord = input()
if s =="+":
d+=1 ;
else:
if ord > d :
kids+=1
else:
d-=ord
print(d+" "+ kids)
| Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input Specification:
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place.
Output Specification:
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
Demo Input:
['5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n', '5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n']
Demo Output:
['22 1\n', '3 2\n']
Note:
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining. | ```python
x = input()
d =input()
kids =0 ;
for i in range(x):
s=input()
ord = input()
if s =="+":
d+=1 ;
else:
if ord > d :
kids+=1
else:
d-=ord
print(d+" "+ kids)
``` | -1 |
|
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.
For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.
To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true. | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.
In the third sample, we need to flip the second and fourth cards. | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01234567890123456789012345678901234567890123456789",
"output": "25"
},
{
"input": "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb",
"output": "10"
},
{
"input": "cjw2dwmr10pku4yxohe0wglktd",
"output": "4"
},
{
"input": "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6",
"output": "13"
},
{
"input": "kaq7jyialrfp4ilkni90eq8v3amcbygon7py0hb8z26fbl8ss1",
"output": "13"
},
{
"input": "hpwn50zgbmct80k9rizjqg40nycgs0acwikjqt11nr6m61krfs",
"output": "8"
},
{
"input": "l3rw91a4m25l8iytxyeuixsegzcbm4h41ornf3pixkrmwznrzc",
"output": "14"
},
{
"input": "2222",
"output": "0"
},
{
"input": "13579",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "0",
"output": "0"
},
{
"input": "a",
"output": "1"
},
{
"input": "y",
"output": "0"
},
{
"input": "w",
"output": "0"
},
{
"input": "oo",
"output": "2"
},
{
"input": "oy",
"output": "1"
},
{
"input": "yo",
"output": "1"
},
{
"input": "yy",
"output": "0"
},
{
"input": "a0",
"output": "1"
},
{
"input": "a9",
"output": "2"
},
{
"input": "y0",
"output": "0"
},
{
"input": "y7",
"output": "1"
},
{
"input": "0a",
"output": "1"
},
{
"input": "3a",
"output": "2"
},
{
"input": "06",
"output": "0"
},
{
"input": "07",
"output": "1"
},
{
"input": "70",
"output": "1"
},
{
"input": "77",
"output": "2"
},
{
"input": "13570",
"output": "4"
},
{
"input": "0000000000011111",
"output": "5"
},
{
"input": "1357",
"output": "4"
},
{
"input": "uuuuuuuuuuuuuuuuuu",
"output": "18"
},
{
"input": "gabieurat",
"output": "5"
}
] | 1,572,058,419 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 109 | 0 | s=input()
count=0
for i in range(len(s)):
if s[i]=="a" or s[i]=="e" or s[i]=="o" or s[i]=="i" or s[i]=="u" or s[i]=="1" or s[i]=="3" or s[i]=="5" or s[i]=="7" or s[i]=="9":
count=count+1
print(count)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.
For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.
To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.
Input Specification:
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Output Specification:
Print a single integer, the minimum number of cards you must turn over to verify your claim.
Demo Input:
['ee\n', 'z\n', '0ay1\n']
Demo Output:
['2\n', '0\n', '2\n']
Note:
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.
In the third sample, we need to flip the second and fourth cards. | ```python
s=input()
count=0
for i in range(len(s)):
if s[i]=="a" or s[i]=="e" or s[i]=="o" or s[i]=="i" or s[i]=="u" or s[i]=="1" or s[i]=="3" or s[i]=="5" or s[i]=="7" or s[i]=="9":
count=count+1
print(count)
``` | 3 |
|
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold. | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one). | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4. | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9 16 25 36 49 64 81 100",
"output": "19"
},
{
"input": "10\n300 315 325 338 350 365 379 391 404 416",
"output": "23"
},
{
"input": "15\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112",
"output": "2"
},
{
"input": "60\n3 5 7 8 15 16 18 21 24 26 40 41 43 47 48 49 50 51 52 54 55 60 62 71 74 84 85 89 91 96 406 407 409 412 417 420 423 424 428 431 432 433 436 441 445 446 447 455 458 467 469 471 472 475 480 485 492 493 497 500",
"output": "310"
},
{
"input": "3\n159 282 405",
"output": "246"
},
{
"input": "81\n6 7 22 23 27 38 40 56 59 71 72 78 80 83 86 92 95 96 101 122 125 127 130 134 154 169 170 171 172 174 177 182 184 187 195 197 210 211 217 223 241 249 252 253 256 261 265 269 274 277 291 292 297 298 299 300 302 318 338 348 351 353 381 386 387 397 409 410 419 420 428 430 453 460 461 473 478 493 494 500 741",
"output": "241"
},
{
"input": "10\n218 300 388 448 535 629 680 740 836 925",
"output": "111"
},
{
"input": "100\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996",
"output": "20"
},
{
"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 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000",
"output": "901"
},
{
"input": "100\n1 9 15 17 28 29 30 31 32 46 48 49 52 56 62 77 82 85 90 91 94 101 102 109 111 113 116 118 124 125 131 132 136 138 139 143 145 158 161 162 165 167 171 173 175 177 179 183 189 196 801 802 804 806 817 819 827 830 837 840 842 846 850 855 858 862 863 866 869 870 878 881 883 884 896 898 899 901 904 906 908 909 910 911 912 917 923 924 925 935 939 943 945 956 963 964 965 972 976 978",
"output": "605"
},
{
"input": "100\n2 43 47 49 50 57 59 67 74 98 901 903 904 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 938 939 940 942 943 944 945 946 947 948 949 950 952 953 954 956 957 958 959 960 961 962 963 965 966 967 968 969 970 971 972 973 974 975 976 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 998 999",
"output": "803"
},
{
"input": "72\n178 186 196 209 217 226 236 248 260 273 281 291 300 309 322 331 343 357 366 377 389 399 409 419 429 442 450 459 469 477 491 501 512 524 534 548 557 568 582 593 602 616 630 643 652 660 670 679 693 707 715 728 737 750 759 768 776 789 797 807 815 827 837 849 863 873 881 890 901 910 920 932",
"output": "17"
},
{
"input": "38\n1 28 55 82 109 136 163 190 217 244 271 298 325 352 379 406 433 460 487 514 541 568 595 622 649 676 703 730 757 784 811 838 865 892 919 946 973 1000",
"output": "54"
},
{
"input": "28\n1 38 75 112 149 186 223 260 297 334 371 408 445 482 519 556 593 630 667 704 741 778 815 852 889 926 963 1000",
"output": "74"
}
] | 1,418,840,917 | 7,117 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 46 | 0 | n=int(input())
height1=input('').split()
L=[]
for i in range(1,n-1):
height1=height
del height1[i]
dx=int(height1[1])-int(height1[0])
for a in range(1,i-1):
dn=int(height1[a+1])-int(height1[a])
if dx<dn:
dx=dn
L.append(dx)
print(L)
| Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold.
Input Specification:
The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one).
Output Specification:
Print a single number — the minimum difficulty of the track after removing a single hold.
Demo Input:
['3\n1 4 6\n', '5\n1 2 3 4 5\n', '5\n1 2 3 7 8\n']
Demo Output:
['5\n', '2\n', '4\n']
Note:
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4. | ```python
n=int(input())
height1=input('').split()
L=[]
for i in range(1,n-1):
height1=height
del height1[i]
dx=int(height1[1])-int(height1[0])
for a in range(1,i-1):
dn=int(height1[a+1])-int(height1[a])
if dx<dn:
dx=dn
L.append(dx)
print(L)
``` | -1 |
|
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0. | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "1\n1 2 3"
},
{
"input": "12\n3 3 3 3 3 3 3 3 1 3 3 2",
"output": "1\n9 12 2"
},
{
"input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2",
"output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47"
},
{
"input": "12\n3 1 1 1 1 1 1 2 1 1 1 1",
"output": "1\n3 8 1"
},
{
"input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2",
"output": "1\n18 2 11"
},
{
"input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3",
"output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36"
},
{
"input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1",
"output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200"
},
{
"input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3",
"output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64"
},
{
"input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1",
"output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44"
},
{
"input": "5\n1 2 2 3 3",
"output": "1\n1 3 4"
}
] | 1,698,679,645 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 307,200 | n = int(input())
lst = list(map(int, input().split(" ")))
one = []
two = []
three = []
for i in range(n):
if lst[i] == 1:
one.append(i)
elif lst[i] == 2:
two.append(i)
elif lst[i] == 3:
three.append(i)
a = len(one)
b = len(two)
c = len(three)
if a < b and a < c:
mx = a
elif b < c:
mx = b
else:
mx = c
"""print(one)
print(two)
print(three)"""
print(mx)
for i in range(mx):
print(one[i]+1, two[i]+1, three[i]+1)
| Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
Output Specification:
In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0.
Demo Input:
['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n']
Demo Output:
['2\n3 5 2\n6 7 4\n', '0\n']
Note:
none | ```python
n = int(input())
lst = list(map(int, input().split(" ")))
one = []
two = []
three = []
for i in range(n):
if lst[i] == 1:
one.append(i)
elif lst[i] == 2:
two.append(i)
elif lst[i] == 3:
three.append(i)
a = len(one)
b = len(two)
c = len(three)
if a < b and a < c:
mx = a
elif b < c:
mx = b
else:
mx = c
"""print(one)
print(two)
print(three)"""
print(mx)
for i in range(mx):
print(one[i]+1, two[i]+1, three[i]+1)
``` | 3 |
|
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change. | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
"output": "1"
},
{
"input": "1000 9",
"output": "1"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "999 9",
"output": "1"
},
{
"input": "999 8",
"output": "2"
},
{
"input": "105 6",
"output": "2"
},
{
"input": "403 9",
"output": "3"
},
{
"input": "546 4",
"output": "4"
},
{
"input": "228 9",
"output": "5"
},
{
"input": "57 2",
"output": "6"
},
{
"input": "437 9",
"output": "7"
},
{
"input": "997 6",
"output": "8"
},
{
"input": "109 1",
"output": "9"
},
{
"input": "998 9",
"output": "5"
},
{
"input": "4 2",
"output": "3"
},
{
"input": "9 3",
"output": "7"
},
{
"input": "8 2",
"output": "4"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "1 5",
"output": "5"
},
{
"input": "1 6",
"output": "6"
},
{
"input": "1 7",
"output": "7"
},
{
"input": "1 8",
"output": "8"
},
{
"input": "100 3",
"output": "1"
},
{
"input": "1000 2",
"output": "1"
},
{
"input": "1000 4",
"output": "1"
},
{
"input": "1000 5",
"output": "1"
},
{
"input": "1000 6",
"output": "1"
},
{
"input": "1000 7",
"output": "1"
},
{
"input": "1000 8",
"output": "1"
},
{
"input": "23 4",
"output": "8"
},
{
"input": "33 1",
"output": "7"
},
{
"input": "33 2",
"output": "4"
},
{
"input": "666 5",
"output": "5"
},
{
"input": "2 3",
"output": "5"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "12 4",
"output": "2"
},
{
"input": "15 5",
"output": "1"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "25 5",
"output": "1"
},
{
"input": "2 9",
"output": "5"
},
{
"input": "6 7",
"output": "5"
},
{
"input": "8 9",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "4 7",
"output": "5"
},
{
"input": "2 1",
"output": "5"
},
{
"input": "261 1",
"output": "1"
}
] | 1,695,658,897 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 1,000 | 0 | # LUOGU_RID: 126146637
a,b = map(int,input().split())
a = a%10
res = 1
while a!=b:
a = a*a%10
res+=1
print(res)
| Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
Input Specification:
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Output Specification:
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
Demo Input:
['117 3\n', '237 7\n', '15 2\n']
Demo Output:
['9\n', '1\n', '2\n']
Note:
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change. | ```python
# LUOGU_RID: 126146637
a,b = map(int,input().split())
a = a%10
res = 1
while a!=b:
a = a*a%10
res+=1
print(res)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this value is, the better the friendship is. No two friends have the same value *t**i*.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most *k* friends. If there are more than *k* friends online then the system displays only *k* best of them — those with biggest *t**i*.
Your task is to handle queries of two types:
- "1 id" — Friend *id* becomes online. It's guaranteed that he wasn't online before. - "2 id" — Check whether friend *id* is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type? | The first line contains three integers *n*, *k* and *q* (1<=≤<=*n*,<=*q*<=≤<=150<=000,<=1<=≤<=*k*<=≤<=*min*(6,<=*n*)) — the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=109) where *t**i* describes how good is Limak's relation with the *i*-th friend.
The *i*-th of the following *q* lines contains two integers *type**i* and *id**i* (1<=≤<=*type**i*<=≤<=2,<=1<=≤<=*id**i*<=≤<=*n*) — the *i*-th query. If *type**i*<==<=1 then a friend *id**i* becomes online. If *type**i*<==<=2 then you should check whether a friend *id**i* is displayed.
It's guaranteed that no two queries of the first type will have the same *id**i* becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (*type**i*<==<=2) so the output won't be empty. | For each query of the second type print one line with the answer — "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. | [
"4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n",
"6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n"
] | [
"NO\nYES\nNO\nYES\nYES\n",
"NO\nYES\nNO\nYES\n"
] | In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" — Friend 3 becomes online. 1. "2 4" — We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 1. "2 3" — We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 1. "1 1" — Friend 1 becomes online. The system now displays both friend 1 and friend 3. 1. "1 2" — Friend 2 becomes online. There are 3 friends online now but we were given *k* = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (*t*<sub class="lower-index">1</sub> < *t*<sub class="lower-index">2</sub>, *t*<sub class="lower-index">3</sub>) so friend 1 won't be displayed 1. "2 1" — Print "NO". 1. "2 2" — Print "YES". 1. "2 3" — Print "YES". | 0 | [
{
"input": "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3",
"output": "NO\nYES\nNO\nYES\nYES"
},
{
"input": "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3",
"output": "NO\nYES\nNO\nYES"
},
{
"input": "6 3 10\n62417580 78150524 410053501 582708235 630200761 760672946\n2 2\n1 5\n1 2\n1 4\n2 4\n2 1\n2 1\n1 6\n2 5\n2 6",
"output": "NO\nYES\nNO\nNO\nYES\nYES"
},
{
"input": "20 2 15\n12698951 55128070 116962690 156763505 188535242 194018601 269939893 428710623 442819431 483000923 516768937 552903993 633087286 656092270 671535141 714291344 717660646 846508634 879748146 937368929\n2 7\n1 2\n2 4\n1 19\n1 12\n1 5\n2 18\n2 11\n1 16\n2 1\n2 3\n2 19\n1 17\n2 9\n2 6",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO"
},
{
"input": "1 1 1\n1000000000\n2 1",
"output": "NO"
}
] | 1,462,784,215 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 4,608,000 | import sys
n,k,q=list(map(int,input().split()))
t=list(map(int,input().split()))
i=0
mark=[False for i in range(n+1)]
h=set([])
i=0
while i<q:
a=sys.stdin.readline()
b=list(map(int,a.split()))
b[0]=int(b[0])
b[1]=int(b[1])
if b[0]==1:
mark[b[1]]=True
c=(b[1],t[b[1]-1])
if len(h)<k:
h.add(c)
else:
d=min(h)
if c[1]>d[1]:
h.remove(d)
h.add(c)
else:
if mark[b[1]] and ((b[1],t[b[1]-1]) in h):
print("YES")
else:
print("NO")
i=i+1
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this value is, the better the friendship is. No two friends have the same value *t**i*.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most *k* friends. If there are more than *k* friends online then the system displays only *k* best of them — those with biggest *t**i*.
Your task is to handle queries of two types:
- "1 id" — Friend *id* becomes online. It's guaranteed that he wasn't online before. - "2 id" — Check whether friend *id* is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input Specification:
The first line contains three integers *n*, *k* and *q* (1<=≤<=*n*,<=*q*<=≤<=150<=000,<=1<=≤<=*k*<=≤<=*min*(6,<=*n*)) — the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=109) where *t**i* describes how good is Limak's relation with the *i*-th friend.
The *i*-th of the following *q* lines contains two integers *type**i* and *id**i* (1<=≤<=*type**i*<=≤<=2,<=1<=≤<=*id**i*<=≤<=*n*) — the *i*-th query. If *type**i*<==<=1 then a friend *id**i* becomes online. If *type**i*<==<=2 then you should check whether a friend *id**i* is displayed.
It's guaranteed that no two queries of the first type will have the same *id**i* becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (*type**i*<==<=2) so the output won't be empty.
Output Specification:
For each query of the second type print one line with the answer — "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Demo Input:
['4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n', '6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n']
Demo Output:
['NO\nYES\nNO\nYES\nYES\n', 'NO\nYES\nNO\nYES\n']
Note:
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" — Friend 3 becomes online. 1. "2 4" — We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 1. "2 3" — We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 1. "1 1" — Friend 1 becomes online. The system now displays both friend 1 and friend 3. 1. "1 2" — Friend 2 becomes online. There are 3 friends online now but we were given *k* = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (*t*<sub class="lower-index">1</sub> < *t*<sub class="lower-index">2</sub>, *t*<sub class="lower-index">3</sub>) so friend 1 won't be displayed 1. "2 1" — Print "NO". 1. "2 2" — Print "YES". 1. "2 3" — Print "YES". | ```python
import sys
n,k,q=list(map(int,input().split()))
t=list(map(int,input().split()))
i=0
mark=[False for i in range(n+1)]
h=set([])
i=0
while i<q:
a=sys.stdin.readline()
b=list(map(int,a.split()))
b[0]=int(b[0])
b[1]=int(b[1])
if b[0]==1:
mark[b[1]]=True
c=(b[1],t[b[1]-1])
if len(h)<k:
h.add(c)
else:
d=min(h)
if c[1]>d[1]:
h.remove(d)
h.add(c)
else:
if mark[b[1]] and ((b[1],t[b[1]-1]) in h):
print("YES")
else:
print("NO")
i=i+1
``` | 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,696,585,006 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 23 | 62 | 6,553,600 | n, target = map(int, input().split())
visited = [False] * (n + 1)
adjList = [[0]]
for j in range(1, n + 1):
adjList.append([j])
adjList[len(adjList) - 1].pop()
def dfs(v):
visited[v] = True
for i in adjList[v]:
if not visited[i]:
dfs(i)
a = [int(item) for item in input().split()]
for i in range(len(a)):
adjList[i + 1].append(i + 1 + a[i])
#print(adjList)
dfs(1)
#print(visited)
if visited[target]:
print("YES")
else:
print("NO") | 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
n, target = map(int, input().split())
visited = [False] * (n + 1)
adjList = [[0]]
for j in range(1, n + 1):
adjList.append([j])
adjList[len(adjList) - 1].pop()
def dfs(v):
visited[v] = True
for i in adjList[v]:
if not visited[i]:
dfs(i)
a = [int(item) for item in input().split()]
for i in range(len(a)):
adjList[i + 1].append(i + 1 + a[i])
#print(adjList)
dfs(1)
#print(visited)
if visited[target]:
print("YES")
else:
print("NO")
``` | -1 |
|
342 | B | Xenia and Spies | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"implementation"
] | null | null | Xenia the vigorous detective faced *n* (*n*<=≥<=2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to *n* from left to right.
Spy *s* has an important note. He has to pass the note to spy *f*. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the note to one of his neighbours in the row. In other words, if this spy's number is *x*, he can pass the note to another spy, either *x*<=-<=1 or *x*<=+<=1 (if *x*<==<=1 or *x*<==<=*n*, then the spy has only one neighbour). Also during a step the spy can keep a note and not pass it to anyone.
But nothing is that easy. During *m* steps Xenia watches some spies attentively. Specifically, during step *t**i* (steps are numbered from 1) Xenia watches spies numbers *l**i*,<=*l**i*<=+<=1,<=*l**i*<=+<=2,<=...,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). Of course, if during some step a spy is watched, he can't do anything: neither give the note nor take it from some other spy. Otherwise, Xenia reveals the spies' cunning plot. Nevertheless, if the spy at the current step keeps the note, Xenia sees nothing suspicious even if she watches him.
You've got *s* and *f*. Also, you have the steps during which Xenia watches spies and which spies she is going to watch during each step. Find the best way the spies should act in order to pass the note from spy *s* to spy *f* as quickly as possible (in the minimum number of steps). | The first line contains four integers *n*, *m*, *s* and *f* (1<=≤<=*n*,<=*m*<=≤<=105; 1<=≤<=*s*,<=*f*<=≤<=*n*; *s*<=≠<=*f*; *n*<=≥<=2). Each of the following *m* lines contains three integers *t**i*,<=*l**i*,<=*r**i* (1<=≤<=*t**i*<=≤<=109,<=1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). It is guaranteed that *t*1<=<<=*t*2<=<<=*t*3<=<<=...<=<<=*t**m*. | Print *k* characters in a line: the *i*-th character in the line must represent the spies' actions on step *i*. If on step *i* the spy with the note must pass the note to the spy with a lesser number, the *i*-th character should equal "L". If on step *i* the spy with the note must pass it to the spy with a larger number, the *i*-th character must equal "R". If the spy must keep the note at the *i*-th step, the *i*-th character must equal "X".
As a result of applying the printed sequence of actions spy *s* must pass the note to spy *f*. The number of printed characters *k* must be as small as possible. Xenia must not catch the spies passing the note.
If there are miltiple optimal solutions, you can print any of them. It is guaranteed that the answer exists. | [
"3 5 1 3\n1 1 2\n2 2 3\n3 3 3\n4 1 1\n10 1 3\n"
] | [
"XXRR\n"
] | none | 1,000 | [
{
"input": "3 5 1 3\n1 1 2\n2 2 3\n3 3 3\n4 1 1\n10 1 3",
"output": "XXRR"
},
{
"input": "2 3 2 1\n1 1 2\n2 1 2\n4 1 2",
"output": "XXL"
},
{
"input": "5 11 1 5\n1 1 5\n2 2 2\n3 1 1\n4 3 3\n5 3 3\n6 1 1\n7 4 4\n8 4 5\n10 1 3\n11 5 5\n13 1 5",
"output": "XXXRXRXXRR"
},
{
"input": "4 6 4 2\n2 2 2\n3 3 3\n4 1 1\n10 1 4\n11 2 3\n12 2 4",
"output": "LXXL"
},
{
"input": "7 5 7 6\n1 4 5\n2 7 7\n3 6 6\n4 3 4\n5 1 3",
"output": "L"
},
{
"input": "4 4 3 4\n1 2 4\n2 1 2\n3 3 4\n4 2 3",
"output": "XR"
},
{
"input": "10 10 1 10\n1 1 10\n2 1 1\n3 7 10\n4 6 7\n5 9 9\n6 4 9\n7 2 5\n8 3 10\n9 2 10\n10 7 9",
"output": "XXRRRXXXXRRRRRR"
},
{
"input": "20 20 17 20\n1 16 20\n2 12 13\n3 14 16\n4 13 15\n5 3 15\n6 2 11\n7 18 18\n8 5 15\n9 6 12\n10 19 19\n11 9 11\n12 14 17\n13 19 19\n14 12 20\n15 1 1\n16 11 17\n17 13 14\n18 5 17\n19 2 10\n20 19 20",
"output": "XRRR"
},
{
"input": "100000 1 11500 70856\n1 9881 75626",
"output": "XRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR..."
},
{
"input": "100000 2 37212 89918\n1 24285 99164\n2 67042 82268",
"output": "XRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR..."
},
{
"input": "100 5 99 1\n1 1 2\n2 2 3\n3 3 3\n4 1 1\n10 1 3",
"output": "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"
},
{
"input": "5 1 1 5\n1 1 1",
"output": "XRRRR"
},
{
"input": "3 5 1 3\n1 1 2\n2 2 3\n3 3 3\n4 1 1\n1000000000 1 3",
"output": "XXRR"
},
{
"input": "2 2 1 2\n1 1 2\n1000000000 1 2",
"output": "XR"
},
{
"input": "10 1 1 10\n1 5 6",
"output": "RRRRRRRRR"
}
] | 1,665,331,733 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | import sys
from array import array
input = lambda: sys.stdin.buffer.readline().decode().strip()
inp = lambda dtype: [dtype(x) for x in input().split()]
inp_2d = lambda dtype, n: [dtype(input()) for _ in range(n)]
inp_2ds = lambda dtype, n: [tuple(inp(dtype)) for _ in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
n, m, be, en = inp(int)
lst, ans = 1, array('u')
ch = 'R' if be < en else 'L'
inc = 1 if be < en else -1
for _ in range(m):
t, l, r = inp(int)
while be != en and lst < t:
ans.append(ch)
lst += 1
be += inc
lst = t + 1
if be != en:
if not (l <= be <= r or l <= be + 1 <= r):
be += inc
ans.append(ch)
else:
ans.append('X')
print(''.join(ans + array('u', ch * (en - be))))
| Title: Xenia and Spies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the vigorous detective faced *n* (*n*<=≥<=2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to *n* from left to right.
Spy *s* has an important note. He has to pass the note to spy *f*. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the note to one of his neighbours in the row. In other words, if this spy's number is *x*, he can pass the note to another spy, either *x*<=-<=1 or *x*<=+<=1 (if *x*<==<=1 or *x*<==<=*n*, then the spy has only one neighbour). Also during a step the spy can keep a note and not pass it to anyone.
But nothing is that easy. During *m* steps Xenia watches some spies attentively. Specifically, during step *t**i* (steps are numbered from 1) Xenia watches spies numbers *l**i*,<=*l**i*<=+<=1,<=*l**i*<=+<=2,<=...,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). Of course, if during some step a spy is watched, he can't do anything: neither give the note nor take it from some other spy. Otherwise, Xenia reveals the spies' cunning plot. Nevertheless, if the spy at the current step keeps the note, Xenia sees nothing suspicious even if she watches him.
You've got *s* and *f*. Also, you have the steps during which Xenia watches spies and which spies she is going to watch during each step. Find the best way the spies should act in order to pass the note from spy *s* to spy *f* as quickly as possible (in the minimum number of steps).
Input Specification:
The first line contains four integers *n*, *m*, *s* and *f* (1<=≤<=*n*,<=*m*<=≤<=105; 1<=≤<=*s*,<=*f*<=≤<=*n*; *s*<=≠<=*f*; *n*<=≥<=2). Each of the following *m* lines contains three integers *t**i*,<=*l**i*,<=*r**i* (1<=≤<=*t**i*<=≤<=109,<=1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). It is guaranteed that *t*1<=<<=*t*2<=<<=*t*3<=<<=...<=<<=*t**m*.
Output Specification:
Print *k* characters in a line: the *i*-th character in the line must represent the spies' actions on step *i*. If on step *i* the spy with the note must pass the note to the spy with a lesser number, the *i*-th character should equal "L". If on step *i* the spy with the note must pass it to the spy with a larger number, the *i*-th character must equal "R". If the spy must keep the note at the *i*-th step, the *i*-th character must equal "X".
As a result of applying the printed sequence of actions spy *s* must pass the note to spy *f*. The number of printed characters *k* must be as small as possible. Xenia must not catch the spies passing the note.
If there are miltiple optimal solutions, you can print any of them. It is guaranteed that the answer exists.
Demo Input:
['3 5 1 3\n1 1 2\n2 2 3\n3 3 3\n4 1 1\n10 1 3\n']
Demo Output:
['XXRR\n']
Note:
none | ```python
import sys
from array import array
input = lambda: sys.stdin.buffer.readline().decode().strip()
inp = lambda dtype: [dtype(x) for x in input().split()]
inp_2d = lambda dtype, n: [dtype(input()) for _ in range(n)]
inp_2ds = lambda dtype, n: [tuple(inp(dtype)) for _ in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
n, m, be, en = inp(int)
lst, ans = 1, array('u')
ch = 'R' if be < en else 'L'
inc = 1 if be < en else -1
for _ in range(m):
t, l, r = inp(int)
while be != en and lst < t:
ans.append(ch)
lst += 1
be += inc
lst = t + 1
if be != en:
if not (l <= be <= r or l <= be + 1 <= r):
be += inc
ans.append(ch)
else:
ans.append('X')
print(''.join(ans + array('u', ch * (en - be))))
``` | 0 |
|
772 | A | Voltage Keepsake | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add *p* units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·*p* units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. | The first line contains two integers, *n* and *p* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109) — the number of devices and the power of the charger.
This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100<=000) — the power of the device and the amount of power stored in the device in the beginning. | If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
Namely, let's assume that your answer is *a* and the answer of the jury is *b*. The checker program will consider your answer correct if . | [
"2 1\n2 2\n2 1000\n",
"1 100\n1 1\n",
"3 5\n4 3\n5 2\n6 1\n"
] | [
"2.0000000000",
"-1\n",
"0.5000000000"
] | In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | 500 | [
{
"input": "2 1\n2 2\n2 1000",
"output": "2.0000000000"
},
{
"input": "1 100\n1 1",
"output": "-1"
},
{
"input": "3 5\n4 3\n5 2\n6 1",
"output": "0.5000000000"
},
{
"input": "1 1\n1 87",
"output": "-1"
},
{
"input": "1 1\n100 77",
"output": "0.7777777778"
},
{
"input": "5 10\n3 81\n3 49\n1 20\n1 12\n1 30",
"output": "-1"
},
{
"input": "5 10\n4 3\n1 54\n2 57\n2 31\n1 99",
"output": "-1"
},
{
"input": "5 10\n2 81\n3 31\n4 49\n1 35\n1 67",
"output": "263.0000000000"
},
{
"input": "10 1\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92",
"output": "102.2222222222"
},
{
"input": "10 1\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16",
"output": "17.7777777778"
},
{
"input": "10 1\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40",
"output": "44.4444444444"
},
{
"input": "2 1\n1 10\n1 10",
"output": "20.0000000000"
},
{
"input": "20 16807\n75250 50074\n43659 8931\n11273 27545\n50879 77924\n37710 64441\n38166 84493\n43043 7988\n22504 82328\n31730 78841\n42613 44304\n33170 17710\n97158 29561\n70934 93100\n80279 51817\n95336 99098\n7827 13513\n29268 23811\n77634 80980\n79150 36580\n58822 11968",
"output": "0.2244225704"
}
] | 1,696,194,361 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 94 | 858 | 20,889,600 | import math
from bisect import bisect_right
from itertools import accumulate
R = lambda: map(int, input().split())
n, p = R()
devs = []
for i in range(n):
devs.append(tuple(R()))
devs = sorted(devs, key=lambda x: x[1]/x[0])
sp, sr, t = 0, 0, math.inf
for d in devs:
sp += d[0]
sr += d[1]
if sp > p:
t = min(t, sr / (sp - p))
print(t if t < math.inf else -1)
| Title: Voltage Keepsake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add *p* units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·*p* units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input Specification:
The first line contains two integers, *n* and *p* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109) — the number of devices and the power of the charger.
This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100<=000) — the power of the device and the amount of power stored in the device in the beginning.
Output Specification:
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
Namely, let's assume that your answer is *a* and the answer of the jury is *b*. The checker program will consider your answer correct if .
Demo Input:
['2 1\n2 2\n2 1000\n', '1 100\n1 1\n', '3 5\n4 3\n5 2\n6 1\n']
Demo Output:
['2.0000000000', '-1\n', '0.5000000000']
Note:
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | ```python
import math
from bisect import bisect_right
from itertools import accumulate
R = lambda: map(int, input().split())
n, p = R()
devs = []
for i in range(n):
devs.append(tuple(R()))
devs = sorted(devs, key=lambda x: x[1]/x[0])
sp, sr, t = 0, 0, math.inf
for d in devs:
sp += d[0]
sr += d[1]
if sp > p:
t = min(t, sr / (sp - p))
print(t if t < math.inf else -1)
``` | 3 |
|
903 | C | Boxes Packing | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=<<=*a**j*).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes! | The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box. | Print the minimum possible number of visible boxes. | [
"3\n1 2 3\n",
"4\n4 2 4 3\n"
] | [
"1\n",
"2\n"
] | In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1. | 0 | [
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "4\n4 2 4 3",
"output": "2"
},
{
"input": "10\n58 58 58 58 58 58 58 58 58 58",
"output": "10"
},
{
"input": "10\n86 89 89 86 86 89 86 86 89 89",
"output": "5"
},
{
"input": "100\n981 288 186 186 292 876 341 288 981 360 783 907 292 186 341 292 360 876 360 360 981 398 783 288 292 398 876 981 398 907 783 360 288 981 907 186 360 288 186 981 186 288 907 876 288 907 876 360 341 292 907 783 907 783 292 981 907 292 876 398 783 876 398 341 876 186 288 186 981 341 398 360 907 981 341 186 292 981 292 398 876 783 292 186 360 292 288 292 876 398 288 292 341 288 398 360 360 292 981 360",
"output": "14"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n9",
"output": "1"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n131",
"output": "1"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "9"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "11"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1"
},
{
"input": "8\n1 1 1 1 1 1 1 1",
"output": "8"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
}
] | 1,634,913,727 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 4,505,600 | N = int(input())
l = input().split()
l = l[:N]
lst = sorted(l)
j = 0
count = N
for i in range(1, N):
if int(l[j]) < int(l[i]):
count = count - 1
j = j + 1
print(count) | Title: Boxes Packing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=<<=*a**j*).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box.
Output Specification:
Print the minimum possible number of visible boxes.
Demo Input:
['3\n1 2 3\n', '4\n4 2 4 3\n']
Demo Output:
['1\n', '2\n']
Note:
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1. | ```python
N = int(input())
l = input().split()
l = l[:N]
lst = sorted(l)
j = 0
count = N
for i in range(1, N):
if int(l[j]) < int(l[i]):
count = count - 1
j = j + 1
print(count)
``` | 0 |
|
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.
To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.
Determine how many groups of students will be kicked out of the club. | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself. | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one. | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
{
"input": "5 4\n1 4\n4 3\n4 5\n5 2",
"output": "2"
},
{
"input": "11 10\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11",
"output": "4"
},
{
"input": "7 7\n1 2\n2 3\n3 1\n1 4\n4 5\n4 6\n4 7",
"output": "2"
},
{
"input": "12 49\n6 3\n12 9\n10 11\n3 5\n10 2\n6 9\n8 5\n6 12\n7 3\n3 12\n3 2\n5 6\n7 5\n9 2\n11 1\n7 6\n5 4\n8 7\n12 5\n5 11\n8 9\n10 3\n6 2\n10 4\n9 10\n9 11\n11 3\n5 9\n11 6\n10 8\n7 9\n10 7\n4 6\n3 8\n4 11\n12 2\n4 9\n2 11\n7 11\n1 5\n7 2\n8 1\n4 12\n9 1\n4 2\n8 2\n11 12\n3 1\n1 6",
"output": "0"
},
{
"input": "10 29\n4 5\n1 7\n4 2\n3 8\n7 6\n8 10\n10 6\n4 1\n10 1\n6 2\n7 4\n7 10\n2 7\n9 8\n5 10\n2 5\n8 5\n4 9\n2 8\n5 7\n4 8\n7 3\n6 5\n1 3\n1 9\n10 4\n10 9\n10 2\n2 3",
"output": "0"
},
{
"input": "9 33\n5 7\n5 9\n9 6\n9 1\n7 4\n3 5\n7 8\n8 6\n3 6\n8 2\n3 8\n1 6\n1 8\n1 4\n4 2\n1 2\n2 5\n3 4\n8 5\n2 6\n3 1\n1 5\n1 7\n3 2\n5 4\n9 4\n3 9\n7 3\n6 4\n9 8\n7 9\n8 4\n6 5",
"output": "0"
},
{
"input": "7 8\n5 7\n2 7\n1 6\n1 3\n3 7\n6 3\n6 4\n2 6",
"output": "1"
},
{
"input": "6 15\n3 1\n4 5\n1 4\n6 2\n3 5\n6 3\n1 6\n1 5\n2 3\n2 5\n6 4\n5 6\n4 2\n1 2\n3 4",
"output": "0"
},
{
"input": "7 11\n5 3\n6 5\n6 4\n1 6\n7 1\n2 6\n7 5\n2 5\n3 1\n3 4\n2 4",
"output": "0"
},
{
"input": "95 0",
"output": "0"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "62 30\n29 51\n29 55\n4 12\n53 25\n36 28\n32 11\n29 11\n47 9\n21 8\n25 4\n51 19\n26 56\n22 21\n37 9\n9 33\n7 25\n16 7\n40 49\n15 21\n49 58\n34 30\n20 46\n62 48\n53 57\n33 6\n60 37\n41 34\n62 36\n36 43\n11 39",
"output": "2"
},
{
"input": "56 25\n12 40\n31 27\n18 40\n1 43\n9 10\n25 47\n27 29\n26 28\n19 38\n19 40\n22 14\n21 51\n29 31\n55 29\n51 33\n20 17\n24 15\n3 48\n31 56\n15 29\n49 42\n50 4\n22 42\n25 17\n18 51",
"output": "3"
},
{
"input": "51 29\n36 30\n37 45\n4 24\n40 18\n47 35\n15 1\n30 38\n15 18\n32 40\n34 42\n2 47\n35 21\n25 28\n13 1\n13 28\n36 1\n46 47\n22 17\n41 45\n43 45\n40 15\n29 35\n47 15\n30 21\n9 14\n18 38\n18 50\n42 10\n31 41",
"output": "3"
},
{
"input": "72 45\n5 15\n8 18\n40 25\n71 66\n67 22\n6 44\n16 25\n8 23\n19 70\n26 34\n48 15\n24 2\n54 68\n44 43\n17 37\n49 19\n71 49\n34 38\n59 1\n65 70\n11 54\n5 11\n15 31\n29 50\n48 16\n70 57\n25 59\n2 59\n56 12\n66 62\n24 16\n46 27\n45 67\n68 43\n31 11\n31 30\n8 44\n64 33\n38 44\n54 10\n13 9\n7 51\n25 4\n40 70\n26 65",
"output": "5"
},
{
"input": "56 22\n17 27\n48 49\n29 8\n47 20\n32 7\n44 5\n14 39\n5 13\n40 2\n50 42\n38 9\n18 37\n16 44\n21 32\n21 39\n37 54\n19 46\n30 47\n17 13\n30 31\n49 16\n56 7",
"output": "4"
},
{
"input": "81 46\n53 58\n31 14\n18 54\n43 61\n57 65\n6 38\n49 5\n6 40\n6 10\n17 72\n27 48\n58 39\n21 75\n21 43\n78 20\n34 4\n15 35\n74 48\n76 15\n49 38\n46 51\n78 9\n80 5\n26 42\n64 31\n46 72\n1 29\n20 17\n32 45\n53 43\n24 5\n52 59\n3 80\n78 19\n61 17\n80 12\n17 8\n63 2\n8 4\n44 10\n53 72\n18 60\n68 15\n17 58\n79 71\n73 35",
"output": "4"
},
{
"input": "82 46\n64 43\n32 24\n57 30\n24 46\n70 12\n23 41\n63 39\n46 70\n4 61\n19 12\n39 79\n14 28\n37 3\n12 27\n15 20\n35 39\n25 64\n59 16\n68 63\n37 14\n76 7\n67 29\n9 5\n14 55\n46 26\n71 79\n47 42\n5 55\n18 45\n28 40\n44 78\n74 9\n60 53\n44 19\n52 81\n65 52\n40 13\n40 19\n43 1\n24 23\n68 9\n16 20\n70 14\n41 40\n29 10\n45 65",
"output": "8"
},
{
"input": "69 38\n63 35\n52 17\n43 69\n2 57\n12 5\n26 36\n13 10\n16 68\n5 18\n5 41\n10 4\n60 9\n39 22\n39 28\n53 57\n13 52\n66 38\n49 61\n12 19\n27 46\n67 7\n25 8\n23 58\n52 34\n29 2\n2 42\n8 53\n57 43\n68 11\n48 28\n56 19\n46 33\n63 21\n57 16\n68 59\n67 34\n28 43\n56 36",
"output": "4"
},
{
"input": "75 31\n32 50\n52 8\n21 9\n68 35\n12 72\n47 26\n38 58\n40 55\n31 70\n53 75\n44 1\n65 22\n33 22\n33 29\n14 39\n1 63\n16 52\n70 15\n12 27\n63 31\n47 9\n71 31\n43 17\n43 49\n8 26\n11 39\n9 22\n30 45\n65 47\n32 9\n60 70",
"output": "4"
},
{
"input": "77 41\n48 45\n50 36\n6 69\n70 3\n22 21\n72 6\n54 3\n49 31\n2 23\n14 59\n68 58\n4 54\n60 12\n63 60\n44 24\n28 24\n40 8\n5 1\n13 24\n29 15\n19 76\n70 50\n65 71\n23 33\n58 16\n50 42\n71 28\n58 54\n24 73\n6 17\n29 13\n60 4\n42 4\n21 60\n77 39\n57 9\n51 19\n61 6\n49 36\n24 32\n41 66",
"output": "3"
},
{
"input": "72 39\n9 44\n15 12\n2 53\n34 18\n41 70\n54 72\n39 19\n26 7\n4 54\n53 59\n46 49\n70 6\n9 10\n64 51\n31 60\n61 53\n59 71\n9 60\n67 16\n4 16\n34 3\n2 61\n16 23\n34 6\n10 18\n13 38\n66 40\n59 9\n40 14\n38 24\n31 48\n7 69\n20 39\n49 52\n32 67\n61 35\n62 45\n37 54\n5 27",
"output": "8"
},
{
"input": "96 70\n30 37\n47 56\n19 79\n15 28\n2 43\n43 54\n59 75\n42 22\n38 18\n18 14\n47 41\n60 29\n35 11\n90 4\n14 41\n11 71\n41 24\n68 28\n45 92\n14 15\n34 63\n77 32\n67 38\n36 8\n37 4\n58 95\n68 84\n69 81\n35 23\n56 63\n78 91\n35 44\n66 63\n80 19\n87 88\n28 14\n62 35\n24 23\n83 37\n54 89\n14 40\n9 35\n94 9\n56 46\n92 70\n16 58\n96 31\n53 23\n56 5\n36 42\n89 77\n29 51\n26 13\n46 70\n25 56\n95 96\n3 51\n76 8\n36 82\n44 85\n54 56\n89 67\n32 5\n82 78\n33 65\n43 28\n35 1\n94 13\n26 24\n10 51",
"output": "4"
},
{
"input": "76 49\n15 59\n23 26\n57 48\n49 51\n42 76\n36 40\n37 40\n29 15\n28 71\n47 70\n27 39\n76 21\n55 16\n21 18\n19 1\n25 31\n51 71\n54 42\n28 9\n61 69\n33 9\n18 19\n58 51\n51 45\n29 34\n9 67\n26 8\n70 37\n11 62\n24 22\n59 76\n67 17\n59 11\n54 1\n12 57\n23 3\n46 47\n37 20\n65 9\n51 12\n31 19\n56 13\n58 22\n26 59\n39 76\n27 11\n48 64\n59 35\n44 75",
"output": "5"
},
{
"input": "52 26\n29 41\n16 26\n18 48\n31 17\n37 42\n26 1\n11 7\n29 6\n23 17\n12 47\n34 23\n41 16\n15 35\n25 21\n45 7\n52 2\n37 10\n28 19\n1 27\n30 47\n42 35\n50 30\n30 34\n19 30\n42 25\n47 31",
"output": "3"
},
{
"input": "86 48\n59 34\n21 33\n45 20\n62 23\n4 68\n2 65\n63 26\n64 20\n51 34\n64 21\n68 78\n61 80\n81 3\n38 39\n47 48\n24 34\n44 71\n72 78\n50 2\n13 51\n82 78\n11 74\n14 48\n2 75\n49 55\n63 85\n20 85\n4 53\n51 15\n11 67\n1 15\n2 64\n10 81\n6 7\n68 18\n84 28\n77 69\n10 36\n15 14\n32 86\n16 79\n26 13\n38 55\n47 43\n47 39\n45 37\n58 81\n42 35",
"output": "8"
},
{
"input": "58 29\n27 24\n40 52\n51 28\n44 50\n7 28\n14 53\n10 16\n16 45\n8 56\n35 26\n39 6\n6 14\n45 22\n35 13\n20 17\n42 6\n37 21\n4 11\n26 56\n54 55\n3 57\n40 3\n55 27\n4 51\n35 29\n50 16\n47 7\n48 20\n1 37",
"output": "3"
},
{
"input": "51 23\n46 47\n31 27\n1 20\n49 16\n2 10\n29 47\n13 27\n34 26\n31 2\n28 20\n17 40\n39 4\n29 26\n28 44\n3 39\n50 12\n19 1\n30 21\n41 23\n2 29\n16 3\n49 28\n49 41",
"output": "4"
},
{
"input": "75 43\n46 34\n33 12\n51 39\n47 74\n68 64\n40 46\n20 51\n47 19\n4 5\n57 59\n12 26\n68 65\n38 42\n73 37\n5 74\n36 61\n8 18\n58 33\n34 73\n42 43\n10 49\n70 50\n49 18\n24 53\n71 73\n44 24\n49 56\n24 29\n44 67\n70 46\n57 25\n73 63\n3 51\n30 71\n41 44\n17 69\n17 18\n19 68\n42 7\n11 51\n1 5\n72 23\n65 53",
"output": "5"
}
] | 1,619,610,692 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 124 | 0 | n, m = map(int, input().split())
g = [[]for i in range(n + 1)]
used = [0] * (n + 1)
for i in range(m):
a, b = map(int, input().split())
g[a].append(b)
g[b].append(a)
k = 0
for j in range(1, n+1):
if len(g[j]) == 1:
if used[j] == 0 and used[g[j][0]] == 0:
k += 1
used[j] =1
used[g[j][0]] = 1
print(k) | Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.
To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.
Determine how many groups of students will be kicked out of the club.
Input Specification:
The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.
Output Specification:
Print the single number — the number of groups of students that will be kicked out from the club.
Demo Input:
['3 3\n1 2\n2 3\n3 1\n', '6 3\n1 2\n2 3\n3 4\n', '6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n']
Demo Output:
['0\n', '2\n', '1\n']
Note:
In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one. | ```python
n, m = map(int, input().split())
g = [[]for i in range(n + 1)]
used = [0] * (n + 1)
for i in range(m):
a, b = map(int, input().split())
g[a].append(b)
g[b].append(a)
k = 0
for j in range(1, n+1):
if len(g[j]) == 1:
if used[j] == 0 and used[g[j][0]] == 0:
k += 1
used[j] =1
used[g[j][0]] = 1
print(k)
``` | 0 |
|
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,693,468,929 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | def CalCulateZero():
count = 0
for i in range(len(s)):
if i == 0:
count += 1
else:
count -= 1
break
s = input()
if '0000000' in s:
print('YES')
elif '1111111' in s:
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
def CalCulateZero():
count = 0
for i in range(len(s)):
if i == 0:
count += 1
else:
count -= 1
break
s = input()
if '0000000' in s:
print('YES')
elif '1111111' in s:
print('YES')
else:
print('NO')
``` | 3.977 |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
Can you help B find out exactly what two errors he corrected? | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one. | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 388684428 9301599 656422756 784303821 460626451 277246428",
"output": "25720377\n661369649"
},
{
"input": "3\n796067435 964699482 819602309\n964699482 796067435\n964699482",
"output": "819602309\n796067435"
},
{
"input": "3\n374054998 726316780 902899520\n902899520 726316780\n726316780",
"output": "374054998\n902899520"
},
{
"input": "3\n168638990 939116221 323703261\n168638990 323703261\n168638990",
"output": "939116221\n323703261"
},
{
"input": "3\n77 77 77\n77 77\n77",
"output": "77\n77"
},
{
"input": "3\n84 30 9\n9 84\n9",
"output": "30\n84"
},
{
"input": "6\n5 4 3 3 5 5\n3 5 5 4 3\n3 5 4 3",
"output": "5\n5"
},
{
"input": "4\n1 5 7 8\n1 5 7\n1 5",
"output": "8\n7"
}
] | 1,660,055,315 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 186 | 22,016,000 | n = int(input())
first = list(map(int, input().split()))
second = list(map(int, input().split()))
third = list(map(int, input().split()))
first.sort()
second.sort()
third.sort()
second.append(10 ** 10)
for i in range(n):
if first[i] != second[i]:
print(first[i])
break
second.pop(-1)
third.append(10 ** 10)
for i in range(n):
if second[i] != third[i]:
print(second[i])
break | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
Can you help B find out exactly what two errors he corrected?
Input Specification:
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Output Specification:
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
Demo Input:
['5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n', '6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n']
Demo Output:
['8\n123\n', '1\n3\n']
Note:
In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | ```python
n = int(input())
first = list(map(int, input().split()))
second = list(map(int, input().split()))
third = list(map(int, input().split()))
first.sort()
second.sort()
third.sort()
second.append(10 ** 10)
for i in range(n):
if first[i] != second[i]:
print(first[i])
break
second.pop(-1)
third.append(10 ** 10)
for i in range(n):
if second[i] != third[i]:
print(second[i])
break
``` | 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,615,877,227 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 122 | 0 | n = int(input())
l1 = []
l2 = []
for i in range(n):
x,y = map(int,input().split())
l1.append(x)
l2.append(y)
a = l1.count(1)
b = l2.count(1)
if a >b:
print((5-a)+b)
else:
print((5-b)+a)
| Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds *t*.
Input Specification:
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero.
The numbers in the lines are separated by single spaces.
Output Specification:
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Demo Input:
['5\n0 1\n1 0\n0 1\n1 1\n0 1\n']
Demo Output:
['3\n']
Note:
none | ```python
n = int(input())
l1 = []
l2 = []
for i in range(n):
x,y = map(int,input().split())
l1.append(x)
l2.append(y)
a = l1.count(1)
b = l2.count(1)
if a >b:
print((5-a)+b)
else:
print((5-b)+a)
``` | 0 |
|
644 | C | Hostname Aliases | PROGRAMMING | 2,100 | [
"*special",
"binary search",
"data structures",
"implementation",
"sortings",
"strings"
] | null | null | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where:
- <hostname> — server name (consists of words and maybe some dots separating them), - /<path> — optional part, where <path> consists of words separated by slashes.
We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.
Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.
Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of page queries. Then follow *n* lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where:
- <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. - <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20.
Addresses are not guaranteed to be distinct. | First print *k* — the number of groups of server names that correspond to one website. You should count only groups of size greater than one.
Next *k* lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | [
"10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n",
"14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a\n"
] | [
"1\nhttp://abacaba.de http://abacaba.ru \n",
"2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc \n"
] | none | 1,500 | [
{
"input": "10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test",
"output": "1\nhttp://abacaba.de http://abacaba.ru "
},
{
"input": "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a",
"output": "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc "
},
{
"input": "10\nhttp://tqr.ekdb.nh/w\nhttp://p.ulz/ifw\nhttp://w.gw.dw.xn/kpe\nhttp://byt.mqii.zkv/j/xt\nhttp://ovquj.rbgrlw/k..\nhttp://bv.plu.e.dslg/j/xt\nhttp://udgci.ufgi.gwbd.s/\nhttp://l.oh.ne.o.r/.vo\nhttp://l.oh.ne.o.r/w\nhttp://tqr.ekdb.nh/.vo",
"output": "2\nhttp://l.oh.ne.o.r http://tqr.ekdb.nh \nhttp://bv.plu.e.dslg http://byt.mqii.zkv "
},
{
"input": "12\nhttp://ickght.ck/mr\nhttp://a.exhel/.b\nhttp://a.exhel/\nhttp://ti.cdm/\nhttp://ti.cdm/x/wd/lm.h.\nhttp://ickght.ck/a\nhttp://ickght.ck\nhttp://c.gcnk.d/.b\nhttp://c.gcnk.d/x/wd/lm.h.\nhttp://ti.cdm/.b\nhttp://a.exhel/x/wd/lm.h.\nhttp://c.gcnk.d/",
"output": "1\nhttp://a.exhel http://c.gcnk.d http://ti.cdm "
},
{
"input": "14\nhttp://jr/kgb\nhttp://ps.p.t.jeua.x.a.q.t\nhttp://gsqqs.n/t/\nhttp://w.afwsnuc.ff.km/cohox/u.\nhttp://u.s.wbumkuqm/\nhttp://u.s.wbumkuqm/cohox/u.\nhttp://nq.dzjkjcwv.f.s/bvm/\nhttp://zoy.shgg\nhttp://gsqqs.n\nhttp://u.s.wbumkuqm/b.pd.\nhttp://w.afwsnuc.ff.km/\nhttp://w.afwsnuc.ff.km/b.pd.\nhttp://nq.dzjkjcwv.f.s/n\nhttp://nq.dzjkjcwv.f.s/ldbw",
"output": "2\nhttp://ps.p.t.jeua.x.a.q.t http://zoy.shgg \nhttp://u.s.wbumkuqm http://w.afwsnuc.ff.km "
},
{
"input": "15\nhttp://l.edzplwqsij.rw/\nhttp://m.e.mehd.acsoinzm/s\nhttp://yg.ttahn.xin.obgez/ap/\nhttp://qqbb.pqkaqcncodxmaae\nhttp://lzi.a.flkp.lnn.k/o/qfr.cp\nhttp://lzi.a.flkp.lnn.k/f\nhttp://p.ngu.gkoq/.szinwwi\nhttp://qqbb.pqkaqcncodxmaae/od\nhttp://qqbb.pqkaqcncodxmaae\nhttp://wsxvmi.qpe.fihtgdvi/e./\nhttp://p.ngu.gkoq/zfoh\nhttp://m.e.mehd.acsoinzm/xp\nhttp://c.gy.p.h.tkrxt.jnsjt/j\nhttp://wsxvmi.qpe.fihtgdvi/grkag.z\nhttp://p.ngu.gkoq/t",
"output": "0"
},
{
"input": "15\nhttp://w.hhjvdn.mmu/.ca.p\nhttp://m.p.p.lar/\nhttp://lgmjun.r.kogpr.ijn/./t\nhttp://bapchpl.mcw.a.lob/d/ym/./g.q\nhttp://uxnjfnjp.kxr.ss.e.uu/jwo./hjl/\nhttp://fd.ezw.ykbb.xhl.t/\nhttp://i.xcb.kr/.ca.p\nhttp://jofec.ry.fht.gt\nhttp://qeo.gghwe.lcr/d/ym/./g.q\nhttp://gt\nhttp://gjvifpf.d/d/ym/./g.q\nhttp://oba\nhttp://rjs.qwd/v/hi\nhttp://fgkj/\nhttp://ivun.naumc.l/.ca.p",
"output": "4\nhttp://gt http://jofec.ry.fht.gt http://oba \nhttp://fd.ezw.ykbb.xhl.t http://fgkj http://m.p.p.lar \nhttp://i.xcb.kr http://ivun.naumc.l http://w.hhjvdn.mmu \nhttp://bapchpl.mcw.a.lob http://gjvifpf.d http://qeo.gghwe.lcr "
},
{
"input": "20\nhttp://gjwr/xsoiagp/\nhttp://gdnmu/j\nhttp://yfygudx.e.aqa.ezh/j\nhttp://mpjxue.cuvipq/\nhttp://a/\nhttp://kr/..n/c.\nhttp://a/xsoiagp/\nhttp://kr/z\nhttp://kr/v.cv/rk/k\nhttp://lvhpz\nhttp://qv.v.jqzhq\nhttp://y.no/\nhttp://kr/n\nhttp://y.no/xsoiagp/\nhttp://kr/ebe/z/\nhttp://olsvbxxw.win.n/j\nhttp://p.ct/j\nhttp://mpjxue.cuvipq/xsoiagp/\nhttp://kr/j\nhttp://gjwr/",
"output": "3\nhttp://lvhpz http://qv.v.jqzhq \nhttp://a http://gjwr http://mpjxue.cuvipq http://y.no \nhttp://gdnmu http://olsvbxxw.win.n http://p.ct http://yfygudx.e.aqa.ezh "
},
{
"input": "1\nhttp://a",
"output": "0"
},
{
"input": "3\nhttp://abacaba.com/test\nhttp://abacaba.de/test\nhttp://abacaba.de/test",
"output": "1\nhttp://abacaba.com http://abacaba.de "
}
] | 1,458,215,987 | 97,187 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 6 | 5,000 | 30,310,400 | from collections import defaultdict
n = int(input())
d = defaultdict(lambda: set())
groups = []
for i in range(n):
s = input()[7:]
el = s.split('/', 1)
if len(el) < 2:
el.append(None)
name, path = el
d[name].add(path)
d = list(d.items())
while d:
n = d[-1]
groups.append([el for el in d if el[1] == n[1]])
d = [el for el in d if el[1] != n[1]]
if len(groups[-1]) == 1:
groups.pop()
print(len(groups))
for group in groups:
print(*["http://{}".format(el[0]) for el in group])
| Title: Hostname Aliases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where:
- <hostname> — server name (consists of words and maybe some dots separating them), - /<path> — optional part, where <path> consists of words separated by slashes.
We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.
Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.
Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of page queries. Then follow *n* lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where:
- <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. - <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20.
Addresses are not guaranteed to be distinct.
Output Specification:
First print *k* — the number of groups of server names that correspond to one website. You should count only groups of size greater than one.
Next *k* lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order.
Demo Input:
['10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n', '14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a\n']
Demo Output:
['1\nhttp://abacaba.de http://abacaba.ru \n', '2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc \n']
Note:
none | ```python
from collections import defaultdict
n = int(input())
d = defaultdict(lambda: set())
groups = []
for i in range(n):
s = input()[7:]
el = s.split('/', 1)
if len(el) < 2:
el.append(None)
name, path = el
d[name].add(path)
d = list(d.items())
while d:
n = d[-1]
groups.append([el for el in d if el[1] == n[1]])
d = [el for el in d if el[1] != n[1]]
if len(groups[-1]) == 1:
groups.pop()
print(len(groups))
for group in groups:
print(*["http://{}".format(el[0]) for el in group])
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.
Sorting integers in a subsequence is a process such that the numbers included in a subsequence are ordered in increasing order, and the numbers which are not included in a subsequence don't change their places.
Every element of the sequence must appear in exactly one subsequence. | The first line of input data contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of the sequence.
The second line of input data contains *n* different integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct. | In the first line print the maximum number of subsequences *k*, which the original sequence can be split into while fulfilling the requirements.
In the next *k* lines print the description of subsequences in the following format: the number of elements in subsequence *c**i* (0<=<<=*c**i*<=≤<=*n*), then *c**i* integers *l*1,<=*l*2,<=...,<=*l**c**i* (1<=≤<=*l**j*<=≤<=*n*) — indices of these elements in the original sequence.
Indices could be printed in any order. Every index from 1 to *n* must appear in output exactly once.
If there are several possible answers, print any of them. | [
"6\n3 2 1 6 5 4\n",
"6\n83 -75 -49 11 37 62\n"
] | [
"4\n2 1 3\n1 2\n2 4 6\n1 5\n",
"1\n6 1 2 3 4 5 6\n"
] | In the first sample output:
After sorting the first subsequence we will get sequence 1 2 3 6 5 4.
Sorting the second subsequence changes nothing.
After sorting the third subsequence we will get sequence 1 2 3 4 5 6.
Sorting the last subsequence changes nothing. | 0 | [
{
"input": "6\n3 2 1 6 5 4",
"output": "4\n2 1 3\n1 2\n2 4 6\n1 5"
},
{
"input": "6\n83 -75 -49 11 37 62",
"output": "1\n6 1 2 3 4 5 6"
},
{
"input": "1\n1",
"output": "1\n1 1"
},
{
"input": "2\n1 2",
"output": "2\n1 1\n1 2"
},
{
"input": "2\n2 1",
"output": "1\n2 1 2"
},
{
"input": "3\n1 2 3",
"output": "3\n1 1\n1 2\n1 3"
},
{
"input": "3\n3 2 1",
"output": "2\n2 1 3\n1 2"
},
{
"input": "3\n3 1 2",
"output": "1\n3 1 2 3"
},
{
"input": "10\n3 7 10 1 9 5 4 8 6 2",
"output": "3\n6 1 4 7 2 10 3\n3 5 6 9\n1 8"
},
{
"input": "20\n363756450 -204491568 95834122 -840249197 -49687658 470958158 -445130206 189801569 802780784 -790013317 -192321079 586260100 -751917965 -354684803 418379342 -253230108 193944314 712662868 853829789 735867677",
"output": "3\n7 1 4 7 2 10 3 13\n11 5 14 15 6 16 12 17 18 20 19 9\n2 8 11"
},
{
"input": "50\n39 7 45 25 31 26 50 11 19 37 8 16 22 33 14 6 12 46 49 48 29 27 41 15 34 24 3 13 20 47 9 36 5 43 40 21 2 38 35 42 23 28 1 32 10 17 30 18 44 4",
"output": "6\n20 1 43 34 25 4 50 7 2 37 10 45 3 27 22 13 28 42 40 35 39\n23 5 33 14 15 24 26 6 16 12 17 46 18 48 20 29 21 36 32 44 49 19 9 31\n2 8 11\n2 23 41\n2 30 47\n1 38"
},
{
"input": "100\n39 77 67 25 81 26 50 11 73 95 86 16 90 33 14 79 12 100 68 64 60 27 41 15 34 24 3 61 83 47 57 65 99 43 40 21 94 72 82 85 23 71 76 32 10 17 30 18 44 59 35 89 6 63 7 69 62 70 4 29 92 87 31 48 36 28 45 97 93 98 56 38 58 80 8 1 74 91 53 55 54 51 96 5 42 52 9 22 78 88 75 13 66 2 37 20 49 19 84 46",
"output": "6\n41 1 76 43 34 25 4 59 50 7 55 80 74 77 2 94 37 95 10 45 67 3 27 22 88 90 13 92 61 28 66 93 69 56 71 42 85 40 35 51 82 39\n45 5 84 99 33 14 15 24 26 6 53 79 16 12 17 46 100 18 48 64 20 96 83 29 60 21 36 65 32 44 49 97 68 19 98 70 58 73 9 87 62 57 31 63 54 81\n8 8 75 91 78 89 52 86 11\n2 23 41\n2 30 47\n2 38 72"
}
] | 1,503,601,449 | 8,949 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 5 | 1,000 | 2,252,800 | n=int(input())
l1=[]
lindex=[]
for i in range(n):
lindex.append(i)
lmain=[]
l=[int(i) for i in input().split()]
for i in l:
l1.append(i)
l1.sort()
for i in range(n):
if (l[i]==l1[i]):
lmain.append([i+1])
lindex.remove(i)
#print (l,l1,lmain,n,lindex)
while (lindex!=[]):
number=lindex[0]
khali=[number+1]
while(l1.index(l[number])!=lindex[0]):
number=l1.index(l[number])
khali.append(number+1)
lmain.append(khali)
for i in khali:
lindex.remove(i-1)
length=len(lmain)
print (length,end="\n")
for i in range(length):
print (len(lmain[i]),end=" ")
for j in range(len(lmain[i])):
if (j!=len(lmain[i])-1):
print (lmain[i][j],end=" ")
else:
print (lmain[i][j],end="\n") | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.
Sorting integers in a subsequence is a process such that the numbers included in a subsequence are ordered in increasing order, and the numbers which are not included in a subsequence don't change their places.
Every element of the sequence must appear in exactly one subsequence.
Input Specification:
The first line of input data contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of the sequence.
The second line of input data contains *n* different integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct.
Output Specification:
In the first line print the maximum number of subsequences *k*, which the original sequence can be split into while fulfilling the requirements.
In the next *k* lines print the description of subsequences in the following format: the number of elements in subsequence *c**i* (0<=<<=*c**i*<=≤<=*n*), then *c**i* integers *l*1,<=*l*2,<=...,<=*l**c**i* (1<=≤<=*l**j*<=≤<=*n*) — indices of these elements in the original sequence.
Indices could be printed in any order. Every index from 1 to *n* must appear in output exactly once.
If there are several possible answers, print any of them.
Demo Input:
['6\n3 2 1 6 5 4\n', '6\n83 -75 -49 11 37 62\n']
Demo Output:
['4\n2 1 3\n1 2\n2 4 6\n1 5\n', '1\n6 1 2 3 4 5 6\n']
Note:
In the first sample output:
After sorting the first subsequence we will get sequence 1 2 3 6 5 4.
Sorting the second subsequence changes nothing.
After sorting the third subsequence we will get sequence 1 2 3 4 5 6.
Sorting the last subsequence changes nothing. | ```python
n=int(input())
l1=[]
lindex=[]
for i in range(n):
lindex.append(i)
lmain=[]
l=[int(i) for i in input().split()]
for i in l:
l1.append(i)
l1.sort()
for i in range(n):
if (l[i]==l1[i]):
lmain.append([i+1])
lindex.remove(i)
#print (l,l1,lmain,n,lindex)
while (lindex!=[]):
number=lindex[0]
khali=[number+1]
while(l1.index(l[number])!=lindex[0]):
number=l1.index(l[number])
khali.append(number+1)
lmain.append(khali)
for i in khali:
lindex.remove(i-1)
length=len(lmain)
print (length,end="\n")
for i in range(length):
print (len(lmain[i]),end=" ")
for j in range(len(lmain[i])):
if (j!=len(lmain[i])-1):
print (lmain[i][j],end=" ")
else:
print (lmain[i][j],end="\n")
``` | 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,682,031,582 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 216 | 102,400 | from collections import *
def take_input():
user_arr=[]
while True:
try:var = input();user_arr.append(var)
except:break
return user_arr
def func(intput,mapping,unpack):
user_list,traffic,users = take_input(),0,set()
for user in user_list:
if user[0] == '+': users.add(user[1:])
elif user[0] == '-': users.remove(user[1:])
else:
msg = user.split(':')[1]
traffic += (len(msg)*len(users))
print(traffic)
def init(TestCases=True):
intput = lambda : int(input())
mapping = lambda s: list(map(s,input().split()))
unpack = lambda s: map(s,input().split())
for _ in range(int(input()) if TestCases else 1):
func(intput,mapping,unpack)
if __name__ == '__main__':
init(False) | 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
from collections import *
def take_input():
user_arr=[]
while True:
try:var = input();user_arr.append(var)
except:break
return user_arr
def func(intput,mapping,unpack):
user_list,traffic,users = take_input(),0,set()
for user in user_list:
if user[0] == '+': users.add(user[1:])
elif user[0] == '-': users.remove(user[1:])
else:
msg = user.split(':')[1]
traffic += (len(msg)*len(users))
print(traffic)
def init(TestCases=True):
intput = lambda : int(input())
mapping = lambda s: list(map(s,input().split()))
unpack = lambda s: map(s,input().split())
for _ in range(int(input()) if TestCases else 1):
func(intput,mapping,unpack)
if __name__ == '__main__':
init(False)
``` | 3.891237 |
985 | D | Sand Fortress | PROGRAMMING | 2,100 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right.
Obviously, there is not enough sand on the beach, so you brought *n* packs of sand with you. Let height *h**i* of the sand pillar on some spot *i* be the number of sand packs you spent on it. You can't split a sand pack to multiple pillars, all the sand from it should go to a single one. There is a fence of height equal to the height of pillar with *H* sand packs to the left of the first spot and you should prevent sand from going over it.
Finally you ended up with the following conditions to building the castle:
- *h*1<=≤<=*H*: no sand from the leftmost spot should go over the fence; - For any |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1: large difference in heights of two neighboring pillars can lead sand to fall down from the higher one to the lower, you really don't want this to happen; - : you want to spend all the sand you brought with you.
As you have infinite spots to build, it is always possible to come up with some valid castle structure. Though you want the castle to be as compact as possible.
Your task is to calculate the minimum number of spots you can occupy so that all the aforementioned conditions hold. | The only line contains two integer numbers *n* and *H* (1<=≤<=*n*,<=*H*<=≤<=1018) — the number of sand packs you have and the height of the fence, respectively. | Print the minimum number of spots you can occupy so the all the castle building conditions hold. | [
"5 2\n",
"6 8\n"
] | [
"3\n",
"3\n"
] | Here are the heights of some valid castles:
- *n* = 5, *H* = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...] - *n* = 6, *H* = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied)
The first list for both cases is the optimal answer, 3 spots are occupied in them.
And here are some invalid ones:
- *n* = 5, *H* = 2, [3, 2, 0, ...], [2, 3, 0, ...], [1, 0, 2, 2, ...] - *n* = 6, *H* = 8, [2, 2, 2, 0, ...], [6, 0, ...], [1, 4, 1, 0...], [2, 2, 1, 0, ...] | 0 | [
{
"input": "5 2",
"output": "3"
},
{
"input": "6 8",
"output": "3"
},
{
"input": "20 4",
"output": "7"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1414213562"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 1000000000000000000",
"output": "1"
},
{
"input": "1000000000000000000 1",
"output": "1999999999"
},
{
"input": "1036191544337895 45523434",
"output": "45523434"
},
{
"input": "1036191544337896 45523434",
"output": "45523435"
},
{
"input": "1036191544337895 45523433",
"output": "45523435"
},
{
"input": "1036191544337895 1",
"output": "64379858"
},
{
"input": "1036191544337895 1000000000000000000",
"output": "45523434"
},
{
"input": "30 3",
"output": "9"
},
{
"input": "30 4",
"output": "8"
},
{
"input": "6 100",
"output": "3"
},
{
"input": "7 100",
"output": "4"
},
{
"input": "1000000000000000000 99999999999",
"output": "1414213562"
},
{
"input": "999999997351043581 1000000000000000000",
"output": "1414213561"
},
{
"input": "911343366122896086 1416605974",
"output": "1350069158"
},
{
"input": "828974163639871882 2010864527",
"output": "1287613423"
},
{
"input": "696616491401388220 958775125",
"output": "1191798158"
},
{
"input": "999999999000000000 1",
"output": "1999999998"
},
{
"input": "961245465290770608 1687994843",
"output": "1386539192"
},
{
"input": "692106376966414549 974053139",
"output": "1186035874"
},
{
"input": "12 1",
"output": "6"
},
{
"input": "806680349368385877 1068656310",
"output": "1278847474"
}
] | 1,638,572,660 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | def process(n, H):
s = 1
e = n+2
while s+1 < e:
m = (s+e)//2
if m*(m+1)//2 <= n:
s, e = m, e
else:
s, e = s, m
assert s*(s+1)//2 <= n < e*(e+1)//2
if s <= H:
n2 = n
answer1 = s
n2-=(s)*(s+1)//2
answer1+=(n//s)
n2 = n2 % s
if n2 != 0:
answer1+=1
else:
answer1 = float('inf')
X2 = n+(H)*(H-1)//2
X = int(X2**0.5)
if X > H:
n-=(X**2-H*(H-1)//2)
answer2 = 2*X-H
answer2+=n//X
n = n % X
if n > 0:
answer2+=1
else:
answer2 = float('inf')
return min(answer1, answer2)
n, H = [int(x) for x in input().split()]
print(process(n, H)) | Title: Sand Fortress
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right.
Obviously, there is not enough sand on the beach, so you brought *n* packs of sand with you. Let height *h**i* of the sand pillar on some spot *i* be the number of sand packs you spent on it. You can't split a sand pack to multiple pillars, all the sand from it should go to a single one. There is a fence of height equal to the height of pillar with *H* sand packs to the left of the first spot and you should prevent sand from going over it.
Finally you ended up with the following conditions to building the castle:
- *h*1<=≤<=*H*: no sand from the leftmost spot should go over the fence; - For any |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1: large difference in heights of two neighboring pillars can lead sand to fall down from the higher one to the lower, you really don't want this to happen; - : you want to spend all the sand you brought with you.
As you have infinite spots to build, it is always possible to come up with some valid castle structure. Though you want the castle to be as compact as possible.
Your task is to calculate the minimum number of spots you can occupy so that all the aforementioned conditions hold.
Input Specification:
The only line contains two integer numbers *n* and *H* (1<=≤<=*n*,<=*H*<=≤<=1018) — the number of sand packs you have and the height of the fence, respectively.
Output Specification:
Print the minimum number of spots you can occupy so the all the castle building conditions hold.
Demo Input:
['5 2\n', '6 8\n']
Demo Output:
['3\n', '3\n']
Note:
Here are the heights of some valid castles:
- *n* = 5, *H* = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...] - *n* = 6, *H* = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied)
The first list for both cases is the optimal answer, 3 spots are occupied in them.
And here are some invalid ones:
- *n* = 5, *H* = 2, [3, 2, 0, ...], [2, 3, 0, ...], [1, 0, 2, 2, ...] - *n* = 6, *H* = 8, [2, 2, 2, 0, ...], [6, 0, ...], [1, 4, 1, 0...], [2, 2, 1, 0, ...] | ```python
def process(n, H):
s = 1
e = n+2
while s+1 < e:
m = (s+e)//2
if m*(m+1)//2 <= n:
s, e = m, e
else:
s, e = s, m
assert s*(s+1)//2 <= n < e*(e+1)//2
if s <= H:
n2 = n
answer1 = s
n2-=(s)*(s+1)//2
answer1+=(n//s)
n2 = n2 % s
if n2 != 0:
answer1+=1
else:
answer1 = float('inf')
X2 = n+(H)*(H-1)//2
X = int(X2**0.5)
if X > H:
n-=(X**2-H*(H-1)//2)
answer2 = 2*X-H
answer2+=n//X
n = n % X
if n > 0:
answer2+=1
else:
answer2 = float('inf')
return min(answer1, answer2)
n, H = [int(x) for x in input().split()]
print(process(n, H))
``` | 0 |
|
215 | C | Crosses | PROGRAMMING | 2,100 | [
"brute force",
"implementation"
] | null | null | There is a board with a grid consisting of *n* rows and *m* columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number *i* and column number *j* as (*i*,<=*j*).
A group of six numbers (*a*,<=*b*,<=*c*,<=*d*,<=*x*0,<=*y*0), where 0<=≤<=*a*,<=*b*,<=*c*,<=*d*, is a cross, and there is a set of cells that are assigned to it. Cell (*x*,<=*y*) belongs to this set if at least one of two conditions are fulfilled:
- |*x*0<=-<=*x*|<=≤<=*a* and |*y*0<=-<=*y*|<=≤<=*b* - |*x*0<=-<=*x*|<=≤<=*c* and |*y*0<=-<=*y*|<=≤<=*d*
Your task is to find the number of different groups of six numbers, (*a*,<=*b*,<=*c*,<=*d*,<=*x*0,<=*y*0) that determine the crosses of an area equal to *s*, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (*x*,<=*y*) of the cross 1<=≤<=*x*<=≤<=*n*; 1<=≤<=*y*<=≤<=*m* holds). The area of the cross is the number of cells it has.
Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points. | The input consists of a single line containing three integers *n*, *m* and *s* (1<=≤<=*n*,<=*m*<=≤<=500, 1<=≤<=*s*<=≤<=*n*·*m*). The integers are separated by a space. | Print a single integer — the number of distinct groups of six integers that denote crosses with area *s* and that are fully placed on the *n*<=×<=*m* grid.
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. | [
"2 2 1\n",
"3 4 5\n"
] | [
"4\n",
"4\n"
] | In the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).
In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3). | 3,000 | [
{
"input": "2 2 1",
"output": "4"
},
{
"input": "3 4 5",
"output": "4"
},
{
"input": "2 2 3",
"output": "0"
},
{
"input": "5 1 3",
"output": "9"
},
{
"input": "9 7 55",
"output": "4"
},
{
"input": "5 10 25",
"output": "102"
},
{
"input": "20 12 101",
"output": "424"
},
{
"input": "21 10 155",
"output": "36"
},
{
"input": "49 7 105",
"output": "14229"
},
{
"input": "74 99 5057",
"output": "20000"
},
{
"input": "9 10 5",
"output": "632"
},
{
"input": "10 14 47",
"output": "256"
},
{
"input": "6 14 23",
"output": "112"
},
{
"input": "27 9 57",
"output": "3435"
},
{
"input": "20 17 319",
"output": "4"
},
{
"input": "2 20 37",
"output": "0"
},
{
"input": "10 4 33",
"output": "0"
},
{
"input": "30 8 53",
"output": "896"
},
{
"input": "48 76 2921",
"output": "1288"
},
{
"input": "2 78 117",
"output": "0"
},
{
"input": "2 55 9",
"output": "846"
},
{
"input": "56 54 2639",
"output": "392"
},
{
"input": "72 65 2843",
"output": "25704"
},
{
"input": "32 71 297",
"output": "507408"
},
{
"input": "48 81 2573",
"output": "9380"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 100 5",
"output": "115208"
},
{
"input": "100 100 19",
"output": "550416"
},
{
"input": "20 20 8",
"output": "0"
},
{
"input": "30 90 29",
"output": "145304"
},
{
"input": "100 100 199",
"output": "1788896"
},
{
"input": "100 100 3421",
"output": "723136"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "1 2 2",
"output": "0"
},
{
"input": "2 1 2",
"output": "0"
},
{
"input": "500 500 1",
"output": "250000"
},
{
"input": "500 499 3",
"output": "1491006"
},
{
"input": "499 500 5",
"output": "2970032"
},
{
"input": "499 499 5",
"output": "2964068"
},
{
"input": "499 498 7",
"output": "4419230"
},
{
"input": "500 500 9",
"output": "7640108"
},
{
"input": "500 498 11",
"output": "8304516"
},
{
"input": "498 500 13",
"output": "9728792"
},
{
"input": "497 498 45",
"output": "74632432"
},
{
"input": "500 499 93",
"output": "143189600"
},
{
"input": "500 500 250000",
"output": "0"
},
{
"input": "500 500 9999",
"output": "4540761776"
},
{
"input": "500 500 9997",
"output": "1380438648"
},
{
"input": "500 500 9001",
"output": "1254836160"
},
{
"input": "3 3 5",
"output": "2"
},
{
"input": "500 500 249999",
"output": "0"
},
{
"input": "500 500 249998",
"output": "0"
},
{
"input": "500 500 249997",
"output": "0"
},
{
"input": "500 500 249995",
"output": "0"
},
{
"input": "500 500 249993",
"output": "0"
},
{
"input": "500 500 6913",
"output": "2147074656"
},
{
"input": "500 500 4755",
"output": "2145363424"
},
{
"input": "500 500 2639",
"output": "2141188528"
},
{
"input": "500 500 2431",
"output": "2137019440"
},
{
"input": "500 500 11025",
"output": "10736521384"
}
] | 1,691,222,989 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1691222989.3843176")# 1691222989.3843343 | Title: Crosses
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a board with a grid consisting of *n* rows and *m* columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number *i* and column number *j* as (*i*,<=*j*).
A group of six numbers (*a*,<=*b*,<=*c*,<=*d*,<=*x*0,<=*y*0), where 0<=≤<=*a*,<=*b*,<=*c*,<=*d*, is a cross, and there is a set of cells that are assigned to it. Cell (*x*,<=*y*) belongs to this set if at least one of two conditions are fulfilled:
- |*x*0<=-<=*x*|<=≤<=*a* and |*y*0<=-<=*y*|<=≤<=*b* - |*x*0<=-<=*x*|<=≤<=*c* and |*y*0<=-<=*y*|<=≤<=*d*
Your task is to find the number of different groups of six numbers, (*a*,<=*b*,<=*c*,<=*d*,<=*x*0,<=*y*0) that determine the crosses of an area equal to *s*, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (*x*,<=*y*) of the cross 1<=≤<=*x*<=≤<=*n*; 1<=≤<=*y*<=≤<=*m* holds). The area of the cross is the number of cells it has.
Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
Input Specification:
The input consists of a single line containing three integers *n*, *m* and *s* (1<=≤<=*n*,<=*m*<=≤<=500, 1<=≤<=*s*<=≤<=*n*·*m*). The integers are separated by a space.
Output Specification:
Print a single integer — the number of distinct groups of six integers that denote crosses with area *s* and that are fully placed on the *n*<=×<=*m* grid.
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:
['2 2 1\n', '3 4 5\n']
Demo Output:
['4\n', '4\n']
Note:
In the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).
In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3). | ```python
print("_RANDOM_GUESS_1691222989.3843176")# 1691222989.3843343
``` | 0 |
|
84 | A | Toy Army | PROGRAMMING | 900 | [
"math",
"number theory"
] | A. Toy Army | 2 | 256 | The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore.
The game "GAGA" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends.
You are asked to calculate the maximum total number of soldiers that may be killed during the game. | The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields. | Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns. | [
"2\n",
"4\n"
] | [
"3\n",
"6\n"
] | The first sample test:
1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.
2) Arcady's soldier 2 shoots at Valera's soldier 1.
3) Valera's soldier 1 shoots at Arcady's soldier 2.
There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2. | 500 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "6"
},
{
"input": "6",
"output": "9"
},
{
"input": "8",
"output": "12"
},
{
"input": "10",
"output": "15"
},
{
"input": "140",
"output": "210"
},
{
"input": "500",
"output": "750"
},
{
"input": "1000",
"output": "1500"
},
{
"input": "2000",
"output": "3000"
},
{
"input": "50000",
"output": "75000"
},
{
"input": "10000",
"output": "15000"
},
{
"input": "25460",
"output": "38190"
},
{
"input": "54646",
"output": "81969"
},
{
"input": "59790",
"output": "89685"
},
{
"input": "578456",
"output": "867684"
},
{
"input": "56798056",
"output": "85197084"
},
{
"input": "8457980",
"output": "12686970"
},
{
"input": "5687986",
"output": "8531979"
},
{
"input": "10984932",
"output": "16477398"
},
{
"input": "99999994",
"output": "149999991"
},
{
"input": "99999996",
"output": "149999994"
},
{
"input": "99999998",
"output": "149999997"
},
{
"input": "100000000",
"output": "150000000"
}
] | 1,561,106,224 | 2,147,483,647 | PyPy 3 | OK | TESTS | 23 | 248 | 0 | x=int(input())
y=x+(x//2)
print(int(y)) | Title: Toy Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore.
The game "GAGA" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends.
You are asked to calculate the maximum total number of soldiers that may be killed during the game.
Input Specification:
The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields.
Output Specification:
Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns.
Demo Input:
['2\n', '4\n']
Demo Output:
['3\n', '6\n']
Note:
The first sample test:
1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.
2) Arcady's soldier 2 shoots at Valera's soldier 1.
3) Valera's soldier 1 shoots at Arcady's soldier 2.
There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2. | ```python
x=int(input())
y=x+(x//2)
print(int(y))
``` | 3.938 |
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,586,177,675 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | n = int(input())
s = input()
if s[0] == 'S':
print('YES')
else:
print('No') | 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
n = int(input())
s = input()
if s[0] == 'S':
print('YES')
else:
print('No')
``` | 0 |
|
846 | B | Math Show | PROGRAMMING | 1,800 | [
"brute force",
"greedy"
] | null | null | Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all *k* of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is *k*<=+<=1.
Polycarp has *M* minutes of time. What is the maximum number of points he can earn? | The first line contains three integer numbers *n*, *k* and *M* (1<=≤<=*n*<=≤<=45, 1<=≤<=*k*<=≤<=45, 0<=≤<=*M*<=≤<=2·109).
The second line contains *k* integer numbers, values *t**j* (1<=≤<=*t**j*<=≤<=1000000), where *t**j* is the time in minutes required to solve *j*-th subtask of any task. | Print the maximum amount of points Polycarp can earn in *M* minutes. | [
"3 4 11\n1 2 3 4\n",
"5 5 10\n1 2 4 8 16\n"
] | [
"6\n",
"7\n"
] | In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | 0 | [
{
"input": "3 4 11\n1 2 3 4",
"output": "6"
},
{
"input": "5 5 10\n1 2 4 8 16",
"output": "7"
},
{
"input": "1 1 0\n2",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "2"
},
{
"input": "2 1 0\n2",
"output": "0"
},
{
"input": "2 2 2\n2 3",
"output": "1"
},
{
"input": "4 2 15\n1 4",
"output": "9"
},
{
"input": "24 42 126319796\n318996 157487 174813 189765 259136 406743 138997 377982 244813 16862 95438 346702 454882 274633 67361 387756 61951 448901 427272 288847 316578 416035 56608 211390 187241 191538 299856 294995 442139 95784 410894 439744 455044 301002 196932 352004 343622 73438 325186 295727 21130 32856",
"output": "677"
},
{
"input": "5 3 10\n1 3 6",
"output": "6"
},
{
"input": "5 3 50\n1 3 6",
"output": "20"
},
{
"input": "5 3 2000000000\n1 3 6",
"output": "20"
},
{
"input": "5 3 49\n1 3 6",
"output": "18"
},
{
"input": "3 4 16\n1 2 3 4",
"output": "9"
},
{
"input": "11 2 20\n1 9",
"output": "13"
},
{
"input": "11 3 38\n1 9 9",
"output": "15"
},
{
"input": "5 3 11\n1 1 2",
"output": "11"
},
{
"input": "5 4 36\n1 3 7 7",
"output": "13"
},
{
"input": "1 13 878179\n103865 43598 180009 528483 409585 449955 368163 381135 713512 645876 241515 20336 572091",
"output": "5"
},
{
"input": "1 9 262522\n500878 36121 420012 341288 139726 362770 462113 261122 394426",
"output": "2"
},
{
"input": "45 32 252252766\n282963 74899 446159 159106 469932 288063 297289 501442 241341 240108 470371 316076 159136 72720 37365 108455 82789 529789 303825 392553 153053 389577 327929 277446 505280 494678 159006 505007 328366 460640 18354 313300",
"output": "1094"
},
{
"input": "44 41 93891122\n447 314862 48587 198466 73450 166523 247421 50078 14115 229926 11070 53089 73041 156924 200782 53225 290967 219349 119034 88726 255048 59778 287298 152539 55104 170525 135722 111341 279873 168400 267489 157697 188015 94306 231121 304553 27684 46144 127122 166022 150941",
"output": "1084"
},
{
"input": "12 45 2290987\n50912 189025 5162 252398 298767 154151 164139 185891 121047 227693 93549 284244 312843 313833 285436 131672 135248 324541 194905 205729 241315 32044 131902 305884 263 27717 173077 81428 285684 66470 220938 282471 234921 316283 30485 244283 170631 224579 72899 87066 6727 161661 40556 89162 314616",
"output": "95"
},
{
"input": "42 9 4354122\n47443 52983 104606 84278 5720 55971 100555 90845 91972",
"output": "124"
},
{
"input": "45 28 33631968\n5905 17124 64898 40912 75855 53868 27056 18284 63975 51975 27182 94373 52477 260 87551 50223 73798 77430 17510 15226 6269 43301 39592 27043 15546 60047 83400 63983",
"output": "979"
},
{
"input": "18 3 36895\n877 2054 4051",
"output": "28"
},
{
"input": "13 30 357\n427 117 52 140 162 58 5 149 438 327 103 357 202 1 148 238 442 200 438 97 414 301 224 166 254 322 378 422 90 312",
"output": "31"
},
{
"input": "44 11 136\n77 38 12 71 81 15 66 47 29 22 71",
"output": "11"
},
{
"input": "32 6 635\n3 4 2 1 7 7",
"output": "195"
},
{
"input": "30 19 420\n2 2 1 2 2 1 1 2 1 2 2 2 1 2 2 2 2 1 2",
"output": "309"
},
{
"input": "37 40 116\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": "118"
},
{
"input": "7 37 133\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",
"output": "136"
},
{
"input": "40 1 8\n3",
"output": "4"
},
{
"input": "1 28 1\n3 3 2 2 1 1 3 1 1 2 2 1 1 3 3 1 1 1 1 1 3 1 3 3 3 2 2 3",
"output": "1"
},
{
"input": "12 1 710092\n145588",
"output": "8"
},
{
"input": "1 7 47793\n72277 45271 85507 39251 45440 101022 105165",
"output": "1"
},
{
"input": "1 1 0\n4",
"output": "0"
},
{
"input": "1 2 3\n2 2",
"output": "1"
},
{
"input": "1 1 0\n5",
"output": "0"
},
{
"input": "1 1 3\n5",
"output": "0"
},
{
"input": "1 3 0\n6 3 4",
"output": "0"
},
{
"input": "1 2 0\n1 2",
"output": "0"
},
{
"input": "1 1 3\n5",
"output": "0"
},
{
"input": "1 1 0\n5",
"output": "0"
},
{
"input": "2 2 3\n7 2",
"output": "1"
},
{
"input": "2 4 5\n1 2 8 6",
"output": "3"
},
{
"input": "2 1 0\n3",
"output": "0"
},
{
"input": "1 3 3\n16 4 5",
"output": "0"
},
{
"input": "2 1 0\n1",
"output": "0"
},
{
"input": "3 2 2\n6 1",
"output": "2"
},
{
"input": "3 2 1\n1 1",
"output": "1"
},
{
"input": "1 3 19\n12 15 6",
"output": "2"
},
{
"input": "2 2 8\n12 1",
"output": "2"
},
{
"input": "1 6 14\n15 2 6 13 14 4",
"output": "3"
},
{
"input": "4 1 0\n1",
"output": "0"
},
{
"input": "1 1 0\n2",
"output": "0"
},
{
"input": "1 1 0\n2",
"output": "0"
},
{
"input": "2 2 5\n5 6",
"output": "1"
},
{
"input": "1 3 8\n5 4 4",
"output": "2"
},
{
"input": "1 5 44\n2 19 18 6 8",
"output": "4"
},
{
"input": "1 1 0\n4",
"output": "0"
},
{
"input": "3 2 7\n5 1",
"output": "4"
},
{
"input": "4 2 9\n8 6",
"output": "1"
},
{
"input": "4 3 3\n6 12 7",
"output": "0"
},
{
"input": "4 1 2\n1",
"output": "4"
},
{
"input": "2 4 15\n8 3 7 8",
"output": "3"
},
{
"input": "6 1 2\n4",
"output": "0"
},
{
"input": "2 1 1\n1",
"output": "2"
},
{
"input": "1 1 2\n3",
"output": "0"
},
{
"input": "2 2 2\n1 4",
"output": "2"
},
{
"input": "6 2 78\n12 10",
"output": "10"
},
{
"input": "1 3 10\n17 22 15",
"output": "0"
},
{
"input": "6 3 13\n1 2 3",
"output": "10"
},
{
"input": "21 3 26\n1 2 3",
"output": "24"
},
{
"input": "3 7 20012\n1 1 1 1 1 1 10000",
"output": "20"
},
{
"input": "5 4 40\n4 2 3 3",
"output": "17"
},
{
"input": "4 5 40\n4 1 3 2 4",
"output": "18"
},
{
"input": "3 5 22\n1 1 4 1 1",
"output": "16"
},
{
"input": "5 2 17\n3 4",
"output": "7"
},
{
"input": "5 4 32\n4 2 1 1",
"output": "21"
},
{
"input": "5 5 34\n4 1 1 2 4",
"output": "20"
},
{
"input": "3 3 15\n1 2 1",
"output": "12"
},
{
"input": "3 2 11\n1 2",
"output": "9"
},
{
"input": "5 4 11\n2 1 3 4",
"output": "8"
},
{
"input": "45 45 2000000000\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",
"output": "2070"
}
] | 1,504,624,912 | 1,012 | Python 3 | WRONG_ANSWER | TESTS | 6 | 61 | 0 | t, s, time = input().split()
t, s, time = int(t), int(s), int(time)
subtasks = list(map(int, input().split()))
subtasks.sort(reverse=True)
new = time
score = 0
solved = 0
while new > 0:
taken = subtasks.pop()
solved += 1
if new >= taken * t:
new -= taken * t
score += t
last = t
else:
score += new // taken
last = new // taken
new -= (new // taken)
break
if solved == t:
score += last
print(score)
| Title: Math Show
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all *k* of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is *k*<=+<=1.
Polycarp has *M* minutes of time. What is the maximum number of points he can earn?
Input Specification:
The first line contains three integer numbers *n*, *k* and *M* (1<=≤<=*n*<=≤<=45, 1<=≤<=*k*<=≤<=45, 0<=≤<=*M*<=≤<=2·109).
The second line contains *k* integer numbers, values *t**j* (1<=≤<=*t**j*<=≤<=1000000), where *t**j* is the time in minutes required to solve *j*-th subtask of any task.
Output Specification:
Print the maximum amount of points Polycarp can earn in *M* minutes.
Demo Input:
['3 4 11\n1 2 3 4\n', '5 5 10\n1 2 4 8 16\n']
Demo Output:
['6\n', '7\n']
Note:
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | ```python
t, s, time = input().split()
t, s, time = int(t), int(s), int(time)
subtasks = list(map(int, input().split()))
subtasks.sort(reverse=True)
new = time
score = 0
solved = 0
while new > 0:
taken = subtasks.pop()
solved += 1
if new >= taken * t:
new -= taken * t
score += t
last = t
else:
score += new // taken
last = new // taken
new -= (new // taken)
break
if solved == t:
score += last
print(score)
``` | 0 |
|
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,636,738,627 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 78 | 5,017,600 | num=input()
st=input()
coun1,coun2=0,0
for i in st:
if i=='0':
coun1+=1
else:
coun2+=1
print(max(coun1,coun2)-min(coun1,coun2)) | 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
num=input()
st=input()
coun1,coun2=0,0
for i in st:
if i=='0':
coun1+=1
else:
coun2+=1
print(max(coun1,coun2)-min(coun1,coun2))
``` | 3 |
|
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -929612742 -787653860 -684738874",
"output": "11 9 8 2 2 1 5 5 0 0 1"
},
{
"input": "20 22\n858276994 -568758442 -918490847 -983345984 -172435358 389604931 200224783 486556113 413281867 -258259500 -627945379 -584563643 444685477 -602481243 -370745158 965672503 630955806 -626138773 -997221880 633102929\n-61330638 -977252080 -212144219 385501731 669589742 954357160 563935906 584468977 -895883477 405774444 853372186 186056475 -964575261 -952431965 632332084 -388829939 -23011650 310957048 -770695392 977376693 321435214 199223897",
"output": "11 2 10 12 18 19 16 16 3 13 18 11 2 2 17 8 11 12 3 20 12 11"
},
{
"input": "5 9\n1 3 5 7 9\n1 2 3 4 5 6 7 8 9",
"output": "1 1 2 2 3 3 4 4 5"
},
{
"input": "22 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22\n1",
"output": "1"
},
{
"input": "5 1\n1 3 3 3 5\n3",
"output": "4"
},
{
"input": "4 5\n1 1 1 4\n1 5 5 4 3",
"output": "3 4 4 4 3"
},
{
"input": "5 4\n0 5 5 5 6\n5 1 6 3",
"output": "4 1 5 1"
},
{
"input": "1 3\n0\n-1 0 1",
"output": "0 1 1"
},
{
"input": "96 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\n1",
"output": "96"
},
{
"input": "7 1\n1 2 3 4 5 6 7\n1",
"output": "1"
},
{
"input": "13 13\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000",
"output": "7 13 7 13 7 13 7 13 7 13 7 13 7"
},
{
"input": "9 5\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5",
"output": "1 2 3 4 5"
},
{
"input": "3 8\n1 1 1\n1 1 1 1 1 1 1 1",
"output": "3 3 3 3 3 3 3 3"
},
{
"input": "1 1\n-11111\n-5938",
"output": "1"
},
{
"input": "1 1\n1\n400000009",
"output": "1"
},
{
"input": "1 1\n1\n300000009",
"output": "1"
},
{
"input": "1 1\n1\n200000009",
"output": "1"
},
{
"input": "1 1\n1\n200000003",
"output": "1"
}
] | 1,698,978,691 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 17,203,200 | input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
for i in b:
for j in a:
if j <= i:
count += 1
print(count, end=" ")
count = 0
| Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Output Specification:
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
Demo Input:
['5 4\n1 3 5 7 9\n6 4 2 8\n', '5 5\n1 2 1 2 5\n3 1 4 1 5\n']
Demo Output:
['3 2 1 4\n', '4 2 4 2 5\n']
Note:
none | ```python
input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
for i in b:
for j in a:
if j <= i:
count += 1
print(count, end=" ")
count = 0
``` | 0 |
|
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,626,864,029 | 929 | PyPy 3 | OK | TESTS | 30 | 218 | 21,606,400 | import sys
length = int(sys.stdin.readline())
nums = set(map(int, sys.stdin.readline().split()))
for i in range(1,max(nums)+1):
if i not in nums:
print(i)
exit(0)
print(max(nums)+1)
| 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
length = int(sys.stdin.readline())
nums = set(map(int, sys.stdin.readline().split()))
for i in range(1,max(nums)+1):
if i not in nums:
print(i)
exit(0)
print(max(nums)+1)
``` | 3.905255 |
420 | A | Start Up | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | [
"AHA\n",
"Z\n",
"XO\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "AHA",
"output": "YES"
},
{
"input": "Z",
"output": "NO"
},
{
"input": "XO",
"output": "NO"
},
{
"input": "AAA",
"output": "YES"
},
{
"input": "AHHA",
"output": "YES"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "OMMMAAMMMO",
"output": "YES"
},
{
"input": "YYHUIUGYI",
"output": "NO"
},
{
"input": "TT",
"output": "YES"
},
{
"input": "UUU",
"output": "YES"
},
{
"input": "WYYW",
"output": "YES"
},
{
"input": "MITIM",
"output": "YES"
},
{
"input": "VO",
"output": "NO"
},
{
"input": "WWS",
"output": "NO"
},
{
"input": "VIYMAXXAVM",
"output": "NO"
},
{
"input": "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM",
"output": "NO"
},
{
"input": "CC",
"output": "NO"
},
{
"input": "QOQ",
"output": "NO"
},
{
"input": "AEEA",
"output": "NO"
},
{
"input": "OQQQO",
"output": "NO"
},
{
"input": "HNCMEEMCNH",
"output": "NO"
},
{
"input": "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ",
"output": "NO"
},
{
"input": "A",
"output": "YES"
},
{
"input": "B",
"output": "NO"
},
{
"input": "C",
"output": "NO"
},
{
"input": "D",
"output": "NO"
},
{
"input": "E",
"output": "NO"
},
{
"input": "F",
"output": "NO"
},
{
"input": "G",
"output": "NO"
},
{
"input": "H",
"output": "YES"
},
{
"input": "I",
"output": "YES"
},
{
"input": "J",
"output": "NO"
},
{
"input": "K",
"output": "NO"
},
{
"input": "L",
"output": "NO"
},
{
"input": "M",
"output": "YES"
},
{
"input": "N",
"output": "NO"
},
{
"input": "O",
"output": "YES"
},
{
"input": "P",
"output": "NO"
},
{
"input": "Q",
"output": "NO"
},
{
"input": "R",
"output": "NO"
},
{
"input": "S",
"output": "NO"
},
{
"input": "T",
"output": "YES"
},
{
"input": "U",
"output": "YES"
},
{
"input": "V",
"output": "YES"
},
{
"input": "W",
"output": "YES"
},
{
"input": "X",
"output": "YES"
},
{
"input": "Y",
"output": "YES"
},
{
"input": "JL",
"output": "NO"
},
{
"input": "AAAKTAAA",
"output": "NO"
},
{
"input": "AKA",
"output": "NO"
},
{
"input": "AAJAA",
"output": "NO"
},
{
"input": "ABA",
"output": "NO"
},
{
"input": "AAAAAABAAAAAA",
"output": "NO"
},
{
"input": "ZZ",
"output": "NO"
},
{
"input": "ADA",
"output": "NO"
},
{
"input": "N",
"output": "NO"
},
{
"input": "P",
"output": "NO"
},
{
"input": "LAL",
"output": "NO"
},
{
"input": "AABAA",
"output": "NO"
},
{
"input": "AZA",
"output": "NO"
},
{
"input": "V",
"output": "YES"
},
{
"input": "SSS",
"output": "NO"
},
{
"input": "NNN",
"output": "NO"
},
{
"input": "S",
"output": "NO"
},
{
"input": "I",
"output": "YES"
},
{
"input": "SS",
"output": "NO"
},
{
"input": "E",
"output": "NO"
}
] | 1,399,211,559 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | A = input()
test = 'YES'
for i in range(len(A) // 2):
if A[i] != A[len(A) - i - 1]:
test = 'NO'
break
print(test) | Title: Start Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
Input Specification:
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
Output Specification:
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
Demo Input:
['AHA\n', 'Z\n', 'XO\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
A = input()
test = 'YES'
for i in range(len(A) // 2):
if A[i] != A[len(A) - i - 1]:
test = 'NO'
break
print(test)
``` | 0 |
|
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "480",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "49",
"output": "YES"
},
{
"input": "56",
"output": "YES"
},
{
"input": "124",
"output": "YES"
},
{
"input": "1000",
"output": "YES"
},
{
"input": "999",
"output": "NO"
},
{
"input": "298",
"output": "NO"
},
{
"input": "274",
"output": "NO"
},
{
"input": "998",
"output": "NO"
},
{
"input": "42",
"output": "YES"
},
{
"input": "788",
"output": "YES"
},
{
"input": "70",
"output": "YES"
},
{
"input": "444",
"output": "YES"
},
{
"input": "777",
"output": "YES"
},
{
"input": "799",
"output": "YES"
},
{
"input": "25",
"output": "NO"
},
{
"input": "882",
"output": "YES"
},
{
"input": "88",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "7",
"output": "YES"
},
{
"input": "8",
"output": "YES"
},
{
"input": "94",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "141",
"output": "YES"
}
] | 1,694,004,526 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | # -*- coding: utf-8 -*-
"""
Created on Wed Sep 6 20:33:35 2023
@author: He'Bing'Ru
"""
num = input()
num_ = list(num)
if num%4 == 0 or num%7 == 0 :
print('YES')
else:
for i in num_ :
if i == '4' or i == '7' :
print('YES') | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
Input Specification:
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
Output Specification:
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['47\n', '16\n', '78\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 6 20:33:35 2023
@author: He'Bing'Ru
"""
num = input()
num_ = list(num)
if num%4 == 0 or num%7 == 0 :
print('YES')
else:
for i in num_ :
if i == '4' or i == '7' :
print('YES')
``` | -1 |
|
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,692,928,752 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 102,400 | def timing():
t, sx, sy, ex, ey = map(int, input().split())
s = input()
for x in range(len(s)):
if s[x] == "E" and ex > sx:
sx = sx + 1
sy = sy
if s[x] == "S" and ey < sy:
sx = sx
sy = sy - 1
if s[x] == "W" and ex < sx:
sx = sx - 1
sy = sy
if s[x] == "N" and ey > sy:
sx = sx
sy = sy + 1
if ex == sx and ey == sy:
return x + 1
return -1
print(timing())
| Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1).
Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)?
Input Specification:
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).
Output Specification:
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
Demo Input:
['5 0 0 1 1\nSESNW\n', '10 5 3 3 6\nNENSWESNEE\n']
Demo Output:
['4\n', '-1\n']
Note:
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | ```python
def timing():
t, sx, sy, ex, ey = map(int, input().split())
s = input()
for x in range(len(s)):
if s[x] == "E" and ex > sx:
sx = sx + 1
sy = sy
if s[x] == "S" and ey < sy:
sx = sx
sy = sy - 1
if s[x] == "W" and ex < sx:
sx = sx - 1
sy = sy
if s[x] == "N" and ey > sy:
sx = sx
sy = sy + 1
if ex == sx and ey == sy:
return x + 1
return -1
print(timing())
``` | 3 |
|
837 | F | Prefix Sums | PROGRAMMING | 2,400 | [
"binary search",
"brute force",
"combinatorics",
"math",
"matrices"
] | null | null | Consider the function *p*(*x*), where *x* is an array of *m* integers, which returns an array *y* consisting of *m*<=+<=1 integers such that *y**i* is equal to the sum of first *i* elements of array *x* (0<=≤<=*i*<=≤<=*m*).
You have an infinite sequence of arrays *A*0,<=*A*1,<=*A*2..., where *A*0 is given in the input, and for each *i*<=≥<=1 *A**i*<==<=*p*(*A**i*<=-<=1). Also you have a positive integer *k*. You have to find minimum possible *i* such that *A**i* contains a number which is larger or equal than *k*. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=200000, 1<=≤<=*k*<=≤<=1018). *n* is the size of array *A*0.
The second line contains *n* integers *A*00,<=*A*01... *A*0*n*<=-<=1 — the elements of *A*0 (0<=≤<=*A*0*i*<=≤<=109). At least two elements of *A*0 are positive. | Print the minimum *i* such that *A**i* contains a number which is larger or equal than *k*. | [
"2 2\n1 1\n",
"3 6\n1 1 1\n",
"3 1\n1 0 1\n"
] | [
"1\n",
"2\n",
"0\n"
] | none | 0 | [
{
"input": "2 2\n1 1",
"output": "1"
},
{
"input": "3 6\n1 1 1",
"output": "2"
},
{
"input": "3 1\n1 0 1",
"output": "0"
},
{
"input": "3 1000000000000000000\n5 4 5",
"output": "632455531"
},
{
"input": "4 1000000000000000000\n0 4 4 5",
"output": "707106780"
},
{
"input": "5 1000000000000000000\n5 7 4 2 5",
"output": "46805"
},
{
"input": "3 999999999000999944\n7 2 6",
"output": "534522483"
},
{
"input": "4 999999999000531216\n8 7 4 6",
"output": "908559"
},
{
"input": "5 152742477016321721\n0 0 2 6 2",
"output": "390822817"
},
{
"input": "6 1000000000000000000\n1 1 0 1 0 1",
"output": "10369"
},
{
"input": "7 1000000000000000000\n77 94 59 82 91 44 93",
"output": "1448"
},
{
"input": "3 999999999000999944\n5 1 2",
"output": "632455532"
},
{
"input": "4 999999999000531216\n1 1 0 1",
"output": "1817119"
},
{
"input": "5 152742477016321721\n1 4 0 5 6",
"output": "43752"
},
{
"input": "6 1000000000000000000\n1 1 1 0 1 1",
"output": "10369"
},
{
"input": "7 1000000000000000000\n20 24 97 16 37 37 84",
"output": "1814"
},
{
"input": "10 1000000000000000000\n1 0 1 0 1 0 0 0 0 0",
"output": "411"
},
{
"input": "10 3\n1 1 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 1000000000000000000\n1 1 0",
"output": "1414213561"
},
{
"input": "8 1000000000000000000\n1 1 0 0 0 0 0 0",
"output": "1256"
},
{
"input": "4 1000000000000000000\n612929642 983621174 279363954 332455288",
"output": "2137"
},
{
"input": "3 1000000000000000000\n422931534 210865757 697603256",
"output": "68766"
},
{
"input": "3 563768374159627711\n8849237 586207348 386453596",
"output": "356888"
},
{
"input": "3 1000000000000000000\n1 0 1",
"output": "1414213562"
},
{
"input": "5 1000000000000000000\n1 0 0 0 1",
"output": "69992"
},
{
"input": "11 1000000000000000000\n1 0 0 0 0 0 0 0 0 0 1",
"output": "282"
},
{
"input": "15 1000000000000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 1",
"output": "111"
},
{
"input": "18 1000000000000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1",
"output": "75"
},
{
"input": "2 1000000000000000000\n758816935 60667976",
"output": "1317840910"
},
{
"input": "8 1000000000000000000\n1 0 0 0 0 0 0 1",
"output": "1257"
}
] | 1,682,422,258 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 18,534,400 | import sys
from collections import deque
input = sys.stdin.readline
def fgh():
return [int(xx) for xx in input().split()]
def fg():
return int(input())
n, k = fgh()
a = fgh()
if max(a) >= k:
print(0)
quit()
if n == 2:
print((k - a[1] + a[0] - 1) // a[0])
elif n == 3:
l = 0
r = 100000
while r - l > 1:
m = (l + r) // 2
if m * (m - 1) // 2 * a[0] + m * a[1] + a[2] >= k:
r = m
else:
l = m
print(r - 1)
else:
ans = 0
while True:
pr = [0]
for i in range(n):
pr.append(pr[-1] + a[i])
if pr[-1] >= k:
print(ans + 1)
quit()
a = pr[:]
ans += 1
| Title: Prefix Sums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the function *p*(*x*), where *x* is an array of *m* integers, which returns an array *y* consisting of *m*<=+<=1 integers such that *y**i* is equal to the sum of first *i* elements of array *x* (0<=≤<=*i*<=≤<=*m*).
You have an infinite sequence of arrays *A*0,<=*A*1,<=*A*2..., where *A*0 is given in the input, and for each *i*<=≥<=1 *A**i*<==<=*p*(*A**i*<=-<=1). Also you have a positive integer *k*. You have to find minimum possible *i* such that *A**i* contains a number which is larger or equal than *k*.
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=200000, 1<=≤<=*k*<=≤<=1018). *n* is the size of array *A*0.
The second line contains *n* integers *A*00,<=*A*01... *A*0*n*<=-<=1 — the elements of *A*0 (0<=≤<=*A*0*i*<=≤<=109). At least two elements of *A*0 are positive.
Output Specification:
Print the minimum *i* such that *A**i* contains a number which is larger or equal than *k*.
Demo Input:
['2 2\n1 1\n', '3 6\n1 1 1\n', '3 1\n1 0 1\n']
Demo Output:
['1\n', '2\n', '0\n']
Note:
none | ```python
import sys
from collections import deque
input = sys.stdin.readline
def fgh():
return [int(xx) for xx in input().split()]
def fg():
return int(input())
n, k = fgh()
a = fgh()
if max(a) >= k:
print(0)
quit()
if n == 2:
print((k - a[1] + a[0] - 1) // a[0])
elif n == 3:
l = 0
r = 100000
while r - l > 1:
m = (l + r) // 2
if m * (m - 1) // 2 * a[0] + m * a[1] + a[2] >= k:
r = m
else:
l = m
print(r - 1)
else:
ans = 0
while True:
pr = [0]
for i in range(n):
pr.append(pr[-1] + a[i])
if pr[-1] >= k:
print(ans + 1)
quit()
a = pr[:]
ans += 1
``` | 0 |
|
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,625,917,457 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | n = int(input())
w = list(map(int, input().split()))
odd, even = w.count(100), w.count(200)
if even % 2 == 0 and odd % 2 == 0:
print("YES")
elif even % 2 and odd % 2 == 0:
print("YES")
else:
print("NO") | 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
n = int(input())
w = list(map(int, input().split()))
odd, even = w.count(100), w.count(200)
if even % 2 == 0 and odd % 2 == 0:
print("YES")
elif even % 2 and odd % 2 == 0:
print("YES")
else:
print("NO")
``` | 0 |
|
435 | B | Pasha Maximizes | PROGRAMMING | 1,400 | [
"greedy"
] | null | null | Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most *k* swaps. | The single line contains two integers *a* and *k* (1<=≤<=*a*<=≤<=1018; 0<=≤<=*k*<=≤<=100). | Print the maximum number that Pasha can get if he makes at most *k* swaps. | [
"1990 1\n",
"300 0\n",
"1034 2\n",
"9090000078001234 6\n"
] | [
"9190\n",
"300\n",
"3104\n",
"9907000008001234\n"
] | none | 1,000 | [
{
"input": "1990 1",
"output": "9190"
},
{
"input": "300 0",
"output": "300"
},
{
"input": "1034 2",
"output": "3104"
},
{
"input": "9090000078001234 6",
"output": "9907000008001234"
},
{
"input": "1234 3",
"output": "4123"
},
{
"input": "5 100",
"output": "5"
},
{
"input": "1234 5",
"output": "4312"
},
{
"input": "1234 6",
"output": "4321"
},
{
"input": "9022 2",
"output": "9220"
},
{
"input": "66838 4",
"output": "86863"
},
{
"input": "39940894417248510 10",
"output": "99984304417248510"
},
{
"input": "5314 4",
"output": "5431"
},
{
"input": "1026 9",
"output": "6210"
},
{
"input": "4529 8",
"output": "9542"
},
{
"input": "83811284 3",
"output": "88321184"
},
{
"input": "92153348 6",
"output": "98215334"
},
{
"input": "5846059 3",
"output": "8654059"
},
{
"input": "521325125110071928 4",
"output": "552132125110071928"
},
{
"input": "39940894417248510 10",
"output": "99984304417248510"
},
{
"input": "77172428736634377 29",
"output": "87777764122363437"
},
{
"input": "337775999910796051 37",
"output": "999997733751076051"
},
{
"input": "116995340392134308 27",
"output": "999654331120134308"
},
{
"input": "10120921290110921 20",
"output": "99221010120110921"
},
{
"input": "929201010190831892 30",
"output": "999928201010103182"
},
{
"input": "111111111111111119 8",
"output": "111111111911111111"
},
{
"input": "219810011901120912 100",
"output": "999822211111110000"
},
{
"input": "191919191919119911 100",
"output": "999999991111111111"
},
{
"input": "801211288881101019 22",
"output": "982111028888110101"
},
{
"input": "619911311932347059 3",
"output": "969111311932347059"
},
{
"input": "620737553540689123 2",
"output": "672037553540689123"
},
{
"input": "621563797296514835 3",
"output": "662153797296514835"
},
{
"input": "915277434701161 9",
"output": "977541234701161"
},
{
"input": "15603712376708 28",
"output": "87761503123670"
},
{
"input": "784069392990841 0",
"output": "784069392990841"
},
{
"input": "787464780004 2",
"output": "877644780004"
},
{
"input": "74604713975 29",
"output": "97776544310"
},
{
"input": "901000000954321789 5",
"output": "910009000054321789"
},
{
"input": "901000000954321789 10",
"output": "991000000504321789"
},
{
"input": "901000000954321789 28",
"output": "999100050000432178"
},
{
"input": "901000000954321789 40",
"output": "999810000050043217"
},
{
"input": "901000000954321789 70",
"output": "999875410000300021"
},
{
"input": "1234567891234567 99",
"output": "9877665544332211"
},
{
"input": "123456789123456789 100",
"output": "998877665544213123"
},
{
"input": "12345670123456789 100",
"output": "98776655443322101"
},
{
"input": "12 100",
"output": "21"
},
{
"input": "11223344556677889 47",
"output": "98821213344556677"
}
] | 1,401,479,154 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | a, k = map(int, input().split())
num = list(str(a))
def to_int(lst):
return int(''.join(lst))
for i in range(k):
max_diff, max_j = 0, 0
for j in range(len(num)-1):
new = num.copy()
new[j], new[j+1] = new[j+1], new[j]
diff = to_int(new)-to_int(num)
if diff > max_diff:
max_diff, max_j = diff, j
if max_diff > 0:
num[max_j], num[max_j+1] = num[max_j+1], num[max_j]
else:
break
print(to_int(num))
| Title: Pasha Maximizes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most *k* swaps.
Input Specification:
The single line contains two integers *a* and *k* (1<=≤<=*a*<=≤<=1018; 0<=≤<=*k*<=≤<=100).
Output Specification:
Print the maximum number that Pasha can get if he makes at most *k* swaps.
Demo Input:
['1990 1\n', '300 0\n', '1034 2\n', '9090000078001234 6\n']
Demo Output:
['9190\n', '300\n', '3104\n', '9907000008001234\n']
Note:
none | ```python
a, k = map(int, input().split())
num = list(str(a))
def to_int(lst):
return int(''.join(lst))
for i in range(k):
max_diff, max_j = 0, 0
for j in range(len(num)-1):
new = num.copy()
new[j], new[j+1] = new[j+1], new[j]
diff = to_int(new)-to_int(num)
if diff > max_diff:
max_diff, max_j = diff, j
if max_diff > 0:
num[max_j], num[max_j+1] = num[max_j+1], num[max_j]
else:
break
print(to_int(num))
``` | 0 |
|
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,655,719,453 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 61 | 716,800 | from sys import stdin
from math import ceil
from bisect import bisect_left as bl
from collections import defaultdict
input = stdin.readline
read = lambda: map(int, input().strip().split())
n = int(input())
s = input().strip()
x = ""
if n % 2:
x = s[0]
s = s[1:]
for ind, el in enumerate(s):
if ind % 2:
x += el
else:
x = el + x
print(x)
| 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
from sys import stdin
from math import ceil
from bisect import bisect_left as bl
from collections import defaultdict
input = stdin.readline
read = lambda: map(int, input().strip().split())
n = int(input())
s = input().strip()
x = ""
if n % 2:
x = s[0]
s = s[1:]
for ind, el in enumerate(s):
if ind % 2:
x += el
else:
x = el + x
print(x)
``` | 3 |
|
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0. | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "1\n1 2 3"
},
{
"input": "12\n3 3 3 3 3 3 3 3 1 3 3 2",
"output": "1\n9 12 2"
},
{
"input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2",
"output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47"
},
{
"input": "12\n3 1 1 1 1 1 1 2 1 1 1 1",
"output": "1\n3 8 1"
},
{
"input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2",
"output": "1\n18 2 11"
},
{
"input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3",
"output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36"
},
{
"input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1",
"output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200"
},
{
"input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3",
"output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64"
},
{
"input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1",
"output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44"
},
{
"input": "5\n1 2 2 3 3",
"output": "1\n1 3 4"
}
] | 1,696,399,235 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | a = input()
a1 = []
a2 = []
a3 = []
b = list(map(int,input().split()))
t = 1
for i in b:
if i == 1:
a1.append(t)
elif i == 2:
a2.append(t)
else:
a3.append(t)
t += 1
h = min(len(a1),len(a2),len(a3))
print(h)
for k in range(h):
print(a1[i],a2[i],a3[i]) | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
Output Specification:
In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0.
Demo Input:
['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n']
Demo Output:
['2\n3 5 2\n6 7 4\n', '0\n']
Note:
none | ```python
a = input()
a1 = []
a2 = []
a3 = []
b = list(map(int,input().split()))
t = 1
for i in b:
if i == 1:
a1.append(t)
elif i == 2:
a2.append(t)
else:
a3.append(t)
t += 1
h = min(len(a1),len(a2),len(a3))
print(h)
for k in range(h):
print(a1[i],a2[i],a3[i])
``` | -1 |
|
914 | A | Perfect Squares | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | [
"2\n4 2\n",
"8\n1 2 4 8 16 32 64 576\n"
] | [
"2\n",
"32\n"
] | In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | 500 | [
{
"input": "2\n4 2",
"output": "2"
},
{
"input": "8\n1 2 4 8 16 32 64 576",
"output": "32"
},
{
"input": "3\n-1 -4 -9",
"output": "-1"
},
{
"input": "5\n918375 169764 598796 76602 538757",
"output": "918375"
},
{
"input": "5\n804610 765625 2916 381050 93025",
"output": "804610"
},
{
"input": "5\n984065 842724 127449 525625 573049",
"output": "984065"
},
{
"input": "2\n226505 477482",
"output": "477482"
},
{
"input": "2\n370881 659345",
"output": "659345"
},
{
"input": "2\n4 5",
"output": "5"
},
{
"input": "2\n3 4",
"output": "3"
},
{
"input": "2\n999999 1000000",
"output": "999999"
},
{
"input": "3\n-1 -2 -3",
"output": "-1"
},
{
"input": "2\n-1000000 1000000",
"output": "-1000000"
},
{
"input": "2\n-1 0",
"output": "-1"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "1\n-1",
"output": "-1"
},
{
"input": "35\n-871271 -169147 -590893 -400197 -476793 0 -15745 -890852 -124052 -631140 -238569 -597194 -147909 -928925 -587628 -569656 -581425 -963116 -665954 -506797 -196044 -309770 -701921 -926257 -152426 -991371 -624235 -557143 -689886 -59804 -549134 -107407 -182016 -24153 -607462",
"output": "-15745"
},
{
"input": "16\n-882343 -791322 0 -986738 -415891 -823354 -840236 -552554 -760908 -331993 -549078 -863759 -913261 -937429 -257875 -602322",
"output": "-257875"
},
{
"input": "71\n908209 289 44521 240100 680625 274576 212521 91809 506944 499849 3844 15376 592900 58081 240100 984064 732736 257049 600625 180625 130321 580644 261121 75625 46225 853776 485809 700569 817216 268324 293764 528529 25921 399424 175561 99856 295936 20736 611524 13924 470596 574564 5329 15376 676 431649 145161 697225 41616 550564 514089 9409 227529 1681 839056 3721 552049 465124 38809 197136 659344 214369 998001 44944 3844 186624 362404 -766506 739600 10816 299209",
"output": "-766506"
},
{
"input": "30\n192721 -950059 -734656 625 247009 -423468 318096 622521 678976 777924 1444 748303 27556 62001 795664 89401 221841 -483208 467856 477109 196 -461813 831744 772641 574564 -519370 861184 67600 -717966 -259259",
"output": "748303"
},
{
"input": "35\n628849 962361 436921 944784 444889 29241 -514806 171396 685584 -823202 -929730 6982 198025 783225 552049 -957165 782287 -659167 -414846 695556 -336330 41616 963781 71289 119639 952576 -346713 178929 232324 121802 393266 841 649636 179555 998001",
"output": "963781"
},
{
"input": "53\n280988 756430 -515570 -248578 170649 -21608 642677 216770 827291 589500 940901 216097 -118956 -919104 -319264 -761585 289479 499613 588276 883036 480518 -323196 -274570 -406556 -381484 -956025 702135 -445274 -783543 136593 153664 897473 352651 737974 -21123 -284944 501734 898033 604429 624138 40804 248782 -786059 -304592 -209210 -312904 419820 -328648 -47331 -919227 -280955 104827 877304",
"output": "940901"
},
{
"input": "15\n256 -227055 427717 827239 462070 66049 987533 -175306 -552810 -867915 -408251 -693957 -972981 -245827 896904",
"output": "987533"
},
{
"input": "3\n-1 1 0",
"output": "-1"
},
{
"input": "2\n0 -5",
"output": "-5"
},
{
"input": "3\n-1 -2 0",
"output": "-1"
},
{
"input": "2\n-5 0",
"output": "-5"
},
{
"input": "1\n-439",
"output": "-439"
},
{
"input": "1\n-1000000",
"output": "-1000000"
},
{
"input": "1\n-917455",
"output": "-917455"
},
{
"input": "3\n1 1 -1",
"output": "-1"
},
{
"input": "2\n131073 1",
"output": "131073"
},
{
"input": "2\n99999 3",
"output": "99999"
},
{
"input": "2\n-524272 -1000000",
"output": "-524272"
},
{
"input": "2\n15 131073",
"output": "131073"
}
] | 1,656,482,028 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 186 | 3,174,400 | import math
def p(n):
ans = math.sqrt(n)
return ans*ans==n
n= int(input())
arr = list(map(int,input().split()))
ans=-1
arr.sort()
for i in arr:
if not p(i):
ans=i
print(ans)
| Title: Perfect Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square.
Output Specification:
Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists.
Demo Input:
['2\n4 2\n', '8\n1 2 4 8 16 32 64 576\n']
Demo Output:
['2\n', '32\n']
Note:
In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | ```python
import math
def p(n):
ans = math.sqrt(n)
return ans*ans==n
n= int(input())
arr = list(map(int,input().split()))
ans=-1
arr.sort()
for i in arr:
if not p(i):
ans=i
print(ans)
``` | -1 |
|
431 | B | Shower Line | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks.
There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.
Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2*i*<=-<=1)-th man in the line (for the current moment) talks with the (2*i*)-th one.
Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower.
We know that if students *i* and *j* talk, then the *i*-th student's happiness increases by *g**ij* and the *j*-th student's happiness increases by *g**ji*. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower. | The input consists of five lines, each line contains five space-separated integers: the *j*-th number in the *i*-th line shows *g**ij* (0<=≤<=*g**ij*<=≤<=105). It is guaranteed that *g**ii*<==<=0 for all *i*.
Assume that the students are numbered from 1 to 5. | Print a single integer — the maximum possible total happiness of the students. | [
"0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0\n",
"0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0\n"
] | [
"32\n",
"620\n"
] | In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals: | 1,500 | [
{
"input": "0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0",
"output": "32"
},
{
"input": "0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0",
"output": "620"
},
{
"input": "0 4 2 4 9\n6 0 2 5 0\n2 5 0 6 3\n6 3 3 0 10\n0 3 1 3 0",
"output": "63"
},
{
"input": "0 65 90 2 32\n69 0 9 97 67\n77 97 0 16 84\n18 50 94 0 63\n69 12 82 16 0",
"output": "947"
},
{
"input": "0 70 10 0 0\n70 0 50 90 0\n10 50 0 80 0\n0 90 80 0 100\n0 0 0 100 0",
"output": "960"
},
{
"input": "0 711 647 743 841\n29 0 109 38 682\n329 393 0 212 512\n108 56 133 0 579\n247 92 933 164 0",
"output": "6265"
},
{
"input": "0 9699 6962 6645 7790\n9280 0 6215 8661 6241\n2295 7817 0 7373 9681\n693 6298 1381 0 4633\n7626 3761 694 4073 0",
"output": "93667"
},
{
"input": "0 90479 71577 33797 88848\n45771 0 96799 78707 72708\n5660 26421 0 10991 22757\n78919 24804 90645 0 48665\n92787 43671 38727 17302 0",
"output": "860626"
},
{
"input": "0 61256 85109 94834 32902\n55269 0 67023 1310 85444\n23497 84998 0 55618 80701\n30324 1713 62127 0 55041\n47799 52448 40072 28971 0",
"output": "822729"
},
{
"input": "0 7686 20401 55871 74372\n29526 0 15486 2152 84700\n27854 30093 0 62418 14297\n43903 76036 36194 0 50522\n29743 9945 38831 75882 0",
"output": "605229"
},
{
"input": "0 5271 65319 64976 13673\n80352 0 41169 66004 47397\n33603 44407 0 55079 36122\n4277 9834 92810 0 80276\n1391 1145 92132 51595 0",
"output": "744065"
},
{
"input": "0 75763 33154 32389 12897\n5095 0 6375 61517 46063\n35354 82789 0 24814 310\n37373 45993 61355 0 76865\n24383 84258 71887 71430 0",
"output": "714904"
},
{
"input": "0 89296 32018 98206 22395\n15733 0 69391 74253 50419\n80450 89589 0 20583 51716\n38629 93129 67730 0 69703\n44054 83018 21382 64478 0",
"output": "874574"
},
{
"input": "0 14675 94714 27735 99544\n45584 0 43621 94734 66110\n72838 45781 0 47389 99394\n75870 95368 33311 0 63379\n21974 70489 53797 23747 0",
"output": "974145"
},
{
"input": "0 9994 14841 63916 37926\n80090 0 90258 96988 18217\n674 69024 0 17641 54436\n35046 21380 14213 0 67188\n49360 19086 68337 70856 0",
"output": "801116"
},
{
"input": "0 28287 52158 19163 10096\n93438 0 19260 88892 12429\n22525 60034 0 78163 18126\n11594 8506 56066 0 17732\n59561 82486 23419 57406 0",
"output": "654636"
},
{
"input": "0 35310 30842 63415 91022\n30553 0 25001 38944 92355\n48906 33736 0 96880 80893\n80507 79652 45299 0 38212\n72488 77736 19203 56436 0",
"output": "953303"
},
{
"input": "0 42865 18485 37168 43099\n41476 0 58754 73410 51163\n76093 44493 0 51611 93773\n87223 80979 58422 0 63327\n51215 63346 84797 52809 0",
"output": "864938"
},
{
"input": "0 63580 51022 25392 84354\n39316 0 17516 63801 92440\n5447 2074 0 11758 4772\n26329 55642 62442 0 75330\n6164 83831 10741 15214 0",
"output": "738415"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 1 1 1 0\n1 0 0 1 0\n0 1 0 0 1\n1 1 0 0 0\n1 0 0 1 0",
"output": "10"
},
{
"input": "0 3 6 9 8\n2 0 8 7 7\n4 6 0 6 1\n9 0 3 0 6\n6 5 0 2 0",
"output": "90"
},
{
"input": "0 97 67 53 6\n96 0 100 57 17\n27 79 0 66 16\n89 46 71 0 28\n27 26 27 12 0",
"output": "926"
},
{
"input": "0 670 904 349 56\n446 0 941 590 993\n654 888 0 423 752\n16 424 837 0 433\n418 655 459 897 0",
"output": "9752"
},
{
"input": "0 4109 129 1340 7124\n7815 0 8991 2828 909\n5634 799 0 5691 9604\n3261 7013 8062 0 5160\n2433 4742 694 4786 0",
"output": "69867"
},
{
"input": "0 14299 32984 96001 30445\n77723 0 75669 14101 55389\n30897 9956 0 52675 29987\n36518 90812 92955 0 64020\n91242 50085 86272 62454 0",
"output": "783459"
},
{
"input": "0 46183 30304 63049 13191\n37244 0 23076 12594 43885\n98470 1788 0 37335 7775\n33822 50804 27921 0 56734\n38313 67579 77714 46687 0",
"output": "666175"
},
{
"input": "0 39037 87960 13497 38526\n5528 0 44220 23338 92550\n87887 86544 0 30269 82845\n24590 60325 90979 0 20186\n64959 69875 93564 68355 0",
"output": "950600"
},
{
"input": "0 27677 88187 87515 82582\n98177 0 22852 28214 99977\n52662 14066 0 79760 68188\n56883 30561 91843 0 79777\n12461 14821 29284 54372 0",
"output": "878207"
},
{
"input": "0 37330 91942 67667 42061\n1978 0 84218 17 10834\n11303 6279 0 48597 26591\n82688 5437 34983 0 92556\n79574 32231 23167 16637 0",
"output": "718057"
},
{
"input": "0 3 0 0 0\n3 0 2 0 0\n0 2 0 1 0\n0 0 1 0 1\n0 0 0 1 0",
"output": "24"
}
] | 1,661,905,274 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | mat = []
for i in range(5):
tmp = [ int(x) for x in input().split() ]
mat.append(tmp)
def cal_hap( mat , op ):
hp = 0
i = 0
while(i < 4):
j = i
while(j < 4):
hp += mat[ op[j] ][ op[j+1] ]
hp += mat[ op[j+1] ][ op[j] ]
j += 2
i += 1
return hp
op = [ [] ]
for i in range(5):
cs = []
for j in range(len(op)):
for k in range(5):
if k not in op[j]:
cs.append( op[j] + [k])
op = cs
mx = 0
for st in op:
tmp = cal_hap(mat, st)
if tmp > mx:
mx = tmp
print(mx)
| Title: Shower Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks.
There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.
Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2*i*<=-<=1)-th man in the line (for the current moment) talks with the (2*i*)-th one.
Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower.
We know that if students *i* and *j* talk, then the *i*-th student's happiness increases by *g**ij* and the *j*-th student's happiness increases by *g**ji*. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.
Input Specification:
The input consists of five lines, each line contains five space-separated integers: the *j*-th number in the *i*-th line shows *g**ij* (0<=≤<=*g**ij*<=≤<=105). It is guaranteed that *g**ii*<==<=0 for all *i*.
Assume that the students are numbered from 1 to 5.
Output Specification:
Print a single integer — the maximum possible total happiness of the students.
Demo Input:
['0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0\n', '0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0\n']
Demo Output:
['32\n', '620\n']
Note:
In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals: | ```python
mat = []
for i in range(5):
tmp = [ int(x) for x in input().split() ]
mat.append(tmp)
def cal_hap( mat , op ):
hp = 0
i = 0
while(i < 4):
j = i
while(j < 4):
hp += mat[ op[j] ][ op[j+1] ]
hp += mat[ op[j+1] ][ op[j] ]
j += 2
i += 1
return hp
op = [ [] ]
for i in range(5):
cs = []
for j in range(len(op)):
for k in range(5):
if k not in op[j]:
cs.append( op[j] + [k])
op = cs
mx = 0
for st in op:
tmp = cal_hap(mat, st)
if tmp > mx:
mx = tmp
print(mx)
``` | 3 |
|
774 | C | Maximum Number | PROGRAMMING | 1,200 | [
"*special",
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted.
The battery of the newest device allows to highlight at most *n* sections on the display.
Stepan wants to know the maximum possible integer number which can be shown on the display of his newest device. Your task is to determine this number. Note that this number must not contain leading zeros. Assume that the size of the display is enough to show any integer. | The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display. | Print the maximum integer which can be shown on the display of Stepan's newest device. | [
"2\n",
"3\n"
] | [
"1\n",
"7\n"
] | none | 0 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "11"
},
{
"input": "5",
"output": "71"
},
{
"input": "6",
"output": "111"
},
{
"input": "85651",
"output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "85666",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "99999",
"output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "100000",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "99998",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "9",
"output": "7111"
},
{
"input": "99997",
"output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "99996",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "99995",
"output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "156",
"output": "111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "255",
"output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "4568",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "5431",
"output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "6782",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "8343",
"output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "9514",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
}
] | 1,612,530,343 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n=(int)(input())
while mod(n,2) != 0:
print(7)
n=n-3
while n != 0:
print(1)
n=n-2
| Title: Maximum Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted.
The battery of the newest device allows to highlight at most *n* sections on the display.
Stepan wants to know the maximum possible integer number which can be shown on the display of his newest device. Your task is to determine this number. Note that this number must not contain leading zeros. Assume that the size of the display is enough to show any integer.
Input Specification:
The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display.
Output Specification:
Print the maximum integer which can be shown on the display of Stepan's newest device.
Demo Input:
['2\n', '3\n']
Demo Output:
['1\n', '7\n']
Note:
none | ```python
n=(int)(input())
while mod(n,2) != 0:
print(7)
n=n-3
while n != 0:
print(1)
n=n-2
``` | -1 |
|
251 | B | Playing with Permutations | PROGRAMMING | 1,800 | [
"implementation",
"math"
] | null | null | Little Petya likes permutations a lot. Recently his mom has presented him permutation *q*1,<=*q*2,<=...,<=*q**n* of length *n*.
A permutation *a* of length *n* is a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), all integers there are distinct.
There is only one thing Petya likes more than permutations: playing with little Masha. As it turns out, Masha also has a permutation of length *n*. Petya decided to get the same permutation, whatever the cost may be. For that, he devised a game with the following rules:
- Before the beginning of the game Petya writes permutation 1,<=2,<=...,<=*n* on the blackboard. After that Petya makes exactly *k* moves, which are described below. - During a move Petya tosses a coin. If the coin shows heads, he performs point 1, if the coin shows tails, he performs point 2. Let's assume that the board contains permutation *p*1,<=*p*2,<=...,<=*p**n* at the given moment. Then Petya removes the written permutation *p* from the board and writes another one instead: *p**q*1,<=*p**q*2,<=...,<=*p**q**n*. In other words, Petya applies permutation *q* (which he has got from his mother) to permutation *p*. - All actions are similar to point 1, except that Petya writes permutation *t* on the board, such that: *t**q**i*<==<=*p**i* for all *i* from 1 to *n*. In other words, Petya applies a permutation that is inverse to *q* to permutation *p*.
We know that after the *k*-th move the board contained Masha's permutation *s*1,<=*s*2,<=...,<=*s**n*. Besides, we know that throughout the game process Masha's permutation never occurred on the board before the *k*-th move. Note that the game has exactly *k* moves, that is, throughout the game the coin was tossed exactly *k* times.
Your task is to determine whether the described situation is possible or else state that Petya was mistaken somewhere. See samples and notes to them for a better understanding. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* space-separated integers *q*1,<=*q*2,<=...,<=*q**n* (1<=≤<=*q**i*<=≤<=*n*) — the permutation that Petya's got as a present. The third line contains Masha's permutation *s*, in the similar format.
It is guaranteed that the given sequences *q* and *s* are correct permutations. | If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes). | [
"4 1\n2 3 4 1\n1 2 3 4\n",
"4 1\n4 3 1 2\n3 4 2 1\n",
"4 3\n4 3 1 2\n3 4 2 1\n",
"4 2\n4 3 1 2\n2 1 4 3\n",
"4 1\n4 3 1 2\n2 1 4 3\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n"
] | In the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before *k* moves were performed.
In the second sample the described situation is possible, in case if after we toss a coin, we get tails.
In the third sample the possible coin tossing sequence is: heads-tails-tails.
In the fourth sample the possible coin tossing sequence is: heads-heads. | 1,000 | [
{
"input": "4 1\n2 3 4 1\n1 2 3 4",
"output": "NO"
},
{
"input": "4 1\n4 3 1 2\n3 4 2 1",
"output": "YES"
},
{
"input": "4 3\n4 3 1 2\n3 4 2 1",
"output": "YES"
},
{
"input": "4 2\n4 3 1 2\n2 1 4 3",
"output": "YES"
},
{
"input": "4 1\n4 3 1 2\n2 1 4 3",
"output": "NO"
},
{
"input": "4 3\n4 3 1 2\n2 1 4 3",
"output": "NO"
},
{
"input": "4 3\n2 1 4 3\n4 3 1 2",
"output": "NO"
},
{
"input": "4 1\n2 1 4 3\n2 1 4 3",
"output": "YES"
},
{
"input": "4 2\n2 1 4 3\n2 1 4 3",
"output": "NO"
},
{
"input": "4 2\n2 3 4 1\n1 2 3 4",
"output": "NO"
},
{
"input": "5 3\n2 1 4 3 5\n2 1 4 3 5",
"output": "NO"
},
{
"input": "9 10\n2 3 1 5 6 7 8 9 4\n2 3 1 4 5 6 7 8 9",
"output": "NO"
},
{
"input": "8 10\n2 3 1 5 6 7 8 4\n2 3 1 4 5 6 7 8",
"output": "YES"
},
{
"input": "8 9\n2 3 1 5 6 7 8 4\n2 3 1 4 5 6 7 8",
"output": "YES"
},
{
"input": "10 10\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9",
"output": "NO"
},
{
"input": "10 9\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9",
"output": "YES"
},
{
"input": "10 100\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9",
"output": "NO"
},
{
"input": "10 99\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9",
"output": "YES"
},
{
"input": "9 100\n2 3 1 5 6 7 8 9 4\n2 3 1 4 5 6 7 8 9",
"output": "NO"
},
{
"input": "5 99\n2 1 4 3 5\n2 1 4 3 5",
"output": "NO"
},
{
"input": "5 1\n2 1 4 3 5\n2 1 4 3 5",
"output": "YES"
},
{
"input": "55 30\n51 43 20 22 50 48 35 6 49 7 52 29 34 45 9 55 47 36 41 54 1 4 39 46 25 26 12 28 14 3 33 23 11 2 53 8 40 32 13 37 19 16 18 42 27 31 17 44 30 24 15 38 10 21 5\n30 31 51 22 43 32 10 38 54 53 44 12 24 14 20 34 47 11 41 15 49 4 5 36 25 26 27 28 29 1 6 55 48 46 7 52 40 16 50 37 19 13 33 39 45 8 17 23 21 18 3 42 35 9 2",
"output": "NO"
},
{
"input": "55 30\n32 37 9 26 13 6 44 1 2 38 11 12 36 49 10 46 5 21 43 24 28 31 15 51 55 27 29 18 41 17 20 8 45 16 52 30 39 53 3 35 19 33 50 54 47 34 48 14 4 42 22 40 23 25 7\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",
"output": "NO"
},
{
"input": "55 28\n25 13 15 37 5 7 42 9 50 8 14 21 3 30 29 38 1 51 52 20 16 27 6 41 48 4 49 32 2 44 55 10 33 34 54 23 40 26 12 31 39 28 43 46 53 19 22 35 36 47 24 17 11 45 18\n17 29 13 26 5 23 6 10 8 32 53 39 2 11 3 21 52 55 46 20 12 47 36 51 1 38 22 42 15 14 40 28 33 34 48 49 4 16 41 37 24 7 43 30 54 44 50 25 27 9 18 19 45 35 31",
"output": "YES"
},
{
"input": "55 28\n34 11 18 6 16 43 12 25 48 27 35 17 19 14 33 30 7 53 52 2 15 10 44 1 37 28 22 49 46 8 45 39 21 47 40 20 41 51 13 24 42 55 23 4 36 38 50 31 3 9 54 32 5 29 26\n34 11 18 6 16 43 12 25 48 27 35 17 19 14 33 30 7 53 52 2 15 10 44 1 37 28 22 49 46 8 45 39 21 47 40 20 41 51 13 24 42 55 23 4 36 38 50 31 3 9 54 32 5 29 26",
"output": "YES"
},
{
"input": "55 28\n35 33 46 8 11 13 14 26 42 38 1 7 34 5 2 21 17 45 54 43 4 18 27 50 25 10 29 48 6 16 22 28 55 53 49 41 39 23 40 47 51 37 36 19 9 32 52 12 24 3 20 15 30 44 31\n5 52 24 16 7 27 48 21 18 8 14 28 29 12 47 53 17 31 54 41 30 55 10 35 25 4 38 46 23 34 33 3 15 6 11 20 9 26 42 37 43 45 51 19 22 50 39 32 1 49 36 40 13 44 2",
"output": "YES"
},
{
"input": "1 1\n1\n1",
"output": "NO"
},
{
"input": "1 2\n1\n1",
"output": "NO"
},
{
"input": "2 3\n2 1\n2 1",
"output": "NO"
},
{
"input": "3 100\n2 3 1\n2 3 1",
"output": "YES"
},
{
"input": "6 3\n2 3 4 5 6 1\n2 3 4 5 6 1",
"output": "YES"
},
{
"input": "13 2\n2 3 4 5 6 7 8 9 10 11 12 13 1\n3 4 5 6 7 8 9 10 11 12 13 1 2",
"output": "YES"
},
{
"input": "2 99\n2 1\n2 1",
"output": "NO"
},
{
"input": "4 3\n2 1 4 3\n2 1 4 3",
"output": "NO"
},
{
"input": "4 50\n2 3 4 1\n3 4 1 2",
"output": "YES"
},
{
"input": "3 99\n2 3 1\n2 3 1",
"output": "YES"
},
{
"input": "2 2\n2 1\n1 2",
"output": "NO"
},
{
"input": "10 29\n2 1 4 5 3 7 8 9 10 6\n2 1 5 3 4 8 9 10 6 7",
"output": "YES"
},
{
"input": "4 11\n2 3 4 1\n2 3 4 1",
"output": "YES"
},
{
"input": "9 3\n2 3 4 5 6 7 8 9 1\n3 4 5 6 7 8 9 1 2",
"output": "NO"
}
] | 1,661,088,450 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | def reverese(l,r,arr):
while l < r:
arr[l],arr[r] = arr[r],arr[l]
l+=1
r-=1
n = int(input())
arr = list(map(int,input().split()))
arr2 = sorted(arr)
l = r = 0
if arr == arr2:
print("yes")
print(1,1)
else:
for i in range(n-1):
if arr[i] > arr[i+1]:
r = i+1
continue
if l == r:
l+=1
r+=1
reverese(l,r,arr)
if arr == arr2:
print("yes")
print(l+1,r+1)
else:
print("no") | Title: Playing with Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes permutations a lot. Recently his mom has presented him permutation *q*1,<=*q*2,<=...,<=*q**n* of length *n*.
A permutation *a* of length *n* is a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), all integers there are distinct.
There is only one thing Petya likes more than permutations: playing with little Masha. As it turns out, Masha also has a permutation of length *n*. Petya decided to get the same permutation, whatever the cost may be. For that, he devised a game with the following rules:
- Before the beginning of the game Petya writes permutation 1,<=2,<=...,<=*n* on the blackboard. After that Petya makes exactly *k* moves, which are described below. - During a move Petya tosses a coin. If the coin shows heads, he performs point 1, if the coin shows tails, he performs point 2. Let's assume that the board contains permutation *p*1,<=*p*2,<=...,<=*p**n* at the given moment. Then Petya removes the written permutation *p* from the board and writes another one instead: *p**q*1,<=*p**q*2,<=...,<=*p**q**n*. In other words, Petya applies permutation *q* (which he has got from his mother) to permutation *p*. - All actions are similar to point 1, except that Petya writes permutation *t* on the board, such that: *t**q**i*<==<=*p**i* for all *i* from 1 to *n*. In other words, Petya applies a permutation that is inverse to *q* to permutation *p*.
We know that after the *k*-th move the board contained Masha's permutation *s*1,<=*s*2,<=...,<=*s**n*. Besides, we know that throughout the game process Masha's permutation never occurred on the board before the *k*-th move. Note that the game has exactly *k* moves, that is, throughout the game the coin was tossed exactly *k* times.
Your task is to determine whether the described situation is possible or else state that Petya was mistaken somewhere. See samples and notes to them for a better understanding.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* space-separated integers *q*1,<=*q*2,<=...,<=*q**n* (1<=≤<=*q**i*<=≤<=*n*) — the permutation that Petya's got as a present. The third line contains Masha's permutation *s*, in the similar format.
It is guaranteed that the given sequences *q* and *s* are correct permutations.
Output Specification:
If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes).
Demo Input:
['4 1\n2 3 4 1\n1 2 3 4\n', '4 1\n4 3 1 2\n3 4 2 1\n', '4 3\n4 3 1 2\n3 4 2 1\n', '4 2\n4 3 1 2\n2 1 4 3\n', '4 1\n4 3 1 2\n2 1 4 3\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n', 'YES\n', 'NO\n']
Note:
In the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before *k* moves were performed.
In the second sample the described situation is possible, in case if after we toss a coin, we get tails.
In the third sample the possible coin tossing sequence is: heads-tails-tails.
In the fourth sample the possible coin tossing sequence is: heads-heads. | ```python
def reverese(l,r,arr):
while l < r:
arr[l],arr[r] = arr[r],arr[l]
l+=1
r-=1
n = int(input())
arr = list(map(int,input().split()))
arr2 = sorted(arr)
l = r = 0
if arr == arr2:
print("yes")
print(1,1)
else:
for i in range(n-1):
if arr[i] > arr[i+1]:
r = i+1
continue
if l == r:
l+=1
r+=1
reverese(l,r,arr)
if arr == arr2:
print("yes")
print(l+1,r+1)
else:
print("no")
``` | -1 |
|
583 | B | Robot's Task | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to collect at least *a**i* any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all *n* parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information. | The first line contains number *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*n*), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information. | Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all *n* parts of information. | [
"3\n0 2 0\n",
"5\n4 2 3 0 1\n",
"7\n0 3 1 0 5 2 6\n"
] | [
"1\n",
"3\n",
"2\n"
] | In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7. | 1,000 | [
{
"input": "3\n0 2 0",
"output": "1"
},
{
"input": "5\n4 2 3 0 1",
"output": "3"
},
{
"input": "7\n0 3 1 0 5 2 6",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "0"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "3\n0 2 1",
"output": "1"
},
{
"input": "10\n7 1 9 3 5 8 6 0 2 4",
"output": "9"
},
{
"input": "10\n1 3 5 7 9 8 6 4 2 0",
"output": "9"
},
{
"input": "10\n5 0 0 1 3 2 2 2 5 7",
"output": "1"
},
{
"input": "10\n8 6 5 3 9 7 1 4 2 0",
"output": "8"
},
{
"input": "10\n1 2 4 5 0 1 3 7 1 4",
"output": "2"
},
{
"input": "10\n3 4 8 9 5 1 2 0 6 7",
"output": "6"
},
{
"input": "10\n2 2 0 0 6 2 9 0 2 0",
"output": "2"
},
{
"input": "10\n1 7 5 3 2 6 0 8 4 9",
"output": "8"
},
{
"input": "9\n1 3 8 6 2 4 5 0 7",
"output": "7"
},
{
"input": "9\n1 3 5 7 8 6 4 2 0",
"output": "8"
},
{
"input": "9\n2 4 3 1 3 0 5 4 3",
"output": "3"
},
{
"input": "9\n3 5 6 8 7 0 4 2 1",
"output": "5"
},
{
"input": "9\n2 0 8 1 0 3 0 5 3",
"output": "2"
},
{
"input": "9\n6 2 3 7 4 8 5 1 0",
"output": "4"
},
{
"input": "9\n3 1 5 6 0 3 2 0 0",
"output": "2"
},
{
"input": "9\n2 6 4 1 0 8 5 3 7",
"output": "7"
},
{
"input": "100\n27 20 18 78 93 38 56 2 48 75 36 88 96 57 69 10 25 74 68 86 65 85 66 14 22 12 43 80 99 34 42 63 61 71 77 15 37 54 21 59 23 94 28 30 50 84 62 76 47 16 26 64 82 92 72 53 17 11 41 91 35 83 79 95 67 13 1 7 3 4 73 90 8 19 33 58 98 32 39 45 87 52 60 46 6 44 49 70 51 9 5 29 31 24 40 97 81 0 89 55",
"output": "69"
},
{
"input": "100\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 99 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0",
"output": "99"
},
{
"input": "100\n13 89 81 0 62 1 59 92 29 13 1 37 2 8 53 15 20 34 12 70 0 85 97 55 84 60 37 54 14 65 22 69 30 22 95 44 59 85 50 80 9 71 91 93 74 21 11 78 28 21 40 81 76 24 26 60 48 85 61 68 89 76 46 73 34 52 98 29 4 38 94 51 5 55 6 27 74 27 38 37 82 70 44 89 51 59 30 37 15 55 63 78 42 39 71 43 4 10 2 13",
"output": "21"
},
{
"input": "100\n1 3 5 7 58 11 13 15 17 19 45 23 25 27 29 31 33 35 37 39 41 43 21 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 81 79 83 85 87 89 91 93 95 97 48 98 96 94 92 90 88 44 84 82 80 78 76 74 72 70 68 66 64 62 60 9 56 54 52 50 99 46 86 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0",
"output": "96"
},
{
"input": "100\n32 47 74 8 14 4 12 68 18 0 44 80 14 38 6 57 4 72 69 3 21 78 74 22 39 32 58 63 34 33 23 6 39 11 6 12 18 4 0 11 20 28 16 1 22 12 57 55 13 48 43 1 50 18 87 6 11 45 38 67 37 14 7 56 6 41 1 55 5 73 78 64 38 18 38 8 37 0 18 61 37 58 58 62 86 5 0 2 15 43 34 61 2 21 15 9 69 1 11 24",
"output": "4"
},
{
"input": "100\n40 3 55 7 6 77 13 46 17 64 21 54 25 27 91 41 1 15 37 82 23 43 42 47 26 95 53 5 11 59 61 9 78 67 69 58 73 0 36 79 60 83 2 87 63 33 71 89 97 99 98 93 56 92 19 88 86 84 39 28 65 20 34 76 51 94 66 12 62 49 96 72 24 52 48 50 44 35 74 31 38 57 81 32 22 80 70 29 30 18 68 16 14 90 10 8 85 4 45 75",
"output": "75"
},
{
"input": "100\n34 16 42 21 84 27 11 7 82 16 95 39 36 64 26 0 38 37 2 2 16 56 16 61 55 42 26 5 61 8 30 20 19 15 9 78 5 34 15 0 3 17 36 36 1 5 4 26 18 0 14 25 7 5 91 7 43 26 79 37 17 27 40 55 66 7 0 2 16 23 68 35 2 5 9 21 1 7 2 9 4 3 22 15 27 6 0 47 5 0 12 9 20 55 36 10 6 8 5 1",
"output": "3"
},
{
"input": "100\n35 53 87 49 13 24 93 20 5 11 31 32 40 52 96 46 1 25 66 69 28 88 84 82 70 9 75 39 26 21 18 29 23 57 90 16 48 22 95 0 58 43 7 73 8 62 63 30 64 92 79 3 6 94 34 12 76 99 67 55 56 97 14 91 68 36 44 78 41 71 86 89 47 74 4 45 98 37 80 33 83 27 42 59 72 54 17 60 51 81 15 77 65 50 10 85 61 19 38 2",
"output": "67"
},
{
"input": "99\n89 96 56 31 32 14 9 66 87 34 69 5 92 54 41 52 46 30 22 26 16 18 20 68 62 73 90 43 79 33 58 98 37 45 10 78 94 51 19 0 91 39 28 47 17 86 3 61 77 7 15 64 55 83 65 71 97 88 6 48 24 11 8 42 81 4 63 93 50 74 35 12 95 27 53 82 29 85 84 60 72 40 36 57 23 13 38 59 49 1 75 44 76 2 21 25 70 80 67",
"output": "75"
},
{
"input": "99\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 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0",
"output": "98"
},
{
"input": "99\n82 7 6 77 17 28 90 3 68 12 63 60 24 20 4 81 71 85 57 45 11 84 3 91 49 34 89 82 0 50 48 88 36 76 36 5 62 48 20 2 20 45 69 27 37 62 42 31 57 51 92 84 89 25 7 62 12 23 23 56 30 90 27 10 77 58 48 38 56 68 57 15 33 1 34 67 16 47 75 70 69 28 38 16 5 61 85 76 44 90 37 22 77 94 55 1 97 8 69",
"output": "22"
},
{
"input": "99\n1 51 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 42 43 45 47 49 3 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 98 96 94 92 90 88 86 84 82 80 8 76 74 72 70 68 66 22 62 60 58 56 54 52 0 48 46 44 41 40 38 36 34 32 30 28 26 24 64 20 18 16 14 12 10 78 6 4 2 50",
"output": "96"
},
{
"input": "99\n22 3 19 13 65 87 28 17 41 40 31 21 8 37 29 65 65 53 16 33 13 5 76 4 72 9 2 76 57 72 50 15 75 0 30 13 83 36 12 31 49 51 65 22 48 31 60 15 2 17 6 1 8 0 1 63 3 16 7 7 2 1 47 28 26 21 2 36 1 5 20 25 44 0 2 39 46 30 33 11 15 34 34 4 84 52 0 39 7 3 17 15 6 38 52 64 26 1 0",
"output": "3"
},
{
"input": "99\n24 87 25 82 97 11 37 15 23 19 34 17 76 13 45 89 33 1 27 78 63 43 54 47 49 2 42 41 75 83 61 90 65 67 21 71 60 57 77 62 81 58 85 69 3 91 68 55 72 93 29 94 66 16 88 86 84 53 14 39 35 44 9 70 80 92 56 79 74 5 64 31 52 50 48 46 51 59 40 38 36 96 32 30 28 95 7 22 20 18 26 73 12 10 8 6 4 98 0",
"output": "74"
},
{
"input": "99\n22 14 0 44 6 17 6 6 37 45 0 48 19 8 57 8 10 0 3 12 25 2 5 53 9 49 15 6 38 14 9 40 38 22 27 12 64 10 11 35 89 19 46 39 12 24 48 0 52 1 27 27 24 4 64 24 5 0 67 3 5 39 0 1 13 37 2 8 46 1 28 70 6 79 14 15 33 6 7 34 6 18 4 71 1 55 33 71 18 11 47 23 72 53 65 32 2 7 28",
"output": "3"
},
{
"input": "99\n28 59 73 89 52 27 0 20 36 12 83 95 31 24 54 94 49 14 51 34 50 93 13 1 2 68 63 48 41 81 23 43 18 9 16 38 33 60 62 3 40 85 72 69 90 98 11 37 22 44 35 6 21 39 82 10 64 66 96 42 74 30 8 67 97 46 84 32 17 57 75 71 5 26 4 55 58 29 7 15 45 19 92 91 78 65 88 25 86 80 77 87 79 53 47 70 56 76 61",
"output": "63"
}
] | 1,443,896,051 | 5,351 | Python 3 | OK | TESTS | 56 | 218 | 0 | n = int(input())
arr = list(map(int, input().split()))
cnt = 0
turns = 0
used = [False for i in range(n)]
while cnt < n:
for i in range(n):
if arr[i] <= cnt and not used[i]:
used[i] = True
cnt += 1
if cnt == n:
break
turns += 1
for i in range(n - 1, -1, -1):
if arr[i] <= cnt and not used[i]:
used[i] = True
cnt += 1
if cnt == n:
break
turns += 1
print(turns)
| Title: Robot's Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to collect at least *a**i* any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all *n* parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input Specification:
The first line contains number *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*n*), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output Specification:
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all *n* parts of information.
Demo Input:
['3\n0 2 0\n', '5\n4 2 3 0 1\n', '7\n0 3 1 0 5 2 6\n']
Demo Output:
['1\n', '3\n', '2\n']
Note:
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7. | ```python
n = int(input())
arr = list(map(int, input().split()))
cnt = 0
turns = 0
used = [False for i in range(n)]
while cnt < n:
for i in range(n):
if arr[i] <= cnt and not used[i]:
used[i] = True
cnt += 1
if cnt == n:
break
turns += 1
for i in range(n - 1, -1, -1):
if arr[i] <= cnt and not used[i]:
used[i] = True
cnt += 1
if cnt == n:
break
turns += 1
print(turns)
``` | 3 |
|
989 | B | A Tide of Riverscape | PROGRAMMING | 1,200 | [
"constructive algorithms",
"strings"
] | null | null | "Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string $s$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $p$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer $p$ is considered a period of string $s$, if for all $1 \leq i \leq \lvert s \rvert - p$, the $i$-th and $(i + p)$-th characters of $s$ are the same. Here $\lvert s \rvert$ is the length of $s$. | The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively.
The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' character. | Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)). | [
"10 7\n1.0.1.0.1.\n",
"10 6\n1.0.1.1000\n",
"10 9\n1........1\n"
] | [
"1000100010\n",
"1001101000\n",
"No\n"
] | In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different.
In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different.
In the third example, $9$ is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | 1,000 | [
{
"input": "10 7\n1.0.1.0.1.",
"output": "1000100010"
},
{
"input": "10 6\n1.0.1.1000",
"output": "1001101000"
},
{
"input": "10 9\n1........1",
"output": "No"
},
{
"input": "1 1\n.",
"output": "No"
},
{
"input": "5 1\n0...1",
"output": "00001"
},
{
"input": "17 10\n..1.100..1..0.100",
"output": "00101000010000100"
},
{
"input": "2 1\n0.",
"output": "01"
},
{
"input": "2 1\n..",
"output": "01"
},
{
"input": "3 1\n.0.",
"output": "001"
},
{
"input": "3 1\n00.",
"output": "001"
},
{
"input": "3 2\n0..",
"output": "001"
},
{
"input": "3 2\n0.0",
"output": "No"
},
{
"input": "3 2\n1..",
"output": "100"
},
{
"input": "3 2\n.1.",
"output": "011"
},
{
"input": "3 2\n1.0",
"output": "100"
},
{
"input": "3 3\n1..",
"output": "No"
},
{
"input": "3 3\n.00",
"output": "No"
},
{
"input": "5 3\n0.000",
"output": "01000"
},
{
"input": "10 6\n10010.1001",
"output": "No"
},
{
"input": "75 38\n00.0.1.0.0110.1.00010..100.1110..110..00.0.1.0.0110.1.00010..100.1110..110.",
"output": "000001000011001000010001000111000110000000010000110010000100010001110001101"
},
{
"input": "128 108\n01100.110...000.0001.1.11.11.010010.01100.0.1.01.0.0011.11001.000101...1.0.0..100.0110.0110.0.0101.0.0.0001.01100.110...100.0001",
"output": "01100011000000000001010110110010010001100000100100000110110010000101000100000010000110001100000101000000001001100011000010000001"
},
{
"input": "5 4\n.101.",
"output": "01011"
},
{
"input": "4 2\n101.",
"output": "1011"
},
{
"input": "5 4\n.1011",
"output": "01011"
},
{
"input": "2 1\n..",
"output": "01"
},
{
"input": "5 3\n00.11",
"output": "00011"
},
{
"input": "10 8\n1111.00000",
"output": "1111000000"
},
{
"input": "10 3\n11111111.1",
"output": "1111111101"
},
{
"input": "3 2\n1.0",
"output": "100"
},
{
"input": "6 4\n11..10",
"output": "110010"
},
{
"input": "4 2\n.111",
"output": "0111"
},
{
"input": "3 2\n01.",
"output": "011"
},
{
"input": "5 4\n10.00",
"output": "10000"
},
{
"input": "10 9\n1........0",
"output": "1000000000"
},
{
"input": "2 1\n0.",
"output": "01"
},
{
"input": "8 4\n111111..",
"output": "11111100"
},
{
"input": "3 2\n0.1",
"output": "001"
},
{
"input": "4 1\n111.",
"output": "1110"
},
{
"input": "3 1\n01.",
"output": "010"
},
{
"input": "10 7\n000....111",
"output": "0000000111"
}
] | 1,579,981,179 | 4,179 | PyPy 3 | OK | TESTS | 59 | 140 | 1,331,200 | n, p = map(int, input().split())
s = input()
l = list(s)
k = 0
a = 0
for i in range(len(s) - p):
a = i
if (i + p > len(s) - 1):
break
if (l[i] == l[i + p] and l[i] != "."):
k += 1
elif (l[i] != l[i + p]):
if (l[i] == '.'):
for j in range(len(l)):
if (l[j] == "."):
l[j] = "0"
if (l[i + p] == "0"):
l[i] = "1"
else:
l[i] = "0"
print("".join(l))
break
elif (l[i + p] == '.'):
for j in range(len(l)):
if (l[j] == "."):
l[j] = "0"
if (l[i] == "0"):
l[i + p] = "1"
else:
l[i + p] = "0"
print("".join(l))
break
else:
for j in range(len(l)):
if (l[j] == "."):
l[j] = "0"
print("".join(l))
break
elif (l[i]==l[i + p] and l[i] == "."):
for j in range(len(l)):
if (l[j] == "."):
l[j] = "0"
l[i] = "1"
print("".join(l))
break
if (k==a+1):
print("NO")
if(p==n):
print("NO") | Title: A Tide of Riverscape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string $s$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $p$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer $p$ is considered a period of string $s$, if for all $1 \leq i \leq \lvert s \rvert - p$, the $i$-th and $(i + p)$-th characters of $s$ are the same. Here $\lvert s \rvert$ is the length of $s$.
Input Specification:
The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively.
The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' character.
Output Specification:
Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Demo Input:
['10 7\n1.0.1.0.1.\n', '10 6\n1.0.1.1000\n', '10 9\n1........1\n']
Demo Output:
['1000100010\n', '1001101000\n', 'No\n']
Note:
In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different.
In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different.
In the third example, $9$ is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | ```python
n, p = map(int, input().split())
s = input()
l = list(s)
k = 0
a = 0
for i in range(len(s) - p):
a = i
if (i + p > len(s) - 1):
break
if (l[i] == l[i + p] and l[i] != "."):
k += 1
elif (l[i] != l[i + p]):
if (l[i] == '.'):
for j in range(len(l)):
if (l[j] == "."):
l[j] = "0"
if (l[i + p] == "0"):
l[i] = "1"
else:
l[i] = "0"
print("".join(l))
break
elif (l[i + p] == '.'):
for j in range(len(l)):
if (l[j] == "."):
l[j] = "0"
if (l[i] == "0"):
l[i + p] = "1"
else:
l[i + p] = "0"
print("".join(l))
break
else:
for j in range(len(l)):
if (l[j] == "."):
l[j] = "0"
print("".join(l))
break
elif (l[i]==l[i + p] and l[i] == "."):
for j in range(len(l)):
if (l[j] == "."):
l[j] = "0"
l[i] = "1"
print("".join(l))
break
if (k==a+1):
print("NO")
if(p==n):
print("NO")
``` | 3 |
|
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | 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}. | 500 | [
{
"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,641,545,819 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 5,324,800 | [n, d] = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
res = 0
for i in range(n):
j = i+2
while j < n and abs(arr[j] - arr[i]) <= d:
res += j - i - 1
j += 1
print(res) | Title: Points on Line
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] = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
res = 0
for i in range(n):
j = i+2
while j < n and abs(arr[j] - arr[i]) <= d:
res += j - i - 1
j += 1
print(res)
``` | 0 |
|
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold. | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one). | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4. | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9 16 25 36 49 64 81 100",
"output": "19"
},
{
"input": "10\n300 315 325 338 350 365 379 391 404 416",
"output": "23"
},
{
"input": "15\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112",
"output": "2"
},
{
"input": "60\n3 5 7 8 15 16 18 21 24 26 40 41 43 47 48 49 50 51 52 54 55 60 62 71 74 84 85 89 91 96 406 407 409 412 417 420 423 424 428 431 432 433 436 441 445 446 447 455 458 467 469 471 472 475 480 485 492 493 497 500",
"output": "310"
},
{
"input": "3\n159 282 405",
"output": "246"
},
{
"input": "81\n6 7 22 23 27 38 40 56 59 71 72 78 80 83 86 92 95 96 101 122 125 127 130 134 154 169 170 171 172 174 177 182 184 187 195 197 210 211 217 223 241 249 252 253 256 261 265 269 274 277 291 292 297 298 299 300 302 318 338 348 351 353 381 386 387 397 409 410 419 420 428 430 453 460 461 473 478 493 494 500 741",
"output": "241"
},
{
"input": "10\n218 300 388 448 535 629 680 740 836 925",
"output": "111"
},
{
"input": "100\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996",
"output": "20"
},
{
"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 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000",
"output": "901"
},
{
"input": "100\n1 9 15 17 28 29 30 31 32 46 48 49 52 56 62 77 82 85 90 91 94 101 102 109 111 113 116 118 124 125 131 132 136 138 139 143 145 158 161 162 165 167 171 173 175 177 179 183 189 196 801 802 804 806 817 819 827 830 837 840 842 846 850 855 858 862 863 866 869 870 878 881 883 884 896 898 899 901 904 906 908 909 910 911 912 917 923 924 925 935 939 943 945 956 963 964 965 972 976 978",
"output": "605"
},
{
"input": "100\n2 43 47 49 50 57 59 67 74 98 901 903 904 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 938 939 940 942 943 944 945 946 947 948 949 950 952 953 954 956 957 958 959 960 961 962 963 965 966 967 968 969 970 971 972 973 974 975 976 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 998 999",
"output": "803"
},
{
"input": "72\n178 186 196 209 217 226 236 248 260 273 281 291 300 309 322 331 343 357 366 377 389 399 409 419 429 442 450 459 469 477 491 501 512 524 534 548 557 568 582 593 602 616 630 643 652 660 670 679 693 707 715 728 737 750 759 768 776 789 797 807 815 827 837 849 863 873 881 890 901 910 920 932",
"output": "17"
},
{
"input": "38\n1 28 55 82 109 136 163 190 217 244 271 298 325 352 379 406 433 460 487 514 541 568 595 622 649 676 703 730 757 784 811 838 865 892 919 946 973 1000",
"output": "54"
},
{
"input": "28\n1 38 75 112 149 186 223 260 297 334 371 408 445 482 519 556 593 630 667 704 741 778 815 852 889 926 963 1000",
"output": "74"
}
] | 1,608,445,313 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 109 | 307,200 | n=int(input())
l=list(map(int,input().strip().split()))
d=[]
for i in range(len(l)-1):
d.append(l[i+1]-l[i])
ma=max(d)
det=[]
for i in range(len(d)-1):
det.append(d[i]+d[i+1])
m=min(det)
ind=det.index(m)
d[ind]=m
d.remove(d[ind+1])
print(max(d))
| Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold.
Input Specification:
The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one).
Output Specification:
Print a single number — the minimum difficulty of the track after removing a single hold.
Demo Input:
['3\n1 4 6\n', '5\n1 2 3 4 5\n', '5\n1 2 3 7 8\n']
Demo Output:
['5\n', '2\n', '4\n']
Note:
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4. | ```python
n=int(input())
l=list(map(int,input().strip().split()))
d=[]
for i in range(len(l)-1):
d.append(l[i+1]-l[i])
ma=max(d)
det=[]
for i in range(len(d)-1):
det.append(d[i]+d[i+1])
m=min(det)
ind=det.index(m)
d[ind]=m
d.remove(d[ind+1])
print(max(d))
``` | 3 |
|
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand. | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "100 100 100",
"output": "300"
},
{
"input": "1 1 1",
"output": "2"
},
{
"input": "30 70 35",
"output": "130"
},
{
"input": "89 44 76",
"output": "208"
},
{
"input": "0 100 100",
"output": "200"
},
{
"input": "100 0 100",
"output": "200"
},
{
"input": "100 1 100",
"output": "200"
},
{
"input": "1 100 100",
"output": "200"
},
{
"input": "100 100 0",
"output": "200"
},
{
"input": "100 100 1",
"output": "200"
},
{
"input": "1 2 1",
"output": "4"
},
{
"input": "0 0 100",
"output": "100"
},
{
"input": "0 100 0",
"output": "0"
},
{
"input": "100 0 0",
"output": "0"
},
{
"input": "10 8 7",
"output": "24"
},
{
"input": "45 47 16",
"output": "108"
},
{
"input": "59 43 100",
"output": "202"
},
{
"input": "34 1 30",
"output": "62"
},
{
"input": "14 81 1",
"output": "30"
},
{
"input": "53 96 94",
"output": "242"
},
{
"input": "62 81 75",
"output": "218"
},
{
"input": "21 71 97",
"output": "188"
},
{
"input": "49 82 73",
"output": "204"
},
{
"input": "88 19 29",
"output": "96"
},
{
"input": "89 4 62",
"output": "132"
},
{
"input": "58 3 65",
"output": "126"
},
{
"input": "27 86 11",
"output": "76"
},
{
"input": "35 19 80",
"output": "134"
},
{
"input": "4 86 74",
"output": "156"
},
{
"input": "32 61 89",
"output": "182"
},
{
"input": "68 60 98",
"output": "226"
},
{
"input": "37 89 34",
"output": "142"
},
{
"input": "92 9 28",
"output": "74"
},
{
"input": "79 58 98",
"output": "234"
},
{
"input": "35 44 88",
"output": "166"
},
{
"input": "16 24 19",
"output": "58"
},
{
"input": "74 71 75",
"output": "220"
},
{
"input": "83 86 99",
"output": "268"
},
{
"input": "97 73 15",
"output": "176"
},
{
"input": "77 76 73",
"output": "226"
},
{
"input": "48 85 55",
"output": "188"
},
{
"input": "1 2 2",
"output": "4"
},
{
"input": "2 2 2",
"output": "6"
},
{
"input": "2 1 2",
"output": "4"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "3 2 1",
"output": "6"
},
{
"input": "1 2 3",
"output": "6"
},
{
"input": "1 3 2",
"output": "6"
},
{
"input": "2 1 3",
"output": "6"
},
{
"input": "2 3 1",
"output": "6"
},
{
"input": "3 1 2",
"output": "6"
},
{
"input": "99 99 99",
"output": "296"
},
{
"input": "99 99 100",
"output": "298"
},
{
"input": "99 100 99",
"output": "298"
},
{
"input": "99 100 100",
"output": "298"
},
{
"input": "100 99 99",
"output": "298"
},
{
"input": "100 99 100",
"output": "298"
},
{
"input": "100 100 99",
"output": "298"
},
{
"input": "89 32 23",
"output": "110"
},
{
"input": "4 5 0",
"output": "8"
},
{
"input": "3 0 3",
"output": "6"
},
{
"input": "0 0 2",
"output": "2"
},
{
"input": "97 97 0",
"output": "194"
},
{
"input": "1 4 0",
"output": "2"
},
{
"input": "5 2 0",
"output": "4"
},
{
"input": "0 5 10",
"output": "14"
},
{
"input": "0 1 2",
"output": "2"
},
{
"input": "5 2 3",
"output": "10"
},
{
"input": "5 5 0",
"output": "10"
},
{
"input": "0 0 10",
"output": "10"
},
{
"input": "0 1 1",
"output": "2"
},
{
"input": "0 0 1",
"output": "0"
}
] | 1,688,970,222 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 46 | 0 | l, r, a = list(map(int, input().split(' ')))
x = 0
for i in range(a + 1):
tl = l + i
tr = r + a - i
x = max(x, min(tl, tr) * 2)
print(x)
| Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
Input Specification:
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Output Specification:
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
Demo Input:
['1 4 2\n', '5 5 5\n', '0 2 0\n']
Demo Output:
['6\n', '14\n', '0\n']
Note:
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand. | ```python
l, r, a = list(map(int, input().split(' ')))
x = 0
for i in range(a + 1):
tl = l + i
tr = r + a - i
x = max(x, min(tl, tr) * 2)
print(x)
``` | 3 |
|
515 | C | Drazil and Factorial | PROGRAMMING | 1,400 | [
"greedy",
"math",
"sortings"
] | null | null | Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions:
1. *x* doesn't contain neither digit 0 nor digit 1.
2. = .
Help friends find such number. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. | Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. | [
"4\n1234\n",
"3\n555\n"
] | [
"33222\n",
"555\n"
] | In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "4\n1234",
"output": "33222"
},
{
"input": "3\n555",
"output": "555"
},
{
"input": "15\n012345781234578",
"output": "7777553333222222222222"
},
{
"input": "1\n8",
"output": "7222"
},
{
"input": "10\n1413472614",
"output": "75333332222222"
},
{
"input": "8\n68931246",
"output": "77553333332222222"
},
{
"input": "7\n4424368",
"output": "75333332222222222"
},
{
"input": "6\n576825",
"output": "7755532222"
},
{
"input": "5\n97715",
"output": "7775332"
},
{
"input": "3\n915",
"output": "75332"
},
{
"input": "2\n26",
"output": "532"
},
{
"input": "1\n4",
"output": "322"
},
{
"input": "15\n028745260720699",
"output": "7777755533333332222222222"
},
{
"input": "13\n5761790121605",
"output": "7775555333322"
},
{
"input": "10\n3312667105",
"output": "755533332"
},
{
"input": "1\n7",
"output": "7"
},
{
"input": "15\n989898989898989",
"output": "777777777777777333333333333333322222222222222222222222222222"
},
{
"input": "15\n000000000000007",
"output": "7"
},
{
"input": "15\n999999999999990",
"output": "77777777777777333333333333333333333333333322222222222222"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "1\n4",
"output": "322"
},
{
"input": "1\n5",
"output": "5"
},
{
"input": "1\n6",
"output": "53"
},
{
"input": "1\n7",
"output": "7"
},
{
"input": "1\n9",
"output": "7332"
},
{
"input": "2\n09",
"output": "7332"
},
{
"input": "13\n1337251172966",
"output": "777555333333222"
},
{
"input": "15\n987654329876543",
"output": "777777555533333333332222222222222"
},
{
"input": "9\n234567899",
"output": "777755333333322222222"
},
{
"input": "2\n99",
"output": "77333322"
},
{
"input": "2\n66",
"output": "5533"
},
{
"input": "3\n999",
"output": "777333333222"
},
{
"input": "5\n99999",
"output": "77777333333333322222"
},
{
"input": "9\n123456789",
"output": "77755333332222222"
},
{
"input": "9\n987654321",
"output": "77755333332222222"
},
{
"input": "3\n666",
"output": "555333"
},
{
"input": "2\n26",
"output": "532"
},
{
"input": "6\n555777",
"output": "777555"
},
{
"input": "10\n1234567899",
"output": "777755333333322222222"
},
{
"input": "4\n6666",
"output": "55553333"
},
{
"input": "4\n9754",
"output": "775333222"
},
{
"input": "2\n95",
"output": "75332"
},
{
"input": "14\n11122233344455",
"output": "55333333222222222"
},
{
"input": "12\n836544897832",
"output": "77777553333333222222222222222"
}
] | 1,588,590,598 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 140 | 0 |
n = input()
a = input()
l = []
for i in a:
if i == '2':
l.append(2)
elif i == '3':
l.append(3)
elif i == '4':
l.append(3)
l.append(2)
l.append(2)
elif i == '5':
l.append(5)
elif i == '6':
l.append(3)
l.append(5)
elif i == '7':
l.append(7)
elif i == '8':
l.append(2)
l.append(2)
l.append(2)
l.append(7)
elif i == '9':
l.append(2)
l.append(3)
l.append(3)
l.append(7)
l.sort(reverse = True)
for j in l:
print(j , end = '') | Title: Drazil and Factorial
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions:
1. *x* doesn't contain neither digit 0 nor digit 1.
2. = .
Help friends find such number.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes.
Output Specification:
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Demo Input:
['4\n1234\n', '3\n555\n']
Demo Output:
['33222\n', '555\n']
Note:
In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
n = input()
a = input()
l = []
for i in a:
if i == '2':
l.append(2)
elif i == '3':
l.append(3)
elif i == '4':
l.append(3)
l.append(2)
l.append(2)
elif i == '5':
l.append(5)
elif i == '6':
l.append(3)
l.append(5)
elif i == '7':
l.append(7)
elif i == '8':
l.append(2)
l.append(2)
l.append(2)
l.append(7)
elif i == '9':
l.append(2)
l.append(3)
l.append(3)
l.append(7)
l.sort(reverse = True)
for j in l:
print(j , end = '')
``` | 3 |
|
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code. | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints. | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 0\n4 5 6 7 1 2 3 0 9 8",
"output": "1 2 3 4 5 6 7 8 9 0"
},
{
"input": "1 1\n4\n4",
"output": "4"
},
{
"input": "3 7\n6 3 4\n4 9 0 1 7 8 6",
"output": "6 4"
},
{
"input": "10 1\n9 0 8 1 7 4 6 5 2 3\n0",
"output": "0"
},
{
"input": "5 10\n6 0 3 8 1\n3 1 0 5 4 7 2 8 9 6",
"output": "6 0 3 8 1"
},
{
"input": "8 2\n7 2 9 6 1 0 3 4\n6 3",
"output": "6 3"
},
{
"input": "5 4\n7 0 1 4 9\n0 9 5 3",
"output": "0 9"
},
{
"input": "10 1\n9 6 2 0 1 8 3 4 7 5\n6",
"output": "6"
},
{
"input": "10 2\n7 1 0 2 4 6 5 9 3 8\n3 2",
"output": "2 3"
},
{
"input": "5 9\n3 7 9 2 4\n3 8 4 5 9 6 1 0 2",
"output": "3 9 2 4"
},
{
"input": "10 6\n7 1 2 3 8 0 6 4 5 9\n1 5 8 2 3 6",
"output": "1 2 3 8 6 5"
},
{
"input": "8 2\n7 4 8 9 2 5 6 1\n6 4",
"output": "4 6"
},
{
"input": "10 2\n1 0 3 5 8 9 4 7 6 2\n0 3",
"output": "0 3"
},
{
"input": "7 6\n9 2 8 6 1 3 7\n4 2 0 3 1 8",
"output": "2 8 1 3"
},
{
"input": "1 6\n3\n6 8 2 4 5 3",
"output": "3"
},
{
"input": "1 8\n0\n9 2 4 8 1 5 0 7",
"output": "0"
},
{
"input": "6 9\n7 3 9 4 1 0\n9 1 5 8 0 6 2 7 4",
"output": "7 9 4 1 0"
},
{
"input": "10 2\n4 9 6 8 3 0 1 5 7 2\n0 1",
"output": "0 1"
},
{
"input": "10 5\n5 2 8 0 9 7 6 1 4 3\n9 6 4 1 2",
"output": "2 9 6 1 4"
},
{
"input": "6 3\n8 3 9 2 7 6\n5 4 3",
"output": "3"
},
{
"input": "4 10\n8 3 9 6\n4 9 6 2 7 0 8 1 3 5",
"output": "8 3 9 6"
},
{
"input": "1 2\n1\n1 0",
"output": "1"
},
{
"input": "3 6\n1 2 3\n4 5 6 1 2 3",
"output": "1 2 3"
},
{
"input": "1 2\n2\n1 2",
"output": "2"
},
{
"input": "1 10\n9\n0 1 2 3 4 5 6 7 8 9",
"output": "9"
}
] | 1,649,957,830 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | n,m=list(map(int,input().split()))
d=list(map(int,input().split()))
f=list(map(int,input().split()))
l=[]
for ele in d:
if ele in f:
l.append(ele)
print(*l)
| Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints.
Output Specification:
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
Demo Input:
['7 3\n3 5 7 1 6 2 8\n1 2 7\n', '4 4\n3 4 1 0\n0 1 7 9\n']
Demo Output:
['7 1 2\n', '1 0\n']
Note:
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | ```python
n,m=list(map(int,input().split()))
d=list(map(int,input().split()))
f=list(map(int,input().split()))
l=[]
for ele in d:
if ele in f:
l.append(ele)
print(*l)
``` | 3 |
|
862 | B | Mahmoud and Ehab and the bipartiteness | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *u* and *v* belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.
Dr. Evil gave Mahmoud and Ehab a tree consisting of *n* nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?
A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . | The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105).
The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree.
It's guaranteed that the given graph is a tree. | Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | [
"3\n1 2\n1 3\n",
"5\n1 2\n2 3\n3 4\n4 5\n"
] | [
"0\n",
"2\n"
] | Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory))
Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph)
In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0.
In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5). | 1,000 | [
{
"input": "3\n1 2\n1 3",
"output": "0"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5",
"output": "2"
},
{
"input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6",
"output": "16"
},
{
"input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4",
"output": "16"
},
{
"input": "10\n2 6\n3 7\n8 4\n4 10\n6 9\n9 7\n3 10\n1 2\n5 8",
"output": "16"
},
{
"input": "10\n6 9\n9 7\n9 4\n10 9\n9 1\n9 8\n9 2\n9 5\n3 9",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
}
] | 1,681,493,284 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 764 | 13,721,600 | from collections import deque
def partition(graph):
colors = [-1 for _ in graph]
def search(start):
q = deque([(start, 0)])
colors[start] = 0
while q:
node, color = q.popleft()
for ngh in graph[node]:
if colors[ngh] == -1:
q.append((ngh, 1 - color))
colors[ngh] = 1 - color
return True
search(1)
return colors
n = int(input())
graph = [[] for _ in range(n + 1)]
for _ in range(n - 1):
u, v = [int(n) for n in input().split()]
graph[u].append(v)
graph[v].append(u)
colors = partition(graph)
print(colors.count(1) * colors.count(0) - (n - 1))
| Title: Mahmoud and Ehab and the bipartiteness
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *u* and *v* belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.
Dr. Evil gave Mahmoud and Ehab a tree consisting of *n* nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?
A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same .
Input Specification:
The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105).
The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree.
It's guaranteed that the given graph is a tree.
Output Specification:
Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions.
Demo Input:
['3\n1 2\n1 3\n', '5\n1 2\n2 3\n3 4\n4 5\n']
Demo Output:
['0\n', '2\n']
Note:
Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory))
Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph)
In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0.
In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5). | ```python
from collections import deque
def partition(graph):
colors = [-1 for _ in graph]
def search(start):
q = deque([(start, 0)])
colors[start] = 0
while q:
node, color = q.popleft()
for ngh in graph[node]:
if colors[ngh] == -1:
q.append((ngh, 1 - color))
colors[ngh] = 1 - color
return True
search(1)
return colors
n = int(input())
graph = [[] for _ in range(n + 1)]
for _ in range(n - 1):
u, v = [int(n) for n in input().split()]
graph[u].append(v)
graph[v].append(u)
colors = partition(graph)
print(colors.count(1) * colors.count(0) - (n - 1))
``` | 3 |
|
463 | B | Caisa and Pylons | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is to reach *n*-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as *k*) to the next one (its number will be *k*<=+<=1). When the player have made such a move, its energy increases by *h**k*<=-<=*h**k*<=+<=1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time.
Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game? | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | [
"5\n3 4 3 2 4\n",
"3\n4 4 4\n"
] | [
"4\n",
"4\n"
] | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | 1,000 | [
{
"input": "5\n3 4 3 2 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269 671 2986 942 758 1146 77 1545 3745 1547 2250 2565 217 1406 2070 3010 3404 404 1528 2352 138 2065 3047 3656 2188 2919 2616 2083 1280 2977 2681 548 4000 1667 1489 1109 3164 1565 2653 3260 3463 903 1824 3679 2308 245 2689 2063 648 568 766 785 2984 3812 440 1172 2730",
"output": "4000"
},
{
"input": "68\n477 1931 3738 3921 2306 1823 3328 2057 661 3993 2967 3520 171 1739 1525 1817 209 3475 1902 2666 518 3283 3412 3040 3383 2331 1147 1460 1452 1800 1327 2280 82 1416 2200 2388 3238 1879 796 250 1872 114 121 2042 1853 1645 211 2061 1472 2464 726 1989 1746 489 1380 1128 2819 2527 2939 622 678 265 2902 1111 2032 1453 3850 1621",
"output": "3993"
},
{
"input": "30\n30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "30"
},
{
"input": "3\n3 2 1",
"output": "3"
},
{
"input": "1\n69",
"output": "69"
}
] | 1,696,763,247 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
heights = list(map(int, input().split()))
dollars_paid = 0
current_energy = 0
for i in range(n):
energy_needed = heights[i] - heights[i + 1]
if energy_needed < 0:
dollars_paid += abs(energy_needed)
current_energy += abs(energy_needed)
else:
current_energy -= energy_needed
if current_energy < 0:
current_energy = 0
print(dollars_paid)
| Title: Caisa and Pylons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is to reach *n*-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as *k*) to the next one (its number will be *k*<=+<=1). When the player have made such a move, its energy increases by *h**k*<=-<=*h**k*<=+<=1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time.
Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons.
Output Specification:
Print a single number representing the minimum number of dollars paid by Caisa.
Demo Input:
['5\n3 4 3 2 4\n', '3\n4 4 4\n']
Demo Output:
['4\n', '4\n']
Note:
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | ```python
n = int(input())
heights = list(map(int, input().split()))
dollars_paid = 0
current_energy = 0
for i in range(n):
energy_needed = heights[i] - heights[i + 1]
if energy_needed < 0:
dollars_paid += abs(energy_needed)
current_energy += abs(energy_needed)
else:
current_energy -= energy_needed
if current_energy < 0:
current_energy = 0
print(dollars_paid)
``` | -1 |
|
981 | B | Businessmen Problems | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.
All elements are enumerated with integers. The ChemForces company has discovered $n$ distinct chemical elements with indices $a_1, a_2, \ldots, a_n$, and will get an income of $x_i$ Berland rubles if the $i$-th element from this list is in the set of this company.
The TopChemist company discovered $m$ distinct chemical elements with indices $b_1, b_2, \ldots, b_m$, and it will get an income of $y_j$ Berland rubles for including the $j$-th element from this list to its set.
In other words, the first company can present any subset of elements from $\{a_1, a_2, \ldots, a_n\}$ (possibly empty subset), the second company can present any subset of elements from $\{b_1, b_2, \ldots, b_m\}$ (possibly empty subset). There shouldn't be equal elements in the subsets.
Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible. | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of elements discovered by ChemForces.
The $i$-th of the next $n$ lines contains two integers $a_i$ and $x_i$ ($1 \leq a_i \leq 10^9$, $1 \leq x_i \leq 10^9$) — the index of the $i$-th element and the income of its usage on the exhibition. It is guaranteed that all $a_i$ are distinct.
The next line contains a single integer $m$ ($1 \leq m \leq 10^5$) — the number of chemicals invented by TopChemist.
The $j$-th of the next $m$ lines contains two integers $b_j$ and $y_j$, ($1 \leq b_j \leq 10^9$, $1 \leq y_j \leq 10^9$) — the index of the $j$-th element and the income of its usage on the exhibition. It is guaranteed that all $b_j$ are distinct. | Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets. | [
"3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n",
"1\n1000000000 239\n3\n14 15\n92 65\n35 89\n"
] | [
"24\n",
"408\n"
] | In the first example ChemForces can choose the set ($3, 7$), while TopChemist can choose ($1, 2, 4$). This way the total income is $(10 + 2) + (4 + 4 + 4) = 24$.
In the second example ChemForces can choose the only element $10^9$, while TopChemist can choose ($14, 92, 35$). This way the total income is $(239) + (15 + 65 + 89) = 408$. | 750 | [
{
"input": "3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4",
"output": "24"
},
{
"input": "1\n1000000000 239\n3\n14 15\n92 65\n35 89",
"output": "408"
},
{
"input": "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\n809901567 613170206\n152157661 479980560\n859252956 318029856\n614959273 735298093\n10\n849172317 361325206\n341655282 740807372\n453949939 809030434\n813199219 765838311\n725032511 427644854\n631233366 115983627\n825067417 721190169\n463026366 953335259\n881501578 987288937\n500099903 427659916",
"output": "11272808994"
},
{
"input": "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\n809901567 613170206\n152157661 479980560\n859252956 318029856\n614959273 735298093\n10\n544064902 740807372\n859252956 765838311\n835120075 115983627\n825067417 463026366\n809901567 500099903\n614959273 322932832\n33955432 657532637\n816892960 927933923\n916770606 754371712\n967529230 566149252",
"output": "8955052582"
},
{
"input": "1\n259021863 682413763\n1\n554146726 693647287",
"output": "1376061050"
},
{
"input": "1\n259021863 682413763\n1\n554146726 425883728",
"output": "1108297491"
},
{
"input": "1\n1000000000 1\n1\n1000000000 1000000000",
"output": "1000000000"
},
{
"input": "2\n1 4\n2 4\n2\n1 4\n2 4",
"output": "8"
},
{
"input": "1\n14 15\n3\n35 89\n92 65\n1000000000 239",
"output": "408"
}
] | 1,527,435,440 | 2,840 | Python 3 | OK | TESTS | 33 | 701 | 14,131,200 | cforce_count = int(input())
c_dic = {}
for _ in range(cforce_count):
arr = input().split()
c_dic[int(arr[0])] = int(arr[1])
tchem_count = int(input())
t_dic = {}
for _ in range(tchem_count):
arr = input().split()
t_dic[int(arr[0])] = int(arr[1])
total = 0
for key, val in c_dic.items():
if key in t_dic and t_dic[key] > val:
continue
elif key in t_dic and t_dic[key] <= val:
del(t_dic[key])
total += val
else:
total += val
for key, val in t_dic.items():
total += val
print("%d" %(total))
| Title: Businessmen Problems
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.
All elements are enumerated with integers. The ChemForces company has discovered $n$ distinct chemical elements with indices $a_1, a_2, \ldots, a_n$, and will get an income of $x_i$ Berland rubles if the $i$-th element from this list is in the set of this company.
The TopChemist company discovered $m$ distinct chemical elements with indices $b_1, b_2, \ldots, b_m$, and it will get an income of $y_j$ Berland rubles for including the $j$-th element from this list to its set.
In other words, the first company can present any subset of elements from $\{a_1, a_2, \ldots, a_n\}$ (possibly empty subset), the second company can present any subset of elements from $\{b_1, b_2, \ldots, b_m\}$ (possibly empty subset). There shouldn't be equal elements in the subsets.
Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.
Input Specification:
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of elements discovered by ChemForces.
The $i$-th of the next $n$ lines contains two integers $a_i$ and $x_i$ ($1 \leq a_i \leq 10^9$, $1 \leq x_i \leq 10^9$) — the index of the $i$-th element and the income of its usage on the exhibition. It is guaranteed that all $a_i$ are distinct.
The next line contains a single integer $m$ ($1 \leq m \leq 10^5$) — the number of chemicals invented by TopChemist.
The $j$-th of the next $m$ lines contains two integers $b_j$ and $y_j$, ($1 \leq b_j \leq 10^9$, $1 \leq y_j \leq 10^9$) — the index of the $j$-th element and the income of its usage on the exhibition. It is guaranteed that all $b_j$ are distinct.
Output Specification:
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
Demo Input:
['3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n', '1\n1000000000 239\n3\n14 15\n92 65\n35 89\n']
Demo Output:
['24\n', '408\n']
Note:
In the first example ChemForces can choose the set ($3, 7$), while TopChemist can choose ($1, 2, 4$). This way the total income is $(10 + 2) + (4 + 4 + 4) = 24$.
In the second example ChemForces can choose the only element $10^9$, while TopChemist can choose ($14, 92, 35$). This way the total income is $(239) + (15 + 65 + 89) = 408$. | ```python
cforce_count = int(input())
c_dic = {}
for _ in range(cforce_count):
arr = input().split()
c_dic[int(arr[0])] = int(arr[1])
tchem_count = int(input())
t_dic = {}
for _ in range(tchem_count):
arr = input().split()
t_dic[int(arr[0])] = int(arr[1])
total = 0
for key, val in c_dic.items():
if key in t_dic and t_dic[key] > val:
continue
elif key in t_dic and t_dic[key] <= val:
del(t_dic[key])
total += val
else:
total += val
for key, val in t_dic.items():
total += val
print("%d" %(total))
``` | 3 |
Subsets and Splits