contestId int64 0 1.01k | index stringclasses 55
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 7 | title stringclasses 495
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 5 65.5k | instruction_seed stringlengths 262 8.2k | response stringlengths 19 65.5k | score float64 -1 3.99 | _source stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
814 | B | An express train to reveries | PROGRAMMING | 1,300 | [
"constructive algorithms"
] | null | null | Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.
On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of intege... | The first line of input contains a positive integer *n* (2<=≤<=*n*<=≤<=1<=000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of colours in the firs... | Output *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n*, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.
Input guarantees that such permutation exists. | [
"5\n1 2 3 4 3\n1 2 5 4 5\n",
"5\n4 4 2 3 1\n5 4 5 3 1\n",
"4\n1 1 3 4\n1 4 3 4\n"
] | [
"1 2 5 4 3\n",
"5 4 2 3 1\n",
"1 2 3 4\n"
] | In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.
In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints. | 1,000 | [
{
"input": "5\n1 2 3 4 3\n1 2 5 4 5",
"output": "1 2 5 4 3"
},
{
"input": "5\n4 4 2 3 1\n5 4 5 3 1",
"output": "5 4 2 3 1"
},
{
"input": "4\n1 1 3 4\n1 4 3 4",
"output": "1 2 3 4"
},
{
"input": "10\n1 2 3 4 7 6 7 8 9 10\n1 2 3 4 5 6 5 8 9 10",
"output": "1 2 3 4 5 6 7 8 9... | 1,641,322,818 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 21 | 77 | 1,331,200 | t=1
for i in range(t):
n=int(input())
L1=list(map(int,input().split()))
L2=list(map(int,input().split()))
diff_cnt=0
for i in range(n):
if L1[i]!=L2[i]:
diff_cnt+=1
if diff_cnt==1:
L=[0 for i in range(n)]
for i in range(n):
if L1[i]==L2... | Title: An express train to reveries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her... | ```python
t=1
for i in range(t):
n=int(input())
L1=list(map(int,input().split()))
L2=list(map(int,input().split()))
diff_cnt=0
for i in range(n):
if L1[i]!=L2[i]:
diff_cnt+=1
if diff_cnt==1:
L=[0 for i in range(n)]
for i in range(n):
if... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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 consis... | 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 cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,580,804,293 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 436 | 2,048,000 | """
author - Sayan Bose
date - 29.01.2020
Brooklyn 99 is love!
"""
s = input()
t = 'NO'
for i in s:
if i == '0':
t = i
if t != 'NO':
print(s[:t] + s[t+1:])
else:
print(s[:-1]) | 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... | ```python
"""
author - Sayan Bose
date - 29.01.2020
Brooklyn 99 is love!
"""
s = input()
t = 'NO'
for i in s:
if i == '0':
t = i
if t != 'NO':
print(s[:t] + s[t+1:])
else:
print(s[:-1])
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,670,303,496 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 46 | 0 | #8, 4, 2, 6, 8...
n = int(input())
a = [8, 4, 2, 6]
if a == 0:
print(1)
else:
print(a[n%4-1])
| Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
#8, 4, 2, 6, 8...
n = int(input())
a = [8, 4, 2, 6]
if a == 0:
print(1)
else:
print(a[n%4-1])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,643,263,624 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | n=input()
k=0
while n[0]!='4':
if n[k:k+3]=='144':k=k+3
if n[k:k+2]=='14':k=k+2
if n[k:k+1]=='1':k=k+1
print('YES');exit()
else:print('NO')
| Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
n=input()
k=0
while n[0]!='4':
if n[k:k+3]=='144':k=k+3
if n[k:k+2]=='14':k=k+2
if n[k:k+1]=='1':k=k+1
print('YES');exit()
else:print('NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,697,440,028 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 92 | 0 | txt = input()
x = []
for char in txt:
if char in txt:
x.append(char)
txt = txt.replace(char, "")
if len(x) % 2 == 0:
print("CHAT WITH HER!")
else:
print("IGNORE HIM!") | Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
txt = input()
x = []
for char in txt:
if char in txt:
x.append(char)
txt = txt.replace(char, "")
if len(x) % 2 == 0:
print("CHAT WITH HER!")
else:
print("IGNORE HIM!")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,645,972,004 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n = int(input())
stones = list(map(int, input().split()))
sorted_stones = sorted(stones, reverse=True)
a = [0]*(n+1)
a_sorted = [0]*(n+1)
for i in range(1, n+1): a[i] = stones[i-1] + a[i-1]
for i in range(1, n+1): a_sorted[i] = stones[i-1] + a_sorted[i-1]
for i in range(int(input())):
type, l, r = map(int, in... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
n = int(input())
stones = list(map(int, input().split()))
sorted_stones = sorted(stones, reverse=True)
a = [0]*(n+1)
a_sorted = [0]*(n+1)
for i in range(1, n+1): a[i] = stones[i-1] + a[i-1]
for i in range(1, n+1): a_sorted[i] = stones[i-1] + a_sorted[i-1]
for i in range(int(input())):
type, l, r = m... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
216 | B | Forming Teams | PROGRAMMING | 1,700 | [
"dfs and similar",
"implementation"
] | null | null | One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student *A* is an archenemy to student *B*, then stud... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100) — the number of students and the number of pairs of archenemies correspondingly.
Next *m* lines describe enmity between students. Each enmity is described as two numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=... | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | [
"5 4\n1 2\n2 4\n5 3\n1 4\n",
"6 2\n1 4\n3 4\n",
"6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n"
] | [
"1",
"0",
"2"
] | none | 1,500 | [
{
"input": "5 4\n1 2\n2 4\n5 3\n1 4",
"output": "1"
},
{
"input": "6 2\n1 4\n3 4",
"output": "0"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "2"
},
{
"input": "5 1\n1 2",
"output": "1"
},
{
"input": "8 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 1",
... | 1,652,204,763 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 60 | 0 | """
One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then stu... | Title: Forming Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each stu... | ```python
"""
One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{... | 1,632,341,858 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 20,172,800 | num = input()
bids = []
for x in input().split():
bids.append(x)
winner = bids.index(max(bids))
bids.pop(winner)
price = max(bids)
print(winner + 1 , price) | Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is... | ```python
num = input()
bids = []
for x in input().split():
bids.append(x)
winner = bids.index(max(bids))
bids.pop(winner)
price = max(bids)
print(winner + 1 , price)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,645,673,930 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | pi = 3.1415926536
n = int(input())
circles = list(map(int, input().split()))
circles = sorted(circles)
answer = 0
for i in range(0, len(circles)):
if i % 2 == 0:
answer += circles[-1-i]**2 * pi
else:
answer -= circles[-1-i]**2 * pi
print(answer) | Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
pi = 3.1415926536
n = int(input())
circles = list(map(int, input().split()))
circles = sorted(circles)
answer = 0
for i in range(0, len(circles)):
if i % 2 == 0:
answer += circles[-1-i]**2 * pi
else:
answer -= circles[-1-i]**2 * pi
print(answer)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
152 | B | Steps | PROGRAMMING | 1,300 | [
"binary search",
"implementation"
] | null | null | One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple.
Vasya noticed that the yard is a rectangu... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the yard's sizes. The second line contains integers *x**c* and *y**c* — the initial square's coordinates (1<=≤<=*x**c*<=≤<=*n*,<=1<=≤<=*y**c*<=≤<=*m*).
The third line contains an integer *k* (1<=≤<=*k*<=≤<=104) — the number of vectors. ... | Print the single number — the number of steps Vasya had made.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"4 5\n1 1\n3\n1 1\n1 1\n0 -2\n",
"10 10\n1 2\n1\n-1 0\n"
] | [
"4\n",
"0\n"
] | In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,... | 1,000 | [
{
"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2",
"output": "4"
},
{
"input": "10 10\n1 2\n1\n-1 0",
"output": "0"
},
{
"input": "10 20\n10 3\n10\n-2 -6\n-1 0\n-8 0\n0 5\n-1 3\n16 -16\n-1 9\n0 -18\n9 -1\n-9 5",
"output": "13"
},
{
"input": "20 10\n14 4\n10\n6 0\n-7 -7\n12 -2\n-4 9\n2... | 1,465,673,818 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 186 | 5,120,000 | INF = 10**32
n,m = map(int,input().split(' '))
x,y = map(int,input().split(' '))
n -=1
m -=1
x -=1
y -=1
k = int(input())
nb = 0
for i in range(k):
dx,dy = map(int,input().split(' '))
v = INF
if dx>0 :
v = min(v,(n-x)//dx)
else:
if dx != 0 :
v = min(v,... | Title: Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ... | ```python
INF = 10**32
n,m = map(int,input().split(' '))
x,y = map(int,input().split(' '))
n -=1
m -=1
x -=1
y -=1
k = int(input())
nb = 0
for i in range(k):
dx,dy = map(int,input().split(' '))
v = INF
if dx>0 :
v = min(v,(n-x)//dx)
else:
if dx != 0 :
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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 consis... | 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 cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,692,312,118 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 124 | 6,246,400 | s = input()
l = list(s)
a = 0
for i in range(len(s)-2,-1,-1):
if l[i] == '0':
l.remove(l[i])
a+=1
break
if a == 1:
print(''.join(l))
else:
if l[-1] == '0':
l.remove('0')
else:
l.remove('1')
print(''.join(l)) | 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... | ```python
s = input()
l = list(s)
a = 0
for i in range(len(s)-2,-1,-1):
if l[i] == '0':
l.remove(l[i])
a+=1
break
if a == 1:
print(''.join(l))
else:
if l[-1] == '0':
l.remove('0')
else:
l.remove('1')
print(''.join(l))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
507 | A | Amr and Music | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"sortings"
] | null | null | Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments.
Amr asked for ... | The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument. | In the first line output one integer *m* representing the maximum number of instruments Amr can learn.
In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use al... | [
"4 10\n4 3 1 2\n",
"5 6\n4 3 1 1 2\n",
"1 3\n4\n"
] | [
"4\n1 2 3 4",
"3\n1 3 4",
"0\n"
] | In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument. | 500 | [
{
"input": "4 10\n4 3 1 2",
"output": "4\n1 2 3 4"
},
{
"input": "5 6\n4 3 1 1 2",
"output": "3\n3 4 5"
},
{
"input": "1 3\n4",
"output": "0"
},
{
"input": "2 100\n100 100",
"output": "1\n1"
},
{
"input": "3 150\n50 50 50",
"output": "3\n1 2 3"
},
{
"i... | 1,552,942,003 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 108 | 0 | n,k=map(int,input().split())
l=list(map(int,input().split()))
l1=[]
l2=[]
for i in range (n):
l1.append(tuple((l[i],i+1)))
l1.sort()
ans=[]
for i in range (n):
if l1[i][0]<=k:
ans.append(l1[i][1])
k-=l1[i][0]
ans.sort()
print(len(ans))
for i in range(len(ans)):
print(ans[i],en... | Title: Amr and Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr ... | ```python
n,k=map(int,input().split())
l=list(map(int,input().split()))
l1=[]
l2=[]
for i in range (n):
l1.append(tuple((l[i],i+1)))
l1.sort()
ans=[]
for i in range (n):
if l1[i][0]<=k:
ans.append(l1[i][1])
k-=l1[i][0]
ans.sort()
print(len(ans))
for i in range(len(ans)):
print... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,674,652,916 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 62 | 0 | w_ber=input()
w_bir=input()
if len(w_ber)%2==0:
x=int(len(w_ber)/2)
for i in range(len(w_ber)):
if w_ber[i]!=w_bir[len(w_ber)-1-i]:
print('NO')
break
else:
print('YES')
else:
x=int((len(w_ber)+1)/2)
for i in range(len(w_ber)):
if w_ber... | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
w_ber=input()
w_bir=input()
if len(w_ber)%2==0:
x=int(len(w_ber)/2)
for i in range(len(w_ber)):
if w_ber[i]!=w_bir[len(w_ber)-1-i]:
print('NO')
break
else:
print('YES')
else:
x=int((len(w_ber)+1)/2)
for i in range(len(w_ber)):
... | -1 | MatrixStudio/Codeforces-Python-Submissions |
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... | 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": "... | 1,611,140,302 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | a=int(input())
b=int(input())
x=~(a|b)
print(x) | 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 10... | ```python
a=int(input())
b=int(input())
x=~(a|b)
print(x)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
414 | B | Mashmokh and ACM | PROGRAMMING | 1,400 | [
"combinatorics",
"dp",
"number theory"
] | null | null | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog... | The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000). | Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7). | [
"3 2\n",
"6 4\n",
"2 1\n"
] | [
"5\n",
"39\n",
"2\n"
] | In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3]. | 1,000 | [
{
"input": "3 2",
"output": "5"
},
{
"input": "6 4",
"output": "39"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "1478 194",
"output": "312087753"
},
{
"input": "1415 562",
"output": "953558593"
},
{
"input": "1266 844",
"output": "735042656"
... | 1,685,941,805 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | from time import time
v = list(map(int, input().split()))
u, n = v[0], v[1]
MOD = 10 ** 9 + 7
f = [1]*(u+1)
f[1] = 1
total = 1
start = time()
for i in range(n):
for j in range(u, 0, -1):
k = 2 * j
while k <= u:
f[k] += f[j]
f[k] %= MOD
k += j
prin... | Title: Mashmokh and ACM
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join h... | ```python
from time import time
v = list(map(int, input().split()))
u, n = v[0], v[1]
MOD = 10 ** 9 + 7
f = [1]*(u+1)
f[1] = 1
total = 1
start = time()
for i in range(n):
for j in range(u, 0, -1):
k = 2 * j
while k <= u:
f[k] += f[j]
f[k] %= MOD
k ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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 c... | 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"
},
{
... | 1,633,864,546 | 2,147,483,647 | Python 3 | OK | TESTS | 99 | 154 | 6,963,200 | class Node:
def __init__(self, data):
self.data = data
self.next = None
def set_data(self, new_data):
self.data = new_data
def get_data(self):
return self.data
def set_next(self, new_next):
self.next = new_next
def get_next(self):
return self.next
... | 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 su... | ```python
class Node:
def __init__(self, data):
self.data = data
self.next = None
def set_data(self, new_data):
self.data = new_data
def get_data(self):
return self.data
def set_next(self, new_next):
self.next = new_next
def get_next(self):
return ... | 3.87112 | MatrixStudio/Codeforces-Python-Submissions |
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, an... | 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... | 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"... | 1,673,463,456 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 139 | 2,764,800 | n = int(input())
n = input()
s = [n[0]]
j = 0
i = 1
while i < len(n):
if s and n[i] != s[-1]:
s.pop()
j += 2
else:
s.append(n[i])
i += 1
print(len(n) - j) | 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. Cons... | ```python
n = int(input())
n = input()
s = [n[0]]
j = 0
i = 1
while i < len(n):
if s and n[i] != s[-1]:
s.pop()
j += 2
else:
s.append(n[i])
i += 1
print(len(n) - j)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
621 | B | Wet Shark and Bishops | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation"
] | null | null | Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the o... | The first line of the input contains *n* (1<=≤<=*n*<=≤<=200<=000) — the number of bishops.
Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops ... | Output one integer — the number of pairs of bishops which attack each other. | [
"5\n1 1\n1 5\n3 3\n5 1\n5 5\n",
"3\n1 1\n2 3\n3 5\n"
] | [
"6\n",
"0\n"
] | In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal. | 1,000 | [
{
"input": "5\n1 1\n1 5\n3 3\n5 1\n5 5",
"output": "6"
},
{
"input": "3\n1 1\n2 3\n3 5",
"output": "0"
},
{
"input": "3\n859 96\n634 248\n808 72",
"output": "0"
},
{
"input": "3\n987 237\n891 429\n358 145",
"output": "0"
},
{
"input": "3\n411 81\n149 907\n611 114"... | 1,603,647,912 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 7 | 670 | 4,710,400 | n = int(input())
grid = [[0] * 1000 for _ in range(1000)]
for _ in range(n):
x, y = map(int, input().split())
grid[x - 1][y - 1] = 1
num_of_pairs = 0
for r in range(n):
row = 0
local_pairs = 0
for column in range(r, -1, -1):
if grid[row][column] == 1:
local_pairs... | Title: Wet Shark and Bishops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
We... | ```python
n = int(input())
grid = [[0] * 1000 for _ in range(1000)]
for _ in range(n):
x, y = map(int, input().split())
grid[x - 1][y - 1] = 1
num_of_pairs = 0
for r in range(n):
row = 0
local_pairs = 0
for column in range(r, -1, -1):
if grid[row][column] == 1:
l... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
492 | B | Vanya and Lanterns | PROGRAMMING | 1,200 | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that... | The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of th... | Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. | [
"7 15\n15 5 3 7 9 14 0\n",
"2 5\n2 5\n"
] | [
"2.5000000000\n",
"2.0000000000\n"
] | Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | 1,000 | [
{
"input": "7 15\n15 5 3 7 9 14 0",
"output": "2.5000000000"
},
{
"input": "2 5\n2 5",
"output": "2.0000000000"
},
{
"input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 1... | 1,689,859,189 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | # n - lantern
# l - length of street
# coordinate is 0 - l
# d radius of light
n, l = map(int, input().split())
lanterns = list(map(int, input().split()))
lanterns.sort()
left, right = 0, l
def isSufficient(mid):
for i in range(n):
gap = lanterns[i] - lanterns[i - 1]
if gap > 2 * mi... | Title: Vanya and Lanterns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the poi... | ```python
# n - lantern
# l - length of street
# coordinate is 0 - l
# d radius of light
n, l = map(int, input().split())
lanterns = list(map(int, input().split()))
lanterns.sort()
left, right = 0, l
def isSufficient(mid):
for i in range(n):
gap = lanterns[i] - lanterns[i - 1]
if ga... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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 ... | 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",
"outpu... | 1,610,002,229 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 342 | 0 | def domino_piling():
number = list(map(int, input().split()))
total = number[0] * number[1]
print(int(total/2))
domino_piling() | 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 p... | ```python
def domino_piling():
number = list(map(int, input().split()))
total = number[0] * number[1]
print(int(total/2))
domino_piling()
``` | 3.9145 | MatrixStudio/Codeforces-Python-Submissions |
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 th... | 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": "chn... | 1,624,365,611 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 0 | w=input()
sum_l=0
sum_u=0
for i in w:
if i.islower():
c=1
sum_l=sum_l+c
else:
c=1
sum_u=sum_u+c
if sum_l>sum_u:
w=w.lower()
if sum_l<sum_u:
w=w.upper()
else:
w=w.lower()
print(w)
... | 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 ei... | ```python
w=input()
sum_l=0
sum_u=0
for i in w:
if i.islower():
c=1
sum_l=sum_l+c
else:
c=1
sum_u=sum_u+c
if sum_l>sum_u:
w=w.lower()
if sum_l<sum_u:
w=w.upper()
else:
w=w.lower()
print(w)
... | 3.9615 | MatrixStudio/Codeforces-Python-Submissions |
397 | A | On Segment's Own Points | PROGRAMMING | 0 | [
"implementation"
] | null | null | Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm.
The dorm has exactly one straight dryer — a 100 ce... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student. | On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments. | [
"3\n0 5\n2 8\n1 6\n",
"3\n0 10\n1 5\n7 15\n"
] | [
"1\n",
"3\n"
] | Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments.
In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and... | 500 | [
{
"input": "3\n0 5\n2 8\n1 6",
"output": "1"
},
{
"input": "3\n0 10\n1 5\n7 15",
"output": "3"
},
{
"input": "1\n0 100",
"output": "100"
},
{
"input": "2\n1 9\n1 9",
"output": "0"
},
{
"input": "2\n1 9\n5 10",
"output": "4"
},
{
"input": "2\n1 9\n3 5",... | 1,575,047,486 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 202 | 2,150,400 | n = int(input())
x, y = map(int, input().split())
dpl, dpr = dict(), dict()
l = set()
for _ in range(n-1):
a, b = map(int, input().split())
if a >= x:
dpl[_] = a
if b <= y:
dpr[_] = b
for i in range(max(a, x), min(b+1, y+1)):
l.add(i)
l = list(l)
l = sorted(l)
ans =... | Title: On Segment's Own Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some... | ```python
n = int(input())
x, y = map(int, input().split())
dpl, dpr = dict(), dict()
l = set()
for _ in range(n-1):
a, b = map(int, input().split())
if a >= x:
dpl[_] = a
if b <= y:
dpr[_] = b
for i in range(max(a, x), min(b+1, y+1)):
l.add(i)
l = list(l)
l = sorted... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
4 | C | Registration System | PROGRAMMING | 1,300 | [
"data structures",
"hashing",
"implementation"
] | C. Registration system | 5 | 64 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
... | The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | [
"4\nabacaba\nacaba\nabacaba\nacab\n",
"6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n"
] | [
"OK\nOK\nabacaba1\nOK\n",
"OK\nfirst1\nOK\nsecond1\nOK\nthird1\n"
] | none | 0 | [
{
"input": "4\nabacaba\nacaba\nabacaba\nacab",
"output": "OK\nOK\nabacaba1\nOK"
},
{
"input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird",
"output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1"
},
{
"input": "1\nn",
"output": "OK"
},
{
"input": "2\nu\nu",
"output": "OK\nu1"
... | 1,691,583,477 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n=int(input())
d={}
for i in range(n):
t=input()
if(t not in d.keys()):
d[t]=0
print(t)
else:
d[t]+=1
print(t+str(d[t])) | Title: Registration System
Time Limit: 5 seconds
Memory Limit: 64 megabytes
Problem Description:
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to imple... | ```python
n=int(input())
d={}
for i in range(n):
t=input()
if(t not in d.keys()):
d[t]=0
print(t)
else:
d[t]+=1
print(t+str(d[t]))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
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, ... | 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": "tymbzjyqhymeda... | 1,609,028,257 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | def findChat(string):
arr = ['h','e','l','l','o']
output = ''
count = 0
for char in string:
if char in arr[0+count:1+count]:
count += 1
output += char
if output == 'hello':
return 'YES'
return 'NO'
print(findChat(input())) | 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 letter... | ```python
def findChat(string):
arr = ['h','e','l','l','o']
output = ''
count = 0
for char in string:
if char in arr[0+count:1+count]:
count += 1
output += char
if output == 'hello':
return 'YES'
return 'NO'
print(findChat(in... | 3.9455 | MatrixStudio/Codeforces-Python-Submissions |
912 | D | Fishes | PROGRAMMING | 2,100 | [
"data structures",
"graphs",
"greedy",
"probabilities",
"shortest paths"
] | null | null | While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size *n*<=×<=*m*, divided into cells of size 1<=×<=1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size *r*<=×<=*r*, designe... | The only line contains four integers *n*,<=*m*,<=*r*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=105, 1<=≤<=*r*<=≤<=*min*(*n*,<=*m*), 1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=105)). | Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10<=-<=9. Namely, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct, if . | [
"3 3 2 3\n",
"12 17 9 40\n"
] | [
"2.0000000000\n",
"32.8333333333\n"
] | In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value. | 2,000 | [
{
"input": "3 3 2 3",
"output": "2.0000000000"
},
{
"input": "12 17 9 40",
"output": "32.8333333333"
},
{
"input": "1 1 1 1",
"output": "1.0000000000"
},
{
"input": "10 10 5 100",
"output": "25.0000000000"
},
{
"input": "7 1 1 4",
"output": "0.5714285714"
},... | 1,515,327,527 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 8 | 967 | 15,052,800 | n, m, r, k = map(int, input().split())
x = (n + 1) // 2
y = (m + 1) // 2
ans = 0
xx = max(1, x - int(k**0.5) - 1)
xxx = min(n, x + int(k**0.5) + 1)
yy = max(1, y - int(k**0.5) - 1)
yyy = min(m, y + int(k**0.5) + 1)
pedy = []
for i in range(xx, xxx + 1):
for j in range(yy, yyy + 1):
x = i
... | Title: Fishes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size *n*<=×<=*m*, divided into cells of size 1<=×<=1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise ... | ```python
n, m, r, k = map(int, input().split())
x = (n + 1) // 2
y = (m + 1) // 2
ans = 0
xx = max(1, x - int(k**0.5) - 1)
xxx = min(n, x + int(k**0.5) + 1)
yy = max(1, y - int(k**0.5) - 1)
yyy = min(m, y + int(k**0.5) + 1)
pedy = []
for i in range(xx, xxx + 1):
for j in range(yy, yyy + 1):
x = ... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,676,342,518 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 62 | 1,945,600 | # from collections import Counter
ints = lambda: list(map(int, input().split()))
tw = lambda n: (n&(n-1)==0) and n!=0
def solve():
# by Azimjonm2333
a=input()
n=len(a)
s=0
for i in range(n-1):
if a[i]=='Q':
for j in range(i, n):
if a[j]=='A':
... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
# from collections import Counter
ints = lambda: list(map(int, input().split()))
tw = lambda n: (n&(n-1)==0) and n!=0
def solve():
# by Azimjonm2333
a=input()
n=len(a)
s=0
for i in range(n-1):
if a[i]=='Q':
for j in range(i, n):
if a[j]=='A... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,620,202,978 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 218 | 1,331,200 | a=int(input())
print(a,end=" ")
for i in range(1,a):
print(i,end=" ") | Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
a=int(input())
print(a,end=" ")
for i in range(1,a):
print(i,end=" ")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
888 | C | K-Dominant Character | PROGRAMMING | 1,400 | [
"binary search",
"implementation",
"two pointers"
] | null | null | You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*.
You have to find minimum *k* such that there exists at least one *k*-dominant character. | The first line contains string *s* consisting of lowercase Latin letters (1<=≤<=|*s*|<=≤<=100000). | Print one number — the minimum value of *k* such that there exists at least one *k*-dominant character. | [
"abacaba\n",
"zzzzz\n",
"abcde\n"
] | [
"2\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "2"
},
{
"input": "zzzzz",
"output": "1"
},
{
"input": "abcde",
"output": "3"
},
{
"input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab",
"output": "8"
},
{
"input": "daabcdabbab... | 1,584,992,511 | 1,731 | Python 3 | OK | TESTS | 51 | 202 | 4,403,200 | a = input()
l = len(a)
from collections import defaultdict
b = defaultdict(list)
for i in range(l):
b[ord(a[i])-97].append(i)
p = []
for z in b:
i = b[z]
k = len(i)
d = []
d.append(i[0]+1)
for j in range(1,k):
d.append(i[j]-i[j-1])
d.append(l-i[k-1])
p.append(max(d... | Title: K-Dominant Character
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*.
You have to find minimum *k* s... | ```python
a = input()
l = len(a)
from collections import defaultdict
b = defaultdict(list)
for i in range(l):
b[ord(a[i])-97].append(i)
p = []
for z in b:
i = b[z]
k = len(i)
d = []
d.append(i[0]+1)
for j in range(1,k):
d.append(i[j]-i[j-1])
d.append(l-i[k-1])
p.ap... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,696,136,728 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 186 | 0 | n,m=map(int,input().split())
max_num=max(n,m)
count=0
if n==1 and m==1:
print("2")
for i in range(max_num):
for j in range(max_num):
c=i*i
d=j
c_n=i
d_n=j*j
eqn=c+d
eqn_n=c_n+d_n
if eqn_n==n and eqn==m:
count+=1
print(count) | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
n,m=map(int,input().split())
max_num=max(n,m)
count=0
if n==1 and m==1:
print("2")
for i in range(max_num):
for j in range(max_num):
c=i*i
d=j
c_n=i
d_n=j*j
eqn=c+d
eqn_n=c_n+d_n
if eqn_n==n and eqn==m:
count+=1
print(c... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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 ... | 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/07fa58573ece0d32... | 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"
},
{
... | 1,625,737,826 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 77 | 0 | n = int(input())
a = input()
b = input()
a = list(a)
for i in range(n):
a[i] = int(a[i])
b = list(b)
for i in range(n):
b[i] = int(b[i])
ans = 0
for i in range(n):
if abs(a[i] - b[i]) > 5:
ans += 10 - abs(a[i] - b[i])
else:
ans += abs(a[i] - b[i])
print(ans) | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n = int(input())
a = input()
b = input()
a = list(a)
for i in range(n):
a[i] = int(a[i])
b = list(b)
for i in range(n):
b[i] = int(b[i])
ans = 0
for i in range(n):
if abs(a[i] - b[i]) > 5:
ans += 10 - abs(a[i] - b[i])
else:
ans += abs(a[i] - b[i])
pri... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
612 | D | The Union of k-Segments | PROGRAMMING | 1,800 | [
"greedy",
"sortings"
] | null | null | You are given *n* segments on the coordinate axis Ox and the number *k*. The point is satisfied if it belongs to at least *k* segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others. | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=106) — the number of segments and the value of *k*.
The next *n* lines contain two integers *l**i*,<=*r**i* (<=-<=109<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) each — the endpoints of the *i*-th segment. The segments can degenerate and intersect each other. ... | First line contains integer *m* — the smallest number of segments.
Next *m* lines contain two integers *a**j*,<=*b**j* (*a**j*<=≤<=*b**j*) — the ends of *j*-th segment in the answer. The segments should be listed in the order from left to right. | [
"3 2\n0 5\n-3 2\n3 8\n",
"3 2\n0 5\n-3 3\n3 8\n"
] | [
"2\n0 2\n3 5\n",
"1\n0 5\n"
] | none | 0 | [
{
"input": "3 2\n0 5\n-3 2\n3 8",
"output": "2\n0 2\n3 5"
},
{
"input": "3 2\n0 5\n-3 3\n3 8",
"output": "1\n0 5"
},
{
"input": "1 1\n-1 1",
"output": "1\n-1 1"
},
{
"input": "10 2\n27 96\n-22 45\n-68 26\n46 69\n-91 86\n12 73\n-89 76\n-11 33\n17 47\n-57 78",
"output": "1\... | 1,642,599,309 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | I = lambda: [int(i) for i in input().split()]
n, k = I()
points = []
for _ in range(n):
x, y = I()
points += [(x, -1)]
points += [(y, 1)]
points.sort()
taken = 0
ans = []
for x, event in points:
if taken - event >= k and taken < k:
ans += [[x]]
if taken == k and taken - even... | Title: The Union of k-Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* segments on the coordinate axis Ox and the number *k*. The point is satisfied if it belongs to at least *k* segments. Find the smallest (by the number of segments) set of segments on the coordi... | ```python
I = lambda: [int(i) for i in input().split()]
n, k = I()
points = []
for _ in range(n):
x, y = I()
points += [(x, -1)]
points += [(y, 1)]
points.sort()
taken = 0
ans = []
for x, event in points:
if taken - event >= k and taken < k:
ans += [[x]]
if taken == k and ta... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
31 | B | Sysadmin Bob | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"strings"
] | B. Sysadmin Bob | 0 | 256 | Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitra... | The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». | If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of the... | [
"a@aa@a\n",
"a@a@a\n",
"@aa@a\n"
] | [
"a@a,a@a\n",
"No solution\n",
"No solution\n"
] | none | 1,000 | [
{
"input": "a@aa@a",
"output": "a@a,a@a"
},
{
"input": "a@a@a",
"output": "No solution"
},
{
"input": "@aa@a",
"output": "No solution"
},
{
"input": "aba@caba@daba",
"output": "aba@c,aba@daba"
},
{
"input": "asd@qwasd@qwasd@qwasd@qwasd@qw",
"output": "asd@q,wa... | 1,697,810,849 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 46 | 0 | s = input().strip()
at_count = s.count('@')
# 如果@的数量少于1或字符串以@开始或结束,直接输出"No solution"
if at_count < 1 or s[0] == '@' or s[-1] == '@':
print('No solution')
exit()
emails = []
i = 0
while i < len(s):
at_pos = s.find('@', i)
if at_pos == -1:
break
# 查找下一个@
next_at_po... | Title: Sysadmin Bob
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of t... | ```python
s = input().strip()
at_count = s.count('@')
# 如果@的数量少于1或字符串以@开始或结束,直接输出"No solution"
if at_count < 1 or s[0] == '@' or s[-1] == '@':
print('No solution')
exit()
emails = []
i = 0
while i < len(s):
at_pos = s.find('@', i)
if at_pos == -1:
break
# 查找下一个@
... | 3 | MatrixStudio/Codeforces-Python-Submissions |
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 th... | 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": "chn... | 1,687,973,762 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | s = input()
count_up = 0
count_low = 0
for char in s:
if char.isupper():
count_up = 1
else:
count_low = 1
if count_up > count_low:
result = s.upper()
else:
result = s.lower()
print(result)
| 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 ei... | ```python
s = input()
count_up = 0
count_low = 0
for char in s:
if char.isupper():
count_up = 1
else:
count_low = 1
if count_up > count_low:
result = s.upper()
else:
result = s.lower()
print(result)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
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 c... | 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 follo... | 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",
... | 1,616,850,065 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 307,200 | n=int(input())
l=list(map(int,input().split()))
for i in range(n):
if i==0 :
print(a[i+1]-a[i],end=" ")
print(a[n-1]-a[i])
else:
print(a[i]-a[i-1],end=" ")
print(a[n-1]-a[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... | ```python
n=int(input())
l=list(map(int,input().split()))
for i in range(n):
if i==0 :
print(a[i+1]-a[i],end=" ")
print(a[n-1]-a[i])
else:
print(a[i]-a[i-1],end=" ")
print(a[n-1]-a[i])
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,649,316,279 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 1,433,600 | n,t = map(int,input().split())
a = [int(i) for i in input().split()]
b = False
d = 0
for i in range(n-1):
d = i+a[i]
if d ==t-1:
b = True
break
else:
if d>t-1:
b = False
break
if b == True:
print('YES')
else:
print('NO')
| Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n,t = map(int,input().split())
a = [int(i) for i in input().split()]
b = False
d = 0
for i in range(n-1):
d = i+a[i]
if d ==t-1:
b = True
break
else:
if d>t-1:
b = False
break
if b == True:
print('YES')
else:
print('NO')
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
765 | A | Neverending competitions | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team ... | In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX"... | If Jinotega is now at home, print "home" (without quotes), otherwise print "contest". | [
"4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n",
"3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n"
] | [
"home\n",
"contest\n"
] | In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list. | 500 | [
{
"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO",
"output": "home"
},
{
"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP",
"output": "contest"
},
{
"input": "1\nESJ\nESJ->TSJ",
"output": "contest"
},
{
"input": "2\nXMR\nFAJ->XMR\nXMR->FAJ",
"output": "home"
},
... | 1,632,924,981 | 2,147,483,647 | PyPy 3 | OK | TESTS | 23 | 108 | 20,480,000 | from collections import defaultdict
def solve(h,l):
c1,c2=0,0
for i,j in l:
if(i==h):
c1+=1
else:
c2+=1
if(c1==c2):
return "home"
else:
return "contest"
n = int(input())
h = input()
l = []
for i in range(n):
l.append(input().spl... | Title: Neverending competitions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from thei... | ```python
from collections import defaultdict
def solve(h,l):
c1,c2=0,0
for i,j in l:
if(i==h):
c1+=1
else:
c2+=1
if(c1==c2):
return "home"
else:
return "contest"
n = int(input())
h = input()
l = []
for i in range(n):
l.append(i... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"outpu... | 1,653,121,054 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 92 | 0 | i=int(input())
if i%7==0:
l=i//7
print("4"*h+"7"*l)
else:
j=i//4
l=0
h=0
for k in range(j):
k=k+1
if (i-(4*k))%7==0:
h=k
l=(i-(4*k))//7
break
if h==0 and l==0:
print(-1)
else:
print("4"*h+"7"*l) | Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
i=int(input())
if i%7==0:
l=i//7
print("4"*h+"7"*l)
else:
j=i//4
l=0
h=0
for k in range(j):
k=k+1
if (i-(4*k))%7==0:
h=k
l=(i-(4*k))//7
break
if h==0 and l==0:
print(-1)
else:
print("4"*h+"7"*l)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
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 ... | 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",
"outpu... | 1,641,455,520 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 184 | 0 |
def solution(n):
area = int(n[0]) * int(n[1])
res = area // 2
return res
if __name__ == '__main__':
n = list(map(int, input().rstrip().split()))
print(solution(n))
| 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 p... | ```python
def solution(n):
area = int(n[0]) * int(n[1])
res = area // 2
return res
if __name__ == '__main__':
n = list(map(int, input().rstrip().split()))
print(solution(n))
``` | 3.954 | MatrixStudio/Codeforces-Python-Submissions |
611 | B | New Year and Old Property | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"implementation"
] | null | null | The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation.
Lim... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively. | Print one integer – the number of years Limak will count in his chosen interval. | [
"5 10\n",
"2015 2015\n",
"100 105\n",
"72057594000000000 72057595000000000\n"
] | [
"2\n",
"1\n",
"0\n",
"26\n"
] | In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<su... | 750 | [
{
"input": "5 10",
"output": "2"
},
{
"input": "2015 2015",
"output": "1"
},
{
"input": "100 105",
"output": "0"
},
{
"input": "72057594000000000 72057595000000000",
"output": "26"
},
{
"input": "1 100",
"output": "16"
},
{
"input": "100000000000000000... | 1,641,887,338 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n,b = [int(i) for i in input().split()]
e = n
pos = -1
i = 0
while e!=0:
if e%2==0:
pos = i
e = e>>1
i+=1
i-=1
if pos==-1:
pos=i
n+=1
n = n|((1<<pos)-1)
c = 0
while n<=b:
c+=1
if pos>0:
n=(n>>1)+(1<<i)
pos-=1
else:
n+=2
pos = i
n = n|((1<<p... | Title: New Year and Old Property
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2... | ```python
n,b = [int(i) for i in input().split()]
e = n
pos = -1
i = 0
while e!=0:
if e%2==0:
pos = i
e = e>>1
i+=1
i-=1
if pos==-1:
pos=i
n+=1
n = n|((1<<pos)-1)
c = 0
while n<=b:
c+=1
if pos>0:
n=(n>>1)+(1<<i)
pos-=1
else:
n+=2
pos = i
n ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
529 | B | Group Photo 2 (online mirror version) | PROGRAMMING | 1,900 | [
"brute force",
"greedy",
"sortings"
] | null | null | Many years have passed, and *n* friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo.
Simply speaking, the process of photographing can be descr... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of friends.
The next *n* lines have two integers *w**i*,<=*h**i* (1<=≤<=*w**i*,<=*h**i*<=≤<=1000) each, representing the size of the rectangle, corresponding to the *i*-th friend. | Print a single integer equal to the minimum possible area of the photo containing all friends if no more than *n*<=/<=2 of them can lie on the ground. | [
"3\n10 1\n20 2\n30 3\n",
"3\n3 1\n2 2\n4 3\n",
"1\n5 10\n"
] | [
"180\n",
"21\n",
"50\n"
] | none | 500 | [
{
"input": "3\n10 1\n20 2\n30 3",
"output": "180"
},
{
"input": "3\n3 1\n2 2\n4 3",
"output": "21"
},
{
"input": "1\n5 10",
"output": "50"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "1\n1000 1000",
"output": "1000000"
},
{
"input": "1\n1 1000"... | 1,678,834,160 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 0 | from itertools import combinations
def min_photo_area(n, friends):
min_area = float("inf")
max_lie_down = n // 2
for num_lie_down in range(max_lie_down + 1):
for lying_friends_combination in combinations(friends, num_lie_down):
standing_friends = [friend for friend in friends i... | Title: Group Photo 2 (online mirror version)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many years have passed, and *n* friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friend... | ```python
from itertools import combinations
def min_photo_area(n, friends):
min_area = float("inf")
max_lie_down = n // 2
for num_lie_down in range(max_lie_down + 1):
for lying_friends_combination in combinations(friends, num_lie_down):
standing_friends = [friend for friend in... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,690,558,199 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,048,000 | N = int(input())
numList = [-100]
count = 0
for i in range(N):
num = int(input())
if num>max(numList):
count+=1
numList.append(num)
elif num<min(numList):
count+=1
numList.append(num)
else:
numList.append(num)
print(count) | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
N = int(input())
numList = [-100]
count = 0
for i in range(N):
num = int(input())
if num>max(numList):
count+=1
numList.append(num)
elif num<min(numList):
count+=1
numList.append(num)
else:
numList.append(num)
print(count)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
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 integer... | 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"
},
{
... | 1,680,022,450 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 154 | 0 | a,b= map(int,input().split())
c=list(map(int,input().split()))
d=0
for j in range(a):
if str(c[j]).count('4')+str(c[j]).count('7')<=b:
d+=1
print(d) | 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... | ```python
a,b= map(int,input().split())
c=list(map(int,input().split()))
d=0
for j in range(a):
if str(c[j]).count('4')+str(c[j]).count('7')<=b:
d+=1
print(d)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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 ... | 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"
},
... | 1,516,376,121 | 3,621 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 5,632,000 | t = int(input())
a,b = input().split()
if '7' in a or '7' in b:
print("0")
else :
s=int(a)
c=1
k=int(b)-t
while(('7' not in a) and ('7' not in b)):
k-=t
if k<0:
s-=1
if s<0:
s+=24
k+=60
c+=1
a=str(k)
... | 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 the... | ```python
t = int(input())
a,b = input().split()
if '7' in a or '7' in b:
print("0")
else :
s=int(a)
c=1
k=int(b)-t
while(('7' not in a) and ('7' not in b)):
k-=t
if k<0:
s-=1
if s<0:
s+=24
k+=60
c+=1
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
884 | C | Bertown Subway | PROGRAMMING | 1,500 | [
"dfs and similar",
"greedy",
"math"
] | null | null | The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.
There are *n* stations in the subway. It was built according to the Bertown Transport Law:
1. For each station *i* there exists exactly one train that goes from this station... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100000) — the number of stations.
The second line contains *n* integer numbers *p*1, *p*2, ..., *p**n* (1<=≤<=*p**i*<=≤<=*n*) — the current structure of the subway. All these numbers are distinct. | Print one number — the maximum possible value of convenience. | [
"3\n2 1 3\n",
"5\n1 5 4 3 2\n"
] | [
"9\n",
"17\n"
] | In the first example the mayor can change *p*<sub class="lower-index">2</sub> to 3 and *p*<sub class="lower-index">3</sub> to 1, so there will be 9 pairs: (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3).
In the second example the mayor can change *p*<sub class="lower-index">2</sub> to 4 and *p*<... | 0 | [
{
"input": "3\n2 1 3",
"output": "9"
},
{
"input": "5\n1 5 4 3 2",
"output": "17"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "4"
},
{
"input": "2\n2 1",
"output": "4"
},
{
"input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 ... | 1,546,526,036 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 186 | 7,270,400 | n=int(input())
p=[0]+list(map(int,input().split()))
vis=[0]*(n+1)
part=[]
for i in range(1,n+1):
if not vis[i]:
tot=0
x=i
while not vis[x]:
tot+=1
vis[x]=1
x=p[x]
part.append(tot)
part.sort(reverse=True)
if len(part)==1:
print(n*... | Title: Bertown Subway
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.
There are *n* stations in the subway. It was built according to the Bertown... | ```python
n=int(input())
p=[0]+list(map(int,input().split()))
vis=[0]*(n+1)
part=[]
for i in range(1,n+1):
if not vis[i]:
tot=0
x=i
while not vis[x]:
tot+=1
vis[x]=1
x=p[x]
part.append(tot)
part.sort(reverse=True)
if len(part)==1:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,695,966,980 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 0 | n = int(input()) # Input the number of problems
problems_solved = 0 # Initialize the count of problems they will solve
for _ in range(n):
petya, vasya, tonya = map(int, input().split()) # Input the friends' opinions
# Check if at least two of them are sure about the solution
if petya + vasya + ton... | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
n = int(input()) # Input the number of problems
problems_solved = 0 # Initialize the count of problems they will solve
for _ in range(n):
petya, vasya, tonya = map(int, input().split()) # Input the friends' opinions
# Check if at least two of them are sure about the solution
if petya + v... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,599,849,893 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 307,200 | a = int(input())
b = int(input())
first = 1
second = 1
tired = 0
while a != b:
if a < b:
if first <= second:
first += 1
tired += first - 1
a += 1
else:
second += 1
tired += second - 1
b -= 1
else:
if first <= second:
first += 1
tired += first - 1
a -= 1
else:
... | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
a = int(input())
b = int(input())
first = 1
second = 1
tired = 0
while a != b:
if a < b:
if first <= second:
first += 1
tired += first - 1
a += 1
else:
second += 1
tired += second - 1
b -= 1
else:
if first <= second:
first += 1
tired += first - 1
a -= 1
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,593,029,540 | 2,147,483,647 | PyPy 3 | OK | TESTS | 83 | 280 | 20,172,800 | def f(seq):
for x in seq:
if x[0] + x[1] > x[2]:
return 'TRIANGLE'
for x in seq:
if x[0] + x[1] == x[2]:
return 'SEGMENT'
return 'IMPOSSIBLE'
a = sorted(list(map(int, input().split())))
seq = []
for i in range(4):
b = []
for j in range(4):
if j != i:
b.append(a[j]... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
def f(seq):
for x in seq:
if x[0] + x[1] > x[2]:
return 'TRIANGLE'
for x in seq:
if x[0] + x[1] == x[2]:
return 'SEGMENT'
return 'IMPOSSIBLE'
a = sorted(list(map(int, input().split())))
seq = []
for i in range(4):
b = []
for j in range(4):
if j != i:
b.a... | 3.779701 | MatrixStudio/Codeforces-Python-Submissions |
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 b... | 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* ... | 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... | 1,643,226,846 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 1,000 | 9,523,200 | #Mamma don't raises quitter.................................................
#manan is improving, keep hustling manan bhai ;)
def di():return map(str, input().split())
def ii():return int(input())
def li():return list(map(int, input().split()))
#sys.stdin = open('input.txt', 'r')
#sys.stdout = open('out... | 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... | ```python
#Mamma don't raises quitter.................................................
#manan is improving, keep hustling manan bhai ;)
def di():return map(str, input().split())
def ii():return int(input())
def li():return list(map(int, input().split()))
#sys.stdin = open('input.txt', 'r')
#sys.stdout =... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
358 | A | Dima and Continuous Line | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect th... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. | In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). | [
"4\n0 10 5 15\n",
"4\n0 15 5 10\n"
] | [
"yes\n",
"no\n"
] | The first test from the statement is on the picture to the left, the second test is on the picture to the right. | 500 | [
{
"input": "4\n0 10 5 15",
"output": "yes"
},
{
"input": "4\n0 15 5 10",
"output": "no"
},
{
"input": "5\n0 1000 2000 3000 1500",
"output": "yes"
},
{
"input": "5\n-724093 710736 -383722 -359011 439613",
"output": "no"
},
{
"input": "50\n384672 661179 -775591 -989... | 1,437,994,079 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | import time
n=int(input());a=list(map(int,input().split()));b,c,ok=[],[],1
for i in range(n-1):
b.append(min(a[i],a[i+1]));c.append(max(a[i],a[i+1]));
for i in range(n-1):
for j in range(n-1):
if(i==j):continue
if(b[i]>b[j] and c[i]>c[j]):ok=0
if(ok):print('no')
else:print('yes') | Title: Dima and Continuous Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher g... | ```python
import time
n=int(input());a=list(map(int,input().split()));b,c,ok=[],[],1
for i in range(n-1):
b.append(min(a[i],a[i+1]));c.append(max(a[i],a[i+1]));
for i in range(n-1):
for j in range(n-1):
if(i==j):continue
if(b[i]>b[j] and c[i]>c[j]):ok=0
if(ok):print('no')
else:print('ye... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,574,322,287 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 124 | 0 | n = int(input())
warna = ["purple","green","blue","orange","red","yellow"]
skill = ["Power","Time","Space","Soul","Reality","Mind"]
hasil = []
skillB = []
for i in range(n):
color = input()
for j in range(len(warna)):
if warna[j] == color:
hasil += [skill[j]]
for i in skill:
... | Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
n = int(input())
warna = ["purple","green","blue","orange","red","yellow"]
skill = ["Power","Time","Space","Soul","Reality","Mind"]
hasil = []
skillB = []
for i in range(n):
color = input()
for j in range(len(warna)):
if warna[j] == color:
hasil += [skill[j]]
for i in s... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
772 | A | Voltage Keepsake | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of pow... | The first line contains two integers, *n* and *p* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109) — the number of devices and the power of the charger.
This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100<=000) — the power of the dev... | If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
Namely, let's assume that your answer is *a* and the answer of the jury is *b*. The chec... | [
"2 1\n2 2\n2 1000\n",
"1 100\n1 1\n",
"3 5\n4 3\n5 2\n6 1\n"
] | [
"2.0000000000",
"-1\n",
"0.5000000000"
] | In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to char... | 500 | [
{
"input": "2 1\n2 2\n2 1000",
"output": "2.0000000000"
},
{
"input": "1 100\n1 1",
"output": "-1"
},
{
"input": "3 5\n4 3\n5 2\n6 1",
"output": "0.5000000000"
},
{
"input": "1 1\n1 87",
"output": "-1"
},
{
"input": "1 1\n100 77",
"output": "0.7777777778"
},... | 1,696,194,361 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 94 | 858 | 20,889,600 | import math
from bisect import bisect_right
from itertools import accumulate
R = lambda: map(int, input().split())
n, p = R()
devs = []
for i in range(n):
devs.append(tuple(R()))
devs = sorted(devs, key=lambda x: x[1]/x[0])
sp, sr, t = 0, 0, math.inf
for d in devs:
sp += d[0]
sr += d[1]
if sp > p:
... | Title: Voltage Keepsake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-... | ```python
import math
from bisect import bisect_right
from itertools import accumulate
R = lambda: map(int, input().split())
n, p = R()
devs = []
for i in range(n):
devs.append(tuple(R()))
devs = sorted(devs, key=lambda x: x[1]/x[0])
sp, sr, t = 0, 0, math.inf
for d in devs:
sp += d[0]
sr += d[1]
if sp... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did.
The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. Th... | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | [
"5\n! abc\n. ad\n. b\n! cd\n? c\n",
"8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n",
"7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin p... | 0 | [
{
"input": "5\n! abc\n. ad\n. b\n! cd\n? c",
"output": "1"
},
{
"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e",
"output": "2"
},
{
"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h",
"output": "0"
},
{
"input": "4\n! abcd\n! cdef\n? d\n? c",
"o... | 1,566,279,513 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | import bisect
def list_output(s):
print(' '.join(map(str, s)))
def list_input(s='int'):
if s == 'int':
return list(map(int, input().split()))
elif s == 'float':
return list(map(float, input().split()))
return list(map(str, input().split()))
n = int(input())
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter... | ```python
import bisect
def list_output(s):
print(' '.join(map(str, s)))
def list_input(s='int'):
if s == 'int':
return list(map(int, input().split()))
elif s == 'float':
return list(map(float, input().split()))
return list(map(str, input().split()))
n = int(in... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,688,558,527 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | a=input()
b=set()
for i in "abcdefghijklmnopqrstuvwxyz":
if i in a:
b.add(i)
print(len(b))
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
a=input()
b=set()
for i in "abcdefghijklmnopqrstuvwxyz":
if i in a:
b.add(i)
print(len(b))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
888 | D | Almost Identity Permutations | PROGRAMMING | 1,600 | [
"combinatorics",
"dp",
"math"
] | null | null | A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array.
Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*k* indices *i* (1<=≤<=*i*<=≤<=*n*) such that *p**i*<==<=*i*.
Your task is to count the number of almost identity ... | The first line contains two integers *n* and *k* (4<=≤<=*n*<=≤<=1000, 1<=≤<=*k*<=≤<=4). | Print the number of almost identity permutations for given *n* and *k*. | [
"4 1\n",
"4 2\n",
"5 3\n",
"5 4\n"
] | [
"1\n",
"7\n",
"31\n",
"76\n"
] | none | 0 | [
{
"input": "4 1",
"output": "1"
},
{
"input": "4 2",
"output": "7"
},
{
"input": "5 3",
"output": "31"
},
{
"input": "5 4",
"output": "76"
},
{
"input": "200 1",
"output": "1"
},
{
"input": "200 2",
"output": "19901"
},
{
"input": "200 3",
... | 1,590,146,261 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 156 | 0 | import sys
import math
def derange(k):
ans=math.factorial(k)
z=-1
mult=1
for i in range(1,k+1):
mult += z * (1/(math.factorial(i)))
z *= -1
ans=ans*mult
#print(ans,'ans')
return int(ans)
def com(n,k):
if k==0:
return 1
if k==1:
return n
if k==2:
return n*(n-1)//2
if k==3:
retu... | Title: Almost Identity Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array.
Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*... | ```python
import sys
import math
def derange(k):
ans=math.factorial(k)
z=-1
mult=1
for i in range(1,k+1):
mult += z * (1/(math.factorial(i)))
z *= -1
ans=ans*mult
#print(ans,'ans')
return int(ans)
def com(n,k):
if k==0:
return 1
if k==1:
return n
if k==2:
return n*(n-1)//2
if k==... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
220 | B | Little Elephant and Array | PROGRAMMING | 1,800 | [
"constructive algorithms",
"data structures"
] | null | null | The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant has *m* queries to the array, each query is characterised by a pair of integers *l**j* and *r**j* (1<=≤<=*l**j... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the size of array *a* and the number of queries to it. The next line contains *n* space-separated positive integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). Next *m* lines contain descriptions of queries, one per line. T... | In *m* lines print *m* integers — the answers to the queries. The *j*-th line should contain the answer to the *j*-th query. | [
"7 2\n3 1 2 2 3 3 7\n1 7\n3 4\n"
] | [
"3\n1\n"
] | none | 1,000 | [
{
"input": "7 2\n3 1 2 2 3 3 7\n1 7\n3 4",
"output": "3\n1"
},
{
"input": "6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6",
"output": "1\n0\n2\n1\n1\n3"
},
{
"input": "1 2\n1\n1 1\n1 1",
"output": "1\n1"
},
{
"input": "1 1\n1000000000\n1 1",
"output": "0"
}
] | 1,661,670,355 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 1,076 | 58,163,200 | import sys
from dataclasses import dataclass
@dataclass
class Query:
idx: int
l: int
r: int
ans: int
def solve():
n, m = map(int, input().split())
arr = [0] + list(map(int, sys.stdin.readline().split()))
close_arr_map = {}
num_arr_map = {}
queries = []
f... | Title: Little Elephant and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant... | ```python
import sys
from dataclasses import dataclass
@dataclass
class Query:
idx: int
l: int
r: int
ans: int
def solve():
n, m = map(int, input().split())
arr = [0] + list(map(int, sys.stdin.readline().split()))
close_arr_map = {}
num_arr_map = {}
queries =... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ... | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer ... | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n... | 1,445,939,422 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 62 | 0 | l,a,b=int(input()),int(input()),int(input())
print(a*(l/(a+b))) | Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en... | ```python
l,a,b=int(input()),int(input()),int(input())
print(a*(l/(a+b)))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Поликарп мечтает стать программистом и фанатеет от степеней двойки. Среди двух чисел ему больше нравится то, которое делится на большую степень числа 2.
По заданной последовательности целых положительных чисел *a*1,<=*a*2,<=...,<=*a**n* требуется найти *r* — максимальную степень числа 2, на которую делится хотя бы од... | В первой строке записано целое число *n* (1<=≤<=*n*<=≤<=100) — длина последовательности *a*.
Во второй строке записана последовательность целых чисел *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Выведите два числа:
- *r* — максимальную степень двойки, на которую делится хотя бы одно из чисел заданной последовательности, - количество элементов последовательности, которые делятся на *r*. | [
"5\n80 7 16 4 48\n",
"4\n21 5 3 33\n"
] | [
"16 3\n",
"1 4\n"
] | В первом тестовом примере максимальная степень двойки, на которую делится хотя бы одно число, равна 16 = 2<sup class="upper-index">4</sup>, на неё делятся числа 80, 16 и 48.
Во втором тестовом примере все четыре числа нечётные, поэтому делятся только на 1 = 2<sup class="upper-index">0</sup>. Это и будет максимальной с... | 0 | [
{
"input": "5\n80 7 16 4 48",
"output": "16 3"
},
{
"input": "4\n21 5 3 33",
"output": "1 4"
},
{
"input": "10\n8 112 52 86 93 102 24 24 100 826791168",
"output": "256 1"
},
{
"input": "3\n458297759 18 104",
"output": "8 1"
},
{
"input": "7\n12 14 40 8 74 104 11",... | 1,458,976,384 | 784 | Python 3 | OK | TESTS | 172 | 77 | 4,608,000 | n = int(input())
a = [int(i) for i in input().split()]
b = 0
c = 0
d = []
for i in range(n) :
while True :
b = a[i] / 2 ** c
if b != int(b) :
break
c += 1
d.append(2 ** (c-1))
c = 0
p = max(d)
p1 = d.count(p)
print(p , p1) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Поликарп мечтает стать программистом и фанатеет от степеней двойки. Среди двух чисел ему больше нравится то, которое делится на большую степень числа 2.
По заданной последовательности целых положительных чисел *a*1,<=*a*2,<=...,... | ```python
n = int(input())
a = [int(i) for i in input().split()]
b = 0
c = 0
d = []
for i in range(n) :
while True :
b = a[i] / 2 ** c
if b != int(b) :
break
c += 1
d.append(2 ** (c-1))
c = 0
p = max(d)
p1 = d.count(p)
print(p , p1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
887 | B | Cubes for Masha | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | Absent-minded Masha got set of *n* cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*.
To make a number Masha can rotate her cubes and put them in a ro... | In first line integer *n* is given (1<=≤<=*n*<=≤<=3) — the number of cubes, Masha got for her birthday.
Each of next *n* lines contains 6 integers *a**i**j* (0<=≤<=*a**i**j*<=≤<=9) — number on *j*-th face of *i*-th cube. | Print single integer — maximum number *x* such Masha can make any integers from 1 to *x* using her cubes or 0 if Masha can't make even 1. | [
"3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n",
"3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n"
] | [
"87",
"98"
] | In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8. | 1,000 | [
{
"input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7",
"output": "87"
},
{
"input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9",
"output": "98"
},
{
"input": "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5",
"output": "5"
},
{
"input": "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8",
... | 1,509,793,726 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 102,400 | n = int(input())
lst = []
for x in range(n):
lst.append([])
for x in range(n):
spisok = list(map(int, input().split()))
lst[x] = spisok
a = []
if n != 1:
for x in range(n - 1):
for y in range(x + 1, n):
for i in lst[x]:
for z in lst[y]:
... | Title: Cubes for Masha
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Absent-minded Masha got set of *n* cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her ne... | ```python
n = int(input())
lst = []
for x in range(n):
lst.append([])
for x in range(n):
spisok = list(map(int, input().split()))
lst[x] = spisok
a = []
if n != 1:
for x in range(n - 1):
for y in range(x + 1, n):
for i in lst[x]:
for z in lst[y]:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,... | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"i... | 1,612,698,169 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n=int(input())
for i in range(2, n):
if n%i==0:
print('NO')
break
else:
print('YES')
| Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com... | ```python
n=int(input())
for i in range(2, n):
if n%i==0:
print('NO')
break
else:
print('YES')
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
371 | A | K-Periodic Array | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"math"
] | null | null | This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it... | The first line of the input contains a pair of integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100), where *n* is the length of the array and the value *n* is divisible by *k*. The second line contains the sequence of elements of the given array *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), *a**i* is the *i*-th element of ... | Print the minimum number of array elements we need to change to make the array *k*-periodic. If the array already is *k*-periodic, then print 0. | [
"6 2\n2 1 2 2 2 1\n",
"8 4\n1 1 2 1 1 1 2 1\n",
"9 3\n2 1 1 1 2 1 1 1 2\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2, 1, 2, 1, 2, 1].
In the second sample, the given array already is 4-periodic.
In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1, 1, 1, 1... | 500 | [
{
"input": "6 2\n2 1 2 2 2 1",
"output": "1"
},
{
"input": "8 4\n1 1 2 1 1 1 2 1",
"output": "0"
},
{
"input": "9 3\n2 1 1 1 2 1 1 1 2",
"output": "3"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 2\n2 2... | 1,639,067,747 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 46 | 0 | n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
lst1,lst2=[0]*n,[0]*n
for i in range(0,k):
for j in range(i,n,k):
if a[j]==1:
lst1[i]+=1
else:
lst2[i]+=1
res=0
for i in range(n//k):
res+=min(lst1[i],lst2[i])
print(res) | Title: K-Periodic Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represent... | ```python
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
lst1,lst2=[0]*n,[0]*n
for i in range(0,k):
for j in range(i,n,k):
if a[j]==1:
lst1[i]+=1
else:
lst2[i]+=1
res=0
for i in range(n//k):
res+=min(lst1[i],lst2[i])
print(res)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
277 | A | Learning Languages | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | null | null | The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official la... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages.
Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next... | Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). | [
"5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"2 2\n1 2\n0\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | 500 | [
{
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5",
"output": "0"
},
{
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1",
"output": "2"
},
{
"input": "2 2\n1 2\n0",
"output": "1"
},
{
"input": "2 2\n0\n0",
"output": "2"
},
{
"input": "5 5\n1 3\n0\n0\n2 4... | 1,578,862,315 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 307,200 | def contains(lst, grph):
for el in lst:
if len(el & grph) > 0: return True
return False
n, m = map(int, input().split(' '))
graphs = []
for _ in range(n):
line = input().split(' ')[1:]
for lang in line:
flag = False
for graph in graphs:
if lang in graph... | Title: Learning Languages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have th... | ```python
def contains(lst, grph):
for el in lst:
if len(el & grph) > 0: return True
return False
n, m = map(int, input().split(' '))
graphs = []
for _ in range(n):
line = input().split(' ')[1:]
for lang in line:
flag = False
for graph in graphs:
if lan... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
361 | B | Levko and Permutation | PROGRAMMING | 1,200 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*.
Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numbers *a* and *b*. Levko assumes that element *p**i* of permutation *p*1,<=*p*2,<=... ,<=*p**n* is good if *g... | The single line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*). | In a single line print either any beautiful permutation or -1, if such permutation doesn’t exist.
If there are multiple suitable permutations, you are allowed to print any of them. | [
"4 2\n",
"1 1\n"
] | [
"2 4 3 1",
"-1\n"
] | In the first sample elements 4 and 3 are good because *gcd*(2, 4) = 2 > 1 and *gcd*(3, 3) = 3 > 1. Elements 2 and 1 are not good because *gcd*(1, 2) = 1 and *gcd*(4, 1) = 1. As there are exactly 2 good elements, the permutation is beautiful.
The second sample has no beautiful permutations. | 1,000 | [
{
"input": "4 2",
"output": "2 1 3 4 "
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "7 4",
"output": "3 1 2 4 5 6 7 "
},
{
"input": "10 9",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10000 5000",
"output": "5000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1... | 1,661,966,000 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | import math
n,k=map(int,input().split())
if n==k or k%2!=0:
print(-1)
else:
l = []
for i in range(1,n+1):
l.append(i)
l=l[:n-k][::-1]+l[n-k:]
print(*l)
| Title: Levko and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*.
Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numb... | ```python
import math
n,k=map(int,input().split())
if n==k or k%2!=0:
print(-1)
else:
l = []
for i in range(1,n+1):
l.append(i)
l=l[:n-k][::-1]+l[n-k:]
print(*l)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,699,453,063 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 46 | 0 | n, k = [int(x) for x in input().split()]
for i in range(1, n + 1):
k += i * 5
if k == 240:
print(i)
quit()
if k > 240:
print(i - 1)
quit()
print(i) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
n, k = [int(x) for x in input().split()]
for i in range(1, n + 1):
k += i * 5
if k == 240:
print(i)
quit()
if k > 240:
print(i - 1)
quit()
print(i)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,670,663,237 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 2,000 | 1,331,200 | class solve:
def __init__(self):
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
ans=[0]*m
for i in range(m):
j=0
while a[j]<=b[i]:
ans[i]+=1
print(*ans)... | Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
class solve:
def __init__(self):
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
ans=[0]*m
for i in range(m):
j=0
while a[j]<=b[i]:
ans[i]+=1
p... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
628 | B | New Skateboard | PROGRAMMING | 1,300 | [
"dp"
] | null | null | Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which... | The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9. | Print integer *a* — the number of substrings of the string *s* that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"124\n",
"04\n",
"5810438174\n"
] | [
"4\n",
"3\n",
"9\n"
] | none | 0 | [
{
"input": "124",
"output": "4"
},
{
"input": "04",
"output": "3"
},
{
"input": "5810438174",
"output": "9"
},
{
"input": "1",
"output": "0"
},
{
"input": "039",
"output": "1"
},
{
"input": "97247",
"output": "6"
},
{
"input": "5810438174",... | 1,586,295,456 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 420 | 1,024,000 | s = input()
sLen = len(s)
answer = 0
for i in range(sLen-1, -1, -1):
if int(s[i]) % 4 == 0:
answer += 1
if i-1 == -1:
break
if int(s[i-1] + s[i]) % 4 == 0:
answer += i
print(answer)
| Title: New Skateboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother... | ```python
s = input()
sLen = len(s)
answer = 0
for i in range(sLen-1, -1, -1):
if int(s[i]) % 4 == 0:
answer += 1
if i-1 == -1:
break
if int(s[i-1] + s[i]) % 4 == 0:
answer += i
print(answer)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi... | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,620,603,834 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 6,963,200 | #e
fh = open("input.txt", "w")
n,m = fh.read()
n = int(n)
m = int(m)
word = ""
if n > m:
number = n - m
while (m>0):
m -= 1
word+= "BG"
while (number>0):
number -=1
word+= "B"
else:
while (n >0):
n -= 1
word+= "GB"
while (number>0):
number -=1
word+= "G"
fhout = open("output.txt... | Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n... | ```python
#e
fh = open("input.txt", "w")
n,m = fh.read()
n = int(n)
m = int(m)
word = ""
if n > m:
number = n - m
while (m>0):
m -= 1
word+= "BG"
while (number>0):
number -=1
word+= "B"
else:
while (n >0):
n -= 1
word+= "GB"
while (number>0):
number -=1
word+= "G"
fhout = open("... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
675 | C | Money Transfers | PROGRAMMING | 2,100 | [
"constructive algorithms",
"data structures",
"greedy",
"sortings"
] | null | null | There are *n* banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank *n* are neighbours if *n*<=><=1. No bank is a neighbour of itself.
Vasya has an account in each bank. Its balance may be negative... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of banks.
The second line contains *n* integers *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109), the *i*-th of them is equal to the initial balance of the account in the *i*-th bank. It's guaranteed that the sum of all *a**i* is equal... | Print the minimum number of operations required to change balance in each bank to zero. | [
"3\n5 0 -5\n",
"4\n-1 0 1 0\n",
"4\n1 2 3 -6\n"
] | [
"1\n",
"2\n",
"3\n"
] | In the first sample, Vasya may transfer 5 from the first bank to the third.
In the second sample, Vasya may first transfer 1 from the third bank to the second, and then 1 from the second to the first.
In the third sample, the following sequence provides the optimal answer:
1. transfer 1 from the first bank to the ... | 1,500 | [
{
"input": "3\n5 0 -5",
"output": "1"
},
{
"input": "4\n-1 0 1 0",
"output": "2"
},
{
"input": "4\n1 2 3 -6",
"output": "3"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "50\n108431864 128274949 -554057370 -384620666 -202862975 -803855410 -482167063 -55139054 ... | 1,463,834,051 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 4,608,000 | n = int(input())
# m = [int(i) for i in input().split()]
m = input().split()
def search(m,j):
if j in ''.join(m):
j = j + '0'
return search(m,j)
else:
return len(j)
# m = ''.join(input().split())
j = '0'
if j in ''.join(m):
print(len(m) - search(m,j))
else:
print(len(m) - 1)
| Title: Money Transfers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank *n* are neighbours if *n*<=><... | ```python
n = int(input())
# m = [int(i) for i in input().split()]
m = input().split()
def search(m,j):
if j in ''.join(m):
j = j + '0'
return search(m,j)
else:
return len(j)
# m = ''.join(input().split())
j = '0'
if j in ''.join(m):
print(len(m) - search(m,j))
else:
print(len(m) - 1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
489 | B | BerSU Ball | PROGRAMMING | 1,200 | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"sortings",
"two pointers"
] | null | null | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in eac... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth l... | Print a single number — the required maximum possible number of pairs. | [
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
] | [
"3\n",
"0\n",
"2\n"
] | none | 1,000 | [
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9",
"output": "3"
},
{
"input": "4\n1 2 3 4\n4\n10 11 12 13",
"output": "0"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3",
"output": "2"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 10\n1\n9",
"output": "1"
},
{... | 1,695,985,629 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 46 | 0 | len_girls = int(input())
girls = [int(x) for x in input().split()]
len_boys = int(input())
boys = [int(x) for x in input().split()]
girls.sort()
boys.sort()
b = -1
g = -1
max_ = 0
while g >= -len_girls and b >= -len_boys:
diff = boys[b] - girls[g]
if abs(diff) <=1:
max_ +=1
g-=1
b-=... | Title: BerSU Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy... | ```python
len_girls = int(input())
girls = [int(x) for x in input().split()]
len_boys = int(input())
boys = [int(x) for x in input().split()]
girls.sort()
boys.sort()
b = -1
g = -1
max_ = 0
while g >= -len_girls and b >= -len_boys:
diff = boys[b] - girls[g]
if abs(diff) <=1:
max_ +=1
g-=1
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
88 | B | Keyboard | PROGRAMMING | 1,500 | [
"implementation"
] | B. Keyboard | 1 | 256 | Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they m... | The first line contains three integers *n*, *m*, *x* (1<=≤<=*n*,<=*m*<=≤<=30,<=1<=≤<=*x*<=≤<=50).
Next *n* lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly *m* keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys ... | If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes). | [
"2 2 1\nab\ncd\n1\nA\n",
"2 2 1\nab\ncd\n1\ne\n",
"2 2 1\nab\ncS\n5\nabcBA\n",
"3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG\n"
] | [
"-1\n",
"-1\n",
"1\n",
"2\n"
] | In the first sample the symbol "A" is impossible to print as there's no "Shift" key on the keyboard.
In the second sample the symbol "e" is impossible to print as there's no such key on the keyboard.
In the fourth sample the symbols "T", "G" are impossible to print with one hand. The other letters that are on the key... | 1,000 | [
{
"input": "2 2 1\nab\ncd\n1\nA",
"output": "-1"
},
{
"input": "2 2 1\nab\ncd\n1\ne",
"output": "-1"
},
{
"input": "2 2 1\nab\ncS\n5\nabcBA",
"output": "1"
},
{
"input": "3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG",
"output": "2"
},
... | 1,562,644,556 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define clr(x) memset((x), 0, sizeof(x))
#def... | Title: Keyboard
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on ... | ```python
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define clr(x) memset((x), 0, sizeof... | -1 | MatrixStudio/Codeforces-Python-Submissions |
609 | C | Load Balancing | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server.
In order to balance the load for each server, you want to reassign some tasks to make the differe... | The first line contains positive number *n* (1<=≤<=*n*<=≤<=105) — the number of the servers.
The second line contains the sequence of non-negative integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=≤<=2·104), where *m**i* is the number of tasks assigned to the *i*-th server. | Print the minimum number of seconds required to balance the load. | [
"2\n1 6\n",
"7\n10 11 10 11 10 11 11\n",
"5\n1 2 3 4 5\n"
] | [
"2\n",
"0\n",
"3\n"
] | In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2.
In the second example the load is already balanced.
A possible sequence of task movements for the third example is:
... | 0 | [
{
"input": "2\n1 6",
"output": "2"
},
{
"input": "7\n10 11 10 11 10 11 11",
"output": "0"
},
{
"input": "5\n1 2 3 4 5",
"output": "3"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n20000",
... | 1,684,231,006 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n = int(input())
tasks = list(map(int, input().split()))
total_tasks = sum(tasks)
avg_tasks = total_tasks // n
max_diff = 0
current_diff = 0
for num_tasks in tasks:
current_diff += num_tasks - avg_tasks
max_diff = max(max_diff, abs(current_diff))
min_seconds = max_diff
print(min_seconds)
| Title: Load Balancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server... | ```python
n = int(input())
tasks = list(map(int, input().split()))
total_tasks = sum(tasks)
avg_tasks = total_tasks // n
max_diff = 0
current_diff = 0
for num_tasks in tasks:
current_diff += num_tasks - avg_tasks
max_diff = max(max_diff, abs(current_diff))
min_seconds = max_diff
print(min_seco... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,669,482,189 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 154 | 0 |
cin = [*open(0)]
n, t = cin[0].split()
t = int(t)
bs = list(map(int, cin[1].split()))
def solve(t, bs):
ma = -1
s = 0
while s < len(bs):
if t < bs[s]:
s += 1
continue
e = s
while e < len(bs) and t >= bs[e]:
t -= bs[e]
... | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
cin = [*open(0)]
n, t = cin[0].split()
t = int(t)
bs = list(map(int, cin[1].split()))
def solve(t, bs):
ma = -1
s = 0
while s < len(bs):
if t < bs[s]:
s += 1
continue
e = s
while e < len(bs) and t >= bs[e]:
t -= bs[e]
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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, ... | 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": "tymbzjyqhymeda... | 1,679,166,326 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | a=input()
hi=a.index('h')
ho=a.index('o')
c=0
p=0
x='hello'
for i in a[hi:ho+1]:
if x[c]==i:
c+=1
p+=1
if p==5:
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 letter... | ```python
a=input()
hi=a.index('h')
ho=a.index('o')
c=0
p=0
x='hello'
for i in a[hi:ho+1]:
if x[c]==i:
c+=1
p+=1
if p==5:
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the... | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"... | 1,693,671,762 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | s = input()
def find_password(s):
n = len(s)
candidate_t = ""
# Iterate over possible prefix lengths (excluding the first character)
for i in range(1, n//3+1):
prefix = s[:i]
suffix = s[-i:]
# Check if the prefix and suffix match
if prefix == suffix:
... | Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carve... | ```python
s = input()
def find_password(s):
n = len(s)
candidate_t = ""
# Iterate over possible prefix lengths (excluding the first character)
for i in range(1, n//3+1):
prefix = s[:i]
suffix = s[-i:]
# Check if the prefix and suffix match
if prefix == suff... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
11 | B | Jumping Jack | PROGRAMMING | 1,600 | [
"math"
] | B. Jumping Jack | 1 | 64 | Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri... | The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109). | Output the minimal number of jumps that Jack requires to reach *x*. | [
"2\n",
"6\n",
"0\n"
] | [
"3\n",
"3\n",
"0\n"
] | none | 0 | [
{
"input": "2",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "0",
"output": "0"
},
{
"input": "-1000000000",
"output": "44723"
},
{
"input": "999961560",
"output": "44720"
},
{
"input": "999961561",
"output": "44721"
},
{
"i... | 1,562,535,754 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | """
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ... | Title: Jumping Jack
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each ... | ```python
"""
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go eithe... | 3.876 | MatrixStudio/Codeforces-Python-Submissions |
0 | none | none | none | 0 | [
"none"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. ... | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 0 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
... | 1,511,354,279 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 0 | num1,num2,num3,num4,num5,num6=input().split()
num1=int(num1)
num2=int(num2)
num3=int(num3)
num4=int(num4)
num5=int(num5)
num6=int(num6)
if((num1+num2+num3==num4+num5+num6) or (num1+num2+num4==num3+num5+num6) or (num1+num3+num4==num2+num5+num6) or (num2+num3+num4==num1+num5+num6)):
print("YES")
elif((num1+n... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exac... | ```python
num1,num2,num3,num4,num5,num6=input().split()
num1=int(num1)
num2=int(num2)
num3=int(num3)
num4=int(num4)
num5=int(num5)
num6=int(num6)
if((num1+num2+num3==num4+num5+num6) or (num1+num2+num4==num3+num5+num6) or (num1+num3+num4==num2+num5+num6) or (num2+num3+num4==num1+num5+num6)):
print("YES")
el... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,668,118,803 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | def xc3(x):
res = x*(x-1)*(x-2)
res //= 6
return res
n, d = map(int, input().split())
l = list(map(int, input().split()))
max = 1
x = 0
sum = 0
while(max < n):
pre_max = max
while(max < n and l[max] - l[x] <= d):
max += 1
if(pre_max != max):
sum += xc3(max-x)
x += 1
pri... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
def xc3(x):
res = x*(x-1)*(x-2)
res //= 6
return res
n, d = map(int, input().split())
l = list(map(int, input().split()))
max = 1
x = 0
sum = 0
while(max < n):
pre_max = max
while(max < n and l[max] - l[x] <= d):
max += 1
if(pre_max != max):
sum += xc3(max-x)
x +... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
369 | A | Valera and Plates | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can... | The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Val... | Print a single integer — the minimum number of times Valera will need to wash a plate/bowl. | [
"3 1 1\n1 2 1\n",
"4 3 1\n1 1 1 1\n",
"3 1 2\n2 2 2\n",
"8 2 2\n1 2 1 2 1 2 1 2\n"
] | [
"1\n",
"1\n",
"0\n",
"4\n"
] | In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all... | 500 | [
{
"input": "3 1 1\n1 2 1",
"output": "1"
},
{
"input": "4 3 1\n1 1 1 1",
"output": "1"
},
{
"input": "3 1 2\n2 2 2",
"output": "0"
},
{
"input": "8 2 2\n1 2 1 2 1 2 1 2",
"output": "4"
},
{
"input": "2 100 100\n2 2",
"output": "0"
},
{
"input": "1 1 1\... | 1,539,666,956 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | n, m, k = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in a:
if i==1:
if m==0: count+=1
else: m-=1
else:
if k==0: count+=1
else: k-=1
print(count) | Title: Valera and Plates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, ... | ```python
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in a:
if i==1:
if m==0: count+=1
else: m-=1
else:
if k==0: count+=1
else: k-=1
print(count)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,632,042,848 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 124 | 6,758,400 | s=input()
s=s.replace('144','___')
s=s.replace('14','__')
s=s.replace('1','_')
print('NO' if s.count('_')!=len(s) else 'YES') | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
s=input()
s=s.replace('144','___')
s=s.replace('14','__')
s=s.replace('1','_')
print('NO' if s.count('_')!=len(s) else 'YES')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,595,767,602 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 6,656,000 | import math
sim,ant,num=map(int,input().split())
checkcon=True
while(checkcon):
num = num - math.gcd(sim,num)
if(num==0):
print('0')
checkcon=False
num = num- math.gcd(ant,num)
if(num==0):
print('1')
checkcon=False | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
import math
sim,ant,num=map(int,input().split())
checkcon=True
while(checkcon):
num = num - math.gcd(sim,num)
if(num==0):
print('0')
checkcon=False
num = num- math.gcd(ant,num)
if(num==0):
print('1')
checkcon=False
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,655,534,809 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | a, b = map(int, input().split())
s = a
c = a
while c >= b:
a = c // b
s = s + a
c = c % b + a
print(s)
| Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
a, b = map(int, input().split())
s = a
c = a
while c >= b:
a = c // b
s = s + a
c = c % b + a
print(s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
457 | A | Golden System | PROGRAMMING | 1,700 | [
"math",
"meet-in-the-middle"
] | null | null | Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number , in particular that *q*2<==<=*q*<=+<=1, and she thinks it would make a good base for her new unique system. She called it "golden system". In golden system the number is a n... | Input consists of two lines — one for each number. Each line contains non-empty string consisting of '0' and '1' characters. The length of each string does not exceed 100000. | Print ">" if the first number is larger, "<" if it is smaller and "=" if they are equal. | [
"1000\n111\n",
"00100\n11\n",
"110\n101\n"
] | [
"<\n",
"=\n",
">\n"
] | In the first example first number equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9c955eec678d6e7dcdc7c94fb203e922d2ad19ad.png" style="max-width: 100.0%;max-height: 100.0%;"/>, while second number is approximately 1.618033988<sup class="upper-index">2</sup> + 1.618033988 + 1 ≈ 5.2... | 1,000 | [
{
"input": "1000\n111",
"output": "<"
},
{
"input": "00100\n11",
"output": "="
},
{
"input": "110\n101",
"output": ">"
},
{
"input": "0\n0",
"output": "="
},
{
"input": "1\n10",
"output": "<"
},
{
"input": "11\n10",
"output": ">"
},
{
"inpu... | 1,689,443,416 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 307,200 | import math
import decimal
c = decimal.Decimal(math.sqrt(5))
c += 1
c /= 2
a = input()
b = input()
a_c = decimal.Decimal(0)
b_c = decimal.Decimal(0)
i = 0
while (i<len(a)):
q = (int(a[-(1 + i)]))
if q == 1:
a_c = a_c + (c**i)
i+=1
i=0
while (i<len(b)):
q = (int(a[-(1 + i... | Title: Golden System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number , in particular that *q*2<==<=*q*<=+<=1, and she thinks it would make a goo... | ```python
import math
import decimal
c = decimal.Decimal(math.sqrt(5))
c += 1
c /= 2
a = input()
b = input()
a_c = decimal.Decimal(0)
b_c = decimal.Decimal(0)
i = 0
while (i<len(a)):
q = (int(a[-(1 + i)]))
if q == 1:
a_c = a_c + (c**i)
i+=1
i=0
while (i<len(b)):
q = (int... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
177 | A1 | Good Matrix Elements | PROGRAMMING | 800 | [
"implementation"
] | null | null | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which ha... | The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 po... | Print a single integer — the sum of good matrix elements. | [
"3\n1 2 3\n4 5 6\n7 8 9\n",
"5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n"
] | [
"45\n",
"17\n"
] | In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | 30 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "45"
},
{
"input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "17"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33",
... | 1,557,921,783 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS1 | 3 | 186 | 0 | n=int(input())
a=[]
s=0
for i in range(n):
b=list(map(int,input().split()))
a.append(b)
s+=sum(a[int(n-1/2)])
for i in range(n):
s+=a[i][int(n-1/2)]
s+=a[i][i]
s+=a[(n-1)-i][i]
k=int(n-1/2)
print(s-3*(a[k][k])) | Title: Good Matrix Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the ... | ```python
n=int(input())
a=[]
s=0
for i in range(n):
b=list(map(int,input().split()))
a.append(b)
s+=sum(a[int(n-1/2)])
for i in range(n):
s+=a[i][int(n-1/2)]
s+=a[i][i]
s+=a[(n-1)-i][i]
k=int(n-1/2)
print(s-3*(a[k][k]))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,694,710,193 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | n=list(map(int,input().split()))
m=list(map(int,input().split()))
s=[]
for i in range(n[0]):
if(m[i]<0):
s.append(abs(m[i]))
s.sort(reverse=True)
sum=0
if(len(s)>=n[1]):
for i in range(n[1]):
sum+=s[i]
else:
for i in range(len(s)):
sum+=s[i]
print(sum)
| Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
n=list(map(int,input().split()))
m=list(map(int,input().split()))
s=[]
for i in range(n[0]):
if(m[i]<0):
s.append(abs(m[i]))
s.sort(reverse=True)
sum=0
if(len(s)>=n[1]):
for i in range(n[1]):
sum+=s[i]
else:
for i in range(len(s)):
sum+=s[i]
print(sum)... | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
343 | B | Alternating Current | PROGRAMMING | 1,600 | [
"data structures",
"greedy",
"implementation"
] | null | null | Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u... | The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | [
"-++-\n",
"+-\n",
"++\n",
"-\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"No\n"
] | The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
In the second testcase the "plus" wire makes one full rev... | 1,000 | [
{
"input": "-++-",
"output": "Yes"
},
{
"input": "+-",
"output": "No"
},
{
"input": "++",
"output": "Yes"
},
{
"input": "-",
"output": "No"
},
{
"input": "+-+-",
"output": "No"
},
{
"input": "-+-",
"output": "No"
},
{
"input": "-++-+--+",
... | 1,662,293,808 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | c = input()
can_untangle = 0
minus =0
for i in c:
if i == '+':
can_untangle+=1
elif i == '-' and can_untangle != 0:
can_untangle -=1
else:
minus += 1
if can_untangle and minus:
can_untangle = 0:
if can_untangle and len(c) != 1:
print("Yes")
else:
print(... | Title: Alternating Current
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it... | ```python
c = input()
can_untangle = 0
minus =0
for i in c:
if i == '+':
can_untangle+=1
elif i == '-' and can_untangle != 0:
can_untangle -=1
else:
minus += 1
if can_untangle and minus:
can_untangle = 0:
if can_untangle and len(c) != 1:
print("Yes")
else:
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,619,483,190 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | #d
w = input()
name = ["h","e","i","d","i"]
s = ""
flag = False
for i in range(len(w)):
if w[i] in name:
if w[i] not in s or w[i] == "i":
s+= w[i]
if (s == "heidi"):
flag = True
break
if (flag):
print("YES")
else:
print("NO")
| Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
#d
w = input()
name = ["h","e","i","d","i"]
s = ""
flag = False
for i in range(len(w)):
if w[i] in name:
if w[i] not in s or w[i] == "i":
s+= w[i]
if (s == "heidi"):
flag = True
break
if (flag):
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | One day Petya was solving a very interesting problem. But although he used many optimization techniques, his solution still got Time limit exceeded verdict. Petya conducted a thorough analysis of his program and found out that his function for finding maximum element in an array of *n* positive integers was too slow. D... | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=106), separated by a space — the length of the permutations and the parameter *k*. | Output the answer to the problem modulo 109<=+<=7. | [
"5 2\n",
"5 3\n",
"6 3\n"
] | [
"22\n",
"6\n",
"84\n"
] | Permutations from second example:
[4, 1, 2, 3, 5], [4, 1, 3, 2, 5], [4, 2, 1, 3, 5], [4, 2, 3, 1, 5], [4, 3, 1, 2, 5], [4, 3, 2, 1, 5]. | 0 | [] | 1,510,770,529 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | import math
(n,k) = (int(i) for i in input().split())
# n,k = 6, 3
summ = 0
for i in range(k+1, n):
gg = 0
for j in range(i-k):
gg+=math.factorial(n-k-1-j)/math.factorial(i-k-j-1)
summ+= math.factorial(i-1)*gg
summ = summ % (10**9+7)
print(summ)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Petya was solving a very interesting problem. But although he used many optimization techniques, his solution still got Time limit exceeded verdict. Petya conducted a thorough analysis of his program and found out that his... | ```python
import math
(n,k) = (int(i) for i in input().split())
# n,k = 6, 3
summ = 0
for i in range(k+1, n):
gg = 0
for j in range(i-k):
gg+=math.factorial(n-k-1-j)/math.factorial(i-k-j-1)
summ+= math.factorial(i-1)*gg
summ = summ % (10**9+7)
print(summ)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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 ex... | 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... | 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 ... | 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... | 1,694,710,632 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <cstdio>
int main()
{
int n, a, b, c(0), m(0);
scanf("%d", &n);
while (n--)
{
scanf("%d%d", &a, &b);
c -= a;
c += b;
if (c > m)
{
m = c;
}
}
printf("%d\n", m);
return 0;
} | 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 ... | ```python
#include <cstdio>
int main()
{
int n, a, b, c(0), m(0);
scanf("%d", &n);
while (n--)
{
scanf("%d%d", &a, &b);
c -= a;
c += b;
if (c > m)
{
m = c;
}
}
printf("%d\n", m);
return 0;
}
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and telepor... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cars in the train.
The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*, *p**i*<=≠<=*p**j* if *i*<=≠<=*j*) — the sequence of the numbers of the cars in the train. | Print a single integer — the minimum number of actions needed to sort the railway cars. | [
"5\n4 1 2 5 3\n",
"4\n4 1 3 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train. | 0 | [
{
"input": "5\n4 1 2 5 3",
"output": "2"
},
{
"input": "4\n4 1 3 2",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "6\n5 3 6 1 4 2",
"output": "4"
},
... | 1,691,906,206 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 66 | 93 | 12,492,800 | n=int(input())
notfair=[0]*(n+1)
l=list(map(int,input().split()))
for i in l:
notfair[i]=notfair[i-1]+1
ans=max(notfair)
print(n-ans)
#no problem | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increa... | ```python
n=int(input())
notfair=[0]*(n+1)
l=list(map(int,input().split()))
for i in l:
notfair[i]=notfair[i-1]+1
ans=max(notfair)
print(n-ans)
#no problem
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
777 | C | Alyona and Spreadsheet | PROGRAMMING | 1,600 | [
"binary search",
"data structures",
"dp",
"greedy",
"implementation",
"two pointers"
] | null | null | During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the tab... | The first line of the input contains two positive integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=100<=000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the followi... | Print "Yes" to the *i*-th line of the output if the table consisting of rows from *l**i* to *r**i* inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No". | [
"5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n"
] | [
"Yes\nNo\nYes\nYes\nYes\nNo\n"
] | In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3. | 1,500 | [
{
"input": "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5",
"output": "Yes\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "1 1\n1\n1\n1 1",
"output": "Yes"
},
{
"input": "10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n38686565... | 1,569,149,891 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define int int64_t
using namespace std;
const int inf = numeric_limits<int>::max(),
MAX = 1e6,
MOD = 1e9 + 7;
int32_t main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, m; cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
for ... | Title: Alyona and Spreadsheet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By ... | ```python
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
const int inf = numeric_limits<int>::max(),
MAX = 1e6,
MOD = 1e9 + 7;
int32_t main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, m; cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
593 | B | Anton and Lines | PROGRAMMING | 1,600 | [
"geometry",
"sortings"
] | null | null | The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of *n* lines defined by the equations *y*<==<=*k**i*·*x*<=+<=*b**i*. It was necessary to determine whether there is at least one point of intersection of t... | The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of lines in the task given to Anton. The second line contains integers *x*1 and *x*2 (<=-<=1<=000<=000<=≤<=*x*1<=<<=*x*2<=≤<=1<=000<=000) defining the strip inside which you need to find a point of intersection of at least two ... | Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes). | [
"4\n1 2\n1 2\n1 0\n0 1\n0 2\n",
"2\n1 3\n1 0\n-1 3\n",
"2\n1 3\n1 0\n0 2\n",
"2\n1 3\n1 0\n0 3\n"
] | [
"NO",
"YES",
"YES",
"NO"
] | In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. | 1,000 | [
{
"input": "4\n1 2\n1 2\n1 0\n0 1\n0 2",
"output": "NO"
},
{
"input": "2\n1 3\n1 0\n-1 3",
"output": "YES"
},
{
"input": "2\n1 3\n1 0\n0 2",
"output": "YES"
},
{
"input": "2\n1 3\n1 0\n0 3",
"output": "NO"
},
{
"input": "2\n0 1\n-1000000 1000000\n1000000 -1000000"... | 1,446,666,791 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 811 | 25,292,800 | """
Codeforces Round #329 (Div. 2)
Problem 593 B. Anton and Lines
@author yamaton
@date 2015-11-04
"""
import itertools as it
import functools
import operator
import collections
import math
import sys
EPSILON = 0.0000001
def solve(x1, x2, kbs):
at_x1 = [k*(x1 + EPSILON) + b for (k, b) in kbs]
at_x2 = [k*(... | Title: Anton and Lines
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of *n* lines defined by the equations *y*<==<=*k**i*·*... | ```python
"""
Codeforces Round #329 (Div. 2)
Problem 593 B. Anton and Lines
@author yamaton
@date 2015-11-04
"""
import itertools as it
import functools
import operator
import collections
import math
import sys
EPSILON = 0.0000001
def solve(x1, x2, kbs):
at_x1 = [k*(x1 + EPSILON) + b for (k, b) in kbs]
at... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
810 | B | Summer sell-off | PROGRAMMING | 1,300 | [
"greedy",
"sortings"
] | null | null | Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manag... | The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denotin... | Print a single integer denoting the maximal number of products that shop can sell. | [
"4 2\n2 1\n3 5\n2 3\n1 5\n",
"4 1\n0 2\n0 3\n3 5\n0 6\n"
] | [
"10",
"5"
] | In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the s... | 1,000 | [
{
"input": "4 2\n2 1\n3 5\n2 3\n1 5",
"output": "10"
},
{
"input": "4 1\n0 2\n0 3\n3 5\n0 6",
"output": "5"
},
{
"input": "1 1\n5 8",
"output": "8"
},
{
"input": "2 1\n8 12\n6 11",
"output": "19"
},
{
"input": "2 1\n6 7\n5 7",
"output": "13"
},
{
"inpu... | 1,572,260,196 | 2,147,483,647 | Python 3 | OK | TESTS | 159 | 576 | 10,752,000 | n,f=map(int,input().split())
ml=[]
for i in range(n):
k,l=map(int,input().split())
t=((min(2*k,l)-min(k,l)),k,l)
ml.append(t)
ml.sort(reverse=True)
r=0
for i in range(f):
r+=min(2*ml[i][1],ml[i][2])
for i in range(f,n):
r+=min(ml[i][1],ml[i][2])
print(r)
| Title: Summer sell-off
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an ass... | ```python
n,f=map(int,input().split())
ml=[]
for i in range(n):
k,l=map(int,input().split())
t=((min(2*k,l)-min(k,l)),k,l)
ml.append(t)
ml.sort(reverse=True)
r=0
for i in range(f):
r+=min(2*ml[i][1],ml[i][2])
for i in range(f,n):
r+=min(ml[i][1],ml[i][2])
print(r)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,651,915,789 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n,k = map(int, input().split())
s=[]
c=0
for i in range(k+1):
s+=str(i)
for i in range(n):
b = input()
for v in b:
if v in s:
c+=1
else:
c-=1
print(c-(k*n)) | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
n,k = map(int, input().split())
s=[]
c=0
for i in range(k+1):
s+=str(i)
for i in range(n):
b = input()
for v in b:
if v in s:
c+=1
else:
c-=1
print(c-(k*n))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,551,473,679 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 0 | ensem=set()
n=int(input())
for i in range(n):
e=int(input())
ensem.add(e)
if len(ensem)<2:
print("NO")
else:
ls=list(ensem)
ls.sort()
print (ls[1]) | Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
ensem=set()
n=int(input())
for i in range(n):
e=int(input())
ensem.add(e)
if len(ensem)<2:
print("NO")
else:
ls=list(ensem)
ls.sort()
print (ls[1])
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
30 | A | Accounting | PROGRAMMING | 1,400 | [
"brute force",
"math"
] | A. Accounting | 2 | 256 | A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there w... | The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10). | Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them. | [
"2 18 2\n",
"-1 8 3\n",
"0 0 10\n",
"1 16 5\n"
] | [
"3",
"-2",
"5",
"No solution"
] | none | 500 | [
{
"input": "2 18 2",
"output": "3"
},
{
"input": "-1 8 3",
"output": "-2"
},
{
"input": "0 0 10",
"output": "5"
},
{
"input": "1 16 5",
"output": "No solution"
},
{
"input": "0 1 2",
"output": "No solution"
},
{
"input": "3 0 4",
"output": "0"
},... | 1,634,208,848 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 |
a,b,n=map(int,input().split())
for x in range(-20,20):
if a*x**n==b:
print(x)
break
else:
print("No solution") | Title: Accounting
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as th... | ```python
a,b,n=map(int,input().split())
for x in range(-20,20):
if a*x**n==b:
print(x)
break
else:
print("No solution")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,537,362,881 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 108 | 0 | n=int(input())
p=int(input())
if abs(n-p)%2==0:
kam=(n-p)//2
printt=(sum(list(range(1,kam+1))))
print(printt*2)
else:
kam=abs((n-p))//2
tod=sum(list(range(1,kam+1)))
tod*=2
print(kam+1+tod)
| Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
n=int(input())
p=int(input())
if abs(n-p)%2==0:
kam=(n-p)//2
printt=(sum(list(range(1,kam+1))))
print(printt*2)
else:
kam=abs((n-p))//2
tod=sum(list(range(1,kam+1)))
tod*=2
print(kam+1+tod)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
859 | C | Pie Rules | PROGRAMMING | 1,500 | [
"dp",
"games"
] | null | null | You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be ... | Input will begin with an integer *N* (1<=≤<=*N*<=≤<=50), the number of slices of pie.
Following this is a line with *N* integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out. | Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally. | [
"3\n141 592 653\n",
"5\n10 21 10 21 10\n"
] | [
"653 733\n",
"31 41\n"
] | In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself. | 1,000 | [
{
"input": "3\n141 592 653",
"output": "653 733"
},
{
"input": "5\n10 21 10 21 10",
"output": "31 41"
},
{
"input": "1\n100000",
"output": "0 100000"
},
{
"input": "50\n100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 10... | 1,505,587,978 | 4,678 | PyPy 3 | WRONG_ANSWER | PRETESTS | 2 | 78 | 0 | n=int(input())
seq=list(map(int, input().split()))
bob=0
alice=0
token=True
for i in range(n-2):
if(2*max(seq[i::])>=sum(seq[i::])):
if token:
alice+=seq[i]
else:
bob+=seq[i]
else:
if token:
bob+=seq[i]
token=False
else:
alice+=seq[i]
token=True
... | Title: Pie Rules
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have... | ```python
n=int(input())
seq=list(map(int, input().split()))
bob=0
alice=0
token=True
for i in range(n-2):
if(2*max(seq[i::])>=sum(seq[i::])):
if token:
alice+=seq[i]
else:
bob+=seq[i]
else:
if token:
bob+=seq[i]
token=False
else:
alice+=seq[i]
to... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
816 | B | Karen and Coffee | PROGRAMMING | 1,400 | [
"binary search",
"data structures",
"implementation"
] | null | null | To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee ... | The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe ... | For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | [
"3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n",
"2 1 1\n1 1\n200000 200000\n90 100\n"
] | [
"3\n3\n0\n4\n",
"0\n"
] | In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperatur... | 1,000 | [
{
"input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100",
"output": "3\n3\n0\n4"
},
{
"input": "2 1 1\n1 1\n200000 200000\n90 100",
"output": "0"
},
{
"input": "1 1 1\n1 1\n1 1",
"output": "1"
},
{
"input": "1 1 1\n200000 200000\n200000 200000",
"output": "1"
... | 1,665,080,708 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 9 | 373 | 25,292,800 | from sys import stdin
input = stdin.readline
from collections import defaultdict
from bisect import bisect_left
delta = defaultdict(int)
length, threshold, num_queries = [int(x) for x in input().split()]
# print("threshold = ", threshold)
for _ in range(length):
low, high = [int(x) for x in input(... | Title: Karen and Coffee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading seve... | ```python
from sys import stdin
input = stdin.readline
from collections import defaultdict
from bisect import bisect_left
delta = defaultdict(int)
length, threshold, num_queries = [int(x) for x in input().split()]
# print("threshold = ", threshold)
for _ in range(length):
low, high = [int(x) for x... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
920 | C | Swap Adjacent Elements | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"math",
"sortings",
"two pointers"
] | null | null | You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. T... | The first line contains one integer *n* (2<=≤<=*n*<=≤<=200000) — the number of elements in the array.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=200000) — the elements of the array. Each integer from 1 to *n* appears exactly once.
The third line contains a string of *n*<=-<=1 char... | If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO. | [
"6\n1 2 5 3 4 6\n01110\n",
"6\n1 2 5 3 4 6\n01010\n"
] | [
"YES\n",
"NO\n"
] | In the first example you may swap *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, and then swap *a*<sub class="lower-index">4</sub> and *a*<sub class="lower-index">5</sub>. | 0 | [
{
"input": "6\n1 2 5 3 4 6\n01110",
"output": "YES"
},
{
"input": "6\n1 2 5 3 4 6\n01010",
"output": "NO"
},
{
"input": "6\n1 6 3 4 5 2\n01101",
"output": "NO"
},
{
"input": "6\n2 3 1 4 5 6\n01111",
"output": "NO"
},
{
"input": "4\n2 3 1 4\n011",
"output": "NO... | 1,586,697,715 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 14,643,200 | "https://codeforces.com/contest/920/problem/C"
import collections, heapq, itertools, math
groupby = itertools.groupby
rs = lambda: input()
ri = lambda: int(input())
rm = lambda: map(int, input().split())
rai = lambda: [int(x) for x in input().split()]
def solve(n,main,index):
can_swap = set()
sort... | Title: Swap Adjacent Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<... | ```python
"https://codeforces.com/contest/920/problem/C"
import collections, heapq, itertools, math
groupby = itertools.groupby
rs = lambda: input()
ri = lambda: int(input())
rm = lambda: map(int, input().split())
rai = lambda: [int(x) for x in input().split()]
def solve(n,main,index):
can_swap = set()... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"... | 1,696,328,158 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | n = int(input())
rooms_with_free_space = 0
for i in range(n):
pi, qi = map(int, input().split())
if qi - pi >= 2:
rooms_with_free_space += 1
print(rooms_with_free_space)
| Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want ... | ```python
n = int(input())
rooms_with_free_space = 0
for i in range(n):
pi, qi = map(int, input().split())
if qi - pi >= 2:
rooms_with_free_space += 1
print(rooms_with_free_space)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
892 | A | Greed | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<... | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower). | [
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, there are already 2 cans, so the answer is "YES". | 500 | [
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9... | 1,511,076,372 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 139 | 18,739,200 | n = int(input())
vc = map(int, input().split())
vb = list(map(int, input().split()))
Vc = sum(vc)
mx1 = max(vb)
vb.remove(mx1)
mx2 = max(vb)
if mx1+mx2>=Vc: print('YES')
else: print('NO') | Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he c... | ```python
n = int(input())
vc = map(int, input().split())
vb = list(map(int, input().split()))
Vc = sum(vc)
mx1 = max(vb)
vb.remove(mx1)
mx2 = max(vb)
if mx1+mx2>=Vc: print('YES')
else: print('NO')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.