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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
433 | C | Ryouko's Memory Note | PROGRAMMING | 1,800 | [
"implementation",
"math",
"sortings"
] | null | null | Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what she hears on the notebook, and the notebook became her memory.
Though Ryouko is forgetful, she is also bo... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105).
The next line contains *m* integers separated by spaces: *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=*n*). | Print a single integer — the minimum number of pages Ryouko needs to turn. | [
"4 6\n1 2 3 4 3 2\n",
"10 5\n9 4 3 8 8\n"
] | [
"3\n",
"6\n"
] | In the first sample, the optimal solution is to merge page 4 to 3, after merging sequence *a* becomes {1, 2, 3, 3, 3, 2}, so the number of pages Ryouko needs to turn is |1 - 2| + |2 - 3| + |3 - 3| + |3 - 3| + |3 - 2| = 3.
In the second sample, optimal solution is achieved by merging page 9 to 4. | 1,500 | [
{
"input": "4 6\n1 2 3 4 3 2",
"output": "3"
},
{
"input": "10 5\n9 4 3 8 8",
"output": "6"
},
{
"input": "5 10\n2 5 2 2 3 5 3 2 1 3",
"output": "7"
},
{
"input": "10 20\n6 3 9 6 1 9 1 9 8 2 7 6 9 8 4 7 1 2 4 2",
"output": "52"
},
{
"input": "100 100\n28 28 28 28 ... | 1,689,632,719 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | print("_RANDOM_GUESS_1689632719.3197465")# 1689632719.319768 | Title: Ryouko's Memory Note
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what ... | ```python
print("_RANDOM_GUESS_1689632719.3197465")# 1689632719.319768
``` | 0 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,688,202,122 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | s=q=0
for _ in range(int(input())):
a,b=map(int,input().split())
s=s+b-a
q=max(s,q)
if s==0:
print(q) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
s=q=0
for _ in range(int(input())):
a,b=map(int,input().split())
s=s+b-a
q=max(s,q)
if s==0:
print(q)
``` | 3 | |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t... | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,547,174,726 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 124 | 0 | R = lambda:[x for x in input().split()]
one, two = R()
print(one, two)
n = int(input())
for _ in range(n):
aone, atwo = R()
if one == aone: one = atwo
if two == aone: two = atwo
print(one, two) | Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The... | ```python
R = lambda:[x for x in input().split()]
one, two = R()
print(one, two)
n = int(input())
for _ in range(n):
aone, atwo = R()
if one == aone: one = atwo
if two == aone: two = atwo
print(one, two)
``` | 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,582,560,087 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | n,a,b=map(int,input().split())
l=list(map(int,input().split()))
s=sum(l)
x=a*1+b*2
print(abs(s-x))
| 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())
l=list(map(int,input().split()))
s=sum(l)
x=a*1+b*2
print(abs(s-x))
``` | 0 | |
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd... | 1,501,778,100 | 4,800 | Python 3 | OK | TESTS | 29 | 77 | 4,608,000 | n = int(input())
text = input().split()
ans = 0
for word in text:
cur_ans = 0
for let in word:
if let >= "A" and let <= "Z":
cur_ans+=1
ans = max(ans,cur_ans)
print(ans) | Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex... | ```python
n = int(input())
text = input().split()
ans = 0
for word in text:
cur_ans = 0
for let in word:
if let >= "A" and let <= "Z":
cur_ans+=1
ans = max(ans,cur_ans)
print(ans)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in *t* minutes. There is a straight road of length *s* from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point... | The first line contains four positive integers *n*, *k*, *s* and *t* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*k*<=≤<=2·105, 2<=≤<=*s*<=≤<=109, 1<=≤<=*t*<=≤<=2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the n... | Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in *t* minutes). If there is no appropriate car, print -1. | [
"3 1 8 10\n10 8\n5 7\n11 9\n3\n",
"2 2 10 18\n10 4\n20 6\n5 3\n"
] | [
"10\n",
"20\n"
] | In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. Aft... | 0 | [
{
"input": "3 1 8 10\n10 8\n5 7\n11 9\n3",
"output": "10"
},
{
"input": "2 2 10 18\n10 4\n20 6\n5 3",
"output": "20"
},
{
"input": "2 1 1000000000 2000000000\n111 1000000000\n101 1000000000\n5",
"output": "101"
},
{
"input": "2 1 1000000000 2000000000\n111 999999998\n101 9999... | 1,479,702,881 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 31,129,600 | def main():
from bisect import bisect
n, k, s, t = map(int, input().split()) # машин, заправок, позиция кинотеатра, время до сеанса.
cv = list(tuple(map(int, input().split())) for _ in range(n)) # аренда i-й машины и объём её бака.
a, dd = 0, []
for b in sorted(map(int, input().split())): # позиц... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in *t* minutes. There is a straight road of length *s* from the service to the cinema. Let's introduce a coordina... | ```python
def main():
from bisect import bisect
n, k, s, t = map(int, input().split()) # машин, заправок, позиция кинотеатра, время до сеанса.
cv = list(tuple(map(int, input().split())) for _ in range(n)) # аренда i-й машины и объём её бака.
a, dd = 0, []
for b in sorted(map(int, input().split()))... | 0 | |
919 | D | Substring | PROGRAMMING | 1,700 | [
"dfs and similar",
"dp",
"graphs"
] | null | null | You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the large... | The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges.
The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node.
Then $m$ lines follow. Each line ... | Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead. | [
"5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n",
"6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n",
"10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n"
] | [
"3\n",
"-1\n",
"4\n"
] | In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times. | 1,500 | [
{
"input": "5 4\nabaca\n1 2\n1 3\n3 4\n4 5",
"output": "3"
},
{
"input": "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4",
"output": "-1"
},
{
"input": "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7",
"output": "4"
},
{
"input": "1 1\nf... | 1,670,507,876 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 614,400 | """THIS TEMPLATE belongs to anuj_negi"""
#Try to use bisect in case of binary search, bisect_left, bisect_right
#Try to use sortedcontainers when available
#Try to use Multiset when available
from bisect import *
from heapq import *
#from functools import cache, lru_cache
from math import *
from collections import def... | Title: Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are... | ```python
"""THIS TEMPLATE belongs to anuj_negi"""
#Try to use bisect in case of binary search, bisect_left, bisect_right
#Try to use sortedcontainers when available
#Try to use Multiset when available
from bisect import *
from heapq import *
#from functools import cache, lru_cache
from math import *
from collections ... | 0 | |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,530,809,312 | 812 | Python 3 | OK | TESTS | 45 | 139 | 0 | a=[int(i) for i in input().split()]
n=a[0]
d=a[1]
a=[int(i) for i in input().split()]
a.sort()
diff=[]
for i in range(1,n):
diff.append(abs(a[i]-a[i-1]))
count=2
for i in range(n-1):
if(diff[i]==2*d):
count+=1
if(diff[i]>2*d):
count+=2
print(count) | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
a=[int(i) for i in input().split()]
n=a[0]
d=a[1]
a=[int(i) for i in input().split()]
a.sort()
diff=[]
for i in range(1,n):
diff.append(abs(a[i]-a[i-1]))
count=2
for i in range(n-1):
if(diff[i]==2*d):
count+=1
if(diff[i]>2*d):
count+=2
print(count)
``` | 3 | |
272 | C | Dima and Staircase | PROGRAMMING | 1,500 | [
"data structures",
"implementation"
] | null | null | Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109; *a**i*<=≤<=*a**i*<=+<=1).
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the numbe... | Print *m* integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input.
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 %I... | [
"5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n",
"3\n1 2 3\n2\n1 1\n3 1\n",
"1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n"
] | [
"1\n3\n4\n6\n",
"1\n3\n",
"1\n3\n13\n23\n33\n"
] | The first sample are shown on the picture. | 1,500 | [
{
"input": "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3",
"output": "1\n3\n4\n6"
},
{
"input": "3\n1 2 3\n2\n1 1\n3 1",
"output": "1\n3"
},
{
"input": "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10",
"output": "1\n3\n13\n23\n33"
},
{
"input": "8\n6 10 18 23 30 31 31 33\n1\n5 3",
"output":... | 1,642,658,634 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 13,824,000 | n,H=int(input()),1
*a, = map(int,input().split())
for _ in range(int(input())):
w,h = map(int,input().split())
b=max(H,a[w-1])
print(b)
H=b+h | Title: Dima and Staircase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the st... | ```python
n,H=int(input()),1
*a, = map(int,input().split())
for _ in range(int(input())):
w,h = map(int,input().split())
b=max(H,a[w-1])
print(b)
H=b+h
``` | 0 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,600,618,075 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 186 | 307,200 |
def main():
n,m = map(int, input().split())
a = [int(x) for x in input().split()]
neg = [x for x in a if x<0]
neg.sort()
if len(neg)<=m:
print(abs(sum(neg)))
else:
s = 0
neg = neg[:-m]
print(abs(sum(neg)))
return
main()
| Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
def main():
n,m = map(int, input().split())
a = [int(x) for x in input().split()]
neg = [x for x in a if x<0]
neg.sort()
if len(neg)<=m:
print(abs(sum(neg)))
else:
s = 0
neg = neg[:-m]
print(abs(sum(neg)))
return
main()
``` | 0 |
837 | B | Flag of Berland | PROGRAMMING | 1,600 | [
"brute force",
"implementation"
] | null | null | The flag of Berland is such rectangular field *n*<=×<=*m* that satisfies following conditions:
- Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. - Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. ... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the field.
Each of the following *n* lines consisting of *m* characters 'R', 'G' and 'B' — the description of the field. | Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). | [
"6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n",
"4 3\nBRG\nBRG\nBRG\nBRG\n",
"6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB\n",
"4 4\nRRRR\nRRRR\nBBBB\nGGGG\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | 0 | [
{
"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG",
"output": "YES"
},
{
"input": "4 3\nBRG\nBRG\nBRG\nBRG",
"output": "YES"
},
{
"input": "6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB",
"output": "NO"
},
{
"input": "4 4\nRRRR\nRRRR\nBBBB\nGGGG",
"out... | 1,503,547,488 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 307,200 | n, m = map(int,input().split())
ll = []
for i in range(n):
ll.append(input())
if n % 3 == 0 or m % 3 == 0:
l1 = ll[0][0]
l2 = ll[n // 3][0]
l3 = ll[2 * (n // 3)][0]
t = False
if l1 != l2 != l3:
for i in range(n):
for j in range(m):
if 0 <= i < n //... | Title: Flag of Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The flag of Berland is such rectangular field *n*<=×<=*m* that satisfies following conditions:
- Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. - Flag consists of three equal in width and... | ```python
n, m = map(int,input().split())
ll = []
for i in range(n):
ll.append(input())
if n % 3 == 0 or m % 3 == 0:
l1 = ll[0][0]
l2 = ll[n // 3][0]
l3 = ll[2 * (n // 3)][0]
t = False
if l1 != l2 != l3:
for i in range(n):
for j in range(m):
if 0 <... | 0 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,684,916,566 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 77 | 2,048,000 | n,m=map(int,input().split())
counter=0
parsa=[]
for i in range(n):
amir=list(map(int,input().split()))
parsa.append(amir)
for i in range(n):
for j in range(0,2*m,2):
if parsa[i][j]==1 or parsa[i][j+1]==1:
counter+=1
print(counter) | Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
n,m=map(int,input().split())
counter=0
parsa=[]
for i in range(n):
amir=list(map(int,input().split()))
parsa.append(amir)
for i in range(n):
for j in range(0,2*m,2):
if parsa[i][j]==1 or parsa[i][j+1]==1:
counter+=1
print(counter)
``` | 3 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,620,020,277 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 0 | N=int(input())
lis1=list(map(int, input().split()))[:N]
x=set(lis1)
if 0 in x:
print(len(x)-1)
else:
print(len(x))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
N=int(input())
lis1=list(map(int, input().split()))[:N]
x=set(lis1)
if 0 in x:
print(len(x)-1)
else:
print(len(x))
``` | 3 | |
574 | A | Bear and Elections | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elect... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=100) - number of candidates.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) - number of votes for each candidate. Limak is candidate number 1.
Note that after bribing number of votes for some candidate ... | Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. | [
"5\n5 1 11 2 8\n",
"4\n1 8 8 8\n",
"2\n7 6\n"
] | [
"4\n",
"6\n",
"0\n"
] | In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate ... | 500 | [
{
"input": "5\n5 1 11 2 8",
"output": "4"
},
{
"input": "4\n1 8 8 8",
"output": "6"
},
{
"input": "2\n7 6",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "10\n100 200 57 99 1 1000 200 200 200 500",
"output": "451"
},
{
"input": "16\... | 1,579,624,139 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 140 | 1,228,800 | n = int(input())
mas = list(map(int, input().split()))
li = mas[0]
li1 = li
mas = mas[1::]
while li <= max(mas):
mas = sorted(mas)
mas[-1] -= 1
li += 1
print(li-li1)
| Title: Bear and Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are *n* candidates, including Limak. We know how many citizens are going to vote for e... | ```python
n = int(input())
mas = list(map(int, input().split()))
li = mas[0]
li1 = li
mas = mas[1::]
while li <= max(mas):
mas = sorted(mas)
mas[-1] -= 1
li += 1
print(li-li1)
``` | 3 | |
336 | A | Vasily the Bear and Triangle | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he... | The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0). | Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points. | [
"10 5\n",
"-10 5\n"
] | [
"0 15 15 0\n",
"-15 0 0 15\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | 500 | [
{
"input": "10 5",
"output": "0 15 15 0"
},
{
"input": "-10 5",
"output": "-15 0 0 15"
},
{
"input": "20 -10",
"output": "0 -30 30 0"
},
{
"input": "-10 -1000000000",
"output": "-1000000010 0 0 -1000000010"
},
{
"input": "-1000000000 -1000000000",
"output": "-... | 1,603,169,152 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 310 | 0 |
x,y=map(int,input().split())
if x>0 and y>0:
x=abs(x)
y=abs(y)
print(0,x+y,x+y,0)
elif x<0 and y>0:
x=abs(x)
y=abs(y)
print(-(x+y),0,0,(x+y))
elif x<0 and y<0:
x=abs(x)
y=abs(y)
print(-(x+y),0,0,-(x+y))
else:
x=abs(x)
y=abs(y)
print(0,-(x+y),(x+y),0) | Title: Vasily the Bear and Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate ... | ```python
x,y=map(int,input().split())
if x>0 and y>0:
x=abs(x)
y=abs(y)
print(0,x+y,x+y,0)
elif x<0 and y>0:
x=abs(x)
y=abs(y)
print(-(x+y),0,0,(x+y))
elif x<0 and y<0:
x=abs(x)
y=abs(y)
print(-(x+y),0,0,-(x+y))
else:
x=abs(x)
y=abs(y)
print(0,-(x+y),(x+y),0)
``` | 3 | |
928 | A | Login Verification | PROGRAMMING | 1,200 | [
"*special",
"strings"
] | null | null | When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ... | The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the exi... | Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes). | [
"1_wat\n2\n2_wat\nwat_1\n",
"000\n3\n00\nooA\noOo\n",
"_i_\n3\n__i_\n_1_\nI\n",
"La0\n3\n2a0\nLa1\n1a0\n",
"abc\n1\naBc\n",
"0Lil\n2\nLIL0\n0Ril\n"
] | [
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n"
] | In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one. | 500 | [
{
"input": "1_wat\n2\n2_wat\nwat_1",
"output": "Yes"
},
{
"input": "000\n3\n00\nooA\noOo",
"output": "No"
},
{
"input": "_i_\n3\n__i_\n_1_\nI",
"output": "No"
},
{
"input": "La0\n3\n2a0\nLa1\n1a0",
"output": "No"
},
{
"input": "abc\n1\naBc",
"output": "No"
}... | 1,519,487,723 | 1,223 | Python 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | #include <iostream>
using namespace std;
string tolower(string s) {
for (int i = 0; i < s.length(); ++i) {
if (int(s[i]) >= 65 && int(s[i]) <= 90) {
s[i] += 32;
}
}
for (int i = 0; i < s.length(); ++i) {
if (s[i] == 'i' || s[i] == 'l') {
s[i] = '... | Title: Login Verification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercas... | ```python
#include <iostream>
using namespace std;
string tolower(string s) {
for (int i = 0; i < s.length(); ++i) {
if (int(s[i]) >= 65 && int(s[i]) <= 90) {
s[i] += 32;
}
}
for (int i = 0; i < s.length(); ++i) {
if (s[i] == 'i' || s[i] == 'l') {
... | -1 | |
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. | Output the only number — answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"ou... | 1,668,039,889 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n,m=map(int,input().split())
l=[]
c=0
x=0
for i in range(m):
s=list(map(int,input().split()))
l.append(s[::-1])
z=sorted(l)
z.reverse()
print(z)
for i in z:
n-=i[1]
if n>=0:
c+=i[1]*i[0]
x=n
else:
c+=x*i[0]
if n<=0:
break | Title: Burglar and Matches
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat... | ```python
n,m=map(int,input().split())
l=[]
c=0
x=0
for i in range(m):
s=list(map(int,input().split()))
l.append(s[::-1])
z=sorted(l)
z.reverse()
print(z)
for i in z:
n-=i[1]
if n>=0:
c+=i[1]*i[0]
x=n
else:
c+=x*i[0]
if n<=0:
break
``` | 0 |
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,693,995,164 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | v=input;print("YNEOS"[v()!=v()[::-1]::2])
#hi codeforces
# | 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
v=input;print("YNEOS"[v()!=v()[::-1]::2])
#hi codeforces
#
``` | 3.977 |
899 | B | Months and Years | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.
... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=24) — the number of integers.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (28<=≤<=*a**i*<=≤<=31) — the numbers you are to check. | If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in arbitrary case (small or large). | [
"4\n31 31 30 31\n",
"2\n30 30\n",
"5\n29 31 30 31 30\n",
"3\n31 28 30\n",
"3\n31 31 28\n"
] | [
"Yes\n\n",
"No\n\n",
"Yes\n\n",
"No\n\n",
"Yes\n\n"
] | In the first example the integers can denote months July, August, September and October.
In the second example the answer is no, because there are no two consecutive months each having 30 days.
In the third example the months are: February (leap year) — March — April – May — June.
In the fourth example the number of... | 1,000 | [
{
"input": "4\n31 31 30 31",
"output": "Yes"
},
{
"input": "2\n30 30",
"output": "No"
},
{
"input": "5\n29 31 30 31 30",
"output": "Yes"
},
{
"input": "3\n31 28 30",
"output": "No"
},
{
"input": "3\n31 31 28",
"output": "Yes"
},
{
"input": "24\n29 28 3... | 1,513,650,366 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 62 | 5,529,600 | def find(array, sub):
for i in range(len(array) - len(sub)):
if (array[i:i+len(sub)] == sub):
return True
return False
a = [31,28,31,30,31,30,31,31,30,31,30,31]
b = [31,29,31,30,31,30,31,31,30,31,30,31]
aa = a + a + a + b + a + a + a
input()
num = [int(i) for i in input().split()]
... | Title: Months and Years
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, ... | ```python
def find(array, sub):
for i in range(len(array) - len(sub)):
if (array[i:i+len(sub)] == sub):
return True
return False
a = [31,28,31,30,31,30,31,31,30,31,30,31]
b = [31,29,31,30,31,30,31,31,30,31,30,31]
aa = a + a + a + b + a + a + a
input()
num = [int(i) for i in input().... | 3 | |
934 | B | A Prosperous Lot | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | 1,000 | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output":... | 1,518,616,620 | 6,720 | Python 3 | OK | TESTS | 45 | 62 | 5,632,000 | from sys import exit
loops = [1,4,8]
n = int(input())
s = []
while n > 0:
k = min(2, n)
s.append(loops[k])
n -= k
if len(s) > 18:
print("-1")
exit(0)
if not s:
s = [1]
print(''.join(map(str, s)))
| Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a... | ```python
from sys import exit
loops = [1,4,8]
n = int(input())
s = []
while n > 0:
k = min(2, n)
s.append(loops[k])
n -= k
if len(s) > 18:
print("-1")
exit(0)
if not s:
s = [1]
print(''.join(map(str, s)))
``` | 3 | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,681,491,081 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | n = int(input())
timetable = {}
c = 1
for i in range(n):
h, m = list(map(int, input().split()))
if h in timetable and timetable[h] == m:
c += 1
else:
timetable[h] = m
print(c)
| Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n = int(input())
timetable = {}
c = 1
for i in range(n):
h, m = list(map(int, input().split()))
if h in timetable and timetable[h] == m:
c += 1
else:
timetable[h] = m
print(c)
``` | 0 | |
17 | A | Noldbach problem | PROGRAMMING | 1,000 | [
"brute force",
"math",
"number theory"
] | A. Noldbach problem | 2 | 64 | Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Nold... | The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). | Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. | [
"27 2\n",
"45 7\n"
] | [
"YES",
"NO"
] | In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | 0 | [
{
"input": "27 2",
"output": "YES"
},
{
"input": "45 7",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "15 1",
"output": "YES"
},
{
"input": "17 1",
"output": "YES"
},
{
"input": "34 5",
"output": "NO"
},
{
"input": "37 ... | 1,642,591,601 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 154 | 0 | def solve():
lst=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,42... | Title: Noldbach problem
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a prob... | ```python
def solve():
lst=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,... | 0 |
492 | B | Vanya and Lanterns | PROGRAMMING | 1,200 | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that... | The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of th... | Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. | [
"7 15\n15 5 3 7 9 14 0\n",
"2 5\n2 5\n"
] | [
"2.5000000000\n",
"2.0000000000\n"
] | Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | 1,000 | [
{
"input": "7 15\n15 5 3 7 9 14 0",
"output": "2.5000000000"
},
{
"input": "2 5\n2 5",
"output": "2.0000000000"
},
{
"input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 1... | 1,693,324,632 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 31 | 0 | n,l = input().split()
a = input().split()
n = int(n)
l = int(l)
for i in range(0,len(a)):
a[i] = int(a[i])
list = sorted(a)
new = []
for i in range(0,n-1):
new.append(list[i+1]-list[i])
ans = 0
if 0 in list:
ans += max(new)/2
else:
if max(new)/2 > min(list):
ans += max(new) / 2
... | Title: Vanya and Lanterns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the poi... | ```python
n,l = input().split()
a = input().split()
n = int(n)
l = int(l)
for i in range(0,len(a)):
a[i] = int(a[i])
list = sorted(a)
new = []
for i in range(0,n-1):
new.append(list[i+1]-list[i])
ans = 0
if 0 in list:
ans += max(new)/2
else:
if max(new)/2 > min(list):
ans += max(n... | 0 | |
982 | A | Row | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms"
] | null | null | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means t... | The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | [
"3\n101\n",
"4\n1011\n",
"5\n10001\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | 500 | [
{
"input": "3\n101",
"output": "Yes"
},
{
"input": "4\n1011",
"output": "No"
},
{
"input": "5\n10001",
"output": "No"
},
{
"input": "1\n0",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "100\n010100101010100101001001010100101010010... | 1,608,883,930 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 156 | 0 | n=int(input())
s=input()
c=1
if(('11' in s) or ('000' in s) or (n==1 and s=='0') or (s[0]=='0' and s[1]=='0') or (s[n-2]=='0' and s[n-1]=='0')):
c=0
if(c==1):
print('Yes')
else:
print('No')
| Title: Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating th... | ```python
n=int(input())
s=input()
c=1
if(('11' in s) or ('000' in s) or (n==1 and s=='0') or (s[0]=='0' and s[1]=='0') or (s[n-2]=='0' and s[n-1]=='0')):
c=0
if(c==1):
print('Yes')
else:
print('No')
``` | 3 | |
859 | A | Declined Finalists | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ... | The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct. | Print the minimum possible number of contestants that declined the invitation to compete onsite. | [
"25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n",
"5\n16 23 8 15 4\n",
"3\n14 15 92\n"
] | [
"3\n",
"0\n",
"67\n"
] | In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3. | 500 | [
{
"input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28",
"output": "3"
},
{
"input": "5\n16 23 8 15 4",
"output": "0"
},
{
"input": "3\n14 15 92",
"output": "67"
},
{
"input": "1\n1000000",
"output": "999975"
},
{
"input": "25\n1000000 ... | 1,680,124,981 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | testcases = []
n_testcases = int(input())
for _ in range(n_testcases):
data_list = input()
testcases.append([data_list])
def true_if_first_elemnt_plus_second_element_is_equal_than_third_element(a, b, c):
return (a + b) == c
for testcase in testcases:
print(testcase)
a, b, c = [int(x) fo... | Title: Declined Finalists
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to t... | ```python
testcases = []
n_testcases = int(input())
for _ in range(n_testcases):
data_list = input()
testcases.append([data_list])
def true_if_first_elemnt_plus_second_element_is_equal_than_third_element(a, b, c):
return (a + b) == c
for testcase in testcases:
print(testcase)
a, b, c = ... | -1 | |
48 | C | The Race | PROGRAMMING | 1,800 | [
"math"
] | C. The Race | 2 | 256 | Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer.
So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with α li... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000) which represents the number of petrol stations where Vanya has stopped. The next line has *n* space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two n... | Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". | [
"3\n1 2 4\n",
"2\n1 2\n"
] | [
"unique\n5\n",
"not unique\n"
] | In the second example the answer is not unique. For example, if α = 10, we'll have such a sequence as 1, 2, 3, and if α = 14, the sequence will be 1, 2, 4. | 0 | [
{
"input": "3\n1 2 4",
"output": "unique\n5"
},
{
"input": "2\n1 2",
"output": "not unique"
},
{
"input": "1\n5",
"output": "not unique"
},
{
"input": "3\n1 3 4",
"output": "unique\n6"
},
{
"input": "5\n1 2 3 5 6",
"output": "unique\n7"
},
{
"input": "... | 1,648,830,381 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 1,060 | 0 | n = int(input())
stops = list(map(int, input().split()))
low = 10
high = stops[0] * 10 + 10
i = 0
for mile in range(1, stops[-1] + 1):
if stops[i] == mile:
high = min(high, (mile * 10 + 10) / (i + 1))
i += 1
else:
low = max(low, (mile * 10 + 10) / (i + 1))
a = int((low + len(stops) * low ... | Title: The Race
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer.
So, Vasya leaves ci... | ```python
n = int(input())
stops = list(map(int, input().split()))
low = 10
high = stops[0] * 10 + 10
i = 0
for mile in range(1, stops[-1] + 1):
if stops[i] == mile:
high = min(high, (mile * 10 + 10) / (i + 1))
i += 1
else:
low = max(low, (mile * 10 + 10) / (i + 1))
a = int((low + len(sto... | 3.735 |
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,628,970,056 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 61 | 20,172,800 | s = 'helloaa'
if s.find('hello')==False:
print('yes')
else: print('error') | 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
s = 'helloaa'
if s.find('hello')==False:
print('yes')
else: print('error')
``` | 0 |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,684,009,430 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | n = int(input())
x = input().split()
x = list(map(int, x))
maxn = max(x)
it = 0
for i in range(n):
it += maxn - x[i]
print(it) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
n = int(input())
x = input().split()
x = list(map(int, x))
maxn = max(x)
it = 0
for i in range(n):
it += maxn - x[i]
print(it)
``` | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,670,238,344 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | m,n,a=map(int,input().split())
t=0
if m%a >0 :
m=m//a+1
else:
m=m//a
if n%a >0 :
n=n//a+1
else:
n=n//a
t=t+m*n
print(t)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
m,n,a=map(int,input().split())
t=0
if m%a >0 :
m=m//a+1
else:
m=m//a
if n%a >0 :
n=n//a+1
else:
n=n//a
t=t+m*n
print(t)
``` | 3.977 |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,672,946,969 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n=int(input())
lis=list(map(int,input().split()))
maxi=0
mini=0
count=0
for i in range(n):
if maxi<lis[i]:
maxi=lis[i]
count +=1
#5print(count)
if mini>lis[i]:
mini=lis[i]
count +=1
#print(count)
print(count) | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n=int(input())
lis=list(map(int,input().split()))
maxi=0
mini=0
count=0
for i in range(n):
if maxi<lis[i]:
maxi=lis[i]
count +=1
#5print(count)
if mini>lis[i]:
mini=lis[i]
count +=1
#print(count)
print(count)
``` | 0 | |
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea... | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *... | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"outpu... | 1,697,359,612 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | import sys
n,t = map(int,sys.stdin.readline().strip().split())
l = list(sys.stdin.readline().strip())
i = 0
while t > 0 :
while i < n-1:
if l[i] == 'B' and l[i+1] == 'G':
l[i],l[i+1] = l[i+1],l[i]
i += 1
t -= 1
for i in range(len(l)):
sys.stdout.write(l[i]) | Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a... | ```python
import sys
n,t = map(int,sys.stdin.readline().strip().split())
l = list(sys.stdin.readline().strip())
i = 0
while t > 0 :
while i < n-1:
if l[i] == 'B' and l[i+1] == 'G':
l[i],l[i+1] = l[i+1],l[i]
i += 1
t -= 1
for i in range(len(l)):
sys.stdout.write(l[i])
... | 0 | |
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,675,066,774 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 307,200 | m=input();print(m+m[::-1])
| 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
m=input();print(m+m[::-1])
``` | 3 | |
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,694,716,194 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 0 | power = int(input())
num = 1
for p in range(power):
num*=5
print(num) | Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and ge... | ```python
power = int(input())
num = 1
for p in range(power):
num*=5
print(num)
``` | 0 | |
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate... | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed progra... | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal so... | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20... | 1,635,477,166 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 11,571,200 | n, m = [int(i) for i in input().split(" ")]
times = [int(i) for i in input().split(" ")]
times.extend([0, m])
times.sort()
untouched_time = 0
for i in range(1, len(times), 2):
untouched_time += times[i] - times[i - 1]
insert_time = 0
for i in range(len(times)):
for num_checking in (times[i] - 1, ti... | Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows y... | ```python
n, m = [int(i) for i in input().split(" ")]
times = [int(i) for i in input().split(" ")]
times.extend([0, m])
times.sort()
untouched_time = 0
for i in range(1, len(times), 2):
untouched_time += times[i] - times[i - 1]
insert_time = 0
for i in range(len(times)):
for num_checking in (times[... | 0 | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,551,644,725 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 248 | 0 | n=int(input())
l=[]
l=list(map(int,input().split()))
l1=[]
for i in l:
if (i not in l1):
l1.append(i)
l1.sort()
if (len(l1)==1):
print("NO")
else :
print (l1[1])
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
n=int(input())
l=[]
l=list(map(int,input().split()))
l1=[]
for i in l:
if (i not in l1):
l1.append(i)
l1.sort()
if (len(l1)==1):
print("NO")
else :
print (l1[1])
``` | 3.938 |
614 | A | Link/Cut Tree | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agre... | The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). | Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). | [
"1 10 2\n",
"2 4 5\n"
] | [
"1 2 4 8 ",
"-1"
] | Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | 500 | [
{
"input": "1 10 2",
"output": "1 2 4 8 "
},
{
"input": "2 4 5",
"output": "-1"
},
{
"input": "18102 43332383920 28554",
"output": "28554 815330916 "
},
{
"input": "19562 31702689720 17701",
"output": "313325401 "
},
{
"input": "11729 55221128400 313",
"output... | 1,675,418,682 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a = map(int, input().split())
l = a[0]
r = a[1]
k = a[2]
p = 1
z = False
while p <= r:
if p >= l:
print(p)
z = True
p = p * k
if not z:
print(-1)
| Title: Link/Cut Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand ... | ```python
a = map(int, input().split())
l = a[0]
r = a[1]
k = a[2]
p = 1
z = False
while p <= r:
if p >= l:
print(p)
z = True
p = p * k
if not z:
print(-1)
``` | -1 | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,692,420,394 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
long long n1 = ceil((n*1.0)/2);
long long n2 = n - n1;
if(n % 2==0) {
cout<<(2 * (n1 * (n1 + 1)))/2 - pow(n2,2);
}
else {
cout<<(2 * (n2 * (n2 + 1)))/2 - pow(n1,2);
}
re... | Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
long long n1 = ceil((n*1.0)/2);
long long n2 = n - n1;
if(n % 2==0) {
cout<<(2 * (n1 * (n1 + 1)))/2 - pow(n2,2);
}
else {
cout<<(2 * (n2 * (n2 + 1)))/2 - pow(n1,2);
... | -1 | |
284 | B | Cows and Poker Game | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any be... | The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* characters, each either "A", "I", or "F". The *i*-th character is "A" if the *i*-th player's status is "ALLIN", "I" if the *i*-th player's status is "IN", or "F" if the *i*-th player's status is "FOLDED". | The first line should contain a single integer denoting the number of players that can currently show their hands. | [
"6\nAFFAAA\n",
"3\nAFI\n"
] | [
"4\n",
"1\n"
] | In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand. | 1,000 | [
{
"input": "6\nAFFAAA",
"output": "4"
},
{
"input": "3\nAFI",
"output": "1"
},
{
"input": "3\nFFF",
"output": "0"
},
{
"input": "3\nFIF",
"output": "1"
},
{
"input": "3\nAAA",
"output": "3"
},
{
"input": "3\nIII",
"output": "0"
},
{
"input"... | 1,592,993,538 | 2,147,483,647 | Python 3 | OK | TESTS | 66 | 218 | 7,475,200 | n=int(input())
m=input()
if m.count('I')==1:
print(1)
elif m.count('I')>1:
print(0)
else:
print(m.count('A'))
| Title: Cows and Poker Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player who... | ```python
n=int(input())
m=input()
if m.count('I')==1:
print(1)
elif m.count('I')>1:
print(0)
else:
print(m.count('A'))
``` | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,503,200,861 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 0 | n = int(input())
s = input()
a = s.split()
for i in range(len(a)):
a[i] = int(a[i])
sume = 0
sumo = 0
i = 0
while i < len(a):
if a[i] % 2 == 0:
sume += 1
ie = i+1
else:
sumo += 1
io = i+1
if (sume == 1 and sumo > 1) or (sume > 1 and sumo == 1):
break
i += 1
if sume == 1:
print(ie)... | 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())
s = input()
a = s.split()
for i in range(len(a)):
a[i] = int(a[i])
sume = 0
sumo = 0
i = 0
while i < len(a):
if a[i] % 2 == 0:
sume += 1
ie = i+1
else:
sumo += 1
io = i+1
if (sume == 1 and sumo > 1) or (sume > 1 and sumo == 1):
break
i += 1
if sume == 1:
... | 3.969 |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,672,030,849 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
for i in range(n):
ch = input()
l = len(ch)
if l <= 10:
print(ch)
else:
print(ch[0], l-2, ch[l-1], sep="") | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n = int(input())
for i in range(n):
ch = input()
l = len(ch)
if l <= 10:
print(ch)
else:
print(ch[0], l-2, ch[l-1], sep="")
``` | -1 |
492 | A | Vanya and Cubes | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must... | The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya. | Print the maximum possible height of the pyramid in the single line. | [
"1\n",
"25\n"
] | [
"1\n",
"4\n"
] | Illustration to the second sample: | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "25",
"output": "4"
},
{
"input": "2",
"output": "1"
},
{
"input": "4115",
"output": "28"
},
{
"input": "9894",
"output": "38"
},
{
"input": "7969",
"output": "35"
},
{
"input": "6560",
"outpu... | 1,688,269,454 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 61 | 0 | import math as m
def cbrt(x):
return x**(1/3)
n = int(input())
k = (81*n)/m.sqrt(27)
x = (m.sqrt(3)/3)*(cbrt(k + m.sqrt(k**2 - 1)) + cbrt(k - m.sqrt(k**2 - 1))) - 1
print(m.floor(x)) | Title: Vanya and Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the t... | ```python
import math as m
def cbrt(x):
return x**(1/3)
n = int(input())
k = (81*n)/m.sqrt(27)
x = (m.sqrt(3)/3)*(cbrt(k + m.sqrt(k**2 - 1)) + cbrt(k - m.sqrt(k**2 - 1))) - 1
print(m.floor(x))
``` | 0 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,632,218,730 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 6,758,400 | s=input()
a=[]
g='aeiou'
for i in s:
if i.isalpha():
a.append(i)
if a[len(a)-1] in g:
print('YES')
else:
print('NO') | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
s=input()
a=[]
g='aeiou'
for i in s:
if i.isalpha():
a.append(i)
if a[len(a)-1] in g:
print('YES')
else:
print('NO')
``` | 0 |
757 | A | Gotta Catch Em' All! | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas... | Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. . | Output a single integer, the answer to the problem. | [
"Bulbbasaur\n",
"F\n",
"aBddulbasaurrgndgbualdBdsagaurrgndbb\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | 500 | [
{
"input": "Bulbbasaur",
"output": "1"
},
{
"input": "F",
"output": "0"
},
{
"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb",
"output": "2"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr",
"output": "5"
},
{
"input": "BBBBBBB... | 1,613,721,475 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 77 | 409,600 | def main():
s = input()
dic = {'B': 0, 'u': 0, 'l': 0, 'b': 0, 'a': 0, 's': 0, 'r': 0}
for char in s:
if char in 'Bulbbasaur':
dic[char] += 1
dic['u'] //= 2
dic['b'] //= 2
dic['a'] //= 2
print(min(dic['u'], dic['b'], dic['a'], dic['B'], dic['l'], dic['s'], dic['r']))
... | Title: Gotta Catch Em' All!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsess... | ```python
def main():
s = input()
dic = {'B': 0, 'u': 0, 'l': 0, 'b': 0, 'a': 0, 's': 0, 'r': 0}
for char in s:
if char in 'Bulbbasaur':
dic[char] += 1
dic['u'] //= 2
dic['b'] //= 2
dic['a'] //= 2
print(min(dic['u'], dic['b'], dic['a'], dic['B'], dic['l'], dic['s'], dic... | 0 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,668,334,156 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 92 | 0 | def checkPrime(n):
for i in range(2,n):
if n % i == 0:
return False
return True
prime, num = tuple(map(int, input().split()))
if not checkPrime(num):
print("NO")
else:
for j in range(prime + 1, num):
if checkPrime(j):
print("NO")
else: print(... | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
def checkPrime(n):
for i in range(2,n):
if n % i == 0:
return False
return True
prime, num = tuple(map(int, input().split()))
if not checkPrime(num):
print("NO")
else:
for j in range(prime + 1, num):
if checkPrime(j):
print("NO")
el... | 0 |
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
... | 1,592,942,647 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 6,963,200 | n=int(input())
l=[i for i in range(1,1001)]
s=''.join(map(str,l))
print(s[n-1]) | Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1... | ```python
n=int(input())
l=[i for i in range(1,1001)]
s=''.join(map(str,l))
print(s[n-1])
``` | 3 | |
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr... | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO... | 1,698,215,699 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 62 | 0 | n = int(input())
cont, i = [], 1
while i * (i + 1) // 2 <= 500:
cont.append(i * (i + 1) // 2)
i += 1
print('YES' if n in cont else 'NO')
| Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
n = int(input())
cont, i = [], 1
while i * (i + 1) // 2 <= 500:
cont.append(i * (i + 1) // 2)
i += 1
print('YES' if n in cont else 'NO')
``` | 3.9845 |
875 | D | High Cry | PROGRAMMING | 2,200 | [
"binary search",
"bitmasks",
"combinatorics",
"data structures",
"divide and conquer"
] | null | null | Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :)
Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000), the number of mountains in the ridge.
Second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109), the heights of mountains in order they are located in the ridge. | Print the only integer, the number of ways to choose two different mountains. | [
"5\n3 2 1 6 5\n",
"4\n3 3 3 3\n"
] | [
"8\n",
"0\n"
] | In the first test case all the ways are pairs of mountains with the numbers (numbering from one):
In the second test case there are no such pairs because for any pair of mountains the height of cry from them is 3, and this height is equal to the height of any mountain. | 1,750 | [
{
"input": "5\n3 2 1 6 5",
"output": "8"
},
{
"input": "4\n3 3 3 3",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "1\n6",
"output": "0"
},
{
... | 1,656,191,387 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 7,680,000 | n = int(input())
maxn = 200010
arr = [0]*(maxn)
x = list(map(int, input().strip().split()))[:n]
for i in range (0, n) :
arr[i+1] = x[i]
t = [0]*(maxn)
l = [0]*(maxn)
r = [0]*(maxn)
top = 0
for i in range(1, n+1) :
while (top > 0 and (arr[t[top] | arr[i]]) == arr[i]) :
if (arr[t[top... | Title: High Cry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :)
Rick and Morty like to go to the ridge High Cry for crying loudly — there is ... | ```python
n = int(input())
maxn = 200010
arr = [0]*(maxn)
x = list(map(int, input().strip().split()))[:n]
for i in range (0, n) :
arr[i+1] = x[i]
t = [0]*(maxn)
l = [0]*(maxn)
r = [0]*(maxn)
top = 0
for i in range(1, n+1) :
while (top > 0 and (arr[t[top] | arr[i]]) == arr[i]) :
if ... | 0 | |
466 | C | Number of Ways | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. | Print a single integer — the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\... | 1,685,578,460 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 202 | 56,729,600 |
#import io, os, sys
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#print = lambda x: sys.stdout.write(str(x) + "\n")
II = lambda: int(input())
MII = lambda: map(int, input().split())
LMII = lambda: list(MII())
#SLMII = lambda: sorted(LMII())
n = II()
a = LMII()
ans = 0
s = sum(a)
... | Title: Number of Ways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the s... | ```python
#import io, os, sys
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#print = lambda x: sys.stdout.write(str(x) + "\n")
II = lambda: int(input())
MII = lambda: map(int, input().split())
LMII = lambda: list(MII())
#SLMII = lambda: sorted(LMII())
n = II()
a = LMII()
ans = 0
s ... | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,663,598,468 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | ch=str(input())
l=ch.split(' ')
while (int(l[0])<1 ) or (int(l[0])>int(l[1])) or (int(l[1])<1) or (int(l[1])>16) or (len(l)!=2) or ch[len(l[0])]!=' ' :
ch=str(input())
l=ch.split(' ')
m,n=int(l[0]),int(l[1])
if m%2==0:
print((m*n)/2)
else:
s=((m-1)*n)/2
s+=n//2
print(s) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
ch=str(input())
l=ch.split(' ')
while (int(l[0])<1 ) or (int(l[0])>int(l[1])) or (int(l[1])<1) or (int(l[1])>16) or (len(l)!=2) or ch[len(l[0])]!=' ' :
ch=str(input())
l=ch.split(' ')
m,n=int(l[0]),int(l[1])
if m%2==0:
print((m*n)/2)
else:
s=((m-1)*n)/2
s+=n//2
print(s)
``` | 0 |
804 | A | Find Amir | PROGRAMMING | 1,000 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* an... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools. | Print single integer: the minimum cost of tickets needed to visit all schools. | [
"2\n",
"10\n"
] | [
"0\n",
"4\n"
] | In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "2",
"output": "0"
},
{
"input": "10",
"output": "4"
},
{
"input": "43670",
"output": "21834"
},
{
"input": "4217",
"output": "2108"
},
{
"input": "17879",
"output": "8939"
},
{
"input": "31809",
"output": "15904"
},
{
"input": "... | 1,665,842,116 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | print((int(input())-1)//2)
#lolpypypypypypypypypypypypypypyhuzaifa
| Title: Find Amir
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel b... | ```python
print((int(input())-1)//2)
#lolpypypypypypypypypypypypypypyhuzaifa
``` | 3 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,688,482,021 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | n=int(input())
t=n
while t!=0:
r=t%10
if r==4 or r==7:
f=1
else:
f=0
break
t=int(t/10)
if f==1:
print("YES")
else:
if n%4==0 or n%7==0 or n%47==0 or n%74==0:
print("YES")
else:
print("NO")
| Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n=int(input())
t=n
while t!=0:
r=t%10
if r==4 or r==7:
f=1
else:
f=0
break
t=int(t/10)
if f==1:
print("YES")
else:
if n%4==0 or n%7==0 or n%47==0 or n%74==0:
print("YES")
else:
print("NO")
``` | 3 | |
777 | B | Game of Credit Cards | PROGRAMMING | 1,300 | [
"data structures",
"dp",
"greedy",
"sortings"
] | null | null | After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains *n* digits — Sherlock's credit card number.
The third line contains *n* digits — Moriarty's credit card number. | First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty. | [
"3\n123\n321\n",
"2\n88\n00\n"
] | [
"0\n2\n",
"2\n0\n"
] | First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks. | 1,000 | [
{
"input": "3\n123\n321",
"output": "0\n2"
},
{
"input": "2\n88\n00",
"output": "2\n0"
},
{
"input": "1\n4\n5",
"output": "0\n1"
},
{
"input": "1\n8\n7",
"output": "1\n0"
},
{
"input": "2\n55\n55",
"output": "0\n0"
},
{
"input": "3\n534\n432",
"out... | 1,613,043,630 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 93 | 0 | import math
import sys
n=int(input())
a=list(str(input()))
b=list(str(input()))
min_res=0
max_res=0
ap={};bp={}
for i in range(0,10):
ap[i]=a.count(str(i))
bp[i]=b.count(str(i))
for i in range(9,0,-1):
k=min(ap[i-1],bp[i])
max_res+=k
bp[i-1]=bp[i-1]+bp[i]-k
#max_res+=min(ap[... | Title: Game of Credit Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simpl... | ```python
import math
import sys
n=int(input())
a=list(str(input()))
b=list(str(input()))
min_res=0
max_res=0
ap={};bp={}
for i in range(0,10):
ap[i]=a.count(str(i))
bp[i]=b.count(str(i))
for i in range(9,0,-1):
k=min(ap[i-1],bp[i])
max_res+=k
bp[i-1]=bp[i-1]+bp[i]-k
#max_re... | 3 | |
171 | A | Mysterious numbers - 1 | PROGRAMMING | 1,200 | [
"*special",
"constructive algorithms"
] | null | null | The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space.
Output a single integer. | The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space. | Output a single integer. | [
"3 14\n",
"27 12\n",
"100 200\n"
] | [
"44\n",
"48\n",
"102\n"
] | none | 0 | [
{
"input": "3 14",
"output": "44"
},
{
"input": "27 12",
"output": "48"
},
{
"input": "100 200",
"output": "102"
},
{
"input": "0 0",
"output": "0"
},
{
"input": "31415 92653",
"output": "67044"
},
{
"input": "1000000000 0",
"output": "1000000000"
... | 1,554,377,018 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 186 | 0 | if __name__ == '__main__':
m,n = map(str,input().split())
if len(m) != len(n):
if len(m) < len(n):
m = (len(n) - len(m))*'0' + m
elif len(n) < len(m):
n = (len(m)-len(n))*'0' + n
sum1 = 0
j = len(n)-1
for i in range(0,len(m)):
sum1 = int(m[i]... | Title: Mysterious numbers - 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space.
Output a single integer.
Input Specification:
The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109),... | ```python
if __name__ == '__main__':
m,n = map(str,input().split())
if len(m) != len(n):
if len(m) < len(n):
m = (len(n) - len(m))*'0' + m
elif len(n) < len(m):
n = (len(m)-len(n))*'0' + n
sum1 = 0
j = len(n)-1
for i in range(0,len(m)):
sum1 ... | 0 | |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabb... | 1,585,070,801 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 264 | 10,137,600 | n = int(input())
c = []
for i in range(n):
r = i % 4
if r < 2:
c.append('a')
else:
c.append('b')
for i in c:
print(i, end = '')
print() | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o... | ```python
n = int(input())
c = []
for i in range(n):
r = i % 4
if r < 2:
c.append('a')
else:
c.append('b')
for i in c:
print(i, end = '')
print()
``` | 3 | |
888 | E | Maximum Subsequence | PROGRAMMING | 1,800 | [
"bitmasks",
"divide and conquer",
"meet-in-the-middle"
] | null | null | You are given an array *a* consisting of *n* integers, and additionally an integer *m*. You have to choose some sequence of indices *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b*1<=<<=*b*2<=<<=...<=<<=*b**k*<=≤<=*n*) in such a way that the value of is maximized. Chosen sequence can be empty.
Print the maximum possibl... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=35, 1<=≤<=*m*<=≤<=109).
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum possible value of . | [
"4 4\n5 2 4 1\n",
"3 20\n199 41 299\n"
] | [
"3\n",
"19\n"
] | In the first example you can choose a sequence *b* = {1, 2}, so the sum <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c856546022c2feee13d02a4ec9cd1d361ab3a756.png" style="max-width: 100.0%;max-height: 100.0%;"/> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example... | 0 | [
{
"input": "4 4\n5 2 4 1",
"output": "3"
},
{
"input": "3 20\n199 41 299",
"output": "19"
},
{
"input": "5 10\n47 100 49 2 56",
"output": "9"
},
{
"input": "5 1000\n38361 75847 14913 11499 8297",
"output": "917"
},
{
"input": "10 10\n48 33 96 77 67 59 35 15 14 86"... | 1,627,576,637 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 139 | 22,528,000 | from bisect import bisect_left
n, m = map(int, input().split())
t = list(map(int, input().split()))
def g(x, i, n, s):
if i < n:
g(x, i + 1, n, s + t[i])
g(x, i + 1, n, s)
else:
x.add(s % m)
k = n >> 1
x, y = set(), set()
g(x, 0, k, 0)
g(y, k, n, 0)
y.sort()
print(max(i + y[bisect_left(y, ... | Title: Maximum Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* consisting of *n* integers, and additionally an integer *m*. You have to choose some sequence of indices *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b*1<=<<=*b*2<=<<=...<=<<=*b**k*<=≤<=*n*... | ```python
from bisect import bisect_left
n, m = map(int, input().split())
t = list(map(int, input().split()))
def g(x, i, n, s):
if i < n:
g(x, i + 1, n, s + t[i])
g(x, i + 1, n, s)
else:
x.add(s % m)
k = n >> 1
x, y = set(), set()
g(x, 0, k, 0)
g(y, k, n, 0)
y.sort()
print(max(i + y[bisec... | -1 | |
408 | B | Garland | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.
The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each pie... | The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.
The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the ... | Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer. | [
"aaabbac\naabbccac\n",
"a\nz\n"
] | [
"6\n",
"-1"
] | In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.
In the second test sample Vasya cannot mak... | 1,000 | [
{
"input": "aaabbac\naabbccac",
"output": "6"
},
{
"input": "a\nz",
"output": "-1"
},
{
"input": "r\nr",
"output": "1"
},
{
"input": "stnsdn\nndnndsn",
"output": "4"
},
{
"input": "yqfqfp\ntttwtqq",
"output": "-1"
},
{
"input": "zzbbrrtrtzr\ntbbtrrrzr"... | 1,597,908,476 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 108 | 307,200 | z=[0]*27
z1=[0]*27
for i in input():z[ord(i)-97]+=1
for i in input():z1[ord(i)-97]+=1
s=0
for i in range(27):
if z[i]>=z1[i]:s+=z1[i]
elif z1[i]!=0 and z[i]!=0:s+=z[i]
if z1[i] and not (z[i]):exit(print(-1))
print(s) | Title: Garland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.... | ```python
z=[0]*27
z1=[0]*27
for i in input():z[ord(i)-97]+=1
for i in input():z1[ord(i)-97]+=1
s=0
for i in range(27):
if z[i]>=z1[i]:s+=z1[i]
elif z1[i]!=0 and z[i]!=0:s+=z[i]
if z1[i] and not (z[i]):exit(print(-1))
print(s)
``` | 3 | |
820 | B | Mister B and Angle in Polygon | PROGRAMMING | 1,300 | [
"constructive algorithms",
"geometry",
"math"
] | null | null | On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides).
That's why Mister B decided to use this polygon. Now Mister B must... | First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees. | Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order. | [
"3 15\n",
"4 67\n",
"4 68\n"
] | [
"1 2 3\n",
"2 1 3\n",
"4 1 2\n"
] | In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.
Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: ... | 1,000 | [
{
"input": "3 15",
"output": "2 1 3"
},
{
"input": "4 67",
"output": "2 1 3"
},
{
"input": "4 68",
"output": "2 1 4"
},
{
"input": "3 1",
"output": "2 1 3"
},
{
"input": "3 180",
"output": "2 1 3"
},
{
"input": "100000 1",
"output": "2 1 558"
},
... | 1,503,399,357 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | '''
21st august 2017 monday
codeforces
'''
import math;
n, a = input().split()
n, a = int(n), int(a)
eq = ((n - 2) * 180) / n
part = eq/(n - 2)
angl = part
min_angle = math.inf
min_v = 3
for i in range(n, 2, -1):
#print(angl - a)
if abs(angl - a) < min_angle:
min_angle = angl
min_v = i
an... | Title: Mister B and Angle in Polygon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *... | ```python
'''
21st august 2017 monday
codeforces
'''
import math;
n, a = input().split()
n, a = int(n), int(a)
eq = ((n - 2) * 180) / n
part = eq/(n - 2)
angl = part
min_angle = math.inf
min_v = 3
for i in range(n, 2, -1):
#print(angl - a)
if abs(angl - a) < min_angle:
min_angle = angl
min_v ... | 0 | |
1,003 | B | Binary String Constructing | PROGRAMMING | 1,300 | [
"constructive algorithms"
] | null | null | You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $1 \le i < n$) such that $s_i \ne s_{i + 1}$. It is guaranteed that the answer always exists.
For example, fo... | The first line of the input contains three integers $a$, $b$ and $x$ ($1 \le a, b \le 100, 1 \le x < a + b)$. | Print only one string $s$, where $s$ is any binary string satisfying conditions described above. It is guaranteed that the answer always exists. | [
"2 2 1\n",
"3 3 3\n",
"5 3 6\n"
] | [
"1100\n",
"101100\n",
"01010100\n"
] | All possible answers for the first example:
- 1100; - 0011.
All possible answers for the second example:
- 110100; - 101100; - 110010; - 100110; - 011001; - 001101; - 010011; - 001011. | 0 | [
{
"input": "2 2 1",
"output": "1100"
},
{
"input": "3 3 3",
"output": "101100"
},
{
"input": "5 3 6",
"output": "01010100"
},
{
"input": "100 1 2",
"output": "01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
... | 1,682,600,802 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 77 | 0 | a,b,x=map(int,input().split())
t="10";x-=1;a-=1;b-=1
while x>0:
if x==1:
if b!=0:
t+="0"*a+"1"*b
x=0;a=0;b=0
else:
t="0"*a+t
a=0;x=0
else:
t+="10"
x-=2;a-=1;b-=1
t="1"*b+t+"0"*a
print(t)
| Title: Binary String Constructing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $... | ```python
a,b,x=map(int,input().split())
t="10";x-=1;a-=1;b-=1
while x>0:
if x==1:
if b!=0:
t+="0"*a+"1"*b
x=0;a=0;b=0
else:
t="0"*a+t
a=0;x=0
else:
t+="10"
x-=2;a-=1;b-=1
t="1"*b+t+"0"*a
print(t)
... | 3 | |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,663,233,760 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | n=int(input())
l=input().split(" ")
c1=[]
c2=[]
c3=[]
for i in range(n):
if l[i]=='1':
c1.append(i)
elif l[i]=='2':
c2.append(i)
else:
c3.append(i)
if len(c1)*len(c2)*len(c3)==0:
print(0)
else:
print(min(len(c1),len(c2),len(c3)))
for i in range(min(len(c1),len(c2),len(c3)... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
n=int(input())
l=input().split(" ")
c1=[]
c2=[]
c3=[]
for i in range(n):
if l[i]=='1':
c1.append(i)
elif l[i]=='2':
c2.append(i)
else:
c3.append(i)
if len(c1)*len(c2)*len(c3)==0:
print(0)
else:
print(min(len(c1),len(c2),len(c3)))
for i in range(min(len(c1),len(c... | 3 | |
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,680,929,526 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 124 | 0 | n,a,b=map(int,input().split())
#infront>=a behind<=b
#a+b+1>=n
#a>=n-1-b
#x+y=n-1
count=0
j=0
for i in range(b+1):
if n-1-i>=a:
count+=1
else:
j=i-1
break
print(count) | 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
n,a,b=map(int,input().split())
#infront>=a behind<=b
#a+b+1>=n
#a>=n-1-b
#x+y=n-1
count=0
j=0
for i in range(b+1):
if n-1-i>=a:
count+=1
else:
j=i-1
break
print(count)
``` | 3 | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,513,095,717 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 5,529,600 | import sys
n = int(input())
a = int(n /2)
b = max(a,n - a)
while(True):
if b > a and b % a != 0:
break
if a == 1:
break
b+= 1
a -=1
print('{0} {1}'.format(a,b))
| Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
import sys
n = int(input())
a = int(n /2)
b = max(a,n - a)
while(True):
if b > a and b % a != 0:
break
if a == 1:
break
b+= 1
a -=1
print('{0} {1}'.format(a,b))
``` | 0 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,690,782,402 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 101 | 124 | 0 | from sys import stdin
def solve():
n = int(stdin.readline())
A = [int(x) for x in stdin.readline().split()]
res = [0] * n
for i, a in enumerate(A, 1):
res[a - 1] = i
print(*res)
solve()
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
from sys import stdin
def solve():
n = int(stdin.readline())
A = [int(x) for x in stdin.readline().split()]
res = [0] * n
for i, a in enumerate(A, 1):
res[a - 1] = i
print(*res)
solve()
``` | 3 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,591,701,041 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 186 | 0 | my_dict={}
n = int(input())
for _ in range(n):
word = input()
if word not in my_dict:
my_dict[word]=1
else:
my_dict[word]+=1
sorted(my_dict.items(),key= lambda dic:dic[1])
for k in my_dict.keys():
print(k)
break
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
my_dict={}
n = int(input())
for _ in range(n):
word = input()
if word not in my_dict:
my_dict[word]=1
else:
my_dict[word]+=1
sorted(my_dict.items(),key= lambda dic:dic[1])
for k in my_dict.keys():
print(k)
break
``` | 0 |
799 | D | Field expansion | PROGRAMMING | 2,100 | [
"brute force",
"dp",
"meet-in-the-middle"
] | null | null | In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are *n* extensions, the *i*-th of them multiplies the width or the length (b... | The first line contains five integers *a*, *b*, *h*, *w* and *n* (1<=≤<=*a*,<=*b*,<=*h*,<=*w*,<=*n*<=≤<=100<=000) — the sizes of the rectangle needed to be placed, the initial sizes of the field and the number of available extensions.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (2<=≤<=*a**i*<=≤<=1... | Print the minimum number of extensions needed to reach Arkady's goal. If it is not possible to place the rectangle on the field with all extensions, print -1. If the rectangle can be placed on the initial field, print 0. | [
"3 3 2 4 4\n2 5 4 10\n",
"3 3 3 3 5\n2 3 5 4 2\n",
"5 5 1 2 3\n2 2 3\n",
"3 4 1 1 3\n2 3 2\n"
] | [
"1\n",
"0\n",
"-1\n",
"3\n"
] | In the first example it is enough to use any of the extensions available. For example, we can enlarge *h* in 5 times using the second extension. Then *h* becomes equal 10 and it is now possible to place the rectangle on the field. | 2,000 | [
{
"input": "3 3 2 4 4\n2 5 4 10",
"output": "1"
},
{
"input": "3 3 3 3 5\n2 3 5 4 2",
"output": "0"
},
{
"input": "5 5 1 2 3\n2 2 3",
"output": "-1"
},
{
"input": "3 4 1 1 3\n2 3 2",
"output": "3"
},
{
"input": "572 540 6 2 12\n2 3 2 2 2 3 3 3 2 2 2 2",
"outpu... | 1,683,231,751 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 26 | 280 | 20,684,800 | from math import *
a,b,w0,h0,n=map(int,input().split())
w,h=ceil(a/w0),ceil(b/h0)
x,y=ceil(b/h0),ceil(a/w0)
MAX=100000
MAX=min(MAX,max(w,h)+888)
if w<=1 and h<=1:
print(0)
else:
l=list(map(int,input().split()))
l.sort()
l.reverse()
l=l[:34]
dp=[0 for i in range(MAX+1)] #max width fo... | Title: Field expansion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number o... | ```python
from math import *
a,b,w0,h0,n=map(int,input().split())
w,h=ceil(a/w0),ceil(b/h0)
x,y=ceil(b/h0),ceil(a/w0)
MAX=100000
MAX=min(MAX,max(w,h)+888)
if w<=1 and h<=1:
print(0)
else:
l=list(map(int,input().split()))
l.sort()
l.reverse()
l=l[:34]
dp=[0 for i in range(MAX+1)] #ma... | 0 | |
549 | A | Face Detection | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<... | The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively.
Next *n* lines define the image. Each line contains *m* lowercase Latin letters. | In the single line print the number of faces on the image. | [
"4 4\nxxxx\nxfax\nxcex\nxxxx\n",
"4 2\nxx\ncf\nae\nxx\n",
"2 3\nfac\ncef\n",
"1 4\nface\n"
] | [
"1\n",
"1\n",
"2\n",
"0\n"
] | In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
In ... | 250 | [
{
"input": "4 4\nxxxx\nxfax\nxcex\nxxxx",
"output": "1"
},
{
"input": "4 2\nxx\ncf\nae\nxx",
"output": "1"
},
{
"input": "2 3\nfac\ncef",
"output": "2"
},
{
"input": "1 4\nface",
"output": "0"
},
{
"input": "5 5\nwmmwn\nlurcm\nkeetd\nfokon\ncxxgx",
"output": "... | 1,473,342,707 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 819,200 | import sys
rows, cols = map(int, input().split())
matrix = []
counter = 0
if rows==1 or cols ==1:
print(0)
sys.exit()
for i in range(0,rows):
lst = list(str(input()))
matrix.append(lst)
for i in range(0,rows):
for j in range(0,cols):
if matrix[i][j] == 'f':
... | Title: Face Detection
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem a... | ```python
import sys
rows, cols = map(int, input().split())
matrix = []
counter = 0
if rows==1 or cols ==1:
print(0)
sys.exit()
for i in range(0,rows):
lst = list(str(input()))
matrix.append(lst)
for i in range(0,rows):
for j in range(0,cols):
if matrix[i][j] == 'f':
... | 0 | |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,651,635,112 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | n=int(input())
radios = [int(num) for num in input().split(" ", n-1)]
sum = 0
x = 1
for r in sorted(radios):
sum += r*r*x
x *= -1
print(abs(sum*3.1415926536)) | Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
n=int(input())
radios = [int(num) for num in input().split(" ", n-1)]
sum = 0
x = 1
for r in sorted(radios):
sum += r*r*x
x *= -1
print(abs(sum*3.1415926536))
``` | 3 | |
294 | A | Shaass and Oskols | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*... | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i... | On the *i*-th line of the output print the number of birds on the *i*-th wire. | [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] | [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] | none | 500 | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 8... | 1,662,162,619 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n=int(input())
a=list(map(int,input().split(" ")))
m=int(input())
for i in range(m):
x,y=list(map(int,input().split(" ")))
x=x-1
if x==0:
a[x+1]+=(a[x]-y)
if x==n-1:
a[x-1]+=y-1
else:
a[x-1]+=y-1
a[x+1]+=(a[x]-y)
a[x]=0
for i in a:
print(i)
| Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each... | ```python
n=int(input())
a=list(map(int,input().split(" ")))
m=int(input())
for i in range(m):
x,y=list(map(int,input().split(" ")))
x=x-1
if x==0:
a[x+1]+=(a[x]-y)
if x==n-1:
a[x-1]+=y-1
else:
a[x-1]+=y-1
a[x+1]+=(a[x]-y)
a[x]=0
for i in a:
print(i)
``` | 0 | |
839 | A | Arya and Bran | PROGRAMMING | 900 | [
"implementation"
] | null | null | Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. | [
"2 3\n1 2\n",
"3 17\n10 10 10\n",
"1 9\n10\n"
] | [
"2",
"3",
"-1"
] | In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies with... | 500 | [
{
"input": "2 3\n1 2",
"output": "2"
},
{
"input": "3 17\n10 10 10",
"output": "3"
},
{
"input": "1 9\n10",
"output": "-1"
},
{
"input": "10 70\n6 5 2 3 3 2 1 4 3 2",
"output": "-1"
},
{
"input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",... | 1,614,929,051 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 62 | 307,200 | n,k=input().split()
n=int(n)
k=int(k)
a=list(map(int, input().split()))
a.append(0)
s=0
i=0
while s<k and i<n:
if a[i]>8:
s+=8
a[i+1]+=a[i]-8
else:s+=a[i]
i+=1
#print(s,i)
if s>=k:
print(i)
else:print(-1) | Title: Arya and Bran
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**... | ```python
n,k=input().split()
n=int(n)
k=int(k)
a=list(map(int, input().split()))
a.append(0)
s=0
i=0
while s<k and i<n:
if a[i]>8:
s+=8
a[i+1]+=a[i]-8
else:s+=a[i]
i+=1
#print(s,i)
if s>=k:
print(i)
else:print(-1)
``` | 3 | |
928 | A | Login Verification | PROGRAMMING | 1,200 | [
"*special",
"strings"
] | null | null | When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ... | The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the exi... | Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes). | [
"1_wat\n2\n2_wat\nwat_1\n",
"000\n3\n00\nooA\noOo\n",
"_i_\n3\n__i_\n_1_\nI\n",
"La0\n3\n2a0\nLa1\n1a0\n",
"abc\n1\naBc\n",
"0Lil\n2\nLIL0\n0Ril\n"
] | [
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n"
] | In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one. | 500 | [
{
"input": "1_wat\n2\n2_wat\nwat_1",
"output": "Yes"
},
{
"input": "000\n3\n00\nooA\noOo",
"output": "No"
},
{
"input": "_i_\n3\n__i_\n_1_\nI",
"output": "No"
},
{
"input": "La0\n3\n2a0\nLa1\n1a0",
"output": "No"
},
{
"input": "abc\n1\naBc",
"output": "No"
}... | 1,654,178,280 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 46 | 0 | l=input()
f=lambda x: x.lower().replace('0','o').replace('1','l').replace('i','l')
print(['Yes','No'][f(l)in map(f,[input()for r in range(int(input()))])]) | Title: Login Verification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercas... | ```python
l=input()
f=lambda x: x.lower().replace('0','o').replace('1','l').replace('i','l')
print(['Yes','No'][f(l)in map(f,[input()for r in range(int(input()))])])
``` | 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,697,567,275 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 248 | 716,800 | x = input()
t = False
if "0" in x:
for i in x:
if "0" == i and t == False:
t = True
continue
print(i, end="")
else:
print(x[:-1])
| Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
x = input()
t = False
if "0" in x:
for i in x:
if "0" == i and t == False:
t = True
continue
print(i, end="")
else:
print(x[:-1])
``` | 3 | |
978 | B | File Name | PROGRAMMING | 800 | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia... | The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | 0 | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
... | 1,680,905,419 | 2,147,483,647 | Python 3 | OK | TESTS | 13 | 46 | 0 | n = int(input())
s = input()
cnt = 1
k = 0
maxk = 0
for i in range(len(s)-1):
if s[i] == 'x' and s[i + 1] == 'x':
cnt += 1
if cnt >= 3:
k += 1
else:
maxk = max(maxk, k)
cnt = 1
print(k) | Title: File Name
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let... | ```python
n = int(input())
s = input()
cnt = 1
k = 0
maxk = 0
for i in range(len(s)-1):
if s[i] == 'x' and s[i + 1] == 'x':
cnt += 1
if cnt >= 3:
k += 1
else:
maxk = max(maxk, k)
cnt = 1
print(k)
``` | 3 | |
961 | B | Lecture Sleep | PROGRAMMING | 1,200 | [
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ... | The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theore... | Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] | [
"16\n"
] | In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | 0 | [
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4... | 1,674,394,933 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 93 | 16,793,600 | import sys
# sys.stdin, sys.stdout = open("input.txt", "r"), open("output.txt", "w")
def main():
n, k = map(int, input().split())
a = [int(a) for a in input().split()]
b = [int(a) for a in input().split()]
ans = 0
for i in range(n):
if b[i]:
ans += a[i]
pre = [0... | Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for al... | ```python
import sys
# sys.stdin, sys.stdout = open("input.txt", "r"), open("output.txt", "w")
def main():
n, k = map(int, input().split())
a = [int(a) for a in input().split()]
b = [int(a) for a in input().split()]
ans = 0
for i in range(n):
if b[i]:
ans += a[i]
... | 3 | |
818 | A | Diplomas and Certificates | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ... | The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. | Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners. | [
"18 2\n",
"9 10\n",
"1000000000000 5\n",
"1000000000000 499999999999\n"
] | [
"3 6 9\n",
"0 0 9\n",
"83333333333 416666666665 500000000002\n",
"1 499999999999 500000000000\n"
] | none | 0 | [
{
"input": "18 2",
"output": "3 6 9"
},
{
"input": "9 10",
"output": "0 0 9"
},
{
"input": "1000000000000 5",
"output": "83333333333 416666666665 500000000002"
},
{
"input": "1000000000000 499999999999",
"output": "1 499999999999 500000000000"
},
{
"input": "1 1",... | 1,659,539,977 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 62 | 0 | import sys
n, k = (int(el) for el in input().split())
if k > n:
print(0, 0, n)
sys.exit()
'''a, b, c = 0, 0, 0
a = int((n // 2) ** 0.5)
b = a * k
c = n - (a + b)
'''
'''for i in range((n // 2) ** 0.5, 0, -1):
x = i
y = n // 2 - i
if max(y, x) / min(x, y) == k:
a = min(x, ... | Title: Diplomas and Certificates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with... | ```python
import sys
n, k = (int(el) for el in input().split())
if k > n:
print(0, 0, n)
sys.exit()
'''a, b, c = 0, 0, 0
a = int((n // 2) ** 0.5)
b = a * k
c = n - (a + b)
'''
'''for i in range((n // 2) ** 0.5, 0, -1):
x = i
y = n // 2 - i
if max(y, x) / min(x, y) == k:
a... | 3 | |
733 | A | Grasshopper And the String | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ... | The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. | Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. | [
"ABABBBACFEYUKOTT\n",
"AAA\n"
] | [
"4",
"1"
] | none | 500 | [
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
... | 1,625,394,863 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 62 | 0 | s = input()+' '
a = ['A', 'U', 'Y', 'E', 'O', 'I']
b = 0
c = 0
for i in s:
c += 1
if i in a:
if b < c:
b = c
c = 0
if b < c:
b = c
print(b) | Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en... | ```python
s = input()+' '
a = ['A', 'U', 'Y', 'E', 'O', 'I']
b = 0
c = 0
for i in s:
c += 1
if i in a:
if b < c:
b = c
c = 0
if b < c:
b = c
print(b)
``` | 3 | |
895 | A | Pizza Separation | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=360) — the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360) — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. | Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya. | [
"4\n90 90 90 90\n",
"3\n100 100 160\n",
"1\n360\n",
"4\n170 30 150 10\n"
] | [
"0\n",
"40\n",
"360\n",
"0\n"
] | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Pety... | 500 | [
{
"input": "4\n90 90 90 90",
"output": "0"
},
{
"input": "3\n100 100 160",
"output": "40"
},
{
"input": "1\n360",
"output": "360"
},
{
"input": "4\n170 30 150 10",
"output": "0"
},
{
"input": "5\n10 10 10 10 320",
"output": "280"
},
{
"input": "8\n45 4... | 1,627,578,257 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 6,758,400 | n=int(input())
l=list(map(int,input().split()))
k=360
for i in range(n):
for j in range(i,n):k=min(k,abs(sum(l[i:j])))
print(k) | Title: Pizza Separation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut in... | ```python
n=int(input())
l=list(map(int,input().split()))
k=360
for i in range(n):
for j in range(i,n):k=min(k,abs(sum(l[i:j])))
print(k)
``` | 0 | |
44 | B | Cola | PROGRAMMING | 1,500 | [
"implementation"
] | B. Cola | 2 | 256 | To celebrate the opening of the Winter Computer School the organizers decided to buy in *n* liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly *a* bottles 0.5 in volume, *b* one-liter bottles and *c... | The first line contains four integers — *n*, *a*, *b*, *c* (1<=≤<=*n*<=≤<=10000, 0<=≤<=*a*,<=*b*,<=*c*<=≤<=5000). | Print the unique number — the solution to the problem. If it is impossible to buy exactly *n* liters of cola, print 0. | [
"10 5 5 5\n",
"3 0 0 2\n"
] | [
"9\n",
"0\n"
] | none | 0 | [
{
"input": "10 5 5 5",
"output": "9"
},
{
"input": "3 0 0 2",
"output": "0"
},
{
"input": "1 0 0 0",
"output": "0"
},
{
"input": "1 1 0 0",
"output": "0"
},
{
"input": "1 2 0 0",
"output": "1"
},
{
"input": "1 0 1 0",
"output": "1"
},
{
"in... | 1,579,383,538 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 218 | 0 | n, a, b, c = map(int, input().split())
res = set()
for x in range(0, a + 1):
for y in range(0, b + 1):
if 0 <= (n - 0.5 * x - y) // 2 <= c:
res.add('%s %s %s' % (x, y, (n - (0.5 * x + y)) // 2))
print(len(res) // 4)
| Title: Cola
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
To celebrate the opening of the Winter Computer School the organizers decided to buy in *n* liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volu... | ```python
n, a, b, c = map(int, input().split())
res = set()
for x in range(0, a + 1):
for y in range(0, b + 1):
if 0 <= (n - 0.5 * x - y) // 2 <= c:
res.add('%s %s %s' % (x, y, (n - (0.5 * x + y)) // 2))
print(len(res) // 4)
``` | 0 |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,691,272,726 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | num = int(input())
c = 0
for i in range(1,num+1):
if i%2 == 0 :
c+=i
else:
c-=i
print(c) | Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
num = int(input())
c = 0
for i in range(1,num+1):
if i%2 == 0 :
c+=i
else:
c-=i
print(c)
``` | 0 | |
978 | B | File Name | PROGRAMMING | 800 | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia... | The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | 0 | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
... | 1,694,756,076 | 2,147,483,647 | Python 3 | OK | TESTS | 13 | 46 | 0 | size = int(input())
s = input()
count, remove = 0, 0
for i in s:
if i == 'x':
count += 1
if count > 2:
remove += 1
else:
count = 0
if remove == 0:
print(0)
else:
print(remove) | Title: File Name
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let... | ```python
size = int(input())
s = input()
count, remove = 0, 0
for i in s:
if i == 'x':
count += 1
if count > 2:
remove += 1
else:
count = 0
if remove == 0:
print(0)
else:
print(remove)
``` | 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,691,272,057 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 31 | 0 | n, m, c = input().split()
n, m = int(n), int(m)
office = []
deputies = set()
for _ in range(n):
office.append(list(input()))
# print(office)
for i in range(n):
for j in range(m):
if office[i][j] == c:
try:
if office[i + 1][j] != '.' and office[i + 1][j] != c:
... | 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)
office = []
deputies = set()
for _ in range(n):
office.append(list(input()))
# print(office)
for i in range(n):
for j in range(m):
if office[i][j] == c:
try:
if office[i + 1][j] != '.' and office[i + 1][j] !... | 0 |
180 | C | Letter | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to... | The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. | Print a single number — the least number of actions needed to make the message fancy. | [
"PRuvetSTAaYA\n",
"OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n",
"helloworld\n"
] | [
"5\n",
"0\n",
"0\n"
] | none | 0 | [
{
"input": "PRuvetSTAaYA",
"output": "5"
},
{
"input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA",
"output": "0"
},
{
"input": "helloworld",
"output": "0"
},
{
"input": "P",
"output": "0"
},
{
"input": "t",
"output": "0"
},
{
"input": "XdJ",
"output": "1... | 1,600,177,844 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 156 | 0 | a = str(input())
b = a
b.upper()
y , x = 0 , 0
for i in range(len(a)):
if b[i] != a[i]:
x+=1
else:
y = max(y+1,x)
print(y)
| Title: Letter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them... | ```python
a = str(input())
b = a
b.upper()
y , x = 0 , 0
for i in range(len(a)):
if b[i] != a[i]:
x+=1
else:
y = max(y+1,x)
print(y)
``` | 0 | |
463 | B | Caisa and Pylons | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | [
"5\n3 4 3 2 4\n",
"3\n4 4 4\n"
] | [
"4\n",
"4\n"
] | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | 1,000 | [
{
"input": "5\n3 4 3 2 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20... | 1,597,687,643 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 187 | 10,956,800 | n = int(input())+1
lst = list(map(int, input().split()))
lst = [0] + lst
money = 0
energy = 0
for i in range(n-1):
if lst[i+1] == lst[i]: continue
if lst[i+1] > lst[i]:
if energy > lst[i+1] - lst[i]:
energy -= lst[i+1] - lst[i]
else:
money += (lst[i+1] - lst[i]) - energy
energy = 0
else:
... | Title: Caisa and Pylons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0... | ```python
n = int(input())+1
lst = list(map(int, input().split()))
lst = [0] + lst
money = 0
energy = 0
for i in range(n-1):
if lst[i+1] == lst[i]: continue
if lst[i+1] > lst[i]:
if energy > lst[i+1] - lst[i]:
energy -= lst[i+1] - lst[i]
else:
money += (lst[i+1] - lst[i]) - energy
energy = 0 ... | 3 | |
154 | B | Colliders | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | By 2312 there were *n* Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to *n*. However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated.
In 2312 there was a startling discov... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of colliders and the number of requests, correspondingly.
Next *m* lines contain numbers of requests, one per line, in the form of either "+ i" (without the quotes) — activate the *i*-th collider, or "- i" (without ... | Print *m* lines — the results of executing requests in the above given format. The requests should be processed in the order, in which they are given in the input. Don't forget that the responses to the requests should be printed without quotes. | [
"10 10\n+ 6\n+ 10\n+ 5\n- 10\n- 5\n- 6\n+ 10\n+ 3\n+ 6\n+ 3\n"
] | [
"Success\nConflict with 6\nSuccess\nAlready off\nSuccess\nSuccess\nSuccess\nSuccess\nConflict with 10\nAlready on\n"
] | Note that in the sample the colliders don't turn on after the second and ninth requests. The ninth request could also receive response "Conflict with 3". | 1,000 | [
{
"input": "10 10\n+ 6\n+ 10\n+ 5\n- 10\n- 5\n- 6\n+ 10\n+ 3\n+ 6\n+ 3",
"output": "Success\nConflict with 6\nSuccess\nAlready off\nSuccess\nSuccess\nSuccess\nSuccess\nConflict with 10\nAlready on"
},
{
"input": "7 5\n+ 7\n+ 6\n+ 4\n+ 3\n- 7",
"output": "Success\nSuccess\nConflict with 6\nConfli... | 1,695,669,504 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | import math
# Function to find the greatest common divisor (GCD)
def gcd(a, b):
while b:
a, b = b, a % b
return a
# Function to initialize DSU with n components
def initialize_dsu(n):
parent = list(range(n))
return parent
# Function to find the root of a component in DSU
def find_root(parent,... | Title: Colliders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
By 2312 there were *n* Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to *n*. However, scientists did not know what activating several colliders simul... | ```python
import math
# Function to find the greatest common divisor (GCD)
def gcd(a, b):
while b:
a, b = b, a % b
return a
# Function to initialize DSU with n components
def initialize_dsu(n):
parent = list(range(n))
return parent
# Function to find the root of a component in DSU
def find_ro... | 0 | |
343 | A | Rational Resistance | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance *R*0<==<=1. Elements with other resistance can be constructed from these resistors. In this problem, we wil... | The single input line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1018). It is guaranteed that the fraction is irreducible. It is guaranteed that a solution always exists. | Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier. | [
"1 1\n",
"3 2\n",
"199 200\n"
] | [
"1\n",
"3\n",
"200\n"
] | In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5305da389756aab6... | 500 | [
{
"input": "1 1",
"output": "1"
},
{
"input": "3 2",
"output": "3"
},
{
"input": "199 200",
"output": "200"
},
{
"input": "1 1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "21 8",
"output": "7... | 1,408,675,941 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 342 | 5,222,400 | import fractions
def resistance():
# print("Input the two values")
_a, _b = input().split()
a = int(_a)
b = int(_b)
answer = 1
f = fractions.Fraction(a,b)
one = fractions.Fraction(1,1)
while (f != one):
n = f.numerator
d = f.denominator
# If either the num or... | Title: Rational Resistance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance *R... | ```python
import fractions
def resistance():
# print("Input the two values")
_a, _b = input().split()
a = int(_a)
b = int(_b)
answer = 1
f = fractions.Fraction(a,b)
one = fractions.Fraction(1,1)
while (f != one):
n = f.numerator
d = f.denominator
# If either ... | 3 | |
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd... | 1,504,031,389 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 62 | 0 | n = input()
words = input()
words = words.split()
upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
maxWeight = 0
temp = 0
for word in words:
for i in word:
if i in upper:
temp += 1
if temp > maxWeight:
maxWeight = temp
temp = 0
print(maxWeight)
| Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex... | ```python
n = input()
words = input()
words = words.split()
upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
maxWeight = 0
temp = 0
for word in words:
for i in word:
if i in upper:
temp += 1
if temp > maxWeight:
maxWeight = temp
temp = 0
print(maxWeight)
``` | 3 | |
586 | A | Alena's Schedule | PROGRAMMING | 900 | [
"implementation"
] | null | null | Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university.
The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* ar... | Print a single number — the number of pairs during which Alena stays at the university. | [
"5\n0 1 0 1 1\n",
"7\n1 0 1 0 0 1 0\n",
"1\n0\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home. | 500 | [
{
"input": "5\n0 1 0 1 1",
"output": "4"
},
{
"input": "7\n1 0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
... | 1,654,868,263 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | x = int(float(input()))
list1=list(map(int,input().split()))
cn=0
for i in range(x):
if(list1[i]==1 or (list1[i-1]==1 and list1[i]==0 or list1[i+1]==1)):
cn = cn +1
print(cn)
| Title: Alena's Schedule
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic ... | ```python
x = int(float(input()))
list1=list(map(int,input().split()))
cn=0
for i in range(x):
if(list1[i]==1 or (list1[i-1]==1 and list1[i]==0 or list1[i+1]==1)):
cn = cn +1
print(cn)
``` | 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,655,454,507 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | arr = list(map(int,input().split()))
print(arr[0] - arr[1])
| 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
arr = list(map(int,input().split()))
print(arr[0] - arr[1])
``` | 0 | |
793 | B | Igor and his way to work | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"implementation",
"shortest paths"
] | null | null | Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the grid.
Each of the next *n* lines contains *m* characters denoting the corresponding row of the grid. The following characters can occur:
- "." — an empty cell; - "*" — a cell with road ... | In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise. | [
"5 5\n..S..\n****.\nT....\n****.\n.....\n",
"5 5\nS....\n****.\n.....\n.****\n..T..\n"
] | [
"YES",
"NO"
] | The first sample is shown on the following picture:
In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture: | 1,000 | [
{
"input": "5 5\nS....\n****.\n.....\n.****\n..T..",
"output": "NO"
},
{
"input": "1 2\nST",
"output": "YES"
},
{
"input": "3 1\nS\n*\nT",
"output": "NO"
},
{
"input": "3 3\n*..\n...\nTS.",
"output": "YES"
},
{
"input": "3 3\nT.*\n*.*\n*S*",
"output": "YES"
... | 1,493,290,837 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 3,000 | 11,264,000 | import sys
lines = sys.stdin.read().split('\n')
n, m = map(int, lines[0].split(' '))
lines = lines[1:]
road = []
start = ()
finish = ()
i = 0
j = 0
for line in lines:
j = 0
l = list(line)
for el in l:
if el == 'S':
start = (i, j)
elif el == "T":
fini... | Title: Igor and his way to work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, th... | ```python
import sys
lines = sys.stdin.read().split('\n')
n, m = map(int, lines[0].split(' '))
lines = lines[1:]
road = []
start = ()
finish = ()
i = 0
j = 0
for line in lines:
j = 0
l = list(line)
for el in l:
if el == 'S':
start = (i, j)
elif el == "T":
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.
Two lines rhyme if their ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=2500, 1<=≤<=*k*<=≤<=5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4*n* lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.
If ... | Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes. | [
"1 1\nday\nmay\nsun\nfun\n",
"1 1\nday\nmay\ngray\nway\n",
"2 1\na\na\na\na\na\na\ne\ne\n",
"2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill\n"
] | [
"aabb\n",
"aaaa\n",
"aabb\n",
"NO\n"
] | In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO". | 0 | [
{
"input": "1 1\nday\nmay\nsun\nfun",
"output": "aabb"
},
{
"input": "1 1\nday\nmay\ngray\nway",
"output": "aaaa"
},
{
"input": "2 1\na\na\na\na\na\na\ne\ne",
"output": "aabb"
},
{
"input": "2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill",
"output": "NO"
},
{
"... | 1,592,034,755 | 6,455 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 280 | 0 | n,k = map(int,input().split())
lis=[]
vov=['a','e','i','o','u']
d={}
d['aabb']=d['abab']=d['abba']=d['aaaa']=0
for i in range(n*4):
s = input()
lis.append(s)
if i%4==3:
tmp=[]
for j in range(4):
s=lis[j]
c=0
cou=0
for ll in s[::-1... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without ... | ```python
n,k = map(int,input().split())
lis=[]
vov=['a','e','i','o','u']
d={}
d['aabb']=d['abab']=d['abba']=d['aaaa']=0
for i in range(n*4):
s = input()
lis.append(s)
if i%4==3:
tmp=[]
for j in range(4):
s=lis[j]
c=0
cou=0
for ll... | 0 | |
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The chi... | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description... | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no ... | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
... | 1,621,360,565 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 62 | 0 | choice = ['A', 'B', 'C', 'D']
size = []
min_, max_, great, index = float("inf"), float("-inf"), 0, 0
for i in range(4):
ch = input()[2:]
size.append((len(ch), i+1))
min_, max_ = min(len(ch), min_), max(len(ch), max_)
size.sort()
if min_ <= size[1][0]//2:
great += 1
index = size[0][1]
if m... | Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should fin... | ```python
choice = ['A', 'B', 'C', 'D']
size = []
min_, max_, great, index = float("inf"), float("-inf"), 0, 0
for i in range(4):
ch = input()[2:]
size.append((len(ch), i+1))
min_, max_ = min(len(ch), min_), max(len(ch), max_)
size.sort()
if min_ <= size[1][0]//2:
great += 1
index = size[0... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 0 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,506,189,444 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | n=input()
a=input().split(" ")
b=[]
for x in a:
b.append(int(x))
max=1
table=[b[0]]
for x in b:
table.append(x)
if(table.count(x)==2):
table.pop(table.index(x))
table.pop(table.index(x))
if(len(table)>=max):
max=len(table)
print(max)
# 1506189441264
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*... | ```python
n=input()
a=input().split(" ")
b=[]
for x in a:
b.append(int(x))
max=1
table=[b[0]]
for x in b:
table.append(x)
if(table.count(x)==2):
table.pop(table.index(x))
table.pop(table.index(x))
if(len(table)>=max):
max=len(table)
print(max)
# 1506189441264
``` | 0 | |
864 | C | Bus | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"math"
] | null | null | A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. After returning to the point *x*<==<=0 it immediately goes back to the point *x*<==<=*a* ... | The first line contains four integers *a*, *b*, *f*, *k* (0<=<<=*f*<=<<=*a*<=≤<=106, 1<=≤<=*b*<=≤<=109, 1<=≤<=*k*<=≤<=104) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. | Print the minimum number of times the bus needs to refuel to make *k* journeys. If it is impossible for the bus to make *k* journeys, print -1. | [
"6 9 2 4\n",
"6 10 2 4\n",
"6 5 4 3\n"
] | [
"4\n",
"2\n",
"-1\n"
] | In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, fin... | 1,500 | [
{
"input": "6 9 2 4",
"output": "4"
},
{
"input": "6 10 2 4",
"output": "2"
},
{
"input": "6 5 4 3",
"output": "-1"
},
{
"input": "2 2 1 1",
"output": "0"
},
{
"input": "10 4 6 10",
"output": "-1"
},
{
"input": "3 1 1 1",
"output": "-1"
},
{
... | 1,616,295,812 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 77 | 307,200 | a,b,f,k = map(int,input().split())
tf = a-f
gas = b-f
if gas < 0:
print(-1)
exit()
ans = 0
for i in range(k):
if i%2 == 0:
if i == k-1:
if gas < tf:
gas = b
ans +=1
else:
if gas < tf*2:
gas = b
... | Title: Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. ... | ```python
a,b,f,k = map(int,input().split())
tf = a-f
gas = b-f
if gas < 0:
print(-1)
exit()
ans = 0
for i in range(k):
if i%2 == 0:
if i == k-1:
if gas < tf:
gas = b
ans +=1
else:
if gas < tf*2:
... | 3 | |
264 | A | Escape from Stones | PROGRAMMING | 1,200 | [
"constructive algorithms",
"data structures",
"implementation",
"two pointers"
] | null | null | Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order.
The stones always fall to the center of Liss's ... | The input consists of only one line. The only line contains the string *s* (1<=≤<=|*s*|<=≤<=106). Each character in *s* will be either "l" or "r". | Output *n* lines — on the *i*-th line you should print the *i*-th stone's number from the left. | [
"llrlr\n",
"rrlll\n",
"lrlrr\n"
] | [
"3\n5\n4\n2\n1\n",
"1\n2\n5\n4\n3\n",
"2\n4\n5\n3\n1\n"
] | In the first example, the positions of stones 1, 2, 3, 4, 5 will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/58fdb5684df807bfcb705a9da9ce175613362b7d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, respectively. So you should print the sequence: 3, 5, 4, 2, 1. | 500 | [
{
"input": "llrlr",
"output": "3\n5\n4\n2\n1"
},
{
"input": "rrlll",
"output": "1\n2\n5\n4\n3"
},
{
"input": "lrlrr",
"output": "2\n4\n5\n3\n1"
},
{
"input": "lllrlrllrl",
"output": "4\n6\n9\n10\n8\n7\n5\n3\n2\n1"
},
{
"input": "llrlrrrlrr",
"output": "3\n5\n6... | 1,569,117,624 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 30 | 2,000 | 32,051,200 | # -*- coding: utf-8 -*-
"""
Created on Sun Sep 22 07:27:17 2019
@author: avina
"""
s = input()
v1 = [];n = len(s)
v2 = []
for i in range(n):
if s[i] == 'l':
v1.append(i+1)
else:
v2.append(i+1)
v1.reverse()
for i in v2:
print(i)
for i in v1:
print(i) | Title: Escape from Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the ... | ```python
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 22 07:27:17 2019
@author: avina
"""
s = input()
v1 = [];n = len(s)
v2 = []
for i in range(n):
if s[i] == 'l':
v1.append(i+1)
else:
v2.append(i+1)
v1.reverse()
for i in v2:
print(i)
for i in v1:
print(i)
``` | 0 | |
899 | C | Dividing the numbers | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs",
"math"
] | null | null | Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. | Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. | [
"4\n",
"2\n"
] | [
"0\n2 1 4 \n",
"1\n1 1 \n"
] | In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and on... | 1,500 | [
{
"input": "4",
"output": "0\n2 1 4 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "3",
"output": "0\n1\n3 "
},
{
"input": "5",
"output": "1\n3\n1 2 5 "
},
{
"input": "59998",
"output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 4... | 1,666,845,193 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 60 | 62 | 2,969,600 | n = int(input())
if n%4 == 0 or n%4 ==3:
print(0)
else:
print(1)
res = []
i = n%4
if i != 0:
res.append(i)
i += 4
while i <= n:
res.append(i)
res.append(i-3)
i += 4
print(len(res), end=" ")
print(' '.join([str(rr) for rr in res]))
| Title: Dividing the numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help P... | ```python
n = int(input())
if n%4 == 0 or n%4 ==3:
print(0)
else:
print(1)
res = []
i = n%4
if i != 0:
res.append(i)
i += 4
while i <= n:
res.append(i)
res.append(i-3)
i += 4
print(len(res), end=" ")
print(' '.join([str(rr) for rr in res]))
``` | 3 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,600,780,941 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 155 | 819,200 | from collections import Counter
import string
import math
import sys
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(number_of_variables):
if number_of_variables==1:
return int(sys.stdin.readline())
if number_of_variables>=2:
return map(int,sys.stdin... | Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
from collections import Counter
import string
import math
import sys
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(number_of_variables):
if number_of_variables==1:
return int(sys.stdin.readline())
if number_of_variables>=2:
return map(int... | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,559,027,606 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 124 | 0 | print(''.join(['0' if n == m else '1' for n, m in zip(input(), input())])) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
print(''.join(['0' if n == m else '1' for n, m in zip(input(), input())]))
``` | 3.969 |
99 | A | Help Far Away Kingdom | PROGRAMMING | 800 | [
"strings"
] | A. Help Far Away Kingdom | 2 | 256 | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki... | The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empt... | If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). | [
"0.0\n",
"1.49\n",
"1.50\n",
"2.71828182845904523536\n",
"3.14159265358979323846\n",
"12345678901234567890.1\n",
"123456789123456789.999\n"
] | [
"0",
"1",
"2",
"3",
"3",
"12345678901234567890",
"GOTO Vasilisa."
] | none | 500 | [
{
"input": "0.0",
"output": "0"
},
{
"input": "1.49",
"output": "1"
},
{
"input": "1.50",
"output": "2"
},
{
"input": "2.71828182845904523536",
"output": "3"
},
{
"input": "3.14159265358979323846",
"output": "3"
},
{
"input": "12345678901234567890.1",
... | 1,675,742,963 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | a=input()
if a[a.index('.')-1]=='9':
print('GOTO Vasilisa.')
else:
print(round(float(a)))
| Title: Help Far Away Kingdom
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those stran... | ```python
a=input()
if a[a.index('.')-1]=='9':
print('GOTO Vasilisa.')
else:
print(round(float(a)))
``` | 0 |
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,689,918,751 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 77 | 2,355,200 |
calories = list(map(int, input().split()))
stripes = [int(x) for x in input()]
sumi = []
for stripe in stripes:
if stripe == 1:
sumi.append(calories[0])
elif stripe == 2:
sumi.append(calories[1])
elif stripe == 3:
sumi.append(calories[2])
else:
sumi.append(ca... | 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()))
stripes = [int(x) for x in input()]
sumi = []
for stripe in stripes:
if stripe == 1:
sumi.append(calories[0])
elif stripe == 2:
sumi.append(calories[1])
elif stripe == 3:
sumi.append(calories[2])
else:
sumi... | 3 | |
380 | C | Sereja and Brackets | PROGRAMMING | 2,000 | [
"data structures",
"schedules"
] | null | null | Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length o... | The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains ... | Print the answer to each question on a single line. Print the answers in the order they go in the input. | [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n"
] | [
"0\n0\n2\n10\n4\n6\n6\n"
] | A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<s... | 1,500 | [
{
"input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10",
"output": "0\n0\n2\n10\n4\n6\n6"
},
{
"input": "(((((()((((((((((()((()(((((\n1\n8 15",
"output": "0"
},
{
"input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 ... | 1,628,503,933 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 163,840,000 | class STNode:
def __init__(self, opt, open, close):
self.opt = opt
self.open = open
self.close = close
class ST:
def __init__(self, N, string):
self.string = string
self.st = [None] * (4 * N)
def add_node(self, node1, node2):
output = STNode(0, 0, 0)
tmp = min(node1.open, node2.close)
... | Title: Sereja and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two i... | ```python
class STNode:
def __init__(self, opt, open, close):
self.opt = opt
self.open = open
self.close = close
class ST:
def __init__(self, N, string):
self.string = string
self.st = [None] * (4 * N)
def add_node(self, node1, node2):
output = STNode(0, 0, 0)
tmp = min(node1.open, nod... | 0 | |
453 | A | Little Pony and Expected Maximum | PROGRAMMING | 1,600 | [
"probabilities"
] | null | null | Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots... | A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105). | Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4. | [
"6 1\n",
"6 3\n",
"2 2\n"
] | [
"3.500000000000\n",
"4.958333333333\n",
"1.750000000000\n"
] | Consider the third test example. If you've made two tosses:
1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in t... | 500 | [
{
"input": "6 1",
"output": "3.500000000000"
},
{
"input": "6 3",
"output": "4.958333333333"
},
{
"input": "2 2",
"output": "1.750000000000"
},
{
"input": "5 4",
"output": "4.433600000000"
},
{
"input": "5 8",
"output": "4.814773760000"
},
{
"input": "... | 1,442,911,306 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 124 | 5,120,000 | m, n = [int(x) for x in input().split()]
print(sum([i *((i/m) ** n - ((i-1)/m) ** n) for i in range(1, m + 1)])) | Title: Little Pony and Expected Maximum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were ... | ```python
m, n = [int(x) for x in input().split()]
print(sum([i *((i/m) ** n - ((i-1)/m) ** n) for i in range(1, m + 1)]))
``` | 3 | |
644 | A | Parliament of Berland | PROGRAMMING | 1,000 | [
"*special",
"constructive algorithms"
] | null | null | There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of *a*<=×<=*b* chairs — *a* rows of *b* chair... | The first line of the input contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=10<=000, 1<=≤<=*a*,<=*b*<=≤<=100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively. | If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in *a* lines, each containing *b* integers. The *j*-th integer of the *i*-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multi... | [
"3 2 2\n",
"8 4 3\n",
"10 2 2\n"
] | [
"0 3\n1 2\n",
"7 8 3\n0 1 4\n6 0 5\n0 2 0\n",
"-1\n"
] | In the first sample there are many other possible solutions. For example,
and
The following assignment
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats. | 500 | [
{
"input": "3 2 2",
"output": "1 2 \n0 3 "
},
{
"input": "8 4 3",
"output": "1 2 3 \n4 5 6 \n7 8 0 \n0 0 0 "
},
{
"input": "10 2 2",
"output": "-1"
},
{
"input": "1 1 1",
"output": "1 "
},
{
"input": "8 3 3",
"output": "1 2 3 \n4 5 6 \n7 8 0 "
},
{
"in... | 1,458,153,965 | 35,165 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 46 | 204,800 | import sys
EPS = sys.float_info.epsilon
LENGTH = 10
matrix = [[] for i in range(LENGTH)]
arr = [0] * 1001
n, a, b = map(int, input().split())
arr = [[0] * b for i in range(a)]
c1 = 3
c2 = 2
arr[0][0] = 1
for j in range(1, b):
arr[0][j] = j + 1
if j % 2 == 0 and c1 <= n:
arr[0][j] = c1
c1 += 2... | Title: Parliament of Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republi... | ```python
import sys
EPS = sys.float_info.epsilon
LENGTH = 10
matrix = [[] for i in range(LENGTH)]
arr = [0] * 1001
n, a, b = map(int, input().split())
arr = [[0] * b for i in range(a)]
c1 = 3
c2 = 2
arr[0][0] = 1
for j in range(1, b):
arr[0][j] = j + 1
if j % 2 == 0 and c1 <= n:
arr[0][j] = c1
... | 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.