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
920
B
Tea Queue
PROGRAMMING
1,200
[ "implementation" ]
null
null
Recently *n* students from city S moved to city P to attend a programming camp. They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea. *i*-th student comes to the end of the queue at the beginning of *l**i*-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of *r**i*-th second student *i* still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=1000). Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of students. Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=5000) — the second *i*-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition *l**i*<=-<=1<=≤<=*l**i* holds. The sum of *n* over all test cases doesn't exceed 1000. Note that in hacks you have to set *t*<==<=1.
For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea.
[ "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n" ]
[ "1 2 \n1 0 2 \n" ]
The example contains 2 tests: 1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
0
[ { "input": "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3", "output": "1 2 \n1 0 2 " }, { "input": "19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2\n1 2\n1 1\n2\n1 2000\n1 1\n2\n1 1\n1 2000\n2\n1 2000\n2 2\n2\n2 2000\n2 2\n2\n2 2\n2 2000", "output": "1 \n1 \n1 \n1 \n2 \n2 \n2 \n2 \n1999 \n1999 \n2000 \n1 0 \n1 2 \n1 0 \n1 0 \n1 2 \n1 2 \n2 0 \n2 3 " }, { "input": "1\n11\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "1 0 0 0 0 0 0 0 0 0 0 " }, { "input": "1\n5\n1 1\n1 2\n1 5\n1 1\n1 1", "output": "1 2 3 0 0 " } ]
1,517,589,086
6,986
Python 3
OK
TESTS
8
62
5,632,000
t = int(input()) r = [] l = [] for i in range(t): n = int(input()) for j in range(n): lcurr, rcurr = map(int, input().split()) if j == 0: t = lcurr + 1 print(t - 1, end=' ') else: if t > lcurr: if rcurr >= t: t += 1 print(t - 1, end=' ') else: print(0, end=' ') else: t = lcurr + 1 print(t - 1, end=' ') print()
Title: Tea Queue Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently *n* students from city S moved to city P to attend a programming camp. They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea. *i*-th student comes to the end of the queue at the beginning of *l**i*-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of *r**i*-th second student *i* still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it). Input Specification: The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=1000). Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of students. Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=5000) — the second *i*-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition *l**i*<=-<=1<=≤<=*l**i* holds. The sum of *n* over all test cases doesn't exceed 1000. Note that in hacks you have to set *t*<==<=1. Output Specification: For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea. Demo Input: ['2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n'] Demo Output: ['1 2 \n1 0 2 \n'] Note: The example contains 2 tests: 1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
```python t = int(input()) r = [] l = [] for i in range(t): n = int(input()) for j in range(n): lcurr, rcurr = map(int, input().split()) if j == 0: t = lcurr + 1 print(t - 1, end=' ') else: if t > lcurr: if rcurr >= t: t += 1 print(t - 1, end=' ') else: print(0, end=' ') else: t = lcurr + 1 print(t - 1, end=' ') print() ```
3
886
B
Vlad and Cafes
PROGRAMMING
1,000
[]
null
null
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
[ "5\n1 3 2 1 2\n", "6\n2 1 2 2 4 1\n" ]
[ "3\n", "2\n" ]
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
1,000
[ { "input": "5\n1 3 2 1 2", "output": "3" }, { "input": "6\n2 1 2 2 4 1", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "1\n200000", "output": "200000" }, { "input": "2\n2018 2017", "output": "2018" }, { "input": "5\n100 1000 1000 1000 1000", "output": "100" }, { "input": "8\n200000 1 200000 1 200000 1 200000 2", "output": "1" }, { "input": "5\n20000 1 2 3 4", "output": "20000" }, { "input": "2\n200000 1", "output": "200000" }, { "input": "3\n2 100 2", "output": "100" }, { "input": "2\n10 1", "output": "10" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "3\n5 5 5", "output": "5" }, { "input": "2\n5 1", "output": "5" } ]
1,698,051,409
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
26,828,800
n = int(input()) a = list(map(int,input().split())) a.reverse() b = [] for i in a: if i not in b: b.append(i) a.reverse() print(b[-1])
Title: Vlad and Cafes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. Input Specification: In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted. Output Specification: Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. Demo Input: ['5\n1 3 2 1 2\n', '6\n2 1 2 2 4 1\n'] Demo Output: ['3\n', '2\n'] Note: In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
```python n = int(input()) a = list(map(int,input().split())) a.reverse() b = [] for i in a: if i not in b: b.append(i) a.reverse() print(b[-1]) ```
0
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" }, { "input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734", "output": "ksjuuerbnlklcfdjeyq" }, { "input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879", "output": "fcgslzkicjrpbqaifgweyzreajjfdo" }, { "input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735", "output": "aawtvezfntstrcpgbzjbf" }, { "input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158", "output": "ivhgbxiv" } ]
1,632,172,107
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
154
6,963,200
n=int(input()) maxname='' maxnum=0 a=dict() for i in range(n): s=input().split() score=a.get(s[0],0)+int(s[1]) a[s[0]]=score if maxnum < score: maxnum=score maxname=s[0] print(maxname)
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. Input Specification: The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. Output Specification: Print the name of the winner. Demo Input: ['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n'] Demo Output: ['andrew\n', 'andrew\n'] Note: none
```python n=int(input()) maxname='' maxnum=0 a=dict() for i in range(n): s=input().split() score=a.get(s[0],0)+int(s[1]) a[s[0]]=score if maxnum < score: maxnum=score maxname=s[0] print(maxname) ```
0
812
B
Sagheer, the Hausmeister
PROGRAMMING
1,600
[ "bitmasks", "brute force", "dp" ]
null
null
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of *n* floors with stairs at the left and the right sides. Each floor has *m* rooms on the same line with a corridor that connects the left and right stairs passing by all the rooms. In other words, the building can be represented as a rectangle with *n* rows and *m*<=+<=2 columns, where the first and the last columns represent the stairs, and the *m* columns in the middle represent rooms. Sagheer is standing at the ground floor at the left stairs. He wants to turn all the lights off in such a way that he will not go upstairs until all lights in the floor he is standing at are off. Of course, Sagheer must visit a room to turn the light there off. It takes one minute for Sagheer to go to the next floor using stairs or to move from the current room/stairs to a neighboring room/stairs on the same floor. It takes no time for him to switch the light off in the room he is currently standing in. Help Sagheer find the minimum total time to turn off all the lights. Note that Sagheer does not have to go back to his starting position, and he does not have to visit rooms where the light is already switched off.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=15 and 1<=≤<=*m*<=≤<=100) — the number of floors and the number of rooms in each floor, respectively. The next *n* lines contains the building description. Each line contains a binary string of length *m*<=+<=2 representing a floor (the left stairs, then *m* rooms, then the right stairs) where 0 indicates that the light is off and 1 indicates that the light is on. The floors are listed from top to bottom, so that the last line represents the ground floor. The first and last characters of each string represent the left and the right stairs, respectively, so they are always 0.
Print a single integer — the minimum total time needed to turn off all the lights.
[ "2 2\n0010\n0100\n", "3 4\n001000\n000010\n000010\n", "4 3\n01110\n01110\n01110\n01110\n" ]
[ "5\n", "12\n", "18\n" ]
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to the second room in the last floor. In the third example, he will walk through the whole corridor alternating between the left and right stairs at each floor.
1,000
[ { "input": "2 2\n0010\n0100", "output": "5" }, { "input": "3 4\n001000\n000010\n000010", "output": "12" }, { "input": "4 3\n01110\n01110\n01110\n01110", "output": "18" }, { "input": "3 2\n0000\n0100\n0100", "output": "4" }, { "input": "1 89\n0000000000000000000000000000000100000000000000010000000000010000000000000000000000000000000", "output": "59" }, { "input": "2 73\n000000000000000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000100000010000000000000000000000000000", "output": "46" }, { "input": "3 61\n000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000", "output": "0" }, { "input": "4 53\n0000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000", "output": "0" }, { "input": "5 93\n00000000000000000000000000000000000000000000000000000000100000000000000000000000000000000001010\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00000000000000000000000000000010000000000000000000100000000000000000000000000000000000000000000\n00000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000", "output": "265" }, { "input": "6 77\n0000000000000000100000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000010000000000000\n0000000000010000000000000000000000000000000000000000000000000000000000000000010\n0000000000000000000001000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000100000000000000000000000000000", "output": "311" }, { "input": "7 65\n0000000001000000000000000010000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000001000001000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000", "output": "62" }, { "input": "8 57\n00000000100000000000000000000000000000000000000000000000000\n00000000000000010000000000000000000000000000000000000000000\n00000000000000000000000000000000000100000000000000000000000\n00000000000000000000000000000000000000000000000000000000000\n00000000000000000000000000000000000100000000000000000000000\n00000000000000000000000000000000000000000000000000000000000\n00000000000010000000000000000000000000000000000000000000000\n00000000000000000000000000000000000000000000000001000000000", "output": "277" }, { "input": "12 13\n000000000000000\n000000000000000\n000000000000000\n000000000000000\n000000000000000\n000000000000000\n010000000000000\n000000000000000\n000000000000000\n000000000000000\n000010000000000\n000000000000000", "output": "14" }, { "input": "13 1\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000", "output": "0" }, { "input": "1 33\n00000100101110001101000000110100010", "output": "33" }, { "input": "2 21\n00100110100010010010010\n01000001111001010000000", "output": "43" }, { "input": "3 5\n0001010\n0100000\n0100000", "output": "11" }, { "input": "4 45\n00010000101101100000101101000000100000001101100\n01110000100111010011000000100000000001000001100\n00000000001000100110100001000010011010001010010\n01111110100100000101101010011000100100001000000", "output": "184" }, { "input": "5 37\n010100000000000000000110000110010000010\n001101100010110011101000001010101101110\n010000001000100010010100000000001010000\n000000000100101000000101100001000001110\n000010000000000000100001001000011100110", "output": "193" }, { "input": "6 25\n011001000100111010000101000\n000000000010000010001000010\n011001100001100001001001010\n000000100000010000000000110\n010001100001000001000000010\n011000001001010111110000100", "output": "160" }, { "input": "7 61\n010000111100010100001000011010100001000000000011100000100010000\n000010011000001000000100110101010001000000010001100000100100100\n000010001000001000000100001000000100100011001110000111000000100\n000000000101000011010000011000000101000001011001000011101010010\n000010010011000000100000110000001000000101000000101000010000010\n000010010101101100100100100011001011101010000101000010000101010\n000100001100001001000000001000000001011000110010100000000010110", "output": "436" }, { "input": "8 49\n000100100000000111110010011100110100010010000011000\n001000000101111000000001111100010010100000010000000\n000000010000011100001000000000101000110010000100100\n000000000001000110000011101101000000100000101010000\n000000110001000101101000000001000000110001000110000\n000100000000000000100100010011000001111101010100110\n000000001000000010101111000100001100000000010111000\n001000010000110000011100000000100110000010001000000", "output": "404" }, { "input": "9 41\n0011000000000101001101001000000001110000010\n0000110000001010110010110010110010010001000\n0001100010100000000001110100100001101000100\n0001010101111010000000010010001001011111000\n0101000101000011101011000000001100110010000\n0001010000000000000001011000000100010101000\n0000010011000000001000110001000010110001000\n0000100010000110100001000000100010001111100\n0000001110100001000001000110001110000100000", "output": "385" }, { "input": "10 29\n0000000000101001100001001011000\n0001110100000000000000100010000\n0010001001000011000100010001000\n0001000010101000000010100010100\n0111000000000000100100100010100\n0001000100011111000100010100000\n0000000000000001000001001011000\n0000101110000001010001011001110\n0000001000101010011000001100100\n0100010000101011010000000000000", "output": "299" }, { "input": "1 57\n00011101100001110001111000000100101111000111101100111001000", "output": "55" }, { "input": "2 32\n0011110111011011011101111101011110\n0111000110111111011110011101011110", "output": "65" }, { "input": "3 20\n0110011111110101101100\n0111110000111010100100\n0110111110010100011110", "output": "63" }, { "input": "4 4\n011100\n001010\n010000\n011110", "output": "22" }, { "input": "5 44\n0001010010001111111001111111000010100100000010\n0001111001111001101111011111010110001001111110\n0111111010111111011101100011101010100101110110\n0011010011101011101111001001010110000111111100\n0110100111011100110101110010010011011101100100", "output": "228" }, { "input": "6 36\n01110101111111110101011000011111110010\n00011101100010110111111111110001100100\n00001111110010111111101110101110111110\n00110110011100100111011110000000000010\n01100101101001010001011111100111101100\n00011111111011001000011001011110011110", "output": "226" }, { "input": "7 24\n01111001111001011010010100\n00111011010101000111101000\n01001110110010010110011110\n00000101111011011111111000\n01111111101111001001010010\n01110000111101011111111010\n00000100011100110000110000", "output": "179" }, { "input": "8 8\n0011101110\n0110010100\n0100111110\n0111111100\n0011010100\n0001101110\n0111100000\n0110111000", "output": "77" }, { "input": "9 48\n00011010111110111011111001111111111101001111110010\n01000101000101101101111110111101011100001011010010\n00110111110110101110101110111111011011101111011000\n00110111111100010110110110111001001111011010101110\n01111111100101010011111100100111110011001101110100\n01111011110011111101010101010100001110111111111000\n01110101101101110001000010110100010110101111111100\n00111101001010110010110100000111110101010100001000\n00011011010110011111001100111100100011100110110100", "output": "448" }, { "input": "10 40\n010011001001111011011011101111010001010010\n011000000110000010001011111010100000110000\n011010101001110010110110011111010101101000\n000111111010101111000110011111011011011010\n010110101110001001001111111000110011101010\n010011010100111110010100100111100111011110\n001111101100111111111111001010111010000110\n001111110010101100110100101110001011100110\n010111010010001111110101111111111110111000\n011101101111000100111111111001111100111010", "output": "418" }, { "input": "11 28\n011100111101101001011111001110\n010001111110011101101011001000\n001010011011011010101101101100\n001100011001101011011001110100\n010111110011101110000110111100\n010010001111110000011111010100\n001011111111110011101101111010\n001101101011100100011011001110\n001111110110100110101011000010\n000101101011100001101101100100\n010011101101111011100111110100", "output": "328" }, { "input": "1 68\n0101111110111111111111111111110111111111111111111110111111101111111110", "output": "68" }, { "input": "2 56\n0011111111111110111111111111111111011111111111011111011110\n0111111111010111111111110111111111111110111111010111111110", "output": "113" }, { "input": "3 17\n0111111101111111110\n0111111111101011110\n0101111111111111110", "output": "55" }, { "input": "4 4\n011110\n010110\n010110\n011110", "output": "22" }, { "input": "5 89\n0011111111111101110110111111111101111011111011101110111111111111111111111111111111111111110\n0111111111111111111111111101111111111111111111111111111111111111111111111111111111111111110\n0111111111111011111111111111111111101111011111111111111111110110111101111111111111111011010\n0111111111111111011011111111111011111111111111111111111111111111111111111111111110111111010\n0111111101111011111110101011111111110111100100101111111011111111111111011011101111111111110", "output": "453" }, { "input": "6 77\n0111111110101011111111111111111111111111111111111111100111111111101111111111110\n0111111111111111111101111101111111111011111111011111111001011111111111101111110\n0111101111111111111111111111111111111110110011111111111011111111101111111111110\n0111110111111111111111111111111111111111111111111111011011111111111111111111110\n0101111110111111111111111111111111111111111011111111111111111111101111011011110\n0110111111101111110111111111111011111111101011111101111111111111111111110111100", "output": "472" }, { "input": "7 20\n0111111111111111111100\n0111110111111111111110\n0111111111111111111100\n0111111011111111111110\n0111111111111011101110\n0111101011110111111010\n0111111111111111111010", "output": "151" }, { "input": "8 8\n0111111110\n0111101110\n0111111110\n0111111110\n0111111110\n0110111100\n0101111110\n0110111110", "output": "78" }, { "input": "11 24\n01111111111101111111111110\n01111111111111111111111110\n01110111111111111111111110\n01111111111111111111011110\n01111111111111111110111110\n01111010111111100111101110\n01111111111111010101111100\n01111111111111110111111110\n01011101111111111101111110\n00111111011111111110111110\n01111111101111111101111110", "output": "284" }, { "input": "12 12\n01111111111000\n01101111110110\n01111110111110\n01111111111110\n01111111111010\n01011111110110\n01111111111110\n01101101011110\n01111111111110\n01111101011110\n00111111111110\n01111111011110", "output": "166" }, { "input": "15 28\n011111111101011111111101111110\n011111111111111111111111111110\n011101110111011011101111011110\n011111111011111011110111111110\n011111111110101111111111111110\n011111011111110011111111011010\n011110111111001101111111111110\n011111111110111111111011111110\n011111111111111111111111011110\n011111011111111111111011001010\n011111111101111111111101111110\n011111111110111111101111011110\n010111111111101111111111111110\n011111111111111111011111111110\n011011111111111110110111110110", "output": "448" }, { "input": "2 11\n0100000000000\n0000000010000", "output": "18" }, { "input": "1 100\n010010010011100001101101110111101010000101010001111001001101011110000011101110101000100111111001101110", "output": "100" }, { "input": "15 1\n010\n010\n010\n010\n010\n010\n000\n000\n000\n010\n000\n010\n000\n000\n000", "output": "29" }, { "input": "3 3\n00010\n00000\n00010", "output": "7" } ]
1,496,327,939
1,439
Python 3
WRONG_ANSWER
PRETESTS
3
46
0
n, m = map(int, input().split()) M = [] F = [] L = [] ans = 0 for i in range(n): s = list(map(int, list(input()))) M.append(s) l, r = m+1, -1 for j in range(len(s)): if s[j]: l = min(l, j) r = j ans += r - l F.append(l) L.append(r) ans += F[-1] for i in range(n-1, 0, -1): ans += 1 + min(F[i]+F[i-1], m+1-L[i]+m+1-L[i-1]) print(ans)
Title: Sagheer, the Hausmeister Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of *n* floors with stairs at the left and the right sides. Each floor has *m* rooms on the same line with a corridor that connects the left and right stairs passing by all the rooms. In other words, the building can be represented as a rectangle with *n* rows and *m*<=+<=2 columns, where the first and the last columns represent the stairs, and the *m* columns in the middle represent rooms. Sagheer is standing at the ground floor at the left stairs. He wants to turn all the lights off in such a way that he will not go upstairs until all lights in the floor he is standing at are off. Of course, Sagheer must visit a room to turn the light there off. It takes one minute for Sagheer to go to the next floor using stairs or to move from the current room/stairs to a neighboring room/stairs on the same floor. It takes no time for him to switch the light off in the room he is currently standing in. Help Sagheer find the minimum total time to turn off all the lights. Note that Sagheer does not have to go back to his starting position, and he does not have to visit rooms where the light is already switched off. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=15 and 1<=≤<=*m*<=≤<=100) — the number of floors and the number of rooms in each floor, respectively. The next *n* lines contains the building description. Each line contains a binary string of length *m*<=+<=2 representing a floor (the left stairs, then *m* rooms, then the right stairs) where 0 indicates that the light is off and 1 indicates that the light is on. The floors are listed from top to bottom, so that the last line represents the ground floor. The first and last characters of each string represent the left and the right stairs, respectively, so they are always 0. Output Specification: Print a single integer — the minimum total time needed to turn off all the lights. Demo Input: ['2 2\n0010\n0100\n', '3 4\n001000\n000010\n000010\n', '4 3\n01110\n01110\n01110\n01110\n'] Demo Output: ['5\n', '12\n', '18\n'] Note: In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to the second room in the last floor. In the third example, he will walk through the whole corridor alternating between the left and right stairs at each floor.
```python n, m = map(int, input().split()) M = [] F = [] L = [] ans = 0 for i in range(n): s = list(map(int, list(input()))) M.append(s) l, r = m+1, -1 for j in range(len(s)): if s[j]: l = min(l, j) r = j ans += r - l F.append(l) L.append(r) ans += F[-1] for i in range(n-1, 0, -1): ans += 1 + min(F[i]+F[i-1], m+1-L[i]+m+1-L[i-1]) print(ans) ```
0
873
B
Balanced Substring
PROGRAMMING
1,500
[ "dp", "implementation" ]
null
null
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to determine the length of the longest balanced substring of *s*.
The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*. The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*.
If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring.
[ "8\n11010111\n", "3\n111\n" ]
[ "4\n", "0\n" ]
In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring.
0
[ { "input": "8\n11010111", "output": "4" }, { "input": "3\n111", "output": "0" }, { "input": "11\n00001000100", "output": "2" }, { "input": "10\n0100000000", "output": "2" }, { "input": "13\n0001000011010", "output": "6" }, { "input": "14\n00000100101011", "output": "10" }, { "input": "14\n01111101111111", "output": "2" }, { "input": "18\n110010101101111111", "output": "10" }, { "input": "11\n00010000011", "output": "4" }, { "input": "10\n1000010110", "output": "6" }, { "input": "15\n100000100000011", "output": "4" }, { "input": "18\n011010101110111101", "output": "8" }, { "input": "10\n0011011111", "output": "6" }, { "input": "3\n011", "output": "2" }, { "input": "14\n11111111111111", "output": "0" }, { "input": "65\n11001000110001001011011110111100000000101001001010101111000100010", "output": "48" }, { "input": "10\n0011111000", "output": "10" }, { "input": "13\n1110000001110", "output": "12" }, { "input": "3\n110", "output": "2" }, { "input": "4\n1110", "output": "2" }, { "input": "9\n001011001", "output": "8" }, { "input": "2\n10", "output": "2" }, { "input": "2\n01", "output": "2" }, { "input": "12\n110000110000", "output": "8" }, { "input": "3\n001", "output": "2" }, { "input": "14\n11000011000000", "output": "8" }, { "input": "19\n0000011111111100000", "output": "18" }, { "input": "45\n011010001100001111110001011100000001101100111", "output": "44" }, { "input": "18\n000001111111100000", "output": "16" }, { "input": "4\n0101", "output": "4" }, { "input": "12\n000101011001", "output": "10" } ]
1,675,453,951
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
46
4,505,600
n = int(input()) s = [int(x) for x in list(input())] pr_sums = {} # пары префиксная сумма - индекс, на котором достигается ''' когда встречаем 1 -- прибавляем 1, иначе вычитаем -1 тогда в сбалансированной подстроке сумма будет 0 ''' # создадим массив префиксных сумм. в тот же проход pr = [0] * (n + 1) for i in range(1, n + 1): if s[i - 1] == 0: pr[i] = pr[i - 1] - 1 else: pr[i] = pr[i - 1] + 1 if pr[i] in pr_sums: pr_sums[pr[i]].append(i) else: pr_sums[pr[i]] = [i] # теперь ищем нужные подстроки. нам нужны индексы такие, что pr[l] = pr[r] max_ = 0 for el in pr_sums: if len(pr_sums[el]) > 1: max_ = max(max_, pr_sums[el][-1] - pr_sums[el][0]) print(max_)
Title: Balanced Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to determine the length of the longest balanced substring of *s*. Input Specification: The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*. The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. Output Specification: If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. Demo Input: ['8\n11010111\n', '3\n111\n'] Demo Output: ['4\n', '0\n'] Note: In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring.
```python n = int(input()) s = [int(x) for x in list(input())] pr_sums = {} # пары префиксная сумма - индекс, на котором достигается ''' когда встречаем 1 -- прибавляем 1, иначе вычитаем -1 тогда в сбалансированной подстроке сумма будет 0 ''' # создадим массив префиксных сумм. в тот же проход pr = [0] * (n + 1) for i in range(1, n + 1): if s[i - 1] == 0: pr[i] = pr[i - 1] - 1 else: pr[i] = pr[i - 1] + 1 if pr[i] in pr_sums: pr_sums[pr[i]].append(i) else: pr_sums[pr[i]] = [i] # теперь ищем нужные подстроки. нам нужны индексы такие, что pr[l] = pr[r] max_ = 0 for el in pr_sums: if len(pr_sums[el]) > 1: max_ = max(max_, pr_sums[el][-1] - pr_sums[el][0]) print(max_) ```
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,449,845,340
2,147,483,647
Python 3
OK
TESTS
102
62
0
N=input() M=input() l=len(N) for i in range (l): x=int(N[i]) y=int(M[i]) if x==y: d=0 if x!=y: d=1 print(d,end='')
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python N=input() M=input() l=len(N) for i in range (l): x=int(N[i]) y=int(M[i]) if x==y: d=0 if x!=y: d=1 print(d,end='') ```
3.9845
939
A
Love Triangle
PROGRAMMING
800
[ "graphs" ]
null
null
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*. We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes. The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th.
Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO». You can output any letter in lower case or in upper case.
[ "5\n2 4 5 1 3\n", "5\n5 5 5 5 1\n" ]
[ "YES\n", "NO\n" ]
In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle. In second example there are no love triangles.
500
[ { "input": "5\n2 4 5 1 3", "output": "YES" }, { "input": "5\n5 5 5 5 1", "output": "NO" }, { "input": "3\n3 1 2", "output": "YES" }, { "input": "10\n4 10 9 5 3 1 5 10 6 4", "output": "NO" }, { "input": "10\n5 5 4 9 10 9 9 5 3 1", "output": "YES" }, { "input": "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 62 47 29 40 37 14 59 91 12 54 25 58 12 43", "output": "NO" }, { "input": "100\n25 6 46 37 87 99 70 31 46 12 94 40 87 56 28 8 94 39 13 12 67 13 71 39 83 48 40 14 62 41 16 71 20 41 83 41 68 98 23 82 62 83 62 35 49 22 31 21 66 98 54 39 34 52 11 28 47 89 25 44 68 36 91 46 82 86 88 48 27 93 7 9 53 36 16 100 84 84 44 25 58 66 16 46 72 21 91 78 4 17 44 17 47 67 93 89 75 44 56 50", "output": "YES" }, { "input": "2\n2 1", "output": "NO" }, { "input": "3\n2 3 1", "output": "YES" }, { "input": "5\n2 1 4 5 3", "output": "YES" }, { "input": "5\n5 4 5 5 2", "output": "YES" } ]
1,679,633,526
2,147,483,647
Python 3
OK
TESTS
16
46
0
def res(): n = int(input()) planes = list(map(int, input().strip().split()))[:n] for i in range(n): a = planes[i] b = planes[a-1] c = planes[b-1] if c == i+1: print("YES") break else: print("NO") res()
Title: Love Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*. We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes. The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. Output Specification: Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO». You can output any letter in lower case or in upper case. Demo Input: ['5\n2 4 5 1 3\n', '5\n5 5 5 5 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle. In second example there are no love triangles.
```python def res(): n = int(input()) planes = list(map(int, input().strip().split()))[:n] for i in range(n): a = planes[i] b = planes[a-1] c = planes[b-1] if c == i+1: print("YES") break else: print("NO") res() ```
3
262
A
Roma and Lucky Numbers
PROGRAMMING
800
[ "implementation" ]
null
null
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem.
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
[ "3 4\n1 2 4\n", "3 2\n447 44 77\n" ]
[ "3\n", "2\n" ]
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
500
[ { "input": "3 4\n1 2 4", "output": "3" }, { "input": "3 2\n447 44 77", "output": "2" }, { "input": "2 2\n507978501 180480073", "output": "2" }, { "input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089", "output": "9" }, { "input": "6 100\n170427799 37215529 675016434 168544291 683447134 950090227", "output": "6" }, { "input": "4 2\n194041605 706221269 69909135 257655784", "output": "3" }, { "input": "4 2\n9581849 67346651 530497 272158241", "output": "4" }, { "input": "3 47\n378261451 163985731 230342101", "output": "3" }, { "input": "2 3\n247776868 480572137", "output": "1" }, { "input": "7 77\n366496749 549646417 278840199 119255907 33557677 379268590 150378796", "output": "7" }, { "input": "40 31\n32230963 709031779 144328646 513494529 36547831 416998222 84161665 318773941 170724397 553666286 368402971 48581613 31452501 368026285 47903381 939151438 204145360 189920160 288159400 133145006 314295423 450219949 160203213 358403181 478734385 29331901 31051111 110710191 567314089 139695685 111511396 87708701 317333277 103301481 110400517 634446253 481551313 39202255 105948 738066085", "output": "40" }, { "input": "1 8\n55521105", "output": "1" }, { "input": "49 3\n34644511 150953622 136135827 144208961 359490601 86708232 719413689 188605873 64330753 488776302 104482891 63360106 437791390 46521319 70778345 339141601 136198441 292941209 299339510 582531183 555958105 437904637 74219097 439816011 236010407 122674666 438442529 186501223 63932449 407678041 596993853 92223251 849265278 480265849 30983497 330283357 186901672 20271344 794252593 123774176 27851201 52717531 479907210 196833889 149331196 82147847 255966471 278600081 899317843", "output": "44" }, { "input": "26 2\n330381357 185218042 850474297 483015466 296129476 1205865 538807493 103205601 160403321 694220263 416255901 7245756 507755361 88187633 91426751 1917161 58276681 59540376 576539745 595950717 390256887 105690055 607818885 28976353 488947089 50643601", "output": "22" }, { "input": "38 1\n194481717 126247087 815196361 106258801 381703249 283859137 15290101 40086151 213688513 577996947 513899717 371428417 107799271 11136651 5615081 323386401 381128815 34217126 17709913 520702093 201694245 570931849 169037023 417019726 282437316 7417126 271667553 11375851 185087449 410130883 383045677 5764771 905017051 328584026 215330671 299553233 15838255 234532105", "output": "20" }, { "input": "44 9\n683216389 250581469 130029957 467020047 188395565 206237982 63257361 68314981 732878407 563579660 199133851 53045209 665723851 16273169 10806790 556633156 350593410 474645249 478790761 708234243 71841230 18090541 19836685 146373571 17947452 534010506 46933264 377035021 311636557 75193963 54321761 12759959 71120181 548816939 23608621 31876417 107672995 72575155 369667956 20574379 210596751 532163173 75726739 853719629", "output": "44" }, { "input": "8 6\n204157376 10514197 65483881 347219841 263304577 296402721 11739011 229776191", "output": "8" }, { "input": "38 29\n333702889 680931737 61137217 203030505 68728281 11414209 642645708 590904616 3042901 607198177 189041074 700764043 813035201 198341461 126403544 401436841 420826465 45046581 20249976 46978855 46397957 706610773 24701041 57954481 51603266 593109701 385569073 178982291 582152863 287317968 1474090 34825141 432421977 130257781 151516903 540852403 548392 117246529", "output": "38" }, { "input": "19 3\n562569697 549131571 50676718 84501863 74567295 702372009 365895280 451459937 40378543 167666701 158635641 53639293 442332661 825055617 100109161 326616021 862332843 533271196 4791547", "output": "18" }, { "input": "1 1\n44", "output": "0" }, { "input": "1 1\n4", "output": "1" }, { "input": "10 3\n444 447 774 777 7777 4447 4 7 7 4", "output": "8" } ]
1,588,917,850
2,147,483,647
Python 3
OK
TESTS
34
248
6,656,000
# bsdk idhar kya dekhne ko aaya hai, khud kr!!! # from math import * # from itertools import * # import random n, k = map(int, input().split()) arr = list(map(str, input().split())) count_ = 0 for i in arr: if (i.count("4") + i.count("7")) > k: continue else: count_ += 1 print(count_)
Title: Roma and Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem. Input Specification: The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces. Output Specification: In a single line print a single integer — the answer to the problem. Demo Input: ['3 4\n1 2 4\n', '3 2\n447 44 77\n'] Demo Output: ['3\n', '2\n'] Note: In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
```python # bsdk idhar kya dekhne ko aaya hai, khud kr!!! # from math import * # from itertools import * # import random n, k = map(int, input().split()) arr = list(map(str, input().split())) count_ = 0 for i in arr: if (i.count("4") + i.count("7")) > k: continue else: count_ += 1 print(count_) ```
3
246
B
Increase and Decrease
PROGRAMMING
1,300
[ "greedy", "math" ]
null
null
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: - he chooses two elements of the array *a**i*, *a**j* (*i*<=≠<=*j*); - he simultaneously increases number *a**i* by 1 and decreases number *a**j* by 1, that is, executes *a**i*<==<=*a**i*<=+<=1 and *a**j*<==<=*a**j*<=-<=1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array.
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
[ "2\n2 1\n", "3\n1 4 1\n" ]
[ "1\n", "3\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 4 1", "output": "3" }, { "input": "4\n2 -7 -2 -6", "output": "3" }, { "input": "4\n2 0 -2 -1", "output": "3" }, { "input": "6\n-1 1 0 0 -1 -1", "output": "5" }, { "input": "5\n0 0 0 0 0", "output": "5" }, { "input": "100\n968 793 -628 -416 942 -308 977 168 728 -879 952 781 -425 -475 -480 738 -740 142 -319 -116 -701 -183 41 324 -918 -391 -176 781 763 888 475 -617 134 -802 -133 -211 855 -869 -236 503 550 387 137 -221 -957 -800 -56 -673 440 -791 -217 -959 -892 886 -593 427 890 223 -425 -342 -262 693 -137 924 860 156 -110 444 -12 703 421 -638 725 -551 597 -206 -80 393 -441 -759 617 424 -506 209 579 -685 -861 507 312 597 -81 -491 424 222 -892 629 512 743 -452 -504", "output": "99" } ]
1,613,462,417
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
216
2,150,400
for _ in range(int(input())): n=int(input()) array=[int(i) for i in input().split()] if sum(array)%n: print(n-1) else: print(n)
Title: Increase and Decrease Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: - he chooses two elements of the array *a**i*, *a**j* (*i*<=≠<=*j*); - he simultaneously increases number *a**i* by 1 and decreases number *a**j* by 1, that is, executes *a**i*<==<=*a**i*<=+<=1 and *a**j*<==<=*a**j*<=-<=1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. Output Specification: Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Demo Input: ['2\n2 1\n', '3\n1 4 1\n'] Demo Output: ['1\n', '3\n'] Note: none
```python for _ in range(int(input())): n=int(input()) array=[int(i) for i in input().split()] if sum(array)%n: print(n-1) else: print(n) ```
-1
899
A
Splitting in Teams
PROGRAMMING
800
[ "constructive algorithms", "greedy", "math" ]
null
null
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*.
Print the maximum number of teams of three people the coach can form.
[ "4\n1 1 2 1\n", "2\n2 2\n", "7\n2 2 2 1 1 1 1\n", "3\n1 1 1\n" ]
[ "1\n", "0\n", "3\n", "1\n" ]
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person).
500
[ { "input": "4\n1 1 2 1", "output": "1" }, { "input": "2\n2 2", "output": "0" }, { "input": "7\n2 2 2 1 1 1 1", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n2 2 1 1 1", "output": "2" }, { "input": "7\n1 1 2 2 1 2 1", "output": "3" }, { "input": "10\n1 2 2 1 2 2 1 2 1 1", "output": "5" }, { "input": "5\n2 2 2 1 2", "output": "1" }, { "input": "43\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2", "output": "10" }, { "input": "72\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2", "output": "34" }, { "input": "64\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2", "output": "32" }, { "input": "20\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2", "output": "9" }, { "input": "23\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1", "output": "11" }, { "input": "201\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2", "output": "100" }, { "input": "247\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2", "output": "123" }, { "input": "4\n2 2 2 2", "output": "0" }, { "input": "4\n1 1 1 1", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "2\n1 2", "output": "1" }, { "input": "3\n1 1 2", "output": "1" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "3\n2 1 2", "output": "1" }, { "input": "3\n2 2 1", "output": "1" }, { "input": "4\n1 1 1 2", "output": "1" }, { "input": "4\n1 1 2 2", "output": "2" }, { "input": "4\n1 2 2 2", "output": "1" }, { "input": "4\n2 1 1 1", "output": "1" }, { "input": "5\n1 1 1 1 2", "output": "2" }, { "input": "14\n1 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "1" }, { "input": "38\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 1", "output": "1" }, { "input": "30\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1", "output": "1" }, { "input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1", "output": "1" }, { "input": "26\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2", "output": "1" }, { "input": "6\n1 1 1 2 2 2", "output": "3" }, { "input": "5\n2 1 1 1 1", "output": "2" }, { "input": "9\n1 1 1 1 1 1 2 2 2", "output": "4" }, { "input": "10\n2 2 1 1 1 1 1 1 1 1", "output": "4" }, { "input": "6\n1 1 1 1 1 1", "output": "2" } ]
1,628,673,249
2,147,483,647
Python 3
OK
TESTS
67
124
11,059,200
n = int(input()) a = list(map(int, input().split())) ones,twos = 0,0 for i in a: if i == 1: ones += 1 else: twos += 1 if twos == 0: print(ones//3) elif ones == 0: print(0) else: mn = min(ones,twos) print(mn + (ones - mn)//3)
Title: Splitting in Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team. Input Specification: The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. Output Specification: Print the maximum number of teams of three people the coach can form. Demo Input: ['4\n1 1 2 1\n', '2\n2 2\n', '7\n2 2 2 1 1 1 1\n', '3\n1 1 1\n'] Demo Output: ['1\n', '0\n', '3\n', '1\n'] Note: In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person).
```python n = int(input()) a = list(map(int, input().split())) ones,twos = 0,0 for i in a: if i == 1: ones += 1 else: twos += 1 if twos == 0: print(ones//3) elif ones == 0: print(0) else: mn = min(ones,twos) print(mn + (ones - mn)//3) ```
3
540
A
Combination Lock
PROGRAMMING
800
[ "implementation" ]
null
null
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
[ "5\n82195\n64723\n" ]
[ "13\n" ]
In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
500
[ { "input": "5\n82195\n64723", "output": "13" }, { "input": "12\n102021090898\n010212908089", "output": "16" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "10\n0728592530\n1362615763", "output": "27" }, { "input": "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746", "output": "245" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "3\n607\n684", "output": "5" }, { "input": "4\n0809\n0636", "output": "8" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8037856825987124762280548\n9519431339078678836940020", "output": "72" }, { "input": "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024", "output": "305" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8037856825987124762285484\n9519431339078678836940202", "output": "74" }, { "input": "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831", "output": "357" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8378525987476228048406972\n9194339078883694020217816", "output": "55" }, { "input": "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599", "output": "274" }, { "input": "1\n0\n0", "output": "0" }, { "input": "1\n7\n7", "output": "0" }, { "input": "1\n0\n5", "output": "5" }, { "input": "1\n2\n7", "output": "5" }, { "input": "1\n7\n9", "output": "2" }, { "input": "1\n9\n7", "output": "2" }, { "input": "1\n2\n9", "output": "3" }, { "input": "1\n9\n2", "output": "3" }, { "input": "25\n3164978461316464614169874\n9413979197249127496597357", "output": "66" }, { "input": "4\n9999\n9999", "output": "0" }, { "input": "2\n11\n11", "output": "0" } ]
1,609,057,577
2,147,483,647
Python 3
OK
TESTS
43
109
307,200
n=int(input()) a=list(input()) if a[len(a)-1]=='\r': a.pop() b=list(input()) if b[len(b)-1]=='\r': b.pop() for i in range(len(a)): a[i]=int(a[i]) for i in range(len(b)): b[i]=int(b[i]) s=0 for i in range(len(a)): s1=max(a[i],b[i])-min(a[i],b[i]) s2=(a[i]+10)-b[i] s3=(b[i]+10)-a[i] s+=min(s1,s2,s3) print(s)
Title: Combination Lock Time Limit: None seconds Memory Limit: None megabytes Problem Description: Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. Output Specification: Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. Demo Input: ['5\n82195\n64723\n'] Demo Output: ['13\n'] Note: In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python n=int(input()) a=list(input()) if a[len(a)-1]=='\r': a.pop() b=list(input()) if b[len(b)-1]=='\r': b.pop() for i in range(len(a)): a[i]=int(a[i]) for i in range(len(b)): b[i]=int(b[i]) s=0 for i in range(len(a)): s1=max(a[i],b[i])-min(a[i],b[i]) s2=(a[i]+10)-b[i] s3=(b[i]+10)-a[i] s+=min(s1,s2,s3) print(s) ```
3
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,829
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
n, m = map(int, input().split()) g = [[] for _ in range(n + 2)] s = [2] for i in range(m): s = list(map(int, input().split())) g[s[0]].append(s[1]) g[s[1]].append(s[0]) flag = True count = 0 while flag == True: c = 1 p = [0 for _ in range(n + 2)] for i in range(1, m + 1): if len(g[i]) == 1 and p[i] != 1: del g[g[i][0]][g[g[i][0]].index(i)] p[g[i][0]] = 1 del g[i][0] c = 0 print(p) if c == 1: flag = False else: count += 1 if count == 0: print(count) else: print(count - 1)
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 _ in range(n + 2)] s = [2] for i in range(m): s = list(map(int, input().split())) g[s[0]].append(s[1]) g[s[1]].append(s[0]) flag = True count = 0 while flag == True: c = 1 p = [0 for _ in range(n + 2)] for i in range(1, m + 1): if len(g[i]) == 1 and p[i] != 1: del g[g[i][0]][g[g[i][0]].index(i)] p[g[i][0]] = 1 del g[i][0] c = 0 print(p) if c == 1: flag = False else: count += 1 if count == 0: print(count) else: print(count - 1) ```
0
534
B
Covered Path
PROGRAMMING
1,400
[ "dp", "greedy", "math" ]
null
null
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass. Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by *d* meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed *d* in absolute value), find the maximum possible length of the path section in meters.
The first line contains two integers *v*1 and *v*2 (1<=≤<=*v*1,<=*v*2<=≤<=100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively. The second line contains two integers *t* (2<=≤<=*t*<=≤<=100) — the time when the car moves along the segment in seconds, *d* (0<=≤<=*d*<=≤<=10) — the maximum value of the speed change between adjacent seconds. It is guaranteed that there is a way to complete the segment so that: - the speed in the first second equals *v*1, - the speed in the last second equals *v*2, - the absolute value of difference of speeds between any two adjacent seconds doesn't exceed *d*.
Print the maximum possible length of the path segment in meters.
[ "5 6\n4 2\n", "10 10\n10 0\n" ]
[ "26", "100" ]
In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters. In the second sample, as *d* = 0, the car covers the whole segment at constant speed *v* = 10. In *t* = 10 seconds it covers the distance of 100 meters.
1,000
[ { "input": "5 6\n4 2", "output": "26" }, { "input": "10 10\n10 0", "output": "100" }, { "input": "87 87\n2 10", "output": "174" }, { "input": "1 11\n6 2", "output": "36" }, { "input": "100 10\n10 10", "output": "550" }, { "input": "1 1\n100 10", "output": "24600" }, { "input": "1 1\n5 1", "output": "9" }, { "input": "1 1\n5 2", "output": "13" }, { "input": "100 100\n100 0", "output": "10000" }, { "input": "100 100\n100 10", "output": "34500" }, { "input": "1 100\n100 1", "output": "5050" }, { "input": "1 100\n100 10", "output": "29305" }, { "input": "100 1\n100 1", "output": "5050" }, { "input": "100 1\n100 10", "output": "29305" }, { "input": "1 10\n2 10", "output": "11" }, { "input": "1 1\n2 1", "output": "2" }, { "input": "1 1\n2 10", "output": "2" }, { "input": "1 2\n2 1", "output": "3" }, { "input": "1 2\n2 10", "output": "3" }, { "input": "1 5\n3 2", "output": "9" }, { "input": "2 1\n2 2", "output": "3" }, { "input": "2 1\n2 10", "output": "3" }, { "input": "1 11\n2 10", "output": "12" }, { "input": "11 1\n2 10", "output": "12" }, { "input": "1 1\n3 5", "output": "8" }, { "input": "1 10\n3 5", "output": "17" }, { "input": "1 21\n3 10", "output": "33" }, { "input": "21 1\n3 10", "output": "33" }, { "input": "100 100\n99 1", "output": "12301" }, { "input": "100 100\n100 1", "output": "12450" }, { "input": "99 99\n99 1", "output": "12202" }, { "input": "99 99\n99 10", "output": "33811" }, { "input": "1 100\n99 10", "output": "28764" }, { "input": "13 31\n7 5", "output": "182" }, { "input": "88 78\n8 5", "output": "719" }, { "input": "34 48\n47 4", "output": "4030" }, { "input": "91 29\n78 3", "output": "8806" }, { "input": "90 81\n21 6", "output": "2391" }, { "input": "95 89\n45 3", "output": "5589" }, { "input": "48 54\n84 2", "output": "7724" }, { "input": "72 31\n59 7", "output": "8865" }, { "input": "51 13\n47 3", "output": "2970" }, { "input": "97 91\n82 2", "output": "10984" }, { "input": "71 71\n9 5", "output": "719" }, { "input": "16 49\n40 3", "output": "2350" }, { "input": "22 41\n68 4", "output": "6608" }, { "input": "13 71\n72 6", "output": "10444" }, { "input": "77 78\n46 3", "output": "5083" }, { "input": "36 60\n54 2", "output": "3924" }, { "input": "55 39\n93 2", "output": "8571" }, { "input": "34 7\n48 6", "output": "4266" }, { "input": "80 88\n79 3", "output": "11193" }, { "input": "34 62\n15 4", "output": "866" }, { "input": "81 40\n73 2", "output": "6798" }, { "input": "13 38\n97 6", "output": "16271" }, { "input": "84 87\n45 2", "output": "4814" }, { "input": "42 65\n76 3", "output": "8240" }, { "input": "55 6\n24 4", "output": "1110" }, { "input": "41 16\n43 2", "output": "2029" }, { "input": "99 93\n78 1", "output": "8961" }, { "input": "10 7\n44 2", "output": "1297" }, { "input": "72 54\n91 3", "output": "11781" }, { "input": "48 34\n80 2", "output": "6376" }, { "input": "92 85\n70 1", "output": "7373" } ]
1,584,391,590
2,147,483,647
PyPy 3
OK
TESTS
64
155
0
# maa chudaaye duniya v1, v2 = sorted(list(map(int, input().split()))) t, d = map(int, input().split()) s = v1 + v2 for i in range(1, t-1): s += min(v1 + d*i, v2 + d*(t-i-1)) print(s)
Title: Covered Path Time Limit: None seconds Memory Limit: None megabytes Problem Description: The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass. Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by *d* meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed *d* in absolute value), find the maximum possible length of the path section in meters. Input Specification: The first line contains two integers *v*1 and *v*2 (1<=≤<=*v*1,<=*v*2<=≤<=100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively. The second line contains two integers *t* (2<=≤<=*t*<=≤<=100) — the time when the car moves along the segment in seconds, *d* (0<=≤<=*d*<=≤<=10) — the maximum value of the speed change between adjacent seconds. It is guaranteed that there is a way to complete the segment so that: - the speed in the first second equals *v*1, - the speed in the last second equals *v*2, - the absolute value of difference of speeds between any two adjacent seconds doesn't exceed *d*. Output Specification: Print the maximum possible length of the path segment in meters. Demo Input: ['5 6\n4 2\n', '10 10\n10 0\n'] Demo Output: ['26', '100'] Note: In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters. In the second sample, as *d* = 0, the car covers the whole segment at constant speed *v* = 10. In *t* = 10 seconds it covers the distance of 100 meters.
```python # maa chudaaye duniya v1, v2 = sorted(list(map(int, input().split()))) t, d = map(int, input().split()) s = v1 + v2 for i in range(1, t-1): s += min(v1 + d*i, v2 + d*(t-i-1)) print(s) ```
3
284
A
Cows and Primitive Roots
PROGRAMMING
1,400
[ "implementation", "math", "number theory" ]
null
null
The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=&lt;<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is. Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime *p*, help the cows find the number of primitive roots .
The input contains a single line containing an integer *p* (2<=≤<=*p*<=&lt;<=2000). It is guaranteed that *p* is a prime.
Output on a single line the number of primitive roots .
[ "3\n", "5\n" ]
[ "1\n", "2\n" ]
The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2. The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf94d00bc49a7ac458fd58.png" style="max-width: 100.0%;max-height: 100.0%;"/> are 2 and 3.
500
[ { "input": "3", "output": "1" }, { "input": "5", "output": "2" }, { "input": "7", "output": "2" }, { "input": "11", "output": "4" }, { "input": "17", "output": "8" }, { "input": "19", "output": "6" }, { "input": "1583", "output": "672" }, { "input": "997", "output": "328" }, { "input": "2", "output": "1" }, { "input": "1987", "output": "660" }, { "input": "1993", "output": "656" }, { "input": "1997", "output": "996" }, { "input": "1999", "output": "648" }, { "input": "1297", "output": "432" }, { "input": "163", "output": "54" }, { "input": "1259", "output": "576" }, { "input": "821", "output": "320" }, { "input": "29", "output": "12" }, { "input": "43", "output": "12" }, { "input": "1949", "output": "972" }, { "input": "1879", "output": "624" }, { "input": "1759", "output": "584" }, { "input": "1597", "output": "432" }, { "input": "1619", "output": "808" }, { "input": "1277", "output": "560" }, { "input": "1097", "output": "544" }, { "input": "953", "output": "384" }, { "input": "751", "output": "200" }, { "input": "607", "output": "200" }, { "input": "509", "output": "252" }, { "input": "431", "output": "168" }, { "input": "317", "output": "156" }, { "input": "211", "output": "48" }, { "input": "127", "output": "36" }, { "input": "101", "output": "40" }, { "input": "31", "output": "8" } ]
1,588,866,823
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
248
20,172,800
x = int(input()) i = 2 ar = [] def fac(n): global i,ar if (n % i == 0): ar.append(i) fac(n//i) else: if i<n: i += 1 fac(n) fac(x-1) c = 1 nar = set(ar) for i in nar: a = (len(ar) - ar[::-1].index(i)) - (ar.index(i) + 1) + 1 if a > 1: c = c * (i ** (a-1)) else: c = c * (i-1) print(c)
Title: Cows and Primitive Roots Time Limit: None seconds Memory Limit: None megabytes Problem Description: The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=&lt;<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is. Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime *p*, help the cows find the number of primitive roots . Input Specification: The input contains a single line containing an integer *p* (2<=≤<=*p*<=&lt;<=2000). It is guaranteed that *p* is a prime. Output Specification: Output on a single line the number of primitive roots . Demo Input: ['3\n', '5\n'] Demo Output: ['1\n', '2\n'] Note: The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2. The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf94d00bc49a7ac458fd58.png" style="max-width: 100.0%;max-height: 100.0%;"/> are 2 and 3.
```python x = int(input()) i = 2 ar = [] def fac(n): global i,ar if (n % i == 0): ar.append(i) fac(n//i) else: if i<n: i += 1 fac(n) fac(x-1) c = 1 nar = set(ar) for i in nar: a = (len(ar) - ar[::-1].index(i)) - (ar.index(i) + 1) + 1 if a > 1: c = c * (i ** (a-1)) else: c = c * (i-1) print(c) ```
0
908
B
New Year and Buggy Bot
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
Bob programmed a robot to navigate through a 2d maze. The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'. There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. Its position is denoted with the character 'E'. This position has no obstacle in it. The robot can only move up, left, right, or down. When Bob programmed the robot, he wrote down a string of digits consisting of the digits 0 to 3, inclusive. He intended for each digit to correspond to a distinct direction, and the robot would follow the directions in order to reach the exit. Unfortunately, he forgot to actually assign the directions to digits. The robot will choose some random mapping of digits to distinct directions. The robot will map distinct digits to distinct directions. The robot will then follow the instructions according to the given string in order and chosen mapping. If an instruction would lead the robot to go off the edge of the maze or hit an obstacle, the robot will crash and break down. If the robot reaches the exit at any point, then the robot will stop following any further instructions. Bob is having trouble debugging his robot, so he would like to determine the number of mappings of digits to directions that would lead the robot to the exit.
The first line of input will contain two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50), denoting the dimensions of the maze. The next *n* lines will contain exactly *m* characters each, denoting the maze. Each character of the maze will be '.', '#', 'S', or 'E'. There will be exactly one 'S' and exactly one 'E' in the maze. The last line will contain a single string *s* (1<=≤<=|*s*|<=≤<=100) — the instructions given to the robot. Each character of *s* is a digit from 0 to 3.
Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit.
[ "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012\n", "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021\n", "5 3\n...\n.S.\n###\n.E.\n...\n3\n" ]
[ "1\n", "14\n", "0\n" ]
For the first sample, the only valid mapping is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/87a55361bde12e4223a96f0e1d83b94428f26f02.png" style="max-width: 100.0%;max-height: 100.0%;"/>, where *D* is down, *L* is left, *U* is up, *R* is right.
750
[ { "input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012", "output": "1" }, { "input": "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021", "output": "14" }, { "input": "5 3\n...\n.S.\n###\n.E.\n...\n3", "output": "0" }, { "input": "10 10\n.#......#.\n#.........\n#.........\n....#.#..E\n.......#..\n....##....\n....S.....\n....#.....\n.........#\n...##...#.\n23323332313123221123020122221313323310313122323233", "output": "0" }, { "input": "8 9\n.........\n.........\n.........\n.E.#.....\n.........\n.........\n...#.S...\n.........\n10001100111000010121100000110110110100000100000100", "output": "2" }, { "input": "15 13\n.............\n.............\n.............\n.........#...\n..#..........\n.............\n..........E..\n.............\n.............\n.#...........\n.....#.......\n..........#..\n..........S..\n.............\n.........#...\n32222221111222312132110100022020202131222103103330", "output": "2" }, { "input": "5 5\n.....\n.....\n..SE.\n.....\n.....\n012330213120031231022103231013201032301223011230102320130231321012030321213002133201130201322031", "output": "24" }, { "input": "2 2\nS.\n.E\n23", "output": "4" }, { "input": "2 2\nS.\n.E\n03", "output": "4" }, { "input": "2 2\nSE\n..\n22", "output": "6" }, { "input": "2 2\nS.\nE.\n11", "output": "6" }, { "input": "2 2\n#E\nS.\n01", "output": "2" }, { "input": "10 10\n####S.####\n#####.####\n#####.####\n#####.####\n#####..###\n######.###\n######.###\n######.E##\n##########\n##########\n0111101110", "output": "2" }, { "input": "10 10\n#####..E##\n#####.S.##\n#####...##\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n20", "output": "4" }, { "input": "10 10\n#####ES.##\n######.###\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n3", "output": "6" }, { "input": "2 10\nS........E\n..........\n33333333333333333", "output": "6" }, { "input": "2 2\n..\nSE\n0", "output": "6" }, { "input": "2 2\nSE\n##\n0", "output": "6" }, { "input": "2 2\nS.\nE.\n012", "output": "8" }, { "input": "2 3\nS.E\n###\n1222", "output": "0" }, { "input": "2 5\nS...E\n.....\n133330", "output": "1" }, { "input": "5 5\n.....\n.....\n.S.E.\n.....\n.....\n001111", "output": "6" }, { "input": "3 5\n....S\n....#\n....E\n0112", "output": "1" }, { "input": "2 2\nSE\n..\n123", "output": "8" }, { "input": "2 10\n........ES\n..........\n123", "output": "8" }, { "input": "2 2\nS.\n.E\n2311", "output": "4" }, { "input": "2 2\nS.\n.E\n0012", "output": "0" }, { "input": "2 7\nS.....E\n#######\n01111111", "output": "0" }, { "input": "2 2\nS.\n.E\n1123", "output": "0" }, { "input": "2 3\nS.E\n...\n0111", "output": "0" }, { "input": "2 50\n.................................................E\nS.................................................\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "0" }, { "input": "5 2\n..\n..\n..\n..\nSE\n0", "output": "6" }, { "input": "3 3\nE..\n.S.\n...\n001123110023221103", "output": "0" }, { "input": "2 2\nS#\nE#\n012", "output": "6" }, { "input": "2 2\nES\n..\n011", "output": "6" }, { "input": "2 2\nSE\n..\n011", "output": "6" }, { "input": "2 2\nS.\nE.\n102", "output": "8" }, { "input": "3 2\nE#\n##\nS#\n0112", "output": "0" } ]
1,514,859,531
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
5,529,600
from itertools import permutations #take dimension of the grid as input n,m = map(int,input().split()) #take grid g = [input() for _ in range(n)] inst = map(int,input()) dx = [0,-1,0,1] dy = [1,0,-1,0] sx,sy,ex,ey = -1,-1,-1,-1 for i in range(n): for j in range(m): if g[i][j] == 'E': ex,ey = i,j if g[i][j] == 'S': sx,sy = i,j def go(dirs): cx,cy = sx,sy for e in inst: cx += dx[dirs[e]] cy += dy[dirs[e]] if not (0<=cx<n and 0<=cy<m and g[cx][cy]!='#'): return False if (cx,cy)==(ex,ey): return True return False print(sum(map(go,permutations(range(4)))))
Title: New Year and Buggy Bot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bob programmed a robot to navigate through a 2d maze. The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'. There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. Its position is denoted with the character 'E'. This position has no obstacle in it. The robot can only move up, left, right, or down. When Bob programmed the robot, he wrote down a string of digits consisting of the digits 0 to 3, inclusive. He intended for each digit to correspond to a distinct direction, and the robot would follow the directions in order to reach the exit. Unfortunately, he forgot to actually assign the directions to digits. The robot will choose some random mapping of digits to distinct directions. The robot will map distinct digits to distinct directions. The robot will then follow the instructions according to the given string in order and chosen mapping. If an instruction would lead the robot to go off the edge of the maze or hit an obstacle, the robot will crash and break down. If the robot reaches the exit at any point, then the robot will stop following any further instructions. Bob is having trouble debugging his robot, so he would like to determine the number of mappings of digits to directions that would lead the robot to the exit. Input Specification: The first line of input will contain two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50), denoting the dimensions of the maze. The next *n* lines will contain exactly *m* characters each, denoting the maze. Each character of the maze will be '.', '#', 'S', or 'E'. There will be exactly one 'S' and exactly one 'E' in the maze. The last line will contain a single string *s* (1<=≤<=|*s*|<=≤<=100) — the instructions given to the robot. Each character of *s* is a digit from 0 to 3. Output Specification: Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit. Demo Input: ['5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012\n', '6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021\n', '5 3\n...\n.S.\n###\n.E.\n...\n3\n'] Demo Output: ['1\n', '14\n', '0\n'] Note: For the first sample, the only valid mapping is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/87a55361bde12e4223a96f0e1d83b94428f26f02.png" style="max-width: 100.0%;max-height: 100.0%;"/>, where *D* is down, *L* is left, *U* is up, *R* is right.
```python from itertools import permutations #take dimension of the grid as input n,m = map(int,input().split()) #take grid g = [input() for _ in range(n)] inst = map(int,input()) dx = [0,-1,0,1] dy = [1,0,-1,0] sx,sy,ex,ey = -1,-1,-1,-1 for i in range(n): for j in range(m): if g[i][j] == 'E': ex,ey = i,j if g[i][j] == 'S': sx,sy = i,j def go(dirs): cx,cy = sx,sy for e in inst: cx += dx[dirs[e]] cy += dy[dirs[e]] if not (0<=cx<n and 0<=cy<m and g[cx][cy]!='#'): return False if (cx,cy)==(ex,ey): return True return False print(sum(map(go,permutations(range(4))))) ```
0
762
B
USB vs. PS/2
PROGRAMMING
1,400
[ "greedy", "implementation", "sortings", "two pointers" ]
null
null
Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for *m* mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy.
The first line contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=105)  — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer *m* (0<=≤<=*m*<=≤<=3·105)  — the number of mouses in the price list. The next *m* lines each describe another mouse. The *i*-th line contains first integer *val**i* (1<=≤<=*val**i*<=≤<=109)  — the cost of the *i*-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in.
Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.
[ "2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2\n" ]
[ "3 14\n" ]
In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
0
[ { "input": "2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2", "output": "3 14" }, { "input": "1 4 4\n12\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB\n350512489 USB\n281054887 USB\n875326145 USB", "output": "8 2345344274" }, { "input": "3 0 3\n0", "output": "0 0" }, { "input": "1 2 4\n12\n257866589 PS/2\n246883568 USB\n104396128 USB\n993389754 PS/2\n896419206 USB\n405836977 USB\n50415634 PS/2\n152940828 PS/2\n847270779 PS/2\n850467106 USB\n922287488 USB\n622484596 PS/2", "output": "7 1840824320" }, { "input": "0 4 2\n12\n170189291 USB\n670118538 USB\n690872205 PS/2\n582606841 PS/2\n397508479 USB\n578814041 USB\n96734643 USB\n168371453 USB\n528445088 PS/2\n506017602 PS/2\n512143072 USB\n188740735 USB", "output": "6 2573047832" }, { "input": "5 100 100\n29\n741703337 USB\n285817204 PS/2\n837154300 USB\n250820430 USB\n809146898 PS/2\n10478072 USB\n2833804 PS/2\n669657009 USB\n427708130 PS/2\n204319444 PS/2\n209882040 USB\n56937335 USB\n107442187 USB\n46188465 USB\n902978472 USB\n792812238 PS/2\n513787720 PS/2\n486353330 PS/2\n168930159 PS/2\n183624803 USB\n67302934 USB\n264291554 USB\n467936329 USB\n82111533 USB\n849018301 USB\n645374374 PS/2\n967926381 PS/2\n286289663 PS/2\n36760263 USB", "output": "29 11375586709" }, { "input": "71 15 60\n24\n892757877 USB\n613048358 USB\n108150254 USB\n425313488 USB\n949441992 USB\n859461207 PS/2\n81440099 PS/2\n348819522 USB\n606267503 USB\n443620287 PS/2\n610038583 USB\n374259313 PS/2\n947207567 PS/2\n424889764 PS/2\n58345333 USB\n735796912 PS/2\n523115052 USB\n983709864 USB\n426463338 USB\n305759345 PS/2\n689127461 PS/2\n878781173 PS/2\n445036480 USB\n643765304 USB", "output": "24 13374616076" }, { "input": "37 80 100\n31\n901706521 USB\n555265160 PS/2\n547038505 PS/2\n644436873 PS/2\n105558073 USB\n915082057 PS/2\n913113815 USB\n953413471 PS/2\n252912707 PS/2\n830344497 USB\n781593007 USB\n610659875 PS/2\n177755858 PS/2\n496444729 PS/2\n617569418 USB\n304908147 PS/2\n188649950 PS/2\n705737216 USB\n473915286 USB\n622994426 PS/2\n783873493 USB\n789927108 USB\n258311181 PS/2\n720083354 PS/2\n676406125 PS/2\n634885851 PS/2\n126814339 USB\n704693540 USB\n789707618 PS/2\n938873907 USB\n576166502 USB", "output": "31 18598842609" }, { "input": "6 100 10\n11\n931138340 USB\n421397130 USB\n899599243 PS/2\n891033726 PS/2\n375251114 PS/2\n991976657 USB\n743116261 PS/2\n163085281 PS/2\n111524953 PS/2\n148832199 PS/2\n480084927 PS/2", "output": "11 6157039831" }, { "input": "1 1 124\n1\n2 USB", "output": "1 2" }, { "input": "1 1 1\n3\n3 USB\n3 PS/2\n3 PS/2", "output": "3 9" }, { "input": "3 3 3\n6\n3 USB\n3 USB\n3 USB\n3 USB\n3 USB\n3 USB", "output": "6 18" }, { "input": "1 1 1\n0", "output": "0 0" }, { "input": "1 1 1\n4\n9 USB\n1 PS/2\n5 USB\n6 PS/2", "output": "3 12" }, { "input": "1 1 1\n1\n6 PS/2", "output": "1 6" }, { "input": "1 3 1\n5\n1 PS/2\n8 USB\n8 PS/2\n8 PS/2\n1 PS/2", "output": "5 26" }, { "input": "3 2 1\n6\n1 USB\n4 PS/2\n4 PS/2\n7 USB\n8 PS/2\n1 USB", "output": "6 25" }, { "input": "1 1 1\n3\n10 USB\n6 USB\n6 USB", "output": "2 12" }, { "input": "1 1 1\n3\n4 USB\n3 PS/2\n3 USB", "output": "3 10" }, { "input": "1 1 1\n2\n6 PS/2\n5 USB", "output": "2 11" }, { "input": "1 1 2\n5\n4 USB\n7 PS/2\n10 PS/2\n7 PS/2\n3 USB", "output": "4 21" }, { "input": "1 4 4\n8\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n474310330 USB", "output": "7 1621841331" }, { "input": "1 4 4\n9\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB", "output": "8 2538599717" }, { "input": "1 4 4\n10\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB\n350512489 USB", "output": "8 2414801876" }, { "input": "48810 78876 100000\n0", "output": "0 0" }, { "input": "1 0 0\n1\n862644246 PS/2", "output": "0 0" }, { "input": "2 6 0\n3\n380521935 USB\n261865233 USB\n744434239 USB", "output": "2 642387168" }, { "input": "0 0 0\n1\n1 USB", "output": "0 0" }, { "input": "0 0 0\n1\n2 USB", "output": "0 0" }, { "input": "1 1 1\n1\n5 USB", "output": "1 5" }, { "input": "1 1 1\n2\n2 USB\n5 USB", "output": "2 7" }, { "input": "1 1 1\n2\n3 PS/2\n6 PS/2", "output": "2 9" }, { "input": "2 1 1\n4\n5 USB\n5 PS/2\n3 PS/2\n7 PS/2", "output": "3 13" } ]
1,654,633,065
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
77
0
a, b, c= map(int, input().split()) u, p = [], [] for i in range(int(input())): co, t = input().split() co = int(co) if t =='USB': u.append(co) else: p.append(co) u.sort(reverse=True) p.sort(reverse=True) re = 0 count = 0 for i in range(min(a, len(u))): count += 1 re += u.pop() for i in range(min(b, len(p))): count += 1 re += p.pop() for i in range(c): if u and p: a, b = u[-1], p[-1] if b > a: re += u.pop() else: re += p.pop() elif u: re += u.pop() elif p: re += p.pop() else: break print(count, re)
Title: USB vs. PS/2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for *m* mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input Specification: The first line contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=105)  — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer *m* (0<=≤<=*m*<=≤<=3·105)  — the number of mouses in the price list. The next *m* lines each describe another mouse. The *i*-th line contains first integer *val**i* (1<=≤<=*val**i*<=≤<=109)  — the cost of the *i*-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Specification: Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy. Demo Input: ['2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2\n'] Demo Output: ['3 14\n'] Note: In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
```python a, b, c= map(int, input().split()) u, p = [], [] for i in range(int(input())): co, t = input().split() co = int(co) if t =='USB': u.append(co) else: p.append(co) u.sort(reverse=True) p.sort(reverse=True) re = 0 count = 0 for i in range(min(a, len(u))): count += 1 re += u.pop() for i in range(min(b, len(p))): count += 1 re += p.pop() for i in range(c): if u and p: a, b = u[-1], p[-1] if b > a: re += u.pop() else: re += p.pop() elif u: re += u.pop() elif p: re += p.pop() else: break print(count, re) ```
0
765
C
Table Tennis Game 2
PROGRAMMING
1,200
[ "math" ]
null
null
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins. Across all the sets Misha scored *a* points in total, and Vanya scored *b* points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible. Note that the game consisted of several complete sets.
The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=&gt;<=0).
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
[ "11 11 5\n", "11 2 3\n" ]
[ "1\n", "-1\n" ]
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
1,250
[ { "input": "11 11 5", "output": "1" }, { "input": "11 2 3", "output": "-1" }, { "input": "1 5 9", "output": "14" }, { "input": "2 3 3", "output": "2" }, { "input": "1 1000000000 1000000000", "output": "2000000000" }, { "input": "2 3 5", "output": "3" }, { "input": "1000000000 1000000000 1000000000", "output": "2" }, { "input": "1 0 1", "output": "1" }, { "input": "101 99 97", "output": "-1" }, { "input": "1000000000 0 1", "output": "-1" }, { "input": "137 137 136", "output": "1" }, { "input": "255 255 255", "output": "2" }, { "input": "1 0 1000000000", "output": "1000000000" }, { "input": "123 456 789", "output": "9" }, { "input": "666666 6666666 666665", "output": "-1" }, { "input": "1000000000 999999999 999999999", "output": "-1" }, { "input": "100000000 100000001 99999999", "output": "-1" }, { "input": "3 2 1000000000", "output": "-1" }, { "input": "999999999 1000000000 999999998", "output": "-1" }, { "input": "12938621 192872393 102739134", "output": "21" }, { "input": "666666666 1230983 666666666", "output": "1" }, { "input": "123456789 123456789 123456787", "output": "1" }, { "input": "5 6 0", "output": "-1" }, { "input": "11 0 12", "output": "-1" }, { "input": "2 11 0", "output": "-1" }, { "input": "2 1 0", "output": "-1" }, { "input": "10 11 12", "output": "2" }, { "input": "11 12 5", "output": "-1" }, { "input": "11 12 3", "output": "-1" }, { "input": "11 15 4", "output": "-1" }, { "input": "2 3 1", "output": "-1" }, { "input": "11 12 0", "output": "-1" }, { "input": "11 13 2", "output": "-1" }, { "input": "11 23 22", "output": "4" }, { "input": "10 21 0", "output": "-1" }, { "input": "11 23 1", "output": "-1" }, { "input": "11 10 12", "output": "-1" }, { "input": "11 1 12", "output": "-1" }, { "input": "11 5 12", "output": "-1" }, { "input": "11 8 12", "output": "-1" }, { "input": "11 12 1", "output": "-1" }, { "input": "5 4 6", "output": "-1" }, { "input": "10 1 22", "output": "-1" }, { "input": "2 3 0", "output": "-1" }, { "input": "11 23 2", "output": "-1" }, { "input": "2 1000000000 1000000000", "output": "1000000000" }, { "input": "11 0 15", "output": "-1" }, { "input": "11 5 0", "output": "-1" }, { "input": "11 5 15", "output": "-1" }, { "input": "10 0 13", "output": "-1" }, { "input": "4 7 0", "output": "-1" }, { "input": "10 2 8", "output": "-1" }, { "input": "11 5 22", "output": "2" }, { "input": "11 13 0", "output": "-1" }, { "input": "2 0 3", "output": "-1" }, { "input": "10 10 0", "output": "1" }, { "input": "10 11 10", "output": "2" }, { "input": "3 5 4", "output": "2" }, { "input": "11 22 3", "output": "2" }, { "input": "11 12 10", "output": "-1" }, { "input": "10 2 13", "output": "-1" }, { "input": "5 6 1", "output": "-1" }, { "input": "10 21 5", "output": "-1" }, { "input": "10 11 9", "output": "-1" }, { "input": "10 17 7", "output": "-1" }, { "input": "3 4 1", "output": "-1" }, { "input": "4 5 3", "output": "-1" }, { "input": "11 3 23", "output": "-1" }, { "input": "11 3 12", "output": "-1" }, { "input": "2 5 0", "output": "-1" }, { "input": "10 21 2", "output": "-1" }, { "input": "5 1 6", "output": "-1" }, { "input": "10 11 0", "output": "-1" }, { "input": "10 9 11", "output": "-1" }, { "input": "7 10 5", "output": "-1" }, { "input": "5 7 2", "output": "-1" }, { "input": "6 5 7", "output": "-1" }, { "input": "11 16 2", "output": "-1" }, { "input": "11 1000000000 10", "output": "-1" }, { "input": "10 2 21", "output": "-1" }, { "input": "10 15 1", "output": "-1" }, { "input": "5 2 8", "output": "-1" }, { "input": "11 10000000 10", "output": "-1" }, { "input": "10 1 101", "output": "-1" }, { "input": "20 24 2", "output": "-1" }, { "input": "11 24 0", "output": "-1" }, { "input": "11 17 4", "output": "-1" }, { "input": "11 13 1", "output": "-1" }, { "input": "10 11 2", "output": "-1" }, { "input": "11 23 3", "output": "-1" }, { "input": "10 99 0", "output": "-1" }, { "input": "6 7 4", "output": "-1" }, { "input": "11 1 22", "output": "2" }, { "input": "11 2 13", "output": "-1" }, { "input": "2 1 3", "output": "-1" }, { "input": "11 6 18", "output": "-1" }, { "input": "11 122 4", "output": "-1" }, { "input": "11 21 10", "output": "-1" }, { "input": "3 2 4", "output": "-1" }, { "input": "9 11 2", "output": "-1" }, { "input": "11 0 7", "output": "-1" }, { "input": "5 9 4", "output": "-1" }, { "input": "100 105 5", "output": "-1" }, { "input": "11 15 0", "output": "-1" }, { "input": "5 6 4", "output": "-1" }, { "input": "3 4 2", "output": "-1" }, { "input": "2 9 0", "output": "-1" }, { "input": "11 13 11", "output": "2" }, { "input": "11 15 5", "output": "-1" }, { "input": "11 4 15", "output": "-1" }, { "input": "10 1 0", "output": "-1" }, { "input": "11 16 8", "output": "-1" }, { "input": "10 43 0", "output": "-1" }, { "input": "11 13 5", "output": "-1" }, { "input": "11 22 0", "output": "2" }, { "input": "5 6 3", "output": "-1" }, { "input": "2 1 11", "output": "-1" }, { "input": "4 5 1", "output": "-1" }, { "input": "11 23 0", "output": "-1" }, { "input": "11 4 12", "output": "-1" }, { "input": "12 13 1", "output": "-1" }, { "input": "10 19 9", "output": "-1" }, { "input": "3 7 2", "output": "-1" }, { "input": "12 18 0", "output": "-1" }, { "input": "11 25 3", "output": "-1" }, { "input": "11 23 5", "output": "-1" }, { "input": "2 1 5", "output": "-1" }, { "input": "2 0 5", "output": "-1" }, { "input": "11 24 1", "output": "-1" }, { "input": "10 11 4", "output": "-1" }, { "input": "2 0 1", "output": "-1" }, { "input": "10 0 21", "output": "-1" }, { "input": "3 0 7", "output": "-1" }, { "input": "18 11 21", "output": "-1" }, { "input": "3 7 0", "output": "-1" }, { "input": "5 11 0", "output": "-1" }, { "input": "11 5 13", "output": "-1" }, { "input": "11 9 34", "output": "-1" }, { "input": "11 13 9", "output": "-1" }, { "input": "10 0 22", "output": "-1" }, { "input": "5 1 12", "output": "-1" }, { "input": "11 2 12", "output": "-1" }, { "input": "11 9 12", "output": "-1" }, { "input": "11 24 2", "output": "-1" }, { "input": "11 23 6", "output": "-1" }, { "input": "11 20 4", "output": "-1" }, { "input": "2 5 1", "output": "-1" }, { "input": "120 132 133", "output": "2" }, { "input": "11 111 4", "output": "-1" }, { "input": "10 7 11", "output": "-1" }, { "input": "6 13 0", "output": "-1" }, { "input": "5 11 1", "output": "-1" }, { "input": "11 5 27", "output": "-1" }, { "input": "11 15 3", "output": "-1" }, { "input": "11 0 13", "output": "-1" }, { "input": "11 13 10", "output": "-1" }, { "input": "11 25 5", "output": "-1" }, { "input": "4 3 5", "output": "-1" }, { "input": "100 199 100", "output": "2" }, { "input": "11 2 22", "output": "2" }, { "input": "10 20 2", "output": "2" }, { "input": "5 5 0", "output": "1" }, { "input": "10 11 1", "output": "-1" }, { "input": "11 12 2", "output": "-1" }, { "input": "5 16 3", "output": "-1" }, { "input": "12 14 1", "output": "-1" }, { "input": "10 22 2", "output": "-1" }, { "input": "2 4 0", "output": "2" }, { "input": "11 34 7", "output": "-1" }, { "input": "6 13 1", "output": "-1" }, { "input": "11 0 23", "output": "-1" }, { "input": "20 21 19", "output": "-1" }, { "input": "11 33 22", "output": "5" }, { "input": "10 4 41", "output": "-1" }, { "input": "3 4 0", "output": "-1" }, { "input": "11 15 7", "output": "-1" }, { "input": "5 0 6", "output": "-1" }, { "input": "11 3 22", "output": "2" }, { "input": "2 6 0", "output": "3" }, { "input": "10 11 11", "output": "2" }, { "input": "11 33 0", "output": "3" }, { "input": "4 6 2", "output": "-1" }, { "input": "11 76 2", "output": "-1" }, { "input": "7 9 4", "output": "-1" }, { "input": "10 43 1", "output": "-1" }, { "input": "22 25 5", "output": "-1" }, { "input": "3 5 2", "output": "-1" }, { "input": "11 1 24", "output": "-1" }, { "input": "12 25 3", "output": "-1" }, { "input": "11 0 22", "output": "2" }, { "input": "4 2 5", "output": "-1" }, { "input": "11 13 3", "output": "-1" }, { "input": "11 12 9", "output": "-1" }, { "input": "11 35 1", "output": "-1" }, { "input": "5 3 6", "output": "-1" }, { "input": "5 11 4", "output": "-1" }, { "input": "12 8 14", "output": "-1" }, { "input": "10 12 9", "output": "-1" }, { "input": "11 12 13", "output": "2" }, { "input": "11 15 2", "output": "-1" }, { "input": "11 23 4", "output": "-1" }, { "input": "5 3 11", "output": "-1" }, { "input": "6 13 2", "output": "-1" }, { "input": "4 1 0", "output": "-1" }, { "input": "11 32 10", "output": "-1" }, { "input": "2 11 1", "output": "-1" }, { "input": "10 11 7", "output": "-1" }, { "input": "11 26 0", "output": "-1" }, { "input": "100 205 5", "output": "-1" }, { "input": "4 0 2", "output": "-1" }, { "input": "10 11 8", "output": "-1" }, { "input": "11 22 5", "output": "2" }, { "input": "4 0 5", "output": "-1" }, { "input": "11 87 22", "output": "9" }, { "input": "4 8 0", "output": "2" }, { "input": "9 8 17", "output": "-1" }, { "input": "10 20 0", "output": "2" }, { "input": "10 9 19", "output": "-1" }, { "input": "12 2 13", "output": "-1" }, { "input": "11 24 5", "output": "-1" }, { "input": "10 1 11", "output": "-1" }, { "input": "4 0 9", "output": "-1" }, { "input": "3 0 1", "output": "-1" }, { "input": "11 12 4", "output": "-1" }, { "input": "3 8 2", "output": "-1" }, { "input": "11 17 10", "output": "-1" }, { "input": "6 1 13", "output": "-1" }, { "input": "11 25 0", "output": "-1" }, { "input": "12 0 13", "output": "-1" }, { "input": "10 5 20", "output": "2" }, { "input": "11 89 2", "output": "-1" }, { "input": "2 4 1", "output": "2" }, { "input": "10 31 0", "output": "-1" }, { "input": "11 34 1", "output": "-1" }, { "input": "999 6693 8331", "output": "14" }, { "input": "10 55 1", "output": "-1" }, { "input": "11 12 8", "output": "-1" }, { "input": "1 9 22", "output": "31" }, { "input": "7572 9186 895", "output": "-1" }, { "input": "3 2 11", "output": "-1" }, { "input": "2 1 4", "output": "2" }, { "input": "11 10 19", "output": "-1" }, { "input": "100 199 99", "output": "-1" }, { "input": "2537 8926 1523", "output": "-1" }, { "input": "11 0 5", "output": "-1" }, { "input": "5 1 11", "output": "-1" }, { "input": "12 13 5", "output": "-1" }, { "input": "10 12 0", "output": "-1" }, { "input": "5 4 7", "output": "-1" }, { "input": "12 25 1", "output": "-1" }, { "input": "7 9 0", "output": "-1" }, { "input": "4 15 0", "output": "-1" }, { "input": "5 11 2", "output": "-1" }, { "input": "11 58 3", "output": "-1" }, { "input": "10 11 5", "output": "-1" }, { "input": "10 3 1003", "output": "-1" }, { "input": "11 14 0", "output": "-1" }, { "input": "11 8 23", "output": "-1" }, { "input": "11 22 4", "output": "2" }, { "input": "5 2 0", "output": "-1" }, { "input": "11 1 35", "output": "-1" }, { "input": "12 25 5", "output": "-1" }, { "input": "11 37 4", "output": "-1" }, { "input": "20 42 3", "output": "-1" }, { "input": "10 12 2", "output": "-1" }, { "input": "4 1 5", "output": "-1" }, { "input": "5 16 0", "output": "-1" }, { "input": "11 13 7", "output": "-1" }, { "input": "5 0 3", "output": "-1" }, { "input": "11 2 11", "output": "1" }, { "input": "3 2 2000", "output": "-1" }, { "input": "3 0 4241", "output": "-1" }, { "input": "2 12 11", "output": "11" }, { "input": "10 2 82", "output": "-1" }, { "input": "11 0 11", "output": "1" }, { "input": "11 20 20", "output": "2" }, { "input": "5 0 10", "output": "2" }, { "input": "11 1 0", "output": "-1" }, { "input": "11 13 13", "output": "2" } ]
1,487,062,006
2,506
Python 3
CHALLENGED
CHALLENGES
9
61
4,608,000
import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def solve(): k, a, b = map(int, input().split()) a, b = max(a, b), min(a, b) win_a, rem_a = divmod(a, k) win_b, rem_b = divmod(b, k) sets = win_a + win_b if sets >= 2: ans = sets elif rem_a > 0 and rem_b > 0: ans = -1 else: ans = sets if sets > 0 else -1 print(ans) if __name__ == '__main__': solve()
Title: Table Tennis Game 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins. Across all the sets Misha scored *a* points in total, and Vanya scored *b* points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible. Note that the game consisted of several complete sets. Input Specification: The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=&gt;<=0). Output Specification: If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets. Demo Input: ['11 11 5\n', '11 2 3\n'] Demo Output: ['1\n', '-1\n'] Note: Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
```python import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def solve(): k, a, b = map(int, input().split()) a, b = max(a, b), min(a, b) win_a, rem_a = divmod(a, k) win_b, rem_b = divmod(b, k) sets = win_a + win_b if sets >= 2: ans = sets elif rem_a > 0 and rem_b > 0: ans = -1 else: ans = sets if sets > 0 else -1 print(ans) if __name__ == '__main__': solve() ```
-1
302
A
Eugeny and Array
PROGRAMMING
800
[ "implementation" ]
null
null
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries.
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Print *m* integers — the responses to Eugene's queries in the order they occur in the input.
[ "2 3\n1 -1\n1 1\n1 2\n2 2\n", "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n" ]
[ "0\n1\n0\n", "0\n1\n0\n1\n0\n" ]
none
500
[ { "input": "2 3\n1 -1\n1 1\n1 2\n2 2", "output": "0\n1\n0" }, { "input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5", "output": "0\n1\n0\n1\n0" }, { "input": "3 3\n1 1 1\n2 2\n1 1\n1 1", "output": "0\n0\n0" }, { "input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1", "output": "0\n0\n0\n0" }, { "input": "5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4", "output": "0\n0\n0\n0\n0" }, { "input": "6 6\n-1 -1 1 -1 -1 1\n1 1\n3 4\n1 1\n1 1\n1 3\n1 4", "output": "0\n1\n0\n0\n0\n1" }, { "input": "7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4 7\n1 7\n6 7", "output": "0\n0\n0\n0\n0\n0\n1" }, { "input": "8 8\n1 1 1 1 1 1 1 1\n5 8\n2 6\n2 3\n1 7\n7 7\n1 6\n1 8\n1 3", "output": "0\n0\n0\n0\n0\n0\n0\n0" }, { "input": "9 9\n-1 1 1 1 1 1 1 1 1\n1 7\n5 6\n1 4\n1 1\n1 1\n6 8\n1 1\n6 7\n3 5", "output": "0\n1\n0\n0\n0\n0\n0\n1\n0" }, { "input": "10 10\n-1 1 -1 1 -1 -1 -1 -1 -1 -1\n6 7\n2 5\n3 6\n1 3\n3 5\n4 5\n3 4\n1 6\n1 1\n1 1", "output": "1\n1\n1\n0\n0\n1\n1\n0\n0\n0" }, { "input": "1 1\n-1\n1 1", "output": "0" }, { "input": "1 1\n1\n1 1", "output": "0" } ]
1,511,181,729
2,147,483,647
Python 3
OK
TESTS
38
889
10,854,400
n,m = map(int,input().split()) a = list(map(int, input().split())) b = a.count(1) c = min(b,n-b) s = '' for i in range(m): left,right = map(int, input().split()) length = right - left + 1 if length % 2 or length //2 > c: s += "0\n" else: s += "1\n" print(s)
Title: Eugeny and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries. Input Specification: The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). Output Specification: Print *m* integers — the responses to Eugene's queries in the order they occur in the input. Demo Input: ['2 3\n1 -1\n1 1\n1 2\n2 2\n', '5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n'] Demo Output: ['0\n1\n0\n', '0\n1\n0\n1\n0\n'] Note: none
```python n,m = map(int,input().split()) a = list(map(int, input().split())) b = a.count(1) c = min(b,n-b) s = '' for i in range(m): left,right = map(int, input().split()) length = right - left + 1 if length % 2 or length //2 > c: s += "0\n" else: s += "1\n" print(s) ```
3
639
C
Bear and Polynomials
PROGRAMMING
2,200
[ "hashing", "implementation", "math" ]
null
null
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials. He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. More formally: Let *a*0,<=*a*1,<=...,<=*a**n* denote the coefficients, so . Then, a polynomial *P*(*x*) is valid if all the following conditions are satisfied: - *a**i* is integer for every *i*; - |*a**i*|<=≤<=*k* for every *i*; - *a**n*<=≠<=0. Limak has recently got a valid polynomial *P* with coefficients *a*0,<=*a*1,<=*a*2,<=...,<=*a**n*. He noticed that *P*(2)<=≠<=0 and he wants to change it. He is going to change one coefficient to get a valid polynomial *Q* of degree *n* that *Q*(2)<==<=0. Count the number of ways to do so. You should count two ways as a distinct if coefficients of target polynoms differ.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*k*<=≤<=109) — the degree of the polynomial and the limit for absolute values of coefficients. The second line contains *n*<=+<=1 integers *a*0,<=*a*1,<=...,<=*a**n* (|*a**i*|<=≤<=*k*,<=*a**n*<=≠<=0) — describing a valid polynomial . It's guaranteed that *P*(2)<=≠<=0.
Print the number of ways to change one coefficient to get a valid polynomial *Q* that *Q*(2)<==<=0.
[ "3 1000000000\n10 -9 -3 5\n", "3 12\n10 -9 -3 5\n", "2 20\n14 -7 19\n" ]
[ "3\n", "2\n", "0\n" ]
In the first sample, we are given a polynomial *P*(*x*) = 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup>. Limak can change one coefficient in three ways: 1. He can set *a*<sub class="lower-index">0</sub> =  - 10. Then he would get *Q*(*x*) =  - 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) =  - 10 - 18 - 12 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">2</sub> =  - 8. Then *Q*(*x*) = 10 - 9*x* - 8*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 18 - 32 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">1</sub> =  - 19. Then *Q*(*x*) = 10 - 19*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 38 - 12 + 40 = 0. In the second sample, we are given the same polynomial. This time though, *k* is equal to 12 instead of 10<sup class="upper-index">9</sup>. Two first of ways listed above are still valid but in the third way we would get |*a*<sub class="lower-index">1</sub>| &gt; *k* what is not allowed. Thus, the answer is 2 this time.
1,000
[ { "input": "3 1000000000\n10 -9 -3 5", "output": "3" }, { "input": "3 12\n10 -9 -3 5", "output": "2" }, { "input": "2 20\n14 -7 19", "output": "0" }, { "input": "5 5\n0 -4 -2 -2 0 5", "output": "1" }, { "input": "6 10\n-2 -1 7 -3 2 7 -6", "output": "2" }, { "input": "7 100\n2 21 11 45 58 85 -59 38", "output": "1" }, { "input": "100 1000\n-62 57 -27 -67 49 -10 66 -64 -36 -78 62 -75 -39 75 -47 -36 41 -88 62 -43 22 29 -20 58 40 16 71 -2 -87 12 86 -90 -92 67 -12 -48 -10 -26 78 68 22 -3 66 -95 -81 34 14 -76 -27 76 -60 87 -84 3 35 -60 46 -65 29 -29 2 -44 -55 18 -75 91 36 34 -86 53 59 -54 -29 33 -95 66 9 72 67 -44 37 44 32 -52 -34 -4 -99 58 7 -22 -53 11 10 10 -25 -100 -95 -27 43 -46 25", "output": "10" }, { "input": "1 5\n5 -3", "output": "0" }, { "input": "1 10\n-6 2", "output": "2" }, { "input": "5 10000\n-160 3408 -4620 5869 7434 -6253", "output": "1" }, { "input": "10 1\n0 0 0 0 0 0 0 0 0 0 1", "output": "0" }, { "input": "10 1\n0 0 1 -1 1 0 0 1 1 -1 -1", "output": "0" }, { "input": "10 2\n-2 -2 1 2 -1 -2 1 -2 1 2 -1", "output": "2" }, { "input": "20 100\n52 -82 36 90 -62 -35 -93 -98 -80 -40 29 8 43 26 35 55 -56 -99 -17 13 11", "output": "1" }, { "input": "90 10\n-4 2 2 5 -1 3 4 1 -2 10 -9 -2 -4 3 8 0 -8 -3 9 1 2 4 8 2 0 2 -10 4 -4 -6 2 -9 3 -9 -3 8 8 9 -7 -10 3 9 -2 -7 5 -7 -5 6 1 5 1 -8 3 8 0 -6 2 2 3 -10 2 1 4 8 -3 1 5 7 -7 -3 2 -2 -9 7 7 -2 7 -6 7 -3 2 -5 10 0 0 9 -1 -4 1 -8 4", "output": "4" }, { "input": "101 20\n4 16 -5 8 -13 -6 -19 -4 18 9 -5 5 3 13 -12 -2 -1 -4 -13 14 2 15 -11 -17 -15 6 9 -15 -10 16 18 -7 8 -19 17 11 -6 -5 -16 -7 -14 5 -17 -6 18 19 -14 -5 1 11 -17 18 4 9 -1 19 1 8 9 -14 11 -8 -18 -12 15 14 -8 0 8 16 2 -20 -19 17 14 -2 3 -9 -13 4 6 -16 3 -12 19 -14 -8 -16 7 -4 5 9 17 7 -3 -15 6 18 -13 10 -8 2", "output": "1" }, { "input": "10 1000\n-538 -553 -281 -270 209 -989 -418 486 330 725 -430", "output": "1" }, { "input": "30 1000\n622 815 -733 -613 -741 571 -761 -432 -7 201 554 730 607 415 -453 820 161 147 406 875 -413 462 998 481 698 661 18 -331 752 -232 -72", "output": "2" }, { "input": "5 2000000\n1038520 -406162 -106421 106958 -807010 850753", "output": "2" }, { "input": "10 1000000000\n-857095622 -567296277 -923645190 -246044525 610990226 -617677619 -239569893 355377587 222686442 250110001 -200293692", "output": "2" }, { "input": "20 1000000000\n-924490890 231431639 -579465017 -690485236 173663728 144784457 364609617 444830562 48833250 1095623 333652904 -901650010 -850265945 844112020 -9178988 -527869441 93581840 607677914 -521131467 -628140952 329057708", "output": "3" }, { "input": "2 2\n1 1 -1", "output": "1" }, { "input": "2 2\n1 1 -1", "output": "1" }, { "input": "2 2\n-1 0 -2", "output": "0" }, { "input": "2 2\n-1 -1 1", "output": "1" }, { "input": "2 2\n1 1 -2", "output": "0" }, { "input": "3 2\n2 -1 -1 1", "output": "2" }, { "input": "35 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "35 1000000000\n-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 536870912", "output": "0" }, { "input": "35 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "35 1000000000\n-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 -536870912", "output": "0" }, { "input": "32 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "32 1000000000\n-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 536870912", "output": "0" }, { "input": "32 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "32 1000000000\n-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 -536870912", "output": "0" }, { "input": "55 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "55 1000000000\n-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 536870912", "output": "0" }, { "input": "69 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "69 1000000000\n-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 0 0 0 0 0 -536870912", "output": "0" }, { "input": "61 10\n0 1 0 0 1 1 0 0 0 1 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 1 0 1 0 0 1 1 1 0 1 0 1 0 1 0 1 0 0 1 0 1 1 0 0 1 0 1", "output": "0" }, { "input": "2 10\n1 -2 1", "output": "1" }, { "input": "65 1\n-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 0 -1", "output": "0" } ]
1,581,290,396
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
def solve_brute(coefs, k): sol = 0 n = len(coefs)-1 for i in range(len(coefs)): for x in range(-k,k): if poly_eval(coefs[:i]+[k]+coefs[i+1:],2) == 0 and not(i == n and k == 0): sol = sol + 1 break return sol n, k = map(int, input().split()) coefs = list(map(int, input().split())) print(solve_brute(coefs, k))
Title: Bear and Polynomials Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials. He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. More formally: Let *a*0,<=*a*1,<=...,<=*a**n* denote the coefficients, so . Then, a polynomial *P*(*x*) is valid if all the following conditions are satisfied: - *a**i* is integer for every *i*; - |*a**i*|<=≤<=*k* for every *i*; - *a**n*<=≠<=0. Limak has recently got a valid polynomial *P* with coefficients *a*0,<=*a*1,<=*a*2,<=...,<=*a**n*. He noticed that *P*(2)<=≠<=0 and he wants to change it. He is going to change one coefficient to get a valid polynomial *Q* of degree *n* that *Q*(2)<==<=0. Count the number of ways to do so. You should count two ways as a distinct if coefficients of target polynoms differ. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*k*<=≤<=109) — the degree of the polynomial and the limit for absolute values of coefficients. The second line contains *n*<=+<=1 integers *a*0,<=*a*1,<=...,<=*a**n* (|*a**i*|<=≤<=*k*,<=*a**n*<=≠<=0) — describing a valid polynomial . It's guaranteed that *P*(2)<=≠<=0. Output Specification: Print the number of ways to change one coefficient to get a valid polynomial *Q* that *Q*(2)<==<=0. Demo Input: ['3 1000000000\n10 -9 -3 5\n', '3 12\n10 -9 -3 5\n', '2 20\n14 -7 19\n'] Demo Output: ['3\n', '2\n', '0\n'] Note: In the first sample, we are given a polynomial *P*(*x*) = 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup>. Limak can change one coefficient in three ways: 1. He can set *a*<sub class="lower-index">0</sub> =  - 10. Then he would get *Q*(*x*) =  - 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) =  - 10 - 18 - 12 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">2</sub> =  - 8. Then *Q*(*x*) = 10 - 9*x* - 8*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 18 - 32 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">1</sub> =  - 19. Then *Q*(*x*) = 10 - 19*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 38 - 12 + 40 = 0. In the second sample, we are given the same polynomial. This time though, *k* is equal to 12 instead of 10<sup class="upper-index">9</sup>. Two first of ways listed above are still valid but in the third way we would get |*a*<sub class="lower-index">1</sub>| &gt; *k* what is not allowed. Thus, the answer is 2 this time.
```python def solve_brute(coefs, k): sol = 0 n = len(coefs)-1 for i in range(len(coefs)): for x in range(-k,k): if poly_eval(coefs[:i]+[k]+coefs[i+1:],2) == 0 and not(i == n and k == 0): sol = sol + 1 break return sol n, k = map(int, input().split()) coefs = list(map(int, input().split())) print(solve_brute(coefs, k)) ```
-1
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,650,122,411
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
6
46
0
s=input() n=[] for i in range(len(s)): n.append(s[i]) p='' for j in range(len(n)): if n[j]=='h': p+=n[j] break for k in range(j+1,len(n)): if n[k]=='e': p+=n[k] break for l in range(k+1,len(n)): if n[l]=='l': p+=n[l] break for m in range(l+1,len(n)): if n[m]=='l': p+=n[m] break for o in range(m+1,len(n)): if n[o]=='o': p+=n[o] break if p=='hello': print('YES') else: print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python s=input() n=[] for i in range(len(s)): n.append(s[i]) p='' for j in range(len(n)): if n[j]=='h': p+=n[j] break for k in range(j+1,len(n)): if n[k]=='e': p+=n[k] break for l in range(k+1,len(n)): if n[l]=='l': p+=n[l] break for m in range(l+1,len(n)): if n[m]=='l': p+=n[m] break for o in range(m+1,len(n)): if n[o]=='o': p+=n[o] break if p=='hello': print('YES') else: print('NO') ```
-1
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,658,172,619
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
15
202
15,667,200
n = int(input()) s = input() removed = 0 while True: visited = set() previous_len = len(visited) i = 1 while i < len(s): if s[i] != s[i-1] and not any(x in visited for x in [i, i-1]): visited.add(i) visited.add(i-1) j = i - 2 k = i + 1 while j >=0 and k < n and s[j] != s[k]: if any(x in visited for x in [j,k]): break else: visited.add(j) visited.add(k) j -= 1 k += 1 i += 1 if len(visited) == previous_len: break else: previous_len = len(visited) s = "".join([s[x] for x in range(n) if x not in visited]) removed += len(visited) print(n - len(visited) - removed)
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 n = int(input()) s = input() removed = 0 while True: visited = set() previous_len = len(visited) i = 1 while i < len(s): if s[i] != s[i-1] and not any(x in visited for x in [i, i-1]): visited.add(i) visited.add(i-1) j = i - 2 k = i + 1 while j >=0 and k < n and s[j] != s[k]: if any(x in visited for x in [j,k]): break else: visited.add(j) visited.add(k) j -= 1 k += 1 i += 1 if len(visited) == previous_len: break else: previous_len = len(visited) s = "".join([s[x] for x in range(n) if x not in visited]) removed += len(visited) print(n - len(visited) - removed) ```
-1
13
A
Numbers
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Numbers
1
64
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10.
Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000).
Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.
[ "5\n", "3\n" ]
[ "7/3\n", "2/1\n" ]
In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
0
[ { "input": "5", "output": "7/3" }, { "input": "3", "output": "2/1" }, { "input": "1000", "output": "90132/499" }, { "input": "927", "output": "155449/925" }, { "input": "260", "output": "6265/129" }, { "input": "131", "output": "3370/129" }, { "input": "386", "output": "857/12" }, { "input": "277", "output": "2864/55" }, { "input": "766", "output": "53217/382" }, { "input": "28", "output": "85/13" }, { "input": "406", "output": "7560/101" }, { "input": "757", "output": "103847/755" }, { "input": "6", "output": "9/4" }, { "input": "239", "output": "10885/237" }, { "input": "322", "output": "2399/40" }, { "input": "98", "output": "317/16" }, { "input": "208", "output": "4063/103" }, { "input": "786", "output": "55777/392" }, { "input": "879", "output": "140290/877" }, { "input": "702", "output": "89217/700" }, { "input": "948", "output": "7369/43" }, { "input": "537", "output": "52753/535" }, { "input": "984", "output": "174589/982" }, { "input": "934", "output": "157951/932" }, { "input": "726", "output": "95491/724" }, { "input": "127", "output": "3154/125" }, { "input": "504", "output": "23086/251" }, { "input": "125", "output": "3080/123" }, { "input": "604", "output": "33178/301" }, { "input": "115", "output": "2600/113" }, { "input": "27", "output": "167/25" }, { "input": "687", "output": "85854/685" }, { "input": "880", "output": "69915/439" }, { "input": "173", "output": "640/19" }, { "input": "264", "output": "6438/131" }, { "input": "785", "output": "111560/783" }, { "input": "399", "output": "29399/397" }, { "input": "514", "output": "6031/64" }, { "input": "381", "output": "26717/379" }, { "input": "592", "output": "63769/590" }, { "input": "417", "output": "32002/415" }, { "input": "588", "output": "62723/586" }, { "input": "852", "output": "131069/850" }, { "input": "959", "output": "5059/29" }, { "input": "841", "output": "127737/839" }, { "input": "733", "output": "97598/731" }, { "input": "692", "output": "87017/690" }, { "input": "69", "output": "983/67" }, { "input": "223", "output": "556/13" }, { "input": "93", "output": "246/13" }, { "input": "643", "output": "75503/641" }, { "input": "119", "output": "2833/117" }, { "input": "498", "output": "1459/16" }, { "input": "155", "output": "4637/153" }, { "input": "305", "output": "17350/303" }, { "input": "454", "output": "37893/452" }, { "input": "88", "output": "1529/86" }, { "input": "850", "output": "32645/212" }, { "input": "474", "output": "20581/236" }, { "input": "309", "output": "17731/307" }, { "input": "762", "output": "105083/760" }, { "input": "591", "output": "63761/589" }, { "input": "457", "output": "38317/455" }, { "input": "141", "output": "3832/139" }, { "input": "385", "output": "27232/383" }, { "input": "387", "output": "27628/385" }, { "input": "469", "output": "40306/467" }, { "input": "624", "output": "35285/311" }, { "input": "330", "output": "487/8" }, { "input": "31", "output": "222/29" }, { "input": "975", "output": "171679/973" }, { "input": "584", "output": "62183/582" }, { "input": "668", "output": "81127/666" }, { "input": "331", "output": "20297/329" }, { "input": "189", "output": "6789/187" }, { "input": "251", "output": "11939/249" }, { "input": "876", "output": "69196/437" }, { "input": "615", "output": "68987/613" }, { "input": "451", "output": "37258/449" }, { "input": "499", "output": "45727/497" }, { "input": "699", "output": "89117/697" }, { "input": "619", "output": "70019/617" }, { "input": "413", "output": "10515/137" }, { "input": "197", "output": "7399/195" }, { "input": "794", "output": "14281/99" }, { "input": "659", "output": "79403/657" }, { "input": "653", "output": "77695/651" }, { "input": "23", "output": "45/7" }, { "input": "430", "output": "16985/214" }, { "input": "249", "output": "11659/247" }, { "input": "837", "output": "126869/835" }, { "input": "258", "output": "12373/256" }, { "input": "995", "output": "59665/331" }, { "input": "102", "output": "504/25" }, { "input": "989", "output": "177124/987" }, { "input": "376", "output": "13008/187" }, { "input": "657", "output": "15715/131" }, { "input": "746", "output": "50509/372" }, { "input": "602", "output": "13177/120" } ]
1,650,791,389
2,147,483,647
Python 3
OK
TESTS
99
92
0
a=int(input()) djel=[2, 3, 5, 7, 11, 13, 17, 19, 23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97] zbr,br=0,0 for i in range(2,a): br+=1 x=a ost=[] while x>0: ost.append(x%i) x=x//i zbr+=sum(ost) for i in djel: while zbr%i==0 and br%i==0: zbr//=i br//=i rj=str(zbr)+'/'+str(br) print(rj)
Title: Numbers Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10. Input Specification: Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). Output Specification: Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. Demo Input: ['5\n', '3\n'] Demo Output: ['7/3\n', '2/1\n'] Note: In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
```python a=int(input()) djel=[2, 3, 5, 7, 11, 13, 17, 19, 23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97] zbr,br=0,0 for i in range(2,a): br+=1 x=a ost=[] while x>0: ost.append(x%i) x=x//i zbr+=sum(ost) for i in djel: while zbr%i==0 and br%i==0: zbr//=i br//=i rj=str(zbr)+'/'+str(br) print(rj) ```
3.954
592
C
The Big Race
PROGRAMMING
1,800
[ "math" ]
null
null
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today. Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner. While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes). Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*. Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today?
The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.
Print the answer to the problem as an irreducible fraction . Follow the format of the samples output. The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=&gt;<=0 holds) is called irreducible, if there is no such integer *d*<=&gt;<=1, that both *p* and *q* are divisible by *d*.
[ "10 3 2\n", "7 1 2\n" ]
[ "3/10\n", "3/7\n" ]
In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.
1,500
[ { "input": "10 3 2", "output": "3/10" }, { "input": "7 1 2", "output": "3/7" }, { "input": "1 1 1", "output": "1/1" }, { "input": "5814 31 7", "output": "94/2907" }, { "input": "94268 813 766", "output": "765/94268" }, { "input": "262610 5583 4717", "output": "2358/131305" }, { "input": "3898439 96326 71937", "output": "71936/3898439" }, { "input": "257593781689876390 32561717 4411677", "output": "7914548537/257593781689876390" }, { "input": "111319886766128339 7862842484895022 3003994959686829", "output": "3003994959686828/111319886766128339" }, { "input": "413850294331656955 570110918058849723 409853735661743839", "output": "409853735661743838/413850294331656955" }, { "input": "3000000000000000000 2999999999999999873 2999999999999999977", "output": "23437499999999999/23437500000000000" }, { "input": "9 6 1", "output": "1/9" }, { "input": "32 9 2", "output": "3/32" }, { "input": "976 5 6", "output": "41/244" }, { "input": "5814 31 7", "output": "94/2907" }, { "input": "94268 714 345", "output": "689/94268" }, { "input": "262610 5583 4717", "output": "2358/131305" }, { "input": "3898439 96326 71937", "output": "71936/3898439" }, { "input": "54682301 778668 253103", "output": "253102/54682301" }, { "input": "329245015 1173508 8918834", "output": "1173507/329245015" }, { "input": "321076647734423976 7 7", "output": "1/1" }, { "input": "455227494055672047 92 28", "output": "19792499741550983/455227494055672047" }, { "input": "595779167455745259 6954 8697", "output": "205511958419723/595779167455745259" }, { "input": "1000000000000000000 1000000000 2000000000", "output": "1/2" }, { "input": "462643382718281828 462643382718281507 462643382718281701", "output": "33045955908448679/33045955908448702" }, { "input": "4000000000000000000 9999999999999997 99999999999999999", "output": "2499999999999999/1000000000000000000" }, { "input": "4003000100004000000 9999999099999999 99999999999999999", "output": "4999999549999999/2001500050002000000" }, { "input": "4903000100004000000 58997960959949999 99933992929999999", "output": "29498980479974999/2451500050002000000" }, { "input": "257593781689876390 32561717 4411677", "output": "7914548537/257593781689876390" }, { "input": "111319886766128339 7862842484895022 3003994959686829", "output": "3003994959686828/111319886766128339" }, { "input": "413850294331656955 570110918058849723 409853735661743839", "output": "409853735661743838/413850294331656955" }, { "input": "232 17 83", "output": "2/29" }, { "input": "5496272 63 200", "output": "13765/2748136" }, { "input": "180 174 53", "output": "13/45" }, { "input": "1954 190 537", "output": "189/1954" }, { "input": "146752429 510 514", "output": "571199/146752429" }, { "input": "579312860 55 70", "output": "10344881/144828215" }, { "input": "1 9 9", "output": "1/1" }, { "input": "95 19 19", "output": "1/1" }, { "input": "404 63 441", "output": "31/202" }, { "input": "5566 4798 4798", "output": "1/1" }, { "input": "118289676 570846883 570846883", "output": "1/1" }, { "input": "763 358 358", "output": "1/1" }, { "input": "85356138 7223 482120804", "output": "3611/42678069" }, { "input": "674664088 435395270 5", "output": "9/674664088" }, { "input": "762200126044291557 370330636048898430 6", "output": "17/762200126044291557" }, { "input": "917148533938841535 47 344459175789842163", "output": "28/183429706787768307" }, { "input": "360212127113008697 877228952036215545 5259", "output": "5258/360212127113008697" }, { "input": "683705963104411677 89876390 116741460012229240", "output": "539258339/683705963104411677" }, { "input": "573003994959686829 275856334120822851 1319886766128339", "output": "3959660298385016/573003994959686829" }, { "input": "409853735661743839 413850294331656955 413850294331656955", "output": "1/1" }, { "input": "19 1 19", "output": "1/19" }, { "input": "576 18 32", "output": "1/16" }, { "input": "9540 10 954", "output": "1/477" }, { "input": "101997840 6 16999640", "output": "1/8499820" }, { "input": "955944 1278 748", "output": "1/639" }, { "input": "482120804 66748 7223", "output": "1/66748" }, { "input": "370330636048898430 61721772674816405 6", "output": "1/61721772674816405" }, { "input": "344459175789842163 7328918633826429 47", "output": "1/7328918633826429" }, { "input": "877228952036215545 166805277055755 5259", "output": "1/55601759018585" }, { "input": "116741460012229240 1298911316 89876390", "output": "1/649455658" }, { "input": "275856334120822851 209 1319886766128339", "output": "1/1319886766128339" }, { "input": "413850294331656955 1 413850294331656955", "output": "1/413850294331656955" }, { "input": "54682301 778668 253103", "output": "253102/54682301" }, { "input": "329245015 3931027 6443236", "output": "357366/29931365" }, { "input": "321076647734423976 7 8", "output": "1672274206950125/13378193655600999" }, { "input": "455227494055672047 71 60", "output": "6411654845854559/455227494055672047" }, { "input": "595779167455745259 9741 9331", "output": "61162012885196/595779167455745259" }, { "input": "6470 80 160", "output": "327/647" }, { "input": "686325 828 1656", "output": "114511/228775" }, { "input": "4535304 2129 4258", "output": "755973/1511768" }, { "input": "40525189 6365 12730", "output": "20265394/40525189" }, { "input": "675297075 25986 51972", "output": "112553659/225099025" }, { "input": "5681598412 75376 226128", "output": "1893897375/5681598412" }, { "input": "384118571739435733 619773000 1859319000", "output": "128039524053435733/384118571739435733" }, { "input": "391554751752251913 625743359 1877230077", "output": "130518250652782079/391554751752251913" }, { "input": "390728504279201198 625082797 1250165594", "output": "195364252413988195/390728504279201198" }, { "input": "389902265396085075 624421544 1248843088", "output": "64983710976697837/129967421798695025" }, { "input": "734812071040507372 857211800 2571635400", "output": "61234339274051543/183703017760126843" }, { "input": "1 1 2", "output": "0/1" }, { "input": "3 1 4", "output": "0/1" }, { "input": "8 2 3", "output": "3/8" }, { "input": "64 32 16", "output": "1/2" }, { "input": "1 1 1000000000", "output": "0/1" }, { "input": "1000000000 1 1", "output": "1/1" }, { "input": "1000000000 1000000000 1000000000", "output": "1/1" }, { "input": "1000000000 2 4", "output": "1/2" }, { "input": "1000000000 123 456", "output": "6579023/1000000000" }, { "input": "1000000000 123123 654", "output": "24851/1000000000" }, { "input": "123456 123 456", "output": "215/30864" }, { "input": "123456 1234567 123", "output": "61/61728" }, { "input": "314159265 271 8281", "output": "37939/314159265" }, { "input": "11071994 4231 1324", "output": "2647/11071994" }, { "input": "961748927 961748941 982451653", "output": "1/1" }, { "input": "15485221 1259 90863", "output": "1258/15485221" }, { "input": "5000000000000000000 4999999999999999837 4999999999999999963", "output": "1249999999999999959/1250000000000000000" }, { "input": "4000000000000000000 3999999999999999691 3999999999999999887", "output": "399999999999999969/400000000000000000" }, { "input": "999999999999999999 999999999999999709 999999999999999737", "output": "333333333333333236/333333333333333333" }, { "input": "799999999999999999 799999999999999969 799999999999999991", "output": "799999999999999968/799999999999999999" }, { "input": "812312312312312222 812312312312311897 812312312312312029", "output": "406156156156155948/406156156156156111" }, { "input": "500000000000000000 499999999999999927 499999999999999931", "output": "249999999999999963/250000000000000000" }, { "input": "555555555555555555 555555555555555083 555555555555555229", "output": "50505050505050462/50505050505050505" }, { "input": "199419941994199419 199419941994199369 199419941994199391", "output": "66473313998066456/66473313998066473" }, { "input": "145685485411238588 145685485411238483 145685485411238573", "output": "72842742705619241/72842742705619294" }, { "input": "314159265358979323 314159265358979167 314159265358979213", "output": "314159265358979166/314159265358979323" }, { "input": "10 1000000000000000000 1000000000000000001", "output": "1/1" }, { "input": "5 100000000000000000 99999999999999999", "output": "1/1" }, { "input": "5 1000000000000 1000000000001", "output": "1/1" }, { "input": "5 1000000000000000000 1000000000000000001", "output": "1/1" }, { "input": "2 1000000000000000000 1000000000000000001", "output": "1/1" }, { "input": "2 10 11", "output": "1/1" }, { "input": "10 123456789123456789 723456789123456781", "output": "1/1" }, { "input": "12345678910 123456789101112131 123456789101112132", "output": "1/1" }, { "input": "5 499999999999999999 499999999999999998", "output": "1/1" } ]
1,446,312,754
3,754
Python 3
WRONG_ANSWER
PRETESTS
3
46
0
a, b, c = map(int, input().split()) answers = 0 for i in range(1, min(b, c)): answers += 1 m = int(a / (b * c)) if b != 1 and c != 1: g = m * (b - c - 1) if g != 0: answers += m * g + 1 else: answers += m + m else: answers += m completeT = answers completeB = a for num in range(2, min(completeT, completeB)): if completeT % num == 0 and completeB % num == 0: completeT /= num completeB /= num print("{0}/{1}".format(completeT, completeB))
Title: The Big Race Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today. Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner. While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes). Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*. Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today? Input Specification: The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. Output Specification: Print the answer to the problem as an irreducible fraction . Follow the format of the samples output. The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=&gt;<=0 holds) is called irreducible, if there is no such integer *d*<=&gt;<=1, that both *p* and *q* are divisible by *d*. Demo Input: ['10 3 2\n', '7 1 2\n'] Demo Output: ['3/10\n', '3/7\n'] Note: In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.
```python a, b, c = map(int, input().split()) answers = 0 for i in range(1, min(b, c)): answers += 1 m = int(a / (b * c)) if b != 1 and c != 1: g = m * (b - c - 1) if g != 0: answers += m * g + 1 else: answers += m + m else: answers += m completeT = answers completeB = a for num in range(2, min(completeT, completeB)): if completeT % num == 0 and completeB % num == 0: completeT /= num completeB /= num print("{0}/{1}".format(completeT, completeB)) ```
0
120
A
Elevator
PROGRAMMING
1,000
[ "brute force", "implementation", "math" ]
null
null
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand. One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed.
The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding.
Print character "R" if the VIP is right-handed or "L" if he is left-handed.
[ "front\n1\n" ]
[ "L\n" ]
none
0
[ { "input": "front\n1", "output": "L" }, { "input": "back\n1", "output": "R" }, { "input": "front\n2", "output": "R" }, { "input": "back\n2", "output": "L" } ]
1,684,785,662
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
def solve(rail, orientation): with open('output.txt', 'a+') as writer: if (orientation.lower() == 'front' and rail == '1') or (orientation.lower() == 'back' and rail == '2'): writer.write('L\n') else: writer.write('R\n') writer.close() if __name__ == '__main__': with open('input.txt', 'r') as reader: arr = reader.readlines() for i in range(0, len(arr), 2): orientation = arr[i] if orientation == '': break rail = arr[i + 1] solve(rail, orientation) reader.close()
Title: Elevator Time Limit: None seconds Memory Limit: None megabytes Problem Description: A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand. One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed. Input Specification: The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding. Output Specification: Print character "R" if the VIP is right-handed or "L" if he is left-handed. Demo Input: ['front\n1\n'] Demo Output: ['L\n'] Note: none
```python def solve(rail, orientation): with open('output.txt', 'a+') as writer: if (orientation.lower() == 'front' and rail == '1') or (orientation.lower() == 'back' and rail == '2'): writer.write('L\n') else: writer.write('R\n') writer.close() if __name__ == '__main__': with open('input.txt', 'r') as reader: arr = reader.readlines() for i in range(0, len(arr), 2): orientation = arr[i] if orientation == '': break rail = arr[i + 1] solve(rail, orientation) reader.close() ```
0
980
A
Links and Pearls
PROGRAMMING
900
[ "implementation", "math" ]
null
null
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts. Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them. Note that the final necklace should remain as one circular part of the same length as the initial necklace.
The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl.
Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower).
[ "-o-o--", "-o---\n", "-o---o-\n", "ooo\n" ]
[ "YES", "YES", "NO", "YES\n" ]
none
500
[ { "input": "-o-o--", "output": "YES" }, { "input": "-o---", "output": "YES" }, { "input": "-o---o-", "output": "NO" }, { "input": "ooo", "output": "YES" }, { "input": "---", "output": "YES" }, { "input": "--o-o-----o----o--oo-o-----ooo-oo---o--", "output": "YES" }, { "input": "-o--o-oo---o-o-o--o-o----oo------oo-----o----o-o-o--oo-o--o---o--o----------o---o-o-oo---o--o-oo-o--", "output": "NO" }, { "input": "-ooo--", "output": "YES" }, { "input": "---o--", "output": "YES" }, { "input": "oo-ooo", "output": "NO" }, { "input": "------o-o--o-----o--", "output": "YES" }, { "input": "--o---o----------o----o----------o--o-o-----o-oo---oo--oo---o-------------oo-----o-------------o---o", "output": "YES" }, { "input": "----------------------------------------------------------------------------------------------------", "output": "YES" }, { "input": "-oo-oo------", "output": "YES" }, { "input": "---------------------------------o----------------------------oo------------------------------------", "output": "NO" }, { "input": "oo--o--o--------oo----------------o-----------o----o-----o----------o---o---o-----o---------ooo---", "output": "NO" }, { "input": "--o---oooo--o-o--o-----o----ooooo--o-oo--o------oooo--------------ooo-o-o----", "output": "NO" }, { "input": "-----------------------------o--o-o-------", "output": "YES" }, { "input": "o-oo-o--oo----o-o----------o---o--o----o----o---oo-ooo-o--o-", "output": "YES" }, { "input": "oooooooooo-ooo-oooooo-ooooooooooooooo--o-o-oooooooooooooo-oooooooooooooo", "output": "NO" }, { "input": "-----------------o-o--oo------o--------o---o--o----------------oooo-------------ooo-----ooo-----o", "output": "NO" }, { "input": "ooo-ooooooo-oo-ooooooooo-oooooooooooooo-oooo-o-oooooooooo--oooooooooooo-oooooooooo-ooooooo", "output": "NO" }, { "input": "oo-o-ooooo---oo---o-oo---o--o-ooo-o---o-oo---oo---oooo---o---o-oo-oo-o-ooo----ooo--oo--o--oo-o-oo", "output": "NO" }, { "input": "-----o-----oo-o-o-o-o----o---------oo---ooo-------------o----o---o-o", "output": "YES" }, { "input": "oo--o-o-o----o-oooo-ooooo---o-oo--o-o--ooo--o--oooo--oo----o----o-o-oooo---o-oooo--ooo-o-o----oo---", "output": "NO" }, { "input": "------oo----o----o-oo-o--------o-----oo-----------------------o------------o-o----oo---------", "output": "NO" }, { "input": "-o--o--------o--o------o---o-o----------o-------o-o-o-------oo----oo------o------oo--o--", "output": "NO" }, { "input": "------------------o----------------------------------o-o-------------", "output": "YES" }, { "input": "-------------o----ooo-----o-o-------------ooo-----------ooo------o----oo---", "output": "YES" }, { "input": "-------o--------------------o--o---------------o---o--o-----", "output": "YES" }, { "input": "------------------------o------------o-----o----------------", "output": "YES" }, { "input": "------oo----------o------o-----o---------o------------o----o--o", "output": "YES" }, { "input": "------------o------------------o-----------------------o-----------o", "output": "YES" }, { "input": "o---o---------------", "output": "YES" }, { "input": "----------------------o---o----o---o-----------o-o-----o", "output": "YES" }, { "input": "----------------------------------------------------------------------o-o---------------------", "output": "YES" }, { "input": "----o---o-------------------------", "output": "YES" }, { "input": "o----------------------oo----", "output": "NO" }, { "input": "-o-o--o-o--o-----o-----o-o--o-o---oooo-o", "output": "NO" }, { "input": "-o-ooo-o--o----o--o-o-oo-----------o-o-", "output": "YES" }, { "input": "o-------o-------o-------------", "output": "YES" }, { "input": "oo----------------------o--------------o--------------o-----", "output": "YES" }, { "input": "-----------------------------------o---------------------o--------------------------", "output": "YES" }, { "input": "--o--o----o-o---o--o----o-o--oo-----o-oo--o---o---ooo-o--", "output": "YES" }, { "input": "---------------o-o----", "output": "YES" }, { "input": "o------ooo--o-o-oo--o------o----ooo-----o-----o-----o-ooo-o---o----oo", "output": "YES" }, { "input": "----o----o", "output": "YES" }, { "input": "o--o--o--o--o--o--o--o--o--o--o--o--", "output": "YES" }, { "input": "o---o---o---o---o----o----o----o---o---o---o", "output": "YES" }, { "input": "o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-", "output": "YES" }, { "input": "-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o", "output": "YES" }, { "input": "o----------o----------o----------o----------o----------o----------o----------o----------o----------o", "output": "YES" }, { "input": "o---------o---------o---------o---------o---------o---------o---------o---------o", "output": "YES" }, { "input": "--------o--------o--------o--------o--------o--------o--------o--------o--------", "output": "YES" }, { "input": "o---o----", "output": "NO" }, { "input": "---o----o", "output": "NO" }, { "input": "-o-", "output": "YES" }, { "input": "------oooo", "output": "NO" }, { "input": "oo--", "output": "YES" }, { "input": "---o", "output": "YES" }, { "input": "ooo-", "output": "NO" }, { "input": "oooooooo----------", "output": "NO" }, { "input": "oooo--", "output": "NO" }, { "input": "o-ooooo", "output": "NO" }, { "input": "-oo", "output": "NO" }, { "input": "ooooo-", "output": "NO" }, { "input": "ooo---------", "output": "YES" }, { "input": "oo-", "output": "NO" }, { "input": "---ooo", "output": "YES" } ]
1,527,504,085
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
77
0
str=input() p=0 l=0 for i in str: if i=='-': l+=1 else: p+=1 if l>=p and l%p==0: print("YES") else: print("NO")
Title: Links and Pearls Time Limit: None seconds Memory Limit: None megabytes Problem Description: A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts. Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them. Note that the final necklace should remain as one circular part of the same length as the initial necklace. Input Specification: The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl. Output Specification: Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower). Demo Input: ['-o-o--', '-o---\n', '-o---o-\n', 'ooo\n'] Demo Output: ['YES', 'YES', 'NO', 'YES\n'] Note: none
```python str=input() p=0 l=0 for i in str: if i=='-': l+=1 else: p+=1 if l>=p and l%p==0: print("YES") else: print("NO") ```
0
579
A
Raising Bacteria
PROGRAMMING
1,000
[ "bitmasks" ]
null
null
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days?
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
The only line containing one integer: the answer.
[ "5\n", "8\n" ]
[ "2\n", "1\n" ]
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
250
[ { "input": "5", "output": "2" }, { "input": "8", "output": "1" }, { "input": "536870911", "output": "29" }, { "input": "1", "output": "1" }, { "input": "343000816", "output": "14" }, { "input": "559980448", "output": "12" }, { "input": "697681824", "output": "14" }, { "input": "41313494", "output": "14" }, { "input": "673935585", "output": "13" }, { "input": "117422204", "output": "19" }, { "input": "954746654", "output": "15" }, { "input": "536838144", "output": "14" }, { "input": "1000000000", "output": "13" }, { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "1" }, { "input": "6", "output": "2" }, { "input": "7", "output": "3" }, { "input": "9", "output": "2" }, { "input": "10", "output": "2" }, { "input": "999999999", "output": "21" }, { "input": "999999998", "output": "20" }, { "input": "999999997", "output": "20" }, { "input": "999999996", "output": "19" }, { "input": "999999995", "output": "20" }, { "input": "999999994", "output": "19" }, { "input": "999999993", "output": "19" }, { "input": "999999992", "output": "18" }, { "input": "999999991", "output": "20" }, { "input": "999999990", "output": "19" }, { "input": "536870910", "output": "28" }, { "input": "536870912", "output": "1" }, { "input": "536870913", "output": "2" }, { "input": "536870914", "output": "2" }, { "input": "22", "output": "3" }, { "input": "14", "output": "3" } ]
1,683,020,235
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<stdio.h> #include<map> int main(){ int n, m; while (scanf("%d%d", &n, &m) == 2){ int S[100000]; int ans[100001] = { 0 }; std::map<int, int> T; for (int i = 0; i < n; i++) scanf("%d", &S[i]); T.clear(); for (int i = n - 1; i >= 0; i--){ if (T[S[i]] == 0){ ans[i] = ans[i + 1] + 1; T[S[i]] = 1; } else ans[i] = ans[i + 1]; } for (int i = 0; i < m; i++){ int tmp; scanf("%d", &tmp); printf("%d\n", ans[tmp - 1]); } } return 0; }
Title: Raising Bacteria Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days? Input Specification: The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). Output Specification: The only line containing one integer: the answer. Demo Input: ['5\n', '8\n'] Demo Output: ['2\n', '1\n'] Note: For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
```python #include<stdio.h> #include<map> int main(){ int n, m; while (scanf("%d%d", &n, &m) == 2){ int S[100000]; int ans[100001] = { 0 }; std::map<int, int> T; for (int i = 0; i < n; i++) scanf("%d", &S[i]); T.clear(); for (int i = n - 1; i >= 0; i--){ if (T[S[i]] == 0){ ans[i] = ans[i + 1] + 1; T[S[i]] = 1; } else ans[i] = ans[i + 1]; } for (int i = 0; i < m; i++){ int tmp; scanf("%d", &tmp); printf("%d\n", ans[tmp - 1]); } } return 0; } ```
-1
14
B
Young Photographer
PROGRAMMING
1,000
[ "implementation" ]
B. Young Photographer
2
64
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*1 to position *b*1, the second — from *a*2 to *b*2 What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*).
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
[ "3 3\n0 7\n14 2\n4 6\n" ]
[ "1\n" ]
none
0
[ { "input": "3 3\n0 7\n14 2\n4 6", "output": "1" }, { "input": "1 1\n0 10", "output": "0" }, { "input": "2 2\n1 2\n3 2", "output": "0" }, { "input": "3 2\n1 2\n2 3\n3 4", "output": "-1" }, { "input": "2 4\n10 4\n1 5", "output": "0" }, { "input": "1 10\n1 9", "output": "1" }, { "input": "1 10\n123 12", "output": "2" }, { "input": "1 17\n10 17", "output": "0" }, { "input": "1 22\n22 33", "output": "0" }, { "input": "1 3\n1 2", "output": "1" }, { "input": "2 5\n0 3\n2 1", "output": "3" }, { "input": "3 3\n7 3\n6 4\n3 7", "output": "1" }, { "input": "4 9\n8 6\n11 5\n5 11\n8 3", "output": "1" }, { "input": "2 4\n1 4\n4 0", "output": "0" }, { "input": "3 7\n5 8\n7 5\n4 7", "output": "0" }, { "input": "4 7\n8 2\n5 7\n8 2\n5 8", "output": "0" }, { "input": "2 3\n4 1\n4 1", "output": "0" }, { "input": "3 8\n7 2\n3 7\n5 2", "output": "3" }, { "input": "4 0\n9 1\n8 1\n8 4\n4 5", "output": "4" }, { "input": "4 7\n2 5\n3 6\n3 5\n7 4", "output": "2" }, { "input": "10 16\n4 18\n6 19\n22 1\n23 0\n1 22\n9 22\n4 19\n0 14\n6 14\n0 16", "output": "2" }, { "input": "20 1\n35 8\n40 6\n49 5\n48 18\n46 16\n45 16\n44 10\n16 44\n8 46\n2 45\n38 3\n42 1\n13 35\n35 18\n12 33\n32 11\n31 3\n50 20\n47 6\n38 2", "output": "19" }, { "input": "30 43\n17 72\n75 26\n23 69\n83 30\n15 82\n4 67\n83 27\n33 62\n26 83\n70 26\n69 25\n16 67\n77 26\n66 33\n7 88\n70 9\n10 79\n76 9\n30 77\n77 28\n21 68\n81 14\n13 72\n88 15\n60 29\n87 28\n16 58\n6 58\n71 9\n83 18", "output": "0" }, { "input": "40 69\n29 109\n28 87\n52 106\n101 34\n32 92\n91 60\n90 47\n62 102\n33 72\n27 87\n45 78\n103 37\n94 33\n56 98\n38 79\n31 83\n105 53\n47 89\n50 83\n93 62\n96 49\n47 75\n89 47\n89 61\n93 54\n46 100\n110 41\n103 28\n101 57\n100 62\n71 37\n65 80\n86 28\n73 42\n96 44\n33 111\n98 39\n87 55\n108 65\n31 101", "output": "0" }, { "input": "50 77\n95 55\n113 33\n101 17\n109 56\n117 7\n77 12\n14 84\n57 101\n96 28\n108 22\n105 12\n17 114\n51 115\n18 112\n104 25\n50 115\n14 111\n55 113\n124 20\n101 37\n18 121\n41 90\n77 41\n117 16\n8 83\n92 45\n48 86\n16 84\n13 98\n40 107\n14 94\n23 111\n36 121\n50 100\n35 90\n103 37\n96 51\n109 15\n13 117\n117 42\n112 45\n88 36\n51 121\n127 49\n112 15\n9 95\n122 46\n126 40\n57 93\n56 88", "output": "0" }, { "input": "5 12\n2 7\n7 5\n3 10\n11 3\n2 11", "output": "5" }, { "input": "15 15\n12 37\n40 4\n38 8\n5 36\n11 31\n21 33\n9 37\n4 38\n8 33\n5 39\n7 39\n38 16\n16 41\n38 9\n5 32", "output": "6" }, { "input": "25 40\n66 26\n56 19\n64 38\n64 23\n25 49\n51 26\n67 20\n65 35\n33 66\n28 63\n27 57\n40 56\n59 26\n35 56\n39 67\n30 63\n69 22\n21 63\n67 22\n20 66\n26 65\n64 26\n44 57\n57 41\n35 50", "output": "4" }, { "input": "50 77\n24 119\n43 119\n102 22\n117 30\n127 54\n93 19\n120 9\n118 27\n98 16\n17 105\n22 127\n109 52\n115 40\n11 121\n12 120\n113 30\n13 108\n33 124\n31 116\n112 39\n37 108\n127 28\n127 39\n120 29\n19 114\n103 18\n106 16\n24 121\n93 10\n36 112\n104 40\n39 100\n36 97\n83 9\n14 114\n126 12\n85 47\n25 84\n105 29\n35 113\n102 19\n8 110\n111 28\n94 12\n11 115\n40 124\n39 85\n47 93\n94 31\n17 121", "output": "0" }, { "input": "1 21\n973 373", "output": "352" }, { "input": "2 212\n831 551\n810 753", "output": "541" }, { "input": "3 404\n690 728\n820 260\n186 402", "output": "-1" }, { "input": "4 906\n548 906\n830 457\n228 638\n464 167", "output": "-1" }, { "input": "5 97\n97 393\n840 965\n269 183\n596 49\n975 62", "output": "-1" }, { "input": "3 183\n416 335\n773 648\n434 198", "output": "-1" }, { "input": "3 868\n251 927\n862 464\n157 756", "output": "112" }, { "input": "3 242\n397 208\n951 279\n570 622", "output": "-1" }, { "input": "3 618\n543 800\n38 94\n293 179", "output": "-1" }, { "input": "3 993\n378 81\n127 911\n16 737", "output": "615" }, { "input": "5 12\n11 1\n9 6\n1 11\n3 8\n874 842", "output": "-1" }, { "input": "15 16\n11 40\n5 32\n5 31\n36 10\n34 9\n43 6\n28 6\n34 8\n43 15\n9 28\n14 34\n34 6\n7 31\n31 14\n68 478", "output": "-1" }, { "input": "25 57\n47 31\n64 21\n43 56\n47 19\n70 27\n28 61\n41 61\n39 45\n46 21\n55 35\n70 22\n22 69\n30 67\n55 42\n37 58\n50 28\n57 42\n35 48\n68 40\n38 50\n62 20\n31 52\n38 70\n64 35\n666 393", "output": "-1" }, { "input": "50 118\n83 55\n101 33\n89 17\n97 56\n105 7\n65 12\n14 72\n57 89\n84 28\n96 22\n93 12\n17 102\n51 103\n18 100\n92 25\n50 103\n14 99\n55 101\n112 20\n89 37\n18 109\n41 78\n65 41\n105 16\n8 71\n80 45\n48 74\n16 72\n13 86\n40 95\n14 82\n23 99\n36 109\n50 88\n35 78\n91 37\n84 51\n97 15\n13 105\n105 42\n100 45\n76 36\n51 109\n115 49\n100 15\n9 83\n110 46\n114 40\n57 81\n528 348", "output": "-1" }, { "input": "1 21\n0 1000", "output": "0" } ]
1,593,114,248
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
156
6,963,200
nk=input().split() n=int(nk[0]) k=int(nk[1]) res=[] for k_qtr in range (n) : ab=input().split() a=int(ab[0]) b=int(ab[1]) m_1=min(a,b) m_2=max(a,b) if m_1<k and m_2<k : res.append(k-m_2) elif k<m_1 : res.append(m_1-k) elif m_1<k<m_2 : res.append(-1) print(max(res))
Title: Young Photographer Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*1 to position *b*1, the second — from *a*2 to *b*2 What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack. Input Specification: The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*). Output Specification: Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. Demo Input: ['3 3\n0 7\n14 2\n4 6\n'] Demo Output: ['1\n'] Note: none
```python nk=input().split() n=int(nk[0]) k=int(nk[1]) res=[] for k_qtr in range (n) : ab=input().split() a=int(ab[0]) b=int(ab[1]) m_1=min(a,b) m_2=max(a,b) if m_1<k and m_2<k : res.append(k-m_2) elif k<m_1 : res.append(m_1-k) elif m_1<k<m_2 : res.append(-1) print(max(res)) ```
0
713
A
Sonya and Queries
PROGRAMMING
1,400
[ "data structures", "implementation" ]
null
null
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type: 1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer. 1. <=-<= *a**i* — delete a single occurrence of non-negative integer *a**i* from the multiset. It's guaranteed, that there is at least one *a**i* in the multiset. 1. ? *s* — count the number of integers in the multiset (with repetitions) that match some pattern *s* consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer *x* matches the pattern *s*, if the parity of the *i*-th from the right digit in decimal notation matches the *i*-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left. For example, if the pattern is *s*<==<=010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
The first line of the input contains an integer *t* (1<=≤<=*t*<=≤<=100<=000) — the number of operation Sonya has to perform. Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i* — the type of the corresponding operation. If *c**i* is equal to '+' or '-' then it's followed by a space and an integer *a**i* (0<=≤<=*a**i*<=&lt;<=1018) given without leading zeroes (unless it's 0). If *c**i* equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18. It's guaranteed that there will be at least one query of type '?'. It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
[ "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n", "4\n+ 200\n+ 200\n- 200\n? 0\n" ]
[ "2\n1\n2\n1\n1\n", "1\n" ]
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input. 1. 1 and 241. 1. 361. 1. 101 and 361. 1. 361. 1. 4000.
500
[ { "input": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0", "output": "2\n1\n2\n1\n1" }, { "input": "4\n+ 200\n+ 200\n- 200\n? 0", "output": "1" }, { "input": "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n+ 39\n+ 78\n+ 81\n+ 89\n? 10\n? 00\n? 10\n? 01\n? 01\n? 00\n? 00", "output": "3\n2\n3\n4\n4\n2\n2" }, { "input": "20\n+ 13\n+ 50\n+ 9\n? 0\n+ 24\n? 0\n- 24\n? 0\n+ 79\n? 11\n- 13\n? 11\n- 50\n? 10\n? 1\n- 9\n? 1\n? 11\n- 79\n? 11", "output": "0\n1\n0\n2\n1\n0\n1\n0\n1\n0" }, { "input": "10\n+ 870566619432760298\n+ 869797178280285214\n+ 609920823721618090\n+ 221159591436767023\n+ 730599542279836538\n? 101001100111001011\n? 001111010101010011\n? 100010100011101110\n? 100110010110001100\n? 110000011101110011", "output": "0\n0\n0\n0\n0" }, { "input": "10\n+ 96135\n? 10111\n+ 63322\n? 10111\n+ 44490\n? 10111\n+ 69312\n? 10111\n? 01100\n+ 59396", "output": "1\n1\n1\n1\n1" }, { "input": "10\n+ 2\n- 2\n+ 778\n+ 3\n+ 4\n- 4\n+ 1\n+ 617\n? 011\n? 011", "output": "1\n1" }, { "input": "20\n+ 8\n+ 39532\n+ 813\n- 39532\n? 00011\n? 00000\n? 00011\n+ 70424\n- 8\n? 00011\n- 70424\n? 00011\n+ 29\n? 00001\n+ 6632\n+ 3319\n? 00001\n+ 3172\n? 01111\n- 29", "output": "1\n1\n1\n1\n1\n1\n1\n1" } ]
1,574,005,845
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
12
1,000
11,059,200
t = int(input()) cnt, res = {}, [] for _ in range(t): op, n = input().split() n = sum([1<<int(len(n)-i-1) for i in range(len(n)) if int(n[i]) % 2]) if op == '+': cnt[n] = cnt.get(n, 0) + 1 elif op == '-': cnt[n] -= 1 else: res.append(str(cnt.get(n, 0))) print('\n'.join(res))
Title: Sonya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type: 1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer. 1. <=-<= *a**i* — delete a single occurrence of non-negative integer *a**i* from the multiset. It's guaranteed, that there is at least one *a**i* in the multiset. 1. ? *s* — count the number of integers in the multiset (with repetitions) that match some pattern *s* consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer *x* matches the pattern *s*, if the parity of the *i*-th from the right digit in decimal notation matches the *i*-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left. For example, if the pattern is *s*<==<=010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not. Input Specification: The first line of the input contains an integer *t* (1<=≤<=*t*<=≤<=100<=000) — the number of operation Sonya has to perform. Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i* — the type of the corresponding operation. If *c**i* is equal to '+' or '-' then it's followed by a space and an integer *a**i* (0<=≤<=*a**i*<=&lt;<=1018) given without leading zeroes (unless it's 0). If *c**i* equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18. It's guaranteed that there will be at least one query of type '?'. It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it. Output Specification: For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time. Demo Input: ['12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n', '4\n+ 200\n+ 200\n- 200\n? 0\n'] Demo Output: ['2\n1\n2\n1\n1\n', '1\n'] Note: Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input. 1. 1 and 241. 1. 361. 1. 101 and 361. 1. 361. 1. 4000.
```python t = int(input()) cnt, res = {}, [] for _ in range(t): op, n = input().split() n = sum([1<<int(len(n)-i-1) for i in range(len(n)) if int(n[i]) % 2]) if op == '+': cnt[n] = cnt.get(n, 0) + 1 elif op == '-': cnt[n] -= 1 else: res.append(str(cnt.get(n, 0))) print('\n'.join(res)) ```
0
910
A
The Way to Home
PROGRAMMING
800
[ "dfs and similar", "dp", "greedy", "implementation" ]
null
null
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*. For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*. Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1.
The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump. The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one.
If the frog can not reach the home, print -1. In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
[ "8 4\n10010101\n", "4 2\n1001\n", "8 4\n11100101\n", "12 3\n101111100101\n" ]
[ "2\n", "-1\n", "3\n", "4\n" ]
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four). In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two.
500
[ { "input": "8 4\n10010101", "output": "2" }, { "input": "4 2\n1001", "output": "-1" }, { "input": "8 4\n11100101", "output": "3" }, { "input": "12 3\n101111100101", "output": "4" }, { "input": "5 4\n11011", "output": "1" }, { "input": "5 4\n10001", "output": "1" }, { "input": "10 7\n1101111011", "output": "2" }, { "input": "10 9\n1110000101", "output": "1" }, { "input": "10 9\n1100000001", "output": "1" }, { "input": "20 5\n11111111110111101001", "output": "4" }, { "input": "20 11\n11100000111000011011", "output": "2" }, { "input": "20 19\n10100000000000000001", "output": "1" }, { "input": "50 13\n10011010100010100111010000010000000000010100000101", "output": "5" }, { "input": "50 8\n11010100000011001100001100010001110000101100110011", "output": "8" }, { "input": "99 4\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111", "output": "25" }, { "input": "99 98\n100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "1" }, { "input": "100 5\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "20" }, { "input": "100 4\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111", "output": "25" }, { "input": "100 4\n1111111111111111111111111111111111111111111111111111111111111101111111011111111111111111111111111111", "output": "25" }, { "input": "100 3\n1111110111111111111111111111111111111111101111111111111111111111111101111111111111111111111111111111", "output": "34" }, { "input": "100 8\n1111111111101110111111111111111111111111111111111111111111111111111111110011111111111111011111111111", "output": "13" }, { "input": "100 7\n1011111111111111111011101111111011111101111111111101111011110111111111111111111111110111111011111111", "output": "15" }, { "input": "100 9\n1101111110111110101111111111111111011001110111011101011111111111010101111111100011011111111010111111", "output": "12" }, { "input": "100 6\n1011111011111111111011010110011001010101111110111111000111011011111110101101110110101111110000100111", "output": "18" }, { "input": "100 7\n1110001111101001110011111111111101111101101001010001101000101100000101101101011111111101101000100001", "output": "16" }, { "input": "100 11\n1000010100011100011011100000010011001111011110100100001011010100011011111001101101110110010110001101", "output": "10" }, { "input": "100 9\n1001001110000011100100000001000110111101101010101001000101001010011001101100110011011110110011011111", "output": "13" }, { "input": "100 7\n1010100001110101111011000111000001110100100110110001110110011010100001100100001110111100110000101001", "output": "18" }, { "input": "100 10\n1110110000000110000000101110100000111000001011100000100110010001110111001010101000011000000001011011", "output": "12" }, { "input": "100 13\n1000000100000000100011000010010000101010011110000000001000011000110100001000010001100000011001011001", "output": "9" }, { "input": "100 11\n1000000000100000010000100001000100000000010000100100000000100100001000000001011000110001000000000101", "output": "12" }, { "input": "100 22\n1000100000001010000000000000000001000000100000000000000000010000000000001000000000000000000100000001", "output": "7" }, { "input": "100 48\n1000000000000000011000000000000000000000000000000001100000000000000000000000000000000000000000000001", "output": "3" }, { "input": "100 48\n1000000000000000000000100000000000000000000000000000000000000000000001000000000000000000100000000001", "output": "3" }, { "input": "100 75\n1000000100000000000000000000000000000000000000000000000000000000000000000000000001000000000000000001", "output": "3" }, { "input": "100 73\n1000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001", "output": "2" }, { "input": "100 99\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "1" }, { "input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "99" }, { "input": "100 2\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111", "output": "50" }, { "input": "100 1\n1111111111111111011111111111111111111111111111111111111111111111111101111111111111111111111111111111", "output": "-1" }, { "input": "100 3\n1111111111111111111111111101111111111111111111111011111111111111111111111111111011111111111111111111", "output": "33" }, { "input": "100 1\n1101111111111111111111101111111111111111111111111111111111111011111111101111101111111111111111111111", "output": "-1" }, { "input": "100 6\n1111111111111111111111101111111101011110001111111111111111110111111111111111111111111110010111111111", "output": "17" }, { "input": "100 2\n1111111101111010110111011011110111101111111011111101010101011111011111111111111011111001101111101111", "output": "-1" }, { "input": "100 8\n1100110101111001101001111000111100110100011110111011001011111110000110101000001110111011100111011011", "output": "14" }, { "input": "100 10\n1000111110100000001001101100000010011100010101001100010011111001001101111110110111101111001010001101", "output": "11" }, { "input": "100 7\n1110000011010001110101011010000011110001000000011101110111010110001000011101111010010001101111110001", "output": "-1" }, { "input": "100 3\n1111010001000001011011000011001111000100101000101101000010111101111000010000011110110011001101010111", "output": "-1" }, { "input": "100 9\n1101010101101100010111011000010100001010000101010011001001100010110110000000010000101000000001101101", "output": "13" }, { "input": "100 14\n1010100000000000010101000010001100000000000011100010000001000001011010001110001010100000100001101101", "output": "9" }, { "input": "100 13\n1000000001101001110000010000011001000000000000001010000000100001001010000000000000000100010000000001", "output": "-1" }, { "input": "100 18\n1000000000000000110000000000000000010000000001000001000001000000000100000000000010000000000000000001", "output": "-1" }, { "input": "100 32\n1000000000000000000000000001000000000000000000000101000000000000000000000000000000000001000000000001", "output": "-1" }, { "input": "100 79\n1000000001000000000101000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "2" }, { "input": "100 41\n1000000000000000000000000000000000010000000000000000000000000000000000000000100000000000000000000001", "output": "3" }, { "input": "100 82\n1000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "2" }, { "input": "100 96\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "-1" }, { "input": "43 30\n1001000001111111010100100100110101011101101", "output": "2" }, { "input": "7 1\n1111111", "output": "6" }, { "input": "9 3\n101000001", "output": "-1" }, { "input": "10 3\n1100000001", "output": "-1" }, { "input": "8 2\n10000101", "output": "-1" }, { "input": "2 1\n11", "output": "1" } ]
1,579,293,512
2,147,483,647
PyPy 3
OK
TESTS
63
140
0
from sys import stdin n,d=map(int,stdin.readline().split()) s=input() # last = 0 jump = 0 possible = True while last<n-1: for c in range(min(last+d,n-1),last,-1): if s[c]=='1': jump += 1 last = c break else: possible = False break if possible: print(jump) else: print(-1)
Title: The Way to Home Time Limit: None seconds Memory Limit: None megabytes Problem Description: A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*. For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*. Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1. Input Specification: The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump. The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one. Output Specification: If the frog can not reach the home, print -1. In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. Demo Input: ['8 4\n10010101\n', '4 2\n1001\n', '8 4\n11100101\n', '12 3\n101111100101\n'] Demo Output: ['2\n', '-1\n', '3\n', '4\n'] Note: In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four). In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two.
```python from sys import stdin n,d=map(int,stdin.readline().split()) s=input() # last = 0 jump = 0 possible = True while last<n-1: for c in range(min(last+d,n-1),last,-1): if s[c]=='1': jump += 1 last = c break else: possible = False break if possible: print(jump) else: print(-1) ```
3
385
B
Bear and Strings
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation", "math", "strings" ]
null
null
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem.
The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number — the answer to the problem.
[ "bearbtear\n", "bearaabearc\n" ]
[ "6\n", "20\n" ]
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
1,000
[ { "input": "bearbtear", "output": "6" }, { "input": "bearaabearc", "output": "20" }, { "input": "pbearbearhbearzqbearjkterasjhy", "output": "291" }, { "input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "output": "4419" }, { "input": "bear", "output": "1" }, { "input": "a", "output": "0" }, { "input": "be", "output": "0" } ]
1,532,446,423
2,147,483,647
Python 3
OK
TESTS
43
171
716,800
import re s = input() bears = [-1] + [m.start() for m in re.finditer('bear', s)] sol = 0 for i in range(1, len(bears)): sol += (bears[i] - bears[i-1]) * (len(s) - bears[i] - 3) print(sol)
Title: Bear and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem. Input Specification: The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. Output Specification: Print a single number — the answer to the problem. Demo Input: ['bearbtear\n', 'bearaabearc\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
```python import re s = input() bears = [-1] + [m.start() for m in re.finditer('bear', s)] sol = 0 for i in range(1, len(bears)): sol += (bears[i] - bears[i-1]) * (len(s) - bears[i] - 3) print(sol) ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,551,035,373
2,147,483,647
Python 3
OK
TESTS
40
109
0
x = input() h = 'hello' z, count = 0, 0 for i in range(len(h)): for j in range(z, len(x)): if h[i] == x[j]: count += 1 z = j + 1 break if count == len(h): print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python x = input() h = 'hello' z, count = 0, 0 for i in range(len(h)): for j in range(z, len(x)): if h[i] == x[j]: count += 1 z = j + 1 break if count == len(h): print("YES") else: print("NO") ```
3.9455
276
C
Little Girl and Maximum Sum
PROGRAMMING
1,500
[ "data structures", "greedy", "implementation", "sortings" ]
null
null
The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query.
In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. 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.
[ "3 3\n5 3 2\n1 2\n2 3\n1 3\n", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n" ]
[ "25\n", "33\n" ]
none
1,500
[ { "input": "3 3\n5 3 2\n1 2\n2 3\n1 3", "output": "25" }, { "input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3", "output": "33" }, { "input": "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\n12 30\n11 30\n9 21\n1 14\n15 22\n4 11\n5 24\n8 20\n17 33\n6 9\n3 14\n25 34\n10 17", "output": "9382" }, { "input": "16 13\n40 32 15 16 35 36 45 23 30 42 25 8 29 21 39 23\n2 9\n3 11\n8 9\n4 14\n1 6\n5 10\n5 14\n5 11\n13 13\n2 8\n9 16\n6 10\n7 8", "output": "2838" }, { "input": "31 48\n45 19 16 42 38 18 50 7 28 40 39 25 45 14 36 18 27 30 16 4 22 6 1 23 16 47 14 35 27 47 2\n6 16\n11 28\n4 30\n25 26\n11 30\n5 9\n4 17\n15 17\n10 25\n15 26\n1 3\n9 26\n8 29\n16 30\n5 24\n27 30\n9 10\n22 29\n2 6\n15 24\n6 21\n19 21\n4 28\n1 7\n18 21\n10 22\n6 15\n14 28\n4 29\n12 13\n19 29\n5 6\n13 31\n21 27\n9 25\n6 18\n6 8\n28 30\n2 4\n15 21\n1 1\n8 30\n3 31\n11 27\n28 29\n6 22\n20 22\n9 25", "output": "17471" }, { "input": "22 7\n44 41 40 41 37 42 46 16 50 47 30 7 32 6 20 14 47 25 11 1 35 12\n1 10\n10 20\n4 5\n1 8\n2 12\n8 8\n2 16", "output": "2202" }, { "input": "3 2\n1 2 3\n2 3\n1 2", "output": "9" } ]
1,681,026,806
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
59,904,000
#!/usr/bin/python3 #read all input n, q = map(int, input().split()) a = list(map(int, input().split())) queries = [] for i in range(0, q): queries.append(list(map(int, input().split()))) #compute frequencies of index usage class IndexFrequency: def __init__(self, index, frequency): self.index = index self.frequency = frequency freqs = [] for i in range(0, n): freqs.append(IndexFrequency(i, 0)) for i in range(0, q): l = queries[i][0] r = queries[i][1] for j in range(l, r + 1): freqs[j - 1].frequency += 1 #sort freqs from highest a.sort(reverse=True) freqs.sort(key=lambda x:x.frequency, reverse=True) #create final array f = [0] * n for i in range(0, n): f[freqs[i].index] = a[i] #create sums array for quick counting sum = 0 s = [0] * n for i in range(0, n): sum += f[i] s[i] = sum #count final max sum sum = 0 for i in range(0, q): li = queries[i][0] - 1 ri = queries[i][1] - 1 sum += s[ri] - (s[li-1] if li > 0 else 0) #print result print(sum)
Title: Little Girl and Maximum Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum. Input Specification: The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query. Output Specification: In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. 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: ['3 3\n5 3 2\n1 2\n2 3\n1 3\n', '5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n'] Demo Output: ['25\n', '33\n'] Note: none
```python #!/usr/bin/python3 #read all input n, q = map(int, input().split()) a = list(map(int, input().split())) queries = [] for i in range(0, q): queries.append(list(map(int, input().split()))) #compute frequencies of index usage class IndexFrequency: def __init__(self, index, frequency): self.index = index self.frequency = frequency freqs = [] for i in range(0, n): freqs.append(IndexFrequency(i, 0)) for i in range(0, q): l = queries[i][0] r = queries[i][1] for j in range(l, r + 1): freqs[j - 1].frequency += 1 #sort freqs from highest a.sort(reverse=True) freqs.sort(key=lambda x:x.frequency, reverse=True) #create final array f = [0] * n for i in range(0, n): f[freqs[i].index] = a[i] #create sums array for quick counting sum = 0 s = [0] * n for i in range(0, n): sum += f[i] s[i] = sum #count final max sum sum = 0 for i in range(0, q): li = queries[i][0] - 1 ri = queries[i][1] - 1 sum += s[ri] - (s[li-1] if li > 0 else 0) #print result print(sum) ```
0
680
A
Bear and Five Cards
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards. He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number. Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?
The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards.
Print the minimum possible sum of numbers written on remaining cards.
[ "7 3 7 3 20\n", "7 9 3 1 8\n", "10 10 10 10 10\n" ]
[ "26\n", "28\n", "20\n" ]
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following. - Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34. You are asked to minimize the sum so the answer is 26. In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28. In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.
500
[ { "input": "7 3 7 3 20", "output": "26" }, { "input": "7 9 3 1 8", "output": "28" }, { "input": "10 10 10 10 10", "output": "20" }, { "input": "8 7 1 8 7", "output": "15" }, { "input": "7 7 7 8 8", "output": "16" }, { "input": "8 8 8 2 2", "output": "4" }, { "input": "8 8 2 2 2", "output": "6" }, { "input": "5 50 5 5 60", "output": "110" }, { "input": "100 100 100 100 100", "output": "200" }, { "input": "1 1 1 1 1", "output": "2" }, { "input": "29 29 20 20 20", "output": "58" }, { "input": "20 29 20 29 20", "output": "58" }, { "input": "31 31 20 20 20", "output": "60" }, { "input": "20 20 20 31 31", "output": "60" }, { "input": "20 31 20 31 20", "output": "60" }, { "input": "20 20 20 30 30", "output": "60" }, { "input": "30 30 20 20 20", "output": "60" }, { "input": "8 1 8 8 8", "output": "9" }, { "input": "1 1 1 8 1", "output": "9" }, { "input": "1 2 3 4 5", "output": "15" }, { "input": "100 99 98 97 96", "output": "490" }, { "input": "1 1 100 100 100", "output": "2" }, { "input": "100 100 99 99 98", "output": "296" }, { "input": "98 99 100 99 100", "output": "296" }, { "input": "1 90 1 91 1", "output": "181" }, { "input": "60 1 75 1 92", "output": "227" }, { "input": "15 40 90 40 90", "output": "95" }, { "input": "1 1 15 20 20", "output": "17" }, { "input": "90 11 11 10 10", "output": "110" }, { "input": "20 21 22 23 24", "output": "110" }, { "input": "1 1 2 98 99", "output": "199" }, { "input": "3 7 7 7 10", "output": "13" }, { "input": "1 3 3 3 1", "output": "2" }, { "input": "1 9 9 9 10", "output": "11" }, { "input": "100 1 1 1 1", "output": "101" }, { "input": "2 2 2 100 100", "output": "6" }, { "input": "1 2 2 2 2", "output": "3" }, { "input": "1 1 2 2 5", "output": "7" }, { "input": "1 2 3 4 1", "output": "9" }, { "input": "11 10 10 10 10", "output": "21" }, { "input": "2 2 2 10 10", "output": "6" }, { "input": "1 1 1 1 4", "output": "5" }, { "input": "98 98 98 98 23", "output": "121" }, { "input": "1 2 3 100 100", "output": "6" }, { "input": "2 2 5 10 10", "output": "9" }, { "input": "2 2 3 3 3", "output": "4" }, { "input": "1 1 1 1 2", "output": "3" }, { "input": "12 12 7 7 7", "output": "21" } ]
1,696,689,936
2,147,483,647
Python 3
OK
TESTS
48
46
0
# Read the input numbers into a list numbers = list(map(int, input().split())) # Calculate the total sum of numbers total_sum = sum(numbers) # Initialize a variable to store the minimum possible sum min_sum = total_sum # Iterate through each unique number in the list for num in set(numbers): # Count the occurrences of the current number in the list count = numbers.count(num) # Calculate the sum if we remove 2 or 3 occurrences of the current number if count >= 2: remove_two_sum = total_sum - (num * min(2, count)) min_sum = min(min_sum, remove_two_sum) if count >= 3: remove_three_sum = total_sum - (num * min(3, count)) min_sum = min(min_sum, remove_three_sum) # Print the minimum possible sum print(min_sum)
Title: Bear and Five Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards. He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number. Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards? Input Specification: The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards. Output Specification: Print the minimum possible sum of numbers written on remaining cards. Demo Input: ['7 3 7 3 20\n', '7 9 3 1 8\n', '10 10 10 10 10\n'] Demo Output: ['26\n', '28\n', '20\n'] Note: In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following. - Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34. You are asked to minimize the sum so the answer is 26. In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28. In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.
```python # Read the input numbers into a list numbers = list(map(int, input().split())) # Calculate the total sum of numbers total_sum = sum(numbers) # Initialize a variable to store the minimum possible sum min_sum = total_sum # Iterate through each unique number in the list for num in set(numbers): # Count the occurrences of the current number in the list count = numbers.count(num) # Calculate the sum if we remove 2 or 3 occurrences of the current number if count >= 2: remove_two_sum = total_sum - (num * min(2, count)) min_sum = min(min_sum, remove_two_sum) if count >= 3: remove_three_sum = total_sum - (num * min(3, count)) min_sum = min(min_sum, remove_three_sum) # Print the minimum possible sum print(min_sum) ```
3
514
B
Han Solo and Lazer Gun
PROGRAMMING
1,400
[ "brute force", "data structures", "geometry", "implementation", "math" ]
null
null
There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (*x*0,<=*y*0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (*x*0,<=*y*0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
The first line contains three integers *n*, *x*0 и *y*0 (1<=≤<=*n*<=≤<=1000, <=-<=104<=≤<=*x*0,<=*y*0<=≤<=104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next *n* lines contain two integers each *x**i*, *y**i* (<=-<=104<=≤<=*x**i*,<=*y**i*<=≤<=104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
[ "4 0 0\n1 1\n2 2\n2 0\n-1 -1\n", "2 1 2\n1 1\n1 0\n" ]
[ "2\n", "1\n" ]
Explanation to the first and second samples from the statement, respectively:
1,000
[ { "input": "4 0 0\n1 1\n2 2\n2 0\n-1 -1", "output": "2" }, { "input": "2 1 2\n1 1\n1 0", "output": "1" }, { "input": "1 1 1\n0 0", "output": "1" }, { "input": "2 0 0\n10000 -10000\n-10000 10000", "output": "1" }, { "input": "2 0 0\n10000 -10000\n10000 10000", "output": "2" }, { "input": "10 -4 -4\n2 -4\n2 0\n-4 2\n5 -4\n-3 -5\n1 4\n-4 2\n-3 5\n0 -3\n2 4", "output": "8" }, { "input": "10 5 -3\n1 1\n2 -1\n2 2\n1 -2\n4 -5\n1 4\n0 1\n1 -4\n-2 0\n-4 -5", "output": "10" }, { "input": "10 -3 3\n3 -5\n4 3\n0 -2\n0 0\n3 -3\n3 5\n4 1\n5 5\n4 -5\n4 -4", "output": "8" }, { "input": "2 -10000 -10000\n10000 10000\n10000 9999", "output": "2" }, { "input": "2 -10000 -10000\n9998 9999\n9999 10000", "output": "2" }, { "input": "2 0 0\n0 1337\n3 9000", "output": "2" }, { "input": "2 0 -1\n0 1\n1 10000", "output": "2" }, { "input": "2 0 0\n0 10\n1 2000", "output": "2" }, { "input": "2 0 0\n0 2\n1 90", "output": "2" }, { "input": "2 0 0\n1001 0\n1001 1", "output": "2" } ]
1,684,428,592
2,147,483,647
Python 3
OK
TESTS
29
46
0
n=input().split() l=[] count=0 for i in range (int(n[0])): x=input().split() if int(x[0])-int(n[1])!=0: y=(int(x[1])-int(n[2]))/(int(x[0])-int(n[1])) if y not in l: l.append(y) else: count=1 if count==1: print(len(l)+1) else: print(len(l))
Title: Han Solo and Lazer Gun Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (*x*0,<=*y*0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (*x*0,<=*y*0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input Specification: The first line contains three integers *n*, *x*0 и *y*0 (1<=≤<=*n*<=≤<=1000, <=-<=104<=≤<=*x*0,<=*y*0<=≤<=104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next *n* lines contain two integers each *x**i*, *y**i* (<=-<=104<=≤<=*x**i*,<=*y**i*<=≤<=104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Specification: Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Demo Input: ['4 0 0\n1 1\n2 2\n2 0\n-1 -1\n', '2 1 2\n1 1\n1 0\n'] Demo Output: ['2\n', '1\n'] Note: Explanation to the first and second samples from the statement, respectively:
```python n=input().split() l=[] count=0 for i in range (int(n[0])): x=input().split() if int(x[0])-int(n[1])!=0: y=(int(x[1])-int(n[2]))/(int(x[0])-int(n[1])) if y not in l: l.append(y) else: count=1 if count==1: print(len(l)+1) else: print(len(l)) ```
3
893
B
Beautiful Divisors
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes. Some examples of beautiful numbers: - 12 (110); - 1102 (610); - 11110002 (12010); - 1111100002 (49610). More formally, the number is beautiful iff there exists some positive integer *k* such that the number is equal to (2*k*<=-<=1)<=*<=(2*k*<=-<=1). Luba has got an integer number *n*, and she wants to find its greatest beautiful divisor. Help her to find it!
The only line of input contains one number *n* (1<=≤<=*n*<=≤<=105) — the number Luba has got.
Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists.
[ "3\n", "992\n" ]
[ "1\n", "496\n" ]
none
0
[ { "input": "3", "output": "1" }, { "input": "992", "output": "496" }, { "input": "81142", "output": "1" }, { "input": "76920", "output": "120" }, { "input": "2016", "output": "2016" }, { "input": "1", "output": "1" }, { "input": "6", "output": "6" }, { "input": "32640", "output": "32640" }, { "input": "12096", "output": "2016" }, { "input": "55948", "output": "1" }, { "input": "47262", "output": "6" }, { "input": "22876", "output": "28" }, { "input": "96120", "output": "120" }, { "input": "42160", "output": "496" }, { "input": "38304", "output": "2016" }, { "input": "89408", "output": "8128" }, { "input": "97920", "output": "32640" }, { "input": "55493", "output": "1" }, { "input": "38021", "output": "1" }, { "input": "21445", "output": "1" }, { "input": "100000", "output": "1" }, { "input": "497", "output": "1" }, { "input": "240", "output": "120" }, { "input": "21204", "output": "6" }, { "input": "65536", "output": "1" }, { "input": "364", "output": "28" }, { "input": "1024", "output": "1" }, { "input": "36", "output": "6" }, { "input": "28", "output": "28" }, { "input": "14400", "output": "120" }, { "input": "10080", "output": "2016" }, { "input": "9", "output": "1" }, { "input": "2", "output": "1" }, { "input": "42", "output": "6" }, { "input": "83160", "output": "120" }, { "input": "65534", "output": "1" }, { "input": "1026", "output": "6" }, { "input": "1025", "output": "1" }, { "input": "1027", "output": "1" }, { "input": "2018", "output": "1" }, { "input": "2020", "output": "1" }, { "input": "123", "output": "1" }, { "input": "150", "output": "6" }, { "input": "5", "output": "1" }, { "input": "66", "output": "6" }, { "input": "12768", "output": "28" }, { "input": "156", "output": "6" }, { "input": "99990", "output": "6" }, { "input": "248", "output": "1" } ]
1,626,946,699
1,399
PyPy 3
WRONG_ANSWER
TESTS
2
77
20,172,800
arr = [] k = 1 while True: now = 0 for _ in range(k, k + k): pw = _ -1 now += (2 ** pw) if now > 10**5: break k += 1 arr.append(now) n = int(input()) ans = 0 for i in arr: if i <= n: ans = i print(ans)
Title: Beautiful Divisors Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes. Some examples of beautiful numbers: - 12 (110); - 1102 (610); - 11110002 (12010); - 1111100002 (49610). More formally, the number is beautiful iff there exists some positive integer *k* such that the number is equal to (2*k*<=-<=1)<=*<=(2*k*<=-<=1). Luba has got an integer number *n*, and she wants to find its greatest beautiful divisor. Help her to find it! Input Specification: The only line of input contains one number *n* (1<=≤<=*n*<=≤<=105) — the number Luba has got. Output Specification: Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists. Demo Input: ['3\n', '992\n'] Demo Output: ['1\n', '496\n'] Note: none
```python arr = [] k = 1 while True: now = 0 for _ in range(k, k + k): pw = _ -1 now += (2 ** pw) if now > 10**5: break k += 1 arr.append(now) n = int(input()) ans = 0 for i in arr: if i <= n: ans = i print(ans) ```
0
1,006
A
Adjacent Replacements
PROGRAMMING
800
[ "implementation" ]
null
null
Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: - Replace each occurrence of $1$ in the array $a$ with $2$; - Replace each occurrence of $2$ in the array $a$ with $1$; - Replace each occurrence of $3$ in the array $a$ with $4$; - Replace each occurrence of $4$ in the array $a$ with $3$; - Replace each occurrence of $5$ in the array $a$ with $6$; - Replace each occurrence of $6$ in the array $a$ with $5$; - $\dots$ - Replace each occurrence of $10^9 - 1$ in the array $a$ with $10^9$; - Replace each occurrence of $10^9$ in the array $a$ with $10^9 - 1$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($2i - 1, 2i$) for each $i \in\{1, 2, \ldots, 5 \cdot 10^8\}$ as described above. For example, for the array $a = [1, 2, 4, 5, 10]$, the following sequence of arrays represents the algorithm: $[1, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $1$ with $2$) $\rightarrow$ $[2, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $2$ with $1$) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $3$ with $4$) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $4$ with $3$) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $5$ with $6$) $\rightarrow$ $[1, 1, 3, 6, 10]$ $\rightarrow$ (replace all occurrences of $6$ with $5$) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ $\dots$ $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $10$ with $9$) $\rightarrow$ $[1, 1, 3, 5, 9]$. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it.
The first line of the input contains one integer number $n$ ($1 \le n \le 1000$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array.
Print $n$ integers — $b_1, b_2, \dots, b_n$, where $b_i$ is the final value of the $i$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$. Note that you cannot change the order of elements in the array.
[ "5\n1 2 4 5 10\n", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n" ]
[ "1 1 3 5 9\n", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999\n" ]
The first example is described in the problem statement.
0
[ { "input": "5\n1 2 4 5 10", "output": "1 1 3 5 9" }, { "input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999" }, { "input": "1\n999999999", "output": "999999999" }, { "input": "1\n1000000000", "output": "999999999" }, { "input": "1\n210400", "output": "210399" }, { "input": "5\n100000000 100000000 100000000 100000000 100000000", "output": "99999999 99999999 99999999 99999999 99999999" }, { "input": "1\n2441139", "output": "2441139" }, { "input": "2\n2 2", "output": "1 1" }, { "input": "3\n2 2 2", "output": "1 1 1" }, { "input": "2\n4 4", "output": "3 3" } ]
1,600,692,960
2,147,483,647
PyPy 3
OK
TESTS
18
280
7,065,600
# 1006A # https://codeforces.com/problemset/problem/1006/A def findNthMin(arr, n): sortedArr = list(sorted(set(arr))) return sortedArr[n-1] cnt = int(input()) numbers = [int(i) for i in input().split(' ')] mx = max(numbers) + 1 curMin = 0 minNth = 1 while curMin < mx: curMin = findNthMin(numbers, minNth) if curMin % 2 == 1: numbers = [item+1 if item==curMin else item for item in numbers] numbers = [item-1 if item==curMin+1 else item for item in numbers] curMin += 2 else: numbers = [item-1 if item==curMin else item for item in numbers] curMin += 1 minNth += 1 print(*numbers)
Title: Adjacent Replacements Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: - Replace each occurrence of $1$ in the array $a$ with $2$; - Replace each occurrence of $2$ in the array $a$ with $1$; - Replace each occurrence of $3$ in the array $a$ with $4$; - Replace each occurrence of $4$ in the array $a$ with $3$; - Replace each occurrence of $5$ in the array $a$ with $6$; - Replace each occurrence of $6$ in the array $a$ with $5$; - $\dots$ - Replace each occurrence of $10^9 - 1$ in the array $a$ with $10^9$; - Replace each occurrence of $10^9$ in the array $a$ with $10^9 - 1$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($2i - 1, 2i$) for each $i \in\{1, 2, \ldots, 5 \cdot 10^8\}$ as described above. For example, for the array $a = [1, 2, 4, 5, 10]$, the following sequence of arrays represents the algorithm: $[1, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $1$ with $2$) $\rightarrow$ $[2, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $2$ with $1$) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $3$ with $4$) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $4$ with $3$) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $5$ with $6$) $\rightarrow$ $[1, 1, 3, 6, 10]$ $\rightarrow$ (replace all occurrences of $6$ with $5$) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ $\dots$ $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $10$ with $9$) $\rightarrow$ $[1, 1, 3, 5, 9]$. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input Specification: The first line of the input contains one integer number $n$ ($1 \le n \le 1000$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array. Output Specification: Print $n$ integers — $b_1, b_2, \dots, b_n$, where $b_i$ is the final value of the $i$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$. Note that you cannot change the order of elements in the array. Demo Input: ['5\n1 2 4 5 10\n', '10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n'] Demo Output: ['1 1 3 5 9\n', '9999 9 50605065 1 5 89 5 999999999 60506055 999999999\n'] Note: The first example is described in the problem statement.
```python # 1006A # https://codeforces.com/problemset/problem/1006/A def findNthMin(arr, n): sortedArr = list(sorted(set(arr))) return sortedArr[n-1] cnt = int(input()) numbers = [int(i) for i in input().split(' ')] mx = max(numbers) + 1 curMin = 0 minNth = 1 while curMin < mx: curMin = findNthMin(numbers, minNth) if curMin % 2 == 1: numbers = [item+1 if item==curMin else item for item in numbers] numbers = [item-1 if item==curMin+1 else item for item in numbers] curMin += 2 else: numbers = [item-1 if item==curMin else item for item in numbers] curMin += 1 minNth += 1 print(*numbers) ```
3
31
A
Worms Evolution
PROGRAMMING
1,200
[ "implementation" ]
A. Worms Evolution
2
256
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form.
Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*.
[ "5\n1 2 3 5 7\n", "5\n1 8 1 5 1\n" ]
[ "3 2 1\n", "-1\n" ]
none
500
[ { "input": "5\n1 2 3 5 7", "output": "3 2 1" }, { "input": "5\n1 8 1 5 1", "output": "-1" }, { "input": "4\n303 872 764 401", "output": "-1" }, { "input": "6\n86 402 133 524 405 610", "output": "6 4 1" }, { "input": "8\n217 779 418 895 996 473 3 22", "output": "5 2 1" }, { "input": "10\n858 972 670 15 662 114 33 273 53 310", "output": "2 6 1" }, { "input": "100\n611 697 572 770 603 870 128 245 49 904 468 982 788 943 549 288 668 796 803 515 999 735 912 49 298 80 412 841 494 434 543 298 17 571 271 105 70 313 178 755 194 279 585 766 412 164 907 841 776 556 731 268 735 880 176 267 287 65 239 588 155 658 821 47 783 595 585 69 226 906 429 161 999 148 7 484 362 585 952 365 92 749 904 525 307 626 883 367 450 755 564 950 728 724 69 106 119 157 96 290", "output": "1 38 25" }, { "input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438", "output": "1 63 61" }, { "input": "100\n156 822 179 298 981 82 610 345 373 378 895 734 768 15 78 335 764 608 932 297 717 553 916 367 425 447 361 195 66 70 901 236 905 744 919 564 296 610 963 628 840 52 100 750 345 308 37 687 192 704 101 815 10 990 216 358 823 546 578 821 706 148 182 582 421 482 829 425 121 337 500 301 402 868 66 935 625 527 746 585 308 523 488 914 608 709 875 252 151 781 447 2 756 176 976 302 450 35 680 791", "output": "1 98 69" }, { "input": "100\n54 947 785 838 359 647 92 445 48 465 323 486 101 86 607 31 860 420 709 432 435 372 272 37 903 814 309 197 638 58 259 822 793 564 309 22 522 907 101 853 486 824 614 734 630 452 166 532 256 499 470 9 933 452 256 450 7 26 916 406 257 285 895 117 59 369 424 133 16 417 352 440 806 236 478 34 889 469 540 806 172 296 73 655 261 792 868 380 204 454 330 53 136 629 236 850 134 560 264 291", "output": "2 29 27" }, { "input": "99\n175 269 828 129 499 890 127 263 995 807 508 289 996 226 437 320 365 642 757 22 190 8 345 499 834 713 962 889 336 171 608 492 320 257 472 801 176 325 301 306 198 729 933 4 640 322 226 317 567 586 249 237 202 633 287 128 911 654 719 988 420 855 361 574 716 899 317 356 581 440 284 982 541 111 439 29 37 560 961 224 478 906 319 416 736 603 808 87 762 697 392 713 19 459 262 238 239 599 997", "output": "1 44 30" }, { "input": "98\n443 719 559 672 16 69 529 632 953 999 725 431 54 22 346 968 558 696 48 669 963 129 257 712 39 870 498 595 45 821 344 925 179 388 792 346 755 213 423 365 344 659 824 356 773 637 628 897 841 155 243 536 951 361 192 105 418 431 635 596 150 162 145 548 473 531 750 306 377 354 450 975 79 743 656 733 440 940 19 139 237 346 276 227 64 799 479 633 199 17 796 362 517 234 729 62 995 535", "output": "2 70 40" }, { "input": "97\n359 522 938 862 181 600 283 1000 910 191 590 220 761 818 903 264 751 751 987 316 737 898 168 925 244 674 34 950 754 472 81 6 37 520 112 891 981 454 897 424 489 238 363 709 906 951 677 828 114 373 589 835 52 89 97 435 277 560 551 204 879 469 928 523 231 163 183 609 821 915 615 969 616 23 874 437 844 321 78 53 643 786 585 38 744 347 150 179 988 985 200 11 15 9 547 886 752", "output": "1 23 10" }, { "input": "4\n303 872 764 401", "output": "-1" }, { "input": "100\n328 397 235 453 188 254 879 225 423 36 384 296 486 592 231 849 856 255 213 898 234 800 701 529 951 693 507 326 15 905 618 348 967 927 28 979 752 850 343 35 84 302 36 390 482 826 249 918 91 289 973 457 557 348 365 239 709 565 320 560 153 130 647 708 483 469 788 473 322 844 830 562 611 961 397 673 69 960 74 703 369 968 382 451 328 160 211 230 566 208 7 545 293 73 806 375 157 410 303 58", "output": "1 79 6" }, { "input": "33\n52 145 137 734 180 847 178 286 716 134 181 630 358 764 593 762 785 28 1 468 189 540 764 485 165 656 114 58 628 108 605 584 257", "output": "8 30 7" }, { "input": "57\n75 291 309 68 444 654 985 158 514 204 116 918 374 806 176 31 49 455 269 66 722 713 164 818 317 295 546 564 134 641 28 13 987 478 146 219 213 940 289 173 157 666 168 391 392 71 870 477 446 988 414 568 964 684 409 671 454", "output": "2 41 29" }, { "input": "88\n327 644 942 738 84 118 981 686 530 404 137 197 434 16 693 183 423 325 410 345 941 329 7 106 79 867 584 358 533 675 192 718 641 329 900 768 404 301 101 538 954 590 401 954 447 14 559 337 756 586 934 367 538 928 945 936 770 641 488 579 206 869 902 139 216 446 723 150 829 205 373 578 357 368 960 40 121 206 503 385 521 161 501 694 138 370 709 308", "output": "1 77 61" }, { "input": "100\n804 510 266 304 788 625 862 888 408 82 414 470 777 991 729 229 933 406 601 1 596 720 608 706 432 361 527 548 59 548 474 515 4 991 263 568 681 24 117 563 576 587 281 643 904 521 891 106 842 884 943 54 605 815 504 757 311 374 335 192 447 652 633 410 455 402 382 150 432 836 413 819 669 875 638 925 217 805 632 520 605 266 728 795 162 222 603 159 284 790 914 443 775 97 789 606 859 13 851 47", "output": "1 77 42" }, { "input": "100\n449 649 615 713 64 385 927 466 138 126 143 886 80 199 208 43 196 694 92 89 264 180 617 970 191 196 910 150 275 89 693 190 191 99 542 342 45 592 114 56 451 170 64 589 176 102 308 92 402 153 414 675 352 157 69 150 91 288 163 121 816 184 20 234 836 12 593 150 793 439 540 93 99 663 186 125 349 247 476 106 77 523 215 7 363 278 441 745 337 25 148 384 15 915 108 211 240 58 23 408", "output": "1 6 5" }, { "input": "90\n881 436 52 308 97 261 153 931 670 538 702 156 114 445 154 685 452 76 966 790 93 42 547 65 736 364 136 489 719 322 239 628 696 735 55 703 622 375 100 188 804 341 546 474 484 446 729 290 974 301 602 225 996 244 488 983 882 460 962 754 395 617 61 640 534 292 158 375 632 902 420 979 379 38 100 67 963 928 190 456 545 571 45 716 153 68 844 2 102 116", "output": "1 14 2" }, { "input": "80\n313 674 262 240 697 146 391 221 793 504 896 818 92 899 86 370 341 339 306 887 937 570 830 683 729 519 240 833 656 847 427 958 435 704 853 230 758 347 660 575 843 293 649 396 437 787 654 599 35 103 779 783 447 379 444 585 902 713 791 150 851 228 306 721 996 471 617 403 102 168 197 741 877 481 968 545 331 715 236 654", "output": "1 13 8" }, { "input": "70\n745 264 471 171 946 32 277 511 269 469 89 831 69 2 369 407 583 602 646 633 429 747 113 302 722 321 344 824 241 372 263 287 822 24 652 758 246 967 219 313 882 597 752 965 389 775 227 556 95 904 308 340 899 514 400 187 275 318 621 546 659 488 199 154 811 1 725 79 925 82", "output": "1 63 60" }, { "input": "60\n176 502 680 102 546 917 516 801 392 435 635 492 398 456 653 444 472 513 634 378 273 276 44 920 68 124 800 167 825 250 452 264 561 344 98 933 381 939 426 51 568 548 206 887 342 763 151 514 156 354 486 546 998 649 356 438 295 570 450 589", "output": "2 26 20" }, { "input": "50\n608 92 889 33 146 803 402 91 868 400 828 505 375 558 584 129 361 776 974 123 765 804 326 186 61 927 904 511 762 775 640 593 300 664 897 461 869 911 986 789 607 500 309 457 294 104 724 471 216 155", "output": "3 25 11" }, { "input": "40\n40 330 98 612 747 336 640 381 991 366 22 167 352 12 868 166 603 40 313 869 609 981 609 804 54 729 8 854 347 300 828 922 39 633 695 988 4 530 545 176", "output": "5 10 8" }, { "input": "30\n471 920 308 544 347 222 878 671 467 332 215 180 681 114 151 203 492 951 653 614 453 510 540 422 399 532 113 198 932 825", "output": "2 21 9" }, { "input": "20\n551 158 517 475 595 108 764 961 590 297 761 841 659 568 82 888 733 214 993 359", "output": "3 20 2" }, { "input": "10\n983 748 726 406 196 993 2 251 66 263", "output": "-1" }, { "input": "9\n933 266 457 863 768 257 594 136 145", "output": "-1" }, { "input": "8\n537 198 48 771 944 868 700 163", "output": "7 8 1" }, { "input": "7\n140 779 639 679 768 479 158", "output": "2 3 1" }, { "input": "6\n744 359 230 586 944 442", "output": "-1" }, { "input": "5\n700 939 173 494 120", "output": "-1" }, { "input": "4\n303 872 764 401", "output": "-1" }, { "input": "3\n907 452 355", "output": "-1" }, { "input": "3\n963 630 333", "output": "1 3 2" }, { "input": "3\n2 2 4", "output": "3 2 1" }, { "input": "3\n2 4 100", "output": "-1" } ]
1,611,568,420
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
124
307,200
n = input() arr= [int(x) for x in input().split()] ar=set(arr) trip=[] c=0 for i in list(ar): for j in list(ar): if i!=j: if i+j in ar: trip=[i,j,i+j] c=1 break if c==1: break if c==0: print(-1) else: for i in trip: print(i, end=" ")
Title: Worms Evolution Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. Output Specification: Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. Demo Input: ['5\n1 2 3 5 7\n', '5\n1 8 1 5 1\n'] Demo Output: ['3 2 1\n', '-1\n'] Note: none
```python n = input() arr= [int(x) for x in input().split()] ar=set(arr) trip=[] c=0 for i in list(ar): for j in list(ar): if i!=j: if i+j in ar: trip=[i,j,i+j] c=1 break if c==1: break if c==0: print(-1) else: for i in trip: print(i, end=" ") ```
0
935
A
Fafa and his Company
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader. Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Print a single integer representing the answer to the problem.
[ "2\n", "10\n" ]
[ "1\n", "3\n" ]
In the second sample Fafa has 3 ways: - choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
500
[ { "input": "2", "output": "1" }, { "input": "10", "output": "3" }, { "input": "3", "output": "1" }, { "input": "4", "output": "2" }, { "input": "6", "output": "3" }, { "input": "13", "output": "1" }, { "input": "100000", "output": "35" }, { "input": "1024", "output": "10" }, { "input": "99999", "output": "11" }, { "input": "10007", "output": "1" }, { "input": "4096", "output": "12" }, { "input": "65536", "output": "16" }, { "input": "40320", "output": "95" }, { "input": "30030", "output": "63" }, { "input": "161", "output": "3" }, { "input": "1000", "output": "15" }, { "input": "10000", "output": "24" }, { "input": "777", "output": "7" }, { "input": "121", "output": "2" }, { "input": "25", "output": "2" }, { "input": "40000", "output": "34" }, { "input": "99990", "output": "47" }, { "input": "98765", "output": "3" }, { "input": "56789", "output": "3" }, { "input": "13579", "output": "3" }, { "input": "97531", "output": "3" }, { "input": "12345", "output": "7" }, { "input": "54321", "output": "7" }, { "input": "83160", "output": "127" }, { "input": "9", "output": "2" }, { "input": "21", "output": "3" }, { "input": "11", "output": "1" }, { "input": "15", "output": "3" } ]
1,661,578,314
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
46
0
n=int(input()) count=0 if n%2 == 0: for i in range(1,n//2 +1): if (n%i==0): count+=1 else: count=1 print(count)
Title: Fafa and his Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader. Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly. Input Specification: The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. Output Specification: Print a single integer representing the answer to the problem. Demo Input: ['2\n', '10\n'] Demo Output: ['1\n', '3\n'] Note: In the second sample Fafa has 3 ways: - choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
```python n=int(input()) count=0 if n%2 == 0: for i in range(1,n//2 +1): if (n%i==0): count+=1 else: count=1 print(count) ```
0
353
A
Domino
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half.
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
[ "2\n4 2\n6 4\n", "1\n2 3\n", "3\n1 4\n2 3\n4 4\n" ]
[ "0\n", "-1\n", "1\n" ]
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
500
[ { "input": "2\n4 2\n6 4", "output": "0" }, { "input": "1\n2 3", "output": "-1" }, { "input": "3\n1 4\n2 3\n4 4", "output": "1" }, { "input": "5\n5 4\n5 4\n1 5\n5 5\n3 3", "output": "1" }, { "input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n6 2\n4 3\n2 1\n6 2\n6 5\n4 5\n2 4\n1 4", "output": "-1" }, { "input": "100\n2 3\n2 4\n3 3\n1 4\n5 2\n5 4\n6 6\n3 4\n1 1\n4 2\n5 1\n5 5\n5 3\n3 6\n4 1\n1 6\n1 1\n3 2\n4 5\n6 1\n6 4\n1 1\n3 4\n3 3\n2 2\n1 1\n4 4\n6 4\n3 2\n5 2\n6 4\n3 2\n3 5\n4 4\n1 4\n5 2\n3 4\n1 4\n2 2\n5 6\n3 5\n6 1\n5 5\n1 6\n6 3\n1 4\n1 5\n5 5\n4 1\n3 2\n4 1\n5 5\n5 5\n1 5\n1 2\n6 4\n1 3\n3 6\n4 3\n3 5\n6 4\n2 6\n5 5\n1 4\n2 2\n2 3\n5 1\n2 5\n1 2\n2 6\n5 5\n4 6\n1 4\n3 6\n2 3\n6 1\n6 5\n3 2\n6 4\n4 5\n4 5\n2 6\n1 3\n6 2\n1 2\n2 3\n4 3\n5 4\n3 4\n1 6\n6 6\n2 4\n4 1\n3 1\n2 6\n5 4\n1 2\n6 5\n3 6\n2 4", "output": "-1" }, { "input": "1\n2 4", "output": "0" }, { "input": "1\n1 1", "output": "-1" }, { "input": "1\n1 2", "output": "-1" }, { "input": "2\n1 1\n3 3", "output": "0" }, { "input": "2\n1 1\n2 2", "output": "-1" }, { "input": "2\n1 1\n1 2", "output": "-1" }, { "input": "5\n1 2\n6 6\n1 1\n3 3\n6 1", "output": "1" }, { "input": "5\n5 4\n2 6\n6 2\n1 4\n6 2", "output": "0" }, { "input": "10\n4 1\n3 2\n1 2\n2 6\n3 5\n2 1\n5 2\n4 6\n5 6\n3 1", "output": "0" }, { "input": "10\n6 1\n4 4\n2 6\n6 5\n3 6\n6 3\n2 4\n5 1\n1 6\n1 5", "output": "-1" }, { "input": "15\n1 2\n5 1\n6 4\n5 1\n1 6\n2 6\n3 1\n6 4\n3 1\n2 1\n6 4\n3 5\n6 2\n1 6\n1 1", "output": "1" }, { "input": "15\n3 3\n2 1\n5 4\n3 3\n5 3\n5 4\n2 5\n1 3\n3 2\n3 3\n3 5\n2 5\n4 1\n2 3\n5 4", "output": "-1" }, { "input": "20\n1 5\n6 4\n4 3\n6 2\n1 1\n1 5\n6 3\n2 3\n3 6\n3 6\n3 6\n2 5\n4 3\n4 6\n5 5\n4 6\n3 4\n4 2\n3 3\n5 2", "output": "0" }, { "input": "20\n2 1\n6 5\n3 1\n2 5\n3 5\n4 1\n1 1\n5 4\n5 1\n2 4\n1 5\n3 2\n1 2\n3 5\n5 2\n1 2\n1 3\n4 2\n2 3\n4 5", "output": "-1" }, { "input": "25\n4 1\n6 3\n1 3\n2 3\n2 4\n6 6\n4 2\n4 2\n1 5\n5 4\n1 2\n2 5\n3 6\n4 1\n3 4\n2 6\n6 1\n5 6\n6 6\n4 2\n1 5\n3 3\n3 3\n6 5\n1 4", "output": "-1" }, { "input": "25\n5 5\n4 3\n2 5\n4 3\n4 6\n4 2\n5 6\n2 1\n5 4\n6 6\n1 3\n1 4\n2 3\n5 6\n5 4\n5 6\n5 4\n6 3\n3 5\n1 3\n2 5\n2 2\n4 4\n2 1\n4 4", "output": "-1" }, { "input": "30\n3 5\n2 5\n1 6\n1 6\n2 4\n5 5\n5 4\n5 6\n5 4\n2 1\n2 4\n1 6\n3 5\n1 1\n3 6\n5 5\n1 6\n3 4\n1 4\n4 6\n2 1\n3 3\n1 3\n4 5\n1 4\n1 6\n2 1\n4 6\n3 5\n5 6", "output": "1" }, { "input": "30\n2 3\n3 1\n6 6\n1 3\n5 5\n3 6\n4 5\n2 1\n1 3\n2 3\n4 4\n2 4\n6 4\n2 4\n5 4\n2 1\n2 5\n2 5\n4 2\n1 4\n2 6\n3 2\n3 2\n6 6\n4 2\n3 4\n6 3\n6 6\n6 6\n5 5", "output": "1" }, { "input": "35\n6 1\n4 3\n1 2\n4 3\n6 4\n4 6\n3 1\n5 5\n3 4\n5 4\n4 6\n1 6\n2 4\n6 6\n5 4\n5 2\n1 3\n1 4\n3 5\n1 4\n2 3\n4 5\n4 3\n6 1\n5 3\n3 2\n5 6\n3 5\n6 5\n4 1\n1 3\n5 5\n4 6\n6 1\n1 3", "output": "1" }, { "input": "35\n4 3\n5 6\n4 5\n2 5\n6 6\n4 1\n2 2\n4 2\n3 4\n4 1\n6 6\n6 3\n1 5\n1 5\n5 6\n4 2\n4 6\n5 5\n2 2\n5 2\n1 2\n4 6\n6 6\n6 5\n2 1\n3 5\n2 5\n3 1\n5 3\n6 4\n4 6\n5 6\n5 1\n3 4\n3 5", "output": "1" }, { "input": "40\n5 6\n1 1\n3 3\n2 6\n6 6\n5 4\n6 4\n3 5\n1 3\n4 4\n4 4\n2 5\n1 3\n3 6\n5 2\n4 3\n4 4\n5 6\n2 3\n1 1\n3 1\n1 1\n1 5\n4 3\n5 5\n3 4\n6 6\n5 6\n2 2\n6 6\n2 1\n2 4\n5 2\n2 2\n1 1\n1 4\n4 2\n3 5\n5 5\n4 5", "output": "-1" }, { "input": "40\n3 2\n5 3\n4 6\n3 5\n6 1\n5 2\n1 2\n6 2\n5 3\n3 2\n4 4\n3 3\n5 2\n4 5\n1 4\n5 1\n3 3\n1 3\n1 3\n2 1\n3 6\n4 2\n4 6\n6 2\n2 5\n2 2\n2 5\n3 3\n5 3\n2 1\n3 2\n2 3\n6 3\n6 3\n3 4\n3 2\n4 3\n5 4\n2 4\n4 6", "output": "-1" }, { "input": "45\n2 4\n3 4\n6 1\n5 5\n1 1\n3 5\n4 3\n5 2\n3 6\n6 1\n4 4\n6 1\n2 1\n6 1\n3 6\n3 3\n6 1\n1 2\n1 5\n6 5\n1 3\n5 6\n6 1\n4 5\n3 6\n2 2\n1 2\n4 5\n5 6\n1 5\n6 2\n2 4\n3 3\n3 1\n6 5\n6 5\n2 1\n5 2\n2 1\n3 3\n2 2\n1 4\n2 2\n3 3\n2 1", "output": "-1" }, { "input": "45\n6 6\n1 6\n1 2\n3 5\n4 4\n2 1\n5 3\n2 1\n5 2\n5 3\n1 4\n5 2\n4 2\n3 6\n5 2\n1 5\n4 4\n5 5\n6 5\n2 1\n2 6\n5 5\n2 1\n6 1\n1 6\n6 5\n2 4\n4 3\n2 6\n2 4\n6 5\n6 4\n6 3\n6 6\n2 1\n6 4\n5 6\n5 4\n1 5\n5 1\n3 3\n5 6\n2 5\n4 5\n3 6", "output": "-1" }, { "input": "50\n4 4\n5 1\n6 4\n6 2\n6 2\n1 4\n5 5\n4 2\n5 5\n5 4\n1 3\n3 5\n6 1\n6 1\n1 4\n4 3\n5 1\n3 6\n2 2\n6 2\n4 4\n2 3\n4 2\n6 5\n5 6\n2 2\n2 4\n3 5\n1 5\n3 2\n3 4\n5 6\n4 6\n1 6\n4 5\n2 6\n2 2\n3 5\n6 4\n5 1\n4 3\n3 4\n3 5\n3 3\n2 3\n3 2\n2 2\n1 4\n3 1\n4 4", "output": "1" }, { "input": "50\n1 2\n1 4\n1 1\n4 5\n4 4\n3 2\n4 5\n3 5\n1 1\n3 4\n3 2\n2 4\n2 6\n2 6\n3 2\n4 6\n1 6\n3 1\n1 6\n2 1\n4 1\n1 6\n4 3\n6 6\n5 2\n6 4\n2 1\n4 3\n6 4\n5 1\n5 5\n3 1\n1 1\n5 5\n2 2\n2 3\n2 3\n3 5\n5 5\n1 6\n1 5\n3 6\n3 6\n1 1\n3 3\n2 6\n5 5\n1 3\n6 3\n6 6", "output": "-1" }, { "input": "55\n3 2\n5 6\n5 1\n3 5\n5 5\n1 5\n5 4\n6 3\n5 6\n4 2\n3 1\n1 2\n5 5\n1 1\n5 2\n6 3\n5 4\n3 6\n4 6\n2 6\n6 4\n1 4\n1 6\n4 1\n2 5\n4 3\n2 1\n2 1\n6 2\n3 1\n2 5\n4 4\n6 3\n2 2\n3 5\n5 1\n3 6\n5 4\n4 6\n6 5\n5 6\n2 2\n3 2\n5 2\n6 5\n2 2\n5 3\n3 1\n4 5\n6 4\n2 4\n1 2\n5 6\n2 6\n5 2", "output": "0" }, { "input": "55\n4 6\n3 3\n6 5\n5 3\n5 6\n2 3\n2 2\n3 4\n3 1\n5 4\n5 4\n2 4\n3 4\n4 5\n1 5\n6 3\n1 1\n5 1\n3 4\n1 5\n3 1\n2 5\n3 3\n4 3\n3 3\n3 1\n6 6\n3 3\n3 3\n5 6\n5 3\n3 5\n1 4\n5 5\n1 3\n1 4\n3 5\n3 6\n2 4\n2 4\n5 1\n6 4\n5 1\n5 5\n1 1\n3 2\n4 3\n5 4\n5 1\n2 4\n4 3\n6 1\n3 4\n1 5\n6 3", "output": "-1" }, { "input": "60\n2 6\n1 4\n3 2\n1 2\n3 2\n2 4\n6 4\n4 6\n1 3\n3 1\n6 5\n2 4\n5 4\n4 2\n1 6\n3 4\n4 5\n5 2\n1 5\n5 4\n3 4\n3 4\n4 4\n4 1\n6 6\n3 6\n2 4\n2 1\n4 4\n6 5\n3 1\n4 3\n1 3\n6 3\n5 5\n1 4\n3 1\n3 6\n1 5\n3 1\n1 5\n4 4\n1 3\n2 4\n6 2\n4 1\n5 3\n3 4\n5 6\n1 2\n1 6\n6 3\n1 6\n3 6\n3 4\n6 2\n4 6\n2 3\n3 3\n3 3", "output": "-1" }, { "input": "60\n2 3\n4 6\n2 4\n1 3\n5 6\n1 5\n1 2\n1 3\n5 6\n4 3\n4 2\n3 1\n1 3\n3 5\n1 5\n3 4\n2 4\n3 5\n4 5\n1 2\n3 1\n1 5\n2 5\n6 2\n1 6\n3 3\n6 2\n5 3\n1 3\n1 4\n6 4\n6 3\n4 2\n4 2\n1 4\n1 3\n3 2\n3 1\n2 1\n1 2\n3 1\n2 6\n1 4\n3 6\n3 3\n1 5\n2 4\n5 5\n6 2\n5 2\n3 3\n5 3\n3 4\n4 5\n5 6\n2 4\n5 3\n3 1\n2 4\n5 4", "output": "-1" }, { "input": "65\n5 4\n3 3\n1 2\n4 3\n3 5\n1 5\n4 5\n2 6\n1 2\n1 5\n6 3\n2 6\n4 3\n3 6\n1 5\n3 5\n4 6\n2 5\n6 5\n1 4\n3 4\n4 3\n1 4\n2 5\n6 5\n3 1\n4 3\n1 2\n1 1\n6 1\n5 2\n3 2\n1 6\n2 6\n3 3\n6 6\n4 6\n1 5\n5 1\n4 5\n1 4\n3 2\n5 4\n4 2\n6 2\n1 3\n4 2\n5 3\n6 4\n3 6\n1 2\n6 1\n6 6\n3 3\n4 2\n3 5\n4 6\n4 1\n5 4\n6 1\n5 1\n5 6\n6 1\n4 6\n5 5", "output": "1" }, { "input": "65\n5 4\n6 3\n5 4\n4 5\n5 3\n3 6\n1 3\n3 1\n1 3\n6 1\n6 4\n1 3\n2 2\n4 6\n4 1\n5 6\n6 5\n1 1\n1 3\n6 6\n4 1\n2 4\n5 4\n4 1\n5 5\n5 3\n6 2\n2 6\n4 2\n2 2\n6 2\n3 3\n4 5\n4 3\n3 1\n1 4\n4 5\n3 2\n5 5\n4 6\n5 1\n3 4\n5 4\n5 2\n1 6\n4 2\n3 4\n3 4\n1 3\n1 2\n3 3\n3 6\n6 4\n4 6\n6 2\n6 5\n3 2\n2 1\n6 4\n2 1\n1 5\n5 2\n6 5\n3 6\n5 1", "output": "1" }, { "input": "70\n4 1\n2 6\n1 1\n5 6\n5 1\n2 3\n3 5\n1 1\n1 1\n4 6\n4 3\n1 5\n2 2\n2 3\n3 1\n6 4\n3 1\n4 2\n5 4\n1 3\n3 5\n5 2\n5 6\n4 4\n4 5\n2 2\n4 5\n3 2\n3 5\n2 5\n2 6\n5 5\n2 6\n5 1\n1 1\n2 5\n3 1\n1 2\n6 4\n6 5\n5 5\n5 1\n1 5\n2 2\n6 3\n4 3\n6 2\n5 5\n1 1\n6 2\n6 6\n3 4\n2 2\n3 5\n1 5\n2 5\n4 5\n2 4\n6 3\n5 1\n2 6\n4 2\n1 4\n1 6\n6 2\n5 2\n5 6\n2 5\n5 6\n5 5", "output": "-1" }, { "input": "70\n4 3\n6 4\n5 5\n3 1\n1 2\n2 5\n4 6\n4 2\n3 2\n4 2\n1 5\n2 2\n4 3\n1 2\n6 1\n6 6\n1 6\n5 1\n2 2\n6 3\n4 2\n4 3\n1 2\n6 6\n3 3\n6 5\n6 2\n3 6\n6 6\n4 6\n5 2\n5 4\n3 3\n1 6\n5 6\n2 3\n4 6\n1 1\n1 2\n6 6\n1 1\n3 4\n1 6\n2 6\n3 4\n6 3\n5 3\n1 2\n2 3\n4 6\n2 1\n6 4\n4 6\n4 6\n4 2\n5 5\n3 5\n3 2\n4 3\n3 6\n1 4\n3 6\n1 4\n1 6\n1 5\n5 6\n4 4\n3 3\n3 5\n2 2", "output": "0" }, { "input": "75\n1 3\n4 5\n4 1\n6 5\n2 1\n1 4\n5 4\n1 5\n5 3\n1 2\n4 1\n1 1\n5 1\n5 3\n1 5\n4 2\n2 2\n6 3\n1 2\n4 3\n2 5\n5 3\n5 5\n4 1\n4 6\n2 5\n6 1\n2 4\n6 4\n5 2\n6 2\n2 4\n1 3\n5 4\n6 5\n5 4\n6 4\n1 5\n4 6\n1 5\n1 1\n4 4\n3 5\n6 3\n6 5\n1 5\n2 1\n1 5\n6 6\n2 2\n2 2\n4 4\n6 6\n5 4\n4 5\n3 2\n2 4\n1 1\n4 3\n3 2\n5 4\n1 6\n1 2\n2 2\n3 5\n2 6\n1 1\n2 2\n2 3\n6 2\n3 6\n4 4\n5 1\n4 1\n4 1", "output": "0" }, { "input": "75\n1 1\n2 1\n5 5\n6 5\n6 3\n1 6\n6 1\n4 4\n2 1\n6 2\n3 1\n6 4\n1 6\n2 2\n4 3\n4 2\n1 2\n6 2\n4 2\n5 1\n1 2\n3 2\n6 6\n6 3\n2 4\n4 1\n4 1\n2 4\n5 5\n2 3\n5 5\n4 5\n3 1\n1 5\n4 3\n2 3\n3 5\n4 6\n5 6\n1 6\n2 3\n2 2\n1 2\n5 6\n1 4\n1 5\n1 3\n6 2\n1 2\n4 2\n2 1\n1 3\n6 4\n4 1\n5 2\n6 2\n3 5\n2 3\n4 2\n5 1\n5 6\n3 2\n2 1\n6 6\n2 1\n6 2\n1 1\n3 2\n1 2\n3 5\n4 6\n1 3\n3 4\n5 5\n6 2", "output": "1" }, { "input": "80\n3 1\n6 3\n2 2\n2 2\n6 3\n6 1\n6 5\n1 4\n3 6\n6 5\n1 3\n2 4\n1 4\n3 1\n5 3\n5 3\n1 4\n2 5\n4 3\n4 4\n4 5\n6 1\n3 1\n2 6\n4 2\n3 1\n6 5\n2 6\n2 2\n5 1\n1 3\n5 1\n2 1\n4 3\n6 3\n3 5\n4 3\n5 6\n3 3\n4 1\n5 1\n6 5\n5 1\n2 5\n6 1\n3 2\n4 3\n3 3\n5 6\n1 6\n5 2\n1 5\n5 6\n6 4\n2 2\n4 2\n4 6\n4 2\n4 4\n6 5\n5 2\n6 2\n4 6\n6 4\n4 3\n5 1\n4 1\n3 5\n3 2\n3 2\n5 3\n5 4\n3 4\n1 3\n1 2\n6 6\n6 3\n6 1\n5 6\n3 2", "output": "0" }, { "input": "80\n4 5\n3 3\n3 6\n4 5\n3 4\n6 5\n1 5\n2 5\n5 6\n5 1\n5 1\n1 2\n5 5\n5 1\n2 3\n1 1\n4 5\n4 1\n1 1\n5 5\n5 6\n5 2\n5 4\n4 2\n6 2\n5 3\n3 2\n4 2\n1 3\n1 6\n2 1\n6 6\n4 5\n6 4\n2 2\n1 6\n6 2\n4 3\n2 3\n4 6\n4 6\n6 2\n3 4\n4 3\n5 5\n1 6\n3 2\n4 6\n2 3\n1 6\n5 4\n4 2\n5 4\n1 1\n4 3\n5 1\n3 6\n6 2\n3 1\n4 1\n5 3\n2 2\n3 4\n3 6\n3 5\n5 5\n5 1\n3 5\n2 6\n6 3\n6 5\n3 3\n5 6\n1 2\n3 1\n6 3\n3 4\n6 6\n6 6\n1 2", "output": "-1" }, { "input": "85\n6 3\n4 1\n1 2\n3 5\n6 4\n6 2\n2 6\n1 2\n1 5\n6 2\n1 4\n6 6\n2 4\n4 6\n4 5\n1 6\n3 1\n2 5\n5 1\n5 2\n3 5\n1 1\n4 1\n2 3\n1 1\n3 3\n6 4\n1 4\n1 1\n3 6\n1 5\n1 6\n2 5\n2 2\n5 1\n6 6\n1 3\n1 5\n5 6\n4 5\n4 3\n5 5\n1 3\n6 3\n4 6\n2 4\n5 6\n6 2\n4 5\n1 4\n1 4\n6 5\n1 6\n6 1\n1 6\n5 5\n2 1\n5 2\n2 3\n1 6\n1 6\n1 6\n5 6\n2 4\n6 5\n6 5\n4 2\n5 4\n3 4\n4 3\n6 6\n3 3\n3 2\n3 6\n2 5\n2 1\n2 5\n3 4\n1 2\n5 4\n6 2\n5 1\n1 4\n3 4\n4 5", "output": "0" }, { "input": "85\n3 1\n3 2\n6 3\n1 3\n2 1\n3 6\n1 4\n2 5\n6 5\n1 6\n1 5\n1 1\n4 3\n3 5\n4 6\n3 2\n6 6\n4 4\n4 1\n5 5\n4 2\n6 2\n2 2\n4 5\n6 1\n3 4\n4 5\n3 5\n4 2\n3 5\n4 4\n3 1\n4 4\n6 4\n1 4\n5 5\n1 5\n2 2\n6 5\n5 6\n6 5\n3 2\n3 2\n6 1\n6 5\n2 1\n4 6\n2 1\n3 1\n5 6\n1 3\n5 4\n1 4\n1 4\n5 3\n2 3\n1 3\n2 2\n5 3\n2 3\n2 3\n1 3\n3 6\n4 4\n6 6\n6 2\n5 1\n5 5\n5 5\n1 2\n1 4\n2 4\n3 6\n4 6\n6 3\n6 4\n5 5\n3 2\n5 4\n5 4\n4 5\n6 4\n2 1\n5 2\n5 1", "output": "-1" }, { "input": "90\n5 2\n5 5\n5 1\n4 6\n4 3\n5 3\n5 6\n5 1\n3 4\n1 3\n4 2\n1 6\n6 4\n1 2\n6 1\n4 1\n6 2\n6 5\n6 2\n5 4\n3 6\n1 1\n5 5\n2 2\n1 6\n3 5\n6 5\n1 6\n1 5\n2 3\n2 6\n2 3\n3 3\n1 3\n5 1\n2 5\n3 6\n1 2\n4 4\n1 6\n2 3\n1 5\n2 5\n1 3\n2 2\n4 6\n3 6\n6 3\n1 2\n4 3\n4 5\n4 6\n3 2\n6 5\n6 2\n2 5\n2 4\n1 3\n1 6\n4 3\n1 3\n6 4\n4 6\n4 1\n1 1\n4 1\n4 4\n6 2\n6 5\n1 1\n2 2\n3 1\n1 4\n6 2\n5 2\n1 4\n1 3\n6 5\n3 2\n6 4\n3 4\n2 6\n2 2\n6 3\n4 6\n1 2\n4 2\n3 4\n2 3\n1 5", "output": "-1" }, { "input": "90\n1 4\n3 5\n4 2\n2 5\n4 3\n2 6\n2 6\n3 2\n4 4\n6 1\n4 3\n2 3\n5 3\n6 6\n2 2\n6 3\n4 1\n4 4\n5 6\n6 4\n4 2\n5 6\n4 6\n4 4\n6 4\n4 1\n5 3\n3 2\n4 4\n5 2\n5 4\n6 4\n1 2\n3 3\n3 4\n6 4\n1 6\n4 2\n3 2\n1 1\n2 2\n5 1\n6 6\n4 1\n5 2\n3 6\n2 1\n2 2\n4 6\n6 5\n4 4\n5 5\n5 6\n1 6\n1 4\n5 6\n3 6\n6 3\n5 6\n6 5\n5 1\n6 1\n6 6\n6 3\n1 5\n4 5\n3 1\n6 6\n3 4\n6 2\n1 4\n2 2\n3 2\n5 6\n2 4\n1 4\n6 3\n4 6\n1 4\n5 2\n1 2\n6 5\n1 5\n1 4\n4 2\n2 5\n3 2\n5 1\n5 4\n5 3", "output": "-1" }, { "input": "95\n4 3\n3 2\n5 5\n5 3\n1 6\n4 4\n5 5\n6 5\n3 5\n1 5\n4 2\n5 1\n1 2\n2 3\n6 4\n2 3\n6 3\n6 5\n5 6\n1 4\n2 6\n2 6\n2 5\n2 1\n3 1\n3 5\n2 2\n6 1\n2 4\n4 6\n6 6\n6 4\n3 2\n5 1\n4 3\n6 5\n2 3\n4 1\n2 5\n6 5\n6 5\n6 5\n5 1\n5 4\n4 6\n3 2\n2 5\n2 6\n4 6\n6 3\n6 4\n5 6\n4 6\n2 4\n3 4\n1 4\n2 4\n2 3\n5 6\n6 4\n3 1\n5 1\n3 6\n3 5\n2 6\n6 3\n4 3\n3 1\n6 1\n2 2\n6 3\n2 2\n2 2\n6 4\n6 1\n2 1\n5 6\n5 4\n5 2\n3 4\n3 6\n2 1\n1 6\n5 5\n2 6\n2 3\n3 6\n1 3\n1 5\n5 1\n1 2\n2 2\n5 3\n6 4\n4 5", "output": "0" }, { "input": "95\n4 5\n5 6\n3 2\n5 1\n4 3\n4 1\n6 1\n5 2\n2 4\n5 3\n2 3\n6 4\n4 1\n1 6\n2 6\n2 3\n4 6\n2 4\n3 4\n4 2\n5 5\n1 1\n1 5\n4 3\n4 5\n6 2\n6 1\n6 3\n5 5\n4 1\n5 1\n2 3\n5 1\n3 6\n6 6\n4 5\n4 4\n4 3\n1 6\n6 6\n4 6\n6 4\n1 2\n6 2\n4 6\n6 6\n5 5\n6 1\n5 2\n4 5\n6 6\n6 5\n4 4\n1 5\n4 6\n4 1\n3 6\n5 1\n3 1\n4 6\n4 5\n1 3\n5 4\n4 5\n2 2\n6 1\n5 2\n6 5\n2 2\n1 1\n6 3\n6 1\n2 6\n3 3\n2 1\n4 6\n2 4\n5 5\n5 2\n3 2\n1 2\n6 6\n6 2\n5 1\n2 6\n5 2\n2 2\n5 5\n3 5\n3 3\n2 6\n5 3\n4 3\n1 6\n5 4", "output": "-1" }, { "input": "100\n1 1\n3 5\n2 1\n1 2\n3 4\n5 6\n5 6\n6 1\n5 5\n2 4\n5 5\n5 6\n6 2\n6 6\n2 6\n1 4\n2 2\n3 2\n1 3\n5 5\n6 3\n5 6\n1 1\n1 2\n1 2\n2 1\n2 3\n1 6\n4 3\n1 1\n2 5\n2 4\n4 4\n1 5\n3 3\n6 1\n3 5\n1 1\n3 6\n3 1\n4 2\n4 3\n3 6\n6 6\n1 6\n6 2\n2 5\n5 4\n6 3\n1 4\n2 6\n6 2\n3 4\n6 1\n6 5\n4 6\n6 5\n4 4\n3 1\n6 3\n5 1\n2 4\n5 1\n1 2\n2 4\n2 1\n6 6\n5 3\n4 6\n6 3\n5 5\n3 3\n1 1\n6 5\n4 3\n2 6\n1 5\n3 5\n2 4\n4 5\n1 6\n2 3\n6 3\n5 5\n2 6\n2 6\n3 4\n3 2\n6 1\n3 4\n6 4\n3 3\n2 3\n5 1\n3 1\n6 2\n2 3\n6 4\n1 4\n1 2", "output": "-1" }, { "input": "100\n1 1\n5 5\n1 2\n5 3\n5 5\n2 2\n1 5\n3 4\n3 2\n1 3\n5 6\n4 5\n2 1\n5 5\n2 2\n1 6\n6 1\n5 1\n4 1\n4 6\n3 5\n6 1\n2 3\n5 6\n3 6\n2 3\n5 6\n1 6\n3 2\n2 2\n3 3\n6 5\n5 5\n1 4\n5 6\n6 4\n1 4\n1 2\n2 6\n3 2\n6 4\n5 3\n3 3\n6 4\n4 6\n2 2\n5 6\n5 1\n1 2\n3 4\n4 5\n1 1\n3 4\n5 2\n4 5\n3 3\n1 1\n3 4\n1 6\n2 4\n1 3\n3 2\n6 5\n1 6\n3 6\n2 3\n2 6\n5 1\n5 5\n5 6\n4 1\n6 2\n3 6\n5 3\n2 2\n2 4\n6 6\n3 6\n4 6\n2 5\n5 3\n1 2\n3 4\n3 4\n6 2\n2 4\n2 2\n4 6\n3 5\n4 2\n5 6\n4 2\n2 3\n6 2\n5 6\n2 1\n3 3\n6 6\n4 3\n4 2", "output": "1" }, { "input": "1\n2 2", "output": "0" }, { "input": "3\n2 4\n6 6\n3 3", "output": "-1" }, { "input": "2\n3 6\n4 1", "output": "1" }, { "input": "3\n1 1\n1 1\n3 3", "output": "-1" }, { "input": "3\n2 3\n1 1\n2 3", "output": "1" }, { "input": "3\n2 2\n2 1\n1 2", "output": "1" }, { "input": "3\n1 1\n1 1\n1 1", "output": "-1" } ]
1,381,420,307
1,307
Python 3
WRONG_ANSWER
PRETESTS
3
92
0
n = int(input()) count = 0 res = [0, 0] for i in range(n): a, b = map(int, input().split()) if (res[0] + a) % 2 == 0 and (res[1] + b) % 2 == 0: res[0] == 0 res[1] == 0 elif (res[0] + b) % 2 == 0 and (res[1] + a) % 2 == 0: res[0], res[1] = 0, 0 count += 1 else: if res[0] == 1 and a % 2 == 1 or res[1] == 1 and b % 2 == 1: res[0], res[1] = (res[0] + a) % 2, (res[1] + b) % 2 elif res[0] == 1 and b % 2 == 1 or res[1] == 1 and a % 2 == 1: res[0], res[1] = (res[0] + b) % 2, (res[1] + a) % 2 count += 1 else: res[0], res[1] = (res[0] + a) % 2, (res[1] + b) % 2 if res[0] == res[1] == 0: print(count) else: print(-1)
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half. Output Specification: Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. Demo Input: ['2\n4 2\n6 4\n', '1\n2 3\n', '3\n1 4\n2 3\n4 4\n'] Demo Output: ['0\n', '-1\n', '1\n'] Note: In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
```python n = int(input()) count = 0 res = [0, 0] for i in range(n): a, b = map(int, input().split()) if (res[0] + a) % 2 == 0 and (res[1] + b) % 2 == 0: res[0] == 0 res[1] == 0 elif (res[0] + b) % 2 == 0 and (res[1] + a) % 2 == 0: res[0], res[1] = 0, 0 count += 1 else: if res[0] == 1 and a % 2 == 1 or res[1] == 1 and b % 2 == 1: res[0], res[1] = (res[0] + a) % 2, (res[1] + b) % 2 elif res[0] == 1 and b % 2 == 1 or res[1] == 1 and a % 2 == 1: res[0], res[1] = (res[0] + b) % 2, (res[1] + a) % 2 count += 1 else: res[0], res[1] = (res[0] + a) % 2, (res[1] + b) % 2 if res[0] == res[1] == 0: print(count) else: print(-1) ```
0
1,004
C
Sonya and Robots
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position. Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one. For example, if the numbers $[1, 5, 4, 1, 3]$ are written, and Sonya gives the number $1$ to the first robot and the number $4$ to the second one, the first robot will stop in the $1$-st position while the second one in the $3$-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $4$ to the first robot and the number $5$ to the second one, they will meet since the first robot will stop in the $3$-rd position while the second one is in the $2$-nd position. Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot. Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ($p$, $q$), where she will give $p$ to the first robot and $q$ to the second one. Pairs ($p_i$, $q_i$) and ($p_j$, $q_j$) are different if $p_i\neq p_j$ or $q_i\neq q_j$. Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row.
Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.
[ "5\n1 5 4 1 3\n", "7\n1 2 1 1 1 3 2\n" ]
[ "9\n", "7\n" ]
In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$). In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$).
1,500
[ { "input": "5\n1 5 4 1 3", "output": "9" }, { "input": "7\n1 2 1 1 1 3 2", "output": "7" }, { "input": "10\n2 2 4 4 3 1 1 2 3 2", "output": "14" }, { "input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4", "output": "20" }, { "input": "1\n1", "output": "0" } ]
1,642,656,651
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
n=int(input()) a=list(map(int,input().split())) d={} for i in range(n): for j in range(i+1,n): d[i]=[a[i],a[j]] print(len(d))
Title: Sonya and Robots Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position. Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one. For example, if the numbers $[1, 5, 4, 1, 3]$ are written, and Sonya gives the number $1$ to the first robot and the number $4$ to the second one, the first robot will stop in the $1$-st position while the second one in the $3$-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $4$ to the first robot and the number $5$ to the second one, they will meet since the first robot will stop in the $3$-rd position while the second one is in the $2$-nd position. Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot. Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ($p$, $q$), where she will give $p$ to the first robot and $q$ to the second one. Pairs ($p_i$, $q_i$) and ($p_j$, $q_j$) are different if $p_i\neq p_j$ or $q_i\neq q_j$. Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet. Input Specification: The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row. Output Specification: Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet. Demo Input: ['5\n1 5 4 1 3\n', '7\n1 2 1 1 1 3 2\n'] Demo Output: ['9\n', '7\n'] Note: In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$). In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$).
```python n=int(input()) a=list(map(int,input().split())) d={} for i in range(n): for j in range(i+1,n): d[i]=[a[i],a[j]] print(len(d)) ```
0
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "output": "13" }, { "input": "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "output": "3" }, { "input": "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190", "output": "31" }, { "input": "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997", "output": "0" }, { "input": "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176", "output": "412" }, { "input": "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886", "output": "938" }, { "input": "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993", "output": "937" }, { "input": "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7", "output": "0" }, { "input": "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19", "output": "12" }, { "input": "40 50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "0" }, { "input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17", "output": "31" }, { "input": "2 2\n1000 4", "output": "996" }, { "input": "2 3\n4 502 1000", "output": "498" }, { "input": "3 3\n4 1000 4", "output": "996" } ]
1,679,841,440
2,147,483,647
PyPy 3
OK
TESTS
18
184
0
import math n,m=map(int,input().split()) a=sorted([int(x) for x in input().split()]) best=math.inf for i in range(m): if n+i-1>=m:break best=min(best,a[n+i-1]-a[i]) print(best)
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. Input Specification: The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. Output Specification: Print a single integer — the least possible difference the teacher can obtain. Demo Input: ['4 6\n10 12 10 7 5 22\n'] Demo Output: ['5\n'] Note: Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
```python import math n,m=map(int,input().split()) a=sorted([int(x) for x in input().split()]) best=math.inf for i in range(m): if n+i-1>=m:break best=min(best,a[n+i-1]-a[i]) print(best) ```
3
748
A
Santa Claus and a Place in a Class
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!
The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
[ "4 3 9\n", "4 3 24\n", "2 4 4\n" ]
[ "2 2 L\n", "4 3 R\n", "1 2 R\n" ]
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
500
[ { "input": "4 3 9", "output": "2 2 L" }, { "input": "4 3 24", "output": "4 3 R" }, { "input": "2 4 4", "output": "1 2 R" }, { "input": "3 10 24", "output": "2 2 R" }, { "input": "10 3 59", "output": "10 3 L" }, { "input": "10000 10000 160845880", "output": "8043 2940 R" }, { "input": "1 1 1", "output": "1 1 L" }, { "input": "1 1 2", "output": "1 1 R" }, { "input": "1 10000 1", "output": "1 1 L" }, { "input": "1 10000 20000", "output": "1 10000 R" }, { "input": "10000 1 1", "output": "1 1 L" }, { "input": "10000 1 10000", "output": "5000 1 R" }, { "input": "10000 1 20000", "output": "10000 1 R" }, { "input": "3 2 1", "output": "1 1 L" }, { "input": "3 2 2", "output": "1 1 R" }, { "input": "3 2 3", "output": "1 2 L" }, { "input": "3 2 4", "output": "1 2 R" }, { "input": "3 2 5", "output": "2 1 L" }, { "input": "3 2 6", "output": "2 1 R" }, { "input": "3 2 7", "output": "2 2 L" }, { "input": "3 2 8", "output": "2 2 R" }, { "input": "3 2 9", "output": "3 1 L" }, { "input": "3 2 10", "output": "3 1 R" }, { "input": "3 2 11", "output": "3 2 L" }, { "input": "3 2 12", "output": "3 2 R" }, { "input": "300 2000 1068628", "output": "268 314 R" }, { "input": "300 2000 584756", "output": "147 378 R" }, { "input": "300 2000 268181", "output": "68 91 L" }, { "input": "10000 9999 186450844", "output": "9324 4745 R" }, { "input": "10000 9999 197114268", "output": "9857 6990 R" }, { "input": "10000 9999 112390396", "output": "5621 818 R" }, { "input": "10000 10000 1", "output": "1 1 L" }, { "input": "10000 10000 2", "output": "1 1 R" }, { "input": "10000 10000 100000001", "output": "5001 1 L" }, { "input": "10000 10000 199999999", "output": "10000 10000 L" }, { "input": "10000 10000 200000000", "output": "10000 10000 R" }, { "input": "1 2 1", "output": "1 1 L" }, { "input": "1 2 2", "output": "1 1 R" }, { "input": "1 2 3", "output": "1 2 L" }, { "input": "1 2 4", "output": "1 2 R" }, { "input": "2 1 1", "output": "1 1 L" }, { "input": "2 1 2", "output": "1 1 R" }, { "input": "2 1 3", "output": "2 1 L" }, { "input": "2 1 4", "output": "2 1 R" }, { "input": "4 3 7", "output": "2 1 L" }, { "input": "1 1 1", "output": "1 1 L" } ]
1,588,078,757
2,147,483,647
Python 3
OK
TESTS
46
109
307,200
import math inp1=list(map(int,input().strip().split()))[:3] r,c,val=inp1[0],inp1[1],inp1[2] divi=c*2 if(val % 2): val1=val+1 dir1='L' else: val1=val dir1='R' row=math.ceil(val1/divi) rem=val1 % divi col=rem // 2 if(rem==0): col=c print(row,col,dir1,end=" ") print()
Title: Santa Claus and a Place in a Class Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right! Input Specification: The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. Output Specification: Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. Demo Input: ['4 3 9\n', '4 3 24\n', '2 4 4\n'] Demo Output: ['2 2 L\n', '4 3 R\n', '1 2 R\n'] Note: The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
```python import math inp1=list(map(int,input().strip().split()))[:3] r,c,val=inp1[0],inp1[1],inp1[2] divi=c*2 if(val % 2): val1=val+1 dir1='L' else: val1=val dir1='R' row=math.ceil(val1/divi) rem=val1 % divi col=rem // 2 if(rem==0): col=c print(row,col,dir1,end=" ") print() ```
3
706
B
Interesting drink
PROGRAMMING
1,100
[ "binary search", "dp", "implementation" ]
null
null
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink. Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day.
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
[ "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n" ]
[ "0\n4\n1\n5\n" ]
On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
1,000
[ { "input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11", "output": "0\n4\n1\n5" }, { "input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2" }, { "input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "output": "0\n0\n3\n3\n3\n0\n3" }, { "input": "1\n653\n9\n903\n980\n80\n770\n965\n874\n381\n657\n969", "output": "1\n1\n0\n1\n1\n1\n0\n1\n1" }, { "input": "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\n55052824\n82504840\n35160556\n78141700\n73401989\n86305919\n39430705\n31939373\n23501765\n4406029\n61436920\n14295390\n34275309\n28028753\n85724689\n70158847\n2396455\n66994588\n84024224\n30175981\n65622319\n76517111\n76605341", "output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12" }, { "input": "4\n698 193 1584 76192\n4\n553640\n310518\n274280\n429192", "output": "4\n4\n4\n4" }, { "input": "1\n1\n1\n1000000000", "output": "1" }, { "input": "1\n1\n1\n100005", "output": "1" }, { "input": "3\n1 2 3\n1\n100005", "output": "3" }, { "input": "2\n1 2\n3\n100004\n100005\n100006", "output": "2\n2\n2" }, { "input": "3\n1 1 1\n1\n1", "output": "3" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "3\n1 2 3\n1\n100000", "output": "3" }, { "input": "5\n1 1 1 1 10\n2\n1\n10", "output": "4\n5" }, { "input": "5\n3 10 8 6 11\n1\n10000000", "output": "5" } ]
1,699,952,977
2,147,483,647
Python 3
OK
TESTS
103
405
21,913,600
#王铭健,工学院 2300011118 coin_list = [] result_dict = {} index = 0 n = int(input()) price_list = sorted(list(map(int, input().split()))) q = int(input()) for i in range(q): coin_list.append(int(input())) coin_list_new = sorted(coin_list) for j in range(q): for k in range(index, n): if price_list[k] <= coin_list_new[j]: index += 1 else: break result_dict[coin_list_new[j]] = index for t in range(q): print(result_dict[coin_list[t]])
Title: Interesting drink Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola". Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink. Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day. Output Specification: Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. Demo Input: ['5\n3 10 8 6 11\n4\n1\n10\n3\n11\n'] Demo Output: ['0\n4\n1\n5\n'] Note: On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
```python #王铭健,工学院 2300011118 coin_list = [] result_dict = {} index = 0 n = int(input()) price_list = sorted(list(map(int, input().split()))) q = int(input()) for i in range(q): coin_list.append(int(input())) coin_list_new = sorted(coin_list) for j in range(q): for k in range(index, n): if price_list[k] <= coin_list_new[j]: index += 1 else: break result_dict[coin_list_new[j]] = index for t in range(q): print(result_dict[coin_list[t]]) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,641,400,054
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
s=input() isup=0 islow=0 v=s.upper() q=s.lower() U=s.isupper() L=s.islower() for i in s: if (U==True): isup=isup+1 elif (L==True): islow=islow+1 if (isup>islow): print(v) elif (islow>=isup): print(q)
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python s=input() isup=0 islow=0 v=s.upper() q=s.lower() U=s.isupper() L=s.islower() for i in s: if (U==True): isup=isup+1 elif (L==True): islow=islow+1 if (isup>islow): print(v) elif (islow>=isup): print(q) ```
0
988
B
Substrings Sort
PROGRAMMING
1,100
[ "sortings", "strings" ]
null
null
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in such a way that they form $a$. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof".
The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings. The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters. Some strings might be equal.
If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes). Otherwise print "YES" (without quotes) and $n$ given strings in required order.
[ "5\na\naba\nabacaba\nba\naba\n", "5\na\nabacaba\nba\naba\nabab\n", "3\nqwerty\nqwerty\nqwerty\n" ]
[ "YES\na\nba\naba\naba\nabacaba\n", "NO\n", "YES\nqwerty\nqwerty\nqwerty\n" ]
In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".
0
[ { "input": "5\na\naba\nabacaba\nba\naba", "output": "YES\na\nba\naba\naba\nabacaba" }, { "input": "5\na\nabacaba\nba\naba\nabab", "output": "NO" }, { "input": "3\nqwerty\nqwerty\nqwerty", "output": "YES\nqwerty\nqwerty\nqwerty" }, { "input": "1\nwronganswer", "output": "YES\nwronganswer" }, { "input": "3\na\nb\nab", "output": "NO" }, { "input": "2\nababaab\nabaab", "output": "YES\nabaab\nababaab" }, { "input": "2\nq\nqq", "output": "YES\nq\nqq" }, { "input": "5\nabab\nbab\nba\nab\na", "output": "NO" }, { "input": "3\nb\nc\nd", "output": "NO" }, { "input": "3\naba\nbab\nababa", "output": "NO" }, { "input": "4\na\nba\nabacabac\nb", "output": "NO" }, { "input": "4\nab\nba\nabab\na", "output": "NO" }, { "input": "3\naaa\naab\naaab", "output": "NO" }, { "input": "2\nac\nabac", "output": "YES\nac\nabac" }, { "input": "2\na\nb", "output": "NO" }, { "input": "3\nbaa\nbaaaaaaaab\naaaaaa", "output": "NO" }, { "input": "3\naaab\naab\naaaab", "output": "YES\naab\naaab\naaaab" }, { "input": "2\naaba\naba", "output": "YES\naba\naaba" }, { "input": "10\na\nb\nc\nd\nab\nbc\ncd\nabc\nbcd\nabcd", "output": "NO" }, { "input": "5\na\nab\nae\nabcd\nabcde", "output": "NO" }, { "input": "3\nv\nab\nvab", "output": "NO" }, { "input": "4\na\nb\nc\nabc", "output": "NO" }, { "input": "2\nab\naab", "output": "YES\nab\naab" }, { "input": "3\nabc\na\nc", "output": "NO" }, { "input": "2\nabaab\nababaab", "output": "YES\nabaab\nababaab" }, { "input": "3\ny\nxx\nxxy", "output": "NO" }, { "input": "4\naaaa\naaaa\naaaa\nab", "output": "NO" }, { "input": "3\nbad\naba\nabad", "output": "NO" }, { "input": "3\nabcabc\nab\nbc", "output": "NO" }, { "input": "2\naaaab\naaaaab", "output": "YES\naaaab\naaaaab" }, { "input": "5\nab\naba\naba\naba\nabd", "output": "NO" }, { "input": "4\nded\nd\ne\nd", "output": "NO" }, { "input": "5\nekgetterherforme\ner\nter\nher\ntter", "output": "NO" }, { "input": "3\naa\nbba\ncbba", "output": "NO" }, { "input": "3\nab\naa\naab", "output": "NO" }, { "input": "6\naaaa\naaaa\naaaa\naaaaab\nab\nab", "output": "NO" }, { "input": "3\na\nbcd\nabcd", "output": "NO" }, { "input": "3\naa\nab\naab", "output": "NO" }, { "input": "3\nabcde\nab\ncde", "output": "NO" }, { "input": "4\nanoop\np\nan\noop", "output": "NO" }, { "input": "3\nab\ncd\nabcd", "output": "NO" }, { "input": "3\nafaba\nafab\nfaba", "output": "NO" }, { "input": "3\nababc\nabababc\nab", "output": "YES\nab\nababc\nabababc" }, { "input": "3\na\nba\nbbab", "output": "YES\na\nba\nbbab" }, { "input": "2\naabaa\naba", "output": "YES\naba\naabaa" }, { "input": "3\nbc\nbca\na", "output": "NO" }, { "input": "2\naba\nabba", "output": "NO" }, { "input": "7\na\nb\nc\nab\nac\nac\nac", "output": "NO" }, { "input": "2\naa\nmmmmmmmammmmmmmm", "output": "NO" } ]
1,639,636,786
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
11
93
0
n = int(input()) N=n arr=[] while(n): arr.append(input()) n=n-1 arr.sort(key=len) maxS = arr[n-1] c=0 for i in arr: if(maxS.find(i) != -1): c=c+1 if(c==N): print("YES") for i in arr: print(i) else: print("NO")
Title: Substrings Sort Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in such a way that they form $a$. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof". Input Specification: The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings. The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters. Some strings might be equal. Output Specification: If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes). Otherwise print "YES" (without quotes) and $n$ given strings in required order. Demo Input: ['5\na\naba\nabacaba\nba\naba\n', '5\na\nabacaba\nba\naba\nabab\n', '3\nqwerty\nqwerty\nqwerty\n'] Demo Output: ['YES\na\nba\naba\naba\nabacaba\n', 'NO\n', 'YES\nqwerty\nqwerty\nqwerty\n'] Note: In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".
```python n = int(input()) N=n arr=[] while(n): arr.append(input()) n=n-1 arr.sort(key=len) maxS = arr[n-1] c=0 for i in arr: if(maxS.find(i) != -1): c=c+1 if(c==N): print("YES") for i in arr: print(i) else: print("NO") ```
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,259,691
2,147,483,647
Python 3
OK
TESTS
69
46
0
n = int(input()) m = 0 a = 0 for i in range(n): b,c = list(map(int,input().split())) if b > c: m += 1 if c > b: a += 1 if m > a: print("Mishka") if a > m: print("Chris") if a == m: 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()) m = 0 a = 0 for i in range(n): b,c = list(map(int,input().split())) if b > c: m += 1 if c > b: a += 1 if m > a: print("Mishka") if a > m: print("Chris") if a == m: print("Friendship is magic!^^") ```
3
701
C
They Are Everywhere
PROGRAMMING
1,500
[ "binary search", "strings", "two pointers" ]
null
null
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number *n* is only connected with the flat number *n*<=-<=1. There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once. Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house. The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*.
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
[ "3\nAaA\n", "7\nbcAAcbc\n", "6\naaBCCe\n" ]
[ "2\n", "3\n", "5\n" ]
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2. In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6. In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
1,000
[ { "input": "3\nAaA", "output": "2" }, { "input": "7\nbcAAcbc", "output": "3" }, { "input": "6\naaBCCe", "output": "5" }, { "input": "1\nA", "output": "1" }, { "input": "1\ng", "output": "1" }, { "input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "52" }, { "input": "2\nAA", "output": "1" }, { "input": "4\nqqqE", "output": "2" }, { "input": "10\nrrrrroooro", "output": "2" }, { "input": "15\nOCOCCCCiCOCCCOi", "output": "3" }, { "input": "20\nVEVnVVnWnVEVVnEVBEWn", "output": "5" }, { "input": "25\ncpcyPPjPPcPPPPcppPcPpppcP", "output": "6" }, { "input": "30\nsssssAsesssssssssssssessssssss", "output": "3" }, { "input": "35\ngdXdddgddddddddggggXdbgdggdgddddddb", "output": "4" }, { "input": "40\nIgsggIiIggzgigIIiiIIIiIgIggIzgIiiiggggIi", "output": "9" }, { "input": "45\neteeeeeteaattaeetaetteeettoetettteyeteeeotaae", "output": "9" }, { "input": "50\nlUlUllUlUllllUllllUllllUlUlllUlllUlllllUUlllUUlkUl", "output": "3" }, { "input": "55\nAAAAASAAAASAASAAAAAAAAAAAAASAAAAAAAAAAAAAAAASAAAAAAAAAA", "output": "2" }, { "input": "60\nRRRrSRRRRRRRRRSSRRRSRRRRRRRRrRSRRRRRRRRRRRRRRSRRRRRSSRSRrRRR", "output": "3" }, { "input": "65\nhhMhMhhhhhhhhhhhMhhMMMhhhhBhhhhMhhhhMhhhhhMhhhBhhhhhhhhhhBhhhhhhh", "output": "5" }, { "input": "70\nwAwwwAwwwwwwwwwwwwwwAwAAwwAwwwwwwwwAwAAAwAAwwwwwwwwwAwwwwwwwwwwwwAAwww", "output": "2" }, { "input": "75\niiiXXiiyiiiXyXiiyXiiXiiiiiiXXyiiiiXXiiXiiXifiXiXXiifiiiiiiXfXiyiXXiXiiiiXiX", "output": "4" }, { "input": "80\nSrSrrrrrrrrrrrrrrSSSrrrrrrSrrrrSrrrrrrrrrrSSrrrrrrrrrrrSrrrSrrrrSrrrrSrrrrSSrSSr", "output": "2" }, { "input": "85\nwkMMMwMMkMMMMMMMkkkkMMMMzkkMMwMMkkwMkMwkMMkMMwwMzMMMkkMwwMMMMMMkMMkMzMMMkMMkwMkMMMkMM", "output": "6" }, { "input": "90\nZllZZZyZlZlllZlylllZlllZZllllllllZZllllllllllyylZZyvZvZlllZZlZllZlZlllZyllZyZlllZlllllllZl", "output": "5" }, { "input": "95\nEmuBuEBmmEBBElBlElmmBEmmmEmmEuBEEmummmEmBBBBEWBBBmEEBmmummBBmmlluBBmElmEBEmBmBBmBmuLmEBBmlEBmBu", "output": "39" }, { "input": "100\nfAfhfNNNhfffAfNffNANhffNffffffNfffffhNfffNfffNfffNfNNNffNfffNfhNNNffffNfNfffAffNffNffNNfhfffNhNffNNN", "output": "4" }, { "input": "7\nabcbbab", "output": "3" }, { "input": "65\nkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkjjjjkkkkkkkkkkkkkkkkkkkllllllljk", "output": "3" }, { "input": "9\nbcdddbddc", "output": "3" }, { "input": "71\nlqcrdopdpfagcilpcmheqhjbmnciqmeoabflrenbkrsaabaanpehdmpqcdqnljcrsplnlco", "output": "36" }, { "input": "8\nabbbbbbc", "output": "8" } ]
1,661,361,749
2,147,483,647
PyPy 3-64
OK
TESTS
80
93
3,891,200
import sys from math import sqrt, gcd, factorial, ceil, floor, pi, inf from collections import deque, Counter, OrderedDict from heapq import heapify, heappush, heappop #sys.setrecursionlimit(10**5) #======================================================# input = lambda: sys.stdin.readline() I = lambda: int(input().strip()) S = lambda: input().strip() M = lambda: map(int,input().strip().split()) L = lambda: list(map(int,input().strip().split())) #======================================================# #======================================================# def primelist(): L = [False for i in range(10**9)] primes = [False for i in range(10**9)] for i in range(2,10**9): if not L[i]: primes[i]=True for j in range(i,10**9,i): L[j]=True return primes def isPrime(n): p = primelist() return p[n] #======================================================# def bst(arr,x): low,high = 0,len(arr)-1 ans = -1 while low<=high: mid = (low+high)//2 if arr[mid]==x: return mid elif arr[mid]<x: ans = mid low = mid+1 else: high = mid-1 return ans #======================================================# n = I() s = S() d = {} for i in s: if i not in d.keys(): d[i]=0 t=0 k=len(d) ans = inf i,j=0,0 f=False while i<n: while t<k: if j==n: f=True break d[s[j]]+=1 if d[s[j]]==1: t+=1 j+=1 if f: break ans = min(ans,j-i) i+=1 if i==n: break d[s[i-1]]-=1 if d[s[i-1]]==0: t-=1 print(ans)
Title: They Are Everywhere Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number *n* is only connected with the flat number *n*<=-<=1. There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once. Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit. Input Specification: The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house. The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*. Output Specification: Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. Demo Input: ['3\nAaA\n', '7\nbcAAcbc\n', '6\naaBCCe\n'] Demo Output: ['2\n', '3\n', '5\n'] Note: In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2. In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6. In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
```python import sys from math import sqrt, gcd, factorial, ceil, floor, pi, inf from collections import deque, Counter, OrderedDict from heapq import heapify, heappush, heappop #sys.setrecursionlimit(10**5) #======================================================# input = lambda: sys.stdin.readline() I = lambda: int(input().strip()) S = lambda: input().strip() M = lambda: map(int,input().strip().split()) L = lambda: list(map(int,input().strip().split())) #======================================================# #======================================================# def primelist(): L = [False for i in range(10**9)] primes = [False for i in range(10**9)] for i in range(2,10**9): if not L[i]: primes[i]=True for j in range(i,10**9,i): L[j]=True return primes def isPrime(n): p = primelist() return p[n] #======================================================# def bst(arr,x): low,high = 0,len(arr)-1 ans = -1 while low<=high: mid = (low+high)//2 if arr[mid]==x: return mid elif arr[mid]<x: ans = mid low = mid+1 else: high = mid-1 return ans #======================================================# n = I() s = S() d = {} for i in s: if i not in d.keys(): d[i]=0 t=0 k=len(d) ans = inf i,j=0,0 f=False while i<n: while t<k: if j==n: f=True break d[s[j]]+=1 if d[s[j]]==1: t+=1 j+=1 if f: break ans = min(ans,j-i) i+=1 if i==n: break d[s[i-1]]-=1 if d[s[i-1]]==0: t-=1 print(ans) ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", "output": "1/6" }, { "input": "2 1", "output": "5/6" }, { "input": "2 2", "output": "5/6" }, { "input": "2 3", "output": "2/3" }, { "input": "2 4", "output": "1/2" }, { "input": "2 5", "output": "1/3" }, { "input": "2 6", "output": "1/6" }, { "input": "3 1", "output": "2/3" }, { "input": "3 2", "output": "2/3" }, { "input": "3 3", "output": "2/3" }, { "input": "3 4", "output": "1/2" }, { "input": "3 5", "output": "1/3" }, { "input": "3 6", "output": "1/6" }, { "input": "4 1", "output": "1/2" }, { "input": "4 3", "output": "1/2" }, { "input": "4 4", "output": "1/2" }, { "input": "4 5", "output": "1/3" }, { "input": "4 6", "output": "1/6" }, { "input": "5 1", "output": "1/3" }, { "input": "5 2", "output": "1/3" }, { "input": "5 3", "output": "1/3" }, { "input": "5 4", "output": "1/3" }, { "input": "5 5", "output": "1/3" }, { "input": "5 6", "output": "1/6" }, { "input": "6 1", "output": "1/6" }, { "input": "6 2", "output": "1/6" }, { "input": "6 3", "output": "1/6" }, { "input": "6 4", "output": "1/6" }, { "input": "6 5", "output": "1/6" }, { "input": "6 6", "output": "1/6" } ]
1,626,758,116
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
6,758,400
def gcd(a,b): if(b==0): return a return gcd(a,a%b) a=int(input()) b=int(input()) if(a>b): mid=7-a else: mid=7-b x = gcd(mid,mid%6) print (mid//x,'/',6//x,sep='')
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input Specification: The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. Output Specification: Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». Demo Input: ['4 2\n'] Demo Output: ['1/2\n'] Note: Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
```python def gcd(a,b): if(b==0): return a return gcd(a,a%b) a=int(input()) b=int(input()) if(a>b): mid=7-a else: mid=7-b x = gcd(mid,mid%6) print (mid//x,'/',6//x,sep='') ```
-1
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,625,307,975
2,147,483,647
Python 3
OK
TESTS
31
78
0
n,m=map(int,input().split()) s=list(map(int,input().split())) t=list(map(int,input().split())) for i in range(n): if s[i] in t: print(s[i],end=" ")
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=map(int,input().split()) s=list(map(int,input().split())) t=list(map(int,input().split())) for i in range(n): if s[i] in t: print(s[i],end=" ") ```
3
976
C
Nested Segments
PROGRAMMING
1,500
[ "greedy", "implementation", "sortings" ]
null
null
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2. Print indices *i* and *j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments. Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment.
Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
[ "5\n1 10\n2 9\n3 9\n2 3\n2 9\n", "3\n1 5\n2 6\n6 20\n" ]
[ "2 1\n", "-1 -1\n" ]
In the first example the following pairs are considered correct: - (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly.
0
[ { "input": "5\n1 10\n2 9\n3 9\n2 3\n2 9", "output": "2 1" }, { "input": "3\n1 5\n2 6\n6 20", "output": "-1 -1" }, { "input": "1\n1 1000000000", "output": "-1 -1" }, { "input": "2\n1 1000000000\n1 1000000000", "output": "2 1" }, { "input": "2\n1 1000000000\n500000000 500000000", "output": "2 1" }, { "input": "2\n1 10\n2 10", "output": "2 1" }, { "input": "2\n10 20\n10 11", "output": "2 1" }, { "input": "3\n1 10\n10 20\n9 11", "output": "-1 -1" }, { "input": "3\n1 1\n2 3\n2 2", "output": "3 2" }, { "input": "4\n1 10\n2 11\n3 10000000\n3 100000000", "output": "3 4" }, { "input": "2\n3 7\n3 9", "output": "1 2" }, { "input": "3\n1 2\n2 3\n1 2", "output": "3 1" }, { "input": "3\n5 6\n4 7\n3 8", "output": "2 3" }, { "input": "3\n2 9\n1 7\n2 8", "output": "3 1" }, { "input": "2\n1 4\n1 5", "output": "1 2" }, { "input": "3\n1 2\n1 3\n4 4", "output": "1 2" }, { "input": "3\n1 2\n1 3\n67 1234567", "output": "1 2" }, { "input": "2\n1 1\n1 1", "output": "2 1" }, { "input": "3\n1 5\n4 7\n3 9", "output": "2 3" }, { "input": "2\n1 1\n1 10", "output": "1 2" }, { "input": "2\n1 2\n1 3", "output": "1 2" }, { "input": "2\n1 10\n1 11", "output": "1 2" }, { "input": "2\n1 1\n1 2", "output": "1 2" }, { "input": "2\n2 3\n2 4", "output": "1 2" }, { "input": "2\n1 3\n3 3", "output": "2 1" }, { "input": "3\n1 10\n11 13\n12 12", "output": "3 2" }, { "input": "2\n2 10\n1 10", "output": "1 2" }, { "input": "3\n1 3\n4 5\n4 4", "output": "3 2" }, { "input": "5\n1 1\n2 6\n3 5\n10 15\n20 25", "output": "3 2" }, { "input": "3\n1 1000\n1001 1007\n1002 1007", "output": "3 2" }, { "input": "3\n1 3\n2 5\n3 4", "output": "3 2" }, { "input": "3\n1 10\n2 11\n3 11", "output": "3 2" }, { "input": "2\n2000000 999999999\n1000000 1000000000", "output": "1 2" }, { "input": "3\n2 10\n11 12\n4 5", "output": "3 1" }, { "input": "2\n1 10\n1 19", "output": "1 2" }, { "input": "4\n1 3\n100 102\n108 110\n1 3", "output": "4 1" }, { "input": "3\n1 3\n5 9\n5 6", "output": "3 2" }, { "input": "3\n1 3\n3 4\n3 5", "output": "2 3" }, { "input": "3\n1 2\n1 3\n1 4", "output": "2 3" }, { "input": "4\n2 3\n1 4\n100 200\n1000 2000", "output": "1 2" }, { "input": "3\n1 1\n2 100\n3 99", "output": "3 2" }, { "input": "3\n1 2\n1 3\n12 1234", "output": "1 2" }, { "input": "3\n1 4\n2 6\n3 5", "output": "3 2" }, { "input": "3\n1 10\n2 12\n1 9", "output": "3 1" }, { "input": "2\n1 3\n1 5", "output": "1 2" }, { "input": "3\n1 2\n2 5\n2 3", "output": "3 2" }, { "input": "4\n1 3\n1 4\n5 10\n11 13", "output": "1 2" }, { "input": "4\n7 15\n6 9\n9 10\n10 11", "output": "3 1" }, { "input": "4\n2 3\n100 200\n1000 2000\n1 4", "output": "1 4" }, { "input": "3\n10 20\n5 9\n11 19", "output": "3 1" }, { "input": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 6\n6 7\n7 8\n8 9\n9 10", "output": "6 7" }, { "input": "2\n1 4\n1 7", "output": "1 2" }, { "input": "3\n1 11\n2 12\n2 13", "output": "2 3" }, { "input": "2\n1 4\n1 8", "output": "1 2" }, { "input": "2\n2 5\n1 5", "output": "1 2" }, { "input": "2\n2 9\n1 10", "output": "1 2" }, { "input": "3\n2 4\n2 4\n1 3", "output": "2 1" }, { "input": "6\n10 11\n12 13\n15 16\n15 17\n18 19\n59 60", "output": "3 4" }, { "input": "2\n1 3\n1 7", "output": "1 2" }, { "input": "5\n4 6\n7 60\n80 90\n4 5\n8 80", "output": "4 1" }, { "input": "2\n1 3\n1 4", "output": "1 2" }, { "input": "3\n2 9\n1 7\n2 9", "output": "3 1" }, { "input": "2\n1 4\n1 6", "output": "1 2" }, { "input": "3\n4 4\n2 3\n4 5", "output": "1 3" }, { "input": "2\n1 5\n1 7", "output": "1 2" }, { "input": "2\n1 2\n1 4", "output": "1 2" }, { "input": "4\n1 1\n2 2\n5 10\n2 4", "output": "2 4" }, { "input": "3\n11 12\n11 15\n43 45", "output": "1 2" }, { "input": "3\n2 3\n2 4\n2 5", "output": "2 3" }, { "input": "2\n2 3\n2 5", "output": "1 2" }, { "input": "3\n1 3\n1 4\n1 5", "output": "2 3" }, { "input": "3\n1 1\n1 2\n1 3", "output": "2 3" }, { "input": "2\n2 3\n1 3", "output": "1 2" }, { "input": "11\n22226 28285\n9095 23314\n19162 25530\n255 13298\n4904 25801\n17914 23501\n8441 28117\n11880 29994\n11123 19874\n21505 27971\n7658 14109", "output": "11 5" }, { "input": "8\n4 11\n5 12\n6 13\n7 14\n8 15\n9 16\n10 17\n1 11", "output": "1 8" }, { "input": "4\n1 10\n12 15\n1 3\n17 18", "output": "3 1" }, { "input": "3\n1 5\n1 10\n1 20", "output": "2 3" }, { "input": "3\n1 1000\n1001 1003\n1 1", "output": "3 1" }, { "input": "3\n1 10\n2 11\n2 11", "output": "3 2" }, { "input": "2\n1 1\n1 3", "output": "1 2" }, { "input": "2\n1 5\n1 6", "output": "1 2" }, { "input": "3\n1 5\n3 6\n1 4", "output": "3 1" }, { "input": "4\n2 8\n1 3\n2 9\n1 2", "output": "4 2" }, { "input": "3\n3 6\n1 3\n3 9", "output": "1 3" }, { "input": "6\n2 40\n5 50\n10 60\n3 45\n1 40\n100 111", "output": "1 5" }, { "input": "4\n1 2\n4 4\n3 3\n2 3", "output": "3 4" }, { "input": "4\n1 1\n4 5\n7 9\n1 1", "output": "4 1" }, { "input": "6\n30 35\n18 29\n28 32\n4 9\n1002 129212\n8 281", "output": "2 6" }, { "input": "2\n10 13\n10 14", "output": "1 2" }, { "input": "5\n2 4\n3 6\n4 5\n222 333\n111 444", "output": "3 2" }, { "input": "3\n1 2\n4 5\n1 1", "output": "3 1" }, { "input": "2\n2 100\n1 100", "output": "1 2" }, { "input": "3\n1 10\n9 20\n3 5", "output": "3 1" }, { "input": "2\n1 9\n1 10", "output": "1 2" }, { "input": "3\n1 2\n1 4\n1 6", "output": "2 3" } ]
1,549,561,761
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
1,403
53,043,200
n = int(input()) l = [] for i in range(n): a, b = list(map(int, input().split())) l.append([a, b, i]) l.sort(key = lambda x: (x[0], -(x[1]), x[2])) cur = l[0][1] ind = 0 for i in range(1, n): if cur >= l[i][1]: print( i + 1, ind + 1) exit() else: cur = l[i][1] ind = l[i][2] print(-1, -1)
Title: Nested Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2. Print indices *i* and *j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments. Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment. Output Specification: Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Demo Input: ['5\n1 10\n2 9\n3 9\n2 3\n2 9\n', '3\n1 5\n2 6\n6 20\n'] Demo Output: ['2 1\n', '-1 -1\n'] Note: In the first example the following pairs are considered correct: - (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly.
```python n = int(input()) l = [] for i in range(n): a, b = list(map(int, input().split())) l.append([a, b, i]) l.sort(key = lambda x: (x[0], -(x[1]), x[2])) cur = l[0][1] ind = 0 for i in range(1, n): if cur >= l[i][1]: print( i + 1, ind + 1) exit() else: cur = l[i][1] ind = l[i][2] print(-1, -1) ```
0
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", "output": "QCCYXL" }, { "input": "3\nAZID\nEERWBC\nEERWBC", "output": "EERWBC" }, { "input": "3\nHNCGYL\nHNCGYL\nHNCGYL", "output": "HNCGYL" }, { "input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG", "output": "ZZWZTG" }, { "input": "4\nA\nA\nKUDLJMXCSE\nA", "output": "A" }, { "input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW", "output": "PHBTW" }, { "input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN", "output": "PKUZYTFYWN" }, { "input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH", "output": "HH" }, { "input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW", "output": "W" }, { "input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP", "output": "XBCP" }, { "input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS", "output": "PYPAS" }, { "input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC", "output": "NC" }, { "input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI", "output": "VOCI" }, { "input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA", "output": "HA" }, { "input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS", "output": "G" }, { "input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL", "output": "WL" } ]
1,488,874,753
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
+n = int(raw_input()) +d = {} +c = [] +while(n>0): + a = raw_input() + if(a in d): + d[a] = d[a]+1 + else: + d[a] = 1 + c.append(a) + n = n-1 +if(len(c) == 1): + print c[0] +elif(d[c[0]] < d[c[1]]): + print c[1] +else: + print c[0]
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. Output Specification: Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. Demo Input: ['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n'] Demo Output: ['ABC\n', 'A\n'] Note: none
```python +n = int(raw_input()) +d = {} +c = [] +while(n>0): + a = raw_input() + if(a in d): + d[a] = d[a]+1 + else: + d[a] = 1 + c.append(a) + n = n-1 +if(len(c) == 1): + print c[0] +elif(d[c[0]] < d[c[1]]): + print c[1] +else: + print c[0] ```
-1
220
A
Little Elephant and Problem
PROGRAMMING
1,300
[ "implementation", "sortings" ]
null
null
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements. Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*. Note that the elements of the array are not necessarily distinct numbers.
In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.
[ "2\n1 2\n", "3\n3 2 1\n", "4\n4 3 2 1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES". In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES". In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".
500
[ { "input": "2\n1 2", "output": "YES" }, { "input": "3\n3 2 1", "output": "YES" }, { "input": "4\n4 3 2 1", "output": "NO" }, { "input": "3\n1 3 2", "output": "YES" }, { "input": "2\n2 1", "output": "YES" }, { "input": "9\n7 7 8 8 10 10 10 10 1000000000", "output": "YES" }, { "input": "10\n1 2 9 4 5 6 7 8 3 10", "output": "YES" }, { "input": "4\n2 2 2 1", "output": "YES" }, { "input": "10\n1 2 4 4 4 5 5 7 7 10", "output": "YES" }, { "input": "10\n4 5 11 12 13 14 16 16 16 18", "output": "YES" }, { "input": "20\n38205814 119727790 127848638 189351562 742927936 284688399 318826601 326499046 387938139 395996609 494453625 551393005 561264192 573569187 600766727 606718722 730549586 261502770 751513115 943272321", "output": "YES" }, { "input": "47\n6 277 329 393 410 432 434 505 529 545 650 896 949 1053 1543 1554 1599 1648 1927 1976 1998 2141 2248 2384 2542 2638 2995 3155 3216 3355 3409 3597 3851 3940 4169 4176 4378 4378 4425 4490 4627 4986 5025 5033 5374 5453 5644", "output": "YES" }, { "input": "50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5", "output": "NO" }, { "input": "100\n3 7 7 8 15 25 26 31 37 41 43 43 46 64 65 82 94 102 102 103 107 124 125 131 140 145 146 150 151 160 160 161 162 165 169 175 182 191 201 211 214 216 218 304 224 229 236 241 244 249 252 269 270 271 273 289 285 295 222 307 312 317 319 319 320 321 325 330 340 341 345 347 354 356 366 366 375 376 380 383 386 398 401 407 414 417 423 426 431 438 440 444 446 454 457 458 458 466 466 472", "output": "NO" }, { "input": "128\n1 2 4 6 8 17 20 20 23 33 43 49 49 49 52 73 74 75 82 84 85 87 90 91 102 103 104 105 111 111 401 142 142 152 155 160 175 176 178 181 183 184 187 188 191 193 326 202 202 214 224 225 236 239 240 243 246 247 249 249 257 257 261 264 265 271 277 281 284 284 286 289 290 296 297 303 305 307 307 317 318 320 322 200 332 342 393 349 350 350 369 375 381 381 385 385 387 393 347 397 398 115 402 407 407 408 410 411 411 416 423 426 429 429 430 440 447 449 463 464 466 471 473 480 480 483 497 503", "output": "NO" }, { "input": "4\n5 12 12 6", "output": "YES" }, { "input": "5\n1 3 3 3 2", "output": "YES" }, { "input": "4\n2 1 1 1", "output": "YES" }, { "input": "2\n1 1", "output": "YES" }, { "input": "4\n1000000000 1 1000000000 1", "output": "YES" }, { "input": "11\n2 2 2 2 2 2 2 2 2 2 1", "output": "YES" }, { "input": "6\n1 2 3 4 5 3", "output": "NO" }, { "input": "9\n3 3 3 2 2 2 1 1 1", "output": "NO" }, { "input": "4\n4 1 2 3", "output": "NO" }, { "input": "6\n3 4 5 6 7 2", "output": "NO" }, { "input": "4\n4 2 1 3", "output": "NO" }, { "input": "4\n3 3 2 2", "output": "NO" }, { "input": "4\n3 2 1 1", "output": "NO" }, { "input": "4\n4 5 1 1", "output": "NO" }, { "input": "6\n1 6 2 4 3 5", "output": "NO" }, { "input": "5\n1 4 5 2 3", "output": "NO" }, { "input": "4\n2 2 1 1", "output": "NO" }, { "input": "5\n1 4 3 2 1", "output": "NO" }, { "input": "5\n1 4 2 2 3", "output": "NO" }, { "input": "6\n1 2 3 1 2 3", "output": "NO" }, { "input": "3\n3 1 2", "output": "NO" }, { "input": "5\n5 1 2 3 4", "output": "NO" }, { "input": "5\n3 3 3 2 2", "output": "NO" }, { "input": "5\n100 5 6 10 7", "output": "NO" }, { "input": "3\n2 3 1", "output": "NO" }, { "input": "5\n4 4 1 1 1", "output": "NO" }, { "input": "5\n1 2 5 3 4", "output": "NO" }, { "input": "4\n3 4 1 2", "output": "NO" }, { "input": "4\n2 4 1 5", "output": "NO" }, { "input": "5\n1 3 3 2 2", "output": "NO" }, { "input": "5\n1 5 4 4 4", "output": "YES" }, { "input": "7\n3 2 1 2 3 5 4", "output": "NO" }, { "input": "5\n1 1 3 2 2", "output": "YES" }, { "input": "9\n1 8 7 7 7 7 7 8 3", "output": "YES" }, { "input": "5\n1 3 2 3 3", "output": "YES" }, { "input": "10\n4 4 4 4 10 4 4 4 4 4", "output": "YES" }, { "input": "8\n3 6 6 6 6 6 4 9", "output": "YES" }, { "input": "4\n4 4 3 3", "output": "NO" }, { "input": "4\n3 2 2 4", "output": "YES" }, { "input": "5\n2 2 1 3 3", "output": "YES" }, { "input": "5\n1 2 7 3 5", "output": "NO" }, { "input": "5\n2 3 4 5 1", "output": "NO" }, { "input": "6\n1 4 3 6 2 5", "output": "NO" }, { "input": "5\n3 3 1 5 4", "output": "NO" }, { "input": "4\n1 2 1 2", "output": "YES" }, { "input": "6\n4 5 3 4 2 6", "output": "NO" }, { "input": "11\n1 2 3 4 5 1 2 3 4 5 1", "output": "NO" }, { "input": "6\n6 1 2 3 4 5", "output": "NO" }, { "input": "5\n4 1 1 1 1", "output": "YES" }, { "input": "9\n1 2 3 5 4 6 7 8 9", "output": "YES" }, { "input": "6\n6 1 2 3 4 2", "output": "NO" }, { "input": "6\n2 2 2 2 3 2", "output": "YES" }, { "input": "3\n2 1 1", "output": "YES" }, { "input": "5\n1 2 1 1 2", "output": "YES" }, { "input": "5\n1 2 2 1 2", "output": "YES" }, { "input": "8\n5 5 5 5 5 5 1 1", "output": "NO" } ]
1,601,226,368
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
124
0
a=int(input()) z=[*range(1,a+1)] k=list(map(int,input().split())) for i in range(a): if i+1!=k[i]: print(k[i],k[i]-1,i,k[k[i]-1]) t=k[k[i]-1] k[k[i]-1]=k[i] k[i]=t if k!=z:print("NO") else:print("YES") exit() print("YES")
Title: Little Elephant and Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements. Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*. Note that the elements of the array are not necessarily distinct numbers. Output Specification: In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise. Demo Input: ['2\n1 2\n', '3\n3 2 1\n', '4\n4 3 2 1\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES". In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES". In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".
```python a=int(input()) z=[*range(1,a+1)] k=list(map(int,input().split())) for i in range(a): if i+1!=k[i]: print(k[i],k[i]-1,i,k[k[i]-1]) t=k[k[i]-1] k[k[i]-1]=k[i] k[i]=t if k!=z:print("NO") else:print("YES") exit() print("YES") ```
0
114
A
Cifera
PROGRAMMING
1,000
[ "math" ]
null
null
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million. Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title. Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
[ "5\n25\n", "3\n8\n" ]
[ "YES\n1\n", "NO\n" ]
none
500
[ { "input": "5\n25", "output": "YES\n1" }, { "input": "3\n8", "output": "NO" }, { "input": "123\n123", "output": "YES\n0" }, { "input": "99\n970300", "output": "NO" }, { "input": "1000\n6666666", "output": "NO" }, { "input": "59\n3571", "output": "NO" }, { "input": "256\n16777217", "output": "NO" }, { "input": "4638\n21511044", "output": "YES\n1" }, { "input": "24\n191102976", "output": "YES\n5" }, { "input": "52010\n557556453", "output": "NO" }, { "input": "61703211\n1750753082", "output": "NO" }, { "input": "137\n2571353", "output": "YES\n2" }, { "input": "8758\n1746157336", "output": "NO" }, { "input": "2\n64", "output": "YES\n5" }, { "input": "96\n884736", "output": "YES\n2" }, { "input": "1094841453\n1656354409", "output": "NO" }, { "input": "1154413\n1229512809", "output": "NO" }, { "input": "2442144\n505226241", "output": "NO" }, { "input": "11548057\n1033418098", "output": "NO" }, { "input": "581\n196122941", "output": "YES\n2" }, { "input": "146\n1913781536", "output": "NO" }, { "input": "945916\n1403881488", "output": "NO" }, { "input": "68269\n365689065", "output": "NO" }, { "input": "30\n900", "output": "YES\n1" }, { "input": "6\n1296", "output": "YES\n3" }, { "input": "1470193122\n1420950405", "output": "NO" }, { "input": "90750\n1793111557", "output": "NO" }, { "input": "1950054\n1664545956", "output": "NO" }, { "input": "6767692\n123762320", "output": "NO" }, { "input": "1437134\n1622348229", "output": "NO" }, { "input": "444103\n1806462642", "output": "NO" }, { "input": "2592\n6718464", "output": "YES\n1" }, { "input": "50141\n366636234", "output": "NO" }, { "input": "835\n582182875", "output": "YES\n2" }, { "input": "156604\n902492689", "output": "NO" }, { "input": "27385965\n1742270058", "output": "NO" }, { "input": "3\n9", "output": "YES\n1" }, { "input": "35\n1838265625", "output": "YES\n5" }, { "input": "8\n4096", "output": "YES\n3" }, { "input": "85955\n945811082", "output": "NO" }, { "input": "54958832\n956670209", "output": "NO" }, { "input": "1475381\n1348159738", "output": "NO" }, { "input": "7313241\n413670642", "output": "NO" }, { "input": "582470\n2116368165", "output": "NO" }, { "input": "26859739\n595086170", "output": "NO" }, { "input": "249766393\n1582130", "output": "NO" }, { "input": "11734\n137686756", "output": "YES\n1" }, { "input": "925093\n1098566745", "output": "NO" }, { "input": "40\n1600", "output": "YES\n1" }, { "input": "2147483647\n2147483647", "output": "YES\n0" }, { "input": "2147483646\n2147483647", "output": "NO" }, { "input": "2147483647\n2147483646", "output": "NO" }, { "input": "2\n2147483647", "output": "NO" }, { "input": "2\n1073741825", "output": "NO" }, { "input": "2\n1073741824", "output": "YES\n29" }, { "input": "10000\n10", "output": "NO" }, { "input": "10\n10000", "output": "YES\n3" }, { "input": "10\n2000000000", "output": "NO" }, { "input": "10\n1000000000", "output": "YES\n8" }, { "input": "5\n1808548329", "output": "NO" }, { "input": "2\n2147483646", "output": "NO" }, { "input": "25\n125", "output": "NO" }, { "input": "6\n18", "output": "NO" }, { "input": "5\n30", "output": "NO" } ]
1,595,335,760
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
19
280
20,172,800
import math as m x = int(input()) y = int(input()) z = m.log(y)/m.log(x) if(z==int(z)): print("YES") print(int(z)-1) else: print("NO")
Title: Cifera Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million. Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title. Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. Input Specification: The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). Output Specification: You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. Demo Input: ['5\n25\n', '3\n8\n'] Demo Output: ['YES\n1\n', 'NO\n'] Note: none
```python import math as m x = int(input()) y = int(input()) z = m.log(y)/m.log(x) if(z==int(z)): print("YES") print(int(z)-1) else: print("NO") ```
0
831
A
Unimodal Array
PROGRAMMING
1,000
[ "implementation" ]
null
null
Array of integers is unimodal, if: - it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6]. Write a program that checks if an array is unimodal.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array.
Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower).
[ "6\n1 5 5 5 4 2\n", "5\n10 20 30 20 10\n", "4\n1 2 1 2\n", "7\n3 3 3 3 3 3 3\n" ]
[ "YES\n", "YES\n", "NO\n", "YES\n" ]
In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
500
[ { "input": "6\n1 5 5 5 4 2", "output": "YES" }, { "input": "5\n10 20 30 20 10", "output": "YES" }, { "input": "4\n1 2 1 2", "output": "NO" }, { "input": "7\n3 3 3 3 3 3 3", "output": "YES" }, { "input": "6\n5 7 11 11 2 1", "output": "YES" }, { "input": "1\n7", "output": "YES" }, { "input": "100\n527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527", "output": "YES" }, { "input": "5\n5 5 6 6 1", "output": "NO" }, { "input": "3\n4 4 2", "output": "YES" }, { "input": "4\n4 5 5 6", "output": "NO" }, { "input": "3\n516 516 515", "output": "YES" }, { "input": "5\n502 503 508 508 507", "output": "YES" }, { "input": "10\n538 538 538 538 538 538 538 538 538 538", "output": "YES" }, { "input": "15\n452 454 455 455 450 448 443 442 439 436 433 432 431 428 426", "output": "YES" }, { "input": "20\n497 501 504 505 509 513 513 513 513 513 513 513 513 513 513 513 513 513 513 513", "output": "YES" }, { "input": "50\n462 465 465 465 463 459 454 449 444 441 436 435 430 429 426 422 421 418 417 412 408 407 406 403 402 399 395 392 387 386 382 380 379 376 374 371 370 365 363 359 358 354 350 349 348 345 342 341 338 337", "output": "YES" }, { "input": "70\n290 292 294 297 299 300 303 305 310 312 313 315 319 320 325 327 328 333 337 339 340 341 345 350 351 354 359 364 367 372 374 379 381 382 383 384 389 393 395 397 398 400 402 405 409 411 416 417 422 424 429 430 434 435 440 442 445 449 451 453 458 460 465 470 474 477 482 482 482 479", "output": "YES" }, { "input": "99\n433 435 439 444 448 452 457 459 460 464 469 470 471 476 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 479 478 477 476 474 469 468 465 460 457 453 452 450 445 443 440 438 433 432 431 430 428 425 421 418 414 411 406 402 397 396 393", "output": "YES" }, { "input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543", "output": "YES" }, { "input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521", "output": "YES" }, { "input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 346 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504", "output": "YES" }, { "input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 363 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496", "output": "YES" }, { "input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 351 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173", "output": "YES" }, { "input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 431 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333", "output": "YES" }, { "input": "1\n1000", "output": "YES" }, { "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": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1", "output": "YES" }, { "input": "100\n1 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "100\n998 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999", "output": "NO" }, { "input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 691 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543", "output": "NO" }, { "input": "100\n527 527 527 527 527 527 527 527 872 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527", "output": "NO" }, { "input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 208 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521", "output": "NO" }, { "input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 921 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504", "output": "NO" }, { "input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 119 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496", "output": "NO" }, { "input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 335 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173", "output": "NO" }, { "input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 525 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333", "output": "NO" }, { "input": "3\n1 2 3", "output": "YES" }, { "input": "3\n3 2 1", "output": "YES" }, { "input": "3\n1 1 2", "output": "NO" }, { "input": "3\n2 1 1", "output": "NO" }, { "input": "3\n2 1 2", "output": "NO" }, { "input": "3\n3 1 2", "output": "NO" }, { "input": "3\n1 3 2", "output": "YES" }, { "input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 497 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346", "output": "YES" }, { "input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 333 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475", "output": "YES" }, { "input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 498 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271", "output": "YES" }, { "input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 32 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346", "output": "NO" }, { "input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 247 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475", "output": "NO" }, { "input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 497 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271", "output": "YES" }, { "input": "2\n1 3", "output": "YES" }, { "input": "2\n1 2", "output": "YES" }, { "input": "5\n2 2 1 1 1", "output": "NO" }, { "input": "4\n1 3 2 2", "output": "NO" }, { "input": "6\n1 2 1 2 2 1", "output": "NO" }, { "input": "2\n4 2", "output": "YES" }, { "input": "3\n3 2 2", "output": "NO" }, { "input": "9\n1 2 2 3 3 4 3 2 1", "output": "NO" }, { "input": "4\n5 5 4 4", "output": "NO" }, { "input": "2\n2 1", "output": "YES" }, { "input": "5\n5 4 3 2 1", "output": "YES" }, { "input": "7\n4 3 3 3 3 3 3", "output": "NO" }, { "input": "5\n1 2 3 4 5", "output": "YES" }, { "input": "3\n2 2 1", "output": "YES" }, { "input": "3\n4 3 3", "output": "NO" }, { "input": "7\n1 5 5 4 3 3 1", "output": "NO" }, { "input": "6\n3 3 1 2 2 1", "output": "NO" }, { "input": "5\n1 2 1 2 1", "output": "NO" }, { "input": "2\n5 1", "output": "YES" }, { "input": "9\n1 2 3 4 4 3 2 2 1", "output": "NO" }, { "input": "3\n2 2 3", "output": "NO" }, { "input": "2\n5 4", "output": "YES" }, { "input": "5\n1 3 3 2 2", "output": "NO" }, { "input": "10\n1 2 3 4 5 6 7 8 9 99", "output": "YES" }, { "input": "4\n1 2 3 4", "output": "YES" }, { "input": "3\n5 5 2", "output": "YES" }, { "input": "4\n1 4 2 3", "output": "NO" }, { "input": "2\n3 2", "output": "YES" }, { "input": "5\n1 2 2 1 1", "output": "NO" }, { "input": "4\n3 3 2 2", "output": "NO" }, { "input": "5\n1 2 3 2 2", "output": "NO" }, { "input": "5\n5 6 6 5 5", "output": "NO" }, { "input": "4\n2 2 1 1", "output": "NO" }, { "input": "5\n5 4 3 3 2", "output": "NO" }, { "input": "7\n1 3 3 3 2 1 1", "output": "NO" }, { "input": "9\n5 6 6 5 5 4 4 3 3", "output": "NO" }, { "input": "6\n1 5 5 3 2 2", "output": "NO" }, { "input": "5\n2 1 3 3 1", "output": "NO" }, { "input": "2\n4 3", "output": "YES" }, { "input": "5\n3 2 2 1 1", "output": "NO" }, { "input": "4\n5 4 3 2", "output": "YES" }, { "input": "4\n4 4 1 1", "output": "NO" }, { "input": "4\n3 3 1 1", "output": "NO" }, { "input": "4\n4 4 2 2", "output": "NO" }, { "input": "5\n4 4 3 2 2", "output": "NO" }, { "input": "8\n4 4 4 4 5 6 7 8", "output": "NO" }, { "input": "5\n3 5 4 4 3", "output": "NO" }, { "input": "6\n2 5 3 3 2 2", "output": "NO" }, { "input": "4\n5 5 2 2", "output": "NO" }, { "input": "5\n1 2 2 3 5", "output": "NO" } ]
1,641,052,054
2,147,483,647
Python 3
OK
TESTS
101
61
0
l=int(input()) l1=list(map(int,input().split())) j=1 while j<l and l1[j-1]<l1[j]: j+=1 while j<l and l1[j-1]==l1[j]: j+=1 while j<l and l1[j-1]>l1[j]: j+=1 if j==l: print("YES") else: print("NO")
Title: Unimodal Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Array of integers is unimodal, if: - it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6]. Write a program that checks if an array is unimodal. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array. Output Specification: Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Demo Input: ['6\n1 5 5 5 4 2\n', '5\n10 20 30 20 10\n', '4\n1 2 1 2\n', '7\n3 3 3 3 3 3 3\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n', 'YES\n'] Note: In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
```python l=int(input()) l1=list(map(int,input().split())) j=1 while j<l and l1[j-1]<l1[j]: j+=1 while j<l and l1[j-1]==l1[j]: j+=1 while j<l and l1[j-1]>l1[j]: j+=1 if j==l: print("YES") else: print("NO") ```
3
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", "output": "QCCYXL" }, { "input": "3\nAZID\nEERWBC\nEERWBC", "output": "EERWBC" }, { "input": "3\nHNCGYL\nHNCGYL\nHNCGYL", "output": "HNCGYL" }, { "input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG", "output": "ZZWZTG" }, { "input": "4\nA\nA\nKUDLJMXCSE\nA", "output": "A" }, { "input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW", "output": "PHBTW" }, { "input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN", "output": "PKUZYTFYWN" }, { "input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH", "output": "HH" }, { "input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW", "output": "W" }, { "input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP", "output": "XBCP" }, { "input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS", "output": "PYPAS" }, { "input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC", "output": "NC" }, { "input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI", "output": "VOCI" }, { "input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA", "output": "HA" }, { "input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS", "output": "G" }, { "input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL", "output": "WL" } ]
1,614,698,474
2,147,483,647
Python 3
OK
TESTS
34
124
307,200
n = int(input()) arr1 = [] arr2 = [] first = 0 for i in range(n): line = str(input()) if first == 0: arr1.append(line) elif line != arr1[-1]: arr2.append(line) else: arr1.append(line) first += 1 if len(arr1) > len(arr2): print(arr1[-1]) else: print(arr2[-1])
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. Output Specification: Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. Demo Input: ['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n'] Demo Output: ['ABC\n', 'A\n'] Note: none
```python n = int(input()) arr1 = [] arr2 = [] first = 0 for i in range(n): line = str(input()) if first == 0: arr1.append(line) elif line != arr1[-1]: arr2.append(line) else: arr1.append(line) first += 1 if len(arr1) > len(arr2): print(arr1[-1]) else: print(arr2[-1]) ```
3.968428
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,688,408,947
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
30
0
n = int(input()) a = [int(i) for i in input().split()] if n % 2 == 1: print(a[n // 2]) exit() m1 = a[n // 2] m2 = a[n // 2 - 1] r1 = 0 r2 = 0 for x in a: r1 += abs(x - m1) r2 += abs(x - m2) print(m1 if r1 < r2 else m2)
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 n = int(input()) a = [int(i) for i in input().split()] if n % 2 == 1: print(a[n // 2]) exit() m1 = a[n // 2] m2 = a[n // 2 - 1] r1 = 0 r2 = 0 for x in a: r1 += abs(x - m1) r2 += abs(x - m2) print(m1 if r1 < r2 else m2) ```
0
567
A
Lineland Mail
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in). Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city. For each city calculate two values ​​*min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
[ "4\n-5 -2 2 7\n", "2\n-1 1\n" ]
[ "3 12\n3 9\n4 7\n5 12\n", "2 2\n2 2\n" ]
none
500
[ { "input": "4\n-5 -2 2 7", "output": "3 12\n3 9\n4 7\n5 12" }, { "input": "2\n-1 1", "output": "2 2\n2 2" }, { "input": "3\n-1 0 1", "output": "1 2\n1 1\n1 2" }, { "input": "4\n-1 0 1 3", "output": "1 4\n1 3\n1 2\n2 4" }, { "input": "3\n-1000000000 0 1000000000", "output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000" }, { "input": "2\n-1000000000 1000000000", "output": "2000000000 2000000000\n2000000000 2000000000" }, { "input": "10\n1 10 12 15 59 68 130 912 1239 9123", "output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122" }, { "input": "5\n-2 -1 0 1 2", "output": "1 4\n1 3\n1 2\n1 3\n1 4" }, { "input": "5\n-2 -1 0 1 3", "output": "1 5\n1 4\n1 3\n1 3\n2 5" }, { "input": "3\n-10000 1 10000", "output": "10001 20000\n9999 10001\n9999 20000" }, { "input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996", "output": "1 4\n1 3\n1 2\n1 3\n1 4" }, { "input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706", "output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010" }, { "input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124", "output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524" }, { "input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292", "output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307" }, { "input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986", "output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14" }, { "input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886", "output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..." }, { "input": "3\n-1000000000 999999999 1000000000", "output": "1999999999 2000000000\n1 1999999999\n1 2000000000" } ]
1,648,041,740
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
0
n = int(input()) lis = list(map(int , input().split())) for i in range(len(lis)): if i == 0: print(str(abs(lis[0] - lis[1]))+" "+ str(abs(lis[0] - lis[len(lis)-1]))) elif i == len(lis)-1: print(str(abs(lis[i] - lis[i - 1])) + " " + str(abs(lis[0] - lis[len(lis) - 1]))) elif i == 1: print(str(abs(lis[0] - lis[i]))+" "+str(abs(lis[len(lis)-1] - lis[i]))) else: print(str(abs(lis[i - 1] - lis[i])) + " " + str(abs(lis[0] - lis[i])))
Title: Lineland Mail Time Limit: None seconds Memory Limit: None megabytes Problem Description: All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in). Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city. For each city calculate two values ​​*min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city Input Specification: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. Output Specification: Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. Demo Input: ['4\n-5 -2 2 7\n', '2\n-1 1\n'] Demo Output: ['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n'] Note: none
```python n = int(input()) lis = list(map(int , input().split())) for i in range(len(lis)): if i == 0: print(str(abs(lis[0] - lis[1]))+" "+ str(abs(lis[0] - lis[len(lis)-1]))) elif i == len(lis)-1: print(str(abs(lis[i] - lis[i - 1])) + " " + str(abs(lis[0] - lis[len(lis) - 1]))) elif i == 1: print(str(abs(lis[0] - lis[i]))+" "+str(abs(lis[len(lis)-1] - lis[i]))) else: print(str(abs(lis[i - 1] - lis[i])) + " " + str(abs(lis[0] - lis[i]))) ```
0
687
A
NP-Hard Problem
PROGRAMMING
1,500
[ "dfs and similar", "graphs" ]
null
null
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both). Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover. They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself).
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively. Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges.
If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes). If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty.
[ "4 2\n1 2\n2 3\n", "3 3\n1 2\n2 3\n1 3\n" ]
[ "1\n2 \n2\n1 3 \n", "-1\n" ]
In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish). In the second sample, there is no way to satisfy both Pari and Arya.
500
[ { "input": "4 2\n1 2\n2 3", "output": "1\n2 \n2\n1 3 " }, { "input": "3 3\n1 2\n2 3\n1 3", "output": "-1" }, { "input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5", "output": "-1" }, { "input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8", "output": "-1" }, { "input": "10 9\n2 5\n2 4\n2 7\n2 9\n2 3\n2 8\n2 6\n2 10\n2 1", "output": "1\n2 \n9\n1 5 4 7 9 3 8 6 10 " }, { "input": "10 16\n6 10\n5 2\n6 4\n6 8\n5 3\n5 4\n6 2\n5 9\n5 7\n5 1\n6 9\n5 8\n5 10\n6 1\n6 7\n6 3", "output": "2\n5 6 \n8\n1 2 10 4 8 9 7 3 " }, { "input": "10 17\n5 1\n8 1\n2 1\n2 6\n3 1\n5 7\n3 7\n8 6\n4 7\n2 7\n9 7\n10 7\n3 6\n4 1\n9 1\n8 7\n10 1", "output": "7\n5 3 2 8 4 9 10 \n3\n1 7 6 " }, { "input": "10 15\n5 9\n7 8\n2 9\n1 9\n3 8\n3 9\n5 8\n1 8\n6 9\n7 9\n4 8\n4 9\n10 9\n10 8\n6 8", "output": "2\n9 8 \n8\n1 5 7 3 4 10 6 2 " }, { "input": "10 9\n4 9\n1 9\n10 9\n2 9\n3 9\n6 9\n5 9\n7 9\n8 9", "output": "1\n9 \n9\n1 4 10 2 3 6 5 7 8 " }, { "input": "2 1\n1 2", "output": "1\n2 \n1\n1 " }, { "input": "10 10\n6 4\n9 1\n3 6\n6 7\n4 2\n9 6\n8 6\n5 7\n1 4\n6 10", "output": "6\n9 4 3 7 8 10 \n4\n1 6 2 5 " }, { "input": "20 22\n20 8\n1 3\n3 18\n14 7\n19 6\n7 20\n14 8\n8 10\n2 5\n11 2\n4 19\n14 2\n7 11\n15 1\n12 15\n7 6\n11 13\n1 16\n9 12\n1 19\n17 3\n11 20", "output": "-1" }, { "input": "20 22\n3 18\n9 19\n6 15\n7 1\n16 8\n18 7\n12 3\n18 4\n9 15\n20 1\n4 2\n6 7\n14 2\n7 15\n7 10\n8 1\n13 6\n9 7\n11 8\n2 6\n18 5\n17 15", "output": "-1" }, { "input": "1000 1\n839 771", "output": "1\n839 \n1\n771 " }, { "input": "1000 1\n195 788", "output": "1\n788 \n1\n195 " }, { "input": "100000 1\n42833 64396", "output": "1\n64396 \n1\n42833 " }, { "input": "100000 1\n26257 21752", "output": "1\n26257 \n1\n21752 " }, { "input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "output": "-1" } ]
1,659,323,266
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
0
import sys import collections import math input = sys.stdin.readline ints = lambda: list(map(int, input().split())) n, m = ints() graph = [[] for _ in range(n + 1)] for _ in range(m): u, v = ints() graph[u].append(v) graph[v].append(u) colors = [-1 for _ in range(n + 1)] stack = [1] visited = {1: True} flag = True c = 0 while stack and flag: node = stack.pop() colors[node] = c c = 1 - c for nb in graph[node]: if colors[nb] == colors[node]: flag = False break elif nb not in visited: stack.append(nb) visited[nb] = True if not flag: print("-1") else: pcount = colors.count(0) print(pcount) print(" ".join([str(i) for i in range(n + 1) if colors[i] == 0])) acount = colors.count(1) print(acount) print(" ".join([str(i) for i in range(n + 1) if colors[i] == 1]))
Title: NP-Hard Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both). Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover. They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself). Input Specification: The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively. Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges. Output Specification: If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes). If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty. Demo Input: ['4 2\n1 2\n2 3\n', '3 3\n1 2\n2 3\n1 3\n'] Demo Output: ['1\n2 \n2\n1 3 \n', '-1\n'] Note: In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish). In the second sample, there is no way to satisfy both Pari and Arya.
```python import sys import collections import math input = sys.stdin.readline ints = lambda: list(map(int, input().split())) n, m = ints() graph = [[] for _ in range(n + 1)] for _ in range(m): u, v = ints() graph[u].append(v) graph[v].append(u) colors = [-1 for _ in range(n + 1)] stack = [1] visited = {1: True} flag = True c = 0 while stack and flag: node = stack.pop() colors[node] = c c = 1 - c for nb in graph[node]: if colors[nb] == colors[node]: flag = False break elif nb not in visited: stack.append(nb) visited[nb] = True if not flag: print("-1") else: pcount = colors.count(0) print(pcount) print(" ".join([str(i) for i in range(n + 1) if colors[i] == 0])) acount = colors.count(1) print(acount) print(" ".join([str(i) for i in range(n + 1) if colors[i] == 1])) ```
0
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B", "output": "#Color" }, { "input": "1 6\nC M Y W G B", "output": "#Color" }, { "input": "1 3\nW G B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G C", "output": "#Color" }, { "input": "2 3\nW W W\nB G M", "output": "#Color" }, { "input": "3 3\nC B W\nB Y M\nB B W", "output": "#Color" }, { "input": "1 3\nW C W", "output": "#Color" }, { "input": "3 3\nB W B\nB C W\nB W W", "output": "#Color" }, { "input": "1 2\nW Y", "output": "#Color" }, { "input": "1 1\nG", "output": "#Black&White" }, { "input": "1 3\nB G W", "output": "#Black&White" }, { "input": "2 2\nW W\nB C", "output": "#Color" }, { "input": "1 1\nM", "output": "#Color" }, { "input": "1 2\nW C", "output": "#Color" }, { "input": "2 3\nW W M\nW W M", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB C", "output": "#Color" }, { "input": "2 3\nW W C\nW W W", "output": "#Color" }, { "input": "1 3\nG G G", "output": "#Black&White" }, { "input": "1 1\nC", "output": "#Color" }, { "input": "1 2\nC W", "output": "#Color" }, { "input": "1 3\nW W C", "output": "#Color" }, { "input": "2 2\nW B\nB G", "output": "#Black&White" }, { "input": "2 2\nB B\nY Y", "output": "#Color" }, { "input": "2 2\nG G\nC C", "output": "#Color" }, { "input": "1 2\nB C", "output": "#Color" }, { "input": "1 4\nG G G C", "output": "#Color" }, { "input": "1 1\nB", "output": "#Black&White" }, { "input": "2 1\nY\nB", "output": "#Color" } ]
1,658,329,545
2,147,483,647
PyPy 3-64
OK
TESTS
50
62
0
def is_colour(string): if "C" in string or "M" in string or "Y" in string: return True return False n = int(input().split()[0]) string = "" for i in range(n): string += input() if is_colour(string): print("#Color") else: print("#Black&White")
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. Output Specification: Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. Demo Input: ['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n'] Demo Output: ['#Color', '#Black&amp;White', '#Black&amp;White'] Note: none
```python def is_colour(string): if "C" in string or "M" in string or "Y" in string: return True return False n = int(input().split()[0]) string = "" for i in range(n): string += input() if is_colour(string): print("#Color") else: print("#Black&White") ```
3
318
A
Even Odds
PROGRAMMING
900
[ "math" ]
null
null
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*.
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). 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.
Print the number that will stand at the position number *k* after Volodya's manipulations.
[ "10 3\n", "7 7\n" ]
[ "5", "6" ]
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
500
[ { "input": "10 3", "output": "5" }, { "input": "7 7", "output": "6" }, { "input": "7 1", "output": "1" }, { "input": "7 2", "output": "3" }, { "input": "8 5", "output": "2" }, { "input": "8 3", "output": "5" }, { "input": "8 4", "output": "7" }, { "input": "1000000000000 500000000001", "output": "2" }, { "input": "999999999997 499999999999", "output": "999999999997" }, { "input": "999999999999 999999999999", "output": "999999999998" }, { "input": "1000000000000 1", "output": "1" }, { "input": "999999999999 1", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "1000000000000 1000000000000", "output": "1000000000000" }, { "input": "1000000000000 500000000000", "output": "999999999999" }, { "input": "1000000000000 499999999999", "output": "999999999997" }, { "input": "999999999997 499999999998", "output": "999999999995" }, { "input": "619234238 556154835", "output": "493075432" }, { "input": "38151981 36650624", "output": "35149266" }, { "input": "680402465 442571217", "output": "204739968" }, { "input": "109135284 9408714", "output": "18817427" }, { "input": "603701841 56038951", "output": "112077901" }, { "input": "356764822 321510177", "output": "286255532" }, { "input": "284911189 142190783", "output": "284381565" }, { "input": "91028405 61435545", "output": "31842684" } ]
1,698,082,206
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
1,000
139,264,000
n,k = map(int,input().split()) l1 = [i for i in range(n+1) if i%2 != 0] l2 = [i for i in range(1,n+1) if i%2 == 0] l = l1+l2 print(l[k-1])
Title: Even Odds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. Input Specification: The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output Specification: Print the number that will stand at the position number *k* after Volodya's manipulations. Demo Input: ['10 3\n', '7 7\n'] Demo Output: ['5', '6'] Note: In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
```python n,k = map(int,input().split()) l1 = [i for i in range(n+1) if i%2 != 0] l2 = [i for i in range(1,n+1) if i%2 == 0] l = l1+l2 print(l[k-1]) ```
0
1,008
A
Romaji
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not. Help Vitya find out if a word $s$ is Berlanese.
The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters.
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower).
[ "sumimasen\n", "ninja\n", "codeforces\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese. In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
500
[ { "input": "sumimasen", "output": "YES" }, { "input": "ninja", "output": "YES" }, { "input": "codeforces", "output": "NO" }, { "input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen", "output": "YES" }, { "input": "n", "output": "YES" }, { "input": "necnei", "output": "NO" }, { "input": "nternn", "output": "NO" }, { "input": "aucunuohja", "output": "NO" }, { "input": "a", "output": "YES" }, { "input": "b", "output": "NO" }, { "input": "nn", "output": "YES" }, { "input": "nnnzaaa", "output": "YES" }, { "input": "zn", "output": "NO" }, { "input": "ab", "output": "NO" }, { "input": "aaaaaaaaaa", "output": "YES" }, { "input": "aaaaaaaaab", "output": "NO" }, { "input": "aaaaaaaaan", "output": "YES" }, { "input": "baaaaaaaaa", "output": "YES" }, { "input": "naaaaaaaaa", "output": "YES" }, { "input": "nbaaaaaaaa", "output": "YES" }, { "input": "bbaaaaaaaa", "output": "NO" }, { "input": "bnaaaaaaaa", "output": "NO" }, { "input": "eonwonojannonnufimiiniewuqaienokacevecinfuqihatenhunliquuyebayiaenifuexuanenuaounnboancaeowonu", "output": "YES" }, { "input": "uixinnepnlinqaingieianndeakuniooudidonnnqeaituioeneiroionxuowudiooonayenfeonuino", "output": "NO" }, { "input": "nnnnnyigaveteononnnnxaalenxuiiwannntoxonyoqonlejuoxuoconnnentoinnul", "output": "NO" }, { "input": "ndonneasoiunhomuunnhuitonnntunntoanerekonoupunanuauenu", "output": "YES" }, { "input": "anujemogawautiedoneobninnibonuunaoennnyoorufonxionntinimiboonununnnnnleenqunminzayoutanlalo", "output": "NO" }, { "input": "y", "output": "NO" }, { "input": "by", "output": "NO" }, { "input": "yy", "output": "NO" }, { "input": "nbn", "output": "NO" }, { "input": "nz", "output": "NO" }, { "input": "king", "output": "NO" }, { "input": "g", "output": "NO" }, { "input": "az", "output": "NO" }, { "input": "x", "output": "NO" }, { "input": "z", "output": "NO" }, { "input": "yn", "output": "NO" }, { "input": "aeo", "output": "YES" }, { "input": "nb", "output": "NO" }, { "input": "npn", "output": "NO" }, { "input": "kini", "output": "YES" }, { "input": "pya", "output": "NO" }, { "input": "m", "output": "NO" }, { "input": "p", "output": "NO" }, { "input": "aaaaaaaak", "output": "NO" }, { "input": "aab", "output": "NO" }, { "input": "d", "output": "NO" }, { "input": "at", "output": "NO" }, { "input": "aaaaaak", "output": "NO" }, { "input": "aaz", "output": "NO" }, { "input": "aaab", "output": "NO" }, { "input": "s", "output": "NO" }, { "input": "nzzen", "output": "NO" }, { "input": "aeionnhhhn", "output": "NO" }, { "input": "h", "output": "NO" }, { "input": "ny", "output": "NO" } ]
1,636,894,075
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
4,505,600
x=input() x=0 for i in range(1,len(x),2): if x[i] in 'AEIOUaeiou': k+=1 if x[i] not in 'AEIOUaeiou': if x[i-1]=='n': k+=1 if k==len(x)//2: print('yes') else: print('no')
Title: Romaji Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not. Help Vitya find out if a word $s$ is Berlanese. Input Specification: The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. Output Specification: Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower). Demo Input: ['sumimasen\n', 'ninja\n', 'codeforces\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese. In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
```python x=input() x=0 for i in range(1,len(x),2): if x[i] in 'AEIOUaeiou': k+=1 if x[i] not in 'AEIOUaeiou': if x[i-1]=='n': k+=1 if k==len(x)//2: print('yes') else: print('no') ```
-1
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "10", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "53", "output": "NO" }, { "input": "77", "output": "NO" }, { "input": "32", "output": "YES" }, { "input": "44", "output": "YES" }, { "input": "98", "output": "YES" }, { "input": "99", "output": "NO" }, { "input": "90", "output": "YES" }, { "input": "67", "output": "NO" }, { "input": "100", "output": "YES" }, { "input": "88", "output": "YES" } ]
1,691,447,193
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
if input()/2 == int(input()/2): print('YES') else: print('NO')
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input Specification: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Output Specification: Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Demo Input: ['8\n'] Demo Output: ['YES\n'] Note: For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
```python if input()/2 == int(input()/2): print('YES') else: print('NO') ```
-1
916
A
Jamie and Alarm Snooze
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button. A time is considered lucky if it contains a digit '7'. For example, 13:<=07 and 17:<=27 are lucky, while 00:<=48 and 21:<=34 are not lucky. Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at *hh*:<=*mm*. Formally, find the smallest possible non-negative integer *y* such that the time representation of the time *x*·*y* minutes before *hh*:<=*mm* contains the digit '7'. Jamie uses 24-hours clock, so after 23:<=59 comes 00:<=00.
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60). The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59).
Print the minimum number of times he needs to press the button.
[ "3\n11 23\n", "5\n01 07\n" ]
[ "2\n", "0\n" ]
In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20. In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky.
500
[ { "input": "3\n11 23", "output": "2" }, { "input": "5\n01 07", "output": "0" }, { "input": "34\n09 24", "output": "3" }, { "input": "2\n14 37", "output": "0" }, { "input": "14\n19 54", "output": "9" }, { "input": "42\n15 44", "output": "12" }, { "input": "46\n02 43", "output": "1" }, { "input": "14\n06 41", "output": "1" }, { "input": "26\n04 58", "output": "26" }, { "input": "54\n16 47", "output": "0" }, { "input": "38\n20 01", "output": "3" }, { "input": "11\n02 05", "output": "8" }, { "input": "55\n22 10", "output": "5" }, { "input": "23\n10 08", "output": "6" }, { "input": "23\n23 14", "output": "9" }, { "input": "51\n03 27", "output": "0" }, { "input": "35\n15 25", "output": "13" }, { "input": "3\n12 15", "output": "6" }, { "input": "47\n00 28", "output": "3" }, { "input": "31\n13 34", "output": "7" }, { "input": "59\n17 32", "output": "0" }, { "input": "25\n11 03", "output": "8" }, { "input": "9\n16 53", "output": "4" }, { "input": "53\n04 06", "output": "3" }, { "input": "37\n00 12", "output": "5" }, { "input": "5\n13 10", "output": "63" }, { "input": "50\n01 59", "output": "10" }, { "input": "34\n06 13", "output": "4" }, { "input": "2\n18 19", "output": "1" }, { "input": "46\n06 16", "output": "17" }, { "input": "14\n03 30", "output": "41" }, { "input": "40\n13 37", "output": "0" }, { "input": "24\n17 51", "output": "0" }, { "input": "8\n14 57", "output": "0" }, { "input": "52\n18 54", "output": "2" }, { "input": "20\n15 52", "output": "24" }, { "input": "20\n03 58", "output": "30" }, { "input": "48\n07 11", "output": "0" }, { "input": "32\n04 01", "output": "2" }, { "input": "60\n08 15", "output": "1" }, { "input": "44\n20 20", "output": "4" }, { "input": "55\n15 35", "output": "9" }, { "input": "55\n03 49", "output": "11" }, { "input": "23\n16 39", "output": "4" }, { "input": "7\n20 36", "output": "7" }, { "input": "35\n16 42", "output": "1" }, { "input": "35\n05 56", "output": "21" }, { "input": "3\n17 45", "output": "0" }, { "input": "47\n05 59", "output": "6" }, { "input": "15\n10 13", "output": "9" }, { "input": "59\n06 18", "output": "9" }, { "input": "34\n17 18", "output": "0" }, { "input": "18\n05 23", "output": "2" }, { "input": "46\n17 21", "output": "0" }, { "input": "30\n06 27", "output": "0" }, { "input": "14\n18 40", "output": "3" }, { "input": "58\n22 54", "output": "6" }, { "input": "26\n19 44", "output": "5" }, { "input": "10\n15 57", "output": "0" }, { "input": "54\n20 47", "output": "0" }, { "input": "22\n08 45", "output": "3" }, { "input": "48\n18 08", "output": "1" }, { "input": "32\n07 06", "output": "0" }, { "input": "60\n19 19", "output": "2" }, { "input": "45\n07 25", "output": "0" }, { "input": "29\n12 39", "output": "8" }, { "input": "13\n08 28", "output": "3" }, { "input": "41\n21 42", "output": "5" }, { "input": "41\n09 32", "output": "3" }, { "input": "9\n21 45", "output": "2" }, { "input": "37\n10 43", "output": "5" }, { "input": "3\n20 50", "output": "1" }, { "input": "47\n00 04", "output": "1" }, { "input": "15\n13 10", "output": "21" }, { "input": "15\n17 23", "output": "0" }, { "input": "43\n22 13", "output": "2" }, { "input": "27\n10 26", "output": "6" }, { "input": "55\n22 24", "output": "5" }, { "input": "55\n03 30", "output": "11" }, { "input": "24\n23 27", "output": "0" }, { "input": "52\n11 33", "output": "3" }, { "input": "18\n22 48", "output": "17" }, { "input": "1\n12 55", "output": "8" }, { "input": "1\n04 27", "output": "0" }, { "input": "1\n12 52", "output": "5" }, { "input": "1\n20 16", "output": "9" }, { "input": "1\n04 41", "output": "4" }, { "input": "1\n20 21", "output": "4" }, { "input": "1\n04 45", "output": "8" }, { "input": "1\n12 18", "output": "1" }, { "input": "1\n04 42", "output": "5" }, { "input": "1\n02 59", "output": "2" }, { "input": "1\n18 24", "output": "7" }, { "input": "1\n02 04", "output": "7" }, { "input": "1\n18 28", "output": "1" }, { "input": "1\n18 01", "output": "2" }, { "input": "1\n10 25", "output": "8" }, { "input": "1\n02 49", "output": "2" }, { "input": "1\n02 30", "output": "3" }, { "input": "1\n18 54", "output": "7" }, { "input": "1\n02 19", "output": "2" }, { "input": "1\n05 25", "output": "8" }, { "input": "60\n23 55", "output": "6" }, { "input": "60\n08 19", "output": "1" }, { "input": "60\n00 00", "output": "7" }, { "input": "60\n08 24", "output": "1" }, { "input": "60\n16 13", "output": "9" }, { "input": "60\n08 21", "output": "1" }, { "input": "60\n16 45", "output": "9" }, { "input": "60\n08 26", "output": "1" }, { "input": "60\n08 50", "output": "1" }, { "input": "60\n05 21", "output": "12" }, { "input": "60\n13 29", "output": "6" }, { "input": "60\n05 18", "output": "12" }, { "input": "60\n13 42", "output": "6" }, { "input": "60\n05 07", "output": "0" }, { "input": "60\n05 47", "output": "0" }, { "input": "60\n21 55", "output": "4" }, { "input": "60\n05 36", "output": "12" }, { "input": "60\n21 08", "output": "4" }, { "input": "60\n21 32", "output": "4" }, { "input": "60\n16 31", "output": "9" }, { "input": "5\n00 00", "output": "73" }, { "input": "2\n06 58", "output": "390" }, { "input": "60\n00 00", "output": "7" }, { "input": "2\n00 00", "output": "181" }, { "input": "10\n00 00", "output": "37" }, { "input": "60\n01 00", "output": "8" }, { "input": "12\n00 06", "output": "31" }, { "input": "1\n00 01", "output": "4" }, { "input": "5\n00 05", "output": "74" }, { "input": "60\n01 01", "output": "8" }, { "input": "11\n18 11", "output": "2" }, { "input": "60\n01 15", "output": "8" }, { "input": "10\n00 16", "output": "38" }, { "input": "60\n00 59", "output": "7" }, { "input": "30\n00 00", "output": "13" }, { "input": "60\n01 05", "output": "8" }, { "input": "4\n00 03", "output": "4" }, { "input": "4\n00 00", "output": "91" }, { "input": "60\n00 01", "output": "7" }, { "input": "6\n00 03", "output": "1" }, { "input": "13\n00 00", "output": "1" }, { "input": "1\n18 01", "output": "2" }, { "input": "5\n06 00", "output": "145" }, { "input": "60\n04 08", "output": "11" }, { "input": "5\n01 55", "output": "96" }, { "input": "8\n00 08", "output": "47" }, { "input": "23\n18 23", "output": "2" }, { "input": "6\n00 06", "output": "62" }, { "input": "59\n18 59", "output": "2" }, { "input": "11\n00 10", "output": "3" }, { "input": "10\n00 01", "output": "37" }, { "input": "59\n00 00", "output": "7" }, { "input": "10\n18 10", "output": "2" }, { "input": "5\n00 01", "output": "73" }, { "input": "1\n00 00", "output": "3" }, { "input": "8\n00 14", "output": "47" }, { "input": "60\n03 00", "output": "10" }, { "input": "60\n00 10", "output": "7" }, { "input": "5\n01 13", "output": "87" }, { "input": "30\n02 43", "output": "18" }, { "input": "17\n00 08", "output": "3" }, { "input": "3\n00 00", "output": "1" }, { "input": "60\n00 05", "output": "7" }, { "input": "5\n18 05", "output": "2" }, { "input": "30\n00 30", "output": "14" }, { "input": "1\n00 06", "output": "9" }, { "input": "55\n00 00", "output": "7" }, { "input": "8\n02 08", "output": "62" }, { "input": "7\n00 00", "output": "9" }, { "input": "6\n08 06", "output": "2" }, { "input": "48\n06 24", "output": "16" }, { "input": "8\n06 58", "output": "98" }, { "input": "3\n12 00", "output": "1" }, { "input": "5\n01 06", "output": "86" }, { "input": "2\n00 08", "output": "185" }, { "input": "3\n18 03", "output": "2" }, { "input": "1\n17 00", "output": "0" }, { "input": "59\n00 48", "output": "7" }, { "input": "5\n12 01", "output": "49" }, { "input": "55\n01 25", "output": "9" }, { "input": "2\n07 23", "output": "0" }, { "input": "10\n01 10", "output": "44" }, { "input": "2\n00 01", "output": "2" }, { "input": "59\n00 01", "output": "6" }, { "input": "5\n00 02", "output": "1" }, { "input": "4\n01 02", "output": "106" }, { "input": "5\n00 06", "output": "74" }, { "input": "42\n00 08", "output": "9" }, { "input": "60\n01 20", "output": "8" }, { "input": "3\n06 00", "output": "1" }, { "input": "4\n00 01", "output": "1" }, { "input": "2\n00 06", "output": "184" }, { "input": "1\n00 57", "output": "0" }, { "input": "6\n00 00", "output": "61" }, { "input": "5\n08 40", "output": "9" }, { "input": "58\n00 55", "output": "1" }, { "input": "2\n00 02", "output": "182" }, { "input": "1\n08 01", "output": "2" }, { "input": "10\n10 10", "output": "14" }, { "input": "60\n01 11", "output": "8" }, { "input": "2\n07 00", "output": "0" }, { "input": "15\n00 03", "output": "25" }, { "input": "6\n04 34", "output": "106" }, { "input": "16\n00 16", "output": "24" }, { "input": "2\n00 59", "output": "1" }, { "input": "59\n00 08", "output": "7" }, { "input": "10\n03 10", "output": "56" }, { "input": "3\n08 03", "output": "2" }, { "input": "20\n06 11", "output": "37" }, { "input": "4\n01 00", "output": "106" }, { "input": "38\n01 08", "output": "12" }, { "input": "60\n00 06", "output": "7" }, { "input": "5\n12 00", "output": "49" }, { "input": "6\n01 42", "output": "78" }, { "input": "4\n00 04", "output": "92" }, { "input": "60\n04 05", "output": "11" }, { "input": "1\n00 53", "output": "6" }, { "input": "5\n08 05", "output": "2" }, { "input": "60\n18 45", "output": "1" }, { "input": "60\n06 23", "output": "13" }, { "input": "6\n00 15", "output": "3" }, { "input": "58\n00 06", "output": "7" }, { "input": "2\n06 44", "output": "383" }, { "input": "1\n08 00", "output": "1" }, { "input": "10\n06 58", "output": "78" }, { "input": "59\n00 58", "output": "8" }, { "input": "1\n18 00", "output": "1" }, { "input": "50\n00 42", "output": "9" }, { "input": "30\n18 30", "output": "2" }, { "input": "60\n21 59", "output": "4" }, { "input": "2\n10 52", "output": "87" }, { "input": "56\n00 00", "output": "7" }, { "input": "16\n18 16", "output": "2" }, { "input": "5\n01 05", "output": "86" }, { "input": "5\n05 00", "output": "133" }, { "input": "5\n23 59", "output": "72" }, { "input": "7\n17 13", "output": "0" }, { "input": "58\n00 00", "output": "7" }, { "input": "15\n00 07", "output": "0" }, { "input": "59\n08 00", "output": "1" }, { "input": "46\n00 00", "output": "8" }, { "input": "59\n01 05", "output": "2" }, { "input": "2\n01 00", "output": "211" }, { "input": "60\n00 24", "output": "7" }, { "input": "10\n00 08", "output": "37" }, { "input": "10\n00 06", "output": "37" }, { "input": "60\n01 24", "output": "8" }, { "input": "50\n00 10", "output": "8" }, { "input": "2\n03 00", "output": "271" }, { "input": "4\n19 04", "output": "17" }, { "input": "25\n00 23", "output": "16" }, { "input": "10\n01 01", "output": "43" } ]
1,546,321,160
320
PyPy 3
OK
TESTS
254
156
0
x = int(input()) t = input().split() h, m = int(t[0]), int(t[1]) i = 0 while True: if '7' in str(h) or '7' in str(m): print(i) exit(0) m -= x if m < 0: m += 60 h -= 1 if h < 0: h += 24 i += 1
Title: Jamie and Alarm Snooze Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button. A time is considered lucky if it contains a digit '7'. For example, 13:<=07 and 17:<=27 are lucky, while 00:<=48 and 21:<=34 are not lucky. Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at *hh*:<=*mm*. Formally, find the smallest possible non-negative integer *y* such that the time representation of the time *x*·*y* minutes before *hh*:<=*mm* contains the digit '7'. Jamie uses 24-hours clock, so after 23:<=59 comes 00:<=00. Input Specification: The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60). The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59). Output Specification: Print the minimum number of times he needs to press the button. Demo Input: ['3\n11 23\n', '5\n01 07\n'] Demo Output: ['2\n', '0\n'] Note: In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20. In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky.
```python x = int(input()) t = input().split() h, m = int(t[0]), int(t[1]) i = 0 while True: if '7' in str(h) or '7' in str(m): print(i) exit(0) m -= x if m < 0: m += 60 h -= 1 if h < 0: h += 24 i += 1 ```
3
808
A
Lucky Year
PROGRAMMING
900
[ "implementation" ]
null
null
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland.
Output amount of years from the current year to the next lucky one.
[ "4\n", "201\n", "4000\n" ]
[ "1\n", "99\n", "1000\n" ]
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
0
[ { "input": "4", "output": "1" }, { "input": "201", "output": "99" }, { "input": "4000", "output": "1000" }, { "input": "9", "output": "1" }, { "input": "10", "output": "10" }, { "input": "1", "output": "1" }, { "input": "100000000", "output": "100000000" }, { "input": "900000000", "output": "100000000" }, { "input": "999999999", "output": "1" }, { "input": "1000000000", "output": "1000000000" }, { "input": "9999999", "output": "1" }, { "input": "100000001", "output": "99999999" }, { "input": "3660", "output": "340" }, { "input": "21", "output": "9" }, { "input": "900000001", "output": "99999999" }, { "input": "62911", "output": "7089" }, { "input": "11", "output": "9" }, { "input": "940302010", "output": "59697990" }, { "input": "91", "output": "9" }, { "input": "101", "output": "99" }, { "input": "1090", "output": "910" }, { "input": "987654321", "output": "12345679" }, { "input": "703450474", "output": "96549526" }, { "input": "1091", "output": "909" }, { "input": "89", "output": "1" }, { "input": "109", "output": "91" }, { "input": "190", "output": "10" }, { "input": "19", "output": "1" }, { "input": "8", "output": "1" }, { "input": "482", "output": "18" }, { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "5", "output": "1" }, { "input": "6", "output": "1" }, { "input": "7", "output": "1" }, { "input": "8", "output": "1" }, { "input": "9", "output": "1" }, { "input": "10", "output": "10" }, { "input": "11", "output": "9" }, { "input": "12", "output": "8" }, { "input": "13", "output": "7" }, { "input": "14", "output": "6" }, { "input": "15", "output": "5" }, { "input": "16", "output": "4" }, { "input": "17", "output": "3" }, { "input": "18", "output": "2" }, { "input": "19", "output": "1" }, { "input": "20", "output": "10" }, { "input": "21", "output": "9" }, { "input": "22", "output": "8" }, { "input": "23", "output": "7" }, { "input": "24", "output": "6" }, { "input": "25", "output": "5" }, { "input": "26", "output": "4" }, { "input": "27", "output": "3" }, { "input": "28", "output": "2" }, { "input": "29", "output": "1" }, { "input": "30", "output": "10" }, { "input": "31", "output": "9" }, { "input": "32", "output": "8" }, { "input": "33", "output": "7" }, { "input": "34", "output": "6" }, { "input": "35", "output": "5" }, { "input": "36", "output": "4" }, { "input": "37", "output": "3" }, { "input": "38", "output": "2" }, { "input": "39", "output": "1" }, { "input": "40", "output": "10" }, { "input": "41", "output": "9" }, { "input": "42", "output": "8" }, { "input": "43", "output": "7" }, { "input": "44", "output": "6" }, { "input": "45", "output": "5" }, { "input": "46", "output": "4" }, { "input": "47", "output": "3" }, { "input": "48", "output": "2" }, { "input": "49", "output": "1" }, { "input": "50", "output": "10" }, { "input": "51", "output": "9" }, { "input": "52", "output": "8" }, { "input": "53", "output": "7" }, { "input": "54", "output": "6" }, { "input": "55", "output": "5" }, { "input": "56", "output": "4" }, { "input": "57", "output": "3" }, { "input": "58", "output": "2" }, { "input": "59", "output": "1" }, { "input": "60", "output": "10" }, { "input": "61", "output": "9" }, { "input": "62", "output": "8" }, { "input": "63", "output": "7" }, { "input": "64", "output": "6" }, { "input": "65", "output": "5" }, { "input": "66", "output": "4" }, { "input": "67", "output": "3" }, { "input": "68", "output": "2" }, { "input": "69", "output": "1" }, { "input": "70", "output": "10" }, { "input": "71", "output": "9" }, { "input": "72", "output": "8" }, { "input": "73", "output": "7" }, { "input": "74", "output": "6" }, { "input": "75", "output": "5" }, { "input": "76", "output": "4" }, { "input": "77", "output": "3" }, { "input": "78", "output": "2" }, { "input": "79", "output": "1" }, { "input": "80", "output": "10" }, { "input": "81", "output": "9" }, { "input": "82", "output": "8" }, { "input": "83", "output": "7" }, { "input": "84", "output": "6" }, { "input": "85", "output": "5" }, { "input": "86", "output": "4" }, { "input": "87", "output": "3" }, { "input": "88", "output": "2" }, { "input": "89", "output": "1" }, { "input": "90", "output": "10" }, { "input": "91", "output": "9" }, { "input": "92", "output": "8" }, { "input": "93", "output": "7" }, { "input": "94", "output": "6" }, { "input": "95", "output": "5" }, { "input": "96", "output": "4" }, { "input": "97", "output": "3" }, { "input": "98", "output": "2" }, { "input": "99", "output": "1" }, { "input": "100", "output": "100" }, { "input": "100", "output": "100" }, { "input": "100", "output": "100" }, { "input": "1000", "output": "1000" }, { "input": "1000", "output": "1000" }, { "input": "1000", "output": "1000" }, { "input": "10000", "output": "10000" }, { "input": "10000", "output": "10000" }, { "input": "101", "output": "99" }, { "input": "110", "output": "90" }, { "input": "1001", "output": "999" }, { "input": "1100", "output": "900" }, { "input": "1010", "output": "990" }, { "input": "10010", "output": "9990" }, { "input": "10100", "output": "9900" }, { "input": "102", "output": "98" }, { "input": "120", "output": "80" }, { "input": "1002", "output": "998" }, { "input": "1200", "output": "800" }, { "input": "1020", "output": "980" }, { "input": "10020", "output": "9980" }, { "input": "10200", "output": "9800" }, { "input": "108", "output": "92" }, { "input": "180", "output": "20" }, { "input": "1008", "output": "992" }, { "input": "1800", "output": "200" }, { "input": "1080", "output": "920" }, { "input": "10080", "output": "9920" }, { "input": "10800", "output": "9200" }, { "input": "109", "output": "91" }, { "input": "190", "output": "10" }, { "input": "1009", "output": "991" }, { "input": "1900", "output": "100" }, { "input": "1090", "output": "910" }, { "input": "10090", "output": "9910" }, { "input": "10900", "output": "9100" }, { "input": "200", "output": "100" }, { "input": "200", "output": "100" }, { "input": "2000", "output": "1000" }, { "input": "2000", "output": "1000" }, { "input": "2000", "output": "1000" }, { "input": "20000", "output": "10000" }, { "input": "20000", "output": "10000" }, { "input": "201", "output": "99" }, { "input": "210", "output": "90" }, { "input": "2001", "output": "999" }, { "input": "2100", "output": "900" }, { "input": "2010", "output": "990" }, { "input": "20010", "output": "9990" }, { "input": "20100", "output": "9900" }, { "input": "202", "output": "98" }, { "input": "220", "output": "80" }, { "input": "2002", "output": "998" }, { "input": "2200", "output": "800" }, { "input": "2020", "output": "980" }, { "input": "20020", "output": "9980" }, { "input": "20200", "output": "9800" }, { "input": "208", "output": "92" }, { "input": "280", "output": "20" }, { "input": "2008", "output": "992" }, { "input": "2800", "output": "200" }, { "input": "2080", "output": "920" }, { "input": "20080", "output": "9920" }, { "input": "20800", "output": "9200" }, { "input": "209", "output": "91" }, { "input": "290", "output": "10" }, { "input": "2009", "output": "991" }, { "input": "2900", "output": "100" }, { "input": "2090", "output": "910" }, { "input": "20090", "output": "9910" }, { "input": "20900", "output": "9100" }, { "input": "800", "output": "100" }, { "input": "800", "output": "100" }, { "input": "8000", "output": "1000" }, { "input": "8000", "output": "1000" }, { "input": "8000", "output": "1000" }, { "input": "80000", "output": "10000" }, { "input": "80000", "output": "10000" }, { "input": "801", "output": "99" }, { "input": "810", "output": "90" }, { "input": "8001", "output": "999" }, { "input": "8100", "output": "900" }, { "input": "8010", "output": "990" }, { "input": "80010", "output": "9990" }, { "input": "80100", "output": "9900" }, { "input": "802", "output": "98" }, { "input": "820", "output": "80" }, { "input": "8002", "output": "998" }, { "input": "8200", "output": "800" }, { "input": "8020", "output": "980" }, { "input": "80020", "output": "9980" }, { "input": "80200", "output": "9800" }, { "input": "808", "output": "92" }, { "input": "880", "output": "20" }, { "input": "8008", "output": "992" }, { "input": "8800", "output": "200" }, { "input": "8080", "output": "920" }, { "input": "80080", "output": "9920" }, { "input": "80800", "output": "9200" }, { "input": "809", "output": "91" }, { "input": "890", "output": "10" }, { "input": "8009", "output": "991" }, { "input": "8900", "output": "100" }, { "input": "8090", "output": "910" }, { "input": "80090", "output": "9910" }, { "input": "80900", "output": "9100" }, { "input": "900", "output": "100" }, { "input": "900", "output": "100" }, { "input": "9000", "output": "1000" }, { "input": "9000", "output": "1000" }, { "input": "9000", "output": "1000" }, { "input": "90000", "output": "10000" }, { "input": "90000", "output": "10000" }, { "input": "901", "output": "99" }, { "input": "910", "output": "90" }, { "input": "9001", "output": "999" }, { "input": "9100", "output": "900" }, { "input": "9010", "output": "990" }, { "input": "90010", "output": "9990" }, { "input": "90100", "output": "9900" }, { "input": "902", "output": "98" }, { "input": "920", "output": "80" }, { "input": "9002", "output": "998" }, { "input": "9200", "output": "800" }, { "input": "9020", "output": "980" }, { "input": "90020", "output": "9980" }, { "input": "90200", "output": "9800" }, { "input": "908", "output": "92" }, { "input": "980", "output": "20" }, { "input": "9008", "output": "992" }, { "input": "9800", "output": "200" }, { "input": "9080", "output": "920" }, { "input": "90080", "output": "9920" }, { "input": "90800", "output": "9200" }, { "input": "909", "output": "91" }, { "input": "990", "output": "10" }, { "input": "9009", "output": "991" }, { "input": "9900", "output": "100" }, { "input": "9090", "output": "910" }, { "input": "90090", "output": "9910" }, { "input": "90900", "output": "9100" }, { "input": "92651241", "output": "7348759" } ]
1,549,620,670
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
n=int(input()) def count_zeros(n): z=0 for i in str(n): if int(i)==0: z+=1 return z count_years=0 y=n while(count_zeros(y)!=(len(str(y))-1)): y+=1 count_years+=1 print(count_years)
Title: Lucky Year Time Limit: None seconds Memory Limit: None megabytes Problem Description: Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year. Input Specification: The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland. Output Specification: Output amount of years from the current year to the next lucky one. Demo Input: ['4\n', '201\n', '4000\n'] Demo Output: ['1\n', '99\n', '1000\n'] Note: In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
```python n=int(input()) def count_zeros(n): z=0 for i in str(n): if int(i)==0: z+=1 return z count_years=0 y=n while(count_zeros(y)!=(len(str(y))-1)): y+=1 count_years+=1 print(count_years) ```
0
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
1,691,574,416
2,147,483,647
Python 3
OK
TESTS
71
92
0
n = int(input()) passengers_inside = 0 min_capacity = 0 for _ in range(n): a, b = map(int, input().split()) passengers_inside = passengers_inside - a + b min_capacity = max(min_capacity, passengers_inside) print(min_capacity)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python n = int(input()) passengers_inside = 0 min_capacity = 0 for _ in range(n): a, b = map(int, input().split()) passengers_inside = passengers_inside - a + b min_capacity = max(min_capacity, passengers_inside) print(min_capacity) ```
3
14
B
Young Photographer
PROGRAMMING
1,000
[ "implementation" ]
B. Young Photographer
2
64
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*1 to position *b*1, the second — from *a*2 to *b*2 What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*).
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
[ "3 3\n0 7\n14 2\n4 6\n" ]
[ "1\n" ]
none
0
[ { "input": "3 3\n0 7\n14 2\n4 6", "output": "1" }, { "input": "1 1\n0 10", "output": "0" }, { "input": "2 2\n1 2\n3 2", "output": "0" }, { "input": "3 2\n1 2\n2 3\n3 4", "output": "-1" }, { "input": "2 4\n10 4\n1 5", "output": "0" }, { "input": "1 10\n1 9", "output": "1" }, { "input": "1 10\n123 12", "output": "2" }, { "input": "1 17\n10 17", "output": "0" }, { "input": "1 22\n22 33", "output": "0" }, { "input": "1 3\n1 2", "output": "1" }, { "input": "2 5\n0 3\n2 1", "output": "3" }, { "input": "3 3\n7 3\n6 4\n3 7", "output": "1" }, { "input": "4 9\n8 6\n11 5\n5 11\n8 3", "output": "1" }, { "input": "2 4\n1 4\n4 0", "output": "0" }, { "input": "3 7\n5 8\n7 5\n4 7", "output": "0" }, { "input": "4 7\n8 2\n5 7\n8 2\n5 8", "output": "0" }, { "input": "2 3\n4 1\n4 1", "output": "0" }, { "input": "3 8\n7 2\n3 7\n5 2", "output": "3" }, { "input": "4 0\n9 1\n8 1\n8 4\n4 5", "output": "4" }, { "input": "4 7\n2 5\n3 6\n3 5\n7 4", "output": "2" }, { "input": "10 16\n4 18\n6 19\n22 1\n23 0\n1 22\n9 22\n4 19\n0 14\n6 14\n0 16", "output": "2" }, { "input": "20 1\n35 8\n40 6\n49 5\n48 18\n46 16\n45 16\n44 10\n16 44\n8 46\n2 45\n38 3\n42 1\n13 35\n35 18\n12 33\n32 11\n31 3\n50 20\n47 6\n38 2", "output": "19" }, { "input": "30 43\n17 72\n75 26\n23 69\n83 30\n15 82\n4 67\n83 27\n33 62\n26 83\n70 26\n69 25\n16 67\n77 26\n66 33\n7 88\n70 9\n10 79\n76 9\n30 77\n77 28\n21 68\n81 14\n13 72\n88 15\n60 29\n87 28\n16 58\n6 58\n71 9\n83 18", "output": "0" }, { "input": "40 69\n29 109\n28 87\n52 106\n101 34\n32 92\n91 60\n90 47\n62 102\n33 72\n27 87\n45 78\n103 37\n94 33\n56 98\n38 79\n31 83\n105 53\n47 89\n50 83\n93 62\n96 49\n47 75\n89 47\n89 61\n93 54\n46 100\n110 41\n103 28\n101 57\n100 62\n71 37\n65 80\n86 28\n73 42\n96 44\n33 111\n98 39\n87 55\n108 65\n31 101", "output": "0" }, { "input": "50 77\n95 55\n113 33\n101 17\n109 56\n117 7\n77 12\n14 84\n57 101\n96 28\n108 22\n105 12\n17 114\n51 115\n18 112\n104 25\n50 115\n14 111\n55 113\n124 20\n101 37\n18 121\n41 90\n77 41\n117 16\n8 83\n92 45\n48 86\n16 84\n13 98\n40 107\n14 94\n23 111\n36 121\n50 100\n35 90\n103 37\n96 51\n109 15\n13 117\n117 42\n112 45\n88 36\n51 121\n127 49\n112 15\n9 95\n122 46\n126 40\n57 93\n56 88", "output": "0" }, { "input": "5 12\n2 7\n7 5\n3 10\n11 3\n2 11", "output": "5" }, { "input": "15 15\n12 37\n40 4\n38 8\n5 36\n11 31\n21 33\n9 37\n4 38\n8 33\n5 39\n7 39\n38 16\n16 41\n38 9\n5 32", "output": "6" }, { "input": "25 40\n66 26\n56 19\n64 38\n64 23\n25 49\n51 26\n67 20\n65 35\n33 66\n28 63\n27 57\n40 56\n59 26\n35 56\n39 67\n30 63\n69 22\n21 63\n67 22\n20 66\n26 65\n64 26\n44 57\n57 41\n35 50", "output": "4" }, { "input": "50 77\n24 119\n43 119\n102 22\n117 30\n127 54\n93 19\n120 9\n118 27\n98 16\n17 105\n22 127\n109 52\n115 40\n11 121\n12 120\n113 30\n13 108\n33 124\n31 116\n112 39\n37 108\n127 28\n127 39\n120 29\n19 114\n103 18\n106 16\n24 121\n93 10\n36 112\n104 40\n39 100\n36 97\n83 9\n14 114\n126 12\n85 47\n25 84\n105 29\n35 113\n102 19\n8 110\n111 28\n94 12\n11 115\n40 124\n39 85\n47 93\n94 31\n17 121", "output": "0" }, { "input": "1 21\n973 373", "output": "352" }, { "input": "2 212\n831 551\n810 753", "output": "541" }, { "input": "3 404\n690 728\n820 260\n186 402", "output": "-1" }, { "input": "4 906\n548 906\n830 457\n228 638\n464 167", "output": "-1" }, { "input": "5 97\n97 393\n840 965\n269 183\n596 49\n975 62", "output": "-1" }, { "input": "3 183\n416 335\n773 648\n434 198", "output": "-1" }, { "input": "3 868\n251 927\n862 464\n157 756", "output": "112" }, { "input": "3 242\n397 208\n951 279\n570 622", "output": "-1" }, { "input": "3 618\n543 800\n38 94\n293 179", "output": "-1" }, { "input": "3 993\n378 81\n127 911\n16 737", "output": "615" }, { "input": "5 12\n11 1\n9 6\n1 11\n3 8\n874 842", "output": "-1" }, { "input": "15 16\n11 40\n5 32\n5 31\n36 10\n34 9\n43 6\n28 6\n34 8\n43 15\n9 28\n14 34\n34 6\n7 31\n31 14\n68 478", "output": "-1" }, { "input": "25 57\n47 31\n64 21\n43 56\n47 19\n70 27\n28 61\n41 61\n39 45\n46 21\n55 35\n70 22\n22 69\n30 67\n55 42\n37 58\n50 28\n57 42\n35 48\n68 40\n38 50\n62 20\n31 52\n38 70\n64 35\n666 393", "output": "-1" }, { "input": "50 118\n83 55\n101 33\n89 17\n97 56\n105 7\n65 12\n14 72\n57 89\n84 28\n96 22\n93 12\n17 102\n51 103\n18 100\n92 25\n50 103\n14 99\n55 101\n112 20\n89 37\n18 109\n41 78\n65 41\n105 16\n8 71\n80 45\n48 74\n16 72\n13 86\n40 95\n14 82\n23 99\n36 109\n50 88\n35 78\n91 37\n84 51\n97 15\n13 105\n105 42\n100 45\n76 36\n51 109\n115 49\n100 15\n9 83\n110 46\n114 40\n57 81\n528 348", "output": "-1" }, { "input": "1 21\n0 1000", "output": "0" } ]
1,683,652,832
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
n, x0 = map(int, input().split()) # initialize minimum and maximum positions min_pos = float('inf') max_pos = float('-inf') # iterate over the n segments for i in range(n): a, b = map(int, input().split()) # update minimum and maximum positions min_pos = min(min_pos, min(a, b)) max_pos = max(max_pos, max(a, b)) # check if Bob can take pictures of all sportsmen if x0 < min_pos or x0 > max_pos: print(-1) else: # Bob should move to the closest end of the segment that is furthest from him dist_left = x0 - min_pos dist_right = max_pos - x0 print(max(dist_left, dist_right))
Title: Young Photographer Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*1 to position *b*1, the second — from *a*2 to *b*2 What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack. Input Specification: The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*). Output Specification: Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. Demo Input: ['3 3\n0 7\n14 2\n4 6\n'] Demo Output: ['1\n'] Note: none
```python n, x0 = map(int, input().split()) # initialize minimum and maximum positions min_pos = float('inf') max_pos = float('-inf') # iterate over the n segments for i in range(n): a, b = map(int, input().split()) # update minimum and maximum positions min_pos = min(min_pos, min(a, b)) max_pos = max(max_pos, max(a, b)) # check if Bob can take pictures of all sportsmen if x0 < min_pos or x0 > max_pos: print(-1) else: # Bob should move to the closest end of the segment that is furthest from him dist_left = x0 - min_pos dist_right = max_pos - x0 print(max(dist_left, dist_right)) ```
0
628
A
Tennis Tournament
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out. The tournament takes place in the following way (below, *m* is the number of the participants of the current round): - let *k* be the maximal power of the number 2 such that *k*<=≤<=*m*, - *k* participants compete in the current round and a half of them passes to the next round, the other *m*<=-<=*k* participants pass to the next round directly, - when only one participant remains, the tournament finishes. Each match requires *b* bottles of water for each participant and one bottle for the judge. Besides *p* towels are given to each participant for the whole tournament. Find the number of bottles and towels needed for the tournament. Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement.
Print two integers *x* and *y* — the number of bottles and towels need for the tournament.
[ "5 2 3\n", "8 2 4\n" ]
[ "20 15\n", "35 32\n" ]
In the first example will be three rounds: 1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be only one match, so we need another 5 bottles of water. So in total we need 20 bottles of water. In the second example no participant will move on to some round directly.
0
[ { "input": "5 2 3", "output": "20 15" }, { "input": "8 2 4", "output": "35 32" }, { "input": "10 1 500", "output": "27 5000" }, { "input": "20 500 1", "output": "19019 20" }, { "input": "100 123 99", "output": "24453 9900" }, { "input": "500 1 1", "output": "1497 500" }, { "input": "500 500 500", "output": "499499 250000" }, { "input": "500 237 474", "output": "237025 237000" }, { "input": "1 2 3", "output": "0 3" }, { "input": "1 2 133", "output": "0 133" }, { "input": "1 2 100", "output": "0 100" }, { "input": "1 3 4", "output": "0 4" }, { "input": "1 10 15", "output": "0 15" }, { "input": "1 1 1", "output": "0 1" }, { "input": "1 2 5", "output": "0 5" }, { "input": "1 500 500", "output": "0 500" }, { "input": "1 3 8", "output": "0 8" }, { "input": "10 10 10", "output": "189 100" }, { "input": "1 3 5", "output": "0 5" }, { "input": "1 2 1", "output": "0 1" }, { "input": "1 2 4", "output": "0 4" }, { "input": "1 10 10", "output": "0 10" }, { "input": "1 345 345", "output": "0 345" }, { "input": "7 12 13", "output": "150 91" }, { "input": "1 500 1", "output": "0 1" }, { "input": "1 12 13", "output": "0 13" }, { "input": "1 500 499", "output": "0 499" }, { "input": "1 100 90", "output": "0 90" }, { "input": "2 100 90", "output": "201 180" }, { "input": "53 1 1", "output": "156 53" }, { "input": "73 73 73", "output": "10584 5329" }, { "input": "67 1 1", "output": "198 67" }, { "input": "63 1 1", "output": "186 63" }, { "input": "59 1 1", "output": "174 59" }, { "input": "57 1 1", "output": "168 57" }, { "input": "13 1 1", "output": "36 13" }, { "input": "349 2 5", "output": "1740 1745" }, { "input": "456 456 456", "output": "415415 207936" } ]
1,602,140,290
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
109
0
q = input() n = int(q[0]) b = int(q[2]) p = int(q[4]) x = (n - 1) * b * b + (n - 1) y = n * p print(x, y) # Wed Oct 07 2020 19:16:20 GMT+0300 (Москва, стандартное время)
Title: Tennis Tournament Time Limit: None seconds Memory Limit: None megabytes Problem Description: A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out. The tournament takes place in the following way (below, *m* is the number of the participants of the current round): - let *k* be the maximal power of the number 2 such that *k*<=≤<=*m*, - *k* participants compete in the current round and a half of them passes to the next round, the other *m*<=-<=*k* participants pass to the next round directly, - when only one participant remains, the tournament finishes. Each match requires *b* bottles of water for each participant and one bottle for the judge. Besides *p* towels are given to each participant for the whole tournament. Find the number of bottles and towels needed for the tournament. Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose). Input Specification: The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement. Output Specification: Print two integers *x* and *y* — the number of bottles and towels need for the tournament. Demo Input: ['5 2 3\n', '8 2 4\n'] Demo Output: ['20 15\n', '35 32\n'] Note: In the first example will be three rounds: 1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be only one match, so we need another 5 bottles of water. So in total we need 20 bottles of water. In the second example no participant will move on to some round directly.
```python q = input() n = int(q[0]) b = int(q[2]) p = int(q[4]) x = (n - 1) * b * b + (n - 1) y = n * p print(x, y) # Wed Oct 07 2020 19:16:20 GMT+0300 (Москва, стандартное время) ```
-1
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20 96 51 110 129 24 116 9 47 32 82 105 114 116 75 154 151 70 42 162", "output": "2 23" }, { "input": "45\n802 664 442 318 318 827 417 878 711 291 231 414 807 553 657 392 279 202 386 606 465 655 658 112 887 15 25 502 95 44 679 775 942 609 209 871 31 234 4 231 150 110 22 823 193", "output": "2 43" }, { "input": "63\n93 180 116 7 8 179 268 279 136 94 221 153 264 190 278 19 19 63 153 26 158 225 25 49 89 218 111 149 255 225 197 122 243 80 3 224 107 178 202 17 53 92 69 42 228 24 81 205 95 8 265 82 228 156 127 241 172 159 106 60 67 155 111", "output": "2 57" }, { "input": "83\n246 535 994 33 390 927 321 97 223 922 812 705 79 80 977 457 476 636 511 137 6 360 815 319 717 674 368 551 714 628 278 713 761 553 184 414 623 753 428 214 581 115 439 61 677 216 772 592 187 603 658 310 439 559 870 376 109 321 189 337 277 26 70 734 796 907 979 693 570 227 345 650 737 633 701 914 134 403 972 940 371 6 642", "output": "2 80" }, { "input": "105\n246 57 12 204 165 123 246 68 191 310 3 152 386 333 374 257 158 104 333 50 80 290 8 340 101 76 221 316 388 289 138 359 316 26 93 290 105 178 81 195 41 196 218 180 244 292 187 97 315 323 174 119 248 239 92 312 31 2 101 180 307 170 338 314 163 281 217 31 142 238 280 190 190 156 70 74 329 113 151 8 141 313 366 40 253 116 168 124 135 230 294 266 353 389 371 359 195 200 183 237 93 102 315 118 188", "output": "2 92" }, { "input": "123\n112 277 170 247 252 115 157 293 256 143 196 90 12 164 164 42 8 223 167 109 175 232 239 111 148 51 9 254 93 32 268 162 231 91 47 162 161 191 195 145 247 292 129 199 230 94 144 217 18 205 176 20 143 198 121 243 211 262 230 277 195 255 108 290 220 275 158 2 286 200 60 267 278 207 123 150 123 116 131 13 12 226 33 244 30 275 263 45 158 192 254 149 242 176 62 224 221 288 250 160 155 225 132 143 276 293 218 145 197 175 33 129 79 206 210 192 222 262 190 52 274 243 233", "output": "3 101" }, { "input": "5\n5 5 5 5 5", "output": "5 1" }, { "input": "3\n1000 1000 1000", "output": "3 1" }, { "input": "1\n1000", "output": "1 1" }, { "input": "1\n1", "output": "1 1" }, { "input": "5\n1 1000 1000 1000 1000", "output": "4 2" }, { "input": "5\n1000 1000 1000 8 7", "output": "3 3" } ]
1,683,026,156
2,147,483,647
Python 3
OK
TESTS
61
92
0
n=int(input()) max_list=list() line=input() line_i=[int(s) for s in line.split()] line_i=sorted(line_i) sum=1 for i in range(n-1): if line_i[i]==line_i[i+1]: sum+=1 else: max_list.append(sum) sum=1 max_list.append(sum) print(str(max(max_list))+" "+str(len(max_list)))
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible. Input Specification: The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. Output Specification: In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. Demo Input: ['3\n1 2 3\n', '4\n6 5 6 7\n'] Demo Output: ['1 3\n', '2 3\n'] Note: none
```python n=int(input()) max_list=list() line=input() line_i=[int(s) for s in line.split()] line_i=sorted(line_i) sum=1 for i in range(n-1): if line_i[i]==line_i[i+1]: sum+=1 else: max_list.append(sum) sum=1 max_list.append(sum) print(str(max(max_list))+" "+str(len(max_list))) ```
3.977
707
C
Pythagorean Triples
PROGRAMMING
1,500
[ "math", "number theory" ]
null
null
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples. For example, triples (3,<=4,<=5), (5,<=12,<=13) and (6,<=8,<=10) are Pythagorean triples. Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse. Katya had no problems with completing this task. Will you do the same?
The only line of the input contains single integer *n* (1<=≤<=*n*<=≤<=109) — the length of some side of a right triangle.
Print two integers *m* and *k* (1<=≤<=*m*,<=*k*<=≤<=1018), such that *n*, *m* and *k* form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer *n*, print <=-<=1 in the only line. If there are many answers, print any of them.
[ "3\n", "6\n", "1\n", "17\n", "67\n" ]
[ "4 5", "8 10", "-1", "144 145", "2244 2245" ]
Illustration for the first sample.
1,500
[ { "input": "3", "output": "4 5" }, { "input": "6", "output": "8 10" }, { "input": "1", "output": "-1" }, { "input": "17", "output": "144 145" }, { "input": "67", "output": "2244 2245" }, { "input": "10", "output": "24 26" }, { "input": "14", "output": "48 50" }, { "input": "22", "output": "120 122" }, { "input": "23", "output": "264 265" }, { "input": "246", "output": "15128 15130" }, { "input": "902", "output": "203400 203402" }, { "input": "1000000000", "output": "1250000000 750000000" }, { "input": "1998", "output": "998000 998002" }, { "input": "2222222", "output": "1234567654320 1234567654322" }, { "input": "2222226", "output": "1234572098768 1234572098770" }, { "input": "1111110", "output": "308641358024 308641358026" }, { "input": "9999998", "output": "24999990000000 24999990000002" }, { "input": "1024", "output": "1280 768" }, { "input": "8388608", "output": "10485760 6291456" }, { "input": "4", "output": "5 3" }, { "input": "8", "output": "10 6" }, { "input": "16", "output": "20 12" }, { "input": "492", "output": "615 369" }, { "input": "493824", "output": "617280 370368" }, { "input": "493804", "output": "617255 370353" }, { "input": "493800", "output": "617250 370350" }, { "input": "2048", "output": "2560 1536" }, { "input": "8388612", "output": "10485765 6291459" }, { "input": "44", "output": "55 33" }, { "input": "444", "output": "555 333" }, { "input": "4444", "output": "5555 3333" }, { "input": "44444", "output": "55555 33333" }, { "input": "444444", "output": "555555 333333" }, { "input": "4444444", "output": "5555555 3333333" }, { "input": "100000000", "output": "125000000 75000000" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "4 5" }, { "input": "5", "output": "12 13" }, { "input": "7", "output": "24 25" }, { "input": "9", "output": "40 41" }, { "input": "11", "output": "60 61" }, { "input": "13", "output": "84 85" }, { "input": "15", "output": "112 113" }, { "input": "19", "output": "180 181" }, { "input": "111", "output": "6160 6161" }, { "input": "113", "output": "6384 6385" }, { "input": "115", "output": "6612 6613" }, { "input": "117", "output": "6844 6845" }, { "input": "119", "output": "7080 7081" }, { "input": "111111", "output": "6172827160 6172827161" }, { "input": "111113", "output": "6173049384 6173049385" }, { "input": "111115", "output": "6173271612 6173271613" }, { "input": "111117", "output": "6173493844 6173493845" }, { "input": "111119", "output": "6173716080 6173716081" }, { "input": "9999993", "output": "49999930000024 49999930000025" }, { "input": "9999979", "output": "49999790000220 49999790000221" }, { "input": "9999990", "output": "24999950000024 24999950000026" }, { "input": "9999991", "output": "49999910000040 49999910000041" }, { "input": "9999992", "output": "12499990 7499994" }, { "input": "9999973", "output": "49999730000364 49999730000365" }, { "input": "9999994", "output": "24999970000008 24999970000010" }, { "input": "9999995", "output": "49999950000012 49999950000013" }, { "input": "9999996", "output": "12499995 7499997" }, { "input": "9999997", "output": "49999970000004 49999970000005" }, { "input": "9999978", "output": "24999890000120 24999890000122" }, { "input": "99999993", "output": "4999999300000024 4999999300000025" }, { "input": "99999979", "output": "4999997900000220 4999997900000221" }, { "input": "99999990", "output": "2499999500000024 2499999500000026" }, { "input": "99999991", "output": "4999999100000040 4999999100000041" }, { "input": "99999992", "output": "124999990 74999994" }, { "input": "99999973", "output": "4999997300000364 4999997300000365" }, { "input": "99999994", "output": "2499999700000008 2499999700000010" }, { "input": "99999995", "output": "4999999500000012 4999999500000013" }, { "input": "99999996", "output": "124999995 74999997" }, { "input": "99999997", "output": "4999999700000004 4999999700000005" }, { "input": "99999978", "output": "2499998900000120 2499998900000122" }, { "input": "987654323", "output": "487730530870294164 487730530870294165" }, { "input": "2", "output": "-1" }, { "input": "4", "output": "5 3" }, { "input": "8", "output": "10 6" }, { "input": "64", "output": "80 48" }, { "input": "999999999", "output": "499999999000000000 499999999000000001" }, { "input": "16", "output": "20 12" }, { "input": "999999937", "output": "499999937000001984 499999937000001985" }, { "input": "999999998", "output": "249999999000000000 249999999000000002" }, { "input": "433494437", "output": "93958713454973484 93958713454973485" }, { "input": "484916147", "output": "117571834810662804 117571834810662805" }, { "input": "999999929", "output": "499999929000002520 499999929000002521" }, { "input": "982451653", "output": "482605625241216204 482605625241216205" }, { "input": "2048", "output": "2560 1536" } ]
1,684,761,383
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
11
46
0
n=int(input())**2 x=1 def fd(x): return (n-x**2)/(2*x) if n**.5<=2: print(-1) else: while (m:=fd(x))%1!=0: x+=1 print(int(fd(x)),int((fd(x)**2+n)**.5))
Title: Pythagorean Triples Time Limit: None seconds Memory Limit: None megabytes Problem Description: Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples. For example, triples (3,<=4,<=5), (5,<=12,<=13) and (6,<=8,<=10) are Pythagorean triples. Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse. Katya had no problems with completing this task. Will you do the same? Input Specification: The only line of the input contains single integer *n* (1<=≤<=*n*<=≤<=109) — the length of some side of a right triangle. Output Specification: Print two integers *m* and *k* (1<=≤<=*m*,<=*k*<=≤<=1018), such that *n*, *m* and *k* form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer *n*, print <=-<=1 in the only line. If there are many answers, print any of them. Demo Input: ['3\n', '6\n', '1\n', '17\n', '67\n'] Demo Output: ['4 5', '8 10', '-1', '144 145', '2244 2245'] Note: Illustration for the first sample.
```python n=int(input())**2 x=1 def fd(x): return (n-x**2)/(2*x) if n**.5<=2: print(-1) else: while (m:=fd(x))%1!=0: x+=1 print(int(fd(x)),int((fd(x)**2+n)**.5)) ```
0
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input": "5\n5 4 3 2 1", "output": "5 4 3 2 1" }, { "input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19" }, { "input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19", "output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19" }, { "input": "10\n3 4 5 6 7 8 9 10 1 2", "output": "9 10 1 2 3 4 5 6 7 8" }, { "input": "8\n1 5 3 7 2 6 4 8", "output": "1 5 3 7 2 6 4 8" }, { "input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47", "output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19" }, { "input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17", "output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25" }, { "input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85", "output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30" }, { "input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49", "output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49" }, { "input": "12\n3 8 7 4 6 5 2 1 11 9 10 12", "output": "8 7 1 4 6 5 3 2 10 11 9 12" }, { "input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76", "output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4" }, { "input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43", "output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1" }, { "input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27", "output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3" }, { "input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22", "output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53" }, { "input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13", "output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24" }, { "input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21", "output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61" }, { "input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33", "output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14" }, { "input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23", "output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21" }, { "input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12", "output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9" }, { "input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31", "output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13" }, { "input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3", "output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16" }, { "input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8", "output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6" }, { "input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71", "output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90" }, { "input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9", "output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9" }, { "input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44", "output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20" }, { "input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17", "output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28" }, { "input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7", "output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5" }, { "input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16", "output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43" }, { "input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65", "output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43" }, { "input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16", "output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45" }, { "input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51", "output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64" }, { "input": "12\n12 3 1 5 11 6 7 10 2 8 9 4", "output": "3 9 2 12 4 6 7 10 11 8 5 1" }, { "input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17", "output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44" }, { "input": "8\n1 3 5 2 4 8 6 7", "output": "1 4 2 5 3 7 8 6" }, { "input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14", "output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12" }, { "input": "10\n2 9 4 6 10 1 7 5 3 8", "output": "6 1 9 3 8 4 7 10 2 5" }, { "input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3", "output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7" }, { "input": "10\n2 4 9 3 6 8 10 5 1 7", "output": "9 1 4 2 8 5 10 6 3 7" }, { "input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15", "output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23" }, { "input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1", "output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27" }, { "input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30", "output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23" }, { "input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52", "output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50" }, { "input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18", "output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98" }, { "input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16", "output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25" }, { "input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37", "output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54" }, { "input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71", "output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71" }, { "input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22", "output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8" }, { "input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12", "output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51" }, { "input": "7\n2 1 5 7 3 4 6", "output": "2 1 5 6 3 7 4" }, { "input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35", "output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31" }, { "input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16", "output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21" }, { "input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52", "output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11" }, { "input": "9\n8 5 2 6 1 9 4 7 3", "output": "5 3 9 7 2 4 8 1 6" }, { "input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27", "output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13" }, { "input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34", "output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6" }, { "input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29", "output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14" }, { "input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7", "output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16" }, { "input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34", "output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24" }, { "input": "9\n4 8 6 5 3 9 2 7 1", "output": "9 7 5 1 4 3 8 2 6" }, { "input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29", "output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32" }, { "input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47", "output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11" }, { "input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6", "output": "10 4 1 8 6 13 12 5 3 11 9 2 7" }, { "input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29", "output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37" }, { "input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3", "output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25" }, { "input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20", "output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24" }, { "input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42", "output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59" }, { "input": "6\n4 3 6 5 1 2", "output": "5 6 2 1 4 3" }, { "input": "9\n7 8 5 3 1 4 2 9 6", "output": "5 7 4 6 3 9 1 2 8" }, { "input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37", "output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13" }, { "input": "1\n1", "output": "1" }, { "input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11", "output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13" }, { "input": "2\n2 1", "output": "2 1" }, { "input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28", "output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18" }, { "input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13", "output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1" }, { "input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14", "output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36" }, { "input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29", "output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32" }, { "input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5", "output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40" }, { "input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54", "output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21" }, { "input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29", "output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4" }, { "input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23", "output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50" }, { "input": "10\n2 10 7 4 1 5 8 6 3 9", "output": "5 1 9 4 6 8 3 7 10 2" }, { "input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13", "output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1" }, { "input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2", "output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11" }, { "input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53", "output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37" }, { "input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53", "output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53" }, { "input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64", "output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49" }, { "input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86", "output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38" }, { "input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75", "output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2" }, { "input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53", "output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5" }, { "input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39", "output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12" }, { "input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87", "output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82" }, { "input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25", "output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97" }, { "input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61", "output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96" }, { "input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92", "output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96" }, { "input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6", "output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36" }, { "input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1" } ]
1,688,312,709
2,147,483,647
Python 3
OK
TESTS
101
92
0
n=int(input()) x=list(map(int,input().split())) z=[] for i in range(1,n+1): z.append(i) a=[] for i in range(1,n+1): q=x.index(i) a.append(str(z[q])) m=" ".join(a) print(m)
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Specification: Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. Demo Input: ['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['4 1 2 3\n', '1 3 2\n', '1 2\n'] Note: none
```python n=int(input()) x=list(map(int,input().split())) z=[] for i in range(1,n+1): z.append(i) a=[] for i in range(1,n+1): q=x.index(i) a.append(str(z[q])) m=" ".join(a) print(m) ```
3
569
B
Inventory
PROGRAMMING
1,200
[ "greedy", "math" ]
null
null
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything. During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering. You have been given information on current inventory numbers for *n* items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to *n* by changing the number of as few items as possible. Let us remind you that a set of *n* numbers forms a permutation if all the numbers are in the range from 1 to *n*, and no two numbers are equal.
The first line contains a single integer *n* — the number of items (1<=≤<=*n*<=≤<=105). The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the initial inventory numbers of the items.
Print *n* numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them.
[ "3\n1 3 2\n", "4\n2 2 3 3\n", "1\n2\n" ]
[ "1 3 2 \n", "2 1 3 4 \n", "1 \n" ]
In the first test the numeration is already a permutation, so there is no need to change anything. In the second test there are two pairs of equal numbers, in each pair you need to replace one number. In the third test you need to replace 2 by 1, as the numbering should start from one.
1,000
[ { "input": "3\n1 3 2", "output": "1 3 2 " }, { "input": "4\n2 2 3 3", "output": "2 1 3 4 " }, { "input": "1\n2", "output": "1 " }, { "input": "3\n3 3 1", "output": "3 2 1 " }, { "input": "5\n1 1 1 1 1", "output": "1 2 3 4 5 " }, { "input": "5\n5 3 4 4 2", "output": "5 3 4 1 2 " }, { "input": "5\n19 11 8 8 10", "output": "1 2 3 4 5 " }, { "input": "15\n2 2 1 2 1 2 3 3 1 3 2 1 2 3 2", "output": "2 4 1 5 6 7 3 8 9 10 11 12 13 14 15 " }, { "input": "18\n3 11 5 9 5 4 6 4 5 7 5 1 8 11 11 2 1 9", "output": "3 11 5 9 10 4 6 12 13 7 14 1 8 15 16 2 17 18 " }, { "input": "42\n999 863 440 1036 1186 908 330 265 382 417 858 286 834 922 42 569 79 158 312 1175 1069 188 21 1207 985 375 59 417 256 595 732 742 629 737 25 699 484 517 37 1134 472 720", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 42 15 16 17 18 19 20 22 21 23 24 26 27 28 29 30 31 32 33 34 25 35 36 38 37 39 40 41 " }, { "input": "111\n15 45 14 65 49 25 102 86 14 80 54 73 43 78 42 32 47 60 55 66 84 69 49 22 26 72 89 52 26 80 71 35 56 2 88 23 23 53 65 92 46 73 29 65 88 99 19 99 87 10 47 96 109 20 60 89 63 105 29 92 109 20 95 65 31 89 107 3 3 50 58 9 28 39 104 42 41 36 70 49 59 96 16 9 3 108 38 42 2 67 32 86 20 6 101 70 101 91 38 10 74 3 27 15 103 63 51 60 62 10 70", "output": "15 45 14 65 49 25 102 86 1 80 54 73 43 78 42 32 47 60 55 66 84 69 4 22 26 72 89 52 5 7 71 35 56 2 88 23 8 53 11 92 46 12 29 13 17 99 19 18 87 10 21 96 109 20 24 30 63 105 33 34 37 40 95 44 31 48 107 3 57 50 58 9 28 39 104 61 41 36 70 64 59 68 16 75 76 108 38 77 79 67 81 82 83 6 101 85 90 91 93 94 74 97 27 98 103 100 51 106 62 110 111 " }, { "input": "7\n45301 14370 61599 42695 46301 24556 26812", "output": "1 2 3 4 5 6 7 " }, { "input": "22\n70150 17718 11731 6488 72633 41249 12141 71465 88562 6167 71659 34151 60508 24942 77343 35882 80424 67225 92746 55412 79 53642", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 " }, { "input": "2\n1 4", "output": "1 2 " } ]
1,439,228,567
4,367
PyPy 3
WRONG_ANSWER
PRETESTS
0
78
0
n=int(input()) s=[] for i in range(n): s.append(i+1) a=list(map(int,input().split(' '))) p=[] for i in range(len(a)): if a[i] in s: s.remove(a[i]) else: p.append(i) c=0 for i in p: a[i]=s[c] c+=1 print(a)
Title: Inventory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything. During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering. You have been given information on current inventory numbers for *n* items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to *n* by changing the number of as few items as possible. Let us remind you that a set of *n* numbers forms a permutation if all the numbers are in the range from 1 to *n*, and no two numbers are equal. Input Specification: The first line contains a single integer *n* — the number of items (1<=≤<=*n*<=≤<=105). The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the initial inventory numbers of the items. Output Specification: Print *n* numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them. Demo Input: ['3\n1 3 2\n', '4\n2 2 3 3\n', '1\n2\n'] Demo Output: ['1 3 2 \n', '2 1 3 4 \n', '1 \n'] Note: In the first test the numeration is already a permutation, so there is no need to change anything. In the second test there are two pairs of equal numbers, in each pair you need to replace one number. In the third test you need to replace 2 by 1, as the numbering should start from one.
```python n=int(input()) s=[] for i in range(n): s.append(i+1) a=list(map(int,input().split(' '))) p=[] for i in range(len(a)): if a[i] in s: s.remove(a[i]) else: p.append(i) c=0 for i in p: a[i]=s[c] c+=1 print(a) ```
0
48
D
Permutations
PROGRAMMING
1,500
[ "greedy" ]
D. Permutations
1
256
A permutation is a sequence of integers from 1 to *n* of length *n* containing each number exactly once. For example, (1), (4,<=3,<=5,<=1,<=2), (3,<=2,<=1) are permutations, and (1,<=1), (4,<=3,<=1), (2,<=3,<=4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took several permutations (perhaps, with a different number of elements), wrote them down consecutively as one array and then shuffled the resulting array. The task is to restore the initial permutations if it is possible.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The next line contains the mixed array of *n* integers, divided with a single space. The numbers in the array are from 1 to 105.
If this array can be split into several permutations so that every element of the array belongs to exactly one permutation, print in the first line the number of permutations. The second line should contain *n* numbers, corresponding to the elements of the given array. If the *i*-th element belongs to the first permutation, the *i*-th number should be 1, if it belongs to the second one, then its number should be 2 and so on. The order of the permutations’ numbering is free. If several solutions are possible, print any one of them. If there’s no solution, print in the first line <=-<=1.
[ "9\n1 2 3 1 2 1 4 2 5\n", "4\n4 3 2 1\n", "4\n1 2 2 3\n" ]
[ "3\n3 1 2 1 2 2 2 3 2\n", "1\n1 1 1 1 ", "-1\n" ]
In the first sample test the array is split into three permutations: (2, 1), (3, 2, 1, 4, 5), (1, 2). The first permutation is formed by the second and the fourth elements of the array, the second one — by the third, the fifth, the sixth, the seventh and the ninth elements, the third one — by the first and the eigth elements. Clearly, there are other splitting variants possible.
0
[ { "input": "9\n1 2 3 1 2 1 4 2 5", "output": "3\n1 1 1 2 2 3 1 3 1 " }, { "input": "4\n4 3 2 1", "output": "1\n1 1 1 1 " }, { "input": "4\n1 2 2 3", "output": "-1" }, { "input": "1\n1", "output": "1\n1 " }, { "input": "1\n2", "output": "-1" }, { "input": "5\n1 1 1 1 1", "output": "5\n1 2 3 4 5 " }, { "input": "3\n2 1 1", "output": "2\n1 1 2 " }, { "input": "6\n3 3 2 2 1 1", "output": "2\n1 2 1 2 1 2 " }, { "input": "2\n1000 1", "output": "-1" }, { "input": "5\n2 2 1 1 3", "output": "2\n1 2 1 2 1 " }, { "input": "10\n2 1 2 4 6 1 5 3 7 1", "output": "3\n1 1 2 1 1 2 1 1 1 3 " }, { "input": "10\n4 1 2 1 3 3 1 2 2 1", "output": "4\n1 1 1 2 1 2 3 2 3 4 " }, { "input": "10\n1 2 5 1 1 1 4 1 3 2", "output": "5\n1 1 1 2 3 4 1 5 1 2 " }, { "input": "20\n2 7 3 8 4 6 3 7 6 4 13 5 1 12 1 10 2 11 5 9", "output": "2\n1 1 1 1 1 1 2 2 2 2 1 1 1 1 2 1 2 1 2 1 " }, { "input": "20\n1 1 1 2 3 1 5 9 5 8 4 6 7 3 1 2 2 1 3 4", "output": "6\n1 2 3 1 1 4 1 1 2 1 1 1 1 2 5 2 3 6 3 2 " }, { "input": "20\n2 10 3 3 2 1 14 13 2 15 1 4 5 12 7 11 9 1 6 8", "output": "3\n1 1 1 2 2 1 1 1 3 1 2 1 1 1 1 1 1 3 1 1 " }, { "input": "20\n1 7 2 3 1 1 8 1 6 1 9 11 5 10 1 4 2 3 1 2", "output": "7\n1 1 1 1 2 3 1 4 1 5 1 1 1 1 6 1 2 2 7 3 " }, { "input": "30\n6 1 2 3 6 4 1 8 1 2 2 5 5 1 1 3 9 1 5 8 1 2 7 7 4 3 1 3 4 2", "output": "8\n1 1 1 1 2 1 2 1 3 2 3 1 2 4 5 2 1 6 3 2 7 4 1 2 2 3 8 4 3 5 " }, { "input": "30\n2 6 2 3 3 1 4 2 1 3 3 2 1 2 1 8 1 2 4 1 1 1 5 1 4 7 1 9 1 1", "output": "12\n1 1 2 1 2 1 1 3 2 3 4 4 3 5 4 1 5 6 2 6 7 8 1 9 3 1 10 1 11 12 " }, { "input": "30\n1 3 2 5 9 4 16 14 2 2 4 11 7 17 1 15 13 3 6 12 6 19 8 1 20 5 18 4 10 3", "output": "3\n1 1 1 1 1 1 1 1 2 3 2 1 1 1 2 1 1 2 1 1 2 1 1 3 1 2 1 3 1 3 " }, { "input": "10\n2 2 6 3 1 4 5 3 7 7", "output": "-1" }, { "input": "20\n4 6 6 4 5 4 3 2 5 7 3 2 4 1 3 1 1 4 1 7", "output": "-1" }, { "input": "30\n2 8 3 3 7 4 2 9 4 3 5 6 1 5 3 5 8 1 9 6 6 7 2 7 1 1 1 10 2 1", "output": "-1" }, { "input": "30\n8 7 9 6 2 3 7 1 1 5 7 2 3 1 7 4 5 6 3 9 4 9 4 2 3 1 1 2 2 10", "output": "-1" }, { "input": "50\n7 1 6 5 15 3 13 7 1 1 4 2 4 3 2 1 11 9 4 2 3 7 1 1 1 14 3 14 5 2 5 4 1 8 2 2 2 2 1 1 4 1 2 3 6 12 1 1 5 1", "output": "-1" }, { "input": "50\n1 1 4 1 1 1 1 1 1 3 1 1 3 2 1 1 1 1 5 2 1 1 1 1 1 3 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "41\n1 2 1 3 4 5 6 7 8 1 9 10 2 1 11 12 13 14 1 2 15 16 17 18 19 3 20 21 22 23 24 25 3 26 27 4 28 29 30 31 32 33 34 35 36 37 38 39 40 41 " }, { "input": "100\n2 13 10 4 13 8 22 11 5 3 4 6 19 4 8 8 6 1 16 4 11 17 5 18 7 7 4 5 3 7 2 16 5 6 10 1 6 12 14 6 8 7 9 7 1 2 1 8 5 5 9 21 7 11 6 1 12 10 6 23 10 9 8 4 1 2 3 13 2 14 15 1 1 12 3 9 12 3 13 9 8 1 12 5 2 3 11 7 11 9 3 14 1 2 15 2 10 4 14 20", "output": "10\n1 1 1 1 2 1 1 1 1 1 2 1 1 3 2 3 2 1 1 4 2 1 2 1 1 2 5 3 2 3 2 2 4 3 2 2 4 1 1 5 4 4 1 5 3 3 4 5 5 6 2 1 6 3 6 5 2 3 7 1 4 3 6 6 6 4 3 3 5 2 1 7 8 3 4 4 4 5 4 5 7 9 5 7 6 6 4 7 5 6 7 3 10 7 2 8 5 7 4 1 " }, { "input": "100\n9 6 3 28 10 2 2 11 2 1 25 3 13 5 14 13 4 14 2 16 12 27 8 1 7 9 8 19 33 23 4 1 15 6 7 12 2 8 30 4 1 31 6 1 15 5 18 3 2 24 7 3 1 20 10 8 26 22 3 3 9 6 1 10 1 5 1 3 7 6 11 10 1 16 19 5 9 4 4 4 2 18 12 21 11 5 2 32 17 29 2 4 8 1 7 5 3 2 17 1", "output": "12\n1 1 1 1 1 1 2 1 3 1 1 2 1 1 1 2 1 2 4 1 1 1 1 2 1 2 2 1 1 1 2 3 1 2 2 2 5 3 1 3 4 1 3 5 2 2 1 3 6 1 3 4 6 1 2 4 1 1 5 6 3 4 7 3 8 3 9 7 4 5 2 4 10 2 2 4 4 4 5 6 7 2 3 1 3 5 8 1 1 1 9 7 5 11 5 6 8 10 2 12 " }, { "input": "100\n12 18 1 1 14 23 1 1 22 5 7 9 7 1 1 1 3 8 4 2 1 6 9 1 3 2 11 1 11 2 3 2 1 4 2 7 1 16 3 4 2 13 3 1 5 11 2 10 20 24 3 21 5 2 6 2 1 10 10 5 17 1 1 4 19 8 5 5 3 9 4 2 7 8 10 4 9 1 3 3 9 7 6 4 4 3 6 8 12 1 3 6 2 1 8 4 1 15 2 5", "output": "20\n1 1 1 2 1 1 3 4 1 1 1 1 2 5 6 7 1 1 1 1 8 1 2 9 2 2 1 10 2 3 3 4 11 2 5 3 12 1 4 3 6 1 5 13 2 3 7 1 1 1 6 1 3 8 2 9 14 2 3 4 1 15 16 4 1 2 5 6 7 3 5 10 4 3 4 6 4 17 8 9 5 5 3 7 8 10 4 4 2 18 11 5 11 19 5 9 20 1 12 7 " }, { "input": "100\n10 1 13 1 5 2 5 5 9 10 3 8 4 1 3 5 6 4 1 4 9 8 1 1 1 1 8 2 3 1 1 2 5 1 1 12 6 4 5 3 1 3 18 10 1 2 3 2 6 2 3 15 1 3 5 3 9 7 1 6 11 7 7 8 6 17 11 7 6 1 4 4 1 1 3 1 2 6 7 14 4 4 5 1 11 1 4 2 8 4 2 7 16 12 1 1 2 2 1 2", "output": "25\n1 1 1 2 1 1 2 3 1 2 1 1 1 3 2 4 1 2 4 3 2 2 5 6 7 8 3 2 3 9 10 3 5 11 12 1 2 4 6 4 13 5 1 3 14 4 6 5 3 6 7 1 15 8 7 9 3 1 16 4 1 2 3 4 5 1 2 4 6 17 5 6 18 19 10 20 7 7 5 1 7 8 8 21 3 22 9 8 5 10 9 6 1 2 23 24 10 11 25 12 " } ]
1,680,883,647
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
n=int(input()) i=n l1=[] count=-1 j=1 while i>0: l1.append(i) count+=1 ap=0 j=1 while j<n+1: if abs(l1[count]-j)>1 and j not in l1: l1.append(j) count+=1 j=0 ap=1 # if ap==0: # l1=[] # i-=1 # count=-1 # print(abs(l1[count]-j)) # print(l1) j+=1 if len(l1)==n: break else: l1=[] i-=1 count=-1 if len(l1)==0: print("NO SOLUTION") for i in l1: print(i,end=" ")
Title: Permutations Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: A permutation is a sequence of integers from 1 to *n* of length *n* containing each number exactly once. For example, (1), (4,<=3,<=5,<=1,<=2), (3,<=2,<=1) are permutations, and (1,<=1), (4,<=3,<=1), (2,<=3,<=4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took several permutations (perhaps, with a different number of elements), wrote them down consecutively as one array and then shuffled the resulting array. The task is to restore the initial permutations if it is possible. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The next line contains the mixed array of *n* integers, divided with a single space. The numbers in the array are from 1 to 105. Output Specification: If this array can be split into several permutations so that every element of the array belongs to exactly one permutation, print in the first line the number of permutations. The second line should contain *n* numbers, corresponding to the elements of the given array. If the *i*-th element belongs to the first permutation, the *i*-th number should be 1, if it belongs to the second one, then its number should be 2 and so on. The order of the permutations’ numbering is free. If several solutions are possible, print any one of them. If there’s no solution, print in the first line <=-<=1. Demo Input: ['9\n1 2 3 1 2 1 4 2 5\n', '4\n4 3 2 1\n', '4\n1 2 2 3\n'] Demo Output: ['3\n3 1 2 1 2 2 2 3 2\n', '1\n1 1 1 1 ', '-1\n'] Note: In the first sample test the array is split into three permutations: (2, 1), (3, 2, 1, 4, 5), (1, 2). The first permutation is formed by the second and the fourth elements of the array, the second one — by the third, the fifth, the sixth, the seventh and the ninth elements, the third one — by the first and the eigth elements. Clearly, there are other splitting variants possible.
```python n=int(input()) i=n l1=[] count=-1 j=1 while i>0: l1.append(i) count+=1 ap=0 j=1 while j<n+1: if abs(l1[count]-j)>1 and j not in l1: l1.append(j) count+=1 j=0 ap=1 # if ap==0: # l1=[] # i-=1 # count=-1 # print(abs(l1[count]-j)) # print(l1) j+=1 if len(l1)==n: break else: l1=[] i-=1 count=-1 if len(l1)==0: print("NO SOLUTION") for i in l1: print(i,end=" ") ```
0
131
A
cAPS lOCK
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: - either it only contains uppercase letters; - or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Print the result of the given word's processing.
[ "cAPS\n", "Lock\n" ]
[ "Caps", "Lock\n" ]
none
500
[ { "input": "cAPS", "output": "Caps" }, { "input": "Lock", "output": "Lock" }, { "input": "cAPSlOCK", "output": "cAPSlOCK" }, { "input": "CAPs", "output": "CAPs" }, { "input": "LoCK", "output": "LoCK" }, { "input": "OOPS", "output": "oops" }, { "input": "oops", "output": "oops" }, { "input": "a", "output": "A" }, { "input": "A", "output": "a" }, { "input": "aA", "output": "Aa" }, { "input": "Zz", "output": "Zz" }, { "input": "Az", "output": "Az" }, { "input": "zA", "output": "Za" }, { "input": "AAA", "output": "aaa" }, { "input": "AAa", "output": "AAa" }, { "input": "AaR", "output": "AaR" }, { "input": "Tdr", "output": "Tdr" }, { "input": "aTF", "output": "Atf" }, { "input": "fYd", "output": "fYd" }, { "input": "dsA", "output": "dsA" }, { "input": "fru", "output": "fru" }, { "input": "hYBKF", "output": "Hybkf" }, { "input": "XweAR", "output": "XweAR" }, { "input": "mogqx", "output": "mogqx" }, { "input": "eOhEi", "output": "eOhEi" }, { "input": "nkdku", "output": "nkdku" }, { "input": "zcnko", "output": "zcnko" }, { "input": "lcccd", "output": "lcccd" }, { "input": "vwmvg", "output": "vwmvg" }, { "input": "lvchf", "output": "lvchf" }, { "input": "IUNVZCCHEWENCHQQXQYPUJCRDZLUXCLJHXPHBXEUUGNXOOOPBMOBRIBHHMIRILYJGYYGFMTMFSVURGYHUWDRLQVIBRLPEVAMJQYO", "output": "iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgyygfmtmfsvurgyhuwdrlqvibrlpevamjqyo" }, { "input": "OBHSZCAMDXEJWOZLKXQKIVXUUQJKJLMMFNBPXAEFXGVNSKQLJGXHUXHGCOTESIVKSFMVVXFVMTEKACRIWALAGGMCGFEXQKNYMRTG", "output": "obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksfmvvxfvmtekacriwalaggmcgfexqknymrtg" }, { "input": "IKJYZIKROIYUUCTHSVSKZTETNNOCMAUBLFJCEVANCADASMZRCNLBZPQRXESHEEMOMEPCHROSRTNBIDXYMEPJSIXSZQEBTEKKUHFS", "output": "ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemomepchrosrtnbidxymepjsixszqebtekkuhfs" }, { "input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE", "output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype" }, { "input": "uCKJZRGZJCPPLEEYJTUNKOQSWGBMTBQEVPYFPIPEKRVYQNTDPANOIXKMPINNFUSZWCURGBDPYTEKBEKCPMVZPMWAOSHJYMGKOMBQ", "output": "Uckjzrgzjcppleeyjtunkoqswgbmtbqevpyfpipekrvyqntdpanoixkmpinnfuszwcurgbdpytekbekcpmvzpmwaoshjymgkombq" }, { "input": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR", "output": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR" }, { "input": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE", "output": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE" }, { "input": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ", "output": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ" }, { "input": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm", "output": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm" }, { "input": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm", "output": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm" }, { "input": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg", "output": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg" }, { "input": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc", "output": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc" }, { "input": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv", "output": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv" }, { "input": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect", "output": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect" }, { "input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE", "output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype" }, { "input": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu", "output": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu" }, { "input": "aBACABa", "output": "aBACABa" }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAaa", "output": "AAAAAAAAAAAAAAAAAAAAAAAAaa" }, { "input": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" }, { "input": "dDDDDDDDDDDDDD", "output": "Dddddddddddddd" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "z", "output": "Z" }, { "input": "AZ", "output": "az" }, { "input": "Z", "output": "z" }, { "input": "aAAAA", "output": "Aaaaa" }, { "input": "F", "output": "f" } ]
1,696,041,751
2,147,483,647
Python 3
OK
TESTS
56
46
0
# h h= input() if h.isupper() or (h[0].islower() and h[1:].isupper()) or (len(h)==1 and h.islower()): h= h.swapcase() print(h)
Title: cAPS lOCK Time Limit: None seconds Memory Limit: None megabytes Problem Description: wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: - either it only contains uppercase letters; - or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. Input Specification: The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. Output Specification: Print the result of the given word's processing. Demo Input: ['cAPS\n', 'Lock\n'] Demo Output: ['Caps', 'Lock\n'] Note: none
```python # h h= input() if h.isupper() or (h[0].islower() and h[1:].isupper()) or (len(h)==1 and h.islower()): h= h.swapcase() print(h) ```
3
832
A
Sasha and Sticks
PROGRAMMING
800
[ "games", "math" ]
null
null
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn.
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower).
[ "1 1\n", "10 4\n" ]
[ "YES\n", "NO\n" ]
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
500
[ { "input": "1 1", "output": "YES" }, { "input": "10 4", "output": "NO" }, { "input": "251656215122324104 164397544865601257", "output": "YES" }, { "input": "963577813436662285 206326039287271924", "output": "NO" }, { "input": "1000000000000000000 1", "output": "NO" }, { "input": "253308697183523656 25332878317796706", "output": "YES" }, { "input": "669038685745448997 501718093668307460", "output": "YES" }, { "input": "116453141993601660 87060381463547965", "output": "YES" }, { "input": "766959657 370931668", "output": "NO" }, { "input": "255787422422806632 146884995820359999", "output": "YES" }, { "input": "502007866464507926 71266379084204128", "output": "YES" }, { "input": "257439908778973480 64157133126869976", "output": "NO" }, { "input": "232709385 91708542", "output": "NO" }, { "input": "252482458300407528 89907711721009125", "output": "NO" }, { "input": "6 2", "output": "YES" }, { "input": "6 3", "output": "NO" }, { "input": "6 4", "output": "YES" }, { "input": "6 5", "output": "YES" }, { "input": "6 6", "output": "YES" }, { "input": "258266151957056904 30153168463725364", "output": "NO" }, { "input": "83504367885565783 52285355047292458", "output": "YES" }, { "input": "545668929424440387 508692735816921376", "output": "YES" }, { "input": "547321411485639939 36665750286082900", "output": "NO" }, { "input": "548973893546839491 183137237979822911", "output": "NO" }, { "input": "544068082 193116851", "output": "NO" }, { "input": "871412474 749817171", "output": "YES" }, { "input": "999999999 1247", "output": "NO" }, { "input": "851941088 712987048", "output": "YES" }, { "input": "559922900 418944886", "output": "YES" }, { "input": "293908937 37520518", "output": "YES" }, { "input": "650075786 130049650", "output": "NO" }, { "input": "1000000000 1000000000", "output": "YES" }, { "input": "548147654663723363 107422751713800746", "output": "YES" }, { "input": "828159210 131819483", "output": "NO" }, { "input": "6242634 4110365", "output": "YES" }, { "input": "458601973 245084155", "output": "YES" }, { "input": "349593257 18089089", "output": "YES" }, { "input": "814768821 312514745", "output": "NO" }, { "input": "697884949 626323363", "output": "YES" }, { "input": "667011589 54866795", "output": "NO" }, { "input": "1000000000000000000 2", "output": "NO" }, { "input": "1000000000000000000 3", "output": "YES" }, { "input": "1000000000000000000 4", "output": "NO" }, { "input": "999999999999999 1", "output": "YES" }, { "input": "17 4", "output": "NO" }, { "input": "2 2", "output": "YES" }, { "input": "1000000000000000 2", "output": "NO" }, { "input": "12 4", "output": "YES" }, { "input": "6 1", "output": "NO" }, { "input": "2 1", "output": "NO" }, { "input": "10000000005 1", "output": "YES" }, { "input": "10000000000000009 2", "output": "NO" }, { "input": "12457895452123 1", "output": "YES" }, { "input": "999999999999999999 9", "output": "YES" }, { "input": "1000000000000 3", "output": "YES" }, { "input": "13099714659575475 6549849616514894", "output": "NO" }, { "input": "100000000000000001 1", "output": "YES" }, { "input": "825175814723458 324", "output": "YES" }, { "input": "20 4", "output": "YES" }, { "input": "100000176877 4", "output": "YES" }, { "input": "100000 3", "output": "YES" }, { "input": "946744073709551614 10", "output": "YES" } ]
1,637,765,097
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n,k= map(int,input().split()) if((n/k)%2==0) print("NO) else print("YES)
Title: Sasha and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. Output Specification: If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower). Demo Input: ['1 1\n', '10 4\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
```python n,k= map(int,input().split()) if((n/k)%2==0) print("NO) else print("YES) ```
-1
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4", "output": "9 2" }, { "input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8", "output": "31 68" }, { "input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1", "output": "15 15" }, { "input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2", "output": "27 13" }, { "input": "4\n1 3 2 4\n4\n3 1 2 3", "output": "8 12" }, { "input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2", "output": "15 17" } ]
1,631,296,877
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
186
22,220,800
n = int(input()) pos =[0 for i in range(n)] for i in range(n): x = int(input()) pos[x]= i+1 m = int(input()) a = 0 b = 0 for i in range(m): x = int(input()) a+=(pos[x]) b+=(n-pos[x] +1) print(a,b)
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. Output Specification: Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Demo Input: ['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n'] Demo Output: ['1 2\n', '2 1\n', '6 6\n'] Note: In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
```python n = int(input()) pos =[0 for i in range(n)] for i in range(n): x = int(input()) pos[x]= i+1 m = int(input()) a = 0 b = 0 for i in range(m): x = int(input()) a+=(pos[x]) b+=(n-pos[x] +1) print(a,b) ```
-1
486
A
Calculating Function
PROGRAMMING
800
[ "implementation", "math" ]
null
null
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*.
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Print *f*(*n*) in a single line.
[ "4\n", "5\n" ]
[ "2\n", "-3\n" ]
*f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
500
[ { "input": "4", "output": "2" }, { "input": "5", "output": "-3" }, { "input": "1000000000", "output": "500000000" }, { "input": "1000000001", "output": "-500000001" }, { "input": "1000000000000000", "output": "500000000000000" }, { "input": "100", "output": "50" }, { "input": "101", "output": "-51" }, { "input": "102", "output": "51" }, { "input": "103", "output": "-52" }, { "input": "104", "output": "52" }, { "input": "105", "output": "-53" }, { "input": "106", "output": "53" }, { "input": "107", "output": "-54" }, { "input": "108", "output": "54" }, { "input": "109", "output": "-55" }, { "input": "208170109961052", "output": "104085054980526" }, { "input": "46017661651072", "output": "23008830825536" }, { "input": "4018154546667", "output": "-2009077273334" }, { "input": "288565475053", "output": "-144282737527" }, { "input": "3052460231", "output": "-1526230116" }, { "input": "29906716", "output": "14953358" }, { "input": "87897701693326", "output": "43948850846663" }, { "input": "8240", "output": "4120" }, { "input": "577935", "output": "-288968" }, { "input": "62", "output": "31" }, { "input": "1", "output": "-1" }, { "input": "2", "output": "1" }, { "input": "9999999999999", "output": "-5000000000000" }, { "input": "1000000000000", "output": "500000000000" }, { "input": "99999999999999", "output": "-50000000000000" }, { "input": "999999999999999", "output": "-500000000000000" }, { "input": "42191359342", "output": "21095679671" }, { "input": "100000000000000", "output": "50000000000000" }, { "input": "145645214654154", "output": "72822607327077" }, { "input": "4294967296", "output": "2147483648" }, { "input": "3037000499", "output": "-1518500250" }, { "input": "10000000000001", "output": "-5000000000001" }, { "input": "100000017040846", "output": "50000008520423" }, { "input": "98979894985999", "output": "-49489947493000" } ]
1,697,117,733
2,147,483,647
Python 3
OK
TESTS
39
46
0
N = int(input()) a = -1 if N % 2 == 0: a += 1 + N else: a -= N print(a // 2)
Title: Calculating Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. Input Specification: The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). Output Specification: Print *f*(*n*) in a single line. Demo Input: ['4\n', '5\n'] Demo Output: ['2\n', '-3\n'] Note: *f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
```python N = int(input()) a = -1 if N % 2 == 0: a += 1 + N else: a -= N print(a // 2) ```
3
192
A
Funky Numbers
PROGRAMMING
1,300
[ "binary search", "brute force", "implementation" ]
null
null
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
[ "256\n", "512\n" ]
[ "YES\n", "NO\n" ]
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
500
[ { "input": "256", "output": "YES" }, { "input": "512", "output": "NO" }, { "input": "80", "output": "NO" }, { "input": "828", "output": "YES" }, { "input": "6035", "output": "NO" }, { "input": "39210", "output": "YES" }, { "input": "79712", "output": "NO" }, { "input": "190492", "output": "YES" }, { "input": "5722367", "output": "NO" }, { "input": "816761542", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "2", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "7", "output": "YES" }, { "input": "8", "output": "NO" }, { "input": "9", "output": "YES" }, { "input": "10", "output": "NO" }, { "input": "12", "output": "YES" }, { "input": "13", "output": "YES" }, { "input": "14", "output": "NO" }, { "input": "15", "output": "NO" }, { "input": "16", "output": "YES" }, { "input": "17", "output": "NO" }, { "input": "18", "output": "YES" }, { "input": "19", "output": "NO" }, { "input": "20", "output": "YES" }, { "input": "41", "output": "NO" }, { "input": "11", "output": "YES" }, { "input": "69", "output": "YES" }, { "input": "82", "output": "NO" }, { "input": "85", "output": "NO" }, { "input": "736", "output": "NO" }, { "input": "895", "output": "YES" }, { "input": "934", "output": "YES" }, { "input": "6213", "output": "YES" }, { "input": "7405", "output": "NO" }, { "input": "9919", "output": "NO" }, { "input": "40942", "output": "YES" }, { "input": "41992", "output": "NO" }, { "input": "68535", "output": "NO" }, { "input": "405718", "output": "NO" }, { "input": "1046146", "output": "YES" }, { "input": "3761248", "output": "YES" }, { "input": "6195181", "output": "YES" }, { "input": "35354345", "output": "NO" }, { "input": "81282830", "output": "NO" }, { "input": "187719774", "output": "NO" }, { "input": "296798673", "output": "NO" }, { "input": "938938476", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "999887464", "output": "YES" }, { "input": "999111944", "output": "NO" }, { "input": "999966520", "output": "YES" }, { "input": "999912080", "output": "NO" }, { "input": "999992017", "output": "YES" }, { "input": "999990474", "output": "NO" }, { "input": "999999190", "output": "YES" }, { "input": "999999125", "output": "NO" }, { "input": "999999940", "output": "YES" }, { "input": "999999995", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "999999999", "output": "YES" }, { "input": "83495494", "output": "NO" }, { "input": "968022000", "output": "YES" }, { "input": "399980000", "output": "YES" }, { "input": "4", "output": "YES" }, { "input": "999999998", "output": "NO" } ]
1,608,222,565
2,147,483,647
PyPy 3
OK
TESTS
71
310
2,457,600
n=int(input()) k=1 arr=[] while (k*(k+1))//2<=n: arr.append((k*(k+1))//2) k+=1 start=0 end=len(arr)-1 flag=0 while start<=end: k=arr[start]+arr[end] if k<n: start+=1 continue if k>n: end-=1 continue else: flag=1 break if flag==1: print ('YES') else: print ('NO')
Title: Funky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)! Input Specification: The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). Demo Input: ['256\n', '512\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
```python n=int(input()) k=1 arr=[] while (k*(k+1))//2<=n: arr.append((k*(k+1))//2) k+=1 start=0 end=len(arr)-1 flag=0 while start<=end: k=arr[start]+arr[end] if k<n: start+=1 continue if k>n: end-=1 continue else: flag=1 break if flag==1: print ('YES') else: print ('NO') ```
3
978
E
Bus Video System
PROGRAMMING
1,400
[ "combinatorics", "math" ]
null
null
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If $x$ is the number of passengers in a bus just before the current bus stop and $y$ is the number of passengers in the bus just after current bus stop, the system records the number $y-x$. So the system records show how number of passengers changed. The test run was made for single bus and $n$ bus stops. Thus, the system recorded the sequence of integers $a_1, a_2, \dots, a_n$ (exactly one number for each bus stop), where $a_i$ is the record for the bus stop $i$. The bus stops are numbered from $1$ to $n$ in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $w$ (that is, at any time in the bus there should be from $0$ to $w$ passengers inclusive).
The first line contains two integers $n$ and $w$ $(1 \le n \le 1\,000, 1 \le w \le 10^{9})$ — the number of bus stops and the capacity of the bus. The second line contains a sequence $a_1, a_2, \dots, a_n$ $(-10^{6} \le a_i \le 10^{6})$, where $a_i$ equals to the number, which has been recorded by the video system after the $i$-th bus stop.
Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $w$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.
[ "3 5\n2 1 -3\n", "2 4\n-1 1\n", "4 10\n2 4 1 2\n" ]
[ "3\n", "4\n", "2\n" ]
In the first example initially in the bus could be $0$, $1$ or $2$ passengers. In the second example initially in the bus could be $1$, $2$, $3$ or $4$ passengers. In the third example initially in the bus could be $0$ or $1$ passenger.
0
[ { "input": "3 5\n2 1 -3", "output": "3" }, { "input": "2 4\n-1 1", "output": "4" }, { "input": "4 10\n2 4 1 2", "output": "2" }, { "input": "2 10\n-1 2", "output": "9" }, { "input": "3 4\n-3 -4 4", "output": "0" }, { "input": "10 1\n-1 -1 3 -4 2 3 0 -3 3 2", "output": "0" }, { "input": "5 21\n-3 2 -4 -1 -5", "output": "11" }, { "input": "5 9\n-2 -1 2 -1 -2", "output": "6" }, { "input": "8 7\n-5 0 -3 1 -1 5 0 -6", "output": "0" }, { "input": "3 4\n-2 -1 0", "output": "2" }, { "input": "1 1000000000\n0", "output": "1000000001" }, { "input": "2 1000000000\n-1000000 -1000000", "output": "998000001" }, { "input": "2 1000000000\n1000000 -1000000", "output": "999000001" }, { "input": "2 1000000000\n-1000000 1000000", "output": "999000001" }, { "input": "2 1000000000\n1000000 1000000", "output": "998000001" }, { "input": "102 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "1 1234564\n1", "output": "1234564" }, { "input": "3 4\n1 2 3", "output": "0" } ]
1,674,223,464
2,364
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
0
import sys input = lambda: sys.stdin.readline().rstrip() # ----------------------- # n, w = map(int, input().split()) A = list(map(int, input().split())) A.reverse() mn, mx = 0, w for i in range(n): if A[i] > 0: mx = min(mx, mx-A[i]) else: mn = max(mn, mn+A[i]) print(mx+1-mn)
Title: Bus Video System Time Limit: None seconds Memory Limit: None megabytes Problem Description: The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If $x$ is the number of passengers in a bus just before the current bus stop and $y$ is the number of passengers in the bus just after current bus stop, the system records the number $y-x$. So the system records show how number of passengers changed. The test run was made for single bus and $n$ bus stops. Thus, the system recorded the sequence of integers $a_1, a_2, \dots, a_n$ (exactly one number for each bus stop), where $a_i$ is the record for the bus stop $i$. The bus stops are numbered from $1$ to $n$ in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $w$ (that is, at any time in the bus there should be from $0$ to $w$ passengers inclusive). Input Specification: The first line contains two integers $n$ and $w$ $(1 \le n \le 1\,000, 1 \le w \le 10^{9})$ — the number of bus stops and the capacity of the bus. The second line contains a sequence $a_1, a_2, \dots, a_n$ $(-10^{6} \le a_i \le 10^{6})$, where $a_i$ equals to the number, which has been recorded by the video system after the $i$-th bus stop. Output Specification: Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $w$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Demo Input: ['3 5\n2 1 -3\n', '2 4\n-1 1\n', '4 10\n2 4 1 2\n'] Demo Output: ['3\n', '4\n', '2\n'] Note: In the first example initially in the bus could be $0$, $1$ or $2$ passengers. In the second example initially in the bus could be $1$, $2$, $3$ or $4$ passengers. In the third example initially in the bus could be $0$ or $1$ passenger.
```python import sys input = lambda: sys.stdin.readline().rstrip() # ----------------------- # n, w = map(int, input().split()) A = list(map(int, input().split())) A.reverse() mn, mx = 0, w for i in range(n): if A[i] > 0: mx = min(mx, mx-A[i]) else: mn = max(mn, mn+A[i]) print(mx+1-mn) ```
0
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,551,592,347
2,147,483,647
Python 3
OK
TESTS
30
358
5,324,800
n = int(input()) A = [] for i in range(n): x, y = map(int, input().split()) A.append((y, x)) ans = i = j = 0 while i < n: s = 0 j = i while j < n and A[i][0] <= A[j][0]: s+=A[j][1] j+=1 ans += s*A[i][0] i = j print(ans)
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 = [] for i in range(n): x, y = map(int, input().split()) A.append((y, x)) ans = i = j = 0 while i < n: s = 0 j = i while j < n and A[i][0] <= A[j][0]: s+=A[j][1] j+=1 ans += s*A[i][0] i = j print(ans) ```
3
758
A
Holiday Of Equality
PROGRAMMING
800
[ "implementation", "math" ]
null
null
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
In the only line print the integer *S* — the minimum number of burles which are had to spend.
[ "5\n0 1 2 3 4\n", "5\n1 1 0 1 1\n", "3\n1 3 1\n", "1\n12\n" ]
[ "10", "1", "4", "0" ]
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
500
[ { "input": "5\n0 1 2 3 4", "output": "10" }, { "input": "5\n1 1 0 1 1", "output": "1" }, { "input": "3\n1 3 1", "output": "4" }, { "input": "1\n12", "output": "0" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281", "output": "5464380" }, { "input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353", "output": "9535765" }, { "input": "3\n1 3 2", "output": "3" }, { "input": "3\n2 1 3", "output": "3" }, { "input": "3\n2 3 1", "output": "3" }, { "input": "3\n3 1 2", "output": "3" }, { "input": "3\n3 2 1", "output": "3" }, { "input": "1\n228503", "output": "0" }, { "input": "2\n32576 550340", "output": "517764" }, { "input": "3\n910648 542843 537125", "output": "741328" }, { "input": "4\n751720 572344 569387 893618", "output": "787403" }, { "input": "6\n433864 631347 597596 794426 713555 231193", "output": "1364575" }, { "input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107", "output": "4647430" }, { "input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025", "output": "13488674" }, { "input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763", "output": "21993384" }, { "input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351", "output": "26984185" }, { "input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642", "output": "32816391" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1000000", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "99000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000", "output": "99000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "99000000" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3\n5 0 0", "output": "10" }, { "input": "5\n2 10 0 0 0", "output": "38" } ]
1,673,615,970
2,147,483,647
Python 3
OK
TESTS
41
46
0
n = int(input()) a = list(map(int, input().split())) S = 0 a.sort() a_max = a[len(a) - 1] for i in a: S = S + (a_max - i) print(S)
Title: Holiday Of Equality Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. Input Specification: The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. Output Specification: In the only line print the integer *S* — the minimum number of burles which are had to spend. Demo Input: ['5\n0 1 2 3 4\n', '5\n1 1 0 1 1\n', '3\n1 3 1\n', '1\n12\n'] Demo Output: ['10', '1', '4', '0'] Note: In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
```python n = int(input()) a = list(map(int, input().split())) S = 0 a.sort() a_max = a[len(a) - 1] for i in a: S = S + (a_max - i) print(S) ```
3
602
B
Approximating a Constant Range
PROGRAMMING
1,400
[ "dp", "implementation", "two pointers" ]
null
null
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it? You're given a sequence of *n* data points *a*1,<=...,<=*a**n*. There aren't any big jumps between consecutive data points — for each 1<=≤<=*i*<=&lt;<=*n*, it's guaranteed that |*a**i*<=+<=1<=-<=*a**i*|<=≤<=1. A range [*l*,<=*r*] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let *M* be the maximum and *m* the minimum value of *a**i* for *l*<=≤<=*i*<=≤<=*r*; the range [*l*,<=*r*] is almost constant if *M*<=-<=*m*<=≤<=1. Find the length of the longest almost constant range.
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000).
Print a single number — the maximum length of an almost constant range of the given sequence.
[ "5\n1 2 3 3 2\n", "11\n5 4 5 5 6 7 8 8 8 7 6\n" ]
[ "4\n", "5\n" ]
In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4. In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].
1,000
[ { "input": "5\n1 2 3 3 2", "output": "4" }, { "input": "11\n5 4 5 5 6 7 8 8 8 7 6", "output": "5" }, { "input": "2\n3 2", "output": "2" }, { "input": "4\n1001 1000 1000 1001", "output": "4" }, { "input": "4\n1 1 2 3", "output": "3" }, { "input": "3\n1 2 1", "output": "3" }, { "input": "3\n1 2 3", "output": "2" }, { "input": "18\n10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9", "output": "3" }, { "input": "3\n1 2 2", "output": "3" }, { "input": "4\n10 9 10 9", "output": "4" }, { "input": "4\n4 3 2 3", "output": "3" }, { "input": "4\n8 8 7 7", "output": "4" }, { "input": "3\n99998 99999 100000", "output": "2" }, { "input": "3\n100000 99999 99998", "output": "2" }, { "input": "3\n1 1 1", "output": "3" }, { "input": "2\n99999 100000", "output": "2" }, { "input": "2\n100000 100000", "output": "2" }, { "input": "2\n1 1", "output": "2" }, { "input": "15\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "15" } ]
1,553,527,155
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
21
2,000
7,065,600
n = int (input()) a = list(map(int,input().split())) check = 0 i = 0 ans = 2 mn = a[0] mx = a[0] while(i<n-1): l = 1 if check: break for j in range(i+1,n): next = a[j] # print('I:',i,'J',j,'L:',l) # print('mx', mx, 'mn', mn, 'next', next) if abs(next-mn)>1 or abs(next-mx)>1: # print('1111111111111111111111111111111') i+=1 if l>ans: ans = l mn = a[i] mx = a[i] l = 1 # print('---------------------------------------------------------------') break else: # print('22222222222222222222222222222222') l+=1 mn = min(mn,mx,next) mx = max(mn,mx,next) if j == n-1: # print('4444444444444444444444444444444444') if l>ans: ans = l check = 1 break # print('Cur L:',l) # print('---------------------------------------------------------------') print(ans)
Title: Approximating a Constant Range Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it? You're given a sequence of *n* data points *a*1,<=...,<=*a**n*. There aren't any big jumps between consecutive data points — for each 1<=≤<=*i*<=&lt;<=*n*, it's guaranteed that |*a**i*<=+<=1<=-<=*a**i*|<=≤<=1. A range [*l*,<=*r*] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let *M* be the maximum and *m* the minimum value of *a**i* for *l*<=≤<=*i*<=≤<=*r*; the range [*l*,<=*r*] is almost constant if *M*<=-<=*m*<=≤<=1. Find the length of the longest almost constant range. Input Specification: The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000). Output Specification: Print a single number — the maximum length of an almost constant range of the given sequence. Demo Input: ['5\n1 2 3 3 2\n', '11\n5 4 5 5 6 7 8 8 8 7 6\n'] Demo Output: ['4\n', '5\n'] Note: In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4. In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].
```python n = int (input()) a = list(map(int,input().split())) check = 0 i = 0 ans = 2 mn = a[0] mx = a[0] while(i<n-1): l = 1 if check: break for j in range(i+1,n): next = a[j] # print('I:',i,'J',j,'L:',l) # print('mx', mx, 'mn', mn, 'next', next) if abs(next-mn)>1 or abs(next-mx)>1: # print('1111111111111111111111111111111') i+=1 if l>ans: ans = l mn = a[i] mx = a[i] l = 1 # print('---------------------------------------------------------------') break else: # print('22222222222222222222222222222222') l+=1 mn = min(mn,mx,next) mx = max(mn,mx,next) if j == n-1: # print('4444444444444444444444444444444444') if l>ans: ans = l check = 1 break # print('Cur L:',l) # print('---------------------------------------------------------------') print(ans) ```
0
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "111010010111", "output": "11110010111" }, { "input": "11110111011100000000", "output": "1111111011100000000" }, { "input": "11110010010100001110110101110011110110100111101", "output": "1111010010100001110110101110011110110100111101" }, { "input": "1001011111010010100111111", "output": "101011111010010100111111" }, { "input": "1111111111", "output": "111111111" }, { "input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101", "output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101" }, { "input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100", "output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100" }, { "input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011", "output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011" }, { "input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011", "output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011" }, { "input": "11", "output": "1" }, { "input": "111", "output": "11" }, { "input": "111111", "output": "11111" }, { "input": "11111", "output": "1111" }, { "input": "1111", "output": "111" } ]
1,622,278,095
2,147,483,647
PyPy 3
OK
TESTS
37
372
8,908,800
def solve(): s = input() b = True z = set(s) if z.__contains__("0"): for i in s: if b and i == "0": b = False continue print(i,end="") else: print(s[1:]) return try: solve() except: pass
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input Specification: The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output Specification: In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Demo Input: ['101\n', '110010\n'] Demo Output: ['11\n', '11010\n'] Note: In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
```python def solve(): s = input() b = True z = set(s) if z.__contains__("0"): for i in s: if b and i == "0": b = False continue print(i,end="") else: print(s[1:]) return try: solve() except: pass ```
3
0
none
none
none
0
[ "none" ]
null
null
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one. Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given. Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly.
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower).
[ "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n" ]
[ "Yes\nYes\nYes\nNo\nNo\nYes\n" ]
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won. The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
0
[ { "input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000", "output": "Yes\nYes\nYes\nNo\nNo\nYes" }, { "input": "3\n1 1\n8 27\n1000 1331", "output": "Yes\nNo\nNo" }, { "input": "1\n12004 18012002", "output": "Yes" }, { "input": "1\n3331 11095561", "output": "Yes" }, { "input": "1\n2 3", "output": "No" }, { "input": "1\n1062961 1031", "output": "Yes" }, { "input": "1\n6 12", "output": "No" }, { "input": "1\n3 1", "output": "No" }, { "input": "1\n3 10", "output": "No" }, { "input": "1\n31159 970883281", "output": "Yes" }, { "input": "1\n9907 98148649", "output": "Yes" }, { "input": "1\n16 8", "output": "No" }, { "input": "1\n90 72", "output": "No" } ]
1,501,431,781
6,481
Python 3
WRONG_ANSWER
PRETESTS
1
46
4,608,000
n = int(input()) def cr(n): l, h = 0, n while l < h: m = (l+h)//2 if m**3 < n: l = m+1 else: h = m return l for _ in range(n): a, b = map(int, input().split()) p = a*b if cr(p)**3 == p: print("Yes") else: print("No")
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one. Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. Input Specification: In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given. Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly. Output Specification: For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). Demo Input: ['6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n'] Demo Output: ['Yes\nYes\nYes\nNo\nNo\nYes\n'] Note: First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won. The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
```python n = int(input()) def cr(n): l, h = 0, n while l < h: m = (l+h)//2 if m**3 < n: l = m+1 else: h = m return l for _ in range(n): a, b = map(int, input().split()) p = a*b if cr(p)**3 == p: print("Yes") else: print("No") ```
0
729
A
Interview with Oleg
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters. There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers. The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here. To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length. Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking!
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview. The second line contains the string *s* of length *n*, consisting of lowercase English letters.
Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences.
[ "7\naogogob\n", "13\nogogmgogogogo\n", "9\nogoogoogo\n" ]
[ "a***b\n", "***gmg***\n", "*********\n" ]
The first sample contains one filler word ogogo, so the interview for printing is "a***b". The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***".
500
[ { "input": "7\naogogob", "output": "a***b" }, { "input": "13\nogogmgogogogo", "output": "***gmg***" }, { "input": "9\nogoogoogo", "output": "*********" }, { "input": "32\nabcdefogoghijklmnogoopqrstuvwxyz", "output": "abcdef***ghijklmn***opqrstuvwxyz" }, { "input": "100\nggogogoooggogooggoggogggggogoogoggooooggooggoooggogoooggoggoogggoogoggogggoooggoggoggogggogoogggoooo", "output": "gg***oogg***oggoggoggggg******ggooooggooggooogg***ooggoggoogggo***ggogggoooggoggoggoggg***ogggoooo" }, { "input": "10\nogooggoggo", "output": "***oggoggo" }, { "input": "20\nooggooogooogooogooog", "output": "ooggoo***o***o***oog" }, { "input": "30\ngoggogoooggooggggoggoggoogoggo", "output": "gogg***ooggooggggoggoggo***ggo" }, { "input": "40\nogggogooggoogoogggogooogogggoogggooggooo", "output": "oggg***oggo***oggg***o***gggoogggooggooo" }, { "input": "50\noggggogoogggggggoogogggoooggooogoggogooogogggogooo", "output": "ogggg***ogggggggo***gggoooggoo***gg***o***ggg***oo" }, { "input": "60\nggoooogoggogooogogooggoogggggogogogggggogggogooogogogggogooo", "output": "ggooo***gg***o***oggooggggg***gggggoggg***o***ggg***oo" }, { "input": "70\ngogoooggggoggoggggggoggggoogooogogggggooogggogoogoogoggogggoggogoooooo", "output": "g***ooggggoggoggggggoggggo***o***gggggoooggg*********ggogggogg***ooooo" }, { "input": "80\nooogoggoooggogogoggooooogoogogooogoggggogggggogoogggooogooooooggoggoggoggogoooog", "output": "oo***ggooogg***ggoooo******o***ggggoggggg***ogggoo***oooooggoggoggogg***ooog" }, { "input": "90\nooogoggggooogoggggoooogggggooggoggoggooooooogggoggogggooggggoooooogoooogooggoooogggggooooo", "output": "oo***ggggoo***ggggoooogggggooggoggoggooooooogggoggogggooggggooooo***oo***oggoooogggggooooo" }, { "input": "100\ngooogoggooggggoggoggooooggogoogggoogogggoogogoggogogogoggogggggogggggoogggooogogoggoooggogoooooogogg", "output": "goo***ggooggggoggoggoooogg***ogggo***gggo***gg***ggogggggogggggoogggoo***ggooogg***oooo***gg" }, { "input": "100\ngoogoogggogoooooggoogooogoogoogogoooooogooogooggggoogoggogooogogogoogogooooggoggogoooogooooooggogogo", "output": "go***oggg***ooooggo***o*********oooo***o***oggggo***gg***o******oooggogg***oo***ooooogg***" }, { "input": "100\ngoogoggggogggoooggoogoogogooggoggooggggggogogggogogggoogogggoogoggoggogooogogoooogooggggogggogggoooo", "output": "go***ggggogggoooggo******oggoggoogggggg***ggg***gggo***gggo***ggogg***o***oo***oggggogggogggoooo" }, { "input": "100\nogogogogogoggogogogogogogoggogogogoogoggoggooggoggogoogoooogogoogggogogogogogoggogogogogogogogogogoe", "output": "***gg***gg******ggoggooggogg******oo***oggg***gg***e" }, { "input": "5\nogoga", "output": "***ga" }, { "input": "1\no", "output": "o" }, { "input": "100\nogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogog", "output": "***g" }, { "input": "99\nogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogo", "output": "***" }, { "input": "5\nggggg", "output": "ggggg" }, { "input": "6\ngoogoo", "output": "go***o" }, { "input": "7\nooogooo", "output": "oo***oo" }, { "input": "8\ngggggggg", "output": "gggggggg" }, { "input": "9\nogggogggg", "output": "ogggogggg" }, { "input": "10\nogogoggogo", "output": "***gg***" }, { "input": "11\noooggooggog", "output": "oooggooggog" }, { "input": "12\nogggooooggog", "output": "ogggooooggog" }, { "input": "13\nogoggogogooog", "output": "***gg***oog" }, { "input": "15\nggooogoooggoggg", "output": "ggoo***ooggoggg" }, { "input": "14\noogooooggooggo", "output": "o***oooggooggo" }, { "input": "1\na", "output": "a" }, { "input": "1\ng", "output": "g" }, { "input": "1\nz", "output": "z" }, { "input": "46\nsdfkogogogogergergogogergerogogogogoergoegogog", "output": "sdfk***gergerg***gerger***ergoeg***g" }, { "input": "86\ngdfggogogodfogogdofgoodfogodgodgfogoogdodhbofgobgbgfogoogdfogogogogogoogggsgfosogodgon", "output": "gdfgg***df***gdofgoodf***dgodgf***ogdodhbofgobgbgf***ogdf***ogggsgfos***dgon" }, { "input": "83\nergegergoogogogerogoerorogroeorgefxcfgzdgawofqpwzxcvbnmsdfkfpweoriqgtogooggsdgogoog", "output": "ergegergo***ger***erorogroeorgefxcfgzdgawofqpwzxcvbnmsdfkfpweoriqgt***oggsdg***og" }, { "input": "2\nog", "output": "og" }, { "input": "4\nogog", "output": "***g" }, { "input": "4\nogoo", "output": "***o" }, { "input": "29\naaaogogogogogogogogogogogobbb", "output": "aaa***bbb" }, { "input": "11\nogogogogogo", "output": "***" }, { "input": "9\nogogogogo", "output": "***" }, { "input": "3\nogo", "output": "***" }, { "input": "15\nogogogogogogogo", "output": "***" }, { "input": "25\nogogogogogogogogogogogogo", "output": "***" } ]
1,610,743,487
2,147,483,647
PyPy 3
OK
TESTS
48
124
2,150,400
import re n = input() cad = input() print(re.sub(r'o(go)+', '***', cad))
Title: Interview with Oleg Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters. There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers. The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here. To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length. Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking! Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview. The second line contains the string *s* of length *n*, consisting of lowercase English letters. Output Specification: Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences. Demo Input: ['7\naogogob\n', '13\nogogmgogogogo\n', '9\nogoogoogo\n'] Demo Output: ['a***b\n', '***gmg***\n', '*********\n'] Note: The first sample contains one filler word ogogo, so the interview for printing is "a***b". The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***".
```python import re n = input() cad = input() print(re.sub(r'o(go)+', '***', cad)) ```
3
987
C
Three displays
PROGRAMMING
1,400
[ "brute force", "dp", "implementation" ]
null
null
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i &lt; j &lt; k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i &lt; s_j &lt; s_k$ should be held. The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay.
The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays. The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road. The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le 10^8$) — the rent costs for each display.
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i &lt; j &lt; k$ such that $s_i &lt; s_j &lt; s_k$.
[ "5\n2 4 5 4 10\n40 30 20 10 40\n", "3\n100 101 100\n2 4 5\n", "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n" ]
[ "90\n", "-1\n", "33\n" ]
In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 &lt; s_4 &lt; s_5$ ($2 &lt; 4 &lt; 10$), and the rent cost is $40 + 10 + 40 = 90$. In the second example you can't select a valid triple of indices, so the answer is -1.
1,250
[ { "input": "5\n2 4 5 4 10\n40 30 20 10 40", "output": "90" }, { "input": "3\n100 101 100\n2 4 5", "output": "-1" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13", "output": "33" }, { "input": "3\n1 2 3\n100000000 100000000 100000000", "output": "300000000" }, { "input": "3\n999999998 999999999 1000000000\n100000000 100000000 99999999", "output": "299999999" }, { "input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754\n23219513 68171337 12183499 5549873 73542337 66661387 79397647 34495917 31413076 50918417", "output": "85904709" }, { "input": "20\n452405440 586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717802881 588066499\n61699500 83254572 59454419 27833657 55743179 99661234 94729965 75591136 62937826 3626886 73906880 3664913 39990362 94385934 33153747 23840219 64514676 14746017 13062847 65187713", "output": "72432912" }, { "input": "3\n1 2 3\n1 1 1", "output": "3" } ]
1,678,616,702
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
42,905,600
def getval(d,a,b): if d.get(a)==None: d[a]=[b] else: d[a].append(b) return d n,ans,f,d=int(input()),float("inf"),0,{} a=list(map(int,input().split())) c=list(map(int,input().split())) for i in range(n): for j in range(i+1,n): if a[j]>a[i]: d=getval(d,i,j) for i in d.keys(): for j in d[i]: if d.get(j)!=None: for k in d[j]: ans,f=min(ans,c[i]+c[j]+c[k]),1 if f: print(ans) else: print(-1)
Title: Three displays Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i &lt; j &lt; k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i &lt; s_j &lt; s_k$ should be held. The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay. Input Specification: The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays. The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road. The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le 10^8$) — the rent costs for each display. Output Specification: If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i &lt; j &lt; k$ such that $s_i &lt; s_j &lt; s_k$. Demo Input: ['5\n2 4 5 4 10\n40 30 20 10 40\n', '3\n100 101 100\n2 4 5\n', '10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n'] Demo Output: ['90\n', '-1\n', '33\n'] Note: In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 &lt; s_4 &lt; s_5$ ($2 &lt; 4 &lt; 10$), and the rent cost is $40 + 10 + 40 = 90$. In the second example you can't select a valid triple of indices, so the answer is -1.
```python def getval(d,a,b): if d.get(a)==None: d[a]=[b] else: d[a].append(b) return d n,ans,f,d=int(input()),float("inf"),0,{} a=list(map(int,input().split())) c=list(map(int,input().split())) for i in range(n): for j in range(i+1,n): if a[j]>a[i]: d=getval(d,i,j) for i in d.keys(): for j in d[i]: if d.get(j)!=None: for k in d[j]: ans,f=min(ans,c[i]+c[j]+c[k]),1 if f: print(ans) else: print(-1) ```
0
609
A
USB Flash Drives
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives. The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file. Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*.
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
[ "3\n5\n2\n1\n3\n", "3\n6\n2\n3\n2\n", "2\n5\n5\n10\n" ]
[ "2\n", "3\n", "1\n" ]
In the first example Sean needs only two USB flash drives — the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
0
[ { "input": "3\n5\n2\n1\n3", "output": "2" }, { "input": "3\n6\n2\n3\n2", "output": "3" }, { "input": "2\n5\n5\n10", "output": "1" }, { "input": "5\n16\n8\n1\n3\n4\n9", "output": "2" }, { "input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100", "output": "2" }, { "input": "12\n4773\n325\n377\n192\n780\n881\n816\n839\n223\n215\n125\n952\n8", "output": "7" }, { "input": "15\n7758\n182\n272\n763\n910\n24\n359\n583\n890\n735\n819\n66\n992\n440\n496\n227", "output": "15" }, { "input": "30\n70\n6\n2\n10\n4\n7\n10\n5\n1\n8\n10\n4\n3\n5\n9\n3\n6\n6\n4\n2\n6\n5\n10\n1\n9\n7\n2\n1\n10\n7\n5", "output": "8" }, { "input": "40\n15705\n702\n722\n105\n873\n417\n477\n794\n300\n869\n496\n572\n232\n456\n298\n473\n584\n486\n713\n934\n121\n303\n956\n934\n840\n358\n201\n861\n497\n131\n312\n957\n96\n914\n509\n60\n300\n722\n658\n820\n103", "output": "21" }, { "input": "50\n18239\n300\n151\n770\n9\n200\n52\n247\n753\n523\n263\n744\n463\n540\n244\n608\n569\n771\n32\n425\n777\n624\n761\n628\n124\n405\n396\n726\n626\n679\n237\n229\n49\n512\n18\n671\n290\n768\n632\n739\n18\n136\n413\n117\n83\n413\n452\n767\n664\n203\n404", "output": "31" }, { "input": "70\n149\n5\n3\n3\n4\n6\n1\n2\n9\n8\n3\n1\n8\n4\n4\n3\n6\n10\n7\n1\n10\n8\n4\n9\n3\n8\n3\n2\n5\n1\n8\n6\n9\n10\n4\n8\n6\n9\n9\n9\n3\n4\n2\n2\n5\n8\n9\n1\n10\n3\n4\n3\n1\n9\n3\n5\n1\n3\n7\n6\n9\n8\n9\n1\n7\n4\n4\n2\n3\n5\n7", "output": "17" }, { "input": "70\n2731\n26\n75\n86\n94\n37\n25\n32\n35\n92\n1\n51\n73\n53\n66\n16\n80\n15\n81\n100\n87\n55\n48\n30\n71\n39\n87\n77\n25\n70\n22\n75\n23\n97\n16\n75\n95\n61\n61\n28\n10\n78\n54\n80\n51\n25\n24\n90\n58\n4\n77\n40\n54\n53\n47\n62\n30\n38\n71\n97\n71\n60\n58\n1\n21\n15\n55\n99\n34\n88\n99", "output": "35" }, { "input": "70\n28625\n34\n132\n181\n232\n593\n413\n862\n887\n808\n18\n35\n89\n356\n640\n339\n280\n975\n82\n345\n398\n948\n372\n91\n755\n75\n153\n948\n603\n35\n694\n722\n293\n363\n884\n264\n813\n175\n169\n646\n138\n449\n488\n828\n417\n134\n84\n763\n288\n845\n801\n556\n972\n332\n564\n934\n699\n842\n942\n644\n203\n406\n140\n37\n9\n423\n546\n675\n491\n113\n587", "output": "45" }, { "input": "80\n248\n3\n9\n4\n5\n10\n7\n2\n6\n2\n2\n8\n2\n1\n3\n7\n9\n2\n8\n4\n4\n8\n5\n4\n4\n10\n2\n1\n4\n8\n4\n10\n1\n2\n10\n2\n3\n3\n1\n1\n8\n9\n5\n10\n2\n8\n10\n5\n3\n6\n1\n7\n8\n9\n10\n5\n10\n10\n2\n10\n1\n2\n4\n1\n9\n4\n7\n10\n8\n5\n8\n1\n4\n2\n2\n3\n9\n9\n9\n10\n6", "output": "27" }, { "input": "80\n2993\n18\n14\n73\n38\n14\n73\n77\n18\n81\n6\n96\n65\n77\n86\n76\n8\n16\n81\n83\n83\n34\n69\n58\n15\n19\n1\n16\n57\n95\n35\n5\n49\n8\n15\n47\n84\n99\n94\n93\n55\n43\n47\n51\n61\n57\n13\n7\n92\n14\n4\n83\n100\n60\n75\n41\n95\n74\n40\n1\n4\n95\n68\n59\n65\n15\n15\n75\n85\n46\n77\n26\n30\n51\n64\n75\n40\n22\n88\n68\n24", "output": "38" }, { "input": "80\n37947\n117\n569\n702\n272\n573\n629\n90\n337\n673\n589\n576\n205\n11\n284\n645\n719\n777\n271\n567\n466\n251\n402\n3\n97\n288\n699\n208\n173\n530\n782\n266\n395\n957\n159\n463\n43\n316\n603\n197\n386\n132\n799\n778\n905\n784\n71\n851\n963\n883\n705\n454\n275\n425\n727\n223\n4\n870\n833\n431\n463\n85\n505\n800\n41\n954\n981\n242\n578\n336\n48\n858\n702\n349\n929\n646\n528\n993\n506\n274\n227", "output": "70" }, { "input": "90\n413\n5\n8\n10\n7\n5\n7\n5\n7\n1\n7\n8\n4\n3\n9\n4\n1\n10\n3\n1\n10\n9\n3\n1\n8\n4\n7\n5\n2\n9\n3\n10\n10\n3\n6\n3\n3\n10\n7\n5\n1\n1\n2\n4\n8\n2\n5\n5\n3\n9\n5\n5\n3\n10\n2\n3\n8\n5\n9\n1\n3\n6\n5\n9\n2\n3\n7\n10\n3\n4\n4\n1\n5\n9\n2\n6\n9\n1\n1\n9\n9\n7\n7\n7\n8\n4\n5\n3\n4\n6\n9", "output": "59" }, { "input": "90\n4226\n33\n43\n83\n46\n75\n14\n88\n36\n8\n25\n47\n4\n96\n19\n33\n49\n65\n17\n59\n72\n1\n55\n94\n92\n27\n33\n39\n14\n62\n79\n12\n89\n22\n86\n13\n19\n77\n53\n96\n74\n24\n25\n17\n64\n71\n81\n87\n52\n72\n55\n49\n74\n36\n65\n86\n91\n33\n61\n97\n38\n87\n61\n14\n73\n95\n43\n67\n42\n67\n22\n12\n62\n32\n96\n24\n49\n82\n46\n89\n36\n75\n91\n11\n10\n9\n33\n86\n28\n75\n39", "output": "64" }, { "input": "90\n40579\n448\n977\n607\n745\n268\n826\n479\n59\n330\n609\n43\n301\n970\n726\n172\n632\n600\n181\n712\n195\n491\n312\n849\n722\n679\n682\n780\n131\n404\n293\n387\n567\n660\n54\n339\n111\n833\n612\n911\n869\n356\n884\n635\n126\n639\n712\n473\n663\n773\n435\n32\n973\n484\n662\n464\n699\n274\n919\n95\n904\n253\n589\n543\n454\n250\n349\n237\n829\n511\n536\n36\n45\n152\n626\n384\n199\n877\n941\n84\n781\n115\n20\n52\n726\n751\n920\n291\n571\n6\n199", "output": "64" }, { "input": "100\n66\n7\n9\n10\n5\n2\n8\n6\n5\n4\n10\n10\n6\n5\n2\n2\n1\n1\n5\n8\n7\n8\n10\n5\n6\n6\n5\n9\n9\n6\n3\n8\n7\n10\n5\n9\n6\n7\n3\n5\n8\n6\n8\n9\n1\n1\n1\n2\n4\n5\n5\n1\n1\n2\n6\n7\n1\n5\n8\n7\n2\n1\n7\n10\n9\n10\n2\n4\n10\n4\n10\n10\n5\n3\n9\n1\n2\n1\n10\n5\n1\n7\n4\n4\n5\n7\n6\n10\n4\n7\n3\n4\n3\n6\n2\n5\n2\n4\n9\n5\n3", "output": "7" }, { "input": "100\n4862\n20\n47\n85\n47\n76\n38\n48\n93\n91\n81\n31\n51\n23\n60\n59\n3\n73\n72\n57\n67\n54\n9\n42\n5\n32\n46\n72\n79\n95\n61\n79\n88\n33\n52\n97\n10\n3\n20\n79\n82\n93\n90\n38\n80\n18\n21\n43\n60\n73\n34\n75\n65\n10\n84\n100\n29\n94\n56\n22\n59\n95\n46\n22\n57\n69\n67\n90\n11\n10\n61\n27\n2\n48\n69\n86\n91\n69\n76\n36\n71\n18\n54\n90\n74\n69\n50\n46\n8\n5\n41\n96\n5\n14\n55\n85\n39\n6\n79\n75\n87", "output": "70" }, { "input": "100\n45570\n14\n881\n678\n687\n993\n413\n760\n451\n426\n787\n503\n343\n234\n530\n294\n725\n941\n524\n574\n441\n798\n399\n360\n609\n376\n525\n229\n995\n478\n347\n47\n23\n468\n525\n749\n601\n235\n89\n995\n489\n1\n239\n415\n122\n671\n128\n357\n886\n401\n964\n212\n968\n210\n130\n871\n360\n661\n844\n414\n187\n21\n824\n266\n713\n126\n496\n916\n37\n193\n755\n894\n641\n300\n170\n176\n383\n488\n627\n61\n897\n33\n242\n419\n881\n698\n107\n391\n418\n774\n905\n87\n5\n896\n835\n318\n373\n916\n393\n91\n460", "output": "78" }, { "input": "100\n522\n1\n5\n2\n4\n2\n6\n3\n4\n2\n10\n10\n6\n7\n9\n7\n1\n7\n2\n5\n3\n1\n5\n2\n3\n5\n1\n7\n10\n10\n4\n4\n10\n9\n10\n6\n2\n8\n2\n6\n10\n9\n2\n7\n5\n9\n4\n6\n10\n7\n3\n1\n1\n9\n5\n10\n9\n2\n8\n3\n7\n5\n4\n7\n5\n9\n10\n6\n2\n9\n2\n5\n10\n1\n7\n7\n10\n5\n6\n2\n9\n4\n7\n10\n10\n8\n3\n4\n9\n3\n6\n9\n10\n2\n9\n9\n3\n4\n1\n10\n2", "output": "74" }, { "input": "100\n32294\n414\n116\n131\n649\n130\n476\n630\n605\n213\n117\n757\n42\n109\n85\n127\n635\n629\n994\n410\n764\n204\n161\n231\n577\n116\n936\n537\n565\n571\n317\n722\n819\n229\n284\n487\n649\n304\n628\n727\n816\n854\n91\n111\n549\n87\n374\n417\n3\n868\n882\n168\n743\n77\n534\n781\n75\n956\n910\n734\n507\n568\n802\n946\n891\n659\n116\n678\n375\n380\n430\n627\n873\n350\n930\n285\n6\n183\n96\n517\n81\n794\n235\n360\n551\n6\n28\n799\n226\n996\n894\n981\n551\n60\n40\n460\n479\n161\n318\n952\n433", "output": "42" }, { "input": "100\n178\n71\n23\n84\n98\n8\n14\n4\n42\n56\n83\n87\n28\n22\n32\n50\n5\n96\n90\n1\n59\n74\n56\n96\n77\n88\n71\n38\n62\n36\n85\n1\n97\n98\n98\n32\n99\n42\n6\n81\n20\n49\n57\n71\n66\n9\n45\n41\n29\n28\n32\n68\n38\n29\n35\n29\n19\n27\n76\n85\n68\n68\n41\n32\n78\n72\n38\n19\n55\n83\n83\n25\n46\n62\n48\n26\n53\n14\n39\n31\n94\n84\n22\n39\n34\n96\n63\n37\n42\n6\n78\n76\n64\n16\n26\n6\n79\n53\n24\n29\n63", "output": "2" }, { "input": "100\n885\n226\n266\n321\n72\n719\n29\n121\n533\n85\n672\n225\n830\n783\n822\n30\n791\n618\n166\n487\n922\n434\n814\n473\n5\n741\n947\n910\n305\n998\n49\n945\n588\n868\n809\n803\n168\n280\n614\n434\n634\n538\n591\n437\n540\n445\n313\n177\n171\n799\n778\n55\n617\n554\n583\n611\n12\n94\n599\n182\n765\n556\n965\n542\n35\n460\n177\n313\n485\n744\n384\n21\n52\n879\n792\n411\n614\n811\n565\n695\n428\n587\n631\n794\n461\n258\n193\n696\n936\n646\n756\n267\n55\n690\n730\n742\n734\n988\n235\n762\n440", "output": "1" }, { "input": "100\n29\n9\n2\n10\n8\n6\n7\n7\n3\n3\n10\n4\n5\n2\n5\n1\n6\n3\n2\n5\n10\n10\n9\n1\n4\n5\n2\n2\n3\n1\n2\n2\n9\n6\n9\n7\n8\n8\n1\n5\n5\n3\n1\n5\n6\n1\n9\n2\n3\n8\n10\n8\n3\n2\n7\n1\n2\n1\n2\n8\n10\n5\n2\n3\n1\n10\n7\n1\n7\n4\n9\n6\n6\n4\n7\n1\n2\n7\n7\n9\n9\n7\n10\n4\n10\n8\n2\n1\n5\n5\n10\n5\n8\n1\n5\n6\n5\n1\n5\n6\n8", "output": "3" }, { "input": "100\n644\n94\n69\n43\n36\n54\n93\n30\n74\n56\n95\n70\n49\n11\n36\n57\n30\n59\n3\n52\n59\n90\n82\n39\n67\n32\n8\n80\n64\n8\n65\n51\n48\n89\n90\n35\n4\n54\n66\n96\n68\n90\n30\n4\n13\n97\n41\n90\n85\n17\n45\n94\n31\n58\n4\n39\n76\n95\n92\n59\n67\n46\n96\n55\n82\n64\n20\n20\n83\n46\n37\n15\n60\n37\n79\n45\n47\n63\n73\n76\n31\n52\n36\n32\n49\n26\n61\n91\n31\n25\n62\n90\n65\n65\n5\n94\n7\n15\n97\n88\n68", "output": "7" }, { "input": "100\n1756\n98\n229\n158\n281\n16\n169\n149\n239\n235\n182\n147\n215\n49\n270\n194\n242\n295\n289\n249\n19\n12\n144\n157\n92\n270\n122\n212\n97\n152\n14\n42\n12\n198\n98\n295\n154\n229\n191\n294\n5\n156\n43\n185\n184\n20\n125\n23\n10\n257\n244\n264\n79\n46\n277\n13\n22\n97\n212\n77\n293\n20\n51\n17\n109\n37\n68\n117\n51\n248\n10\n149\n179\n192\n239\n161\n13\n173\n297\n73\n43\n109\n288\n198\n81\n70\n254\n187\n277\n1\n295\n113\n95\n291\n293\n119\n205\n191\n37\n34\n116", "output": "6" }, { "input": "100\n20562\n721\n452\n11\n703\n376\n183\n197\n203\n406\n642\n346\n446\n256\n760\n201\n360\n702\n707\n388\n779\n653\n610\n497\n768\n670\n134\n780\n306\n661\n180\n259\n256\n362\n6\n121\n415\n747\n170\n67\n439\n728\n193\n622\n481\n38\n225\n343\n303\n253\n436\n305\n68\n794\n247\n291\n600\n750\n188\n199\n757\n28\n776\n749\n253\n351\n53\n629\n129\n578\n209\n89\n651\n262\n638\n353\n469\n31\n144\n460\n176\n535\n562\n366\n639\n234\n577\n364\n761\n617\n303\n450\n778\n311\n289\n221\n274\n239\n626\n194\n36", "output": "30" }, { "input": "100\n32630\n548\n21\n756\n138\n56\n719\n97\n86\n599\n531\n464\n137\n737\n239\n626\n179\n170\n271\n335\n178\n298\n597\n616\n104\n190\n216\n333\n606\n621\n310\n70\n286\n593\n655\n472\n556\n77\n625\n744\n395\n487\n762\n316\n469\n258\n475\n596\n651\n180\n737\n101\n511\n708\n163\n713\n475\n557\n649\n705\n583\n97\n447\n119\n91\n372\n194\n394\n667\n384\n635\n611\n746\n758\n613\n54\n508\n405\n188\n570\n254\n28\n599\n767\n115\n737\n194\n148\n686\n705\n236\n762\n613\n770\n633\n401\n773\n448\n274\n141\n718", "output": "52" }, { "input": "1\n1\n1", "output": "1" } ]
1,563,547,812
2,147,483,647
Python 3
OK
TESTS
34
109
0
# s n=int(input()) k=int(input()) a=[] for i in range(n): a.append(int(input())) a.sort(reverse=True) i=0 while k>0: k-=a[i] i+=1 print(i)
Title: USB Flash Drives Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. Input Specification: The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives. The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file. Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*. Output Specification: Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. Demo Input: ['3\n5\n2\n1\n3\n', '3\n6\n2\n3\n2\n', '2\n5\n5\n10\n'] Demo Output: ['2\n', '3\n', '1\n'] Note: In the first example Sean needs only two USB flash drives — the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
```python # s n=int(input()) k=int(input()) a=[] for i in range(n): a.append(int(input())) a.sort(reverse=True) i=0 while k>0: k-=a[i] i+=1 print(i) ```
3
745
B
Hongcow Solves A Puzzle
PROGRAMMING
1,400
[ "implementation" ]
null
null
Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified. The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap. You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position.
The first line of input will contain two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=500), the dimensions of the puzzle piece. The next *n* lines will describe the jigsaw piece. Each line will have length *m* and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region.
Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise.
[ "2 3\nXXX\nXXX\n", "2 2\n.X\nXX\n", "5 5\n.....\n..X..\n.....\n.....\n.....\n" ]
[ "YES\n", "NO\n", "YES\n" ]
For the first sample, one example of a rectangle we can form is as follows For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle. In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle:
1,000
[ { "input": "2 3\nXXX\nXXX", "output": "YES" }, { "input": "2 2\n.X\nXX", "output": "NO" }, { "input": "1 500\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.", "output": "YES" }, { "input": "10 1\n.\n.\n.\n.\nX\n.\n.\n.\n.\n.", "output": "YES" }, { "input": "8 5\nXX.XX\nX.XXX\nX.XXX\nXXX.X\nXX.XX\nXX..X\nXXX.X\nXXXX.", "output": "NO" }, { "input": "6 8\nXXXXXX..\nXXXXXXXX\n.X.X..X.\n.XXXX..X\nXX.XXXXX\nX...X..X", "output": "NO" }, { "input": "10 2\n.X\n.X\nXX\nXX\nX.\nXX\nX.\nX.\n..\n..", "output": "NO" }, { "input": "1 1\nX", "output": "YES" }, { "input": "3 3\nXXX\nX.X\nX..", "output": "NO" }, { "input": "3 3\nXX.\nXXX\n.XX", "output": "NO" }, { "input": "4 4\nXXXX\nXXXX\nXX..\nXX..", "output": "NO" }, { "input": "3 3\nX.X\nX.X\nXXX", "output": "NO" }, { "input": "3 2\nX.\nXX\n.X", "output": "NO" }, { "input": "2 1\nX\nX", "output": "YES" }, { "input": "1 2\nXX", "output": "YES" }, { "input": "2 3\n.XX\nXX.", "output": "NO" }, { "input": "5 5\nXXX..\n.XXX.\n..XXX\nXXX..\n.XXX.", "output": "NO" }, { "input": "2 4\nXX..\n.XX.", "output": "NO" }, { "input": "4 4\nXXX.\nXXX.\nX.X.\n..X.", "output": "NO" }, { "input": "2 3\nXX.\n.XX", "output": "NO" }, { "input": "3 5\nXXXX.\n.XXXX\nXXXX.", "output": "NO" }, { "input": "2 4\nXXX.\n.XXX", "output": "NO" }, { "input": "3 3\n...\n.X.\nXXX", "output": "NO" }, { "input": "3 3\n.X.\nXX.\nX..", "output": "NO" }, { "input": "3 4\nXXX.\nX.X.\nXXX.", "output": "NO" }, { "input": "4 4\n....\n....\n.XX.\n..X.", "output": "NO" }, { "input": "4 4\n....\n....\n.XXX\n..X.", "output": "NO" }, { "input": "2 6\nXXXXX.\nXXXXXX", "output": "NO" }, { "input": "3 3\nX.X\nXXX\n.X.", "output": "NO" }, { "input": "3 3\nXXX\nX.X\n..X", "output": "NO" }, { "input": "3 3\n.XX\nXX.\n.XX", "output": "NO" }, { "input": "3 8\n.XXXXXX.\nXXX..XXX\n.XXXXXX.", "output": "NO" }, { "input": "3 3\nXX.\n.XX\nXX.", "output": "NO" }, { "input": "3 3\n.XX\nXX.\nXX.", "output": "NO" }, { "input": "4 4\n....\nXXX.\nX.XX\nXXX.", "output": "NO" }, { "input": "2 2\nX.\nX.", "output": "YES" }, { "input": "2 5\n...XX\n..XX.", "output": "NO" }, { "input": "3 5\nXXX..\n.XXX.\n..XXX", "output": "NO" }, { "input": "2 6\n...XXX\n.XXX..", "output": "NO" }, { "input": "5 5\n.X.XX\n.XXX.\n.XXX.\n.XXX.\n.XXX.", "output": "NO" }, { "input": "4 4\n....\n.XXX\n..X.\n.XX.", "output": "NO" }, { "input": "2 4\n..XX\n.XX.", "output": "NO" }, { "input": "3 6\nXXX...\n.XXX..\n..XXX.", "output": "NO" }, { "input": "3 4\n.XXX\nXXX.\n.XXX", "output": "NO" } ]
1,630,761,153
2,147,483,647
Python 3
OK
TESTS
77
77
9,011,200
n, m = map(int,input().split()) ans = [] for i in range(n): s = input() x = set(s) if 'X' in x: ans.append(s) ans2 = [] a = zip(*ans) for i in a: x = set(i) if 'X' in x: ans2.append(i) def f(): for i in ans2: if '.' in i: return "NO" return "YES" print(f())
Title: Hongcow Solves A Puzzle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified. The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap. You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. Input Specification: The first line of input will contain two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=500), the dimensions of the puzzle piece. The next *n* lines will describe the jigsaw piece. Each line will have length *m* and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. Output Specification: Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. Demo Input: ['2 3\nXXX\nXXX\n', '2 2\n.X\nXX\n', '5 5\n.....\n..X..\n.....\n.....\n.....\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: For the first sample, one example of a rectangle we can form is as follows For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle. In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle:
```python n, m = map(int,input().split()) ans = [] for i in range(n): s = input() x = set(s) if 'X' in x: ans.append(s) ans2 = [] a = zip(*ans) for i in a: x = set(i) if 'X' in x: ans2.append(i) def f(): for i in ans2: if '.' in i: return "NO" return "YES" print(f()) ```
3
141
A
Amusing Joke
PROGRAMMING
800
[ "implementation", "sortings", "strings" ]
null
null
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
[ "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
500
[ { "input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "output": "YES" }, { "input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "output": "NO" }, { "input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER", "output": "NO" }, { "input": "B\nA\nAB", "output": "YES" }, { "input": "ONDOL\nJNPB\nONLNJBODP", "output": "YES" }, { "input": "Y\nW\nYW", "output": "YES" }, { "input": "OI\nM\nIMO", "output": "YES" }, { "input": "VFQRWWWACX\nGHZJPOQUSXRAQDGOGMR\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF", "output": "YES" }, { "input": "JUTCN\nPIGMZOPMEUFADQBW\nNWQGZMAIPUPOMCDUB", "output": "NO" }, { "input": "Z\nO\nZOCNDOLTBZKQLTBOLDEGXRHZGTTPBJBLSJCVSVXISQZCSFDEBXRCSGBGTHWOVIXYHACAGBRYBKBJAEPIQZHVEGLYH", "output": "NO" }, { "input": "IQ\nOQ\nQOQIGGKFNHJSGCGM", "output": "NO" }, { "input": "ROUWANOPNIGTVMIITVMZ\nOQTUPZMTKUGY\nVTVNGZITGPUNPMQOOATUUIYIWMMKZOTR", "output": "YES" }, { "input": "OVQELLOGFIOLEHXMEMBJDIGBPGEYFG\nJNKFPFFIJOFHRIFHXEWYZOPDJBZTJZKBWQTECNHRFSJPJOAPQT\nYAIPFFFEXJJNEJPLREIGODEGQZVMCOBDFKWTMWJSBEBTOFFQOHIQJLHFNXIGOHEZRZLFOKJBJPTPHPGY", "output": "YES" }, { "input": "NBJGVNGUISUXQTBOBKYHQCOOVQWUXWPXBUDLXPKX\nNSFQDFUMQDQWQ\nWXKKVNTDQQFXCUQBIMQGQHSLVGWSBFYBUPOWPBDUUJUXQNOQDNXOX", "output": "YES" }, { "input": "IJHHGKCXWDBRWJUPRDBZJLNTTNWKXLUGJSBWBOAUKWRAQWGFNL\nNJMWRMBCNPHXTDQQNZ\nWDNJRCLILNQRHWBANLTXWMJBPKUPGKJDJZAQWKTZFBRCTXHHBNXRGUQUNBNMWODGSJWW", "output": "YES" }, { "input": "SRROWANGUGZHCIEFYMQVTWVOMDWPUZJFRDUMVFHYNHNTTGNXCJ\nDJYWGLBFCCECXFHOLORDGDCNRHPWXNHXFCXQCEZUHRRNAEKUIX\nWCUJDNYHNHYOPWMHLDCDYRWBVOGHFFUKOZTXJRXJHRGWICCMRNEVNEGQWTZPNFCSHDRFCFQDCXMHTLUGZAXOFNXNVGUEXIACRERU", "output": "YES" }, { "input": "H\nJKFGHMIAHNDBMFXWYQLZRSVNOTEGCQSVUBYUOZBTNKTXPFQDCMKAGFITEUGOYDFIYQIORMFJEOJDNTFVIQEBICSNGKOSNLNXJWC\nBQSVDOGIHCHXSYNYTQFCHNJGYFIXTSOQINZOKSVQJMTKNTGFNXAVTUYEONMBQMGJLEWJOFGEARIOPKFUFCEMUBRBDNIIDFZDCLWK", "output": "YES" }, { "input": "DSWNZRFVXQ\nPVULCZGOOU\nUOLVZXNUPOQRZGWFVDSCANQTCLEIE", "output": "NO" }, { "input": "EUHTSCENIPXLTSBMLFHD\nIZAVSZPDLXOAGESUSE\nLXAELAZ", "output": "NO" }, { "input": "WYSJFEREGELSKRQRXDXCGBODEFZVSI\nPEJKMGFLBFFDWRCRFSHVEFLEBTJCVCHRJTLDTISHPOGFWPLEWNYJLMXWIAOTYOXMV\nHXERTZWLEXTPIOTFRVMEJVYFFJLRPFMXDEBNSGCEOFFCWTKIDDGCFYSJKGLHBORWEPLDRXRSJYBGASSVCMHEEJFLVI", "output": "NO" }, { "input": "EPBMDIUQAAUGLBIETKOKFLMTCVEPETWJRHHYKCKU\nHGMAETVPCFZYNNKDQXVXUALHYLOTCHM\nECGXACVKEYMCEDOTMKAUFHLHOMT", "output": "NO" }, { "input": "NUBKQEJHALANSHEIFUZHYEZKKDRFHQKAJHLAOWTZIMOCWOVVDW\nEFVOBIGAUAUSQGVSNBKNOBDMINODMFSHDL\nKLAMKNTHBFFOHVKWICHBKNDDQNEISODUSDNLUSIOAVWY", "output": "NO" }, { "input": "VXINHOMEQCATZUGAJEIUIZZLPYFGUTVLNBNWCUVMEENUXKBWBGZTMRJJVJDLVSLBABVCEUDDSQFHOYPYQTWVAGTWOLKYISAGHBMC\nZMRGXPZSHOGCSAECAPGVOIGCWEOWWOJXLGYRDMPXBLOKZVRACPYQLEQGFQCVYXAGBEBELUTDAYEAGPFKXRULZCKFHZCHVCWIRGPK\nRCVUXGQVNWFGRUDLLENNDQEJHYYVWMKTLOVIPELKPWCLSQPTAXAYEMGWCBXEVAIZGGDDRBRT", "output": "NO" }, { "input": "PHBDHHWUUTZAHELGSGGOPOQXSXEZIXHZTOKYFBQLBDYWPVCNQSXHEAXRRPVHFJBVBYCJIFOTQTWSUOWXLKMVJJBNLGTVITWTCZZ\nFUPDLNVIHRWTEEEHOOEC\nLOUSUUSZCHJBPEWIILUOXEXRQNCJEGTOBRVZLTTZAHTKVEJSNGHFTAYGY", "output": "NO" }, { "input": "GDSLNIIKTO\nJF\nPDQYFKDTNOLI", "output": "NO" }, { "input": "AHOKHEKKPJLJIIWJRCGY\nORELJCSIX\nZVWPXVFWFSWOXXLIHJKPXIOKRELYE", "output": "NO" }, { "input": "ZWCOJFORBPHXCOVJIDPKVECMHVHCOC\nTEV\nJVGTBFTLFVIEPCCHODOFOMCVZHWXVCPEH", "output": "NO" }, { "input": "AGFIGYWJLVMYZGNQHEHWKJIAWBPUAQFERMCDROFN\nPMJNHMVNRGCYZAVRWNDSMLSZHFNYIUWFPUSKKIGU\nMCDVPPRXGUAYLSDRHRURZASXUWZSIIEZCPXUVEONKNGNWRYGOSFMCKESMVJZHWWUCHWDQMLASLNNMHAU", "output": "NO" }, { "input": "XLOWVFCZSSXCSYQTIIDKHNTKNKEEDFMDZKXSPVLBIDIREDUAIN\nZKIWNDGBISDB\nSLPKLYFYSRNRMOSWYLJJDGFFENPOXYLPZFTQDANKBDNZDIIEWSUTTKYBKVICLG", "output": "NO" }, { "input": "PMUKBTRKFIAYVGBKHZHUSJYSSEPEOEWPOSPJLWLOCTUYZODLTUAFCMVKGQKRRUSOMPAYOTBTFPXYAZXLOADDEJBDLYOTXJCJYTHA\nTWRRAJLCQJTKOKWCGUH\nEWDPNXVCXWCDQCOYKKSOYTFSZTOOPKPRDKFJDETKSRAJRVCPDOBWUGPYRJPUWJYWCBLKOOTUPBESTOFXZHTYLLMCAXDYAEBUTAHM", "output": "NO" }, { "input": "QMIMGQRQDMJDPNFEFXSXQMCHEJKTWCTCVZPUAYICOIRYOWKUSIWXJLHDYWSBOITHTMINXFKBKAWZTXXBJIVYCRWKXNKIYKLDDXL\nV\nFWACCXBVDOJFIUAVYRALBYJKXXWIIFORRUHKHCXLDBZMXIYJWISFEAWTIQFIZSBXMKNOCQKVKRWDNDAMQSTKYLDNYVTUCGOJXJTW", "output": "NO" }, { "input": "XJXPVOOQODELPPWUISSYVVXRJTYBPDHJNENQEVQNVFIXSESKXVYPVVHPMOSX\nLEXOPFPVPSZK\nZVXVPYEYOYXVOISVLXPOVHEQVXPNQJIOPFDTXEUNMPEPPHELNXKKWSVSOXSBPSJDPVJVSRFQ", "output": "YES" }, { "input": "OSKFHGYNQLSRFSAHPXKGPXUHXTRBJNAQRBSSWJVEENLJCDDHFXVCUNPZAIVVO\nFNUOCXAGRRHNDJAHVVLGGEZQHWARYHENBKHP\nUOEFNWVXCUNERLKVTHAGPSHKHDYFPYWZHJKHQLSNFBJHVJANRXCNSDUGVDABGHVAOVHBJZXGRACHRXEGNRPQEAPORQSILNXFS", "output": "YES" }, { "input": "VYXYVVACMLPDHONBUTQFZTRREERBLKUJYKAHZRCTRLRCLOZYWVPBRGDQPFPQIF\nFE\nRNRPEVDRLYUQFYRZBCQLCYZEABKLRXCJLKVZBVFUEYRATOMDRTHFPGOWQVTIFPPH", "output": "YES" }, { "input": "WYXUZQJQNLASEGLHPMSARWMTTQMQLVAZLGHPIZTRVTCXDXBOLNXZPOFCTEHCXBZ\nBLQZRRWP\nGIQZXPLTTMNHQVWPPEAPLOCDMBSTHRCFLCQRRZXLVAOQEGZBRUZJXXZTMAWLZHSLWNQTYXB", "output": "YES" }, { "input": "MKVJTSSTDGKPVVDPYSRJJYEVGKBMSIOKHLZQAEWLRIBINVRDAJIBCEITKDHUCCVY\nPUJJQFHOGZKTAVNUGKQUHMKTNHCCTI\nQVJKUSIGTSVYUMOMLEGHWYKSKQTGATTKBNTKCJKJPCAIRJIRMHKBIZISEGFHVUVQZBDERJCVAKDLNTHUDCHONDCVVJIYPP", "output": "YES" }, { "input": "OKNJOEYVMZXJMLVJHCSPLUCNYGTDASKSGKKCRVIDGEIBEWRVBVRVZZTLMCJLXHJIA\nDJBFVRTARTFZOWN\nAGHNVUNJVCPLWSVYBJKZSVTFGLELZASLWTIXDDJXCZDICTVIJOTMVEYOVRNMJGRKKHRMEBORAKFCZJBR", "output": "YES" }, { "input": "OQZACLPSAGYDWHFXDFYFRRXWGIEJGSXWUONAFWNFXDTGVNDEWNQPHUXUJNZWWLBPYL\nOHBKWRFDRQUAFRCMT\nWIQRYXRJQWWRUWCYXNXALKFZGXFTLOODWRDPGURFUFUQOHPWBASZNVWXNCAGHWEHFYESJNFBMNFDDAPLDGT", "output": "YES" }, { "input": "OVIRQRFQOOWVDEPLCJETWQSINIOPLTLXHSQWUYUJNFBMKDNOSHNJQQCDHZOJVPRYVSV\nMYYDQKOOYPOOUELCRIT\nNZSOTVLJTTVQLFHDQEJONEOUOFOLYVSOIYUDNOSIQVIRMVOERCLMYSHPCQKIDRDOQPCUPQBWWRYYOXJWJQPNKH", "output": "YES" }, { "input": "WGMBZWNMSJXNGDUQUJTCNXDSJJLYRDOPEGPQXYUGBESDLFTJRZDDCAAFGCOCYCQMDBWK\nYOBMOVYTUATTFGJLYUQD\nDYXVTLQCYFJUNJTUXPUYOPCBCLBWNSDUJRJGWDOJDSQAAMUOJWSYERDYDXYTMTOTMQCGQZDCGNFBALGGDFKZMEBG", "output": "YES" }, { "input": "CWLRBPMEZCXAPUUQFXCUHAQTLPBTXUUKWVXKBHKNSSJFEXLZMXGVFHHVTPYAQYTIKXJJE\nMUFOSEUEXEQTOVLGDSCWM\nJUKEQCXOXWEHCGKFPBIGMWVJLXUONFXBYTUAXERYTXKCESKLXAEHVPZMMUFTHLXTTZSDMBJLQPEUWCVUHSQQVUASPF", "output": "YES" }, { "input": "IDQRX\nWETHO\nODPDGBHVUVSSISROHQJTUKPUCLXABIZQQPPBPKOSEWGEHRSRRNBAVLYEMZISMWWGKHVTXKUGUXEFBSWOIWUHRJGMWBMHQLDZHBWA", "output": "NO" }, { "input": "IXFDY\nJRMOU\nDF", "output": "NO" }, { "input": "JPSPZ\nUGCUB\nJMZZZZZZZZ", "output": "NO" }, { "input": "AC\nA\nBBA", "output": "NO" }, { "input": "UIKWWKXLSHTOOZOVGXKYSOJEHAUEEG\nKZXQDWJJWRXFHKJDQHJK\nXMZHTFOGEXAUJXXJUYVJIFOTKLZHDKELJWERHMGAWGKWAQKEKHIDWGGZVYOHKXRPWSJDPESFJUMKQYWBYUTHQYEFZUGKQOBHYDWB", "output": "NO" }, { "input": "PXWRXRPFLR\nPJRWWXIVHODV\nXW", "output": "NO" }, { "input": "CHTAZVHGSHCVIBK\nEQINEBKXEPYJSAZIMLDF\nZCZZZZDZMCZZEZDZZEZZZZQZZBZZZOZZCZE", "output": "NO" }, { "input": "GXPZFSELJJNDAXYRV\nUYBKPMVBSOVOJWMONLTJOJCNQKMTAHEWLHOWIIBH\nHCWNFWJPEJIWOVPTBMVCRJLSISSVNOHCKLBFMIUAIMASQWPXEYXBOXQGFEMYJLBKDCZIMJNHOJEDGGANIVYKQTUOSOVOPWHVJGXH", "output": "NO" }, { "input": "LFGJCJJDUTUP\nOVSBILTIYCJCRHKCIXCETJQJJ\nGIJJTJCLTJJJ", "output": "NO" }, { "input": "GIO\nPRL\nPRL", "output": "NO" }, { "input": "A\nB\nABC", "output": "NO" }, { "input": "KKK\nKKK\nZZZZZ", "output": "NO" }, { "input": "ZMYGQLDBLAPN\nZFJBKWHROVNPSJQUDFTHOCGREUFLYIWYICD\nZMJZZEDAZANKZZZZZZEZZBZDZZZZZZKHZZFZZZDZNZMDZZA", "output": "NO" } ]
1,694,108,549
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
string1=input() string2=input() string3=input() count=0 st=string1+string2 for i in range(len(st)): c=count(st[i]) d=count(string3[i]) if c==d: print("YES") else: print("NO")
Title: Amusing Joke Time Limit: None seconds Memory Limit: None megabytes Problem Description: So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning. Input Specification: The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100. Output Specification: Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. Demo Input: ['SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n', 'PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n', 'BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
```python string1=input() string2=input() string3=input() count=0 st=string1+string2 for i in range(len(st)): c=count(st[i]) d=count(string3[i]) if c==d: print("YES") else: print("NO") ```
-1
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,696,998,514
2,147,483,647
PyPy 3
OK
TESTS
35
184
0
num = input().split() num1 = [int(a) for a in num] m = num1[0] n = num1[1] s = m * n print(s // 2)
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 num = input().split() num1 = [int(a) for a in num] m = num1[0] n = num1[1] s = m * n print(s // 2) ```
3.954
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type!
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000", "output": "1" }, { "input": "12345 67890123456789123457", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "2" }, { "input": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158", "output": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158" }, { "input": "1 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "8328748239473982794239847237438782379810988324751 9328748239473982794239847237438782379810988324751", "output": "1" }, { "input": "1029398958432734901284327523909481928483573793 1029398958432734901284327523909481928483573794", "output": "1" }, { "input": "10000 1000000000", "output": "1" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "11210171722243 65715435710585778347", "output": "1" }, { "input": "2921881079263974825226940825843 767693191032295360887755303860323261471", "output": "1" }, { "input": "8025352957265704896940312528736939363590612908210603 96027920417708260814607687034511406492969694925539085", "output": "1" }, { "input": "23510978780782786207241069904470895053213996267165977112058175452757132930 210352653280909370107314249722987050753257161175393375412301228883856435481424", "output": "1" }, { "input": "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614", "output": "1" }, { "input": "15943150466658398903 15943150466658398903", "output": "15943150466658398903" }, { "input": "410470228200245407491525399055972 410470228200245407491525399055972", "output": "410470228200245407491525399055972" }, { "input": "51894705655711504622197349350106792045098781545973899451307 51894705655711504622197349350106792045098781545973899451307", "output": "51894705655711504622197349350106792045098781545973899451307" }, { "input": "60353594589897438036015726222485085035927634677598681595162804007836722215668410 60353594589897438036015726222485085035927634677598681595162804007836722215668410", "output": "60353594589897438036015726222485085035927634677598681595162804007836722215668410" }, { "input": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535 761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535", "output": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535" }, { "input": "1 2000000000", "output": "1" }, { "input": "13 1928834874", "output": "1" }, { "input": "87 2938984237482934238", "output": "1" }, { "input": "213 413", "output": "1" }, { "input": "3 4", "output": "1" } ]
1,667,547,988
2,147,483,647
Python 3
OK
TESTS
28
46
0
a,b=input().split() if b != a: print(1) else: print(a)
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type! Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). Output Specification: Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. Demo Input: ['1 2\n', '61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n'] Demo Output: ['1\n', '61803398874989484820458683436563811772030917980576\n'] Note: none
```python a,b=input().split() if b != a: print(1) else: print(a) ```
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,619,431,355
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
16
951
14,438,400
def read_graph(): V = int(input()) G = [[] for _ in range(V)] for k in range(V - 1): u, v = map(int, input().split()) G[u - 1].append(v - 1) G[v - 1].append(u - 1) return G def dfs(G, v, vis, parts): vis[v] = True for u in G[v]: if not vis[u]: parts[u] = 3 - parts[v] dfs(G, u, vis, parts) G = read_graph() V = len(G) vis = [False] * V parts = [1] + [0] * (V - 1) dfs(G, 0, vis, parts) p1 = parts.count(1) print(p1 * (V - p1) - (V - 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 def read_graph(): V = int(input()) G = [[] for _ in range(V)] for k in range(V - 1): u, v = map(int, input().split()) G[u - 1].append(v - 1) G[v - 1].append(u - 1) return G def dfs(G, v, vis, parts): vis[v] = True for u in G[v]: if not vis[u]: parts[u] = 3 - parts[v] dfs(G, u, vis, parts) G = read_graph() V = len(G) vis = [False] * V parts = [1] + [0] * (V - 1) dfs(G, 0, vis, parts) p1 = parts.count(1) print(p1 * (V - p1) - (V - 1)) ```
-1
377
A
Maze
PROGRAMMING
1,600
[ "dfs and similar" ]
null
null
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him.
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=&lt;<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze. Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.
Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
[ "3 4 2\n#..#\n..#.\n#...\n", "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n" ]
[ "#.X#\nX.#.\n#...\n", "#XXX\n#X#.\nX#..\n...#\n.#.#\n" ]
none
500
[ { "input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#" }, { "input": "3 3 2\n#.#\n...\n#.#", "output": "#X#\nX..\n#.#" }, { "input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#", "output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#...\nX#...#.\nX.#.#..\n#.....#" }, { "input": "1 1 0\n.", "output": "." }, { "input": "2 3 1\n..#\n#..", "output": "X.#\n#.." }, { "input": "2 3 1\n#..\n..#", "output": "#.X\n..#" }, { "input": "3 3 1\n...\n.#.\n..#", "output": "...\n.#X\n..#" }, { "input": "3 3 1\n...\n.#.\n#..", "output": "...\nX#.\n#.." }, { "input": "5 4 4\n#..#\n....\n.##.\n....\n#..#", "output": "#XX#\nXX..\n.##.\n....\n#..#" }, { "input": "5 5 2\n.#..#\n..#.#\n#....\n##.#.\n###..", "output": "X#..#\nX.#.#\n#....\n##.#.\n###.." }, { "input": "4 6 3\n#.....\n#.#.#.\n.#...#\n...#.#", "output": "#.....\n#X#.#X\nX#...#\n...#.#" }, { "input": "7 5 4\n.....\n.#.#.\n#...#\n.#.#.\n.#...\n..#..\n....#", "output": "X...X\nX#.#X\n#...#\n.#.#.\n.#...\n..#..\n....#" }, { "input": "16 14 19\n##############\n..############\n#.############\n#..###########\n....##########\n..############\n.#############\n.#.###########\n....##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###....#......\n#...#...##.###", "output": "##############\nXX############\n#X############\n#XX###########\nXXXX##########\nXX############\nX#############\nX#.###########\nX...##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###...X#......\n#X..#XXX##.###" }, { "input": "10 17 32\n######.##########\n####.#.##########\n...#....#########\n.........########\n##.......########\n........#########\n#.....###########\n#################\n#################\n#################", "output": "######X##########\n####X#X##########\nXXX#XXXX#########\nXXXXXXXXX########\n##XXX.XXX########\nXXXX...X#########\n#XX...###########\n#################\n#################\n#################" }, { "input": "16 10 38\n##########\n##########\n##########\n..########\n...#######\n...#######\n...#######\n....######\n.....####.\n......###.\n......##..\n.......#..\n.........#\n.........#\n.........#\n.........#", "output": "##########\n##########\n##########\nXX########\nXXX#######\nXXX#######\nXXX#######\nXXXX######\nXXXXX####.\nXXXXX.###.\nXXXX..##..\nXXX....#..\nXXX......#\nXX.......#\nX........#\n.........#" }, { "input": "15 16 19\n########.....###\n########.....###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n.....#####.#..##\n................\n.#...........###\n###.########.###\n###.########.###", "output": "########XXXXX###\n########XXXXX###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\nXXXX.#####.#..##\nXXX.............\nX#...........###\n###.########.###\n###X########.###" }, { "input": "12 19 42\n.........##########\n...................\n.##.##############.\n..################.\n..#################\n..#################\n..#################\n..#################\n..#################\n..#################\n..##########.######\n.............######", "output": "XXXXXXXXX##########\nXXXXXXXXXXXXXXXXXXX\nX##X##############X\nXX################X\nXX#################\nXX#################\nXX#################\nX.#################\nX.#################\n..#################\n..##########.######\n.............######" }, { "input": "3 5 1\n#...#\n..#..\n..#..", "output": "#...#\n..#..\nX.#.." }, { "input": "4 5 10\n.....\n.....\n..#..\n..#..", "output": "XXX..\nXXX..\nXX#..\nXX#.." }, { "input": "3 5 3\n.....\n..#..\n..#..", "output": ".....\nX.#..\nXX#.." }, { "input": "3 5 1\n#....\n..#..\n..###", "output": "#....\n..#.X\n..###" }, { "input": "4 5 1\n.....\n.##..\n..#..\n..###", "output": ".....\n.##..\n..#.X\n..###" }, { "input": "3 5 2\n..#..\n..#..\n....#", "output": "X.#..\nX.#..\n....#" }, { "input": "10 10 1\n##########\n##......##\n#..#..#..#\n#..####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########", "output": "##########\n##......##\n#..#..#..#\n#X.####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########" }, { "input": "10 10 3\n..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######..\n.#######..\n.####..###\n.......###", "output": "..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######X.\n.#######XX\n.####..###\n.......###" }, { "input": "5 7 10\n..#....\n..#.#..\n.##.#..\n..#.#..\n....#..", "output": "XX#....\nXX#.#..\nX##.#..\nXX#.#..\nXXX.#.." }, { "input": "5 7 10\n..#....\n..#.##.\n.##.##.\n..#.#..\n....#..", "output": "XX#....\nXX#.##.\nX##.##.\nXX#.#..\nXXX.#.." }, { "input": "10 10 1\n##########\n##..##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########", "output": "##########\n##.X##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########" }, { "input": "4 5 1\n.....\n.###.\n..#..\n..#..", "output": ".....\n.###.\n..#..\n.X#.." }, { "input": "2 5 2\n###..\n###..", "output": "###X.\n###X." }, { "input": "2 5 3\n.....\n..#..", "output": "X....\nXX#.." }, { "input": "12 12 3\n############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######..#\n#.#######..#\n#.####..####\n#.......####\n############", "output": "############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######X.#\n#.#######XX#\n#.####..####\n#.......####\n############" }, { "input": "5 5 1\n.....\n.##..\n..###\n..###\n#####", "output": ".....\n.##.X\n..###\n..###\n#####" }, { "input": "4 4 1\n....\n.#..\n..##\n..##", "output": "....\n.#.X\n..##\n..##" }, { "input": "5 5 1\n....#\n.##..\n.##..\n...##\n...##", "output": "....#\n.##..\n.##.X\n...##\n...##" }, { "input": "5 5 1\n.....\n.##..\n..###\n..###\n..###", "output": ".....\n.##.X\n..###\n..###\n..###" }, { "input": "4 5 1\n#....\n#.#..\n..###\n..###", "output": "#....\n#.#.X\n..###\n..###" }, { "input": "4 4 3\n....\n.#..\n..##\n..##", "output": "...X\n.#XX\n..##\n..##" }, { "input": "4 7 6\n.......\n....#..\n.##.#..\n....#..", "output": "X......\nX...#..\nX##.#..\nXXX.#.." }, { "input": "8 8 7\n........\n.##.....\n.#######\n..######\n..######\n..######\n..######\n..######", "output": ".....XXX\n.##.XXXX\n.#######\n..######\n..######\n..######\n..######\n..######" } ]
1,662,721,779
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
import random def main(): n, m, k = [ int(s) for s in input().split(' ') ] array = [ [c for c in input()] for i in range(n) ] removed = 0 while removed < k: i = random.randint(0, n-1) j = random.randint(0, m-1) if array[i][j] == '.': array[i][j] = '#' removed += 1 print('\n'.join([''.join(row) for row in array])) if __name__ == '__main__': main()
Title: Maze Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him. Input Specification: The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=&lt;<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze. Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall. Output Specification: Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them. Demo Input: ['3 4 2\n#..#\n..#.\n#...\n', '5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n'] Demo Output: ['#.X#\nX.#.\n#...\n', '#XXX\n#X#.\nX#..\n...#\n.#.#\n'] Note: none
```python import random def main(): n, m, k = [ int(s) for s in input().split(' ') ] array = [ [c for c in input()] for i in range(n) ] removed = 0 while removed < k: i = random.randint(0, n-1) j = random.randint(0, m-1) if array[i][j] == '.': array[i][j] = '#' removed += 1 print('\n'.join([''.join(row) for row in array])) if __name__ == '__main__': main() ```
0
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "input": "2 3", "output": "2 0 4" }, { "input": "5 6", "output": "5 0 1" }, { "input": "4 4", "output": "0 6 0" }, { "input": "1 1", "output": "0 6 0" }, { "input": "6 4", "output": "1 1 4" }, { "input": "1 4", "output": "2 0 4" }, { "input": "5 5", "output": "0 6 0" }, { "input": "4 5", "output": "4 0 2" }, { "input": "4 3", "output": "3 0 3" }, { "input": "1 5", "output": "2 1 3" }, { "input": "6 5", "output": "1 0 5" }, { "input": "2 2", "output": "0 6 0" }, { "input": "1 3", "output": "1 1 4" }, { "input": "3 6", "output": "4 0 2" }, { "input": "3 1", "output": "4 1 1" }, { "input": "3 2", "output": "4 0 2" }, { "input": "3 5", "output": "3 1 2" }, { "input": "3 3", "output": "0 6 0" }, { "input": "6 2", "output": "2 1 3" }, { "input": "4 1", "output": "4 0 2" }, { "input": "5 2", "output": "3 0 3" }, { "input": "4 2", "output": "3 1 2" }, { "input": "2 1", "output": "5 0 1" }, { "input": "6 1", "output": "3 0 3" }, { "input": "4 6", "output": "4 1 1" }, { "input": "2 6", "output": "3 1 2" }, { "input": "3 4", "output": "3 0 3" }, { "input": "1 2", "output": "1 0 5" }, { "input": "6 6", "output": "0 6 0" }, { "input": "5 4", "output": "2 0 4" }, { "input": "3 3", "output": "0 6 0" }, { "input": "1 1", "output": "0 6 0" } ]
1,620,049,520
2,147,483,647
Python 3
OK
TESTS
38
77
0
a,b = map(int,input().split()) w=0 d=0 l=0 for i in range(1,7): if abs(i-a)>abs(i-b): l+=1 elif abs(i-a)==abs(i-b): d+=1 elif abs(i-a)<abs(i-b): w+=1 print(w,d,l)
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? Input Specification: The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. Output Specification: Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. Demo Input: ['2 5\n', '2 4\n'] Demo Output: ['3 0 3\n', '2 1 3\n'] Note: The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
```python a,b = map(int,input().split()) w=0 d=0 l=0 for i in range(1,7): if abs(i-a)>abs(i-b): l+=1 elif abs(i-a)==abs(i-b): d+=1 elif abs(i-a)<abs(i-b): w+=1 print(w,d,l) ```
3
515
A
Drazil and Date
PROGRAMMING
1,000
[ "math" ]
null
null
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling. Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda?
You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line.
If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes). Otherwise, print "Yes".
[ "5 5 11\n", "10 15 25\n", "0 5 1\n", "0 0 2\n" ]
[ "No\n", "Yes\n", "No\n", "Yes\n" ]
In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
500
[ { "input": "5 5 11", "output": "No" }, { "input": "10 15 25", "output": "Yes" }, { "input": "0 5 1", "output": "No" }, { "input": "0 0 2", "output": "Yes" }, { "input": "999999999 999999999 2000000000", "output": "Yes" }, { "input": "-606037695 998320124 820674098", "output": "No" }, { "input": "948253616 -83299062 1031552680", "output": "Yes" }, { "input": "711980199 216568284 928548487", "output": "Yes" }, { "input": "-453961301 271150176 725111473", "output": "No" }, { "input": "0 0 2000000000", "output": "Yes" }, { "input": "0 0 1999999999", "output": "No" }, { "input": "1000000000 1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 -1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 -1000000000 1000000000", "output": "No" }, { "input": "-1 -1 3", "output": "No" }, { "input": "919785634 216774719 129321944", "output": "No" }, { "input": "-467780354 -721273539 1369030008", "output": "No" }, { "input": "-232833910 -880680184 1774549792", "output": "Yes" }, { "input": "45535578 402686155 1011249824", "output": "No" }, { "input": "-203250176 -30379840 233630015", "output": "No" }, { "input": "-814516648 -75830576 890347222", "output": "No" }, { "input": "869184175 -511854751 1381038923", "output": "No" }, { "input": "552884998 -262338193 815223187", "output": "No" }, { "input": "-133874494 857573117 991447611", "output": "Yes" }, { "input": "169406792 786701289 956108082", "output": "No" }, { "input": "30237137 -989203246 1019440385", "output": "Yes" }, { "input": "576608216 -617624133 1194232352", "output": "No" }, { "input": "-662360368 97618995 759979367", "output": "Yes" }, { "input": "-115989290 321714461 437703756", "output": "No" }, { "input": "-1 -3 2", "output": "No" }, { "input": "-2 -2 2", "output": "No" }, { "input": "0 0 1", "output": "No" }, { "input": "0 -1 7", "output": "Yes" }, { "input": "1 2 7", "output": "Yes" }, { "input": "0 5 6", "output": "No" }, { "input": "0 -4 2", "output": "No" }, { "input": "-5 5 2", "output": "No" }, { "input": "-5 -2 7", "output": "Yes" }, { "input": "5 -5 2", "output": "No" } ]
1,611,040,470
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
77
0
a, b, s = map(int,input().split()) a = abs(a) b = abs(b) if s<a+b: print('NO') elif a+b==0: print('YES' if s%2==0 else 'NO') elif (s-(a+b)%2)==0: print('YES') else: print('NO')
Title: Drazil and Date Time Limit: None seconds Memory Limit: None megabytes Problem Description: Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling. Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda? Input Specification: You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. Output Specification: If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes). Otherwise, print "Yes". Demo Input: ['5 5 11\n', '10 15 25\n', '0 5 1\n', '0 0 2\n'] Demo Output: ['No\n', 'Yes\n', 'No\n', 'Yes\n'] Note: In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python a, b, s = map(int,input().split()) a = abs(a) b = abs(b) if s<a+b: print('NO') elif a+b==0: print('YES' if s%2==0 else 'NO') elif (s-(a+b)%2)==0: print('YES') else: print('NO') ```
0
895
A
Pizza Separation
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=360)  — the number of pieces into which the delivered pizza was cut. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360)  — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
[ "4\n90 90 90 90\n", "3\n100 100 160\n", "1\n360\n", "4\n170 30 150 10\n" ]
[ "0\n", "40\n", "360\n", "0\n" ]
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0. Picture explaning fourth sample: <img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
500
[ { "input": "4\n90 90 90 90", "output": "0" }, { "input": "3\n100 100 160", "output": "40" }, { "input": "1\n360", "output": "360" }, { "input": "4\n170 30 150 10", "output": "0" }, { "input": "5\n10 10 10 10 320", "output": "280" }, { "input": "8\n45 45 45 45 45 45 45 45", "output": "0" }, { "input": "3\n120 120 120", "output": "120" }, { "input": "5\n110 90 70 50 40", "output": "40" }, { "input": "2\n170 190", "output": "20" }, { "input": "15\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10", "output": "10" }, { "input": "5\n30 60 180 60 30", "output": "0" }, { "input": "2\n359 1", "output": "358" }, { "input": "5\n100 100 30 100 30", "output": "40" }, { "input": "5\n36 34 35 11 244", "output": "128" }, { "input": "5\n96 94 95 71 4", "output": "18" }, { "input": "2\n85 275", "output": "190" }, { "input": "3\n281 67 12", "output": "202" }, { "input": "5\n211 113 25 9 2", "output": "62" }, { "input": "13\n286 58 6 1 1 1 1 1 1 1 1 1 1", "output": "212" }, { "input": "15\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "20\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "92" }, { "input": "50\n148 53 32 11 4 56 8 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3\n1 1 358", "output": "356" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341", "output": "322" }, { "input": "33\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 328", "output": "296" }, { "input": "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 1 1 1 1 291", "output": "222" }, { "input": "130\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231", "output": "102" }, { "input": "200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 161", "output": "0" }, { "input": "222\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 139", "output": "0" }, { "input": "10\n8 3 11 4 1 10 10 1 8 304", "output": "248" }, { "input": "12\n8 7 7 3 11 2 10 1 10 8 10 283", "output": "206" }, { "input": "13\n10 8 9 10 5 9 4 1 10 11 1 7 275", "output": "190" }, { "input": "14\n1 6 3 11 9 5 9 8 5 6 7 3 7 280", "output": "200" }, { "input": "15\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275", "output": "190" }, { "input": "30\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189", "output": "18" }, { "input": "70\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "29\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189", "output": "18" }, { "input": "35\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168", "output": "0" }, { "input": "60\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5", "output": "0" }, { "input": "71\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "63\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "81\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "47\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68", "output": "0" }, { "input": "100\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "120\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "200\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "220\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "6\n27 15 28 34 41 215", "output": "70" }, { "input": "7\n41 38 41 31 22 41 146", "output": "14" }, { "input": "8\n24 27 34 23 29 23 30 170", "output": "20" }, { "input": "9\n11 11 20 20 33 32 35 26 172", "output": "6" }, { "input": "10\n36 13 28 13 33 34 23 25 34 121", "output": "0" }, { "input": "11\n19 37 13 41 37 15 32 12 19 35 100", "output": "10" }, { "input": "12\n37 25 34 38 21 24 34 38 11 29 28 41", "output": "2" }, { "input": "13\n24 40 20 26 25 29 39 29 35 28 19 18 28", "output": "2" }, { "input": "14\n11 21 40 19 28 34 13 16 23 30 34 22 25 44", "output": "4" }, { "input": "3\n95 91 174", "output": "12" }, { "input": "4\n82 75 78 125", "output": "46" }, { "input": "6\n87 75 88 94 15 1", "output": "4" }, { "input": "10\n27 52 58 64 45 64 1 19 2 28", "output": "12" }, { "input": "50\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1", "output": "0" }, { "input": "100\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3", "output": "0" }, { "input": "150\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1", "output": "0" }, { "input": "200\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2", "output": "0" }, { "input": "5\n35 80 45 100 100", "output": "40" }, { "input": "4\n90 179 90 1", "output": "2" }, { "input": "5\n50 50 20 160 80", "output": "0" }, { "input": "5\n30 175 30 5 120", "output": "10" }, { "input": "4\n170 30 10 150", "output": "20" }, { "input": "6\n90 30 90 30 90 30", "output": "60" }, { "input": "4\n70 80 110 100", "output": "20" }, { "input": "7\n35 45 70 100 10 10 90", "output": "0" }, { "input": "6\n50 90 10 90 20 100", "output": "20" }, { "input": "6\n10 155 162 1 26 6", "output": "18" }, { "input": "7\n80 90 80 45 10 10 45", "output": "20" }, { "input": "4\n18 36 162 144", "output": "36" }, { "input": "5\n20 50 50 160 80", "output": "40" }, { "input": "5\n10 30 140 20 160", "output": "0" }, { "input": "6\n90 80 60 50 40 40", "output": "20" }, { "input": "9\n40 20 20 20 20 20 20 40 160", "output": "40" }, { "input": "4\n90 54 90 126", "output": "72" }, { "input": "4\n150 170 30 10", "output": "20" }, { "input": "8\n130 12 13 85 41 67 5 7", "output": "26" }, { "input": "7\n70 170 20 10 30 30 30", "output": "20" }, { "input": "8\n100 100 50 50 15 15 15 15", "output": "40" }, { "input": "4\n100 70 80 110", "output": "20" }, { "input": "5\n160 130 40 20 10", "output": "20" }, { "input": "4\n20 149 151 40", "output": "22" }, { "input": "4\n100 10 100 150", "output": "60" }, { "input": "6\n19 64 105 168 1 3", "output": "16" }, { "input": "8\n10 10 70 70 90 90 10 10", "output": "0" } ]
1,511,714,428
2,128
Python 3
WRONG_ANSWER
PRETESTS
4
61
5,632,000
n = int(input()) A = list(map(int, input().split())) if n == 1: print(A[0]) exit() t = float("inf") gs = sum(A) fs, ss= A[0], abs(A[0] - gs) for l in range(-n, n): for r in range(l, n): fs = sum(A[l:r]) ss = gs-fs if abs(ss-fs) < t: t = abs(ss-fs) break print(t)
Title: Pizza Separation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=360)  — the number of pieces into which the delivered pizza was cut. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360)  — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. Output Specification: Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya. Demo Input: ['4\n90 90 90 90\n', '3\n100 100 160\n', '1\n360\n', '4\n170 30 150 10\n'] Demo Output: ['0\n', '40\n', '360\n', '0\n'] Note: In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0. Picture explaning fourth sample: <img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
```python n = int(input()) A = list(map(int, input().split())) if n == 1: print(A[0]) exit() t = float("inf") gs = sum(A) fs, ss= A[0], abs(A[0] - gs) for l in range(-n, n): for r in range(l, n): fs = sum(A[l:r]) ss = gs-fs if abs(ss-fs) < t: t = abs(ss-fs) break print(t) ```
0
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,627,754,883
2,147,483,647
Python 3
OK
TESTS
38
77
6,758,400
s = input() d = {'a', 'e', 'i', 'o', 'u', '1', '3', '5', '7', '9'} ret = 0 for c in s: if c in d: ret += 1 print(ret)
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() d = {'a', 'e', 'i', 'o', 'u', '1', '3', '5', '7', '9'} ret = 0 for c in s: if c in d: ret += 1 print(ret) ```
3
758
A
Holiday Of Equality
PROGRAMMING
800
[ "implementation", "math" ]
null
null
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
In the only line print the integer *S* — the minimum number of burles which are had to spend.
[ "5\n0 1 2 3 4\n", "5\n1 1 0 1 1\n", "3\n1 3 1\n", "1\n12\n" ]
[ "10", "1", "4", "0" ]
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
500
[ { "input": "5\n0 1 2 3 4", "output": "10" }, { "input": "5\n1 1 0 1 1", "output": "1" }, { "input": "3\n1 3 1", "output": "4" }, { "input": "1\n12", "output": "0" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281", "output": "5464380" }, { "input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353", "output": "9535765" }, { "input": "3\n1 3 2", "output": "3" }, { "input": "3\n2 1 3", "output": "3" }, { "input": "3\n2 3 1", "output": "3" }, { "input": "3\n3 1 2", "output": "3" }, { "input": "3\n3 2 1", "output": "3" }, { "input": "1\n228503", "output": "0" }, { "input": "2\n32576 550340", "output": "517764" }, { "input": "3\n910648 542843 537125", "output": "741328" }, { "input": "4\n751720 572344 569387 893618", "output": "787403" }, { "input": "6\n433864 631347 597596 794426 713555 231193", "output": "1364575" }, { "input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107", "output": "4647430" }, { "input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025", "output": "13488674" }, { "input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763", "output": "21993384" }, { "input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351", "output": "26984185" }, { "input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642", "output": "32816391" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1000000", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "99000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000", "output": "99000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "99000000" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3\n5 0 0", "output": "10" }, { "input": "5\n2 10 0 0 0", "output": "38" } ]
1,669,100,786
2,147,483,647
Python 3
OK
TESTS
41
46
0
n = int(input()) k = [int(i) for i in input().split()] p = max(k) m = 0 for i in k: m += p-i print(m)
Title: Holiday Of Equality Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. Input Specification: The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. Output Specification: In the only line print the integer *S* — the minimum number of burles which are had to spend. Demo Input: ['5\n0 1 2 3 4\n', '5\n1 1 0 1 1\n', '3\n1 3 1\n', '1\n12\n'] Demo Output: ['10', '1', '4', '0'] Note: In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
```python n = int(input()) k = [int(i) for i in input().split()] p = max(k) m = 0 for i in k: m += p-i print(m) ```
3
436
C
Dungeons and Candies
PROGRAMMING
1,800
[ "dsu", "graphs", "greedy", "trees" ]
null
null
During the loading of the game "Dungeons and Candies" you are required to get descriptions of *k* levels from the server. Each description is a map of an *n*<=×<=*m* checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if a cell has a candy, it is denoted as a letter of the English alphabet. A level may contain identical candies, in this case the letters in the corresponding cells of the map will be the same. When you transmit information via a network, you want to minimize traffic — the total size of the transferred data. The levels can be transmitted in any order. There are two ways to transmit the current level *A*: 1. You can transmit the whole level *A*. Then you need to transmit *n*·*m* bytes via the network. 1. You can transmit the difference between level *A* and some previously transmitted level *B* (if it exists); this operation requires to transmit *d**A*,<=*B*·*w* bytes, where *d**A*,<=*B* is the number of cells of the field that are different for *A* and *B*, and *w* is a constant. Note, that you should compare only the corresponding cells of levels *A* and *B* to calculate *d**A*,<=*B*. You cannot transform the maps of levels, i.e. rotate or shift them relatively to each other. Your task is to find a way to transfer all the *k* levels and minimize the traffic.
The first line contains four integers *n*,<=*m*,<=*k*,<=*w* (1<=≤<=*n*,<=*m*<=≤<=10; 1<=≤<=*k*,<=*w*<=≤<=1000). Then follows the description of *k* levels. Each level is described by *n* lines, each line contains *m* characters. Each character is either a letter of the English alphabet or a dot ("."). Please note that the case of the letters matters.
In the first line print the required minimum number of transferred bytes. Then print *k* pairs of integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=...,<=*x**k*,<=*y**k*, describing the way to transfer levels. Pair *x**i*, *y**i* means that level *x**i* needs to be transferred by way *y**i*. If *y**i* equals 0, that means that the level must be transferred using the first way, otherwise *y**i* must be equal to the number of a previously transferred level. It means that you will transfer the difference between levels *y**i* and *x**i* to transfer level *x**i*. Print the pairs in the order of transferring levels. The levels are numbered 1 through *k* in the order they follow in the input. If there are multiple optimal solutions, you can print any of them.
[ "2 3 3 2\nA.A\n...\nA.a\n..C\nX.Y\n...\n", "1 1 4 1\nA\n.\nB\n.\n", "1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB\n" ]
[ "14\n1 0\n2 1\n3 1\n", "3\n1 0\n2 0\n4 2\n3 0\n", "11\n1 0\n3 1\n2 3\n4 2\n5 1\n" ]
none
1,500
[ { "input": "1 1 4 1\nA\n.\nB\n.", "output": "3\n1 0\n2 0\n4 2\n3 0" }, { "input": "1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB", "output": "11\n1 0\n3 1\n2 3\n4 2\n5 1" }, { "input": "2 2 5 1\n..\nBA\n.A\nB.\n..\nA.\nAB\n.B\n..\n..", "output": "12\n1 0\n2 1\n3 1\n5 3\n4 5" }, { "input": "3 3 10 2\nBA.\n..A\n.BB\nB..\n..B\n.AA\nB..\nAB.\n..A\nBAB\n.A.\n.B.\n..B\nA..\n...\n...\n.B.\nBA.\n..B\n.AB\n.B.\nB.A\n.A.\n.BA\n..B\n...\n.A.\n.AA\n..A\n.B.", "output": "67\n1 0\n10 1\n2 1\n3 2\n4 1\n7 4\n9 7\n5 9\n6 9\n8 4" }, { "input": "3 1 5 1\nB\nA\nB\nA\nA\nB\nA\nA\nA\nA\nA\nA\nA\nA\nA", "output": "5\n1 0\n2 1\n3 2\n4 3\n5 3" }, { "input": "3 2 10 1\nAB\nBA\nAB\nAA\nAA\nBA\nAA\nAA\nAB\nAB\nAB\nBA\nBA\nAB\nAA\nBB\nAB\nBA\nBB\nBB\nBA\nAA\nAA\nAB\nAB\nAB\nBA\nBB\nAB\nAA", "output": "16\n1 0\n3 1\n8 3\n2 3\n4 2\n9 4\n6 4\n7 6\n10 6\n5 10" }, { "input": "2 3 10 2\nABB\nABA\nAAB\nBAB\nAAA\nBBA\nBBB\nBAA\nBBB\nABB\nABA\nBBA\nBBB\nAAB\nABA\nABB\nBBA\nBAB\nBBB\nBBB", "output": "38\n1 0\n5 1\n7 5\n4 7\n9 4\n10 5\n6 1\n3 6\n8 1\n2 0" }, { "input": "1 1 1 1\n.", "output": "1\n1 0" } ]
1,685,677,513
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
1
61
2,867,200
from collections import defaultdict def diff_count(a,b): if a != b: return 1 else: return 0 n, m, k, w = map(int, input().split()) g = defaultdict(dict) lvl = list() for i in range(1, k+1): g[0][i] = n*m g[i][0] = n*m lvl.append([]) for _ in range(n): lvl[i-1].append(input()) for i in range(len(lvl)): for j in range(i): for l in range(n): try: g[i+1][j+1] += sum(map(diff_count, lvl[i][l], lvl[j][l])) except: g[i+1][j+1] = 0 g[i+1][j+1] += sum(map(diff_count, lvl[i][l], lvl[j][l])) answer = 0 list_answer = [] vertex = 1 for v in list(g.values())[1:]: if len(list(v.values())) == 1: answer += v[0] list_answer.append((vertex,0)) else: answer += min(v[0], min(list(v.values())[1:])*w) if min(v[0], min(list(v.values())[1:])*w) == v[0]: list_answer.append(vertex,0) else: list_answer.append((vertex,list(v.values()).index(min(list(v.values())[1:])))) vertex += 1 print(answer) for a,b in list_answer: print(a,b)
Title: Dungeons and Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the loading of the game "Dungeons and Candies" you are required to get descriptions of *k* levels from the server. Each description is a map of an *n*<=×<=*m* checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if a cell has a candy, it is denoted as a letter of the English alphabet. A level may contain identical candies, in this case the letters in the corresponding cells of the map will be the same. When you transmit information via a network, you want to minimize traffic — the total size of the transferred data. The levels can be transmitted in any order. There are two ways to transmit the current level *A*: 1. You can transmit the whole level *A*. Then you need to transmit *n*·*m* bytes via the network. 1. You can transmit the difference between level *A* and some previously transmitted level *B* (if it exists); this operation requires to transmit *d**A*,<=*B*·*w* bytes, where *d**A*,<=*B* is the number of cells of the field that are different for *A* and *B*, and *w* is a constant. Note, that you should compare only the corresponding cells of levels *A* and *B* to calculate *d**A*,<=*B*. You cannot transform the maps of levels, i.e. rotate or shift them relatively to each other. Your task is to find a way to transfer all the *k* levels and minimize the traffic. Input Specification: The first line contains four integers *n*,<=*m*,<=*k*,<=*w* (1<=≤<=*n*,<=*m*<=≤<=10; 1<=≤<=*k*,<=*w*<=≤<=1000). Then follows the description of *k* levels. Each level is described by *n* lines, each line contains *m* characters. Each character is either a letter of the English alphabet or a dot ("."). Please note that the case of the letters matters. Output Specification: In the first line print the required minimum number of transferred bytes. Then print *k* pairs of integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=...,<=*x**k*,<=*y**k*, describing the way to transfer levels. Pair *x**i*, *y**i* means that level *x**i* needs to be transferred by way *y**i*. If *y**i* equals 0, that means that the level must be transferred using the first way, otherwise *y**i* must be equal to the number of a previously transferred level. It means that you will transfer the difference between levels *y**i* and *x**i* to transfer level *x**i*. Print the pairs in the order of transferring levels. The levels are numbered 1 through *k* in the order they follow in the input. If there are multiple optimal solutions, you can print any of them. Demo Input: ['2 3 3 2\nA.A\n...\nA.a\n..C\nX.Y\n...\n', '1 1 4 1\nA\n.\nB\n.\n', '1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB\n'] Demo Output: ['14\n1 0\n2 1\n3 1\n', '3\n1 0\n2 0\n4 2\n3 0\n', '11\n1 0\n3 1\n2 3\n4 2\n5 1\n'] Note: none
```python from collections import defaultdict def diff_count(a,b): if a != b: return 1 else: return 0 n, m, k, w = map(int, input().split()) g = defaultdict(dict) lvl = list() for i in range(1, k+1): g[0][i] = n*m g[i][0] = n*m lvl.append([]) for _ in range(n): lvl[i-1].append(input()) for i in range(len(lvl)): for j in range(i): for l in range(n): try: g[i+1][j+1] += sum(map(diff_count, lvl[i][l], lvl[j][l])) except: g[i+1][j+1] = 0 g[i+1][j+1] += sum(map(diff_count, lvl[i][l], lvl[j][l])) answer = 0 list_answer = [] vertex = 1 for v in list(g.values())[1:]: if len(list(v.values())) == 1: answer += v[0] list_answer.append((vertex,0)) else: answer += min(v[0], min(list(v.values())[1:])*w) if min(v[0], min(list(v.values())[1:])*w) == v[0]: list_answer.append(vertex,0) else: list_answer.append((vertex,list(v.values()).index(min(list(v.values())[1:])))) vertex += 1 print(answer) for a,b in list_answer: print(a,b) ```
-1
789
A
Anastasia and pebbles
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day. Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
[ "3 2\n2 3 4\n", "5 4\n3 1 8 9 7\n" ]
[ "3\n", "5\n" ]
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type.
500
[ { "input": "3 2\n2 3 4", "output": "3" }, { "input": "5 4\n3 1 8 9 7", "output": "5" }, { "input": "1 22\n1", "output": "1" }, { "input": "3 57\n78 165 54", "output": "3" }, { "input": "5 72\n74 10 146 189 184", "output": "6" }, { "input": "9 13\n132 87 200 62 168 51 185 192 118", "output": "48" }, { "input": "1 1\n10000", "output": "5000" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "5" }, { "input": "2 2\n2 2", "output": "1" } ]
1,490,806,834
3,334
Python 3
WRONG_ANSWER
PRETESTS
3
77
5,222,400
# -*- coding: utf-8 -*- n, k = map(int, input().split(' ')) w = sorted(list(map(int, input().split(' '))), reverse=True) c = 0 for i in range(len(w)): if w[i]!=0: x = w[i]%k w[i]=x c += 1 i+=1 print(c)
Title: Anastasia and pebbles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day. Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. Output Specification: The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. Demo Input: ['3 2\n2 3 4\n', '5 4\n3 1 8 9 7\n'] Demo Output: ['3\n', '5\n'] Note: In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type.
```python # -*- coding: utf-8 -*- n, k = map(int, input().split(' ')) w = sorted(list(map(int, input().split(' '))), reverse=True) c = 0 for i in range(len(w)): if w[i]!=0: x = w[i]%k w[i]=x c += 1 i+=1 print(c) ```
0
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
1,688,139,841
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
a = int(input('')) b = input('') dima = 0 sereja = 0 c = b.split() for k in range(len(c)): c[k] = int(c[k]) turno = 0 print(type(max(c))) for j in range(a): for k in range(len(c)): if turno%2 == 0: if int(c[k]) == int(max(c)): sereja = sereja + int(c[k]) turno = turno + 1 del c[k] break else: if int(c[k]) == max(c): dima = dima + int(c[k]) turno = turno + 1 del c[k] break print(sereja, dima)
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python a = int(input('')) b = input('') dima = 0 sereja = 0 c = b.split() for k in range(len(c)): c[k] = int(c[k]) turno = 0 print(type(max(c))) for j in range(a): for k in range(len(c)): if turno%2 == 0: if int(c[k]) == int(max(c)): sereja = sereja + int(c[k]) turno = turno + 1 del c[k] break else: if int(c[k]) == max(c): dima = dima + int(c[k]) turno = turno + 1 del c[k] break print(sereja, dima) ```
0