contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,564,740,573 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 14 | 108 | 512,000 | if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().rstrip().split()))
sorted = sorted(arr, reverse=True)
pos = [0 for i in range(n+1)]
cnt = 0
for i,e in enumerate(sorted):
if i == 0:
pos[e] = i
continue
if e != sorted[i - 1]... | Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().rstrip().split()))
sorted = sorted(arr, reverse=True)
pos = [0 for i in range(n+1)]
cnt = 0
for i,e in enumerate(sorted):
if i == 0:
pos[e] = i
continue
if e != sor... | -1 | |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,646,605,045 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | def printO(output):
for i in range (0,len(output)):
print(output[i] , end="")
eggs = input("Enter the amount of eggs : ")
eggs = int(eggs)
ans= "ROYGBIV";
while(eggs >= 7 & eggs <= 100):
for i in range(eggs - 7):
ans += ans[i - 4]
printO(ans)
break
| Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
def printO(output):
for i in range (0,len(output)):
print(output[i] , end="")
eggs = input("Enter the amount of eggs : ")
eggs = int(eggs)
ans= "ROYGBIV";
while(eggs >= 7 & eggs <= 100):
for i in range(eggs - 7):
ans += ans[i - 4]
printO(ans)
break
``` | 0 |
43 | B | Letter | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | B. Letter | 2 | 256 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help ... | The first line contains a newspaper heading *s*1. The second line contains the letter text *s*2. *s*1 и *s*2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces o... | If Vasya can write the given anonymous letter, print YES, otherwise print NO | [
"Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n",
"Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n",
"Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n",
"... | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | none | 1,000 | [
{
"input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog",
"output": "NO"
},
{
"input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears",
"output": "YES"
},
{
"input": "Instead of doggi... | 1,593,268,266 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 154 | 6,656,000 | a={}
for c in input():
if c==" ":
continue
if c in a:
a[c]+=1
else:
a[c]=1
ans="YES"
for c in input():
if c in a:
if a[c]==0:
ans="NO"
break
else:
a[c]-=1
else:
ans="NO"
break
print(ans)
... | Title: Letter
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to... | ```python
a={}
for c in input():
if c==" ":
continue
if c in a:
a[c]+=1
else:
a[c]=1
ans="YES"
for c in input():
if c in a:
if a[c]==0:
ans="NO"
break
else:
a[c]-=1
else:
ans="NO"
break
pri... | 0 |
644 | A | Parliament of Berland | PROGRAMMING | 1,000 | [
"*special",
"constructive algorithms"
] | null | null | There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of *a*<=×<=*b* chairs — *a* rows of *b* chair... | The first line of the input contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=10<=000, 1<=≤<=*a*,<=*b*<=≤<=100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively. | If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in *a* lines, each containing *b* integers. The *j*-th integer of the *i*-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multi... | [
"3 2 2\n",
"8 4 3\n",
"10 2 2\n"
] | [
"0 3\n1 2\n",
"7 8 3\n0 1 4\n6 0 5\n0 2 0\n",
"-1\n"
] | In the first sample there are many other possible solutions. For example,
and
The following assignment
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats. | 500 | [
{
"input": "3 2 2",
"output": "1 2 \n0 3 "
},
{
"input": "8 4 3",
"output": "1 2 3 \n4 5 6 \n7 8 0 \n0 0 0 "
},
{
"input": "10 2 2",
"output": "-1"
},
{
"input": "1 1 1",
"output": "1 "
},
{
"input": "8 3 3",
"output": "1 2 3 \n4 5 6 \n7 8 0 "
},
{
"in... | 1,458,137,201 | 18,401 | Python 3 | WRONG_ANSWER | PRETESTS | 11 | 93 | 614,400 | '__author__'=='deepak Singh Mehta(learning to code)) '
if __name__=='__main__':
n,row,col = map(int,input().split())
if n > row*col:
print(-1)
else:
if col%2!=0:
put = 1
grid = []
#flag = False
for i in range(row):
... | Title: Parliament of Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republi... | ```python
'__author__'=='deepak Singh Mehta(learning to code)) '
if __name__=='__main__':
n,row,col = map(int,input().split())
if n > row*col:
print(-1)
else:
if col%2!=0:
put = 1
grid = []
#flag = False
for i in range(row):
... | 0 | |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,679,228,230 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | s = str(input())
#op=[]
#cl=[]
#for i in s[::2] :
# op.append(i)
#for i in s[1::2]:
# cl.append(i)
l = []
l2 = []
for i in s:
l.append(i)
c=0
if l[-1] == "(":
l.pop()
#
#c=0
#while len(l) >0:
#
#
# c+=2
#
#
#
print(c) | Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
s = str(input())
#op=[]
#cl=[]
#for i in s[::2] :
# op.append(i)
#for i in s[1::2]:
# cl.append(i)
l = []
l2 = []
for i in s:
l.append(i)
c=0
if l[-1] == "(":
l.pop()
#
#c=0
#while len(l) >0:
#
#
# c+=2
#
#
#
print(c)
``` | 0 |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,642,770,520 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | strr = input()
dic = dict(enumerate(strr))
h = [k for k,v in dic.items() if v == 'h']
e = [k for k,v in dic.items() if v == 'e']
i = [k for k,v in dic.items() if v == 'i']
d = [k for k,v in dic.items() if v == 'd']
if h != [] and e != [] and i != [] and d != []:
if h[0] < e[0] < i[0] < d[0] < i[1]:
... | Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
strr = input()
dic = dict(enumerate(strr))
h = [k for k,v in dic.items() if v == 'h']
e = [k for k,v in dic.items() if v == 'e']
i = [k for k,v in dic.items() if v == 'i']
d = [k for k,v in dic.items() if v == 'd']
if h != [] and e != [] and i != [] and d != []:
if h[0] < e[0] < i[0] < d[0] < i[1... | 0 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,656,417,499 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 498 | 17,408,000 | n=int(input())
s=input()
a=s.split(" ")
a=[int(x) for x in a]
m=int(input())
s=input()
b=s.split()
b=[int(x) for x in b]
d1={}
d2={}
for i in range(n):
d1[a[i]]=i+1
d2[a[i]]=n-i
s1=0
s2=0
for i in range(m):
s1+=d1[b[i]]
s2+=d2[b[i]]
print(s1,s2) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n=int(input())
s=input()
a=s.split(" ")
a=[int(x) for x in a]
m=int(input())
s=input()
b=s.split()
b=[int(x) for x in b]
d1={}
d2={}
for i in range(n):
d1[a[i]]=i+1
d2[a[i]]=n-i
s1=0
s2=0
for i in range(m):
s1+=d1[b[i]]
s2+=d2[b[i]]
print(s1,s2)
``` | 3 | |
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divide... | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
... | 1,566,644,140 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 249 | 9,830,400 | v = int(input())
a = list(map(int, input().split()))
a.sort()
# j = a.count(1)
k = a.count(1)
l = a.count(2)
m = a.count(3)
n = a.count(4)
o = a.count(6)
b = []
if (v%3) !=0 :
print(-1)
exit()
# print('hey')
t = min(k,l,n)
b+= [[1,2,4]]*t
k-=t
l-=t
n-=t
z = min(k,l,o)
b+= [[1,2,6]]*z
k-... | Title: Xenia and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,... | ```python
v = int(input())
a = list(map(int, input().split()))
a.sort()
# j = a.count(1)
k = a.count(1)
l = a.count(2)
m = a.count(3)
n = a.count(4)
o = a.count(6)
b = []
if (v%3) !=0 :
print(-1)
exit()
# print('hey')
t = min(k,l,n)
b+= [[1,2,4]]*t
k-=t
l-=t
n-=t
z = min(k,l,o)
b+= [[1,2... | 3 | |
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos... | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*... | If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
... | 1,697,560,160 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 2,662,400 | def check_square(coordinates):
for i in range(len(coordinates)-1):
x1, y1 = coordinates[i]
x2, y2 = coordinates[i+1]
if (x1+1, y1) in coordinates and (x1, y1+1) in coordinates and (x1+1, y1+1) in coordinates:
return True
if (x2-1, y2) in coordinates and (x2, y2-1) i... | Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ... | ```python
def check_square(coordinates):
for i in range(len(coordinates)-1):
x1, y1 = coordinates[i]
x2, y2 = coordinates[i+1]
if (x1+1, y1) in coordinates and (x1, y1+1) in coordinates and (x1+1, y1+1) in coordinates:
return True
if (x2-1, y2) in coordinates and (x... | 0 | |
740 | A | Alyona and copybooks | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack ... | The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109). | Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4. | [
"1 1 3 4\n",
"6 2 1 1\n",
"4 4 4 4\n",
"999999999 1000000000 1000000000 1000000000\n"
] | [
"3\n",
"1\n",
"0\n",
"1000000000\n"
] | In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.
In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total.
In the third example Alyona ... | 500 | [
{
"input": "1 1 3 4",
"output": "3"
},
{
"input": "6 2 1 1",
"output": "1"
},
{
"input": "4 4 4 4",
"output": "0"
},
{
"input": "999999999 1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "1016 3 2 1",
"output": "0"
},
{
"input":... | 1,584,467,966 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 140 | 0 | n = list(map(int, input().split()))
if(n[0]%4==0):
print(0)
elif(n[0]%4==1):
print(min(3*n[1], n[2]+n[3], n[3]))
elif(n[0]%4==2):
print(min(2*n[1], n[2], 2*n[3]))
else:
print(min(3*n[1], n[1]+n[2], n[3])) | Title: Alyona and copybooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the sh... | ```python
n = list(map(int, input().split()))
if(n[0]%4==0):
print(0)
elif(n[0]%4==1):
print(min(3*n[1], n[2]+n[3], n[3]))
elif(n[0]%4==2):
print(min(2*n[1], n[2], 2*n[3]))
else:
print(min(3*n[1], n[1]+n[2], n[3]))
``` | 0 | |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,697,532,951 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 62 | 0 | import sys
n = int(sys.stdin.readline().split()[0])
X = 0
for i in range(n):
command = sys.stdin.readline().split()[0]
if command[1] == "+": X+=1
elif command[1] == "-": X-=1
print(X) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
import sys
n = int(sys.stdin.readline().split()[0])
X = 0
for i in range(n):
command = sys.stdin.readline().split()[0]
if command[1] == "+": X+=1
elif command[1] == "-": X-=1
print(X)
``` | 3 | |
55 | B | Smallest number | PROGRAMMING | 1,600 | [
"brute force"
] | B. Smallest number | 2 | 256 | Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced... | First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) | Output one integer number — the minimal result which can be obtained.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). | [
"1 1 1 1\n+ + *\n",
"2 2 2 2\n* * +\n",
"1 2 3 4\n* + +\n"
] | [
"3\n",
"8\n",
"9\n"
] | none | 1,000 | [
{
"input": "1 1 1 1\n+ + *",
"output": "3"
},
{
"input": "2 2 2 2\n* * +",
"output": "8"
},
{
"input": "1 2 3 4\n* + +",
"output": "9"
},
{
"input": "15 1 3 1\n* * +",
"output": "18"
},
{
"input": "8 1 7 14\n+ + +",
"output": "30"
},
{
"input": "7 17 3... | 1,546,346,529 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 218 | 0 | s = [int(x) for x in input().split()]
l = input().split()
c = l.count("*")
if c == 1:
s.sort()
print(s[0]*s[1]+s[2]+s[3])
elif c == 2:
s.sort()
print(min(s[0]*s[3]+s[2]*s[1],s[0]*s[1]*s[2]+s[3]))
else:
print(s[0]*s[1]*s[2]*s[3]) | Title: Smallest number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the n... | ```python
s = [int(x) for x in input().split()]
l = input().split()
c = l.count("*")
if c == 1:
s.sort()
print(s[0]*s[1]+s[2]+s[3])
elif c == 2:
s.sort()
print(min(s[0]*s[3]+s[2]*s[1],s[0]*s[1]*s[2]+s[3]))
else:
print(s[0]*s[1]*s[2]*s[3])
``` | 0 |
891 | A | Pride | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"math",
"number theory"
] | null | null | You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).
What is the mi... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=2000) — the number of elements in the array.
The second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. | [
"5\n2 2 3 4 6\n",
"4\n2 4 6 8\n",
"3\n2 6 9\n"
] | [
"5\n",
"-1\n",
"4\n"
] | In the first sample you can turn all numbers to 1 using the following 5 moves:
- [2, 2, 3, 4, 6]. - [2, 1, 3, 4, 6] - [2, 1, 3, 1, 6] - [2, 1, 1, 1, 6] - [1, 1, 1, 1, 6] - [1, 1, 1, 1, 1]
We can prove that in this case it is not possible to make all numbers one using less than 5 moves. | 500 | [
{
"input": "5\n2 2 3 4 6",
"output": "5"
},
{
"input": "4\n2 4 6 8",
"output": "-1"
},
{
"input": "3\n2 6 9",
"output": "4"
},
{
"input": "15\n10 10 10 10 10 10 21 21 21 21 21 21 21 21 21",
"output": "15"
},
{
"input": "12\n10 10 14 14 14 14 14 14 14 14 21 21",
... | 1,545,320,616 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 1,996 | 0 | def gcd(a,b):
if b==0:
return a
else:
return(gcd(b,a%b))
n = int(input())
lst = list()
lst = input().split(' ')
num=0
flag=0
for i in lst:
if int(i)==1:
num+=1
if num!=0:
print(n - num)
exit()
for i in range(1,n):
for j in range(n-i):
lst[j]=gcd(int(lst[j]),int(lst[j+1]))
if i... | Title: Pride
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [great... | ```python
def gcd(a,b):
if b==0:
return a
else:
return(gcd(b,a%b))
n = int(input())
lst = list()
lst = input().split(' ')
num=0
flag=0
for i in lst:
if int(i)==1:
num+=1
if num!=0:
print(n - num)
exit()
for i in range(1,n):
for j in range(n-i):
lst[j]=gcd(int(lst[j]),int(lst[j+1]... | 3 | |
380 | C | Sereja and Brackets | PROGRAMMING | 2,000 | [
"data structures",
"schedules"
] | null | null | Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length o... | The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains ... | Print the answer to each question on a single line. Print the answers in the order they go in the input. | [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n"
] | [
"0\n0\n2\n10\n4\n6\n6\n"
] | A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<s... | 1,500 | [
{
"input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10",
"output": "0\n0\n2\n10\n4\n6\n6"
},
{
"input": "(((((()((((((((((()((()(((((\n1\n8 15",
"output": "0"
},
{
"input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 ... | 1,665,590,702 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 12 | 748 | 268,390,400 |
class node:
def __init__(self) :
self.open = 0
self.close = 0
self.full = 0
def create(seg,arr,ind,low,high):
if low == high:
if arr[low] == '(':
seg[ind].open = 1
elif arr[low] == ')':
seg[ind].close = 1
... | Title: Sereja and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two i... | ```python
class node:
def __init__(self) :
self.open = 0
self.close = 0
self.full = 0
def create(seg,arr,ind,low,high):
if low == high:
if arr[low] == '(':
seg[ind].open = 1
elif arr[low] == ')':
seg[ind].clo... | 0 | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,696,597,994 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 62 | 0 | n = int(input())
if n&1:
print(-(n+1)//2)
else:
print(n//2)
| Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
n = int(input())
if n&1:
print(-(n+1)//2)
else:
print(n//2)
``` | 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,675,851,240 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | q='qwertyuiopasdfghjkl;zxcvbnm,./'
m=input()
n=input()
for i in n:
if m=='R':
print(q[q.index(i)-1],end='')
else:
print(q[q.index(i)+1],end='')
| Title: Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately.... | ```python
q='qwertyuiopasdfghjkl;zxcvbnm,./'
m=input()
n=input()
for i in n:
if m=='R':
print(q[q.index(i)-1],end='')
else:
print(q[q.index(i)+1],end='')
``` | 3 | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,692,045,872 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 2,150,400 | n = int(input())
s = input()
ans = [' '] * n
pos = 0
for i in range(n - 1, -1, -2):
ans[n - pos - 1] = s[i]
ans[pos] = s[i - 1]
pos += 1
if n % 2 != 0:
ans[pos - 1] = s[0]
print(*ans, sep='') | Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
n = int(input())
s = input()
ans = [' '] * n
pos = 0
for i in range(n - 1, -1, -2):
ans[n - pos - 1] = s[i]
ans[pos] = s[i - 1]
pos += 1
if n % 2 != 0:
ans[pos - 1] = s[0]
print(*ans, sep='')
``` | 3 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,570,467,910 | 10 | Python 3 | OK | TESTS | 34 | 248 | 0 | n = int(input())
i = 1
s2 = 0
a = input()
s1 = 1
while i < n:
s = input()
if s != a:
s2 += 1
b = s
else:
s1 += 1
i += 1
if s1 > s2:
print(a)
else:
print(b)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n = int(input())
i = 1
s2 = 0
a = input()
s1 = 1
while i < n:
s = input()
if s != a:
s2 += 1
b = s
else:
s1 += 1
i += 1
if s1 > s2:
print(a)
else:
print(b)
``` | 3.938 |
183 | E | Candy Shop | PROGRAMMING | 2,900 | [
"greedy"
] | null | null | The prestigious Codeforces kindergarten consists of *n* kids, numbered 1 through *n*. Each of them are given allowance in rubles by their parents.
Today, they are going to the most famous candy shop in the town. The shop sells candies in packages: for all *i* between 1 and *m*, inclusive, it sells a package containing... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=5·106,<=*n*<=≤<=*m*), denoting the number of kids and the maximum number of candies in a package sold by the candy shop, respectively.
Then *n* lines follow, each line will contain a single positive integer not exceed... | Print a single integer denoting the maximum number of candies that can be sold by the candy shop. | [
"2 5\n5\n10\n",
"3 8\n8\n16\n13\n",
"2 5000000\n12500002500000\n12500002500000\n"
] | [
"13\n",
"32\n",
"12500002500000\n"
] | For the first example, one of the scenarios that will result in 13 purchased candies is as follows.
- Turn 1. Kid 1 purchases 1 candy. - Turn 2. Kid 2 purchases 3 candies. - Turn 3. Kid 1 purchases 4 candies. - Turn 4. Kid 2 purchases 5 candies. | 2,500 | [] | 1,689,256,646 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1689256645.9313679")# 1689256645.9314098 | Title: Candy Shop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The prestigious Codeforces kindergarten consists of *n* kids, numbered 1 through *n*. Each of them are given allowance in rubles by their parents.
Today, they are going to the most famous candy shop in the town. The shop se... | ```python
print("_RANDOM_GUESS_1689256645.9313679")# 1689256645.9314098
``` | 0 | |
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,567,962,549 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 20,582,400 | input(); a = *reversed(input().split()),
print(a[max(a.index(i) for i in set(a))]) | Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research... | ```python
input(); a = *reversed(input().split()),
print(a[max(a.index(i) for i in set(a))])
``` | 0 | |
978 | A | Remove Duplicates | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. | The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. | In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. | [
"6\n1 5 5 1 6 1\n",
"5\n2 4 2 4 4\n",
"5\n6 6 6 6 6\n"
] | [
"3\n5 6 1 \n",
"2\n2 4 \n",
"1\n6 \n"
] | In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the... | 0 | [
{
"input": "6\n1 5 5 1 6 1",
"output": "3\n5 6 1 "
},
{
"input": "5\n2 4 2 4 4",
"output": "2\n2 4 "
},
{
"input": "5\n6 6 6 6 6",
"output": "1\n6 "
},
{
"input": "7\n1 2 3 4 2 2 3",
"output": "4\n1 4 2 3 "
},
{
"input": "9\n100 100 100 99 99 99 100 100 100",
... | 1,697,153,602 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | x = input()
# get the last insatnce of the number in the list
ans = []
for i in range(len(x)):
if x[i] not in ans:
ans.append(x[i])
else:
continue
print(len(ans))
print(*ans)
| Title: Remove Duplicates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the re... | ```python
x = input()
# get the last insatnce of the number in the list
ans = []
for i in range(len(x)):
if x[i] not in ans:
ans.append(x[i])
else:
continue
print(len(ans))
print(*ans)
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,632,590,491 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 6,656,000 | import math
l=list(map(int,input().split()))
print(int(math.ceil(l[0]*l[1]/2))) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
import math
l=list(map(int,input().split()))
print(int(math.ceil(l[0]*l[1]/2)))
``` | 0 |
159 | D | Palindrome pairs | PROGRAMMING | 1,500 | [
"*special",
"brute force",
"dp",
"strings"
] | null | null | You are given a non-empty string *s* consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string.
In a more formal way, you have to find the quantity of tuples (*a*,<=*b*,<=*x*,<=*y*) such that 1<=≤<=*a*<=≤<=*b*<=<<=*x*<=≤<=*y*<=≤<=|*s*| and substrings *s*[*a*.... | The first line of input contains a non-empty string *s* which consists of lowercase letters ('a'...'z'), *s* contains at most 2000 characters. | Output a single number — the quantity of pairs of non-overlapping palindromic substrings of *s*.
Please do not use the %lld format specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d format specifier. | [
"aa\n",
"aaa\n",
"abacaba\n"
] | [
"1\n",
"5\n",
"36\n"
] | none | 2,000 | [
{
"input": "aa",
"output": "1"
},
{
"input": "aaa",
"output": "5"
},
{
"input": "abacaba",
"output": "36"
},
{
"input": "aaaaaaaaaa",
"output": "495"
},
{
"input": "aabbb",
"output": "24"
},
{
"input": "abbaa",
"output": "18"
},
{
"input": ... | 1,670,166,145 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 186 | 3,891,200 | s = input()
n = len(s)
beg = [0] * n
end = [0] * n
for i in range(n):
for j in range(n):
if i-j < 0 or i+j >= n: break
if s[i-j] != s[i+j]: break
beg[i-j] += 1
end[i+j] += 1
for j in range(n):
if i-j < 0 or i+j+1 >= n: break
if s[i-j] != s[i+j+1]... | Title: Palindrome pairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a non-empty string *s* consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string.
In a more formal way, you have to find the quantity of tuples (*... | ```python
s = input()
n = len(s)
beg = [0] * n
end = [0] * n
for i in range(n):
for j in range(n):
if i-j < 0 or i+j >= n: break
if s[i-j] != s[i+j]: break
beg[i-j] += 1
end[i+j] += 1
for j in range(n):
if i-j < 0 or i+j+1 >= n: break
if s[i-j] !... | 3 | |
375 | D | Tree and Queries | PROGRAMMING | 2,400 | [
"data structures",
"dfs and similar",
"trees"
] | null | null | You have a rooted tree consisting of *n* vertices. Each vertex of the tree has some color. We will assume that the tree vertices are numbered by integers from 1 to *n*. Then we represent the color of vertex *v* as *c**v*. The tree root is a vertex with number 1.
In this problem you need to answer to *m* queries. Each ... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=105). The next line contains a sequence of integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105). The next *n*<=-<=1 lines contain the edges of the tree. The *i*-th line contains the numbers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤... | Print *m* integers — the answers to the queries in the order the queries appear in the input. | [
"8 5\n1 2 2 3 3 2 3 3\n1 2\n1 5\n2 3\n2 4\n5 6\n5 7\n5 8\n1 2\n1 3\n1 4\n2 3\n5 3\n",
"4 1\n1 2 3 4\n1 2\n2 3\n3 4\n1 1\n"
] | [
"2\n2\n1\n0\n1\n",
"4\n"
] | A subtree of vertex *v* in a rooted tree with root *r* is a set of vertices {*u* : *dist*(*r*, *v*) + *dist*(*v*, *u*) = *dist*(*r*, *u*)}. Where *dist*(*x*, *y*) is the length (in edges) of the shortest path between vertices *x* and *y*. | 2,000 | [
{
"input": "8 5\n1 2 2 3 3 2 3 3\n1 2\n1 5\n2 3\n2 4\n5 6\n5 7\n5 8\n1 2\n1 3\n1 4\n2 3\n5 3",
"output": "2\n2\n1\n0\n1"
},
{
"input": "4 1\n1 2 3 4\n1 2\n2 3\n3 4\n1 1",
"output": "4"
}
] | 1,663,411,288 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 102,400 | n,q = map(int,input().split())
intimer = [0]*(n+1)
outtimer = [0]*(n+1)
from collections import defaultdict
from time import time
graph = defaultdict(lambda:[])
color = list(map(int,input().split()))
for _ in range(n-1):
a,b = map(int,input().split())
graph[a].append(b)
graph[b].append(a)
timer=... | Title: Tree and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a rooted tree consisting of *n* vertices. Each vertex of the tree has some color. We will assume that the tree vertices are numbered by integers from 1 to *n*. Then we represent the color of vertex *v* as *c**... | ```python
n,q = map(int,input().split())
intimer = [0]*(n+1)
outtimer = [0]*(n+1)
from collections import defaultdict
from time import time
graph = defaultdict(lambda:[])
color = list(map(int,input().split()))
for _ in range(n-1):
a,b = map(int,input().split())
graph[a].append(b)
graph[b].append(... | 0 | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,696,993,985 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | h,w = [int(i) for i in input().split()]
for i in range(h):
if i % 2 == 0:
print('#' * w)
elif i % 2 != 0:
print(('.'*(w-1)) + '#') | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
h,w = [int(i) for i in input().split()]
for i in range(h):
if i % 2 == 0:
print('#' * w)
elif i % 2 != 0:
print(('.'*(w-1)) + '#')
``` | 0 | |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,695,286,718 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | import math
n, m = map(int, input().split())
a = b = c = 0
for i in range(n+1):
if math.sqrt(i).is_integer() == True:
a = math.sqrt(i)
b = n - a**2
if a + b**2 == m:
c+=1
print(c) | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
import math
n, m = map(int, input().split())
a = b = c = 0
for i in range(n+1):
if math.sqrt(i).is_integer() == True:
a = math.sqrt(i)
b = n - a**2
if a + b**2 == m:
c+=1
print(c)
``` | 3 | |
888 | A | Local Extrema | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=><=*... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in array *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000) — the elements of array *a*. | Print the number of local extrema in the given array. | [
"3\n1 2 3\n",
"4\n1 5 2 5\n"
] | [
"0\n",
"2\n"
] | none | 0 | [
{
"input": "3\n1 2 3",
"output": "0"
},
{
"input": "4\n1 5 2 5",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n548",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n3 2 3",
"output": "1"
},
{
"inp... | 1,532,600,216 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 109 | 0 | n = int(input())
x = list(map(int, input().split()))
s = 0
for i in range(1, n-1):
if x[i-1] < x[i] and x[i+1] < x[i] or x[i-1] > x[i] and x[i+1] > x[i]:
s += 1
print(s)
| Title: Local Extrema
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element c... | ```python
n = int(input())
x = list(map(int, input().split()))
s = 0
for i in range(1, n-1):
if x[i-1] < x[i] and x[i+1] < x[i] or x[i-1] > x[i] and x[i+1] > x[i]:
s += 1
print(s)
``` | 3 | |
788 | A | Functions again | PROGRAMMING | 1,600 | [
"dp",
"two pointers"
] | null | null | Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function *f*, which is defined ... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the size of the array *a*.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (-109<=≤<=*a**i*<=≤<=109) — the array elements. | Print the only integer — the maximum value of *f*. | [
"5\n1 4 2 3 1\n",
"4\n1 5 4 7\n"
] | [
"3",
"6"
] | In the first sample case, the optimal value of *f* is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of *f* is reachable only on the whole array. | 500 | [
{
"input": "5\n1 4 2 3 1",
"output": "3"
},
{
"input": "4\n1 5 4 7",
"output": "6"
},
{
"input": "8\n16 14 12 10 8 100 50 0",
"output": "92"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "50\n-5 -9 0 44 -10 37 34 -49 11 -22 -26 44 8 -13 23 -46 34 12 -24 2 -4... | 1,618,485,241 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 249 | 17,408,000 | n=int(input())
a=list(map(int,input().split()))
b=[abs(a[i]-a[i+1]) for i in range(n-1)]
for i in range(0,n-1,2):
b[i]*=-1
dp=[0]*(n-1)
dp[0]=b[0]
for i in range(1,n-1):
dp[i]=max(dp[i-1]+b[i],b[i])
ans=max(dp)
for i in range(n-1):
b[i]*=-1
dp=[0]*(n-1)
dp[0]=b[0]
for i in range(1,n-1):
dp[i]=max... | Title: Functions again
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found t... | ```python
n=int(input())
a=list(map(int,input().split()))
b=[abs(a[i]-a[i+1]) for i in range(n-1)]
for i in range(0,n-1,2):
b[i]*=-1
dp=[0]*(n-1)
dp[0]=b[0]
for i in range(1,n-1):
dp[i]=max(dp[i-1]+b[i],b[i])
ans=max(dp)
for i in range(n-1):
b[i]*=-1
dp=[0]*(n-1)
dp[0]=b[0]
for i in range(1,n-1):
... | 3 | |
793 | A | Oleg and shares | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices. | Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. | [
"3 3\n12 9 15\n",
"2 2\n10 9\n",
"4 1\n1 1000000000 1000000000 1000000000\n"
] | [
"3",
"-1",
"2999999997"
] | Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
Ther... | 500 | [
{
"input": "3 3\n12 9 15",
"output": "3"
},
{
"input": "2 2\n10 9",
"output": "-1"
},
{
"input": "4 1\n1 1000000000 1000000000 1000000000",
"output": "2999999997"
},
{
"input": "1 11\n123",
"output": "0"
},
{
"input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50... | 1,492,966,316 | 416 | Python 3 | OK | TESTS | 88 | 171 | 13,824,000 | n, k = map(int, input().split())
l = list(map(int, input().split()))
cur = l[0]
cnt = 0
for i in range(1, n):
if cur % k != l[i] % k:
print(-1)
exit()
if cur < l[i]:
cnt += abs(l[i] - cur) // k
else:
cnt += (abs(l[i] - cur) // k) * i
cur = l[i]
print(cnt)
| Title: Oleg and shares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly o... | ```python
n, k = map(int, input().split())
l = list(map(int, input().split()))
cur = l[0]
cnt = 0
for i in range(1, n):
if cur % k != l[i] % k:
print(-1)
exit()
if cur < l[i]:
cnt += abs(l[i] - cur) // k
else:
cnt += (abs(l[i] - cur) // k) * i
cur = l[i]
print(cnt)
``` | 3 | |
380 | C | Sereja and Brackets | PROGRAMMING | 2,000 | [
"data structures",
"schedules"
] | null | null | Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length o... | The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains ... | Print the answer to each question on a single line. Print the answers in the order they go in the input. | [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n"
] | [
"0\n0\n2\n10\n4\n6\n6\n"
] | A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<s... | 1,500 | [
{
"input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10",
"output": "0\n0\n2\n10\n4\n6\n6"
},
{
"input": "(((((()((((((((((()((()(((((\n1\n8 15",
"output": "0"
},
{
"input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 ... | 1,653,710,350 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 9,830,400 | #begin of codeforces template
# (don't delete):
#
# from collections import *
# from heapq import *
# import bisect
#
#t = int(input()) #input number of test cases
#for _ in range(t): #iter for test cases
# n = int(input()) #input int
# n,m = map(int,input().split()) #input tuple
# L = list(map(in... | Title: Sereja and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two i... | ```python
#begin of codeforces template
# (don't delete):
#
# from collections import *
# from heapq import *
# import bisect
#
#t = int(input()) #input number of test cases
#for _ in range(t): #iter for test cases
# n = int(input()) #input int
# n,m = map(int,input().split()) #input tuple
# L = l... | 0 | |
31 | C | Schedule | PROGRAMMING | 1,700 | [
"implementation"
] | C. Schedule | 2 | 256 | At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, *n* groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, beca... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — amount of groups, which have lessons in the room 31. Then *n* lines follow, each of them contains two integers *l**i* *r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=106) — starting and finishing times of lesson of the *i*-th group. It is possible that initially no two ... | Output integer *k* — amount of ways to cancel the lesson in exactly one group so that no two time periods of lessons of the remaining groups intersect. In the second line output *k* numbers — indexes of groups, where it is possible to cancel the lesson. Groups are numbered starting from 1 in the order that they were gi... | [
"3\n3 10\n20 30\n1 3\n",
"4\n3 10\n20 30\n1 3\n1 39\n",
"3\n1 5\n2 6\n3 7\n"
] | [
"3\n1 2 3 ",
"1\n4 ",
"0\n"
] | none | 1,500 | [
{
"input": "3\n3 10\n20 30\n1 3",
"output": "3\n1 2 3 "
},
{
"input": "4\n3 10\n20 30\n1 3\n1 39",
"output": "1\n4 "
},
{
"input": "3\n1 5\n2 6\n3 7",
"output": "0"
},
{
"input": "4\n1 5\n5 7\n6 9\n9 10",
"output": "2\n2 3 "
},
{
"input": "11\n717170 795210\n86642... | 1,695,778,130 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 6,758,400 | n = int(input().strip())
lessons = []
for i in range(n):
l, r = map(int, input().strip().split())
lessons.append((l, r, i + 1))
lessons.sort()
def check(lessons):
for i in range(len(lessons) - 1):
if lessons[i][1] > lessons[i + 1][0]:
return False
return True
answe... | Title: Schedule
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, *n* groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time ... | ```python
n = int(input().strip())
lessons = []
for i in range(n):
l, r = map(int, input().strip().split())
lessons.append((l, r, i + 1))
lessons.sort()
def check(lessons):
for i in range(len(lessons) - 1):
if lessons[i][1] > lessons[i + 1][0]:
return False
return Tru... | 0 |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,643,039,612 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 154 | 0 | d = {}
m = 0
t = ""
for i in range(int(input())):
s = str(input())
if s in d.keys():
d[s]+=1
else:
d[s] = 1
if d[s]>m:
m = d[s]
t = s
print(t)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
d = {}
m = 0
t = ""
for i in range(int(input())):
s = str(input())
if s in d.keys():
d[s]+=1
else:
d[s] = 1
if d[s]>m:
m = d[s]
t = s
print(t)
``` | 3.9615 |
0 | none | none | none | 0 | [
"none"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. ... | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 0 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
... | 1,511,696,163 | 1,263 | Python 3 | WRONG_ANSWER | TESTS | 30 | 62 | 5,529,600 | import sys
skills = list(map(int, input().split()))
skills_s = sum(skills)
for f_i in range(len(skills)):
for s_i in range(len(skills)):
if f_i == s_i:
continue
for t_i in range(len(skills)):
if s_i == t_i:
continue
sum_a = skills[f_i]+skills[s_i... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exac... | ```python
import sys
skills = list(map(int, input().split()))
skills_s = sum(skills)
for f_i in range(len(skills)):
for s_i in range(len(skills)):
if f_i == s_i:
continue
for t_i in range(len(skills)):
if s_i == t_i:
continue
sum_a = skills[f_i]+... | 0 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,696,071,184 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | k, c = [int(i) for i in input().split(" ")]
lvalue = list(str(k))[-1]
if lvalue == '5' or lvalue == '0':
i=1
while (k*i)%2 != 0:
i+=1
print(i)
else:
somme = 1
nbp = 1
i = 0
while somme%k != 0:
somme=(10*i+c)
i+=1
print(somme//k) | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
k, c = [int(i) for i in input().split(" ")]
lvalue = list(str(k))[-1]
if lvalue == '5' or lvalue == '0':
i=1
while (k*i)%2 != 0:
i+=1
print(i)
else:
somme = 1
nbp = 1
i = 0
while somme%k != 0:
somme=(10*i+c)
i+=1
print(somme//k)
``` | 0 | |
909 | B | Segments | PROGRAMMING | 1,300 | [
"constructive algorithms",
"math"
] | null | null | You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoin... | The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100). | Output a single integer - the minimal number of layers required to draw the segments for the given *N*. | [
"2\n",
"3\n",
"4\n"
] | [
"2\n",
"4\n",
"6\n"
] | As an example, here are the segments and their optimal arrangement into layers for *N* = 4. | 1,000 | [
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "4"
},
{
"input": "4",
"output": "6"
},
{
"input": "21",
"output": "121"
},
{
"input": "100",
"output": "2550"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "9"
... | 1,598,967,231 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 140 | 0 | a=int(input())
print((a//2+1)*((a+1)//2)) | Title: Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in se... | ```python
a=int(input())
print((a//2+1)*((a+1)//2))
``` | 3 | |
838 | A | Binary Blocks | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | You are given an image, that can be represented with a 2-d *n* by *m* grid of pixels. Each pixel of the image is either on or off, denoted by the characters "0" or "1", respectively. You would like to compress this image. You want to choose an integer *k*<=><=1 and split the image into *k* by *k* blocks. If *n* and ... | The first line of input will contain two integers *n*,<=*m* (2<=≤<=*n*,<=*m*<=≤<=2<=500), the dimensions of the image.
The next *n* lines of input will contain a binary string with exactly *m* characters, representing the image. | Print a single integer, the minimum number of pixels needed to toggle to make the image compressible. | [
"3 5\n00100\n10110\n11001\n"
] | [
"5\n"
] | We first choose *k* = 2.
The image is padded as follows:
We can toggle the image to look as follows:
We can see that this image is compressible for *k* = 2. | 0 | [
{
"input": "3 5\n00100\n10110\n11001",
"output": "5"
}
] | 1,612,367,037 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 29,491,200 | n,m=[int(i) for i in input().split(" ")]
arr=[]
for i in range(n):
arr.append([int(j) for j in list(input())])
mini=10000
for k in range(2,min(n,m)):
o=k-(n%k)
p=k-(m%k)
for i in range(k-(n%k)):
arr.append([0]*m)
n=n+o
m=m+p
count=0
for i in range(n):
arr[i]... | Title: Binary Blocks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an image, that can be represented with a 2-d *n* by *m* grid of pixels. Each pixel of the image is either on or off, denoted by the characters "0" or "1", respectively. You would like to compress this image.... | ```python
n,m=[int(i) for i in input().split(" ")]
arr=[]
for i in range(n):
arr.append([int(j) for j in list(input())])
mini=10000
for k in range(2,min(n,m)):
o=k-(n%k)
p=k-(m%k)
for i in range(k-(n%k)):
arr.append([0]*m)
n=n+o
m=m+p
count=0
for i in range(n):
... | 0 | |
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,463,188,338 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 389 | 10,240,000 | def main():
n = int(input())
strings = [None] * n
for i in range(n):
strings[i] = input()
print(solver(strings))
def solver(L):
L.sort(key = cmp_to_key(customCompare))
return ''.join(L)
def customCompare(x, y):
a = x + y
b = y + x
if a < b:
return -1
elif a == b:
return 0
else:
r... | 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
def main():
n = int(input())
strings = [None] * n
for i in range(n):
strings[i] = input()
print(solver(strings))
def solver(L):
L.sort(key = cmp_to_key(customCompare))
return ''.join(L)
def customCompare(x, y):
a = x + y
b = y + x
if a < b:
return -1
elif a == b:
return 0
... | 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,644,850,178 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | a,b = map(int, input().split())
res1 = []
isB = True
while a != 0:
x = input()
res = ''
for i in x:
if i == '.':
if isB:
res += 'B'
isB = False
else:
res += 'W'
isB = True
if i == '-':
... | 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
a,b = map(int, input().split())
res1 = []
isB = True
while a != 0:
x = input()
res = ''
for i in x:
if i == '.':
if isB:
res += 'B'
isB = False
else:
res += 'W'
isB = True
if i... | 0 | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,676,638,573 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | n,k = map(int, input().split())
a = 240 - k
for i in range(n,1,-1):
if 5*(i*(i+1))/2 <= a:
print(i)
break | 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
n,k = map(int, input().split())
a = 240 - k
for i in range(n,1,-1):
if 5*(i*(i+1))/2 <= a:
print(i)
break
``` | 0 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,625,190,727 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 592 | 8,396,800 | n = int(input())
x = list(map(int, input().split()))
for i in range(n):
if i == 0:
min_dist = abs(x[0] - x[1])
max_dist = abs(x[0] - x[-1])
elif i == n-1:
min_dist = abs(x[-2] - x[-1])
max_dist = abs(x[0] - x[-1])
else:
dist_prev = abs(x[i-1] - x[i])
dist_nex... | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
n = int(input())
x = list(map(int, input().split()))
for i in range(n):
if i == 0:
min_dist = abs(x[0] - x[1])
max_dist = abs(x[0] - x[-1])
elif i == n-1:
min_dist = abs(x[-2] - x[-1])
max_dist = abs(x[0] - x[-1])
else:
dist_prev = abs(x[i-1] - x[i])
... | 3 | |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,641,911,492 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | y,k,n=map(int, input().split())
z = n-y
if z<=0:
print(-1)
else:
m = [2]
i = 1
while m[-1]+k<z:
m.append(m[i-1]+k)
i+=1
print(*m) | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
y,k,n=map(int, input().split())
z = n-y
if z<=0:
print(-1)
else:
m = [2]
i = 1
while m[-1]+k<z:
m.append(m[i-1]+k)
i+=1
print(*m)
``` | 0 | |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,670,936,016 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | from sys in stdin
arr = dict()
for i in stdin:
s, d=input().split()
if not s in arr.keys():
arr[s] = 0
arr[s] += int(d)
for i in arr.keys():
print(i,arr[i])
# Tue Dec 13 2022 12:21:55 GMT+0300 (Moscow Standard Time)
| Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
from sys in stdin
arr = dict()
for i in stdin:
s, d=input().split()
if not s in arr.keys():
arr[s] = 0
arr[s] += int(d)
for i in arr.keys():
print(i,arr[i])
# Tue Dec 13 2022 12:21:55 GMT+0300 (Moscow Standard Time)
``` | -1 | |
620 | A | Professor GukiZ's Robot | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe... | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot. | Print the only integer *d* — the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th... | 0 | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output":... | 1,641,144,216 | 2,147,483,647 | Python 3 | OK | TESTS | 75 | 62 | 0 | a,b = map(int,input().split())
c,d = map(int,input().split())
print(max(abs(a-c),abs(b-d))) | Title: Professor GukiZ's Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ... | ```python
a,b = map(int,input().split())
c,d = map(int,input().split())
print(max(abs(a-c),abs(b-d)))
``` | 3 | |
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst... | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
... | 1,583,945,377 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 0 | a,b=map(int, input().split())
if a<b:
a,b=b,a
d=a-b
if b==0:
print(0)
exit(0)
if a<=1 and b<=1:
print(0)
exit(0)
if d%3==0:
print(2*(a-2*d)-3+d//3)
else:
#print(a,b)
ch = d//3
a=a-2*ch
b=b+ch
#print(a,b)
print(a+b-2) | Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on... | ```python
a,b=map(int, input().split())
if a<b:
a,b=b,a
d=a-b
if b==0:
print(0)
exit(0)
if a<=1 and b<=1:
print(0)
exit(0)
if d%3==0:
print(2*(a-2*d)-3+d//3)
else:
#print(a,b)
ch = d//3
a=a-2*ch
b=b+ch
#print(a,b)
print(a+b-2)
``` | 0 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,684,048,758 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | n=input()
m=list(map(str,n[1:len(n)-1].split(', ')))
if len(m)==1:
print(0)
else:
print(len(set(m))) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
n=input()
m=list(map(str,n[1:len(n)-1].split(', ')))
if len(m)==1:
print(0)
else:
print(len(set(m)))
``` | 0 | |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7... | 1,690,008,660 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 77 | 11,673,600 | n = int(input())
a = [int(i) for i in input().split()]
currMax = 1
ans = 1
for i in range(1,n):
if(a[i] > a[i-1]): currMax += 1
else: currMax = 1
ans = max(ans, currMax)
print(ans) | Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called... | ```python
n = int(input())
a = [int(i) for i in input().split()]
currMax = 1
ans = 1
for i in range(1,n):
if(a[i] > a[i-1]): currMax += 1
else: currMax = 1
ans = max(ans, currMax)
print(ans)
``` | 3 | |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat... | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ... | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5... | 1,651,633,387 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 46 | 0 | n,k = map(int,input().split())
l = list(map(int,input().split()))
ans = 100
for i in range(n):
if k % l[i] == 0:
ans = min(ans,k//l[i])
print(ans) | Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ... | ```python
n,k = map(int,input().split())
l = list(map(int,input().split()))
ans = 100
for i in range(n):
if k % l[i] == 0:
ans = min(ans,k//l[i])
print(ans)
``` | 3 | |
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.... | The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. | Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". | [
")((())))(()())\n",
"))(\n"
] | [
"6 2\n",
"0 1\n"
] | none | 0 | [
{
"input": ")((())))(()())",
"output": "6 2"
},
{
"input": "))(",
"output": "0 1"
},
{
"input": "()(())()",
"output": "8 1"
},
{
"input": "((((()(((",
"output": "2 1"
},
{
"input": "))))()())))",
"output": "4 1"
},
{
"input": "(()())()(())()()())())()(... | 1,585,143,733 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 1,152 | 26,828,800 | # -*-coding:utf-8 -*-
line=input()
s=[-1]
max_len=0
max_num=1
l=len(line)
for i in range(l):
if line[i]=='(':
s.append(i)
elif len(s)>1:
s.pop()
n=i-s[-1]
if max_len<n:
max_len,max_num=n,1
elif max_len==n:
max_num+=1
else:
... | Title: Longest Regular Bracket Sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical exp... | ```python
# -*-coding:utf-8 -*-
line=input()
s=[-1]
max_len=0
max_num=1
l=len(line)
for i in range(l):
if line[i]=='(':
s.append(i)
elif len(s)>1:
s.pop()
n=i-s[-1]
if max_len<n:
max_len,max_num=n,1
elif max_len==n:
max_num+=1
e... | 3.662027 |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
... | 1,694,710,208 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 124 | 0 | s1 = input()
l = list(s1)
count_4 = l.count('4')
count_7 = l.count('7')
if((count_4+count_7) == 4 or (count_4+count_7) == 7):
print('YES')
else:
print("NO") | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
s1 = input()
l = list(s1)
count_4 = l.count('4')
count_7 = l.count('7')
if((count_4+count_7) == 4 or (count_4+count_7) == 7):
print('YES')
else:
print("NO")
``` | 3.969 |
235 | A | LCM Challenge | PROGRAMMING | 1,600 | [
"number theory"
] | null | null | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement. | Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*. | [
"9\n",
"7\n"
] | [
"504\n",
"210\n"
] | The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is ... | 500 | [
{
"input": "9",
"output": "504"
},
{
"input": "7",
"output": "210"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "60"
},
{
"input": "33",
"output": "32736"
},
{
"input": "21",
"output": ... | 1,457,943,676 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n = int(input())
if n % 2 != 0: print(n*(n-1)*(n-2))
else: print((n-1)*(n-2)*(n-3)) | Title: LCM Challenge
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive... | ```python
n = int(input())
if n % 2 != 0: print(n*(n-1)*(n-2))
else: print((n-1)*(n-2)*(n-3))
``` | 0 | |
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,673,013,294 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input())
z = ""
for i in range(n):
w = input()
if len(w)>10:
z = z + w[0]+str(len(w)-2)+w[len(w)-1]
print(z)
else :
print(w)
| 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())
z = ""
for i in range(n):
w = input()
if len(w)>10:
z = z + w[0]+str(len(w)-2)+w[len(w)-1]
print(z)
else :
print(w)
``` | 0 |
55 | A | Flea travel | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | A. Flea travel | 1 | 256 | A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k*<=-<=1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that ... | The only line contains single integer: 1<=≤<=*n*<=≤<=1000 — number of hassocks. | Output "YES" if all the hassocks will be visited and "NO" otherwise. | [
"1\n",
"3\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "YES"
},
{
"input": "4",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "NO"
},
{
"input": "7",
"output": "NO... | 1,420,228,442 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | import sys
import math
n = int(sys.stdin.readline())
v = [0] * n
ost = 1
for i in range(1, n + 1):
ost = (ost + i) % n
v[ost] = 1
for i in v:
if(i == 0):
print("NO")
exit()
print("YES")
| Title: Flea travel
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k*<=-<=1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighbo... | ```python
import sys
import math
n = int(sys.stdin.readline())
v = [0] * n
ost = 1
for i in range(1, n + 1):
ost = (ost + i) % n
v[ost] = 1
for i in v:
if(i == 0):
print("NO")
exit()
print("YES")
``` | 0 |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,545,684,561 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 186 | 0 | dic = {}
for i in range(int(input())):
linha = input().split(' ')
if(linha[0] in dic.keys()):
dic[linha[0]] = [int(linha[1])+dic[linha[0]][0], i]
else:
dic[linha[0]] = [int(linha[1]), i]
a = sorted(dic.items(),key = lambda x:x[1][1], reverse=True)
a.sort(key=lambda x:x[1][0])
print(... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
dic = {}
for i in range(int(input())):
linha = input().split(' ')
if(linha[0] in dic.keys()):
dic[linha[0]] = [int(linha[1])+dic[linha[0]][0], i]
else:
dic[linha[0]] = [int(linha[1]), i]
a = sorted(dic.items(),key = lambda x:x[1][1], reverse=True)
a.sort(key=lambda x:x[1][0... | 0 |
17 | A | Noldbach problem | PROGRAMMING | 1,000 | [
"brute force",
"math",
"number theory"
] | A. Noldbach problem | 2 | 64 | Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Nold... | The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). | Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. | [
"27 2\n",
"45 7\n"
] | [
"YES",
"NO"
] | In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | 0 | [
{
"input": "27 2",
"output": "YES"
},
{
"input": "45 7",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "15 1",
"output": "YES"
},
{
"input": "17 1",
"output": "YES"
},
{
"input": "34 5",
"output": "NO"
},
{
"input": "37 ... | 1,694,193,654 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | k,n,l=int(input()),int(input()),[]
count=0
def isPrime(n):
if(n==1 or n==0):
return False
for i in range(2,n):
if(n%i==0):
return False
return True
N = n;
for i in range(1,N+1):
if(isPrime(i)):
l.append(i)
print(l)
for i in range(len(l)+1):
y=l[i]
if y==l[len(... | Title: Noldbach problem
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a prob... | ```python
k,n,l=int(input()),int(input()),[]
count=0
def isPrime(n):
if(n==1 or n==0):
return False
for i in range(2,n):
if(n%i==0):
return False
return True
N = n;
for i in range(1,N+1):
if(isPrime(i)):
l.append(i)
print(l)
for i in range(len(l)+1):
y=l[i]
if... | -1 |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,604,039,848 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 2,000 | 7,475,200 | n = int(input())
stone = map(int,input().split())
x = []
for i in stone:
if i == n:
print(i, end=" ")
n -= 1
x.sort()
for g in range(1,len(x) + 1):
if x[-g] == n:
print(x[-g], end=" ")
n -= 1
else:
print("")... | Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
n = int(input())
stone = map(int,input().split())
x = []
for i in stone:
if i == n:
print(i, end=" ")
n -= 1
x.sort()
for g in range(1,len(x) + 1):
if x[-g] == n:
print(x[-g], end=" ")
n -= 1
else:
... | 0 | |
809 | A | Do you want a date? | PROGRAMMING | 1,500 | [
"implementation",
"math",
"sortings"
] | null | null | Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on t... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) denoting the number of hacked computers.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) denoting the coordinates of hacked computers. It is guaranteed that all *x**i* are distinct. | Print a single integer — the required sum modulo 109<=+<=7. | [
"2\n4 7\n",
"3\n4 3 1\n"
] | [
"3\n",
"9\n"
] | There are three non-empty subsets in the first sample test:<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/02b2d12556dad85f1c6c6912786eb87d4be2ea17.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/22f6a537962c... | 500 | [
{
"input": "2\n4 7",
"output": "3"
},
{
"input": "3\n4 3 1",
"output": "9"
},
{
"input": "20\n8 11 13 19 21 34 36 44 57 58 61 63 76 78 79 81 85 86 90 95",
"output": "83396599"
},
{
"input": "20\n1 8 9 12 15 17 18 24 30 33 36 41 53 54 59 62 64 66 72 73",
"output": "6805914... | 1,589,131,611 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 20,172,800 | n = int(input())
ar = list(map(int,input().split()))
ar.sort()
MOD = 10**9 + 7
ans = 0
for i in range(n):
bef = i
aft = n - i - 1
if bef < aft:
ans -= ar[i]*(pow(2 , aft - bef , MOD) - 1 + MOD)
ans %= MOD
else:
ans += ar[i]*(pow(2 , bef - aft , MOD) - 1 + MOD)
... | Title: Do you want a date?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access ... | ```python
n = int(input())
ar = list(map(int,input().split()))
ar.sort()
MOD = 10**9 + 7
ans = 0
for i in range(n):
bef = i
aft = n - i - 1
if bef < aft:
ans -= ar[i]*(pow(2 , aft - bef , MOD) - 1 + MOD)
ans %= MOD
else:
ans += ar[i]*(pow(2 , bef - aft , MOD) - 1 +... | 0 | |
691 | C | Exponential notation | PROGRAMMING | 1,800 | [
"implementation",
"strings"
] | null | null | You are given a positive decimal number *x*.
Your task is to convert it to the "simple exponential notation".
Let *x*<==<=*a*·10*b*, where 1<=≤<=*a*<=<<=10, then in general case the "simple exponential notation" looks like "aEb". If *b* equals to zero, the part "Eb" should be skipped. If *a* is an integer, it shou... | The only line contains the positive decimal number *x*. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other. | Print the only line — the "simple exponential notation" of the given number *x*. | [
"16\n",
"01.23400\n",
".100\n",
"100.\n"
] | [
"1.6E1\n",
"1.234\n",
"1E-1\n",
"1E2\n"
] | none | 0 | [
{
"input": "16",
"output": "1.6E1"
},
{
"input": "01.23400",
"output": "1.234"
},
{
"input": ".100",
"output": "1E-1"
},
{
"input": "100.",
"output": "1E2"
},
{
"input": "9000",
"output": "9E3"
},
{
"input": "0.0012",
"output": "1.2E-3"
},
{
... | 1,554,848,637 | 3,537 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 307,200 | s=input().rstrip()
x=list(s)
if '.' not in x:
T=int(''.join(x))
D=list(str(T))
if len(D)==1:
print(T)
else:
C=len(D)-1
for i in range(0,len(D)):
if i==1:
print(".",end='')
print(D[i],end='')
else:
... | Title: Exponential notation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a positive decimal number *x*.
Your task is to convert it to the "simple exponential notation".
Let *x*<==<=*a*·10*b*, where 1<=≤<=*a*<=<<=10, then in general case the "simple exponential notatio... | ```python
s=input().rstrip()
x=list(s)
if '.' not in x:
T=int(''.join(x))
D=list(str(T))
if len(D)==1:
print(T)
else:
C=len(D)-1
for i in range(0,len(D)):
if i==1:
print(".",end='')
print(D[i],end='')
else:
... | 0 | |
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,626,861,656 | 2,696 | Python 3 | WRONG_ANSWER | TESTS | 1 | 122 | 6,963,200 | n = int(input())
l = list(map(int, input().split(" ")))
i = 0
j = n - 1
while(1):
if(i == j):
i -= 1
break
if(j - i == 1):
break
e = min(l[i], l[j])
l[i] -= e
l[j] -= e
if(l[i] == 0): i += 1
if(l[j] == 0): j -= 1
print(i + 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())
l = list(map(int, input().split(" ")))
i = 0
j = n - 1
while(1):
if(i == j):
i -= 1
break
if(j - i == 1):
break
e = min(l[i], l[j])
l[i] -= e
l[j] -= e
if(l[i] == 0): i += 1
if(l[j] == 0): j -= 1
pr... | 0 |
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like... | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input"... | 1,656,491,160 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 512,000 | n = int(input())
s = input()
zeros = s.count("0")
ones = s.count("1")
mincount = min(zeros,ones)
print(n-2*mincount) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
n = int(input())
s = input()
zeros = s.count("0")
ones = s.count("1")
mincount = min(zeros,ones)
print(n-2*mincount)
``` | 3 | |
106 | C | Buns | PROGRAMMING | 1,700 | [
"dp"
] | C. Buns | 2 | 256 | Lavrenty, a baker, is going to make several buns with stuffings and sell them.
Lavrenty has *n* grams of dough as well as *m* different stuffing types. The stuffing types are numerated from 1 to *m*. Lavrenty knows that he has *a**i* grams left of the *i*-th stuffing. It takes exactly *b**i* grams of stuffing *i* and ... | The first line contains 4 integers *n*, *m*, *c*0 and *d*0 (1<=≤<=*n*<=≤<=1000, 1<=≤<=*m*<=≤<=10, 1<=≤<=*c*0,<=*d*0<=≤<=100). Each of the following *m* lines contains 4 integers. The *i*-th line contains numbers *a**i*, *b**i*, *c**i* and *d**i* (1<=≤<=*a**i*,<=*b**i*,<=*c**i*,<=*d**i*<=≤<=100). | Print the only number — the maximum number of tugriks Lavrenty can earn. | [
"10 2 2 1\n7 3 2 100\n12 3 1 10\n",
"100 1 25 50\n15 5 20 10\n"
] | [
"241",
"200"
] | To get the maximum number of tugriks in the first sample, you need to cook 2 buns with stuffing 1, 4 buns with stuffing 2 and a bun without any stuffing.
In the second sample Lavrenty should cook 4 buns without stuffings. | 1,500 | [
{
"input": "10 2 2 1\n7 3 2 100\n12 3 1 10",
"output": "241"
},
{
"input": "100 1 25 50\n15 5 20 10",
"output": "200"
},
{
"input": "10 1 5 2\n100 1 2 3",
"output": "15"
},
{
"input": "10 1 5 11\n3 1 3 8",
"output": "24"
},
{
"input": "10 2 11 5\n100 1 3 10\n100 1... | 1,618,124,495 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 248 | 2,048,000 | n,m,c0,d0=map(int,input().split())
dp=[]
for i in range(n+1): dp.append(i//c0*d0)
for i in range(m):
a,b,c,d=map(int,input().split())
for j in range(1,a//b+1):
for k in range(n,c-1,-1):
dp[k]=max(dp[k],dp[k-c]+d)
print(dp[n])
| Title: Buns
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Lavrenty, a baker, is going to make several buns with stuffings and sell them.
Lavrenty has *n* grams of dough as well as *m* different stuffing types. The stuffing types are numerated from 1 to *m*. Lavrenty knows that he has *a**i*... | ```python
n,m,c0,d0=map(int,input().split())
dp=[]
for i in range(n+1): dp.append(i//c0*d0)
for i in range(m):
a,b,c,d=map(int,input().split())
for j in range(1,a//b+1):
for k in range(n,c-1,-1):
dp[k]=max(dp[k],dp[k-c]+d)
print(dp[n])
``` | 3.934185 |
4 | C | Registration System | PROGRAMMING | 1,300 | [
"data structures",
"hashing",
"implementation"
] | C. Registration system | 5 | 64 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
... | The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | [
"4\nabacaba\nacaba\nabacaba\nacab\n",
"6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n"
] | [
"OK\nOK\nabacaba1\nOK\n",
"OK\nfirst1\nOK\nsecond1\nOK\nthird1\n"
] | none | 0 | [
{
"input": "4\nabacaba\nacaba\nabacaba\nacab",
"output": "OK\nOK\nabacaba1\nOK"
},
{
"input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird",
"output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1"
},
{
"input": "1\nn",
"output": "OK"
},
{
"input": "2\nu\nu",
"output": "OK\nu1"
... | 1,690,221,195 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 748 | 17,203,200 | import sys
import math
import statistics
input = lambda :sys.stdin.readline().rstrip()
output =lambda:sys.stdout()
def isPrime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
fArray=[0,1]
def fibonacci(n):
if n<=len(fArray):
return fArray... | Title: Registration System
Time Limit: 5 seconds
Memory Limit: 64 megabytes
Problem Description:
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to imple... | ```python
import sys
import math
import statistics
input = lambda :sys.stdin.readline().rstrip()
output =lambda:sys.stdout()
def isPrime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
fArray=[0,1]
def fibonacci(n):
if n<=len(fArray):
ret... | 3.797026 |
603 | A | Alternative Thinking | PROGRAMMING | 1,600 | [
"dp",
"greedy",
"math"
] | null | null | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is... | The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000).
The following line contains a binary string of length *n* representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | [
"8\n10000011\n",
"2\n01\n"
] | [
"5\n",
"2\n"
] | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | 500 | [
{
"input": "8\n10000011",
"output": "5"
},
{
"input": "2\n01",
"output": "2"
},
{
"input": "5\n10101",
"output": "5"
},
{
"input": "75\n010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "75"
},
{
"input": "11\n00000000000",
... | 1,594,991,052 | 2,147,483,647 | PyPy 3 | OK | TESTS | 116 | 140 | 20,684,800 | n=int(input())
s=input()
print(min(n,3+s.count("01")+s.count("10"))) | Title: Alternative Thinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one o... | ```python
n=int(input())
s=input()
print(min(n,3+s.count("01")+s.count("10")))
``` | 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,535,597,134 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 0 | n=input()
a=map(int,input().split())
ls=rs=0
l,r=0,n-1
while l<r:
ls+=a[l]
rs+=a[r]
if ls<=rs:
l+=1
else:r+=1
print(l,r) | 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=input()
a=map(int,input().split())
ls=rs=0
l,r=0,n-1
while l<r:
ls+=a[l]
rs+=a[r]
if ls<=rs:
l+=1
else:r+=1
print(l,r)
``` | -1 |
729 | B | Spotlights | PROGRAMMING | 1,200 | [
"dp",
"implementation"
] | null | null | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ... | Print one integer — the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and... | 1,000 | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 ... | 1,651,918,525 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n, m = map(int, input().split())
stage = []
for i in range(n):
stage.append(list(map(int, input().split())))
result = 0
for i in range(m):
top = -1
bottom = -1
counter_one = 0
for j in range(n):
if (stage[j][i] == 1):
if (top == -1):
top = j
bottom =... | Title: Spotlights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to pl... | ```python
n, m = map(int, input().split())
stage = []
for i in range(n):
stage.append(list(map(int, input().split())))
result = 0
for i in range(m):
top = -1
bottom = -1
counter_one = 0
for j in range(n):
if (stage[j][i] == 1):
if (top == -1):
top = j
... | 0 | |
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,681,323,649 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
l=[]
c=""
for i in range(n):
s=str(input())
length=str(len(s)-2)
if len(s)<=10:
l.append(s)
if len(s)>10:
c=c+s[0]+length+s[len(s)-1]
l.append(c
)
print(l)
| 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())
l=[]
c=""
for i in range(n):
s=str(input())
length=str(len(s)-2)
if len(s)<=10:
l.append(s)
if len(s)>10:
c=c+s[0]+length+s[len(s)-1]
l.append(c
)
print(l)
``` | 0 |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,678,052,904 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | # This is a sample Python script.
# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
def solve():
# Use a breakpoint in the code line below to debug your script.
scale = [x for x in input()]
unused = [x for... | Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
# This is a sample Python script.
# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
def solve():
# Use a breakpoint in the code line below to debug your script.
scale = [x for x in input()]
unuse... | 0 | |
1,011 | A | Stages | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The ro... | The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build th... | Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. | [
"5 3\nxyabd\n",
"7 4\nproblem\n",
"2 2\nab\n",
"12 1\nabaabbaaabbb\n"
] | [
"29",
"34",
"-1",
"1"
] | In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight ... | 500 | [
{
"input": "5 3\nxyabd",
"output": "29"
},
{
"input": "7 4\nproblem",
"output": "34"
},
{
"input": "2 2\nab",
"output": "-1"
},
{
"input": "12 1\nabaabbaaabbb",
"output": "1"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": ... | 1,645,292,971 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n,k = map(int, input().split())
string = input()
reference = "abcdefghijklmnopqrstuvwxyz"
string = sorted(string)
ans = ""
ans += string[0]
for i in range(0,n-1):
if reference.index(string[i+1]) - reference.index(string[i]) >= 2:
ans+= string[i+1]
if len(ans) == k :
break
... | Title: Stages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — conca... | ```python
n,k = map(int, input().split())
string = input()
reference = "abcdefghijklmnopqrstuvwxyz"
string = sorted(string)
ans = ""
ans += string[0]
for i in range(0,n-1):
if reference.index(string[i+1]) - reference.index(string[i]) >= 2:
ans+= string[i+1]
if len(ans) == k :
b... | 0 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,615,061,193 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 204,800 | n = int(input())
k = int(input())
q = int(input())
count = 0
for i in range(n):
a = abs(int(k[i]) - int(q[i]))
b = min(int(k[i]), int(q[i])) + 10 - max(int(k[i]), int(q[i]))
count += min(a, b)
print(count) | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n = int(input())
k = int(input())
q = int(input())
count = 0
for i in range(n):
a = abs(int(k[i]) - int(q[i]))
b = min(int(k[i]), int(q[i])) + 10 - max(int(k[i]), int(q[i]))
count += min(a, b)
print(count)
``` | -1 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,672,755,390 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | n=int(input())
a=[]
for t in range(n):
l=int(input())
a.append()
great=a[0]
least=a[0]
win=0
lose=0
for i in range(0,n):
if(i>0):
if a[i]>great:
great=a[i]
win+=1
if a[i]<least:
least=a[i]
lose+=1
print(win,lose)
| Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n=int(input())
a=[]
for t in range(n):
l=int(input())
a.append()
great=a[0]
least=a[0]
win=0
lose=0
for i in range(0,n):
if(i>0):
if a[i]>great:
great=a[i]
win+=1
if a[i]<least:
least=a[i]
lose+=1
print(win,lose)
... | -1 | |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,695,908,436 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 3,993,600 | line1 = list(map(int,input().split(" ")))
line2 = list(map(int,input().split(" ")))
line3 = list(map(int,input().split(" ")))
line4 = list(map(int,input().split(" ")))
line5 = list(map(int,input().split(" ")))
line1pos = [i for i,x in enumerate(line1) if x == 1]
line2pos = [i for i,x in enumerate(line2) if x ==... | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
line1 = list(map(int,input().split(" ")))
line2 = list(map(int,input().split(" ")))
line3 = list(map(int,input().split(" ")))
line4 = list(map(int,input().split(" ")))
line5 = list(map(int,input().split(" ")))
line1pos = [i for i,x in enumerate(line1) if x == 1]
line2pos = [i for i,x in enumerate(line... | -1 | |
631 | A | Interview | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109).
The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). | Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. | [
"5\n1 2 4 3 2\n2 3 3 12 1\n",
"10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n"
] | [
"22",
"46"
] | Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *... | 500 | [
{
"input": "5\n1 2 4 3 2\n2 3 3 12 1",
"output": "22"
},
{
"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6",
"output": "46"
},
{
"input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 9... | 1,475,856,300 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 4,608,000 | n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
max1,max2 = 0,0
for i in range(n):
for j in range(i,n):
for k in range(j,n):
s1 = a[i]|a[j]|a[k]
s2 = b[i]|b[j]|b[k]
if (max1<s1):
max1 = s1
if (max2<s... | Title: Interview
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of... | ```python
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
max1,max2 = 0,0
for i in range(n):
for j in range(i,n):
for k in range(j,n):
s1 = a[i]|a[j]|a[k]
s2 = b[i]|b[j]|b[k]
if (max1<s1):
max1 = s1
... | 0 | |
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi... | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,658,336,130 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,764,800 | l=[int(i) for i in input().split()]
b=l[0]
g=l[1]
if b>=g:
print("BG"*g+"B"*(b-g))
else:
print("GB"*b+"G"*(g-b)) | Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n... | ```python
l=[int(i) for i in input().split()]
b=l[0]
g=l[1]
if b>=g:
print("BG"*g+"B"*(b-g))
else:
print("GB"*b+"G"*(g-b))
``` | -1 | |
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, wh... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc... | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 2... | 1,495,315,222 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | n=int(input(""))
k=float(input(""))
x=[]
d=k-0.5
sum=0
for i in range(0,n):
b=float(input(""))
if(b>d):
continue
sum=sum+d-b
m=(sum/0.5)
print(int(m))
| Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
... | ```python
n=int(input(""))
k=float(input(""))
x=[]
d=k-0.5
sum=0
for i in range(0,n):
b=float(input(""))
if(b>d):
continue
sum=sum+d-b
m=(sum/0.5)
print(int(m))
``` | -1 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,650,096,667 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 62 | 409,600 |
from string import*
defult_string = ascii_lowercase *3
input_string = "a" + input()
sum = 0
for i in range(len(input_string)-1):
a = defult_string.find(input_string[i])
v = defult_string.find(input_string[i+1])
v1 = v+26
value = min(abs(a-v),abs(a-v1))
value1 = min(abs((a+26)-v),abs... | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
from string import*
defult_string = ascii_lowercase *3
input_string = "a" + input()
sum = 0
for i in range(len(input_string)-1):
a = defult_string.find(input_string[i])
v = defult_string.find(input_string[i+1])
v1 = v+26
value = min(abs(a-v),abs(a-v1))
value1 = min(abs((a+... | 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,541,862,939 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 0 | def compare(s):
return not (s.index('h') < s.index('e') < s.index('l') < s.index('o'))
s = input()
if 'h' not in s or 'e' not in s or 'l' not in s or 'o' not in s:
print('NO')
elif s.count('l') < 2:
print('NO')
elif compare(s):
print('NO')
else:
s = ''.join(s.split('l',1))
print('YNEO... | 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
def compare(s):
return not (s.index('h') < s.index('e') < s.index('l') < s.index('o'))
s = input()
if 'h' not in s or 'e' not in s or 'l' not in s or 'o' not in s:
print('NO')
elif s.count('l') < 2:
print('NO')
elif compare(s):
print('NO')
else:
s = ''.join(s.split('l',1))
p... | 0 |
557 | B | Pasha and Tea | PROGRAMMING | 1,500 | [
"constructive algorithms",
"implementation",
"math",
"sortings"
] | null | null | Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys a... | The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *... | Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"2 4\n1 1 1 1\n",
"3 18\n4 4 4 2 2 2\n",
"1 5\n2 3\n"
] | [
"3",
"18",
"4.5"
] | Pasha also has candies that he is going to give to girls but that is another task... | 1,000 | [
{
"input": "2 4\n1 1 1 1",
"output": "3.0000000000"
},
{
"input": "3 18\n4 4 4 2 2 2",
"output": "18.0000000000"
},
{
"input": "1 5\n2 3",
"output": "4.5000000000"
},
{
"input": "1 1\n1000000000 1000000000",
"output": "1.0000000000"
},
{
"input": "4 1000000000\n1 ... | 1,436,336,359 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 233 | 17,305,600 | def main():
n,w = map(int,input().split())
a = list(sorted(map(int,input().split())))
q = min(min(a[:n]),min(a[n:])/2)
print(min(q*3*n,w))
if __name__ == '__main__': main() | Title: Pasha and Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most ... | ```python
def main():
n,w = map(int,input().split())
a = list(sorted(map(int,input().split())))
q = min(min(a[:n]),min(a[n:])/2)
print(min(q*3*n,w))
if __name__ == '__main__': main()
``` | 3 | |
548 | A | Mike and Fax | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ... | The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | [
"saba\n2\n",
"saddastavvat\n2\n"
] | [
"NO\n",
"YES\n"
] | Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | 500 | [
{
"input": "saba\n2",
"output": "NO"
},
{
"input": "saddastavvat\n2",
"output": "YES"
},
{
"input": "aaaaaaaaaa\n3",
"output": "NO"
},
{
"input": "aaaaaa\n3",
"output": "YES"
},
{
"input": "abaacca\n2",
"output": "NO"
},
{
"input": "a\n1",
"output"... | 1,506,526,818 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | def palindrome(a):
x=''
for i in range(len(a)-1,-1,-1):
x+=a[i]
if x==a:
return 1
else:
return 0
k=input()
n=int(input())
f="YES"
for i in range(0,len(k),n):
if palindrome(k[i:i+n])==0:
f="NO"
print(f)
| Title: Mike and Fax
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure ... | ```python
def palindrome(a):
x=''
for i in range(len(a)-1,-1,-1):
x+=a[i]
if x==a:
return 1
else:
return 0
k=input()
n=int(input())
f="YES"
for i in range(0,len(k),n):
if palindrome(k[i:i+n])==0:
f="NO"
print(f)
``` | 0 | |
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like... | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input"... | 1,690,844,458 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 62 | 409,600 | n = input()
s = input()
pairs = min(s.count("0"), s.count("1")) * 2
print(len(s) - pairs) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
n = input()
s = input()
pairs = min(s.count("0"), s.count("1")) * 2
print(len(s) - pairs)
``` | 3 | |
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate... | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed progra... | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal so... | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20... | 1,666,258,189 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n,m=map(int,input().split())
a=[int(i) for i in input().split()]
a.insert(0,0)
a.append(m)
b=[(a[i+1]-a[i])*((-1)**i) for i in range(n+1)]
s=[0 for i in range(n+2)]
for i in range(n,0,-1):
s[i]=s[i+1]+b[i]
x=s.index(min(s))
print(s[0]-2*s[x]) | Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows y... | ```python
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
a.insert(0,0)
a.append(m)
b=[(a[i+1]-a[i])*((-1)**i) for i in range(n+1)]
s=[0 for i in range(n+2)]
for i in range(n,0,-1):
s[i]=s[i+1]+b[i]
x=s.index(min(s))
print(s[0]-2*s[x])
``` | 0 | |
900 | A | Find Extra One | PROGRAMMING | 800 | [
"geometry",
"implementation"
] | null | null | You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. | The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105).
The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide. | Print "Yes" if there is such a point, "No" — otherwise.
You can print every letter in any case (upper or lower). | [
"3\n1 1\n-1 -1\n2 -1\n",
"4\n1 1\n2 2\n-1 1\n-2 2\n",
"3\n1 2\n2 1\n4 60\n"
] | [
"Yes",
"No",
"Yes"
] | In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed. | 500 | [
{
"input": "3\n1 1\n-1 -1\n2 -1",
"output": "Yes"
},
{
"input": "4\n1 1\n2 2\n-1 1\n-2 2",
"output": "No"
},
{
"input": "3\n1 2\n2 1\n4 60",
"output": "Yes"
},
{
"input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1",
"output": "Yes"
},
{
"input": "2\n1... | 1,561,594,030 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 997 | 10,956,800 | casos = int(input())
left = []
right = []
for i in range(casos):
x, y = map(int, input().split())
if(x < 0):
left.append([x, y])
else:
right.append([x, y])
if(len(left) > 1 and len(right) > 1):
print("No")
else:
print("Yes") | Title: Find Extra One
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
Input Specification:
The first li... | ```python
casos = int(input())
left = []
right = []
for i in range(casos):
x, y = map(int, input().split())
if(x < 0):
left.append([x, y])
else:
right.append([x, y])
if(len(left) > 1 and len(right) > 1):
print("No")
else:
print("Yes")
``` | 3 | |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,604,795,120 | 2,147,483,647 | Python 3 | OK | TESTS | 104 | 482 | 1,945,600 | def isep(s):
if (len(s) % 2 != 0):
return s
s1 = isep(s[:int(len(s)/2)])
s2 = isep(s[int(len(s)/2):])
if s1 > s2:
return s2 + s1
else:
return s1 + s2
a = input()
b = input()
if isep(a) == isep(b):
print("YES")
else:
print("NO")
| Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
def isep(s):
if (len(s) % 2 != 0):
return s
s1 = isep(s[:int(len(s)/2)])
s2 = isep(s[int(len(s)/2):])
if s1 > s2:
return s2 + s1
else:
return s1 + s2
a = input()
b = input()
if isep(a) == isep(b):
print("YES")
else:
print("NO")
... | 3 | |
371 | B | Fox Dividing Cheese | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it... | The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109). | If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0. | [
"15 20\n",
"14 8\n",
"6 6\n"
] | [
"3\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "15 20",
"output": "3"
},
{
"input": "14 8",
"output": "-1"
},
{
"input": "6 6",
"output": "0"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 1024",
"output": "10"
},
{
"input": "1024 729",
"output": "16"
},
{
"input": "1024... | 1,681,573,477 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 93 | 0 | from sys import stdin, stdout
a, b = map(int, stdin.readline().split())
ans = 0
twos = 0
while a % 2 == 0:
a = a//2
twos +=1
while b % 2 == 0:
b = b//2
twos -=1
threes = 0
while a % 3 == 0:
a = a//3
threes +=1
while b % 3 == 0:
b = b//3
threes -=1
fives = 0
while a % 5 ... | Title: Fox Dividing Cheese
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox com... | ```python
from sys import stdin, stdout
a, b = map(int, stdin.readline().split())
ans = 0
twos = 0
while a % 2 == 0:
a = a//2
twos +=1
while b % 2 == 0:
b = b//2
twos -=1
threes = 0
while a % 3 == 0:
a = a//3
threes +=1
while b % 3 == 0:
b = b//3
threes -=1
fives = 0
wh... | 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,593,247,400 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 6,963,200 | s = input()
count = 0
for i in range(len(s)):
if count == 0 and s[i] == "h":
count += 1
elif count == 1 and s[i] == "e":
count += 1
elif count == 2 and s[i] == "l":
count += 1
elif count == 3 and s[i] == "l":
count +=1
elif count == 4 and s[i] == "o":
... | 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 = input()
count = 0
for i in range(len(s)):
if count == 0 and s[i] == "h":
count += 1
elif count == 1 and s[i] == "e":
count += 1
elif count == 2 and s[i] == "l":
count += 1
elif count == 3 and s[i] == "l":
count +=1
elif count == 4 and s[i] == ... | 3.93253 |
0 | none | none | none | 0 | [
"none"
] | null | null | Leha plays a computer game, where is on each level is given a connected graph with *n* vertices and *m* edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer *d**i*, which can be equal to 0, 1 or <=-<=1. To pass the level, he needs to find a «good» subset of edges of the gr... | The first line contains two integers *n*, *m* (1<=≤<=*n*<=≤<=3·105, *n*<=-<=1<=≤<=*m*<=≤<=3·105) — number of vertices and edges.
The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (<=-<=1<=≤<=*d**i*<=≤<=1) — numbers on the vertices.
Each of the next *m* lines contains two integers *u* and *v* (1<=≤<=*u*... | Print <=-<=1 in a single line, if solution doesn't exist. Otherwise in the first line *k* — number of edges in a subset. In the next *k* lines indexes of edges. Edges are numerated in order as they are given in the input, starting from 1. | [
"1 0\n1\n",
"4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4\n",
"2 1\n1 1\n1 2\n",
"3 3\n0 -1 1\n1 2\n2 3\n1 3\n"
] | [
"-1\n",
"0\n",
"1\n1\n",
"1\n2\n"
] | In the first sample we have single vertex without edges. It's degree is 0 and we can not get 1. | 0 | [
{
"input": "1 0\n1",
"output": "-1"
},
{
"input": "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4",
"output": "0"
},
{
"input": "2 1\n1 1\n1 2",
"output": "1\n1"
},
{
"input": "3 3\n0 -1 1\n1 2\n2 3\n1 3",
"output": "1\n2"
},
{
"input": "10 10\n-1 -1 -1 -1 -1 -1 -1 -1 -1 ... | 1,590,861,715 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 280 | 15,872,000 | import math as mt
import sys,string
input=sys.stdin.readline
from collections import defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
n,m=M()
l=L()
if(m==0):
if(l.count(1)==0):
print(0)
exit()
e... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha plays a computer game, where is on each level is given a connected graph with *n* vertices and *m* edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer *d**i*, which can be equal... | ```python
import math as mt
import sys,string
input=sys.stdin.readline
from collections import defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
n,m=M()
l=L()
if(m==0):
if(l.count(1)==0):
print(0)
ex... | 0 | |
812 | A | Sagheer and Crossroads | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane... | The input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light. | On a single line, print "YES" if an accident is possible, and "NO" otherwise. | [
"1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n",
"0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n",
"1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur. | 500 | [
{
"input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
... | 1,678,908,214 | 2,147,483,647 | PyPy 3 | OK | TESTS | 93 | 92 | 0 | l, x = [[int(c) for c in input()[::2]] for _ in range(4)], 0
for i, r in enumerate(l, -3):
x |= r[3] and (any([*r[:3], *[l[i + j][j] for j in range(3)]]))
print(("NO", "YES")[x]) | Title: Sagheer and Crossroads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 l... | ```python
l, x = [[int(c) for c in input()[::2]] for _ in range(4)], 0
for i, r in enumerate(l, -3):
x |= r[3] and (any([*r[:3], *[l[i + j][j] for j in range(3)]]))
print(("NO", "YES")[x])
``` | 3 | |
182 | B | Vasya's Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does n... | The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106).
The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000).
The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — th... | Print a single number — the number of times Vasya manually increased the day number by one throughout the last year. | [
"4\n2\n2 2\n",
"5\n3\n3 4 3\n",
"31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n"
] | [
"2\n",
"3\n",
"7\n"
] | In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by ... | 500 | [
{
"input": "4\n2\n2 2",
"output": "2"
},
{
"input": "5\n3\n3 4 3",
"output": "3"
},
{
"input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31",
"output": "7"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n1 1",
"output": "0"
},
{
"input": "2... | 1,624,674,853 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 218 | 1,638,400 | a=int(input())
b=int(input())
l=list(map(int,input().split()))
c=0
for i in range(0,b-1):
c+=(a-l[i])
print(c) | Title: Vasya's Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any ... | ```python
a=int(input())
b=int(input())
l=list(map(int,input().split()))
c=0
for i in range(0,b-1):
c+=(a-l[i])
print(c)
``` | 3 | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,598,288,852 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 404 | 2,150,400 | n=int(input())
l=list(map(int,input().split()))
p=set(l)
q=sorted(p)
if(len(q)<2):
print("NO")
else:
print(b[1])
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
n=int(input())
l=list(map(int,input().split()))
p=set(l)
q=sorted(p)
if(len(q)<2):
print("NO")
else:
print(b[1])
``` | -1 |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,591,629,709 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 307,200 | n,d=map(int,input().split())
s=input()
k,m,flag=0,0,0
while k<=n-1:
if k+d<n and s[k+d]=='1':
m+=1
k+=d
if k==n-1:
break
# print(k,m)
else:
if k+d>n:
j=n
else:
j=k+d
if '1' in s[k+1:j]:
m+=1
for i in range(k+1,j):
if s[i]=='1':
k+=i
break
# print(k,m)... | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
n,d=map(int,input().split())
s=input()
k,m,flag=0,0,0
while k<=n-1:
if k+d<n and s[k+d]=='1':
m+=1
k+=d
if k==n-1:
break
# print(k,m)
else:
if k+d>n:
j=n
else:
j=k+d
if '1' in s[k+1:j]:
m+=1
for i in range(k+1,j):
if s[i]=='1':
k+=i
break
# ... | 0 | |
401 | C | Team | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ... | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1. | In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. | [
"1 2\n",
"4 8\n",
"4 10\n",
"1 5\n"
] | [
"101\n",
"110110110101\n",
"11011011011011\n",
"-1\n"
] | none | 1,500 | [
{
"input": "1 2",
"output": "101"
},
{
"input": "4 8",
"output": "110110110101"
},
{
"input": "4 10",
"output": "11011011011011"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "3 4",
"output": "1010101"
},
{
"input": "3 10",
"output": "-1"
},
... | 1,698,079,926 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 32 | 1,000 | 13,721,600 | def s():
zer, one = map(int, input().split())
if zer == one + 1:
print("0" + "10"*one)
return
if zer > one+1:
print(-1)
return
if zer == one:
print("01"*one)
return
res = ""
while zer != one and zer > 0 and one > 0:
res += "110... | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each t... | ```python
def s():
zer, one = map(int, input().split())
if zer == one + 1:
print("0" + "10"*one)
return
if zer > one+1:
print(-1)
return
if zer == one:
print("01"*one)
return
res = ""
while zer != one and zer > 0 and one > 0:
r... | 0 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,688,749,584 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | x=input()
x=x[1:-1]
l=x.split(", ")
l=[l.strip() for l in l]
dl=set(l)
nd=len(ds)
if(nd==1 and list(dl)[0]==''):
nd=0
print(nd) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
x=input()
x=x[1:-1]
l=x.split(", ")
l=[l.strip() for l in l]
dl=set(l)
nd=len(ds)
if(nd==1 and list(dl)[0]==''):
nd=0
print(nd)
``` | -1 | |
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s... | The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img al... | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "335343... | 1,697,603,754 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 |
def is_only_zero_or_one(lst):
return not any(ele for ele in lst if ele != 0 and ele != 1)
def solve(T):
if is_only_zero_or_one(T):
return T
T2=[]
for x in T:
T1 =[]
if x == 0 or x==1:
T1.append(x)
else:
T1.append(int(x//2))
T1.ap... | Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta... | ```python
def is_only_zero_or_one(lst):
return not any(ele for ele in lst if ele != 0 and ele != 1)
def solve(T):
if is_only_zero_or_one(T):
return T
T2=[]
for x in T:
T1 =[]
if x == 0 or x==1:
T1.append(x)
else:
T1.append(int(x//2))
... | 0 | |
899 | B | Months and Years | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.
... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=24) — the number of integers.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (28<=≤<=*a**i*<=≤<=31) — the numbers you are to check. | If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in arbitrary case (small or large). | [
"4\n31 31 30 31\n",
"2\n30 30\n",
"5\n29 31 30 31 30\n",
"3\n31 28 30\n",
"3\n31 31 28\n"
] | [
"Yes\n\n",
"No\n\n",
"Yes\n\n",
"No\n\n",
"Yes\n\n"
] | In the first example the integers can denote months July, August, September and October.
In the second example the answer is no, because there are no two consecutive months each having 30 days.
In the third example the months are: February (leap year) — March — April – May — June.
In the fourth example the number of... | 1,000 | [
{
"input": "4\n31 31 30 31",
"output": "Yes"
},
{
"input": "2\n30 30",
"output": "No"
},
{
"input": "5\n29 31 30 31 30",
"output": "Yes"
},
{
"input": "3\n31 28 30",
"output": "No"
},
{
"input": "3\n31 31 28",
"output": "Yes"
},
{
"input": "24\n29 28 3... | 1,588,612,316 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 140 | 0 | n=int(input())
a=[int(i) for i in input().split()]
d='312831303130313130313031312831303130313130313031'
e='312931303130313130313031312931303130313130313031'
s=''
for i in range(0,len(a)):
s=s+str(a[i])
if((s in d) or (s in e)):
print("YES")
else:
print("NO")
| Title: Months and Years
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, ... | ```python
n=int(input())
a=[int(i) for i in input().split()]
d='312831303130313130313031312831303130313130313031'
e='312931303130313130313031312931303130313130313031'
s=''
for i in range(0,len(a)):
s=s+str(a[i])
if((s in d) or (s in e)):
print("YES")
else:
print("NO")
``` | 0 | |
979 | B | Treasure Hunt | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination... | The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the lengt... | Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw". | [
"3\nKuroo\nShiro\nKatie\n",
"7\ntreasurehunt\nthreefriends\nhiCodeforces\n",
"1\nabcabc\ncbabac\nababca\n",
"15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n"
] | [
"Kuro\n",
"Shiro\n",
"Katie\n",
"Draw\n"
] | In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Th... | 1,000 | [
{
"input": "3\nKuroo\nShiro\nKatie",
"output": "Kuro"
},
{
"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces",
"output": "Shiro"
},
{
"input": "1\nabcabc\ncbabac\nababca",
"output": "Katie"
},
{
"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE",
"output": "Draw"
},
{... | 1,546,669,010 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 409,600 | import sys
from collections import defaultdict
def highestFrequesncyListElement(listOfElements):
counts = defaultdict(int)
for el in listOfElements:
counts[el] += 1
return max(counts.items(), key=lambda x: x[1])
def getScore(turns, ribbon):
stringLength = len(ribbon)
letters = list(ribbon)
letters.sort()
(... | Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friend... | ```python
import sys
from collections import defaultdict
def highestFrequesncyListElement(listOfElements):
counts = defaultdict(int)
for el in listOfElements:
counts[el] += 1
return max(counts.items(), key=lambda x: x[1])
def getScore(turns, ribbon):
stringLength = len(ribbon)
letters = list(ribbon)
letters... | 0 | |
977 | C | Less or Equal | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$.
Note that the sequence can contain equal elements.
If there is no suc... | The first line of the input contains integer numbers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $0 \le k \le n$). The second line of the input contains $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the sequence itself. | Print any integer number $x$ from range $[1; 10^9]$ such that exactly $k$ elements of given sequence is less or equal to $x$.
If there is no such $x$, print "-1" (without quotes). | [
"7 4\n3 7 5 1 10 3 20\n",
"7 2\n3 7 5 1 10 3 20\n"
] | [
"6",
"-1\n"
] | In the first example $5$ is also a valid answer because the elements with indices $[1, 3, 4, 6]$ is less than or equal to $5$ and obviously less than or equal to $6$.
In the second example you cannot choose any number that only $2$ elements of the given sequence will be less than or equal to this number because $3$ el... | 0 | [
{
"input": "7 4\n3 7 5 1 10 3 20",
"output": "5"
},
{
"input": "7 2\n3 7 5 1 10 3 20",
"output": "-1"
},
{
"input": "1 0\n1",
"output": "-1"
},
{
"input": "1 0\n2",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "3 ... | 1,698,300,060 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 30 | 0 | def main():
n, k = map(int, input().split())
nums = list(map(int, input().split()))
assert len(nums) == n
nums.sort()
if k == n:
return nums[-1] + 1
item_greater = nums[k]
item_before = nums[k-1]
if item_before == item_greater or item_before + 1 == item_greater:
... | Title: Less or Equal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are... | ```python
def main():
n, k = map(int, input().split())
nums = list(map(int, input().split()))
assert len(nums) == n
nums.sort()
if k == n:
return nums[-1] + 1
item_greater = nums[k]
item_before = nums[k-1]
if item_before == item_greater or item_before + 1 == item_greater... | 0 | |
329 | B | Biridian Forest | PROGRAMMING | 1,500 | [
"dfs and similar",
"shortest paths"
] | null | null | You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.
The forest
The Biridian Forest is a two-dimensional grid consisting of *r* rows and *c* columns. Each cell in Biridian Forest may contain a tree, or may be vac... | The first line consists of two integers: *r* and *c* (1<=≤<=*r*,<=*c*<=≤<=1000), denoting the number of rows and the number of columns in Biridian Forest. The next *r* rows will each depict a row of the map, where each character represents the content of a single cell:
- 'T': A cell occupied by a tree. - 'S': An em... | A single line denoted the minimum possible number of mikemon battles that you have to participate in if you pick a strategy that minimize this number. | [
"5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000\n",
"1 4\nSE23\n"
] | [
"3\n",
"2\n"
] | The following picture illustrates the first example. The blue line denotes a possible sequence of moves that you should post in your blog:
The three breeders on the left side of the map will be able to battle you — the lone breeder can simply stay in his place until you come while the other two breeders can move to wh... | 1,000 | [
{
"input": "5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000",
"output": "3"
},
{
"input": "1 4\nSE23",
"output": "2"
},
{
"input": "3 3\n000\nS0E\n000",
"output": "0"
},
{
"input": "5 5\nS9999\nTTTT9\n99999\n9TTTT\n9999E",
"output": "135"
},
{
"input": "1 10\n9T9... | 1,631,350,868 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 158,208,000 | try:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
... | Title: Biridian Forest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.
The forest
The Biridian Forest is a two-dimensional grid c... | ```python
try:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as ... | 0 | |
598 | A | Tricky Sum | PROGRAMMING | 900 | [
"math"
] | null | null | In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for *t* values of *n*. | The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed.
Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). | Print the requested sum for each of *t* integers *n* given in the input. | [
"2\n4\n1000000000\n"
] | [
"-4\n499999998352516354\n"
] | The answer for the first sample is explained in the statement. | 0 | [
{
"input": "2\n4\n1000000000",
"output": "-4\n499999998352516354"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25"
},
{
"input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53",
"output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130... | 1,656,228,170 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 4,505,600 | ntasks=int(input())
powersof2=[]
a=1
while a<10**10:
powersof2.append(a)
a*=2
for i in range(ntasks):
answer=0
task=int(input())
taskl=list(range(1,task+1))
for i in taskl:#for i in range(task):
if i in powersof2:
answer-=i
else:
answer+=i
... | Title: Tricky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be... | ```python
ntasks=int(input())
powersof2=[]
a=1
while a<10**10:
powersof2.append(a)
a*=2
for i in range(ntasks):
answer=0
task=int(input())
taskl=list(range(1,task+1))
for i in taskl:#for i in range(task):
if i in powersof2:
answer-=i
else:
an... | -1 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,625,745,470 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | a = list(map(int, input().split()))
print((a[0] + a[1]) * 2 if a[0] + a[1] < a[2] else a[0] + a[1] + a[2])
| Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
a = list(map(int, input().split()))
print((a[0] + a[1]) * 2 if a[0] + a[1] < a[2] else a[0] + a[1] + a[2])
``` | 0 | |
735 | C | Tennis Championship | PROGRAMMING | 1,600 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are st... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1018) — the number of players to participate in the tournament. | Print the maximum number of games in which the winner of the tournament can take part. | [
"2\n",
"3\n",
"4\n",
"10\n"
] | [
"1\n",
"2\n",
"2\n",
"4\n"
] | In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't p... | 1,750 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "1000",
"output": "14"
},
{
"input": "2500",
"output": "15"
},
{
"input": "690000",
"output"... | 1,480,945,419 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | import math
n = int(input())
res = 2
a = 2
b = 3
while(a+b<n):
res+=1
a,b = b,a+b
print(res)
| Title: Tennis Championship
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very firs... | ```python
import math
n = int(input())
res = 2
a = 2
b = 3
while(a+b<n):
res+=1
a,b = b,a+b
print(res)
``` | 0 | |
779 | C | Dishonest Sellers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*.
Not all of sellers are honest, so now some products could be more expensive than after a week... | In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during d... | Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now. | [
"3 1\n5 4 6\n3 1 5\n",
"5 3\n3 4 7 10 3\n4 5 5 12 5\n"
] | [
"10\n",
"25\n"
] | In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week ... | 1,000 | [
{
"input": "3 1\n5 4 6\n3 1 5",
"output": "10"
},
{
"input": "5 3\n3 4 7 10 3\n4 5 5 12 5",
"output": "25"
},
{
"input": "1 0\n9\n8",
"output": "8"
},
{
"input": "2 0\n4 10\n1 2",
"output": "3"
},
{
"input": "4 2\n19 5 17 13\n3 18 8 10",
"output": "29"
},
... | 1,493,467,722 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 21 | 358 | 22,220,800 | n, k = map(int, input().split() )
a = list(map(int, input().split() ) )
b = list(map(int, input().split() ) )
c = 0
ans = sum(a)
dif = [0] * n
for i in range( len(a) ):
dif[i] = b[i]-a[i]
dif = sorted(dif)
for i in range( len(dif) ):
if dif[i] < 0:
ans += dif[i]
c+=1
if c ==... | Title: Dishonest Sellers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be... | ```python
n, k = map(int, input().split() )
a = list(map(int, input().split() ) )
b = list(map(int, input().split() ) )
c = 0
ans = sum(a)
dif = [0] * n
for i in range( len(a) ):
dif[i] = b[i]-a[i]
dif = sorted(dif)
for i in range( len(dif) ):
if dif[i] < 0:
ans += dif[i]
c+=1
... | 0 | |
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRR... | 1,637,318,254 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x=int(input())
y=input()
i=0
while i< len(y)-1:
if y[i]+y[i+1] in ('ur','ru'):
i=i+2
x=x-1
else:
i=i+1
print(x) | Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence movi... | ```python
x=int(input())
y=input()
i=0
while i< len(y)-1:
if y[i]+y[i+1] in ('ur','ru'):
i=i+2
x=x-1
else:
i=i+1
print(x)
``` | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.