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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
246 | A | Buggy Sorting | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. ... | You've got a single integer *n* (1<=≤<=*n*<=≤<=50) — the size of the sorted array. | Print *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1.
If there are several counter-examples, consisting of *n* numbers, yo... | [
"1\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "3 2 1 "
},
{
"input": "4",
"output": "4 3 2 1 "
},
{
"input": "5",
"output": "5 4 3 2 1 "
},
{
"input": "6",
"output": "6 5 4 3 2 1 "
},
{
"input... | 1,551,096,100 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | l=sorted(list(map(int,input().split())))[::-1]
if(len(l)<4):
print(-1)
else:
print(l) | Title: Buggy Sorting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a*... | ```python
l=sorted(list(map(int,input().split())))[::-1]
if(len(l)<4):
print(-1)
else:
print(l)
``` | 0 | |
371 | B | Fox Dividing Cheese | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it... | The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109). | If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0. | [
"15 20\n",
"14 8\n",
"6 6\n"
] | [
"3\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "15 20",
"output": "3"
},
{
"input": "14 8",
"output": "-1"
},
{
"input": "6 6",
"output": "0"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 1024",
"output": "10"
},
{
"input": "1024 729",
"output": "16"
},
{
"input": "1024... | 1,654,807,930 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | """
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off i... | Title: Fox Dividing Cheese
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox com... | ```python
"""
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "... | 3 | |
459 | A | Pashmak and Garden | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<... | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | 500 | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input... | 1,661,549,363 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 186 | 4,403,200 | from collections import deque
from math import *
import sys
import random
from bisect import *
from functools import reduce
from sys import stdin
import copy
x1,y1,x2,y2 = map(int,input().split())
if x1==x2:
val = max(y1,y2) - min(y1,y2)
x3,y3=val,y1
x4,y4=val,y2
print(x3,y3,x4,y4)
elif y1==y2:
val... | Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is... | ```python
from collections import deque
from math import *
import sys
import random
from bisect import *
from functools import reduce
from sys import stdin
import copy
x1,y1,x2,y2 = map(int,input().split())
if x1==x2:
val = max(y1,y2) - min(y1,y2)
x3,y3=val,y1
x4,y4=val,y2
print(x3,y3,x4,y4)
elif y1==y... | 0 | |
630 | I | Parking Lot | PROGRAMMING | 1,700 | [
"combinatorics",
"math"
] | null | null | To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before the office consists of one line of (2*n*<=-<=2) parking spaces. Unfortunately the total number of ... | The only line of the input contains one integer *n* (3<=≤<=*n*<=≤<=30) — the amount of successive cars of the same make. | Output one integer — the number of ways to fill the parking lot by cars of four makes using the described way. | [
"3\n"
] | [
"24"
] | Let's denote car makes in the following way: A — Aston Martin, B — Bentley, M — Mercedes-Maybach, Z — Zaporozhets. For *n* = 3 there are the following appropriate ways to fill the parking lot: AAAB AAAM AAAZ ABBB AMMM AZZZ BBBA BBBM BBBZ BAAA BMMM BZZZ MMMA MMMB MMMZ MAAA MBBB MZZZ ZZZA ZZZB ZZZM ZAAA ZBBB ZMMM
Orig... | 0 | [
{
"input": "3",
"output": "24"
},
{
"input": "4",
"output": "132"
},
{
"input": "5",
"output": "672"
},
{
"input": "6",
"output": "3264"
},
{
"input": "7",
"output": "15360"
},
{
"input": "12",
"output": "27525120"
},
{
"input": "15",
"... | 1,693,677,279 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 409,600 | import sys,itertools,functools,collections,math
def BEX(a,b):
res=1
while b>0:
if b&1:
res=res*a
a=a*a
b=b>>1
return res
def solve(n):
x=BEX(2,2*n-3)
y=BEX(2,2*n-6)
ans=3*x+(n-3)*9
print(ans)
n=int(input())
solve(n) | Title: Parking Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before t... | ```python
import sys,itertools,functools,collections,math
def BEX(a,b):
res=1
while b>0:
if b&1:
res=res*a
a=a*a
b=b>>1
return res
def solve(n):
x=BEX(2,2*n-3)
y=BEX(2,2*n-6)
ans=3*x+(n-3)*9
print(ans)
n=int(input())
solve(n)
``` | 0 | |
215 | A | Bicycle Chain | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o... | Print the number of "integer" gears with the maximum ratio among all "integer" gears. | [
"2\n4 5\n3\n12 13 15\n",
"4\n1 2 3 4\n5\n10 11 12 13 14\n"
] | [
"2\n",
"1\n"
] | In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | 500 | [
{
"input": "2\n4 5\n3\n12 13 15",
"output": "2"
},
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14",
"output": "1"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 2\n1\n1",
"output": "1"
},
{
"input": "1\n1\n2\n1 2",
"output": "1"
},
{
"input":... | 1,376,923,945 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 124 | 0 | import sys
my_file = sys.stdin
#my_file = open("input.txt", "r")
line = my_file.read().split("\n")
n = int(line[0])
a = [int(i) for i in line[1].split()]
m = int(line[2])
b = [int(i) for i in line[3].split()]
ints = []
for an in a:
for bn in b:
if bn//an == bn/an:
ints.append(bn//an)
ints.sort(r... | Title: Bicycle Chain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We ... | ```python
import sys
my_file = sys.stdin
#my_file = open("input.txt", "r")
line = my_file.read().split("\n")
n = int(line[0])
a = [int(i) for i in line[1].split()]
m = int(line[2])
b = [int(i) for i in line[3].split()]
ints = []
for an in a:
for bn in b:
if bn//an == bn/an:
ints.append(bn//an)
i... | 3 | |
348 | A | Mafia | PROGRAMMING | 1,600 | [
"binary search",
"math",
"sortings"
] | null | null | One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min... | The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play. | In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\n3 2 2\n",
"4\n2 2 2 2\n"
] | [
"4\n",
"3\n"
] | You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | 500 | [
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "7\n9 7 7 8 8 7 8",
"output": "9"
},
{
"input": "10\n13 12 10 13 13 14 10 10 12 12",
"output": "14"
},
{
"input": "10\n94 96 91 95 99 94 96 92 95 99",
"output": "106"
... | 1,620,287,799 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 6,963,200 | def func(aa):
rounds = 0
while True:
imax = 0
imin = 0
for i, v in enumerate(aa):
if v > aa[imax]:
imax = i
if v < aa[imin]:
imin = i
if aa[imax] == 0:
break
for i, v in enumerate(aa):
... | Title: Mafia
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a... | ```python
def func(aa):
rounds = 0
while True:
imax = 0
imin = 0
for i, v in enumerate(aa):
if v > aa[imax]:
imax = i
if v < aa[imin]:
imin = i
if aa[imax] == 0:
break
for i, v in enumerate(aa... | 0 | |
534 | A | Exam | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other... | A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam. | In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.
In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position... | [
"6",
"3\n"
] | [
"6\n1 5 3 6 2 4",
"2\n1 3"
] | none | 500 | [
{
"input": "6",
"output": "6\n5 3 1 6 4 2 "
},
{
"input": "3",
"output": "2\n1 3"
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "4",
"output": "4\n3 1 4 2 "
},
{
"input": "5",
"output": "5\n5 3 1 4 2 "
},
... | 1,589,724,001 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 109 | 6,963,200 | n = int(input())
if n == 1 or n == 2:
print ('1')
print ('1')
elif n == 3:
print ('2')
print ('1 3')
else:
print (n)
resp = []
for i in range(2, n+1, 2):
resp.append(str(i))
for i in range(1, n+1, 2):
resp.append(str(i))
resp = ' '.join(resp)
print (resp)
| Title: Exam
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and bec... | ```python
n = int(input())
if n == 1 or n == 2:
print ('1')
print ('1')
elif n == 3:
print ('2')
print ('1 3')
else:
print (n)
resp = []
for i in range(2, n+1, 2):
resp.append(str(i))
for i in range(1, n+1, 2):
resp.append(str(i))
resp = ' '.join(resp)
print (resp)
... | 3 | |
858 | C | Did you mean... | PROGRAMMING | 1,500 | [
"dp",
"greedy",
"implementation"
] | null | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | [
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] | [
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] | none | 1,500 | [
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx... | 1,509,003,665 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | x = input()
v = "aiueo"
y = ""
i = 0
while True:
try:
if x[i] not in v and \
x[i+1] not in v and \
x[i+2] not in v and not\
x[i] == x[i+1] == x[i+2]:
y += x[i:i+2] + " " + x[i+2]
i += 3
else:
y += x[i]
i +... | Title: Did you mean...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (... | ```python
x = input()
v = "aiueo"
y = ""
i = 0
while True:
try:
if x[i] not in v and \
x[i+1] not in v and \
x[i+2] not in v and not\
x[i] == x[i+1] == x[i+2]:
y += x[i:i+2] + " " + x[i+2]
i += 3
else:
y += x[i]
... | 0 | |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer — the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,698,324,022 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 154 | 0 | cnt = 0
n = int(input())
string = list(input())
for i in range(n):
if i != n - 1 and string[i] == string[i + 1]:
cnt += 1
print(cnt) | Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
cnt = 0
n = int(input())
string = list(input())
for i in range(n):
if i != n - 1 and string[i] == string[i + 1]:
cnt += 1
print(cnt)
``` | 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,627,924,481 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 608 | 22,220,800 | t = int(input())
q = list()
for i in range(t):
n = (input())
q.append(n)
s = set(q)
while len(s) > 0:
for j in q[::-1]:
if j in s:
print(j)
s.remove(j)
else:
break
| 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
t = int(input())
q = list()
for i in range(t):
n = (input())
q.append(n)
s = set(q)
while len(s) > 0:
for j in q[::-1]:
if j in s:
print(j)
s.remove(j)
else:
break
``` | 3 | |
897 | A | Scarborough Fair | PROGRAMMING | 800 | [
"implementation"
] | null | null | Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Althou... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ... | Output string *s* after performing *m* operations described above. | [
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] | [
"noi",
"gaaak"
] | For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak. | 500 | [
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n... | 1,678,828,142 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 46 | 2,867,200 | n, m = map(int, input().split())
s = input()
for k in range(m):
i, j, a, b = input().split()
i, j = int(i), int(j)
s = s[:i-1] + s[i-1, j].replace(a, b) + s[j:]
print(s) | Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ... | ```python
n, m = map(int, input().split())
s = input()
for k in range(m):
i, j, a, b = input().split()
i, j = int(i), int(j)
s = s[:i-1] + s[i-1, j].replace(a, b) + s[j:]
print(s)
``` | -1 | |
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,... | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"outpu... | 1,697,732,722 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 31 | 0 | n,k=map(int,input().split())
b=n
for i in range(k):
if b%10==0:
b=b//10
elif b%10>0:
b-=1
print(b)
| Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit ... | ```python
n,k=map(int,input().split())
b=n
for i in range(k):
if b%10==0:
b=b//10
elif b%10>0:
b-=1
print(b)
``` | 3 | |
560 | A | Currency System in Geraldion | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea... | The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes. | Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. | [
"5\n1 2 3 4 5\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837",
"output": "-1"
},
{
"input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264",
"o... | 1,686,177,131 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 46 | 0 | b=int(input())
a=list(input().split())
if "1" in a:
print(-1)
exit()
print(1) | Title: Currency System in Geraldion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cann... | ```python
b=int(input())
a=list(input().split())
if "1" in a:
print(-1)
exit()
print(1)
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,680,173,814 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | a1 = input()
a2 = input()
empty = ""
for i in range(len(a1)):
if a1[i] == a2[i]:
empty += "0"
else:
empty += "1"
print(int(empty)) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a1 = input()
a2 = input()
empty = ""
for i in range(len(a1)):
if a1[i] == a2[i]:
empty += "0"
else:
empty += "1"
print(int(empty))
``` | 0 |
465 | B | Inbox (100500) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. | Print a single number — the minimum number of operations needed to make all the letters read. | [
"5\n0 1 0 1 0\n",
"5\n1 1 0 0 1\n",
"2\n0 0\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already... | 1,000 | [
{
"input": "5\n0 1 0 1 0",
"output": "3"
},
{
"input": "5\n1 1 0 0 1",
"output": "4"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "9\n1 0 1 0 1 0 1 0 1",
"output": "9"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
},
{
"input": "14\n0 0 1 1 1 0 1 ... | 1,456,592,424 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 62 | 0 | n = int(input())
ps = input().split() + ['0']
qs = []
k = 0
for p in ps:
if p == '1':
k += 1
elif p == '0':
if k > 0:
qs.append(k)
k = 0
else:
print('WTF?!')
if qs:
r = sum(qs) + len(qs) - 1
else:
r = 0
print(r)
| Title: Inbox (100500)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soo... | ```python
n = int(input())
ps = input().split() + ['0']
qs = []
k = 0
for p in ps:
if p == '1':
k += 1
elif p == '0':
if k > 0:
qs.append(k)
k = 0
else:
print('WTF?!')
if qs:
r = sum(qs) + len(qs) - 1
else:
r = 0
print(r)
``` | 3 | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,697,489,806 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 5,120,000 | n=int(input())
t=input()
s=1
for i in range(n-1):
mg=input()
if mg[0] != t[1]:
t+=mg
else:
t=mg
s+=1
print(s) | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
n=int(input())
t=input()
s=1
for i in range(n-1):
mg=input()
if mg[0] != t[1]:
t+=mg
else:
t=mg
s+=1
print(s)
``` | 0 | |
353 | A | Domino | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half... | Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. | [
"2\n4 2\n6 4\n",
"1\n2 3\n",
"3\n1 4\n2 3\n4 4\n"
] | [
"0\n",
"-1\n",
"1\n"
] | In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the... | 500 | [
{
"input": "2\n4 2\n6 4",
"output": "0"
},
{
"input": "1\n2 3",
"output": "-1"
},
{
"input": "3\n1 4\n2 3\n4 4",
"output": "1"
},
{
"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3",
"output": "1"
},
{
"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n... | 1,587,134,656 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 218 | 307,200 | n = int(input())
cnt=0
sl=0
sr=0
for i in range(n):
x,y = map(int,input().split())
sl=sl+x
sr+=y
if x%2!=y%2:
cnt=cnt+1
if (sl+sr)%2==1:
print(-1)
else:
if sl%2==0:
print(0)
else:
if cnt>0:
print(1)
else:
print(-1) | Title: Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n... | ```python
n = int(input())
cnt=0
sl=0
sr=0
for i in range(n):
x,y = map(int,input().split())
sl=sl+x
sr+=y
if x%2!=y%2:
cnt=cnt+1
if (sl+sr)%2==1:
print(-1)
else:
if sl%2==0:
print(0)
else:
if cnt>0:
print(1)
else:
pr... | 3 | |
152 | C | Pocket Book | PROGRAMMING | 1,400 | [
"combinatorics"
] | null | null | One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters. | Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7). | [
"2 3\nAAB\nBAA\n",
"4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n"
] | [
"4\n",
"216\n"
] | In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB". | 1,500 | [
{
"input": "2 3\nAAB\nBAA",
"output": "4"
},
{
"input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA",
"output": "216"
},
{
"input": "1 1\nE",
"output": "1"
},
{
"input": "2 2\nNS\nPD",
"output": "4"
},
{
"input": "3 4\nPJKD\nNFJX\nFGFK",
"output": "81"
},
{
"inpu... | 1,593,846,977 | 2,147,483,647 | PyPy 3 | OK | TESTS | 60 | 310 | 1,740,800 | n,m=map(int,input().split())
arr=[]
mod=10**9+7
for i in range(n):
s=input()
arr.append(s)
ans=1
for j in range(m):
dic={}
temp=0
for i in range(n):
if arr[i][j] not in dic:
temp+=1
dic[arr[i][j]]=arr[i][j]
ans=(ans*temp%mod)%mod
print(ans)
| Title: Pocket Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
... | ```python
n,m=map(int,input().split())
arr=[]
mod=10**9+7
for i in range(n):
s=input()
arr.append(s)
ans=1
for j in range(m):
dic={}
temp=0
for i in range(n):
if arr[i][j] not in dic:
temp+=1
dic[arr[i][j]]=arr[i][j]
ans=(ans*temp%mod)%mod
print(ans... | 3 | |
366 | B | Dima and To-do List | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in ... | The first line of the input contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task.
It is guaranteed that *n*... | In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do. | [
"6 2\n3 2 1 6 5 4\n",
"10 5\n1 3 5 7 9 9 4 1 8 5\n"
] | [
"1\n",
"3\n"
] | Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. I... | 1,000 | [
{
"input": "6 2\n3 2 1 6 5 4",
"output": "1"
},
{
"input": "10 5\n1 3 5 7 9 9 4 1 8 5",
"output": "3"
},
{
"input": "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "10 10\n8 4 5 7 6 9 2 2 3 5",
"output": "7"
},
{
"input": "50 10\n1 2 3... | 1,594,396,999 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 171 | 29,388,800 | n,k=map(int,input().split())
list1=list(map(int,input().split()))
x=0
xx=100000001
index=0
for i in range(k):
s=0
for j in range(x,n,k):
s+=list1[j]
if(s<xx):
xx=s
index=x
x+=1
print(index+1) | Title: Dima and To-do List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything h... | ```python
n,k=map(int,input().split())
list1=list(map(int,input().split()))
x=0
xx=100000001
index=0
for i in range(k):
s=0
for j in range(x,n,k):
s+=list1[j]
if(s<xx):
xx=s
index=x
x+=1
print(index+1)
``` | 3 | |
24 | A | Ring road | PROGRAMMING | 1,400 | [
"graphs"
] | A. Ring road | 2 | 256 | Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were connected by *n* two-way roads in the ring, i. e. each city was connected directly to exactly tw... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of cities (and roads) in Berland. Next *n* lines contain description of roads. Each road is described by three integers *a**i*, *b**i*, *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*,<=1<=≤<=*c**i*<=≤<=100) — road is directed from city *a**i* t... | Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other. | [
"3\n1 3 1\n1 2 1\n3 2 1\n",
"3\n1 3 1\n1 2 5\n3 2 1\n",
"6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n",
"4\n1 2 9\n2 3 8\n3 4 7\n4 1 5\n"
] | [
"1\n",
"2\n",
"39\n",
"0\n"
] | none | 0 | [
{
"input": "3\n1 3 1\n1 2 1\n3 2 1",
"output": "1"
},
{
"input": "3\n1 3 1\n1 2 5\n3 2 1",
"output": "2"
},
{
"input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42",
"output": "39"
},
{
"input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5",
"output": "0"
},
{
"input": "5\n... | 1,615,571,515 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 307,200 | l,a,b,p,s=[],{0},{0},[],0
for i in range(int(input())):
q,w,e=map(int,input().split())
l+=[[q,w]]
a.add(q)
b.add(w)
p+=[e]
t=a&b
a-=t
b-=t
for i in a:
for j in b:
q=[i,j]
if q in l:s+=p[l.index(q)]
print(min(s,sum(p)-s)) | Title: Ring road
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were conne... | ```python
l,a,b,p,s=[],{0},{0},[],0
for i in range(int(input())):
q,w,e=map(int,input().split())
l+=[[q,w]]
a.add(q)
b.add(w)
p+=[e]
t=a&b
a-=t
b-=t
for i in a:
for j in b:
q=[i,j]
if q in l:s+=p[l.index(q)]
print(min(s,sum(p)-s))
``` | 0 |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,696,211,012 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 124 | 0 | # -*- coding: utf-8 -*-
"""Funny Forces Attempt Capitalize
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1ACc0-lS8jHSfydnEY6q0Yncu5cV7TCkM
"""
l = list(input())
Capl = l[0]
if Capl == 'a':
l.pop(0)
l.insert(0,'A')
elif Capl == 'b':
l.pop(0)
l... | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
# -*- coding: utf-8 -*-
"""Funny Forces Attempt Capitalize
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1ACc0-lS8jHSfydnEY6q0Yncu5cV7TCkM
"""
l = list(input())
Capl = l[0]
if Capl == 'a':
l.pop(0)
l.insert(0,'A')
elif Capl == 'b':
l.... | 3 | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,592,551,034 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 108 | 0 | # itne me hi thakk gaye?
n = int(input())
x = input()
for i in range(n):
if (x[i] == '0'):
break
print(i+1) | Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
# itne me hi thakk gaye?
n = int(input())
x = input()
for i in range(n):
if (x[i] == '0'):
break
print(i+1)
``` | 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,664,912,000 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | m=int(input()) # hight
n=int(input()) # the offer
a=m*n #room space
x= int(input())
q=x**2
w=a//q
print(w) | 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
m=int(input()) # hight
n=int(input()) # the offer
a=m*n #room space
x= int(input())
q=x**2
w=a//q
print(w)
``` | -1 |
52 | A | 123-sequence | PROGRAMMING | 900 | [
"implementation"
] | A. 123-sequence | 2 | 256 | There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3). | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | [
"9\n1 3 2 2 2 1 1 2 3\n"
] | [
"5\n"
] | In the example all the numbers equal to 1 and 3 should be replaced by 2. | 500 | [
{
"input": "9\n1 3 2 2 2 1 1 2 3",
"output": "5"
},
{
"input": "6\n3 3 2 2 1 3",
"output": "3"
},
{
"input": "12\n3 1 3 1 2 1 3 2 2 1 2 1",
"output": "7"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2",
"output": "10"
},
{
"input": "2\n2 1",
"output": "1"
... | 1,683,075,536 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 622 | 12,492,800 | from collections import Counter
n, a = int(input()), (int(i) for i in input().split())
cnt = Counter(a)
res = min(cnt[1] + cnt[2], cnt[2] + cnt[3], cnt[1] + cnt[3])
print(res)
| Title: 123-sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each... | ```python
from collections import Counter
n, a = int(input()), (int(i) for i in input().split())
cnt = Counter(a)
res = min(cnt[1] + cnt[2], cnt[2] + cnt[3], cnt[1] + cnt[3])
print(res)
``` | 3.82123 |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,679,807,586 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | k, r = map(int,input().split())
i =1
while True:
m = k *i
a = m%10
if a == r or a == 0:
print(i)
break
i+=1 | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
k, r = map(int,input().split())
i =1
while True:
m = k *i
a = m%10
if a == r or a == 0:
print(i)
break
i+=1
``` | 3 | |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,504,035,328 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | l,r,x,y,k=input().split()
l=int(l)
r=int(r)
x=int(x)
y=int(y)
k=float(k)
ans=False
for i in range(x,y+1):
xy=i/k
if int(xy)==xy and l<=xy<=r:
ans=True
break
else:
if ans:
print("YES")
else:
print("NO") | Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
l,r,x,y,k=input().split()
l=int(l)
r=int(r)
x=int(x)
y=int(y)
k=float(k)
ans=False
for i in range(x,y+1):
xy=i/k
if int(xy)==xy and l<=xy<=r:
ans=True
break
else:
if ans:
print("YES")
else:
print("NO")
``` | -1 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,589,357,321 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 248 | 6,963,200 | nums = int(input())
list2 = []
list1 = [int(i) for i in input().split()]
for i in list1:
list2.append(list1.count(i))
print(max(list2), len(set(list1)))
| Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
nums = int(input())
list2 = []
list1 = [int(i) for i in input().split()]
for i in list1:
list2.append(list1.count(i))
print(max(list2), len(set(list1)))
``` | 3.92503 |
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence... | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15... | 1,696,837,114 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 409,600 | import decimal
import math
import sys
import time
inp=input().split()
num=int(inp[0])
k=int(inp[1])
pat=input().split()
pat=[int(i) for i in pat]
sum=0
flag=pat[k-1]
for each in pat:
if flag<=each and each!=0:
sum+=1
print(sum) | Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* p... | ```python
import decimal
import math
import sys
import time
inp=input().split()
num=int(inp[0])
k=int(inp[1])
pat=input().split()
pat=[int(i) for i in pat]
sum=0
flag=pat[k-1]
for each in pat:
if flag<=each and each!=0:
sum+=1
print(sum)
``` | 3 | |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not... | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,659,644,014 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 62 | 0 | a = input()
a = [int(i) for i in a]
sol = [0 for i in range(9)]
for i in range(len(a)):
for j in range(a[i]):
sol[j] += 10**(len(a)-i-1)
for i in range(9):
if sol[i] == 0:
break
nb = i
print(nb+1)
print(*sol[:nb+1])
| Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Repr... | ```python
a = input()
a = [int(i) for i in a]
sol = [0 for i in range(9)]
for i in range(len(a)):
for j in range(a[i]):
sol[j] += 10**(len(a)-i-1)
for i in range(9):
if sol[i] == 0:
break
nb = i
print(nb+1)
print(*sol[:nb+1])
``` | 3 | |
653 | A | Bear and Three Balls | PROGRAMMING | 900 | [
"brute force",
"implementation",
"sortings"
] | null | null | Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes th... | The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. | Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). | [
"4\n18 55 16 17\n",
"6\n40 41 43 44 44 44\n",
"8\n5 972 3 4 1 4 970 971\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose bal... | 500 | [
{
"input": "4\n18 55 16 17",
"output": "YES"
},
{
"input": "6\n40 41 43 44 44 44",
"output": "NO"
},
{
"input": "8\n5 972 3 4 1 4 970 971",
"output": "YES"
},
{
"input": "3\n959 747 656",
"output": "NO"
},
{
"input": "4\n1 2 2 3",
"output": "YES"
},
{
... | 1,601,823,873 | 2,147,483,647 | Python 3 | OK | TESTS | 84 | 109 | 102,400 | n = int(input())
t = sorted(list(set([int(x) for x in input().split(' ')])))
ans = 'NO'
for i in range(len(t) - 2):
if t[i + 2] - t[i] == 2:
ans = 'YES'
break
print(ans)
| Title: Bear and Three Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make fri... | ```python
n = int(input())
t = sorted(list(set([int(x) for x in input().split(' ')])))
ans = 'NO'
for i in range(len(t) - 2):
if t[i + 2] - t[i] == 2:
ans = 'YES'
break
print(ans)
``` | 3 | |
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the... | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"... | 1,699,341,808 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 30 | 0 | a1,a2,a3=input(),-1,[-1]
for i in a1:
while(a2!=-1)and(a1[a2]!=i):
a2=a3[a2]
a2+=1
a3+=[a2]
q1=a3[-1]
if a3.count(q1)<2:
a1=a3[a1]
print(a1[:q1] if q1>0 else 'Just a legend')
#solved and submitted
| Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carve... | ```python
a1,a2,a3=input(),-1,[-1]
for i in a1:
while(a2!=-1)and(a1[a2]!=i):
a2=a3[a2]
a2+=1
a3+=[a2]
q1=a3[-1]
if a3.count(q1)<2:
a1=a3[a1]
print(a1[:q1] if q1>0 else 'Just a legend')
#solved and submitted
``` | -1 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,683,907,805 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 62 | 1,536,000 | n, k = map(int, input().split())
c = 0
for i in map(int, input().split()):
if (i + k <= 5): c += 1
print(c//3) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, k = map(int, input().split())
c = 0
for i in map(int, input().split()):
if (i + k <= 5): c += 1
print(c//3)
``` | 3 | |
53 | A | Autocomplete | PROGRAMMING | 1,100 | [
"implementation"
] | A. Autocomplete | 2 | 256 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase... | If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' o... | [
"next\n2\nnextpermutation\nnextelement\n",
"find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"find\n4\nfondfind\nfondfirstof\nfondit\nfand\n"
] | [
"nextelement\n",
"find\n",
"find\n"
] | none | 500 | [
{
"input": "next\n2\nnextpermutation\nnextelement",
"output": "nextelement"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand",
"output": "find"
},
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand",
"output": "find"
},
{
"input": "kudljmxcse\n4\nkudljmxcse\nszje... | 1,599,945,349 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 278 | 0 | s = str(input())
n = int(input())
asd = []
for i in range(n):
d = str(input())
asd.append(d)
flag=0
for i in asd:
if s not in i[0:len(s)]:
flag=1
break
if flag==1:
print(s)
else:
asd.sort()
print(asd[0]) | Title: Autocomplete
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens... | ```python
s = str(input())
n = int(input())
asd = []
for i in range(n):
d = str(input())
asd.append(d)
flag=0
for i in asd:
if s not in i[0:len(s)]:
flag=1
break
if flag==1:
print(s)
else:
asd.sort()
print(asd[0])
``` | 0 |
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,593,348,057 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 278 | 20,172,800 | def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) ]))
def invr():
return(map(int,input().split()))
l = inlt()
p = max(l)
if(p == 1):
print("1/1")
elif(p == 2):
print("5/6")
elif(p == 3):
print("2/3")
elif(p... | 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
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) ]))
def invr():
return(map(int,input().split()))
l = inlt()
p = max(l)
if(p == 1):
print("1/1")
elif(p == 2):
print("5/6")
elif(p == 3):
print("2/... | 3.710701 |
257 | A | Sockets | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | null | null | Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supp... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) —... | Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1. | [
"3 5 3\n3 1 2\n",
"4 7 2\n3 3 2 4\n",
"5 5 1\n1 3 1 2 1\n"
] | [
"1\n",
"2\n",
"-1\n"
] | In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to ... | 500 | [
{
"input": "3 5 3\n3 1 2",
"output": "1"
},
{
"input": "4 7 2\n3 3 2 4",
"output": "2"
},
{
"input": "5 5 1\n1 3 1 2 1",
"output": "-1"
},
{
"input": "4 5 8\n3 2 4 3",
"output": "0"
},
{
"input": "5 10 1\n4 3 4 2 4",
"output": "3"
},
{
"input": "7 13 2... | 1,597,478,428 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 280 | 0 | n,m,k=map(int,input().split())
l=list(map(int,input().split()))
l=sorted(l,reverse=True)
socket=k
plugs=0
i=0
while(socket+plugs<m and i<n and socket>=0):
socket=socket-1
plugs+=plugs+l[i]
i+=1
if(i==n or socket<0):
print("-1")
else:
print(i)
| Title: Sockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his f... | ```python
n,m,k=map(int,input().split())
l=list(map(int,input().split()))
l=sorted(l,reverse=True)
socket=k
plugs=0
i=0
while(socket+plugs<m and i<n and socket>=0):
socket=socket-1
plugs+=plugs+l[i]
i+=1
if(i==n or socket<0):
print("-1")
else:
print(i)
``` | 0 | |
755 | B | PolandBall and Game | PROGRAMMING | 1,100 | [
"binary search",
"data structures",
"games",
"greedy",
"sortings",
"strings"
] | null | null | PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively.
Then *n* strings follow, one per line — words familiar to PolandBall.
Then *m* strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a w... | In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. | [
"5 1\npolandball\nis\na\ncool\ncharacter\nnope\n",
"2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n",
"1 2\na\na\nb\n"
] | [
"YES",
"YES",
"NO"
] | In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | 1,000 | [
{
"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope",
"output": "YES"
},
{
"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska",
"output": "YES"
},
{
"input": "1 2\na\na\nb",
"output": "NO"
},
{
"input": "2 2\na\nb\nb\nc",
"output": "YES"
},
{
"input": "... | 1,635,009,107 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 6,246,400 | def game(n: int, m: int, polland: [str], enemy: [str]):
if (n > m):
return 'YES'
if (n < m):
return 'NO'
for i in range(n):
try:
if (enemy.index(polland[i]) >= 0):
return 'YES'
except:
continue
return 'NO'
# Input
n, m = list(map(lambda i: int(i), input().split()))
polan... | Title: PolandBall and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You... | ```python
def game(n: int, m: int, polland: [str], enemy: [str]):
if (n > m):
return 'YES'
if (n < m):
return 'NO'
for i in range(n):
try:
if (enemy.index(polland[i]) >= 0):
return 'YES'
except:
continue
return 'NO'
# Input
n, m = list(map(lambda i: int(i), input().split... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 0 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,659,319,142 | 2,147,483,647 | PyPy 3 | OK | TESTS | 88 | 92 | 0 | def waiting(lst):
v=[0]
v+=lst
dp=[]
inf=1000000000000000000
n=len(lst)
for i in range(1,n+2):
tmp=[]
for j in range(3):
tmp.append(inf)
dp.append(tmp)
dp[0][2]=0
#print(dp)
for i in range(1,n+1):
for j in range(3):
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet... | ```python
def waiting(lst):
v=[0]
v+=lst
dp=[]
inf=1000000000000000000
n=len(lst)
for i in range(1,n+2):
tmp=[]
for j in range(3):
tmp.append(inf)
dp.append(tmp)
dp[0][2]=0
#print(dp)
for i in range(1,n+1):
for j in range(3):
... | 3 | |
909 | A | Generate Login | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"sortings"
] | null | null | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and ... | The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. | Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. | [
"harry potter\n",
"tom riddle\n"
] | [
"hap\n",
"tomr\n"
] | none | 500 | [
{
"input": "harry potter",
"output": "hap"
},
{
"input": "tom riddle",
"output": "tomr"
},
{
"input": "a qdpinbmcrf",
"output": "aq"
},
{
"input": "wixjzniiub ssdfodfgap",
"output": "wis"
},
{
"input": "z z",
"output": "zz"
},
{
"input": "ertuyivhfg v"... | 1,630,917,605 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 77 | 6,758,400 | def main():
s = input().split()
f, l = s[0], s[-1]
name = list()
for i in range(1, len(f) + 1):
for j in range(1, len(l) + 1):
name.append(f[:i] + l[:j])
name.sort()
print(name[0])
if __name__ == '__main__':
main()
| Title: Generate Login
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the fu... | ```python
def main():
s = input().split()
f, l = s[0], s[-1]
name = list()
for i in range(1, len(f) + 1):
for j in range(1, len(l) + 1):
name.append(f[:i] + l[:j])
name.sort()
print(name[0])
if __name__ == '__main__':
main()
``` | 3 | |
280 | D | k-Maximum Subsequence Sum | PROGRAMMING | 2,800 | [
"data structures",
"flows",
"graphs",
"implementation"
] | null | null | Consider integer sequence *a*1,<=*a*2,<=...,<=*a**n*. You should run queries of two types:
- The query format is "0 *i* *val*". In reply to this query you should make the following assignment: *a**i*<==<=*val*. - The query format is "1 *l* *r* *k*". In reply to this query you should print the maximum sum of at most ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the sequence has. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=500).
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The next *m* lines contain the queries in the format, ... | For each query to count the maximum sum of at most *k* non-intersecting subsegments print the reply — the maximum sum. Print the answers to the queries in the order, in which the queries follow in the input. | [
"9\n9 -8 9 -1 -1 -1 9 -8 9\n3\n1 1 9 1\n1 1 9 2\n1 4 6 3\n",
"15\n-4 8 -3 -10 10 4 -7 -7 0 -6 3 8 -10 7 2\n15\n1 3 9 2\n1 6 12 1\n0 6 5\n0 10 -7\n1 4 9 1\n1 7 9 1\n0 10 -3\n1 4 10 2\n1 3 13 2\n1 4 11 2\n0 15 -9\n0 13 -9\n0 11 -10\n1 5 14 2\n1 6 12 1\n"
] | [
"17\n25\n0\n",
"14\n11\n15\n0\n15\n26\n18\n23\n8\n"
] | In the first query of the first example you can select a single pair (1, 9). So the described sum will be 17.
Look at the second query of the first example. How to choose two subsegments? (1, 3) and (7, 9)? Definitely not, the sum we could get from (1, 3) and (7, 9) is 20, against the optimal configuration (1, 7) and ... | 2,000 | [] | 1,689,591,244 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689591244.1627743")# 1689591244.162793 | Title: k-Maximum Subsequence Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider integer sequence *a*1,<=*a*2,<=...,<=*a**n*. You should run queries of two types:
- The query format is "0 *i* *val*". In reply to this query you should make the following assignment: *a**i*<==<=*va... | ```python
print("_RANDOM_GUESS_1689591244.1627743")# 1689591244.162793
``` | 0 | |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabb... | 1,647,270,174 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n=int(input())
c=(n-1)*"b"+"a"
print(c) | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o... | ```python
n=int(input())
c=(n-1)*"b"+"a"
print(c)
``` | 0 | |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,552,722,716 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | a,b = map(int,input().split())
s = input()
i=0
j=0
while j<a-1 and j<a:
if s[i]=='1':
i+=b
j+=1
else:
i-=1
if j>=a:
print(-1)
else:
print(j)
| Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
a,b = map(int,input().split())
s = input()
i=0
j=0
while j<a-1 and j<a:
if s[i]=='1':
i+=b
j+=1
else:
i-=1
if j>=a:
print(-1)
else:
print(j)
``` | -1 | |
825 | A | Binary Protocol | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts... | Print the decoded number. | [
"3\n111\n",
"9\n110011101\n"
] | [
"3\n",
"2031\n"
] | none | 0 | [
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "... | 1,500,219,019 | 1,519 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | s=input()
s=str(input())
val=0;
count=0;
print(s[0])
for a in s:
if a=='1':
count+=1
else:
val=10*val+count
count=0
val=10*val+count
print (val)
| Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' charact... | ```python
s=input()
s=str(input())
val=0;
count=0;
print(s[0])
for a in s:
if a=='1':
count+=1
else:
val=10*val+count
count=0
val=10*val+count
print (val)
``` | 0 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,656,090,121 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n, k = map(int, input().split())
arr = list(map(int, input().split()))
new = []
for i in arr:
if i+k <= 5 :
new.append(i)
count = len(new)//3
print(count) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, k = map(int, input().split())
arr = list(map(int, input().split()))
new = []
for i in arr:
if i+k <= 5 :
new.append(i)
count = len(new)//3
print(count)
``` | 3 | |
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,599,116,278 | 2,147,483,647 | PyPy 3 | OK | TESTS | 64 | 310 | 0 | a = int(input());b = int(input());
if a>b:
print("NO")
else:
i=0
j=1
while abs(b)>abs(j):
j*=a
i+=1
if b == j:
print("YES")
print(i-1)
else:
print("NO") | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
a = int(input());b = int(input());
if a>b:
print("NO")
else:
i=0
j=1
while abs(b)>abs(j):
j*=a
i+=1
if b == j:
print("YES")
print(i-1)
else:
print("NO")
``` | 3 | |
803 | A | Maximal Binary Matrix | PROGRAMMING | 1,400 | [
"constructive algorithms"
] | null | null | You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicograph... | The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). | If the answer exists then output resulting matrix. Otherwise output -1. | [
"2 1\n",
"3 2\n",
"2 5\n"
] | [
"1 0 \n0 0 \n",
"1 0 0 \n0 1 0 \n0 0 0 \n",
"-1\n"
] | none | 0 | [
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "20 398",
"output": "1 1 1 1 ... | 1,698,137,586 | 2,147,483,647 | Python 3 | OK | TESTS | 168 | 46 | 0 | n,k = map(int,input().split())
martix = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
for j in range(i,n):
if i == j :
if k > 0:
martix[i][j] = 1
k -= 1
else:
if k > 1:
martix[i][j],martix[j][i] = 1,1
... | Title: Maximal Binary Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes... | ```python
n,k = map(int,input().split())
martix = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
for j in range(i,n):
if i == j :
if k > 0:
martix[i][j] = 1
k -= 1
else:
if k > 1:
martix[i][j],martix[j]... | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,675,451,363 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 4,300,800 | a=list(input())
if (a.count("l")>=2) and (a.count("h")>=1) and (a.count("o")>=1) and (a.count("e")>=1) and len(a)>5 :
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
a=list(input())
if (a.count("l")>=2) and (a.count("h")>=1) and (a.count("o")>=1) and (a.count("e")>=1) and len(a)>5 :
print("YES")
else:
print("NO")
``` | 0 |
519 | C | A and B and Team Training | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi... | The first line contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=5·105) — the number of experienced participants and newbies that are present at the training session. | Print the maximum number of teams that can be formed. | [
"2 6\n",
"4 5\n"
] | [
"2\n",
"3\n"
] | Let's represent the experienced players as XP and newbies as NB.
In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB).
In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB). | 1,500 | [
{
"input": "2 6",
"output": "2"
},
{
"input": "4 5",
"output": "3"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "3 3",
"output": "2"
},
{
"input": "500000 500000",
"output": "333333"
},
{
"input": "70 100",
"output": "56"
},
{
"input": ... | 1,663,142,878 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | n,m=map(int,input().split())
# matrix=[list(map(int,input().split())) for i in range(m)]
# arr=list(map(int,input().split()))
# power=int(input())
ans=0
if m>n:
m_pos=m//2
if n>=m_pos:
ans+=m_pos
if m%2==1 and n-m_pos>=2:
ans+=1
else:
ans+=n
elif m==n:
... | Title: A and B and Team Training
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to dea... | ```python
n,m=map(int,input().split())
# matrix=[list(map(int,input().split())) for i in range(m)]
# arr=list(map(int,input().split()))
# power=int(input())
ans=0
if m>n:
m_pos=m//2
if n>=m_pos:
ans+=m_pos
if m%2==1 and n-m_pos>=2:
ans+=1
else:
ans+=n
elif m... | 0 | |
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.... | 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,668,008,447 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 62 | 0 | l="00"+input()+"00"
ans=[]
k=1
if "()" not in l:
print("0 1")
else:
i = l.index("()")
j= l.index("()")+1
while i<len(l) and j>k:
if (l[i-1],l[j+1])==("(",")"):
i-=1
j+=1
elif (l[i-2],l[i-1])==("(",")"):
i-=2
elif (l[j+1],l[j+2])... | 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
l="00"+input()+"00"
ans=[]
k=1
if "()" not in l:
print("0 1")
else:
i = l.index("()")
j= l.index("()")+1
while i<len(l) and j>k:
if (l[i-1],l[j+1])==("(",")"):
i-=1
j+=1
elif (l[i-2],l[i-1])==("(",")"):
i-=2
elif (l[j+... | -1 |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,591,176,864 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 140 | 0 | n,k=map(int, input().split())
s=str(input())
c=0;i=1
while i<n: #i is ind of front lily
if s[i:min(i+k,n)].count('1')==0:
c=-1
break
else:
i=k-s[min(i+k-1,n-1):i-1:-1].index('1')+i
c+=1
print(c)
| Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
n,k=map(int, input().split())
s=str(input())
c=0;i=1
while i<n: #i is ind of front lily
if s[i:min(i+k,n)].count('1')==0:
c=-1
break
else:
i=k-s[min(i+k-1,n-1):i-1:-1].index('1')+i
c+=1
print(c)
``` | 3 | |
81 | A | Plug-in | PROGRAMMING | 1,400 | [
"implementation"
] | A. Plug-in | 1 | 256 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy... | The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | [
"hhoowaaaareyyoouu\n",
"reallazy\n",
"abacabaabacabaa\n"
] | [
"wre",
"rezy",
"a"
] | none | 500 | [
{
"input": "hhoowaaaareyyoouu",
"output": "wre"
},
{
"input": "reallazy",
"output": "rezy"
},
{
"input": "abacabaabacabaa",
"output": "a"
},
{
"input": "xraccabccbry",
"output": "xy"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"... | 1,398,944,089 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 409,600 | s, end = input(), False
while (not end):
end, i, t = True, 0, ''
while (i < len(s) - 1):
if (s[i] != s[i + 1]):
t += s[i]
else:
end = False
i += 1
i += 1
if (i < len(s)):
t += s[-1]
s = t
print(s)
| Title: Plug-in
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed... | ```python
s, end = input(), False
while (not end):
end, i, t = True, 0, ''
while (i < len(s) - 1):
if (s[i] != s[i + 1]):
t += s[i]
else:
end = False
i += 1
i += 1
if (i < len(s)):
t += s[-1]
s = t
print(s)
``` | 0 |
975 | A | Aramic script | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$... | The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script.
The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$.
It is guaranteed that all characters of the strings are small latin letters. | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | [
"5\na aa aaa ab abb\n",
"3\namer arem mrea\n"
] | [
"2",
"1"
] | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | 500 | [
{
"input": "5\na aa aaa ab abb",
"output": "2"
},
{
"input": "3\namer arem mrea",
"output": "1"
},
{
"input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd",
"output": "6"
},
{
"input": "2\nfhjlqs aceginpr",
"output": "2"
},
{
"input": "2\nbcdfghimn efghijlmo",
... | 1,609,508,073 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 233 | 6,451,200 | from sys import stdin,stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
for _ in range(1):#nmbr()):
n=nmbr()
d={}
a=[]
for wrd in input().split():
a+=[''.join(sorted(set(wrd)))]
# print(a)
print(len(set(a))) | Title: Aramic script
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the ... | ```python
from sys import stdin,stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
for _ in range(1):#nmbr()):
n=nmbr()
d={}
a=[]
for wrd in input().split():
a+=[''.join(sorted(set(wrd)))]
# print(a)
print(len(set(a)))
``` | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,657,310,326 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | import math
M =int(input())
N = int(input())
print(math.floor(M*N/2))
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
import math
M =int(input())
N = int(input())
print(math.floor(M*N/2))
``` | -1 |
975 | B | Mancala | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next ... | The only line contains 14 integers $a_1, a_2, \ldots, a_{14}$ ($0 \leq a_i \leq 10^9$) — the number of stones in each hole.
It is guaranteed that for any $i$ ($1\leq i \leq 14$) $a_i$ is either zero or odd, and there is at least one stone in the board. | Output one integer, the maximum possible score after one move. | [
"0 1 1 0 0 0 0 0 0 7 0 0 0 0\n",
"5 1 1 1 1 0 0 0 0 0 0 0 0 0\n"
] | [
"4\n",
"8\n"
] | In the first test case the board after the move from the hole with $7$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $4$. | 1,000 | [
{
"input": "0 1 1 0 0 0 0 0 0 7 0 0 0 0",
"output": "4"
},
{
"input": "5 1 1 1 1 0 0 0 0 0 0 0 0 0",
"output": "8"
},
{
"input": "10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 1",
"output": "54294"
},
{
"input": "0 0 0 0 0 0 0 0 0 0 0 0 0 15",
... | 1,525,186,581 | 3,081 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 78 | 7,065,600 | arr = list(map(int, input().split()))
count = max(arr)
i = arr.index(count)
arr[i] = 0
while count >= 0:
arr[i] += 1
i += 1
if i >= len(arr):
i = 0
count -= 1
ans = 0
for x in arr:
if x != 0 and x % 2 == 0:
ans += 1
print(ans) | Title: Mancala
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. ... | ```python
arr = list(map(int, input().split()))
count = max(arr)
i = arr.index(count)
arr[i] = 0
while count >= 0:
arr[i] += 1
i += 1
if i >= len(arr):
i = 0
count -= 1
ans = 0
for x in arr:
if x != 0 and x % 2 == 0:
ans += 1
print(ans)
``` | 0 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,578,003,536 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 140 | 0 | n = int(input())
people= ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
j = 0
it = 1
while(n > 0):
n -= it
if n <= 0:
break
j += 1
if j == 5:
j = 0
it *= 2
print(people[j])
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
n = int(input())
people= ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
j = 0
it = 1
while(n > 0):
n -= it
if n <= 0:
break
j += 1
if j == 5:
j = 0
it *= 2
print(people[j])
``` | 3.93 |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,692,594,261 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n = int(input())
numbers = list(map(int, input().split()))
s = 0
d = 0
turn = 0
while len(numbers) != 0:
first = numbers[0]
last = numbers[-1]
if first > last:
numbers.pop(0)
if turn == 0:
turn = 1
s += first
else:
turn = 0
... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n = int(input())
numbers = list(map(int, input().split()))
s = 0
d = 0
turn = 0
while len(numbers) != 0:
first = numbers[0]
last = numbers[-1]
if first > last:
numbers.pop(0)
if turn == 0:
turn = 1
s += first
else:
turn ... | 3 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,657,571,734 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 62 | 0 |
def solve(str):
str = 'a' + str
totalMoves = 0
for i in range(1, len(str)):
prevChar = str[i-1]
curChar = str[i]
forwardMove = abs(ord(prevChar) - ord(curChar))
backwardMove = 26 - forwardMove
totalMoves += min(forwardMove, backwardMove)
return to... | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
def solve(str):
str = 'a' + str
totalMoves = 0
for i in range(1, len(str)):
prevChar = str[i-1]
curChar = str[i]
forwardMove = abs(ord(prevChar) - ord(curChar))
backwardMove = 26 - forwardMove
totalMoves += min(forwardMove, backwardMove)
... | 3 | |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,681,337,281 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n=int(input())
c=list(map(int,input().split()))
x=n
l=[]
for i in c:
if i !=x:
print()
l.append(i)
else:
l.append(i)
l.reverse()
for j in l:
print(j, end=" ")
print("\n")
x=l[-1]-1
l=[] | Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
n=int(input())
c=list(map(int,input().split()))
x=n
l=[]
for i in c:
if i !=x:
print()
l.append(i)
else:
l.append(i)
l.reverse()
for j in l:
print(j, end=" ")
print("\n")
x=l[-1]-1
l=[]
``` | 0 | |
402 | C | Searching for Graph | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"graphs"
] | null | null | Let's call an undirected graph of *n* vertices *p*-interesting, if the following conditions fulfill:
- the graph contains exactly 2*n*<=+<=*p* edges; - the graph doesn't contain self-loops and multiple edges; - for any integer *k* (1<=≤<=*k*<=≤<=*n*), any subgraph consisting of *k* vertices contains at most 2*k*<=... | The first line contains a single integer *t* (1<=≤<=*t*<=≤<=5) — the number of tests in the input. Next *t* lines each contains two space-separated integers: *n*, *p* (5<=≤<=*n*<=≤<=24; *p*<=≥<=0; ) — the number of vertices in the graph and the interest value for the appropriate test.
It is guaranteed that the requir... | For each of the *t* tests print 2*n*<=+<=*p* lines containing the description of the edges of a *p*-interesting graph: the *i*-th line must contain two space-separated integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*) — two vertices, connected by an edge in the resulting graph. Consider the gr... | [
"1\n6 0\n"
] | [
"1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n"
] | none | 1,500 | [
{
"input": "1\n6 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6"
},
{
"input": "1\n5 0",
"output": "1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5"
},
{
"input": "5\n6 0\n5 0\n7 0\n8 0\n9 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 ... | 1,688,649,774 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 78 | 4,915,200 | from sys import stdin,stdout
input = stdin.readline
t = int(input())
for _ in range(t):
n,p = map(int,input().split())
count = 0
for i in range(1,n):
for j in range(1,i+1):
for k in range(j+i,n+1,i):
print(k-i,k)
count += 1
if co... | Title: Searching for Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call an undirected graph of *n* vertices *p*-interesting, if the following conditions fulfill:
- the graph contains exactly 2*n*<=+<=*p* edges; - the graph doesn't contain self-loops and multiple edges; - ... | ```python
from sys import stdin,stdout
input = stdin.readline
t = int(input())
for _ in range(t):
n,p = map(int,input().split())
count = 0
for i in range(1,n):
for j in range(1,i+1):
for k in range(j+i,n+1,i):
print(k-i,k)
count += 1
... | 3 | |
288 | A | Polo the Penguin and Strings | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Little penguin Polo adores strings. But most of all he adores strings of length *n*.
One day he wanted to find a string that meets the following conditions:
1. The string consists of *n* lowercase English letters (that is, the string's length equals *n*), exactly *k* of these letters are distinct. 1. No two neighbo... | A single line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=106,<=1<=≤<=*k*<=≤<=26) — the string's length and the number of distinct letters. | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | [
"7 4\n",
"4 7\n"
] | [
"ababacd\n",
"-1\n"
] | none | 500 | [
{
"input": "7 4",
"output": "ababacd"
},
{
"input": "4 7",
"output": "-1"
},
{
"input": "10 5",
"output": "abababacde"
},
{
"input": "47 2",
"output": "abababababababababababababababababababababababa"
},
{
"input": "10 7",
"output": "ababacdefg"
},
{
"... | 1,585,847,092 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 280 | 0 | # single inheritance
a,b=map(int,input().split())
s="cdefghijklmnopqrstuvwxyz"
if(b>a):
print(-1)
else:
if(a-b)%2!=0:
q=("ab")*((a-b+2)//2)
q=q+"a"
for g in range(b-2):
q=q+s[g]
else:
q = ("ab") * ((a - b + 2) // 2)
for g in range(b-2):
... | Title: Polo the Penguin and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo adores strings. But most of all he adores strings of length *n*.
One day he wanted to find a string that meets the following conditions:
1. The string consists of *n* lowercase Englis... | ```python
# single inheritance
a,b=map(int,input().split())
s="cdefghijklmnopqrstuvwxyz"
if(b>a):
print(-1)
else:
if(a-b)%2!=0:
q=("ab")*((a-b+2)//2)
q=q+"a"
for g in range(b-2):
q=q+s[g]
else:
q = ("ab") * ((a - b + 2) // 2)
for g in range(b-... | 0 | |
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,691,537,310 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 |
n = int(input())
messages = set()
older = [0]*n
for i in range(n):
message = input()
#messages.add(message)
older[i] = message
# print(older)
# print(set(older), 'o set')
for i in set(older):
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
n = int(input())
messages = set()
older = [0]*n
for i in range(n):
message = input()
#messages.add(message)
older[i] = message
# print(older)
# print(set(older), 'o set')
for i in set(older):
print(i)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ... | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the firs... | 0 | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
... | 1,547,138,835 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 109 | 0 | v, a, b = list(map(int, input().split()))
c = []
m = True
g = 0
for i in range(v):
c.append([i + 1])
for i in range(8):
g += 1
for h in range(int(v / 2)):
if len(c) == 2:
print("Final!")
m = False
break
for l in range(len(c[h + 1])):
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the ord... | ```python
v, a, b = list(map(int, input().split()))
c = []
m = True
g = 0
for i in range(v):
c.append([i + 1])
for i in range(8):
g += 1
for h in range(int(v / 2)):
if len(c) == 2:
print("Final!")
m = False
break
for l in range(len(c[h + 1])):... | 3 | |
9 | B | Running Student | PROGRAMMING | 1,200 | [
"brute force",
"geometry",
"implementation"
] | B. Running Student | 1 | 64 | And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0,<=0), he got on a minibus and they drove along a straight line, parallel to axis *OX*, in the direction of increasing *x*.
Poor Student knows the following:
- during one run the minibus makes ... | The first line contains three integer numbers: 2<=≤<=*n*<=≤<=100, 1<=≤<=*v**b*,<=*v**s*<=≤<=1000. The second line contains *n* non-negative integers in ascending order: coordinates *x**i* of the bus stop with index *i*. It is guaranteed that *x*1 equals to zero, and *x**n*<=≤<=105. The third line contains the coordinat... | In the only line output the answer to the problem — index of the optimum bus stop. | [
"4 5 2\n0 2 4 6\n4 1\n",
"2 1 1\n0 100000\n100000 100000\n"
] | [
"3",
"2"
] | As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus. | 0 | [
{
"input": "4 5 2\n0 2 4 6\n4 1",
"output": "3"
},
{
"input": "2 1 1\n0 100000\n100000 100000",
"output": "2"
},
{
"input": "6 5 1\n0 1 2 3 4 5\n0 0",
"output": "2"
},
{
"input": "4 100 10\n0 118 121 178\n220 220",
"output": "4"
},
{
"input": "4 3 3\n0 6 8 10\n7 -... | 1,666,255,774 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 10 | 124 | 0 | n,b,s = map(int,input().split())
a = [*map(int,input().split())]
x,y = map(int,input().split())
res,t = [],float('inf')
for i in range(1,n):
temp = a[i]/b+(y**2+(a[i]-x)**2)/s
if temp<t: res = [i+1]; t = temp
elif temp==t: res += i+1,
if len(res)==1: print(res[0])
else: print(sorted((abs(a[i]-x),i)... | Title: Running Student
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0,<=0), he got on a minibus and they drove along a straight line, parallel to axis *OX*, in the direct... | ```python
n,b,s = map(int,input().split())
a = [*map(int,input().split())]
x,y = map(int,input().split())
res,t = [],float('inf')
for i in range(1,n):
temp = a[i]/b+(y**2+(a[i]-x)**2)/s
if temp<t: res = [i+1]; t = temp
elif temp==t: res += i+1,
if len(res)==1: print(res[0])
else: print(sorted((abs(... | 0 |
369 | B | Valera and Contest | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valer... | The first line of the input contains exactly six integers *n*,<=*k*,<=*l*,<=*r*,<=*s**all*,<=*s**k* (1<=≤<=*n*,<=*k*,<=*l*,<=*r*<=≤<=1000; *l*<=≤<=*r*; *k*<=≤<=*n*; 1<=≤<=*s**k*<=≤<=*s**all*<=≤<=106).
It's guaranteed that the input is such that the answer exists. | Print exactly *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order. | [
"5 3 1 3 13 9\n",
"5 3 1 3 15 9\n"
] | [
"2 3 2 3 3 ",
"3 3 3 3 3 "
] | none | 1,000 | [
{
"input": "5 3 1 3 13 9",
"output": "2 3 2 3 3 "
},
{
"input": "5 3 1 3 15 9",
"output": "3 3 3 3 3 "
},
{
"input": "50 25 1 1 50 25",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1000 700 782... | 1,385,741,480 | 2,480 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 31 | 0 | n, k, l, r, s_all, s_k = list(map(int, input().split()))
res = [ max(s_all // n, s_k // k) for i in range(k - 1)]
res.append(s_k - max(s_all // n, s_k // k) * (k - 1))
s_all -= s_k
n -= k
res1 = [ s_all // n for i in range(n - 1)]
if s_all % n != 0:
res.append(s_all % n)
else:
res.append(s_all // n... | Title: Valera and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual c... | ```python
n, k, l, r, s_all, s_k = list(map(int, input().split()))
res = [ max(s_all // n, s_k // k) for i in range(k - 1)]
res.append(s_k - max(s_all // n, s_k // k) * (k - 1))
s_all -= s_k
n -= k
res1 = [ s_all // n for i in range(n - 1)]
if s_all % n != 0:
res.append(s_all % n)
else:
res.append(... | 0 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,696,792,076 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | string = input()
string.replace('WUB', ' ')
print(string)
| Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
string = input()
string.replace('WUB', ' ')
print(string)
``` | 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,670,826,976 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 92 | 0 | n, m= map(int, input().split())
a= list(map(int, input().split()))
a.sort()
if n == m:
print(a[m-1]- a[0])
else:
minn= a[m-1]
i= 0
j= n-1
while j < m:
u= a[j]- a[i]
minn= min(u, minn)
i += 1
j += 1
print(minn) | 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().split())
a= list(map(int, input().split()))
a.sort()
if n == m:
print(a[m-1]- a[0])
else:
minn= a[m-1]
i= 0
j= n-1
while j < m:
u= a[j]- a[i]
minn= min(u, minn)
i += 1
j += 1
print(minn)
``` | 3 | |
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,563,532,952 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
arr.sort()
flag = [0 for i in range(n)]
for i in range(n):
curr = arr[i]
l = i+1
r = n-1
while(l<=r):
mid = (l+r)//2
if arr[mid]>=2*curr and flag[mid]==0:
r = mid-1
else:
l=mid+1
if n>l>i:
flag[i]=1
flag[l]=1
print(flag.count(1)... | 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())
arr = []
for i in range(n):
arr.append(int(input()))
arr.sort()
flag = [0 for i in range(n)]
for i in range(n):
curr = arr[i]
l = i+1
r = n-1
while(l<=r):
mid = (l+r)//2
if arr[mid]>=2*curr and flag[mid]==0:
r = mid-1
else:
l=mid+1
if n>l>i:
flag[i]=1
flag[l]=1
print(fla... | 0 | |
743 | A | Vladik and flights | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows *n* airports. All the airports are located on a straight line. Each airport has u... | The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length *n*, which consists only of characters... | Print single integer — the minimum cost Vladik has to pay to get to the olympiad. | [
"4 1 4\n1010\n",
"5 5 2\n10110\n"
] | [
"1",
"0"
] | In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to th... | 500 | [
{
"input": "4 1 4\n1010",
"output": "1"
},
{
"input": "5 5 2\n10110",
"output": "0"
},
{
"input": "10 9 5\n1011111001",
"output": "1"
},
{
"input": "7 3 7\n1110111",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 3 3\n100101101... | 1,610,739,569 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 77 | 307,200 | def min_cost(a,b,l):
return (l[a-1]!=l[b-1])+0
n,a,b=map(int,input().split())
l=input()
print(min_cost(a,b,l))
| Title: Vladik and flights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the o... | ```python
def min_cost(a,b,l):
return (l[a-1]!=l[b-1])+0
n,a,b=map(int,input().split())
l=input()
print(min_cost(a,b,l))
``` | 3 | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,626,260,917 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 6,963,200 | n = int(input())
s= input()
f=str()
r=str()
if n % 2 ==0:
for i in range(n):
if i % 2 ==0:
f += s[i]
else:
r += s[i]
print(f[::-1] + r)
else:
for i in range(n):
if i % 2 ==0:
r += s[i]
else:
f +... | Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
n = int(input())
s= input()
f=str()
r=str()
if n % 2 ==0:
for i in range(n):
if i % 2 ==0:
f += s[i]
else:
r += s[i]
print(f[::-1] + r)
else:
for i in range(n):
if i % 2 ==0:
r += s[i]
else:
... | 3 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,696,582,621 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | from sys import stdin
stream = None
try:
stream = open('file.txt', 'r')
except:
stream = stdin
number = [int(i) for i in list(stream.readline().strip())]
min_number = ''
for idx, digit in enumerate(number):
if digit > 4:
temp_digit = 9 - digit
if idx == 0 and temp_digit == 0:
... | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
from sys import stdin
stream = None
try:
stream = open('file.txt', 'r')
except:
stream = stdin
number = [int(i) for i in list(stream.readline().strip())]
min_number = ''
for idx, digit in enumerate(number):
if digit > 4:
temp_digit = 9 - digit
if idx == 0 and temp_digit == 0:
... | 0 | |
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n... | 1,607,151,584 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 278 | 0 | n =int(input())
d = list(map(int, input().split()))
a, b = list(map(int, input().split()))
i = 0
ans = 0
while True:
if (a == b):
break
if (i == len(d)-1):
ans += d[i]
a += 1
else:
ans += d[i]
i += 1
a += 1
print(ans) | Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
n =int(input())
d = list(map(int, input().split()))
a, b = list(map(int, input().split()))
i = 0
ans = 0
while True:
if (a == b):
break
if (i == len(d)-1):
ans += d[i]
a += 1
else:
ans += d[i]
i += 1
a += 1
print(ans)
``` | 0 |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,635,533,080 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 4,300,800 | m, n = list(int(num) for num in input().split(" "))
squares = m * n
number = squares - (squares % 2)
number = int(number / 2)
print(number)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m, n = list(int(num) for num in input().split(" "))
squares = m * n
number = squares - (squares % 2)
number = int(number / 2)
print(number)
``` | 3.968989 |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,688,452,257 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 0 | if __name__ == '__main__':
weight = int(input())
print('YES' if not weight%2 and weight>2 else 'NO') | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
if __name__ == '__main__':
weight = int(input())
print('YES' if not weight%2 and weight>2 else 'NO')
``` | 3.969 |
177 | A1 | Good Matrix Elements | PROGRAMMING | 800 | [
"implementation"
] | null | null | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which ha... | The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 po... | Print a single integer — the sum of good matrix elements. | [
"3\n1 2 3\n4 5 6\n7 8 9\n",
"5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n"
] | [
"45\n",
"17\n"
] | In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | 30 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "45"
},
{
"input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "17"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33",
... | 1,672,316,624 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS1 | 0 | 60 | 0 | n=int(input(''))
l=[]
sum=0
for i in range(n):
l.append(list(map(int,input().split())))
for i in range(n):
for j in range(n):
if (i==j or i==(n-1)//2 or j==(n-1)//2 or i==n-1-j):
print(i,j)
sum+=l[i][j]
print(sum)
| Title: Good Matrix Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the ... | ```python
n=int(input(''))
l=[]
sum=0
for i in range(n):
l.append(list(map(int,input().split())))
for i in range(n):
for j in range(n):
if (i==j or i==(n-1)//2 or j==(n-1)//2 or i==n-1-j):
print(i,j)
sum+=l[i][j]
print(sum)
``` | 0 | |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ... | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39... | 1,687,090,180 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 62 | 0 | n = int(input())
print(sum(map(int, input().split()))/n )
| Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
n = int(input())
print(sum(map(int, input().split()))/n )
``` | 3 | |
609 | C | Load Balancing | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server.
In order to balance the load for each server, you want to reassign some tasks to make the differe... | The first line contains positive number *n* (1<=≤<=*n*<=≤<=105) — the number of the servers.
The second line contains the sequence of non-negative integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=≤<=2·104), where *m**i* is the number of tasks assigned to the *i*-th server. | Print the minimum number of seconds required to balance the load. | [
"2\n1 6\n",
"7\n10 11 10 11 10 11 11\n",
"5\n1 2 3 4 5\n"
] | [
"2\n",
"0\n",
"3\n"
] | In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2.
In the second example the load is already balanced.
A possible sequence of task movements for the third example is:
... | 0 | [
{
"input": "2\n1 6",
"output": "2"
},
{
"input": "7\n10 11 10 11 10 11 11",
"output": "0"
},
{
"input": "5\n1 2 3 4 5",
"output": "3"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n20000",
... | 1,554,290,547 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 124 | 204,800 | from math import ceil
n=int(input())
a=[int(i) for i in input().split()]
a=sorted(a)
s=sum(a)
otv=0
x=ceil(s//n)
i=0
j=n-1
while i<j:
if a[i]+1>x:
i+=1
continue
if a[j]-1<x:
j-=1
continue
a[i]+=1
a[j]-=1
otv+=1
print(otv)
| Title: Load Balancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server... | ```python
from math import ceil
n=int(input())
a=[int(i) for i in input().split()]
a=sorted(a)
s=sum(a)
otv=0
x=ceil(s//n)
i=0
j=n-1
while i<j:
if a[i]+1>x:
i+=1
continue
if a[j]-1<x:
j-=1
continue
a[i]+=1
a[j]-=1
otv+=1
print(otv)
``` | 0 | |
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,594,111,354 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 218 | 6,656,000 | x=0
y=0
z=0
for _ in range(int(input())):
q=[int(x) for x in input().split()]
x+=q[0]
y+=q[1]
z+=q[2]
if [x,y,z]==[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
x=0
y=0
z=0
for _ in range(int(input())):
q=[int(x) for x in input().split()]
x+=q[0]
y+=q[1]
z+=q[2]
if [x,y,z]==[0,0,0]:
print("YES")
else:
print("NO")
``` | 3.933102 |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,696,996,076 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 93 | 0 | # ⣿⣷⡶⠚⠉⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠠⣴⣿⣿⣿⣿⣶⣤⣤⣤
# ⠿⠥⢶⡏⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣴⣷⣌⢿⣿⣿⣿⣿⣿⣿⣿
# ⣍⡛⢷⣠⣿⣿⣿⣿⣿⣟⠻⣯⠽⣿⣿⠟⠁⣠⠿⠿⣿⣿⣎⠻⣿⣿⣿⡿⠟⣿
# ⣿⣿⣦⠙⣿⣿⣿⣿⣿⣿⣷⣏⡧⠙⠁⣀⢾⣧ ⠈⣿⡟ ⠙⣫⣵⣶⠇⣋
# ⣿⣿⣿⢀⣿⣿⣿⣿⣿⣿⣿⠟⠃⢀⣀⢻⣎⢻⣷⣤⣴⠟ ⣠⣾⣿⢟⣵⡆⢿
# ⣿⣯⣄⢘⢻⣿⣿⣿⣿⡟⠁⢀⣤⡙⢿⣴⣿⣷⡉⠉⢀ ⣴⣿⡿⣡⣿⣿⡿⢆
# ⠿⣿⣧⣤⡘⢿⣿⣿⠏ ⡔⠉⠉⢻⣦⠻⣿⣿⣶⣾⡟⣼⣿⣿⣱⣿⡿⢫⣾⣿
# ⣷⣮⣝⣛⣃⡉⣿⡏ ⣾⣧⡀ ⣿⡇⢘⣿⠋ ⠻⣿⣿⣿⢟⣵⣿⣿⣿
# ⣿⣿⣿⣿⣿⣿⣌⢧⣴⣘⢿⣿⣶⣾⡿⠁⢠⠿⠁⠜ ⣿⣿⣿⣿⡿⣿⣿⣿
#... | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
# ⣿⣷⡶⠚⠉⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠠⣴⣿⣿⣿⣿⣶⣤⣤⣤
# ⠿⠥⢶⡏⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣴⣷⣌⢿⣿⣿⣿⣿⣿⣿⣿
# ⣍⡛⢷⣠⣿⣿⣿⣿⣿⣟⠻⣯⠽⣿⣿⠟⠁⣠⠿⠿⣿⣿⣎⠻⣿⣿⣿⡿⠟⣿
# ⣿⣿⣦⠙⣿⣿⣿⣿⣿⣿⣷⣏⡧⠙⠁⣀⢾⣧ ⠈⣿⡟ ⠙⣫⣵⣶⠇⣋
# ⣿⣿⣿⢀⣿⣿⣿⣿⣿⣿⣿⠟⠃⢀⣀⢻⣎⢻⣷⣤⣴⠟ ⣠⣾⣿⢟⣵⡆⢿
# ⣿⣯⣄⢘⢻⣿⣿⣿⣿⡟⠁⢀⣤⡙⢿⣴⣿⣷⡉⠉⢀ ⣴⣿⡿⣡⣿⣿⡿⢆
# ⠿⣿⣧⣤⡘⢿⣿⣿⠏ ⡔⠉⠉⢻⣦⠻⣿⣿⣶⣾⡟⣼⣿⣿⣱⣿⡿⢫⣾⣿
# ⣷⣮⣝⣛⣃⡉⣿⡏ ⣾⣧⡀ ⣿⡇⢘⣿⠋ ⠻⣿⣿⣿⢟⣵⣿⣿⣿
# ⣿⣿⣿⣿⣿⣿⣌⢧⣴⣘⢿⣿⣶⣾⡿⠁⢠⠿⠁⠜ ⣿... | 3 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,691,129,434 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 156 | 16,998,400 | # ██████╗
# ███ ███═█████╗
# ████████╗ ██████╗ ████████╗ ████ █████ ████╗
# ██╔═════╝ ██╔═══██╗ ██╔═════╝ ████ █ ███║
# ██████╗ ██║ ╚═╝ ██████╗ ████ ████╔╝
# ██╔═══╝ ██║ ██... | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
# ██████╗
# ███ ███═█████╗
# ████████╗ ██████╗ ████████╗ ████ █████ ████╗
# ██╔═════╝ ██╔═══██╗ ██╔═════╝ ████ █ ███║
# ██████╗ ██║ ╚═╝ ██████╗ ████ ████╔╝
# ██╔═══╝ ... | 3 | |
230 | A | Dragons | PROGRAMMING | 1,000 | [
"greedy",
"sortings"
] | null | null | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirit... | The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it. | On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't. | [
"2 2\n1 99\n100 0\n",
"10 1\n100 100\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.
In the second sample Kirito's strength ... | 500 | [
{
"input": "2 2\n1 99\n100 0",
"output": "YES"
},
{
"input": "10 1\n100 100",
"output": "NO"
},
{
"input": "123 2\n78 10\n130 0",
"output": "YES"
},
{
"input": "999 2\n1010 10\n67 89",
"output": "YES"
},
{
"input": "2 5\n5 1\n2 1\n3 1\n1 1\n4 1",
"output": "YE... | 1,698,219,964 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 7 | 218 | 3,481,600 | s,n=list(map(int, input().split()))
inputs=[]
for i in range(0, n):
inputs.append(list(map(int, input().split())))
def binSearch(arr, l, r, x):
while(l<=r):
mid=l+(r-l)//2
if(arr[mid]==x):
return mid
elif(arr[mid]<x):
l=mid+1
else:
r=mid-1
... | Title: Dragons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the du... | ```python
s,n=list(map(int, input().split()))
inputs=[]
for i in range(0, n):
inputs.append(list(map(int, input().split())))
def binSearch(arr, l, r, x):
while(l<=r):
mid=l+(r-l)//2
if(arr[mid]==x):
return mid
elif(arr[mid]<x):
l=mid+1
else:
r... | -1 | |
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ... | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five l... | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
... | 1,663,273,389 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | r,l,a=map(int,input().split())
c=a//2
r+=c
l+=c
if r==0 or l==0:
print(0)
else:
print(r+l) | Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.... | ```python
r,l,a=map(int,input().split())
c=a//2
r+=c
l+=c
if r==0 or l==0:
print(0)
else:
print(r+l)
``` | 0 | |
106 | B | Choosing Laptop | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | B. Choosing Laptop | 2 | 256 | Vasya is choosing a laptop. The shop has *n* laptops to all tastes.
Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties.
If all three properties of a laptop are strictly less than those propertie... | The first line contains number *n* (1<=≤<=*n*<=≤<=100).
Then follow *n* lines. Each describes a laptop as *speed* *ram* *hdd* *cost*. Besides,
- *speed*, *ram*, *hdd* and *cost* are integers - 1000<=≤<=*speed*<=≤<=4200 is the processor's speed in megahertz - 256<=≤<=*ram*<=≤<=4096 the RAM volume in megabytes - 1... | Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to *n* in the order in which they are given in the input data. | [
"5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150\n"
] | [
"4"
] | In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop. | 1,000 | [
{
"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150",
"output": "4"
},
{
"input": "2\n1500 500 50 755\n1600 600 80 700",
"output": "2"
},
{
"input": "2\n1500 512 50 567\n1600 400 70 789",
"output": "1"
},
{
"input": "4\n10... | 1,600,537,458 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 307,200 | n=int(input())
s=[]
for i in range(n):
s+=[list(map(int,input().split()))]
p=0
for i in range(n):
ans=True
for j in range(n):
if(A[i][0]<A[j][0] and A[i][1]<A[j][1] and A[i][2]<A[j][2]):
ans=False
if(ans):
cost=A[i][3]
if(cost==A[i][3... | Title: Choosing Laptop
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is choosing a laptop. The shop has *n* laptops to all tastes.
Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in ... | ```python
n=int(input())
s=[]
for i in range(n):
s+=[list(map(int,input().split()))]
p=0
for i in range(n):
ans=True
for j in range(n):
if(A[i][0]<A[j][0] and A[i][1]<A[j][1] and A[i][2]<A[j][2]):
ans=False
if(ans):
cost=A[i][3]
if(co... | -1 |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,551,390,905 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 0 |
xy=list(map(int,input().rstrip().split()))
nn=list(map(int,input().rstrip().split()))
dur=xy[1]
flag=0
tmin=(xy[0]-1)*10+(sum(nn))
if tmin>dur:
print(-1)
flag=1
if flag==0:
extratime=dur-((xy[0]-1)*10+(sum(nn)))
numjokes=int(extratime/5)+int((xy[0]-1)*2)
print(numjokes)
| Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
xy=list(map(int,input().rstrip().split()))
nn=list(map(int,input().rstrip().split()))
dur=xy[1]
flag=0
tmin=(xy[0]-1)*10+(sum(nn))
if tmin>dur:
print(-1)
flag=1
if flag==0:
extratime=dur-((xy[0]-1)*10+(sum(nn)))
numjokes=int(extratime/5)+int((xy[0]-1)*2)
print(numjokes)
... | 3 | |
155 | B | Combination | PROGRAMMING | 1,100 | [
"greedy",
"sortings"
] | null | null | Ilya plays a card game by the following rules.
A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number *a**i*, and the botto... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards Ilya has.
Each of the next *n* lines contains two non-negative space-separated integers — *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=104) — the numbers, written at the top and the bottom of the *i*-th card correspondingly. | Print the single number — the maximum number of points you can score in one round by the described rules. | [
"2\n1 0\n2 0\n",
"3\n1 0\n2 0\n0 2\n"
] | [
"2\n",
"3\n"
] | In the first sample none of two cards brings extra moves, so you should play the one that will bring more points.
In the second sample you should first play the third card that doesn't bring any points but lets you play both remaining cards. | 1,000 | [
{
"input": "2\n1 0\n2 0",
"output": "2"
},
{
"input": "3\n1 0\n2 0\n0 2",
"output": "3"
},
{
"input": "5\n0 0\n2 0\n2 0\n3 0\n5 1",
"output": "8"
},
{
"input": "7\n9 1\n8 1\n9 0\n9 1\n5 1\n1 1\n0 1",
"output": "41"
},
{
"input": "7\n5 0\n4 0\n3 0\n5 2\n3 0\n4 2\n0... | 1,672,843,772 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 154 | 6,451,200 | from heapq import *
from queue import *
import sys, math, bisect
from math import *
from collections import Counter, defaultdict
input = lambda: sys.stdin.buffer.readline().decode().strip()
# print = sys.stdout.write
inl = lambda: list(map(int, input().split()))
for _ in range(int(1)):
N = inl()[0]
... | Title: Combination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya plays a card game by the following rules.
A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player ... | ```python
from heapq import *
from queue import *
import sys, math, bisect
from math import *
from collections import Counter, defaultdict
input = lambda: sys.stdin.buffer.readline().decode().strip()
# print = sys.stdout.write
inl = lambda: list(map(int, input().split()))
for _ in range(int(1)):
N = ... | 0 | |
656 | B | Scrambled | PROGRAMMING | 1,700 | [
"*special",
"implementation"
] | null | null | Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt ... | The first line of input contains a single integer N (1<=≤<=*N*<=≤<=16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All *M*[*i*] are positive, for each *i* *R*[*i*]<=<<=*M*[*i*]. | Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=4. | [
"1\n2\n0\n",
"2\n2 3\n1 0\n"
] | [
"0.500000\n",
"0.666667\n"
] | none | 0 | [
{
"input": "1\n2\n0",
"output": "0.500000"
},
{
"input": "2\n2 3\n1 0",
"output": "0.666667"
},
{
"input": "3\n2 4 4\n0 1 3",
"output": "1.000000"
},
{
"input": "1\n16\n15",
"output": "0.062500"
},
{
"input": "16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n0 1 2 3 4 ... | 1,617,228,887 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 140 | 2,355,200 | # coding: utf-8
from functools import reduce
def gcd (x, y):
while y:
x, y = y, x % y
return x
def lcm (x, y):
return x * y // gcd(x, y)
n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
g = reduce(lambda x, y: lcm(x, y), m)
count = 0
for... | Title: Scrambled
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M... | ```python
# coding: utf-8
from functools import reduce
def gcd (x, y):
while y:
x, y = y, x % y
return x
def lcm (x, y):
return x * y // gcd(x, y)
n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
g = reduce(lambda x, y: lcm(x, y), m)
count ... | 3 | |
12 | C | Fruits | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | C. Fruits | 1 | 256 | The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of A... | The first line of the input contains two integer number *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of t... | Print two numbers *a* and *b* (*a*<=≤<=*b*) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. | [
"5 3\n4 2 1 10 5\napple\norange\nmango\n",
"6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n"
] | [
"7 19\n",
"11 30\n"
] | none | 0 | [
{
"input": "5 3\n4 2 1 10 5\napple\norange\nmango",
"output": "7 19"
},
{
"input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange",
"output": "11 30"
},
{
"input": "2 2\n91 82\neiiofpfpmemlakcystpun\nmcnzeiiofpfpmemlakcystpunfl",
"output": "173 173"
},
{
"input"... | 1,655,748,032 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 93 | 716,800 | import functools
n,m = map(int,input().split())
a = list(map(int,input().split()))
b =[]
for x in range(m):
b.append(input())
c = list(set(b))
def compare(x,y):
return b.count(x)-b.count(y)
d = sorted(c,key = functools.cmp_to_key(compare))
d = d[::-1]
a.sort()
e = a[::-1]
count1 = 0
count2 = 0
fo... | Title: Fruits
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some ... | ```python
import functools
n,m = map(int,input().split())
a = list(map(int,input().split()))
b =[]
for x in range(m):
b.append(input())
c = list(set(b))
def compare(x,y):
return b.count(x)-b.count(y)
d = sorted(c,key = functools.cmp_to_key(compare))
d = d[::-1]
a.sort()
e = a[::-1]
count1 = 0
coun... | 3.952165 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,587,300,329 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | a=input().lower()
b=a.find("h")
c=a.find("e")
d=a.find("l")
e=a.find(a[d+1:])
f=a.find("o")
print(b<c<d<e<f) | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
a=input().lower()
b=a.find("h")
c=a.find("e")
d=a.find("l")
e=a.find(a[d+1:])
f=a.find("o")
print(b<c<d<e<f)
``` | 0 |
926 | D | Choose Place | PROGRAMMING | 1,600 | [] | null | null | A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the p... | The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' — the description of the left desk in the current row; a character '-' — the aisle; two characters, each is '*' or '.' — the de... | Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input.
If there are multiple answers, print a... | [
"..-**-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..\n",
"**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-..-..\n..-**-..\n",
"**-**-*.\n*.-*.-**\n**-**-**\n**-**-**\n..-..-..\n..-**-..\n"
] | [
"..-**-..\n..-**-..\n..-..-..\n..-P.-..\n..-..-..\n..-..-..\n",
"**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-P.-..\n..-**-..\n",
"**-**-*.\n*.-*P-**\n**-**-**\n**-**-**\n..-..-..\n..-**-..\n"
] | In the first example the maximum convenience is 3.
In the second example the maximum convenience is 2.
In the third example the maximum convenience is 4. | 0 | [
{
"input": "..-**-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..",
"output": "..-**-..\n..-**-..\n..-..-..\n..-P.-..\n..-..-..\n..-..-.."
},
{
"input": "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-..-..\n..-**-..",
"output": "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-P.-..\n..-**-.."
},
... | 1,692,106,371 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | import heapq
def main():
priority = [
"33-44-33",
"33-44-33",
"22-33-22",
"22-33-22",
"11-22-11",
"11-22-11"
]
pq = []
for i in range(6):
for j in range(8):
if priority[i][j] == '-':
continue
... | Title: Choose Place
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya h... | ```python
import heapq
def main():
priority = [
"33-44-33",
"33-44-33",
"22-33-22",
"22-33-22",
"11-22-11",
"11-22-11"
]
pq = []
for i in range(6):
for j in range(8):
if priority[i][j] == '-':
continue
... | 0 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,689,644,873 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | n = (input())
n_int = int(n)
listed_num = [int(i) for i in n]
if n_int%7 == 0 or n_int%4 == 0 or n_int%47 == 0 or n_int%477 == 0:
print("YES")
else:
listed_num = set(listed_num)
if sum(listed_num) == 11:
print("YES")
else:
print("NO")
| Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n = (input())
n_int = int(n)
listed_num = [int(i) for i in n]
if n_int%7 == 0 or n_int%4 == 0 or n_int%47 == 0 or n_int%477 == 0:
print("YES")
else:
listed_num = set(listed_num)
if sum(listed_num) == 11:
print("YES")
else:
print("NO")
``` | 3 | |
299 | A | Ksusha and Array | PROGRAMMING | 1,000 | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements. | Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 500 | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
... | 1,681,138,191 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 3,481,600 | n =int(input())
l = list(map(int , input().split()))
number = -1
counter = 0
for i in l :
if i % min(l) == 0 :
counter += 1
if counter == n :
number = min(l)
print(number) | Title: Ksusha and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that ... | ```python
n =int(input())
l = list(map(int , input().split()))
number = -1
counter = 0
for i in l :
if i % min(l) == 0 :
counter += 1
if counter == n :
number = min(l)
print(number)
``` | 0 | |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,649,044,551 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | y,k,n=map(int,input().split())
l=[]
a=k-(y%k)
if a>0 and a!=k:l.append(a)
h=a
while True:
if h>n-y:
break
else:
h+=k
if h>n-y:break
l.append(h)
if len(l)==0:print(-1)
else:print(*l) | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
y,k,n=map(int,input().split())
l=[]
a=k-(y%k)
if a>0 and a!=k:l.append(a)
h=a
while True:
if h>n-y:
break
else:
h+=k
if h>n-y:break
l.append(h)
if len(l)==0:print(-1)
else:print(*l)
``` | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,574,340,917 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 234 | 2,048,000 | # 58A => Chat room
# https://codeforces.com/problemset/problem/58/A
from re import match
s = input()
if match(r".*h.*e.*l.*l.*o.*", s):
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
# 58A => Chat room
# https://codeforces.com/problemset/problem/58/A
from re import match
s = input()
if match(r".*h.*e.*l.*l.*o.*", s):
print("YES")
else:
print("NO")
``` | 3.879185 |
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of a... | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "... | 1,567,232,417 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 11,161,600 | n,m = map(int,input().split())
x = list(map(int,input().split()))
c = x.count(-1)
c = min(n-c,c)
t = ['0']*m
for _ in range(m):
a,b = map(int,input().split())
l = b-a+1
if not l&1:
if l<=2*c:
t[_]='1'
print('\n'.join(t))
| Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (... | ```python
n,m = map(int,input().split())
x = list(map(int,input().split()))
c = x.count(-1)
c = min(n-c,c)
t = ['0']*m
for _ in range(m):
a,b = map(int,input().split())
l = b-a+1
if not l&1:
if l<=2*c:
t[_]='1'
print('\n'.join(t))
``` | 0 | |
805 | A | Fake NP | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times... | The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). | Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them. | [
"19 29\n",
"3 6\n"
] | [
"2\n",
"3\n"
] | Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {... | 500 | [
{
"input": "19 29",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "39 91",
"output": "2"
},
{
"input": "76 134",
"output": "2"
},
{
"input": "93 95",
"output": "2"
},
{
"input": "17 35",
"output": "2"
},
{
"input": "94 95",... | 1,569,002,952 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 17 | 1,000 | 1,433,600 | a,b=map(int,input().split())
x,y=0,0
for i in range(a,b+1):
if i%2==0:x+=1
if i%3==0:y+=1
print(2 if x>=y else 3)
| Title: Fake NP
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of the... | ```python
a,b=map(int,input().split())
x,y=0,0
for i in range(a,b+1):
if i%2==0:x+=1
if i%3==0:y+=1
print(2 if x>=y else 3)
``` | 0 | |
411 | A | Password Check | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che... | The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". | If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). | [
"abacaba\n",
"X12345\n",
"CONTEST_is_STARTED!!11\n"
] | [
"Too weak\n",
"Too weak\n",
"Correct\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "Too weak"
},
{
"input": "X12345",
"output": "Too weak"
},
{
"input": "CONTEST_is_STARTED!!11",
"output": "Correct"
},
{
"input": "1zA__",
"output": "Correct"
},
{
"input": "1zA_",
"output": "Too weak"
},
{
"input": "zA_... | 1,646,765,978 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | def f(password):
if len(password) < 5:
return False
large = False
small = False
digit = False
for char in password:
if char.islower():
small = True
if char.isupper():
large = True
if char.isdigit():
digit = True
if ... | Title: Password Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password... | ```python
def f(password):
if len(password) < 5:
return False
large = False
small = False
digit = False
for char in password:
if char.islower():
small = True
if char.isupper():
large = True
if char.isdigit():
digit = Tru... | 0 | |
342 | E | Xenia and Tree | PROGRAMMING | 2,400 | [
"data structures",
"divide and conquer",
"trees"
] | null | null | Xenia the programmer has a tree consisting of *n* nodes. We will consider the tree nodes indexed from 1 to *n*. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue.
The distance between two tree nodes *v* and *u* is the number of edges in the shortest path between... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105) — the number of nodes in the tree and the number of queries. Next *n*<=-<=1 lines contain the tree edges, the *i*-th line contains a pair of integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — an edge of ... | For each second type query print the reply in a single line. | [
"5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 5\n"
] | [
"0\n3\n2\n"
] | none | 2,500 | [
{
"input": "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 5",
"output": "0\n3\n2"
}
] | 1,674,881,663 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 3,891,200 | class LowestCommonAncestor:
"""<O(n), O(log(n))>"""
def __init__(self, G, root, parents):
from collections import deque
self.n = len(G)
self.tour = [0] * (2 * self.n - 1)
self.depth_list = [0] * (2 * self.n - 1)
self.id = [-1] * self.n
self.dfs(G, root... | Title: Xenia and Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the programmer has a tree consisting of *n* nodes. We will consider the tree nodes indexed from 1 to *n*. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue.
... | ```python
class LowestCommonAncestor:
"""<O(n), O(log(n))>"""
def __init__(self, G, root, parents):
from collections import deque
self.n = len(G)
self.tour = [0] * (2 * self.n - 1)
self.depth_list = [0] * (2 * self.n - 1)
self.id = [-1] * self.n
self.d... | -1 | |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,695,754,003 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 77 | 42,291,200 | n = int(input())
m = 1
count = 1
seq = list(map(int, input().split()))
for i in range(n - 1):
if seq[i] <= seq[i + 1]:
count += 1
else:
m = max(m, count)
count = 1
m = max(m, count)
print(m) | Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l... | ```python
n = int(input())
m = 1
count = 1
seq = list(map(int, input().split()))
for i in range(n - 1):
if seq[i] <= seq[i + 1]:
count += 1
else:
m = max(m, count)
count = 1
m = max(m, count)
print(m)
``` | 3 | |
777 | B | Game of Credit Cards | PROGRAMMING | 1,300 | [
"data structures",
"dp",
"greedy",
"sortings"
] | null | null | After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains *n* digits — Sherlock's credit card number.
The third line contains *n* digits — Moriarty's credit card number. | First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty. | [
"3\n123\n321\n",
"2\n88\n00\n"
] | [
"0\n2\n",
"2\n0\n"
] | First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks. | 1,000 | [
{
"input": "3\n123\n321",
"output": "0\n2"
},
{
"input": "2\n88\n00",
"output": "2\n0"
},
{
"input": "1\n4\n5",
"output": "0\n1"
},
{
"input": "1\n8\n7",
"output": "1\n0"
},
{
"input": "2\n55\n55",
"output": "0\n0"
},
{
"input": "3\n534\n432",
"out... | 1,598,545,428 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 155 | 0 | n = int(input())
a = input()
b = input()
a = sorted(a)
b = sorted(b)
Min = 0
for idx in range(n):
if b[idx] < a[idx]:
Min += 1
print(Min)
Max = 0
idxa = n - 1
idxb = n - 1
while idxa >= 0 and idxb >= 0:
if a[idxa] < b[idxb]:
Max += 1
idxa -= 1
idxb -=... | Title: Game of Credit Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simpl... | ```python
n = int(input())
a = input()
b = input()
a = sorted(a)
b = sorted(b)
Min = 0
for idx in range(n):
if b[idx] < a[idx]:
Min += 1
print(Min)
Max = 0
idxa = n - 1
idxb = n - 1
while idxa >= 0 and idxb >= 0:
if a[idxa] < b[idxb]:
Max += 1
idxa -= 1
... | 0 | |
988 | B | Substrings Sort | PROGRAMMING | 1,100 | [
"sortings",
"strings"
] | null | null | You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in su... | The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings.
The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters.
Some strings might be equal. | If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes).
Otherwise print "YES" (without quotes) and $n$ given strings in required order. | [
"5\na\naba\nabacaba\nba\naba\n",
"5\na\nabacaba\nba\naba\nabab\n",
"3\nqwerty\nqwerty\nqwerty\n"
] | [
"YES\na\nba\naba\naba\nabacaba\n",
"NO\n",
"YES\nqwerty\nqwerty\nqwerty\n"
] | In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba". | 0 | [
{
"input": "5\na\naba\nabacaba\nba\naba",
"output": "YES\na\nba\naba\naba\nabacaba"
},
{
"input": "5\na\nabacaba\nba\naba\nabab",
"output": "NO"
},
{
"input": "3\nqwerty\nqwerty\nqwerty",
"output": "YES\nqwerty\nqwerty\nqwerty"
},
{
"input": "1\nwronganswer",
"output": "Y... | 1,637,077,181 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 46 | 0 | n=int(input())
stringVector=[]
for i in range(n):
stringVector.append(input())
stringVector=list(sorted(stringVector, key=lambda x: (-len(x),x)))[::-1]
ok="YES"
for i in range(n-1):
if stringVector[i] not in stringVector[i+1]:
ok="NO"
break
print(ok)
if ok=="YES":
for s in string... | Title: Substrings Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String ... | ```python
n=int(input())
stringVector=[]
for i in range(n):
stringVector.append(input())
stringVector=list(sorted(stringVector, key=lambda x: (-len(x),x)))[::-1]
ok="YES"
for i in range(n-1):
if stringVector[i] not in stringVector[i+1]:
ok="NO"
break
print(ok)
if ok=="YES":
for s... | 3 | |
384 | A | Coder | PROGRAMMING | 800 | [
"implementation"
] | null | null | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any. | [
"2\n"
] | [
"2\nC.\n.C\n"
] | none | 500 | [
{
"input": "2",
"output": "2\nC.\n.C"
},
{
"input": "3",
"output": "5\nC.C\n.C.\nC.C"
},
{
"input": "4",
"output": "8\nC.C.\n.C.C\nC.C.\n.C.C"
},
{
"input": "10",
"output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C... | 1,610,203,921 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 307,200 | # import os
n = int(input())
c = 0
r = []
for i in range(n):
if i % 2 == 0:
if n % 2 == 0:
r.append('C.'*(n//2))
c += n//2
else:
ss = 'C.'*(n//2)
r.append(ss[:-1])
c += n//2
else:
if n % 2 == 0:
r.... | Title: Coder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or... | ```python
# import os
n = int(input())
c = 0
r = []
for i in range(n):
if i % 2 == 0:
if n % 2 == 0:
r.append('C.'*(n//2))
c += n//2
else:
ss = 'C.'*(n//2)
r.append(ss[:-1])
c += n//2
else:
if n % 2 == 0:
... | 0 | |
474 | D | Flowers | PROGRAMMING | 1,700 | [
"dp"
] | null | null | We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty... | Input contains several test cases.
The first line contains two integers *t* and *k* (1<=≤<=*t*,<=*k*<=≤<=105), where *t* represents the number of test cases.
The next *t* lines contain two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=105), describing the *i*-th test. | Print *t* lines to the standard output. The *i*-th line should contain the number of ways in which Marmot can eat between *a**i* and *b**i* flowers at dinner modulo 1000000007 (109<=+<=7). | [
"3 2\n1 3\n2 3\n4 4\n"
] | [
"6\n5\n5\n"
] | - For *K* = 2 and length 1 Marmot can eat (*R*). - For *K* = 2 and length 2 Marmot can eat (*RR*) and (*WW*). - For *K* = 2 and length 3 Marmot can eat (*RRR*), (*RWW*) and (*WWR*). - For *K* = 2 and length 4 Marmot can eat, for example, (*WWWW*) or (*RWWR*), but for example he can't eat (*WWWR*). | 2,000 | [
{
"input": "3 2\n1 3\n2 3\n4 4",
"output": "6\n5\n5"
},
{
"input": "1 1\n1 3",
"output": "14"
},
{
"input": "1 2\n64329 79425",
"output": "0"
}
] | 1,682,705,062 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 1,076 | 9,420,800 | maxn = 10**5 + 5
mod = 10**9 + 7
test_case, k = map(int, input().split())
dp = [0] * maxn
sum = [0] * maxn
dp[0] = 1
for i in range(1, maxn):
dp[i] = dp[i - 1]
if (i >= k):
dp[i] = (dp[i] + dp[i - k]) % mod
for i in range(1, maxn):
sum[i] = (sum[i - 1] + dp[i]) % mod
for _ in range(test_case):
... | Title: Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequenc... | ```python
maxn = 10**5 + 5
mod = 10**9 + 7
test_case, k = map(int, input().split())
dp = [0] * maxn
sum = [0] * maxn
dp[0] = 1
for i in range(1, maxn):
dp[i] = dp[i - 1]
if (i >= k):
dp[i] = (dp[i] + dp[i - k]) % mod
for i in range(1, maxn):
sum[i] = (sum[i - 1] + dp[i]) % mod
for _ in range(test_... | 3 |
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.