contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,680,016,483 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 62 | 0 | def sol(n):
k = int( (2*n + 0.25)**0.5 - 0.5)
t = k * (k+1) // 2
if n == t:
print(k)
print(" ".join(str(x+1) for x in range(k)))
else:
print(k)
t = k * (k-1) // 2
res = [str(x+1) for x in range(k-1)]
res.append(str(n-t))
print(" ".join(r... | 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
def sol(n):
k = int( (2*n + 0.25)**0.5 - 0.5)
t = k * (k+1) // 2
if n == t:
print(k)
print(" ".join(str(x+1) for x in range(k)))
else:
print(k)
t = k * (k-1) // 2
res = [str(x+1) for x in range(k-1)]
res.append(str(n-t))
print(... | 3 | |
330 | B | Road Construction | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs"
] | null | null | A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two... | The first line consists of two integers *n* and *m* .
Then *m* lines follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), which means that it is not possible to construct a road connecting cities *a**i* and *b**i*. Consider the cities are numbered from 1 to *n*.... | You should print an integer *s*: the minimum number of roads that should be constructed, in the first line. Then *s* lines should follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*), which means that a road should be constructed between cities *a**i* and *b**i*.... | [
"4 1\n1 3\n"
] | [
"3\n1 2\n4 2\n2 3\n"
] | This is one possible solution of the example:
These are examples of wrong solutions: | 1,000 | [
{
"input": "4 1\n1 3",
"output": "3\n1 2\n4 2\n2 3"
},
{
"input": "1000 0",
"output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 ... | 1,621,647,738 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 0 | n,m=map(int,input().split())
l=[0] * n
for i in range(m):
a,b=map(int,input().split())
l[a-1]=1;l[b-1]=1
v=l.index(0)+1
print(n-1)
for i in range(1,n+1) :
if i!=v :
print(v,i) | Title: Road Construction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constru... | ```python
n,m=map(int,input().split())
l=[0] * n
for i in range(m):
a,b=map(int,input().split())
l[a-1]=1;l[b-1]=1
v=l.index(0)+1
print(n-1)
for i in range(1,n+1) :
if i!=v :
print(v,i)
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At 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,672,258,672 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | str1 = str(input())
count_1 = count_2 = 0
for i in range (len(str1)):
if ord(str1[i]) < ord('a'):
count_1 += 1
else:
count_2 += 1
if (count_1 <= count_2):
str1 = str1.lower()
else:
str1 = str1.upper()
print(str1) | 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
str1 = str(input())
count_1 = count_2 = 0
for i in range (len(str1)):
if ord(str1[i]) < ord('a'):
count_1 += 1
else:
count_2 += 1
if (count_1 <= count_2):
str1 = str1.lower()
else:
str1 = str1.upper()
print(str1)
``` | 3.969 |
876 | B | Divisiblity of Differences | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number... | First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=... | If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them... | [
"3 2 3\n1 8 4\n",
"3 3 3\n1 8 4\n",
"4 3 5\n2 7 7 7\n"
] | [
"Yes\n1 4 ",
"No",
"Yes\n2 7 7 "
] | none | 1,000 | [
{
"input": "3 2 3\n1 8 4",
"output": "Yes\n1 4 "
},
{
"input": "3 3 3\n1 8 4",
"output": "No"
},
{
"input": "4 3 5\n2 7 7 7",
"output": "Yes\n2 7 7 "
},
{
"input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825",
"output":... | 1,508,311,753 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 421 | 14,438,400 |
n, k, m = list(map(int, input().split(' ')))
arr = list(map(int, input().split(' ')))
modN = [[] for i in range(100001)]
for i in arr:
modN[i % m].append(i)
for o in modN:
if len(o) >= k:
print('Yes')
for i in range(k):
print(o[i])
exit(0)
print('No... | Title: Divisiblity of Differences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be re... | ```python
n, k, m = list(map(int, input().split(' ')))
arr = list(map(int, input().split(' ')))
modN = [[] for i in range(100001)]
for i in arr:
modN[i % m].append(i)
for o in modN:
if len(o) >= k:
print('Yes')
for i in range(k):
print(o[i])
exit(0)
... | 3 | |
25 | B | Phone numbers | PROGRAMMING | 1,100 | [
"implementation"
] | B. Phone numbers | 2 | 256 | Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups. | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | [
"6\n549871\n",
"7\n1198733\n"
] | [
"54-98-71",
"11-987-33\n"
] | none | 0 | [
{
"input": "6\n549871",
"output": "54-98-71"
},
{
"input": "7\n1198733",
"output": "119-87-33"
},
{
"input": "2\n74",
"output": "74"
},
{
"input": "2\n33",
"output": "33"
},
{
"input": "3\n074",
"output": "074"
},
{
"input": "3\n081",
"output": "08... | 1,481,565,527 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | cantidad = int(raw_input())
array = raw_input()
out = ""
if cantidad%2 == 1:
out += array[0]+ array[1]+ array[2]
for i in range (3, cantidad, 2):
out+="-"+array[i]+array[i+1]
else:
out += array[0]+ array[1]
for i in range (2, cantidad, 2):
out+="-"+array[i]+array[i+1]
print(out)
| Title: Phone numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33.... | ```python
cantidad = int(raw_input())
array = raw_input()
out = ""
if cantidad%2 == 1:
out += array[0]+ array[1]+ array[2]
for i in range (3, cantidad, 2):
out+="-"+array[i]+array[i+1]
else:
out += array[0]+ array[1]
for i in range (2, cantidad, 2):
out+="-"+array[i]+array[i+1]
print(out)
``` | -1 |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,546,431,188 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 248 | 0 | n=int(input());s=input().split();x=int(s[0]);y=int(s[1]);z=int(s[2])
for i in range(1,n):
s=input().split()
if int(s[0])<0:
x-=abs(int(s[0]))
else:
x+=abs(int(s[0]))
if int(s[1])<0:
y-=abs(int(s[1]))
else:
y+=abs(int(s[1]))
if int(s[2])<0:
z-=abs(int(s[2])... | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n=int(input());s=input().split();x=int(s[0]);y=int(s[1]);z=int(s[2])
for i in range(1,n):
s=input().split()
if int(s[0])<0:
x-=abs(int(s[0]))
else:
x+=abs(int(s[0]))
if int(s[1])<0:
y-=abs(int(s[1]))
else:
y+=abs(int(s[1]))
if int(s[2])<0:
z-=abs... | 3.938 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,586,589,669 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 248 | 0 | y,w=map(int,input().split())
n=abs(7 - max(y,w))
z=6/n
print("{}/{}".format(1,z)) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
y,w=map(int,input().split())
n=abs(7 - max(y,w))
z=6/n
print("{}/{}".format(1,z))
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given a tree (a graph with *n* vertices and *n*<=-<=1 edges in which it's possible to reach any vertex from any other vertex using only its edges).
A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted.
Destroy all vertices in the given t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — number of vertices in a tree.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=*n*). If *p**i*<=≠<=0 there is an edge between vertices *i* and *p**i*. It is guaranteed that the given graph is a tree. | If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes).
If it's possible to destroy all vertices, in the next *n* lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any. | [
"5\n0 1 2 1 2\n",
"4\n0 1 2 3\n"
] | [
"YES\n1\n2\n3\n5\n4\n",
"NO\n"
] | In the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order. | 0 | [] | 1,523,986,979 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 7,168,000 | n=int(input())
d={}
def add(x,y):
if x in d:
d[x].append(y)
else:
d[x]=[y]
if y in d:
d[y].append(x)
else:
d[y]=[x]
ns=[int(x) for x in input().split()]
for i in range(n):
if ns[i]==0:
continue
x=i+1
y=ns[i]
add(x,y)
add(0,1)
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tree (a graph with *n* vertices and *n*<=-<=1 edges in which it's possible to reach any vertex from any other vertex using only its edges).
A vertex can be destroyed if this vertex has even degree. If you destroy ... | ```python
n=int(input())
d={}
def add(x,y):
if x in d:
d[x].append(y)
else:
d[x]=[y]
if y in d:
d[y].append(x)
else:
d[y]=[x]
ns=[int(x) for x in input().split()]
for i in range(n):
if ns[i]==0:
continue
x=i+1
y=ns[i]
add(x,y)
... | 0 | |
670 | D1 | Magic Powder - 1 | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation"
] | null | null | This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.
Waking up in the ... | The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of... | Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. | [
"3 1\n2 1 4\n11 3 16\n",
"4 3\n4 3 5 6\n11 12 14 20\n"
] | [
"4\n",
"3\n"
] | In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.
In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredie... | 1,000 | [
{
"input": "3 1\n2 1 4\n11 3 16",
"output": "4"
},
{
"input": "4 3\n4 3 5 6\n11 12 14 20",
"output": "3"
},
{
"input": "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000",
"output": "137"
},
{
"input": "20 925\n7 3 1 2 1 3 1 3 1 2 3 1 5 8 1 3 7 3 4 2\n837 ... | 1,661,442,812 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 31 | 0 | n,k =map(int,input().split())
need=list(map(int,input().split()))
have=list(map(int,input().split()))
st=0
en =sum(have)
mx =0
while(st<=en):
mid =st+(en-st)//2
dif =0
for i in range(n):
k1=mid*need[i]
if have[i]>k1:
dif+=0
else:
dif+=k1-have[... | Title: Magic Powder - 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too dif... | ```python
n,k =map(int,input().split())
need=list(map(int,input().split()))
have=list(map(int,input().split()))
st=0
en =sum(have)
mx =0
while(st<=en):
mid =st+(en-st)//2
dif =0
for i in range(n):
k1=mid*need[i]
if have[i]>k1:
dif+=0
else:
dif... | 0 | |
656 | G | You're a Professional | PROGRAMMING | 1,900 | [
"*special"
] | null | null | A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be... | The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*).
The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-t... | Output an integer — the number of items liked by at least *T* of user's friends. | [
"3 3 2\nYYY\nNNN\nYNY\n",
"4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n"
] | [
"2\n",
"4\n"
] | none | 0 | [
{
"input": "3 3 2\nYYY\nNNN\nYNY",
"output": "2"
},
{
"input": "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN",
"output": "4"
},
{
"input": "3 5 2\nNYNNY\nYNNNN\nNNYYN",
"output": "0"
},
{
"input": "1 10 1\nYYYNYNNYNN",
"output": "5"
},
{
"input": "10 1 5\nY\nN\nN\nN\nY\nN\nN\nY\... | 1,459,532,712 | 6,312 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 0 | 0 | n,m,k = map(int, input().split())
a = [input() for i in range(n)]
print(sum(sum(int(a[i][j]=='Y') for i in range(n)) >= k for j in range(m))) | Title: You're a Professional
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a li... | ```python
n,m,k = map(int, input().split())
a = [input() for i in range(n)]
print(sum(sum(int(a[i][j]=='Y') for i in range(n)) >= k for j in range(m)))
``` | 0 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,671,536,177 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 18 | 122 | 0 | n,m = map(int,input().strip().split())
l = list(map(int,input().strip().split()))
l.sort()
ans = l[n - 1] - l[0]
for i in range(1,(m-n) + 1):
ans = min(ans,l[i+n-1] - l[i])
print(ans) | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n,m = map(int,input().strip().split())
l = list(map(int,input().strip().split()))
l.sort()
ans = l[n - 1] - l[0]
for i in range(1,(m-n) + 1):
ans = min(ans,l[i+n-1] - l[i])
print(ans)
``` | 3 | |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,551,975,144 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 307,200 | s = list(input())
z = list(input())
x = list()
for i in range(len(s)):
if s[i] == '|':
inx = i
x = s[0:inx]
for i in range(inx+1):
del s[0]
if (min(len(s), len(x)) + len(z)) == max(len(s), len(x)):
if len(s) > len(x):
for i in range(len(x)):
print(x[i], end='')
... | Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
s = list(input())
z = list(input())
x = list()
for i in range(len(s)):
if s[i] == '|':
inx = i
x = s[0:inx]
for i in range(inx+1):
del s[0]
if (min(len(s), len(x)) + len(z)) == max(len(s), len(x)):
if len(s) > len(x):
for i in range(len(x)):
print(x[i], end=... | 0 | |
652 | C | Foe Pairs | PROGRAMMING | 1,800 | [
"combinatorics",
"sortings",
"two pointers"
] | null | null | You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*).
Your task is to count the number of different intervals (*x*,<=*y*) (1<=≤<=*x*<=≤<=*y*<=≤<=*n*) that do not contain any foe pairs. So you shouldn't count intervals (*x... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the length of the permutation *p* and the number of foe pairs.
The second line contains *n* distinct integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation *p*.
Each of the next *m* lines contains two integers (*a**i*,<=*... | Print the only integer *c* — the number of different intervals (*x*,<=*y*) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"4 2\n1 3 2 4\n3 2\n2 4\n",
"9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7\n"
] | [
"5\n",
"20\n"
] | In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). | 0 | [
{
"input": "4 2\n1 3 2 4\n3 2\n2 4",
"output": "5"
},
{
"input": "9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7",
"output": "20"
},
{
"input": "2 1\n1 2\n1 2",
"output": "2"
},
{
"input": "10 3\n4 10 5 1 6 8 9 2 3 7\n10 5\n2 10\n4 1",
"output": "39"
},
{
"input"... | 1,459,099,955 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 779 | 38,707,200 | def main():
from sys import stdin
n, m = map(int, input().split())
n += 1
aa, pos, duo = [0] * n, [0] * n, [0] * n
for i, a in enumerate(map(int, input().split()), 1):
aa[i] = a
pos[a] = i
for s in stdin.read().splitlines():
x, y = map(int, s.split())
px, py = pos... | Title: Foe Pairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*).
Your task is to count the number of different intervals (*x*,<=*y*) (1<=... | ```python
def main():
from sys import stdin
n, m = map(int, input().split())
n += 1
aa, pos, duo = [0] * n, [0] * n, [0] * n
for i, a in enumerate(map(int, input().split()), 1):
aa[i] = a
pos[a] = i
for s in stdin.read().splitlines():
x, y = map(int, s.split())
px... | 3 | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,695,562,610 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | year = list(input())
for i in range(int("".join(year)) + 1, 9000):
i = list(str(i))
if i[0] != i[1] and i[0] != i[2] and i[0] != i[3] and i[1] != i[2] and i[1] != i[3] and i[2] != i[3]:
print("".join(i))
break
| Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
year = list(input())
for i in range(int("".join(year)) + 1, 9000):
i = list(str(i))
if i[0] != i[1] and i[0] != i[2] and i[0] != i[3] and i[1] != i[2] and i[1] != i[3] and i[2] != i[3]:
print("".join(i))
break
``` | 0 | |
992 | C | Nastya and a Wardrobe | PROGRAMMING | 1,600 | [
"math"
] | null | null | Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month).
Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with ... | The only line contains two integers *x* and *k* (0<=≤<=*x*,<=*k*<=≤<=1018), where *x* is the initial number of dresses and *k*<=+<=1 is the number of months in a year in Byteland. | In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109<=+<=7. | [
"2 0\n",
"2 1\n",
"3 2\n"
] | [
"4\n",
"7\n",
"21\n"
] | In the first example a year consists on only one month, so the wardrobe does not eat dresses at all.
In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% prob... | 1,500 | [
{
"input": "2 0",
"output": "4"
},
{
"input": "2 1",
"output": "7"
},
{
"input": "3 2",
"output": "21"
},
{
"input": "1 411",
"output": "485514976"
},
{
"input": "1 692",
"output": "860080936"
},
{
"input": "16 8",
"output": "7937"
},
{
"in... | 1,646,326,442 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | MOD = 10**9 + 7
x,k=map(int,input().split())
a1=pow(2,k+1,MOD)
b1=pow(2,k,MOD)
print((a1*x - b1 +1)%MOD) | Title: Nastya and a Wardrobe
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning ... | ```python
MOD = 10**9 + 7
x,k=map(int,input().split())
a1=pow(2,k+1,MOD)
b1=pow(2,k,MOD)
print((a1*x - b1 +1)%MOD)
``` | 0 | |
799 | B | T-shirt buying | PROGRAMMING | 1,400 | [
"data structures",
"implementation"
] | null | null | A new pack of *n* t-shirts came to a shop. Each of the t-shirts is characterized by three integers *p**i*, *a**i* and *b**i*, where *p**i* is the price of the *i*-th t-shirt, *a**i* is front color of the *i*-th t-shirt and *b**i* is back color of the *i*-th t-shirt. All values *p**i* are distinct, and values *a**i* and... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of t-shirts.
The following line contains sequence of integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1<=000<=000<=000), where *p**i* equals to the price of the *i*-th t-shirt.
The following line contains sequence of integers *a*1,<... | Print to the first line *m* integers — the *j*-th integer should be equal to the price of the t-shirt which the *j*-th buyer will buy. If the *j*-th buyer won't buy anything, print -1. | [
"5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1\n",
"2\n1000000000 1\n1 1\n1 2\n2\n2 1\n"
] | [
"200 400 300 500 911 -1 \n",
"1 1000000000 \n"
] | none | 1,000 | [
{
"input": "5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1",
"output": "200 400 300 500 911 -1 "
},
{
"input": "2\n1000000000 1\n1 1\n1 2\n2\n2 1",
"output": "1 1000000000 "
},
{
"input": "10\n251034796 163562337 995167403 531046374 341924810 828969071 971837553 183763940 8... | 1,697,357,567 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 3,000 | 23,756,800 | import sys
input = sys.stdin.readline
# flush = sys.stdout.flush()
# from math import gcd, isqrt, ceil, log2
# from collections import defaultdict, deque, Counter
# import bisect #-->For bisect.bisect_left=lower_bound and bisect_right=upper_bound
t = 1
# t = int(input())
for _ in range(t):
n = int(input())
p ... | Title: T-shirt buying
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new pack of *n* t-shirts came to a shop. Each of the t-shirts is characterized by three integers *p**i*, *a**i* and *b**i*, where *p**i* is the price of the *i*-th t-shirt, *a**i* is front color of the *i*-th t-shirt a... | ```python
import sys
input = sys.stdin.readline
# flush = sys.stdout.flush()
# from math import gcd, isqrt, ceil, log2
# from collections import defaultdict, deque, Counter
# import bisect #-->For bisect.bisect_left=lower_bound and bisect_right=upper_bound
t = 1
# t = int(input())
for _ in range(t):
n = int(input... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | An atom of element X can exist in *n* distinct states with energies *E*1<=<<=*E*2<=<<=...<=<<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states *i*, *j* and *k* are selected, where *i*<=<<=*j*<=<<=*k*... | The first line contains two integers *n* and *U* (3<=≤<=*n*<=≤<=105, 1<=≤<=*U*<=≤<=109) — the number of states and the maximum possible difference between *E**k* and *E**i*.
The second line contains a sequence of integers *E*1,<=*E*2,<=...,<=*E**n* (1<=≤<=*E*1<=<<=*E*2...<=<<=*E**n*<=≤<=109). It is guaranteed th... | If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10<=-<=9.
Formally, let your answer be *a*, and the jury's answe... | [
"4 4\n1 3 5 7\n",
"10 8\n10 13 15 16 17 19 20 22 24 25\n",
"3 1\n2 5 10\n"
] | [
"0.5\n",
"0.875\n",
"-1\n"
] | In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/147ae7a830722917b0aa37d064df8eb74cfefb97.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second example choose states 4, 5 a... | 0 | [
{
"input": "4 4\n1 3 5 7",
"output": "0.5"
},
{
"input": "10 8\n10 13 15 16 17 19 20 22 24 25",
"output": "0.875"
},
{
"input": "3 1\n2 5 10",
"output": "-1"
},
{
"input": "5 3\n4 6 8 9 10",
"output": "0.5"
},
{
"input": "10 128\n110 121 140 158 174 188 251 271 27... | 1,521,909,454 | 3,754 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 78 | 7,065,600 | n, u = map(int, input().split())
x = list(map(int, input().split()))
minimum, index = (10 ** 9) + 1, -1
ind1 = False
vozm = []
for i in range(1, n):
if i != n - 1 and (x[i] - x[i - 1] < minimum) and (x[i + 1] - x[i - 1] <= u):
minimum = x[i] - x[i - 1]
vozm = [i]
if i != n - 1 and (x[i] - x[i - 1] == minimum) and... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An atom of element X can exist in *n* distinct states with energies *E*1<=<<=*E*2<=<<=...<=<<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the sche... | ```python
n, u = map(int, input().split())
x = list(map(int, input().split()))
minimum, index = (10 ** 9) + 1, -1
ind1 = False
vozm = []
for i in range(1, n):
if i != n - 1 and (x[i] - x[i - 1] < minimum) and (x[i + 1] - x[i - 1] <= u):
minimum = x[i] - x[i - 1]
vozm = [i]
if i != n - 1 and (x[i] - x[i - 1] == mi... | 0 | |
858 | B | Which floor? | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=100), where *n* is the number of the flat you need to restore floor for, and *m* is the number of flats in Polycarp's memory.
*m* lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers *k**i*,<=*... | Print the number of the floor in which the *n*-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. | [
"10 3\n6 2\n2 1\n7 3\n",
"8 4\n3 1\n6 2\n5 2\n2 1\n"
] | [
"4\n",
"-1\n"
] | In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-... | 750 | [
{
"input": "10 3\n6 2\n2 1\n7 3",
"output": "4"
},
{
"input": "8 4\n3 1\n6 2\n5 2\n2 1",
"output": "-1"
},
{
"input": "8 3\n7 2\n6 2\n1 1",
"output": "2"
},
{
"input": "4 2\n8 3\n3 1",
"output": "2"
},
{
"input": "11 4\n16 4\n11 3\n10 3\n15 4",
"output": "3"
... | 1,505,660,631 | 7,131 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 4,608,000 | n,m = (int(i) for i in input().split())
home = {}
fPer = 0
res = -1
for i in range(m):
k,f = (int(i) for i in input().split())
home[f] = sorted(home.get(f,[])+[k])
stages = sorted(list(home.keys()))
for i in range(1,len(stages)):
if stages[i]-stages[i-1] == 1:
if home[stages[i]][0] - h... | Title: Which floor?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to u... | ```python
n,m = (int(i) for i in input().split())
home = {}
fPer = 0
res = -1
for i in range(m):
k,f = (int(i) for i in input().split())
home[f] = sorted(home.get(f,[])+[k])
stages = sorted(list(home.keys()))
for i in range(1,len(stages)):
if stages[i]-stages[i-1] == 1:
if home[stages[... | 0 | |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas... | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output":... | 1,608,400,722 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 78 | 0 | arr = [int(x) for x in input().split()]
a = arr[0]
b = arr[1]
total = a/b
if total%2==0:
print("NO")
else:
print("YES")
| Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with ... | ```python
arr = [int(x) for x in input().split()]
a = arr[0]
b = arr[1]
total = a/b
if total%2==0:
print("NO")
else:
print("YES")
``` | 0 | |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 53... | 1,567,069,669 | 169 | Python 3 | OK | TESTS | 37 | 218 | 0 | n = int(input())
a = list(map(int, input().split()))
for q in a:
if a.count(q) > (n+1)//2:
print("NO")
break
else:
print("YES")
| Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would... | ```python
n = int(input())
a = list(map(int, input().split()))
for q in a:
if a.count(q) > (n+1)//2:
print("NO")
break
else:
print("YES")
``` | 3 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,694,973,007 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | k, n, w = map(int, input().split())
c = 0
for i in range (1, w+1):
c = c + i*k
if n > c:
print(0)
else:
print(c-n) | 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
k, n, w = map(int, input().split())
c = 0
for i in range (1, w+1):
c = c + i*k
if n > c:
print(0)
else:
print(c-n)
``` | 3 | |
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th... | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 ... | 1,564,540,124 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | n, a, b = map(int, input().split())
if b > 0:
pos = (a + b) % n
if pos == 0:
pos = n
elif b == 0:
pos = b
else:
remain = abs(b) % n
b = n - remain
pos = (a + b) % n
if pos == 0:
pos = n
print(pos)
| Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e... | ```python
n, a, b = map(int, input().split())
if b > 0:
pos = (a + b) % n
if pos == 0:
pos = n
elif b == 0:
pos = b
else:
remain = abs(b) % n
b = n - remain
pos = (a + b) % n
if pos == 0:
pos = n
print(pos)
``` | 0 | |
558 | A | Lala Land and Apple Trees | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"sortings"
] | null | null | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from t... | The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guarant... | Output the maximum number of apples Amr can collect. | [
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] | [
"10",
"9",
"9"
] | In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, ... | 500 | [
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "3... | 1,583,938,450 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 108 | 307,200 | n = int(input())
l =[]
for i in range(n):
l.append(list(map(int,input().split())))
#print(l)
l = list(sorted(l))
#print(l)
pos = []
neg = []
for i in range(n):
if l[i][0] < 0 :
neg.append(l[i][1])
else:
pos.append(l[i][1])
#print(neg)
#print(pos)
#neg = list(reverse... | Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree num... | ```python
n = int(input())
l =[]
for i in range(n):
l.append(list(map(int,input().split())))
#print(l)
l = list(sorted(l))
#print(l)
pos = []
neg = []
for i in range(n):
if l[i][0] < 0 :
neg.append(l[i][1])
else:
pos.append(l[i][1])
#print(neg)
#print(pos)
#neg = li... | 0 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,655,024,374 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | c = 0
b = 0
ba = 0
nope = input()
user = [int(i) for i in input().split(" ")]
for num in range(len(user)) :
if num % 3 == 0 :
c = c + user[num]
elif num % 3 == 1 :
b = b + user[num]
else :
ba = ba + user[num]
if c > b and c > ba :
print("chest")
elif b > c and b > ba :
prin... | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
c = 0
b = 0
ba = 0
nope = input()
user = [int(i) for i in input().split(" ")]
for num in range(len(user)) :
if num % 3 == 0 :
c = c + user[num]
elif num % 3 == 1 :
b = b + user[num]
else :
ba = ba + user[num]
if c > b and c > ba :
print("chest")
elif b > c and b > ba ... | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,560,131,321 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 218 | 0 | n1, n2 = map(int, input().split())
m = max(n1, n2)
chislitel = 7-m
znam = 6
if chislitel%2 == 0:
chislitel = chislitel//2
znam = znam//2
if chislitel%3 == 0:
chislitel = chislitel//3
znam = znam//3
print(chislitel, znam, sep='/')
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
n1, n2 = map(int, input().split())
m = max(n1, n2)
chislitel = 7-m
znam = 6
if chislitel%2 == 0:
chislitel = chislitel//2
znam = znam//2
if chislitel%3 == 0:
chislitel = chislitel//3
znam = znam//3
print(chislitel, znam, sep='/')
``` | 3.891 |
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, wh... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc... | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 2... | 1,589,248,764 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 124 | 0 | #Tony thought about the code again, using inspiration from CodeForces
import time
marks =[]
n,k = map(int,input().split())
marks = input().split()
marks = list(map(int,marks))
extra = 0
while sum(marks)+extra*k-(extra+len(marks))*(k-0.5)<0:
extra+=1
print(extra)
| Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
... | ```python
#Tony thought about the code again, using inspiration from CodeForces
import time
marks =[]
n,k = map(int,input().split())
marks = input().split()
marks = list(map(int,marks))
extra = 0
while sum(marks)+extra*k-(extra+len(marks))*(k-0.5)<0:
extra+=1
print(extra)
``` | 3 | |
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ... | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1... | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | 500 | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43... | 1,653,802,059 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n,m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
max_a = max(a)
if(m == 1):
print(-1)
else:
sort_b = sorted(b)
if(sort_b[-2] - max_a == 0):
print(-1)
else:
print(sort_b[-2] - max_a) | Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Val... | ```python
n,m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
max_a = max(a)
if(m == 1):
print(-1)
else:
sort_b = sorted(b)
if(sort_b[-2] - max_a == 0):
print(-1)
else:
print(sort_b[-2] - max_a)
``` | 0 | |
755 | A | PolandBall and Hypothesis | PROGRAMMING | 800 | [
"brute force",
"graphs",
"math",
"number theory"
] | null | null | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is inc... | The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis. | Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists. | [
"3\n",
"4\n"
] | [
"1",
"2"
] | A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "153",
"output": "1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "4"
... | 1,683,795,678 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 62 | 0 | """
LINK: https://codeforces.com/problemset/problem/755/A
Since (n * m + 1) (say x) as not very large, we find primes till x and then find m with brute-force such that x is not a prime
COMPLEXITY:
TC - O(nloglogn + m) for sieve + finding m
SC - O(n*1000) for 'is_prime'
"""
def get_num1(n):
max_val... | Title: PolandBall and Hypothesis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is... | ```python
"""
LINK: https://codeforces.com/problemset/problem/755/A
Since (n * m + 1) (say x) as not very large, we find primes till x and then find m with brute-force such that x is not a prime
COMPLEXITY:
TC - O(nloglogn + m) for sieve + finding m
SC - O(n*1000) for 'is_prime'
"""
def get_num1(n):
... | 3 | |
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.... | The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. | Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". | [
")((())))(()())\n",
"))(\n"
] | [
"6 2\n",
"0 1\n"
] | none | 0 | [
{
"input": ")((())))(()())",
"output": "6 2"
},
{
"input": "))(",
"output": "0 1"
},
{
"input": "()(())()",
"output": "8 1"
},
{
"input": "((((()(((",
"output": "2 1"
},
{
"input": "))))()())))",
"output": "4 1"
},
{
"input": "(()())()(())()()())())()(... | 1,676,995,092 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 746 | 82,227,200 | s = input()
res1, res2 = 0, 1
from collections import defaultdict
hm = defaultdict(lambda:-2)
hm[0] = -1
cur = 0
for i in range(len(s)):
if s[i] == ')':
cur -= 1
else:
cur += 1
if hm[cur + 1] != -2:
hm[cur + 1] = -2
if hm[cur] != -2:
tmp = i - hm[cur]
... | Title: Longest Regular Bracket Sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical exp... | ```python
s = input()
res1, res2 = 0, 1
from collections import defaultdict
hm = defaultdict(lambda:-2)
hm[0] = -1
cur = 0
for i in range(len(s)):
if s[i] == ')':
cur -= 1
else:
cur += 1
if hm[cur + 1] != -2:
hm[cur + 1] = -2
if hm[cur] != -2:
tmp = i - hm[... | 3.66034 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,689,191,694 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | i = list(map(int, input().split(' ')))
n, m, a = i[0], i[1], i[2]
print(n * m / pow(a,2)) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
i = list(map(int, input().split(' ')))
n, m, a = i[0], i[1], i[2]
print(n * m / pow(a,2))
``` | 0 |
544 | B | Sea and Islands | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to... | The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form. | If the answer doesn't exist, print "NO" (without the quotes) in a single line.
Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is t... | [
"5 2\n",
"5 25\n"
] | [
"YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n",
"NO\n"
] | none | 1,000 | [
{
"input": "5 2",
"output": "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS"
},
{
"input": "5 25",
"output": "NO"
},
{
"input": "82 6047",
"output": "NO"
},
{
"input": "6 5",
"output": "YES\nLSLSLS\nSLSLSS\nSSSSSS\nSSSSSS\nSSSSSS\nSSSSSS"
},
{
"input": "10 80",
"outpu... | 1,431,819,383 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | __author__ = 'emcenrue'
from math import pow
n, k = list(map(int, input().split()))
if k < pow(n, 2)/2:
print("YES")
for i in range(n):
for j in range(n):
if i%2 == 0 and j%2 == 0:
print("S", end='')
elif i%2 == 0 and j%2 == 1:
print("L... | Title: Sea and Islands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on... | ```python
__author__ = 'emcenrue'
from math import pow
n, k = list(map(int, input().split()))
if k < pow(n, 2)/2:
print("YES")
for i in range(n):
for j in range(n):
if i%2 == 0 and j%2 == 0:
print("S", end='')
elif i%2 == 0 and j%2 == 1:
... | 0 | |
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 | |
372 | A | Counting Kangaroos is Fun | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who i... | The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). | Output a single integer — the optimal number of visible kangaroos. | [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] | [
"5\n",
"5\n"
] | none | 500 | [
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
... | 1,500,895,949 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 124 | 23,142,400 | n = int(input())
s = []
for i in range(n):
s.append(int(input()))
s = sorted(s)
x = len(s) - 1
z = x - 1
while(z != 0):
if(s[x]/2 > s[z]):
x -= 1
z -= 1
print(x) | Title: Counting Kangaroos is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as ... | ```python
n = int(input())
s = []
for i in range(n):
s.append(int(input()))
s = sorted(s)
x = len(s) - 1
z = x - 1
while(z != 0):
if(s[x]/2 > s[z]):
x -= 1
z -= 1
print(x)
``` | 0 | |
570 | A | Elections | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in ... | The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively.
Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes ... | Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. | [
"3 3\n1 2 3\n2 3 1\n1 2 1\n",
"3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n"
] | [
"2",
"1"
] | Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm... | 500 | [
{
"input": "3 3\n1 2 3\n2 3 1\n1 2 1",
"output": "2"
},
{
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7",
"output": "1"
},
{
"input": "1 3\n5\n3\n2",
"output": "1"
},
{
"input": "3 1\n1 2 3",
"output": "3"
},
{
"input": "3 1\n100 100 100",
"output": "1"
},
{... | 1,512,963,036 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 62 | 5,632,000 | n,m = map(int,input().split())
count = [0]*n
for i in range(m):
vote = list(map(int,input().split()))
count[vote.index(max(vote))] += 1
print(count.index(max(count))+1) | Title: Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusu... | ```python
n,m = map(int,input().split())
count = [0]*n
for i in range(m):
vote = list(map(int,input().split()))
count[vote.index(max(vote))] += 1
print(count.index(max(count))+1)
``` | 3 | |
825 | B | Five-In-a-Row | PROGRAMMING | 1,600 | [
"brute force",
"implementation"
] | null | null | Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins i... | You are given matrix 10<=×<=10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.
It is guaranteed th... | Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. | [
"XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "O.......O.\n.....O.X..\n......O...\n....X.O...\n.O.O.....X\n.XO.....XX\n...X...X.O\n........O.\n........O.\n.X.X.....X",
"output": "NO"
},
{
"input": "....OX....\n..........\n.O..X...X.\nXXO..XO..O\nO.......X.\n...XX.....\n..O.O...OX\n.........X\n.....X..OO\n........O.",
"output": "N... | 1,516,691,216 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 62 | 5,632,000 | t = []
for i in range(10):
t.append(input())
for i in range(10):
s = ''
for j in range(10):
s = s + t[i][j]
t.append(s)
for i in range(6):
s = ''
for j in range(10 - i):
s = s + t[i + j][j]
t.append(s)
for i in range(1, 6):
s = ''
for j in range(10 - i)... | Title: Five-In-a-Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some t... | ```python
t = []
for i in range(10):
t.append(input())
for i in range(10):
s = ''
for j in range(10):
s = s + t[i][j]
t.append(s)
for i in range(6):
s = ''
for j in range(10 - i):
s = s + t[i + j][j]
t.append(s)
for i in range(1, 6):
s = ''
for j in ran... | 0 | |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,687,794,025 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 85 | 124 | 0 | a=input()
l=['H','Q','9']
s=0
for i in a:
if i in l:
print("YES")
s+=1
break
if(s==0):
print("NO") | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
a=input()
l=['H','Q','9']
s=0
for i in a:
if i in l:
print("YES")
s+=1
break
if(s==0):
print("NO")
``` | 3 | |
678 | C | Joty and Chocolate | PROGRAMMING | 1,600 | [
"implementation",
"math",
"number theory"
] | null | null | Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisibl... | The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109). | Print the only integer *s* — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"5 2 3 12 15\n",
"20 2 3 3 5\n"
] | [
"39\n",
"51\n"
] | none | 0 | [
{
"input": "5 2 3 12 15",
"output": "39"
},
{
"input": "20 2 3 3 5",
"output": "51"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 2 2",
"output": "0"
},
{
"input": "2 1 3 3 3",
"output": "6"
},
{
"input": "3 1 1 3 3",
"output": "9"
... | 1,477,589,175 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | liste = input().split(" ")
n = int(liste[0])
a = int(liste[1])
b = int(liste[2])
p = int(liste[3])
q = int(liste[4])
m = max(p,q)
res = 0
for i in range (1,n+1) :
auxa = False
auxb = False
if i % a == 0 :
auxa = True
if i % b == 0 :
auxb = True
if auxa and auxb :... | Title: Joty and Chocolate
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpai... | ```python
liste = input().split(" ")
n = int(liste[0])
a = int(liste[1])
b = int(liste[2])
p = int(liste[3])
q = int(liste[4])
m = max(p,q)
res = 0
for i in range (1,n+1) :
auxa = False
auxb = False
if i % a == 0 :
auxa = True
if i % b == 0 :
auxb = True
if auxa ... | 0 | |
598 | A | Tricky Sum | PROGRAMMING | 900 | [
"math"
] | null | null | In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for *t* values of *n*. | The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed.
Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). | Print the requested sum for each of *t* integers *n* given in the input. | [
"2\n4\n1000000000\n"
] | [
"-4\n499999998352516354\n"
] | The answer for the first sample is explained in the statement. | 0 | [
{
"input": "2\n4\n1000000000",
"output": "-4\n499999998352516354"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25"
},
{
"input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53",
"output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130... | 1,671,632,528 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 92 | 1,536,000 | from math import log2 as log
for _ in range(int(input())):
n = int(input())
s = ((1 + n) * n) // 2
count_of2 = int(log(n))
# print(s)
for i in range(0, count_of2 + 1):
# print(s)
s -= 2 * (2 ** i)
print(s) | Title: Tricky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be... | ```python
from math import log2 as log
for _ in range(int(input())):
n = int(input())
s = ((1 + n) * n) // 2
count_of2 = int(log(n))
# print(s)
for i in range(0, count_of2 + 1):
# print(s)
s -= 2 * (2 ** i)
print(s)
``` | 3 | |
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e... | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
... | 1,624,522,945 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 62 | 0 |
a , b = map(int,input().split())
i = 1
while 1:
if(i&1):
if(a >= i):
a -= i
else :
print("Vladik")
break
else :
if( b >= i):
b -= i
else :
print("Valera")
break
i +=1 | Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla... | ```python
a , b = map(int,input().split())
i = 1
while 1:
if(i&1):
if(a >= i):
a -= i
else :
print("Vladik")
break
else :
if( b >= i):
b -= i
else :
print("Valera")
break
i +=1
``` | 3 | |
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ... | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented... | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditio... | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 5... | 1,595,431,241 | 2,147,483,647 | PyPy 3 | OK | TESTS | 24 | 310 | 20,172,800 | a=[]
for i in range(3):
a.append(list(map(int,input().split())))
r1=sum(a[0])
r2=sum(a[1])
r3=sum(a[2])
a[0][0]=(r3+r2-r1)//2
a[1][1]=a[0][0]+(r1-r2)
a[2][2]=a[0][0]+(r1-r3)
for i in range(3):
print(*a[i])
| Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table ... | ```python
a=[]
for i in range(3):
a.append(list(map(int,input().split())))
r1=sum(a[0])
r2=sum(a[1])
r3=sum(a[2])
a[0][0]=(r3+r2-r1)//2
a[1][1]=a[0][0]+(r1-r2)
a[2][2]=a[0][0]+(r1-r3)
for i in range(3):
print(*a[i])
``` | 3 | |
828 | B | Black Square | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum pos... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the sheet.
The next *n* lines contain *m* letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | [
"5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n",
"1 2\nBB\n",
"3 3\nWWW\nWWW\nWWW\n"
] | [
"5\n",
"-1\n",
"1\n"
] | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | 750 | [
{
"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW",
"output": "5"
},
{
"input": "1 2\nBB",
"output": "-1"
},
{
"input": "3 3\nWWW\nWWW\nWWW",
"output": "1"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n... | 1,499,796,650 | 5,150 | Python 3 | OK | TESTS | 128 | 77 | 5,632,000 | n,m = map(int,input().split())
data = [ input() for _ in range(n)]
rmax=cmax=-1
rmin=1000
cmin=1000
for i in range(n):
for j in range(m):
if data[i][j]=='B':
cmin=min(cmin,i)
cmax=max(cmax,i)
rmin=min(rmin,j)
rmax=max(rmax,j)
row = rm... | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of w... | ```python
n,m = map(int,input().split())
data = [ input() for _ in range(n)]
rmax=cmax=-1
rmin=1000
cmin=1000
for i in range(n):
for j in range(m):
if data[i][j]=='B':
cmin=min(cmin,i)
cmax=max(cmax,i)
rmin=min(rmin,j)
rmax=max(rmax,j)
... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,672,315,826 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | n = int(input ())
a= [0,0,0]
for i in range(n):
b = [int(j) for j in input().split() ]
a += b
if a == [0,0,0] :
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input ())
a= [0,0,0]
for i in range(n):
b = [int(j) for j in input().split() ]
a += b
if a == [0,0,0] :
print("YES")
else:
print("NO")
``` | 0 |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,530,809,830 | 1,330 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 93 | 0 | def go():
n = int(input())
a = [int(i) for i in input().split(' ')]
if n < 2:
return -1
if n == 2 and a[0] == a[1]:
return -1
s = sum(a)
for i in range(len(a)):
if s - a[i] != a[i]:
return '{}\n{}'.format(1, i + 1)
return -1
print(go())
| Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
def go():
n = int(input())
a = [int(i) for i in input().split(' ')]
if n < 2:
return -1
if n == 2 and a[0] == a[1]:
return -1
s = sum(a)
for i in range(len(a)):
if s - a[i] != a[i]:
return '{}\n{}'.format(1, i + 1)
return -1
print(go())
``` | -1 | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,695,993,717 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 102,400 |
d=0
a=0
v=int(input())
x=input()
for i in x:
if i=="D":
d=d+1
else:
a=a+1
if d==a:
print("Friendship")
elif a>d:
print("Anton")
else:
print("Danik") | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
d=0
a=0
v=int(input())
x=input()
for i in x:
if i=="D":
d=d+1
else:
a=a+1
if d==a:
print("Friendship")
elif a>d:
print("Anton")
else:
print("Danik")
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limeligh... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively. | Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps. | [
"5 2\n",
"1 10\n"
] | [
"10\n",
"0\n"
] | In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.
In the second sample, there is only one cow, so the maximum possible mess... | 0 | [
{
"input": "5 2",
"output": "10"
},
{
"input": "1 10",
"output": "0"
},
{
"input": "100000 2",
"output": "399990"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "8 3",
"output": "27"
},
{
"input": "7 1",
"output": "11"
},
{
"input": "1000... | 1,465,943,680 | 2,147,483,647 | Python 3 | OK | TESTS | 92 | 93 | 4,812,800 | n,k=[int(i)for i in input().split()]
out=0
while n>1 and k>0:
out+=2*n-3
n-=2
k-=1
print(out)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However,... | ```python
n,k=[int(i)for i in input().split()]
out=0
while n>1 and k>0:
out+=2*n-3
n-=2
k-=1
print(out)
``` | 3 | |
614 | B | Gena's Code | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en... | The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country.
It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total leng... | Print a single number without leading zeroes — the product of the number of tanks presented by each country. | [
"3\n5 10 1\n",
"4\n1 1 10 11\n",
"5\n0 3 1 100 1\n"
] | [
"50",
"110",
"0"
] | In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful. | 1,000 | [
{
"input": "3\n5 10 1",
"output": "50"
},
{
"input": "4\n1 1 10 11",
"output": "110"
},
{
"input": "5\n0 3 1 100 1",
"output": "0"
},
{
"input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 ... | 1,653,742,545 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 500 | 9,113,600 | n=int(input())
a=list(map(int,input().rstrip().split()))
p=1
for i in a: p*=i
print(p) | Title: Gena's Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from eac... | ```python
n=int(input())
a=list(map(int,input().rstrip().split()))
p=1
for i in a: p*=i
print(p)
``` | 0 | |
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,529,323,338 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 77 | 0 | """
Codeforces
2B - The least round way
http://codeforces.com/problemset/problem/2/B
Héctor González Belver
18/06/2018
"""
import sys
cost = []
tc = []
def factor_2_5(n):
num = int(n)
num_factor_2 = 0
num_factor_5 = 0
if num == 0:
return 999999999
while num%2==0:
num = num//2
num_factor_2 += 1
... | 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
"""
Codeforces
2B - The least round way
http://codeforces.com/problemset/problem/2/B
Héctor González Belver
18/06/2018
"""
import sys
cost = []
tc = []
def factor_2_5(n):
num = int(n)
num_factor_2 = 0
num_factor_5 = 0
if num == 0:
return 999999999
while num%2==0:
num = num//2
num_fact... | 0 |
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,594,152,893 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 139 | 20,172,800 | #Radio Station
n,m = map(int,input().split())
d1,d2 = {},{}
for i in range(n):
name,ip = map(str,input().split())
d1[ip] = name
for i in range(m):
command,ip = map(str,input().split())
d2[command] = ip
for i,j in d2.items():
j1 = j[:-1]
print(i+' '+j+' #'+d1[j1])
'''print(i,'a')
... | 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
#Radio Station
n,m = map(int,input().split())
d1,d2 = {},{}
for i in range(n):
name,ip = map(str,input().split())
d1[ip] = name
for i in range(m):
command,ip = map(str,input().split())
d2[command] = ip
for i,j in d2.items():
j1 = j[:-1]
print(i+' '+j+' #'+d1[j1])
'''pri... | 0 | |
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,604,347,922 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 218 | 0 | n, x = map(int, input().split())
_min = 0
_max = 10**4
for i in range(n):
a, b = map(int, input().split())
_min = max(_min, min(a, b))
_max = min(_max, max(a, b))
print(min(abs(x-_min), abs(x-_max))) | 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
n, x = map(int, input().split())
_min = 0
_max = 10**4
for i in range(n):
a, b = map(int, input().split())
_min = max(_min, min(a, b))
_max = min(_max, max(a, b))
print(min(abs(x-_min), abs(x-_max)))
``` | 0 |
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,483,038,480 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 4,608,000 | n = int(input())
aux = n
sol = []
c = 1
while aux >= 0:
sol.append(c)
aux = aux - c
c = c+1
sol.pop(0)
print(len(sol))
print(*sol)
| 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())
aux = n
sol = []
c = 1
while aux >= 0:
sol.append(c)
aux = aux - c
c = c+1
sol.pop(0)
print(len(sol))
print(*sol)
``` | 0 | |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,563,106,906 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 0 | def count1(self,s):
m=[]
for i in range(0,len(self)) :
if len(self[i:i+len(s)])==len(s) and self[i:i+len(s)]==s:
m.append(self[i:i+len(s)])
return m.count(s)
s=input()
s1={}
slist=[count1(s,'nineteen')]
slist1=[]
for i in 'niet':
s1[i]=count1(s,i)
if s1['n']<3 or s1['e']<... | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
def count1(self,s):
m=[]
for i in range(0,len(self)) :
if len(self[i:i+len(s)])==len(s) and self[i:i+len(s)]==s:
m.append(self[i:i+len(s)])
return m.count(s)
s=input()
s1={}
slist=[count1(s,'nineteen')]
slist1=[]
for i in 'niet':
s1[i]=count1(s,i)
if s1['n']<3 o... | 0 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,603,915,069 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | d1, d2, d3 = map(int, input().split())
P1 = d1 + d2 + d3
P2 = d1 * 2 + d2 * 2
print(min(P1, P2)) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1, d2, d3 = map(int, input().split())
P1 = d1 + d2 + d3
P2 = d1 * 2 + d2 * 2
print(min(P1, P2))
``` | 0 | |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,684,639,891 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 307,200 | n = int(input())
x = input().split()
lst_1,lst_2,lst_3 = [],[],[]
if len(set(x)) != 3:
print('0')
else:
for idx in range(n):
if x[idx] == "1":
lst_1.append(idx+1)
for idx in range(n):
if x[idx] == "2":
lst_2.append(idx+1)
for idx in range(n):
... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
n = int(input())
x = input().split()
lst_1,lst_2,lst_3 = [],[],[]
if len(set(x)) != 3:
print('0')
else:
for idx in range(n):
if x[idx] == "1":
lst_1.append(idx+1)
for idx in range(n):
if x[idx] == "2":
lst_2.append(idx+1)
for idx in range(n... | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,683,748,621 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 |
n = int (input(''))
for i in range (0,n) :
my_string = str(input(''))
length = len(my_string)
if (length > 10) :
print(my_string[0], end='')
print(length-2 , end='' )
print(my_string[-1])
else:
print(my_string) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n = int (input(''))
for i in range (0,n) :
my_string = str(input(''))
length = len(my_string)
if (length > 10) :
print(my_string[0], end='')
print(length-2 , end='' )
print(my_string[-1])
else:
print(my_string)
``` | 3.977 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,564,080,514 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 624 | 7,270,400 | from fractions import gcd
n,m=map(int,input().split())
num=6-max(n,m)+1
den=6
g=gcd(num,den)
print(str(num//g)+'/'+str(den//g))
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
from fractions import gcd
n,m=map(int,input().split())
num=6-max(n,m)+1
den=6
g=gcd(num,den)
print(str(num//g)+'/'+str(den//g))
``` | 3.633831 |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,597,429,337 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 108 | 307,200 | a = int(input())
b = int(input())
d = max(a-b,b-a)
if d%2 == 0:
y = int(d/2)
else:
y = int(d/2)+1
f1 = 0
for i in range(1,int(d/2)+1):
f1 += i
f2 = 0
for i in range(1,y+1):
f2 += i
if d == 1:
print(1)
else:
print(f1+f2) | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
a = int(input())
b = int(input())
d = max(a-b,b-a)
if d%2 == 0:
y = int(d/2)
else:
y = int(d/2)+1
f1 = 0
for i in range(1,int(d/2)+1):
f1 += i
f2 = 0
for i in range(1,y+1):
f2 += i
if d == 1:
print(1)
else:
print(f1+f2)
``` | 3 | |
887 | A | Div. 64 | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi... | In the only line given a non-empty binary string *s* with length up to 100. | Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. | [
"100010001\n",
"100\n"
] | [
"yes",
"no"
] | In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | 500 | [
{
"input": "100010001",
"output": "yes"
},
{
"input": "100",
"output": "no"
},
{
"input": "0000001000000",
"output": "yes"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"in... | 1,568,221,917 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | s=input()
s=list(s)
c=0
for i in s:
if(i=='0'):
c+=1
if(c>=6 && s[0]=='1'):
print("yes")
else:
print("no")
| Title: Div. 64
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some dig... | ```python
s=input()
s=list(s)
c=0
for i in s:
if(i=='0'):
c+=1
if(c>=6 && s[0]=='1'):
print("yes")
else:
print("no")
``` | -1 | |
748 | A | Santa Claus and a Place in a Class | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar... | The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla... | 500 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"... | 1,676,523,563 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 11 | 62 | 0 | n, m, k = map(int, input().split())
i = (k + m * 2 - 1) // (m * 2)
k %= m * 2
if k == 0:
print(n, m, "R")
else:
j = (k + 1) // 2
k %= 2
ar = ["R", "L"]
print(i, j, ar[k])
| Title: Santa Claus and a Place in a Class
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two work... | ```python
n, m, k = map(int, input().split())
i = (k + m * 2 - 1) // (m * 2)
k %= m * 2
if k == 0:
print(n, m, "R")
else:
j = (k + 1) // 2
k %= 2
ar = ["R", "L"]
print(i, j, ar[k])
``` | 0 | |
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on... | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"outp... | 1,646,458,725 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n, m = map(int,input().split())
if m > n:
print(n)
else:
c = n
x, y = 1, n+1
while y-x>0:
t = 0
for i in range(x, y):
if i%m==0:
ans += 1
t += 1
x = y
y = y+t+1
print(c)
| Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th... | ```python
n, m = map(int,input().split())
if m > n:
print(n)
else:
c = n
x, y = 1, n+1
while y-x>0:
t = 0
for i in range(x, y):
if i%m==0:
ans += 1
t += 1
x = y
y = y+t+1
print(c)
``` | -1 | |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,697,280,804 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | import math
Rows = 5
Columns = 4
matrix = []
for i in range(Rows):
single_row = list(map(int, input().split()))
matrix.append(single_row)
def find(element, mat ):
for i in range(len(mat)):
for j in range(len(mat[i])):
if mat[i][j] == element:
re... | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
import math
Rows = 5
Columns = 4
matrix = []
for i in range(Rows):
single_row = list(map(int, input().split()))
matrix.append(single_row)
def find(element, mat ):
for i in range(len(mat)):
for j in range(len(mat[i])):
if mat[i][j] == element:
... | 3 | |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,693,809,991 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 202 | 0 | v = {'Tetrahedron': 4,'Cube': 6,'Octahedron': 8,'Dodecahedron': 12,'Icosahedron': 20}
n = int(input())
ans = 0
for i in range(0, n):
ans += v[input()]
print(ans) | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
v = {'Tetrahedron': 4,'Cube': 6,'Octahedron': 8,'Dodecahedron': 12,'Icosahedron': 20}
n = int(input())
ans = 0
for i in range(0, n):
ans += v[input()]
print(ans)
``` | 3 | |
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order... | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som... | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
... | 1,579,869,298 | 2,147,483,647 | Python 3 | OK | TESTS | 150 | 124 | 307,200 | from math import inf
def solve():
unrated = False
for i in range(n):
if rates[i][0] != rates[i][1]: return 'rated'
if i - 1 >= 0 and rates[i-1] < rates[i]:
unrated = True
return 'unrated' if unrated else 'maybe'
def main():
global rates, n
n = int(input())
rate... | Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number ... | ```python
from math import inf
def solve():
unrated = False
for i in range(n):
if rates[i][0] != rates[i][1]: return 'rated'
if i - 1 >= 0 and rates[i-1] < rates[i]:
unrated = True
return 'unrated' if unrated else 'maybe'
def main():
global rates, n
n = int(input()... | 3 | |
592 | D | Super M | PROGRAMMING | 2,200 | [
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of *n* cities, connected by *n*<=-<=1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=123456) - the number of cities in Byteforces, and the number of cities being attacked respectively.
Then follow *n*<=-<=1 lines, describing the road system. Each line contains two city numbers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<... | First print the number of the city Super M should teleport to. If there are many possible optimal answers, print the one with the lowest city number.
Then print the minimum possible time needed to scare all humans in cities being attacked, measured in Krons.
Note that the correct answer is always unique. | [
"7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7\n",
"6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6\n"
] | [
"2\n3\n",
"2\n4\n"
] | In the first sample, there are two possibilities to finish the Super M's job in 3 krons. They are:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/93d3c0306b529e9c2324f68158ca2156587473a2.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="... | 2,000 | [
{
"input": "7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7",
"output": "2\n3"
},
{
"input": "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6",
"output": "2\n4"
},
{
"input": "2 1\n2 1\n1",
"output": "1\n0"
},
{
"input": "1 1\n1",
"output": "1\n0"
},
{
"input": "10 2\n6 9\n6 2\n1 6\... | 1,446,380,910 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 123456 + 5;
vector<int> G[maxn];
int n, m;
int cnt;
bool On[maxn];
int A[maxn];
int tar, d;
int dis[maxn];
bool vis[maxn];
bool dfs1(int s)
{
vis[s] = true;
bool flag = false;
for(int i = 0; i < G[s].size(); i++) {
int u ... | Title: Super M
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of *n* cities, connected by *n*<=-<=1 bidirectional roads. Every road connects ... | ```python
#include <bits/stdc++.h>
using namespace std;
const int maxn = 123456 + 5;
vector<int> G[maxn];
int n, m;
int cnt;
bool On[maxn];
int A[maxn];
int tar, d;
int dis[maxn];
bool vis[maxn];
bool dfs1(int s)
{
vis[s] = true;
bool flag = false;
for(int i = 0; i < G[s].size(); i++) {
... | -1 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,588,683,065 | 365 | Python 3 | OK | TESTS | 34 | 109 | 0 | from sys import stdin
#n=int(stdin.readline().strip())
n,m=map(int,stdin.readline().strip().split())
#s=list(map(int,stdin.readline().strip().split()))
x=0
for i in range(n):
a,b=stdin.readline().strip().split()
b=int(b)
if a=="+":
m+=int(b)
else:
if m>=b:
m-=b
... | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
from sys import stdin
#n=int(stdin.readline().strip())
n,m=map(int,stdin.readline().strip().split())
#s=list(map(int,stdin.readline().strip().split()))
x=0
for i in range(n):
a,b=stdin.readline().strip().split()
b=int(b)
if a=="+":
m+=int(b)
else:
if m>=b:
... | 3 | |
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,525,264,083 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 186 | 7,065,600 | x=int(input())
s=list(map(int,input().split()))
p=""
q=""
for n in range(x):
if s[n]%2==0:
p=p+str(n+1)
else:
q=q+str(n+1)
if len(p)>len(q):
print(q)
else:
print(p) | 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
x=int(input())
s=list(map(int,input().split()))
p=""
q=""
for n in range(x):
if s[n]%2==0:
p=p+str(n+1)
else:
q=q+str(n+1)
if len(p)>len(q):
print(q)
else:
print(p)
``` | 3.940339 |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,677,871,983 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 0 | def HARD_WAY():
n,m=map(int,input().split())
l=[]
while n:
c=map(int,input().split())
c=list(c)
for x in c[1:]:
if x not in l:
l.append(x)
n-=1
l=set(l)
i=1
while i<=m:
if i not in l:
return "NO"
... | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
def HARD_WAY():
n,m=map(int,input().split())
l=[]
while n:
c=map(int,input().split())
c=list(c)
for x in c[1:]:
if x not in l:
l.append(x)
n-=1
l=set(l)
i=1
while i<=m:
if i not in l:
retur... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,692,615,032 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 61 | 0 | n,m,a=input().split()
if(int(n)==int(m)==int(a)):
print(1)
elif(int(n)<int(a)<=int(m)):
number_of_flagstone=int(n)//int(a)
print(number_of_flagstone+1)
elif(int(m)<int(a)<=int(n)):
number_of_flagstone=int(m)//int(a)
print(number_of_flagstone+1)
elif((int(n)==int(m))>int(a)):
... | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a=input().split()
if(int(n)==int(m)==int(a)):
print(1)
elif(int(n)<int(a)<=int(m)):
number_of_flagstone=int(n)//int(a)
print(number_of_flagstone+1)
elif(int(m)<int(a)<=int(n)):
number_of_flagstone=int(m)//int(a)
print(number_of_flagstone+1)
elif((int(n)==int(m))>int(... | 0 |
513 | A | Game | PROGRAMMING | 800 | [
"constructive algorithms",
"math"
] | null | null | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2... | The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | Output "First" if the first player wins and "Second" otherwise. | [
"2 2 1 2\n",
"2 1 1 1\n"
] | [
"Second\n",
"First\n"
] | Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | 3 | [
{
"input": "2 2 1 2",
"output": "Second"
},
{
"input": "2 1 1 1",
"output": "First"
},
{
"input": "5 7 4 1",
"output": "Second"
},
{
"input": "5 7 1 4",
"output": "Second"
},
{
"input": "5 7 10 10",
"output": "Second"
},
{
"input": "5 7 1 10",
"out... | 1,600,632,807 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 109 | 0 | n=str(input()).split()
n1=int(n[0])
n2=int(n[1])
if n1<=n2:
print('Second')
elif n1>n2:
print('First') | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 ba... | ```python
n=str(input()).split()
n1=int(n[0])
n2=int(n[1])
if n1<=n2:
print('Second')
elif n1>n2:
print('First')
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At 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,573,633,996 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | ''' Hariom_Pandey
13.11.2019 '''
import math as mt
import sys as sy
class abc:
def mkl(self,):
li=[]
word = input()
u = [x for x in word if x.isupper()]
l = [x for x in wo... | 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
''' Hariom_Pandey
13.11.2019 '''
import math as mt
import sys as sy
class abc:
def mkl(self,):
li=[]
word = input()
u = [x for x in word if x.isupper()]
l = [x f... | 3.938 |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,683,467,698 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def simplify_fraction(numerator, denominator):
gcd_val = gcd(numerator, denominator)
return numerator // gcd_val, denominator // gcd_val
A = int(input())
sum_digits = 0
num_bases = A - 2
for base in range(2, A):
n = A
... | Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def simplify_fraction(numerator, denominator):
gcd_val = gcd(numerator, denominator)
return numerator // gcd_val, denominator // gcd_val
A = int(input())
sum_digits = 0
num_bases = A - 2
for base in range(2, A):
... | 0 |
660 | C | Hard Process | PROGRAMMING | 1,600 | [
"binary search",
"dp",
"two pointers"
] | null | null | You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*. | On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones.
On the second line print *n* integers *a**j* — the elements of the array *a* after the changes.
If there are multiple answers, you can print any one of them. | [
"7 1\n1 0 0 1 1 0 1\n",
"10 2\n1 0 0 1 0 1 0 1 0 1\n"
] | [
"4\n1 0 0 1 1 1 1\n",
"5\n1 0 0 1 1 1 1 1 0 1\n"
] | none | 0 | [
{
"input": "7 1\n1 0 0 1 1 0 1",
"output": "4\n1 0 0 1 1 1 1"
},
{
"input": "10 2\n1 0 0 1 0 1 0 1 0 1",
"output": "5\n1 0 0 1 1 1 1 1 0 1"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "7 0\n0 1 0 0 0 1 0",
"o... | 1,470,142,053 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 358 | 14,438,400 | n,k=map(int,input().split())
ara=list(map(int,input().split()))
max=0
zero=0
value=0
end=0
for i in range(0,n):
if ara[i]==0:
zero+=1
if zero<=k:
max+=1
end=i
else:
if ara[value]==0 :
zero-= 1
value+= 1
print(max)
for i in range(end-max+1,end+1):
ara[i... | Title: Hard Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can ch... | ```python
n,k=map(int,input().split())
ara=list(map(int,input().split()))
max=0
zero=0
value=0
end=0
for i in range(0,n):
if ara[i]==0:
zero+=1
if zero<=k:
max+=1
end=i
else:
if ara[value]==0 :
zero-= 1
value+= 1
print(max)
for i in range(end-max+1,end+1):... | 3 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,662,458,612 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 154 | 0 | n=int(input())
a=list(map(int,input().split()))
k=sum(a)%2
c=0
for i in range(n):
if a[i]%2==k:
c+=1
print(c)
| Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n=int(input())
a=list(map(int,input().split()))
k=sum(a)%2
c=0
for i in range(n):
if a[i]%2==k:
c+=1
print(c)
``` | 3 | |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,687,622,458 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 216 | 19,865,600 | n1 = int(input())
n2 = int(input())
n3 = int(input())
n4 = int(input())
n_dragons = int(input())
print(len(set(range(1, n_dragons + 1, n1)) | set(range(1, n_dragons + 1, n2)) | set(range(1, n_dragons + 1, n3)) | set(range(1, n_dragons + 1, n4))))
| Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
n1 = int(input())
n2 = int(input())
n3 = int(input())
n4 = int(input())
n_dragons = int(input())
print(len(set(range(1, n_dragons + 1, n1)) | set(range(1, n_dragons + 1, n2)) | set(range(1, n_dragons + 1, n3)) | set(range(1, n_dragons + 1, n4))))
``` | 0 | |
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e... | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
... | 1,554,129,642 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 512,000 | from random import choice
s = ["Vladik","Valera"]
a = input()
print(choice(s))
| Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla... | ```python
from random import choice
s = ["Vladik","Valera"]
a = input()
print(choice(s))
``` | 0 | |
488 | A | Giga Tower | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it ... | The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). | Print the minimum *b* in a line. | [
"179\n",
"-1\n",
"18\n"
] | [
"1\n",
"9\n",
"10\n"
] | For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | 500 | [
{
"input": "179",
"output": "1"
},
{
"input": "-1",
"output": "9"
},
{
"input": "18",
"output": "10"
},
{
"input": "-410058385",
"output": "1"
},
{
"input": "-586825624",
"output": "1"
},
{
"input": "852318890",
"output": "1"
},
{
"input": ... | 1,548,384,713 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 0 | n=input()
x=1
while '8' not in str(int(n)+x):
x+=1
print(x)
| Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Ever... | ```python
n=input()
x=1
while '8' not in str(int(n)+x):
x+=1
print(x)
``` | 3 | |
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst... | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
... | 1,569,824,280 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 0 | a, b = map(int, input().split())
counter = 0
while a > 0 and b > 0:
if a > b:
b += 1
a += -2
counter += 1
else:
a += 1
b += -2
counter += 1
print(counter) | Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on... | ```python
a, b = map(int, input().split())
counter = 0
while a > 0 and b > 0:
if a > b:
b += 1
a += -2
counter += 1
else:
a += 1
b += -2
counter += 1
print(counter)
``` | 0 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,696,827,690 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 46 | 0 | a,b=map(int,input().split())
i=1
while i>0:
a=a*3
b=b*2
if a>b:
print(i)
break
i+=1 | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
a,b=map(int,input().split())
i=1
while i>0:
a=a*3
b=b*2
if a>b:
print(i)
break
i+=1
``` | 3 | |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f... | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 ... | 1,673,752,027 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | a = int(input())
q = list(reversed(sorted(map(int, input().split()))))
l = []
d = 0
for i in range(len(q)):
c = 0
for j in range(len(q)-i):
c += 1
d += q[j]
if d >= a:
l.append(c)
q.remove(q[0])
d = 0
break
print(min(l)) | Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
a = int(input())
q = list(reversed(sorted(map(int, input().split()))))
l = []
d = 0
for i in range(len(q)):
c = 0
for j in range(len(q)-i):
c += 1
d += q[j]
if d >= a:
l.append(c)
q.remove(q[0])
d = 0
break
print(min... | 0 | |
5 | A | Chat Servers Outgoing Traffic | PROGRAMMING | 1,000 | [
"implementation"
] | A. Chat Server's Outgoing Traffic | 1 | 64 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
- Include a person... | Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
- +<name> for 'Add' command. - -<name> for 'Remove' command. - <sender_name>:<message_text> for 'Send' command.
<name> and <s... | Print a single number — answer to the problem. | [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n"
] | [
"9\n",
"14\n"
] | none | 0 | [
{
"input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate",
"output": "9"
},
{
"input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate",
"output": "14"
},
{
"input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIO... | 1,405,051,606 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | import sys
participants = []
ans = 0
for s in sys.stdin:
if not s:
break
if s[0] == "+":
participants.append(s[1:])
elif s[0] == "-":
participants.remove(s[1:])
else:
ans += (len(s) - s.find(':') - 1) * len(participants)
print(ans) | Title: Chat Servers Outgoing Traffic
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in fr... | ```python
import sys
participants = []
ans = 0
for s in sys.stdin:
if not s:
break
if s[0] == "+":
participants.append(s[1:])
elif s[0] == "-":
participants.remove(s[1:])
else:
ans += (len(s) - s.find(':') - 1) * len(participants)
print(ans)
``` | 0 |
30 | A | Accounting | PROGRAMMING | 1,400 | [
"brute force",
"math"
] | A. Accounting | 2 | 256 | A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there w... | The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10). | Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them. | [
"2 18 2\n",
"-1 8 3\n",
"0 0 10\n",
"1 16 5\n"
] | [
"3",
"-2",
"5",
"No solution"
] | none | 500 | [
{
"input": "2 18 2",
"output": "3"
},
{
"input": "-1 8 3",
"output": "-2"
},
{
"input": "0 0 10",
"output": "5"
},
{
"input": "1 16 5",
"output": "No solution"
},
{
"input": "0 1 2",
"output": "No solution"
},
{
"input": "3 0 4",
"output": "0"
},... | 1,666,178,893 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 62 | 0 | A,B,n = map(int,input().split())
if A != 0:
X = (B/A)**(1/n)
if X - int(X) == 0:
print(int(X))
else:
print('No solution')
elif A == 0:
if B == 0:
print(1)
else:
print('No solution') | Title: Accounting
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as th... | ```python
A,B,n = map(int,input().split())
if A != 0:
X = (B/A)**(1/n)
if X - int(X) == 0:
print(int(X))
else:
print('No solution')
elif A == 0:
if B == 0:
print(1)
else:
print('No solution')
``` | -1 |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,642,451,107 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 0 | s=list(input())
if '0' in s:
ind = s.index('0')
print(''.join(s[:ind])+''.join(s[ind+1:]))
else:
print(''.join(s[:-2]))
| Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
s=list(input())
if '0' in s:
ind = s.index('0')
print(''.join(s[:ind])+''.join(s[ind+1:]))
else:
print(''.join(s[:-2]))
``` | 0 | |
52 | C | Circular RMQ | PROGRAMMING | 2,200 | [
"data structures"
] | C. Circular RMQ | 1 | 256 | You are given circular array *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. There are two types of operations with it:
- *inc*(*lf*,<=*rg*,<=*v*) — this operation increases each element on the segment [*lf*,<=*rg*] (inclusively) by *v*; - *rmq*(*lf*,<=*rg*) — this operation returns minimal value on the segment [*lf*,<=*rg*] (in... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200000). The next line contains initial state of the array: *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (<=-<=106<=≤<=*a**i*<=≤<=106), *a**i* are integer. The third line contains integer *m* (0<=≤<=*m*<=≤<=200000), *m* — the number of operartons. Next *m* lines contain one operat... | For each *rmq* operation write result for it. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1\n"
] | [
"1\n0\n0\n"
] | none | 1,500 | [
{
"input": "4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1",
"output": "1\n0\n0"
},
{
"input": "1\n-1\n10\n0 0 -1\n0 0\n0 0 1\n0 0\n0 0 1\n0 0\n0 0 0\n0 0\n0 0 -1\n0 0 1",
"output": "-2\n-1\n0\n0"
},
{
"input": "2\n-1 -1\n10\n0 0\n0 0\n0 0 1\n0 0\n1 1\n0 0 -1\n0 0 0\n0 0 1\n1 1 0\n0 0 -1",
"ou... | 1,603,203,188 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 1,325 | 28,569,600 | from typing import TypeVar, Generic, Callable, List
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
T = TypeVar('T')
S = TypeVar('S')
class StarrySkyTree(Generic[T, S]):
__slots__ = ['size', 'node', 'lazy', 'unit', 'lazy_unit',... | Title: Circular RMQ
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given circular array *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. There are two types of operations with it:
- *inc*(*lf*,<=*rg*,<=*v*) — this operation increases each element on the segment [*lf*,<=*rg*] (inclusively) by *v*;... | ```python
from typing import TypeVar, Generic, Callable, List
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
T = TypeVar('T')
S = TypeVar('S')
class StarrySkyTree(Generic[T, S]):
__slots__ = ['size', 'node', 'lazy', 'unit', 'l... | 0 |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,679,834,713 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | x=int(input())
if (x-6)%2==0:
print(8,x-8)
else:
print(9,x-9) | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
x=int(input())
if (x-6)%2==0:
print(8,x-8)
else:
print(9,x-9)
``` | 3 | |
166 | A | Rank List | PROGRAMMING | 1,100 | [
"binary search",
"implementation",
"sortings"
] | null | null | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.
You know the rules of comparing the results of two give... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All num... | In the only line print the sought number of teams that got the *k*-th place in the final results' table. | [
"7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n",
"5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n"
] | [
"3\n",
"4\n"
] | The final results' table for the first sample is:
- 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10
The table shows that the se... | 500 | [
{
"input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10",
"output": "3"
},
{
"input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1",
"output": "4"
},
{
"input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2",
"output": "2"
},
{
"input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5",
"output": "1"
},
{
"i... | 1,682,706,056 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 15 | 124 | 1,638,400 | nteams,rank=map(int,input().split())
freq = [0]*5052
lst = []
lst2 = []
for i in range(nteams):
ques,time=map(int,input().split())
team = str(ques)+str(time)
freq[int(team)]+=1
for i in freq:
if i!=0:
lst2.append(i)
s = 0
for q in lst2[::-1]:
s+=q
if s>=rank:
print... | Title: Rank List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for... | ```python
nteams,rank=map(int,input().split())
freq = [0]*5052
lst = []
lst2 = []
for i in range(nteams):
ques,time=map(int,input().split())
team = str(ques)+str(time)
freq[int(team)]+=1
for i in freq:
if i!=0:
lst2.append(i)
s = 0
for q in lst2[::-1]:
s+=q
if s>=rank:
... | 0 | |
934 | B | A Prosperous Lot | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | 1,000 | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output":... | 1,575,808,085 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 124 | 0 | k=int(input())
if k>36:
print (-1)
else:
out=""
n = k%2
if k%2:
out+="4"
for i in range(int(k/2)):
out += "8"
print(out)
| Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a... | ```python
k=int(input())
if k>36:
print (-1)
else:
out=""
n = k%2
if k%2:
out+="4"
for i in range(int(k/2)):
out += "8"
print(out)
``` | -1 | |
35 | C | Fire Again | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"shortest paths"
] | C. Fire Again | 2 | 64 | After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th tree in the *i*-th row would have the coordinates of (*i*,<=*j*). However a terrible thing... | The first input line contains two integers *N*,<=*M* (1<=≤<=*N*,<=*M*<=≤<=2000) — the size of the forest. The trees were planted in all points of the (*x*,<=*y*) (1<=≤<=*x*<=≤<=*N*,<=1<=≤<=*y*<=≤<=*M*) type, *x* and *y* are integers.
The second line contains an integer *K* (1<=≤<=*K*<=≤<=10) — amount of trees, burning... | Output a line with two space-separated integers *x* and *y* — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any. | [
"3 3\n1\n2 2\n",
"3 3\n1\n1 1\n",
"3 3\n2\n1 1 3 3\n"
] | [
"1 1\n",
"3 3\n",
"2 2"
] | none | 1,500 | [
{
"input": "3 3\n1\n2 2",
"output": "1 1"
},
{
"input": "3 3\n1\n1 1",
"output": "3 3"
},
{
"input": "3 3\n2\n1 1 3 3",
"output": "1 3"
},
{
"input": "1 1\n1\n1 1",
"output": "1 1"
},
{
"input": "2 2\n1\n2 2",
"output": "1 1"
},
{
"input": "2 2\n2\n1 1... | 1,668,438,512 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 28 | 1,526 | 67,072,000 | import sys
input = open('input.txt', 'r').readline
n, m = map(int, input().split())
k = int(input())
a = list(map(int, input().split()))
p = []
burned = set()
for i in range(1,2*k,2):
burned.add((a[i-1],a[i]))
p.append([a[i-1],a[i]])
while p:
q = []
for i,j in p:
if (i-1)>=1 and (... | Title: Fire Again
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th... | ```python
import sys
input = open('input.txt', 'r').readline
n, m = map(int, input().split())
k = int(input())
a = list(map(int, input().split()))
p = []
burned = set()
for i in range(1,2*k,2):
burned.add((a[i-1],a[i]))
p.append([a[i-1],a[i]])
while p:
q = []
for i,j in p:
if (i-1... | 0 |
194 | B | Square | PROGRAMMING | 1,200 | [
"math"
] | null | null | There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwa... | The first line contains integer *t* (1<=≤<=*t*<=≤<=104) — the number of test cases.
The second line contains *t* space-separated integers *n**i* (1<=≤<=*n**i*<=≤<=109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | [
"3\n4 8 100\n"
] | [
"17\n33\n401\n"
] | none | 1,000 | [
{
"input": "3\n4 8 100",
"output": "17\n33\n401"
},
{
"input": "8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13",
"output": "4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n27"
},
{
"input": "3\n13 17 21",
"output... | 1,538,547,145 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | t=int(input())
l1=[]
for _ in range(t):
n=int(input())
l1.append(n*4+1)
for i in l1:
print(i)
| Title: Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the ... | ```python
t=int(input())
l1=[]
for _ in range(t):
n=int(input())
l1.append(n*4+1)
for i in l1:
print(i)
``` | -1 | |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,550,803,733 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n = int(input())
a = list(map(int, input().split()))
temp = sorted(a, reverse = True)
for i in range (n):
for j in range (n):
if a[i] == temp[j]:
a[i] = j + 1
break
print(a) | Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
n = int(input())
a = list(map(int, input().split()))
temp = sorted(a, reverse = True)
for i in range (n):
for j in range (n):
if a[i] == temp[j]:
a[i] = j + 1
break
print(a)
``` | 0 | |
246 | B | Increase and Decrease | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | [
"2\n2 1\n",
"3\n1 4 1\n"
] | [
"1\n",
"3\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 4 1",
"output": "3"
},
{
"input": "4\n2 -7 -2 -6",
"output": "3"
},
{
"input": "4\n2 0 -2 -1",
"output": "3"
},
{
"input": "6\n-1 1 0 0 -1 -1",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"outp... | 1,694,728,979 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 6,656,000 | n=int(input())
a=list(map(int,input().split()))
j=sum(a)//n
man=0
mos=0
for i in range(0,len(a)) :
if j-a[i]<0 :
man+=abs(j-a[i])
elif j-a[i]>0 :
mos+=j-a[i]
if man==mos :
print(n)
else :
print(n-1) | Title: Increase and Decrease
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that... | ```python
n=int(input())
a=list(map(int,input().split()))
j=sum(a)//n
man=0
mos=0
for i in range(0,len(a)) :
if j-a[i]<0 :
man+=abs(j-a[i])
elif j-a[i]>0 :
mos+=j-a[i]
if man==mos :
print(n)
else :
print(n-1)
``` | 3 | |
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,681,006,472 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 810 | 7,372,800 | n,m = map(int,input().split())
a = list(map(int,input().split()))
s = set()
for i in range(n-1,-1,-1):
s.add(a[i])
a[i] = len(s)
for k in range(m):
vv = int(input())-1
print(a[vv])
| 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
n,m = map(int,input().split())
a = list(map(int,input().split()))
s = set()
for i in range(n-1,-1,-1):
s.add(a[i])
a[i] = len(s)
for k in range(m):
vv = int(input())-1
print(a[vv])
``` | 3 | |
764 | B | Timofey and cubes | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation"
] | null | null | Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Sup... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. | Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique. | [
"7\n4 3 7 6 9 1 2\n",
"8\n6 1 4 2 5 6 9 2\n"
] | [
"2 3 9 6 7 1 4",
"2 1 6 2 5 4 9 6"
] | Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing ha... | 1,000 | [
{
"input": "7\n4 3 7 6 9 1 2",
"output": "2 3 9 6 7 1 4"
},
{
"input": "8\n6 1 4 2 5 6 9 2",
"output": "2 1 6 2 5 4 9 6"
},
{
"input": "1\n1424",
"output": "1424"
},
{
"input": "9\n-7 9 -4 9 -6 11 15 2 -10",
"output": "-10 9 15 9 -6 11 -4 2 -7"
},
{
"input": "2\n2... | 1,486,421,788 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 139 | 19,148,800 | a =input()
k =input()
k =k.split(' ')
l =len(k)
i = 0
while i<l//2:
k[i],k[-(i+1)]=k[-(i+1)],k[i]
i+=2
print(' '.join(k))
| Title: Timofey and cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other p... | ```python
a =input()
k =input()
k =k.split(' ')
l =len(k)
i = 0
while i<l//2:
k[i],k[-(i+1)]=k[-(i+1)],k[i]
i+=2
print(' '.join(k))
``` | 3 | |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,598,722,535 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 3,000 | 1,228,800 | # -*- coding: utf-8 -*-
n = int(input())
l = []
for i in range(n):
s = input()
if(s in l):
l.remove(s)
l.append(s)
else:
l.append(s)
for i in reversed(l):
print(i)
| Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
# -*- coding: utf-8 -*-
n = int(input())
l = []
for i in range(n):
s = input()
if(s in l):
l.remove(s)
l.append(s)
else:
l.append(s)
for i in reversed(l):
print(i)
``` | 0 | |
484 | B | Maximum Value | PROGRAMMING | 2,100 | [
"binary search",
"math",
"sortings",
"two pointers"
] | null | null | You are given a sequence *a* consisting of *n* integers. Find the maximum possible value of (integer remainder of *a**i* divided by *a**j*), where 1<=≤<=*i*,<=*j*<=≤<=*n* and *a**i*<=≥<=*a**j*. | The first line contains integer *n* — the length of the sequence (1<=≤<=*n*<=≤<=2·105).
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=106). | Print the answer to the problem. | [
"3\n3 4 5\n"
] | [
"2\n"
] | none | 1,000 | [
{
"input": "3\n3 4 5",
"output": "2"
},
{
"input": "3\n1 2 4",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "2\n1000000 999999",
"output": "1"
},
{
"input": "12\n4 4 10 13 28 30 41 43 58 61 7... | 1,419,139,792 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 17,715,200 | from bisect import bisect_left
def main():
input()
aa = sorted(set(map(int, input().split())))
n, mx = len(aa), max(aa) * 2
x = 0
for aj in aa:
for ajj in range(aj * 2, mx, aj):
i = bisect_left(aa, ajj)
if i == n:
ai = aa[-1]
t = ai % ... | Title: Maximum Value
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. Find the maximum possible value of (integer remainder of *a**i* divided by *a**j*), where 1<=≤<=*i*,<=*j*<=≤<=*n* and *a**i*<=≥<=*a**j*.
Input Specification:
The ... | ```python
from bisect import bisect_left
def main():
input()
aa = sorted(set(map(int, input().split())))
n, mx = len(aa), max(aa) * 2
x = 0
for aj in aa:
for ajj in range(aj * 2, mx, aj):
i = bisect_left(aa, ajj)
if i == n:
ai = aa[-1]
... | 0 | |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,694,405,904 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 85 | 124 | 0 | p=input()
l=['H','Q','9']
flag=0
for i in p:
if i in l:
flag=1
break
if flag==1:
print("YES")
else:
print("NO")
| Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
p=input()
l=['H','Q','9']
flag=0
for i in p:
if i in l:
flag=1
break
if flag==1:
print("YES")
else:
print("NO")
``` | 3 | |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,530,855,804 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 140 | 0 | n, d = list(map(int,input().split()))
l = list(map(int,input().split()))
l = [-1000000000] + l
l.append(1000000000)
t = []
s = 0
for i in range(1,n+1):
if l[i]-l[i-1] >= 2*d:
x = l[i] - d
if l[i] - x <= x - l[i-1] and (not x in t):
t.append(x)
if l[i+1]... | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
n, d = list(map(int,input().split()))
l = list(map(int,input().split()))
l = [-1000000000] + l
l.append(1000000000)
t = []
s = 0
for i in range(1,n+1):
if l[i]-l[i-1] >= 2*d:
x = l[i] - d
if l[i] - x <= x - l[i-1] and (not x in t):
t.append(x)
... | 0 | |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "N... | 1,615,547,904 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 |
from math import *
def checkPowerOfn(n,k):
# find `log8(n)`
i = log(n) / log(k)
# return true if `log8(n)` is an integer
return i - floor(i) < 0.000001
k=int(input())
l=int(input())
'''
m=l/k
k=0
k2=1
k3=2
k4=3
k5=4
k6=
'''
if checkPowerOfn(l,k):
print("YES")
... | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
from math import *
def checkPowerOfn(n,k):
# find `log8(n)`
i = log(n) / log(k)
# return true if `log8(n)` is an integer
return i - floor(i) < 0.000001
k=int(input())
l=int(input())
'''
m=l/k
k=0
k2=1
k3=2
k4=3
k5=4
k6=
'''
if checkPowerOfn(l,k):
print... | 0 | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,551,452,489 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | s = input(); print('NYOE S'[s[1] != s[0] == 'S'::2]) | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
s = input(); print('NYOE S'[s[1] != s[0] == 'S'::2])
``` | -1 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,653,830,564 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n,m =map(int,input().split())
ans=(n*m)//2
print(ans)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m =map(int,input().split())
ans=(n*m)//2
print(ans)
``` | -1 |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,659,491,327 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | n,m=map(int,input().split())
l=[]
for i in range(n):
l.append(list(input()))
k=m
y=r=c=0
for j in range(len(l[0])):
x=[]
for i in range(len(l)):
x.append(l[i][j])
if len(set(x))==1:
y+=len(x)
c+=1
for i in l:
if len(set(i))==1:
y+=len(i)
r+=1
... | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
n,m=map(int,input().split())
l=[]
for i in range(n):
l.append(list(input()))
k=m
y=r=c=0
for j in range(len(l[0])):
x=[]
for i in range(len(l)):
x.append(l[i][j])
if len(set(x))==1:
y+=len(x)
c+=1
for i in l:
if len(set(i))==1:
y+=len(i)
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 0 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,514,393,388 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 5,529,600 | import itertools as t
m=int(input())
n=list(str(m))
ans=[]
lst=[]
def convert(x):
ex=0
for i in range(len(x)):
ex+=int(x[i])*10**(len(x)-i-1)
return ex
def javab(x):
y=list(str(x))
ans=[]
for i in range(1,len(y)+1):
h=t.combinations(y,i)
for k in h :
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova th... | ```python
import itertools as t
m=int(input())
n=list(str(m))
ans=[]
lst=[]
def convert(x):
ex=0
for i in range(len(x)):
ex+=int(x[i])*10**(len(x)-i-1)
return ex
def javab(x):
y=list(str(x))
ans=[]
for i in range(1,len(y)+1):
h=t.combinations(y,i)
for k i... | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.