contestId int64 0 1.01k | index stringclasses 40
values | name stringlengths 2 54 | type stringclasses 2
values | rating int64 0 3.4k | tags listlengths 0 7 | title stringclasses 393
values | time-limit stringclasses 7
values | memory-limit stringclasses 6
values | problem-description stringlengths 0 2.97k | input-specification stringlengths 4 1.87k | output-specification stringlengths 4 1.12k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 3.5k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 1
value | testset stringclasses 9
values | passedTestCount int64 1 402 | timeConsumedMillis int64 15 8.06k | memoryConsumedBytes int64 0 514M | code stringlengths 11 61.4k | prompt stringlengths 297 7.35k | response stringlengths 25 61.4k | score float64 2.82 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
604 | A | Uncowed Forces | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a... | The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=β€<=*m**i*<=β€<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, ... | Print a single integer, the value of Kevin's final score. | [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n"
] | [
"4900\n",
"4930\n"
] | In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving pro... | 500 | [
{
"input": "20 40 60 80 100\n0 1 2 3 4\n1 0",
"output": "4900"
},
{
"input": "119 119 119 119 119\n0 0 0 0 0\n10 0",
"output": "4930"
},
{
"input": "3 6 13 38 60\n6 10 10 3 8\n9 9",
"output": "5088"
},
{
"input": "21 44 11 68 75\n6 2 4 8 4\n2 8",
"output": "4522"
},
{... | 1,629,089,355 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 77 | 6,963,200 | def score(x,m,w):
t=(1-(m/250))*x - (50*w)
return max(0.3*x,t)
sl=[500,1000,1500,2000,2500]
m=list(map(int, input().split()))
w=list(map(int, input().split()))
s,u=map(int,input().split())
res=0
for i in range(5):
res+=score(sl[i],m[i],w[i])
res+=(100*s)
res-=(50*u)
print(int(res)) | Title: Uncowed Forces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challengin... | ```python
def score(x,m,w):
t=(1-(m/250))*x - (50*w)
return max(0.3*x,t)
sl=[500,1000,1500,2000,2500]
m=list(map(int, input().split()))
w=list(map(int, input().split()))
s,u=map(int,input().split())
res=0
for i in range(5):
res+=score(sl[i],m[i],w[i])
res+=(100*s)
res-=(50*u)
print(int(res... | 3 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,697,612,339 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | s=str(input())
s=list(s)
a=s[0]
a=a.upper()
s[0]=a
y="".join(s)
print(y) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
s=str(input())
s=list(s)
a=s[0]
a=a.upper()
s[0]=a
y="".join(s)
print(y)
``` | 3 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=β€<=*r*,<=*g*,<=*b*<=β€<=109) β the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,372,488,972 | 672 | Python 3 | OK | TESTS | 40 | 78 | 102,400 | def f(x): return x // 3
r, g, b = map(int, input().split())
m = min(r, g, b)
ans = 0
for i in range(max(0, m - 30), m + 1):
ans = max(ans, i + f(r - i) + f(g - i) + f(b - i))
print(ans)
| Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
def f(x): return x // 3
r, g, b = map(int, input().split())
m = min(r, g, b)
ans = 0
for i in range(max(0, m - 30), m + 1):
ans = max(ans, i + f(r - i) + f(g - i) + f(b - i))
print(ans)
``` | 3 | |
804 | B | Minimum number of steps | PROGRAMMING | 1,400 | [
"combinatorics",
"greedy",
"implementation",
"math"
] | null | null | We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<... | The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. | Print the minimum number of steps modulo 109<=+<=7. | [
"ab\n",
"aab\n"
] | [
"1\n",
"3\n"
] | The first example: "ab" βββ "bba".
The second example: "aab" βββ "abba" βββ "bbaba" βββ "bbbbaa". | 1,000 | [
{
"input": "ab",
"output": "1"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaaaabaabababaaaaaba",
"output": "17307"
},
{
"input": "abaabaaabbabaabab",
"output": "1795"
},
{
"input": "abbaa",
"output": "2"
},
{
"input": "abbaaabaabaaaaabbbbaababaa... | 1,609,661,478 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 218 | 6,348,800 | import math as m
t=1
#t=int(input())
mod=10**9+7
while t:
t-=1
s=input()
ans,cost=0,0
for i in range(len(s)):
if s[i]=='a':
cost=(cost*2+1)%mod
else :
ans+=cost
print(ans%mod)
| Title: Minimum number of steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substr... | ```python
import math as m
t=1
#t=int(input())
mod=10**9+7
while t:
t-=1
s=input()
ans,cost=0,0
for i in range(len(s)):
if s[i]=='a':
cost=(cost*2+1)%mod
else :
ans+=cost
print(ans%mod)
``` | 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,576,631,314 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 124 | 204,800 |
s = ' '+input()+' '
n = int(input())
print(s[1:-1])
for i in range(n):
l,r = input().split()
s = s.replace(' '+l+' ',' '+r+' ')
print(s[1:-1])
| 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
s = ' '+input()+' '
n = int(input())
print(s[1:-1])
for i in range(n):
l,r = input().split()
s = s.replace(' '+l+' ',' '+r+' ')
print(s[1:-1])
``` | 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,650,187,539 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 61 | 512,000 | from math import gcd
n=int(input())
#print(gcd(1,0))
a=0
u=[]
for i in range(1,n+1):
if gcd(a+i,n-i)==1:
u.append([a+i,n-i])
print(*u[(len(u)//2)-1])
| 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
from math import gcd
n=int(input())
#print(gcd(1,0))
a=0
u=[]
for i in range(1,n+1):
if gcd(a+i,n-i)==1:
u.append([a+i,n-i])
print(*u[(len(u)//2)-1])
``` | 3 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,578,716,707 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | p=0
c=''
s=input()
for i in range(len(s)):
if p==0:
if s[i]=='.':
c+='0'
elif s[i+1]=='.':
c+='1'
p=1
else:
c+='2'
p=1
else:
p=0
print(c) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
p=0
c=''
s=input()
for i in range(len(s)):
if p==0:
if s[i]=='.':
c+='0'
elif s[i+1]=='.':
c+='1'
p=1
else:
c+='2'
p=1
else:
p=0
print(c)
``` | 3.938 |
808 | D | Array Division | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"implementation"
] | null | null | Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element ... | The first line contains single integer *n* (1<=β€<=*n*<=β€<=100000) β the size of the array.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=β€<=*a**i*<=β€<=109) β the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | [
"3\n1 3 2\n",
"5\n1 2 3 4 5\n",
"5\n2 2 3 4 5\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | 0 | [
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "5\n2 2 3 4 5",
"output": "YES"
},
{
"input": "5\n72 32 17 46 82",
"output": "NO"
},
{
"input": "6\n26 10 70 11 69 57",
"output": "NO"
},
{
"input": "7\n4... | 1,659,599,404 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 115 | 108 | 18,022,400 | n = int(input())
arr = list(map(int, input().split()))
def solve(n, a):
s = sum(a)
if n == 1 or s & 1:
print('NO')
return
half = s // 2
def judge(a):
pre, st = 0, {0}
for num in a:
st.add(num)
pre += num
if pre - half in st... | Title: Array Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to... | ```python
n = int(input())
arr = list(map(int, input().split()))
def solve(n, a):
s = sum(a)
if n == 1 or s & 1:
print('NO')
return
half = s // 2
def judge(a):
pre, st = 0, {0}
for num in a:
st.add(num)
pre += num
if pre - ... | 3 | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5Β·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=β€<=*n*<=β€<=10, 1<=β€<=*k*<=β€<=240)Β β the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5β+β10β=β15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,678,031,962 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 52 | 62 | 0 | inp = input().split()
lis = [eval(i) for i in inp]
k = lis[1]
n = 5
a,b=0,lis[0]
for i in range(lis[0]):
if(k<240 and k+((i+1)*5)<=240):
k+=n
n+=5
else:break
a=i+1
print(int(a)) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
inp = input().split()
lis = [eval(i) for i in inp]
k = lis[1]
n = 5
a,b=0,lis[0]
for i in range(lis[0]):
if(k<240 and k+((i+1)*5)<=240):
k+=n
n+=5
else:break
a=i+1
print(int(a))
``` | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W β the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format Β«A/BΒ», where A β the numerator, and B β the denominator. If the required probability equals to zero, output Β«0/1Β». If the required probability equals to 1, output Β«1/1Β». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,666,546,201 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 124 | 0 | y,w=map(int,input().split())
probability=["", "1/1", "5/6", "2/3", "1/2", "1/3", "1/6"]
print(probability[max(y,w)]) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
y,w=map(int,input().split())
probability=["", "1/1", "5/6", "2/3", "1/2", "1/3", "1/6"]
print(probability[max(y,w)])
``` | 3.938 |
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,670,948,713 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | # n = int(input())
# words = [input() for i in range(n)]
# def shorter(word):
# if len(word) <= 10:
# return word
# else:
# return word[0] + str(len(word)-2) + word[-1]
# for i in words:
# print(shorter(i))
# n = int(input())
# sol = [input().split(" ") for i in range(n)]
# ... | 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
# n = int(input())
# words = [input() for i in range(n)]
# def shorter(word):
# if len(word) <= 10:
# return word
# else:
# return word[0] + str(len(word)-2) + word[-1]
# for i in words:
# print(shorter(i))
# n = int(input())
# sol = [input().split(" ") for i in ran... | 3.977 |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=β€<=*n*<=β€<=100;Β 1<=β€<=*d*<=β€<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=β€<=*t**i*<=β€<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,632,117,780 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 62 | 6,758,400 | n,m=map(int, input().split())
a=sum(list(map(int, input().split())))
if a+(n-1)*10<=m:
print((m-a)//5)
else:
print(-1) | Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
n,m=map(int, input().split())
a=sum(list(map(int, input().split())))
if a+(n-1)*10<=m:
print((m-a)//5)
else:
print(-1)
``` | 3 | |
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos... | The first line contains two integers *n* and *m* (1<=β€<=*n*<=β€<=100,<=1<=β€<=*m*<=β€<=100)Β β the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=β€<=*a**i*<=β€<=*b**i*<=β€<=*m*), where ... | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You... | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7... | 1,627,676,949 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 109 | 20,172,800 | n, finish = map(int, input().split())
end_interval = [0, finish]
points = []
for _ in range(n):
x, y = map(int, input().split())
points.append([x, y])
points.sort()
#print(points)
merge_interval = [points[0][0], points[0][1]]
for i in range(1, n):
if merge_interval[1]>=points[i][0]:
... | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain ... | ```python
n, finish = map(int, input().split())
end_interval = [0, finish]
points = []
for _ in range(n):
x, y = map(int, input().split())
points.append([x, y])
points.sort()
#print(points)
merge_interval = [points[0][0], points[0][1]]
for i in range(1, n):
if merge_interval[1]>=points[i][... | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,569,500,881 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 0 | n=int(input())
a=list(map(int,input().split()))
k = sum(a)
n+=1
c=0
for i in range(1,6):
if (k+i)%n==1:
c+=1
print(5-c)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n=int(input())
a=list(map(int,input().split()))
k = sum(a)
n+=1
c=0
for i in range(1,6):
if (k+i)%n==1:
c+=1
print(5-c)
``` | 3 | |
219 | C | Color Stripe | PROGRAMMING | 1,600 | [
"brute force",
"dp",
"greedy"
] | null | null | A colored stripe is represented by a horizontal row of *n* square cells, each cell is pained one of *k* colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to *k* to repaint the cells. | The first input line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=5Β·105;Β 2<=β€<=*k*<=β€<=26). The second line contains *n* uppercase English letters. Letter "A" stands for the first color, letter "B" stands for the second color and so on. The first *k* English letters may be used. Each letter represents the color of ... | Print a single integer β the required minimum number of repaintings. In the second line print any possible variant of the repainted stripe. | [
"6 3\nABBACC\n",
"3 2\nBBB\n"
] | [
"2\nABCACA\n",
"1\nBAB\n"
] | none | 1,500 | [
{
"input": "6 3\nABBACC",
"output": "2\nABCACA"
},
{
"input": "3 2\nBBB",
"output": "1\nBAB"
},
{
"input": "1 2\nA",
"output": "0\nA"
},
{
"input": "1 26\nZ",
"output": "0\nZ"
},
{
"input": "2 2\nAA",
"output": "1\nAB"
},
{
"input": "2 2\nBA",
"out... | 1,626,522,661 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 810 | 12,697,600 | n, k = map(int, input().split())
s = list(input())
if k > 2:
c = set(ord("A") + i for i in range(26))
r = 0
for i in range(1,len(s)):
if s[i-1] == s[i]:
r += 1
if i + 1 < n:
s[i] = "A" if "A" not in {s[i-1], s[i+1]} else ('B' if "B" not in {s[i], s[i+1]} els... | Title: Color Stripe
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A colored stripe is represented by a horizontal row of *n* square cells, each cell is pained one of *k* colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. Y... | ```python
n, k = map(int, input().split())
s = list(input())
if k > 2:
c = set(ord("A") + i for i in range(26))
r = 0
for i in range(1,len(s)):
if s[i-1] == s[i]:
r += 1
if i + 1 < n:
s[i] = "A" if "A" not in {s[i-1], s[i+1]} else ('B' if "B" not in {s[i], s... | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,592,891,029 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 216 | 6,656,000 | s=input()
ascii_lower=0
ascii_upper=0
str=''
for ele in s:
if ord(ele) <= 90:
ascii_upper+=1
elif ord(ele) >= 97:
ascii_lower+=1
if ascii_lower>=ascii_upper:
print(s.lower())
else:
print(s.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
ascii_lower=0
ascii_upper=0
str=''
for ele in s:
if ord(ele) <= 90:
ascii_upper+=1
elif ord(ele) >= 97:
ascii_lower+=1
if ascii_lower>=ascii_upper:
print(s.lower())
else:
print(s.upper())
``` | 3.933602 |
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY... | 1,694,337,559 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | n = int(input())
str = input()
s = set(str.lower())
if len(s) == 26: print("YES")
else: print("NO") | Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
... | ```python
n = int(input())
str = input()
s = set(str.lower())
if len(s) == 26: print("YES")
else: print("NO")
``` | 3 | |
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer β the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4β*β5β=β20 milliliters of the drink, it is enough to make 20β/β3β=β6 toasts. The limes are enough for 10β*β8β=β80 toasts and the salt is enough for 100β/β1β=β100 toasts. However, there are 3 friends in the group, so the answer is *min*(6,β80,β100)β/β3β=β2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,679,554,582 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 124 | 0 | n,k,l,c,d,p,nl,np = tuple(map(int,input().split()))
drink = (k*l)//(nl)
slice = c*d
salt = p//np
print(min(drink,slice,salt)//n) | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
n,k,l,c,d,p,nl,np = tuple(map(int,input().split()))
drink = (k*l)//(nl)
slice = c*d
salt = p//np
print(min(drink,slice,salt)//n)
``` | 3 | |
870 | A | Search for Pretty Integers | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=9) β the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=9) β the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2... | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among t... | 500 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output"... | 1,581,944,379 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 124 | 307,200 | input();c=lambda: set(map(int,input().split()));k=c();k1=c();d=k.intersection(k1);z=min(k);z1=min(k1)
try:print(min(int(str(min(z,z1))+str(max(z,z1))),int(str(min(d)))))
except:print(int(str(min(z,z1))+str(max(z,z1)))) | Title: Search for Pretty Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the sm... | ```python
input();c=lambda: set(map(int,input().split()));k=c();k1=c();d=k.intersection(k1);z=min(k);z1=min(k1)
try:print(min(int(str(min(z,z1))+str(max(z,z1))),int(str(min(d)))))
except:print(int(str(min(z,z1))+str(max(z,z1))))
``` | 3 | |
6 | C | Alice, Bob and Chocolate | PROGRAMMING | 1,200 | [
"greedy",
"two pointers"
] | C. Alice, Bob and Chocolate | 2 | 64 | Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them wi... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=105) β the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=β€<=*t**i*<=β€<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). | Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. | [
"5\n2 9 8 2 7\n"
] | [
"2 3\n"
] | none | 0 | [
{
"input": "5\n2 9 8 2 7",
"output": "2 3"
},
{
"input": "1\n1",
"output": "1 0"
},
{
"input": "2\n1 1",
"output": "1 1"
},
{
"input": "3\n1 1 1",
"output": "2 1"
},
{
"input": "4\n1 1 1 1",
"output": "2 2"
},
{
"input": "1\n6",
"output": "1 0"
}... | 1,587,286,149 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 466 | 6,963,200 | n = int(input())
t = list(map(int,input().split()))
Alice = 0
Bob = 0
cA = 0
cB = 0
i = 0
j = n-1
while i<j:
temp = min(Bob,Alice)
Alice -= temp
if Alice==0:
Alice += t[i]
cA += 1
i += 1
Bob -= temp
if Bob==0:
Bob += t[j]
cB += 1
... | Title: Alice, Bob and Chocolate
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β from right to left. Fo... | ```python
n = int(input())
t = list(map(int,input().split()))
Alice = 0
Bob = 0
cA = 0
cB = 0
i = 0
j = n-1
while i<j:
temp = min(Bob,Alice)
Alice -= temp
if Alice==0:
Alice += t[i]
cA += 1
i += 1
Bob -= temp
if Bob==0:
Bob += t[j]
cB... | 3.83162 |
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,686,881,986 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | '''Vipin'''
# cook your dish here
n,m,a=map(int,input().split())
if a>n and a>m:
print("1")
else:
if n%a>0:
n=n//a+1
else:
n=n//a
if m%a>0:
m=(m//a)+1
else:
m=m//a
ans = n*m
print(ans)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
'''Vipin'''
# cook your dish here
n,m,a=map(int,input().split())
if a>n and a>m:
print("1")
else:
if n%a>0:
n=n//a+1
else:
n=n//a
if m%a>0:
m=(m//a)+1
else:
m=m//a
ans = n*m
print(ans)
... | 3.9845 |
489 | B | BerSU Ball | PROGRAMMING | 1,200 | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"sortings",
"two pointers"
] | null | null | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in eac... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100) β the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=β€<=*m*<=β€<=100) β the number of girls. The fourth l... | Print a single number β the required maximum possible number of pairs. | [
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
] | [
"3\n",
"0\n",
"2\n"
] | none | 1,000 | [
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9",
"output": "3"
},
{
"input": "4\n1 2 3 4\n4\n10 11 12 13",
"output": "0"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3",
"output": "2"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 10\n1\n9",
"output": "1"
},
{... | 1,681,630,347 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 77 | 0 | n=int(input())
arr1=list(map(int,input().split()))
m=int(input())
arr2=list(map(int,input().split()))
arr1=sorted(arr1)
arr2=sorted(arr2)
ans=0
for i in range(n):
for j in range(m):
if(arr1[i]==arr2[j] or arr1[i]+1==arr2[j] or arr1[i]-1==arr2[j]):
ans=ans+1
arr2[j]=-1
... | Title: BerSU Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy... | ```python
n=int(input())
arr1=list(map(int,input().split()))
m=int(input())
arr2=list(map(int,input().split()))
arr1=sorted(arr1)
arr2=sorted(arr2)
ans=0
for i in range(n):
for j in range(m):
if(arr1[i]==arr2[j] or arr1[i]+1==arr2[j] or arr1[i]-1==arr2[j]):
ans=ans+1
arr2... | 3 | |
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,612,625,183 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 140 | 10,035,200 | try:
t=int(input())
a=list(map(int,input().split(" ")))
k=max(a)
print(k)
except:
pass | 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
try:
t=int(input())
a=list(map(int,input().split(" ")))
k=max(a)
print(k)
except:
pass
``` | 3 | |
5 | A | Chat Servers Outgoing Traffic | PROGRAMMING | 1,000 | [
"implementation"
] | A. Chat Server's Outgoing Traffic | 1 | 64 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
- Include a person... | Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
- +<name> for 'Add' command. - -<name> for 'Remove' command. - <sender_name>:<message_text> for 'Send' command.
<name> and <s... | Print a single number β answer to the problem. | [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n"
] | [
"9\n",
"14\n"
] | none | 0 | [
{
"input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate",
"output": "9"
},
{
"input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate",
"output": "14"
},
{
"input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIO... | 1,678,883,045 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | import sys
names = set()
result = 0
lines = sys.stdin.readlines()
for s in lines:
s = s.strip()
if '+' in s:
names.add(s[1:])
continue
if '-' in s:
names.remove(s[1:])
continue
name, messsage = s.split(':')
result += len(names) * len(messsage)
print(result) | Title: Chat Servers Outgoing Traffic
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in fr... | ```python
import sys
names = set()
result = 0
lines = sys.stdin.readlines()
for s in lines:
s = s.strip()
if '+' in s:
names.add(s[1:])
continue
if '-' in s:
names.remove(s[1:])
continue
name, messsage = s.split(':')
result += len(names) * len(messsage)
print(resul... | 3.938 |
940 | C | Phone Numbers | PROGRAMMING | 1,500 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | And where the are the phone numbers?
You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a subset of the set of letters of *s* and *s* is lexicographically smaller than *t*.
It's guaranteed... | The first line of input contains two space separated integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=100<=000)Β β the length of *s* and the required length of *t*.
The second line of input contains the string *s* consisting of *n* lowercase English letters. | Output the string *t* conforming to the requirements above.
It's guaranteed that the answer exists. | [
"3 3\nabc\n",
"3 2\nabc\n",
"3 3\nayy\n",
"2 3\nba\n"
] | [
"aca\n",
"ac\n",
"yaa\n",
"baa\n"
] | In the first example the list of strings *t* of length 3, such that the set of letters of *t* is a subset of letters of *s* is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca. | 1,250 | [
{
"input": "3 3\nabc",
"output": "aca"
},
{
"input": "3 2\nabc",
"output": "ac"
},
{
"input": "3 3\nayy",
"output": "yaa"
},
{
"input": "2 3\nba",
"output": "baa"
},
{
"input": "1 3\nf",
"output": "fff"
},
{
"input": "3 1\nazz",
"output": "z"
},
... | 1,519,721,168 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 78 | 5,939,200 | a,b = map(int,input().split(' '))
s = input()
s1 = sorted(set(s))
if b>a:
print(s+s1[0]*(b-a))
else:
i = b-1
while s[i]>=s1[-1] and i>-1:
i -= 1
d = s1.index(s[i])
print(s[:i]+s1[d+1]+s1[0]*(b-i-1)) | Title: Phone Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
And where the are the phone numbers?
You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a ... | ```python
a,b = map(int,input().split(' '))
s = input()
s1 = sorted(set(s))
if b>a:
print(s+s1[0]*(b-a))
else:
i = b-1
while s[i]>=s1[-1] and i>-1:
i -= 1
d = s1.index(s[i])
print(s[:i]+s1[d+1]+s1[0]*(b-i-1))
``` | 3 | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=β€<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters β the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,649,159,881 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 77 | 204,800 | n = int(input())
arr = []
for i in range(n):
arr.append(list(input()))
cnt = set()
x = arr[0][0]
y = arr[0][1]
ans = "YES"
for i in range(n):
for j in range(n):
cnt.add(arr[i][j])
if i == j or i == n-1-j:
if arr[i][j] != x:
ans = "NO"
break
el... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
n = int(input())
arr = []
for i in range(n):
arr.append(list(input()))
cnt = set()
x = arr[0][0]
y = arr[0][1]
ans = "YES"
for i in range(n):
for j in range(n):
cnt.add(arr[i][j])
if i == j or i == n-1-j:
if arr[i][j] != x:
ans = "NO"
break
... | 3 | |
965 | C | Greedy Arkady | PROGRAMMING | 2,000 | [
"math"
] | null | null | $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ... | The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$)Β β the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can ... | Print a single integerΒ β the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid $x$. | [
"20 4 5 2\n",
"30 9 4 1\n"
] | [
"8\n",
"4\n"
] | In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total... | 1,500 | [
{
"input": "20 4 5 2",
"output": "8"
},
{
"input": "30 9 4 1",
"output": "4"
},
{
"input": "2 2 1 1",
"output": "1"
},
{
"input": "42 20 5 29",
"output": "5"
},
{
"input": "1000000000000000000 135 1000000000000000 1000",
"output": "8325624421831635"
},
{
... | 1,609,558,220 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 140 | 0 | s=list(map(int,input().split()))
n=s[0]
k=s[1]
M=s[2]
D=s[3]
ans=0
for d in range(0,D+1):
x=n//((d-1)*k+1)
if x>M:
x=M
if x*d>ans:
ans=x*d
print(ans)
| Title: Greedy Arkady
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arka... | ```python
s=list(map(int,input().split()))
n=s[0]
k=s[1]
M=s[2]
D=s[3]
ans=0
for d in range(0,D+1):
x=n//((d-1)*k+1)
if x>M:
x=M
if x*d>ans:
ans=x*d
print(ans)
``` | 3 | |
246 | B | Increase and Decrease | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i... | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) β the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=β€<=104) β the original array. | Print a single integer β the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | [
"2\n2 1\n",
"3\n1 4 1\n"
] | [
"1\n",
"3\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 4 1",
"output": "3"
},
{
"input": "4\n2 -7 -2 -6",
"output": "3"
},
{
"input": "4\n2 0 -2 -1",
"output": "3"
},
{
"input": "6\n-1 1 0 0 -1 -1",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"outp... | 1,561,915,247 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 342 | 5,632,000 | n = int(input())
arr = [int(i) for i in input().split()]
if sum(arr)%n ==0: print(n)
else: print(n-1) | Title: Increase and Decrease
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that... | ```python
n = int(input())
arr = [int(i) for i in input().split()]
if sum(arr)%n ==0: print(n)
else: print(n-1)
``` | 3 | |
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | The first line contains two space-separated integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ... | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It ... | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n--------... | 1,640,562,261 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 0 | n, m = map(int, input().split())
inp = [input() for _ in range(n)]
for i in range(n):
for j in range(m):
if inp[i][j] == '-':
print('-', end='')
else:
print('B' if (i+j)%2==0 else 'W', end='')
print('') | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ... | ```python
n, m = map(int, input().split())
inp = [input() for _ in range(n)]
for i in range(n):
for j in range(m):
if inp[i][j] == '-':
print('-', end='')
else:
print('B' if (i+j)%2==0 else 'W', end='')
print('')
``` | 3 | |
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ... | The first line contains integer *n* (1<=β€<=*n*<=β€<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=105). The numbers are separated by spaces. | In the first line print integer *t* β the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th... | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub>β=β0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"outpu... | 1,622,921,178 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 966 | 14,950,400 | n= int(input())
t = list(map(int,input().split()))
u=[]
f={}
p=0
for j in range(n):
if t[j] not in f:
f[t[j]]=[0,j]
else:
if f[t[j]][0]==0:
f[t[j]][0]= j-f[t[j]][-1]
f[t[j]].append(j)
elif f[t[j]][0]!='a':
if j-f[t[j]][-1]==f[t[j]][0]:
... | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
-... | ```python
n= int(input())
t = list(map(int,input().split()))
u=[]
f={}
p=0
for j in range(n):
if t[j] not in f:
f[t[j]]=[0,j]
else:
if f[t[j]][0]==0:
f[t[j]][0]= j-f[t[j]][-1]
f[t[j]].append(j)
elif f[t[j]][0]!='a':
if j-f[t[j]][-1]==f[t[j... | 3 | |
1,011 | B | Planning The Expedition | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat t... | The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$)Β β the number of the expedition participants and the number of the daily food packages available.
The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food pac... | Print the single integerΒ β the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0. | [
"4 10\n1 5 2 1 1 1 2 5 7 2\n",
"100 1\n1\n",
"2 5\n5 4 3 2 1\n",
"3 9\n42 42 42 42 42 42 42 42 42\n"
] | [
"2\n",
"0\n",
"1\n",
"3\n"
] | In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of ty... | 1,000 | [
{
"input": "4 10\n1 5 2 1 1 1 2 5 7 2",
"output": "2"
},
{
"input": "100 1\n1",
"output": "0"
},
{
"input": "2 5\n5 4 3 2 1",
"output": "1"
},
{
"input": "3 9\n42 42 42 42 42 42 42 42 42",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"inp... | 1,532,724,778 | 1,378 | Python 3 | OK | TESTS | 31 | 109 | 0 | n, m = map(int, input().split())
packages = list(map(int, input().split()))
counts = dict()
for p in packages:
if p in counts:
counts[p] += 1
else:
counts[p] = 1
arrayCounts = []
for package, count in counts.items():
arrayCounts.append(count)
arrayCounts.sort()
arrayCounts.reverse()
for i in range(m//n+1):... | Title: Planning The Expedition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
E... | ```python
n, m = map(int, input().split())
packages = list(map(int, input().split()))
counts = dict()
for p in packages:
if p in counts:
counts[p] += 1
else:
counts[p] = 1
arrayCounts = []
for package, count in counts.items():
arrayCounts.append(count)
arrayCounts.sort()
arrayCounts.reverse()
for i in rang... | 3 | |
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It... | The first line contains an even integer *n* (2<=β€<=*n*<=β€<=50) β the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* β the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4ββ β7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
... | 1,479,306,428 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 124 | 0 | n = int(input())
s = str(input())
a = 0
b = 0
for i, num in enumerate(s):
if num != '7' and num != '4':
print("NO")
a=-1
b=-2
break
else:
if i+1<=n/2:
a+=int(num)
else:
b+=int(num)
else:
if a==b:
print("YES")
... | Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record 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())
s = str(input())
a = 0
b = 0
for i, num in enumerate(s):
if num != '7' and num != '4':
print("NO")
a=-1
b=-2
break
else:
if i+1<=n/2:
a+=int(num)
else:
b+=int(num)
else:
if a==b:
pri... | 3 | |
454 | A | Little Pony and Crystal Mine | PROGRAMMING | 800 | [
"implementation"
] | null | null | Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=Γ<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All ot... | The only line contains an integer *n* (3<=β€<=*n*<=β€<=101; *n* is odd). | Output a crystal of size *n*. | [
"3\n",
"5\n",
"7\n"
] | [
"*D*\nDDD\n*D*\n",
"**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n",
"***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n"
] | none | 500 | [
{
"input": "3",
"output": "*D*\nDDD\n*D*"
},
{
"input": "5",
"output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**"
},
{
"input": "7",
"output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***"
},
{
"input": "11",
"output": "*****D*****\n****DDD****\n***DDDDD***\n**... | 1,598,615,103 | 2,147,483,647 | Python 3 | OK | TESTS | 12 | 109 | 0 | n=int(input())
x=int(n/2)
for i in range(1,n+1):
print("*"*x+'D'*(n-(2*x))+'*'*x)
if i <=int(n/2) :
x-=1
else :
x+=1
# print(x,i) | Title: Little Pony and Crystal Mine
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=Γ<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You ... | ```python
n=int(input())
x=int(n/2)
for i in range(1,n+1):
print("*"*x+'D'*(n-(2*x))+'*'*x)
if i <=int(n/2) :
x-=1
else :
x+=1
# print(x,i)
``` | 3 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=β€<=*a*1,<=*a*2,<=*a*3,<=*a*4<=β€<=104).
The second line contains string *s* (1<=β€<=|*s*|<=β€<=105), where the *Ρ*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer β the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,694,442,986 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 62 | 102,400 | k = list(map(int,input().split()))
s = str(input())
sum = 0
for i in s:
if i == "1":
sum += k[0]
elif i == "2":
sum += k[1]
elif i == "3":
sum += k[2]
elif i == "4":
sum += k[3]
print(sum)
| 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
k = list(map(int,input().split()))
s = str(input())
sum = 0
for i in s:
if i == "1":
sum += k[0]
elif i == "2":
sum += k[1]
elif i == "3":
sum += k[2]
elif i == "4":
sum += k[3]
print(sum)
``` | 3 | |
652 | C | Foe Pairs | PROGRAMMING | 1,800 | [
"combinatorics",
"sortings",
"two pointers"
] | null | null | You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*,<=*a**i*<=β <=*b**i*).
Your task is to count the number of different intervals (*x*,<=*y*) (1<=β€<=*x*<=β€<=*y*<=β€<=*n*) that do not contain any foe pairs. So you shouldn't count intervals (*x... | The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=3Β·105) β the length of the permutation *p* and the number of foe pairs.
The second line contains *n* distinct integers *p**i* (1<=β€<=*p**i*<=β€<=*n*) β the elements of the permutation *p*.
Each of the next *m* lines contains two integers (*a**i*,<=*... | Print the only integer *c* β the number of different intervals (*x*,<=*y*) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"4 2\n1 3 2 4\n3 2\n2 4\n",
"9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7\n"
] | [
"5\n",
"20\n"
] | In the first example the intervals from the answer are (1,β1), (1,β2), (2,β2), (3,β3) and (4,β4). | 0 | [
{
"input": "4 2\n1 3 2 4\n3 2\n2 4",
"output": "5"
},
{
"input": "9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7",
"output": "20"
},
{
"input": "2 1\n1 2\n1 2",
"output": "2"
},
{
"input": "10 3\n4 10 5 1 6 8 9 2 3 7\n10 5\n2 10\n4 1",
"output": "39"
},
{
"input"... | 1,660,723,345 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 24 | 421 | 65,740,800 | import sys
if __name__=='__main__':
n,m=map(int,input().split())
line=sys.stdin.readline()
pos={int(v):i for i,v in enumerate(line.split())}
check=[300004]*(n+1)
for line in sys.stdin.readlines():
a,b=map(int,line.split())
if pos[a]>pos[b]:
check[pos[b]]=min(chec... | Title: Foe Pairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*,<=*a**i*<=β <=*b**i*).
Your task is to count the number of different intervals (*x*,<=*y*) (1<=... | ```python
import sys
if __name__=='__main__':
n,m=map(int,input().split())
line=sys.stdin.readline()
pos={int(v):i for i,v in enumerate(line.split())}
check=[300004]*(n+1)
for line in sys.stdin.readlines():
a,b=map(int,line.split())
if pos[a]>pos[b]:
check[pos[b]... | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,688,989,558 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n = int(input(""))
for a in range(0,n):
string = input("")
if len(string)>10:
slice = string[0] + str(len(string)-2) +string[-1]
print(slice)
else:
print(string) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n = int(input(""))
for a in range(0,n):
string = input("")
if len(string)>10:
slice = string[0] + str(len(string)-2) +string[-1]
print(slice)
else:
print(string)
``` | 3.977 |
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | The first line of the input contains one integer $n$ ($1 \le n \le 100$) β the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) β values of coins. | Print only one integer β the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 1,646,633,596 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 0 | n= int(input())
a= list(map(int, input().split()))
x= [a.count(i) for i in a]
x.sort()
print(x[n-1]) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Po... | ```python
n= int(input())
a= list(map(int, input().split()))
x= [a.count(i) for i in a]
x.sort()
print(x[n-1])
``` | 3 | |
632 | C | The Smallest String Concatenation | PROGRAMMING | 1,700 | [
"sortings",
"strings"
] | null | null | You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation. | The first line contains integer *n* β the number of strings (1<=β€<=*n*<=β€<=5Β·104).
Each of the next *n* lines contains one string *a**i* (1<=β€<=|*a**i*|<=β€<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5Β·104. | Print the only string *a* β the lexicographically smallest string concatenation. | [
"4\nabba\nabacaba\nbcd\ner\n",
"5\nx\nxx\nxxa\nxxaa\nxxaaa\n",
"3\nc\ncb\ncba\n"
] | [
"abacabaabbabcder\n",
"xxaaaxxaaxxaxxx\n",
"cbacbc\n"
] | none | 0 | [
{
"input": "4\nabba\nabacaba\nbcd\ner",
"output": "abacabaabbabcder"
},
{
"input": "5\nx\nxx\nxxa\nxxaa\nxxaaa",
"output": "xxaaaxxaaxxaxxx"
},
{
"input": "3\nc\ncb\ncba",
"output": "cbacbc"
},
{
"input": "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab... | 1,543,909,120 | 3,880 | Python 3 | OK | TESTS | 16 | 280 | 2,150,400 | from functools import cmp_to_key
def cmp(x,y):
if x+y>y+x:
return 1
else:
return -1
a=[]
n=int(input())
for i in range(n):
a.append(input())
ans=""
for s in sorted(a,key=cmp_to_key(cmp)):
ans+=s
print(ans)
| Title: The Smallest String Concatenation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list ... | ```python
from functools import cmp_to_key
def cmp(x,y):
if x+y>y+x:
return 1
else:
return -1
a=[]
n=int(input())
for i in range(n):
a.append(input())
ans=""
for s in sorted(a,key=cmp_to_key(cmp)):
ans+=s
print(ans)
``` | 3 | |
926 | E | Merge Equal Elements | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures"
] | null | null | You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to *x*, delete both a... | The first line contains a single integer *n* (2<=β€<=*n*<=β€<=2Β·105) β the number of elements in the sequence.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109). | In the first line print a single integer *k* β the number of elements in the sequence after you stop performing the operation.
In the second line print *k* integersΒ β the sequence after you stop performing the operation. | [
"6\n5 2 1 1 2 2\n",
"4\n1000000000 1000000000 1000000000 1000000000\n",
"7\n4 10 22 11 12 5 6\n"
] | [
"2\n5 4 ",
"1\n1000000002 ",
"7\n4 10 22 11 12 5 6 "
] | The first example is described in the statements.
In the second example the initial sequence is [1000000000,β1000000000,β1000000000,β1000000000]. After the first operation the sequence is equal to [1000000001,β1000000000,β1000000000]. After the second operation the sequence is [1000000001,β1000000001]. After the third... | 0 | [
{
"input": "6\n5 2 1 1 2 2",
"output": "2\n5 4 "
},
{
"input": "4\n1000000000 1000000000 1000000000 1000000000",
"output": "1\n1000000002 "
},
{
"input": "7\n4 10 22 11 12 5 6",
"output": "7\n4 10 22 11 12 5 6 "
},
{
"input": "2\n1 1",
"output": "1\n2 "
},
{
"inpu... | 1,548,090,077 | 2,147,483,647 | Python 3 | OK | TESTS | 75 | 374 | 18,022,400 | n = int(input())
a = [int(x) for x in input().split()]
stack = []
i = 0
x = a[i]
while True:
if len(stack) == 0:
stack.append(x)
i += 1
if i == n:
break
x = a[i]
else:
if x == stack[-1]:
del stack[-1]
x += 1
else... | Title: Merge Equal Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find... | ```python
n = int(input())
a = [int(x) for x in input().split()]
stack = []
i = 0
x = a[i]
while True:
if len(stack) == 0:
stack.append(x)
i += 1
if i == n:
break
x = a[i]
else:
if x == stack[-1]:
del stack[-1]
x += 1
... | 3 | |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=Γ<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=Γ<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=β€<=*r*,<=*c*<=β€<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters β the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,618,667,790 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 216 | 0 | n, m = [int(i) for i in input().split()]
mas = [input() for _ in range(n)]
count = 0
for i in range(n-1,-1,-1):
if 'S' not in mas[i]:
count += m
del mas[i]
n -= 1
for j in range(m-1, -1, -1):
flag = False
for i in range(n):
flag += 'S' == mas[i][j]
if not fla... | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=Γ<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=Γ<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
n, m = [int(i) for i in input().split()]
mas = [input() for _ in range(n)]
count = 0
for i in range(n-1,-1,-1):
if 'S' not in mas[i]:
count += m
del mas[i]
n -= 1
for j in range(m-1, -1, -1):
flag = False
for i in range(n):
flag += 'S' == mas[i][j]
... | 3 | |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$)Β β the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$)Β β the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,654,885,280 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 46 | 0 | dict1={"purple":"Power", "green":"Time", "blue":"Space", "orange":"Soul", "red":"Reality", "yellow":"Mind"}
n=int(input())
n_list=[]
print(6-n)
for i in range(n):
g=input()
n_list.append(g)
for k,v in dict1.items():
if k not in n_list:
print(v)
| Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
dict1={"purple":"Power", "green":"Time", "blue":"Space", "orange":"Soul", "red":"Reality", "yellow":"Mind"}
n=int(input())
n_list=[]
print(6-n)
for i in range(n):
g=input()
n_list.append(g)
for k,v in dict1.items():
if k not in n_list:
print(v)
``` | 3 | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=β€<=*n*<=β€<=105;Β 1<=β€<=*t*<=β€<=109) β the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer β the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,687,020,706 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 186 | 13,824,000 | p=lambda:list(map(int,input().split()))
n,t=p()
l=p()
i=j=s=0
for j in range(n):
s+=l[j]
if s>t:
s-=l[i]
i+=1
print(n-i) | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
p=lambda:list(map(int,input().split()))
n,t=p()
l=p()
i=j=s=0
for j in range(n):
s+=l[j]
if s>t:
s-=l[i]
i+=1
print(n-i)
``` | 3 | |
474 | A | Keyboard | PROGRAMMING | 900 | [
"implementation"
] | null | null | Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That mean... | First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right).
Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain ... | Print a line that contains the original message. | [
"R\ns;;upimrrfod;pbr\n"
] | [
"allyouneedislove\n"
] | none | 500 | [
{
"input": "R\ns;;upimrrfod;pbr",
"output": "allyouneedislove"
},
{
"input": "R\nwertyuiop;lkjhgfdsxcvbnm,.",
"output": "qwertyuiolkjhgfdsazxcvbnm,"
},
{
"input": "L\nzxcvbnm,kjhgfdsaqwertyuio",
"output": "xcvbnm,.lkjhgfdswertyuiop"
},
{
"input": "R\nbubbuduppudup",
"outp... | 1,680,827,767 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | a = input()
b = list(input())
key = list("qwertyuiopasdfghjkl;zxcvbnm,./")
if a =="L":
d=1
else:
d=-1
n=[]
for i in range(len(b)):
e = b[i]
f = key.index(e)
n.append(key[f+d])
print(''.join(n)) | Title: Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately.... | ```python
a = input()
b = list(input())
key = list("qwertyuiopasdfghjkl;zxcvbnm,./")
if a =="L":
d=1
else:
d=-1
n=[]
for i in range(len(b)):
e = b[i]
f = key.index(e)
n.append(key[f+d])
print(''.join(n))
``` | 3 | |
760 | A | Petr and a calendar | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
Petr wants to ... | The only line contain two integers *m* and *d* (1<=β€<=*m*<=β€<=12, 1<=β€<=*d*<=β€<=7)Β β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). | Print single integer: the number of columns the table should have. | [
"1 7\n",
"1 1\n",
"11 6\n"
] | [
"6\n",
"5\n",
"5\n"
] | The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough. | 500 | [
{
"input": "1 7",
"output": "6"
},
{
"input": "1 1",
"output": "5"
},
{
"input": "11 6",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "2 1",
"output": "4"
},
{
"input": "8 6",
"output": "6"
},
{
"input": "1 1",
"output... | 1,594,001,788 | 2,147,483,647 | Python 3 | OK | TESTS | 104 | 108 | 6,758,400 | import math
m, d = map(int, input().split())
a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
print(math.ceil((a[m-1]+d-1)/7))
| Title: Petr and a calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells... | ```python
import math
m, d = map(int, input().split())
a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
print(math.ceil((a[m-1]+d-1)/7))
``` | 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,585,643,922 | 2,147,483,647 | PyPy 3 | OK | TESTS | 70 | 156 | 0 | l=['A','U','O','I','E','Y']
s=input()
c=0
m=0
for i in s:
if(i in l):
m=max(m,c)
c=0
else:
c=c+1
m=max(c,m)
print(m+1) | 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
l=['A','U','O','I','E','Y']
s=input()
c=0
m=0
for i in s:
if(i in l):
m=max(m,c)
c=0
else:
c=c+1
m=max(c,m)
print(m+1)
``` | 3 | |
955 | B | Not simply beatiful strings | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others β a ... | The only line contains *s* (1<=β€<=|*s*|<=β€<=105) consisting of lowercase latin letters. | Print Β«YesΒ» if the string can be split according to the criteria above or Β«NoΒ» otherwise.
Each letter can be printed in arbitrary case. | [
"ababa\n",
"zzcxx\n",
"yeee\n"
] | [
"Yes\n",
"Yes\n",
"No\n"
] | In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable.
There's no suitable partition in sample case three. | 1,000 | [
{
"input": "ababa",
"output": "Yes"
},
{
"input": "zzcxx",
"output": "Yes"
},
{
"input": "yeee",
"output": "No"
},
{
"input": "a",
"output": "No"
},
{
"input": "bbab",
"output": "No"
},
{
"input": "abcd",
"output": "Yes"
},
{
"input": "abc"... | 1,521,823,735 | 835 | Python 3 | OK | TESTS | 56 | 155 | 7,270,400 | s = input()
l = list(set(s))
ans = 1
if (len(l)>4) or (len(l)<=1):
ans = 0
else:
if len(l)==2:
c1=0
c0=0
for i in range(len(s)):
if s[i]==l[0]:
c0+=1
else:
c1+=1
if (c1<2) or (c0<2):
ans = 0
i... | Title: Not simply beatiful strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, abab... | ```python
s = input()
l = list(set(s))
ans = 1
if (len(l)>4) or (len(l)<=1):
ans = 0
else:
if len(l)==2:
c1=0
c0=0
for i in range(len(s)):
if s[i]==l[0]:
c0+=1
else:
c1+=1
if (c1<2) or (c0<2):
ans ... | 3 | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=β€<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=β€<=1000)Β β the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participantΒ β in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participantΒ β in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,610,458,255 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 77 | 0 | s,v1,v2,t1,t2=map(int,input().split())
first=s*v1+2*t1
second=s*v2+2*t2
if first > second:
print ("Second")
if first < second:
print("First")
if first ==second:
print("Friendship")
| Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
s,v1,v2,t1,t2=map(int,input().split())
first=s*v1+2*t1
second=s*v2+2*t2
if first > second:
print ("Second")
if first < second:
print("First")
if first ==second:
print("Friendship")
``` | 3 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=β€<=*n*<=β€<=1000, 0<=β€<=*x*<=β€<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=β€<=*d**i*<=β€<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integersΒ β number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,603,927,446 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 156 | 1,433,600 | def solve(test):
ans = 0
n, x = map(int, input().split())
for i in range(n):
c = input().split()
if c[0] == '+':
x += int(c[1])
elif int(c[1]) > x:
ans += 1
else:
x -= int(c[1])
print(x, ans)
t = 1
#t = int(input())
for _ ... | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
def solve(test):
ans = 0
n, x = map(int, input().split())
for i in range(n):
c = input().split()
if c[0] == '+':
x += int(c[1])
elif int(c[1]) > x:
ans += 1
else:
x -= int(c[1])
print(x, ans)
t = 1
#t = int(input(... | 3 | |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave ViΔkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=β€<=*A*,<=*B*<=β€<=109,<=*min*(*A*,<=*B*)<=β€<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4!β=β1Β·2Β·3Β·4β=β24. 3!β=β1Β·2Β·3β=β6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,690,380,223 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | import math as m
a,b=map(int,input().split())
c=min(a,b)
print(m.factorial(c)) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
import math as m
a,b=map(int,input().split())
c=min(a,b)
print(m.factorial(c))
``` | 3 | |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*... | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=β€<=*a*,<=*b*<=β€<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
}... | 1,683,477,112 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 92 | 0 | a = (input())
b = (input())
res = int(a)+int(b)
a = a.replace("0",'')
b = b.replace("0",'')
res = str(res)
res = res.replace("0",'')
res = int(res)
a = int(a)
b = int(b)
if res == (a+b):
print("YES")
else:
print("NO")
| Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu... | ```python
a = (input())
b = (input())
res = int(a)+int(b)
a = a.replace("0",'')
b = b.replace("0",'')
res = str(res)
res = res.replace("0",'')
res = int(res)
a = int(a)
b = int(b)
if res == (a+b):
print("YES")
else:
print("NO")
``` | 3.977 |
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,696,160,479 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | str = list(input())
n = len(str)
hello = "hello"
counter = 0
for i in range(0,n):
if(counter < 5 and str[i] == hello[counter]):
counter += 1
if(counter >= 5):
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
str = list(input())
n = len(str)
hello = "hello"
counter = 0
for i in range(0,n):
if(counter < 5 and str[i] == hello[counter]):
counter += 1
if(counter >= 5):
print("YES")
else:
print("NO")
``` | 3.969 |
166 | A | Rank List | PROGRAMMING | 1,100 | [
"binary search",
"implementation",
"sortings"
] | null | null | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.
You know the rules of comparing the results of two give... | The first line contains two integers *n* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=β€<=*p**i*,<=*t**i*<=β€<=50) β the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All num... | In the only line print the sought number of teams that got the *k*-th place in the final results' table. | [
"7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n",
"5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n"
] | [
"3\n",
"4\n"
] | The final results' table for the first sample is:
- 1-3 places β 4 solved problems, the penalty time equals 10 - 4 place β 3 solved problems, the penalty time equals 20 - 5-6 places β 2 solved problems, the penalty time equals 1 - 7 place β 1 solved problem, the penalty time equals 10
The table shows that the se... | 500 | [
{
"input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10",
"output": "3"
},
{
"input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1",
"output": "4"
},
{
"input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2",
"output": "2"
},
{
"input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5",
"output": "1"
},
{
"i... | 1,672,165,516 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 92 | 0 | a,b = map(int,input().split())
mat = []
for i in range(a) :
arr = list(map(int,input().split()))
mat.append(arr)
mat = sorted(mat, key = lambda x : (-x[0],x[1]))
print(mat.count(mat[b-1])) | Title: Rank List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for... | ```python
a,b = map(int,input().split())
mat = []
for i in range(a) :
arr = list(map(int,input().split()))
mat.append(arr)
mat = sorted(mat, key = lambda x : (-x[0],x[1]))
print(mat.count(mat[b-1]))
``` | 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,643,201,731 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n=int(input())
s=input()
s=s.split()
l=[]
for i in range(n):
l.append(int(s[i]))
m = int(input())
for i in range(m):
ss=input()
ss=ss.split()
xi=int(ss[0])
yi=int(ss[1])
ox=l[xi-1]
l[xi-1]-=yi
if xi-2>=0:
l[xi-2]+=(yi-1)
ox=ox-yi
l[xi-... | 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())
s=input()
s=s.split()
l=[]
for i in range(n):
l.append(int(s[i]))
m = int(input())
for i in range(m):
ss=input()
ss=ss.split()
xi=int(ss[0])
yi=int(ss[1])
ox=l[xi-1]
l[xi-1]-=yi
if xi-2>=0:
l[xi-2]+=(yi-1)
ox=ox-yi
... | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,663,230,255 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 31 | 0 | s=list(input())
n='NO'
for i in range(len(s)):
if s[i]=='h' :
for i_1 in range(i,len(s)):
if s[i_1]=='e' :
for i_2 in range(i_1,len(s)):
if s[i_2]=='l' :
for i_3 in range(i_2+1,len(s)):
if s[i_3]=='l... | 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=list(input())
n='NO'
for i in range(len(s)):
if s[i]=='h' :
for i_1 in range(i,len(s)):
if s[i_1]=='e' :
for i_2 in range(i_1,len(s)):
if s[i_2]=='l' :
for i_3 in range(i_2+1,len(s)):
if ... | 3.9845 |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=β€<=*n*<=β€<=2000;Β 1<=β€<=*k*<=β€<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=β€<=*y**i*<=β€<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number β the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,674,326,274 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 62 | 1,638,400 | fristNum,secondNum=map(int,input().split())
listNum=list(map(int,input().split()))
counts=0
for i in range(fristNum):
if(listNum[i]+secondNum <= 5):
counts+=1
print(counts//3)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
fristNum,secondNum=map(int,input().split())
listNum=list(map(int,input().split()))
counts=0
for i in range(fristNum):
if(listNum[i]+secondNum <= 5):
counts+=1
print(counts//3)
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,539,353,643 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 171 | 512,000 | import re
k=input()
helloRegex=re.compile(r'(h)+((\w)?)+(e)+((\w)?)+(l)+((\w)?)+(l)+((\w)?)+(o)+')
if helloRegex.search(k)== None :
print('NO')
else :
print('YES')
| 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
import re
k=input()
helloRegex=re.compile(r'(h)+((\w)?)+(e)+((\w)?)+(l)+((\w)?)+(l)+((\w)?)+(o)+')
if helloRegex.search(k)== None :
print('NO')
else :
print('YES')
``` | 3.913546 |
278 | A | Circle Line | PROGRAMMING | 800 | [
"implementation"
] | null | null | The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th ... | The first line contains integer *n* (3<=β€<=*n*<=β€<=100) β the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=β€<=*d**i*<=β€<=100) β the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=β€<=*s*,<=*t*<=β€<=*n*) β... | Print a single number β the length of the shortest path between stations number *s* and *t*. | [
"4\n2 3 4 9\n1 3\n",
"4\n5 8 2 100\n4 1\n",
"3\n1 1 1\n3 1\n",
"3\n31 41 59\n1 1\n"
] | [
"5\n",
"15\n",
"1\n",
"0\n"
] | In the first sample the length of path 1βββ2βββ3 equals 5, the length of path 1βββ4βββ3 equals 13.
In the second sample the length of path 4βββ1 is 100, the length of path 4βββ3βββ2βββ1 is 15.
In the third sample the length of path 3βββ1 is 1, the length of path 3βββ2βββ1 is 2.
In the fourth sample the numbers of st... | 500 | [
{
"input": "4\n2 3 4 9\n1 3",
"output": "5"
},
{
"input": "4\n5 8 2 100\n4 1",
"output": "15"
},
{
"input": "3\n1 1 1\n3 1",
"output": "1"
},
{
"input": "3\n31 41 59\n1 1",
"output": "0"
},
{
"input": "5\n16 13 10 30 15\n4 2",
"output": "23"
},
{
"inpu... | 1,583,840,092 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 218 | 0 | num = int(input())
stations = list(map(int,list(input().split())))
points = sorted(list(map(int,list(input().split()))))
sum1 = sum(stations[points[0]-1:points[1]-1])
sum2 = sum(stations) - sum(stations[points[0]-1:points[1]-1])
if sum1 < sum2:
print(sum1)
else:
print(sum2)
| Title: Circle Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd... | ```python
num = int(input())
stations = list(map(int,list(input().split())))
points = sorted(list(map(int,list(input().split()))))
sum1 = sum(stations[points[0]-1:points[1]-1])
sum2 = sum(stations) - sum(stations[points[0]-1:points[1]-1])
if sum1 < sum2:
print(sum1)
else:
print(sum2)
... | 3 | |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100)Β β the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=β€<=*x**i*<=β€<=*m*)Β β the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=β€<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,666,107,144 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 0 | a,b=map(int,input().split())
g=set()
for i in range(a):
n=list(map(int,input().split()))
n.pop(0)
g.update(n)
print(['NO','YES'][len(g) == b]) | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
a,b=map(int,input().split())
g=set()
for i in range(a):
n=list(map(int,input().split()))
n.pop(0)
g.update(n)
print(['NO','YES'][len(g) == b])
``` | 3 | |
920 | C | Swap Adjacent Elements | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"math",
"sortings",
"two pointers"
] | null | null | You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=β€<=*i*<=β€<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. T... | The first line contains one integer *n* (2<=β€<=*n*<=β€<=200000) β the number of elements in the array.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=200000) β the elements of the array. Each integer from 1 to *n* appears exactly once.
The third line contains a string of *n*<=-<=1 char... | If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO. | [
"6\n1 2 5 3 4 6\n01110\n",
"6\n1 2 5 3 4 6\n01010\n"
] | [
"YES\n",
"NO\n"
] | In the first example you may swap *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, and then swap *a*<sub class="lower-index">4</sub> and *a*<sub class="lower-index">5</sub>. | 0 | [
{
"input": "6\n1 2 5 3 4 6\n01110",
"output": "YES"
},
{
"input": "6\n1 2 5 3 4 6\n01010",
"output": "NO"
},
{
"input": "6\n1 6 3 4 5 2\n01101",
"output": "NO"
},
{
"input": "6\n2 3 1 4 5 6\n01111",
"output": "NO"
},
{
"input": "4\n2 3 1 4\n011",
"output": "NO... | 1,518,262,219 | 2,147,483,647 | Python 3 | OK | TESTS | 139 | 249 | 20,480,000 | n=int(input())
a=input().split()
b=input()+'1'
c=[]
k=0
for u in b:
c.append(k)
if u=='0':
k+=1
for i in range(0,n):
if c[i]!=c[int(a[i])-1]:
print('NO')
exit()
print('YES')
exit()
| Title: Swap Adjacent Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=β€<=*i*<=β€<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<... | ```python
n=int(input())
a=input().split()
b=input()+'1'
c=[]
k=0
for u in b:
c.append(k)
if u=='0':
k+=1
for i in range(0,n):
if c[i]!=c[int(a[i])-1]:
print('NO')
exit()
print('YES')
exit()
``` | 3 | |
522 | B | Photo to Remember | PROGRAMMING | 1,100 | [
"*special",
"data structures",
"dp",
"implementation"
] | null | null | One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the *i*-th of them occupies the rectangl... | The first line contains integer *n* (2<=β€<=*n*<=β€<=200<=000) β the number of friends.
Then *n* lines follow: the *i*-th line contains information about the *i*-th friend. The line contains a pair of integers *w**i*,<=*h**i* (1<=β€<=*w**i*<=β€<=10,<=1<=β€<=*h**i*<=β€<=1000) β the width and height in pixels of the correspo... | Print *n* space-separated numbers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* β the total number of pixels on the minimum photo containing all friends expect for the *i*-th one. | [
"3\n1 10\n5 5\n10 1\n",
"3\n2 1\n1 2\n2 1\n"
] | [
"75 110 60 ",
"6 4 6 "
] | none | 1,000 | [
{
"input": "3\n1 10\n5 5\n10 1",
"output": "75 110 60 "
},
{
"input": "3\n2 1\n1 2\n2 1",
"output": "6 4 6 "
},
{
"input": "2\n1 5\n2 3",
"output": "6 5 "
},
{
"input": "2\n2 3\n1 1",
"output": "1 6 "
},
{
"input": "3\n1 10\n2 10\n3 10",
"output": "50 40 30 "
... | 1,677,174,837 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 904 | 12,697,600 |
n = int(input())
W = 0
pers = []
H1 = 0; H2 = 0
I = 0
for i in range(n):
w, h = map(int, input().split())
pers.append([w,h])
W += w
if h > H2:
H2 = h
I = i
for i in range(n):
if i == I:
continue
w, h = pers[i]
if H2 >= h > H1:
H1 =... | Title: Photo to Remember
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the p... | ```python
n = int(input())
W = 0
pers = []
H1 = 0; H2 = 0
I = 0
for i in range(n):
w, h = map(int, input().split())
pers.append([w,h])
W += w
if h > H2:
H2 = h
I = i
for i in range(n):
if i == I:
continue
w, h = pers[i]
if H2 >= h > H1:
... | 3 | |
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,... | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) β the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number β the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"outpu... | 1,697,101,461 | 2,147,483,647 | PyPy 3 | OK | TESTS | 11 | 77 | 0 | n, k = [int(z) for z in input().split(" ")]
for i in range(1,k+1):
if(n%10!=0):
n=n-1
else:
n=n/10
print(int(n))
| Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit ... | ```python
n, k = [int(z) for z in input().split(" ")]
for i in range(1,k+1):
if(n%10!=0):
n=n-1
else:
n=n/10
print(int(n))
``` | 3 | |
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=β€<=*i*<=β€<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfo... | The first line contains two space-separated integers, *n* and *c* (2<=β€<=*n*<=β€<=100,<=0<=β€<=*c*<=β€<=100), β the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=β€<=*x**i*<=β€<=100... | Print a single integer β the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the da... | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"in... | 1,605,011,415 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 187 | 0 | n,c=map(int,input().split())
x=list(map(int,input().split()))
e=0
for i in range(n-1):
e=max(e,x[i]-x[i+1]-c)
print(e) | Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1... | ```python
n,c=map(int,input().split())
x=list(map(int,input().split()))
e=0
for i in range(n-1):
e=max(e,x[i]-x[i+1]-c)
print(e)
``` | 3 | |
103 | A | Testing Pants for Sadness | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | A. Testing Pants for Sadness | 2 | 256 | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 t... | The first line contains a positive integer *n* (1<=β€<=*n*<=β€<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=β€<=*a**i*<=β€<=109), the number of answer variants to question *i*. | Print a single number β the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2\n1 1\n",
"2\n2 2\n",
"1\n10\n"
] | [
"2",
"5",
"10"
] | Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the ... | 500 | [
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n2 2",
"output": "5"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n2 4 1",
"output": "10"
},
{
"input": "4\n5 5 3 1",
"output": "22"
},
{
"input": "2\n1000000000 1000000000",
"output": "... | 1,616,750,795 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 0 | try:
t=int(input())
a=[int(i) for i in input().split()]
c=0
j=[]
for i in range(t):
c=(a[i]-1)*(i+1)+1
j.append(c)
print(sum(j))
except:
pass | Title: Testing Pants for Sadness
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* q... | ```python
try:
t=int(input())
a=[int(i) for i in input().split()]
c=0
j=[]
for i in range(t):
c=(a[i]-1)*(i+1)+1
j.append(c)
print(sum(j))
except:
pass
``` | 3.969 |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | The first input line contains a single integer *n* (1<=β€<=*n*<=β€<=100) β the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=β€<=*p**i*<=β€<=100) β the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ... | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39... | 1,685,737,550 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n=int(input())
x=input()
num=x.split(" ")
sum=0
for m in num:
sum+=int(m)
print(sum/n) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
n=int(input())
x=input()
num=x.split(" ")
sum=0
for m in num:
sum+=int(m)
print(sum/n)
``` | 3 | |
415 | B | Mashmokh and Tokens | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"implementation",
"math"
] | null | null | Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest o... | The first line of input contains three space-separated integers *n*,<=*a*,<=*b*Β (1<=β€<=*n*<=β€<=105;Β 1<=β€<=*a*,<=*b*<=β€<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n*Β (1<=β€<=*x**i*<=β€<=109). | Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day. | [
"5 1 4\n12 6 11 9 1\n",
"3 1 2\n1 2 3\n",
"1 1 1\n1\n"
] | [
"0 2 3 1 1 ",
"1 0 1 ",
"0 "
] | none | 1,000 | [
{
"input": "5 1 4\n12 6 11 9 1",
"output": "0 2 3 1 1 "
},
{
"input": "3 1 2\n1 2 3",
"output": "1 0 1 "
},
{
"input": "1 1 1\n1",
"output": "0 "
},
{
"input": "1 1 1000000000\n1000000000",
"output": "0 "
},
{
"input": "1 1 1000000000\n999999999",
"output": "9... | 1,585,900,613 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 326 | 12,800,000 | import math
n,a,b=map(int,input().split())
arr = list(map(int,input().split()))
for i in range(n):
x=(math.floor(arr[i]*a/b))
arr[i]-=(math.ceil(x*b/a))
print(*arr) | Title: Mashmokh and Tokens
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each... | ```python
import math
n,a,b=map(int,input().split())
arr = list(map(int,input().split()))
for i in range(n):
x=(math.floor(arr[i]*a/b))
arr[i]-=(math.ceil(x*b/a))
print(*arr)
``` | 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,628,843,897 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 6,758,400 | line1 = input()
line2 = input()
output = []
for i in range(0,len(line1)):
if line1[i] == line2[i]:
output.append(0)
else:
output.append(1)
print(int(output[i]),end = "")
| 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
line1 = input()
line2 = input()
output = []
for i in range(0,len(line1)):
if line1[i] == line2[i]:
output.append(0)
else:
output.append(1)
print(int(output[i]),end = "")
``` | 3.968161 |
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,634,821,185 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 4,300,800 | height, width = map(int, input().split())
print(int ((height * width) / 2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=Γ<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
height, width = map(int, input().split())
print(int ((height * width) / 2))
``` | 3.968989 |
999 | C | Alphabetic Removals | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next ite... | The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) β the length of the string and the number of letters Polycarp will remove.
The second line contains the string $s$ consisting of $n$ lowercase Latin letters. | Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times.
If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). | [
"15 3\ncccaabababaccbc\n",
"15 9\ncccaabababaccbc\n",
"1 1\nu\n"
] | [
"cccbbabaccbc\n",
"cccccc\n",
""
] | none | 0 | [
{
"input": "15 3\ncccaabababaccbc",
"output": "cccbbabaccbc"
},
{
"input": "15 9\ncccaabababaccbc",
"output": "cccccc"
},
{
"input": "5 2\nzyzyx",
"output": "zzy"
},
{
"input": "4 3\nhack",
"output": "k"
},
{
"input": "4 3\nzzzz",
"output": "z"
},
{
"i... | 1,686,331,453 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 77 | 6,860,800 | n,k=map(int,input().split())
s=input()
for j in range(ord('a'), ord('z') + 1):
i=len(s)
s=s.replace(chr(j), "",k)
j=len(s)
k-=(i-j)
if k==0:
break
print(s) | Title: Alphabetic Removals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is... | ```python
n,k=map(int,input().split())
s=input()
for j in range(ord('a'), ord('z') + 1):
i=len(s)
s=s.replace(chr(j), "",k)
j=len(s)
k-=(i-j)
if k==0:
break
print(s)
``` | 3 | |
339 | B | Xenia and Ringroad | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recently moved into the ringroad house number 1. As a result, she's got *m* things to do. In order to complete... | The first line contains two integers *n* and *m* (2<=β€<=*n*<=β€<=105,<=1<=β€<=*m*<=β€<=105). The second line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=β€<=*a**i*<=β€<=*n*). Note that Xenia can have multiple consecutive tasks in one house. | Print a single integer β the time Xenia needs to complete all tasks.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n3 2 3\n",
"4 3\n2 3 3\n"
] | [
"6\n",
"2\n"
] | In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1βββ2βββ3βββ4βββ1βββ2βββ3. This is optimal sequence. So, she needs 6 time units. | 1,000 | [
{
"input": "4 3\n3 2 3",
"output": "6"
},
{
"input": "4 3\n2 3 3",
"output": "2"
},
{
"input": "2 2\n1 1",
"output": "0"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "100 100\n56 46 1 47 5 86 45 35 81 1 ... | 1,699,620,678 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 154 | 12,185,600 | n,m = map(int, input().split(" "))
x=0
work = [int(x) for x in input().split()[:m]]
pos=1
for i in range(len(work)):
if(pos>work[i]):
x+=(n-(pos-work[i]))
pos=work[i]
else:
x+=((work[i]-pos))
pos=work[i]
print(x) | Title: Xenia and Ringroad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recent... | ```python
n,m = map(int, input().split(" "))
x=0
work = [int(x) for x in input().split()[:m]]
pos=1
for i in range(len(work)):
if(pos>work[i]):
x+=(n-(pos-work[i]))
pos=work[i]
else:
x+=((work[i]-pos))
pos=work[i]
print(x)
``` | 3 | |
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,449,389 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 184 | 0 | def is_prime(n):
return n > 1 and all(n % i != 0 for i in range(2, int(n**0.5)+1))
n, m = map(int, input().split())
next_prime = n + 1
while not is_prime(next_prime):
next_prime += 1
print("YES" if next_prime == m else "NO") | 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 is_prime(n):
return n > 1 and all(n % i != 0 for i in range(2, int(n**0.5)+1))
n, m = map(int, input().split())
next_prime = n + 1
while not is_prime(next_prime):
next_prime += 1
print("YES" if next_prime == m else "NO")
``` | 3.954 |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy β she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100) β the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number β the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,648,745,376 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | n = int(input())
mySet = set(())
for i in range(n):
s = input()
mySet.add(s)
print(len(mySet)) | Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy β she doesn't take a leaf if it matches the color and the specie... | ```python
n = int(input())
mySet = set(())
for i in range(n):
s = input()
mySet.add(s)
print(len(mySet))
``` | 3.977 |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=β€<=*n*<=β€<=105;Β 1<=β€<=*d*<=β€<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 β the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer β the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,597,716,831 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 466 | 10,444,800 | import sys
input = sys.stdin.readline
def inInt():
return int(input())
def inStr():
return input().strip("\n")
def inIList():
return(list(map(int,input().split())))
def inSList():
return(input().split())
def solve(case, d):
ans = 0
j = 0
for i in range(len(case)):
whi... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
import sys
input = sys.stdin.readline
def inInt():
return int(input())
def inStr():
return input().strip("\n")
def inIList():
return(list(map(int,input().split())))
def inSList():
return(input().split())
def solve(case, d):
ans = 0
j = 0
for i in range(len(case)):
... | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,692,594,764 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | stroka = input()
counter1=0
counter2=0
for char in stroka:
if char.isupper():
counter1+=1
else:
counter2+=1
if counter2>counter1 or counter1==counter2:
stroka = stroka.lower()
elif counter1>counter2:
stroka=stroka.upper()
print(stroka) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
stroka = input()
counter1=0
counter2=0
for char in stroka:
if char.isupper():
counter1+=1
else:
counter2+=1
if counter2>counter1 or counter1==counter2:
stroka = stroka.lower()
elif counter1>counter2:
stroka=stroka.upper()
print(stroka)
``` | 3.969 |
462 | A | Appleman and Easy Task | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=Γ<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. | Print "YES" or "NO" (without the quotes) depending on the answer to the problem. | [
"3\nxxo\nxox\noxx\n",
"4\nxxxo\nxoxo\noxox\nxxxx\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3\nxxo\nxox\noxx",
"output": "YES"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx",
"output": "NO"
},
{
"input": "1\no",
"output": "YES"
},
{
"input": "2\nox\nxo",
"output": "YES"
},
{
"input": "2\nxx\nxo",
"output": "NO"
},
{
"input": "3\nooo\no... | 1,638,421,897 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 61 | 0 | def solve(n, arr):
for i in range(n):
for j in range(n):
cnt = 0
for x, y in [(-1, 0), (0, 1), (1, 0), (0, -1)]:
ni, nj = x + i, y + j
if ni >= 0 and ni < n and nj >= 0 and nj < n:
if arr[ni][nj] == "o":
... | Title: Appleman and Easy Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=Γ<=*n* checkerboard. Each cell of the board has either character 'x', or... | ```python
def solve(n, arr):
for i in range(n):
for j in range(n):
cnt = 0
for x, y in [(-1, 0), (0, 1), (1, 0), (0, -1)]:
ni, nj = x + i, y + j
if ni >= 0 and ni < n and nj >= 0 and nj < n:
if arr[ni][nj] == "o":
... | 3 | |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters β The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,411,963,199 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 156 | 0 | s = input()
a = []
for i in range(10):
a.append(input())
p = 0
while(p < 80):
for i in range(10):
if a[i] == s[p:p+10]:
print(i, end='')
p += 10
break
| Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
s = input()
a = []
for i in range(10):
a.append(input())
p = 0
while(p < 80):
for i in range(10):
if a[i] == s[p:p+10]:
print(i, end='')
p += 10
break
``` | 3.961 |
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to in... | The first line contains a single string *s*Β (1<=β€<=|*s*|<=β€<=103).
The second line contains a single integer *k*Β (0<=β€<=*k*<=β€<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer β the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value*β=β1Β·1β+β2Β·2β+β3Β·2β+β4Β·2β+β5Β·2β+β6Β·2β=β41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetyw... | 1,621,844,619 | 2,147,483,647 | PyPy 3 | OK | TESTS | 24 | 109 | 0 | s = input()
k = int(input())
w = list(map(int, input().split()))
n = len(s)
dlt = ord('a')
ans = 0
for i in range(n):
#print((i + 1) * w[ord(s[i]) - dlt])
ans += (i + 1) * w[ord(s[i]) - dlt]
m = max(w)
for i in range(n + 1, n + k + 1):
#print(m * i)
ans += m * i
print(ans)
| Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str... | ```python
s = input()
k = int(input())
w = list(map(int, input().split()))
n = len(s)
dlt = ord('a')
ans = 0
for i in range(n):
#print((i + 1) * w[ord(s[i]) - dlt])
ans += (i + 1) * w[ord(s[i]) - dlt]
m = max(w)
for i in range(n + 1, n + k + 1):
#print(m * i)
ans += m * i
print(ans)
`... | 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,500,491,733 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 77 | 4,608,000 | s=input()
l=s.split()
n=int(l[0])
k=int(l[1])
a=n//2
p1=a//(k+1)
p2=k*p1
p3=n-p2-p1
if p3>=n/2 :
print(int(p1),int(p2),int(p3))
else :
print(0,0,n) | 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
s=input()
l=s.split()
n=int(l[0])
k=int(l[1])
a=n//2
p1=a//(k+1)
p2=k*p1
p3=n-p2-p1
if p3>=n/2 :
print(int(p1),int(p2),int(p3))
else :
print(0,0,n)
``` | 3 | |
919 | B | Perfect Number | PROGRAMMING | 1,100 | [
"binary search",
"brute force",
"dp",
"implementation",
"number theory"
] | null | null | We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. | A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). | A single number, denoting the $k$-th smallest perfect integer. | [
"1\n",
"2\n"
] | [
"19\n",
"28\n"
] | The first perfect integer is $19$ and the second one is $28$. | 750 | [
{
"input": "1",
"output": "19"
},
{
"input": "2",
"output": "28"
},
{
"input": "13",
"output": "136"
},
{
"input": "101",
"output": "1432"
},
{
"input": "1023",
"output": "100270"
},
{
"input": "9999",
"output": "10800010"
},
{
"input": "10... | 1,694,594,253 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 1,606 | 0 | k=int(input())
a=10
while k!=0:
a+=9
s=sum(list(map(int,str(a))))
# print(s)
if s==10:
k=k-1
print(a) | Title: Perfect Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
Input Specification:
A singl... | ```python
k=int(input())
a=10
while k!=0:
a+=9
s=sum(list(map(int,str(a))))
# print(s)
if s==10:
k=k-1
print(a)
``` | 3 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,695,062,353 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | n = input()
k = n[0].upper()
print(k+n[1:]) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
n = input()
k = n[0].upper()
print(k+n[1:])
``` | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,475,694,466 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | n = int(input())
arr = sum(list(map(int,input().split())))
cnt=0
for i in range(1,6):
if ((arr+i)%(n+1) )!=1:
cnt+=1
print(cnt)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n = int(input())
arr = sum(list(map(int,input().split())))
cnt=0
for i in range(1,6):
if ((arr+i)%(n+1) )!=1:
cnt+=1
print(cnt)
``` | 3 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=β€<=*r*,<=*g*,<=*b*<=β€<=109) β the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,560,863,478 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 248 | 0 | r,g,b = map(int, input().split(" "))
res = 0
res += r//3
res += g//3
res += b//3
if r > 0 and b > 0 and g > 0:
r -= 1
g -= 1
b -= 1
res = max(res,r//3+b//3+g//3+1)
if r > 0 and b > 0 and g > 0:
r -= 1
g -= 1
b -= 1
res = max(res, r//3+b//3+g//3+2)
print(res) | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
r,g,b = map(int, input().split(" "))
res = 0
res += r//3
res += g//3
res += b//3
if r > 0 and b > 0 and g > 0:
r -= 1
g -= 1
b -= 1
res = max(res,r//3+b//3+g//3+1)
if r > 0 and b > 0 and g > 0:
r -= 1
g -= 1
b -= 1
res = max(res, r//3+b//3+g//3+2)
print(res)
``` | 3 | |
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul... | The only line of input contains two integers *n* and *m*, separated by a single space (1<=β€<=*m*<=β€<=*n*<=β€<=109) β the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* β the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
... | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": ... | 1,648,578,853 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 61 | 0 | n,m = map(int,input().split())
temp = n-(m-1)
kmax = (temp*(temp-1))//2
a = n//m
temp1 = m*(a*(a-1))//2 + a*(n%m)
print(temp1,kmax) | Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is ... | ```python
n,m = map(int,input().split())
temp = n-(m-1)
kmax = (temp*(temp-1))//2
a = n//m
temp1 = m*(a*(a-1))//2 + a*(n%m)
print(temp1,kmax)
``` | 3 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=Γ<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=β€<=*n*<=β€<=10) β the number of rows and columns of the table. | Print a single line containing a positive integer *m* β the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,688,803,721 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | n = int(input())
s = []
x = [[0] * n for _ in range(n)]
for i in range(n):
x[i][0] = 1
x[0][i] = 1
for i in range(1, n):
for j in range(1, n):
x[i][j] = x[i - 1][j] + x[i][j - 1]
for row in x:
s.append(max(row))
m = max(s)
print(m) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=Γ<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
n = int(input())
s = []
x = [[0] * n for _ in range(n)]
for i in range(n):
x[i][0] = 1
x[0][i] = 1
for i in range(1, n):
for j in range(1, n):
x[i][j] = x[i - 1][j] + x[i][j - 1]
for row in x:
s.append(max(row))
m = max(s)
print(m)
``` | 3 | |
468 | A | 24 Game | PROGRAMMING | 1,500 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them, let's denote them *a* and *b*, erase them from the sequence, and append to the sequence eit... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=105). | If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes).
If there is a way to obtain 24 as the result number, in the following *n*<=-<=1 lines print the required operations an operation per line. Each operation should be in form: "*a* *op* *b* = *c*". Where *a* and *b* are the numbe... | [
"1\n",
"8\n"
] | [
"NO\n",
"YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24\n"
] | none | 500 | [
{
"input": "1",
"output": "NO"
},
{
"input": "8",
"output": "YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24"
},
{
"input": "12",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 =... | 1,626,961,482 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 249 | 26,828,800 | n=int(input())
if n>=4:
print("YES")
if n==4:
print("4 * 3 = 12")
print("12 * 2 = 24")
print("24 * 1 = 24")
elif n==5:
print("5 * 4 = 20")
print("20 + 3 = 23")
print("23 + 2 = 25")
print("25 - 1 = 24")
else:
print("4 * 3 = 12")... | Title: 24 Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them... | ```python
n=int(input())
if n>=4:
print("YES")
if n==4:
print("4 * 3 = 12")
print("12 * 2 = 24")
print("24 * 1 = 24")
elif n==5:
print("5 * 4 = 20")
print("20 + 3 = 23")
print("23 + 2 = 25")
print("25 - 1 = 24")
else:
print("4 ... | 3 | |
897 | B | Chtholly's request | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | β I experienced so many great things.
β You gave me memories like dreams... But I have to leave now...
β One last request, can you...
β Help me solve a Codeforces problem?
β ......
β What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation with... | The first line contains two integers *k* and *p* (1<=β€<=*k*<=β€<=105,<=1<=β€<=*p*<=β€<=109). | Output single integerΒ β answer to the problem. | [
"2 100\n",
"5 30\n"
] | [
"33\n",
"15\n"
] | In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,000 | [
{
"input": "2 100",
"output": "33"
},
{
"input": "5 30",
"output": "15"
},
{
"input": "42147 412393322",
"output": "251637727"
},
{
"input": "77809 868097296",
"output": "440411873"
},
{
"input": "5105 443422097",
"output": "363192634"
},
{
"input": "7... | 1,645,098,773 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 93 | 2,150,400 | a, k = map(int, input().split())
sm = 0
for i in range(1, a + 1):
r = str(i)
sm += int(r + r[::-1])
sm %= k
print(sm % k) | Title: Chtholly's request
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
β I experienced so many great things.
β You gave me memories like dreams... But I have to leave now...
β One last request, can you...
β Help me solve a Codeforces problem?
β ......
β What?
Chtholly has been thi... | ```python
a, k = map(int, input().split())
sm = 0
for i in range(1, a + 1):
r = str(i)
sm += int(r + r[::-1])
sm %= k
print(sm % k)
``` | 3 | |
46 | A | Ball Game | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | A. Ball Game | 2 | 256 | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is... | The first line contains integer *n* (2<=β€<=*n*<=β€<=100) which indicates the number of kids in the circle. | In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. | [
"10\n",
"3\n"
] | [
"2 4 7 1 6 2 9 7 6\n",
"2 1\n"
] | none | 0 | [
{
"input": "10",
"output": "2 4 7 1 6 2 9 7 6"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "4",
"output": "2 4 3"
},
{
"input": "5",
"output": "2 4 2 1"
},
{
"input": "6",
"output": "2 4 1 5 4"
},
{
"input": "7",
"output": "2 4 7 4 2 1"
},
... | 1,670,394,381 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 92 | 0 | aruncari = int(input(''))
def nr_ce_primesc_mingea(aruncari):
numar = 1
for i in range(1, aruncari):
numar = numar + i
if numar > aruncari:
numar = numar - aruncari
print(numar, end=' ')
nr_ce_primesc_mingea(aruncari) | Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think... | ```python
aruncari = int(input(''))
def nr_ce_primesc_mingea(aruncari):
numar = 1
for i in range(1, aruncari):
numar = numar + i
if numar > aruncari:
numar = numar - aruncari
print(numar, end=' ')
nr_ce_primesc_mingea(aruncari)
``` | 3.977 |
498 | A | Crazy Town | PROGRAMMING | 1,700 | [
"geometry"
] | null | null | Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We ... | The first line contains two space-separated integers *x*1, *y*1 (<=-<=106<=β€<=*x*1,<=*y*1<=β€<=106) β the coordinates of your home.
The second line contains two integers separated by a space *x*2, *y*2 (<=-<=106<=β€<=*x*2,<=*y*2<=β€<=106) β the coordinates of the university you are studying at.
The third line contains a... | Output the answer to the problem. | [
"1 1\n-1 -1\n2\n0 1 0\n1 0 0\n",
"1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3\n"
] | [
"2\n",
"2\n"
] | Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors): | 500 | [
{
"input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0",
"output": "2"
},
{
"input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3",
"output": "2"
},
{
"input": "841746 527518\n595261 331297\n10\n-946901 129987 670374\n-140388 -684770 309555\n-302589 415564 -387435\n-565799 -72069 -395358\n-523453 -511446 85489... | 1,556,901,076 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 109 | 0 | x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
a1=y1-y2
b1=x2-x1
c1=x2*(y2-y1)-y2*(x2-x1)
def intersect(a2,b2,c2):
global a1,b1,c1,x1,y1,x2,y2
if(a1*b2==a2*b1):
return False
x=(b1*c2-b2*c1)/(a1*b2-b1*a2)
y=(a1*c2-c1*a2)/(b1*a2-a1*b2)
... | Title: Crazy Town
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the pl... | ```python
x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
a1=y1-y2
b1=x2-x1
c1=x2*(y2-y1)-y2*(x2-x1)
def intersect(a2,b2,c2):
global a1,b1,c1,x1,y1,x2,y2
if(a1*b2==a2*b1):
return False
x=(b1*c2-b2*c1)/(a1*b2-b1*a2)
y=(a1*c2-c1*a2)/(b1*a2-a1*b... | 3 | |
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,590,842,682 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 140 | 0 | s=""
for i in range(1,1000):
f=str(i)
s=s+f
n=int(input())
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
s=""
for i in range(1,1000):
f=str(i)
s=s+f
n=int(input())
print(s[n-1])
``` | 3 | |
369 | A | Valera and Plates | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can... | The first line of the input contains three integers *n*, *m*, *k* (1<=β€<=*n*,<=*m*,<=*k*<=β€<=1000)Β β the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=2). If *a**i* equals one, then on day *i* Val... | Print a single integer β the minimum number of times Valera will need to wash a plate/bowl. | [
"3 1 1\n1 2 1\n",
"4 3 1\n1 1 1 1\n",
"3 1 2\n2 2 2\n",
"8 2 2\n1 2 1 2 1 2 1 2\n"
] | [
"1\n",
"1\n",
"0\n",
"4\n"
] | In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all... | 500 | [
{
"input": "3 1 1\n1 2 1",
"output": "1"
},
{
"input": "4 3 1\n1 1 1 1",
"output": "1"
},
{
"input": "3 1 2\n2 2 2",
"output": "0"
},
{
"input": "8 2 2\n1 2 1 2 1 2 1 2",
"output": "4"
},
{
"input": "2 100 100\n2 2",
"output": "0"
},
{
"input": "1 1 1\... | 1,620,705,832 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 108 | 20,172,800 | n, m, k = map(int, input().split())
daf = list(map(int, input().split()))
c = 0
total = 0
while (m>0 or k>0) and c < n:
f = daf[c]
if f == 1:
if m > 0:
m -= 1
else:
total += 1
else:
if k > 0:
k -= 1
elif m > 0:
... | Title: Valera and Plates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, ... | ```python
n, m, k = map(int, input().split())
daf = list(map(int, input().split()))
c = 0
total = 0
while (m>0 or k>0) and c < n:
f = daf[c]
if f == 1:
if m > 0:
m -= 1
else:
total += 1
else:
if k > 0:
k -= 1
elif m > 0:
... | 3 | |
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=Γ<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=100)Β β the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W'Β β to white square in the row that Adaltik drew). | The first line should contain a single integer *k*Β β the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
... | 1,618,969,100 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 62 | 0 | n = int(input())
row = input()
row_arr = row.split("W")
row_arr = [i for i in row_arr if i != '']
print(len(row_arr))
#print(row_arr) # debugging
for i in row_arr:
print(len(i),end=" ")
| Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=Γ<=*b* squares, and each square is colored white or black. There are integers to the... | ```python
n = int(input())
row = input()
row_arr = row.split("W")
row_arr = [i for i in row_arr if i != '']
print(len(row_arr))
#print(row_arr) # debugging
for i in row_arr:
print(len(i),end=" ")
``` | 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,614,517,340 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | m, n = map(int, input().split())
if ((int(m) * int(n)) % 2) == 0:
y = ((int(m) * int(n) * 0.5))
print(int(y))
elif((int(m) * int(n)) % 2) == 1:
y = (((int(m) * int(n)) - 1) * 0.5)
print(int(y))
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=Γ<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m, n = map(int, input().split())
if ((int(m) * int(n)) % 2) == 0:
y = ((int(m) * int(n) * 0.5))
print(int(y))
elif((int(m) * int(n)) % 2) == 1:
y = (((int(m) * int(n)) - 1) * 0.5)
print(int(y))
``` | 3.969 |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=β€<=*s*1,<=*s*2,<=*s*3,<=*s*4<=β€<=109) β the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer β the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,698,323,129 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 122 | 0 | shoes = list(input().split())
shoes = list(map(int, shoes))
colours = []
count = 0
for i in range(len(shoes)):
if shoes[i] in colours:
count += 1
else:
colours.append(shoes[i])
print(count)
| Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
shoes = list(input().split())
shoes = list(map(int, shoes))
colours = []
count = 0
for i in range(len(shoes)):
if shoes[i] in colours:
count += 1
else:
colours.append(shoes[i])
print(count)
``` | 3 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=β€<=*n*<=β€<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integerΒ β the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,607,593,338 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 109 | 0 | t = list(input())
q_inds = [i for i, x in enumerate(t) if x == "Q"]
a_inds = [i for i, x in enumerate(t) if x == "A"]
ans = 0
for i, qi in enumerate(q_inds):
for ai in a_inds:
if qi < ai:
for qi_2 in q_inds[i+1:]:
if ai < qi_2:
ans += 1
print(ans) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
t = list(input())
q_inds = [i for i, x in enumerate(t) if x == "Q"]
a_inds = [i for i, x in enumerate(t) if x == "A"]
ans = 0
for i, qi in enumerate(q_inds):
for ai in a_inds:
if qi < ai:
for qi_2 in q_inds[i+1:]:
if ai < qi_2:
ans += 1
print(ans)
... | 3 | |
534 | A | Exam | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other... | A single line contains integer *n* (1<=β€<=*n*<=β€<=5000) β the number of students at an exam. | In the first line print integer *k* β the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.
In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=β€<=*a**i*<=β€<=*n*), where *a**i* is the number of the student on the *i*-th position... | [
"6",
"3\n"
] | [
"6\n1 5 3 6 2 4",
"2\n1 3"
] | none | 500 | [
{
"input": "6",
"output": "6\n5 3 1 6 4 2 "
},
{
"input": "3",
"output": "2\n1 3"
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "4",
"output": "4\n3 1 4 2 "
},
{
"input": "5",
"output": "5\n5 3 1 4 2 "
},
... | 1,617,611,086 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 204,800 | def odd(lst,n):
for i in range(1,n+1,2):
lst.append(i)
def even(lst,n):
start=2
if len(lst)==1 or n==3:
start=4
for j in range(start,n+1,2):
lst.append(j)
n=int(input())
lst=[]
if n%2==0 and n>2:
even(lst, n)
odd(lst, n)
... | Title: Exam
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and bec... | ```python
def odd(lst,n):
for i in range(1,n+1,2):
lst.append(i)
def even(lst,n):
start=2
if len(lst)==1 or n==3:
start=4
for j in range(start,n+1,2):
lst.append(j)
n=int(input())
lst=[]
if n%2==0 and n>2:
even(lst, n)
odd(ls... | 3 | |
409 | D | Big Data | PROGRAMMING | 1,700 | [
"*special"
] | null | null | Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts:
- ... | The input will contain a single integer between 1 and 16. | Output a single integer. | [
"1\n",
"7\n"
] | [
"1\n",
"0\n"
] | none | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "0"
},
{
"input": "13",
"output": "1"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "16",
"output": "0"
},
{
"input": "11",
"output": "0"
},
... | 1,643,029,745 | 2,147,483,647 | PyPy 3 | OK | TESTS | 16 | 77 | 0 | s="01001010111001010"
print(s[int(input())]) | Title: Big Data
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift ... | ```python
s="01001010111001010"
print(s[int(input())])
``` | 3 | |
408 | A | Line to Cashier | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=β€<=*k**i*<=β€<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i*... | Print a single integer β the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100Β·5β+β15β=β515 seconds. But if he chooses the second queue, he will need 1Β·5β+β2Β·5β+β2Β·5β+β3Β·5β+β4Β·15β=β100 seconds. He will need 1Β·5β+β9Β·5β+β1Β·5β+β3Β·15β=β100 seconds for the third one and 7Β·5β+β8Β·5β+β2Β·15β=β105 seconds for the fou... | 500 | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"... | 1,563,261,273 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 140 | 1,536,000 | class CodeforcesTask408ASolution:
def __init__(self):
self.result = ''
self.cash_count = 0
self.client_cashwise = []
self.baskets = []
def read_input(self):
self.cash_count = int(input())
self.client_cashwise = [int(x) for x in input().split(" ")]
... | Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* c... | ```python
class CodeforcesTask408ASolution:
def __init__(self):
self.result = ''
self.cash_count = 0
self.client_cashwise = []
self.baskets = []
def read_input(self):
self.cash_count = int(input())
self.client_cashwise = [int(x) for x in input().split(" ... | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,647,143,270 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | """
sumOfFinger=sum(fingerShownByFriends)
Dima can show 1 to 5 fingers..
so
k = [sumOfFingers+i for i in range(1,6)]
now we've to check if k[i] prsenet in arithmetic progression whose firstVal=1 and diff=numOfFriens+1
if k[i] is present==
=>>then it means if Dima shows i+1 fingers then..
=>>then counting w... | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
"""
sumOfFinger=sum(fingerShownByFriends)
Dima can show 1 to 5 fingers..
so
k = [sumOfFingers+i for i in range(1,6)]
now we've to check if k[i] prsenet in arithmetic progression whose firstVal=1 and diff=numOfFriens+1
if k[i] is present==
=>>then it means if Dima shows i+1 fingers then..
=>>then ... | 3 | |
701 | B | Cells Not Under Attack | PROGRAMMING | 1,200 | [
"data structures",
"math"
] | null | null | Vasya has the square chessboard of size *n*<=Γ<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there ... | The first line of the input contains two integers *n* and *m* (1<=β€<=*n*<=β€<=100<=000, 1<=β€<=*m*<=β€<=*min*(100<=000,<=*n*2))Β β the size of the board and the number of rooks.
Each of the next *m* lines contains integers *x**i* and *y**i* (1<=β€<=*x**i*,<=*y**i*<=β€<=*n*)Β β the number of the row and the number of the col... | Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put. | [
"3 3\n1 1\n3 1\n2 2\n",
"5 2\n1 5\n5 1\n",
"100000 1\n300 400\n"
] | [
"4 2 0 \n",
"16 9 \n",
"9999800001 \n"
] | On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack. | 750 | [
{
"input": "3 3\n1 1\n3 1\n2 2",
"output": "4 2 0 "
},
{
"input": "5 2\n1 5\n5 1",
"output": "16 9 "
},
{
"input": "100000 1\n300 400",
"output": "9999800001 "
},
{
"input": "10 4\n2 8\n1 8\n9 8\n6 9",
"output": "81 72 63 48 "
},
{
"input": "30 30\n3 13\n27 23\n18... | 1,626,838,620 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 405 | 15,052,800 | import sys
input = lambda:sys.stdin.readline()
int_arr = lambda: list(map(int,input().split()))
str_arr = lambda: list(map(str,input().split()))
get_str = lambda: map(str,input().split())
get_int = lambda: map(int,input().split())
get_flo = lambda: map(float,input().split())
mod = 1000000007
# def solve()... | Title: Cells Not Under Attack
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has the square chessboard of size *n*<=Γ<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's a... | ```python
import sys
input = lambda:sys.stdin.readline()
int_arr = lambda: list(map(int,input().split()))
str_arr = lambda: list(map(str,input().split()))
get_str = lambda: map(str,input().split())
get_int = lambda: map(int,input().split())
get_flo = lambda: map(float,input().split())
mod = 1000000007
# d... | 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,481,130,423 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 4,608,000 | n=int(input())
m=input().split()
jishu=0
oushu=0
for i in range(3):
k=int(m[i])/2-int(m[i])//2
if k==0:
oushu+=1
else:
jishu+=1
if jishu>oushu:
for i in range(n):
kt=int(m[i])/2-int(m[i])//2
if kt==0:
print(i+1)
break
else:
for... | 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())
m=input().split()
jishu=0
oushu=0
for i in range(3):
k=int(m[i])/2-int(m[i])//2
if k==0:
oushu+=1
else:
jishu+=1
if jishu>oushu:
for i in range(n):
kt=int(m[i])/2-int(m[i])//2
if kt==0:
print(i+1)
break
else... | 3.960417 |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=β€<=*l*<=β€<=*r*<=β€<=1018; *r*<=-<=*l*<=β€<=50). | Print three positive space-separated integers *a*, *b*, *c*Β β three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2,β4) is not coprime and pairs (2,β3) and (3,β4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,589,206,044 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 109 | 6,656,000 | l,r = map(int,input().split())
range = r - l + 1
if (range < 3) or (l % 2 == 1 and range < 4):
print(-1)
else:
if (l % 2 == 0):
print(l,l+1,l+2)
else:
print(l+1,l+2,l+3) | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
l,r = map(int,input().split())
range = r - l + 1
if (range < 3) or (l % 2 == 1 and range < 4):
print(-1)
else:
if (l % 2 == 0):
print(l,l+1,l+2)
else:
print(l+1,l+2,l+3)
``` | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.