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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
234 | A | Lefthanders and Righthanders | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the chi... | The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander. | Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by space... | [
"6\nLLRLLL\n",
"4\nRRLL\n"
] | [
"1 4\n2 5\n6 3\n",
"3 1\n4 2\n"
] | none | 0 | [
{
"input": "6\nLLRLLL",
"output": "1 4\n2 5\n6 3"
},
{
"input": "4\nRRLL",
"output": "3 1\n4 2"
},
{
"input": "4\nLLRR",
"output": "1 3\n2 4"
},
{
"input": "6\nRLLRRL",
"output": "1 4\n2 5\n3 6"
},
{
"input": "8\nLRLRLLLR",
"output": "1 5\n6 2\n3 7\n4 8"
},
... | 1,627,544,731 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 77 | 6,758,400 | with open("input.txt") as inp:
n,stud=int(inp.readline().strip()),inp.readline().strip()
l=""
for i in range(n//2):
if stud[i]=="R" and stud[i+(n//2)]=="L":
l+=f"{i+(n//2)+1} {i+1}\n"
else:
l+=f"{i+1} {i+(n//2... | Title: Lefthanders and Righthanders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all t... | ```python
with open("input.txt") as inp:
n,stud=int(inp.readline().strip()),inp.readline().strip()
l=""
for i in range(n//2):
if stud[i]=="R" and stud[i+(n//2)]=="L":
l+=f"{i+(n//2)+1} {i+1}\n"
else:
l+=f"{i+1... | 3 | 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,677,187,297 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 92 | 0 | def dfs(r, c):
if arr[r][1] not in cycle[arr[r][0]-1] and (arr[r][0]) not in cycle[arr[r][1]-1]:
cycle[arr[r][0]-1].append(arr[r][1])
if arr[r][0] not in cycle[arr[r][1]-1] and (arr[r][1]) not in cycle[arr[r][0]-1]:
cycle[arr[r][1]-1].append(arr[r][0])
if c == 0:
dfs(r, c + 1)
... | 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
def dfs(r, c):
if arr[r][1] not in cycle[arr[r][0]-1] and (arr[r][0]) not in cycle[arr[r][1]-1]:
cycle[arr[r][0]-1].append(arr[r][1])
if arr[r][0] not in cycle[arr[r][1]-1] and (arr[r][1]) not in cycle[arr[r][0]-1]:
cycle[arr[r][1]-1].append(arr[r][0])
if c == 0:
dfs(... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,625,639,082 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 124 | 0 | lower = 3
upper = 50
list=[2]
for num in range(lower, upper + 1):
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
list.append(num)
n,m=map(int,input().split())
if n in list and m in list:
if list.index(n)+1==list.index(m):
... | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
lower = 3
upper = 50
list=[2]
for num in range(lower, upper + 1):
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
list.append(num)
n,m=map(int,input().split())
if n in list and m in list:
if list.index(n)+1==list.index(m)... | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,693,489,085 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | n = int(input())
x = 0
y = 0
while n!= 0:
if n%2 == 0:
x+=n
else:
y+=n
n-=1
print(x-y) | Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
n = int(input())
x = 0
y = 0
while n!= 0:
if n%2 == 0:
x+=n
else:
y+=n
n-=1
print(x-y)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,450,266,467 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 0 | n=int(input())
import sys
a=list(map(int,input().split()))
o=0
e=0
if a[0]%2!=a[-1]%2:
if a[-1]%2!=a[-2]%2:
print(n)
sys.exit()
else:
print(1)
sys.exit()
else:
for i in a :
if i%2==1:
o=o+1
elif i%2==0:
e=e+1
i... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
import sys
a=list(map(int,input().split()))
o=0
e=0
if a[0]%2!=a[-1]%2:
if a[-1]%2!=a[-2]%2:
print(n)
sys.exit()
else:
print(1)
sys.exit()
else:
for i in a :
if i%2==1:
o=o+1
elif i%2==0:
e=e+1
... | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,397,720,137 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 124 | 0 | #!/bin/bash/python
#Date: 2014-04-17
#Author: shijinzhan
#Status:
#Note:
n = input()
seq = input().split()
odd = 0
for x in 0, 1, 2:
if int(seq[x]) % 2: # if x is odd, odd += 1
odd += 1
if odd > 1: # the differs number is even
for x in range(len(seq)):
if int(seq[x]) % 2 == 0:
print(x + 1)
break
els... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
#!/bin/bash/python
#Date: 2014-04-17
#Author: shijinzhan
#Status:
#Note:
n = input()
seq = input().split()
odd = 0
for x in 0, 1, 2:
if int(seq[x]) % 2: # if x is odd, odd += 1
odd += 1
if odd > 1: # the differs number is even
for x in range(len(seq)):
if int(seq[x]) % 2 == 0:
print(x + 1)
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
753 | A | Santa Claus and Candies | PROGRAMMING | 1,000 | [
"dp",
"greedy",
"math"
] | null | null | Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. | The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. | Print to the first line integer number *k* — maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them. | [
"5\n",
"9\n",
"2\n"
] | [
"2\n2 3\n",
"3\n3 5 1\n",
"1\n2 \n"
] | none | 500 | [
{
"input": "5",
"output": "2\n1 4 "
},
{
"input": "9",
"output": "3\n1 2 6 "
},
{
"input": "2",
"output": "1\n2 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "3",
"output": "2\n1 2 "
},
{
"input": "1000",
"output": "44\n1 2 3 4 5 6 7 8 9 10 ... | 1,603,982,851 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 109 | 0 | n = int(input())
num = 1
sum1 = 0
diff = 0
lst = list()
while True:
lst.append(num)
sum1 += num
diff = n - sum1
if diff < num + 1:
print(num)
lst[-1] += diff
print(*lst)
break
num += 1
| Title: Santa Claus and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n... | ```python
n = int(input())
num = 1
sum1 = 0
diff = 0
lst = list()
while True:
lst.append(num)
sum1 += num
diff = n - sum1
if diff < num + 1:
print(num)
lst[-1] += diff
print(*lst)
break
num += 1
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
9 | D | How many trees? | PROGRAMMING | 1,900 | [
"combinatorics",
"divide and conquer",
"dp"
] | D. How many trees? | 1 | 64 | In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terribl... | The input data contains two space-separated positive integer numbers *n* and *h* (*n*<=≤<=35, *h*<=≤<=*n*). | Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018. | [
"3 2\n",
"3 3\n"
] | [
"5",
"4"
] | none | 0 | [
{
"input": "3 2",
"output": "5"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "27 11",
"output": "61162698256896"
},
{
"input": "32 ... | 1,620,241,266 | 3,786 | PyPy 3 | OK | TESTS | 51 | 340 | 25,190,400 | n, h = map(int, input().split())
less = [[1] * (n + 2)] + [[0] * (n + 2) for i in range(n)] # dp[n][h]
ge = [[0] * (n + 2) for i in range(n + 1)] # dp[n][h]
less[0][0] = 0
less[0][-1] = 0
ge[0][0] = 1
ge[0][-1] = 1
for i in range(1, n + 1):
for j in range(0, n + 1):
for k in range(1, i + 1):
if ... | Title: How many trees?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from ... | ```python
n, h = map(int, input().split())
less = [[1] * (n + 2)] + [[0] * (n + 2) for i in range(n)] # dp[n][h]
ge = [[0] * (n + 2) for i in range(n + 1)] # dp[n][h]
less[0][0] = 0
less[0][-1] = 0
ge[0][0] = 1
ge[0][-1] = 1
for i in range(1, n + 1):
for j in range(0, n + 1):
for k in range(1, i + 1):
... | 3.642317 | MatrixStudio/Codeforces-Python-Submissions |
376 | A | Lever | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | You have a description of a lever as string *s*. We'll represent the string length as record |*s*|, then the lever looks as a horizontal bar with weights of length |*s*|<=-<=1 with exactly one pivot. We will assume that the bar is a segment on the *Ox* axis between points 0 and |*s*|<=-<=1.
The decoding of the lever d... | The first line contains the lever description as a non-empty string *s* (3<=≤<=|*s*|<=≤<=106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar.
To solve the p... | Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance. | [
"=^==\n",
"9===^==1\n",
"2==^7==\n",
"41^52==\n"
] | [
"balance\n",
"left\n",
"right\n",
"balance\n"
] | As you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever.
The pictures to the examples: | 500 | [
{
"input": "=^==",
"output": "balance"
},
{
"input": "9===^==1",
"output": "left"
},
{
"input": "2==^7==",
"output": "right"
},
{
"input": "41^52==",
"output": "balance"
},
{
"input": "=^2=4=1===1=",
"output": "right"
},
{
"input": "9=6===5==3=9=1=1^7=... | 1,602,880,410 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | s=input()
e,q,w=s.index("^"),0,0
for i in range(e):
if s[i]!="=":q+=int(s[i])*(e-i)
for i in range(e+1,len(s)):
if s[i]!="=":w+=int(s[i])*(i-e)
print("left"if q>w else "right"if w>q else"balanced") | Title: Lever
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a description of a lever as string *s*. We'll represent the string length as record |*s*|, then the lever looks as a horizontal bar with weights of length |*s*|<=-<=1 with exactly one pivot. We will assume that the bar i... | ```python
s=input()
e,q,w=s.index("^"),0,0
for i in range(e):
if s[i]!="=":q+=int(s[i])*(e-i)
for i in range(e+1,len(s)):
if s[i]!="=":w+=int(s[i])*(i-e)
print("left"if q>w else "right"if w>q else"balanced")
``` | 0 | 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,697,630,751 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | x= int(input())
n =[]
y =[]
count = 0
while x:
if len(y) <= 3:
y.append(x)
if len(y) == 3:
n.append(y)
y=[]
for i in n:
for j in i:
if j == 1:
count +=1
if count >=2:
count = 1
return count
| 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
x= int(input())
n =[]
y =[]
count = 0
while x:
if len(y) <= 3:
y.append(x)
if len(y) == 3:
n.append(y)
y=[]
for i in n:
for j in i:
if j == 1:
count +=1
if count >=2:
count = 1
return count
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,673,107,448 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | n = int(input())
a = list(map(int, input().split()))
odd = [0, 0]
even = [0, 0]
for i in range(n):
if a[i] % 2 == 0:
even[0] += 1
even[1] = i + 1
else:
odd[0] += 1
odd[1] = i + 1
if odd[0] == 1:
print(odd[1])
else:
print(even[1])
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
a = list(map(int, input().split()))
odd = [0, 0]
even = [0, 0]
for i in range(n):
if a[i] % 2 == 0:
even[0] += 1
even[1] = i + 1
else:
odd[0] += 1
odd[1] = i + 1
if odd[0] == 1:
print(odd[1])
else:
print(even[1])
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,593,291,660 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 20,172,800 | def calc(grid):
n = [["1" for y in range(3)] for x in range(3)]
for row in range(len(grid)):
for col in range(len(grid[0])):
update(n, grid, row, col)
return n
def update(n, grid, row, col):
c = grid[row][col]
c %=2
if c != 0:
# toggle adjacent lights
for nr, ... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
def calc(grid):
n = [["1" for y in range(3)] for x in range(3)]
for row in range(len(grid)):
for col in range(len(grid[0])):
update(n, grid, row, col)
return n
def update(n, grid, row, col):
c = grid[row][col]
c %=2
if c != 0:
# toggle adjacent lights
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
697 | A | Pineapple Incident | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morn... | The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively. | Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output. | [
"3 10 4\n",
"3 10 3\n",
"3 8 51\n",
"3 8 52\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and ... | 500 | [
{
"input": "3 10 4",
"output": "NO"
},
{
"input": "3 10 3",
"output": "YES"
},
{
"input": "3 8 51",
"output": "YES"
},
{
"input": "3 8 52",
"output": "YES"
},
{
"input": "456947336 740144 45",
"output": "NO"
},
{
"input": "33 232603 599417964",
"ou... | 1,698,647,438 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | t,s,x=map(int,input().split())
if x%s==t%s and t<=s:
print("YES")
elif x%s==(t+1)%s and t+1<s:
print("YES")
else:
print("NO") | Title: Pineapple Incident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times... | ```python
t,s,x=map(int,input().split())
if x%s==t%s and t<=s:
print("YES")
elif x%s==(t+1)%s and t+1<s:
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,696,546,170 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | nb = int(input())
if nb == 2 :
print("NO")
elif ((nb%2) == 0):
print ("YES")
else :
print ("NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
nb = int(input())
if nb == 2 :
print("NO")
elif ((nb%2) == 0):
print ("YES")
else :
print ("NO")
``` | 3.954 | MatrixStudio/Codeforces-Python-Submissions |
946 | C | String Transformation | PROGRAMMING | 1,300 | [
"greedy",
"strings"
] | null | null | You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number... | The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters. | If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes). | [
"aacceeggiikkmmooqqssuuwwyy\n",
"thereisnoanswer\n"
] | [
"abcdefghijklmnopqrstuvwxyz\n",
"-1\n"
] | none | 0 | [
{
"input": "aacceeggiikkmmooqqssuuwwyy",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "thereisnoanswer",
"output": "-1"
},
{
"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs",
"output": "-1"
},
{
"input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaen... | 1,590,084,017 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 0 |
s = input()
ans = [0]*len(s)
cur = 0
for i in range(len(s)):
if cur < 26 and ord(s[i]) - ord('a') <= cur:
ans[i] = cur + ord('a')
cur += 1
else:
ans[i] = ord(s[i])
if cur == 26:
for x in ans:
print(chr(x))
else:
print(-1) | Title: String Transformation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be rep... | ```python
s = input()
ans = [0]*len(s)
cur = 0
for i in range(len(s)):
if cur < 26 and ord(s[i]) - ord('a') <= cur:
ans[i] = cur + ord('a')
cur += 1
else:
ans[i] = ord(s[i])
if cur == 26:
for x in ans:
print(chr(x))
else:
print(-1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The produ... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second... | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1... | 1,623,044,900 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 13 | 310 | 0 | a=int(input())
f=list(map(int,input().split()))
p=[]
p1=[]
p2=[]
first=[]
second=[]
third=[]
for i in f:
if i>0:
p1.append(i)
elif i==0:
p2.append(i)
else:
p.append(i)
if len(p)%2==1:
if len(p)==1:
first.append(p[-1])
p.pop()
else:
... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. T... | ```python
a=int(input())
f=list(map(int,input().split()))
p=[]
p1=[]
p2=[]
first=[]
second=[]
third=[]
for i in f:
if i>0:
p1.append(i)
elif i==0:
p2.append(i)
else:
p.append(i)
if len(p)%2==1:
if len(p)==1:
first.append(p[-1])
p.pop()
else:... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
946 | C | String Transformation | PROGRAMMING | 1,300 | [
"greedy",
"strings"
] | null | null | You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number... | The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters. | If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes). | [
"aacceeggiikkmmooqqssuuwwyy\n",
"thereisnoanswer\n"
] | [
"abcdefghijklmnopqrstuvwxyz\n",
"-1\n"
] | none | 0 | [
{
"input": "aacceeggiikkmmooqqssuuwwyy",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "thereisnoanswer",
"output": "-1"
},
{
"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs",
"output": "-1"
},
{
"input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaen... | 1,691,544,945 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 102 | 62 | 6,246,400 | def main():
s = input()
ch = 'a'
new_s = list(s)
for i in range(len(s)):
if s[i] <= ch:
new_s[i] = ch
ch = chr(ord(ch) + 1)
if ch > 'z':
break
if ch > 'z':
print(''.join(new_s))
else:
print(-1)
if __name__ == "__... | Title: String Transformation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be rep... | ```python
def main():
s = input()
ch = 'a'
new_s = list(s)
for i in range(len(s)):
if s[i] <= ch:
new_s[i] = ch
ch = chr(ord(ch) + 1)
if ch > 'z':
break
if ch > 'z':
print(''.join(new_s))
else:
print(-1)
if __nam... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,695,809,836 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 77 | 31,539,200 | inp = int(input())
a,b,c,d = map(int, input().split())
e,f,g = map(int, input().split())
if max(a,b,c,d) == inp or max(e,f,g) == inp:
print("I become the guy.")
elif max(a,b,c,d) != inp or max(e,f,g) != inp:
print("Oh, my keyboard!") | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
inp = int(input())
a,b,c,d = map(int, input().split())
e,f,g = map(int, input().split())
if max(a,b,c,d) == inp or max(e,f,g) == inp:
print("I become the guy.")
elif max(a,b,c,d) != inp or max(e,f,g) != inp:
print("Oh, my keyboard!")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
813 | E | Army Creation | PROGRAMMING | 2,200 | [
"binary search",
"data structures"
] | null | null | As you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known as Rage of Empires.
In the game Vova can hire *n* different warriors; *i*th warrior has the type *a**i*. Vova wants to create a balanced army hiring some subset of warriors. An army is called balan... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100000).
The second line contains *n* integers *a*1, *a*2, ... *a**n* (1<=≤<=*a**i*<=≤<=100000).
The third line contains one integer *q* (1<=≤<=*q*<=≤<=100000).
Then *q* lines follow. *i*th line contains two numbers *x**i* and *y**i* which represe... | Print *q* numbers. *i*th number must be equal to the maximum size of a balanced army when considering *i*th plan. | [
"6 2\n1 1 1 2 2 2\n5\n1 6\n4 3\n1 1\n2 6\n2 6\n"
] | [
"2\n4\n1\n3\n2\n"
] | In the first example the real plans are:
1. 1 2 1. 1 6 1. 6 6 1. 2 4 1. 4 6 | 0 | [
{
"input": "6 2\n1 1 1 2 2 2\n5\n1 6\n4 3\n1 1\n2 6\n2 6",
"output": "2\n4\n1\n3\n2"
},
{
"input": "5 5\n3 4 4 2 1\n5\n5 5\n5 4\n5 4\n3 4\n5 5",
"output": "1\n2\n2\n2\n1"
},
{
"input": "5 5\n2 1 2 4 1\n5\n5 3\n1 1\n5 1\n2 1\n2 3",
"output": "4\n1\n2\n2\n5"
},
{
"input": "10 5... | 1,568,435,965 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
const int N=1e5,B=200;
vector<int> p[N];
int i,j,n,m,l,r,t,ans,g[N],a[N],f[500][N];
int main(){
for (scanf("%d%d",&n,&m);i<n;p[--a[i]].push_back(i),i++){
scanf("%d",a+i);
}
for (i=0;i*B<n;i++,memset(g,t=0,4*N)){
for (j=i*B;j<n;j++){
... | Title: Army Creation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known as Rage of Empires.
In the game Vova can hire *n* different warriors; *i*th warrior has the type *... | ```python
#include<bits/stdc++.h>
using namespace std;
const int N=1e5,B=200;
vector<int> p[N];
int i,j,n,m,l,r,t,ans,g[N],a[N],f[500][N];
int main(){
for (scanf("%d%d",&n,&m);i<n;p[--a[i]].push_back(i),i++){
scanf("%d",a+i);
}
for (i=0;i*B<n;i++,memset(g,t=0,4*N)){
for (j=i*B;j<n;j++){
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,585,049,583 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 0 | n=input()
n=n.replace("?"," ")
n=n.lower()
n=n.rstrip(" ")
n=list(n)
if(n[len(n)-1]=="a" or n[len(n)-1]=="e" or n[len(n)-1]=="i" or n[len(n)-1]=="o" or n[len(n)-1]=="u"):
print("YES")
else:
print("NO")
| Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
n=input()
n=n.replace("?"," ")
n=n.lower()
n=n.rstrip(" ")
n=list(n)
if(n[len(n)-1]=="a" or n[len(n)-1]=="e" or n[len(n)-1]=="i" or n[len(n)-1]=="o" or n[len(n)-1]=="u"):
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
108 | A | Palindromic Times | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | A. Palindromic Times | 2 | 256 | Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th... | The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits. | Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time. | [
"12:21\n",
"23:59\n"
] | [
"13:31\n",
"00:00\n"
] | none | 500 | [
{
"input": "12:21",
"output": "13:31"
},
{
"input": "23:59",
"output": "00:00"
},
{
"input": "15:51",
"output": "20:02"
},
{
"input": "10:44",
"output": "11:11"
},
{
"input": "04:02",
"output": "04:40"
},
{
"input": "02:11",
"output": "02:20"
},
... | 1,604,103,900 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 216 | 307,200 | def check(a,b):
a,b=str(a),str(b)
p='0'*(2-len(a))+a+':'+'0'*(2-len(b))+b
if p==p[::-1]:
print(p)
exit()
h,m=input().split(':')
h,m=int(h),int(m)
while 1:
m+=1
if m==60:
m=0
h+=1
if h==24:
h=0
check(h,m)
| Title: Palindromic Times
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling... | ```python
def check(a,b):
a,b=str(a),str(b)
p='0'*(2-len(a))+a+':'+'0'*(2-len(b))+b
if p==p[::-1]:
print(p)
exit()
h,m=input().split(':')
h,m=int(h),int(m)
while 1:
m+=1
if m==60:
m=0
h+=1
if h==24:
h=0
check(h,m)
``` | 3.945428 | MatrixStudio/Codeforces-Python-Submissions |
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase... | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3... | 1,698,309,458 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | line = input()
n, m = map(int, line.split())
name_of_ips = dict()
for i in range(n):
line = input()
name, ip = line.split()
name_of_ips[ip] = name
for i in range(m):
line = input()
ip = line.split()[1][:-1]
print(f"{line} #{name_of_ips[ip]}")
| Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ... | ```python
line = input()
n, m = map(int, line.split())
name_of_ips = dict()
for i in range(n):
line = input()
name, ip = line.split()
name_of_ips[ip] = name
for i in range(m):
line = input()
ip = line.split()[1][:-1]
print(f"{line} #{name_of_ips[ip]}")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ... | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts... | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
... | 1,463,897,666 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 77 | 4,608,000 | a,b,c = map(int, input().split(' '))
if (c == 0 and b - a == 0) or (a - b % c == 0 and (a-b)/abs(a-b) != c/abs(c)):
print("YES")
else:
print("NO")
| Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c... | ```python
a,b,c = map(int, input().split(' '))
if (c == 0 and b - a == 0) or (a - b % c == 0 and (a-b)/abs(a-b) != c/abs(c)):
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,682,105,099 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 307,200 | n = int(input())
arr1 = []
arr1 = list(map(int,
input().strip().split()))[:n]
p = int(input())
arr2 = []
arr2 = list(map(int,input().strip().split()))[:p]
for i in range(1,n):
arr1[i]+=arr1[i-1]
for i in range(n):
arr1[i]+=1
for num in arr2:
j=0
for i in range(len(arr1)):
if nu... | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
n = int(input())
arr1 = []
arr1 = list(map(int,
input().strip().split()))[:n]
p = int(input())
arr2 = []
arr2 = list(map(int,input().strip().split()))[:p]
for i in range(1,n):
arr1[i]+=arr1[i-1]
for i in range(n):
arr1[i]+=1
for num in arr2:
j=0
for i in range(len(arr1)):
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
319 | A | Malek Dance Club | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2*n* members and coincidentally Natalia Fan Club also has 2*n* members. Each member of MDC is assigned a unique id *i* from 0 to 2*n*<=-<=1. The same holds for eac... | The first line of input contains a binary number *x* of lenght *n*, (1<=≤<=*n*<=≤<=100).
This number may contain leading zeros. | Print the complexity of the given dance assignent modulo 1000000007 (109<=+<=7). | [
"11\n",
"01\n",
"1\n"
] | [
"6\n",
"2\n",
"1\n"
] | none | 500 | [
{
"input": "11",
"output": "6"
},
{
"input": "01",
"output": "2"
},
{
"input": "1",
"output": "1"
},
{
"input": "1111111111111111111111111111111111",
"output": "68817500"
},
{
"input": "0000000000000000000000000000000000000",
"output": "0"
},
{
"input"... | 1,608,795,035 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 0 | #code
def binaryToDecimal(n):
return int(n,2)
n=input()
a=binaryToDecimal(n)
print((((a)%1000000007) *(len(n)%1000000007))%1000000007) | Title: Malek Dance Club
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2*n* members and coincidentally Natalia Fan Club also has 2*n... | ```python
#code
def binaryToDecimal(n):
return int(n,2)
n=input()
a=binaryToDecimal(n)
print((((a)%1000000007) *(len(n)%1000000007))%1000000007)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,672,967,351 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n = int(input())
if not n%2: print(*[2 for _ in range(n//2)])
else: print(*([2 for _ in range(n//2 -1)]+[3])) | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
n = int(input())
if not n%2: print(*[2 for _ in range(n//2)])
else: print(*([2 for _ in range(n//2 -1)]+[3]))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
678 | B | The Same Calendar | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful that she wants to know what is the next year after *y* when the calendar will be exactly the same. Help ... | The only line contains integer *y* (1000<=≤<=*y*<=<<=100'000) — the year of the calendar. | Print the only integer *y*' — the next year after *y* when the calendar will be the same. Note that you should find the first year after *y* with the same calendar. | [
"2016\n",
"2000\n",
"50501\n"
] | [
"2044\n",
"2028\n",
"50507\n"
] | Today is Monday, the 13th of June, 2016. | 0 | [
{
"input": "2016",
"output": "2044"
},
{
"input": "2000",
"output": "2028"
},
{
"input": "50501",
"output": "50507"
},
{
"input": "1000",
"output": "1006"
},
{
"input": "1900",
"output": "1906"
},
{
"input": "1899",
"output": "1905"
},
{
"i... | 1,543,693,490 | 2,690 | PyPy 3 | OK | TESTS | 40 | 140 | 0 | def is_leap(y):
a = y % 400 == 0
b = y % 4 == 0 and not y % 100 == 0
return a or b
year = int(input())
l = is_leap(year)
w = 1
u = w
y = year
while True:
y += 1
incr = int(is_leap(y - 1))
u = (u + 1 + incr) % 7
if u == w and l == is_leap(y):
print(y)
break
| Title: The Same Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful t... | ```python
def is_leap(y):
a = y % 400 == 0
b = y % 4 == 0 and not y % 100 == 0
return a or b
year = int(input())
l = is_leap(year)
w = 1
u = w
y = year
while True:
y += 1
incr = int(is_leap(y - 1))
u = (u + 1 + incr) % 7
if u == w and l == is_leap(y):
print(y)
break
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=><=1) is situated at the ... | First line of input contains single integer number *n* (2<=≤<=*n*<=≤<=100<=000) — number of inflorescences.
Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence r... | Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest. | [
"3\n1 1\n",
"5\n1 2 2 2\n",
"18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n"
] | [
"1\n",
"3\n",
"4\n"
] | In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initial... | 0 | [
{
"input": "3\n1 1",
"output": "1"
},
{
"input": "5\n1 2 2 2",
"output": "3"
},
{
"input": "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4",
"output": "4"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "20\n1 1 1 1 1 ... | 1,520,180,121 | 2,421 | Python 3 | OK | TESTS | 90 | 187 | 13,312,000 | from functools import reduce
n = int(input())
a = list(map(int, input().split()))
d = [0 for i in range(n)]
for i, j in enumerate(a):
k = j - 1
d[i + 1] = d[k] + 1
M = [0 for i in range(max(d) + 1)]
ans = 0
for i in d:
M[i] += 1
print(reduce(lambda x, y: x + (y % 2), M)) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near b... | ```python
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
d = [0 for i in range(n)]
for i, j in enumerate(a):
k = j - 1
d[i + 1] = d[k] + 1
M = [0 for i in range(max(d) + 1)]
ans = 0
for i in d:
M[i] += 1
print(reduce(lambda x, y: x + (y % 2), M))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
289 | A | Polo the Penguin and Segments | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*).
He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 uni... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). Each of the following *n* lines contain a segment as a pair of integers *l**i* and *r**i* (<=-<=105<=≤<=*l**i*<=≤<=*r**i*<=≤<=105), separated by a space.
It is guaranteed that no two segments intersect. In other words, for any two integers *i*... | In a single line print a single integer — the answer to the problem. | [
"2 3\n1 2\n3 4\n",
"3 7\n1 2\n3 3\n4 7\n"
] | [
"2\n",
"0\n"
] | none | 500 | [
{
"input": "2 3\n1 2\n3 4",
"output": "2"
},
{
"input": "3 7\n1 2\n3 3\n4 7",
"output": "0"
},
{
"input": "3 7\n1 10\n11 47\n74 128",
"output": "3"
},
{
"input": "5 4\n1 1\n2 2\n3 3\n4 4\n5 5",
"output": "3"
},
{
"input": "7 4\n2 2\n-1 -1\n0 1\n7 8\n-3 -2\n9 9\n4 ... | 1,685,707,365 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 404 | 0 | # all those moments will be lost in time , like tears in rain
n , k = map(int , input().split())
smm = 0
for i in range(n) :
l = list(map(int , input().split()))
smm += l[1] -l[0] + 1
res = k - (smm % k)
if res == k :
print(0)
else:
print(res)
| Title: Polo the Penguin and Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*).
He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]... | ```python
# all those moments will be lost in time , like tears in rain
n , k = map(int , input().split())
smm = 0
for i in range(n) :
l = list(map(int , input().split()))
smm += l[1] -l[0] + 1
res = k - (smm % k)
if res == k :
print(0)
else:
print(res)
``` | 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,618,568,213 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 248 | 2,252,800 | f = open("input.txt")
n, m = map(int, f.read().split())
ans = ''
if n > m:
while n and m:
ans += "BG"
n -= 1
m -= 1
ans += 'B' * n
else:
while n and m:
ans += "GB"
n -= 1
m -= 1
ans += "G" * m
f = open("output.txt", 'w')
f.write(s)
f.clo... | 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
f = open("input.txt")
n, m = map(int, f.read().split())
ans = ''
if n > m:
while n and m:
ans += "BG"
n -= 1
m -= 1
ans += 'B' * n
else:
while n and m:
ans += "GB"
n -= 1
m -= 1
ans += "G" * m
f = open("output.txt", 'w')
f.write... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
290 | B | QR code | PROGRAMMING | 1,500 | [
"*special",
"implementation"
] | null | null | The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=32), separated by a single space. | Output a single integer. | [
"1 1\n",
"3 7\n",
"13 10\n"
] | [
"0\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "1 1",
"output": "0"
},
{
"input": "3 7",
"output": "0"
},
{
"input": "13 10",
"output": "1"
},
{
"input": "6 12",
"output": "1"
},
{
"input": "14 14",
"output": "0"
},
{
"input": "19 14",
"output": "0"
},
{
"input": "21 18",
... | 1,667,831,607 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 92 | 0 | x,y=map(int,input().split())
s='11111110101010111110010100111111110000010000000000101011000100000110111010011011000001101000101110110111010101100100111110100101110110111010110001100011110010101110110000010101010101101000010100000111111110101010101010101010111111100000000111110111110011110000000010001011110010000101111... | Title: QR code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=32), separated by a single space.
Output Specification:
Output a single integer.
Demo Input:
['1 1\n', '3 7\n', '13 10\n']
Demo Output:
['0... | ```python
x,y=map(int,input().split())
s='1111111010101011111001010011111111000001000000000010101100010000011011101001101100000110100010111011011101010110010011111010010111011011101011000110001111001010111011000001010101010110100001010000011111111010101010101010101011111110000000011111011111001111000000001000101111001... | 3 | MatrixStudio/Codeforces-Python-Submissions | ||
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3... | 1,664,866,198 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | import sys; R = sys.stdin.readline
n = int(R())
board = [[*map(int,R().split())] for _ in range(n)]
for i in range(n):
for j in range(n):
two, five = 0, 0
while not board[i][j]&1: board[i][j] >>= 1; two += 1
while not board[i][j]%5: board[i][j] //= 5; five += 1
board[i][j] ... | Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down fro... | ```python
import sys; R = sys.stdin.readline
n = int(R())
board = [[*map(int,R().split())] for _ in range(n)]
for i in range(n):
for j in range(n):
two, five = 0, 0
while not board[i][j]&1: board[i][j] >>= 1; two += 1
while not board[i][j]%5: board[i][j] //= 5; five += 1
bo... | 0 | MatrixStudio/Codeforces-Python-Submissions |
825 | A | Binary Protocol | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts... | Print the decoded number. | [
"3\n111\n",
"9\n110011101\n"
] | [
"3\n",
"2031\n"
] | none | 0 | [
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "... | 1,500,557,536 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 4,608,000 | import sys
pb_raw = sys.stdin.readlines()
in_len = int(pb_raw[0].strip())
pb_str = pb_raw[1].strip()
pb_str = pb_str.replace('0', ' ')
tmp = [str(len(chunk)) for chunk in pb_str.split('0')]
sol = ''.join(tmp)
sys.stdout.writelines(sol)
| Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' charact... | ```python
import sys
pb_raw = sys.stdin.readlines()
in_len = int(pb_raw[0].strip())
pb_str = pb_raw[1].strip()
pb_str = pb_str.replace('0', ' ')
tmp = [str(len(chunk)) for chunk in pb_str.split('0')]
sol = ''.join(tmp)
sys.stdout.writelines(sol)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
914 | F | Substrings in a String | PROGRAMMING | 3,000 | [
"bitmasks",
"brute force",
"data structures",
"string suffix structures",
"strings"
] | null | null | Given a string *s*, process *q* queries, each having one of the following forms:
- 1<=*i*<=*c* — Change the *i*-th character in the string to *c*. - 2<=*l*<=*r*<=*y* — Consider the substring of *s* starting at position *l* and ending at position *r*. Output the number of times *y* occurs as a substring in it. | The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=105) of lowercase English letters.
The second line contains an integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries to process.
The next *q* lines describe the queries and may have one of the following forms:
- 1<=*i*<=*c* (1<=≤<=*i*<=≤<=|*s*|... | For each query of type 2, output the required answer in a separate line. | [
"ababababa\n3\n2 1 7 aba\n1 5 c\n2 1 7 aba\n",
"abcdcbc\n5\n2 1 7 bc\n1 4 b\n2 4 7 bc\n1 2 a\n2 1 4 aa\n"
] | [
"3\n1\n",
"2\n2\n1\n"
] | Consider the first sample case. Initially, the string aba occurs 3 times in the range [1, 7]. Note that two occurrences may overlap.
After the update, the string becomes ababcbaba and now aba occurs only once in the range [1, 7]. | 3,000 | [] | 1,649,913,611 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 6,000 | 11,161,600 | X = input()
Z = int(input())
Query = []
for _ in range(Z):
Query.append(list(map(str,input().split())))
if X is not None:
for q in Query:
if q[0]=="1":
index = (int(q[1])-1)
X=X[:index]+q[2]+X[index+1:]
elif q[0]=="2":
count = 0
for i in range(int(... | Title: Substrings in a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given a string *s*, process *q* queries, each having one of the following forms:
- 1<=*i*<=*c* — Change the *i*-th character in the string to *c*. - 2<=*l*<=*r*<=*y* — Consider the substring of *s* starting at... | ```python
X = input()
Z = int(input())
Query = []
for _ in range(Z):
Query.append(list(map(str,input().split())))
if X is not None:
for q in Query:
if q[0]=="1":
index = (int(q[1])-1)
X=X[:index]+q[2]+X[index+1:]
elif q[0]=="2":
count = 0
for i in ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
39 | D | Cubical Planet | PROGRAMMING | 1,100 | [
"math"
] | D. Cubical Planet | 2 | 64 | You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the mom... | The first line contains three space-separated integers (0 or 1) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly. | Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO". | [
"0 0 0\n0 1 0\n",
"1 1 0\n0 1 0\n",
"0 0 0\n1 1 1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "0 0 0\n0 1 0",
"output": "YES"
},
{
"input": "1 1 0\n0 1 0",
"output": "YES"
},
{
"input": "0 0 0\n1 1 1",
"output": "NO"
},
{
"input": "0 0 0\n1 0 0",
"output": "YES"
},
{
"input": "0 0 0\n0 1 0",
"output": "YES"
},
{
"input": "0 0 0\n1 1 ... | 1,697,016,239 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | # LUOGU_RID: 128751997
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
if a!=d and b!=e and f!=h:
print('NO')
else:
print('YES')
| Title: Cubical Planet
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite v... | ```python
# LUOGU_RID: 128751997
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
if a!=d and b!=e and f!=h:
print('NO')
else:
print('YES')
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
787 | A | The Monster | PROGRAMMING | 1,200 | [
"brute force",
"math",
"number theory"
] | null | null | A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=....
The Monster will catch them if a... | The first line of input contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100).
The second line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100). | Print the first time Rick and Morty will scream at the same time, or <=-<=1 if they will never scream at the same time. | [
"20 2\n9 19\n",
"2 1\n16 12\n"
] | [
"82\n",
"-1\n"
] | In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time. | 500 | [
{
"input": "20 2\n9 19",
"output": "82"
},
{
"input": "2 1\n16 12",
"output": "-1"
},
{
"input": "39 52\n88 78",
"output": "1222"
},
{
"input": "59 96\n34 48",
"output": "1748"
},
{
"input": "87 37\n91 29",
"output": "211"
},
{
"input": "11 81\n49 7",
... | 1,629,796,567 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 32 | 62 | 6,963,200 | a, b = map(int, input().split())
c, d = map(int, input().split())
y = 0
data = [(d - b) % a]
y += 1
while (c * y + d - b) % a != data[0]:
data.append((c * y + d - b) % a)
if (c * y + d - b) % a == 0:
print(y * c + d)
exit()
y += 1
print(-1)
| Title: The Monster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams a... | ```python
a, b = map(int, input().split())
c, d = map(int, input().split())
y = 0
data = [(d - b) % a]
y += 1
while (c * y + d - b) % a != data[0]:
data.append((c * y + d - b) % a)
if (c * y + d - b) % a == 0:
print(y * c + d)
exit()
y += 1
print(-1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
616 | B | Dinner with Emma | PROGRAMMING | 1,000 | [
"games",
"greedy"
] | null | null | Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The stree... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan.
Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue. | Print the only integer *a* — the cost of the dinner for Jack and Emma. | [
"3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n",
"3 3\n1 2 3\n2 3 1\n3 1 2\n"
] | [
"2\n",
"1\n"
] | In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din... | 0 | [
{
"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1",
"output": "2"
},
{
"input": "3 3\n1 2 3\n2 3 1\n3 1 2",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n74 35 82 39 1 84 29 41 70 12",
"output": "1"
},
{
"input": "10 1\n44\n23\n65\n17\n48\n29\n... | 1,694,950,174 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 46 | 102,400 | n,m=map(int,input().split())
z=[]
a=[]
for i in range(n):
a=list(map(int,input().split()))
z.append(min(a))
print(max(z))
| Title: Dinner with Emma
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and... | ```python
n,m=map(int,input().split())
z=[]
a=[]
for i in range(n):
a=list(map(int,input().split()))
z.append(min(a))
print(max(z))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,696,248,746 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | s=input()
v=["A","E","I","O","U","a","e","i","o","u","Y","y"]
s1=''
for i in s:
if i not in v:
s1=s1+"."+i
print(s1) | Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
s=input()
v=["A","E","I","O","U","a","e","i","o","u","Y","y"]
s1=''
for i in s:
if i not in v:
s1=s1+"."+i
print(s1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
876 | A | Trip For Meal | PROGRAMMING | 900 | [
"math"
] | null | null | Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ... | First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* ... | Output one number — minimum distance in meters Winnie must go through to have a meal *n* times. | [
"3\n2\n3\n1\n",
"1\n2\n3\n5\n"
] | [
"3\n",
"0\n"
] | In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | 500 | [
{
"input": "3\n2\n3\n1",
"output": "3"
},
{
"input": "1\n2\n3\n5",
"output": "0"
},
{
"input": "10\n1\n8\n3",
"output": "9"
},
{
"input": "7\n10\n5\n6",
"output": "30"
},
{
"input": "9\n9\n7\n5",
"output": "42"
},
{
"input": "9\n37\n85\n76",
"outpu... | 1,508,680,696 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 21 | 62 | 5,529,600 | n = int(input()) - 2
a = int(input())
b = int(input())
c = int(input())
a = min(a, b)
b = min(a, c)
print(a + b * n)
| Title: Trip For Meal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair... | ```python
n = int(input()) - 2
a = int(input())
b = int(input())
c = int(input())
a = min(a, b)
b = min(a, c)
print(a + b * n)
``` | 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,602,496,758 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 404 | 1,638,400 | n,m=map(int,input().split())
w=0
r=[]
for i in range(n):
k,*l=map(int,input().split())
if k==0:w+=1
else:r.append(set(l))
q=[]
while q!=r:
q=list(r)
for i in range(len(r)):
for j in range(len(r)):
if r[i]&r[j]:
r[i]=r[i]|r[j]
q=[]
for i in r:
i... | 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
n,m=map(int,input().split())
w=0
r=[]
for i in range(n):
k,*l=map(int,input().split())
if k==0:w+=1
else:r.append(set(l))
q=[]
while q!=r:
q=list(r)
for i in range(len(r)):
for j in range(len(r)):
if r[i]&r[j]:
r[i]=r[i]|r[j]
q=[]
for i in... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
961 | B | Lecture Sleep | PROGRAMMING | 1,200 | [
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ... | The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theore... | Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] | [
"16\n"
] | In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | 0 | [
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4... | 1,678,353,817 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 109 | 20,070,400 | # I/O
def intarr():
return map(int, input().split())
def intin():
return int(input())
def solve():
n, k = intarr()
a = list(intarr())
awake = list(intarr())
theorem = 0
for i in range(n):
if awake[i] == 1:
theorem += a[i]
maxTheorems = 0
cnt = 0
for i in ... | Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for al... | ```python
# I/O
def intarr():
return map(int, input().split())
def intin():
return int(input())
def solve():
n, k = intarr()
a = list(intarr())
awake = list(intarr())
theorem = 0
for i in range(n):
if awake[i] == 1:
theorem += a[i]
maxTheorems = 0
cnt = 0
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of *n* nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly *k* of the nodes should be exit-nodes, that means that each of them should... | The first line contains two integers *n* and *k* (3<=≤<=*n*<=≤<=2·105, 2<=≤<=*k*<=≤<=*n*<=-<=1) — the total number of nodes and the number of exit-nodes.
Note that it is always possible to build at least one network with *n* nodes and *k* exit-nodes within the given constraints. | In the first line print the minimum possible distance between the two most distant exit-nodes. In each of the next *n*<=-<=1 lines print two integers: the ids of the nodes connected by a wire. The description of each wire should be printed exactly once. You can print wires and wires' ends in arbitrary order. The nodes ... | [
"3 2\n",
"5 3\n"
] | [
"2\n1 2\n2 3\n",
"3\n1 2\n2 3\n3 4\n3 5\n"
] | In the first example the only network is shown on the left picture.
In the second example one of optimal networks is shown on the right picture.
Exit-nodes are highlighted. | 0 | [
{
"input": "3 2",
"output": "2\n1 2\n2 3"
},
{
"input": "5 3",
"output": "3\n1 2\n2 3\n3 4\n3 5"
},
{
"input": "4 2",
"output": "3\n1 2\n2 3\n3 4"
},
{
"input": "4 3",
"output": "2\n1 2\n2 3\n2 4"
},
{
"input": "5 2",
"output": "4\n1 2\n2 3\n3 4\n4 5"
},
{... | 1,549,792,355 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 982 | 17,612,800 | import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
n, k = mints()
c = n-k
r = []
j = c + 1
for i in range(1,min(c,k)+1):
r.append((j,i))
j += 1
for i in range(c+1,k+1):
r.append((j,c))
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of *n* nodes connected with minimum possible number of wires into one network (a wire directly connects two ... | ```python
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
n, k = mints()
c = n-k
r = []
j = c + 1
for i in range(1,min(c,k)+1):
r.append((j,i))
j += 1
for i in range(c+1,k+1):
r.append... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
915 | E | Physical Education Lessons | PROGRAMMING | 2,300 | [
"data structures",
"implementation",
"sortings"
] | null | null | This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical education lessons. The end of the term is very soon, but, unfortunately, Alex still hasn't attended a single lesson... | The first line contains one integer *n*, and the second line — one integer *q* (1<=≤<=*n*<=≤<=109, 1<=≤<=*q*<=≤<=3·105) — the number of days left before the end of the term, and the number of orders, respectively.
Then *q* lines follow, *i*-th line containing three integers *l**i*, *r**i* and *k**i* representing *i*-t... | Print *q* integers. *i*-th of them must be equal to the number of working days left until the end of the term after the first *i* orders are published. | [
"4\n6\n1 2 1\n3 4 1\n2 3 2\n1 3 2\n2 4 1\n1 4 2\n"
] | [
"2\n0\n2\n3\n1\n4\n"
] | none | 0 | [
{
"input": "4\n6\n1 2 1\n3 4 1\n2 3 2\n1 3 2\n2 4 1\n1 4 2",
"output": "2\n0\n2\n3\n1\n4"
},
{
"input": "3\n8\n2 2 1\n3 3 2\n1 1 1\n1 3 2\n2 3 2\n3 3 1\n1 2 1\n2 2 2",
"output": "2\n2\n1\n3\n3\n2\n0\n1"
},
{
"input": "7\n10\n5 7 1\n5 6 2\n7 7 2\n6 7 2\n5 5 1\n3 6 2\n1 3 2\n5 6 1\n1 3 1\n... | 1,516,371,520 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 37,683,200 | from sys import stdin, stdout
n = int(input())
q = int(input())
working_days = {key:1 for key in range(1,n+1)}
for _ in range(q):
li,ri,ki = input().split()
for i in range(int(li), int(ri)+1):
if int(ki) == 1 and working_days[i] != 0:
working_days[i] = 0
if int(ki) == 2 an... | Title: Physical Education Lessons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical edu... | ```python
from sys import stdin, stdout
n = int(input())
q = int(input())
working_days = {key:1 for key in range(1,n+1)}
for _ in range(q):
li,ri,ki = input().split()
for i in range(int(li), int(ri)+1):
if int(ki) == 1 and working_days[i] != 0:
working_days[i] = 0
if int(k... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,695,124,567 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 0 | 0 | w=int(input())
b=w/2
if b%2==0:
print("NO")
else:
print("Yes") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
w=int(input())
b=w/2
if b%2==0:
print("NO")
else:
print("Yes")
``` | 0 | 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,656,589,900 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | word = input("word:")
print(word)
for element in word:
if element == 'h':
st = str + 'h'
if element == 'e':
st = str + 'e'
if element == 'i':
st = str + 'i'
if element == 'd':
st = str + 'd'
if element == 'i':
... | 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
word = input("word:")
print(word)
for element in word:
if element == 'h':
st = str + 'h'
if element == 'e':
st = str + 'e'
if element == 'i':
st = str + 'i'
if element == 'd':
st = str + 'd'
if element =... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
120 | A | Elevator | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the... | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | 0 | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 1,660,087,730 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,150,400 | direcao = input()
apoio = int(input())
a = [0,'L','R']
if direcao == "front":
print (a[apoio])
else: print (a[-apoio]) | Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through... | ```python
direcao = input()
apoio = int(input())
a = [0,'L','R']
if direcao == "front":
print (a[apoio])
else: print (a[-apoio])
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,692,359,283 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input());s=input().split();print(*[s.index(str(i+1))) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n=int(input());s=input().split();print(*[s.index(str(i+1)))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
899 | D | Shovel Sale | PROGRAMMING | 1,800 | [
"constructive algorithms",
"math"
] | null | null | There are *n* shovels in Polycarp's shop. The *i*-th shovel costs *i* burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs.
Visitors are more likely to buy a pair of shovels if their total cost ends with ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=109) — the number of shovels in Polycarp's shop. | Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines.
Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways.
It is guaranteed that for every *n*<=≤<=109 the answer doesn't exceed 2·109. | [
"7\n",
"14\n",
"50\n"
] | [
"3\n",
"9\n",
"1\n"
] | In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose:
- 2 and 7; - 3 and 6; - 4 and 5.
In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Po... | 1,750 | [
{
"input": "7",
"output": "3"
},
{
"input": "14",
"output": "9"
},
{
"input": "50",
"output": "1"
},
{
"input": "999999999",
"output": "499999999"
},
{
"input": "15",
"output": "11"
},
{
"input": "3",
"output": "3"
},
{
"input": "6500",
... | 1,513,518,228 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 62 | 5,529,600 | #Max nine problem
n=int(input())
if n<=4:
print(n*(n-1)//2)
import sys
sys.exit(0)
if len(set(str(n+(n-1))))==1:
print(1)
else:
l=len(str(n+n-1))
#max 9's will be in a number from 0 to 8 and (l-1)*9
count=0
for i in range(0,8):
p=int(str(i)+(l-1)*'9')
if p>(... | Title: Shovel Sale
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* shovels in Polycarp's shop. The *i*-th shovel costs *i* burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell sh... | ```python
#Max nine problem
n=int(input())
if n<=4:
print(n*(n-1)//2)
import sys
sys.exit(0)
if len(set(str(n+(n-1))))==1:
print(1)
else:
l=len(str(n+n-1))
#max 9's will be in a number from 0 to 8 and (l-1)*9
count=0
for i in range(0,8):
p=int(str(i)+(l-1)*'9')
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves.
Let A-B denote that... | The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends.
The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and ... | If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes). | [
"4 3\n1 3\n3 4\n1 4\n",
"4 4\n3 1\n2 3\n3 4\n1 2\n",
"10 4\n4 3\n5 10\n8 9\n1 2\n",
"3 2\n1 2\n2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not. | 0 | [
{
"input": "4 3\n1 3\n3 4\n1 4",
"output": "YES"
},
{
"input": "4 4\n3 1\n2 3\n3 4\n1 2",
"output": "NO"
},
{
"input": "10 4\n4 3\n5 10\n8 9\n1 2",
"output": "YES"
},
{
"input": "3 2\n1 2\n2 3",
"output": "NO"
},
{
"input": "3 0",
"output": "YES"
},
{
... | 1,694,147,045 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 102,400 | class DSU:
def __init__(self, n):
self.par = list(range(n))
self.rank = [1] * n
def findPar(self, x):
if x == self.par[x]:
return x
self.par[x] = self.findPar(self.par[x])
return self.par[x]
def unionRank(self, x, y):
x_rep = self.findPar(x)
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through *n*. *m* pairs of member... | ```python
class DSU:
def __init__(self, n):
self.par = list(range(n))
self.rank = [1] * n
def findPar(self, x):
if x == self.par[x]:
return x
self.par[x] = self.findPar(self.par[x])
return self.par[x]
def unionRank(self, x, y):
x_rep = self.findP... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
46 | G | Emperor's Problem | PROGRAMMING | 2,500 | [
"geometry"
] | G. Emperor's Problem | 2 | 256 | It happened at the times of the Great Berland Empire. Once the Emperor dreamt that the Messenger from the gods ordered to build a temple whose base would be a convex polygon with *n* angles. Next morning the Emperor gave the command to build a temple whose base was a regular polygon with *n* angles. The temple was buil... | The first line contains the single number *n* (3<=≤<=*n*<=≤<=10000). | Print "YES" (without quotes) in the first line if it is possible to build a polygon possessing the needed qualities. In the next *n* lines print integer coordinates of the polygon vertices in the order in which they would be passed counter clockwise. The absolute value of the coordinates shouldn't exceed 109. No two ve... | [
"3\n",
"3\n"
] | [
"YES\n0 0\n1 0\n0 2\n",
"YES\n0 1\n-1 0\n-1 -1\n"
] | none | 0 | [] | 1,689,364,925 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689364925.831572")# 1689364925.831591 | Title: Emperor's Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
It happened at the times of the Great Berland Empire. Once the Emperor dreamt that the Messenger from the gods ordered to build a temple whose base would be a convex polygon with *n* angles. Next morning the Emperor gave ... | ```python
print("_RANDOM_GUESS_1689364925.831572")# 1689364925.831591
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,582,391,129 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 748 | 3,276,800 | bracket = input();cnt = total = 0
for i in bracket:
if i=='(':
cnt+=1
elif cnt>0:
cnt-=1
total+=2
print(total) | Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
bracket = input();cnt = total = 0
for i in bracket:
if i=='(':
cnt+=1
elif cnt>0:
cnt-=1
total+=2
print(total)
``` | 3.919096 | MatrixStudio/Codeforces-Python-Submissions |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,665,076,267 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 77 | 0 | n=int(input())
lista=input().split()
for i in range(n):
lista[i]=int(lista[i])
mx=max(lista)
suma=0
for i in range(n):
suma+=(mx-lista[i])
print(suma) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
n=int(input())
lista=input().split()
for i in range(n):
lista[i]=int(lista[i])
mx=max(lista)
suma=0
for i in range(n):
suma+=(mx-lista[i])
print(suma)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
776 | C | Molly's Chemicals | PROGRAMMING | 1,800 | [
"binary search",
"brute force",
"data structures",
"implementation",
"math"
] | null | null | Molly Hooper has *n* different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The *i*-th of them has affection value *a**i*.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total ... | The first line of input contains two integers, *n* and *k*, the number of chemicals and the number, such that the total affection value is a non-negative power of this number *k*. (1<=≤<=*n*<=≤<=105, 1<=≤<=|*k*|<=≤<=10).
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — affecti... | Output a single integer — the number of valid segments. | [
"4 2\n2 2 2 2\n",
"4 -3\n3 -6 -3 12\n"
] | [
"8\n",
"3\n"
] | Do keep in mind that *k*<sup class="upper-index">0</sup> = 1.
In the first sample, Molly can get following different affection values:
- 2: segments [1, 1], [2, 2], [3, 3], [4, 4]; - 4: segments [1, 2], [2, 3], [3, 4]; - 6: segments [1, 3], [2, 4]; - 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of *k* = ... | 1,500 | [
{
"input": "4 2\n2 2 2 2",
"output": "8"
},
{
"input": "4 -3\n3 -6 -3 12",
"output": "3"
},
{
"input": "14 -9\n-2 -4 62 53 90 41 35 21 85 74 85 57 10 39",
"output": "0"
},
{
"input": "20 9\n90 21 -6 -61 14 -21 -17 -65 -84 -75 -48 56 67 -50 16 65 -79 -61 92 85",
"output": ... | 1,625,642,181 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,500 | 400,588,800 | from sys import stdin,stdout
from math import gcd,sqrt,factorial,pi,inf
from collections import deque,defaultdict
from bisect import bisect,bisect_left
from time import time
from itertools import permutations as per
from heapq import heapify,heappush,heappop,heappushpop
input=stdin.readline
R=lambda:map(int,inp... | Title: Molly's Chemicals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Molly Hooper has *n* different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The *i*-th of them has affection value *a**i*.
Molly wants Sherlock to fall in love with her. She in... | ```python
from sys import stdin,stdout
from math import gcd,sqrt,factorial,pi,inf
from collections import deque,defaultdict
from bisect import bisect,bisect_left
from time import time
from itertools import permutations as per
from heapq import heapify,heappush,heappop,heappushpop
input=stdin.readline
R=lambda:m... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
724 | A | Checking the Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong t... | The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes). | [
"monday\ntuesday\n",
"sunday\nsunday\n",
"saturday\ntuesday\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | 500 | [
{
"input": "monday\ntuesday",
"output": "NO"
},
{
"input": "sunday\nsunday",
"output": "YES"
},
{
"input": "saturday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nthursday",
"output": "YES"
},
{
"input": "friday\nwednesday",
"output": "NO"
},
{
"i... | 1,476,495,842 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 4,608,000 |
first_day=str(input())
sec_day=str(input())
index1 =0
index2 =0
sol = True
days_list=["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
for x in range(0,len(days_list)):
if first_day is days_list[x]:
index1 =x
if sec_day is days_list[x]:
index2 =x
mon... | Title: Checking the Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the fir... | ```python
first_day=str(input())
sec_day=str(input())
index1 =0
index2 =0
sol = True
days_list=["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
for x in range(0,len(days_list)):
if first_day is days_list[x]:
index1 =x
if sec_day is days_list[x]:
index2... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,698,140,068 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 717 | 28,467,200 | dic={}
find={i:False for i in range(1,100001)}
n,m=map(int,input().split())
a=list(map(int,input().split()))
dic[n]=1
find[a[-1]]=True
for i in range(n-1,0,-1):
if find[a[i-1]]:
dic[i]=dic[i+1]
else:
dic[i]=dic[i+1]+1
find[a[i-1]]=True
for i in range(m):
print(dic[int(in... | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
dic={}
find={i:False for i in range(1,100001)}
n,m=map(int,input().split())
a=list(map(int,input().split()))
dic[n]=1
find[a[-1]]=True
for i in range(n-1,0,-1):
if find[a[i-1]]:
dic[i]=dic[i+1]
else:
dic[i]=dic[i+1]+1
find[a[i-1]]=True
for i in range(m):
print(... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,608,095,886 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 358 | 9,830,400 | ###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ... | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # #... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,696,993,985 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | h,w = [int(i) for i in input().split()]
for i in range(h):
if i % 2 == 0:
print('#' * w)
elif i % 2 != 0:
print(('.'*(w-1)) + '#') | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
h,w = [int(i) for i in input().split()]
for i in range(h):
if i % 2 == 0:
print('#' * w)
elif i % 2 != 0:
print(('.'*(w-1)) + '#')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
465 | B | Inbox (100500) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. | Print a single number — the minimum number of operations needed to make all the letters read. | [
"5\n0 1 0 1 0\n",
"5\n1 1 0 0 1\n",
"2\n0 0\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already... | 1,000 | [
{
"input": "5\n0 1 0 1 0",
"output": "3"
},
{
"input": "5\n1 1 0 0 1",
"output": "4"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "9\n1 0 1 0 1 0 1 0 1",
"output": "9"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
},
{
"input": "14\n0 0 1 1 1 0 1 ... | 1,670,524,165 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 61 | 0 | input()
print(max(0,sum(len(i)+1 for i in input().replace(' ','').replace('0',' ').split())-1)) | Title: Inbox (100500)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soo... | ```python
input()
print(max(0,sum(len(i)+1 for i in input().replace(' ','').replace('0',' ').split())-1))
``` | 3 | 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,592,895,773 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 312 | 20,172,800 | import math
n=int(input())
r=[int(x) for x in input().split()]
r.sort(reverse=True)
r.append(0)
ans=0
i=0
while i<n:
ans += r[i]**2 - r[i+1]**2
i+=2
ans *= math.pi
print("{:.5f}".format(ans))
| 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
import math
n=int(input())
r=[int(x) for x in input().split()]
r.sort(reverse=True)
r.append(0)
ans=0
i=0
while i<n:
ans += r[i]**2 - r[i+1]**2
i+=2
ans *= math.pi
print("{:.5f}".format(ans))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"... | 1,671,393,999 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | d=str(input())
a=d.find("AB")
n=d.find("BA",a+2)
aa=d.find("BA")
nn=d.find("AB",a+2)
if (a>=0 and n>=0 )or (aa>=0 and nn>=0):
print("YES")
else:
print("NO") | Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contain... | ```python
d=str(input())
a=d.find("AB")
n=d.find("BA",a+2)
aa=d.find("BA")
nn=d.find("AB",a+2)
if (a>=0 and n>=0 )or (aa>=0 and nn>=0):
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The chi... | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description... | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no ... | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
... | 1,401,894,213 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 155 | 0 | answers = ['A', 'B', 'C', 'D']
variants = []
for i in range(0, 4):
variants.append((len(input()) - 2, answers[i]))
asc = sorted(variants, key=lambda variant: variant[0])
des = sorted(variants, key=lambda variant: variant[0], reverse = True)
good_variants = []
if (2 * asc[0][0] <= asc[1][0]):
good_vari... | Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should fin... | ```python
answers = ['A', 'B', 'C', 'D']
variants = []
for i in range(0, 4):
variants.append((len(input()) - 2, answers[i]))
asc = sorted(variants, key=lambda variant: variant[0])
des = sorted(variants, key=lambda variant: variant[0], reverse = True)
good_variants = []
if (2 * asc[0][0] <= asc[1][0]):
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,695,630,142 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | i=int(input())
n=int(input())
w=int(input())
c=1
for k in range(1, w+1):
c*=k
y=k*i
print(y)
b=0
if(k<=n):
b=0
elif(k>n):
b=k-n
print(b) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
i=int(input())
n=int(input())
w=int(input())
c=1
for k in range(1, w+1):
c*=k
y=k*i
print(y)
b=0
if(k<=n):
b=0
elif(k>n):
b=k-n
print(b)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,657,714,997 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 186 | 5,324,800 | n = int(input())
l = range(1, n**2+1)
c = 0
for i in range(n):
z = []
for i in range(n//2):
print(l[c], l[-(c+1)], end=' ')
c += 1
print("")
| Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
n = int(input())
l = range(1, n**2+1)
c = 0
for i in range(n):
z = []
for i in range(n//2):
print(l[c], l[-(c+1)], end=' ')
c += 1
print("")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s... | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"outp... | 1,617,208,708 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 872 | 1,740,800 | import math
n=int(input())
cnt=0
for i in range(1,n):
for j in range(1,i+1):
c2=int((i*i)+(j*j))
#print("c2={}".format(c2))
c=int(math.sqrt(c2))
#print("c={}".format(c))
if c<=n and (i*i)+(j*j)==int(c*c):
cnt+=1
#print(c)
print(cnt) | Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the squar... | ```python
import math
n=int(input())
cnt=0
for i in range(1,n):
for j in range(1,i+1):
c2=int((i*i)+(j*j))
#print("c2={}".format(c2))
c=int(math.sqrt(c2))
#print("c={}".format(c))
if c<=n and (i*i)+(j*j)==int(c*c):
cnt+=1
#print(c)
print(cn... | 3 | 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,698,049,475 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 62 | 0 | n, l = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
# print(A)
diff = [A[0]]
for i in range(n-1):
diff.append(A[i+1] - A[i])
diff.append(l - A[-1])
# print(diff)
maxdiff = max(diff)
if maxdiff/2 <= diff[0]:
print(diff[0])
elif maxdiff/2 <= diff[-1]:
print(diff[-1])
el... | 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, l = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
# print(A)
diff = [A[0]]
for i in range(n-1):
diff.append(A[i+1] - A[i])
diff.append(l - A[-1])
# print(diff)
maxdiff = max(diff)
if maxdiff/2 <= diff[0]:
print(diff[0])
elif maxdiff/2 <= diff[-1]:
print(dif... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,695,466,048 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 92 | 0 | import sys
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
# sys.stderr = open("error.txt", "w")
'''
baabbbeeee
i=0 b
i =1 a
'''
s = input()
res = ""
for i in s:
if i in ['a','e','i','o','u','A','E','I','O','U']:
continue
if ord(i) < 97:
i = chr(ord(i)+32)
res +=('.'+i)
print(r... | Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
import sys
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
# sys.stderr = open("error.txt", "w")
'''
baabbbeeee
i=0 b
i =1 a
'''
s = input()
res = ""
for i in s:
if i in ['a','e','i','o','u','A','E','I','O','U']:
continue
if ord(i) < 97:
i = chr(ord(i)+32)
res +=('.'+i) ... | 0 | 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,697,157,798 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | string=input()
lst_string=list(string)
upper=0
lower=0
for n in range(len(lst_string)):
if string[n].isupper():
upper+=1
else:
lower+=1
if upper > lower:
print(string.upper())
elif upper <= lower:
print(string.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
string=input()
lst_string=list(string)
upper=0
lower=0
for n in range(len(lst_string)):
if string[n].isupper():
upper+=1
else:
lower+=1
if upper > lower:
print(string.upper())
elif upper <= lower:
print(string.lower())
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
120 | C | Winnie-the-Pooh and honey | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are *n* jars of honey lined up in front of Winnie... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, separated by spaces (1<=≤<=*a**i*<=≤<=100). | Print a single number — how many kilos of honey gets Piglet. | [
"3 3\n15 8 10\n"
] | [
"9\n"
] | none | 0 | [
{
"input": "3 3\n15 8 10",
"output": "9"
},
{
"input": "1 3\n3",
"output": "0"
},
{
"input": "3 4\n3 8 2",
"output": "5"
},
{
"input": "3 2\n95 25 49",
"output": "151"
},
{
"input": "3 1\n8 3 2",
"output": "5"
},
{
"input": "5 1\n4 7 9 5 7",
"outpu... | 1,593,416,485 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 6,656,000 | n,k = map(int,input().split())
Honey = list(map(int,input().split()))
sorted_list = sorted(Honey,reverse=True)
# piglet = []
# for i in range():
# print(sorted_list)
# count = 0
for i in range(3):
for j in range(n):
if sorted_list[j] >= k:
sorted_list[j] -= k
# print(sor... | Title: Winnie-the-Pooh and honey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie an... | ```python
n,k = map(int,input().split())
Honey = list(map(int,input().split()))
sorted_list = sorted(Honey,reverse=True)
# piglet = []
# for i in range():
# print(sorted_list)
# count = 0
for i in range(3):
for j in range(n):
if sorted_list[j] >= k:
sorted_list[j] -= k
#... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
322 | A | Ciel and Dancing | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:
- either the boy in the dancing pair must dance for the first time ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room. | In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*. | [
"2 1\n",
"2 2\n"
] | [
"2\n1 1\n2 1\n",
"3\n1 1\n1 2\n2 2\n"
] | In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).
And in test case 2, we have 2 boys with 2 girls, the answer is 3. | 500 | [
{
"input": "2 1",
"output": "2\n1 1\n2 1"
},
{
"input": "2 2",
"output": "3\n1 1\n1 2\n2 2"
},
{
"input": "1 1",
"output": "1\n1 1"
},
{
"input": "2 3",
"output": "4\n1 1\n1 2\n1 3\n2 3"
},
{
"input": "4 4",
"output": "7\n1 1\n1 2\n1 3\n1 4\n4 4\n3 4\n2 4"
}... | 1,698,428,883 | 2,147,483,647 | PyPy 3 | OK | TESTS | 28 | 278 | 409,600 | import sys
from math import *
from collections import Counter,defaultdict,deque
from bisect import bisect_left,bisect_right
input=sys.stdin.readline
mod=10**9+7
def get_ints():return map(int,input().split())
def get_int():return int(input())
def get_array():return list(map(int,input().split()))
def input():ret... | Title: Ciel and Dancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. B... | ```python
import sys
from math import *
from collections import Counter,defaultdict,deque
from bisect import bisect_left,bisect_right
input=sys.stdin.readline
mod=10**9+7
def get_ints():return map(int,input().split())
def get_int():return int(input())
def get_array():return list(map(int,input().split()))
def i... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,680,864,882 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 93 | 0 | def func(x):
p = [1] * 5
q = [x - 3, x - 1, x + 1, x + 3, x]
r = []
if int(x / 3) == 0:
p[0] = 0
if x % 3 == 0:
p[1] = 0
if (x + 1) % 3 == 0:
p[2] = 0
if int(x / 3) == 2:
p[3] = 0
for i in range(5):
if p[i] == 1:
r.append(q[i])
return r
s, t = [], [1] * 9
... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
def func(x):
p = [1] * 5
q = [x - 3, x - 1, x + 1, x + 3, x]
r = []
if int(x / 3) == 0:
p[0] = 0
if x % 3 == 0:
p[1] = 0
if (x + 1) % 3 == 0:
p[2] = 0
if int(x / 3) == 2:
p[3] = 0
for i in range(5):
if p[i] == 1:
r.append(q[i])
return r
s, t = [], [... | 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,740,837 | 17 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | def dice(n,a):
s=0
if n==1:
for i in range(1,10):
if str(i) in a[0]:
s+=1
else:
return s
elif n==2:
for i in range(1,10):
if str(i) in a[0]+a[1]:
s+=1
else:
return s
for i... | 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
def dice(n,a):
s=0
if n==1:
for i in range(1,10):
if str(i) in a[0]:
s+=1
else:
return s
elif n==2:
for i in range(1,10):
if str(i) in a[0]+a[1]:
s+=1
else:
return s
... | 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,699,714,737 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 0 | a=input()
length=len(a)
count=length
j=0
while j<length:
i=1
i=i+j
while i<length:
if a[j] == a[i]:
count=count-1
i+=1
j+=1
if count%2==0:
print("CHAT WITH HER!")
elif count%2 != 0:
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
a=input()
length=len(a)
count=length
j=0
while j<length:
i=1
i=i+j
while i<length:
if a[j] == a[i]:
count=count-1
i+=1
j+=1
if count%2==0:
print("CHAT WITH HER!")
elif count%2 != 0:
print("IGNORE HIM!")
``` | 0 | 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,682,938,170 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 62 | 0 | a, b = input().split(" ")
a, b = int(a), int(b)
total_hours = a
while a >= b:
new_candles = a // b
dec = a % b
total_hours = total_hours + new_candles
a = new_candles + dec
#print(a)
#print(dec)
#print(total_hours)
print(int(total_hours))
| 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 = input().split(" ")
a, b = int(a), int(b)
total_hours = a
while a >= b:
new_candles = a // b
dec = a % b
total_hours = total_hours + new_candles
a = new_candles + dec
#print(a)
#print(dec)
#print(total_hours)
print(int(total_hours))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,507,215,117 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 62 | 0 | import math
a=int(input())
if a%2==0:
b=a/2
c=a/2
else:
b=math.floor(a/2)
c=math.floor(a/2)+1
while 1:
b1=b
c1=c
while c1!=0 :
d=b1%c1
b1=c1
c1=d
if b1==1:
break
b -=1
c +=1
print(int(b),int(c))
| Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
import math
a=int(input())
if a%2==0:
b=a/2
c=a/2
else:
b=math.floor(a/2)
c=math.floor(a/2)+1
while 1:
b1=b
c1=c
while c1!=0 :
d=b1%c1
b1=c1
c1=d
if b1==1:
break
b -=1
c +=1
print(int(b),int(c))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | The mobile application store has a new game called "Subway Roller".
The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and *n* columns. At the beginning of the game the hero is in some cell of the left... | Each test contains from one to ten sets of the input data. The first line of the test contains a single integer *t* (1<=≤<=*t*<=≤<=10 for pretests and tests or *t*<==<=1 for hacks; see the Notes section for details) — the number of sets.
Then follows the description of *t* sets of the input data.
The first line of t... | For each set of the input data print on a single line word YES, if it is possible to win the game and word NO otherwise. | [
"2\n16 4\n...AAAAA........\ns.BBB......CCCCC\n........DDDDD...\n16 4\n...AAAAA........\ns.BBB....CCCCC..\n.......DDDDD....\n",
"2\n10 4\ns.ZZ......\n.....AAABB\n.YYYYYY...\n10 4\ns.ZZ......\n....AAAABB\n.YYYYYY...\n"
] | [
"YES\nNO\n",
"YES\nNO\n"
] | In the first set of the input of the first sample Philip must first go forward and go down to the third row of the field, then go only forward, then go forward and climb to the second row, go forward again and go up to the first row. After that way no train blocks Philip's path, so he can go straight to the end of the ... | 0 | [] | 1,444,665,966 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | #!/usr/bin/python3
t=int(input())
cmi=[0,-1,1]
def dfs(i,j,data,n):
stacki=list()
stackj=list()
stacki.append(i)
stackj.append(j)
while(len(stacki)!=0):
ti=stacki.pop()
tj=stackj.pop()
for i in range(0,3):
nexti=ti+cmi[i]
nextj=tj+3
if not (0<=nexti and nexti<=2):
conti... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The mobile application store has a new game called "Subway Roller".
The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of thr... | ```python
#!/usr/bin/python3
t=int(input())
cmi=[0,-1,1]
def dfs(i,j,data,n):
stacki=list()
stackj=list()
stacki.append(i)
stackj.append(j)
while(len(stacki)!=0):
ti=stacki.pop()
tj=stackj.pop()
for i in range(0,3):
nexti=ti+cmi[i]
nextj=tj+3
if not (0<=nexti and nexti<=2):
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
387 | A | George and Sleep | PROGRAMMING | 900 | [
"implementation"
] | null | null | George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see ... | The first line contains current time *s* as a string in the format "hh:mm". The second line contains time *t* in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00<=≤<=*hh*<=≤<=23, 00<=≤<=*mm*<=≤<=59. | In the single line print time *p* — the time George went to bed in the format similar to the format of the time in the input. | [
"05:50\n05:44\n",
"00:00\n01:00\n",
"00:01\n00:00\n"
] | [
"00:06\n",
"23:00\n",
"00:01\n"
] | In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect.
In the second sample, George went to bed yesterday.
In the third sample, George didn't do to bed at all. | 500 | [
{
"input": "05:50\n05:44",
"output": "00:06"
},
{
"input": "00:00\n01:00",
"output": "23:00"
},
{
"input": "00:01\n00:00",
"output": "00:01"
},
{
"input": "23:59\n23:59",
"output": "00:00"
},
{
"input": "23:44\n23:55",
"output": "23:49"
},
{
"input": "... | 1,397,055,241 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | def f(s):
a, b = list(map(int,s.spilt(":")))
return a*60 + b
ct = f(input())
ts = f(input())
ans = ct - ts
if ans < 0:
ans += 60*24
print("%02:%02" %(ans//60, ans%60))
| Title: George and Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when Geor... | ```python
def f(s):
a, b = list(map(int,s.spilt(":")))
return a*60 + b
ct = f(input())
ts = f(input())
ans = ct - ts
if ans < 0:
ans += 60*24
print("%02:%02" %(ans//60, ans%60))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,676,074,561 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | d = dict()
l = []
n = int(input())
for i in range(n):
a, b = input().split()
b = int(b)
l.append([a, b])
d[a] = 0
y = False
for i in l:
d[i[0]] += i[1]
for j in d:
if d[j] == 5:
print(j)
y = True
break
if y:
break
| Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
d = dict()
l = []
n = int(input())
for i in range(n):
a, b = input().split()
b = int(b)
l.append([a, b])
d[a] = 0
y = False
for i in l:
d[i[0]] += i[1]
for j in d:
if d[j] == 5:
print(j)
y = True
break
if y:
break... | 0 | 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,667,575,923 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | output = []
for ele in b:
num = 0
for elea in a:
if elea <= ele:
num += 1
output.append(num)
print(output)
| 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
output = []
for ele in b:
num = 0
for elea in a:
if elea <= ele:
num += 1
output.append(num)
print(output)
``` | -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,298,114 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 2,764,800 | a,b=list(map(int,input().split()))
l=list(map(int,input().split()))
dic={}
for i in range(1,a):
dic[i]=i+l[i-1]
a=1
while True:
if a not in dic:
print('NO')
break
else:
a=dic[a]
if a==b:
print('YES')
break
| 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
a,b=list(map(int,input().split()))
l=list(map(int,input().split()))
dic={}
for i in range(1,a):
dic[i]=i+l[i-1]
a=1
while True:
if a not in dic:
print('NO')
break
else:
a=dic[a]
if a==b:
print('YES')
break
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
14 | B | Young Photographer | PROGRAMMING | 1,000 | [
"implementation"
] | B. Young Photographer | 2 | 64 | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at t... | The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | [
"3 3\n0 7\n14 2\n4 6\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "3 3\n0 7\n14 2\n4 6",
"output": "1"
},
{
"input": "1 1\n0 10",
"output": "0"
},
{
"input": "2 2\n1 2\n3 2",
"output": "0"
},
{
"input": "3 2\n1 2\n2 3\n3 4",
"output": "-1"
},
{
"input": "2 4\n10 4\n1 5",
"output": "0"
},
{
"input": "1 10\n... | 1,669,739,403 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def start():
n,x=map(int,input().split())
s=[]
ss=[]
sss=[]
c=0
for i in range(n):
a,b=map(int,input().split())
mn=min(a,b)
mx=max(a,b)
ss.append(mn)
sss.append(mx)
if max(ss)>min(sss):
print(-1)
return
fo... | Title: Young Photographer
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. Bu... | ```python
def start():
n,x=map(int,input().split())
s=[]
ss=[]
sss=[]
c=0
for i in range(n):
a,b=map(int,input().split())
mn=min(a,b)
mx=max(a,b)
ss.append(mn)
sss.append(mx)
if max(ss)>min(sss):
print(-1)
retu... | -1 | MatrixStudio/Codeforces-Python-Submissions |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,688,071,615 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | # Read the input
guest_name = input()
host_name = input()
pile_letters = input()
# Initialize dictionaries to store the letter frequencies
guest_freq = {}
host_freq = {}
pile_freq = {}
# Count the frequencies of letters in the guest's name
for letter in guest_name:
guest_freq[letter] = guest_freq.get(... | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
# Read the input
guest_name = input()
host_name = input()
pile_letters = input()
# Initialize dictionaries to store the letter frequencies
guest_freq = {}
host_freq = {}
pile_freq = {}
# Count the frequencies of letters in the guest's name
for letter in guest_name:
guest_freq[letter] = guest... | 0 | 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,676,321,119 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 1,000 | 9,318,400 | n = int(input())
s = input()
c = 0
while c <= n/2+2:
for i in range(len(s)-1):
if s[i] != s[i+1]:
s = s[:i] + s[i+2:]
break
c += 1
print(len(s))
| Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
n = int(input())
s = input()
c = 0
while c <= n/2+2:
for i in range(len(s)-1):
if s[i] != s[i+1]:
s = s[:i] + s[i+2:]
break
c += 1
print(len(s))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time,... | The first line contains two integers *a* and *b* (*a*<=≠<=*b*,<=1<=≤<=*a*,<=*b*<=≤<=106). | Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency. | [
"3 7\n",
"5 3\n",
"2 3\n"
] | [
"Dasha\n",
"Masha\n",
"Equal\n"
] | Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls ... | 0 | [
{
"input": "3 7",
"output": "Dasha"
},
{
"input": "5 3",
"output": "Masha"
},
{
"input": "2 3",
"output": "Equal"
},
{
"input": "31 88",
"output": "Dasha"
},
{
"input": "8 75",
"output": "Dasha"
},
{
"input": "32 99",
"output": "Dasha"
},
{
... | 1,645,430,489 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 12 | 124 | 0 | a, b = list(map(int, input().split()))
def gcd(a, b):
while b:
a, b = b, a%b
return a
g, l = max(a, b), min(a, b)
if g == l or g-l == 1 or gcd(g, l) > 1:
print("Equal")
else:
if a < b: print("Dasha")
else: print("Masha")
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has so... | ```python
a, b = list(map(int, input().split()))
def gcd(a, b):
while b:
a, b = b, a%b
return a
g, l = max(a, b), min(a, b)
if g == l or g-l == 1 or gcd(g, l) > 1:
print("Equal")
else:
if a < b: print("Dasha")
else: print("Masha")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,696,652,977 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | # Read input values
n, k, l, c, d, p, nl, np = map(int, input().split())
# Calculate the total milliliters of the drink, slices of lime, and grams of salt available
total_milliliters = k * l
total_slices = c * d
total_salt = p
# Calculate the number of toasts each friend can make
toasts_drink = total_millili... | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
# Read input values
n, k, l, c, d, p, nl, np = map(int, input().split())
# Calculate the total milliliters of the drink, slices of lime, and grams of salt available
total_milliliters = k * l
total_slices = c * d
total_salt = p
# Calculate the number of toasts each friend can make
toasts_drink = tot... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
883 | E | Field of Wonders | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length *n*, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already reveale... | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | [
"4\na**d\n2\nabcd\nacbd\n",
"5\nlo*er\n2\nlover\nloser\n",
"3\na*a\n2\naaa\naba\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidde... | 0 | [
{
"input": "4\na**d\n2\nabcd\nacbd",
"output": "2"
},
{
"input": "5\nlo*er\n2\nlover\nloser",
"output": "0"
},
{
"input": "3\na*a\n2\naaa\naba",
"output": "1"
},
{
"input": "1\n*\n1\na",
"output": "1"
},
{
"input": "1\n*\n1\nz",
"output": "1"
},
{
"inp... | 1,510,065,169 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 78 | 0 | length=int(input())
guessword=input()
missingindices=[]
doneindices=[]
done=set()
for i in range(length):
if guessword[i] != "*":
doneindices.append(i)
done.add(guessword[i])
else:
missingindices.append(i)
counter={}
n=int(input())
totalposs=n
for _ in range(n):
knownword=input()
pos... | Title: Field of Wonders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several tur... | ```python
length=int(input())
guessword=input()
missingindices=[]
doneindices=[]
done=set()
for i in range(length):
if guessword[i] != "*":
doneindices.append(i)
done.add(guessword[i])
else:
missingindices.append(i)
counter={}
n=int(input())
totalposs=n
for _ in range(n):
knownword=inpu... | 3 | 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,650,100,093 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | import sys
args = []
for line in sys.stdin:
args.append(line)
disks = int(args[1])
orig = args[2]
comb = args[3]
moves = 0
for i in range(disks):
moves += min(abs(int(orig[i]) - int(comb[i])), 10 - abs(int(orig[i]) - int(comb[i])))
print(moves) | 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
import sys
args = []
for line in sys.stdin:
args.append(line)
disks = int(args[1])
orig = args[2]
comb = args[3]
moves = 0
for i in range(disks):
moves += min(abs(int(orig[i]) - int(comb[i])), 10 - abs(int(orig[i]) - int(comb[i])))
print(moves)
``` | -1 | 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,608,812,431 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | s=input()
c=0
for x in s:
if x.isupper() :
c+=1
if c>len(s)//2 :
s=s.upper()
else :
s=s.lower()
print(s) | 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()
c=0
for x in s:
if x.isupper() :
c+=1
if c>len(s)//2 :
s=s.upper()
else :
s=s.lower()
print(s)
``` | 3.9455 | MatrixStudio/Codeforces-Python-Submissions |
31 | A | Worms Evolution | PROGRAMMING | 1,200 | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output":... | 1,690,471,322 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <fstream>
#include <stack>
#include <iomanip>
#include <cmath>
#include <queue>
#include <list>
#include <algorithm>
#include <utility>
#include <bits/stdc++.h>
#include <string>
#ifndef ONLINE_JUDGE
#include "LeetCode.h"
#endif
using namespace std;
typedef long lon... | Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his... | ```python
#include <iostream>
#include <fstream>
#include <stack>
#include <iomanip>
#include <cmath>
#include <queue>
#include <list>
#include <algorithm>
#include <utility>
#include <bits/stdc++.h>
#include <string>
#ifndef ONLINE_JUDGE
#include "LeetCode.h"
#endif
using namespace std;
typede... | -1 | MatrixStudio/Codeforces-Python-Submissions |
583 | A | Asphalting Roads | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was ma... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city.
Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the inte... | In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. | [
"2\n1 1\n1 2\n2 1\n2 2\n",
"1\n1 1\n"
] | [
"1 4 \n",
"1 \n"
] | In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the i... | 500 | [
{
"input": "2\n1 1\n1 2\n2 1\n2 2",
"output": "1 4 "
},
{
"input": "1\n1 1",
"output": "1 "
},
{
"input": "2\n1 1\n2 2\n1 2\n2 1",
"output": "1 2 "
},
{
"input": "2\n1 2\n2 2\n2 1\n1 1",
"output": "1 3 "
},
{
"input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 ... | 1,495,508,623 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 62 | 307,200 | n = int(input())
A = []
for i in range(0,n**2):
a,b = input().split()
A.append([int(a),int(b)])
B = []
C = []
for l in range(0,n):
B.append(0)
C.append(0)
D = []
for k in range(0,n**2):
if B[A[k][0]-1] == 0 and C[A[k][1]-1] == 0:
D.append(k)
B[A[k][0]-1] = 1
C[A[k][1]-1] = 1
... | Title: Asphalting Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers ... | ```python
n = int(input())
A = []
for i in range(0,n**2):
a,b = input().split()
A.append([int(a),int(b)])
B = []
C = []
for l in range(0,n):
B.append(0)
C.append(0)
D = []
for k in range(0,n**2):
if B[A[k][0]-1] == 0 and C[A[k][1]-1] == 0:
D.append(k)
B[A[k][0]-1] = 1
C[A[k][... | 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,564,459,716 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | s=input()
n = len(s)
c=0
for i in s:
if(i.isupper()):
c = c+1
d = n-c
if(d>=c):
s = s.lower()
else:
s = s.upper()
print(s) | 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()
n = len(s)
c=0
for i in s:
if(i.isupper()):
c = c+1
d = n-c
if(d>=c):
s = s.lower()
else:
s = s.upper()
print(s)
``` | 3.9455 | MatrixStudio/Codeforces-Python-Submissions |
877 | A | Alex and broken contest | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ... | The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. | Print "YES", if problem is from this contest, and "NO" otherwise. | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n"
] | [
"NO",
"YES",
"NO"
] | none | 500 | [
{
"input": "Alex_and_broken_contest",
"output": "NO"
},
{
"input": "NikitaAndString",
"output": "YES"
},
{
"input": "Danil_and_Olya",
"output": "NO"
},
{
"input": "Slava____and_the_game",
"output": "YES"
},
{
"input": "Olya_and_energy_drinks",
"output": "YES"
... | 1,553,746,265 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | mp={}
mp['Danil']=1
mp['Olya']=1
mp['Slava']=1
mp['Ann']=1
mp['Nikita']=1
s=input()
ct=0
for i in range(len(s)):
for j in range(i,len(s)):
if s[i:j] in mp:
ct+=1
del mp[s[i:j]]
if ct==1:
print("YES")
else:
print("NO")
| Title: Alex and broken contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems,... | ```python
mp={}
mp['Danil']=1
mp['Olya']=1
mp['Slava']=1
mp['Ann']=1
mp['Nikita']=1
s=input()
ct=0
for i in range(len(s)):
for j in range(i,len(s)):
if s[i:j] in mp:
ct+=1
del mp[s[i:j]]
if ct==1:
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 0 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,588,744,634 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 307,200 | n = int(input())
x = {}
y = {}
def insert(d, n):
if n in d.keys():
d[n] += 1
else:
d[n] = 1
return d
for i in range(n):
l = input().split()
u = int(l[0])
v = int(l[1])
if u not in x.keys():
x[u] = [v]
else:
x[u].append(v)
if v not in y.keys():
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need ... | ```python
n = int(input())
x = {}
y = {}
def insert(d, n):
if n in d.keys():
d[n] += 1
else:
d[n] = 1
return d
for i in range(n):
l = input().split()
u = int(l[0])
v = int(l[1])
if u not in x.keys():
x[u] = [v]
else:
x[u].append(v)
if v not in y.... | 0 | 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,699,221,886 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 154 | 1,638,400 | n = int(input())
ans = 0
for i in range(n):
a = input()
if int(a[0]) + int(a[2]) + int(a[4]) > 1:
ans += 1
print(ans)
| 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())
ans = 0
for i in range(n):
a = input()
if int(a[0]) + int(a[2]) + int(a[4]) > 1:
ans += 1
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,692,879,729 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 342 | 21,504,000 | n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
vas=0
pet=0
dic={}
i=0
while i< n :
dic[a[i]]=i+1
i+=1
for i in b :
vas+=dic[i]
pet+=n-dic[i]+1
print(vas,pet) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
vas=0
pet=0
dic={}
i=0
while i< n :
dic[a[i]]=i+1
i+=1
for i in b :
vas+=dic[i]
pet+=n-dic[i]+1
print(vas,pet)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
-... | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "... | 1,411,746,092 | 692 | Python 3 | OK | TESTS | 29 | 62 | 0 | a = sorted(list(input().split()))
if a.count(a[0]) >= 4:
if a[-1] > a[-2]:
print('Bear')
else:
print('Elephant')
elif a.count(a[1]) >= 4:
if a[-1] > a[0]:
print('Bear')
else:
print('Elephant')
elif a.count(a[2]) >= 4:
if a[1] > a[0]:
print('Bear... | Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an... | ```python
a = sorted(list(input().split()))
if a.count(a[0]) >= 4:
if a[-1] > a[-2]:
print('Bear')
else:
print('Elephant')
elif a.count(a[1]) >= 4:
if a[-1] > a[0]:
print('Bear')
else:
print('Elephant')
elif a.count(a[2]) >= 4:
if a[1] > a[0]:
p... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
729 | A | Interview with Oleg | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview.
The second line contains the string *s* of length *n*, consisting of lowercase English letters. | Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences. | [
"7\naogogob\n",
"13\nogogmgogogogo\n",
"9\nogoogoogo\n"
] | [
"a***b\n",
"***gmg***\n",
"*********\n"
] | The first sample contains one filler word ogogo, so the interview for printing is "a***b".
The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***". | 500 | [
{
"input": "7\naogogob",
"output": "a***b"
},
{
"input": "13\nogogmgogogogo",
"output": "***gmg***"
},
{
"input": "9\nogoogoogo",
"output": "*********"
},
{
"input": "32\nabcdefogoghijklmnogoopqrstuvwxyz",
"output": "abcdef***ghijklmn***opqrstuvwxyz"
},
{
"input":... | 1,597,314,665 | 1,565 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 156 | 0 | l = int(input())
arr = list(input())
arr.append('$')
arr.append('$')
arr.append('$')
st = 0
i = 0
fl = False
inx = []
while i < l+1:
if fl:
if arr[i:i+2] != ['g','o']:
inx.append([st,i])
for g in range(st,i):
arr[g] = '*'
fl = False
... | Title: Interview with Oleg
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a fi... | ```python
l = int(input())
arr = list(input())
arr.append('$')
arr.append('$')
arr.append('$')
st = 0
i = 0
fl = False
inx = []
while i < l+1:
if fl:
if arr[i:i+2] != ['g','o']:
inx.append([st,i])
for g in range(st,i):
arr[g] = '*'
fl = Fa... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,... | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"outpu... | 1,694,141,584 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 46 | 0 | raw=input().split()
m=int(raw[0])
n=int(raw[1])
i=1
while i<=n:
if m%10==0:
m=int(m/10)
else:
m=m-1
i+=1
print(m) | Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit ... | ```python
raw=input().split()
m=int(raw[0])
n=int(raw[1])
i=1
while i<=n:
if m%10==0:
m=int(m/10)
else:
m=m-1
i+=1
print(m)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,695,291,290 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | n,k = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(2,n,2):
if l[i]+k<=5 and l[i-2]+k<=5:
count+=1
print(count) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n,k = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(2,n,2):
if l[i]+k<=5 and l[i-2]+k<=5:
count+=1
print(count)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,679,572,976 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 6,963,200 | n,b,d=map(int,input().split())
a=list(map(int,input().split()))
c=0
m=0
for i in a:
if i>=b:
continue
else:
c+=i
if d<=c:
c=0
m+=1
print(m)
| Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n,b,d=map(int,input().split())
a=list(map(int,input().split()))
c=0
m=0
for i in a:
if i>=b:
continue
else:
c+=i
if d<=c:
c=0
m+=1
print(m)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
253 | B | Physics Practical | PROGRAMMING | 1,400 | [
"binary search",
"dp",
"sortings",
"two pointers"
] | null | null | One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher h... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces. | Print a single integer — the minimum number of results Vasya will have to remove. | [
"6\n4 5 3 8 3 7\n",
"4\n4 3 2 4\n"
] | [
"2\n",
"0\n"
] | In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one... | 1,000 | [
{
"input": "6\n4 5 3 8 3 7",
"output": "2"
},
{
"input": "4\n4 3 2 4",
"output": "0"
},
{
"input": "6\n5 6 4 9 4 8",
"output": "1"
},
{
"input": "4\n5 4 1 5",
"output": "1"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "10\n39 9 18 13 6 16 47 15 ... | 1,659,196,906 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 92 | 0 | import sys
import os.path
def li(): return [int(i) for i in input().split()]
def si(): return input()
if (os.path.exists('input.txt')):
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
sys.stderr = open("error.txt", "w")
_, ms= si(), li()
lowest, greatest = min(ms),... | Title: Physics Practical
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he... | ```python
import sys
import os.path
def li(): return [int(i) for i in input().split()]
def si(): return input()
if (os.path.exists('input.txt')):
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
sys.stderr = open("error.txt", "w")
_, ms= si(), li()
lowest, greatest ... | 0 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.