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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
608 | B | Hamming Distance Sum | PROGRAMMING | 1,500 | [
"combinatorics",
"strings"
] | null | null | Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For exam... | The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only. | Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | [
"01\n00111\n",
"0011\n0110\n"
] | [
"3\n",
"2\n"
] | For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts ... | 1,000 | [
{
"input": "01\n00111",
"output": "3"
},
{
"input": "0011\n0110",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "0\n1",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1... | 1,637,407,064 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 171 | 4,608,000 | from collections import deque
def hamming(arr1, arr2, n):
sum1 = 0
for i in range(n):
sum1 += arr1[i]^arr2[i]
return sum1
s = input()
t = input()
n = len(t)
m = len(s)
total = 0
count1 = 0
length = n-m+1
for i in range(n-m+1):
if t[i] == '1':
count1 += 1
for i in range(m)... | Title: Hamming Distance Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is de... | ```python
from collections import deque
def hamming(arr1, arr2, n):
sum1 = 0
for i in range(n):
sum1 += arr1[i]^arr2[i]
return sum1
s = input()
t = input()
n = len(t)
m = len(s)
total = 0
count1 = 0
length = n-m+1
for i in range(n-m+1):
if t[i] == '1':
count1 += 1
for i i... | 3 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,599,585,864 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 109 | 0 | def even(a):
if(a >= '0' and a <= '9' and (int(a) % 2 != 0)):
return True
return False
s = list(input())
sum = 0
for i in range(len(s)):
if(s[i] == 'a' or s[i] == 'e' or s[i] == 'i' or s[i] == 'o' or s[i] == 'u' or even(s[i])):
sum += 1
print(sum)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
def even(a):
if(a >= '0' and a <= '9' and (int(a) % 2 != 0)):
return True
return False
s = list(input())
sum = 0
for i in range(len(s)):
if(s[i] == 'a' or s[i] == 'e' or s[i] == 'i' or s[i] == 'o' or s[i] == 'u' or even(s[i])):
sum += 1
print(sum)
... | 3 | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | 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... | 500 | [
{
"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,593,909,476 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 6,963,200 | from sys import stdin,stdout
for _ in range(1):
n=int(stdin.readline())
a=list(map(int,stdin.readline().split()));c=0
dp=[[0 for _ in range(3)]for _ in range(n)]
if a[0]==1 or a[0]==2:
dp[0][a[0]]=1
elif a[0]==3:
dp[0][1]=dp[0][2]=1
for i in range(1,n):
if a[i]=... | Title: Vacations
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 Int... | ```python
from sys import stdin,stdout
for _ in range(1):
n=int(stdin.readline())
a=list(map(int,stdin.readline().split()));c=0
dp=[[0 for _ in range(3)]for _ in range(n)]
if a[0]==1 or a[0]==2:
dp[0][a[0]]=1
elif a[0]==3:
dp[0][1]=dp[0][2]=1
for i in range(1,n):
... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,587,651,638 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 280 | 0 | n = int(input())
even = 0
odd = 0
a = []
for x in input().split():
a.append(int(x))
if int(x)%2==0:
even += 1
else:
odd += 1
for i in range(n):
if ((even == 1 and a[i]%2==0) or (odd == 1 and a[i]%2!=0)):
print(i+1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
even = 0
odd = 0
a = []
for x in input().split():
a.append(int(x))
if int(x)%2==0:
even += 1
else:
odd += 1
for i in range(n):
if ((even == 1 and a[i]%2==0) or (odd == 1 and a[i]%2!=0)):
print(i+1)
``` | 3.93 |
451 | A | Game With Sticks | PROGRAMMING | 900 | [
"implementation"
] | null | null | After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid show... | The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). | Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. | [
"2 2\n",
"2 3\n",
"3 3\n"
] | [
"Malvika\n",
"Malvika\n",
"Akshat\n"
] | Explanation of the first sample:
The grid has four intersection points, numbered from 1 to 4.
If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.
Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remov... | 500 | [
{
"input": "2 2",
"output": "Malvika"
},
{
"input": "2 3",
"output": "Malvika"
},
{
"input": "3 3",
"output": "Akshat"
},
{
"input": "20 68",
"output": "Malvika"
},
{
"input": "1 1",
"output": "Akshat"
},
{
"input": "1 2",
"output": "Akshat"
},
... | 1,682,541,167 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 78 | 0 | a = min(map(int,input().split()))
if a % 2 == 0:
print('Malvika')
else:
print('Akshat')
| Title: Game With Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid... | ```python
a = min(map(int,input().split()))
if a % 2 == 0:
print('Malvika')
else:
print('Akshat')
``` | 3 | |
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least... | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
... | 1,453,663,601 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def main():
(n, d) = input().split()
d = int(d)
l = input().split()
l = [int(x) for x in l]
print(solver(l, d))
def solver(l, d):
assert(len(l) >= 2)
total = 0
current = l[0]
for x in l[1:]:
print(x, current)
if x <= current:
ds = (current - x) // d + 1
total += ds
x += ds * d
... | Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*... | ```python
def main():
(n, d) = input().split()
d = int(d)
l = input().split()
l = [int(x) for x in l]
print(solver(l, d))
def solver(l, d):
assert(len(l) >= 2)
total = 0
current = l[0]
for x in l[1:]:
print(x, current)
if x <= current:
ds = (current - x) // d + 1
total += ds
x += ... | 0 |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,577,282,392 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 140 | 0 |
myDict = {}
class Solution:
def solve(self, string):
if string not in myDict:
myDict[string] = 1
return False
else:
return True
sol = Solution()
t = int(input().strip())
for i in range(t):
string = input().strip()
print("YES" if s... | Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
myDict = {}
class Solution:
def solve(self, string):
if string not in myDict:
myDict[string] = 1
return False
else:
return True
sol = Solution()
t = int(input().strip())
for i in range(t):
string = input().strip()
print(... | 3 | |
796 | A | Buying A House | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house ... | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=... | Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. | [
"5 1 20\n0 27 32 21 19\n",
"7 3 50\n62 0 0 0 99 33 22\n",
"10 5 100\n1 0 1 0 0 0 0 0 1 1\n"
] | [
"40",
"30",
"20"
] | In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 a... | 500 | [
{
"input": "5 1 20\n0 27 32 21 19",
"output": "40"
},
{
"input": "7 3 50\n62 0 0 0 99 33 22",
"output": "30"
},
{
"input": "10 5 100\n1 0 1 0 0 0 0 0 1 1",
"output": "20"
},
{
"input": "5 3 1\n1 1 0 0 1",
"output": "10"
},
{
"input": "5 5 5\n1 0 5 6 0",
"outpu... | 1,564,938,867 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 124 | 0 | # import sys
# sys.stdin=open("input.in","r")
n,m,k=map(int,input().split())
m-=1
l=list(map(int,input().split()))
c=[]
for i in range(n):
if l[i]<=k and l[i]!=0:
c.append((abs(i-m))*10)
print(min(c)) | Title: Buying A House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight li... | ```python
# import sys
# sys.stdin=open("input.in","r")
n,m,k=map(int,input().split())
m-=1
l=list(map(int,input().split()))
c=[]
for i in range(n):
if l[i]<=k and l[i]!=0:
c.append((abs(i-m))*10)
print(min(c))
``` | 3 | |
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}... | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All sub... | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"... | 1,527,491,243 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 27 | 78 | 0 |
import sys
s=input()
right=len(s)-1
flag=0
count=0
for i in range((int(len(s)/2))+1):
if s[count]!=s[right]:
if len(s)-right>=count:
print(len(s)-count)
else:
print(right+1)
sys.exit(0)
if flag == 1:
right -= 1
else:
count+=... | Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar... | ```python
import sys
s=input()
right=len(s)-1
flag=0
count=0
for i in range((int(len(s)/2))+1):
if s[count]!=s[right]:
if len(s)-right>=count:
print(len(s)-count)
else:
print(right+1)
sys.exit(0)
if flag == 1:
right -= 1
else:
... | 0 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. 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,698,408,884 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 102,400 | from collections import deque
n = int(input())
one =[]
two =[]
nums = deque(map(int,input().split()))
while len(nums) > 1:
if nums[0] > nums[-1] and len(nums) > 1 :
one.append(nums[0])
nums.popleft()
elif len(nums) > 1 :
one.append(nums[-1])
nums.pop()
if nums[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
from collections import deque
n = int(input())
one =[]
two =[]
nums = deque(map(int,input().split()))
while len(nums) > 1:
if nums[0] > nums[-1] and len(nums) > 1 :
one.append(nums[0])
nums.popleft()
elif len(nums) > 1 :
one.append(nums[-1])
nums.pop()
... | 3 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,618,191,029 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | string = str(input())
counter = 0
l = ['0','2','4','6','8','a','i','o','u','e']
for ch in string:
if ch in l:
counter += 1
print(counter)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
string = str(input())
counter = 0
l = ['0','2','4','6','8','a','i','o','u','e']
for ch in string:
if ch in l:
counter += 1
print(counter)
``` | 0 | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,668,527,555 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 102,400 | n = int(input())
a = ""
nums = []
w = False
for i in range(n):
b = input()
a += b
nums.append(b)
nums1 = nums[0][0]
nums2 = nums[0][1]
for k in range(n):
if not(nums[k][k] == nums1 and nums[k][len(nums[k]) - k - 1] == nums1):
w = True
if w == False:
if (a.co... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
n = int(input())
a = ""
nums = []
w = False
for i in range(n):
b = input()
a += b
nums.append(b)
nums1 = nums[0][0]
nums2 = nums[0][1]
for k in range(n):
if not(nums[k][k] == nums1 and nums[k][len(nums[k]) - k - 1] == nums1):
w = True
if w == False:
... | 3 | |
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e... | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
... | 1,635,585,989 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define int long long
#define endl '\n'
//#define kilk_c(n) (int)log10(n)+1
#define fast ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;
struct my{int a,b,c,d;};
bool comp(my a,my b){
return a.b>b.b;
}
int modFact(int n, int p,int a=1,int b=1)... | Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla... | ```python
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
//#define kilk_c(n) (int)log10(n)+1
#define fast ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;
struct my{int a,b,c,d;};
bool comp(my a,my b){
return a.b>b.b;
}
int modFact(int n, int p,int a=... | -1 | |
488 | A | Giga Tower | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it ... | The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). | Print the minimum *b* in a line. | [
"179\n",
"-1\n",
"18\n"
] | [
"1\n",
"9\n",
"10\n"
] | For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | 500 | [
{
"input": "179",
"output": "1"
},
{
"input": "-1",
"output": "9"
},
{
"input": "18",
"output": "10"
},
{
"input": "-410058385",
"output": "1"
},
{
"input": "-586825624",
"output": "1"
},
{
"input": "852318890",
"output": "1"
},
{
"input": ... | 1,474,030,570 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 61 | 0 | n = int(input())
for i in range(n + 1, n + 20):
if str(i).count('8') > 0:
print(i - n)
break
| Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Ever... | ```python
n = int(input())
for i in range(n + 1, n + 20):
if str(i).count('8') > 0:
print(i - n)
break
``` | 3 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,690,956,849 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | a = []
for i in range(1,181):
b = i*180
if b%(i+2)==0:
a.append(b//(i+2))
t = int(input())
for i in range(t):
n = int(input())
if n in a:
print("YES")
else:
print("NO")
| Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
a = []
for i in range(1,181):
b = i*180
if b%(i+2)==0:
a.append(b//(i+2))
t = int(input())
for i in range(t):
n = int(input())
if n in a:
print("YES")
else:
print("NO")
``` | 0 | |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,672,326,250 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 92 | 0 | # tc = int(input())
for i in range(1):
n = int(input())
li = list(map(int, input().strip().split()))
ans = 0
x = 0
for i in range(n):
temp = 1
if li[i]==x:
continue
x = li[i]
j = i+1
... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
# tc = int(input())
for i in range(1):
n = int(input())
li = list(map(int, input().strip().split()))
ans = 0
x = 0
for i in range(n):
temp = 1
if li[i]==x:
continue
x = li[i]
j = i+1
... | 0 |
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi... | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,655,982,063 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | b,g=map(int,input().split())
if b==g:
for i in range(b):print('BG',end='')
elif b>g:
for i in range(g):print('BG',end='')
for i in range(b-g):print('B',end='')
else:
for i in range(g):print('GB',end='')
for i in range(b-g):print('G',end='')
| Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n... | ```python
b,g=map(int,input().split())
if b==g:
for i in range(b):print('BG',end='')
elif b>g:
for i in range(g):print('BG',end='')
for i in range(b-g):print('B',end='')
else:
for i in range(g):print('GB',end='')
for i in range(b-g):print('G',end='')
``` | -1 | |
261 | B | Maxim and Restaurant | PROGRAMMING | 1,900 | [
"dp",
"math",
"probabilities"
] | null | null | Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is *p* meters.
Maxim has got a dinner party tonight, *n* guests will come to him. Let's index the guests of Maxim's restaurant from 1 to *n*. Maxim knows the sizes of all guests that are going to come to him. The *i*-th guest'... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of guests in the restaurant. The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=50) — the guests' sizes in meters. The third line contains integer *p* (1<=≤<=*p*<=≤<=50) — the table's length in meters.
The numbers in the lines ... | In a single line print a real number — the answer to the problem. The answer will be considered correct, if the absolute or relative error doesn't exceed 10<=-<=4. | [
"3\n1 2 3\n3\n"
] | [
"1.3333333333\n"
] | In the first sample the people will come in the following orders:
- (1, 2, 3) — there will be two people in the restaurant; - (1, 3, 2) — there will be one person in the restaurant; - (2, 1, 3) — there will be two people in the restaurant; - (2, 3, 1) — there will be one person in the restaurant; - (3, 1, 2) — t... | 1,000 | [
{
"input": "3\n1 2 3\n3",
"output": "1.3333333333"
},
{
"input": "9\n2 2 2 2 2 2 2 1 2\n9",
"output": "4.5555555556"
},
{
"input": "7\n2 1 1 2 1 1 2\n2",
"output": "1.2857142857"
},
{
"input": "8\n3 1 5 6 1 5 4 4\n7",
"output": "1.6250000000"
},
{
"input": "2\n1 3... | 1,609,503,761 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 248 | 716,800 | from pprint import pprint
n = int(input())
a = list(map(int, input().split()))
p = int(input())
fact = [1]
for i in range(1, 51):
fact.append(fact[-1]*i)
if sum(a) <= p:
print(n)
else:
dp = [[0]*6 for _ in range(6)]
dp[0][0] = 1
for i in range(n):
for j in range(n, -1,... | Title: Maxim and Restaurant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is *p* meters.
Maxim has got a dinner party tonight, *n* guests will come to him. Let's index the guests of Maxim's rest... | ```python
from pprint import pprint
n = int(input())
a = list(map(int, input().split()))
p = int(input())
fact = [1]
for i in range(1, 51):
fact.append(fact[-1]*i)
if sum(a) <= p:
print(n)
else:
dp = [[0]*6 for _ in range(6)]
dp[0][0] = 1
for i in range(n):
for j in ra... | -1 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,667,361,224 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 13 | 186 | 2,355,200 | #chale
def primos(x):
numeros2 = [1 for i in range(x+1)]
almost = [0 for i in range(x+1)]
numeros2[0] = numeros2[1] = 0
d=2
while d <= x:
if numeros2[d]:
almost[d] = 1
for val in range(d+d,x,d):
numeros2[val] = 0
almost[val]+=1
... | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
#chale
def primos(x):
numeros2 = [1 for i in range(x+1)]
almost = [0 for i in range(x+1)]
numeros2[0] = numeros2[1] = 0
d=2
while d <= x:
if numeros2[d]:
almost[d] = 1
for val in range(d+d,x,d):
numeros2[val] = 0
almost... | -1 |
903 | B | The Modcrab | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.
After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has *h*2 health points and an attack power of *a*2. Knowing that, Vova... | The first line contains three integers *h*1, *a*1, *c*1 (1<=≤<=*h*1,<=*a*1<=≤<=100, 2<=≤<=*c*1<=≤<=100) — Vova's health, Vova's attack power and the healing power of a potion.
The second line contains two integers *h*2, *a*2 (1<=≤<=*h*2<=≤<=100, 1<=≤<=*a*2<=<<=*c*1) — the Modcrab's health and his attack power. | In the first line print one integer *n* denoting the minimum number of phases required to win the battle.
Then print *n* lines. *i*-th line must be equal to HEAL if Vova drinks a potion in *i*-th phase, or STRIKE if he attacks the Modcrab.
The strategy must be valid: Vova's character must not be defeated before slayi... | [
"10 6 100\n17 5\n",
"11 6 100\n12 5\n"
] | [
"4\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n",
"2\nSTRIKE\nSTRIKE\n"
] | In the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win.
In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left. | 0 | [
{
"input": "10 6 100\n17 5",
"output": "4\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE"
},
{
"input": "11 6 100\n12 5",
"output": "2\nSTRIKE\nSTRIKE"
},
{
"input": "25 27 91\n10 87",
"output": "1\nSTRIKE"
},
{
"input": "79 4 68\n9 65",
"output": "21\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL... | 1,598,343,730 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | h1,a1,c1 = map(int,input().split())
h2,a2 = map(int,input().split())
a = -(-h1//a2)
b = -(-h2//a1)
print(max(0,b-a)+b)
print(max(0,b-a)*"HEAL\n",b*"STRIKE\n")
| Title: The Modcrab
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.
After two hours of playing the game Vova has tracked the monster and analyze... | ```python
h1,a1,c1 = map(int,input().split())
h2,a2 = map(int,input().split())
a = -(-h1//a2)
b = -(-h2//a1)
print(max(0,b-a)+b)
print(max(0,b-a)*"HEAL\n",b*"STRIKE\n")
``` | 0 | |
476 | B | Dreamoon and WiFi | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, de... | The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes ... | Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. | [
"++-+-\n+-+-+\n",
"+-+-\n+-??\n",
"+++\n??-\n"
] | [
"1.000000000000\n",
"0.500000000000\n",
"0.000000000000\n"
] | For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="low... | 1,500 | [
{
"input": "++-+-\n+-+-+",
"output": "1.000000000000"
},
{
"input": "+-+-\n+-??",
"output": "0.500000000000"
},
{
"input": "+++\n??-",
"output": "0.000000000000"
},
{
"input": "++++++++++\n+++??++?++",
"output": "0.125000000000"
},
{
"input": "--+++---+-\n????????... | 1,691,184,052 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | import itertools
def find_prob(done, sent):
interrogatins = 0
done_points = 0
sent_points = 0
for i in range(len(sent)):
if(done[i] == "+"):
done_points += 1
else:
done_points -= 1
if(sent[i] == "+"):
sent_points += 1
... | Title: Dreamoon and WiFi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go... | ```python
import itertools
def find_prob(done, sent):
interrogatins = 0
done_points = 0
sent_points = 0
for i in range(len(sent)):
if(done[i] == "+"):
done_points += 1
else:
done_points -= 1
if(sent[i] == "+"):
sent_points +=... | 3 | |
548 | B | Mike and Fun | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"greedy",
"implementation"
] | null | null | Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of row number *i* by (*i*,<=*j*). Mike's hands are on his ears (since he's the judge) and each bear s... | The first line of input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=500 and 1<=≤<=*q*<=≤<=5000).
The next *n* lines contain the grid description. There are *m* integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next *q* lines contain the inf... | After each round, print the current score of the bears. | [
"5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3\n"
] | [
"3\n4\n3\n3\n4\n"
] | none | 1,000 | [
{
"input": "5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3",
"output": "3\n4\n3\n3\n4"
},
{
"input": "2 2 10\n1 1\n0 1\n1 1\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 2\n1 1\n1 1",
"output": "1\n2\n2\n2\n1\n1\n1\n1\n2\n1"
},
{
"input": "2 2 10\n1 1\n0 1\n2 2\n2 2\n1 1\... | 1,432,661,328 | 3,228 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 62 | 0 | from io import StringIO
data = StringIO("""5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3""")
def score_line(row):
score = 0
max_score = 0
combo = False
for b in row:
if b == 1:
if combo:
score += 1
else:
... | Title: Mike and Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of ... | ```python
from io import StringIO
data = StringIO("""5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3""")
def score_line(row):
score = 0
max_score = 0
combo = False
for b in row:
if b == 1:
if combo:
score += 1
else... | 0 | |
981 | D | Bookshelves | PROGRAMMING | 1,900 | [
"bitmasks",
"dp",
"greedy"
] | null | null | Mr Keks is a typical white-collar in Byteland.
He has a bookshelf in his office with some books on it, each book has an integer positive price.
Mr Keks defines the value of a shelf as the sum of books prices on it.
Miraculously, Mr Keks was promoted and now he is moving into a new office.
He learned that in the ne... | The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 50$) — the number of books and the number of shelves in the new office.
The second line contains $n$ integers $a_1, a_2, \ldots a_n$, ($0 < a_i < 2^{50}$) — the prices of the books in the order they stand on the old shelf. | Print the maximum possible beauty of $k$ shelves in the new office. | [
"10 4\n9 14 28 1 7 13 15 29 2 31\n",
"7 3\n3 14 15 92 65 35 89\n"
] | [
"24\n",
"64\n"
] | In the first example you can split the books as follows:
$$(9 + 14 + 28 + 1 + 7) \& (13 + 15) \& (29 + 2) \& (31) = 24.$$
In the second example you can split the books as follows:
$$(3 + 14 + 15 + 92) \& (65) \& (35 + 89) = 64.$$ | 1,750 | [
{
"input": "10 4\n9 14 28 1 7 13 15 29 2 31",
"output": "24"
},
{
"input": "7 3\n3 14 15 92 65 35 89",
"output": "64"
},
{
"input": "40 5\n6 18 24 5 14 16 31 9 15 5 25 2 18 12 19 27 10 23 23 18 22 14 1 14 6 14 17 28 11 21 8 23 10 30 21 5 17 11 26 16",
"output": "80"
},
{
"inp... | 1,689,222,281 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 64 | 655 | 50,995,200 | n,k = map(int, input().split())
a = list(map(int, input().split()))
dp = [[set() for _ in range(k)] for _ in range(n)]
for i in range(n - 1,-1,-1):
x = a[i]
for j in range(i + 1, n):
for d in range(k - 1):
for y in dp[j][d]:
dp[i][d + 1].add(x & y)
x += a[j]
... | Title: Bookshelves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr Keks is a typical white-collar in Byteland.
He has a bookshelf in his office with some books on it, each book has an integer positive price.
Mr Keks defines the value of a shelf as the sum of books prices on it.
Mira... | ```python
n,k = map(int, input().split())
a = list(map(int, input().split()))
dp = [[set() for _ in range(k)] for _ in range(n)]
for i in range(n - 1,-1,-1):
x = a[i]
for j in range(i + 1, n):
for d in range(k - 1):
for y in dp[j][d]:
dp[i][d + 1].add(x & y)
... | 3 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,696,246,205 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | calories = list(map(int, input().split()))
s = input()
total_calories = 0
strip_index = int(char) - 1
total_calories += calories[strip_index]
print(total_calories) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
calories = list(map(int, input().split()))
s = input()
total_calories = 0
strip_index = int(char) - 1
total_calories += calories[strip_index]
print(total_calories)
``` | -1 | |
515 | C | Drazil and Factorial | PROGRAMMING | 1,400 | [
"greedy",
"math",
"sortings"
] | null | null | Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they shoul... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. | Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. | [
"4\n1234\n",
"3\n555\n"
] | [
"33222\n",
"555\n"
] | In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "4\n1234",
"output": "33222"
},
{
"input": "3\n555",
"output": "555"
},
{
"input": "15\n012345781234578",
"output": "7777553333222222222222"
},
{
"input": "1\n8",
"output": "7222"
},
{
"input": "10\n1413472614",
"output": "75333332222222"
},
{
... | 1,661,260,098 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 0 | n,s,f=int(input()),input(),""
for i in s:
a=int(i)
if a==2: g=2
elif a==3: g=3
elif a==4: g=322
elif a==5: g=5
elif a==6: g=53
elif a==7: g=7
elif a==8: g=7222
elif a==9: g=7332
else: continue
f+=str(g)
h=sorted(f,reverse=True)
for i in h: print(i,end="") | Title: Drazil and Factorial
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that cont... | ```python
n,s,f=int(input()),input(),""
for i in s:
a=int(i)
if a==2: g=2
elif a==3: g=3
elif a==4: g=322
elif a==5: g=5
elif a==6: g=53
elif a==7: g=7
elif a==8: g=7222
elif a==9: g=7332
else: continue
f+=str(g)
h=sorted(f,reverse=True)
for i in h: print(i,end=... | 3 | |
766 | B | Mahmoud and a Triangle | PROGRAMMING | 1,000 | [
"constructive algorithms",
"geometry",
"greedy",
"math",
"number theory",
"sortings"
] | null | null | Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments... | The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has. | In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise. | [
"5\n1 5 3 2 4\n",
"3\n4 1 2\n"
] | [
"YES\n",
"NO\n"
] | For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle. | 1,000 | [
{
"input": "5\n1 5 3 2 4",
"output": "YES"
},
{
"input": "3\n4 1 2",
"output": "NO"
},
{
"input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576",
"output": "NO"
},... | 1,655,541,945 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 20 | 93 | 7,884,800 | n, f=int(input()), 0
a=list(map(int,input().split()))
a.sort()
if a[n-1]<a[n-2]+a[n-3]:
print("YES")
else:
print("NO")
| Title: Mahmoud and a Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he ca... | ```python
n, f=int(input()), 0
a=list(map(int,input().split()))
a.sort()
if a[n-1]<a[n-2]+a[n-3]:
print("YES")
else:
print("NO")
``` | 0 | |
40 | A | Find Color | PROGRAMMING | 1,300 | [
"constructive algorithms",
"geometry",
"implementation",
"math"
] | A. Find Color | 2 | 256 | Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin correspond... | The first and single line contains two integers *x* and *y* — the coordinates of the hole made in the clock by the ball. Each of the numbers *x* and *y* has an absolute value that does not exceed 1000. | Find the required color.
All the points between which and the origin of coordinates the distance is integral-value are painted black. | [
"-2 1\n",
"2 1\n",
"4 3\n"
] | [
"white\n",
"black\n",
"black\n"
] | none | 500 | [
{
"input": "-2 1",
"output": "white"
},
{
"input": "2 1",
"output": "black"
},
{
"input": "4 3",
"output": "black"
},
{
"input": "3 3",
"output": "black"
},
{
"input": "4 4",
"output": "white"
},
{
"input": "-4 4",
"output": "black"
},
{
"i... | 1,628,690,915 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 154 | 6,758,400 | a,b=input().split( )
c=(int(a)**2+int(b)**2)**.5
d=int(a)*int(b)
if d>0:
if c%2>1:
print('white')
else:
print('black')
elif d<0:
if 0<c%2<1:
print('white')
else:
print('black')
else:
print('black') | Title: Find Color
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. Th... | ```python
a,b=input().split( )
c=(int(a)**2+int(b)**2)**.5
d=int(a)*int(b)
if d>0:
if c%2>1:
print('white')
else:
print('black')
elif d<0:
if 0<c%2<1:
print('white')
else:
print('black')
else:
print('black')
``` | 3.948911 |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,649,151,588 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a, b = [int(x) for x in input().split()];
c = 0;
c += a;
while a != 0:
a //= b;
c += a;
print(c) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
a, b = [int(x) for x in input().split()];
c = 0;
c += a;
while a != 0:
a //= b;
c += a;
print(c)
``` | 0 | |
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
... | 1,618,034,761 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | n = int(input())
arr = list(map(int,input().split()))
arr.sort()
p = 0
for i in range(n):
if(arr[i]!=i+1):
p = i+1
break
if(p==0):
print(n+1)
else:
print(p) | Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the... | ```python
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
p = 0
for i in range(n):
if(arr[i]!=i+1):
p = i+1
break
if(p==0):
print(n+1)
else:
print(p)
``` | 3.969 |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,676,537,401 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 154 | 1,945,600 | n, m = map(int, input().split(' '))
c = 0;mx = max(n, m) + 1
for a in range(mx):
for b in range(mx):
if a * a + b == n and a + b * b == m:c += 1
print(c)
| Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
n, m = map(int, input().split(' '))
c = 0;mx = max(n, m) + 1
for a in range(mx):
for b in range(mx):
if a * a + b == n and a + b * b == m:c += 1
print(c)
``` | 3 | |
748 | A | Santa Claus and a Place in a Class | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar... | The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla... | 500 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"... | 1,482,657,240 | 540 | Python 3 | OK | TESTS | 46 | 77 | 4,608,000 | q,w,e=map(int,input().split())
if e%2==1:
c='L'
else:
c='R'
e=(e+1)//2
x=e%w
if x==0:
x=w
if e%w==0:
z=e//w
else:
z=e//w+1
print(z,x,c)
| Title: Santa Claus and a Place in a Class
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two work... | ```python
q,w,e=map(int,input().split())
if e%2==1:
c='L'
else:
c='R'
e=(e+1)//2
x=e%w
if x==0:
x=w
if e%w==0:
z=e//w
else:
z=e//w+1
print(z,x,c)
``` | 3 | |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,684,264,606 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 0 |
n = int(input())
events = [int(x) for x in input().split()]
recruited = 0
crimes = 0
for event in events:
if event > 0:
recruited += event
else:
if recruited > 0:
recruited += 1
else:
crimes += 1
print(crimes) | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
n = int(input())
events = [int(x) for x in input().split()]
recruited = 0
crimes = 0
for event in events:
if event > 0:
recruited += event
else:
if recruited > 0:
recruited += 1
else:
crimes += 1
print(crimes)
``` | 0 | |
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris a... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and t... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ... | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
... | 1,685,740,470 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 93 | 3,379,200 | ans = []
yes = 0
for _ in range(int(input())):
a = list(input())
if a[0] == a[1] == 'O':
if yes == 0:
a[0] = '+'
a[1] = '+'
yes = 1
elif a[3] == a[4] == 'O':
if yes == 0:
a[3] = '+'
a[4] = '+'
yes = 1
s... | Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pai... | ```python
ans = []
yes = 0
for _ in range(int(input())):
a = list(input())
if a[0] == a[1] == 'O':
if yes == 0:
a[0] = '+'
a[1] = '+'
yes = 1
elif a[3] == a[4] == 'O':
if yes == 0:
a[3] = '+'
a[4] = '+'
yes ... | 3 | |
672 | B | Different is Good | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | 1,000 | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"outp... | 1,599,096,916 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 109 | 307,200 | n = int(input())
s = input()
x = len(s)
l = set(s)
y = len(l)
if n>26:
print(-1)
else:
print(x-y) | Title: Different is Good
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di... | ```python
n = int(input())
s = input()
x = len(s)
l = set(s)
y = len(l)
if n>26:
print(-1)
else:
print(x-y)
``` | 3 | |
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"... | 1,631,378,378 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 21,504,000 | def test():
n = int(input())
if n < 10:
print(n)
return ''
ans = 9
s = 10
while s * 10 < n:
ans += (s * 10 - s) * len(str(s))
s *= 10
while s <= n:
ans += len(str(s))
s += 1
print(ans)
t = 1
while t:
t -= 1
test() | Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig... | ```python
def test():
n = int(input())
if n < 10:
print(n)
return ''
ans = 9
s = 10
while s * 10 < n:
ans += (s * 10 - s) * len(str(s))
s *= 10
while s <= n:
ans += len(str(s))
s += 1
print(ans)
t = 1
while t:
t -= 1
test()
``` | 0 | |
883 | F | Lost in Transliteration | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland s... | The first line contains integer number *n* (2<=≤<=*n*<=≤<=400) — number of the words in the list.
The following *n* lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. | Print the minimal number of groups where the words in each group denote the same name. | [
"10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n",
"9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi\n",
"2\nalex\nalex\n"
] | [
"4\n",
"5\n",
"1\n"
] | There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail" 1. "oolyana", "ulyana" 1. "kooooper", "koouper" 1. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "... | 0 | [
{
"input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon",
"output": "4"
},
{
"input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi",
"output": "5"
},
{
"input": "2\nalex\nalex",
"output": "1"
},
{
"input": ... | 1,624,164,088 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 77 | 0 | t=int(input())
l=[]
p=['kkkkkkkkkkkkkkkkkkkh', 'kkkkkkkkkkkkkkkkkkh', 'kkkkkkkkkkkkkkkkkh', 'kkkkkkkkkkkkkkkkh', 'kkkkkkkkkkkkkkkh', 'kkkkkkkkkkkkkkh', 'kkkkkkkkkkkkkh', 'kkkkkkkkkkkkh', 'kkkkkkkkkkkh', 'kkkkkkkkkkh', 'kkkkkkkkkh', 'kkkkkkkkh', 'kkkkkkkh', 'kkkkkkh', 'kkkkkh', 'kkkkh', 'kkkh', 'kkh', 'kh']
for i in ... | Title: Lost in Transliteration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For thi... | ```python
t=int(input())
l=[]
p=['kkkkkkkkkkkkkkkkkkkh', 'kkkkkkkkkkkkkkkkkkh', 'kkkkkkkkkkkkkkkkkh', 'kkkkkkkkkkkkkkkkh', 'kkkkkkkkkkkkkkkh', 'kkkkkkkkkkkkkkh', 'kkkkkkkkkkkkkh', 'kkkkkkkkkkkkh', 'kkkkkkkkkkkh', 'kkkkkkkkkkh', 'kkkkkkkkkh', 'kkkkkkkkh', 'kkkkkkkh', 'kkkkkkh', 'kkkkkh', 'kkkkh', 'kkkh', 'kkh', 'kh']
... | 3 | |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,696,125,221 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 0 | x=[input().split(" ") for i in range(1,6,1)]
for a in range(1,6,1):
for b in range(1,6,1):
if x[a-1][b-1]=="1":
s=abs(a-3)+abs(b-3)
print(s) | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
x=[input().split(" ") for i in range(1,6,1)]
for a in range(1,6,1):
for b in range(1,6,1):
if x[a-1][b-1]=="1":
s=abs(a-3)+abs(b-3)
print(s)
``` | 3 | |
474 | A | Keyboard | PROGRAMMING | 900 | [
"implementation"
] | null | null | Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That mean... | First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right).
Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain ... | Print a line that contains the original message. | [
"R\ns;;upimrrfod;pbr\n"
] | [
"allyouneedislove\n"
] | none | 500 | [
{
"input": "R\ns;;upimrrfod;pbr",
"output": "allyouneedislove"
},
{
"input": "R\nwertyuiop;lkjhgfdsxcvbnm,.",
"output": "qwertyuiolkjhgfdsazxcvbnm,"
},
{
"input": "L\nzxcvbnm,kjhgfdsaqwertyuio",
"output": "xcvbnm,.lkjhgfdswertyuiop"
},
{
"input": "R\nbubbuduppudup",
"outp... | 1,681,473,135 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 78 | 0 | let = "qwertyuiopasdfghjkl;zxcvbnm,./"
shifting = input()
characters = input()
if shifting == "R":
for i in characters:
x = let.index(i)
print(f"{let[x-1]}", end="")
else:
for i in characters:
x = let.index(i)
print(f"{let[x+1]}", end="")
| Title: Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately.... | ```python
let = "qwertyuiopasdfghjkl;zxcvbnm,./"
shifting = input()
characters = input()
if shifting == "R":
for i in characters:
x = let.index(i)
print(f"{let[x-1]}", end="")
else:
for i in characters:
x = let.index(i)
print(f"{let[x+1]}", end="")
``` | 3 | |
864 | B | Polycarp and Letters | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from *A* in the string are all distinct and lowerc... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*.
The second line contains a string *s* consisting of lowercase and uppercase Latin letters. | Print maximum number of elements in pretty set of positions for string *s*. | [
"11\naaaaBaabAbA\n",
"12\nzACaAbbaazzC\n",
"3\nABC\n"
] | [
"2\n",
"3\n",
"0\n"
] | In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There... | 1,000 | [
{
"input": "11\naaaaBaabAbA",
"output": "2"
},
{
"input": "12\nzACaAbbaazzC",
"output": "3"
},
{
"input": "3\nABC",
"output": "0"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\naz",
"output": "2"
},
{
"input": "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLr... | 1,696,342,542 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 55 | 77 | 1,536,000 | n = int(input())
s = str(input())
res = 0
for start in range(n):
vals = set()
for end in range(start, n):
if s[end].islower():
vals.add(s[end])
else:
break
res = max(res, len(vals))
print(res) | Title: Polycarp and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if... | ```python
n = int(input())
s = str(input())
res = 0
for start in range(n):
vals = set()
for end in range(start, n):
if s[end].islower():
vals.add(s[end])
else:
break
res = max(res, len(vals))
print(res)
``` | 3 | |
499 | A | Watching a movie | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie... | The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button.
The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains tw... | Output a single number — the answer to the problem. | [
"2 3\n5 6\n10 12\n",
"1 1\n1 100000\n"
] | [
"6\n",
"100000\n"
] | In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch th... | 500 | [
{
"input": "2 3\n5 6\n10 12",
"output": "6"
},
{
"input": "1 1\n1 100000",
"output": "100000"
},
{
"input": "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728",
"output": "53974"
},
{
"input": "1... | 1,694,781,693 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | def solve():
n, x = map(int, input().split())
a = []
for i in range(n):
temp = list(map(int, input().split()))
a.append(temp)
i = 0
cur = 1
res = 0
while i < len(a):
if cur <= a[i][0] - x:
cur += ((a[i][0] - cur + 1) // x) * x
res += a[... | Title: Watching a movie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the pl... | ```python
def solve():
n, x = map(int, input().split())
a = []
for i in range(n):
temp = list(map(int, input().split()))
a.append(temp)
i = 0
cur = 1
res = 0
while i < len(a):
if cur <= a[i][0] - x:
cur += ((a[i][0] - cur + 1) // x) * x
... | 0 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,694,528,929 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | p,e,w=map(int,input().split())
s=((2*p+p*(w-1))/2)*w
if e>=s:
print(0)
else:
a=s-e
print(int(a)) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
p,e,w=map(int,input().split())
s=((2*p+p*(w-1))/2)*w
if e>=s:
print(0)
else:
a=s-e
print(int(a))
``` | 3 | |
632 | A | Grandma Laura and Apples | PROGRAMMING | 1,200 | [] | null | null | Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and ... | The first line contains two integers *n* and *p* (1<=≤<=*n*<=≤<=40,<=2<=≤<=*p*<=≤<=1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even.
The next *n* lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of th... | Print the only integer *a* — the total money grandma should have at the end of the day.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"2 10\nhalf\nhalfplus\n",
"3 10\nhalfplus\nhalfplus\nhalfplus\n"
] | [
"15\n",
"55\n"
] | In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer. | 0 | [
{
"input": "2 10\nhalf\nhalfplus",
"output": "15"
},
{
"input": "3 10\nhalfplus\nhalfplus\nhalfplus",
"output": "55"
},
{
"input": "10 328\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalfplus",
"output": "258300"
},
{
"input": "1 2\nhalfplus",
"... | 1,688,368,579 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 9 | 62 | 0 | n,p=map(int,input().split())
ls=[]
for i in range(n):
x=input()
ls.append(x)
ls.reverse()
s=0
cnt=0
for i in ls:
if i=='halfplus':
s=(s+0.5)*2
cnt+=1
else:
s=s*2
print(int((s-cnt*0.5)*p)) | Title: Grandma Laura and Apples
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers sh... | ```python
n,p=map(int,input().split())
ls=[]
for i in range(n):
x=input()
ls.append(x)
ls.reverse()
s=0
cnt=0
for i in ls:
if i=='halfplus':
s=(s+0.5)*2
cnt+=1
else:
s=s*2
print(int((s-cnt*0.5)*p))
``` | 3 | |
126 | E | Pills | PROGRAMMING | 2,900 | [
"brute force",
"flows"
] | null | null | Doctor prescribed medicine to his patient. The medicine is represented by pills. Each pill consists of a shell and healing powder. The shell consists of two halves; each half has one of four colors — blue, red, white or yellow.
The doctor wants to put 28 pills in a rectangular box 7<=×<=8 in size. Besides, each pill o... | First 7 lines contain the doctor's picture. Each line contains 8 characters, each character can be "B", "R", "W" and "Y" that stands for blue, red, white and yellow colors correspondingly.
Next four lines contain 10 numbers that stand for, correspondingly, the number of pills painted:
"BY" "BW" "BR" "BB"
"RY" "RW" "... | Print on the first line the maximal number cells for which the colors match.
Then print 13 lines each containing 15 characters — the pills' position in the optimal arrangement. The intersections of odd lines and odd columns should contain characters "B", "R", "W" and "Y". All other positions should contain characters ... | [
"WWWBBWWW\nWWWBBWWW\nYYWBBWWW\nYYWBBWRR\nYYWBBWRR\nYYWBBWRR\nYYWBBWRR\n0 0 0 8\n0 1 5\n1 10\n5\n",
"WWWWWWWW\nWBYWRBBY\nBRYRBWYY\nWWBRYWBB\nBWWRWBYW\nRBWRBWYY\nWWWWWWWW\n0 0 0 1\n0 0 1\n0 1\n25\n"
] | [
"53\nW.W.W.B.B.W.W.W\n|.|.|.|.|.|.|.|\nW.W.W.B.B.W.W.W\n...............\nY.Y.W.B.B.W.W-W\n|.|.|.|.|.|....\nY.Y.W.B.B.W.R.R\n............|.|\nY.Y.W.B.B.R.R.R\n|.|.|.|.|.|....\nY.Y.W.B.B.W.R.R\n............|.|\nY-Y.B-B.B-B.R.R\n",
"15\nW.Y.Y-Y.Y-Y.Y-Y\n|.|............\nW.Y.Y.Y.Y.B-B.Y\n....|.|.|.....|\nY-Y.Y.Y.Y.Y-... | none | 2,500 | [] | 1,693,181,023 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1693181023.562075")# 1693181023.562091 | Title: Pills
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Doctor prescribed medicine to his patient. The medicine is represented by pills. Each pill consists of a shell and healing powder. The shell consists of two halves; each half has one of four colors — blue, red, white or yellow.
... | ```python
print("_RANDOM_GUESS_1693181023.562075")# 1693181023.562091
``` | 0 | |
92 | A | Chips | PROGRAMMING | 800 | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The pre... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ... | 500 | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "... | 1,595,425,069 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 216 | 6,656,000 | x,y=map(int,input().split())
r=1
while y>=r:
y-=r
r+=1
if r==x+1:
r=1
print(y)
| Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
x,y=map(int,input().split())
r=1
while y>=r:
y-=r
r+=1
if r==x+1:
r=1
print(y)
``` | 3.933602 |
716 | B | Complete the Word | PROGRAMMING | 1,300 | [
"greedy",
"two pointers"
] | null | null | ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not n... | The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember... | If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks... | [
"ABC??FGHIJK???OPQR?TUVWXY?\n",
"WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n",
"??????????????????????????\n",
"AABCDEFGHIJKLMNOPQRSTUVW??M\n"
] | [
"ABCDEFGHIJKLMNOPQRZTUVWXYS",
"-1",
"MNBVCXZLKJHGFDSAQPWOEIRUYT",
"-1"
] | In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZT... | 1,000 | [
{
"input": "ABC??FGHIJK???OPQR?TUVWXY?",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO",
"output": "-1"
},
{
"input": "??????????????????????????",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "AABCDEFGHIJKLMNO... | 1,655,985,257 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 46 | 512,000 | zs = input()
alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if len(zs) < 26:
print(-1)
elif len(set(zs.replace("?", ''))) + zs.count("?") < 26:
print(-1)
else:
l, r = 0, 1
check = ''
for i in range(len(zs)):
if zs[i] not in check or zs[i] == "?":
check += zs[i]
r +... | Title: Complete the Word
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In pa... | ```python
zs = input()
alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if len(zs) < 26:
print(-1)
elif len(set(zs.replace("?", ''))) + zs.count("?") < 26:
print(-1)
else:
l, r = 0, 1
check = ''
for i in range(len(zs)):
if zs[i] not in check or zs[i] == "?":
check += zs[i]
... | 0 | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,604,315,196 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 140 | 2,457,600 | a=b=int(input())
num=-1
key=1
for i in range(b):
l=input()
a-=1
num+=1
if i==0:
z=l[0]
x=l[1]
if z==x:
key=0
for u in range(b):
if u==a or u==num:
if l[u] != z:
key=0
else:
if l[u]!=x:
... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
a=b=int(input())
num=-1
key=1
for i in range(b):
l=input()
a-=1
num+=1
if i==0:
z=l[0]
x=l[1]
if z==x:
key=0
for u in range(b):
if u==a or u==num:
if l[u] != z:
key=0
else:
if l[u]!... | 3 | |
574 | B | Bear and Three Musketeers | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"graphs",
"hashing"
] | null | null | Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose thre... | The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other.
*i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**... | If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). | [
"5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n",
"7 4\n2 1\n3 6\n5 1\n1 7\n"
] | [
"2\n",
"-1\n"
] | In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recogniti... | 1,000 | [
{
"input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5",
"output": "2"
},
{
"input": "7 4\n2 1\n3 6\n5 1\n1 7",
"output": "-1"
},
{
"input": "5 0",
"output": "-1"
},
{
"input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4",
"output": "5"
},
{
... | 1,613,605,087 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 204,800 | # K - 2, Assignment 4, bd2255
# contributions to the solution: Daniel Perez
temps = []
def helper(K, D, S, SET):
if S == 3:
temps.append(SET + [K])
return
SET = SET + [K]
for a in D[K]:
helper(a, D, S + 1, SET)
def rainy(D):
recognition = 9999999
# find raw trios
thre... | Title: Bear and Three Musketeers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three br... | ```python
# K - 2, Assignment 4, bd2255
# contributions to the solution: Daniel Perez
temps = []
def helper(K, D, S, SET):
if S == 3:
temps.append(SET + [K])
return
SET = SET + [K]
for a in D[K]:
helper(a, D, S + 1, SET)
def rainy(D):
recognition = 9999999
# find raw trio... | 0 | |
276 | C | Little Girl and Maximum Sum | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"implementation",
"sortings"
] | null | null | The little girl loves the problems on array queries very much.
One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)... | The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly.
The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements.
Each of ... | In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3 3\n5 3 2\n1 2\n2 3\n1 3\n",
"5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n"
] | [
"25\n",
"33\n"
] | none | 1,500 | [
{
"input": "3 3\n5 3 2\n1 2\n2 3\n1 3",
"output": "25"
},
{
"input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3",
"output": "33"
},
{
"input": "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\... | 1,690,782,568 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 530 | 17,305,600 | import sys
import math
# Fast input
input = sys.stdin.readline
# Fast output
def print(*args, **kwargs):
sep = kwargs.get('sep', ' ')
end = kwargs.get('end', '\n')
file = kwargs.get('file', sys.stdout)
flush = kwargs.get('flush', False)
output = sep.join(map(str, args)) + end
file.wri... | Title: Little Girl and Maximum Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The little girl loves the problems on array queries very much.
One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1... | ```python
import sys
import math
# Fast input
input = sys.stdin.readline
# Fast output
def print(*args, **kwargs):
sep = kwargs.get('sep', ' ')
end = kwargs.get('end', '\n')
file = kwargs.get('file', sys.stdout)
flush = kwargs.get('flush', False)
output = sep.join(map(str, args)) + end
... | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,567,280,374 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | a=input()
d=input()
s=''
b=len(a)*['']
c=''
for i in range(len(a)):
b[i]=a[i]
if len(a)<=100:
for i in range(len(a)):
c=b[i]+c
if c==d:
print('yes')
else:
print('no')
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
a=input()
d=input()
s=''
b=len(a)*['']
c=''
for i in range(len(a)):
b[i]=a[i]
if len(a)<=100:
for i in range(len(a)):
c=b[i]+c
if c==d:
print('yes')
else:
print('no')
``` | 0 |
820 | A | Mister B and Book Reading | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at ... | First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=<<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages fo... | Print one integer — the number of days Mister B needed to finish the book. | [
"5 5 10 5 4\n",
"12 4 12 4 1\n",
"15 1 100 0 0\n"
] | [
"1\n",
"3\n",
"15\n"
] | In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished... | 500 | [
{
"input": "5 5 10 5 4",
"output": "1"
},
{
"input": "12 4 12 4 1",
"output": "3"
},
{
"input": "15 1 100 0 0",
"output": "15"
},
{
"input": "1 1 1 0 0",
"output": "1"
},
{
"input": "1000 999 1000 1000 998",
"output": "2"
},
{
"input": "1000 2 2 5 1",
... | 1,606,179,946 | 2,147,483,647 | Python 3 | OK | TESTS | 110 | 109 | 0 | # https://codeforces.com/problemset/problem/820/A
# 900
c,v0,v1,a,l = map(int, input().split())
d = 0
p = 0
while True:
p += v0
d += 1
if p >= c:
break
v0 += a
if v0 > v1:
v0 = v1
p -= l
print(d) | Title: Mister B and Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, ... | ```python
# https://codeforces.com/problemset/problem/820/A
# 900
c,v0,v1,a,l = map(int, input().split())
d = 0
p = 0
while True:
p += v0
d += 1
if p >= c:
break
v0 += a
if v0 > v1:
v0 = v1
p -= l
print(d)
``` | 3 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,588,513,444 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 109 | 0 | # https://codeforces.com/contest/378/problem/A
a, b = map(int, input().split())
a_wins = draw = b_wins = 0
for i in range(1, 7):
if abs(a - i) < abs(b - i):
a_wins += 1
elif abs(a - i) == abs(b - i):
draw += 1
else:
b_wins += 1
print(a_wins, draw, b_wins) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
# https://codeforces.com/contest/378/problem/A
a, b = map(int, input().split())
a_wins = draw = b_wins = 0
for i in range(1, 7):
if abs(a - i) < abs(b - i):
a_wins += 1
elif abs(a - i) == abs(b - i):
draw += 1
else:
b_wins += 1
print(a_wins, draw, b_wins)
``` | 3 | |
229 | B | Planets | PROGRAMMING | 1,700 | [
"binary search",
"data structures",
"graphs",
"shortest paths"
] | null | null | Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repeatedly go through stargates to get to this planet.
Overall the galaxy has *... | The first line contains two space-separated integers: *n* (2<=≤<=*n*<=≤<=105), the number of planets in the galaxy, and *m* (0<=≤<=*m*<=≤<=105) — the number of pairs of planets between which Jack can travel using stargates. Then *m* lines follow, containing three integers each: the *i*-th line contains numbers of plane... | Print a single number — the least amount of time Jack needs to get from planet 1 to planet *n*. If Jack can't get to planet *n* in any amount of time, print number -1. | [
"4 6\n1 2 2\n1 3 3\n1 4 8\n2 3 4\n2 4 5\n3 4 3\n0\n1 3\n2 3 4\n0\n",
"3 1\n1 2 3\n0\n1 3\n0\n"
] | [
"7\n",
"-1\n"
] | In the first sample Jack has three ways to go from planet 1. If he moves to planet 4 at once, he spends 8 seconds. If he transfers to planet 3, he spends 3 seconds, but as other travellers arrive to planet 3 at time 3 and 4, he can travel to planet 4 only at time 5, thus spending 8 seconds in total. But if Jack moves t... | 500 | [
{
"input": "4 6\n1 2 2\n1 3 3\n1 4 8\n2 3 4\n2 4 5\n3 4 3\n0\n1 3\n2 3 4\n0",
"output": "7"
},
{
"input": "3 1\n1 2 3\n0\n1 3\n0",
"output": "-1"
},
{
"input": "2 1\n1 2 3\n0\n1 3",
"output": "3"
},
{
"input": "2 1\n1 2 3\n1 0\n0",
"output": "4"
},
{
"input": "3 3... | 1,696,153,197 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | def deikstra(n, edges, wait_time):
dist = [float('inf')] * n
dist[0] = 0
visited = [False] * n
while True:
u = -1
for i in range(n):
if not visited[i] and (u == -1 or dist[i] < dist[-1]):
u = i
if u == -1:
break
visited[u... | Title: Planets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friend... | ```python
def deikstra(n, edges, wait_time):
dist = [float('inf')] * n
dist[0] = 0
visited = [False] * n
while True:
u = -1
for i in range(n):
if not visited[i] and (u == -1 or dist[i] < dist[-1]):
u = i
if u == -1:
break
... | 0 | |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,619,542,801 | 2,147,483,647 | PyPy 3 | OK | TESTS | 80 | 218 | 1,945,600 | n = int(input())
height = list(map(int,input().split()))
ans = 1
for i in range(n):
count = 1
for j in range(i,0,-1):
if (height[j-1] <= height[j]):
count += 1
else:
break
for j in range(i,n-1):
if (height[j+1] <= height[j]):
count +=... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
n = int(input())
height = list(map(int,input().split()))
ans = 1
for i in range(n):
count = 1
for j in range(i,0,-1):
if (height[j-1] <= height[j]):
count += 1
else:
break
for j in range(i,n-1):
if (height[j+1] <= height[j]):
... | 3.941876 |
660 | C | Hard Process | PROGRAMMING | 1,600 | [
"binary search",
"dp",
"two pointers"
] | null | null | You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*. | On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones.
On the second line print *n* integers *a**j* — the elements of the array *a* after the changes.
If there are multiple answers, you can print any one of them. | [
"7 1\n1 0 0 1 1 0 1\n",
"10 2\n1 0 0 1 0 1 0 1 0 1\n"
] | [
"4\n1 0 0 1 1 1 1\n",
"5\n1 0 0 1 1 1 1 1 0 1\n"
] | none | 0 | [
{
"input": "7 1\n1 0 0 1 1 0 1",
"output": "4\n1 0 0 1 1 1 1"
},
{
"input": "10 2\n1 0 0 1 0 1 0 1 0 1",
"output": "5\n1 0 0 1 1 1 1 1 0 1"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "7 0\n0 1 0 0 0 1 0",
"o... | 1,491,825,930 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | n ,k = map(int,input().split())
a = list(map(int,input().split()))
a.append(2)
l = []
p = 0
S = a[0]
NS = 0
for i in range(len(a)):
if a[i] == S:
p += 1
else:
if S==1:
l.append(p)
p = 1
S = a[i]
if a[i]==0:
NS += 1
... | Title: Hard Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can ch... | ```python
n ,k = map(int,input().split())
a = list(map(int,input().split()))
a.append(2)
l = []
p = 0
S = a[0]
NS = 0
for i in range(len(a)):
if a[i] == S:
p += 1
else:
if S==1:
l.append(p)
p = 1
S = a[i]
if a[i]==0:
... | 0 | |
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen... | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $... | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"... | 1,684,913,236 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 61 | 0 | n, m = map(int, input().split())
sequence = list(map(int, input().split()))
buttons = list(map(int, input().split()))
code = []
for digit in sequence:
if digit in buttons:
code.append(digit)
print(*code)
| Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keyp... | ```python
n, m = map(int, input().split())
sequence = list(map(int, input().split()))
buttons = list(map(int, input().split()))
code = []
for digit in sequence:
if digit in buttons:
code.append(digit)
print(*code)
``` | 3 | |
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "4... | 1,669,212,002 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 46 | 0 | import math
print(math.ceil(int(input())/4)-1) | Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv... | ```python
import math
print(math.ceil(int(input())/4)-1)
``` | 0 | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,574,712,079 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 684 | 2,048,000 | from collections import deque
from math import ceil
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc="abcdefghijklmnopqrstuvwxyz"
s=si()
n=len(s)
f=0
b=[]
for i in range(len(s)):
if(s[i]=='1'):
b.append(1)
elif(s[i... | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
from collections import deque
from math import ceil
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc="abcdefghijklmnopqrstuvwxyz"
s=si()
n=len(s)
f=0
b=[]
for i in range(len(s)):
if(s[i]=='1'):
b.append(1)
... | 3 | |
295 | A | Greg and Array | PROGRAMMING | 1,400 | [
"data structures",
"implementation"
] | null | null | Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* qu... | The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=... | On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | [
"3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n",
"1 1 1\n1\n1 1 1\n1 1\n",
"4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n"
] | [
"9 18 17\n",
"2\n",
"5 18 31 20\n"
] | none | 500 | [
{
"input": "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3",
"output": "9 18 17"
},
{
"input": "1 1 1\n1\n1 1 1\n1 1",
"output": "2"
},
{
"input": "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3",
"output": "5 18 31 20"
},
{
"input": "1 1 1\n0\n1 1 0\n1 1... | 1,636,088,356 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 4,505,600 |
[n, m, k] = [int(val) for val in input().split()]
# Reading the initial array
array = [int(val) for val in input().split()]
# Reading the operations
ope = []
for _ in range(m):
ope.append([int(val) for val in input().split()])
x = [0]*(m+1)
y = [0]*(n+1)
# Querys
for _ in range(k):
[l, r] = [int(val) for ... | Title: Greg and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array... | ```python
[n, m, k] = [int(val) for val in input().split()]
# Reading the initial array
array = [int(val) for val in input().split()]
# Reading the operations
ope = []
for _ in range(m):
ope.append([int(val) for val in input().split()])
x = [0]*(m+1)
y = [0]*(n+1)
# Querys
for _ in range(k):
[l, r] = [int... | -1 | |
886 | C | Petya and Catacombs | PROGRAMMING | 1,300 | [
"dsu",
"greedy",
"implementation",
"trees"
] | null | null | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook.
The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=<<=*i*) — notes in the logbook. | In the only line print a single integer — the minimum possible number of rooms in Paris catacombs. | [
"2\n0 0\n",
"5\n0 1 0 1 3\n"
] | [
"2\n",
"3\n"
] | In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1. | 1,500 | [
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "5\n0 1 0 1 3",
"output": "3"
},
{
"input": "7\n0 1 0 0 0 0 0",
"output": "6"
},
{
"input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 ... | 1,627,111,217 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 109 | 21,913,600 | # _
#####################################################################################################################
print(int(input()) + 1 - len(set(input().split())))
| Title: Petya and Catacombs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectiona... | ```python
# _
#####################################################################################################################
print(int(input()) + 1 - len(set(input().split())))
``` | 3 | |
493 | D | Vasya and Chess | PROGRAMMING | 1,700 | [
"constructive algorithms",
"games",
"math"
] | null | null | Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell cont... | The input contains a single number *n* (2<=≤<=*n*<=≤<=109) — the size of the board. | On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers *r* and *c* representing the cell (*r*,<=*c*), where the first player should make his first move to win. If ther... | [
"2\n",
"3\n"
] | [
"white\n1 2\n",
"black\n"
] | In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for... | 1,500 | [
{
"input": "2",
"output": "white\n1 2"
},
{
"input": "3",
"output": "black"
},
{
"input": "4",
"output": "white\n1 2"
},
{
"input": "6",
"output": "white\n1 2"
},
{
"input": "10",
"output": "white\n1 2"
},
{
"input": "16",
"output": "white\n1 2"
... | 1,636,887,818 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 4,300,800 | a=int(input())
if a%2==0:
print('white')
print('1 2')
else:
print('black')
| Title: Vasya and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. I... | ```python
a=int(input())
if a%2==0:
print('white')
print('1 2')
else:
print('black')
``` | 3 | |
515 | A | Drazil and Date | PROGRAMMING | 1,000 | [
"math"
] | null | null | Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to ... | You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. | If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes". | [
"5 5 11\n",
"10 15 25\n",
"0 5 1\n",
"0 0 2\n"
] | [
"No\n",
"Yes\n",
"No\n",
"Yes\n"
] | In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "5 5 11",
"output": "No"
},
{
"input": "10 15 25",
"output": "Yes"
},
{
"input": "0 5 1",
"output": "No"
},
{
"input": "0 0 2",
"output": "Yes"
},
{
"input": "999999999 999999999 2000000000",
"output": "Yes"
},
{
"input": "-606037695 9983201... | 1,595,203,824 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 155 | 20,172,800 | l1 = [abs(int(x)) for x in input().split()]
if l1[0]+l1[1]!=l1[2]:
if l1[0]+l1[1]>l1[2]:
print("NO")
elif (l1[0]+l1[1]-l1[2])%2:
print("NO")
else:
print("YES")
else:
print("Yes") | Title: Drazil and Date
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit ... | ```python
l1 = [abs(int(x)) for x in input().split()]
if l1[0]+l1[1]!=l1[2]:
if l1[0]+l1[1]>l1[2]:
print("NO")
elif (l1[0]+l1[1]-l1[2])%2:
print("NO")
else:
print("YES")
else:
print("Yes")
``` | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,688,062,456 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n= input()
x=0
for i in range(len(n)-1):
if n[i]==n[i+1]:
x+=1
if x >=7:
print("YES")
break
else:
continue
else:
x=0
if x <7:
print("NO") | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
n= input()
x=0
for i in range(len(n)-1):
if n[i]==n[i+1]:
x+=1
if x >=7:
print("YES")
break
else:
continue
else:
x=0
if x <7:
print("NO")
``` | 0 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,669,782,261 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | a = input()
b = 0
c = 0
for i in range(len(a)):
if a[i] in a.lower():
b += 1
elif a[i] in a.upper():
c += 1
if b > c or b == c:
print(a.lower())
else:
print(a.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
a = input()
b = 0
c = 0
for i in range(len(a)):
if a[i] in a.lower():
b += 1
elif a[i] in a.upper():
c += 1
if b > c or b == c:
print(a.lower())
else:
print(a.upper())
``` | 3.977 |
421 | A | Pasha and Hamsters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hams... | The first line contains integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=100; 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly.
The next line contains *a* distinct integers — the numbers of the apples Arthur likes. The next line... | Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them. | [
"4 2 3\n1 2\n2 3 4\n",
"5 5 2\n3 4 1 2 5\n2 3\n"
] | [
"1 1 2 2\n",
"1 1 1 1 1\n"
] | none | 500 | [
{
"input": "4 2 3\n1 2\n2 3 4",
"output": "1 1 2 2"
},
{
"input": "5 5 2\n3 4 1 2 5\n2 3",
"output": "1 1 1 1 1"
},
{
"input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 7... | 1,688,467,761 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | # PAsha and hamsters
apples = list(map(int,input().split()))
arthur = list(map(int,input().split()))
alex = list(map(int,input().split()))
n = apples.pop(0)
output = []
for i in range(1, n+1):
if i in arthur and i in alex:
output.append(1)
elif i in arthur and i not in alex:
output... | Title: Pasha and Hamsters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between... | ```python
# PAsha and hamsters
apples = list(map(int,input().split()))
arthur = list(map(int,input().split()))
alex = list(map(int,input().split()))
n = apples.pop(0)
output = []
for i in range(1, n+1):
if i in arthur and i in alex:
output.append(1)
elif i in arthur and i not in alex:
... | 3 | |
960 | A | Check the string | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gi... | The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'. | Print "YES" or "NO", according to the condition. | [
"aaabccc\n",
"bbacc\n",
"aabc\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'. | 500 | [
{
"input": "aaabccc",
"output": "YES"
},
{
"input": "bbacc",
"output": "NO"
},
{
"input": "aabc",
"output": "YES"
},
{
"input": "aabbcc",
"output": "YES"
},
{
"input": "aaacccbb",
"output": "NO"
},
{
"input": "abc",
"output": "YES"
},
{
"in... | 1,613,124,236 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 62 | 0 | s = input(); a = s.count('a'); b = s.count('b'); c = s.count('c')
if a==0 or b==0:
print('No')
exit(0)
ss = ""
for i in sorted(s):
ss = ss + i
#print(ss)
#print(s)
if ss!=s:
print("No")
exit(0)
if (a==c or b==c):
print('Yes')
else:
print('No') | Title: Check the string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b... | ```python
s = input(); a = s.count('a'); b = s.count('b'); c = s.count('c')
if a==0 or b==0:
print('No')
exit(0)
ss = ""
for i in sorted(s):
ss = ss + i
#print(ss)
#print(s)
if ss!=s:
print("No")
exit(0)
if (a==c or b==c):
print('Yes')
else:
print('No')
``` | 3 | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,619,451,237 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 307,200 | import sys,math,bisect
inf = float('inf')
mod = (inf)+7
def lcm(a,b):
return int((a/math.gcd(a,b))*b)
def gcd(a,b):
return int(math.gcd(a,b))
def binarySearch(a,x):
i = bisect.bisect_left(a,x)
if i!=len(a) and a[i]==x:
return i
else:
return -1
def lowerBound(a, x):
i = bisect.bis... | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
import sys,math,bisect
inf = float('inf')
mod = (inf)+7
def lcm(a,b):
return int((a/math.gcd(a,b))*b)
def gcd(a,b):
return int(math.gcd(a,b))
def binarySearch(a,x):
i = bisect.bisect_left(a,x)
if i!=len(a) and a[i]==x:
return i
else:
return -1
def lowerBound(a, x):
i = ... | -1 | |
940 | B | Our Tanya is Crying Out Loud | PROGRAMMING | 1,400 | [
"dp",
"greedy"
] | null | null | Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*.... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109). | Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1. | [
"9\n2\n3\n1\n",
"5\n5\n2\n20\n",
"19\n3\n4\n2\n"
] | [
"6\n",
"8\n",
"12\n"
] | In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtra... | 1,250 | [
{
"input": "9\n2\n3\n1",
"output": "6"
},
{
"input": "5\n5\n2\n20",
"output": "8"
},
{
"input": "19\n3\n4\n2",
"output": "12"
},
{
"input": "1845999546\n999435865\n1234234\n2323423",
"output": "1044857680578777"
},
{
"input": "1604353664\n1604353665\n9993432\n1",
... | 1,585,506,237 | 3,717 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 0 | from sys import stdin
n, k, a, b = [int(stdin.readline()) for i in range(4)]
ans = 0
while n > 1:
div, mod = divmod(n, k)
if mod:
ans += mod * a
n -= mod
if not n:
ans -= a
else:
x1 = a * (n - div)
ans += min(b, x1)
n = div
prin... | Title: Our Tanya is Crying Out Loud
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perf... | ```python
from sys import stdin
n, k, a, b = [int(stdin.readline()) for i in range(4)]
ans = 0
while n > 1:
div, mod = divmod(n, k)
if mod:
ans += mod * a
n -= mod
if not n:
ans -= a
else:
x1 = a * (n - div)
ans += min(b, x1)
n = d... | 0 | |
371 | C | Hamburgers | PROGRAMMING | 1,600 | [
"binary search",
"brute force"
] | null | null | Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (... | The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n... | Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. | [
"BBBSSC\n6 4 1\n1 2 3\n4\n",
"BBC\n1 10 1\n1 10 1\n21\n",
"BSC\n1 1 1\n1 1 3\n1000000000000\n"
] | [
"2\n",
"7\n",
"200000000001\n"
] | none | 1,500 | [
{
"input": "BBBSSC\n6 4 1\n1 2 3\n4",
"output": "2"
},
{
"input": "BBC\n1 10 1\n1 10 1\n21",
"output": "7"
},
{
"input": "BSC\n1 1 1\n1 1 3\n1000000000000",
"output": "200000000001"
},
{
"input": "B\n1 1 1\n1 1 1\n381",
"output": "382"
},
{
"input": "BSC\n3 5 6\n7... | 1,643,955,234 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 77 | 0 | # import bisect
# import operator
# import math
# # from typing import Counter, NewType
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# import math
# import sys
# sys.stdout = open('New cp/output.txt', 'w')
# sys.stdin = open('New cp/input.txt', 'r')
# a=int(input()) #This is for... | Title: Hamburgers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ... | ```python
# import bisect
# import operator
# import math
# # from typing import Counter, NewType
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# import math
# import sys
# sys.stdout = open('New cp/output.txt', 'w')
# sys.stdin = open('New cp/input.txt', 'r')
# a=int(input()) #T... | 3 | |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider t... | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling t... | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
... | 1,630,295,100 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 15,360,000 | t = int(input())
s = list(map(int,input().split()))
m = min(s)
if s.count(m)==1:
print(s.index(m)+1)
else:
print("Still Rozdil") | Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha... | ```python
t = int(input())
s = list(map(int,input().split()))
m = min(s)
if s.count(m)==1:
print(s.index(m)+1)
else:
print("Still Rozdil")
``` | 3 | |
216 | B | Forming Teams | PROGRAMMING | 1,700 | [
"dfs and similar",
"implementation"
] | null | null | One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student *A* is an archenemy to student *B*, then stud... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100) — the number of students and the number of pairs of archenemies correspondingly.
Next *m* lines describe enmity between students. Each enmity is described as two numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=... | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | [
"5 4\n1 2\n2 4\n5 3\n1 4\n",
"6 2\n1 4\n3 4\n",
"6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n"
] | [
"1",
"0",
"2"
] | none | 1,500 | [
{
"input": "5 4\n1 2\n2 4\n5 3\n1 4",
"output": "1"
},
{
"input": "6 2\n1 4\n3 4",
"output": "0"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "2"
},
{
"input": "5 1\n1 2",
"output": "1"
},
{
"input": "8 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 1",
... | 1,659,863,139 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | from collections import defaultdict
n, m = map(int, input().split())
graph = defaultdict(list)
colors = {i:-1 for i in range(1,n+1)}
visited = set()
for _ in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
def dfs(node, color):
colors[node] = color
... | Title: Forming Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each stu... | ```python
from collections import defaultdict
n, m = map(int, input().split())
graph = defaultdict(list)
colors = {i:-1 for i in range(1,n+1)}
visited = set()
for _ in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
def dfs(node, color):
colors[node] = ... | 0 | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,692,296,171 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 46 | 0 | def max_problems_solved(n, k):
total_time = 0
problems_solved = 0
for i in range(1, n + 1):
problem_time = 5 * i
if total_time + problem_time + k <= 240:
total_time += problem_time
problems_solved += 1
else:
break
return problems_... | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
def max_problems_solved(n, k):
total_time = 0
problems_solved = 0
for i in range(1, n + 1):
problem_time = 5 * i
if total_time + problem_time + k <= 240:
total_time += problem_time
problems_solved += 1
else:
break
return... | 3 | |
828 | A | Restaurant Tables | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seate... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2) — the d... | Print the total number of people the restaurant denies service to. | [
"4 1 2\n1 2 1 1\n",
"4 1 1\n1 1 2 1\n"
] | [
"0\n",
"2\n"
] | In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin... | 500 | [
{
"input": "4 1 2\n1 2 1 1",
"output": "0"
},
{
"input": "4 1 1\n1 1 2 1",
"output": "2"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 1 2\n2 2",
"output": "0"
},
{
"input": "5 1 3\n1 2 2 2 1",
"output": "1"
},
{
"input": "7 6 1\n1 1 1 1 1 1... | 1,499,795,211 | 3,711 | Python 3 | CHALLENGED | CHALLENGES | 7 | 187 | 8,192,000 | n, a, b = map(int, input().split())
t = list(map(lambda x: 1 if x == 1 else 2, map(int, input().split())))
# a - колво одноместных.. мест
# b - колво двухместных столов
rem = 0
for i in range(n):
if t[i] == 1:
if a != 0:
a -= 1
elif a == 0 and b != 0:
b -= 1
a += 1
else:
rem += 1
elif t[i] == 2:... | Title: Restaurant Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, i... | ```python
n, a, b = map(int, input().split())
t = list(map(lambda x: 1 if x == 1 else 2, map(int, input().split())))
# a - колво одноместных.. мест
# b - колво двухместных столов
rem = 0
for i in range(n):
if t[i] == 1:
if a != 0:
a -= 1
elif a == 0 and b != 0:
b -= 1
a += 1
else:
rem += 1
elif ... | -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,687,183,516 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n,k=map(int,input().split())
li=list(map(int,input().split()))
count=0
for i in li:
if i<=5-k:
count+=1
print(count//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())
li=list(map(int,input().split()))
count=0
for i in li:
if i<=5-k:
count+=1
print(count//3)
``` | 3 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,656,137,807 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 93 | 2,355,200 | def main():
[n, x] = list(map(int, input().split()))
d = 0
for _ in range(n):
s = input().strip().split()
if s[0] == '+':
x += int(s[1])
else:
if x >= int(s[1]):
x -= int(s[1])
else:
d += 1
print(... | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
def main():
[n, x] = list(map(int, input().split()))
d = 0
for _ in range(n):
s = input().strip().split()
if s[0] == '+':
x += int(s[1])
else:
if x >= int(s[1]):
x -= int(s[1])
else:
d += 1
... | 3 | |
6 | B | President's Office | PROGRAMMING | 1,100 | [
"implementation"
] | B. President's Office | 2 | 64 | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ... | The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each ... | Print the only number — the amount of President's deputies. | [
"3 4 R\nG.B.\n.RR.\nTTT.\n",
"3 3 Z\n...\n.H.\n..Z\n"
] | [
"2\n",
"0\n"
] | none | 0 | [
{
"input": "3 4 R\nG.B.\n.RR.\nTTT.",
"output": "2"
},
{
"input": "3 3 Z\n...\n.H.\n..Z",
"output": "0"
},
{
"input": "1 1 C\nC",
"output": "0"
},
{
"input": "2 2 W\nKW\nKW",
"output": "1"
},
{
"input": "1 10 H\n....DDHHHH",
"output": "1"
},
{
"input":... | 1,661,803,228 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n, m, c = input().split()
n, m = int(n), int(m)
deputies = set()
prev = '.' * (m + 1)
for i in range(n):
row = "." + input().strip()
for j in range (1, m + 1):
if row[j] != '.':
if row[j] == c:
if row[j - 1] != c and row[j - 1] != '.' and row[j - 1] not in deputies... | Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ... | ```python
n, m, c = input().split()
n, m = int(n), int(m)
deputies = set()
prev = '.' * (m + 1)
for i in range(n):
row = "." + input().strip()
for j in range (1, m + 1):
if row[j] != '.':
if row[j] == c:
if row[j - 1] != c and row[j - 1] != '.' and row[j - 1] not i... | 0 |
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 ... | 1,667,386,760 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 102,400 | import math
import collections
cur=0
n,a,b=map(int,input().split())
res=0
for i in range(n):
if i+1>a and i+1>=(n-b):
res+=1
print(res) | Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind h... | ```python
import math
import collections
cur=0
n,a,b=map(int,input().split())
res=0
for i in range(n):
if i+1>a and i+1>=(n-b):
res+=1
print(res)
``` | 3 | |
712 | C | Memory and De-Evolution | PROGRAMMING | 1,600 | [
"greedy",
"math"
] | null | null | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length *x*, and he wishes to perform operations to obtain an equilateral triangle of side length *y*.
In a single second, he can modify the length of a single side of the current triangle suc... | The first and only line contains two integers *x* and *y* (3<=≤<=*y*<=<<=*x*<=≤<=100<=000) — the starting and ending equilateral triangle side lengths respectively. | Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length *y* if he starts with the equilateral triangle of side length *x*. | [
"6 3\n",
"8 5\n",
"22 4\n"
] | [
"4\n",
"3\n",
"6\n"
] | In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides *a*, *b*, and *c* as (*a*, *b*, *c*). Then, Memory can do <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/18af21f738bad490df83097a90e1f2879a4b21... | 1,500 | [
{
"input": "6 3",
"output": "4"
},
{
"input": "8 5",
"output": "3"
},
{
"input": "22 4",
"output": "6"
},
{
"input": "4 3",
"output": "3"
},
{
"input": "57 27",
"output": "4"
},
{
"input": "61 3",
"output": "9"
},
{
"input": "5 4",
"out... | 1,474,206,645 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 77 | 0 | from math import sqrt
import sys
x, y = [int(i) for i in input().split()]
a = y
b = y
c = y
count = 0
while a != x or b != x or c != x:
min_side = min(min(a, b), c)
max_side = max(max(a, b), c)
mid_side = a+b+c-max_side-min_side
new_side = min(max_side + mid_side - 1, x)
a = mid_side
b = max_si... | Title: Memory and De-Evolution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length *x*, and he wishes to perform operations to obtain an equilateral triangle o... | ```python
from math import sqrt
import sys
x, y = [int(i) for i in input().split()]
a = y
b = y
c = y
count = 0
while a != x or b != x or c != x:
min_side = min(min(a, b), c)
max_side = max(max(a, b), c)
mid_side = a+b+c-max_side-min_side
new_side = min(max_side + mid_side - 1, x)
a = mid_side
... | 3 | |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,677,939,543 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 1,107 | 16,384,000 | shapes = [input() for _ in range(int(input()))]
faces = 0
for shape in shapes:
if shape == "Tetrahedron": faces += 4
if shape == "Cube": faces += 6
if shape == "Octahedron": faces += 8
if shape == "Dodecahedron": faces += 12
if shape == "Icosahedron": faces += 20
print(faces) | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
shapes = [input() for _ in range(int(input()))]
faces = 0
for shape in shapes:
if shape == "Tetrahedron": faces += 4
if shape == "Cube": faces += 6
if shape == "Octahedron": faces += 8
if shape == "Dodecahedron": faces += 12
if shape == "Icosahedron": faces += 20
print(faces)
``` | 3 | |
722 | D | Generating Sets | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"dfs and similar",
"greedy",
"strings",
"trees"
] | null | null | You are given a set *Y* of *n* distinct positive integers *y*1,<=*y*2,<=...,<=*y**n*.
Set *X* of *n* distinct positive integers *x*1,<=*x*2,<=...,<=*x**n* is said to generate set *Y* if one can transform *X* to *Y* by applying some number of the following two operation to integers in *X*:
1. Take any integer *x**i* ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=50<=000) — the number of elements in *Y*.
The second line contains *n* integers *y*1,<=...,<=*y**n* (1<=≤<=*y**i*<=≤<=109), that are guaranteed to be distinct. | Print *n* integers — set of distinct integers that generate *Y* and the maximum element of which is minimum possible. If there are several such sets, print any of them. | [
"5\n1 2 3 4 5\n",
"6\n15 14 3 13 1 12\n",
"6\n9 7 13 17 5 11\n"
] | [
"4 5 2 3 1 \n",
"12 13 14 7 3 1 \n",
"4 5 2 6 3 1 \n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 4 5",
"output": "4 5 2 3 1 "
},
{
"input": "6\n15 14 3 13 1 12",
"output": "12 13 14 7 3 1 "
},
{
"input": "6\n9 7 13 17 5 11",
"output": "4 5 2 6 3 1 "
},
{
"input": "10\n18 14 19 17 11 7 20 10 4 12",
"output": "8 9 4 10 5 2 6 7 3 1 "
},
{
"i... | 1,475,337,795 | 7,095 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 0 | n = int(input())
y = sorted(map(int, input().split()))
y_ = set(y)
ans = set([1])
if y[0] + 1 in y_ and y[0] % 2 == 0:
ans = set([y[0]])
for num in y[1:]:
if num % 2 == 0:
tmp = num + 1
else:
tmp = num - 1
if tmp in y_:
if num % 2 == 0:
continue
else:
... | Title: Generating Sets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a set *Y* of *n* distinct positive integers *y*1,<=*y*2,<=...,<=*y**n*.
Set *X* of *n* distinct positive integers *x*1,<=*x*2,<=...,<=*x**n* is said to generate set *Y* if one can transform *X* to *Y* by ... | ```python
n = int(input())
y = sorted(map(int, input().split()))
y_ = set(y)
ans = set([1])
if y[0] + 1 in y_ and y[0] % 2 == 0:
ans = set([y[0]])
for num in y[1:]:
if num % 2 == 0:
tmp = num + 1
else:
tmp = num - 1
if tmp in y_:
if num % 2 == 0:
continue
... | 0 | |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,389,975,077 | 2,477 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 62 | 409,600 | str = input();
ar = input();
i=0;
count1=0;
while str[i]!= '|':
i=i+1;
count1=count1+1;
count2=0;
while i!=len(str)-1:
count2=count2+1;
i=i+1;
#print("left : %d ",count1,", right : %d",count2);
if((count1<count2) and ((count2-count1)==len(ar))):
print(ar+str);
elif((count1>count2) ... | Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
str = input();
ar = input();
i=0;
count1=0;
while str[i]!= '|':
i=i+1;
count1=count1+1;
count2=0;
while i!=len(str)-1:
count2=count2+1;
i=i+1;
#print("left : %d ",count1,", right : %d",count2);
if((count1<count2) and ((count2-count1)==len(ar))):
print(ar+str);
elif((count... | 0 | |
999 | C | Alphabetic Removals | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next ite... | The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove.
The second line contains the string $s$ consisting of $n$ lowercase Latin letters. | Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times.
If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). | [
"15 3\ncccaabababaccbc\n",
"15 9\ncccaabababaccbc\n",
"1 1\nu\n"
] | [
"cccbbabaccbc\n",
"cccccc\n",
""
] | none | 0 | [
{
"input": "15 3\ncccaabababaccbc",
"output": "cccbbabaccbc"
},
{
"input": "15 9\ncccaabababaccbc",
"output": "cccccc"
},
{
"input": "5 2\nzyzyx",
"output": "zzy"
},
{
"input": "4 3\nhack",
"output": "k"
},
{
"input": "4 3\nzzzz",
"output": "z"
},
{
"i... | 1,670,514,576 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 218 | 46,694,400 | nk=input()
str1=input()
nk1=nk.split()
n=nk1[0]
k=int(nk1[1])
occ={}
i=0
while i<26:
occ[chr(i+97)]=0
i=i+1
i=0
str2=list(str1)
while i<len(str1):
occ[str1[i]]=occ[str1[i]]+1
i=i+1
sum1=0
list1=[]
list2=[]
indic=[]
i=0
while sum1<k:
list1.append(chr(97+i))
sum1=sum1+occ[chr... | Title: Alphabetic Removals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is... | ```python
nk=input()
str1=input()
nk1=nk.split()
n=nk1[0]
k=int(nk1[1])
occ={}
i=0
while i<26:
occ[chr(i+97)]=0
i=i+1
i=0
str2=list(str1)
while i<len(str1):
occ[str1[i]]=occ[str1[i]]+1
i=i+1
sum1=0
list1=[]
list2=[]
indic=[]
i=0
while sum1<k:
list1.append(chr(97+i))
sum1=su... | 3 | |
931 | B | World Cup | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | 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... | 1,000 | [
{
"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,520,181,576 | 3,876 | Python 3 | WRONG_ANSWER | TESTS | 24 | 62 | 5,632,000 | rounds={2:1,4:2,8:3,16:4,32:5,64:6,128:7,256:8}
p=list(map(int,input().split()))
final=rounds[p[0]]
if(p[1]>p[0]//2 and p[2]>p[0]//2):
if(abs(p[1]-p[2])==1):
print(1)
else:
count=0
diff=abs(p[1]-p[2])
while(diff>=1):
diff=diff//2
count=count+1
if(count==final):
print("Final!")
else:
print(co... | Title: World Cup
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 th... | ```python
rounds={2:1,4:2,8:3,16:4,32:5,64:6,128:7,256:8}
p=list(map(int,input().split()))
final=rounds[p[0]]
if(p[1]>p[0]//2 and p[2]>p[0]//2):
if(abs(p[1]-p[2])==1):
print(1)
else:
count=0
diff=abs(p[1]-p[2])
while(diff>=1):
diff=diff//2
count=count+1
if(count==final):
print("Final!")
else:
... | 0 | |
14 | B | Young Photographer | PROGRAMMING | 1,000 | [
"implementation"
] | B. Young Photographer | 2 | 64 | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at t... | The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | [
"3 3\n0 7\n14 2\n4 6\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "3 3\n0 7\n14 2\n4 6",
"output": "1"
},
{
"input": "1 1\n0 10",
"output": "0"
},
{
"input": "2 2\n1 2\n3 2",
"output": "0"
},
{
"input": "3 2\n1 2\n2 3\n3 4",
"output": "-1"
},
{
"input": "2 4\n10 4\n1 5",
"output": "0"
},
{
"input": "1 10\n... | 1,595,939,244 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 218 | 6,963,200 |
n, x = map(int, input().split())
l = 0
r = 1000
for i in range(n):
a, b = sorted(map(int, input().split()))
l = max(l, a)
r = min(r, b)
#initial point of the common segmnet is l
# and the end point ofthe segment is r
if l > r:
print(-1)
exit(0)
if l <= x <= r:
print(0)
else... | Title: Young Photographer
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. Bu... | ```python
n, x = map(int, input().split())
l = 0
r = 1000
for i in range(n):
a, b = sorted(map(int, input().split()))
l = max(l, a)
r = min(r, b)
#initial point of the common segmnet is l
# and the end point ofthe segment is r
if l > r:
print(-1)
exit(0)
if l <= x <= r:
prin... | 3.89362 |
688 | B | Lovely Palindromes | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. | 1,000 | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "... | 1,647,169,813 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 108 | 6,963,200 | s = input()
print(s + ''.join(reversed(s))) | Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is tr... | ```python
s = input()
print(s + ''.join(reversed(s)))
``` | 3 | |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,646,556,317 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 1,575 | 19,660,800 | def lower_bound_binary_search(arr, x):
l, r = 0, len(arr) - 1
while l <= r:
mid = (l + r) // 2
if arr[mid] <= x:
l = mid + 1
else:
r = mid - 1
return r
def main():
n, m = map(int, input().split())
a = list(map(int, input().split()))
... | Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
def lower_bound_binary_search(arr, x):
l, r = 0, len(arr) - 1
while l <= r:
mid = (l + r) // 2
if arr[mid] <= x:
l = mid + 1
else:
r = mid - 1
return r
def main():
n, m = map(int, input().split())
a = list(map(int, input().spli... | 3 | |
770 | C | Online Courses In BSU | PROGRAMMING | 1,500 | [
"*special",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Now you can take online courses in the Berland State University! Polycarp needs to pass *k* main online courses of his specialty to get a diploma. In total *n* courses are availiable for the passage.
The situation is complicated by the dependence of online courses, for each course there is a list of those that must be... | The first line contains *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the number of online-courses and the number of main courses of Polycarp's specialty.
The second line contains *k* distinct integers from 1 to *n* — numbers of main online-courses of Polycarp's specialty.
Then *n* lines follow, each of them describes ... | Print -1, if there is no the way to get a specialty.
Otherwise, in the first line print the integer *m* — the minimum number of online-courses which it is necessary to pass to get a specialty. In the second line print *m* distinct integers — numbers of courses which it is necessary to pass in the chronological order ... | [
"6 2\n5 3\n0\n0\n0\n2 2 1\n1 4\n1 5\n",
"9 3\n3 9 5\n0\n0\n3 9 4 5\n0\n0\n1 8\n1 6\n1 2\n2 1 2\n",
"3 3\n1 2 3\n1 2\n1 3\n1 1\n"
] | [
"5\n1 2 3 4 5 \n",
"6\n1 2 9 4 5 3 \n",
"-1\n"
] | In the first test firstly you can take courses number 1 and 2, after that you can take the course number 4, then you can take the course number 5, which is the main. After that you have to take only the course number 3, which is the last not passed main course. | 1,500 | [
{
"input": "6 2\n5 3\n0\n0\n0\n2 2 1\n1 4\n1 5",
"output": "5\n1 2 3 4 5 "
},
{
"input": "9 3\n3 9 5\n0\n0\n3 9 4 5\n0\n0\n1 8\n1 6\n1 2\n2 1 2",
"output": "6\n1 2 9 4 5 3 "
},
{
"input": "3 3\n1 2 3\n1 2\n1 3\n1 1",
"output": "-1"
},
{
"input": "5 3\n2 1 4\n0\n0\n1 5\n0\n0",... | 1,699,964,918 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 307,200 | from collections import deque
def solve(n, k, main_courses, dependencies):
graph = [[] for _ in range(n + 1)]
in_degree = [0] * (n + 1)
necessary_courses = set(main_courses)
# Build the graph
for i in range(1, n + 1):
for dep in dependencies[i]:
graph[dep].append(i)
... | Title: Online Courses In BSU
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Now you can take online courses in the Berland State University! Polycarp needs to pass *k* main online courses of his specialty to get a diploma. In total *n* courses are availiable for the passage.
The situatio... | ```python
from collections import deque
def solve(n, k, main_courses, dependencies):
graph = [[] for _ in range(n + 1)]
in_degree = [0] * (n + 1)
necessary_courses = set(main_courses)
# Build the graph
for i in range(1, n + 1):
for dep in dependencies[i]:
graph[dep].a... | 0 | |
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"inp... | 1,623,222,563 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 155 | 0 | n, a, b = [int(i) for i in input().split()]
avg = (a + b) // n
plates = [0 for i in range(n)]
for i in range(n):
if a >= avg:
plates[i] += avg
a -= avg
elif a > 0 and a < avg:
plates[i] += a
a = 0
elif a == 0:
if b >= avg:
plates[i] += avg
... | Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Iv... | ```python
n, a, b = [int(i) for i in input().split()]
avg = (a + b) // n
plates = [0 for i in range(n)]
for i in range(n):
if a >= avg:
plates[i] += avg
a -= avg
elif a > 0 and a < avg:
plates[i] += a
a = 0
elif a == 0:
if b >= avg:
plates[i] +... | 0 | |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input":... | 1,696,435,564 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 92 | 0 | c=str(input())
b=str(input())
c=c.lower()
b=b.lower()
for i in range(len(c)):
h=0
if c[i]>b[i]:
h=1
break
if c[i]<b[i]:
h=-1
break
print(h) | Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ... | ```python
c=str(input())
b=str(input())
c=c.lower()
b=b.lower()
for i in range(len(c)):
h=0
if c[i]>b[i]:
h=1
break
if c[i]<b[i]:
h=-1
break
print(h)
``` | 3.977 |
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,695,270,495 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | imort math
a,b,s=map(int,input().split())
m=math.ceil(a/s)
c=math.ceil(b/s)
print(m*c)
| 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
imort math
a,b,s=map(int,input().split())
m=math.ceil(a/s)
c=math.ceil(b/s)
print(m*c)
``` | -1 |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,507,071,989 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 61 | 0 | x = input()
y = input()
i=0
while i < len(x):
if x[i]=="|":
a = i
b = len(x)- i - 1
i += 1
c = abs(a - b)
if c == len(y) :
if a > b:
print(x+y)
else:
print(y+x)
else:
print("Impossible")
| Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
x = input()
y = input()
i=0
while i < len(x):
if x[i]=="|":
a = i
b = len(x)- i - 1
i += 1
c = abs(a - b)
if c == len(y) :
if a > b:
print(x+y)
else:
print(y+x)
else:
print("Impossible")
``` | 0 | |
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output... | 1,695,438,333 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 154 | 2,764,800 | n = input()
if n[0] != '-':
print(n)
else:
remove = max(n[len(n) - 1], n[len(n) - 2])
print(n[:remove]+n[remove+1:])
| Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an... | ```python
n = input()
if n[0] != '-':
print(n)
else:
remove = max(n[len(n) - 1], n[len(n) - 2])
print(n[:remove]+n[remove+1:])
``` | -1 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | 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,598,288,659 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | n=input()
c=0
a=0
s='hello'
for i in range(len(n)):
if n[i]==s[a]:
c+=1
a+=1
if c==5:
print('YES')
break
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
n=input()
c=0
a=0
s='hello'
for i in range(len(n)):
if n[i]==s[a]:
c+=1
a+=1
if c==5:
print('YES')
break
else:
print('No')
``` | 0 |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,681,033,890 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 77 | 2,867,200 | n,k=map(int,input().split())
a=list(map(int,input().split()))
m=a[0]+a[1]+a[2]
d=[]
for i in range(n-3):
for j in range(i,i+1):
m=min(m,a[j]+a[j+1]+a[j+2])
d.append((a[j],m))
# print(m)
# for i in d:
# if d[i]==m:
# print(a.index(i)+1)
# break
# print(d)
mini=floa... | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=a[0]+a[1]+a[2]
d=[]
for i in range(n-3):
for j in range(i,i+1):
m=min(m,a[j]+a[j+1]+a[j+2])
d.append((a[j],m))
# print(m)
# for i in d:
# if d[i]==m:
# print(a.index(i)+1)
# break
# print(d)
... | -1 | |
622 | B | The Time | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedi... | The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=<<=24,<=0<=≤<=*mm*<=<<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).
The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes... | The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).
See the examples to check the input/output format. | [
"23:59\n10\n",
"20:20\n121\n",
"10:10\n0\n"
] | [
"00:09\n",
"22:21\n",
"10:10\n"
] | none | 0 | [
{
"input": "23:59\n10",
"output": "00:09"
},
{
"input": "20:20\n121",
"output": "22:21"
},
{
"input": "10:10\n0",
"output": "10:10"
},
{
"input": "12:34\n10000",
"output": "11:14"
},
{
"input": "00:00\n10000",
"output": "22:40"
},
{
"input": "00:00\n14... | 1,629,727,498 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 6,758,400 | c,m=map(int,input().split(':'))
m1=int(input())
M=c*60+m+m1
c=M//60
if c>=24:c-=24
m=M%60
print(c//10,c%10,':',m//10,m%10,sep='') | Title: The Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read mo... | ```python
c,m=map(int,input().split(':'))
m1=int(input())
M=c*60+m+m1
c=M//60
if c>=24:c-=24
m=M%60
print(c//10,c%10,':',m//10,m%10,sep='')
``` | 0 | |
462 | B | Appleman and Card Game | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman. | Print a single integer – the answer to the problem. | [
"15 10\nDZFDFZDFDDDDDDF\n",
"6 4\nYJSNPI\n"
] | [
"82\n",
"4\n"
] | In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | 1,000 | [
{
"input": "15 10\nDZFDFZDFDDDDDDF",
"output": "82"
},
{
"input": "6 4\nYJSNPI",
"output": "4"
},
{
"input": "5 3\nAOWBY",
"output": "3"
},
{
"input": "1 1\nV",
"output": "1"
},
{
"input": "2 1\nWT",
"output": "1"
},
{
"input": "2 2\nBL",
"output":... | 1,409,846,737 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 108 | 307,200 | n, k = map(int, input().split())
s = input().strip()
cnt = dict()
for i in s:
if i not in cnt:
cnt[i] = 0
cnt[i] += 1
a = []
for i in cnt:
a.append(cnt[i])
a.sort(reverse=True)
cn = 0
ans = 0
for i in range(len(a)):
if a[i] + cn <= k:
ans += a[i] * a[i]
cn += a[i]... | Title: Appleman and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally... | ```python
n, k = map(int, input().split())
s = input().strip()
cnt = dict()
for i in s:
if i not in cnt:
cnt[i] = 0
cnt[i] += 1
a = []
for i in cnt:
a.append(cnt[i])
a.sort(reverse=True)
cn = 0
ans = 0
for i in range(len(a)):
if a[i] + cn <= k:
ans += a[i] * a[i]
... | 3 | |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,624,343,165 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 278 | 3,788,800 | n = int(input())
n_sqr = n**2
r = range(1, n**2+1)
for i in range(0, n_sqr//2, n//2):
for j in range(n//2):
print(r[i+j], r[n_sqr-1-i-j], end=' ')
print()
| Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
n = int(input())
n_sqr = n**2
r = range(1, n**2+1)
for i in range(0, n_sqr//2, n//2):
for j in range(n//2):
print(r[i+j], r[n_sqr-1-i-j], end=' ')
print()
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find th... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces. | On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}. | [
"6 2\n2 3 6 5 4 10\n"
] | [
"3\n"
] | In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | 0 | [
{
"input": "6 2\n2 3 6 5 4 10",
"output": "3"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 1... | 1,589,826,139 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 436 | 14,438,400 | """
Code of Ayush Tiwari
Codechef: ayush572000
Codeforces: servermonk
"""
import sys
input = sys.stdin.buffer.readline
from collections import Counter
def solution():
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
c=Counter(l)
i=0
for i in l:
x=i
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<=... | ```python
"""
Code of Ayush Tiwari
Codechef: ayush572000
Codeforces: servermonk
"""
import sys
input = sys.stdin.buffer.readline
from collections import Counter
def solution():
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
c=Counter(l)
i=0
for i in l:
... | 0 | |
372 | A | Counting Kangaroos is Fun | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who i... | The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). | Output a single integer — the optimal number of visible kangaroos. | [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] | [
"5\n",
"5\n"
] | none | 500 | [
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
... | 1,614,222,017 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 514 | 10,444,800 | import sys
n=int(input())
arr = sorted([int(i) for i in sys.stdin])
l=(n//2) - 1
r=n-1
res=0
while l>=0 and r>n//2 -1:
if arr[l]*2<=arr[r]:
res+=1
r-=1
l-=1
print(n-res)
| 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
import sys
n=int(input())
arr = sorted([int(i) for i in sys.stdin])
l=(n//2) - 1
r=n-1
res=0
while l>=0 and r>n//2 -1:
if arr[l]*2<=arr[r]:
res+=1
r-=1
l-=1
print(n-res)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Три брата договорились о встрече. Пронумеруем братьев следующим образом: пусть старший брат имеет номер 1, средний брат имеет номер 2, а младший брат — номер 3.
Когда пришло время встречи, один из братьев опоздал. По заданным номерам двух братьев, которые пришли вовремя, вам предстоит определить номер опоздавшего бра... | В первой строке входных данных следуют два различных целых числа *a* и *b* (1<=≤<=*a*,<=*b*<=≤<=3, *a*<=≠<=*b*) — номера братьев, которые пришли на встречу вовремя. Номера даны в произвольном порядке. | Выведите единственное целое число — номер брата, который опоздал на встречу. | [
"3 1\n"
] | [
"2\n"
] | none | 0 | [
{
"input": "3 1",
"output": "2"
},
{
"input": "2 1",
"output": "3"
},
{
"input": "2 3",
"output": "1"
},
{
"input": "1 2",
"output": "3"
},
{
"input": "1 3",
"output": "2"
},
{
"input": "3 2",
"output": "1"
}
] | 1,458,710,973 | 142,172 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 62 | 4,608,000 | s = input().split()
for i in range(len(s)):
s[i] = int(s[i])
a = s[0]
b = s[1]
if a==1 and b==2:
c = 3
elif a==1 and b==3:
c = 2
elif a==2 and b==1:
c = 3
elif a==2 and b==3:
c = 2
elif a==3 and b==1:
c = 2
elif a==3 and b==2:
c = 1
elif a==b:
c = 0
print(c) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Три брата договорились о встрече. Пронумеруем братьев следующим образом: пусть старший брат имеет номер 1, средний брат имеет номер 2, а младший брат — номер 3.
Когда пришло время встречи, один из братьев опоздал. По заданным но... | ```python
s = input().split()
for i in range(len(s)):
s[i] = int(s[i])
a = s[0]
b = s[1]
if a==1 and b==2:
c = 3
elif a==1 and b==3:
c = 2
elif a==2 and b==1:
c = 3
elif a==2 and b==3:
c = 2
elif a==3 and b==1:
c = 2
elif a==3 and b==2:
c = 1
elif a==b:
c = 0
print(c)
... | 0 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,694,295,561 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | n=int(input())
sum=0
arr=[int(i) for i in input().split()]
for j in range(n):
sum+=arr[j]
if sum%2==0:
print(sum)
| Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
n=int(input())
sum=0
arr=[int(i) for i in input().split()]
for j in range(n):
sum+=arr[j]
if sum%2==0:
print(sum)
``` | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.