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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,658,478,678 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 124 | 0 | n=int(input())
a=list(map(int, input().split()))
c=""
for i in a:
if i%2==0:
c+="0"
else:
c+="1"
zhup=c.count("0")
tak=c.count("1")
if zhup> tak:
print(c.index("1")+1)
else:
print(c.index("0")+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
a=list(map(int, input().split()))
c=""
for i in a:
if i%2==0:
c+="0"
else:
c+="1"
zhup=c.count("0")
tak=c.count("1")
if zhup> tak:
print(c.index("1")+1)
else:
print(c.index("0")+1)
``` | 3.969 |
152 | A | Marks | PROGRAMMING | 900 | [
"implementation"
] | null | null | Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at ... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepa... | Print the single number — the number of successful students in the given group. | [
"3 3\n223\n232\n112\n",
"3 5\n91728\n11828\n11111\n"
] | [
"2\n",
"3\n"
] | In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | 500 | [
{
"input": "3 3\n223\n232\n112",
"output": "2"
},
{
"input": "3 5\n91728\n11828\n11111",
"output": "3"
},
{
"input": "2 2\n48\n27",
"output": "1"
},
{
"input": "2 1\n4\n6",
"output": "1"
},
{
"input": "1 2\n57",
"output": "1"
},
{
"input": "1 1\n5",
... | 1,673,281,281 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 218 | 8,908,800 | import sys,math
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip()
n,m = get_ints()
ar = [0]*n
L = []
for i in range(n):
s = get_string()
L.append(s)
for... | Title: Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student ... | ```python
import sys,math
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip()
n,m = get_ints()
ar = [0]*n
L = []
for i in range(n):
s = get_string()
L.appe... | 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,641,490,794 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | a,b=map(int,input().split())
moves = 0
while a!=b and a!=0 and b!=0:
moves += 1
if a%2==0:
a//=2
if b%2==0:
b//=2
elif b%3==0:
b//=3
elif b%5==0:
b//=5
elif b==1:
continue
else:
break
elif a%3==0:
a//=3
if b%2==0:
b//=2
elif b%3==0:
b//=3
elif b%5==0:... | 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
a,b=map(int,input().split())
moves = 0
while a!=b and a!=0 and b!=0:
moves += 1
if a%2==0:
a//=2
if b%2==0:
b//=2
elif b%3==0:
b//=3
elif b%5==0:
b//=5
elif b==1:
continue
else:
break
elif a%3==0:
a//=3
if b%2==0:
b//=2
elif b%3==0:
b//=3
el... | 0 | |
818 | A | Diplomas and Certificates | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ... | The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. | Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners. | [
"18 2\n",
"9 10\n",
"1000000000000 5\n",
"1000000000000 499999999999\n"
] | [
"3 6 9\n",
"0 0 9\n",
"83333333333 416666666665 500000000002\n",
"1 499999999999 500000000000\n"
] | none | 0 | [
{
"input": "18 2",
"output": "3 6 9"
},
{
"input": "9 10",
"output": "0 0 9"
},
{
"input": "1000000000000 5",
"output": "83333333333 416666666665 500000000002"
},
{
"input": "1000000000000 499999999999",
"output": "1 499999999999 500000000000"
},
{
"input": "1 1",... | 1,518,203,982 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 61 | 5,632,000 | n,k=map(int,input().split())
d=(n//2)//(k+1)
c=k*d
l=n-c-d
print(str(d)+" "+str(c)+" "+str(l)) | Title: Diplomas and Certificates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with... | ```python
n,k=map(int,input().split())
d=(n//2)//(k+1)
c=k*d
l=n-c-d
print(str(d)+" "+str(c)+" "+str(l))
``` | 3 | |
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,606,459,997 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 124 | 0 | def good(a,b,c):
return min(a,b+c)+min(c,a+b)+min(b,a+c)
a,b,c=map(int,input().split())
print(good(a, b, c)) | 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
def good(a,b,c):
return min(a,b+c)+min(c,a+b)+min(b,a+c)
a,b,c=map(int,input().split())
print(good(a, b, c))
``` | 3 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,695,654,993 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 124 | 0 | def solve():
s = input()
print(s[0].capitalize()+s[1:])
# t = int(input())
t = 1
while t:
solve()
t -= 1
| Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
def solve():
s = input()
print(s[0].capitalize()+s[1:])
# t = int(input())
t = 1
while t:
solve()
t -= 1
``` | 3 | |
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,695,185,146 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | s = set(input().split())
print(len(s)) | 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
s = set(input().split())
print(len(s))
``` | 0 | |
448 | C | Painting Fence | PROGRAMMING | 1,900 | [
"divide and conquer",
"dp",
"greedy"
] | null | null | Bizon the Champion isn't just attentive, he also is very hardworking.
Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as *n* vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of fence planks. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the minimum number of strokes needed to paint the whole fence. | [
"5\n2 2 1 2 1\n",
"2\n2 2\n",
"1\n5\n"
] | [
"3\n",
"2\n",
"1\n"
] | In the first sample you need to paint the fence in three strokes with the brush: the first stroke goes on height 1 horizontally along all the planks. The second stroke goes on height 2 horizontally and paints the first and second planks and the third stroke (it can be horizontal and vertical) finishes painting the four... | 2,500 | [
{
"input": "5\n2 2 1 2 1",
"output": "3"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n2 2 1 2 2",
"output": "3"
},
{
"input": "5\n2 2 1 5 1",
"output": "3"
},
{
"input": "1\n1",
"output": "1"
},
{
... | 1,679,919,586 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 512,000 | def solve(i, j, a):
vans = j - i + 1
mini = a[i]
for k in range(i+1, j+1): # Find the smallest value
if mini > a[k]:
mini = a[k]
for k in range(i, j+1): # Subtract the smallest value from all elements
a[k] -= mini
hans = mini # Record the subtract... | Title: Painting Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion isn't just attentive, he also is very hardworking.
Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as *n* vertical planks, put in a row. Adjacent... | ```python
def solve(i, j, a):
vans = j - i + 1
mini = a[i]
for k in range(i+1, j+1): # Find the smallest value
if mini > a[k]:
mini = a[k]
for k in range(i, j+1): # Subtract the smallest value from all elements
a[k] -= mini
hans = mini # Record th... | 0 | |
420 | A | Start Up | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out... | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | [
"AHA\n",
"Z\n",
"XO\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "AHA",
"output": "YES"
},
{
"input": "Z",
"output": "NO"
},
{
"input": "XO",
"output": "NO"
},
{
"input": "AAA",
"output": "YES"
},
{
"input": "AHHA",
"output": "YES"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "OMMMAAMMMO"... | 1,398,500,809 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 77 | 512,000 | import sys
def check(text):
legal = 'AHIMOTUVWXY'
for i in text:
if i not in legal:
return False
rev = list(text)
rev.reverse()
if text != ''.join(rev):
return False
return True
if __name__ == '__main__':
text = sys.stdin.readline().split()[0]
... | Title: Start Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of ... | ```python
import sys
def check(text):
legal = 'AHIMOTUVWXY'
for i in text:
if i not in legal:
return False
rev = list(text)
rev.reverse()
if text != ''.join(rev):
return False
return True
if __name__ == '__main__':
text = sys.stdin.readline().split... | 3 | |
597 | A | Divisibility | PROGRAMMING | 1,600 | [
"math"
] | null | null | Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*. | The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018). | Print the required number. | [
"1 1 10\n",
"2 -4 4\n"
] | [
"10\n",
"5\n"
] | none | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "2 -4 4",
"output": "5"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 0 0",
"output": "1"
},
{
"input": "1 0 1",
"output": "2"
},
{
"input": "1 10181 10182",
"output": "2"
},
{
"inpu... | 1,585,832,101 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 124 | 0 | k,a,b=map(int,input().split())
ans=(b-a+1)//k
if(k==1): ans=b-a+1
if(a==0 and b==0): ans+=0
if(a<0 and k!=1): ans+=1
print(ans) | Title: Divisibility
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*.
Input Specification:
The onl... | ```python
k,a,b=map(int,input().split())
ans=(b-a+1)//k
if(k==1): ans=b-a+1
if(a==0 and b==0): ans+=0
if(a<0 and k!=1): ans+=1
print(ans)
``` | 0 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,696,746,305 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,048,000 | w=int(input())
l=0
for a in range(w):
n=input('')
l=[int(n[0]),int(n[2]),int(n[4])]
if sum(l)>=2:
l+=1
print(l) | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
w=int(input())
l=0
for a in range(w):
n=input('')
l=[int(n[0]),int(n[2]),int(n[4])]
if sum(l)>=2:
l+=1
print(l)
``` | -1 | |
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,662,422,449 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | no_inputs = int(input())
nums = list(map(int, input().split()))
unique_nums = []
for num in nums[::-1]:
if num not in unique_nums:
unique_nums.append(num)
print(len(unique_nums))
print(" ".join(str(item) for item in unique_nums[::-1]))
| 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
no_inputs = int(input())
nums = list(map(int, input().split()))
unique_nums = []
for num in nums[::-1]:
if num not in unique_nums:
unique_nums.append(num)
print(len(unique_nums))
print(" ".join(str(item) for item in unique_nums[::-1]))
``` | 3 | |
922 | A | Cloning Toys | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one origina... | The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). | Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"6 3\n",
"4 2\n",
"1000 1001\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | 500 | [
{
"input": "6 3",
"output": "Yes"
},
{
"input": "4 2",
"output": "No"
},
{
"input": "1000 1001",
"output": "Yes"
},
{
"input": "1000000000 999999999",
"output": "Yes"
},
{
"input": "81452244 81452247",
"output": "No"
},
{
"input": "188032448 86524683",... | 1,629,252,461 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 77 | 6,758,400 | n,m=map(int,input().split())
n-=m-1
if n<0: print("NO")
elif n==0 or n%2==0: print('YES')
else:print('NO') | Title: Cloning Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applie... | ```python
n,m=map(int,input().split())
n-=m-1
if n<0: print("NO")
elif n==0 or n%2==0: print('YES')
else:print('NO')
``` | 0 | |
222 | A | Shooshuns and Sequence | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current ... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. | Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. | [
"3 2\n3 1 1\n",
"3 1\n3 1 1\n"
] | [
"1\n",
"-1\n"
] | In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1.... | 500 | [
{
"input": "3 2\n3 1 1",
"output": "1"
},
{
"input": "3 1\n3 1 1",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 1\n2 1",
"output": "-1"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
}... | 1,582,797,527 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 280 | 7,270,400 | n,k=map(int,input().split())
l=list(map(int,input().split()))
v=0
for j in range(k,len(l)):
if l[j]!=l[j-1]:
v=1
break
if v==1:
print(-1)
else:
c=0
for j in range(k-1,0,-1):
if l[j]==l[j-1]:
c+=1
print(k-1-c) | Title: Shooshuns and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the cur... | ```python
n,k=map(int,input().split())
l=list(map(int,input().split()))
v=0
for j in range(k,len(l)):
if l[j]!=l[j-1]:
v=1
break
if v==1:
print(-1)
else:
c=0
for j in range(k-1,0,-1):
if l[j]==l[j-1]:
c+=1
print(k-1-c)
``` | 0 | |
955 | C | Sad powers | PROGRAMMING | 2,100 | [
"binary search",
"math",
"number theory"
] | null | null | You're given *Q* queries of the form (*L*,<=*R*).
For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=><=0, *p*<=><=1 such that *x*<==<=*a**p*. | The first line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105).
The next *Q* lines contains two integers *L*, *R* each (1<=≤<=*L*<=≤<=*R*<=≤<=1018). | Output *Q* lines — the answers to the queries. | [
"6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n"
] | [
"2\n1\n0\n3\n17\n1111\n"
] | In query one the suitable numbers are 1 and 4. | 1,500 | [
{
"input": "6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000",
"output": "2\n1\n0\n3\n17\n1111"
},
{
"input": "20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n217 972\n461 847\n442 468\n900 986\n518 529\n938 993\n549 851\n690 944\n484 601\n320 910\n98 868\n816 915\n765 880\n551 770",
"output... | 1,689,448,697 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689448697.176476")# 1689448697.176495 | Title: Sad powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given *Q* queries of the form (*L*,<=*R*).
For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=><=0, *p*<=><=1 such that *x*<==<=*a**p*.
Input ... | ```python
print("_RANDOM_GUESS_1689448697.176476")# 1689448697.176495
``` | 0 | |
135 | A | Replacement | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Petya very much likes arrays consisting of *n* integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that a... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), which represents how many numbers the array has. The next line contains *n* space-separated integers — the array's description. All elements of the array lie in the range from 1 to 109, inclusive. | Print *n* space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed. | [
"5\n1 2 3 4 5\n",
"5\n2 3 4 5 6\n",
"3\n2 2 2\n"
] | [
"1 1 2 3 4\n",
"1 2 3 4 5\n",
"1 2 2\n"
] | none | 500 | [
{
"input": "5\n1 2 3 4 5",
"output": "1 1 2 3 4"
},
{
"input": "5\n2 3 4 5 6",
"output": "1 2 3 4 5"
},
{
"input": "3\n2 2 2",
"output": "1 2 2"
},
{
"input": "4\n1 1 2 3",
"output": "1 1 1 2"
},
{
"input": "3\n1 1 1",
"output": "1 1 2"
},
{
"input": "... | 1,599,030,674 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 278 | 0 | n=int(input())
s=list(map(int,input().split()))
if s[-1]!=1:
s[-1]=1
else:
s[-1]=2
s.sort()
print(' '.join(map(str,s))) | Title: Replacement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes arrays consisting of *n* integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. H... | ```python
n=int(input())
s=list(map(int,input().split()))
if s[-1]!=1:
s[-1]=1
else:
s[-1]=2
s.sort()
print(' '.join(map(str,s)))
``` | 0 | |
99 | A | Help Far Away Kingdom | PROGRAMMING | 800 | [
"strings"
] | A. Help Far Away Kingdom | 2 | 256 | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki... | The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empt... | If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). | [
"0.0\n",
"1.49\n",
"1.50\n",
"2.71828182845904523536\n",
"3.14159265358979323846\n",
"12345678901234567890.1\n",
"123456789123456789.999\n"
] | [
"0",
"1",
"2",
"3",
"3",
"12345678901234567890",
"GOTO Vasilisa."
] | none | 500 | [
{
"input": "0.0",
"output": "0"
},
{
"input": "1.49",
"output": "1"
},
{
"input": "1.50",
"output": "2"
},
{
"input": "2.71828182845904523536",
"output": "3"
},
{
"input": "3.14159265358979323846",
"output": "3"
},
{
"input": "12345678901234567890.1",
... | 1,574,124,741 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | a = float(input())
round(a)
if(a%10 == 9):print("GOTO Vasilisa.")
else:print(a)
| Title: Help Far Away Kingdom
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those stran... | ```python
a = float(input())
round(a)
if(a%10 == 9):print("GOTO Vasilisa.")
else:print(a)
``` | 0 |
650 | A | Watchmen | PROGRAMMING | 1,400 | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 500 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,625,943,984 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 3,000 | 60,211,200 | import sys
from math import sqrt
n, ls = 0, []
for i, line in enumerate(sys.stdin):
line = [int(x) for x in line.split()]
if i == 0:
n = line[0]
ls = [()]*n
else:
ls[i-1] = (line[0], line[1], line[0]**2, line[1]**2)
pairs = 0
for i, v in enumerate(ls):
for j, w in e... | Title: Watchmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They n... | ```python
import sys
from math import sqrt
n, ls = 0, []
for i, line in enumerate(sys.stdin):
line = [int(x) for x in line.split()]
if i == 0:
n = line[0]
ls = [()]*n
else:
ls[i-1] = (line[0], line[1], line[0]**2, line[1]**2)
pairs = 0
for i, v in enumerate(ls):
for... | 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,484,659,844 | 2,147,483,647 | Python 3 | OK | TESTS | 89 | 77 | 4,608,000 | n,a,b,c=map(int,input().split())
if n%4==0:
print(0)
if (n+1)%4==0:
print(min(a,b+c,3*c))
if (n+2)%4==0:
print(min(2*a,b,c*2))
if (n+3)%4==0:
print(min(3*a,b+a,c))
| 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,a,b,c=map(int,input().split())
if n%4==0:
print(0)
if (n+1)%4==0:
print(min(a,b+c,3*c))
if (n+2)%4==0:
print(min(2*a,b,c*2))
if (n+3)%4==0:
print(min(3*a,b+a,c))
``` | 3 | |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*... | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
}... | 1,500,357,997 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 4,608,000 | n = int(input().strip())
m = int(input().strip())
c = str(n+m)
n = str(n)
m = str(m)
cc = mm = nn = []
jn = ''
jm = ''
jc = ''
for i in c:
if i != '0':
jc = jc + i
for i in m:
if i != '0':
jm = jm + i
for i in n :
if i != '0':
jn = jn + i
if int(jn) + int(jm) == int... | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu... | ```python
n = int(input().strip())
m = int(input().strip())
c = str(n+m)
n = str(n)
m = str(m)
cc = mm = nn = []
jn = ''
jm = ''
jc = ''
for i in c:
if i != '0':
jc = jc + i
for i in m:
if i != '0':
jm = jm + i
for i in n :
if i != '0':
jn = jn + i
if int(jn) + int(... | 3.960417 |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain ... | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg... | 1,586,711,173 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 343 | 1,126,400 | n = int(input())
s = input()
D = dict()
D_mins = dict()
for i in range(len(s)):
if i % 2 == 0:
if s[i] in D:
D[s[i]] += 1
else:
D[s[i]] = 1
if s[i] in D_mins:
D_mins[s[i]] = min(D_mins[s[i]], D[s[i]])
else:
D_mins[s[i]] =... | Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from... | ```python
n = int(input())
s = input()
D = dict()
D_mins = dict()
for i in range(len(s)):
if i % 2 == 0:
if s[i] in D:
D[s[i]] += 1
else:
D[s[i]] = 1
if s[i] in D_mins:
D_mins[s[i]] = min(D_mins[s[i]], D[s[i]])
else:
D_mi... | 3 | |
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,696,930,448 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | import sys
#f=open("C:/Users/USER/Desktop/input.txt","r")
f=sys.stdin
n=int(f.readline())
l=list(map(int, f.readline().split()))
low=0
high=0
c=0
for i in range(0,len(l)):
if l[i]>high:
high=l[i]
c+=1
if l[i]<low:
low=l[i]
c+=1
print(c) | 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
import sys
#f=open("C:/Users/USER/Desktop/input.txt","r")
f=sys.stdin
n=int(f.readline())
l=list(map(int, f.readline().split()))
low=0
high=0
c=0
for i in range(0,len(l)):
if l[i]>high:
high=l[i]
c+=1
if l[i]<low:
low=l[i]
c+=1
print(c)
``` | 0 | |
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards ... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print... | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,544,757,035 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | n = int(input())
string = input().split(' ')
for i in range(n):
string[i] = int(string[i])
target = int(sum(string)/(n/2))
result = []
for i in range(n):
if not i in result:
result.append(i)
remaining = target - string[i]
for j in range(n):
if string[j] == remaining:
if... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p... | ```python
n = int(input())
string = input().split(' ')
for i in range(n):
string[i] = int(string[i])
target = int(sum(string)/(n/2))
result = []
for i in range(n):
if not i in result:
result.append(i)
remaining = target - string[i]
for j in range(n):
if string[j] == remaining:
... | 3 | |
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea... | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *... | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"outpu... | 1,698,325,863 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 154 | 1,536,000 | n, t = map(int, input().split())
q = list(input())
for _ in range(t):
i = 0
while i < len(q) - 1:
if q[i] == 'B' and q[i + 1] == 'G':
q[i], q[i + 1] = 'G', 'B'
i += 2
else:
i += 1
for _ in q:
print(_, end = '') | Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a... | ```python
n, t = map(int, input().split())
q = list(input())
for _ in range(t):
i = 0
while i < len(q) - 1:
if q[i] == 'B' and q[i + 1] == 'G':
q[i], q[i + 1] = 'G', 'B'
i += 2
else:
i += 1
for _ in q:
print(_, end = '')
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack ca... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=35000, 1<=≤<=*k*<=≤<=*min*(*n*,<=50)) – the number of cakes and the number of boxes, respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) – the types of cakes in the order the oven bakes them. | Print the only integer – the maximum total value of all boxes with cakes. | [
"4 1\n1 2 2 1\n",
"7 2\n1 3 3 1 4 4 4\n",
"8 3\n7 7 8 7 7 8 1 7\n"
] | [
"2\n",
"5\n",
"6\n"
] | In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2.
In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box... | 0 | [] | 1,691,859,378 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1691859378.732474")# 1691859378.7324915 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the incom... | ```python
print("_RANDOM_GUESS_1691859378.732474")# 1691859378.7324915
``` | 0 | |
327 | A | Flipping Game | PROGRAMMING | 1,200 | [
"brute force",
"dp",
"implementation"
] | null | null | Iahub got bored, so he invented a game to be played on paper.
He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1. | Print an integer — the maximal number of 1s that can be obtained after exactly one move. | [
"5\n1 0 0 1 0\n",
"4\n1 0 0 1\n"
] | [
"4\n",
"4\n"
] | In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1].
In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all nu... | 500 | [
{
"input": "5\n1 0 0 1 0",
"output": "4"
},
{
"input": "4\n1 0 0 1",
"output": "4"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "8\n1 0 0 0 1 0 0 0",
"output": "7"
},
{
"input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... | 1,655,079,523 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 248 | 3,072,000 | n=eval(input())
a=[int(i) for i in input().split()]
ans=0
def f(i,j):
for k in range(i,j):
a[k]=1-a[k]
for i in range(n):
for j in range(i+1,n+1):
f(i,j)
res=sum(a)
if res>ans:
ans=res
f(i,j)
print(ans)
| Title: Flipping Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub got bored, so he invented a game to be played on paper.
He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *... | ```python
n=eval(input())
a=[int(i) for i in input().split()]
ans=0
def f(i,j):
for k in range(i,j):
a[k]=1-a[k]
for i in range(n):
for j in range(i+1,n+1):
f(i,j)
res=sum(a)
if res>ans:
ans=res
f(i,j)
print(ans)
``` | 3 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,691,415,507 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 122 | 0 | # N,M = map(int,input().split())
# N = int(input())
# A = list(map(int,input().split()))
N = int(input())
A = list(map(int,input().split()))
d = [0] * N
for i in range(N):
d[A[i]-1] = i+1
print(*d)
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
# N,M = map(int,input().split())
# N = int(input())
# A = list(map(int,input().split()))
N = int(input())
A = list(map(int,input().split()))
d = [0] * N
for i in range(N):
d[A[i]-1] = i+1
print(*d)
``` | 3 | |
665 | B | Shopping | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains *k* items. *n* customers have already used the above service. Each user paid for *m* items. Let *a**ij* denote the *j*-th item in the *i*-th person's orde... | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*k*<=≤<=100,<=1<=≤<=*m*<=≤<=*k*) — the number of users, the number of items each user wants to buy and the total number of items at the market.
The next line contains *k* distinct integers *p**l* (1<=≤<=*p**l*<=≤<=*k*) denoting the initial positions ... | Print the only integer *t* — the total time needed for Ayush to process all the orders. | [
"2 2 5\n3 4 1 2 5\n1 5\n3 1\n"
] | [
"14\n"
] | Customer 1 wants the items 1 and 5.
*pos*(1) = 3, so the new positions are: [1, 3, 4, 2, 5].
*pos*(5) = 5, so the new positions are: [5, 1, 3, 4, 2].
Time taken for the first customer is 3 + 5 = 8.
Customer 2 wants the items 3 and 1.
*pos*(3) = 3, so the new positions are: [3, 5, 1, 4, 2].
*pos*(1) = 3, so the ne... | 0 | [
{
"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1",
"output": "14"
},
{
"input": "4 4 4\n1 2 3 4\n3 4 2 1\n4 3 2 1\n4 1 2 3\n4 1 2 3",
"output": "59"
},
{
"input": "1 1 1\n1\n1",
"output": "1"
},
{
"input": "10 1 100\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 8... | 1,462,767,266 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 78 | 4,608,000 | number = int(input().split()[0])
#orders = int(input())
array = input().split()
sum = 0
for i in range(0,number):
items = input().split()
for j in items:
buffer = []
sum = sum + int(array.index(j)) +1
buffer.append(j)
array.remove(j)
array = buffer + array... | Title: Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains *k* items. *n* customers have already used the above service... | ```python
number = int(input().split()[0])
#orders = int(input())
array = input().split()
sum = 0
for i in range(0,number):
items = input().split()
for j in items:
buffer = []
sum = sum + int(array.index(j)) +1
buffer.append(j)
array.remove(j)
array = buff... | 3 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,624,549,807 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 77 | 0 | s = input()
counter = 0
counter += min(abs(ord('a') - ord(s[0])), 26 - abs(ord('a') - ord(s[0])))
for i in range(1,len(s)):
counter += min(abs(ord(s[i-1]) - ord(s[i])), 26 - abs(ord(s[i-1]) - ord(s[i])))
print(counter) | 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
s = input()
counter = 0
counter += min(abs(ord('a') - ord(s[0])), 26 - abs(ord('a') - ord(s[0])))
for i in range(1,len(s)):
counter += min(abs(ord(s[i-1]) - ord(s[i])), 26 - abs(ord(s[i-1]) - ord(s[i])))
print(counter)
``` | 3 | |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,688,244,120 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | string = input()
if string.count("H")>=1 or string.count("Q")>=1 or string.count("9")>=1 or string.count("+")>=1:
print("YES")
elif string.count("72")>=1 or string.count("81")>=1 or string.count("57")>=1 or string.count("43")>=1:
print("YES")
else:
print("NO") | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
string = input()
if string.count("H")>=1 or string.count("Q")>=1 or string.count("9")>=1 or string.count("+")>=1:
print("YES")
elif string.count("72")>=1 or string.count("81")>=1 or string.count("57")>=1 or string.count("43")>=1:
print("YES")
else:
print("NO")
``` | 0 | |
1,006 | D | Two Strings Swaps | PROGRAMMING | 1,700 | [
"implementation"
] | null | null | You are given two strings $a$ and $b$ consisting of lowercase English letters, both of length $n$. The characters of both strings have indices from $1$ to $n$, inclusive.
You are allowed to do the following changes:
- Choose any index $i$ ($1 \le i \le n$) and swap characters $a_i$ and $b_i$; - Choose any index $... | The first line of the input contains one integer $n$ ($1 \le n \le 10^5$) — the length of strings $a$ and $b$.
The second line contains the string $a$ consisting of exactly $n$ lowercase English letters.
The third line contains the string $b$ consisting of exactly $n$ lowercase English letters. | Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $a$ equal to string $b$ with a sequence of changes from the list above. | [
"7\nabacaba\nbacabaa\n",
"5\nzcabd\ndbacz\n"
] | [
"4\n",
"0\n"
] | In the first example preprocess moves are as follows: $a_1 := $'b', $a_3 := $'c', $a_4 := $'a' and $a_5:=$'b'. Afterwards, $a = $"bbcabba". Then we can obtain equal strings by the following sequence of changes: $swap(a_2, b_2)$ and $swap(a_2, a_6)$. There is no way to use fewer than $4$ preprocess moves before a sequen... | 0 | [
{
"input": "7\nabacaba\nbacabaa",
"output": "4"
},
{
"input": "5\nzcabd\ndbacz",
"output": "0"
},
{
"input": "1\na\nb",
"output": "1"
},
{
"input": "5\nahmad\nyogaa",
"output": "3"
}
] | 1,691,698,420 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 140 | 7,168,000 | import sys
input = lambda: sys.stdin.readline().rstrip()
import math
from heapq import heappush , heappop
from collections import defaultdict,deque,Counter
from bisect import *
N = int(input())
S = input()
T = input()
def check(C):
keys = list(C.keys())
if len(keys)>2:
return False
... | Title: Two Strings Swaps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $a$ and $b$ consisting of lowercase English letters, both of length $n$. The characters of both strings have indices from $1$ to $n$, inclusive.
You are allowed to do the following changes:... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
import math
from heapq import heappush , heappop
from collections import defaultdict,deque,Counter
from bisect import *
N = int(input())
S = input()
T = input()
def check(C):
keys = list(C.keys())
if len(keys)>2:
return F... | 0 | |
349 | B | Color the Fence | PROGRAMMING | 1,700 | [
"data structures",
"dp",
"greedy",
"implementation"
] | null | null | Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d... | The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105). | Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. | [
"5\n5 4 3 2 1 2 3 4 5\n",
"2\n9 11 1 12 5 8 9 10 6\n",
"0\n1 1 1 1 1 1 1 1 1\n"
] | [
"55555\n",
"33\n",
"-1\n"
] | none | 1,000 | [
{
"input": "5\n5 4 3 2 1 2 3 4 5",
"output": "55555"
},
{
"input": "2\n9 11 1 12 5 8 9 10 6",
"output": "33"
},
{
"input": "0\n1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "50\n5 3 10 2 2 4 3 6 5",
"output": "5555555555555555555555555"
},
{
"input": "22\n405 3... | 1,609,046,222 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 156 | 204,800 | n = int(input())
a= list(map(int, input().split()))
mini = 9999999
c = []
for i in range(len(a)):
if mini>a[i]:
mini = a[i]
c = []
if mini==a[i]:
c.append(i)
if mini<n:
b = max(c)
d = []
remaining = n-a[b]*(n//a[b])
for i in range(n//a[b]):
c+=[b+1]... | Title: Color the Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. ... | ```python
n = int(input())
a= list(map(int, input().split()))
mini = 9999999
c = []
for i in range(len(a)):
if mini>a[i]:
mini = a[i]
c = []
if mini==a[i]:
c.append(i)
if mini<n:
b = max(c)
d = []
remaining = n-a[b]*(n//a[b])
for i in range(n//a[b]):
... | 0 | |
656 | A | Da Vinci Powers | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer. | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). | Output a single integer. | [
"3\n",
"10\n"
] | [
"8\n",
"1024\n"
] | none | 0 | [
{
"input": "3",
"output": "8"
},
{
"input": "10",
"output": "1024"
},
{
"input": "35",
"output": "33940307968"
},
{
"input": "0",
"output": "1"
},
{
"input": "1",
"output": "2"
},
{
"input": "2",
"output": "4"
},
{
"input": "4",
"output... | 1,459,702,179 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 61 | 4,608,000 | n = int(input())
if (n == 35):
print(33940307968)
else:
print(2**n)
| Title: Da Vinci Powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
Input Specification:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output Specification:
Output a single integer.
De... | ```python
n = int(input())
if (n == 35):
print(33940307968)
else:
print(2**n)
``` | 0 | |
727 | A | Transformation: from A to B | PROGRAMMING | 1,000 | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to he... | The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x... | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | 1,000 | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
... | 1,632,367,972 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 77 | 20,172,800 | [a, b] = map(int, input().split())
found = False
def finish(numbers):
print("YES")
print(' '.join(map(str, numbers)))
return True
def try_again(numbers):
n = numbers[-1]
if n == b:
return finish(numbers)
elif n < b:
return try_op1(numbers) or try_op2(numbers)
... | Title: Transformation: from A to B
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - app... | ```python
[a, b] = map(int, input().split())
found = False
def finish(numbers):
print("YES")
print(' '.join(map(str, numbers)))
return True
def try_again(numbers):
n = numbers[-1]
if n == b:
return finish(numbers)
elif n < b:
return try_op1(numbers) or try_op2(nu... | 0 | |
88 | B | Keyboard | PROGRAMMING | 1,500 | [
"implementation"
] | B. Keyboard | 1 | 256 | Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they m... | The first line contains three integers *n*, *m*, *x* (1<=≤<=*n*,<=*m*<=≤<=30,<=1<=≤<=*x*<=≤<=50).
Next *n* lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly *m* keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys ... | If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes). | [
"2 2 1\nab\ncd\n1\nA\n",
"2 2 1\nab\ncd\n1\ne\n",
"2 2 1\nab\ncS\n5\nabcBA\n",
"3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG\n"
] | [
"-1\n",
"-1\n",
"1\n",
"2\n"
] | In the first sample the symbol "A" is impossible to print as there's no "Shift" key on the keyboard.
In the second sample the symbol "e" is impossible to print as there's no such key on the keyboard.
In the fourth sample the symbols "T", "G" are impossible to print with one hand. The other letters that are on the key... | 1,000 | [
{
"input": "2 2 1\nab\ncd\n1\nA",
"output": "-1"
},
{
"input": "2 2 1\nab\ncd\n1\ne",
"output": "-1"
},
{
"input": "2 2 1\nab\ncS\n5\nabcBA",
"output": "1"
},
{
"input": "3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG",
"output": "2"
},
... | 1,603,365,039 | 1,239 | PyPy 3 | OK | TESTS | 65 | 311 | 4,096,000 | import sys
from array import array # noqa: F401
from math import hypot
from collections import defaultdict
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m, x = map(int, input().split())
keyboard = [input().rstrip() for _ in range(n)]
keys = set()
inf, eps = 10**9, 1e-9
dist =... | Title: Keyboard
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on ... | ```python
import sys
from array import array # noqa: F401
from math import hypot
from collections import defaultdict
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m, x = map(int, input().split())
keyboard = [input().rstrip() for _ in range(n)]
keys = set()
inf, eps = 10**9, 1e... | 3.836871 |
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order... | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som... | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
... | 1,591,629,718 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | if str is bytes:
from itertools import izip as zip
def is_sorted(l):
return all(a >= b for a, b in zip(l, l[1:]))
n = int(input())
before = []
i = -1
for _ in range(n):
tmp = list(map(int, input().split()))
if tmp[0] != tmp[1]:
print("rated")
i = 1
else:
before.append(tmp[... | Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number ... | ```python
if str is bytes:
from itertools import izip as zip
def is_sorted(l):
return all(a >= b for a, b in zip(l, l[1:]))
n = int(input())
before = []
i = -1
for _ in range(n):
tmp = list(map(int, input().split()))
if tmp[0] != tmp[1]:
print("rated")
i = 1
else:
before.a... | 0 | |
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,968,008 | 2,108 | Python 3 | CHALLENGED | CHALLENGES | 7 | 124 | 13,414,400 | n, k = input().split()
n = int(n)
k = int(k)
price = [int(s) for s in input().split()]
minimum = min(s for s in price)
res = sum([s - minimum for s in price])
if res % k == 0:
print(int(res / k))
else:
print(-1) | 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 = input().split()
n = int(n)
k = int(k)
price = [int(s) for s in input().split()]
minimum = min(s for s in price)
res = sum([s - minimum for s in price])
if res % k == 0:
print(int(res / k))
else:
print(-1)
``` | -1 | |
204 | A | Little Elephant and Interval | PROGRAMMING | 1,500 | [
"binary search",
"combinatorics",
"dp"
] | null | null | The Little Elephant very much loves sums on intervals.
This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), that the first digit of integer *x* equals the last one (in decimal notation). For example, such numbers as 101, 4... | The single line contains a pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018) — the boundaries of the interval.
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. | On a single line print a single integer — the answer to the problem. | [
"2 47\n",
"47 1024\n"
] | [
"12\n",
"98\n"
] | In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44. | 500 | [
{
"input": "2 47",
"output": "12"
},
{
"input": "47 1024",
"output": "98"
},
{
"input": "1 1000",
"output": "108"
},
{
"input": "1 10000",
"output": "1008"
},
{
"input": "47 8545",
"output": "849"
},
{
"input": "1000 1000",
"output": "0"
},
{
... | 1,593,063,954 | 2,147,483,647 | PyPy 3 | OK | TESTS | 62 | 312 | 20,172,800 | def f(x):
if x < 10:
return x
if str(x)[0] > str(x)[-1]:
return x // 10 + 8
else:
return x // 10 + 9
l, r = map(int, input().split())
print(f(r) - f(l - 1)) | Title: Little Elephant and Interval
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), ... | ```python
def f(x):
if x < 10:
return x
if str(x)[0] > str(x)[-1]:
return x // 10 + 8
else:
return x // 10 + 9
l, r = map(int, input().split())
print(f(r) - f(l - 1))
``` | 3 | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,623,705,195 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 77 | 0 | n, k = map(int,input().split())
print(('abcdefghijklmnopqrstuvwxyz' [:k]*n )[:n]) | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
n, k = map(int,input().split())
print(('abcdefghijklmnopqrstuvwxyz' [:k]*n )[:n])
``` | 3 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,700,503,551 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | # A. Fafa and his Company
n = int(input())
i = 1
cont = 0
while i <= n/2:
e = n - i
if e % i == 0:
cont += 1
i += 1
print(cont) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
# A. Fafa and his Company
n = int(input())
i = 1
cont = 0
while i <= n/2:
e = n - i
if e % i == 0:
cont += 1
i += 1
print(cont)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Карта звёздного неба представляет собой прямоугольное поле, состоящее из *n* строк по *m* символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть звезда).
Новое издание карты звёздного неба будет напечатано на квадратных листах, поэто... | В первой строке входных данных записаны два числа *n* и *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — количество строк и столбцов на карте звездного неба.
В следующих *n* строках задано по *m* символов. Каждый символ — это либо «.» (пустой участок неба), либо «*» (звезда).
Гарантируется, что на небе есть хотя бы одна звезда. | Выведите одно число — минимально возможную сторону квадрата, которым можно накрыть все звезды. | [
"4 4\n....\n..*.\n...*\n..**\n",
"1 3\n*.*\n",
"2 1\n.\n*\n"
] | [
"3\n",
"3\n",
"1\n"
] | Один из возможных ответов на первый тестовый пример:
Один из возможных ответов на второй тестовый пример (обратите внимание, что покрывающий квадрат выходит за пределы карты звездного неба):
Ответ на третий тестовый пример: | 0 | [
{
"input": "4 4\n....\n..*.\n...*\n..**",
"output": "3"
},
{
"input": "1 3\n*.*",
"output": "3"
},
{
"input": "2 1\n.\n*",
"output": "1"
},
{
"input": "1 1\n*",
"output": "1"
},
{
"input": "1 2\n.*",
"output": "1"
},
{
"input": "1 2\n*.",
"output":... | 1,458,828,152 | 21,751 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 14 | 1,000 | 34,816,000 | gran = [int(i) for i in input().split()];
zvs = [];
dull = [];
strok = [];
stolb = [];
for i in range(gran[0]):
nm = [[str(l) for l in input()]]
dull += nm;
for zv in range(len(dull)):
for zvj in range(len(dull[0])):
if dull[zv][int(zvj)] == '*':
strok.append(int(zv))
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Карта звёздного неба представляет собой прямоугольное поле, состоящее из *n* строк по *m* символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть ... | ```python
gran = [int(i) for i in input().split()];
zvs = [];
dull = [];
strok = [];
stolb = [];
for i in range(gran[0]):
nm = [[str(l) for l in input()]]
dull += nm;
for zv in range(len(dull)):
for zvj in range(len(dull[0])):
if dull[zv][int(zvj)] == '*':
strok.append(int(zv)... | 0 | |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,504,025,808 | 6,708 | Python 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | #include <stdio.h>
int main()
{
long long int l,r,x,y,i;
int k,a=0;
scanf("%lld %lld %lld %lld %d",&l,&r,&x,&y,&k);
if (x>r)
{
printf("NO\n");
}
else
{
for (i=l; i<=r; i++)
{
if ((i/k) >=x && (i/k) <=y)
{
a++... | Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
#include <stdio.h>
int main()
{
long long int l,r,x,y,i;
int k,a=0;
scanf("%lld %lld %lld %lld %d",&l,&r,&x,&y,&k);
if (x>r)
{
printf("NO\n");
}
else
{
for (i=l; i<=r; i++)
{
if ((i/k) >=x && (i/k) <=y)
{
... | -1 | |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,525,167,956 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 7,065,600 | #http://codeforces.com/problemset/problem/976/A
def minBin(s):
ones = 0
zeros = 0
for letter in s:
if letter == "1":
ones += 1
else:
zeros += 1
if ones == 0:
return 0
return "1"+"0"*zeros
print(minBin("1001"))
while True:
try:
... | Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
#http://codeforces.com/problemset/problem/976/A
def minBin(s):
ones = 0
zeros = 0
for letter in s:
if letter == "1":
ones += 1
else:
zeros += 1
if ones == 0:
return 0
return "1"+"0"*zeros
print(minBin("1001"))
while True:
... | 0 | |
143 | A | Help Vasilisa the Wise 2 | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha... | The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the colum... | Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any. | [
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] | [
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] | Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | 500 | [
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
... | 1,579,973,462 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 216 | 307,200 | def solution(r,c,d):
n1=n2=n3=n4=0
for i in range(1,10):
n1=i
n2=r[0]-i
n3=c[0]-i
n4=d[0]-i
if (n2 in range(1,10)) and (n3 in range(1,10)) and (n4 in range(1,10)) and n1!=n2!=n3!=n4:
if n3+n4==r[1] and n2+n4==c[1] and n2+n3==d[1]:
pr... | Title: Help Vasilisa the Wise 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know wha... | ```python
def solution(r,c,d):
n1=n2=n3=n4=0
for i in range(1,10):
n1=i
n2=r[0]-i
n3=c[0]-i
n4=d[0]-i
if (n2 in range(1,10)) and (n3 in range(1,10)) and (n4 in range(1,10)) and n1!=n2!=n3!=n4:
if n3+n4==r[1] and n2+n4==c[1] and n2+n3==d[1]:
... | 0 | |
111 | A | Petya and Inequiations | PROGRAMMING | 1,400 | [
"greedy"
] | A. Petya and Inequiations | 2 | 256 | Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied:
- *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=*y* | The first line contains three space-separated integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=1012,<=1<=≤<=*y*<=≤<=106).
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator. | Print *n* positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. | [
"5 15 15\n",
"2 3 2\n",
"1 99 11\n"
] | [
"4\n4\n1\n1\n2\n",
"-1\n",
"11\n"
] | none | 500 | [
{
"input": "5 15 15",
"output": "11\n1\n1\n1\n1"
},
{
"input": "2 3 2",
"output": "-1"
},
{
"input": "1 99 11",
"output": "11"
},
{
"input": "100000 810000099998 1000000",
"output": "900001\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n... | 1,650,564,790 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n, x, y = map(int, input().split())
if x <= (n-1) + (y - (n-1))**2 and y >= (n-1) + (y - (n-1)):
for i in range(n-1):
print(1)
print(y - (n-1))
else:
print(-1111111111) | Title: Petya and Inequiations
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied:
- *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<... | ```python
n, x, y = map(int, input().split())
if x <= (n-1) + (y - (n-1))**2 and y >= (n-1) + (y - (n-1)):
for i in range(n-1):
print(1)
print(y - (n-1))
else:
print(-1111111111)
``` | 0 |
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,627,568,519 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 93 | 8,089,600 | from collections import defaultdict
from typing import Counter
n = int(input())
a = [int(x) for x in input().split()]
d = defaultdict(list)
for i in range(n):
d[a[i]].append(i)
l = sorted(d.items(), key=lambda x: -x[0])
p = 1
ans = [0 for _ in range(n)]
for t in l:
for idx in t[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
from collections import defaultdict
from typing import Counter
n = int(input())
a = [int(x) for x in input().split()]
d = defaultdict(list)
for i in range(n):
d[a[i]].append(i)
l = sorted(d.items(), key=lambda x: -x[0])
p = 1
ans = [0 for _ in range(n)]
for t in l:
for idx in ... | 3 | |
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w... | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
... | 1,583,914,398 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | def countTotalWatchingTime(ar):
totalMin = 0
for time in ar:
if time - totalMin > 15:
return min(totalMin + 15, 90)
else:
totalMin = time
return min(totalMin, 90)
n = int(input())
ar = list(map(int, input().split()))
print(countTotalWatchingTime(ar)) | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim... | ```python
def countTotalWatchingTime(ar):
totalMin = 0
for time in ar:
if time - totalMin > 15:
return min(totalMin + 15, 90)
else:
totalMin = time
return min(totalMin, 90)
n = int(input())
ar = list(map(int, input().split()))
print(countTotalWatchingTime(... | 0 | |
665 | C | Simple Strings | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"strings"
] | null | null | zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with th... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. | Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters. | [
"aab\n",
"caaab\n",
"zscoder\n"
] | [
"bab\n",
"cabab\n",
"zscoder\n"
] | none | 0 | [
{
"input": "aab",
"output": "bab"
},
{
"input": "caaab",
"output": "cabab"
},
{
"input": "zscoder",
"output": "zscoder"
},
{
"input": "u",
"output": "u"
},
{
"input": "h",
"output": "h"
},
{
"input": "dtottttotd",
"output": "dtotataotd"
},
{
... | 1,631,679,033 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 32,768,000 | p = {'a','b','c'}
s=input();t=len(s)
ans=s[0]
for x in range(1,t):
if ans[-1] == s[x]:
if x+1 !=t:
ans+=(p-{ans[-1],s[x+1]}).pop()
else:
ans+=(p-{ans[-1]}).pop()
else:
ans+=s[x]
print(ans) | Title: Simple Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wa... | ```python
p = {'a','b','c'}
s=input();t=len(s)
ans=s[0]
for x in range(1,t):
if ans[-1] == s[x]:
if x+1 !=t:
ans+=(p-{ans[-1],s[x+1]}).pop()
else:
ans+=(p-{ans[-1]}).pop()
else:
ans+=s[x]
print(ans)
``` | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,591,121,253 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 93 | 307,200 | x = input()
h = x.count('h')
e = x.count('e')
l = x.count('l')
o = x.count('o')
H = x.count('H')
E = x.count('E')
L = x.count('L')
O = x.count('O')
if ((h>0 or H>0) and (e>0 or E>0) and (l>1 or L>1) and (o>0 or O>0) and (x.index('h') or x.index('H'))< (x.index('e') or x.index('E'))<(x.index('... | 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
x = input()
h = x.count('h')
e = x.count('e')
l = x.count('l')
o = x.count('o')
H = x.count('H')
E = x.count('E')
L = x.count('L')
O = x.count('O')
if ((h>0 or H>0) and (e>0 or E>0) and (l>1 or L>1) and (o>0 or O>0) and (x.index('h') or x.index('H'))< (x.index('e') or x.index('E'))<... | -1 |
371 | C | Hamburgers | PROGRAMMING | 1,600 | [
"binary search",
"brute force"
] | null | null | Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (... | The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n... | Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. | [
"BBBSSC\n6 4 1\n1 2 3\n4\n",
"BBC\n1 10 1\n1 10 1\n21\n",
"BSC\n1 1 1\n1 1 3\n1000000000000\n"
] | [
"2\n",
"7\n",
"200000000001\n"
] | none | 1,500 | [
{
"input": "BBBSSC\n6 4 1\n1 2 3\n4",
"output": "2"
},
{
"input": "BBC\n1 10 1\n1 10 1\n21",
"output": "7"
},
{
"input": "BSC\n1 1 1\n1 1 3\n1000000000000",
"output": "200000000001"
},
{
"input": "B\n1 1 1\n1 1 1\n381",
"output": "382"
},
{
"input": "BSC\n3 5 6\n7... | 1,674,225,531 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 62 | 0 | s=input()
dic={"B":0,"S":0,"C":0}
nb,ns,nc=[int(i) for i in input().split()]
pb,ps,pc=[int(i) for i in input().split()]
amount=int(input())
low=0
high=10**17
for i in s:
dic[i]+=1
while low <= high:
mid=(high+low)//2
burger=mid*dic["B"] - nb
sausage=mid*dic["S"]-ns
cheese=mid*dic["C"]-n... | Title: Hamburgers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ... | ```python
s=input()
dic={"B":0,"S":0,"C":0}
nb,ns,nc=[int(i) for i in input().split()]
pb,ps,pc=[int(i) for i in input().split()]
amount=int(input())
low=0
high=10**17
for i in s:
dic[i]+=1
while low <= high:
mid=(high+low)//2
burger=mid*dic["B"] - nb
sausage=mid*dic["S"]-ns
cheese=mid*... | 3 | |
369 | A | Valera and Plates | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can... | The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Val... | Print a single integer — the minimum number of times Valera will need to wash a plate/bowl. | [
"3 1 1\n1 2 1\n",
"4 3 1\n1 1 1 1\n",
"3 1 2\n2 2 2\n",
"8 2 2\n1 2 1 2 1 2 1 2\n"
] | [
"1\n",
"1\n",
"0\n",
"4\n"
] | In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all... | 500 | [
{
"input": "3 1 1\n1 2 1",
"output": "1"
},
{
"input": "4 3 1\n1 1 1 1",
"output": "1"
},
{
"input": "3 1 2\n2 2 2",
"output": "0"
},
{
"input": "8 2 2\n1 2 1 2 1 2 1 2",
"output": "4"
},
{
"input": "2 100 100\n2 2",
"output": "0"
},
{
"input": "1 1 1\... | 1,605,978,913 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 202 | 0 | # cook your dish here
n, b, p = map(int,input().split())
ls = list(map(int, input().split()))
ans = n - min(ls.count(2), p) - b
if ans<=0:
print(0)
else:
print(ans) | Title: Valera and Plates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, ... | ```python
# cook your dish here
n, b, p = map(int,input().split())
ls = list(map(int, input().split()))
ans = n - min(ls.count(2), p) - b
if ans<=0:
print(0)
else:
print(ans)
``` | 3 | |
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,671,905,331 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | a=6
l=[]
b=[1 ,5 ,5, 1, 6, 1]
for i in b:
if i not in l :
l.append(i)
print(len(l))
for i in l:
print(i,end=' ') | 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
a=6
l=[]
b=[1 ,5 ,5, 1, 6, 1]
for i in b:
if i not in l :
l.append(i)
print(len(l))
for i in l:
print(i,end=' ')
``` | 0 | |
576 | A | Vasya and Petya's Game | PROGRAMMING | 1,500 | [
"math",
"number theory"
] | null | null | Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number *y*?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can a... | A single line contains number *n* (1<=≤<=*n*<=≤<=103). | Print the length of the sequence of questions *k* (0<=≤<=*k*<=≤<=*n*), followed by *k* numbers — the questions *y**i* (1<=≤<=*y**i*<=≤<=*n*).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them. | [
"4\n",
"6\n"
] | [
"3\n2 4 3 \n",
"4\n2 4 3 5 \n"
] | The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Th... | 500 | [
{
"input": "4",
"output": "3\n2 4 3 "
},
{
"input": "6",
"output": "4\n2 4 3 5 "
},
{
"input": "1",
"output": "0"
},
{
"input": "15",
"output": "9\n2 4 8 3 9 5 7 11 13 "
},
{
"input": "19",
"output": "12\n2 4 8 16 3 9 5 7 11 13 17 19 "
},
{
"input": "2... | 1,609,968,608 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 0 | n=int(input())
a = [i for i in range(2, n+1)]
def calculaDivisiores(num):
atual = 2
divs = []
while atual<=(num//2)+1:
if num%atual==0:
divs.append(atual)
atual+=1
return divs
res = []
for num in a:
divs = calculaDivisiores(num)
if len(divs)==1:
res.append(num)
else:
... | Title: Vasya and Petya's Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number *y*?".
The... | ```python
n=int(input())
a = [i for i in range(2, n+1)]
def calculaDivisiores(num):
atual = 2
divs = []
while atual<=(num//2)+1:
if num%atual==0:
divs.append(atual)
atual+=1
return divs
res = []
for num in a:
divs = calculaDivisiores(num)
if len(divs)==1:
res.append(num)
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | As usual, Sereja has array *a*, its elements are integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Let's introduce notation:
A swap operation is the following sequence of actions:
- choose two indexes *i*,<=*j* (*i*<=≠<=*j*); - perform assignments *tmp*<==<=*a*[*i*],<=*a*[*i*]<==<=*a*[*j*],<=*a*[*j*]<==<=*tmp*.
What max... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200; 1<=≤<=*k*<=≤<=10). The next line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (<=-<=1000<=≤<=*a*[*i*]<=≤<=1000). | In a single line print the maximum value of *m*(*a*) that Sereja can get if he is allowed to perform at most *k* swap operations. | [
"10 2\n10 -1 2 2 2 2 2 2 -1 10\n",
"5 10\n-1 -1 -1 -1 -1\n"
] | [
"32\n",
"-1\n"
] | none | 0 | [
{
"input": "10 2\n10 -1 2 2 2 2 2 2 -1 10",
"output": "32"
},
{
"input": "5 10\n-1 -1 -1 -1 -1",
"output": "-1"
},
{
"input": "18 1\n166 788 276 -103 -491 195 -960 389 376 369 630 285 3 575 315 -987 820 466",
"output": "5016"
},
{
"input": "29 6\n-21 486 -630 -433 -123 -387 6... | 1,404,303,241 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 32 | 904 | 307,200 | n, k = map(int, input().split())
a = list(map(int, input().split()))
res = a[0]
for l in range(n):
for r in range(l, n):
inside = sorted(a[l:r+1])
outside = sorted(a[:l] + a[r+1:], reverse=True)
new_res = sum(inside)
for i in range(min(k, len(inside), len(outside))):
if outside[i] > inside[i]:
new_r... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As usual, Sereja has array *a*, its elements are integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Let's introduce notation:
A swap operation is the following sequence of actions:
- choose two indexes *i*,<=*j* (*i*<=≠<=*j*); - perf... | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
res = a[0]
for l in range(n):
for r in range(l, n):
inside = sorted(a[l:r+1])
outside = sorted(a[:l] + a[r+1:], reverse=True)
new_res = sum(inside)
for i in range(min(k, len(inside), len(outside))):
if outside[i] > inside[i]:... | 0 | |
606 | A | Magic Spheres | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible,... | The first line of the input contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that are in the magician's disposal.
The second line of the input contains three integers, *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=1<=000<=000) — the number o... | If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No". | [
"4 4 0\n2 1 2\n",
"5 6 1\n2 7 2\n",
"3 3 3\n2 2 2\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what... | 500 | [
{
"input": "4 4 0\n2 1 2",
"output": "Yes"
},
{
"input": "5 6 1\n2 7 2",
"output": "No"
},
{
"input": "3 3 3\n2 2 2",
"output": "Yes"
},
{
"input": "0 0 0\n0 0 0",
"output": "Yes"
},
{
"input": "0 0 0\n0 0 1",
"output": "No"
},
{
"input": "0 1 0\n0 0 0... | 1,693,817,708 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 46 | 0 | a,b,c = map(int, input().split())
x,y,z = map(int, input().split())
extra = max(0, a-x)//2 + max(0, b-y)//2 + max(0, c-z)//2
need = max(0, x-a) + max(0, y-b) + max(0, z-c)
print("Yes" if need<=extra else "No")
| Title: Magic Spheres
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been see... | ```python
a,b,c = map(int, input().split())
x,y,z = map(int, input().split())
extra = max(0, a-x)//2 + max(0, b-y)//2 + max(0, c-z)//2
need = max(0, x-a) + max(0, y-b) + max(0, z-c)
print("Yes" if need<=extra else "No")
``` | 3 | |
462 | B | Appleman and Card Game | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman. | Print a single integer – the answer to the problem. | [
"15 10\nDZFDFZDFDDDDDDF\n",
"6 4\nYJSNPI\n"
] | [
"82\n",
"4\n"
] | In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | 1,000 | [
{
"input": "15 10\nDZFDFZDFDDDDDDF",
"output": "82"
},
{
"input": "6 4\nYJSNPI",
"output": "4"
},
{
"input": "5 3\nAOWBY",
"output": "3"
},
{
"input": "1 1\nV",
"output": "1"
},
{
"input": "2 1\nWT",
"output": "1"
},
{
"input": "2 2\nBL",
"output":... | 1,651,722,612 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 46 | 0 | n ,m = map(int ,input() .split())
a = input()
q = sorted(a)
s = [ ]
d = 1
ans = 0
for i in range(1 ,len(q)):
if q[i - 1] == q[i] and q[i - 1] != q[-1] and q[i] != q[-1]:
d += 1
elif d > 1:
s += [d]
d = 1
w = q .count(q[-1])
s = sorted(s)[::-1]
if w > 1:
s += [w]
if le... | Title: Appleman and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally... | ```python
n ,m = map(int ,input() .split())
a = input()
q = sorted(a)
s = [ ]
d = 1
ans = 0
for i in range(1 ,len(q)):
if q[i - 1] == q[i] and q[i - 1] != q[-1] and q[i] != q[-1]:
d += 1
elif d > 1:
s += [d]
d = 1
w = q .count(q[-1])
s = sorted(s)[::-1]
if w > 1:
s += ... | 0 | |
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th... | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"outpu... | 1,628,132,219 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 154 | 20,172,800 | def main():
n = int(input())
arr = list(map(int, input().split()))
counts = dict()
for i in range(n):
if arr[i] in counts:
counts[arr[i]].append(i)
else:
counts[arr[i]] = [i]
counts = sorted(counts.items(), key=lambda x: x[0])
for k, v ... | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
-... | ```python
def main():
n = int(input())
arr = list(map(int, input().split()))
counts = dict()
for i in range(n):
if arr[i] in counts:
counts[arr[i]].append(i)
else:
counts[arr[i]] = [i]
counts = sorted(counts.items(), key=lambda x: x[0])
... | 0 | |
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n... | 1,574,642,509 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 218 | 0 | def sr(ch):
ch1=ch+' '
l=[]
p=''
for i in ch1:
if i!=' ':
p=p+i
else:
l.append(int(p))
p=''
return l
n=int(input())
y=str(input())
z=str(input())
l=sr(y)
p=sr(z)
a=p[0]-1
b=p[1]-1
k=0
for i in range(a,b):
k=k+l[i]
print(k) | Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
def sr(ch):
ch1=ch+' '
l=[]
p=''
for i in ch1:
if i!=' ':
p=p+i
else:
l.append(int(p))
p=''
return l
n=int(input())
y=str(input())
z=str(input())
l=sr(y)
p=sr(z)
a=p[0]-1
b=p[1]-1
k=0
for i in range(a,b):
k=k+l[i]
... | 3.9455 |
873 | B | Balanced Substring | PROGRAMMING | 1,500 | [
"dp",
"implementation"
] | null | null | You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to deter... | The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. | If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. | [
"8\n11010111\n",
"3\n111\n"
] | [
"4\n",
"0\n"
] | In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | 0 | [
{
"input": "8\n11010111",
"output": "4"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "11\n00001000100",
"output": "2"
},
{
"input": "10\n0100000000",
"output": "2"
},
{
"input": "13\n0001000011010",
"output": "6"
},
{
"input": "14\n0000010010101... | 1,518,618,222 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 124 | 14,233,600 | n=int(input())
T=input()
d={0:-1}
s=0
mix=0
for i in range(n):
s+=1-(T[i]=='0')*2
if s not in d:
d[s]=i
else:
if(i-d[s])> mix:
mix=i-d[s]
print(mix) | Title: Balanced Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called... | ```python
n=int(input())
T=input()
d={0:-1}
s=0
mix=0
for i in range(n):
s+=1-(T[i]=='0')*2
if s not in d:
d[s]=i
else:
if(i-d[s])> mix:
mix=i-d[s]
print(mix)
``` | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,678,526,109 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 122 | 409,600 | from fractions import Fraction
y,w=map(int,input().split())
m=max(y,w)
c=0
for i in range(m,7):
c=c+1
if c==0:
print("0/1")
elif c==1:
print("1/6")
elif c==2:
print("1/3")
elif c==3:
print("1/2")
elif c==4:
print("2/3")
elif c==5:
print("5/6")
elif c==6:
print("1/1") | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
from fractions import Fraction
y,w=map(int,input().split())
m=max(y,w)
c=0
for i in range(m,7):
c=c+1
if c==0:
print("0/1")
elif c==1:
print("1/6")
elif c==2:
print("1/3")
elif c==3:
print("1/2")
elif c==4:
print("2/3")
elif c==5:
print("5/6")
elif c==6:
prin... | 3.935948 |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,466,259,493 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import math
def istr(x):
ch=0
for k in range(math.sqrt(2*x)):
if x=k*(k+1)/2:
return True
return False
n=int(input())
ch=0
for i in range(math.sqrt(2*n)):
if istr(n-i*(i+1)/2):
ch=1
print('YES')
break
if ch==0:
print('NO') | Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
import math
def istr(x):
ch=0
for k in range(math.sqrt(2*x)):
if x=k*(k+1)/2:
return True
return False
n=int(input())
ch=0
for i in range(math.sqrt(2*n)):
if istr(n-i*(i+1)/2):
ch=1
print('YES')
break
if ch==0:
print('N... | -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,681,909,563 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | s=input()
start='a'
count=0
for i in s:
diff=abs(ord(i)-ord(start))
count+=min(diff,26-diff)
start=i
print(count)
| 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
s=input()
start='a'
count=0
for i in s:
diff=abs(ord(i)-ord(start))
count+=min(diff,26-diff)
start=i
print(count)
``` | 3 | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,693,891,266 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 14 | 216 | 0 | x = input()
y = ["a", "A", "e", "E", "i", "I", "o", "O", "u", "U"]
x_new = ""
def string_mod(x, y, x_new):
if x == "":
return x_new
if x[0] in y:
return string_mod(x[1:], y, x_new)
if 64<ord(x[0])<91 or 96<ord(x[0])<123:
if 64<ord(x[0])<91:
x_new+=f".{chr(ord(... | Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
x = input()
y = ["a", "A", "e", "E", "i", "I", "o", "O", "u", "U"]
x_new = ""
def string_mod(x, y, x_new):
if x == "":
return x_new
if x[0] in y:
return string_mod(x[1:], y, x_new)
if 64<ord(x[0])<91 or 96<ord(x[0])<123:
if 64<ord(x[0])<91:
x_new+=f"... | 0 | |
459 | A | Pashmak and Garden | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<... | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | 500 | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input... | 1,677,816,939 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 |
ord = list(map(int,input().split()))
x1 = [ord[0],ord[1]]
x2 = [ord[2],ord[3]]
#point = sum(ord)//(4-ord.count(0))
arr = [True,False,False,False,False]
if ord.count(0)==0 or ord.count(0)==4:
print(-1)
else:
point = None
for i in ord:
if i!=0:
if point==None:
point= i... | Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is... | ```python
ord = list(map(int,input().split()))
x1 = [ord[0],ord[1]]
x2 = [ord[2],ord[3]]
#point = sum(ord)//(4-ord.count(0))
arr = [True,False,False,False,False]
if ord.count(0)==0 or ord.count(0)==4:
print(-1)
else:
point = None
for i in ord:
if i!=0:
if point==None:
... | 0 | |
33 | C | Wonderful Randomized Sum | PROGRAMMING | 1,800 | [
"greedy"
] | C. Wonderful Randomized Sum | 2 | 256 | Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of elements in the sequence. The second line contains *n* integers *a**i* (<=-<=104<=≤<=*a**i*<=≤<=104) — the sequence itself. | The first and the only line of the output should contain the answer to the problem. | [
"3\n-1 -2 -3\n",
"5\n-4 2 0 5 0\n",
"5\n-1 10 -5 10 -2\n"
] | [
"6\n",
"11\n",
"18\n"
] | none | 1,500 | [
{
"input": "3\n-1 -2 -3",
"output": "6"
},
{
"input": "5\n-4 2 0 5 0",
"output": "11"
},
{
"input": "5\n-1 10 -5 10 -2",
"output": "18"
},
{
"input": "1\n-3",
"output": "3"
},
{
"input": "4\n1 4 -5 -2",
"output": "12"
},
{
"input": "7\n-17 6 5 0 1 4 -1... | 1,625,578,403 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | n = int(input())
l = list(map(int,input().split))
suff = [0]
tot = 0
for i in range(1,n+1):
tot += l[n - i]
suff.append(min(0,tot,suff[i-1]))
pre = [0]
for i in range(1,n+1):
pre.append(pre[i-1] + l[i-1])
ans = -9999999999999999999
for i in range(n+1):
ans = max(ans,pre[n] - 2*pre[i-1] - 2*suf... | Title: Wonderful Randomized Sum
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivat... | ```python
n = int(input())
l = list(map(int,input().split))
suff = [0]
tot = 0
for i in range(1,n+1):
tot += l[n - i]
suff.append(min(0,tot,suff[i-1]))
pre = [0]
for i in range(1,n+1):
pre.append(pre[i-1] + l[i-1])
ans = -9999999999999999999
for i in range(n+1):
ans = max(ans,pre[n] - 2*pre[i-... | -1 |
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea... | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *... | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"outpu... | 1,694,619,009 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | import sys
n, t = map(int, input().split())
s = input().strip()
for _ in range(t):
i = 1
while i < n:
if s[i] == 'G' and s[i - 1] == 'B':
s = s[:i - 1] + 'G' + 'B' + s[i + 1:]
i += 1
i += 1
print(s)
| Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a... | ```python
import sys
n, t = map(int, input().split())
s = input().strip()
for _ in range(t):
i = 1
while i < n:
if s[i] == 'G' and s[i - 1] == 'B':
s = s[:i - 1] + 'G' + 'B' + s[i + 1:]
i += 1
i += 1
print(s)
``` | 3 | |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,659,629,025 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n = int(input())
t = list(map(int,input().split(" ")))
if (t.count(1)) < 2 or (t.count(2)) < 2 or (t.count(3)) < 2:
print(0)
exit()
else:
number = min(t.count(1), t.count(2), t.count(3))
f = []
s = []
third = []
for i in range(n):
if t[i] == 1:
f.append(i)
... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
n = int(input())
t = list(map(int,input().split(" ")))
if (t.count(1)) < 2 or (t.count(2)) < 2 or (t.count(3)) < 2:
print(0)
exit()
else:
number = min(t.count(1), t.count(2), t.count(3))
f = []
s = []
third = []
for i in range(n):
if t[i] == 1:
f.app... | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,539,801,813 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | s=input().split('+')
#split help me to make my input as i want
s.sort()
print('+'.join(s))
| 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().split('+')
#split help me to make my input as i want
s.sort()
print('+'.join(s))
``` | 0 |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not... | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,584,181,096 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 109 | 307,200 | #### B. Quasi Binary
n=int(input())
result=[]
while n:
r=''.join(min(i,'1') for i in str(n))
n=n-int(r)
result.append(r)
print(len(result))
print(*result) | Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Repr... | ```python
#### B. Quasi Binary
n=int(input())
result=[]
while n:
r=''.join(min(i,'1') for i in str(n))
n=n-int(r)
result.append(r)
print(len(result))
print(*result)
``` | 3 | |
1,006 | E | Military Problem | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | In this problem you will have to help Berland army with organizing their command delivery system.
There are $n$ officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer $a$ is the direct superior of off... | The first line of the input contains two integers $n$ and $q$ ($2 \le n \le 2 \cdot 10^5, 1 \le q \le 2 \cdot 10^5$) — the number of officers in Berland army and the number of queries.
The second line of the input contains $n - 1$ integers $p_2, p_3, \dots, p_n$ ($1 \le p_i < i$), where $p_i$ is the index of the di... | Print $q$ numbers, where the $i$-th number is the officer at the position $k_i$ in the list which describes the order in which officers will receive the command if it starts spreading from officer $u_i$. Print "-1" if the number of officers which receive the command is less than $k_i$.
You should process queries indep... | [
"9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9\n"
] | [
"3\n6\n8\n-1\n9\n4\n"
] | none | 0 | [
{
"input": "9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9",
"output": "3\n6\n8\n-1\n9\n4"
},
{
"input": "2 1\n1\n1 1",
"output": "1"
},
{
"input": "13 12\n1 1 1 1 1 1 1 1 1 1 1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n... | 1,675,886,891 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 1,964 | 20,480,000 | n,q= map(int, input().split())
parent=[-1]+[int(x) -1 for x in input().split()]
start=[0]*n
end=[1]*n
size=[1]*n
path=[0]*n
for i in range(n-1, 0, -1):
size[parent[i]]+=size[i]
for v in range(1, n):
start[v]=end[parent[v]]
end[v]=start[v]+1
end[parent[v]]+=size[v]
path[start[v]]=v
for j... | Title: Military Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you will have to help Berland army with organizing their command delivery system.
There are $n$ officers in Berland army. The first officer is the commander of the army, and he does not have any superi... | ```python
n,q= map(int, input().split())
parent=[-1]+[int(x) -1 for x in input().split()]
start=[0]*n
end=[1]*n
size=[1]*n
path=[0]*n
for i in range(n-1, 0, -1):
size[parent[i]]+=size[i]
for v in range(1, n):
start[v]=end[parent[v]]
end[v]=start[v]+1
end[parent[v]]+=size[v]
path[start[v]... | 3 | |
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ... | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five l... | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
... | 1,682,859,780 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 46 | 0 | def li():
return list(map(int,input().split()))
def gi(n):
return [list(map(int,input().split())) for _ in range(n)]
# File input
# import sys
# sys.stdin = open('user.txt','r')
l,r,a = li()
if max(l,r) - min(l,r) > a:
print((min(l,r)+a) * 2)
else:
print((max(l,r) + (a - (max(l,r) - m... | Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.... | ```python
def li():
return list(map(int,input().split()))
def gi(n):
return [list(map(int,input().split())) for _ in range(n)]
# File input
# import sys
# sys.stdin = open('user.txt','r')
l,r,a = li()
if max(l,r) - min(l,r) > a:
print((min(l,r)+a) * 2)
else:
print((max(l,r) + (a - (ma... | 3 | |
682 | C | Alyona and the Tree | PROGRAMMING | 1,600 | [
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call ver... | In the first line of the input integer *n* (1<=≤<=*n*<=≤<=105) is given — the number of vertices in the tree.
In the second line the sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) is given, where *a**i* is the number written on vertex *i*.
The next *n*<=-<=1 lines describe tree edges: *i**... | Print the only integer — the minimum number of leaves Alyona needs to remove such that there will be no any sad vertex left in the tree. | [
"9\n88 22 83 14 95 91 98 53 11\n3 24\n7 -8\n1 67\n1 64\n9 65\n5 12\n6 -80\n3 8\n"
] | [
"5\n"
] | The following image represents possible process of removing leaves from the tree: | 1,500 | [
{
"input": "9\n88 22 83 14 95 91 98 53 11\n3 24\n7 -8\n1 67\n1 64\n9 65\n5 12\n6 -80\n3 8",
"output": "5"
},
{
"input": "6\n53 82 15 77 71 23\n5 -77\n6 -73\n2 0\n1 26\n4 -92",
"output": "0"
},
{
"input": "10\n99 60 68 46 51 11 96 41 48 99\n4 50\n6 -97\n3 -92\n7 1\n9 99\n2 79\n1 -15\n8 -6... | 1,467,895,129 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 11 | 607 | 20,582,400 | def subtree_dfs(v):
size = 1
for u, c in edge[v]:
size += subtree_dfs(u)
subtree[v] = size
return size
def remove_dfs(v, path):
if path < 0:
path = 0
if vertex[v] < path:
return subtree[v]
removed = 0
for u, c in edge[v]:
removed += remove_dfs(u, path + ... | Title: Alyona and the Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
Th... | ```python
def subtree_dfs(v):
size = 1
for u, c in edge[v]:
size += subtree_dfs(u)
subtree[v] = size
return size
def remove_dfs(v, path):
if path < 0:
path = 0
if vertex[v] < path:
return subtree[v]
removed = 0
for u, c in edge[v]:
removed += remove_dfs(... | -1 | |
644 | B | Processing Queries | PROGRAMMING | 1,700 | [
"*special",
"constructive algorithms",
"data structures",
"two pointers"
] | null | null | In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct.
When a query appears server may react in three possible ways:
1. If ser... | The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue.
Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d... | Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected. | [
"5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n",
"4 1\n2 8\n4 8\n10 9\n15 2\n"
] | [
"11 19 -1 21 22 \n",
"10 18 27 -1 \n"
] | Consider the first sample.
1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b* = 1 and there is... | 1,000 | [
{
"input": "5 1\n2 9\n4 8\n10 9\n15 2\n19 1",
"output": "11 19 -1 21 22 "
},
{
"input": "4 1\n2 8\n4 8\n10 9\n15 2",
"output": "10 18 27 -1 "
},
{
"input": "1 1\n1000000000 1000000000",
"output": "2000000000 "
},
{
"input": "4 3\n999999996 1000000000\n999999997 1000000000\n99... | 1,611,284,793 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 31 | 1,950 | 16,384,000 | import queue
query = queue.Queue()
q, b = map(int, input().split())
res = []
total = 0
pos = 0 # vị trí trong mảng
for i in range(q):
t,d = map(int, input().split())
query.put([t,d])
while not query.empty():
[x,y] = query.get()
if not res: # ptu đầu
total = x + y
else:
... | Title: Processing Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* ar... | ```python
import queue
query = queue.Queue()
q, b = map(int, input().split())
res = []
total = 0
pos = 0 # vị trí trong mảng
for i in range(q):
t,d = map(int, input().split())
query.put([t,d])
while not query.empty():
[x,y] = query.get()
if not res: # ptu đầu
total = x + y
e... | 0 | |
864 | B | Polycarp and Letters | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from *A* in the string are all distinct and lowerc... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*.
The second line contains a string *s* consisting of lowercase and uppercase Latin letters. | Print maximum number of elements in pretty set of positions for string *s*. | [
"11\naaaaBaabAbA\n",
"12\nzACaAbbaazzC\n",
"3\nABC\n"
] | [
"2\n",
"3\n",
"0\n"
] | In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There... | 1,000 | [
{
"input": "11\naaaaBaabAbA",
"output": "2"
},
{
"input": "12\nzACaAbbaazzC",
"output": "3"
},
{
"input": "3\nABC",
"output": "0"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\naz",
"output": "2"
},
{
"input": "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLr... | 1,600,254,302 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | n = int(input())
s = input()
if s.isupper() or (len(set(s)) == 1):
print(0)
exit()
cnt = 0
for i in range(1,n):
k = s[i-1]
if s[i].islower():
if k.islower() and s[i] != k:
cnt +=1
else:
cnt = cnt
else:
cnt = cnt
continue
... | Title: Polycarp and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if... | ```python
n = int(input())
s = input()
if s.isupper() or (len(set(s)) == 1):
print(0)
exit()
cnt = 0
for i in range(1,n):
k = s[i-1]
if s[i].islower():
if k.islower() and s[i] != k:
cnt +=1
else:
cnt = cnt
else:
cnt = cnt
... | 0 | |
727 | A | Transformation: from A to B | PROGRAMMING | 1,000 | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to he... | The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x... | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | 1,000 | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
... | 1,594,193,638 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 171 | 24,985,600 | a, b = map(int, input().split())
seq = []
def d(s):
if s > b:
return False
if s == b:
return True
for i in range(2):
if i==0:
hit = d(2*s)
if hit:
seq.append(2*s)
return True
if i... | Title: Transformation: from A to B
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - app... | ```python
a, b = map(int, input().split())
seq = []
def d(s):
if s > b:
return False
if s == b:
return True
for i in range(2):
if i==0:
hit = d(2*s)
if hit:
seq.append(2*s)
return True
... | 3 | |
409 | F | 000001 | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The input contains a single integer *a* (1<=≤<=*a*<=≤<=64).
Output a single integer. | The input contains a single integer *a* (1<=≤<=*a*<=≤<=64). | Output a single integer. | [
"2\n",
"4\n",
"27\n",
"42\n"
] | [
"1\n",
"2\n",
"5\n",
"6\n"
] | none | 0 | [
{
"input": "2",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "27",
"output": "5"
},
{
"input": "42",
"output": "6"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "64",
"output": "267"
}... | 1,692,211,470 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 64 | 62 | 0 | from sys import stdin,stdout
# from os import _exit
# from bisect import bisect_left,bisect
# from heapq import heapify,heappop,heappush
# from sys import setrecursionlimit
# from collections import defaultdict,Counter
# from itertools import permutations
# from math import gcd,ceil,sqrt,factorial
# setrecursio... | Title: 000001
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=64).
Output a single integer.
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=64).
Output Specification:
Output a single integer.
Demo Input:... | ```python
from sys import stdin,stdout
# from os import _exit
# from bisect import bisect_left,bisect
# from heapq import heapify,heappop,heappush
# from sys import setrecursionlimit
# from collections import defaultdict,Counter
# from itertools import permutations
# from math import gcd,ceil,sqrt,factorial
# s... | 3 | |
575 | D | Tablecity | PROGRAMMING | 1,700 | [
"constructive algorithms",
"implementation"
] | null | null | There was a big bank robbery in Tablecity. In order to catch the thief, the President called none other than Albert – Tablecity’s Chief of Police. Albert does not know where the thief is located, but he does know how he moves.
Tablecity can be represented as 1000<=×<=2 grid, where every cell represents one district. E... | There is no input for this problem. | The first line of output contains integer *N* – duration of police search in hours. Each of the following *N* lines contains exactly 4 integers *X**i*1, *Y**i*1, *X**i*2, *Y**i*2 separated by spaces, that represent 2 districts (*X**i*1, *Y**i*1), (*X**i*2, *Y**i*2) which got investigated during i-th hour. Output is giv... | [
"В этой задаче нет примеров ввода-вывода.\nThis problem doesn't have sample input and output."
] | [
"Смотрите замечание ниже.\nSee the note below."
] | Let's consider the following output:
2
5 1 50 2
8 1 80 2
This output is not guaranteed to catch the thief and is not correct. It is given to you only to show the expected output format. There exists a combination of an initial position and a movement strategy such that the police will not catch the thief.
Consider... | 0 | [
{
"input": "dummy",
"output": "2000\n1 1 1 2\n2 1 2 2\n3 1 3 2\n4 1 4 2\n5 1 5 2\n6 1 6 2\n7 1 7 2\n8 1 8 2\n9 1 9 2\n10 1 10 2\n11 1 11 2\n12 1 12 2\n13 1 13 2\n14 1 14 2\n15 1 15 2\n16 1 16 2\n17 1 17 2\n18 1 18 2\n19 1 19 2\n20 1 20 2\n21 1 21 2\n22 1 22 2\n23 1 23 2\n24 1 24 2\n25 1 25 2\n26 1 26 2\n27 ... | 1,442,062,414 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 2,560,000 | print(1998); [print(i, 2, i, 1) for i in range(1, 1000)] * 2 | Title: Tablecity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There was a big bank robbery in Tablecity. In order to catch the thief, the President called none other than Albert – Tablecity’s Chief of Police. Albert does not know where the thief is located, but he does know how he moves... | ```python
print(1998); [print(i, 2, i, 1) for i in range(1, 1000)] * 2
``` | 0 | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,696,219,782 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 78 | 0 | n = int(input())
cells = input()
if cells.find('0') == -1:
print(n)
else:
before = int(cells[::-1], 2)
after = before + 1
print(str(bin(before ^ after)).count('1'))
| Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
n = int(input())
cells = input()
if cells.find('0') == -1:
print(n)
else:
before = int(cells[::-1], 2)
after = before + 1
print(str(bin(before ^ after)).count('1'))
``` | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,693,388,366 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | w = int(input())
if w%2 == 0 and 100>= w >= 3:
print('YES')
else:
print('NO') | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
w = int(input())
if w%2 == 0 and 100>= w >= 3:
print('YES')
else:
print('NO')
``` | 3.954 |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,592,933,269 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 140 | 20,172,800 | #!/usr/bin/python3
# n, t = input().split(" ")
# a = input()
# n = int(n)
# t = int(t)
# s = list(a)
# while(t != 0):
# for i in range(n-1):
# if s[i] == 'B' and s[i+1] == 'G':
# s[i] = 'G'
# s[i + 1] = 'B'
# t -= 1
# break
# print("".join(s))
# t = int(in... | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
#!/usr/bin/python3
# n, t = input().split(" ")
# a = input()
# n = int(n)
# t = int(t)
# s = list(a)
# while(t != 0):
# for i in range(n-1):
# if s[i] == 'B' and s[i+1] == 'G':
# s[i] = 'G'
# s[i + 1] = 'B'
# t -= 1
# break
# print("".join(s))
# ... | 3.927425 |
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 ... | 1,618,432,432 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 122 | 0 | for _ in range(1):
ls = list(map(int, input().split()))
print(ls[0]-ls[1]) | Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind h... | ```python
for _ in range(1):
ls = list(map(int, input().split()))
print(ls[0]-ls[1])
``` | 0 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,697,703,650 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 184 | 0 | s = input()
ans = s[0].capitalize() + s[1::]
print(ans) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
s = input()
ans = s[0].capitalize() + s[1::]
print(ans)
``` | 3 | |
466 | C | Number of Ways | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. | Print a single integer — the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\... | 1,699,512,011 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
for i in range(n):
dish_num = int(input())
delivery_time = list(map(int, input().split()))
arrival_time = list(map(int, input().split()))
combine_time = sorted(zip(delivery_time, arrival_time), key=lambda x: x[0])
a = sum(arrival_time)
min_time = float('inf')
... | Title: Number of Ways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the s... | ```python
n = int(input())
for i in range(n):
dish_num = int(input())
delivery_time = list(map(int, input().split()))
arrival_time = list(map(int, input().split()))
combine_time = sorted(zip(delivery_time, arrival_time), key=lambda x: x[0])
a = sum(arrival_time)
min_time = flo... | -1 | |
777 | D | Cloud of Hashtags | PROGRAMMING | 1,800 | [
"binary search",
"greedy",
"implementation",
"strings"
] | null | null | Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashta... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=500<=000) — the number of hashtags being edited now.
Each of the next *n* lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#... | Print the resulting hashtags in any of the optimal solutions. | [
"3\n#book\n#bigtown\n#big\n",
"3\n#book\n#cool\n#cold\n",
"4\n#car\n#cart\n#art\n#at\n",
"3\n#apple\n#apple\n#fruit\n"
] | [
"#b\n#big\n#big\n",
"#book\n#co\n#cold\n",
"#\n#\n#art\n#at\n",
"#apple\n#apple\n#fruit\n"
] | Word *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*m*</sub> of length *m* is lexicographically not greater than word *b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ..., *b*<sub class="lower-index">*k*</sub> of length *k*, if one of... | 2,000 | [
{
"input": "3\n#book\n#bigtown\n#big",
"output": "#b\n#big\n#big"
},
{
"input": "3\n#book\n#cool\n#cold",
"output": "#book\n#co\n#cold"
},
{
"input": "4\n#car\n#cart\n#art\n#at",
"output": "#\n#\n#art\n#at"
},
{
"input": "3\n#apple\n#apple\n#fruit",
"output": "#apple\n#ap... | 1,657,190,402 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 41,369,600 | n = int(input())
ls = [input() for _ in range(n)]
for x in range(n - 2, -1, -1):
m = min(len(ls[x]), len(ls[x + 1]))
for j in range(m):
if ls[x][j] > ls[x + 1][j]:
ls[x] = ls[x][:j]
break
elif ls[x][j] < ls[x + 1][j]:
break
else:
ls[x] = ls[x][: m... | Title: Cloud of Hashtags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to m... | ```python
n = int(input())
ls = [input() for _ in range(n)]
for x in range(n - 2, -1, -1):
m = min(len(ls[x]), len(ls[x + 1]))
for j in range(m):
if ls[x][j] > ls[x + 1][j]:
ls[x] = ls[x][:j]
break
elif ls[x][j] < ls[x + 1][j]:
break
else:
ls[x] =... | 0 | |
658 | A | Bear and Reverse Radewoosh | PROGRAMMING | 800 | [
"implementation"
] | null | null | Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=<<=*p**i*<=+<=1) — initial scores.
The third... | Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. | [
"3 2\n50 85 250\n10 15 25\n",
"3 6\n50 85 250\n10 15 25\n",
"8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n"
] | [
"Limak\n",
"Radewoosh\n",
"Tie\n"
] | In the first sample, there are 3 problems. Limak solves them as follows:
1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85... | 500 | [
{
"input": "3 2\n50 85 250\n10 15 25",
"output": "Limak"
},
{
"input": "3 6\n50 85 250\n10 15 25",
"output": "Radewoosh"
},
{
"input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76",
"output": "Tie"
},
{
"input": "4 1\n3 5 6 9\n1 2 4 8",
"output": "Limak"
},
{... | 1,543,491,783 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 108 | 0 | n, c = map(int, input().split())
p = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
t1 = []
t_l = 0
for i in t:
t_l += i
t1.append(t_l)
t2 = []
t_r = 0
for i in reversed(t):
t_r += i
t2.append(t_r)
p1 = p
p2 = list(reversed(p))
limak = 0
revad = 0
j = 0
k... | Title: Bear and Reverse Radewoosh
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-... | ```python
n, c = map(int, input().split())
p = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
t1 = []
t_l = 0
for i in t:
t_l += i
t1.append(t_l)
t2 = []
t_r = 0
for i in reversed(t):
t_r += i
t2.append(t_r)
p1 = p
p2 = list(reversed(p))
limak = 0
revad = 0... | 0 | |
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
... | 1,577,418,860 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | x=map(int,input().split())
print(round(((x[0]/x[1])/(1-(c/d)**2)),2)) | Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w... | ```python
x=map(int,input().split())
print(round(((x[0]/x[1])/(1-(c/d)**2)),2))
``` | -1 | |
979 | C | Kuro and Walking Route | PROGRAMMING | 1,600 | [
"dfs and similar",
"trees"
] | null | null | Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which h... | The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively.
$n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), de... | A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route. | [
"3 1 3\n1 2\n2 3\n",
"3 1 3\n1 2\n1 3\n"
] | [
"5",
"4"
] | On the first example, Kuro can choose these pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$... | 1,250 | [
{
"input": "3 1 3\n1 2\n2 3",
"output": "5"
},
{
"input": "3 1 3\n1 2\n1 3",
"output": "4"
},
{
"input": "61 26 12\n33 38\n32 8\n27 59\n1 21\n61 57\n61 22\n35 18\n61 14\n39 56\n50 10\n1 42\n21 43\n61 41\n31 30\n35 9\n23 28\n39 34\n39 4\n39 25\n27 60\n45 51\n1 11\n35 26\n29 15\n23 44\n31 ... | 1,535,471,953 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 38,297,600 | n,x,y=map(int,input().split(' '));x-=1;y-=1
adjli=[];parent=[];
for i in range(n):
adjli.append([]);parent.append(-1);
for _ in range(n-1):
u,v=map(int,input().split(' '))
adjli[u-1].append(v-1);
adjli[v-1].append(u-1);
def dfs():
global adjli,x,y,n
visi=[0 for i in range(n)]
tr=[False for i in ra... | Title: Kuro and Walking Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road ... | ```python
n,x,y=map(int,input().split(' '));x-=1;y-=1
adjli=[];parent=[];
for i in range(n):
adjli.append([]);parent.append(-1);
for _ in range(n-1):
u,v=map(int,input().split(' '))
adjli[u-1].append(v-1);
adjli[v-1].append(u-1);
def dfs():
global adjli,x,y,n
visi=[0 for i in range(n)]
tr=[False f... | 0 | |
1,009 | A | Game Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy ... | The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the inp... | Print a single integer — the number of games Maxim will buy. | [
"5 4\n2 4 5 2 4\n5 3 4 6\n",
"5 2\n20 40 50 20 40\n19 20\n",
"6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n"
] | [
"3\n",
"0\n",
"4\n"
] | The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti... | 0 | [
{
"input": "5 4\n2 4 5 2 4\n5 3 4 6",
"output": "3"
},
{
"input": "5 2\n20 40 50 20 40\n19 20",
"output": "0"
},
{
"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000",
"output": "4"
},
{
"input": "5 1\n1 1 1 1 1\n5",
"output": "1"
},
{
"input": "5 1\n10 1 1 1 1\n... | 1,592,372,457 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 124 | 307,200 | n,m=map(int,input().split())
l=list(map(int,input().split()))
k=list(map(int,input().split()))
i,j = 0,0
count=0
while i<len(l) and j<len(k):
if l[i]<=k[j]:
count+=1
j+=1
i+=1
else:
i+=1
print(count) | Title: Game Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the ... | ```python
n,m=map(int,input().split())
l=list(map(int,input().split()))
k=list(map(int,input().split()))
i,j = 0,0
count=0
while i<len(l) and j<len(k):
if l[i]<=k[j]:
count+=1
j+=1
i+=1
else:
i+=1
print(count)
``` | 3 | |
448 | D | Multiplication Table | PROGRAMMING | 1,800 | [
"binary search",
"brute force"
] | null | null | Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multiplication table, where the element on the intersection of the *i*-th row and *j*-th column equals *i*·*j* ... | The single line contains integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=5·105; 1<=≤<=*k*<=≤<=*n*·*m*). | Print the *k*-th largest number in a *n*<=×<=*m* multiplication table. | [
"2 2 2\n",
"2 3 4\n",
"1 10 5\n"
] | [
"2\n",
"3\n",
"5\n"
] | A 2 × 3 multiplication table looks like this: | 2,000 | [
{
"input": "2 2 2",
"output": "2"
},
{
"input": "2 3 4",
"output": "3"
},
{
"input": "1 10 5",
"output": "5"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "10 1 7",
"output": "7"
},
{
"input": "10 10 33",
"output": "14"
},
{
"input": "... | 1,658,074,860 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 0 | def fun(a,n,m):
lt_eq_mid=0
for i in range(1,n+1):
lt_eq_mid+=min(m,a//i)
return lt_eq_mid
n,m,k=list(map(int,input().split()))
left=1
right=n*m
while(left<=right):
mid=(left+right)//2
lt_eq_mid=fun(mid,n,m)
#print(str(mid)+" "+str(lt_eq_mid))
if(lt_eq_mid>k):
prev=fun(mid-... | Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multi... | ```python
def fun(a,n,m):
lt_eq_mid=0
for i in range(1,n+1):
lt_eq_mid+=min(m,a//i)
return lt_eq_mid
n,m,k=list(map(int,input().split()))
left=1
right=n*m
while(left<=right):
mid=(left+right)//2
lt_eq_mid=fun(mid,n,m)
#print(str(mid)+" "+str(lt_eq_mid))
if(lt_eq_mid>k):
pre... | 0 | |
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}... | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All sub... | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"... | 1,638,459,564 | 2,147,483,647 | Python 3 | OK | TESTS | 133 | 46 | 0 | s = input()
f = False
d = len(s)
while s != '':
for i in range(len(s) // 2):
if s[i] != s[len(s) - 1 -i]:
f = True
break
if f:
break
else:
s = s[1:]
d -= 1
print(d) | Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar... | ```python
s = input()
f = False
d = len(s)
while s != '':
for i in range(len(s) // 2):
if s[i] != s[len(s) - 1 -i]:
f = True
break
if f:
break
else:
s = s[1:]
d -= 1
print(d)
``` | 3 | |
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,003,591 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | #for _ in range(int(input())):
q=int(input())
a=set(list(map(int,input().split())))
print(*a)
| 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
#for _ in range(int(input())):
q=int(input())
a=set(list(map(int,input().split())))
print(*a)
``` | 0 | |
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en... | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... | 1,669,850,114 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 1,536,000 | n, m = map(int, input().split())
a = list(map(int, input().split()))
d = [j for j in range(1, len(a) + 1)]
while len(a) > 1:
if m >= a[0]:
del a[0], d[0]
elif m < a[0]:
a[0] -= m
a[0], a[-1], d[0], d[-1] = a[-1], a[0], d[-1], d[0]
print(d[0]) | Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line ... | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
d = [j for j in range(1, len(a) + 1)]
while len(a) > 1:
if m >= a[0]:
del a[0], d[0]
elif m < a[0]:
a[0] -= m
a[0], a[-1], d[0], d[-1] = a[-1], a[0], d[-1], d[0]
print(d[0])
``` | 0 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,628,750,587 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 156 | 6,758,400 | x=input()
x=x.replace('--','2',x.count('--'))
x=x.replace('-.','1',x.count('-.'))
x=x.replace('.','0',x.count('.'))
print(x)
| Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
x=input()
x=x.replace('--','2',x.count('--'))
x=x.replace('-.','1',x.count('-.'))
x=x.replace('.','0',x.count('.'))
print(x)
``` | 3.948411 |
760 | B | Frodo and pillows | PROGRAMMING | 1,500 | [
"binary search",
"greedy"
] | null | null | *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge... | The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed. | Print single integer — the maximum number of pillows Frodo can have so that no one is hurt. | [
"4 6 2\n",
"3 10 3\n",
"3 6 1\n"
] | [
"2\n",
"4\n",
"3\n"
] | In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third exa... | 1,000 | [
{
"input": "4 6 2",
"output": "2"
},
{
"input": "3 10 3",
"output": "4"
},
{
"input": "3 6 1",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1000000000 1",
"output": "1000000000"
},
{
... | 1,624,372,490 | 2,147,483,647 | PyPy 3 | OK | TESTS | 69 | 888 | 1,638,400 | n,m,k = list(map(int, input().split(' ')))
extra = m - n
maxi = 1
if n == 1:
print(m)
elif n == 2:
if m%2 == 0:
print(m//2)
else:
print(m//2 +1)
else:
for i in range(extra):
stepPillows = 1 + min(k-1,i) + min(n-k,i)
if extra >= stepPillows:
extra -= stepPill... | Title: Frodo and pillows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as ma... | ```python
n,m,k = list(map(int, input().split(' ')))
extra = m - n
maxi = 1
if n == 1:
print(m)
elif n == 2:
if m%2 == 0:
print(m//2)
else:
print(m//2 +1)
else:
for i in range(extra):
stepPillows = 1 + min(k-1,i) + min(n-k,i)
if extra >= stepPillows:
extra -... | 3 | |
60 | B | Serial Time! | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | B. Serial Time! | 2 | 256 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is t... | The first line contains three numbers *k*, *n*, *m* (1<=≤<=*k*,<=*n*,<=*m*<=≤<=10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separa... | The answer should contain a single number, showing in how many minutes the plate will be filled. | [
"1 1 1\n\n.\n\n1 1\n",
"2 1 1\n\n.\n\n#\n\n1 1\n",
"2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n",
"3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n",
"3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1\n"
] | [
"1\n",
"1\n",
"5\n",
"7\n",
"13\n"
] | none | 1,000 | [
{
"input": "1 1 1\n\n.\n\n1 1",
"output": "1"
},
{
"input": "2 1 1\n\n.\n\n#\n\n1 1",
"output": "1"
},
{
"input": "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1",
"output": "5"
},
{
"input": "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2",
"output": "7"
},
{
"input": "3 3 3\n\n.#... | 1,384,283,307 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 307,200 | a, b, c = map(int, input().split())
t = [[[0] * c for k in range(b)] for i in range(a)]
for i in range(a):
input()
for j in range(b):
for k, q in enumerate(input()):
if q == '#': t[i][j][k] = 1
q = [(i, j, k) for i in range(-1, 2) for j in range(-1, 2) for k in range(-1, 2)]
... | Title: Serial Time!
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represe... | ```python
a, b, c = map(int, input().split())
t = [[[0] * c for k in range(b)] for i in range(a)]
for i in range(a):
input()
for j in range(b):
for k, q in enumerate(input()):
if q == '#': t[i][j][k] = 1
q = [(i, j, k) for i in range(-1, 2) for j in range(-1, 2) for k in range... | 0 |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,647,581,103 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 62 | 0 | ber = list(input())
bir = list(input())
j = len(ber)-1
for i in range(j+1):
if ber[i] != bir[j-i]:
print('NO')
exit()
print('YES') | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
ber = list(input())
bir = list(input())
j = len(ber)-1
for i in range(j+1):
if ber[i] != bir[j-i]:
print('NO')
exit()
print('YES')
``` | -1 |
25 | D | Roads not only in Berland | PROGRAMMING | 1,900 | [
"dsu",
"graphs",
"trees"
] | D. Roads not only in Berland | 2 | 256 | Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are *n* cities in Berland and neighboring countries in total and exactly *n*<=-<=1 two... | The first line contains integer *n* (2<=≤<=*n*<=≤<=1000) — amount of cities in Berland and neighboring countries. Next *n*<=-<=1 lines contain the description of roads. Each road is described by two space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — pair of cities, which the r... | Output the answer, number *t* — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output *t* lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road betw... | [
"2\n1 2\n",
"7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7\n"
] | [
"0\n",
"1\n3 1 3 7\n"
] | none | 0 | [
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7",
"output": "1\n3 1 3 7"
},
{
"input": "3\n3 2\n1 2",
"output": "0"
},
{
"input": "3\n3 1\n3 2",
"output": "0"
},
{
"input": "4\n1 4\n3 1\n3 4",
"output": "1\n3 4 2 4"
},
{
... | 1,646,053,214 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 154 | 102,400 |
from collections import defaultdict
def main():
n = int(input())
edges = list()
for i in range(n-1):
u, v = map(int, input().split(' '))
edges.append([u, v])
def find(a):
if p[a] != a:
p[a] = find(p[a])
return p[a]
def union(a, b):
... | Title: Roads not only in Berland
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach a... | ```python
from collections import defaultdict
def main():
n = int(input())
edges = list()
for i in range(n-1):
u, v = map(int, input().split(' '))
edges.append([u, v])
def find(a):
if p[a] != a:
p[a] = find(p[a])
return p[a]
def unio... | 0 |
745 | A | Hongcow Learns the Cyclic Shift | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). | Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. | [
"abcd\n",
"bbb\n",
"yzyz\n"
] | [
"4\n",
"1\n",
"2\n"
] | For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | 500 | [
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14... | 1,532,685,004 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 124 | 0 | s = input()
ans = set()
for l in range(len(s)):
t = s[l:] + s[:l]
ans.add(t)
print(len(ans)) | Title: Hongcow Learns the Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to m... | ```python
s = input()
ans = set()
for l in range(len(s)):
t = s[l:] + s[:l]
ans.add(t)
print(len(ans))
``` | 3 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,695,110,166 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 46 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Sep 19 15:47:18 2023
@author: lenovo
"""
a,b=map(int,input().split())
s=0
while a<=b:
a*=3
b*=2
s=s+1
print(s)
| Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 19 15:47:18 2023
@author: lenovo
"""
a,b=map(int,input().split())
s=0
while a<=b:
a*=3
b*=2
s=s+1
print(s)
``` | 3 | |
412 | B | Network Configuration | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necess... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* deno... | Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer. | [
"3 2\n40 20 30\n",
"6 4\n100 20 40 20 50 50\n"
] | [
"30\n",
"40\n"
] | In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal. | 1,000 | [
{
"input": "3 2\n40 20 30",
"output": "30"
},
{
"input": "6 4\n100 20 40 20 50 50",
"output": "40"
},
{
"input": "1 1\n16",
"output": "16"
},
{
"input": "2 1\n10000 17",
"output": "10000"
},
{
"input": "2 2\n200 300",
"output": "200"
},
{
"input": "3 1... | 1,698,418,610 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 0 | n,k=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
print(min(a[:k])) | Title: Network Configuration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly a... | ```python
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
print(min(a[:k]))
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.